Skip to content

Commit 91c083d

Browse files
authored
Merge pull request #177 from duckdb/bump144
Bump to 144
2 parents 0ebfe54 + 3c8d2f4 commit 91c083d

File tree

91 files changed

+988
-502
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+988
-502
lines changed

src/duckdb/extension/core_functions/aggregate/holistic/mode.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,15 +234,12 @@ struct BaseModeFunction {
234234
}
235235

236236
template <class STATE, class OP>
237-
static void Combine(const STATE &source, STATE &target, AggregateInputData &) {
237+
static void Combine(const STATE &source, STATE &target, AggregateInputData &aggr_input_data) {
238238
if (!source.frequency_map) {
239239
return;
240240
}
241241
if (!target.frequency_map) {
242-
// Copy - don't destroy! Otherwise windowing will break.
243-
target.frequency_map = new typename STATE::Counts(*source.frequency_map);
244-
target.count = source.count;
245-
return;
242+
target.frequency_map = TYPE_OP::CreateEmpty(aggr_input_data.allocator);
246243
}
247244
for (auto &val : *source.frequency_map) {
248245
auto &i = (*target.frequency_map)[val.first];

src/duckdb/extension/core_functions/scalar/date/date_trunc.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,8 @@ unique_ptr<BaseStatistics> DateTruncStatistics(vector<BaseStatistics> &child_sta
612612
auto result = NumericStats::CreateEmpty(min_value.type());
613613
NumericStats::SetMin(result, min_value);
614614
NumericStats::SetMax(result, max_value);
615-
result.CopyValidity(child_stats[0]);
615+
616+
result.CombineValidity(child_stats[0], child_stats[1]);
616617
return result.ToUnique();
617618
}
618619

src/duckdb/extension/icu/icu-makedate.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22
#include "duckdb/common/operator/cast_operators.hpp"
33
#include "duckdb/common/operator/subtract.hpp"
44
#include "duckdb/common/types/date.hpp"
5-
#include "duckdb/common/types/time.hpp"
65
#include "duckdb/common/types/timestamp.hpp"
76
#include "duckdb/common/vector_operations/senary_executor.hpp"
87
#include "duckdb/common/vector_operations/septenary_executor.hpp"
98
#include "duckdb/function/cast/cast_function_set.hpp"
109
#include "duckdb/main/extension/extension_loader.hpp"
11-
#include "duckdb/parser/parsed_data/create_scalar_function_info.hpp"
10+
#include "duckdb/main/settings.hpp"
1211
#include "include/icu-casts.hpp"
1312
#include "include/icu-datefunc.hpp"
1413
#include "include/icu-datetrunc.hpp"
@@ -57,6 +56,10 @@ BoundCastInfo ICUMakeDate::BindCastToDate(BindCastInput &input, const LogicalTyp
5756
if (!input.context) {
5857
throw InternalException("Missing context for TIMESTAMPTZ to DATE cast.");
5958
}
59+
if (DBConfig::GetSetting<DisableTimestamptzCastsSetting>(*input.context)) {
60+
throw BinderException("Casting from TIMESTAMP WITH TIME ZONE to DATE without an explicit time zone "
61+
"has been disabled - use \"AT TIME ZONE ...\"");
62+
}
6063

6164
auto cast_data = make_uniq<CastData>(make_uniq<BindData>(*input.context));
6265

@@ -80,7 +83,7 @@ struct ICUMakeTimestampTZFunc : public ICUDateFunc {
8083
ss -= secs;
8184
ss *= Interval::MSECS_PER_SEC;
8285
const auto millis = int32_t(ss);
83-
int64_t micros = std::round((ss - millis) * Interval::MICROS_PER_MSEC);
86+
int64_t micros = LossyNumericCast<int64_t, double>(std::round((ss - millis) * Interval::MICROS_PER_MSEC));
8487

8588
calendar->set(UCAL_YEAR, year);
8689
calendar->set(UCAL_MONTH, month);

src/duckdb/extension/icu/third_party/icu/stubdata/stubdata.cpp

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/duckdb/extension/parquet/include/reader/string_column_reader.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ class StringColumnReader : public ColumnReader {
3636
const StringColumnType string_column_type;
3737

3838
public:
39-
static void VerifyString(const char *str_data, uint32_t str_len, const bool isVarchar);
39+
static bool IsValid(const char *str_data, uint32_t str_len, bool is_varchar);
40+
static bool IsValid(const string &str, bool is_varchar);
41+
static void VerifyString(const char *str_data, uint32_t str_len, bool is_varchar);
4042
void VerifyString(const char *str_data, uint32_t str_len) const;
4143

4244
static void ReferenceBlock(Vector &result, shared_ptr<ResizeableBuffer> &block);

src/duckdb/extension/parquet/parquet_statistics.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -396,18 +396,14 @@ unique_ptr<BaseStatistics> ParquetStatisticsUtils::TransformColumnStatistics(con
396396
break;
397397
case LogicalTypeId::VARCHAR: {
398398
auto string_stats = StringStats::CreateUnknown(type);
399-
if (parquet_stats.__isset.min_value) {
400-
StringColumnReader::VerifyString(parquet_stats.min_value.c_str(), parquet_stats.min_value.size(), true);
399+
if (parquet_stats.__isset.min_value && StringColumnReader::IsValid(parquet_stats.min_value, true)) {
401400
StringStats::SetMin(string_stats, parquet_stats.min_value);
402-
} else if (parquet_stats.__isset.min) {
403-
StringColumnReader::VerifyString(parquet_stats.min.c_str(), parquet_stats.min.size(), true);
401+
} else if (parquet_stats.__isset.min && StringColumnReader::IsValid(parquet_stats.min, true)) {
404402
StringStats::SetMin(string_stats, parquet_stats.min);
405403
}
406-
if (parquet_stats.__isset.max_value) {
407-
StringColumnReader::VerifyString(parquet_stats.max_value.c_str(), parquet_stats.max_value.size(), true);
404+
if (parquet_stats.__isset.max_value && StringColumnReader::IsValid(parquet_stats.max_value, true)) {
408405
StringStats::SetMax(string_stats, parquet_stats.max_value);
409-
} else if (parquet_stats.__isset.max) {
410-
StringColumnReader::VerifyString(parquet_stats.max.c_str(), parquet_stats.max.size(), true);
406+
} else if (parquet_stats.__isset.max && StringColumnReader::IsValid(parquet_stats.max, true)) {
411407
StringStats::SetMax(string_stats, parquet_stats.max);
412408
}
413409
row_group_stats = string_stats.ToUnique();

src/duckdb/extension/parquet/reader/string_column_reader.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,23 @@ StringColumnReader::StringColumnReader(ParquetReader &reader, const ParquetColum
1616
}
1717
}
1818

19-
void StringColumnReader::VerifyString(const char *str_data, uint32_t str_len, const bool is_varchar) {
19+
bool StringColumnReader::IsValid(const char *str_data, uint32_t str_len, const bool is_varchar) {
2020
if (!is_varchar) {
21-
return;
21+
return true;
2222
}
2323
// verify if a string is actually UTF8, and if there are no null bytes in the middle of the string
2424
// technically Parquet should guarantee this, but reality is often disappointing
2525
UnicodeInvalidReason reason;
2626
size_t pos;
2727
auto utf_type = Utf8Proc::Analyze(str_data, str_len, &reason, &pos);
28-
if (utf_type == UnicodeType::INVALID) {
28+
return utf_type != UnicodeType::INVALID;
29+
}
30+
31+
bool StringColumnReader::IsValid(const string &str, bool is_varchar) {
32+
return IsValid(str.c_str(), str.size(), is_varchar);
33+
}
34+
void StringColumnReader::VerifyString(const char *str_data, uint32_t str_len, const bool is_varchar) {
35+
if (!IsValid(str_data, str_len, is_varchar)) {
2936
throw InvalidInputException("Invalid string encoding found in Parquet file: value \"%s\" is not valid UTF8!",
3037
Blob::ToString(string_t(str_data, str_len)));
3138
}

src/duckdb/src/catalog/catalog_search_path.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,15 @@ void CatalogSearchPath::Set(CatalogSearchEntry new_value, CatalogSetPathType set
195195
Set(std::move(new_paths), set_type);
196196
}
197197

198-
const vector<CatalogSearchEntry> &CatalogSearchPath::Get() const {
199-
return paths;
198+
vector<CatalogSearchEntry> CatalogSearchPath::Get() const {
199+
vector<CatalogSearchEntry> res;
200+
for (auto &path : paths) {
201+
if (path.schema.empty()) {
202+
continue;
203+
}
204+
res.emplace_back(path);
205+
}
206+
return res;
200207
}
201208

202209
string CatalogSearchPath::GetDefaultSchema(const string &catalog) const {
@@ -248,7 +255,7 @@ vector<string> CatalogSearchPath::GetCatalogsForSchema(const string &schema) con
248255
catalogs.push_back(SYSTEM_CATALOG);
249256
} else {
250257
for (auto &path : paths) {
251-
if (StringUtil::CIEquals(path.schema, schema)) {
258+
if (StringUtil::CIEquals(path.schema, schema) || path.schema.empty()) {
252259
catalogs.push_back(path.catalog);
253260
}
254261
}
@@ -259,24 +266,24 @@ vector<string> CatalogSearchPath::GetCatalogsForSchema(const string &schema) con
259266
vector<string> CatalogSearchPath::GetSchemasForCatalog(const string &catalog) const {
260267
vector<string> schemas;
261268
for (auto &path : paths) {
262-
if (StringUtil::CIEquals(path.catalog, catalog)) {
269+
if (!path.schema.empty() && StringUtil::CIEquals(path.catalog, catalog)) {
263270
schemas.push_back(path.schema);
264271
}
265272
}
266273
return schemas;
267274
}
268275

269276
const CatalogSearchEntry &CatalogSearchPath::GetDefault() const {
270-
const auto &paths = Get();
271277
D_ASSERT(paths.size() >= 2);
278+
D_ASSERT(!paths[1].schema.empty());
272279
return paths[1];
273280
}
274281

275282
void CatalogSearchPath::SetPathsInternal(vector<CatalogSearchEntry> new_paths) {
276283
this->set_paths = std::move(new_paths);
277284

278285
paths.clear();
279-
paths.reserve(set_paths.size() + 3);
286+
paths.reserve(set_paths.size() + 4);
280287
paths.emplace_back(TEMP_CATALOG, DEFAULT_SCHEMA);
281288
for (auto &path : set_paths) {
282289
paths.push_back(path);

src/duckdb/src/common/adbc/adbc.cpp

Lines changed: 55 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include "duckdb/common/adbc/single_batch_array_stream.hpp"
1414
#include "duckdb/function/table/arrow.hpp"
1515
#include "duckdb/common/adbc/wrappers.hpp"
16+
#include <algorithm>
17+
#include <cstring>
1618
#include <stdlib.h>
1719
#include <string.h>
1820

@@ -862,6 +864,22 @@ AdbcStatusCode StatementExecuteQuery(struct AdbcStatement *statement, struct Arr
862864
if (has_stream && to_table) {
863865
return IngestToTableFromBoundStream(wrapper, error);
864866
}
867+
868+
if (!wrapper->statement) {
869+
if (out) {
870+
out->private_data = nullptr;
871+
out->get_schema = nullptr;
872+
out->get_next = nullptr;
873+
out->release = nullptr;
874+
out->get_last_error = nullptr;
875+
}
876+
877+
if (rows_affected) {
878+
*rows_affected = 0;
879+
}
880+
return ADBC_STATUS_OK;
881+
}
882+
865883
auto stream_wrapper = static_cast<DuckDBAdbcStreamWrapper *>(malloc(sizeof(DuckDBAdbcStreamWrapper)));
866884
if (has_stream) {
867885
// A stream was bound to the statement, use that to bind parameters
@@ -987,6 +1005,12 @@ AdbcStatusCode StatementSetSqlQuery(struct AdbcStatement *statement, const char
9871005
return ADBC_STATUS_INVALID_ARGUMENT;
9881006
}
9891007

1008+
auto query_len = strlen(query);
1009+
if (std::all_of(query, query + query_len, duckdb::StringUtil::CharacterIsSpace)) {
1010+
SetError(error, "No statements found");
1011+
return ADBC_STATUS_INVALID_ARGUMENT;
1012+
}
1013+
9901014
auto wrapper = static_cast<DuckDBAdbcStatementWrapper *>(statement->private_data);
9911015
if (wrapper->ingestion_stream.release) {
9921016
// Release any resources currently held by the ingestion stream before we overwrite it
@@ -1006,6 +1030,13 @@ AdbcStatusCode StatementSetSqlQuery(struct AdbcStatement *statement, const char
10061030
duckdb_destroy_extracted(&extracted_statements);
10071031
return ADBC_STATUS_INTERNAL;
10081032
}
1033+
1034+
if (extract_statements_size == 0) {
1035+
// Query is non-empty, but there are no actual statements.
1036+
duckdb_destroy_extracted(&extracted_statements);
1037+
return ADBC_STATUS_OK;
1038+
}
1039+
10091040
// Now lets loop over the statements, and execute every one
10101041
for (idx_t i = 0; i < extract_statements_size - 1; i++) {
10111042
duckdb_prepared_statement statement_internal = nullptr;
@@ -1161,12 +1192,21 @@ AdbcStatusCode StatementSetOption(struct AdbcStatement *statement, const char *k
11611192
return ADBC_STATUS_INVALID_ARGUMENT;
11621193
}
11631194

1195+
std::string createFilter(const char *input) {
1196+
if (input) {
1197+
auto quoted = duckdb::KeywordHelper::WriteQuoted(input, '\'');
1198+
return quoted;
1199+
}
1200+
return "'%'";
1201+
}
1202+
11641203
AdbcStatusCode ConnectionGetObjects(struct AdbcConnection *connection, int depth, const char *catalog,
11651204
const char *db_schema, const char *table_name, const char **table_type,
11661205
const char *column_name, struct ArrowArrayStream *out, struct AdbcError *error) {
1167-
std::string catalog_filter = catalog ? catalog : "%";
1168-
std::string db_schema_filter = db_schema ? db_schema : "%";
1169-
std::string table_name_filter = table_name ? table_name : "%";
1206+
std::string catalog_filter = createFilter(catalog);
1207+
std::string db_schema_filter = createFilter(db_schema);
1208+
std::string table_name_filter = createFilter(table_name);
1209+
std::string column_name_filter = createFilter(column_name);
11701210
std::string table_type_condition = "";
11711211
if (table_type && table_type[0]) {
11721212
table_type_condition = " AND table_type IN (";
@@ -1182,13 +1222,10 @@ AdbcStatusCode ConnectionGetObjects(struct AdbcConnection *connection, int depth
11821222
if (i > 0) {
11831223
table_type_condition += ", ";
11841224
}
1185-
table_type_condition += "'";
1186-
table_type_condition += table_type[i];
1187-
table_type_condition += "'";
1225+
table_type_condition += createFilter(table_type[i]);
11881226
}
11891227
table_type_condition += ")";
11901228
}
1191-
std::string column_name_filter = column_name ? column_name : "%";
11921229

11931230
std::string query;
11941231
switch (depth) {
@@ -1233,7 +1270,7 @@ AdbcStatusCode ConnectionGetObjects(struct AdbcConnection *connection, int depth
12331270
)[] catalog_db_schemas
12341271
FROM
12351272
information_schema.schemata
1236-
WHERE catalog_name LIKE '%s'
1273+
WHERE catalog_name LIKE %s
12371274
GROUP BY catalog_name
12381275
)",
12391276
catalog_filter);
@@ -1246,7 +1283,7 @@ AdbcStatusCode ConnectionGetObjects(struct AdbcConnection *connection, int depth
12461283
catalog_name,
12471284
schema_name,
12481285
FROM information_schema.schemata
1249-
WHERE schema_name LIKE '%s'
1286+
WHERE schema_name LIKE %s
12501287
)
12511288
12521289
SELECT
@@ -1289,7 +1326,7 @@ AdbcStatusCode ConnectionGetObjects(struct AdbcConnection *connection, int depth
12891326
information_schema.schemata
12901327
LEFT JOIN db_schemas dbs
12911328
USING (catalog_name, schema_name)
1292-
WHERE catalog_name LIKE '%s'
1329+
WHERE catalog_name LIKE %s
12931330
GROUP BY catalog_name
12941331
)",
12951332
db_schema_filter, catalog_filter);
@@ -1333,7 +1370,7 @@ AdbcStatusCode ConnectionGetObjects(struct AdbcConnection *connection, int depth
13331370
)[],
13341371
}) db_schema_tables
13351372
FROM information_schema.tables
1336-
WHERE table_name LIKE '%s'%s
1373+
WHERE table_name LIKE %s%s
13371374
GROUP BY table_catalog, table_schema
13381375
),
13391376
db_schemas AS (
@@ -1344,7 +1381,7 @@ AdbcStatusCode ConnectionGetObjects(struct AdbcConnection *connection, int depth
13441381
FROM information_schema.schemata
13451382
LEFT JOIN tables
13461383
USING (catalog_name, schema_name)
1347-
WHERE schema_name LIKE '%s'
1384+
WHERE schema_name LIKE %s
13481385
)
13491386
13501387
SELECT
@@ -1357,7 +1394,7 @@ AdbcStatusCode ConnectionGetObjects(struct AdbcConnection *connection, int depth
13571394
information_schema.schemata
13581395
LEFT JOIN db_schemas dbs
13591396
USING (catalog_name, schema_name)
1360-
WHERE catalog_name LIKE '%s'
1397+
WHERE catalog_name LIKE %s
13611398
GROUP BY catalog_name
13621399
)",
13631400
table_name_filter, table_type_condition, db_schema_filter, catalog_filter);
@@ -1392,7 +1429,7 @@ AdbcStatusCode ConnectionGetObjects(struct AdbcConnection *connection, int depth
13921429
xdbc_is_generatedcolumn: NULL::BOOLEAN,
13931430
}) table_columns
13941431
FROM information_schema.columns
1395-
WHERE column_name LIKE '%s'
1432+
WHERE column_name LIKE %s
13961433
GROUP BY table_catalog, table_schema, table_name
13971434
),
13981435
constraints AS (
@@ -1421,7 +1458,7 @@ AdbcStatusCode ConnectionGetObjects(struct AdbcConnection *connection, int depth
14211458
constraint_column_names,
14221459
list_filter(
14231460
constraint_column_names,
1424-
lambda name: name LIKE '%s'
1461+
lambda name: name LIKE %s
14251462
)
14261463
)
14271464
GROUP BY database_name, schema_name, table_name
@@ -1441,7 +1478,7 @@ AdbcStatusCode ConnectionGetObjects(struct AdbcConnection *connection, int depth
14411478
USING (table_catalog, table_schema, table_name)
14421479
LEFT JOIN constraints
14431480
USING (table_catalog, table_schema, table_name)
1444-
WHERE table_name LIKE '%s'%s
1481+
WHERE table_name LIKE %s%s
14451482
GROUP BY table_catalog, table_schema
14461483
),
14471484
db_schemas AS (
@@ -1452,7 +1489,7 @@ AdbcStatusCode ConnectionGetObjects(struct AdbcConnection *connection, int depth
14521489
FROM information_schema.schemata
14531490
LEFT JOIN tables
14541491
USING (catalog_name, schema_name)
1455-
WHERE schema_name LIKE '%s'
1492+
WHERE schema_name LIKE %s
14561493
)
14571494
14581495
SELECT
@@ -1465,7 +1502,7 @@ AdbcStatusCode ConnectionGetObjects(struct AdbcConnection *connection, int depth
14651502
information_schema.schemata
14661503
LEFT JOIN db_schemas dbs
14671504
USING (catalog_name, schema_name)
1468-
WHERE catalog_name LIKE '%s'
1505+
WHERE catalog_name LIKE %s
14691506
GROUP BY catalog_name
14701507
)",
14711508
column_name_filter, column_name_filter, table_name_filter,

0 commit comments

Comments
 (0)