Skip to content

Commit 920f177

Browse files
Update vendored DuckDB sources to 23a8774245
1 parent 9d72938 commit 920f177

29 files changed

Lines changed: 563 additions & 246 deletions

File tree

src/duckdb/extension/core_functions/scalar/generic/type_functions.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ static void GetTypeFunction(DataChunk &args, ExpressionState &state, Vector &res
4444
result.Reference(v);
4545
}
4646

47+
static unique_ptr<FunctionData> BindGetTypeFunction(ClientContext &context, ScalarFunction &bound_function,
48+
vector<unique_ptr<Expression>> &arguments) {
49+
if (arguments[0]->HasParameter()) {
50+
throw ParameterNotResolvedException();
51+
}
52+
bound_function.arguments[0] = arguments[0]->return_type;
53+
return nullptr;
54+
}
55+
4756
static unique_ptr<Expression> BindGetTypeFunctionExpression(FunctionBindExpressionInput &input) {
4857
auto &return_type = input.children[0]->return_type;
4958
if (return_type.id() == LogicalTypeId::UNKNOWN || return_type.id() == LogicalTypeId::SQLNULL) {
@@ -55,7 +64,7 @@ static unique_ptr<Expression> BindGetTypeFunctionExpression(FunctionBindExpressi
5564
}
5665

5766
ScalarFunction GetTypeFun::GetFunction() {
58-
auto fun = ScalarFunction({LogicalType::ANY}, LogicalType::VARCHAR, GetTypeFunction);
67+
auto fun = ScalarFunction({LogicalType::ANY}, LogicalType::TYPE(), GetTypeFunction, BindGetTypeFunction);
5968
fun.SetNullHandling(FunctionNullHandling::SPECIAL_HANDLING);
6069
fun.SetBindExpressionCallback(BindGetTypeFunctionExpression);
6170
return fun;

src/duckdb/extension/parquet/parquet_statistics.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,11 @@ static bool ConvertShreddedStatsItem(BaseStatistics &result, BaseStatistics &inp
354354
D_ASSERT(result.GetType().id() == LogicalTypeId::STRUCT);
355355
D_ASSERT(input.GetType().id() == LogicalTypeId::STRUCT);
356356

357-
auto &untyped_value_index_stats = StructStats::GetChildStats(result, 0);
358-
auto &typed_value_result = StructStats::GetChildStats(result, 1);
357+
// result variant stats
358+
auto &untyped_value_index_stats = StructStats::GetChildStats(result, VariantStats::UNTYPED_VALUE_INDEX);
359+
auto &typed_value_result = StructStats::GetChildStats(result, VariantStats::TYPED_VALUE_INDEX);
359360

361+
// input parquet stats
360362
auto &value_stats = StructStats::GetChildStats(input, 0);
361363
auto &typed_value_input = StructStats::GetChildStats(input, 1);
362364

@@ -441,14 +443,14 @@ unique_ptr<BaseStatistics> ParquetStatisticsUtils::TransformColumnStatistics(con
441443
return nullptr;
442444
}
443445
auto shredding_type = TypeVisitor::VisitReplace(logical_type, [](const LogicalType &type) {
444-
return LogicalType::STRUCT({{"untyped_value_index", LogicalType::UINTEGER}, {"typed_value", type}});
446+
return LogicalType::STRUCT({{"typed_value", type}, {"untyped_value_index", LogicalType::UINTEGER}});
445447
});
446448
auto variant_stats = VariantStats::CreateShredded(shredding_type);
447449

448450
//! Take the root stats
449451
auto &shredded_stats = VariantStats::GetShreddedStats(variant_stats);
450-
auto &untyped_value_index_stats = StructStats::GetChildStats(shredded_stats, 0);
451-
auto &typed_value_stats = StructStats::GetChildStats(shredded_stats, 1);
452+
auto &untyped_value_index_stats = StructStats::GetChildStats(shredded_stats, VariantStats::UNTYPED_VALUE_INDEX);
453+
auto &typed_value_stats = StructStats::GetChildStats(shredded_stats, VariantStats::TYPED_VALUE_INDEX);
452454

453455
//! Convert the root 'value' -> 'untyped_value_index'
454456
auto &value = schema.children[1];

src/duckdb/extension/parquet/writer/variant/convert_variant.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,18 @@ struct ParquetVariantShreddingState : public VariantShreddingState {
163163
};
164164

165165
struct ParquetVariantShredding : public VariantShredding {
166+
ParquetVariantShredding() {
167+
// for parquet untyped ("value") comes before typed ("typed_value")
168+
untyped_value_index = 0;
169+
typed_value_index = 1;
170+
}
171+
166172
void WriteVariantValues(UnifiedVariantVectorData &variant, Vector &result, optional_ptr<const SelectionVector> sel,
167173
optional_ptr<const SelectionVector> value_index_sel,
168174
optional_ptr<const SelectionVector> result_sel, idx_t count) override;
175+
176+
protected:
177+
void WriteMissingField(Vector &vector, idx_t index) override;
169178
};
170179

171180
} // namespace
@@ -729,6 +738,11 @@ static void CreateValues(UnifiedVariantVectorData &variant, Vector &value, optio
729738
}
730739
}
731740

741+
void ParquetVariantShredding::WriteMissingField(Vector &vector, idx_t index) {
742+
//! The field is missing, set it to null
743+
FlatVector::SetNull(vector, index, true);
744+
}
745+
732746
void ParquetVariantShredding::WriteVariantValues(UnifiedVariantVectorData &variant, Vector &result,
733747
optional_ptr<const SelectionVector> sel,
734748
optional_ptr<const SelectionVector> value_index_sel,

src/duckdb/src/common/error_data.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ void ErrorData::Merge(const ErrorData &other) {
102102
*this = other;
103103
return;
104104
}
105+
if (Exception::InvalidatesDatabase(other.Type()) || other.type == ExceptionType::INTERNAL) {
106+
// inherit severe types
107+
type = other.type;
108+
}
105109
final_message += "\n\n" + other.Message();
106110
}
107111

src/duckdb/src/common/types/variant/variant_value.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,17 @@ namespace duckdb {
2222

2323
void VariantValue::AddChild(const string &key, VariantValue &&val) {
2424
D_ASSERT(value_type == VariantValueType::OBJECT);
25+
if (val.IsMissing()) {
26+
throw InternalException("Adding a missing value to an object");
27+
}
2528
object_children.emplace(key, std::move(val));
2629
}
2730

2831
void VariantValue::AddItem(VariantValue &&val) {
2932
D_ASSERT(value_type == VariantValueType::ARRAY);
33+
if (val.IsMissing()) {
34+
throw InternalException("Adding a missing value to an array");
35+
}
3036
array_items.push_back(std::move(val));
3137
}
3238

@@ -216,6 +222,8 @@ static void AnalyzeValue(const VariantValue &value, idx_t row, DataChunk &offset
216222
}
217223
break;
218224
}
225+
case VariantValueType::MISSING:
226+
throw InternalException("Unexpected MISSING value in Variant AnalyzeValue");
219227
default:
220228
throw InternalException("VariantValueType not handled");
221229
}

src/duckdb/src/function/cast/variant/from_variant.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ struct VariantBooleanConversion {
7474
static bool Convert(const VariantLogicalType type_id, uint32_t byte_offset, const_data_ptr_t value, bool &ret,
7575
const EmptyConversionPayloadFromVariant &payload, string &error) {
7676
if (type_id != VariantLogicalType::BOOL_FALSE && type_id != VariantLogicalType::BOOL_TRUE) {
77-
error = StringUtil::Format("Can't convert from VARIANT(%s)", EnumUtil::ToString(type_id));
77+
if (error.empty()) {
78+
error = StringUtil::Format("Can't convert from VARIANT(%s)", EnumUtil::ToString(type_id));
79+
}
7880
return false;
7981
}
8082
ret = type_id == VariantLogicalType::BOOL_TRUE;
@@ -89,7 +91,9 @@ struct VariantDirectConversion {
8991
static bool Convert(const VariantLogicalType type_id, uint32_t byte_offset, const_data_ptr_t value, T &ret,
9092
const EmptyConversionPayloadFromVariant &payload, string &error) {
9193
if (type_id != TYPE_ID) {
92-
error = StringUtil::Format("Can't convert from VARIANT(%s)", EnumUtil::ToString(type_id));
94+
if (error.empty()) {
95+
error = StringUtil::Format("Can't convert from VARIANT(%s)", EnumUtil::ToString(type_id));
96+
}
9397
return false;
9498
}
9599
ret = Load<T>(value + byte_offset);
@@ -99,7 +103,9 @@ struct VariantDirectConversion {
99103
static bool Convert(const VariantLogicalType type_id, uint32_t byte_offset, const_data_ptr_t value, T &ret,
100104
const StringConversionPayload &payload, string &error) {
101105
if (type_id != TYPE_ID) {
102-
error = StringUtil::Format("Can't convert from VARIANT(%s)", EnumUtil::ToString(type_id));
106+
if (error.empty()) {
107+
error = StringUtil::Format("Can't convert from VARIANT(%s)", EnumUtil::ToString(type_id));
108+
}
103109
return false;
104110
}
105111
auto ptr = value + byte_offset;
@@ -117,7 +123,9 @@ struct VariantDecimalConversion {
117123
static bool Convert(const VariantLogicalType type_id, uint32_t byte_offset, const_data_ptr_t value, T &ret,
118124
const DecimalConversionPayloadFromVariant &payload, string &error) {
119125
if (type_id != TYPE_ID) {
120-
error = StringUtil::Format("Can't convert from VARIANT(%s)", EnumUtil::ToString(type_id));
126+
if (error.empty()) {
127+
error = StringUtil::Format("Can't convert from VARIANT(%s)", EnumUtil::ToString(type_id));
128+
}
121129
return false;
122130
}
123131
auto ptr = value + byte_offset;

src/duckdb/src/function/scalar/geometry/geometry_functions.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ static unique_ptr<Expression> BindCRSFunctionExpression(FunctionBindExpressionIn
9191

9292
static unique_ptr<FunctionData> BindCRSFunction(ClientContext &context, ScalarFunction &bound_function,
9393
vector<unique_ptr<Expression>> &arguments) {
94+
if (arguments[0]->HasParameter() || arguments[0]->return_type.id() == LogicalTypeId::SQLNULL) {
95+
// parameter - unknown return type
96+
return nullptr;
97+
}
98+
9499
// Check if the CRS is set in the first argument
95100
bound_function.arguments[0] = arguments[0]->return_type;
96101
return nullptr;

src/duckdb/src/function/table/version/pragma_version.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#ifndef DUCKDB_PATCH_VERSION
2-
#define DUCKDB_PATCH_VERSION "0-dev7183"
2+
#define DUCKDB_PATCH_VERSION "0-dev7214"
33
#endif
44
#ifndef DUCKDB_MINOR_VERSION
55
#define DUCKDB_MINOR_VERSION 5
@@ -8,10 +8,10 @@
88
#define DUCKDB_MAJOR_VERSION 1
99
#endif
1010
#ifndef DUCKDB_VERSION
11-
#define DUCKDB_VERSION "v1.5.0-dev7183"
11+
#define DUCKDB_VERSION "v1.5.0-dev7214"
1212
#endif
1313
#ifndef DUCKDB_SOURCE_ID
14-
#define DUCKDB_SOURCE_ID "862439822d"
14+
#define DUCKDB_SOURCE_ID "23a8774245"
1515
#endif
1616
#include "duckdb/function/table/system_functions.hpp"
1717
#include "duckdb/main/database.hpp"

src/duckdb/src/function/variant/variant_shredding.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ void VariantShredding::WriteTypedPrimitiveValues(UnifiedVariantVectorData &varia
156156
}
157157
}
158158

159+
void VariantShredding::WriteMissingField(Vector &vector, idx_t index) {
160+
FlatVector::GetData<uint32_t>(vector)[index] = 0;
161+
}
162+
159163
void VariantShredding::WriteTypedObjectValues(UnifiedVariantVectorData &variant, Vector &result,
160164
const SelectionVector &sel, const SelectionVector &value_index_sel,
161165
const SelectionVector &result_sel, idx_t count) {
@@ -209,10 +213,10 @@ void VariantShredding::WriteTypedObjectValues(UnifiedVariantVectorData &variant,
209213
idx_t child_count = 0;
210214
for (idx_t i = 0; i < count; i++) {
211215
if (!lookup_validity.RowIsValid(i)) {
212-
//! The field is missing, set it to null
213-
FlatVector::SetNull(*child_variant_vectors[0], result_sel[i], true);
216+
//! The field is missing, set the untyped value index to 0
217+
WriteMissingField(*child_variant_vectors[untyped_value_index], result_sel[i]);
214218
if (child_variant_vectors.size() >= 2) {
215-
FlatVector::SetNull(*child_variant_vectors[1], result_sel[i], true);
219+
FlatVector::SetNull(*child_variant_vectors[typed_value_index], result_sel[i], true);
216220
}
217221
continue;
218222
}

src/duckdb/src/include/duckdb/function/variant/variant_shredding.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,14 @@ struct VariantShredding {
7575
optional_ptr<const SelectionVector> value_index_sel,
7676
optional_ptr<const SelectionVector> result_sel, idx_t count) = 0;
7777

78+
protected:
79+
idx_t typed_value_index = VariantStats::TYPED_VALUE_INDEX;
80+
idx_t untyped_value_index = VariantStats::UNTYPED_VALUE_INDEX;
81+
7882
protected:
7983
void WriteTypedValues(UnifiedVariantVectorData &variant, Vector &result, const SelectionVector &sel,
8084
const SelectionVector &value_index_sel, const SelectionVector &result_sel, idx_t count);
85+
virtual void WriteMissingField(Vector &vector, idx_t index);
8186

8287
private:
8388
void WriteTypedObjectValues(UnifiedVariantVectorData &variant, Vector &result, const SelectionVector &sel,

0 commit comments

Comments
 (0)