duckdb 0.3.5-dev1364.0 → 0.3.5-dev1402.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "duckdb",
3
3
  "main": "./lib/duckdb.js",
4
- "version": "0.3.5-dev1364.0",
4
+ "version": "0.3.5-dev1402.0",
5
5
  "description": "DuckDB node.js API",
6
6
  "gypfile": true,
7
7
  "dependencies": {
package/src/duckdb.cpp CHANGED
@@ -45605,6 +45605,126 @@ bool Value::ValuesAreEqual(const Value &result_value, const Value &value) {
45605
45605
 
45606
45606
 
45607
45607
 
45608
+ //===----------------------------------------------------------------------===//
45609
+ // DuckDB
45610
+ //
45611
+ // duckdb/function/scalar/nested_functions.hpp
45612
+ //
45613
+ //
45614
+ //===----------------------------------------------------------------------===//
45615
+
45616
+
45617
+
45618
+
45619
+
45620
+
45621
+
45622
+
45623
+ namespace duckdb {
45624
+
45625
+ enum class MapInvalidReason : uint8_t { VALID, NULL_KEY_LIST, NULL_KEY, DUPLICATE_KEY };
45626
+
45627
+ struct VariableReturnBindData : public FunctionData {
45628
+ LogicalType stype;
45629
+
45630
+ explicit VariableReturnBindData(const LogicalType &stype_p) : stype(stype_p) {
45631
+ }
45632
+
45633
+ unique_ptr<FunctionData> Copy() const override {
45634
+ return make_unique<VariableReturnBindData>(stype);
45635
+ }
45636
+ bool Equals(const FunctionData &other_p) const override {
45637
+ auto &other = (const VariableReturnBindData &)other_p;
45638
+ return stype == other.stype;
45639
+ }
45640
+ };
45641
+
45642
+ template <class T, class MAP_TYPE = map<T, idx_t>>
45643
+ struct HistogramAggState {
45644
+ MAP_TYPE *hist;
45645
+ };
45646
+
45647
+ struct ArraySliceFun {
45648
+ static void RegisterFunction(BuiltinFunctions &set);
45649
+ };
45650
+
45651
+ struct StructPackFun {
45652
+ static void RegisterFunction(BuiltinFunctions &set);
45653
+ };
45654
+
45655
+ struct ListValueFun {
45656
+ static void RegisterFunction(BuiltinFunctions &set);
45657
+ };
45658
+
45659
+ struct ListRangeFun {
45660
+ static void RegisterFunction(BuiltinFunctions &set);
45661
+ };
45662
+
45663
+ struct MapFun {
45664
+ static void RegisterFunction(BuiltinFunctions &set);
45665
+ };
45666
+
45667
+ struct MapExtractFun {
45668
+ static void RegisterFunction(BuiltinFunctions &set);
45669
+ };
45670
+
45671
+ struct ListExtractFun {
45672
+ static void RegisterFunction(BuiltinFunctions &set);
45673
+ };
45674
+
45675
+ struct ListConcatFun {
45676
+ static ScalarFunction GetFunction();
45677
+ static void RegisterFunction(BuiltinFunctions &set);
45678
+ };
45679
+
45680
+ struct ListContainsFun {
45681
+ static ScalarFunction GetFunction();
45682
+ static void RegisterFunction(BuiltinFunctions &set);
45683
+ };
45684
+
45685
+ struct ListFlattenFun {
45686
+ static void RegisterFunction(BuiltinFunctions &set);
45687
+ };
45688
+
45689
+ struct ListPositionFun {
45690
+ static ScalarFunction GetFunction();
45691
+ static void RegisterFunction(BuiltinFunctions &set);
45692
+ };
45693
+
45694
+ struct ListAggregateFun {
45695
+ static ScalarFunction GetFunction();
45696
+ static void RegisterFunction(BuiltinFunctions &set);
45697
+ };
45698
+
45699
+ struct ListDistinctFun {
45700
+ static ScalarFunction GetFunction();
45701
+ static void RegisterFunction(BuiltinFunctions &set);
45702
+ };
45703
+
45704
+ struct ListUniqueFun {
45705
+ static ScalarFunction GetFunction();
45706
+ static void RegisterFunction(BuiltinFunctions &set);
45707
+ };
45708
+
45709
+ struct ListSortFun {
45710
+ static ScalarFunction GetFunction();
45711
+ static void RegisterFunction(BuiltinFunctions &set);
45712
+ };
45713
+
45714
+ struct CardinalityFun {
45715
+ static void RegisterFunction(BuiltinFunctions &set);
45716
+ };
45717
+
45718
+ struct StructExtractFun {
45719
+ static ScalarFunction GetFunction();
45720
+ static void RegisterFunction(BuiltinFunctions &set);
45721
+ };
45722
+
45723
+ MapInvalidReason CheckMapValidity(Vector &map, idx_t count,
45724
+ const SelectionVector &sel = *FlatVector::IncrementalSelectionVector());
45725
+
45726
+ } // namespace duckdb
45727
+
45608
45728
 
45609
45729
  #include <cstring> // strlen() on Solaris
45610
45730
 
@@ -46585,6 +46705,14 @@ void Vector::UTFVerify(idx_t count) {
46585
46705
  UTFVerify(*flat_sel, count);
46586
46706
  }
46587
46707
 
46708
+ void Vector::VerifyMap(Vector &vector_p, const SelectionVector &sel_p, idx_t count) {
46709
+ #ifdef DEBUG
46710
+ D_ASSERT(vector_p.GetType().id() == LogicalTypeId::MAP);
46711
+ auto valid_check = CheckMapValidity(vector_p, count, sel_p);
46712
+ D_ASSERT(valid_check == MapInvalidReason::VALID);
46713
+ #endif // DEBUG
46714
+ }
46715
+
46588
46716
  void Vector::Verify(Vector &vector_p, const SelectionVector &sel_p, idx_t count) {
46589
46717
  #ifdef DEBUG
46590
46718
  if (count == 0) {
@@ -46676,6 +46804,9 @@ void Vector::Verify(Vector &vector_p, const SelectionVector &sel_p, idx_t count)
46676
46804
  }
46677
46805
  }
46678
46806
  }
46807
+ if (vector->GetType().id() == LogicalTypeId::MAP) {
46808
+ VerifyMap(*vector, *sel, count);
46809
+ }
46679
46810
  }
46680
46811
 
46681
46812
  if (type.InternalType() == PhysicalType::LIST) {
@@ -86125,120 +86256,6 @@ void BuiltinFunctions::RegisterHolisticAggregates() {
86125
86256
  Register<ReservoirQuantileFun>();
86126
86257
  }
86127
86258
 
86128
- } // namespace duckdb
86129
- //===----------------------------------------------------------------------===//
86130
- // DuckDB
86131
- //
86132
- // duckdb/function/scalar/nested_functions.hpp
86133
- //
86134
- //
86135
- //===----------------------------------------------------------------------===//
86136
-
86137
-
86138
-
86139
-
86140
-
86141
-
86142
-
86143
-
86144
- namespace duckdb {
86145
-
86146
- struct VariableReturnBindData : public FunctionData {
86147
- LogicalType stype;
86148
-
86149
- explicit VariableReturnBindData(const LogicalType &stype_p) : stype(stype_p) {
86150
- }
86151
-
86152
- unique_ptr<FunctionData> Copy() const override {
86153
- return make_unique<VariableReturnBindData>(stype);
86154
- }
86155
- bool Equals(const FunctionData &other_p) const override {
86156
- auto &other = (const VariableReturnBindData &)other_p;
86157
- return stype == other.stype;
86158
- }
86159
- };
86160
-
86161
- template <class T, class MAP_TYPE = map<T, idx_t>>
86162
- struct HistogramAggState {
86163
- MAP_TYPE *hist;
86164
- };
86165
-
86166
- struct ArraySliceFun {
86167
- static void RegisterFunction(BuiltinFunctions &set);
86168
- };
86169
-
86170
- struct StructPackFun {
86171
- static void RegisterFunction(BuiltinFunctions &set);
86172
- };
86173
-
86174
- struct ListValueFun {
86175
- static void RegisterFunction(BuiltinFunctions &set);
86176
- };
86177
-
86178
- struct ListRangeFun {
86179
- static void RegisterFunction(BuiltinFunctions &set);
86180
- };
86181
-
86182
- struct MapFun {
86183
- static void RegisterFunction(BuiltinFunctions &set);
86184
- };
86185
-
86186
- struct MapExtractFun {
86187
- static void RegisterFunction(BuiltinFunctions &set);
86188
- };
86189
-
86190
- struct ListExtractFun {
86191
- static void RegisterFunction(BuiltinFunctions &set);
86192
- };
86193
-
86194
- struct ListConcatFun {
86195
- static ScalarFunction GetFunction();
86196
- static void RegisterFunction(BuiltinFunctions &set);
86197
- };
86198
-
86199
- struct ListContainsFun {
86200
- static ScalarFunction GetFunction();
86201
- static void RegisterFunction(BuiltinFunctions &set);
86202
- };
86203
-
86204
- struct ListFlattenFun {
86205
- static void RegisterFunction(BuiltinFunctions &set);
86206
- };
86207
-
86208
- struct ListPositionFun {
86209
- static ScalarFunction GetFunction();
86210
- static void RegisterFunction(BuiltinFunctions &set);
86211
- };
86212
-
86213
- struct ListAggregateFun {
86214
- static ScalarFunction GetFunction();
86215
- static void RegisterFunction(BuiltinFunctions &set);
86216
- };
86217
-
86218
- struct ListDistinctFun {
86219
- static ScalarFunction GetFunction();
86220
- static void RegisterFunction(BuiltinFunctions &set);
86221
- };
86222
-
86223
- struct ListUniqueFun {
86224
- static ScalarFunction GetFunction();
86225
- static void RegisterFunction(BuiltinFunctions &set);
86226
- };
86227
-
86228
- struct ListSortFun {
86229
- static ScalarFunction GetFunction();
86230
- static void RegisterFunction(BuiltinFunctions &set);
86231
- };
86232
-
86233
- struct CardinalityFun {
86234
- static void RegisterFunction(BuiltinFunctions &set);
86235
- };
86236
-
86237
- struct StructExtractFun {
86238
- static ScalarFunction GetFunction();
86239
- static void RegisterFunction(BuiltinFunctions &set);
86240
- };
86241
-
86242
86259
  } // namespace duckdb
86243
86260
 
86244
86261
  //===----------------------------------------------------------------------===//
@@ -96802,8 +96819,110 @@ void CardinalityFun::RegisterFunction(BuiltinFunctions &set) {
96802
96819
 
96803
96820
 
96804
96821
 
96822
+ //===----------------------------------------------------------------------===//
96823
+ // DuckDB
96824
+ //
96825
+ // duckdb/parser/expression_map.hpp
96826
+ //
96827
+ //
96828
+ //===----------------------------------------------------------------------===//
96829
+
96830
+
96831
+
96832
+
96833
+
96834
+
96835
+
96805
96836
  namespace duckdb {
96806
96837
 
96838
+ struct ValueHashFunction {
96839
+ uint64_t operator()(const Value &value) const {
96840
+ return (uint64_t)value.Hash();
96841
+ }
96842
+ };
96843
+
96844
+ struct ValueEquality {
96845
+ bool operator()(const Value &a, const Value &b) const {
96846
+ return Value::NotDistinctFrom(a, b);
96847
+ }
96848
+ };
96849
+
96850
+ template <typename T>
96851
+ using value_map_t = unordered_map<Value, T, ValueHashFunction, ValueEquality>;
96852
+
96853
+ using value_set_t = unordered_set<Value, ValueHashFunction, ValueEquality>;
96854
+
96855
+ } // namespace duckdb
96856
+
96857
+
96858
+ namespace duckdb {
96859
+
96860
+ // TODO: this doesn't recursively verify maps if maps are nested
96861
+ MapInvalidReason CheckMapValidity(Vector &map, idx_t count, const SelectionVector &sel) {
96862
+ D_ASSERT(map.GetType().id() == LogicalTypeId::MAP);
96863
+ VectorData map_vdata;
96864
+ map.Orrify(count, map_vdata);
96865
+ auto &map_validity = map_vdata.validity;
96866
+
96867
+ auto &key_vector = *(StructVector::GetEntries(map)[0]);
96868
+ VectorData key_vdata;
96869
+ key_vector.Orrify(count, key_vdata);
96870
+ auto key_data = (list_entry_t *)key_vdata.data;
96871
+ auto &key_validity = key_vdata.validity;
96872
+
96873
+ auto &key_entries = ListVector::GetEntry(key_vector);
96874
+ VectorData key_entry_vdata;
96875
+ key_entries.Orrify(count, key_entry_vdata);
96876
+ auto &entry_validity = key_entry_vdata.validity;
96877
+
96878
+ for (idx_t row = 0; row < count; row++) {
96879
+ auto mapped_row = sel.get_index(row);
96880
+ auto row_idx = map_vdata.sel->get_index(mapped_row);
96881
+ // map is allowed to be NULL
96882
+ if (!map_validity.RowIsValid(row_idx)) {
96883
+ continue;
96884
+ }
96885
+ row_idx = key_vdata.sel->get_index(row);
96886
+ if (!key_validity.RowIsValid(row_idx)) {
96887
+ return MapInvalidReason::NULL_KEY_LIST;
96888
+ }
96889
+ value_set_t unique_keys;
96890
+ for (idx_t i = 0; i < key_data[row_idx].length; i++) {
96891
+ auto index = key_data[row_idx].offset + i;
96892
+ index = key_entry_vdata.sel->get_index(index);
96893
+ if (!entry_validity.RowIsValid(index)) {
96894
+ return MapInvalidReason::NULL_KEY;
96895
+ }
96896
+ auto value = key_entries.GetValue(index);
96897
+ auto result = unique_keys.insert(value);
96898
+ if (!result.second) {
96899
+ return MapInvalidReason::DUPLICATE_KEY;
96900
+ }
96901
+ }
96902
+ }
96903
+ return MapInvalidReason::VALID;
96904
+ }
96905
+
96906
+ static void MapConversionVerify(Vector &vector, idx_t count) {
96907
+ auto valid_check = CheckMapValidity(vector, count);
96908
+ switch (valid_check) {
96909
+ case MapInvalidReason::VALID:
96910
+ break;
96911
+ case MapInvalidReason::DUPLICATE_KEY: {
96912
+ throw InvalidInputException("Map keys have to be unique");
96913
+ }
96914
+ case MapInvalidReason::NULL_KEY: {
96915
+ throw InvalidInputException("Map keys can not be NULL");
96916
+ }
96917
+ case MapInvalidReason::NULL_KEY_LIST: {
96918
+ throw InvalidInputException("The list of map keys is not allowed to be NULL");
96919
+ }
96920
+ default: {
96921
+ throw InternalException("MapInvalidReason not implemented");
96922
+ }
96923
+ }
96924
+ }
96925
+
96807
96926
  static void MapFunction(DataChunk &args, ExpressionState &state, Vector &result) {
96808
96927
  D_ASSERT(result.GetType().id() == LogicalTypeId::MAP);
96809
96928
 
@@ -96817,19 +96936,19 @@ static void MapFunction(DataChunk &args, ExpressionState &state, Vector &result)
96817
96936
 
96818
96937
  auto &child_entries = StructVector::GetEntries(result);
96819
96938
  D_ASSERT(child_entries.size() == 2);
96820
- auto &key_vector = child_entries[0];
96821
- auto &value_vector = child_entries[1];
96939
+ auto &key_vector = *child_entries[0];
96940
+ auto &value_vector = *child_entries[1];
96822
96941
  if (args.data.empty()) {
96823
96942
  // no arguments: construct an empty map
96824
- ListVector::SetListSize(*key_vector, 0);
96825
- key_vector->SetVectorType(VectorType::CONSTANT_VECTOR);
96826
- auto list_data = ConstantVector::GetData<list_entry_t>(*key_vector);
96943
+ ListVector::SetListSize(key_vector, 0);
96944
+ key_vector.SetVectorType(VectorType::CONSTANT_VECTOR);
96945
+ auto list_data = ConstantVector::GetData<list_entry_t>(key_vector);
96827
96946
  list_data->offset = 0;
96828
96947
  list_data->length = 0;
96829
96948
 
96830
- ListVector::SetListSize(*value_vector, 0);
96831
- value_vector->SetVectorType(VectorType::CONSTANT_VECTOR);
96832
- list_data = ConstantVector::GetData<list_entry_t>(*value_vector);
96949
+ ListVector::SetListSize(value_vector, 0);
96950
+ value_vector.SetVectorType(VectorType::CONSTANT_VECTOR);
96951
+ list_data = ConstantVector::GetData<list_entry_t>(value_vector);
96833
96952
  list_data->offset = 0;
96834
96953
  list_data->length = 0;
96835
96954
 
@@ -96840,8 +96959,10 @@ static void MapFunction(DataChunk &args, ExpressionState &state, Vector &result)
96840
96959
  if (ListVector::GetListSize(args.data[0]) != ListVector::GetListSize(args.data[1])) {
96841
96960
  throw Exception("Key list has a different size from Value list");
96842
96961
  }
96843
- key_vector->Reference(args.data[0]);
96844
- value_vector->Reference(args.data[1]);
96962
+
96963
+ key_vector.Reference(args.data[0]);
96964
+ value_vector.Reference(args.data[1]);
96965
+ MapConversionVerify(result, args.size());
96845
96966
 
96846
96967
  result.Verify(args.size());
96847
96968
  }
@@ -105367,6 +105488,7 @@ void BuiltinFunctions::RegisterArrowFunctions() {
105367
105488
 
105368
105489
 
105369
105490
 
105491
+
105370
105492
  namespace duckdb {
105371
105493
 
105372
105494
  void ShiftRight(unsigned char *ar, int size, int shift) {
@@ -105569,6 +105691,26 @@ void ArrowToDuckDBBlob(Vector &vector, ArrowArray &array, ArrowScanLocalState &s
105569
105691
  }
105570
105692
  }
105571
105693
 
105694
+ void ArrowToDuckDBMapVerify(Vector &vector, idx_t count) {
105695
+ auto valid_check = CheckMapValidity(vector, count);
105696
+ switch (valid_check) {
105697
+ case MapInvalidReason::VALID:
105698
+ break;
105699
+ case MapInvalidReason::DUPLICATE_KEY: {
105700
+ throw InvalidInputException("Arrow map contains duplicate key, which isn't supported by DuckDB map type");
105701
+ }
105702
+ case MapInvalidReason::NULL_KEY: {
105703
+ throw InvalidInputException("Arrow map contains NULL as map key, which isn't supported by DuckDB map type");
105704
+ }
105705
+ case MapInvalidReason::NULL_KEY_LIST: {
105706
+ throw InvalidInputException("Arrow map contains NULL as key list, which isn't supported by DuckDB map type");
105707
+ }
105708
+ default: {
105709
+ throw InternalException("MapInvalidReason not implemented");
105710
+ }
105711
+ }
105712
+ }
105713
+
105572
105714
  void ArrowToDuckDBMapList(Vector &vector, ArrowArray &array, ArrowScanLocalState &scan_state, idx_t size,
105573
105715
  unordered_map<idx_t, unique_ptr<ArrowConvertData>> &arrow_convert_data, idx_t col_idx,
105574
105716
  pair<idx_t, idx_t> &arrow_convert_idx, uint32_t *offsets, ValidityMask *parent_mask) {
@@ -105975,6 +106117,7 @@ void ColumnArrowToDuckDB(Vector &vector, ArrowArray &array, ArrowScanLocalState
105975
106117
  ArrowToDuckDBMapList(*child_entries[type_idx], *struct_arrow.children[type_idx], scan_state, size,
105976
106118
  arrow_convert_data, col_idx, arrow_convert_idx, offsets, &struct_validity_mask);
105977
106119
  }
106120
+ ArrowToDuckDBMapVerify(vector, size);
105978
106121
  break;
105979
106122
  }
105980
106123
  case LogicalTypeId::STRUCT: {
package/src/duckdb.hpp CHANGED
@@ -11,8 +11,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
11
11
  #pragma once
12
12
  #define DUCKDB_AMALGAMATION 1
13
13
  #define DUCKDB_AMALGAMATION_EXTENDED 1
14
- #define DUCKDB_SOURCE_ID "aa105267d"
15
- #define DUCKDB_VERSION "v0.3.5-dev1364"
14
+ #define DUCKDB_SOURCE_ID "192e3cf8a"
15
+ #define DUCKDB_VERSION "v0.3.5-dev1402"
16
16
  //===----------------------------------------------------------------------===//
17
17
  // DuckDB
18
18
  //
@@ -3718,6 +3718,8 @@ public:
3718
3718
  //! Verify that the Vector is in a consistent, not corrupt state. DEBUG
3719
3719
  //! FUNCTION ONLY!
3720
3720
  DUCKDB_API void Verify(idx_t count);
3721
+ //! Asserts that the CheckMapValidity returns MapInvalidReason::VALID
3722
+ DUCKDB_API static void VerifyMap(Vector &map, const SelectionVector &sel, idx_t count);
3721
3723
  DUCKDB_API static void Verify(Vector &vector, const SelectionVector &sel, idx_t count);
3722
3724
  DUCKDB_API void UTFVerify(idx_t count);
3723
3725
  DUCKDB_API void UTFVerify(const SelectionVector &sel, idx_t count);