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

dsq failed to recognize nested field, if its parent object absents in some records #110

Open
mon-jai opened this issue Apr 22, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@mon-jai
Copy link

mon-jai commented Apr 22, 2023

Describe the bug and expected behavior

dsq failed to recognize nested field if its parent object absents in some records.

Reproduction steps

dsq failed to retrieve location.city, if location is absent in some records.

user_addresses.json

[
  {"name": "Agarrah", "location": {"city": "Toronto", "address": { "number": 1002 }}},
  {"name": "Minoara", "location": {"city": "Mexico City", "address": { "number": 19 }}},
  {"name": "Fontoon"}
]

Result:

dsq user_addresses.json 'SELECT name, "location.city" FROM {}'
[{"name":"Agarrah","\"location.city\"":"location.city"},
{"name":"Minoara","\"location.city\"":"location.city"},
{"name":"Fontoon","\"location.city\"":"location.city"}]

Expected behavior:

dsq user_addresses.json 'SELECT name, "location.city" FROM {}'
[{"name":"Agarrah","location.city":"Toronto"},
{"name":"Minoara","location.city":"Mexico City"},
{"name":"Fontoon","location.city":null}]

Versions

  • OS: Linux DESKTOP-IID1F0E 5.15.90.1-microsoft-standard-WSL2 #1 SMP Fri Jan 27 02:56:13 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
  • Shell: Bash
  • dsq version: 0.23.0
@mon-jai mon-jai added the bug Something isn't working label Apr 22, 2023
@eatonphil
Copy link
Member

Here's a way you can work around this:

$ dsq user_addresses.json 'select location->>"address" FROM {}'
[{"location->>\"address\"":"{\"number\":1002}"},
{"location->>\"address\"":"{\"number\":19}"},
{"location->>\"address\"":null}]

@mon-jai
Copy link
Author

mon-jai commented Apr 23, 2023

@eatonphil That is great. But it won't work if every record contains the location field, so won't work consistently on other datasets with the same schema.

Maybe we can add a flag to also include the string representation of objects, regardless of whether or not it can be extracted to sub-fields, like something called --preserve-json-string?

# location field will present in all situations
$ dsq user_addresses.json 'select location->>"address" FROM {}' --preserve-json-string

@eatonphil
Copy link
Member

But it won't work if every record contains the location field, so won't work consistently on other datasets with the same schema.

I don't understand what you mean by this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants