430932 {
430933 switch (
filter.filter_type) {
430934 case TableFilterType::OPTIONAL_FILTER: {
430935 auto &opt_filter =
filter.Cast<OptionalFilter>();
430936 return opt_filter.FilterSelection(sel, vector, vdata, filter_state, scan_count, approved_tuple_count);
430937 }
430938 case TableFilterType::CONJUNCTION_OR: {
430939
430940 auto &state = filter_state.Cast<ConjunctionOrFilterState>();
430941 idx_t count_total = 0;
430942 SelectionVector result_sel(approved_tuple_count);
430943 auto &conjunction_or =
filter.Cast<ConjunctionOrFilter>();
430944 for (
idx_t child_idx = 0; child_idx < conjunction_or.child_filters.size(); child_idx++) {
430945 auto &child_filter = *conjunction_or.child_filters[child_idx];
430946 SelectionVector temp_sel;
430947 temp_sel.Initialize(sel);
430948 idx_t temp_tuple_count = approved_tuple_count;
430949 idx_t temp_count = FilterSelection(temp_sel, vector, vdata, child_filter, *state.child_states[child_idx],
430950 scan_count, temp_tuple_count);
430951
430952 for (
idx_t i = 0; i < temp_count; i++) {
430953 auto new_idx = temp_sel.get_index(i);
430954 bool is_new_idx = true;
430955 for (
idx_t res_idx = 0; res_idx < count_total; res_idx++) {
430956 if (result_sel.get_index(res_idx) == new_idx) {
430957 is_new_idx = false;
430958 break;
430959 }
430960 }
430961 if (is_new_idx) {
430962 result_sel.set_index(count_total++, new_idx);
430963 }
430964 }
430965 }
430966 sel.Initialize(result_sel);
430967 approved_tuple_count = count_total;
430968 return approved_tuple_count;
430969 }
430970 case TableFilterType::CONJUNCTION_AND: {
430971 auto &conjunction_and =
filter.Cast<ConjunctionAndFilter>();
430972 auto &state = filter_state.Cast<ConjunctionAndFilterState>();
430973 for (
idx_t child_idx = 0; child_idx < conjunction_and.child_filters.size(); child_idx++) {
430974 auto &child_filter = *conjunction_and.child_filters[child_idx];
430975 FilterSelection(sel, vector, vdata, child_filter, *state.child_states[child_idx], scan_count,
430976 approved_tuple_count);
430977 }
430978 return approved_tuple_count;
430979 }
430980 case TableFilterType::CONSTANT_COMPARISON: {
430981 auto &constant_filter =
filter.Cast<ConstantFilter>();
430982 switch (vector.GetType().InternalType()) {
430984 auto predicate = UTinyIntValue::Get(constant_filter.constant);
430985 FilterSelectionSwitch<uint8_t>(vdata, predicate, sel, approved_tuple_count,
430986 constant_filter.comparison_type);
430987 break;
430988 }
430990 auto predicate = USmallIntValue::Get(constant_filter.constant);
430991 FilterSelectionSwitch<uint16_t>(vdata, predicate, sel, approved_tuple_count,
430992 constant_filter.comparison_type);
430993 break;
430994 }
430996 auto predicate = UIntegerValue::Get(constant_filter.constant);
430997 FilterSelectionSwitch<uint32_t>(vdata, predicate, sel, approved_tuple_count,
430998 constant_filter.comparison_type);
430999 break;
431000 }
431002 auto predicate = UBigIntValue::Get(constant_filter.constant);
431003 FilterSelectionSwitch<uint64_t>(vdata, predicate, sel, approved_tuple_count,
431004 constant_filter.comparison_type);
431005 break;
431006 }
431008 auto predicate = TinyIntValue::Get(constant_filter.constant);
431009 FilterSelectionSwitch<int8_t>(vdata, predicate, sel, approved_tuple_count, constant_filter.comparison_type);
431010 break;
431011 }
431013 auto predicate = SmallIntValue::Get(constant_filter.constant);
431014 FilterSelectionSwitch<int16_t>(vdata, predicate, sel, approved_tuple_count,
431015 constant_filter.comparison_type);
431016 break;
431017 }
431019 auto predicate = IntegerValue::Get(constant_filter.constant);
431020 FilterSelectionSwitch<int32_t>(vdata, predicate, sel, approved_tuple_count,
431021 constant_filter.comparison_type);
431022 break;
431023 }
431025 auto predicate = BigIntValue::Get(constant_filter.constant);
431026 FilterSelectionSwitch<int64_t>(vdata, predicate, sel, approved_tuple_count,
431027 constant_filter.comparison_type);
431028 break;
431029 }
431030 case PhysicalType::INT128: {
431031 auto predicate = HugeIntValue::Get(constant_filter.constant);
431032 FilterSelectionSwitch<hugeint_t>(vdata, predicate, sel, approved_tuple_count,
431033 constant_filter.comparison_type);
431034 break;
431035 }
431036 case PhysicalType::UINT128: {
431037 auto predicate = UhugeIntValue::Get(constant_filter.constant);
431038 FilterSelectionSwitch<uhugeint_t>(vdata, predicate, sel, approved_tuple_count,
431039 constant_filter.comparison_type);
431040 break;
431041 }
431043 auto predicate = FloatValue::Get(constant_filter.constant);
431044 FilterSelectionSwitch<float>(vdata, predicate, sel, approved_tuple_count, constant_filter.comparison_type);
431045 break;
431046 }
431048 auto predicate = DoubleValue::Get(constant_filter.constant);
431049 FilterSelectionSwitch<double>(vdata, predicate, sel, approved_tuple_count, constant_filter.comparison_type);
431050 break;
431051 }
431053 auto predicate = string_t(StringValue::Get(constant_filter.constant));
431054 FilterSelectionSwitch<string_t>(vdata, predicate, sel, approved_tuple_count,
431055 constant_filter.comparison_type);
431056 break;
431057 }
431059 auto predicate = BooleanValue::Get(constant_filter.constant);
431060 FilterSelectionSwitch<bool>(vdata, predicate, sel, approved_tuple_count, constant_filter.comparison_type);
431061 break;
431062 }
431063 default:
431064 throw InvalidTypeException(vector.GetType(), "Invalid type for filter pushed down to table comparison");
431065 }
431066 return approved_tuple_count;
431067 }
431068 case TableFilterType::IS_NULL: {
431069 return TemplatedNullSelection<true>(vdata, sel, approved_tuple_count);
431070 }
431071 case TableFilterType::IS_NOT_NULL: {
431072 return TemplatedNullSelection<false>(vdata, sel, approved_tuple_count);
431073 }
431074 case TableFilterType::STRUCT_EXTRACT: {
431075 auto &struct_filter =
filter.Cast<StructFilter>();
431076
431077 auto &child_vec = StructVector::GetEntries(vector)[struct_filter.child_idx];
431078 UnifiedVectorFormat child_data;
431079 child_vec->ToUnifiedFormat(scan_count, child_data);
431080 return FilterSelection(sel, *child_vec, child_data, *struct_filter.child_filter, filter_state, scan_count,
431081 approved_tuple_count);
431082 }
431083 case TableFilterType::BLOOM_FILTER: {
431084 auto &bloom_filter =
filter.Cast<BFTableFilter>();
431085 auto &state = filter_state.Cast<BFTableFilterState>();
431086 return bloom_filter.Filter(vector, sel, approved_tuple_count, state);
431087 }
431088 case TableFilterType::EXPRESSION_FILTER: {
431089 auto &state = filter_state.Cast<ExpressionFilterState>();
431090 SelectionVector result_sel(approved_tuple_count);
431091 if (scan_count > STANDARD_VECTOR_SIZE) {
431092
431094 idx_t result_offset = 0;
431095 idx_t current_sel_offset = 0;
431096 SelectionVector current_sel(approved_tuple_count);
431097 while (
offset < scan_count) {
431098 idx_t chunk_count = MinValue<idx_t>(STANDARD_VECTOR_SIZE, scan_count -
offset);
431100 DataChunk chunk;
431101 chunk.
data.emplace_back(vector,
offset, chunk_end);
431102 chunk.SetCardinality(chunk_count);
431103
431104
431105 idx_t current_count = 0;
431106 for (; current_sel_offset < approved_tuple_count; current_sel_offset++) {
431107 auto sel_index = sel.get_index(current_sel_offset);
431108 if (sel_index >= chunk_end) {
431109
431110 break;
431111 }
431112 if (sel_index <
offset) {
431113 throw InternalException("sel_index < offset in expression filter");
431114 }
431115 current_sel.set_index(current_count++, sel_index -
offset);
431116 }
431117 if (current_count == 0) {
431118
431120 continue;
431121 }
431122 auto current_result_data = result_sel.data() + result_offset;
431123 SelectionVector current_result_sel(current_result_data);
431124 idx_t new_matches =
431125 state.executor.SelectExpression(chunk, current_result_sel, current_sel, current_count);
431126
431127 for (
idx_t i = 0; i < new_matches; i++) {
431128 current_result_data[i] +=
offset;
431129 }
431130 result_offset += new_matches;
431132 }
431133 approved_tuple_count = result_offset;
431134 } else {
431135
431136 DataChunk chunk;
431137 chunk.
data.emplace_back(vector);
431138 chunk.SetCardinality(scan_count);
431139 approved_tuple_count = state.executor.SelectExpression(chunk, result_sel, sel, approved_tuple_count);
431140 }
431141 sel.Initialize(result_sel);
431142 return approved_tuple_count;
431143 }
431144 default:
431145 throw InternalException("FIXME: unsupported type for filter selection");
431146 }
431147}
vector< Vector > data
The vectors owned by the DataChunk.
Definition duckdb.hpp:11445
void filter(InputArray image, InputArray kernel, OutputArray output)
@ UINT32
Unsigned 32-bit little-endian integer.
Definition duckdb.hpp:2758
@ UINT16
Unsigned 16-bit little-endian integer.
Definition duckdb.hpp:2752
@ INT64
Signed 64-bit little-endian integer.
Definition duckdb.hpp:2767
@ INT16
Signed 16-bit little-endian integer.
Definition duckdb.hpp:2755
@ INT32
Signed 32-bit little-endian integer.
Definition duckdb.hpp:2761
@ UINT64
Unsigned 64-bit little-endian integer.
Definition duckdb.hpp:2764
@ BOOL
Boolean as 8 bit "bool" value.
Definition duckdb.hpp:2743
@ VARCHAR
DuckDB Extensions.
Definition duckdb.hpp:2847
@ FLOAT
4-byte floating point value
Definition duckdb.hpp:2773
@ UINT8
Unsigned 8-bit little-endian integer.
Definition duckdb.hpp:2746
@ INT8
Signed 8-bit little-endian integer.
Definition duckdb.hpp:2749
@ DOUBLE
8-byte floating point value
Definition duckdb.hpp:2776
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237