duckdb 0.3.3-dev534.0 → 0.3.3-dev575.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/duckdb.cpp +517 -336
- package/src/duckdb.hpp +5157 -5133
- package/src/parquet-amalgamation.cpp +36617 -36617
package/src/duckdb.cpp
CHANGED
|
@@ -4212,6 +4212,10 @@ static DefaultMacro internal_macros[] = {
|
|
|
4212
4212
|
{DEFAULT_SCHEMA, "array_append", {"arr", "el", nullptr}, "list_append(arr, el)"},
|
|
4213
4213
|
{DEFAULT_SCHEMA, "list_prepend", {"e", "l", nullptr}, "list_concat(list_value(e), l)"},
|
|
4214
4214
|
{DEFAULT_SCHEMA, "array_prepend", {"el", "arr", nullptr}, "list_prepend(el, arr)"},
|
|
4215
|
+
{DEFAULT_SCHEMA, "array_pop_back", {"arr", nullptr}, "arr[:LEN(arr)-1]"},
|
|
4216
|
+
{DEFAULT_SCHEMA, "array_pop_front", {"arr", nullptr}, "arr[1:]"},
|
|
4217
|
+
{DEFAULT_SCHEMA, "array_push_back", {"arr", "e", nullptr}, "list_concat(arr, list_value(e))"},
|
|
4218
|
+
{DEFAULT_SCHEMA, "array_push_front", {"arr", "e", nullptr}, "list_concat(list_value(e), arr)"},
|
|
4215
4219
|
{DEFAULT_SCHEMA, "generate_subscripts", {"arr", "dim", nullptr}, "unnest(generate_series(1, array_length(arr, dim)))"},
|
|
4216
4220
|
{DEFAULT_SCHEMA, "fdiv", {"x", "y", nullptr}, "floor(x/y)"},
|
|
4217
4221
|
{DEFAULT_SCHEMA, "fmod", {"x", "y", nullptr}, "(x-y*floor(x/y))"},
|
|
@@ -62789,9 +62793,15 @@ OperatorResultType PhysicalUnnest::Execute(ExecutionContext &context, DataChunk
|
|
|
62789
62793
|
auto &list_vector = state.list_data.data[col_idx];
|
|
62790
62794
|
list_vector.Orrify(state.list_data.size(), state.list_vector_data[col_idx]);
|
|
62791
62795
|
|
|
62792
|
-
|
|
62793
|
-
|
|
62794
|
-
|
|
62796
|
+
if (list_vector.GetType() == LogicalType::SQLNULL) {
|
|
62797
|
+
// UNNEST(NULL)
|
|
62798
|
+
auto &child_vector = list_vector;
|
|
62799
|
+
child_vector.Orrify(0, state.list_child_data[col_idx]);
|
|
62800
|
+
} else {
|
|
62801
|
+
auto list_size = ListVector::GetListSize(list_vector);
|
|
62802
|
+
auto &child_vector = ListVector::GetEntry(list_vector);
|
|
62803
|
+
child_vector.Orrify(list_size, state.list_child_data[col_idx]);
|
|
62804
|
+
}
|
|
62795
62805
|
}
|
|
62796
62806
|
state.first_fetch = false;
|
|
62797
62807
|
}
|
|
@@ -62840,34 +62850,40 @@ OperatorResultType PhysicalUnnest::Execute(ExecutionContext &context, DataChunk
|
|
|
62840
62850
|
for (idx_t col_idx = 0; col_idx < state.list_data.ColumnCount(); col_idx++) {
|
|
62841
62851
|
auto &result_vector = chunk.data[col_idx + input.ColumnCount()];
|
|
62842
62852
|
|
|
62843
|
-
|
|
62844
|
-
|
|
62845
|
-
|
|
62846
|
-
|
|
62847
|
-
auto list_data = (list_entry_t *)vdata.data;
|
|
62848
|
-
auto list_entry = list_data[current_idx];
|
|
62849
|
-
|
|
62850
|
-
idx_t list_count;
|
|
62851
|
-
if (state.list_position >= list_entry.length) {
|
|
62852
|
-
list_count = 0;
|
|
62853
|
+
if (state.list_data.data[col_idx].GetType() == LogicalType::SQLNULL) {
|
|
62854
|
+
// UNNEST(NULL)
|
|
62855
|
+
chunk.SetCardinality(0);
|
|
62853
62856
|
} else {
|
|
62854
|
-
|
|
62855
|
-
|
|
62857
|
+
auto &vdata = state.list_vector_data[col_idx];
|
|
62858
|
+
auto &child_data = state.list_child_data[col_idx];
|
|
62859
|
+
auto current_idx = vdata.sel->get_index(state.parent_position);
|
|
62856
62860
|
|
|
62857
|
-
|
|
62858
|
-
|
|
62859
|
-
|
|
62861
|
+
auto list_data = (list_entry_t *)vdata.data;
|
|
62862
|
+
auto list_entry = list_data[current_idx];
|
|
62863
|
+
|
|
62864
|
+
idx_t list_count;
|
|
62865
|
+
if (state.list_position >= list_entry.length) {
|
|
62866
|
+
list_count = 0;
|
|
62860
62867
|
} else {
|
|
62861
|
-
|
|
62862
|
-
|
|
62863
|
-
|
|
62868
|
+
list_count = MinValue<idx_t>(this_chunk_len, list_entry.length - state.list_position);
|
|
62869
|
+
}
|
|
62870
|
+
|
|
62871
|
+
if (list_entry.length > state.list_position) {
|
|
62872
|
+
if (!vdata.validity.RowIsValid(current_idx)) {
|
|
62873
|
+
UnnestNull(0, list_count, result_vector);
|
|
62874
|
+
} else {
|
|
62875
|
+
auto &list_vector = state.list_data.data[col_idx];
|
|
62876
|
+
auto &child_vector = ListVector::GetEntry(list_vector);
|
|
62877
|
+
auto list_size = ListVector::GetListSize(list_vector);
|
|
62864
62878
|
|
|
62865
|
-
|
|
62866
|
-
|
|
62867
|
-
|
|
62879
|
+
auto base_offset = list_entry.offset + state.list_position;
|
|
62880
|
+
UnnestVector(child_data, child_vector, list_size, base_offset, base_offset + list_count,
|
|
62881
|
+
result_vector);
|
|
62882
|
+
}
|
|
62868
62883
|
}
|
|
62884
|
+
|
|
62885
|
+
UnnestNull(list_count, this_chunk_len, result_vector);
|
|
62869
62886
|
}
|
|
62870
|
-
UnnestNull(list_count, this_chunk_len, result_vector);
|
|
62871
62887
|
}
|
|
62872
62888
|
|
|
62873
62889
|
state.list_position += this_chunk_len;
|
|
@@ -75757,6 +75773,16 @@ struct ListContainsFun {
|
|
|
75757
75773
|
static void RegisterFunction(BuiltinFunctions &set);
|
|
75758
75774
|
};
|
|
75759
75775
|
|
|
75776
|
+
struct ListFlattenFun {
|
|
75777
|
+
static ScalarFunction GetFunction();
|
|
75778
|
+
static void RegisterFunction(BuiltinFunctions &set);
|
|
75779
|
+
};
|
|
75780
|
+
|
|
75781
|
+
struct ListPositionFun {
|
|
75782
|
+
static ScalarFunction GetFunction();
|
|
75783
|
+
static void RegisterFunction(BuiltinFunctions &set);
|
|
75784
|
+
};
|
|
75785
|
+
|
|
75760
75786
|
struct CardinalityFun {
|
|
75761
75787
|
static void RegisterFunction(BuiltinFunctions &set);
|
|
75762
75788
|
};
|
|
@@ -83759,6 +83785,231 @@ void ArraySliceFun::RegisterFunction(BuiltinFunctions &set) {
|
|
|
83759
83785
|
|
|
83760
83786
|
|
|
83761
83787
|
|
|
83788
|
+
namespace duckdb {
|
|
83789
|
+
|
|
83790
|
+
template <class T>
|
|
83791
|
+
static inline bool ValueEqualsOrNot(const T &left, const T &right) {
|
|
83792
|
+
return left == right;
|
|
83793
|
+
}
|
|
83794
|
+
|
|
83795
|
+
template <>
|
|
83796
|
+
inline bool ValueEqualsOrNot(const string_t &left, const string_t &right) {
|
|
83797
|
+
return StringComparisonOperators::EqualsOrNot<false>(left, right);
|
|
83798
|
+
}
|
|
83799
|
+
|
|
83800
|
+
struct ContainsFunctor {
|
|
83801
|
+
static inline bool Initialize() {
|
|
83802
|
+
return false;
|
|
83803
|
+
}
|
|
83804
|
+
static inline bool UpdateResultEntries(idx_t child_idx) {
|
|
83805
|
+
return true;
|
|
83806
|
+
}
|
|
83807
|
+
};
|
|
83808
|
+
|
|
83809
|
+
struct PositionFunctor {
|
|
83810
|
+
static inline int32_t Initialize() {
|
|
83811
|
+
return 0;
|
|
83812
|
+
}
|
|
83813
|
+
static inline int32_t UpdateResultEntries(idx_t child_idx) {
|
|
83814
|
+
return child_idx + 1;
|
|
83815
|
+
}
|
|
83816
|
+
};
|
|
83817
|
+
|
|
83818
|
+
template <class CHILD_TYPE, class RETURN_TYPE, class OP>
|
|
83819
|
+
static void TemplatedContainsOrPosition(DataChunk &args, ExpressionState &state, Vector &result,
|
|
83820
|
+
bool is_nested = false) {
|
|
83821
|
+
D_ASSERT(args.ColumnCount() == 2);
|
|
83822
|
+
auto count = args.size();
|
|
83823
|
+
Vector &list = args.data[0];
|
|
83824
|
+
Vector &value_vector = args.data[1];
|
|
83825
|
+
|
|
83826
|
+
// Create a result vector of type RETURN_TYPE
|
|
83827
|
+
result.SetVectorType(VectorType::FLAT_VECTOR);
|
|
83828
|
+
auto result_entries = FlatVector::GetData<RETURN_TYPE>(result);
|
|
83829
|
+
auto &result_validity = FlatVector::Validity(result);
|
|
83830
|
+
|
|
83831
|
+
if (list.GetType().id() == LogicalTypeId::SQLNULL) {
|
|
83832
|
+
result_validity.SetInvalid(0);
|
|
83833
|
+
return;
|
|
83834
|
+
}
|
|
83835
|
+
|
|
83836
|
+
auto list_size = ListVector::GetListSize(list);
|
|
83837
|
+
auto &child_vector = ListVector::GetEntry(list);
|
|
83838
|
+
|
|
83839
|
+
VectorData child_data;
|
|
83840
|
+
child_vector.Orrify(list_size, child_data);
|
|
83841
|
+
|
|
83842
|
+
VectorData list_data;
|
|
83843
|
+
list.Orrify(count, list_data);
|
|
83844
|
+
auto list_entries = (list_entry_t *)list_data.data;
|
|
83845
|
+
|
|
83846
|
+
VectorData value_data;
|
|
83847
|
+
value_vector.Orrify(count, value_data);
|
|
83848
|
+
|
|
83849
|
+
for (idx_t i = 0; i < count; i++) {
|
|
83850
|
+
auto list_index = list_data.sel->get_index(i);
|
|
83851
|
+
auto value_index = value_data.sel->get_index(i);
|
|
83852
|
+
|
|
83853
|
+
if (!list_data.validity.RowIsValid(list_index) || !value_data.validity.RowIsValid(value_index)) {
|
|
83854
|
+
result_validity.SetInvalid(i);
|
|
83855
|
+
continue;
|
|
83856
|
+
}
|
|
83857
|
+
|
|
83858
|
+
const auto &list_entry = list_entries[list_index];
|
|
83859
|
+
auto source_idx = child_data.sel->get_index(list_entry.offset);
|
|
83860
|
+
|
|
83861
|
+
// not required for a comparison of nested types
|
|
83862
|
+
auto child_value = FlatVector::GetData<CHILD_TYPE>(child_vector);
|
|
83863
|
+
auto values = FlatVector::GetData<CHILD_TYPE>(value_vector);
|
|
83864
|
+
|
|
83865
|
+
result_entries[list_index] = OP::Initialize();
|
|
83866
|
+
for (idx_t child_idx = 0; child_idx < list_entry.length; child_idx++) {
|
|
83867
|
+
auto child_value_idx = source_idx + child_idx;
|
|
83868
|
+
|
|
83869
|
+
if (!child_data.validity.RowIsValid(child_value_idx)) {
|
|
83870
|
+
continue;
|
|
83871
|
+
}
|
|
83872
|
+
|
|
83873
|
+
if (!is_nested) {
|
|
83874
|
+
if (ValueEqualsOrNot<CHILD_TYPE>(child_value[child_value_idx], values[value_index])) {
|
|
83875
|
+
result_entries[list_index] = OP::UpdateResultEntries(child_idx);
|
|
83876
|
+
break; // Found value in list, no need to look further
|
|
83877
|
+
}
|
|
83878
|
+
} else {
|
|
83879
|
+
// FIXME: using Value is less efficient than modifying the vector comparison code
|
|
83880
|
+
// to more efficiently compare nested types
|
|
83881
|
+
if (ValueEqualsOrNot<Value>(child_vector.GetValue(child_value_idx),
|
|
83882
|
+
value_vector.GetValue(value_index))) {
|
|
83883
|
+
result_entries[list_index] = OP::UpdateResultEntries(child_idx);
|
|
83884
|
+
break; // Found value in list, no need to look further
|
|
83885
|
+
}
|
|
83886
|
+
}
|
|
83887
|
+
}
|
|
83888
|
+
}
|
|
83889
|
+
}
|
|
83890
|
+
|
|
83891
|
+
template <class T, class OP>
|
|
83892
|
+
static void ListContainsOrPosition(DataChunk &args, ExpressionState &state, Vector &result) {
|
|
83893
|
+
switch (args.data[1].GetType().InternalType()) {
|
|
83894
|
+
case PhysicalType::BOOL:
|
|
83895
|
+
case PhysicalType::INT8:
|
|
83896
|
+
TemplatedContainsOrPosition<int8_t, T, OP>(args, state, result);
|
|
83897
|
+
break;
|
|
83898
|
+
case PhysicalType::INT16:
|
|
83899
|
+
TemplatedContainsOrPosition<int16_t, T, OP>(args, state, result);
|
|
83900
|
+
break;
|
|
83901
|
+
case PhysicalType::INT32:
|
|
83902
|
+
TemplatedContainsOrPosition<int32_t, T, OP>(args, state, result);
|
|
83903
|
+
break;
|
|
83904
|
+
case PhysicalType::INT64:
|
|
83905
|
+
TemplatedContainsOrPosition<int64_t, T, OP>(args, state, result);
|
|
83906
|
+
break;
|
|
83907
|
+
case PhysicalType::INT128:
|
|
83908
|
+
TemplatedContainsOrPosition<hugeint_t, T, OP>(args, state, result);
|
|
83909
|
+
break;
|
|
83910
|
+
case PhysicalType::UINT8:
|
|
83911
|
+
TemplatedContainsOrPosition<uint8_t, T, OP>(args, state, result);
|
|
83912
|
+
break;
|
|
83913
|
+
case PhysicalType::UINT16:
|
|
83914
|
+
TemplatedContainsOrPosition<uint16_t, T, OP>(args, state, result);
|
|
83915
|
+
break;
|
|
83916
|
+
case PhysicalType::UINT32:
|
|
83917
|
+
TemplatedContainsOrPosition<uint32_t, T, OP>(args, state, result);
|
|
83918
|
+
break;
|
|
83919
|
+
case PhysicalType::UINT64:
|
|
83920
|
+
TemplatedContainsOrPosition<uint64_t, T, OP>(args, state, result);
|
|
83921
|
+
break;
|
|
83922
|
+
case PhysicalType::FLOAT:
|
|
83923
|
+
TemplatedContainsOrPosition<float, T, OP>(args, state, result);
|
|
83924
|
+
break;
|
|
83925
|
+
case PhysicalType::DOUBLE:
|
|
83926
|
+
TemplatedContainsOrPosition<double, T, OP>(args, state, result);
|
|
83927
|
+
break;
|
|
83928
|
+
case PhysicalType::VARCHAR:
|
|
83929
|
+
TemplatedContainsOrPosition<string_t, T, OP>(args, state, result);
|
|
83930
|
+
break;
|
|
83931
|
+
case PhysicalType::MAP:
|
|
83932
|
+
case PhysicalType::STRUCT:
|
|
83933
|
+
case PhysicalType::LIST:
|
|
83934
|
+
TemplatedContainsOrPosition<int8_t, T, OP>(args, state, result, true);
|
|
83935
|
+
break;
|
|
83936
|
+
default:
|
|
83937
|
+
throw NotImplementedException("This function has not been implemented for this type");
|
|
83938
|
+
}
|
|
83939
|
+
}
|
|
83940
|
+
|
|
83941
|
+
static void ListContainsFunction(DataChunk &args, ExpressionState &state, Vector &result) {
|
|
83942
|
+
return ListContainsOrPosition<bool, ContainsFunctor>(args, state, result);
|
|
83943
|
+
}
|
|
83944
|
+
|
|
83945
|
+
static void ListPositionFunction(DataChunk &args, ExpressionState &state, Vector &result) {
|
|
83946
|
+
return ListContainsOrPosition<int32_t, PositionFunctor>(args, state, result);
|
|
83947
|
+
}
|
|
83948
|
+
|
|
83949
|
+
template <LogicalTypeId RETURN_TYPE>
|
|
83950
|
+
static unique_ptr<FunctionData> ListContainsOrPositionBind(ClientContext &context, ScalarFunction &bound_function,
|
|
83951
|
+
vector<unique_ptr<Expression>> &arguments) {
|
|
83952
|
+
D_ASSERT(bound_function.arguments.size() == 2);
|
|
83953
|
+
|
|
83954
|
+
const auto &list = arguments[0]->return_type; // change to list
|
|
83955
|
+
const auto &value = arguments[1]->return_type;
|
|
83956
|
+
if (list.id() == LogicalTypeId::SQLNULL && value.id() == LogicalTypeId::SQLNULL) {
|
|
83957
|
+
bound_function.arguments[0] = LogicalType::SQLNULL;
|
|
83958
|
+
bound_function.arguments[1] = LogicalType::SQLNULL;
|
|
83959
|
+
bound_function.return_type = LogicalType::SQLNULL;
|
|
83960
|
+
} else if (list.id() == LogicalTypeId::SQLNULL || value.id() == LogicalTypeId::SQLNULL) {
|
|
83961
|
+
// In case either the list or the value is NULL, return NULL
|
|
83962
|
+
// Similar to behaviour of prestoDB
|
|
83963
|
+
bound_function.arguments[0] = list;
|
|
83964
|
+
bound_function.arguments[1] = value;
|
|
83965
|
+
bound_function.return_type = LogicalTypeId::SQLNULL;
|
|
83966
|
+
} else {
|
|
83967
|
+
auto const &child_type = ListType::GetChildType(arguments[0]->return_type);
|
|
83968
|
+
auto max_child_type = LogicalType::MaxLogicalType(child_type, value);
|
|
83969
|
+
ExpressionBinder::ResolveParameterType(max_child_type);
|
|
83970
|
+
auto list_type = LogicalType::LIST(max_child_type);
|
|
83971
|
+
|
|
83972
|
+
bound_function.arguments[0] = list_type;
|
|
83973
|
+
bound_function.arguments[1] = value == max_child_type ? value : max_child_type;
|
|
83974
|
+
|
|
83975
|
+
// list_contains and list_position only differ in their return type
|
|
83976
|
+
bound_function.return_type = RETURN_TYPE;
|
|
83977
|
+
}
|
|
83978
|
+
return make_unique<VariableReturnBindData>(bound_function.return_type);
|
|
83979
|
+
}
|
|
83980
|
+
|
|
83981
|
+
static unique_ptr<FunctionData> ListContainsBind(ClientContext &context, ScalarFunction &bound_function,
|
|
83982
|
+
vector<unique_ptr<Expression>> &arguments) {
|
|
83983
|
+
return ListContainsOrPositionBind<LogicalType::BOOLEAN>(context, bound_function, arguments);
|
|
83984
|
+
}
|
|
83985
|
+
|
|
83986
|
+
static unique_ptr<FunctionData> ListPositionBind(ClientContext &context, ScalarFunction &bound_function,
|
|
83987
|
+
vector<unique_ptr<Expression>> &arguments) {
|
|
83988
|
+
return ListContainsOrPositionBind<LogicalType::INTEGER>(context, bound_function, arguments);
|
|
83989
|
+
}
|
|
83990
|
+
|
|
83991
|
+
ScalarFunction ListContainsFun::GetFunction() {
|
|
83992
|
+
return ScalarFunction({LogicalType::LIST(LogicalType::ANY), LogicalType::ANY}, // argument list
|
|
83993
|
+
LogicalType::BOOLEAN, // return type
|
|
83994
|
+
ListContainsFunction, false, ListContainsBind, nullptr);
|
|
83995
|
+
}
|
|
83996
|
+
|
|
83997
|
+
ScalarFunction ListPositionFun::GetFunction() {
|
|
83998
|
+
return ScalarFunction({LogicalType::LIST(LogicalType::ANY), LogicalType::ANY}, // argument list
|
|
83999
|
+
LogicalType::INTEGER, // return type
|
|
84000
|
+
ListPositionFunction, false, ListPositionBind, nullptr);
|
|
84001
|
+
}
|
|
84002
|
+
|
|
84003
|
+
void ListContainsFun::RegisterFunction(BuiltinFunctions &set) {
|
|
84004
|
+
set.AddFunction({"list_contains", "array_contains", "list_has", "array_has"}, GetFunction());
|
|
84005
|
+
}
|
|
84006
|
+
|
|
84007
|
+
void ListPositionFun::RegisterFunction(BuiltinFunctions &set) {
|
|
84008
|
+
set.AddFunction({"list_position", "list_indexof", "array_position", "array_indexof"}, GetFunction());
|
|
84009
|
+
}
|
|
84010
|
+
} // namespace duckdb
|
|
84011
|
+
|
|
84012
|
+
|
|
83762
84013
|
//===----------------------------------------------------------------------===//
|
|
83763
84014
|
// DuckDB
|
|
83764
84015
|
//
|
|
@@ -83797,6 +84048,142 @@ public:
|
|
|
83797
84048
|
} // namespace duckdb
|
|
83798
84049
|
|
|
83799
84050
|
|
|
84051
|
+
namespace duckdb {
|
|
84052
|
+
|
|
84053
|
+
void ListFlattenFunction(DataChunk &args, ExpressionState &state, Vector &result) {
|
|
84054
|
+
D_ASSERT(args.ColumnCount() == 1);
|
|
84055
|
+
|
|
84056
|
+
Vector &input = args.data[0];
|
|
84057
|
+
if (input.GetType().id() == LogicalTypeId::SQLNULL) {
|
|
84058
|
+
result.Reference(input);
|
|
84059
|
+
return;
|
|
84060
|
+
}
|
|
84061
|
+
|
|
84062
|
+
idx_t count = args.size();
|
|
84063
|
+
|
|
84064
|
+
VectorData list_data;
|
|
84065
|
+
input.Orrify(count, list_data);
|
|
84066
|
+
auto list_entries = (list_entry_t *)list_data.data;
|
|
84067
|
+
|
|
84068
|
+
auto &child_vector = ListVector::GetEntry(input);
|
|
84069
|
+
|
|
84070
|
+
result.SetVectorType(VectorType::FLAT_VECTOR);
|
|
84071
|
+
auto result_entries = FlatVector::GetData<list_entry_t>(result);
|
|
84072
|
+
auto &result_validity = FlatVector::Validity(result);
|
|
84073
|
+
|
|
84074
|
+
if (child_vector.GetType().id() == LogicalTypeId::SQLNULL) {
|
|
84075
|
+
auto result_entries = FlatVector::GetData<list_entry_t>(result);
|
|
84076
|
+
for (idx_t i = 0; i < count; i++) {
|
|
84077
|
+
auto list_index = list_data.sel->get_index(i);
|
|
84078
|
+
if (!list_data.validity.RowIsValid(list_index)) {
|
|
84079
|
+
result_validity.SetInvalid(i);
|
|
84080
|
+
continue;
|
|
84081
|
+
}
|
|
84082
|
+
result_entries[i].offset = 0;
|
|
84083
|
+
result_entries[i].length = 0;
|
|
84084
|
+
}
|
|
84085
|
+
return;
|
|
84086
|
+
}
|
|
84087
|
+
|
|
84088
|
+
auto child_size = ListVector::GetListSize(input);
|
|
84089
|
+
VectorData child_data;
|
|
84090
|
+
child_vector.Orrify(child_size, child_data);
|
|
84091
|
+
auto child_entries = (list_entry_t *)child_data.data;
|
|
84092
|
+
auto &data_vector = ListVector::GetEntry(child_vector);
|
|
84093
|
+
|
|
84094
|
+
idx_t offset = 0;
|
|
84095
|
+
for (idx_t i = 0; i < count; i++) {
|
|
84096
|
+
auto list_index = list_data.sel->get_index(i);
|
|
84097
|
+
if (!list_data.validity.RowIsValid(list_index)) {
|
|
84098
|
+
result_validity.SetInvalid(i);
|
|
84099
|
+
continue;
|
|
84100
|
+
}
|
|
84101
|
+
auto list_entry = list_entries[list_index];
|
|
84102
|
+
|
|
84103
|
+
idx_t source_offset = 0;
|
|
84104
|
+
// Find first valid child list entry to get offset
|
|
84105
|
+
for (idx_t j = 0; j < list_entry.length; j++) {
|
|
84106
|
+
auto child_list_index = child_data.sel->get_index(list_entry.offset + j);
|
|
84107
|
+
if (child_data.validity.RowIsValid(child_list_index)) {
|
|
84108
|
+
source_offset = child_entries[child_list_index].offset;
|
|
84109
|
+
break;
|
|
84110
|
+
}
|
|
84111
|
+
}
|
|
84112
|
+
|
|
84113
|
+
idx_t length = 0;
|
|
84114
|
+
// Find last valid child list entry to get length
|
|
84115
|
+
for (idx_t j = list_entry.length - 1; j != (idx_t)-1; j--) {
|
|
84116
|
+
auto child_list_index = child_data.sel->get_index(list_entry.offset + j);
|
|
84117
|
+
if (child_data.validity.RowIsValid(child_list_index)) {
|
|
84118
|
+
auto child_entry = child_entries[child_list_index];
|
|
84119
|
+
length = child_entry.offset + child_entry.length - source_offset;
|
|
84120
|
+
break;
|
|
84121
|
+
}
|
|
84122
|
+
}
|
|
84123
|
+
ListVector::Append(result, data_vector, source_offset + length, source_offset);
|
|
84124
|
+
|
|
84125
|
+
result_entries[i].offset = offset;
|
|
84126
|
+
result_entries[i].length = length;
|
|
84127
|
+
offset += length;
|
|
84128
|
+
}
|
|
84129
|
+
|
|
84130
|
+
if (input.GetVectorType() == VectorType::CONSTANT_VECTOR) {
|
|
84131
|
+
result.SetVectorType(VectorType::CONSTANT_VECTOR);
|
|
84132
|
+
}
|
|
84133
|
+
}
|
|
84134
|
+
|
|
84135
|
+
static unique_ptr<FunctionData> ListFlattenBind(ClientContext &context, ScalarFunction &bound_function,
|
|
84136
|
+
vector<unique_ptr<Expression>> &arguments) {
|
|
84137
|
+
D_ASSERT(bound_function.arguments.size() == 1);
|
|
84138
|
+
|
|
84139
|
+
auto &input_type = arguments[0]->return_type;
|
|
84140
|
+
bound_function.arguments[0] = input_type;
|
|
84141
|
+
if (input_type.id() == LogicalTypeId::SQLNULL) {
|
|
84142
|
+
bound_function.return_type = LogicalType(LogicalTypeId::SQLNULL);
|
|
84143
|
+
return make_unique<VariableReturnBindData>(bound_function.return_type);
|
|
84144
|
+
}
|
|
84145
|
+
D_ASSERT(input_type.id() == LogicalTypeId::LIST);
|
|
84146
|
+
|
|
84147
|
+
auto child_type = ListType::GetChildType(input_type);
|
|
84148
|
+
if (child_type.id() == LogicalType::SQLNULL) {
|
|
84149
|
+
bound_function.return_type = input_type;
|
|
84150
|
+
return make_unique<VariableReturnBindData>(bound_function.return_type);
|
|
84151
|
+
}
|
|
84152
|
+
D_ASSERT(child_type.id() == LogicalTypeId::LIST);
|
|
84153
|
+
|
|
84154
|
+
bound_function.return_type = child_type;
|
|
84155
|
+
return make_unique<VariableReturnBindData>(bound_function.return_type);
|
|
84156
|
+
}
|
|
84157
|
+
|
|
84158
|
+
static unique_ptr<BaseStatistics> ListFlattenStats(ClientContext &context, BoundFunctionExpression &expr,
|
|
84159
|
+
FunctionData *bind_data,
|
|
84160
|
+
vector<unique_ptr<BaseStatistics>> &child_stats) {
|
|
84161
|
+
if (!child_stats[0]) {
|
|
84162
|
+
return nullptr;
|
|
84163
|
+
}
|
|
84164
|
+
auto &list_stats = (ListStatistics &)*child_stats[0];
|
|
84165
|
+
if (!list_stats.child_stats || list_stats.child_stats->type == LogicalTypeId::SQLNULL) {
|
|
84166
|
+
return nullptr;
|
|
84167
|
+
}
|
|
84168
|
+
|
|
84169
|
+
auto child_copy = list_stats.child_stats->Copy();
|
|
84170
|
+
child_copy->validity_stats = make_unique<ValidityStatistics>(true);
|
|
84171
|
+
return child_copy;
|
|
84172
|
+
}
|
|
84173
|
+
|
|
84174
|
+
void ListFlattenFun::RegisterFunction(BuiltinFunctions &set) {
|
|
84175
|
+
ScalarFunction fun({LogicalType::LIST(LogicalType::LIST(LogicalType::ANY))}, LogicalType::LIST(LogicalType::ANY),
|
|
84176
|
+
ListFlattenFunction, false, ListFlattenBind, nullptr, ListFlattenStats);
|
|
84177
|
+
set.AddFunction({"flatten"}, fun);
|
|
84178
|
+
}
|
|
84179
|
+
|
|
84180
|
+
} // namespace duckdb
|
|
84181
|
+
|
|
84182
|
+
|
|
84183
|
+
|
|
84184
|
+
|
|
84185
|
+
|
|
84186
|
+
|
|
83800
84187
|
|
|
83801
84188
|
namespace duckdb {
|
|
83802
84189
|
|
|
@@ -83931,226 +84318,6 @@ void ListConcatFun::RegisterFunction(BuiltinFunctions &set) {
|
|
|
83931
84318
|
|
|
83932
84319
|
|
|
83933
84320
|
|
|
83934
|
-
namespace duckdb {
|
|
83935
|
-
|
|
83936
|
-
template <class T>
|
|
83937
|
-
static inline bool ValueCompare(const T &left, const T &right) {
|
|
83938
|
-
return left == right;
|
|
83939
|
-
}
|
|
83940
|
-
|
|
83941
|
-
template <>
|
|
83942
|
-
inline bool ValueCompare(const string_t &left, const string_t &right) {
|
|
83943
|
-
return StringComparisonOperators::EqualsOrNot<false>(left, right);
|
|
83944
|
-
}
|
|
83945
|
-
|
|
83946
|
-
template <>
|
|
83947
|
-
inline bool ValueCompare(const Value &left, const Value &right) {
|
|
83948
|
-
return left == right;
|
|
83949
|
-
}
|
|
83950
|
-
|
|
83951
|
-
template <class T>
|
|
83952
|
-
static void TemplatedListContainsFunction(DataChunk &args, ExpressionState &state, Vector &result) {
|
|
83953
|
-
D_ASSERT(args.ColumnCount() == 2);
|
|
83954
|
-
auto count = args.size();
|
|
83955
|
-
Vector &list = args.data[0];
|
|
83956
|
-
Vector &value_vector = args.data[1];
|
|
83957
|
-
|
|
83958
|
-
result.SetVectorType(VectorType::FLAT_VECTOR);
|
|
83959
|
-
auto result_entries = FlatVector::GetData<bool>(result); // Create a vector of bool
|
|
83960
|
-
auto &result_validity = FlatVector::Validity(result);
|
|
83961
|
-
|
|
83962
|
-
if (list.GetType().id() == LogicalTypeId::SQLNULL) {
|
|
83963
|
-
result_validity.SetInvalid(0);
|
|
83964
|
-
return;
|
|
83965
|
-
}
|
|
83966
|
-
|
|
83967
|
-
auto list_size = ListVector::GetListSize(list);
|
|
83968
|
-
auto &child_vector = ListVector::GetEntry(list);
|
|
83969
|
-
|
|
83970
|
-
VectorData child_data;
|
|
83971
|
-
child_vector.Orrify(list_size, child_data);
|
|
83972
|
-
|
|
83973
|
-
VectorData list_data;
|
|
83974
|
-
list.Orrify(count, list_data);
|
|
83975
|
-
auto list_entries = (list_entry_t *)list_data.data;
|
|
83976
|
-
|
|
83977
|
-
VectorData value_data;
|
|
83978
|
-
value_vector.Orrify(count, value_data);
|
|
83979
|
-
|
|
83980
|
-
for (idx_t i = 0; i < count; i++) {
|
|
83981
|
-
auto list_index = list_data.sel->get_index(i);
|
|
83982
|
-
auto value_index = value_data.sel->get_index(i);
|
|
83983
|
-
|
|
83984
|
-
if (!list_data.validity.RowIsValid(list_index) || !value_data.validity.RowIsValid(value_index)) {
|
|
83985
|
-
result_validity.SetInvalid(i);
|
|
83986
|
-
continue;
|
|
83987
|
-
}
|
|
83988
|
-
|
|
83989
|
-
const auto &list_entry = list_entries[list_index];
|
|
83990
|
-
auto source_idx = child_data.sel->get_index(list_entry.offset);
|
|
83991
|
-
auto child_value = FlatVector::GetData<T>(child_vector);
|
|
83992
|
-
|
|
83993
|
-
auto values = FlatVector::GetData<T>(value_vector);
|
|
83994
|
-
result_entries[list_index] = false;
|
|
83995
|
-
for (idx_t child_idx = 0; child_idx < list_entry.length; child_idx++) {
|
|
83996
|
-
auto child_value_idx = source_idx + child_idx;
|
|
83997
|
-
|
|
83998
|
-
if (!child_data.validity.RowIsValid(child_value_idx)) {
|
|
83999
|
-
continue;
|
|
84000
|
-
}
|
|
84001
|
-
if (ValueCompare<T>(child_value[child_value_idx], values[value_index])) {
|
|
84002
|
-
result_entries[list_index] = true;
|
|
84003
|
-
break; // Found value in list, no need to look further
|
|
84004
|
-
}
|
|
84005
|
-
}
|
|
84006
|
-
}
|
|
84007
|
-
}
|
|
84008
|
-
|
|
84009
|
-
static void NestedListContainsFunction(DataChunk &args, ExpressionState &state, Vector &result) {
|
|
84010
|
-
D_ASSERT(args.ColumnCount() == 2);
|
|
84011
|
-
auto count = args.size();
|
|
84012
|
-
Vector &list = args.data[0];
|
|
84013
|
-
Vector &value_vector = args.data[1];
|
|
84014
|
-
|
|
84015
|
-
result.SetVectorType(VectorType::FLAT_VECTOR);
|
|
84016
|
-
auto result_entries = FlatVector::GetData<bool>(result); // Create a vector of bool
|
|
84017
|
-
auto &result_validity = FlatVector::Validity(result);
|
|
84018
|
-
|
|
84019
|
-
if (list.GetType().id() == LogicalTypeId::SQLNULL) {
|
|
84020
|
-
result_validity.SetInvalid(0);
|
|
84021
|
-
return;
|
|
84022
|
-
}
|
|
84023
|
-
|
|
84024
|
-
auto list_size = ListVector::GetListSize(list);
|
|
84025
|
-
auto &child_vector = ListVector::GetEntry(list);
|
|
84026
|
-
|
|
84027
|
-
VectorData child_data;
|
|
84028
|
-
child_vector.Orrify(list_size, child_data);
|
|
84029
|
-
|
|
84030
|
-
VectorData list_data;
|
|
84031
|
-
list.Orrify(count, list_data);
|
|
84032
|
-
auto list_entries = (list_entry_t *)list_data.data;
|
|
84033
|
-
|
|
84034
|
-
VectorData value_data;
|
|
84035
|
-
value_vector.Orrify(count, value_data);
|
|
84036
|
-
|
|
84037
|
-
for (idx_t i = 0; i < count; i++) {
|
|
84038
|
-
auto list_index = list_data.sel->get_index(i);
|
|
84039
|
-
auto value_index = value_data.sel->get_index(i);
|
|
84040
|
-
|
|
84041
|
-
if (!list_data.validity.RowIsValid(list_index) || !value_data.validity.RowIsValid(value_index)) {
|
|
84042
|
-
result_validity.SetInvalid(i);
|
|
84043
|
-
continue;
|
|
84044
|
-
}
|
|
84045
|
-
|
|
84046
|
-
const auto &list_entry = list_entries[list_index];
|
|
84047
|
-
auto source_idx = child_data.sel->get_index(list_entry.offset);
|
|
84048
|
-
|
|
84049
|
-
result_entries[list_index] = false;
|
|
84050
|
-
for (idx_t child_idx = 0; child_idx < list_entry.length; child_idx++) {
|
|
84051
|
-
auto child_value_idx = source_idx + child_idx;
|
|
84052
|
-
if (!child_data.validity.RowIsValid(child_value_idx)) {
|
|
84053
|
-
continue;
|
|
84054
|
-
}
|
|
84055
|
-
if (ValueCompare<Value>(child_vector.GetValue(child_value_idx), value_vector.GetValue(value_index))) {
|
|
84056
|
-
result_entries[list_index] = true;
|
|
84057
|
-
break; // Found value in list, no need to look further
|
|
84058
|
-
}
|
|
84059
|
-
}
|
|
84060
|
-
}
|
|
84061
|
-
}
|
|
84062
|
-
|
|
84063
|
-
static void ListContainsFunction(DataChunk &args, ExpressionState &state, Vector &result) {
|
|
84064
|
-
switch (args.data[1].GetType().InternalType()) {
|
|
84065
|
-
case PhysicalType::BOOL:
|
|
84066
|
-
case PhysicalType::INT8:
|
|
84067
|
-
TemplatedListContainsFunction<int8_t>(args, state, result);
|
|
84068
|
-
break;
|
|
84069
|
-
case PhysicalType::INT16:
|
|
84070
|
-
TemplatedListContainsFunction<int16_t>(args, state, result);
|
|
84071
|
-
break;
|
|
84072
|
-
case PhysicalType::INT32:
|
|
84073
|
-
TemplatedListContainsFunction<int32_t>(args, state, result);
|
|
84074
|
-
break;
|
|
84075
|
-
case PhysicalType::INT64:
|
|
84076
|
-
TemplatedListContainsFunction<int64_t>(args, state, result);
|
|
84077
|
-
break;
|
|
84078
|
-
case PhysicalType::INT128:
|
|
84079
|
-
TemplatedListContainsFunction<hugeint_t>(args, state, result);
|
|
84080
|
-
break;
|
|
84081
|
-
case PhysicalType::UINT8:
|
|
84082
|
-
TemplatedListContainsFunction<uint8_t>(args, state, result);
|
|
84083
|
-
break;
|
|
84084
|
-
case PhysicalType::UINT16:
|
|
84085
|
-
TemplatedListContainsFunction<uint16_t>(args, state, result);
|
|
84086
|
-
break;
|
|
84087
|
-
case PhysicalType::UINT32:
|
|
84088
|
-
TemplatedListContainsFunction<uint32_t>(args, state, result);
|
|
84089
|
-
break;
|
|
84090
|
-
case PhysicalType::UINT64:
|
|
84091
|
-
TemplatedListContainsFunction<uint64_t>(args, state, result);
|
|
84092
|
-
break;
|
|
84093
|
-
case PhysicalType::FLOAT:
|
|
84094
|
-
TemplatedListContainsFunction<float>(args, state, result);
|
|
84095
|
-
break;
|
|
84096
|
-
case PhysicalType::DOUBLE:
|
|
84097
|
-
TemplatedListContainsFunction<double>(args, state, result);
|
|
84098
|
-
break;
|
|
84099
|
-
case PhysicalType::VARCHAR:
|
|
84100
|
-
TemplatedListContainsFunction<string_t>(args, state, result);
|
|
84101
|
-
break;
|
|
84102
|
-
case PhysicalType::MAP:
|
|
84103
|
-
case PhysicalType::STRUCT:
|
|
84104
|
-
case PhysicalType::LIST:
|
|
84105
|
-
NestedListContainsFunction(args, state, result);
|
|
84106
|
-
break;
|
|
84107
|
-
default:
|
|
84108
|
-
throw NotImplementedException("This function has not been implemented for this type");
|
|
84109
|
-
}
|
|
84110
|
-
}
|
|
84111
|
-
|
|
84112
|
-
static unique_ptr<FunctionData> ListContainsBind(ClientContext &context, ScalarFunction &bound_function,
|
|
84113
|
-
vector<unique_ptr<Expression>> &arguments) {
|
|
84114
|
-
D_ASSERT(bound_function.arguments.size() == 2);
|
|
84115
|
-
|
|
84116
|
-
const auto &list = arguments[0]->return_type; // change to list
|
|
84117
|
-
const auto &value = arguments[1]->return_type;
|
|
84118
|
-
if (list.id() == LogicalTypeId::SQLNULL && value.id() == LogicalTypeId::SQLNULL) {
|
|
84119
|
-
bound_function.arguments[0] = LogicalType::SQLNULL;
|
|
84120
|
-
bound_function.arguments[1] = LogicalType::SQLNULL;
|
|
84121
|
-
bound_function.return_type = LogicalType::SQLNULL;
|
|
84122
|
-
} else if (list.id() == LogicalTypeId::SQLNULL || value.id() == LogicalTypeId::SQLNULL) {
|
|
84123
|
-
// In case either the list or the value is NULL, return NULL
|
|
84124
|
-
// Similar to behaviour of prestoDB
|
|
84125
|
-
bound_function.arguments[0] = list;
|
|
84126
|
-
bound_function.arguments[1] = value;
|
|
84127
|
-
bound_function.return_type = LogicalTypeId::SQLNULL;
|
|
84128
|
-
} else {
|
|
84129
|
-
auto const &child_type = ListType::GetChildType(arguments[0]->return_type);
|
|
84130
|
-
auto max_child_type = LogicalType::MaxLogicalType(child_type, value);
|
|
84131
|
-
ExpressionBinder::ResolveParameterType(max_child_type);
|
|
84132
|
-
auto list_type = LogicalType::LIST(max_child_type);
|
|
84133
|
-
|
|
84134
|
-
bound_function.arguments[0] = list_type;
|
|
84135
|
-
bound_function.arguments[1] = value == max_child_type ? value : max_child_type;
|
|
84136
|
-
bound_function.return_type = LogicalType::BOOLEAN;
|
|
84137
|
-
}
|
|
84138
|
-
return make_unique<VariableReturnBindData>(bound_function.return_type);
|
|
84139
|
-
}
|
|
84140
|
-
|
|
84141
|
-
ScalarFunction ListContainsFun::GetFunction() {
|
|
84142
|
-
return ScalarFunction({LogicalType::LIST(LogicalType::ANY), LogicalType::ANY}, // argument list
|
|
84143
|
-
LogicalType::BOOLEAN, // return type
|
|
84144
|
-
ListContainsFunction, false, ListContainsBind, nullptr);
|
|
84145
|
-
}
|
|
84146
|
-
|
|
84147
|
-
void ListContainsFun::RegisterFunction(BuiltinFunctions &set) {
|
|
84148
|
-
set.AddFunction({"list_contains", "array_contains", "list_has", "array_has"}, GetFunction());
|
|
84149
|
-
}
|
|
84150
|
-
} // namespace duckdb
|
|
84151
|
-
|
|
84152
|
-
|
|
84153
|
-
|
|
84154
84321
|
|
|
84155
84322
|
|
|
84156
84323
|
|
|
@@ -86202,9 +86369,11 @@ void BuiltinFunctions::RegisterNestedFunctions() {
|
|
|
86202
86369
|
Register<StructExtractFun>();
|
|
86203
86370
|
Register<ListConcatFun>();
|
|
86204
86371
|
Register<ListContainsFun>();
|
|
86372
|
+
Register<ListPositionFun>();
|
|
86205
86373
|
Register<ListValueFun>();
|
|
86206
86374
|
Register<ListExtractFun>();
|
|
86207
86375
|
Register<ListRangeFun>();
|
|
86376
|
+
Register<ListFlattenFun>();
|
|
86208
86377
|
Register<MapFun>();
|
|
86209
86378
|
Register<MapExtractFun>();
|
|
86210
86379
|
Register<CardinalityFun>();
|
|
@@ -104282,7 +104451,7 @@ class SelectStatement;
|
|
|
104282
104451
|
|
|
104283
104452
|
class QueryRelation : public Relation {
|
|
104284
104453
|
public:
|
|
104285
|
-
QueryRelation(ClientContext &context, unique_ptr<SelectStatement> select_stmt, string alias);
|
|
104454
|
+
QueryRelation(const std::shared_ptr<ClientContext> &context, unique_ptr<SelectStatement> select_stmt, string alias);
|
|
104286
104455
|
~QueryRelation();
|
|
104287
104456
|
|
|
104288
104457
|
unique_ptr<SelectStatement> select_stmt;
|
|
@@ -104320,8 +104489,8 @@ namespace duckdb {
|
|
|
104320
104489
|
|
|
104321
104490
|
class ReadCSVRelation : public Relation {
|
|
104322
104491
|
public:
|
|
104323
|
-
ReadCSVRelation(ClientContext &context, string csv_file, vector<ColumnDefinition> columns,
|
|
104324
|
-
string alias = string());
|
|
104492
|
+
ReadCSVRelation(const std::shared_ptr<ClientContext> &context, string csv_file, vector<ColumnDefinition> columns,
|
|
104493
|
+
bool auto_detect = false, string alias = string());
|
|
104325
104494
|
|
|
104326
104495
|
string csv_file;
|
|
104327
104496
|
bool auto_detect;
|
|
@@ -104355,7 +104524,7 @@ namespace duckdb {
|
|
|
104355
104524
|
|
|
104356
104525
|
class TableRelation : public Relation {
|
|
104357
104526
|
public:
|
|
104358
|
-
TableRelation(ClientContext &context, unique_ptr<TableDescription> description);
|
|
104527
|
+
TableRelation(const std::shared_ptr<ClientContext> &context, unique_ptr<TableDescription> description);
|
|
104359
104528
|
|
|
104360
104529
|
unique_ptr<TableDescription> description;
|
|
104361
104530
|
|
|
@@ -104390,10 +104559,10 @@ namespace duckdb {
|
|
|
104390
104559
|
|
|
104391
104560
|
class TableFunctionRelation : public Relation {
|
|
104392
104561
|
public:
|
|
104393
|
-
TableFunctionRelation(ClientContext &context, string name, vector<Value> parameters,
|
|
104562
|
+
TableFunctionRelation(const std::shared_ptr<ClientContext> &context, string name, vector<Value> parameters,
|
|
104394
104563
|
named_parameter_map_t named_parameters, shared_ptr<Relation> input_relation_p = nullptr);
|
|
104395
104564
|
|
|
104396
|
-
TableFunctionRelation(ClientContext &context, string name, vector<Value> parameters,
|
|
104565
|
+
TableFunctionRelation(const std::shared_ptr<ClientContext> &context, string name, vector<Value> parameters,
|
|
104397
104566
|
shared_ptr<Relation> input_relation_p = nullptr);
|
|
104398
104567
|
|
|
104399
104568
|
string name;
|
|
@@ -104430,9 +104599,10 @@ namespace duckdb {
|
|
|
104430
104599
|
|
|
104431
104600
|
class ValueRelation : public Relation {
|
|
104432
104601
|
public:
|
|
104433
|
-
ValueRelation(ClientContext &context, const vector<vector<Value>> &values,
|
|
104602
|
+
ValueRelation(const std::shared_ptr<ClientContext> &context, const vector<vector<Value>> &values,
|
|
104603
|
+
vector<string> names, string alias = "values");
|
|
104604
|
+
ValueRelation(const std::shared_ptr<ClientContext> &context, const string &values, vector<string> names,
|
|
104434
104605
|
string alias = "values");
|
|
104435
|
-
ValueRelation(ClientContext &context, const string &values, vector<string> names, string alias = "values");
|
|
104436
104606
|
|
|
104437
104607
|
vector<vector<unique_ptr<ParsedExpression>>> expressions;
|
|
104438
104608
|
vector<string> names;
|
|
@@ -104467,7 +104637,7 @@ namespace duckdb {
|
|
|
104467
104637
|
|
|
104468
104638
|
class ViewRelation : public Relation {
|
|
104469
104639
|
public:
|
|
104470
|
-
ViewRelation(ClientContext &context, string schema_name, string view_name);
|
|
104640
|
+
ViewRelation(const std::shared_ptr<ClientContext> &context, string schema_name, string view_name);
|
|
104471
104641
|
|
|
104472
104642
|
string schema_name;
|
|
104473
104643
|
string view_name;
|
|
@@ -104662,7 +104832,7 @@ shared_ptr<Relation> Connection::Table(const string &schema_name, const string &
|
|
|
104662
104832
|
if (!table_info) {
|
|
104663
104833
|
throw Exception("Table does not exist!");
|
|
104664
104834
|
}
|
|
104665
|
-
return make_shared<TableRelation>(
|
|
104835
|
+
return make_shared<TableRelation>(context, move(table_info));
|
|
104666
104836
|
}
|
|
104667
104837
|
|
|
104668
104838
|
shared_ptr<Relation> Connection::View(const string &tname) {
|
|
@@ -104670,7 +104840,7 @@ shared_ptr<Relation> Connection::View(const string &tname) {
|
|
|
104670
104840
|
}
|
|
104671
104841
|
|
|
104672
104842
|
shared_ptr<Relation> Connection::View(const string &schema_name, const string &table_name) {
|
|
104673
|
-
return make_shared<ViewRelation>(
|
|
104843
|
+
return make_shared<ViewRelation>(context, schema_name, table_name);
|
|
104674
104844
|
}
|
|
104675
104845
|
|
|
104676
104846
|
shared_ptr<Relation> Connection::TableFunction(const string &fname) {
|
|
@@ -104681,11 +104851,11 @@ shared_ptr<Relation> Connection::TableFunction(const string &fname) {
|
|
|
104681
104851
|
|
|
104682
104852
|
shared_ptr<Relation> Connection::TableFunction(const string &fname, const vector<Value> &values,
|
|
104683
104853
|
const named_parameter_map_t &named_parameters) {
|
|
104684
|
-
return make_shared<TableFunctionRelation>(
|
|
104854
|
+
return make_shared<TableFunctionRelation>(context, fname, values, named_parameters);
|
|
104685
104855
|
}
|
|
104686
104856
|
|
|
104687
104857
|
shared_ptr<Relation> Connection::TableFunction(const string &fname, const vector<Value> &values) {
|
|
104688
|
-
return make_shared<TableFunctionRelation>(
|
|
104858
|
+
return make_shared<TableFunctionRelation>(context, fname, values);
|
|
104689
104859
|
}
|
|
104690
104860
|
|
|
104691
104861
|
shared_ptr<Relation> Connection::Values(const vector<vector<Value>> &values) {
|
|
@@ -104695,7 +104865,7 @@ shared_ptr<Relation> Connection::Values(const vector<vector<Value>> &values) {
|
|
|
104695
104865
|
|
|
104696
104866
|
shared_ptr<Relation> Connection::Values(const vector<vector<Value>> &values, const vector<string> &column_names,
|
|
104697
104867
|
const string &alias) {
|
|
104698
|
-
return make_shared<ValueRelation>(
|
|
104868
|
+
return make_shared<ValueRelation>(context, values, column_names, alias);
|
|
104699
104869
|
}
|
|
104700
104870
|
|
|
104701
104871
|
shared_ptr<Relation> Connection::Values(const string &values) {
|
|
@@ -104704,7 +104874,7 @@ shared_ptr<Relation> Connection::Values(const string &values) {
|
|
|
104704
104874
|
}
|
|
104705
104875
|
|
|
104706
104876
|
shared_ptr<Relation> Connection::Values(const string &values, const vector<string> &column_names, const string &alias) {
|
|
104707
|
-
return make_shared<ValueRelation>(
|
|
104877
|
+
return make_shared<ValueRelation>(context, values, column_names, alias);
|
|
104708
104878
|
}
|
|
104709
104879
|
|
|
104710
104880
|
shared_ptr<Relation> Connection::ReadCSV(const string &csv_file) {
|
|
@@ -104716,7 +104886,7 @@ shared_ptr<Relation> Connection::ReadCSV(const string &csv_file) {
|
|
|
104716
104886
|
for (idx_t i = 0; i < reader.sql_types.size(); i++) {
|
|
104717
104887
|
column_list.emplace_back(reader.col_names[i], reader.sql_types[i]);
|
|
104718
104888
|
}
|
|
104719
|
-
return make_shared<ReadCSVRelation>(
|
|
104889
|
+
return make_shared<ReadCSVRelation>(context, csv_file, move(column_list), true);
|
|
104720
104890
|
}
|
|
104721
104891
|
|
|
104722
104892
|
shared_ptr<Relation> Connection::ReadCSV(const string &csv_file, const vector<string> &columns) {
|
|
@@ -104729,19 +104899,19 @@ shared_ptr<Relation> Connection::ReadCSV(const string &csv_file, const vector<st
|
|
|
104729
104899
|
}
|
|
104730
104900
|
column_list.push_back(move(col_list[0]));
|
|
104731
104901
|
}
|
|
104732
|
-
return make_shared<ReadCSVRelation>(
|
|
104902
|
+
return make_shared<ReadCSVRelation>(context, csv_file, move(column_list));
|
|
104733
104903
|
}
|
|
104734
104904
|
|
|
104735
104905
|
unordered_set<string> Connection::GetTableNames(const string &query) {
|
|
104736
104906
|
return context->GetTableNames(query);
|
|
104737
104907
|
}
|
|
104738
104908
|
|
|
104739
|
-
shared_ptr<Relation> Connection::RelationFromQuery(const string &query, string alias, const string &error) {
|
|
104740
|
-
return RelationFromQuery(QueryRelation::ParseStatement(*context, query, error),
|
|
104909
|
+
shared_ptr<Relation> Connection::RelationFromQuery(const string &query, const string &alias, const string &error) {
|
|
104910
|
+
return RelationFromQuery(QueryRelation::ParseStatement(*context, query, error), alias);
|
|
104741
104911
|
}
|
|
104742
104912
|
|
|
104743
|
-
shared_ptr<Relation> Connection::RelationFromQuery(unique_ptr<SelectStatement> select_stmt, string alias) {
|
|
104744
|
-
return make_shared<QueryRelation>(
|
|
104913
|
+
shared_ptr<Relation> Connection::RelationFromQuery(unique_ptr<SelectStatement> select_stmt, const string &alias) {
|
|
104914
|
+
return make_shared<QueryRelation>(context, move(select_stmt), alias);
|
|
104745
104915
|
}
|
|
104746
104916
|
|
|
104747
104917
|
void Connection::BeginTransaction() {
|
|
@@ -114959,7 +115129,7 @@ AggregateRelation::AggregateRelation(shared_ptr<Relation> child_p,
|
|
|
114959
115129
|
: Relation(child_p->context, RelationType::AGGREGATE_RELATION), expressions(move(parsed_expressions)),
|
|
114960
115130
|
child(move(child_p)) {
|
|
114961
115131
|
// bind the expressions
|
|
114962
|
-
context.TryBindRelation(*this, this->columns);
|
|
115132
|
+
context.GetContext()->TryBindRelation(*this, this->columns);
|
|
114963
115133
|
}
|
|
114964
115134
|
|
|
114965
115135
|
AggregateRelation::AggregateRelation(shared_ptr<Relation> child_p,
|
|
@@ -114968,7 +115138,7 @@ AggregateRelation::AggregateRelation(shared_ptr<Relation> child_p,
|
|
|
114968
115138
|
: Relation(child_p->context, RelationType::AGGREGATE_RELATION), expressions(move(parsed_expressions)),
|
|
114969
115139
|
groups(move(groups_p)), child(move(child_p)) {
|
|
114970
115140
|
// bind the expressions
|
|
114971
|
-
context.TryBindRelation(*this, this->columns);
|
|
115141
|
+
context.GetContext()->TryBindRelation(*this, this->columns);
|
|
114972
115142
|
}
|
|
114973
115143
|
|
|
114974
115144
|
unique_ptr<QueryNode> AggregateRelation::GetQueryNode() {
|
|
@@ -115104,7 +115274,7 @@ namespace duckdb {
|
|
|
115104
115274
|
CreateTableRelation::CreateTableRelation(shared_ptr<Relation> child_p, string schema_name, string table_name)
|
|
115105
115275
|
: Relation(child_p->context, RelationType::CREATE_TABLE_RELATION), child(move(child_p)),
|
|
115106
115276
|
schema_name(move(schema_name)), table_name(move(table_name)) {
|
|
115107
|
-
context.TryBindRelation(*this, this->columns);
|
|
115277
|
+
context.GetContext()->TryBindRelation(*this, this->columns);
|
|
115108
115278
|
}
|
|
115109
115279
|
|
|
115110
115280
|
BoundStatement CreateTableRelation::Bind(Binder &binder) {
|
|
@@ -115177,7 +115347,7 @@ CreateViewRelation::CreateViewRelation(shared_ptr<Relation> child_p, string view
|
|
|
115177
115347
|
bool temporary_p)
|
|
115178
115348
|
: Relation(child_p->context, RelationType::CREATE_VIEW_RELATION), child(move(child_p)),
|
|
115179
115349
|
view_name(move(view_name_p)), replace(replace_p), temporary(temporary_p) {
|
|
115180
|
-
context.TryBindRelation(*this, this->columns);
|
|
115350
|
+
context.GetContext()->TryBindRelation(*this, this->columns);
|
|
115181
115351
|
}
|
|
115182
115352
|
|
|
115183
115353
|
BoundStatement CreateViewRelation::Bind(Binder &binder) {
|
|
@@ -115247,10 +115417,10 @@ namespace duckdb {
|
|
|
115247
115417
|
|
|
115248
115418
|
CrossProductRelation::CrossProductRelation(shared_ptr<Relation> left_p, shared_ptr<Relation> right_p)
|
|
115249
115419
|
: Relation(left_p->context, RelationType::CROSS_PRODUCT_RELATION), left(move(left_p)), right(move(right_p)) {
|
|
115250
|
-
if (
|
|
115420
|
+
if (left->context.GetContext() != right->context.GetContext()) {
|
|
115251
115421
|
throw Exception("Cannot combine LEFT and RIGHT relations of different connections!");
|
|
115252
115422
|
}
|
|
115253
|
-
context.TryBindRelation(*this, this->columns);
|
|
115423
|
+
context.GetContext()->TryBindRelation(*this, this->columns);
|
|
115254
115424
|
}
|
|
115255
115425
|
|
|
115256
115426
|
unique_ptr<QueryNode> CrossProductRelation::GetQueryNode() {
|
|
@@ -115295,7 +115465,7 @@ namespace duckdb {
|
|
|
115295
115465
|
|
|
115296
115466
|
class DeleteRelation : public Relation {
|
|
115297
115467
|
public:
|
|
115298
|
-
DeleteRelation(
|
|
115468
|
+
DeleteRelation(ClientContextWrapper &context, unique_ptr<ParsedExpression> condition, string schema_name,
|
|
115299
115469
|
string table_name);
|
|
115300
115470
|
|
|
115301
115471
|
vector<ColumnDefinition> columns;
|
|
@@ -115353,11 +115523,11 @@ public:
|
|
|
115353
115523
|
|
|
115354
115524
|
namespace duckdb {
|
|
115355
115525
|
|
|
115356
|
-
DeleteRelation::DeleteRelation(
|
|
115357
|
-
string table_name_p)
|
|
115526
|
+
DeleteRelation::DeleteRelation(ClientContextWrapper &context, unique_ptr<ParsedExpression> condition_p,
|
|
115527
|
+
string schema_name_p, string table_name_p)
|
|
115358
115528
|
: Relation(context, RelationType::DELETE_RELATION), condition(move(condition_p)), schema_name(move(schema_name_p)),
|
|
115359
115529
|
table_name(move(table_name_p)) {
|
|
115360
|
-
context.TryBindRelation(*this, this->columns);
|
|
115530
|
+
context.GetContext()->TryBindRelation(*this, this->columns);
|
|
115361
115531
|
}
|
|
115362
115532
|
|
|
115363
115533
|
BoundStatement DeleteRelation::Bind(Binder &binder) {
|
|
@@ -115430,7 +115600,7 @@ namespace duckdb {
|
|
|
115430
115600
|
DistinctRelation::DistinctRelation(shared_ptr<Relation> child_p)
|
|
115431
115601
|
: Relation(child_p->context, RelationType::DISTINCT_RELATION), child(move(child_p)) {
|
|
115432
115602
|
vector<ColumnDefinition> dummy_columns;
|
|
115433
|
-
context.TryBindRelation(*this, dummy_columns);
|
|
115603
|
+
context.GetContext()->TryBindRelation(*this, dummy_columns);
|
|
115434
115604
|
}
|
|
115435
115605
|
|
|
115436
115606
|
unique_ptr<QueryNode> DistinctRelation::GetQueryNode() {
|
|
@@ -115496,7 +115666,7 @@ namespace duckdb {
|
|
|
115496
115666
|
|
|
115497
115667
|
ExplainRelation::ExplainRelation(shared_ptr<Relation> child_p)
|
|
115498
115668
|
: Relation(child_p->context, RelationType::EXPLAIN_RELATION), child(move(child_p)) {
|
|
115499
|
-
context.TryBindRelation(*this, this->columns);
|
|
115669
|
+
context.GetContext()->TryBindRelation(*this, this->columns);
|
|
115500
115670
|
}
|
|
115501
115671
|
|
|
115502
115672
|
BoundStatement ExplainRelation::Bind(Binder &binder) {
|
|
@@ -115628,7 +115798,7 @@ namespace duckdb {
|
|
|
115628
115798
|
FilterRelation::FilterRelation(shared_ptr<Relation> child_p, unique_ptr<ParsedExpression> condition_p)
|
|
115629
115799
|
: Relation(child_p->context, RelationType::FILTER_RELATION), condition(move(condition_p)), child(move(child_p)) {
|
|
115630
115800
|
vector<ColumnDefinition> dummy_columns;
|
|
115631
|
-
context.TryBindRelation(*this, dummy_columns);
|
|
115801
|
+
context.GetContext()->TryBindRelation(*this, dummy_columns);
|
|
115632
115802
|
}
|
|
115633
115803
|
|
|
115634
115804
|
unique_ptr<QueryNode> FilterRelation::GetQueryNode() {
|
|
@@ -115753,7 +115923,7 @@ namespace duckdb {
|
|
|
115753
115923
|
InsertRelation::InsertRelation(shared_ptr<Relation> child_p, string schema_name, string table_name)
|
|
115754
115924
|
: Relation(child_p->context, RelationType::INSERT_RELATION), child(move(child_p)), schema_name(move(schema_name)),
|
|
115755
115925
|
table_name(move(table_name)) {
|
|
115756
|
-
context.TryBindRelation(*this, this->columns);
|
|
115926
|
+
context.GetContext()->TryBindRelation(*this, this->columns);
|
|
115757
115927
|
}
|
|
115758
115928
|
|
|
115759
115929
|
BoundStatement InsertRelation::Bind(Binder &binder) {
|
|
@@ -115827,20 +115997,20 @@ JoinRelation::JoinRelation(shared_ptr<Relation> left_p, shared_ptr<Relation> rig
|
|
|
115827
115997
|
unique_ptr<ParsedExpression> condition_p, JoinType type)
|
|
115828
115998
|
: Relation(left_p->context, RelationType::JOIN_RELATION), left(move(left_p)), right(move(right_p)),
|
|
115829
115999
|
condition(move(condition_p)), join_type(type) {
|
|
115830
|
-
if (
|
|
116000
|
+
if (left->context.GetContext() != right->context.GetContext()) {
|
|
115831
116001
|
throw Exception("Cannot combine LEFT and RIGHT relations of different connections!");
|
|
115832
116002
|
}
|
|
115833
|
-
context.TryBindRelation(*this, this->columns);
|
|
116003
|
+
context.GetContext()->TryBindRelation(*this, this->columns);
|
|
115834
116004
|
}
|
|
115835
116005
|
|
|
115836
116006
|
JoinRelation::JoinRelation(shared_ptr<Relation> left_p, shared_ptr<Relation> right_p, vector<string> using_columns_p,
|
|
115837
116007
|
JoinType type)
|
|
115838
116008
|
: Relation(left_p->context, RelationType::JOIN_RELATION), left(move(left_p)), right(move(right_p)),
|
|
115839
116009
|
using_columns(move(using_columns_p)), join_type(type) {
|
|
115840
|
-
if (
|
|
116010
|
+
if (left->context.GetContext() != right->context.GetContext()) {
|
|
115841
116011
|
throw Exception("Cannot combine LEFT and RIGHT relations of different connections!");
|
|
115842
116012
|
}
|
|
115843
|
-
context.TryBindRelation(*this, this->columns);
|
|
116013
|
+
context.GetContext()->TryBindRelation(*this, this->columns);
|
|
115844
116014
|
}
|
|
115845
116015
|
|
|
115846
116016
|
unique_ptr<QueryNode> JoinRelation::GetQueryNode() {
|
|
@@ -116007,7 +116177,7 @@ OrderRelation::OrderRelation(shared_ptr<Relation> child_p, vector<OrderByNode> o
|
|
|
116007
116177
|
: Relation(child_p->context, RelationType::ORDER_RELATION), orders(move(orders)), child(move(child_p)) {
|
|
116008
116178
|
// bind the expressions
|
|
116009
116179
|
vector<ColumnDefinition> dummy_columns;
|
|
116010
|
-
context.TryBindRelation(*this, dummy_columns);
|
|
116180
|
+
context.GetContext()->TryBindRelation(*this, dummy_columns);
|
|
116011
116181
|
}
|
|
116012
116182
|
|
|
116013
116183
|
unique_ptr<QueryNode> OrderRelation::GetQueryNode() {
|
|
@@ -116094,7 +116264,7 @@ ProjectionRelation::ProjectionRelation(shared_ptr<Relation> child_p,
|
|
|
116094
116264
|
}
|
|
116095
116265
|
}
|
|
116096
116266
|
// bind the expressions
|
|
116097
|
-
context.TryBindRelation(*this, this->columns);
|
|
116267
|
+
context.GetContext()->TryBindRelation(*this, this->columns);
|
|
116098
116268
|
}
|
|
116099
116269
|
|
|
116100
116270
|
unique_ptr<QueryNode> ProjectionRelation::GetQueryNode() {
|
|
@@ -116151,9 +116321,10 @@ string ProjectionRelation::ToString(idx_t depth) {
|
|
|
116151
116321
|
|
|
116152
116322
|
namespace duckdb {
|
|
116153
116323
|
|
|
116154
|
-
QueryRelation::QueryRelation(ClientContext &context, unique_ptr<SelectStatement> select_stmt_p,
|
|
116324
|
+
QueryRelation::QueryRelation(const std::shared_ptr<ClientContext> &context, unique_ptr<SelectStatement> select_stmt_p,
|
|
116325
|
+
string alias_p)
|
|
116155
116326
|
: Relation(context, RelationType::QUERY_RELATION), select_stmt(move(select_stmt_p)), alias(move(alias_p)) {
|
|
116156
|
-
context
|
|
116327
|
+
context->TryBindRelation(*this, this->columns);
|
|
116157
116328
|
}
|
|
116158
116329
|
|
|
116159
116330
|
QueryRelation::~QueryRelation() {
|
|
@@ -116212,8 +116383,8 @@ string QueryRelation::ToString(idx_t depth) {
|
|
|
116212
116383
|
|
|
116213
116384
|
namespace duckdb {
|
|
116214
116385
|
|
|
116215
|
-
ReadCSVRelation::ReadCSVRelation(ClientContext &context, string csv_file_p,
|
|
116216
|
-
bool auto_detect, string alias_p)
|
|
116386
|
+
ReadCSVRelation::ReadCSVRelation(const std::shared_ptr<ClientContext> &context, string csv_file_p,
|
|
116387
|
+
vector<ColumnDefinition> columns_p, bool auto_detect, string alias_p)
|
|
116217
116388
|
: Relation(context, RelationType::READ_CSV_RELATION), csv_file(move(csv_file_p)), auto_detect(auto_detect),
|
|
116218
116389
|
alias(move(alias_p)), columns(move(columns_p)) {
|
|
116219
116390
|
if (alias.empty()) {
|
|
@@ -116306,11 +116477,11 @@ namespace duckdb {
|
|
|
116306
116477
|
SetOpRelation::SetOpRelation(shared_ptr<Relation> left_p, shared_ptr<Relation> right_p, SetOperationType setop_type_p)
|
|
116307
116478
|
: Relation(left_p->context, RelationType::SET_OPERATION_RELATION), left(move(left_p)), right(move(right_p)),
|
|
116308
116479
|
setop_type(setop_type_p) {
|
|
116309
|
-
if (
|
|
116480
|
+
if (left->context.GetContext() != right->context.GetContext()) {
|
|
116310
116481
|
throw Exception("Cannot combine LEFT and RIGHT relations of different connections!");
|
|
116311
116482
|
}
|
|
116312
116483
|
vector<ColumnDefinition> dummy_columns;
|
|
116313
|
-
context.TryBindRelation(*this, dummy_columns);
|
|
116484
|
+
context.GetContext()->TryBindRelation(*this, dummy_columns);
|
|
116314
116485
|
}
|
|
116315
116486
|
|
|
116316
116487
|
unique_ptr<QueryNode> SetOpRelation::GetQueryNode() {
|
|
@@ -116395,7 +116566,7 @@ namespace duckdb {
|
|
|
116395
116566
|
SubqueryRelation::SubqueryRelation(shared_ptr<Relation> child_p, string alias_p)
|
|
116396
116567
|
: Relation(child_p->context, RelationType::SUBQUERY_RELATION), child(move(child_p)), alias(move(alias_p)) {
|
|
116397
116568
|
vector<ColumnDefinition> dummy_columns;
|
|
116398
|
-
context.TryBindRelation(*this, dummy_columns);
|
|
116569
|
+
context.GetContext()->TryBindRelation(*this, dummy_columns);
|
|
116399
116570
|
}
|
|
116400
116571
|
|
|
116401
116572
|
unique_ptr<QueryNode> SubqueryRelation::GetQueryNode() {
|
|
@@ -116429,19 +116600,20 @@ string SubqueryRelation::ToString(idx_t depth) {
|
|
|
116429
116600
|
|
|
116430
116601
|
namespace duckdb {
|
|
116431
116602
|
|
|
116432
|
-
TableFunctionRelation::TableFunctionRelation(ClientContext &context, string name_p,
|
|
116433
|
-
named_parameter_map_t named_parameters,
|
|
116603
|
+
TableFunctionRelation::TableFunctionRelation(const std::shared_ptr<ClientContext> &context, string name_p,
|
|
116604
|
+
vector<Value> parameters_p, named_parameter_map_t named_parameters,
|
|
116434
116605
|
shared_ptr<Relation> input_relation_p)
|
|
116435
116606
|
: Relation(context, RelationType::TABLE_FUNCTION_RELATION), name(move(name_p)), parameters(move(parameters_p)),
|
|
116436
116607
|
named_parameters(move(named_parameters)), input_relation(move(input_relation_p)) {
|
|
116437
|
-
context
|
|
116608
|
+
context->TryBindRelation(*this, this->columns);
|
|
116438
116609
|
}
|
|
116439
|
-
TableFunctionRelation::TableFunctionRelation(ClientContext &context, string name_p,
|
|
116610
|
+
TableFunctionRelation::TableFunctionRelation(const std::shared_ptr<ClientContext> &context, string name_p,
|
|
116611
|
+
vector<Value> parameters_p,
|
|
116440
116612
|
|
|
116441
116613
|
shared_ptr<Relation> input_relation_p)
|
|
116442
116614
|
: Relation(context, RelationType::TABLE_FUNCTION_RELATION), name(move(name_p)), parameters(move(parameters_p)),
|
|
116443
116615
|
input_relation(move(input_relation_p)) {
|
|
116444
|
-
context
|
|
116616
|
+
context->TryBindRelation(*this, this->columns);
|
|
116445
116617
|
}
|
|
116446
116618
|
|
|
116447
116619
|
unique_ptr<QueryNode> TableFunctionRelation::GetQueryNode() {
|
|
@@ -116524,7 +116696,7 @@ namespace duckdb {
|
|
|
116524
116696
|
|
|
116525
116697
|
class UpdateRelation : public Relation {
|
|
116526
116698
|
public:
|
|
116527
|
-
UpdateRelation(
|
|
116699
|
+
UpdateRelation(ClientContextWrapper &context, unique_ptr<ParsedExpression> condition, string schema_name,
|
|
116528
116700
|
string table_name, vector<string> update_columns, vector<unique_ptr<ParsedExpression>> expressions);
|
|
116529
116701
|
|
|
116530
116702
|
vector<ColumnDefinition> columns;
|
|
@@ -116550,7 +116722,7 @@ public:
|
|
|
116550
116722
|
|
|
116551
116723
|
namespace duckdb {
|
|
116552
116724
|
|
|
116553
|
-
TableRelation::TableRelation(ClientContext &context, unique_ptr<TableDescription> description)
|
|
116725
|
+
TableRelation::TableRelation(const std::shared_ptr<ClientContext> &context, unique_ptr<TableDescription> description)
|
|
116554
116726
|
: Relation(context, RelationType::TABLE_RELATION), description(move(description)) {
|
|
116555
116727
|
}
|
|
116556
116728
|
|
|
@@ -116595,15 +116767,15 @@ static unique_ptr<ParsedExpression> ParseCondition(ClientContext &context, const
|
|
|
116595
116767
|
void TableRelation::Update(const string &update_list, const string &condition) {
|
|
116596
116768
|
vector<string> update_columns;
|
|
116597
116769
|
vector<unique_ptr<ParsedExpression>> expressions;
|
|
116598
|
-
auto cond = ParseCondition(context, condition);
|
|
116599
|
-
Parser::ParseUpdateList(update_list, update_columns, expressions, context.GetParserOptions());
|
|
116770
|
+
auto cond = ParseCondition(*context.GetContext(), condition);
|
|
116771
|
+
Parser::ParseUpdateList(update_list, update_columns, expressions, context.GetContext()->GetParserOptions());
|
|
116600
116772
|
auto update = make_shared<UpdateRelation>(context, move(cond), description->schema, description->table,
|
|
116601
116773
|
move(update_columns), move(expressions));
|
|
116602
116774
|
update->Execute();
|
|
116603
116775
|
}
|
|
116604
116776
|
|
|
116605
116777
|
void TableRelation::Delete(const string &condition) {
|
|
116606
|
-
auto cond = ParseCondition(context, condition);
|
|
116778
|
+
auto cond = ParseCondition(*context.GetContext(), condition);
|
|
116607
116779
|
auto del = make_shared<DeleteRelation>(context, move(cond), description->schema, description->table);
|
|
116608
116780
|
del->Execute();
|
|
116609
116781
|
}
|
|
@@ -116652,13 +116824,13 @@ public:
|
|
|
116652
116824
|
|
|
116653
116825
|
namespace duckdb {
|
|
116654
116826
|
|
|
116655
|
-
UpdateRelation::UpdateRelation(
|
|
116656
|
-
string table_name_p, vector<string> update_columns_p,
|
|
116827
|
+
UpdateRelation::UpdateRelation(ClientContextWrapper &context, unique_ptr<ParsedExpression> condition_p,
|
|
116828
|
+
string schema_name_p, string table_name_p, vector<string> update_columns_p,
|
|
116657
116829
|
vector<unique_ptr<ParsedExpression>> expressions_p)
|
|
116658
116830
|
: Relation(context, RelationType::UPDATE_RELATION), condition(move(condition_p)), schema_name(move(schema_name_p)),
|
|
116659
116831
|
table_name(move(table_name_p)), update_columns(move(update_columns_p)), expressions(move(expressions_p)) {
|
|
116660
116832
|
D_ASSERT(update_columns.size() == expressions.size());
|
|
116661
|
-
context.TryBindRelation(*this, this->columns);
|
|
116833
|
+
context.GetContext()->TryBindRelation(*this, this->columns);
|
|
116662
116834
|
}
|
|
116663
116835
|
|
|
116664
116836
|
BoundStatement UpdateRelation::Bind(Binder &binder) {
|
|
@@ -116702,8 +116874,8 @@ string UpdateRelation::ToString(idx_t depth) {
|
|
|
116702
116874
|
|
|
116703
116875
|
namespace duckdb {
|
|
116704
116876
|
|
|
116705
|
-
ValueRelation::ValueRelation(ClientContext &context, const vector<vector<Value>> &values,
|
|
116706
|
-
string alias_p)
|
|
116877
|
+
ValueRelation::ValueRelation(const std::shared_ptr<ClientContext> &context, const vector<vector<Value>> &values,
|
|
116878
|
+
vector<string> names_p, string alias_p)
|
|
116707
116879
|
: Relation(context, RelationType::VALUE_LIST_RELATION), names(move(names_p)), alias(move(alias_p)) {
|
|
116708
116880
|
// create constant expressions for the values
|
|
116709
116881
|
for (idx_t row_idx = 0; row_idx < values.size(); row_idx++) {
|
|
@@ -116714,13 +116886,14 @@ ValueRelation::ValueRelation(ClientContext &context, const vector<vector<Value>>
|
|
|
116714
116886
|
}
|
|
116715
116887
|
this->expressions.push_back(move(expressions));
|
|
116716
116888
|
}
|
|
116717
|
-
context
|
|
116889
|
+
context->TryBindRelation(*this, this->columns);
|
|
116718
116890
|
}
|
|
116719
116891
|
|
|
116720
|
-
ValueRelation::ValueRelation(ClientContext &context, const string &values_list,
|
|
116892
|
+
ValueRelation::ValueRelation(const std::shared_ptr<ClientContext> &context, const string &values_list,
|
|
116893
|
+
vector<string> names_p, string alias_p)
|
|
116721
116894
|
: Relation(context, RelationType::VALUE_LIST_RELATION), names(move(names_p)), alias(move(alias_p)) {
|
|
116722
|
-
this->expressions = Parser::ParseValuesList(values_list, context
|
|
116723
|
-
context
|
|
116895
|
+
this->expressions = Parser::ParseValuesList(values_list, context->GetParserOptions());
|
|
116896
|
+
context->TryBindRelation(*this, this->columns);
|
|
116724
116897
|
}
|
|
116725
116898
|
|
|
116726
116899
|
unique_ptr<QueryNode> ValueRelation::GetQueryNode() {
|
|
@@ -116791,9 +116964,9 @@ string ValueRelation::ToString(idx_t depth) {
|
|
|
116791
116964
|
|
|
116792
116965
|
namespace duckdb {
|
|
116793
116966
|
|
|
116794
|
-
ViewRelation::ViewRelation(ClientContext &context, string schema_name_p, string view_name_p)
|
|
116967
|
+
ViewRelation::ViewRelation(const std::shared_ptr<ClientContext> &context, string schema_name_p, string view_name_p)
|
|
116795
116968
|
: Relation(context, RelationType::VIEW_RELATION), schema_name(move(schema_name_p)), view_name(move(view_name_p)) {
|
|
116796
|
-
context
|
|
116969
|
+
context->TryBindRelation(*this, this->columns);
|
|
116797
116970
|
}
|
|
116798
116971
|
|
|
116799
116972
|
unique_ptr<QueryNode> ViewRelation::GetQueryNode() {
|
|
@@ -116896,7 +117069,7 @@ namespace duckdb {
|
|
|
116896
117069
|
|
|
116897
117070
|
WriteCSVRelation::WriteCSVRelation(shared_ptr<Relation> child_p, string csv_file_p)
|
|
116898
117071
|
: Relation(child_p->context, RelationType::WRITE_CSV_RELATION), child(move(child_p)), csv_file(move(csv_file_p)) {
|
|
116899
|
-
context.TryBindRelation(*this, this->columns);
|
|
117072
|
+
context.GetContext()->TryBindRelation(*this, this->columns);
|
|
116900
117073
|
}
|
|
116901
117074
|
|
|
116902
117075
|
BoundStatement WriteCSVRelation::Bind(Binder &binder) {
|
|
@@ -116958,7 +117131,7 @@ shared_ptr<Relation> Relation::Project(const string &expression, const string &a
|
|
|
116958
117131
|
}
|
|
116959
117132
|
|
|
116960
117133
|
shared_ptr<Relation> Relation::Project(const string &select_list, const vector<string> &aliases) {
|
|
116961
|
-
auto expressions = Parser::ParseExpressionList(select_list, context.GetParserOptions());
|
|
117134
|
+
auto expressions = Parser::ParseExpressionList(select_list, context.GetContext()->GetParserOptions());
|
|
116962
117135
|
return make_shared<ProjectionRelation>(shared_from_this(), move(expressions), aliases);
|
|
116963
117136
|
}
|
|
116964
117137
|
|
|
@@ -116984,12 +117157,12 @@ static vector<unique_ptr<ParsedExpression>> StringListToExpressionList(ClientCon
|
|
|
116984
117157
|
}
|
|
116985
117158
|
|
|
116986
117159
|
shared_ptr<Relation> Relation::Project(const vector<string> &expressions, const vector<string> &aliases) {
|
|
116987
|
-
auto result_list = StringListToExpressionList(context, expressions);
|
|
117160
|
+
auto result_list = StringListToExpressionList(*context.GetContext(), expressions);
|
|
116988
117161
|
return make_shared<ProjectionRelation>(shared_from_this(), move(result_list), aliases);
|
|
116989
117162
|
}
|
|
116990
117163
|
|
|
116991
117164
|
shared_ptr<Relation> Relation::Filter(const string &expression) {
|
|
116992
|
-
auto expression_list = Parser::ParseExpressionList(expression, context.GetParserOptions());
|
|
117165
|
+
auto expression_list = Parser::ParseExpressionList(expression, context.GetContext()->GetParserOptions());
|
|
116993
117166
|
if (expression_list.size() != 1) {
|
|
116994
117167
|
throw ParserException("Expected a single expression as filter condition");
|
|
116995
117168
|
}
|
|
@@ -116998,7 +117171,7 @@ shared_ptr<Relation> Relation::Filter(const string &expression) {
|
|
|
116998
117171
|
|
|
116999
117172
|
shared_ptr<Relation> Relation::Filter(const vector<string> &expressions) {
|
|
117000
117173
|
// if there are multiple expressions, we AND them together
|
|
117001
|
-
auto expression_list = StringListToExpressionList(context, expressions);
|
|
117174
|
+
auto expression_list = StringListToExpressionList(*context.GetContext(), expressions);
|
|
117002
117175
|
D_ASSERT(!expression_list.empty());
|
|
117003
117176
|
|
|
117004
117177
|
auto expr = move(expression_list[0]);
|
|
@@ -117014,7 +117187,7 @@ shared_ptr<Relation> Relation::Limit(int64_t limit, int64_t offset) {
|
|
|
117014
117187
|
}
|
|
117015
117188
|
|
|
117016
117189
|
shared_ptr<Relation> Relation::Order(const string &expression) {
|
|
117017
|
-
auto order_list = Parser::ParseOrderList(expression, context.GetParserOptions());
|
|
117190
|
+
auto order_list = Parser::ParseOrderList(expression, context.GetContext()->GetParserOptions());
|
|
117018
117191
|
return make_shared<OrderRelation>(shared_from_this(), move(order_list));
|
|
117019
117192
|
}
|
|
117020
117193
|
|
|
@@ -117024,7 +117197,7 @@ shared_ptr<Relation> Relation::Order(const vector<string> &expressions) {
|
|
|
117024
117197
|
}
|
|
117025
117198
|
vector<OrderByNode> order_list;
|
|
117026
117199
|
for (auto &expression : expressions) {
|
|
117027
|
-
auto inner_list = Parser::ParseOrderList(expression, context.GetParserOptions());
|
|
117200
|
+
auto inner_list = Parser::ParseOrderList(expression, context.GetContext()->GetParserOptions());
|
|
117028
117201
|
if (inner_list.size() != 1) {
|
|
117029
117202
|
throw ParserException("Expected a single ORDER BY expression in the expression list");
|
|
117030
117203
|
}
|
|
@@ -117034,7 +117207,7 @@ shared_ptr<Relation> Relation::Order(const vector<string> &expressions) {
|
|
|
117034
117207
|
}
|
|
117035
117208
|
|
|
117036
117209
|
shared_ptr<Relation> Relation::Join(const shared_ptr<Relation> &other, const string &condition, JoinType type) {
|
|
117037
|
-
auto expression_list = Parser::ParseExpressionList(condition, context.GetParserOptions());
|
|
117210
|
+
auto expression_list = Parser::ParseExpressionList(condition, context.GetContext()->GetParserOptions());
|
|
117038
117211
|
D_ASSERT(!expression_list.empty());
|
|
117039
117212
|
|
|
117040
117213
|
if (expression_list.size() > 1 || expression_list[0]->type == ExpressionType::COLUMN_REF) {
|
|
@@ -117082,24 +117255,24 @@ shared_ptr<Relation> Relation::Alias(const string &alias) {
|
|
|
117082
117255
|
}
|
|
117083
117256
|
|
|
117084
117257
|
shared_ptr<Relation> Relation::Aggregate(const string &aggregate_list) {
|
|
117085
|
-
auto expression_list = Parser::ParseExpressionList(aggregate_list, context.GetParserOptions());
|
|
117258
|
+
auto expression_list = Parser::ParseExpressionList(aggregate_list, context.GetContext()->GetParserOptions());
|
|
117086
117259
|
return make_shared<AggregateRelation>(shared_from_this(), move(expression_list));
|
|
117087
117260
|
}
|
|
117088
117261
|
|
|
117089
117262
|
shared_ptr<Relation> Relation::Aggregate(const string &aggregate_list, const string &group_list) {
|
|
117090
|
-
auto expression_list = Parser::ParseExpressionList(aggregate_list, context.GetParserOptions());
|
|
117091
|
-
auto groups = Parser::ParseExpressionList(group_list, context.GetParserOptions());
|
|
117263
|
+
auto expression_list = Parser::ParseExpressionList(aggregate_list, context.GetContext()->GetParserOptions());
|
|
117264
|
+
auto groups = Parser::ParseExpressionList(group_list, context.GetContext()->GetParserOptions());
|
|
117092
117265
|
return make_shared<AggregateRelation>(shared_from_this(), move(expression_list), move(groups));
|
|
117093
117266
|
}
|
|
117094
117267
|
|
|
117095
117268
|
shared_ptr<Relation> Relation::Aggregate(const vector<string> &aggregates) {
|
|
117096
|
-
auto aggregate_list = StringListToExpressionList(context, aggregates);
|
|
117269
|
+
auto aggregate_list = StringListToExpressionList(*context.GetContext(), aggregates);
|
|
117097
117270
|
return make_shared<AggregateRelation>(shared_from_this(), move(aggregate_list));
|
|
117098
117271
|
}
|
|
117099
117272
|
|
|
117100
117273
|
shared_ptr<Relation> Relation::Aggregate(const vector<string> &aggregates, const vector<string> &groups) {
|
|
117101
|
-
auto aggregate_list = StringListToExpressionList(context, aggregates);
|
|
117102
|
-
auto group_list = StringListToExpressionList(context, groups);
|
|
117274
|
+
auto aggregate_list = StringListToExpressionList(*context.GetContext(), aggregates);
|
|
117275
|
+
auto group_list = StringListToExpressionList(*context.GetContext(), groups);
|
|
117103
117276
|
return make_shared<AggregateRelation>(shared_from_this(), move(aggregate_list), move(group_list));
|
|
117104
117277
|
}
|
|
117105
117278
|
|
|
@@ -117114,7 +117287,7 @@ unique_ptr<TableRef> Relation::GetTableRef() {
|
|
|
117114
117287
|
}
|
|
117115
117288
|
|
|
117116
117289
|
unique_ptr<QueryResult> Relation::Execute() {
|
|
117117
|
-
return context.Execute(shared_from_this());
|
|
117290
|
+
return context.GetContext()->Execute(shared_from_this());
|
|
117118
117291
|
}
|
|
117119
117292
|
|
|
117120
117293
|
BoundStatement Relation::Bind(Binder &binder) {
|
|
@@ -117137,7 +117310,7 @@ void Relation::Insert(const string &schema_name, const string &table_name) {
|
|
|
117137
117310
|
|
|
117138
117311
|
void Relation::Insert(const vector<vector<Value>> &values) {
|
|
117139
117312
|
vector<string> column_names;
|
|
117140
|
-
auto rel = make_shared<ValueRelation>(context, values, move(column_names), "values");
|
|
117313
|
+
auto rel = make_shared<ValueRelation>(context.GetContext(), values, move(column_names), "values");
|
|
117141
117314
|
rel->Insert(GetAlias());
|
|
117142
117315
|
}
|
|
117143
117316
|
|
|
@@ -117171,7 +117344,7 @@ shared_ptr<Relation> Relation::CreateView(const string &name, bool replace, bool
|
|
|
117171
117344
|
}
|
|
117172
117345
|
|
|
117173
117346
|
unique_ptr<QueryResult> Relation::Query(const string &sql) {
|
|
117174
|
-
return context.Query(sql, false);
|
|
117347
|
+
return context.GetContext()->Query(sql, false);
|
|
117175
117348
|
}
|
|
117176
117349
|
|
|
117177
117350
|
unique_ptr<QueryResult> Relation::Query(const string &name, const string &sql) {
|
|
@@ -117194,11 +117367,12 @@ void Relation::Delete(const string &condition) {
|
|
|
117194
117367
|
|
|
117195
117368
|
shared_ptr<Relation> Relation::TableFunction(const std::string &fname, const vector<Value> &values,
|
|
117196
117369
|
const named_parameter_map_t &named_parameters) {
|
|
117197
|
-
return make_shared<TableFunctionRelation>(context, fname, values, named_parameters,
|
|
117370
|
+
return make_shared<TableFunctionRelation>(context.GetContext(), fname, values, named_parameters,
|
|
117371
|
+
shared_from_this());
|
|
117198
117372
|
}
|
|
117199
117373
|
|
|
117200
117374
|
shared_ptr<Relation> Relation::TableFunction(const std::string &fname, const vector<Value> &values) {
|
|
117201
|
-
return make_shared<TableFunctionRelation>(context, fname, values, shared_from_this());
|
|
117375
|
+
return make_shared<TableFunctionRelation>(context.GetContext(), fname, values, shared_from_this());
|
|
117202
117376
|
}
|
|
117203
117377
|
|
|
117204
117378
|
string Relation::ToString() {
|
|
@@ -148800,13 +148974,19 @@ BindResult SelectBinder::BindUnnest(FunctionExpression &function, idx_t depth) {
|
|
|
148800
148974
|
}
|
|
148801
148975
|
auto &child = (BoundExpression &)*function.children[0];
|
|
148802
148976
|
auto &child_type = child.expr->return_type;
|
|
148803
|
-
|
|
148804
|
-
|
|
148977
|
+
|
|
148978
|
+
if (child_type.id() != LogicalTypeId::LIST && child_type.id() != LogicalTypeId::SQLNULL) {
|
|
148979
|
+
return BindResult(binder.FormatError(function, "Unnest() can only be applied to lists and NULL"));
|
|
148805
148980
|
}
|
|
148981
|
+
|
|
148806
148982
|
if (depth > 0) {
|
|
148807
148983
|
throw BinderException(binder.FormatError(function, "Unnest() for correlated expressions is not supported yet"));
|
|
148808
148984
|
}
|
|
148809
|
-
|
|
148985
|
+
|
|
148986
|
+
auto return_type = LogicalType(LogicalTypeId::SQLNULL);
|
|
148987
|
+
if (child_type.id() == LogicalTypeId::LIST) {
|
|
148988
|
+
return_type = ListType::GetChildType(child_type);
|
|
148989
|
+
}
|
|
148810
148990
|
|
|
148811
148991
|
auto result = make_unique<BoundUnnestExpression>(return_type);
|
|
148812
148992
|
result->child = move(child.expr);
|
|
@@ -148820,6 +149000,7 @@ BindResult SelectBinder::BindUnnest(FunctionExpression &function, idx_t depth) {
|
|
|
148820
149000
|
auto colref = make_unique<BoundColumnRefExpression>(
|
|
148821
149001
|
function.alias.empty() ? node.unnests[unnest_index]->ToString() : function.alias, return_type,
|
|
148822
149002
|
ColumnBinding(node.unnest_index, unnest_index), depth);
|
|
149003
|
+
|
|
148823
149004
|
return BindResult(move(colref));
|
|
148824
149005
|
}
|
|
148825
149006
|
|