duckdb 0.3.1-dev511.0 → 0.3.1-dev517.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.1-dev511.0",
4
+ "version": "0.3.1-dev517.0",
5
5
  "description": "DuckDB node.js API",
6
6
  "gypfile": true,
7
7
  "dependencies": {
package/src/duckdb.cpp CHANGED
@@ -9435,7 +9435,11 @@ static DefaultMacro internal_macros[] = {
9435
9435
  {DEFAULT_SCHEMA, "round_even", {"x", "n", nullptr}, "CASE ((abs(x) * power(10, n+1)) % 10) WHEN 5 THEN round(x/2, n) * 2 ELSE round(x, n) END"},
9436
9436
  {DEFAULT_SCHEMA, "roundbankers", {"x", "n", nullptr}, "round_even(x, n)"},
9437
9437
  {DEFAULT_SCHEMA, "nullif", {"a", "b", nullptr}, "CASE WHEN a=b THEN NULL ELSE a END"},
9438
- {nullptr, nullptr, {nullptr}, nullptr}};
9438
+ {DEFAULT_SCHEMA, "list_append", {"l", "e", nullptr}, "list_concat(l, list_value(e))"},
9439
+ {DEFAULT_SCHEMA, "array_append", {"arr", "el", nullptr}, "list_append(arr, el)"},
9440
+ {DEFAULT_SCHEMA, "list_prepend", {"e", "l", nullptr}, "list_concat(list_value(e), l)"},
9441
+ {DEFAULT_SCHEMA, "array_prepend", {"el", "arr", nullptr}, "list_prepend(el, arr)"},
9442
+ {nullptr, nullptr, {nullptr}, nullptr}};
9439
9443
 
9440
9444
  static unique_ptr<CreateFunctionInfo> GetDefaultFunction(const string &schema, const string &name) {
9441
9445
  for (idx_t index = 0; internal_macros[index].name != nullptr; index++) {
@@ -76623,9 +76627,16 @@ struct MapFun {
76623
76627
  struct MapExtractFun {
76624
76628
  static void RegisterFunction(BuiltinFunctions &set);
76625
76629
  };
76630
+
76626
76631
  struct ListExtractFun {
76627
76632
  static void RegisterFunction(BuiltinFunctions &set);
76628
76633
  };
76634
+
76635
+ struct ListConcatFun {
76636
+ static ScalarFunction GetFunction();
76637
+ static void RegisterFunction(BuiltinFunctions &set);
76638
+ };
76639
+
76629
76640
  struct CardinalityFun {
76630
76641
  static void RegisterFunction(BuiltinFunctions &set);
76631
76642
  };
@@ -83601,11 +83612,6 @@ void ArraySliceFun::RegisterFunction(BuiltinFunctions &set) {
83601
83612
 
83602
83613
 
83603
83614
 
83604
-
83605
-
83606
-
83607
-
83608
-
83609
83615
  //===----------------------------------------------------------------------===//
83610
83616
  // DuckDB
83611
83617
  //
@@ -83645,6 +83651,147 @@ public:
83645
83651
 
83646
83652
 
83647
83653
 
83654
+ namespace duckdb {
83655
+
83656
+ static void ListConcatFunction(DataChunk &args, ExpressionState &state, Vector &result) {
83657
+ D_ASSERT(args.ColumnCount() == 2);
83658
+ auto count = args.size();
83659
+
83660
+ Vector &lhs = args.data[0];
83661
+ Vector &rhs = args.data[1];
83662
+ if (lhs.GetType().id() == LogicalTypeId::SQLNULL) {
83663
+ result.Reference(rhs);
83664
+ return;
83665
+ }
83666
+ if (rhs.GetType().id() == LogicalTypeId::SQLNULL) {
83667
+ result.Reference(lhs);
83668
+ return;
83669
+ }
83670
+
83671
+ VectorData lhs_data;
83672
+ VectorData rhs_data;
83673
+ lhs.Orrify(count, lhs_data);
83674
+ rhs.Orrify(count, rhs_data);
83675
+ auto lhs_entries = (list_entry_t *)lhs_data.data;
83676
+ auto rhs_entries = (list_entry_t *)rhs_data.data;
83677
+
83678
+ auto lhs_list_size = ListVector::GetListSize(lhs);
83679
+ auto rhs_list_size = ListVector::GetListSize(rhs);
83680
+ auto &lhs_child = ListVector::GetEntry(lhs);
83681
+ auto &rhs_child = ListVector::GetEntry(rhs);
83682
+ VectorData lhs_child_data;
83683
+ VectorData rhs_child_data;
83684
+ lhs_child.Orrify(lhs_list_size, lhs_child_data);
83685
+ rhs_child.Orrify(rhs_list_size, rhs_child_data);
83686
+
83687
+ result.SetVectorType(VectorType::FLAT_VECTOR);
83688
+ auto result_entries = FlatVector::GetData<list_entry_t>(result);
83689
+ auto &result_validity = FlatVector::Validity(result);
83690
+
83691
+ idx_t offset = 0;
83692
+ for (idx_t i = 0; i < count; i++) {
83693
+ auto lhs_list_index = lhs_data.sel->get_index(i);
83694
+ auto rhs_list_index = rhs_data.sel->get_index(i);
83695
+ if (!lhs_data.validity.RowIsValid(lhs_list_index) && !rhs_data.validity.RowIsValid(rhs_list_index)) {
83696
+ result_validity.SetInvalid(i);
83697
+ continue;
83698
+ }
83699
+ result_entries[i].offset = offset;
83700
+ result_entries[i].length = 0;
83701
+ if (lhs_data.validity.RowIsValid(lhs_list_index)) {
83702
+ const auto &lhs_entry = lhs_entries[lhs_list_index];
83703
+ result_entries[i].length += lhs_entry.length;
83704
+ ListVector::Append(result, lhs_child, *lhs_child_data.sel, lhs_entry.offset + lhs_entry.length,
83705
+ lhs_entry.offset);
83706
+ }
83707
+ if (rhs_data.validity.RowIsValid(rhs_list_index)) {
83708
+ const auto &rhs_entry = rhs_entries[rhs_list_index];
83709
+ result_entries[i].length += rhs_entry.length;
83710
+ ListVector::Append(result, rhs_child, *rhs_child_data.sel, rhs_entry.offset + rhs_entry.length,
83711
+ rhs_entry.offset);
83712
+ }
83713
+ offset += result_entries[i].length;
83714
+ }
83715
+ D_ASSERT(ListVector::GetListSize(result) == offset);
83716
+
83717
+ if (lhs.GetVectorType() == VectorType::CONSTANT_VECTOR && rhs.GetVectorType() == VectorType::CONSTANT_VECTOR) {
83718
+ result.SetVectorType(VectorType::CONSTANT_VECTOR);
83719
+ }
83720
+ }
83721
+
83722
+ static unique_ptr<FunctionData> ListConcatBind(ClientContext &context, ScalarFunction &bound_function,
83723
+ vector<unique_ptr<Expression>> &arguments) {
83724
+ D_ASSERT(bound_function.arguments.size() == 2);
83725
+
83726
+ auto &lhs = arguments[0]->return_type;
83727
+ auto &rhs = arguments[1]->return_type;
83728
+ if (lhs.id() == LogicalTypeId::SQLNULL && rhs.id() == LogicalTypeId::SQLNULL) {
83729
+ bound_function.return_type = LogicalType::SQLNULL;
83730
+ } else if (lhs.id() == LogicalTypeId::SQLNULL || rhs.id() == LogicalTypeId::SQLNULL) {
83731
+ // we mimic postgres behaviour: list_concat(NULL, my_list) = my_list
83732
+ bound_function.arguments[0] = lhs;
83733
+ bound_function.arguments[1] = rhs;
83734
+ bound_function.return_type = rhs.id() == LogicalTypeId::SQLNULL ? lhs : rhs;
83735
+ } else {
83736
+ D_ASSERT(lhs.id() == LogicalTypeId::LIST);
83737
+ D_ASSERT(rhs.id() == LogicalTypeId::LIST);
83738
+
83739
+ // Resolve list type
83740
+ auto child_type = LogicalType::SQLNULL;
83741
+ for (const auto &argument : arguments) {
83742
+ child_type = LogicalType::MaxLogicalType(child_type, ListType::GetChildType(argument->return_type));
83743
+ }
83744
+ ExpressionBinder::ResolveParameterType(child_type);
83745
+ auto list_type = LogicalType::LIST(move(child_type));
83746
+
83747
+ bound_function.arguments[0] = list_type;
83748
+ bound_function.arguments[1] = list_type;
83749
+ bound_function.return_type = list_type;
83750
+ }
83751
+ return make_unique<VariableReturnBindData>(bound_function.return_type);
83752
+ }
83753
+
83754
+ static unique_ptr<BaseStatistics> ListConcatStats(ClientContext &context, BoundFunctionExpression &expr,
83755
+ FunctionData *bind_data,
83756
+ vector<unique_ptr<BaseStatistics>> &child_stats) {
83757
+ D_ASSERT(child_stats.size() == 2);
83758
+ if (!child_stats[0] || !child_stats[1]) {
83759
+ return nullptr;
83760
+ }
83761
+
83762
+ auto &left_stats = (ListStatistics &)*child_stats[0];
83763
+ auto &right_stats = (ListStatistics &)*child_stats[1];
83764
+
83765
+ auto stats = left_stats.Copy();
83766
+ stats->Merge(right_stats);
83767
+
83768
+ return stats;
83769
+ }
83770
+
83771
+ ScalarFunction ListConcatFun::GetFunction() {
83772
+ // the arguments and return types are actually set in the binder function
83773
+ return ScalarFunction({LogicalType::LIST(LogicalType::ANY), LogicalType::LIST(LogicalType::ANY)},
83774
+ LogicalType::LIST(LogicalType::ANY), ListConcatFunction, false, ListConcatBind, nullptr,
83775
+ ListConcatStats);
83776
+ }
83777
+
83778
+ void ListConcatFun::RegisterFunction(BuiltinFunctions &set) {
83779
+ set.AddFunction({"list_concat", "list_cat", "array_concat", "array_cat"}, GetFunction());
83780
+ }
83781
+
83782
+ } // namespace duckdb
83783
+
83784
+
83785
+
83786
+
83787
+
83788
+
83789
+
83790
+
83791
+
83792
+
83793
+
83794
+
83648
83795
  namespace duckdb {
83649
83796
 
83650
83797
  template <class T, bool HEAP_REF = false, bool VALIDITY_ONLY = false>
@@ -85613,6 +85760,7 @@ void BuiltinFunctions::RegisterNestedFunctions() {
85613
85760
  Register<ArraySliceFun>();
85614
85761
  Register<StructPackFun>();
85615
85762
  Register<StructExtractFun>();
85763
+ Register<ListConcatFun>();
85616
85764
  Register<ListValueFun>();
85617
85765
  Register<ListExtractFun>();
85618
85766
  Register<ListRangeFun>();
@@ -85959,6 +86107,7 @@ struct BitwiseNotFun {
85959
86107
 
85960
86108
 
85961
86109
 
86110
+
85962
86111
  #include <limits>
85963
86112
 
85964
86113
  namespace duckdb {
@@ -86274,6 +86423,8 @@ void AddFun::RegisterFunction(BuiltinFunctions &set) {
86274
86423
 
86275
86424
  functions.AddFunction(GetFunction(LogicalType::TIMESTAMP, LogicalType::INTERVAL));
86276
86425
  functions.AddFunction(GetFunction(LogicalType::INTERVAL, LogicalType::TIMESTAMP));
86426
+ // we can add lists together
86427
+ functions.AddFunction(ListConcatFun::GetFunction());
86277
86428
 
86278
86429
  set.AddFunction(functions);
86279
86430
  }
@@ -87856,6 +88007,7 @@ void CHR::RegisterFunction(BuiltinFunctions &set) {
87856
88007
 
87857
88008
 
87858
88009
 
88010
+
87859
88011
  #include <string.h>
87860
88012
 
87861
88013
  namespace duckdb {
@@ -88101,6 +88253,7 @@ void ConcatFun::RegisterFunction(BuiltinFunctions &set) {
88101
88253
  concat_op.AddFunction(
88102
88254
  ScalarFunction({LogicalType::VARCHAR, LogicalType::VARCHAR}, LogicalType::VARCHAR, ConcatOperator));
88103
88255
  concat_op.AddFunction(ScalarFunction({LogicalType::BLOB, LogicalType::BLOB}, LogicalType::BLOB, ConcatOperator));
88256
+ concat_op.AddFunction(ListConcatFun::GetFunction());
88104
88257
  set.AddFunction(concat_op);
88105
88258
 
88106
88259
  ScalarFunction concat_ws = ScalarFunction("concat_ws", {LogicalType::VARCHAR, LogicalType::VARCHAR},
package/src/duckdb.hpp CHANGED
@@ -10,8 +10,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
10
10
 
11
11
  #pragma once
12
12
  #define DUCKDB_AMALGAMATION 1
13
- #define DUCKDB_SOURCE_ID "c0d4ec2d7"
14
- #define DUCKDB_VERSION "0.3.1-dev511"
13
+ #define DUCKDB_SOURCE_ID "9fd34ad70"
14
+ #define DUCKDB_VERSION "0.3.1-dev517"
15
15
  //===----------------------------------------------------------------------===//
16
16
  // DuckDB
17
17
  //