Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
482 changes: 242 additions & 240 deletions pixi.lock

Large diffs are not rendered by default.

61 changes: 44 additions & 17 deletions src/adbc_driver_quack.cc
Original file line number Diff line number Diff line change
Expand Up @@ -650,19 +650,42 @@ void CloseConnectionState(ConnectionState* state) {
state->transaction_active = false;
}

AdbcStatusCode RunDuckDbQuery(ConnectionState* state, std::string const& sql,
AdbcError* error) {
enum class IngestConflict { None, Create, Append };

AdbcStatusCode DuckDbQueryError(AdbcError* error, duckdb_error_type error_type,
std::string message,
IngestConflict ingest_conflict) {
bool const create_conflict =
ingest_conflict == IngestConflict::Create &&
(error_type == DUCKDB_ERROR_CATALOG ||
error_type == DUCKDB_ERROR_INVALID_INPUT) &&
message.find("already exists") != std::string::npos;
bool const schema_conflict =
ingest_conflict == IngestConflict::Append &&
error_type == DUCKDB_ERROR_BINDER &&
message.find(" columns but ") != std::string::npos &&
message.find(" values were supplied") != std::string::npos;
if (create_conflict || schema_conflict) {
return StatusError(error, ADBC_STATUS_ALREADY_EXISTS, std::move(message),
static_cast<int32_t>(error_type));
}
return IoError(error, std::move(message), static_cast<int32_t>(error_type));
}

AdbcStatusCode RunDuckDbQuery(
ConnectionState* state, std::string const& sql, AdbcError* error,
IngestConflict ingest_conflict = IngestConflict::None) {
duckdb_result result;
duckdb_state const query_state =
duckdb_query(state->connection, sql.c_str(), &result);
if (query_state == DuckDBError) {
char const* result_error = duckdb_result_error(&result);
std::string message =
result_error != nullptr ? result_error : "DuckDB query failed";
auto const error_type =
static_cast<int32_t>(duckdb_result_error_type(&result));
auto const error_type = duckdb_result_error_type(&result);
duckdb_destroy_result(&result);
return IoError(error, std::move(message), error_type);
return DuckDbQueryError(error, error_type, std::move(message),
ingest_conflict);
}
duckdb_destroy_result(&result);
return Ok(error);
Expand All @@ -687,9 +710,9 @@ bool IsNotFoundDuckDbError(duckdb_error_type error_type,
lower_message.find("no catalog + schema named") != std::string::npos;
}

AdbcStatusCode RunDuckDbQueryAllowNotFound(ConnectionState* state,
std::string const& sql,
AdbcError* error) {
AdbcStatusCode RunDuckDbQueryAllowNotFound(
ConnectionState* state, std::string const& sql, AdbcError* error,
IngestConflict ingest_conflict = IngestConflict::None) {
duckdb_result result;
duckdb_state const query_state =
duckdb_query(state->connection, sql.c_str(), &result);
Expand All @@ -704,16 +727,18 @@ AdbcStatusCode RunDuckDbQueryAllowNotFound(ConnectionState* state,
if (IsNotFoundDuckDbError(result_error_type, message)) {
return NotFound(error, std::move(message), error_type);
}
return IoError(error, std::move(message), error_type);
return DuckDbQueryError(error, result_error_type, std::move(message),
ingest_conflict);
}
duckdb_destroy_result(&result);
return Ok(error);
}

AdbcStatusCode RunRemoteQuery(ConnectionState* state, std::string const& sql,
AdbcError* error) {
AdbcStatusCode RunRemoteQuery(
ConnectionState* state, std::string const& sql, AdbcError* error,
IngestConflict ingest_conflict = IngestConflict::None) {
return RunDuckDbQuery(state, adbc_driver_quack::BuildRemoteQuerySql(sql),
error);
error, ingest_conflict);
}

AdbcStatusCode RunRemoteQueryAllowNotFound(ConnectionState* state,
Expand Down Expand Up @@ -842,9 +867,9 @@ AdbcStatusCode ExecuteBulkIngest(StatementState* state, int64_t* rows_affected,
std::string const create_columns =
" (" + JoinColumnDefinitions(column_definitions) + ")";
if (state->ingest_mode == ADBC_INGEST_OPTION_MODE_CREATE) {
status =
RunRemoteQuery(state->connection,
"CREATE TABLE " + server_target + create_columns, error);
status = RunRemoteQuery(state->connection,
"CREATE TABLE " + server_target + create_columns,
error, IngestConflict::Create);
if (status == ADBC_STATUS_OK) {
status = RunDuckDbQuery(state->connection,
"SELECT * FROM quack_clear_cache()", error);
Expand All @@ -860,7 +885,8 @@ AdbcStatusCode ExecuteBulkIngest(StatementState* state, int64_t* rows_affected,
if (status == ADBC_STATUS_OK) {
status = RunDuckDbQueryAllowNotFound(
state->connection,
"INSERT INTO " + target + " SELECT * FROM " + quoted_data, error);
"INSERT INTO " + target + " SELECT * FROM " + quoted_data, error,
IngestConflict::Append);
}
} else if (state->ingest_mode == ADBC_INGEST_OPTION_MODE_REPLACE) {
status = RunRemoteQuery(state->connection,
Expand Down Expand Up @@ -890,7 +916,8 @@ AdbcStatusCode ExecuteBulkIngest(StatementState* state, int64_t* rows_affected,
if (status == ADBC_STATUS_OK) {
status = RunDuckDbQuery(
state->connection,
"INSERT INTO " + target + " SELECT * FROM " + quoted_data, error);
"INSERT INTO " + target + " SELECT * FROM " + quoted_data, error,
IngestConflict::Append);
}
} else {
status = InvalidArgument(error, "unsupported bulk ingest mode");
Expand Down
33 changes: 33 additions & 0 deletions validation/queries/type/select/timestamp0.txtcase
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) 2026 ADBC Drivers Contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// part: metadata

[tags]
sql-type-name = "TIMESTAMP_S"
field-type-name = "TIMESTAMP_S"

// part: setup_query

CREATE TABLE test_timestamp (
idx INTEGER,
res TIMESTAMP_S
);

INSERT INTO test_timestamp (idx, res) VALUES (1, '2023-05-15 13:45:30');
INSERT INTO test_timestamp (idx, res) VALUES (2, '2000-01-01 00:00:00');
INSERT INTO test_timestamp (idx, res) VALUES (3, '1969-07-20 20:17:40');
INSERT INTO test_timestamp (idx, res) VALUES (4, '0001-01-01 00:00:00');
INSERT INTO test_timestamp (idx, res) VALUES (5, '9999-12-31 23:59:59');
INSERT INTO test_timestamp (idx, res) VALUES (6, NULL);
56 changes: 56 additions & 0 deletions validation/queries/type/select/timestamp0tz.txtcase
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright (c) 2026 ADBC Drivers Contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// part: metadata

[tags]
sql-type-name = "TIMESTAMPTZ"
field-type-name = "TIMESTAMPTZ"
caveats = ["DuckDB returns TIMESTAMPTZ values at microsecond precision; additional fractional digits are discarded. See https://duckdb.org/docs/current/sql/data_types/timestamp."]

// part: setup_query

CREATE TABLE test_timestamptz (
idx INTEGER,
res TIMESTAMPTZ
);

INSERT INTO test_timestamptz (idx, res) VALUES (1, TIMESTAMP WITH TIME ZONE '2023-05-15 13:45:30+00');
INSERT INTO test_timestamptz (idx, res) VALUES (2, TIMESTAMP WITH TIME ZONE '2000-01-01 00:00:00+00');
INSERT INTO test_timestamptz (idx, res) VALUES (3, TIMESTAMP WITH TIME ZONE '1969-07-20 20:17:40+00');
INSERT INTO test_timestamptz (idx, res) VALUES (4, TIMESTAMP WITH TIME ZONE '0001-01-01 00:00:00+00');
INSERT INTO test_timestamptz (idx, res) VALUES (5, TIMESTAMP WITH TIME ZONE '9999-12-31 23:59:59+00');
INSERT INTO test_timestamptz (idx, res) VALUES (6, NULL);

// part: expected_schema

{
"format": "+s",
"children": [
{
"name": "res",
"format": "tsu:UTC",
"flags": ["nullable"]
}
]
}

// part: expected

{"res": 1684158330000000}
{"res": 946684800000000}
{"res": -14182940000000}
{"res": -62135596800000000}
{"res": 253402300799000000}
{"res": null}
33 changes: 33 additions & 0 deletions validation/queries/type/select/timestamp1.txtcase
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) 2026 ADBC Drivers Contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// part: metadata

[tags]
sql-type-name = "TIMESTAMP_MS"
field-type-name = "TIMESTAMP_MS"

// part: setup_query

CREATE TABLE test_timestamp (
idx INTEGER,
res TIMESTAMP_MS
);

INSERT INTO test_timestamp (idx, res) VALUES (1, '2023-05-15 13:45:30.1');
INSERT INTO test_timestamp (idx, res) VALUES (2, '2000-01-01 00:00:00.2');
INSERT INTO test_timestamp (idx, res) VALUES (3, '1969-07-20 20:17:40.3');
INSERT INTO test_timestamp (idx, res) VALUES (4, '0001-01-01 00:00:00.0');
INSERT INTO test_timestamp (idx, res) VALUES (5, '9999-12-31 23:59:59.9');
INSERT INTO test_timestamp (idx, res) VALUES (6, NULL);
56 changes: 56 additions & 0 deletions validation/queries/type/select/timestamp1tz.txtcase
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright (c) 2026 ADBC Drivers Contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// part: metadata

[tags]
sql-type-name = "TIMESTAMPTZ"
field-type-name = "TIMESTAMPTZ"
caveats = ["DuckDB returns TIMESTAMPTZ values at microsecond precision; additional fractional digits are discarded. See https://duckdb.org/docs/current/sql/data_types/timestamp."]

// part: setup_query

CREATE TABLE test_timestamptz (
idx INTEGER,
res TIMESTAMPTZ
);

INSERT INTO test_timestamptz (idx, res) VALUES (1, TIMESTAMP WITH TIME ZONE '2023-05-15 13:45:30.1+00');
INSERT INTO test_timestamptz (idx, res) VALUES (2, TIMESTAMP WITH TIME ZONE '2000-01-01 00:00:00.2+00');
INSERT INTO test_timestamptz (idx, res) VALUES (3, TIMESTAMP WITH TIME ZONE '1969-07-20 20:17:40.3+00');
INSERT INTO test_timestamptz (idx, res) VALUES (4, TIMESTAMP WITH TIME ZONE '0001-01-01 00:00:00.0+00');
INSERT INTO test_timestamptz (idx, res) VALUES (5, TIMESTAMP WITH TIME ZONE '9999-12-31 23:59:59.9+00');
INSERT INTO test_timestamptz (idx, res) VALUES (6, NULL);

// part: expected_schema

{
"format": "+s",
"children": [
{
"name": "res",
"format": "tsu:UTC",
"flags": ["nullable"]
}
]
}

// part: expected

{"res": 1684158330100000}
{"res": 946684800200000}
{"res": -14182939700000}
{"res": -62135596800000000}
{"res": 253402300799900000}
{"res": null}
33 changes: 33 additions & 0 deletions validation/queries/type/select/timestamp2.txtcase
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) 2026 ADBC Drivers Contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// part: metadata

[tags]
sql-type-name = "TIMESTAMP_MS"
field-type-name = "TIMESTAMP_MS"

// part: setup_query

CREATE TABLE test_timestamp (
idx INTEGER,
res TIMESTAMP_MS
);

INSERT INTO test_timestamp (idx, res) VALUES (1, '2023-05-15 13:45:30.12');
INSERT INTO test_timestamp (idx, res) VALUES (2, '2000-01-01 00:00:00.23');
INSERT INTO test_timestamp (idx, res) VALUES (3, '1969-07-20 20:17:40.34');
INSERT INTO test_timestamp (idx, res) VALUES (4, '0001-01-01 00:00:00.00');
INSERT INTO test_timestamp (idx, res) VALUES (5, '9999-12-31 23:59:59.99');
INSERT INTO test_timestamp (idx, res) VALUES (6, NULL);
56 changes: 56 additions & 0 deletions validation/queries/type/select/timestamp2tz.txtcase
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright (c) 2026 ADBC Drivers Contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// part: metadata

[tags]
sql-type-name = "TIMESTAMPTZ"
field-type-name = "TIMESTAMPTZ"
caveats = ["DuckDB returns TIMESTAMPTZ values at microsecond precision; additional fractional digits are discarded. See https://duckdb.org/docs/current/sql/data_types/timestamp."]

// part: setup_query

CREATE TABLE test_timestamptz (
idx INTEGER,
res TIMESTAMPTZ
);

INSERT INTO test_timestamptz (idx, res) VALUES (1, TIMESTAMP WITH TIME ZONE '2023-05-15 13:45:30.12+00');
INSERT INTO test_timestamptz (idx, res) VALUES (2, TIMESTAMP WITH TIME ZONE '2000-01-01 00:00:00.23+00');
INSERT INTO test_timestamptz (idx, res) VALUES (3, TIMESTAMP WITH TIME ZONE '1969-07-20 20:17:40.34+00');
INSERT INTO test_timestamptz (idx, res) VALUES (4, TIMESTAMP WITH TIME ZONE '0001-01-01 00:00:00.00+00');
INSERT INTO test_timestamptz (idx, res) VALUES (5, TIMESTAMP WITH TIME ZONE '9999-12-31 23:59:59.99+00');
INSERT INTO test_timestamptz (idx, res) VALUES (6, NULL);

// part: expected_schema

{
"format": "+s",
"children": [
{
"name": "res",
"format": "tsu:UTC",
"flags": ["nullable"]
}
]
}

// part: expected

{"res": 1684158330120000}
{"res": 946684800230000}
{"res": -14182939660000}
{"res": -62135596800000000}
{"res": 253402300799990000}
{"res": null}
Loading
Loading