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
17 changes: 17 additions & 0 deletions src/duckdb/extension/parquet/parquet_statistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,16 @@ static unique_ptr<BaseStatistics> CreateFloatingPointStats(const LogicalType &ty
return stats.ToUnique();
}

//! Whether every non-NULL value of the column chunk is NaN, according to its nan_count and null_count
static bool AllValuesAreNaN(const duckdb_parquet::Statistics &parquet_stats,
optional_ptr<const ColumnChunk> column_chunk) {
if (!column_chunk || !parquet_stats.__isset.nan_count || !parquet_stats.__isset.null_count) {
return false;
}
const auto nan_count = parquet_stats.nan_count;
return nan_count > 0 && nan_count == column_chunk->meta_data.num_values - parquet_stats.null_count;
}

bool ParquetStatisticsUtils::CanHaveNaN(const duckdb_parquet::Statistics &parquet_stats, bool can_have_nan) {
if (parquet_stats.__isset.nan_count) {
return parquet_stats.nan_count != 0;
Expand Down Expand Up @@ -570,6 +580,13 @@ unique_ptr<BaseStatistics> ParquetStatisticsUtils::TransformParquetStatistics(
return CreateNumericStats(type, schema, parquet_stats);
case LogicalTypeId::FLOAT:
case LogicalTypeId::DOUBLE:
if (AllValuesAreNaN(parquet_stats, column_chunk)) {
auto nan_stats = NumericStats::CreateUnknown(type);
auto nan_value = Value("nan").DefaultCastAs(type);
NumericStats::SetMin(nan_stats, nan_value);
NumericStats::SetMax(nan_stats, nan_value);
return nan_stats.ToUnique();
}
if (CanHaveNaN(parquet_stats, can_have_nan)) {
// The column can contain NaN values - create stats without an upper max value, as NaN compares larger than
// anything else and is not included in the Parquet min/max
Expand Down
8 changes: 4 additions & 4 deletions src/duckdb/generated_extension_loader_package_build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ int32_t duckdb_extension_core_functions_describe(duckdb_extension_descriptor *de
descriptor->version = 1;
descriptor->name = "core_functions";
descriptor->extension_version = EXT_VERSION_CORE_FUNCTIONS;
descriptor->api_version = "v2.1.0-alpha57135";
descriptor->api_version = "v2.1.0-alpha57181";
descriptor->entry_cpp = (void (*)(void))core_functions_duckdb_cpp_init;
return 0;
}
Expand Down Expand Up @@ -78,7 +78,7 @@ int32_t duckdb_extension_parquet_describe(duckdb_extension_descriptor *descripto
descriptor->version = 1;
descriptor->name = "parquet";
descriptor->extension_version = EXT_VERSION_PARQUET;
descriptor->api_version = "v2.1.0-alpha57135";
descriptor->api_version = "v2.1.0-alpha57181";
descriptor->entry_cpp = (void (*)(void))parquet_duckdb_cpp_init;
return 0;
}
Expand Down Expand Up @@ -111,7 +111,7 @@ int32_t duckdb_extension_icu_describe(duckdb_extension_descriptor *descriptor) {
descriptor->version = 1;
descriptor->name = "icu";
descriptor->extension_version = EXT_VERSION_ICU;
descriptor->api_version = "v2.1.0-alpha57135";
descriptor->api_version = "v2.1.0-alpha57181";
descriptor->entry_cpp = (void (*)(void))icu_duckdb_cpp_init;
return 0;
}
Expand Down Expand Up @@ -144,7 +144,7 @@ int32_t duckdb_extension_json_describe(duckdb_extension_descriptor *descriptor)
descriptor->version = 1;
descriptor->name = "json";
descriptor->extension_version = EXT_VERSION_JSON;
descriptor->api_version = "v2.1.0-alpha57135";
descriptor->api_version = "v2.1.0-alpha57181";
descriptor->entry_cpp = (void (*)(void))json_duckdb_cpp_init;
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/duckdb/src/catalog/catalog_entry/duck_table_entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1486,7 +1486,7 @@ void DuckTableEntry::CommitAlter(string &column_name, CommitDropState &drop_stat
}

void DuckTableEntry::CommitDrop(CommitDropState &drop_state) {
storage->CommitDropTable(drop_state);
drop_state.DropTable(storage);
}

DataTable &DuckTableEntry::GetStorage() {
Expand Down
8 changes: 6 additions & 2 deletions src/duckdb/src/common/row_operations/row_aggregate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,12 @@ void RowOperations::UpdateFilteredStates(RowOperationsState &state, AggregateFil
return;
}

Vector filtered_addresses(addresses, filter_data.true_sel, count);
filtered_addresses.Flatten();
if (!state.addresses) {
state.addresses = make_uniq<Vector>(LogicalType::POINTER);
}
auto &filtered_addresses = *state.addresses;
VectorOperations::Copy(addresses, filtered_addresses, filter_data.true_sel, count, 0, 0);
FlatVector::SetSize(filtered_addresses, count_t(count));

UpdateStates(state, aggr, filtered_addresses, filter_data.filtered_payload, arg_idx);
}
Expand Down
1 change: 1 addition & 0 deletions src/duckdb/src/common/types/vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ void Vector::ToUnifiedFormat(idx_t count, UnifiedVectorFormat &format) const {

void Vector::ToUnifiedFormat(UnifiedVectorFormat &format) const {
format.physical_type = GetType().InternalType();
format.owned_sel = SelectionVector();
auto vtype = GetVectorType();
if (vtype != VectorType::FLAT_VECTOR && vtype != VectorType::CONSTANT_VECTOR &&
vtype != VectorType::DICTIONARY_VECTOR) {
Expand Down
2 changes: 1 addition & 1 deletion src/duckdb/src/common/vector/array_vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ void VectorArrayBuffer::ToUnifiedFormat(UnifiedVectorFormat &format) const {
format.sel = FlatVector::IncrementalSelectionVector();
}
format.data = nullptr;
format.validity = validity;
format.validity.Initialize(validity.GetData(), validity.Capacity());
}

void VectorArrayBuffer::CopyInternal(const Vector &source, const SelectionVector &source_sel, idx_t source_count,
Expand Down
6 changes: 3 additions & 3 deletions src/duckdb/src/common/vector/dictionary_vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,16 @@ void DictionaryBuffer::VerifyInternal(const LogicalType &type, const SelectionVe
}

void DictionaryBuffer::ToUnifiedFormat(UnifiedVectorFormat &format) const {
format.owned_sel.Initialize(sel_vector);
format.sel = &format.owned_sel;
format.sel = &sel_vector;

auto &child = entry->data;
if (child.GetVectorType() != VectorType::FLAT_VECTOR) {
// flatten the child in-place
entry->data.Flatten();
}
format.data = FlatVector::GetData(entry->data);
format.validity = FlatVector::Validity(entry->data);
const auto &validity = FlatVector::Validity(entry->data);
format.validity.Initialize(validity.GetData(), validity.Capacity());
}

buffer_ptr<VectorBuffer> DictionaryBuffer::SliceWithCache(SelCache &cache, const LogicalType &type,
Expand Down
2 changes: 1 addition & 1 deletion src/duckdb/src/common/vector/flat_vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ void StandardVectorBuffer::ToUnifiedFormat(UnifiedVectorFormat &format) const {
format.sel = FlatVector::IncrementalSelectionVector();
}
format.data = data_ptr;
format.validity = validity;
format.validity.Initialize(validity.GetData(), validity.Capacity());
}

template <idx_t TYPE_SIZE>
Expand Down
2 changes: 1 addition & 1 deletion src/duckdb/src/common/vector/list_vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ void VectorListBuffer::ToUnifiedFormat(UnifiedVectorFormat &format) const {
format.sel = FlatVector::IncrementalSelectionVector();
}
format.data = data_ptr;
format.validity = validity;
format.validity.Initialize(validity.GetData(), validity.Capacity());
}

buffer_ptr<VectorBuffer> VectorListBuffer::CreateBuffer(AllocatedData &&new_data, count_t count) const {
Expand Down
2 changes: 1 addition & 1 deletion src/duckdb/src/common/vector/struct_vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ void VectorStructBuffer::ToUnifiedFormat(UnifiedVectorFormat &format) const {
format.sel = FlatVector::IncrementalSelectionVector();
}
format.data = nullptr;
format.validity = validity;
format.validity.Initialize(validity.GetData(), validity.Capacity());
}

void VectorStructBuffer::SetValue(const LogicalType &type, idx_t index, const Value &val) {
Expand Down
15 changes: 9 additions & 6 deletions src/duckdb/src/common/vector_operations/scalar_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,21 @@ void ScalarExecutor::PrepareConstantResult(Vector &result) {
FlatVector::ValidityMutable(result).SetValid(0);
}

bool ScalarExecutor::PrepareGenericResultValidity(const UnifiedVectorFormat *formats, idx_t format_count,
Vector &result, idx_t count, bool preserve_result_validity,
bool adds_nulls) {
bool ScalarExecutor::PrepareGenericResultValidity(UnifiedVectorFormat *formats, idx_t format_count, Vector &result,
idx_t count, bool preserve_result_validity, bool adds_nulls) {
auto &result_validity = FlatVector::ValidityMutable(result);
bool inputs_can_have_null = false;
for (idx_t input_idx = 0; input_idx < format_count; input_idx++) {
if (formats[input_idx].validity.CanHaveNull()) {
auto &input_validity = formats[input_idx].validity;
if (input_validity.CanHaveNull()) {
inputs_can_have_null = true;
break;
if (input_validity.GetData() == result_validity.GetData()) {
// Keep aliased input validity alive when resetting the result below.
input_validity.Initialize(result_validity);
}
}
}

auto &result_validity = FlatVector::ValidityMutable(result);
if (inputs_can_have_null || !preserve_result_validity) {
result_validity.Reset(count);
} else if (adds_nulls && result_validity.CanHaveNull()) {
Expand Down
39 changes: 23 additions & 16 deletions src/duckdb/src/common/vector_operations/vector_hash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,24 @@ void TightLoopHash(const T *__restrict ldata, hash_t *__restrict result_data, co

template <bool HAS_RSEL, class T, bool INPUT_IS_ALREADY_HASH = false>
void TemplatedLoopHash(const Vector &input, Vector &result, const SelectionVector *rsel, idx_t count) {
if (input.GetVectorType() == VectorType::CONSTANT_VECTOR) {
const auto &source = INPUT_IS_ALREADY_HASH ? DictionaryVector::GetCachedHashes(input) : input;
if (source.GetVectorType() == VectorType::CONSTANT_VECTOR) {
result.SetVectorType(VectorType::CONSTANT_VECTOR);
FlatVector::SetSize(result, count_t(count));

auto ldata = ConstantVector::GetData<T>(input);
auto ldata = ConstantVector::GetData<T>(source);
auto result_data = ConstantVector::GetData<hash_t>(result);
*result_data = INPUT_IS_ALREADY_HASH ? CachedHashOp::Operation(*ldata)
: HashOp::Operation(*ldata, ConstantVector::IsNull(input));
: HashOp::Operation(*ldata, ConstantVector::IsNull(source));
} else {
result.SetVectorType(VectorType::FLAT_VECTOR);
FlatVector::SetSize(result, count_t(count));

UnifiedVectorFormat idata;
input.ToUnifiedFormat(idata);
source.ToUnifiedFormat(idata);
if constexpr (INPUT_IS_ALREADY_HASH) {
idata.sel = &DictionaryVector::SelVector(input);
}

if (idata.sel->IsSet()) {
TightLoopHash<HAS_RSEL, true, T, INPUT_IS_ALREADY_HASH>(UnifiedVectorFormat::GetData<T>(idata),
Expand Down Expand Up @@ -416,16 +420,23 @@ static inline void TightLoopCombineHash(const T *__restrict ldata, hash_t *__res

template <bool HAS_RSEL, class T, bool INPUT_IS_ALREADY_HASH = false>
void TemplatedLoopCombineHash(const Vector &input, Vector &hashes, const SelectionVector *rsel, idx_t count) {
if (input.GetVectorType() == VectorType::CONSTANT_VECTOR && hashes.GetVectorType() == VectorType::CONSTANT_VECTOR) {
auto ldata = ConstantVector::GetData<T>(input);
const auto &source = INPUT_IS_ALREADY_HASH ? DictionaryVector::GetCachedHashes(input) : input;
if (source.GetVectorType() == VectorType::CONSTANT_VECTOR &&
hashes.GetVectorType() == VectorType::CONSTANT_VECTOR) {
auto ldata = ConstantVector::GetData<T>(source);
auto hash_data = ConstantVector::GetData<hash_t>(hashes);

auto other_hash = INPUT_IS_ALREADY_HASH ? CachedHashOp::Operation(*ldata)
: HashOp::Operation(*ldata, ConstantVector::IsNull(input));
: HashOp::Operation(*ldata, ConstantVector::IsNull(source));
*hash_data = CombineHashScalar(*hash_data, other_hash);
} else {
UnifiedVectorFormat idata;
input.ToUnifiedFormat(idata);
source.ToUnifiedFormat(idata);
if constexpr (INPUT_IS_ALREADY_HASH) {
idata.sel = source.GetVectorType() == VectorType::CONSTANT_VECTOR
? ConstantVector::ZeroSelectionVector(input.size(), idata.owned_sel)
: &DictionaryVector::SelVector(input);
}
if (hashes.GetVectorType() == VectorType::CONSTANT_VECTOR) {
// mix constant with non-constant, first get the constant value
auto constant_hash = *ConstantVector::GetData<hash_t>(hashes);
Expand Down Expand Up @@ -515,17 +526,15 @@ void CombineHashTypeSwitch(Vector &hashes, const Vector &input, const SelectionV

void VectorOperations::Hash(const Vector &input, Vector &result, idx_t count) {
if (input.GetVectorType() == VectorType::DICTIONARY_VECTOR && DictionaryVector::CanCacheHashes(input)) {
Vector input_hashes(DictionaryVector::GetCachedHashes(input), DictionaryVector::SelVector(input), count);
TemplatedLoopHash<false, hash_t, true>(input_hashes, result, nullptr, count);
TemplatedLoopHash<false, hash_t, true>(input, result, nullptr, count);
} else {
HashTypeSwitch<false>(input, result, nullptr, count);
}
}

void VectorOperations::Hash(const Vector &input, Vector &result, const SelectionVector &sel, idx_t count) {
if (input.GetVectorType() == VectorType::DICTIONARY_VECTOR && DictionaryVector::CanCacheHashes(input)) {
Vector input_hashes(DictionaryVector::GetCachedHashes(input), DictionaryVector::SelVector(input), count);
TemplatedLoopHash<true, hash_t, true>(input_hashes, result, &sel, count);
TemplatedLoopHash<true, hash_t, true>(input, result, &sel, count);
} else {
HashTypeSwitch<true>(input, result, &sel, count);
}
Expand All @@ -537,8 +546,7 @@ void VectorOperations::Hash(const Vector &input, Vector &result) {

void VectorOperations::CombineHash(Vector &hashes, const Vector &input, idx_t count) {
if (input.GetVectorType() == VectorType::DICTIONARY_VECTOR && DictionaryVector::CanCacheHashes(input)) {
Vector input_hashes(DictionaryVector::GetCachedHashes(input), DictionaryVector::SelVector(input), count);
TemplatedLoopCombineHash<false, hash_t, true>(input_hashes, hashes, nullptr, count);
TemplatedLoopCombineHash<false, hash_t, true>(input, hashes, nullptr, count);
} else {
CombineHashTypeSwitch<false>(hashes, input, nullptr, count);
}
Expand All @@ -556,8 +564,7 @@ void VectorOperations::CombineHash(Vector &hashes, const Vector &input) {

void VectorOperations::CombineHash(Vector &hashes, const Vector &input, const SelectionVector &rsel, idx_t count) {
if (input.GetVectorType() == VectorType::DICTIONARY_VECTOR && DictionaryVector::CanCacheHashes(input)) {
Vector input_hashes(DictionaryVector::GetCachedHashes(input), DictionaryVector::SelVector(input), count);
TemplatedLoopCombineHash<true, hash_t, true>(input_hashes, hashes, &rsel, count);
TemplatedLoopCombineHash<true, hash_t, true>(input, hashes, &rsel, count);
} else {
CombineHashTypeSwitch<true>(hashes, input, &rsel, count);
}
Expand Down
13 changes: 5 additions & 8 deletions src/duckdb/src/execution/join_hashtable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -675,8 +675,9 @@ void JoinHashTable::EncodeDictSurvivingColumn(const DictSurvivingColumn &column,
static_cast<uint64_t>(build_col_idx));
}

static bool MarkJoinNullRows(const UnifiedVectorFormat &format, idx_t count,
optional_ptr<bool> rows_with_null = nullptr) {
static bool MarkJoinNullRows(const Vector &input, idx_t count, optional_ptr<bool> rows_with_null = nullptr) {
UnifiedVectorFormat format;
input.ToUnifiedFormat(format);
if (format.validity.CannotHaveNull()) {
return false;
}
Expand All @@ -696,16 +697,12 @@ static bool MarkJoinNullRows(const UnifiedVectorFormat &format, idx_t count,
static bool MarkJoinKeysHaveNull(DataChunk &keys, optional_ptr<bool> rows_with_null = nullptr) {
bool has_null = false;
for (idx_t col_idx = 0; col_idx < keys.ColumnCount(); col_idx++) {
UnifiedVectorFormat format;
if (keys.data[col_idx].GetType().IsNested()) {
Vector comparison(LogicalType::BOOLEAN, keys.size());
VectorOperations::Equals(keys.data[col_idx], keys.data[col_idx], comparison);
comparison.ToUnifiedFormat(format);
has_null |= MarkJoinNullRows(comparison, keys.size(), rows_with_null);
} else {
keys.data[col_idx].ToUnifiedFormat(format);
}
if (MarkJoinNullRows(format, keys.size(), rows_with_null)) {
has_null = true;
has_null |= MarkJoinNullRows(keys.data[col_idx], keys.size(), rows_with_null);
}
}
return has_null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1573,6 +1573,10 @@ void StringValueScanner::ProcessOverBufferValue() {
// the file ended inside a quoted value: record that before the value itself is added
result.current_errors.Insert(UNTERMINATED_QUOTES, result.cur_col_id, result.chunk_col_id, result.last_position);
}
// With a single column, a record separator read right after a state reset is an empty line only when it does not
// end an open row or comment
const bool single_column_empty_line = states.EmptyLine() && state_machine->dialect_options.num_cols == 1;
const bool empty_line = single_column_empty_line && result.cur_col_id == 0 && !result.comment;
bool skip_value = false;
if (result.projecting_columns) {
if (result.cur_col_id < result.number_of_columns && !result.projected_columns[result.cur_col_id]) {
Expand Down Expand Up @@ -1662,8 +1666,10 @@ void StringValueScanner::ProcessOverBufferValue() {
}
}
}
if (states.EmptyLine() && state_machine->dialect_options.num_cols == 1) {
result.EmptyLine(result, iterator.pos.buffer_pos);
if (single_column_empty_line) {
if (empty_line) {
result.EmptyLine(result, iterator.pos.buffer_pos);
}
} else if (!states.IsNotSet() && (!result.comment || !value.Empty())) {
idx_t value_size = value.GetSize();
if (!removed_extra_delimiter_bytes) {
Expand All @@ -1675,16 +1681,14 @@ void StringValueScanner::ProcessOverBufferValue() {
}
result.AddValueToVector(value.GetData(), value_size, true);
}
} else {
if (states.EmptyLine() && state_machine->dialect_options.num_cols == 1) {
result.EmptyLine(result, iterator.pos.buffer_pos);
}
} else if (empty_line) {
result.EmptyLine(result, iterator.pos.buffer_pos);
}

if (states.NewRow() && !states.IsNotSet()) {
if (result.IsCommentSet(result)) {
result.UnsetComment(result, iterator.pos.buffer_pos);
} else {
} else if (!empty_line) {
result.AddRowInternal();
}
lines_read++;
Expand Down
6 changes: 3 additions & 3 deletions src/duckdb/src/function/table/version/pragma_version.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef DUCKDB_PATCH_VERSION
#define DUCKDB_PATCH_VERSION "0-alpha57135"
#define DUCKDB_PATCH_VERSION "0-alpha57181"
#endif
#ifndef DUCKDB_MINOR_VERSION
#define DUCKDB_MINOR_VERSION 1
Expand All @@ -8,10 +8,10 @@
#define DUCKDB_MAJOR_VERSION 2
#endif
#ifndef DUCKDB_VERSION
#define DUCKDB_VERSION "v2.1.0-alpha57135"
#define DUCKDB_VERSION "v2.1.0-alpha57181"
#endif
#ifndef DUCKDB_SOURCE_ID
#define DUCKDB_SOURCE_ID "620752ed3c"
#define DUCKDB_SOURCE_ID "3b3e55925f"
#endif
#include "duckdb/function/table/system_functions.hpp"
#include "duckdb/main/database.hpp"
Expand Down
1 change: 1 addition & 0 deletions src/duckdb/src/include/duckdb/common/types/vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ class Vector {
//! Access to the individual vector elements can be performed through data_pointer[sel_idx[i]]/validity[sel_idx[i]]
//! The most common vector types (flat, constant & dictionary) can be converted to the canonical format "for free"
//! ToUnifiedFormat was originally called Orrify, as a tribute to Orri Erling who came up with it
//! Borrows source data and metadata: keep their storage and selection alive and stable until the final read.
DUCKDB_API void ToUnifiedFormat(UnifiedVectorFormat &data) const;

[[deprecated("RecursiveToUnifiedFormat no longer requires a count - use RecursiveToUnifiedFormat(input, data) "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ struct ScalarExecutor {

//! Makes a reused result ready for the one-row generic path: like the constant path, a stale NULL does not survive
DUCKDB_API static void PrepareConstantResult(Vector &result);
DUCKDB_API static bool PrepareGenericResultValidity(const UnifiedVectorFormat *formats, idx_t format_count,
DUCKDB_API static bool PrepareGenericResultValidity(UnifiedVectorFormat *formats, idx_t format_count,
Vector &result, idx_t count, bool preserve_result_validity,
bool adds_nulls);

Expand Down
Loading
Loading