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 shorthand in record expression creates field name "cast" #5315

Open
philrz opened this issue Oct 3, 2024 · 0 comments
Open

Cast shorthand in record expression creates field name "cast" #5315

philrz opened this issue Oct 3, 2024 · 0 comments

Comments

@philrz
Copy link
Contributor

philrz commented Oct 3, 2024

tl;dr

As a user, the field name cast seems unexpected here.

$ echo '{x:1, y:2}' | zq 'cut x,float64(y)' -
{x:1,cast:2.}

Details

Repro is with Zed commit b8fe312.

In the language, field names are commonly derived from function names when the calls are made in record expressions like this. For instance:

$ zq -version
Version: v1.18.0-11-gb8fe3121

$ echo '{x:1, y:-2}' | zq 'cut x,abs(y)' -
{x:1,abs:2}

And of course, if a user wants to explicitly assign a field name to avoid this effect, they can include explicit assignment.

$ echo '{x:1, y:-2}' | zq 'cut x,y:=abs(y)' -
{x:1,y:2}

That said, going back to our first example, the field name cast would only make sense if the user knows the implementation detail of float64() being a wrapper around the cast() function. Instead one of the following would seem more intuitive:

  1. Using the field name float64 to match the behavior we just saw with abs().
  2. Maintaining the original field name (y in this case).

In a group discussion, there was consensus on maintaining the original field name, which happens to match my instincts as well.

In that same discussion, @mattnibs pointed out a related surprise that when dealing with nested fields, this casting operation creates a top-level field, whereas he's felt it should keep the value in its nested path location.

$ echo '{x:1, y:2, a: {b: 3}}' | zq 'cut x,float64(a.b)' -
{x:1,cast:3.}

If we don't address that when taking up this issue, I can open a separate issue at that time.

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

No branches or pull requests

1 participant