diff --git a/runtime/drivers/duckdb/transporter_postgres_to_duckDB_test.go b/runtime/drivers/duckdb/transporter_postgres_to_duckDB_test.go index 2a7bb9a0c3c..f67f6144865 100644 --- a/runtime/drivers/duckdb/transporter_postgres_to_duckDB_test.go +++ b/runtime/drivers/duckdb/transporter_postgres_to_duckDB_test.go @@ -19,6 +19,7 @@ import ( var sqlStmt = `CREATE TYPE country AS ENUM ('IND', 'AUS', 'SA', 'NZ'); CREATE TABLE all_datatypes ( id serial PRIMARY KEY, + uuid UUID, name text, age integer, is_married boolean, @@ -45,9 +46,9 @@ var sqlStmt = `CREATE TYPE country AS ENUM ('IND', 'AUS', 'SA', 'NZ'); emp_salary NUMERIC, country country ); - INSERT INTO all_datatypes (name, age, is_married, date_of_birth, time_of_day, created_at, json, json_data, bit,bit_varying, character, character_varying, bpchar, smallint, text, timestamptz, float4, float8, int2, int4, int8, int8_array, timestamptz_array, emp_salary, country) + INSERT INTO all_datatypes (uuid, name, age, is_married, date_of_birth, time_of_day, created_at, json, json_data, bit,bit_varying, character, character_varying, bpchar, smallint, text, timestamptz, float4, float8, int2, int4, int8, int8_array, timestamptz_array, emp_salary, country) VALUES - ('John Doe', 30, true, '1983-03-08', '12:35:00', '2023-09-12 12:46:55', '{"name": "John Doe", "age": 30, "salary": 100000}', '{"name": "John Doe", "age": 30, "salary": 100000}', b'1',b'10101010', 'a', 'ab', 'abcd', 123, 'This is a text string.', '2023-09-12 12:46:55+05:30', 23.2, 123.45, 1, 1234, 1234567, Array[1234567, 7654312], Array[timestamp'2023-09-12 12:46:55+05:30', timestamp'2023-10-12 12:46:55+05:30'], 38500000000000.71256565656563, 'IND'); + (gen_random_uuid(), 'John Doe', 30, true, '1983-03-08', '12:35:00', '2023-09-12 12:46:55', '{"name": "John Doe", "age": 30, "salary": 100000}', '{"name": "John Doe", "age": 30, "salary": 100000}', b'1',b'10101010', 'a', 'ab', 'abcd', 123, 'This is a text string.', '2023-09-12 12:46:55+05:30', 23.2, 123.45, 1, 1234, 1234567, Array[1234567, 7654312], Array[timestamp'2023-09-12 12:46:55+05:30', timestamp'2023-10-12 12:46:55+05:30'], 38500000000000.71256565656563, 'IND'); ` func TestTransfer(t *testing.T) { diff --git a/runtime/drivers/duckdb/transporter_sqlstore_to_duckDB.go b/runtime/drivers/duckdb/transporter_sqlstore_to_duckDB.go index 2c4d4f12142..fe883418654 100644 --- a/runtime/drivers/duckdb/transporter_sqlstore_to_duckDB.go +++ b/runtime/drivers/duckdb/transporter_sqlstore_to_duckDB.go @@ -191,6 +191,9 @@ func (s *sqlStoreToDuckDB) transferFromRowIterator(ctx context.Context, iter dri } return err } + if err := convert(row, schema); err != nil { // duckdb specific datatype conversion + return err + } if err := a.AppendRow(row...); err != nil { return err @@ -224,6 +227,21 @@ func CreateTableQuery(schema *runtimev1.StructType, name string) (string, error) return query, nil } +func convert(row []driver.Value, schema *runtimev1.StructType) error { + for i, v := range row { + if schema.Fields[i].Type.Code == runtimev1.Type_CODE_UUID { + val, ok := v.([16]byte) + if !ok { + return fmt.Errorf("unknown type for UUID field %s: %T", schema.Fields[i].Name, v) + } + var uuid duckdb.UUID + copy(uuid[:], val[:]) + row[i] = uuid + } + } + return nil +} + func pbTypeToDuckDB(t *runtimev1.Type) (string, error) { code := t.Code switch code { diff --git a/runtime/drivers/postgres/parser.go b/runtime/drivers/postgres/parser.go index eb940da79f1..c3dbe76724b 100644 --- a/runtime/drivers/postgres/parser.go +++ b/runtime/drivers/postgres/parser.go @@ -6,7 +6,6 @@ import ( "strings" "time" - "github.com/google/uuid" "github.com/jackc/pgx/v5/pgtype" runtimev1 "github.com/rilldata/rill/proto/gen/rill/runtime/v1" ) @@ -248,11 +247,7 @@ func (m *uuidMapper) runtimeType() *runtimev1.Type { func (m *uuidMapper) value(pgxVal any) (any, error) { switch b := pgxVal.(type) { case [16]byte: - id, err := uuid.FromBytes(b[:]) - if err != nil { - return nil, err - } - return id.String(), nil + return b, nil default: return nil, fmt.Errorf("uuidMapper: unsupported type %v", b) }