cube2222 / octosql

OctoSQL is a query tool that allows you to join, analyse and transform data from multiple databases and file formats using SQL.
Mozilla Public License 2.0
4.74k stars 201 forks source link

It converts ints to floats #293

Closed ostrolucky closed 1 year ago

ostrolucky commented 1 year ago
➜  fe-bl-service git:(master) ✗ cat foo.json                                                                                                                                                                                                                <<<
{"price":3900,"productId":4999418}
{"price":3900,"productId":4999418}
{"price":16149,"productId":11233876}
{"price":4214,"productId":13443985}
{"price":4100,"productId":17839840}
{"price":2498,"productId":17839841}
{"price":1980,"productId":17839841}
{"price":2595,"productId":17839843}
{"price":2599,"productId":17839875}
{"price":2150,"productId":17839875}
➜  fe-bl-service git:(master) ✗ octosql "SELECT productId FROM foo.json"                                                                                                                                                                                    <<<
+---------------+
|   productId   |
+---------------+
| 4.999418e+06  |
| 4.999418e+06  |
| 1.1233876e+07 |
| 1.3443985e+07 |
| 1.783984e+07  |
| 1.7839841e+07 |
| 1.7839841e+07 |
| 1.7839843e+07 |
| 1.7839875e+07 |
| 1.7839875e+07 |
+---------------+

How can I make it stop reformatting those numbers? I've tried SELECT productId::int as well as COALESCE, to no avail:

➜  fe-bl-service git:(master) ✗ octosql "SELECT productId::string FROM foo.json"                                                                                                                                                                            <<<
Usage:
  octosql <query> [flags]
  octosql [command]

Examples:
octosql "SELECT * FROM myfile.json"
octosql "SELECT * FROM mydir/myfile.csv"
octosql "SELECT * FROM plugins.plugins"

Available Commands:
  completion  Generate the autocompletion script for the specified shell
  help        Help about any command
  plugin

Flags:
      --describe         Describe query output schema.
      --explain int      Describe query output schema.
  -h, --help             help for octosql
      --optimize         Whether OctoSQL should optimize the query. (default true)
  -o, --output string    Output format to use. Available options are live_table, batch_table, csv, json and stream_native. (default "live_table")
      --profile string   Enable profiling of the given type: cpu, memory, trace.
  -v, --version          version for octosql

Use "octosql [command] --help" for more information about a command.

Error: typecheck error: typecast of non-union type expression 'Float'
cube2222 commented 1 year ago

Hey @ostrolucky, unfortunately - and I don't like this either - there are no ints in JSON as an encoding format. It's all floats.

You can use int(productId) to convert.

ostrolucky commented 1 year ago

Ah int(productId) I didn't know this one. I think that's a good enough 👍