malloy icon indicating copy to clipboard operation
malloy copied to clipboard

duckdb-wasm and arrow does weird things with some numeric constants

Open broneill opened this issue 10 months ago • 12 comments

What happens?

When running a query with a literal containing a decimal point, the number is parsed as if the decimal point wasn't there at all.

To Reproduce

run: duckdb.table('airports.csv') -> {
  select: num is 123.4
  limit: 1
}

Produces this result:

num
1,234

As a workaround, 1234e-1 can be used instead.

OS:

Windows

Malloy Client:

Web-based VSCode

Malloy Client Version:

???

Database Connection:

DuckDB

broneill avatar Apr 07 '24 19:04 broneill

@broneill I can't reproduce this running the vscode extension, is it possible you are running a very very old version of the extension?

run: duckdb.sql("select 1")->{ select: n is 123.4 }

Produces ...

[
  {
    "n": 123.4
  }
]

mtoy-googly-moogly avatar Apr 10 '24 19:04 mtoy-googly-moogly

I installed the extension a few hours before I found this issue. How can I see what version it is?

broneill avatar Apr 10 '24 22:04 broneill

The only way I know is to look in the upper right of the Malloy pane in the install window ...

image

mtoy-googly-moogly avatar Apr 11 '24 01:04 mtoy-googly-moogly

It looks like I'm running v0.2.1712075074 as well. I'm using Firefox, in case that would make a difference.

broneill avatar Apr 11 '24 01:04 broneill

@broneill I appreciate the bug report, and there once was a bug like this. That bug was fixed eight months ago.

I cannot reproduce what you are seeing from the information in your bug report. The code you posted looks like non-working code to me, since duckdb.table('airports.csv') doesn't read a CSV file, but rather looks for a table called airports.csv in the current schema inside duckdb. I'm not sure what is going on, can we try this ...

Post a screen shot, press Show SQL on the run: in the vscode window where you are seeing this problem maybe we can figure out why I can't reproduce this locally

image

Or catch me on Slack some time and we'll work through it

mtoy-googly-moogly avatar Apr 11 '24 17:04 mtoy-googly-moogly

I created a new decimal-test.malloy file, ran the query, but there's no SQL output, just HTML. I'm running Malloy using the first link provided in the README. Is there another way I should be running it?

m1 m2

broneill avatar Apr 11 '24 17:04 broneill

I am not well versed in these web-only experiences work. I'll redirect this bug towards someone who is, this is definitely a problem with how you are getting your Malloy.

Find us on slack: https://malloy-community.slack.com/ and we'll figure it out.

mtoy-googly-moogly avatar Apr 11 '24 18:04 mtoy-googly-moogly

@whscullin I don't know what is going on here, I cannot reproduce on my machine, but it is somehow related to the try-malloy setup

mtoy-googly-moogly avatar Apr 11 '24 18:04 mtoy-googly-moogly

@broneill I have reproduced this now. It's something weird about the try version of Malloy. We are working on it.

If you have vscode installed, and download the malloy extension, this doesn't happen.,

mtoy-googly-moogly avatar Apr 11 '24 19:04 mtoy-googly-moogly

There's a bug somewhere either in Apache Arrow or DuckDB wasm. We're getting a DecimalBigNum back, and depending on how you ask it for its value, you can get either '1234' or 425289321781646713966358060312437982418n. Weirdly if you use 123.4 / 1, it appears to return correctly as a normal number value. Working on a repro case with the upstream libraries.

whscullin avatar Apr 11 '24 20:04 whscullin

My guess at what's happening is that duckdb-wasm is using the C++ version of Arrow, using the Arrow IPC format to transfer values from the WASM worker to JavaScript, and there is a disconnect somewhere in either the encoding in C++ or decoding in Javascript.

whscullin avatar Apr 11 '24 21:04 whscullin

I've opened https://github.com/duckdb/duckdb-wasm/issues/1703 to track this in DuckDb WASM.

whscullin avatar Apr 15 '24 16:04 whscullin