Skip to content

C API, wrong uuid value from vector #519

@barsdeveloper

Description

@barsdeveloper

TLDR: When reading a uuid it will have the first bit swapped so that for example initial 80 becomes 00, 11 becomes 91

Hello, I am trying to read a uuid from a vector

let data = *(data as *const duckdb_hugeint).add(row);
println!("upper: {:#x}, lower: {:#x}", data.upper, data.lower);
let uuid = Uuid::from_u64_pair(data.upper as u64, data.lower);
println!("uuid: {}", uuid);

Data is:

let chunk = duckdb_stream_fetch_chunk(*result);
let vector = duckdb_data_chunk_get_vector(*chunk, i);
let data = duckdb_vector_get_data(vector);

You get the idea and I think the way I get it is not the problem. I insert a UUID column with value 550e8400-e29b-41d4-a716-446655440000 and I verify (using duckdb -ui) that my order_id is actually 550e8400-e29b-41d4-a716-446655440000.

The problem is that the first snippet of code prints

upper: 0xd50e8400e29b41d4, lower: 0xa716446655440000
uuid: d50e8400-e29b-41d4-a716-446655440000

If we compare, the value received is one bit off (D = 1101, 5 = 0101)

Read:     d50e8400-e29b-41d4-a716-446655440000
Expected: 550e8400-e29b-41d4-a716-446655440000

I don't understand why would that be the case. I also tried reading duckdb_uhugeint instead of duckdb_hugeint (this is what the documentation says to be the storage type: https://duckdb.org/docs/stable/sql/data_types/numeric.html#universally-unique-identifiers-uuids, also why? A uuid should use unsigned integer). Reading unsigned produces the same problem.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions