Skip to content

Commit be79180

Browse files
duckdblabs-botgithub-actions[bot]
authored andcommitted
Update vendored DuckDB sources to b5761ca54c
1 parent 2faea29 commit be79180

76 files changed

Lines changed: 1331 additions & 564 deletions

File tree

Some content is hidden

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

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/src/common/adbc/adbc.cpp

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,12 +1320,21 @@ AdbcStatusCode StatementSetOption(struct AdbcStatement *statement, const char *k
13201320
return ADBC_STATUS_INVALID_ARGUMENT;
13211321
}
13221322

1323+
std::string createFilter(const char *input) {
1324+
if (input) {
1325+
auto quoted = duckdb::KeywordHelper::WriteQuoted(input, '\'');
1326+
return quoted;
1327+
}
1328+
return "'%'";
1329+
}
1330+
13231331
AdbcStatusCode ConnectionGetObjects(struct AdbcConnection *connection, int depth, const char *catalog,
13241332
const char *db_schema, const char *table_name, const char **table_type,
13251333
const char *column_name, struct ArrowArrayStream *out, struct AdbcError *error) {
1326-
std::string catalog_filter = catalog ? catalog : "%";
1327-
std::string db_schema_filter = db_schema ? db_schema : "%";
1328-
std::string table_name_filter = table_name ? table_name : "%";
1334+
std::string catalog_filter = createFilter(catalog);
1335+
std::string db_schema_filter = createFilter(db_schema);
1336+
std::string table_name_filter = createFilter(table_name);
1337+
std::string column_name_filter = createFilter(column_name);
13291338
std::string table_type_condition = "";
13301339
if (table_type && table_type[0]) {
13311340
table_type_condition = " AND table_type IN (";
@@ -1341,13 +1350,10 @@ AdbcStatusCode ConnectionGetObjects(struct AdbcConnection *connection, int depth
13411350
if (i > 0) {
13421351
table_type_condition += ", ";
13431352
}
1344-
table_type_condition += "'";
1345-
table_type_condition += table_type[i];
1346-
table_type_condition += "'";
1353+
table_type_condition += createFilter(table_type[i]);
13471354
}
13481355
table_type_condition += ")";
13491356
}
1350-
std::string column_name_filter = column_name ? column_name : "%";
13511357

13521358
std::string query;
13531359
switch (depth) {
@@ -1392,7 +1398,7 @@ AdbcStatusCode ConnectionGetObjects(struct AdbcConnection *connection, int depth
13921398
)[] catalog_db_schemas
13931399
FROM
13941400
information_schema.schemata
1395-
WHERE catalog_name LIKE '%s'
1401+
WHERE catalog_name LIKE %s
13961402
GROUP BY catalog_name
13971403
)",
13981404
catalog_filter);
@@ -1405,7 +1411,7 @@ AdbcStatusCode ConnectionGetObjects(struct AdbcConnection *connection, int depth
14051411
catalog_name,
14061412
schema_name,
14071413
FROM information_schema.schemata
1408-
WHERE schema_name LIKE '%s'
1414+
WHERE schema_name LIKE %s
14091415
)
14101416
14111417
SELECT
@@ -1448,7 +1454,7 @@ AdbcStatusCode ConnectionGetObjects(struct AdbcConnection *connection, int depth
14481454
information_schema.schemata
14491455
LEFT JOIN db_schemas dbs
14501456
USING (catalog_name, schema_name)
1451-
WHERE catalog_name LIKE '%s'
1457+
WHERE catalog_name LIKE %s
14521458
GROUP BY catalog_name
14531459
)",
14541460
db_schema_filter, catalog_filter);
@@ -1492,7 +1498,7 @@ AdbcStatusCode ConnectionGetObjects(struct AdbcConnection *connection, int depth
14921498
)[],
14931499
}) db_schema_tables
14941500
FROM information_schema.tables
1495-
WHERE table_name LIKE '%s'%s
1501+
WHERE table_name LIKE %s%s
14961502
GROUP BY table_catalog, table_schema
14971503
),
14981504
db_schemas AS (
@@ -1503,7 +1509,7 @@ AdbcStatusCode ConnectionGetObjects(struct AdbcConnection *connection, int depth
15031509
FROM information_schema.schemata
15041510
LEFT JOIN tables
15051511
USING (catalog_name, schema_name)
1506-
WHERE schema_name LIKE '%s'
1512+
WHERE schema_name LIKE %s
15071513
)
15081514
15091515
SELECT
@@ -1516,7 +1522,7 @@ AdbcStatusCode ConnectionGetObjects(struct AdbcConnection *connection, int depth
15161522
information_schema.schemata
15171523
LEFT JOIN db_schemas dbs
15181524
USING (catalog_name, schema_name)
1519-
WHERE catalog_name LIKE '%s'
1525+
WHERE catalog_name LIKE %s
15201526
GROUP BY catalog_name
15211527
)",
15221528
table_name_filter, table_type_condition, db_schema_filter, catalog_filter);
@@ -1551,7 +1557,7 @@ AdbcStatusCode ConnectionGetObjects(struct AdbcConnection *connection, int depth
15511557
xdbc_is_generatedcolumn: NULL::BOOLEAN,
15521558
}) table_columns
15531559
FROM information_schema.columns
1554-
WHERE column_name LIKE '%s'
1560+
WHERE column_name LIKE %s
15551561
GROUP BY table_catalog, table_schema, table_name
15561562
),
15571563
constraints AS (
@@ -1580,7 +1586,7 @@ AdbcStatusCode ConnectionGetObjects(struct AdbcConnection *connection, int depth
15801586
constraint_column_names,
15811587
list_filter(
15821588
constraint_column_names,
1583-
lambda name: name LIKE '%s'
1589+
lambda name: name LIKE %s
15841590
)
15851591
)
15861592
GROUP BY database_name, schema_name, table_name
@@ -1600,7 +1606,7 @@ AdbcStatusCode ConnectionGetObjects(struct AdbcConnection *connection, int depth
16001606
USING (table_catalog, table_schema, table_name)
16011607
LEFT JOIN constraints
16021608
USING (table_catalog, table_schema, table_name)
1603-
WHERE table_name LIKE '%s'%s
1609+
WHERE table_name LIKE %s%s
16041610
GROUP BY table_catalog, table_schema
16051611
),
16061612
db_schemas AS (
@@ -1611,7 +1617,7 @@ AdbcStatusCode ConnectionGetObjects(struct AdbcConnection *connection, int depth
16111617
FROM information_schema.schemata
16121618
LEFT JOIN tables
16131619
USING (catalog_name, schema_name)
1614-
WHERE schema_name LIKE '%s'
1620+
WHERE schema_name LIKE %s
16151621
)
16161622
16171623
SELECT
@@ -1624,7 +1630,7 @@ AdbcStatusCode ConnectionGetObjects(struct AdbcConnection *connection, int depth
16241630
information_schema.schemata
16251631
LEFT JOIN db_schemas dbs
16261632
USING (catalog_name, schema_name)
1627-
WHERE catalog_name LIKE '%s'
1633+
WHERE catalog_name LIKE %s
16281634
GROUP BY catalog_name
16291635
)",
16301636
column_name_filter, column_name_filter, table_name_filter,

src/duckdb/src/common/arrow/schema_metadata.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,21 +97,21 @@ unsafe_unique_array<char> ArrowSchemaMetadata::SerializeMetadata() const {
9797
auto metadata_array_ptr = make_unsafe_uniq_array<char>(total_size);
9898
auto metadata_ptr = metadata_array_ptr.get();
9999
// 1. number of key-value pairs (int32)
100-
const idx_t map_size = schema_metadata_map.size();
100+
const int32_t map_size = static_cast<int32_t>(schema_metadata_map.size());
101101
memcpy(metadata_ptr, &map_size, sizeof(int32_t));
102102
metadata_ptr += sizeof(int32_t);
103103
// Iterate through each key-value pair in the map
104104
for (const auto &pair : schema_metadata_map) {
105105
const std::string &key = pair.first;
106-
idx_t key_size = key.size();
106+
int32_t key_size = static_cast<int32_t>(key.size());
107107
// Length of the key (int32)
108108
memcpy(metadata_ptr, &key_size, sizeof(int32_t));
109109
metadata_ptr += sizeof(int32_t);
110110
// Key
111111
memcpy(metadata_ptr, key.c_str(), key_size);
112112
metadata_ptr += key_size;
113113
const std::string &value = pair.second;
114-
const idx_t value_size = value.size();
114+
const int32_t value_size = static_cast<int32_t>(value.size());
115115
// Length of the value (int32)
116116
memcpy(metadata_ptr, &value_size, sizeof(int32_t));
117117
metadata_ptr += sizeof(int32_t);

src/duckdb/src/common/enum_util.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3029,6 +3029,7 @@ const StringUtil::EnumStringLiteral *GetMetricTypeValues() {
30293029
{ static_cast<uint32_t>(MetricType::OPTIMIZER_CTE_INLINING), "OPTIMIZER_CTE_INLINING" },
30303030
{ static_cast<uint32_t>(MetricType::OPTIMIZER_COMMON_SUBPLAN), "OPTIMIZER_COMMON_SUBPLAN" },
30313031
{ static_cast<uint32_t>(MetricType::OPTIMIZER_JOIN_ELIMINATION), "OPTIMIZER_JOIN_ELIMINATION" },
3032+
{ static_cast<uint32_t>(MetricType::OPTIMIZER_COUNT_WINDOW_ELIMINATION), "OPTIMIZER_COUNT_WINDOW_ELIMINATION" },
30323033
{ static_cast<uint32_t>(MetricType::ALL_OPTIMIZERS), "ALL_OPTIMIZERS" },
30333034
{ static_cast<uint32_t>(MetricType::CUMULATIVE_OPTIMIZER_TIMING), "CUMULATIVE_OPTIMIZER_TIMING" },
30343035
{ static_cast<uint32_t>(MetricType::PHYSICAL_PLANNER), "PHYSICAL_PLANNER" },
@@ -3043,12 +3044,12 @@ const StringUtil::EnumStringLiteral *GetMetricTypeValues() {
30433044

30443045
template<>
30453046
const char* EnumUtil::ToChars<MetricType>(MetricType value) {
3046-
return StringUtil::EnumToString(GetMetricTypeValues(), 66, "MetricType", static_cast<uint32_t>(value));
3047+
return StringUtil::EnumToString(GetMetricTypeValues(), 67, "MetricType", static_cast<uint32_t>(value));
30473048
}
30483049

30493050
template<>
30503051
MetricType EnumUtil::FromString<MetricType>(const char *value) {
3051-
return static_cast<MetricType>(StringUtil::StringToEnum(GetMetricTypeValues(), 66, "MetricType", value));
3052+
return static_cast<MetricType>(StringUtil::StringToEnum(GetMetricTypeValues(), 67, "MetricType", value));
30523053
}
30533054

30543055
const StringUtil::EnumStringLiteral *GetMultiFileColumnMappingModeValues() {
@@ -3284,19 +3285,20 @@ const StringUtil::EnumStringLiteral *GetOptimizerTypeValues() {
32843285
{ static_cast<uint32_t>(OptimizerType::LATE_MATERIALIZATION), "LATE_MATERIALIZATION" },
32853286
{ static_cast<uint32_t>(OptimizerType::CTE_INLINING), "CTE_INLINING" },
32863287
{ static_cast<uint32_t>(OptimizerType::COMMON_SUBPLAN), "COMMON_SUBPLAN" },
3287-
{ static_cast<uint32_t>(OptimizerType::JOIN_ELIMINATION), "JOIN_ELIMINATION" }
3288+
{ static_cast<uint32_t>(OptimizerType::JOIN_ELIMINATION), "JOIN_ELIMINATION" },
3289+
{ static_cast<uint32_t>(OptimizerType::COUNT_WINDOW_ELIMINATION), "COUNT_WINDOW_ELIMINATION" }
32883290
};
32893291
return values;
32903292
}
32913293

32923294
template<>
32933295
const char* EnumUtil::ToChars<OptimizerType>(OptimizerType value) {
3294-
return StringUtil::EnumToString(GetOptimizerTypeValues(), 33, "OptimizerType", static_cast<uint32_t>(value));
3296+
return StringUtil::EnumToString(GetOptimizerTypeValues(), 34, "OptimizerType", static_cast<uint32_t>(value));
32953297
}
32963298

32973299
template<>
32983300
OptimizerType EnumUtil::FromString<OptimizerType>(const char *value) {
3299-
return static_cast<OptimizerType>(StringUtil::StringToEnum(GetOptimizerTypeValues(), 33, "OptimizerType", value));
3301+
return static_cast<OptimizerType>(StringUtil::StringToEnum(GetOptimizerTypeValues(), 34, "OptimizerType", value));
33003302
}
33013303

33023304
const StringUtil::EnumStringLiteral *GetOrderByNullTypeValues() {

src/duckdb/src/common/enums/optimizer_type.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ static const DefaultOptimizerType internal_optimizer_types[] = {
4545
{"cte_inlining", OptimizerType::CTE_INLINING},
4646
{"common_subplan", OptimizerType::COMMON_SUBPLAN},
4747
{"join_elimination", OptimizerType::JOIN_ELIMINATION},
48+
{"count_window_elimination", OptimizerType::COUNT_WINDOW_ELIMINATION},
4849
{nullptr, OptimizerType::INVALID}};
4950

5051
string OptimizerTypeToString(OptimizerType type) {

src/duckdb/src/common/types/geometry.cpp

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ class BlobWriter {
1616
public:
1717
template <class T>
1818
void Write(const T &value) {
19-
auto ptr = reinterpret_cast<const char *>(&value);
19+
auto le_value = BSwapIfBE(value);
20+
auto ptr = reinterpret_cast<const char *>(&le_value);
2021
buffer.insert(buffer.end(), ptr, ptr + sizeof(T));
2122
}
2223

@@ -38,16 +39,12 @@ class BlobWriter {
3839
if (reserved.offset + sizeof(T) > buffer.size()) {
3940
throw InternalException("Write out of bounds in BinaryWriter");
4041
}
41-
auto ptr = reinterpret_cast<const char *>(&reserved.value);
42+
auto le_value = BSwapIfBE(reserved.value);
43+
auto ptr = reinterpret_cast<const char *>(&le_value);
4244
// We've reserved 0 bytes, so we can safely memcpy
4345
memcpy(buffer.data() + reserved.offset, ptr, sizeof(T));
4446
}
4547

46-
void Write(const char *data, size_t size) {
47-
D_ASSERT(data != nullptr);
48-
buffer.insert(buffer.end(), data, data + size);
49-
}
50-
5148
const vector<char> &GetBuffer() const {
5249
return buffer;
5350
}
@@ -70,18 +67,11 @@ class FixedSizeBlobWriter {
7067
if (pos + sizeof(T) > end) {
7168
throw InvalidInputException("Writing beyond end of binary data at position %zu", pos - beg);
7269
}
73-
memcpy(pos, &value, sizeof(T));
70+
auto le_value = BSwapIfBE(value);
71+
memcpy(pos, &le_value, sizeof(T));
7472
pos += sizeof(T);
7573
}
7674

77-
void Write(const char *data, size_t size) {
78-
if (pos + size > end) {
79-
throw InvalidInputException("Writing beyond end of binary data at position %zu", pos - beg);
80-
}
81-
memcpy(pos, data, size);
82-
pos += size;
83-
}
84-
8575
size_t GetPosition() const {
8676
return static_cast<idx_t>(pos - beg);
8777
}
@@ -112,17 +102,9 @@ class BlobReader {
112102
throw InvalidInputException("Unexpected end of binary data at position %zu", pos - beg);
113103
}
114104
T value;
115-
if (LE) {
116-
memcpy(&value, pos, sizeof(T));
117-
pos += sizeof(T);
118-
} else {
119-
char temp[sizeof(T)];
120-
for (size_t i = 0; i < sizeof(T); ++i) {
121-
temp[i] = pos[sizeof(T) - 1 - i];
122-
}
123-
memcpy(&value, temp, sizeof(T));
124-
pos += sizeof(T);
125-
}
105+
memcpy(&value, pos, sizeof(T));
106+
value = LE ? BSwapIfBE(value) : BSwapIfLE(value);
107+
pos += sizeof(T);
126108
return value;
127109
}
128110

@@ -1060,9 +1042,20 @@ static uint32_t ParseVerticesInternal(BlobReader &reader, GeometryExtent &extent
10601042

10611043
// Issue a single .Reserve() for all vertices, to minimize bounds checking overhead
10621044
const auto ptr = const_data_ptr_cast(reader.Reserve(vert_count * sizeof(VERTEX_TYPE)));
1063-
1045+
#if DUCKDB_IS_BIG_ENDIAN
1046+
double be_buffer[sizeof(VERTEX_TYPE)];
1047+
auto be_ptr = reinterpret_cast<const_data_ptr_t>(be_buffer);
1048+
#endif
10641049
for (uint32_t vert_idx = 0; vert_idx < vert_count; vert_idx++) {
1050+
#if DUCKDB_IS_BIG_ENDIAN
1051+
auto vert_ofs = vert_idx * sizeof(VERTEX_TYPE);
1052+
for (idx_t i = 0; i < sizeof(VERTEX_TYPE) / sizeof(double); ++i) {
1053+
be_buffer[i] = LoadLE<double>(ptr + vert_ofs + i * sizeof(double));
1054+
}
1055+
VERTEX_TYPE vertex = Load<VERTEX_TYPE>(be_ptr);
1056+
#else
10651057
VERTEX_TYPE vertex = Load<VERTEX_TYPE>(ptr + vert_idx * sizeof(VERTEX_TYPE));
1058+
#endif
10661059
if (check_nan && vertex.AllNan()) {
10671060
continue;
10681061
}

src/duckdb/src/common/types/hash.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ hash_t HashBytes(const_data_ptr_t ptr, const idx_t len) noexcept {
8484
// Hash/combine in blocks of 8 bytes
8585
const auto remainder = len & 7U;
8686
for (const auto end = ptr + len - remainder; ptr != end; ptr += 8U) {
87-
h ^= Load<hash_t>(ptr);
87+
h ^= LoadLE<hash_t>(ptr);
8888
h *= 0xd6e8feb86659fd93U;
8989
}
9090

@@ -93,14 +93,15 @@ hash_t HashBytes(const_data_ptr_t ptr, const idx_t len) noexcept {
9393
D_ASSERT(len >= 8);
9494
// Load remaining (<8) bytes (with a Load instead of a memcpy)
9595
const auto inv_rem = 8U - remainder;
96-
const auto hr = Load<hash_t>(ptr - inv_rem) >> (inv_rem * 8U);
96+
const auto hr = LoadLE<hash_t>(ptr - inv_rem) >> (inv_rem * 8U);
9797

9898
h ^= hr;
9999
h *= 0xd6e8feb86659fd93U;
100100
} else {
101101
// Load remaining (<8) bytes (with a memcpy)
102102
hash_t hr = 0;
103103
memcpy(&hr, ptr, remainder);
104+
hr = BSwapIfBE(hr);
104105

105106
h ^= hr;
106107
h *= 0xd6e8feb86659fd93U;
@@ -122,14 +123,15 @@ hash_t Hash(string_t val) {
122123

123124
// Hash/combine the first 8-byte block
124125
if (!val.Empty()) {
125-
h ^= Load<hash_t>(const_data_ptr_cast(val.GetPrefix()));
126+
h ^= LoadLE<hash_t>(const_data_ptr_cast(val.GetPrefix()));
126127
h *= 0xd6e8feb86659fd93U;
127128
}
128129

129130
// Load remaining 4 bytes
130131
if (val.GetSize() > sizeof(hash_t)) {
131132
hash_t hr = 0;
132133
memcpy(&hr, const_data_ptr_cast(val.GetPrefix()) + sizeof(hash_t), 4U);
134+
hr = BSwapIfBE(hr);
133135

134136
h ^= hr;
135137
h *= 0xd6e8feb86659fd93U;

0 commit comments

Comments
 (0)