DuckDB window function returns tuple instead of value #1713
-
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
| Running the (non-cast) query using the duckdb CLI gives: The output type is a  | 
Beta Was this translation helpful? Give feedback.
-
| Yep, this is how Apache Arrow represents large integers. A trivial reproduction of this is: ```sql id=[{n}]
SELECT 11111111100::INT128 AS n
```This defines  const n = new Arrow.util.BN(new Uint16Array([0x19bc, 0x9646, 0x0002, 0, 0, 0, 0, 0]));In order to work with this value as a number, you’ll need to cast it to a number. You can do that in JavaScript as: Number(n)You can also implicitly cast it to a number e.g. as  Alternatively, if you want a bigint, you can go through a string (unfortunately it does not appear that you can coerce directly to BigInt with the current version of Apache Arrow): BigInt(String(n))Inputs.table doesn’t know about the  SELECT (11111111100::INT128)::DOUBLE AS nOr, if you know that the value will fit in 32 bits, you could use  SELECT (1234::INT128)::INT AS nThere was previously a bug https://github.com/apache/arrow/issues/37920 in how Apache Arrow converted decimals to numbers, but that appears to be fixed now. There’s also duckdb/duckdb-wasm#1703 in DuckDB-Wasm. Lastly I’ll note that DuckDB-Wasm has a castBigIntToDouble query option, which we implicitly default to true in DuckDBClient: framework/src/client/stdlib/duckdb.js Lines 168 to 170 in e8e590c However, it seems that this doesn’t really function as desired, perhaps because Apache Arrow is returning a  | 
Beta Was this translation helpful? Give feedback.


Yep, this is how Apache Arrow represents large integers. A trivial reproduction of this is:
This defines
nas aArrow.util.BNinstance in the same fashion as if you had written:In order to work with this value as a number, you’ll need to cast it to a number. You can do that in JavaScript as:
You can also implicitly cast it to a number e.g. as
+n.Alternatively, if you want a bigint, you can go through a string (unfortunately it does not appear that you can coerce directly to BigInt with the current version of Apache Arrow):
I…