Prunes a list of filenames based on a set of filters, can be used by TableFunctions in the pushdown_complex_filter function to skip files with filename-based filters. Also removes the filters that always evaluate to true.
77921 {
77922 vector<OpenFileInfo> pruned_files;
77923 vector<bool> have_preserved_filter(filters.size(), false);
77924 vector<unique_ptr<Expression>> pruned_filters;
77925 unordered_set<idx_t> filters_applied_to_files;
77926 auto table_index = info.table_index;
77927
77928 if ((!filter_info.filename_enabled && !filter_info.hive_enabled) || filters.empty()) {
77929 return;
77930 }
77931
77932 for (idx_t i = 0; i < files.size(); i++) {
77933 auto &file = files[i];
77934 bool should_prune_file = false;
77935 auto known_values = GetKnownColumnValues(file.path, filter_info);
77936
77937 for (idx_t j = 0; j < filters.size(); j++) {
77938 auto &
filter = filters[j];
77939 unique_ptr<Expression> filter_copy =
filter->Copy();
77940 ConvertKnownColRefToConstants(context, filter_copy, known_values, table_index);
77941
77942 Value result_value;
77943
77944 if (!filter_copy->IsScalar() || !filter_copy->IsFoldable() ||
77946
77947 if (!have_preserved_filter[j]) {
77948 pruned_filters.emplace_back(
filter->Copy());
77949 have_preserved_filter[j] = true;
77950 }
77951 } else if (result_value.IsNull() || !result_value.GetValue<bool>()) {
77952
77953 should_prune_file = true;
77954
77955 if (filters_applied_to_files.find(j) == filters_applied_to_files.end()) {
77956 info.extra_info.file_filters +=
filter->ToString();
77957 filters_applied_to_files.insert(j);
77958 }
77959 }
77960 }
77961
77962 if (!should_prune_file) {
77963 pruned_files.push_back(file);
77964 }
77965 }
77966
77967 D_ASSERT(filters.size() >= pruned_filters.size());
77968
77969 info.extra_info.total_files = files.size();
77970 info.extra_info.filtered_files = pruned_files.size();
77971
77972 filters = std::move(pruned_filters);
77973 files = std::move(pruned_files);
77974}
static DUCKDB_API bool TryEvaluateScalar(ClientContext &context, const Expression &expr, Value &result)
Try to evaluate a scalar expression and fold it into a single value, returns false if an exception is...
void filter(InputArray image, InputArray kernel, OutputArray output)