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
Original file line number Diff line number Diff line change
Expand Up @@ -172,22 +172,8 @@ struct InternalApproxTopKState {
}
auto &value = values.back().get();
if (value.count > 0) {
// the capacity is reached - we need to replace an entry

// we use the filter as an early out
// based on the hash - we find a slot in the filter
// instead of monitoring the value immediately, we add to the slot in the filter
// ONLY when the value in the filter exceeds the current min value, we start monitoring the value
// this speeds up the algorithm as switching monitor values means we need to erase/insert in the hash table
auto &filter_value = filter[input.hash & filter_mask];
if (filter_value + increment < value.count) {
// if the filter has a lower count than the current min count
// we can skip adding this entry (for now)
filter_value += increment;
return;
}
// the filter exceeds the min value - start monitoring this value
// erase the existing entry from the lookup table (before CopyValue overwrites its hash and data)
// the capacity is reached - replace the entry with the lowest count
// erase it from the lookup table (before CopyValue overwrites its hash and data)
// and set the filter for the minimum value back to the current minimum value
filter[value.str_val.hash & filter_mask] = value.count;
Erase(value);
Expand All @@ -197,6 +183,22 @@ struct InternalApproxTopKState {
IncrementCount(value, increment);
}

//! Returns true if an unmonitored input is only counted in the filter
bool FilterInput(const ApproxTopKString &input) {
if (values.size() < capacity) {
return false;
}
// instead of monitoring the value immediately, we add to its slot in the filter
// ONLY when the filter slot reaches the current min count, we start monitoring the value
// this speeds up the algorithm as switching monitor values means we need to erase/insert in the hash table
auto &filter_value = filter[input.hash & filter_mask];
if (filter_value + 1 < values.back().get().count) {
filter_value++;
return true;
}
return false;
}

void IncrementCount(ApproxTopKValue &value, idx_t increment = 1) {
value.count += increment;
// maintain sortedness of "values"
Expand Down Expand Up @@ -266,8 +268,8 @@ struct ApproxTopKOperation {
if (entry) {
// the input is monitored - increment the count
state.IncrementCount(*entry);
} else {
// the input is not monitored - replace the first entry with the current entry and increment
} else if (!state.FilterInput(topk_string)) {
// the input is not monitored and passes the filter - start monitoring it
state.InsertOrReplaceEntry(topk_string, aggr_input);
}
}
Expand Down Expand Up @@ -311,6 +313,11 @@ struct ApproxTopKOperation {
}
target.IncrementCount(val, increment);
}
// copy over the filter before evicting, so an evicted value sets its slot to its merged count
D_ASSERT(source.filter.size() == target.filter.size());
for (idx_t filter_idx = 0; filter_idx < source.filter.size(); filter_idx++) {
target.filter[filter_idx] += source.filter[filter_idx];
}
// now for each entry in source, if it is not tracked by the target, at the target minimum
for (auto &source_entry : source.values) {
auto &source_val = source_entry.get();
Expand All @@ -337,11 +344,6 @@ struct ApproxTopKOperation {
}
target.InsertOrReplaceEntry(source_val.str_val, aggr_input, increment);
}
// copy over the filter
D_ASSERT(source.filter.size() == target.filter.size());
for (idx_t filter_idx = 0; filter_idx < source.filter.size(); filter_idx++) {
target.filter[filter_idx] += source.filter[filter_idx];
}
target.Verify();
}

Expand Down
30 changes: 27 additions & 3 deletions src/duckdb/extension/parquet/parquet_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2656,18 +2656,42 @@ struct ParquetPartitionRowGroup : public PartitionRowGroup {
D_ASSERT(metadata.row_groups.size() > row_group_idx);

// Special handle generated columns.
const auto &column_schema = root_schema->children[primary_index];
if (column_schema.schema_type == ParquetColumnSchemaType::FILE_ROW_NUMBER) {
reference<const ParquetColumnSchema> column_schema = root_schema->children[primary_index];
if (column_schema.get().schema_type == ParquetColumnSchemaType::FILE_ROW_NUMBER) {
return true;
}
// resolve an extracted struct field to the leaf column it reads
if (storage_index.IsPushdownExtract()) {
reference<const StorageIndex> index = storage_index;
while (index.get().HasChildren() && column_schema.get().type.id() == LogicalTypeId::STRUCT) {
if (column_schema.get().children.empty()) {
// INT96 can be exposed as a struct without physical child columns.
return false;
}
index = index.get().GetChildIndex(0);
column_schema = column_schema.get().children[index.get().GetPrimaryIndex()];
}
}
// row_group.columns is indexed by leaf column, so only leaf columns map to a column chunk
auto &leaf_schema = column_schema.get();
if (leaf_schema.schema_type != ParquetColumnSchemaType::COLUMN || !leaf_schema.children.empty()) {
return false;
}

const auto &row_group = metadata.row_groups[row_group_idx];
const auto &column_chunk = row_group.columns[primary_index];
const auto &column_chunk = row_group.columns[leaf_schema.column_index];

if (column_chunk.__isset.meta_data && column_chunk.meta_data.__isset.statistics &&
column_chunk.meta_data.statistics.__isset.is_min_value_exact &&
column_chunk.meta_data.statistics.__isset.is_max_value_exact) {
const auto &stats = column_chunk.meta_data.statistics;
const auto type_id = leaf_schema.type.id();
const bool is_floating_point = type_id == LogicalTypeId::FLOAT || type_id == LogicalTypeId::DOUBLE;
const bool can_have_nan = parquet_options->can_have_nan && stats.__isset.nan_count == 0;
if (is_floating_point && can_have_nan) {
// the max is replaced by NaN as an upper bound, as the stored max leaves out NaN values
return false;
}
return stats.is_min_value_exact && stats.is_max_value_exact;
}
return false;
Expand Down
5 changes: 4 additions & 1 deletion src/duckdb/extension/parquet/parquet_statistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,10 @@ ParquetStatisticsUtils::TransformColumnStatistics(const ParquetColumnSchema &sch
row_group_stats->Set(StatsInfo::CANNOT_HAVE_NULL_VALUES);
}
if (parquet_stats.__isset.null_count && parquet_stats.null_count == column_chunk.meta_data.num_values) {
row_group_stats->Set(StatsInfo::CANNOT_HAVE_VALID_VALUES);
row_group_stats = BaseStatistics::CreateEmpty(type).ToUnique();
if (parquet_stats.null_count > 0) {
row_group_stats->Set(StatsInfo::CAN_HAVE_NULL_VALUES);
}
}
}
return row_group_stats;
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-alpha57096";
descriptor->api_version = "v2.1.0-alpha57135";
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-alpha57096";
descriptor->api_version = "v2.1.0-alpha57135";
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-alpha57096";
descriptor->api_version = "v2.1.0-alpha57135";
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-alpha57096";
descriptor->api_version = "v2.1.0-alpha57135";
descriptor->entry_cpp = (void (*)(void))json_duckdb_cpp_init;
return 0;
}
Expand Down
Loading
Loading