duckdb 0.3.3-dev332.0 → 0.3.3-dev349.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.3-dev332.0",
4
+ "version": "0.3.3-dev349.0",
5
5
  "description": "DuckDB node.js API",
6
6
  "gypfile": true,
7
7
  "dependencies": {
package/src/duckdb.cpp CHANGED
@@ -75343,6 +75343,11 @@ struct ListConcatFun {
75343
75343
  static void RegisterFunction(BuiltinFunctions &set);
75344
75344
  };
75345
75345
 
75346
+ struct ListContainsFun {
75347
+ static ScalarFunction GetFunction();
75348
+ static void RegisterFunction(BuiltinFunctions &set);
75349
+ };
75350
+
75346
75351
  struct CardinalityFun {
75347
75352
  static void RegisterFunction(BuiltinFunctions &set);
75348
75353
  };
@@ -83501,6 +83506,226 @@ void ListConcatFun::RegisterFunction(BuiltinFunctions &set) {
83501
83506
 
83502
83507
 
83503
83508
 
83509
+ namespace duckdb {
83510
+
83511
+ template <class T>
83512
+ static inline bool ValueCompare(const T &left, const T &right) {
83513
+ return left == right;
83514
+ }
83515
+
83516
+ template <>
83517
+ inline bool ValueCompare(const string_t &left, const string_t &right) {
83518
+ return StringComparisonOperators::EqualsOrNot<false>(left, right);
83519
+ }
83520
+
83521
+ template <>
83522
+ inline bool ValueCompare(const Value &left, const Value &right) {
83523
+ return left == right;
83524
+ }
83525
+
83526
+ template <class T>
83527
+ static void TemplatedListContainsFunction(DataChunk &args, ExpressionState &state, Vector &result) {
83528
+ D_ASSERT(args.ColumnCount() == 2);
83529
+ auto count = args.size();
83530
+ Vector &list = args.data[0];
83531
+ Vector &value_vector = args.data[1];
83532
+
83533
+ result.SetVectorType(VectorType::FLAT_VECTOR);
83534
+ auto result_entries = FlatVector::GetData<bool>(result); // Create a vector of bool
83535
+ auto &result_validity = FlatVector::Validity(result);
83536
+
83537
+ if (list.GetType().id() == LogicalTypeId::SQLNULL) {
83538
+ result_validity.SetInvalid(0);
83539
+ return;
83540
+ }
83541
+
83542
+ auto list_size = ListVector::GetListSize(list);
83543
+ auto &child_vector = ListVector::GetEntry(list);
83544
+
83545
+ VectorData child_data;
83546
+ child_vector.Orrify(list_size, child_data);
83547
+
83548
+ VectorData list_data;
83549
+ list.Orrify(count, list_data);
83550
+ auto list_entries = (list_entry_t *)list_data.data;
83551
+
83552
+ VectorData value_data;
83553
+ value_vector.Orrify(count, value_data);
83554
+
83555
+ for (idx_t i = 0; i < count; i++) {
83556
+ auto list_index = list_data.sel->get_index(i);
83557
+ auto value_index = value_data.sel->get_index(i);
83558
+
83559
+ if (!list_data.validity.RowIsValid(list_index) || !value_data.validity.RowIsValid(value_index)) {
83560
+ result_validity.SetInvalid(i);
83561
+ continue;
83562
+ }
83563
+
83564
+ const auto &list_entry = list_entries[list_index];
83565
+ auto source_idx = child_data.sel->get_index(list_entry.offset);
83566
+ auto child_value = FlatVector::GetData<T>(child_vector);
83567
+
83568
+ auto values = FlatVector::GetData<T>(value_vector);
83569
+ result_entries[list_index] = false;
83570
+ for (idx_t child_idx = 0; child_idx < list_entry.length; child_idx++) {
83571
+ auto child_value_idx = source_idx + child_idx;
83572
+
83573
+ if (!child_data.validity.RowIsValid(child_value_idx)) {
83574
+ continue;
83575
+ }
83576
+ if (ValueCompare<T>(child_value[child_value_idx], values[value_index])) {
83577
+ result_entries[list_index] = true;
83578
+ break; // Found value in list, no need to look further
83579
+ }
83580
+ }
83581
+ }
83582
+ }
83583
+
83584
+ static void NestedListContainsFunction(DataChunk &args, ExpressionState &state, Vector &result) {
83585
+ D_ASSERT(args.ColumnCount() == 2);
83586
+ auto count = args.size();
83587
+ Vector &list = args.data[0];
83588
+ Vector &value_vector = args.data[1];
83589
+
83590
+ result.SetVectorType(VectorType::FLAT_VECTOR);
83591
+ auto result_entries = FlatVector::GetData<bool>(result); // Create a vector of bool
83592
+ auto &result_validity = FlatVector::Validity(result);
83593
+
83594
+ if (list.GetType().id() == LogicalTypeId::SQLNULL) {
83595
+ result_validity.SetInvalid(0);
83596
+ return;
83597
+ }
83598
+
83599
+ auto list_size = ListVector::GetListSize(list);
83600
+ auto &child_vector = ListVector::GetEntry(list);
83601
+
83602
+ VectorData child_data;
83603
+ child_vector.Orrify(list_size, child_data);
83604
+
83605
+ VectorData list_data;
83606
+ list.Orrify(count, list_data);
83607
+ auto list_entries = (list_entry_t *)list_data.data;
83608
+
83609
+ VectorData value_data;
83610
+ value_vector.Orrify(count, value_data);
83611
+
83612
+ for (idx_t i = 0; i < count; i++) {
83613
+ auto list_index = list_data.sel->get_index(i);
83614
+ auto value_index = value_data.sel->get_index(i);
83615
+
83616
+ if (!list_data.validity.RowIsValid(list_index) || !value_data.validity.RowIsValid(value_index)) {
83617
+ result_validity.SetInvalid(i);
83618
+ continue;
83619
+ }
83620
+
83621
+ const auto &list_entry = list_entries[list_index];
83622
+ auto source_idx = child_data.sel->get_index(list_entry.offset);
83623
+
83624
+ result_entries[list_index] = false;
83625
+ for (idx_t child_idx = 0; child_idx < list_entry.length; child_idx++) {
83626
+ auto child_value_idx = source_idx + child_idx;
83627
+ if (!child_data.validity.RowIsValid(child_value_idx)) {
83628
+ continue;
83629
+ }
83630
+ if (ValueCompare<Value>(child_vector.GetValue(child_value_idx), value_vector.GetValue(value_index))) {
83631
+ result_entries[list_index] = true;
83632
+ break; // Found value in list, no need to look further
83633
+ }
83634
+ }
83635
+ }
83636
+ }
83637
+
83638
+ static void ListContainsFunction(DataChunk &args, ExpressionState &state, Vector &result) {
83639
+ switch (args.data[1].GetType().InternalType()) {
83640
+ case PhysicalType::BOOL:
83641
+ case PhysicalType::INT8:
83642
+ TemplatedListContainsFunction<int8_t>(args, state, result);
83643
+ break;
83644
+ case PhysicalType::INT16:
83645
+ TemplatedListContainsFunction<int16_t>(args, state, result);
83646
+ break;
83647
+ case PhysicalType::INT32:
83648
+ TemplatedListContainsFunction<int32_t>(args, state, result);
83649
+ break;
83650
+ case PhysicalType::INT64:
83651
+ TemplatedListContainsFunction<int64_t>(args, state, result);
83652
+ break;
83653
+ case PhysicalType::INT128:
83654
+ TemplatedListContainsFunction<hugeint_t>(args, state, result);
83655
+ break;
83656
+ case PhysicalType::UINT8:
83657
+ TemplatedListContainsFunction<uint8_t>(args, state, result);
83658
+ break;
83659
+ case PhysicalType::UINT16:
83660
+ TemplatedListContainsFunction<uint16_t>(args, state, result);
83661
+ break;
83662
+ case PhysicalType::UINT32:
83663
+ TemplatedListContainsFunction<uint32_t>(args, state, result);
83664
+ break;
83665
+ case PhysicalType::UINT64:
83666
+ TemplatedListContainsFunction<uint64_t>(args, state, result);
83667
+ break;
83668
+ case PhysicalType::FLOAT:
83669
+ TemplatedListContainsFunction<float>(args, state, result);
83670
+ break;
83671
+ case PhysicalType::DOUBLE:
83672
+ TemplatedListContainsFunction<double>(args, state, result);
83673
+ break;
83674
+ case PhysicalType::VARCHAR:
83675
+ TemplatedListContainsFunction<string_t>(args, state, result);
83676
+ break;
83677
+ case PhysicalType::MAP:
83678
+ case PhysicalType::STRUCT:
83679
+ case PhysicalType::LIST:
83680
+ NestedListContainsFunction(args, state, result);
83681
+ break;
83682
+ default:
83683
+ throw NotImplementedException("This function has not been implemented for this type");
83684
+ }
83685
+ }
83686
+
83687
+ static unique_ptr<FunctionData> ListContainsBind(ClientContext &context, ScalarFunction &bound_function,
83688
+ vector<unique_ptr<Expression>> &arguments) {
83689
+ D_ASSERT(bound_function.arguments.size() == 2);
83690
+
83691
+ const auto &list = arguments[0]->return_type; // change to list
83692
+ const auto &value = arguments[1]->return_type;
83693
+ if (list.id() == LogicalTypeId::SQLNULL && value.id() == LogicalTypeId::SQLNULL) {
83694
+ bound_function.arguments[0] = LogicalType::SQLNULL;
83695
+ bound_function.arguments[1] = LogicalType::SQLNULL;
83696
+ bound_function.return_type = LogicalType::SQLNULL;
83697
+ } else if (list.id() == LogicalTypeId::SQLNULL || value.id() == LogicalTypeId::SQLNULL) {
83698
+ // In case either the list or the value is NULL, return NULL
83699
+ // Similar to behaviour of prestoDB
83700
+ bound_function.arguments[0] = list;
83701
+ bound_function.arguments[1] = value;
83702
+ bound_function.return_type = LogicalTypeId::SQLNULL;
83703
+ } else {
83704
+ auto const &child_type = ListType::GetChildType(arguments[0]->return_type);
83705
+ auto max_child_type = LogicalType::MaxLogicalType(child_type, value);
83706
+ ExpressionBinder::ResolveParameterType(max_child_type);
83707
+ auto list_type = LogicalType::LIST(max_child_type);
83708
+
83709
+ bound_function.arguments[0] = list_type;
83710
+ bound_function.arguments[1] = value == max_child_type ? value : max_child_type;
83711
+ bound_function.return_type = LogicalType::BOOLEAN;
83712
+ }
83713
+ return make_unique<VariableReturnBindData>(bound_function.return_type);
83714
+ }
83715
+
83716
+ ScalarFunction ListContainsFun::GetFunction() {
83717
+ return ScalarFunction({LogicalType::LIST(LogicalType::ANY), LogicalType::ANY}, // argument list
83718
+ LogicalType::BOOLEAN, // return type
83719
+ ListContainsFunction, false, ListContainsBind, nullptr);
83720
+ }
83721
+
83722
+ void ListContainsFun::RegisterFunction(BuiltinFunctions &set) {
83723
+ set.AddFunction({"list_contains", "array_contains", "list_has", "array_has"}, GetFunction());
83724
+ }
83725
+ } // namespace duckdb
83726
+
83727
+
83728
+
83504
83729
 
83505
83730
 
83506
83731
 
@@ -85551,6 +85776,7 @@ void BuiltinFunctions::RegisterNestedFunctions() {
85551
85776
  Register<StructPackFun>();
85552
85777
  Register<StructExtractFun>();
85553
85778
  Register<ListConcatFun>();
85779
+ Register<ListContainsFun>();
85554
85780
  Register<ListValueFun>();
85555
85781
  Register<ListExtractFun>();
85556
85782
  Register<ListRangeFun>();
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 "618e5518a"
15
- #define DUCKDB_VERSION "v0.3.3-dev332"
14
+ #define DUCKDB_SOURCE_ID "d226502f3"
15
+ #define DUCKDB_VERSION "v0.3.3-dev349"
16
16
  //===----------------------------------------------------------------------===//
17
17
  // DuckDB
18
18
  //