Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cast to "type" type #4714

Closed
philrz opened this issue Jul 15, 2023 · 1 comment · Fixed by #4980
Closed

Cast to "type" type #4714

philrz opened this issue Jul 15, 2023 · 1 comment · Fixed by #4980

Comments

@philrz
Copy link
Contributor

philrz commented Jul 15, 2023

Repro is with Zed commit e6be73e.

tl;dr

I found myself wanting to perform this cast, but it's not implemented yet.

$ zq -version
Version: v1.8.1-64-ge6be73ee

$ echo '"<int64>"' | zq -z 'yield type(this)' -
error("cast to type not implemented")

Details

The high level use case is that I want to cast values to richer Zed types so I can use them in certain functions. I'll explain by first using a non-type example.

$ echo '{addr:"1.2.3.4", net:1.0.0.0/8}' | zq -z 'yield cidr_match(net, ip(addr))' -
true

i..e, addr started as a string, so I turned it into an ip so I could use it as an arg to cidr_match().

That worked, so let's start from this:

$ echo '{value:1, dest_type:<int8>}' | zq -z 'yield cast(value, dest_type)' -
1(int8)

That works since dest_type was a type type out of the gate. But what if I do this?

$ echo '{value:1, dest_type:"<int8>"}' | zq -z 'yield cast(value, type(dest_type))' -
error({message:"shaper type argument is not a type",on:error("cast to type not implemented")})

@mattnibs did point out this works, though.

$ echo '{value:1, dest_type:"<int8>"}' | zq -z 'yield cast(value, parse_zson(dest_type))' -
1(int8)

As a user, I'd not thought to try that since the other casting functions work the way they do.

mattnibs added a commit that referenced this issue Jan 11, 2024
mattnibs added a commit that referenced this issue Jan 12, 2024
mattnibs added a commit that referenced this issue Jan 12, 2024
mattnibs added a commit that referenced this issue Jan 15, 2024
@philrz
Copy link
Contributor Author

philrz commented Jan 15, 2024

Verified in Zed commit 8a48163.

The cast attempted in the repro steps now succeeds.

$ zq -version
Version: v1.12.0-28-g8a48163f

$ echo '"<int64>"' | zq -z 'yield type(this)' -
<int64>

Thanks @mattnibs!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant