duckdb 0.5.1-dev13.0 → 0.5.1-dev134.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/src/duckdb.cpp CHANGED
@@ -620,7 +620,88 @@ public:
620
620
 
621
621
  } // namespace duckdb
622
622
 
623
+ //===----------------------------------------------------------------------===//
624
+ // DuckDB
625
+ //
626
+ // extension_functions.hpp
627
+ //
628
+ //
629
+ //===----------------------------------------------------------------------===//
630
+
631
+
623
632
 
633
+
634
+
635
+ namespace duckdb {
636
+
637
+ struct ExtensionFunction {
638
+ char function[48];
639
+ char extension[48];
640
+ };
641
+
642
+ static constexpr ExtensionFunction EXTENSION_FUNCTIONS[] = {
643
+ {"->>", "json"},
644
+ {"array_to_json", "json"},
645
+ {"create_fts_index", "fts"},
646
+ {"dbgen", "tpch"},
647
+ {"drop_fts_index", "fts"},
648
+ {"dsdgen", "tpcds"},
649
+ {"excel_text", "excel"},
650
+ {"from_json", "json"},
651
+ {"from_json_strict", "json"},
652
+ {"from_substrait", "substrait"},
653
+ {"get_substrait", "substrait"},
654
+ {"get_substrait_json", "substrait"},
655
+ {"icu_calendar_names", "icu"},
656
+ {"icu_sort_key", "icu"},
657
+ {"json", "json"},
658
+ {"json_array", "json"},
659
+ {"json_array_length", "json"},
660
+ {"json_extract", "json"},
661
+ {"json_extract_path", "json"},
662
+ {"json_extract_path_text", "json"},
663
+ {"json_extract_string", "json"},
664
+ {"json_group_array", "json"},
665
+ {"json_group_object", "json"},
666
+ {"json_group_structure", "json"},
667
+ {"json_merge_patch", "json"},
668
+ {"json_object", "json"},
669
+ {"json_quote", "json"},
670
+ {"json_structure", "json"},
671
+ {"json_transform", "json"},
672
+ {"json_transform_strict", "json"},
673
+ {"json_type", "json"},
674
+ {"json_valid", "json"},
675
+ {"make_timestamptz", "icu"},
676
+ {"parquet_metadata", "parquet"},
677
+ {"parquet_scan", "parquet"},
678
+ {"parquet_schema", "parquet"},
679
+ {"pg_timezone_names", "icu"},
680
+ {"postgres_attach", "postgres_scanner"},
681
+ {"postgres_scan", "postgres_scanner"},
682
+ {"postgres_scan_pushdown", "postgres_scanner"},
683
+ {"read_json_objects", "json"},
684
+ {"read_ndjson_objects", "json"},
685
+ {"read_parquet", "parquet"},
686
+ {"row_to_json", "json"},
687
+ {"sqlite_attach", "sqlite_scanner"},
688
+ {"sqlite_scan", "sqlite_scanner"},
689
+ {"stem", "fts"},
690
+ {"text", "excel"},
691
+ {"to_json", "json"},
692
+ {"tpcds", "tpcds"},
693
+ {"tpcds_answers", "tpcds"},
694
+ {"tpcds_queries", "tpcds"},
695
+ {"tpch", "tpch"},
696
+ {"tpch_answers", "tpch"},
697
+ {"tpch_queries", "tpch"},
698
+ {"visualize_diff_profiling_output", "visualizer"},
699
+ {"visualize_json_profiling_output", "visualizer"},
700
+ {"visualize_last_profiling_output", "visualizer"},
701
+ };
702
+ } // namespace duckdb
703
+
704
+ #include <algorithm>
624
705
  namespace duckdb {
625
706
 
626
707
  string SimilarCatalogEntry::GetQualifiedName() const {
@@ -823,6 +904,16 @@ SimilarCatalogEntry Catalog::SimilarEntryInSchemas(ClientContext &context, const
823
904
  return {most_similar.first, most_similar.second, schema_of_most_similar};
824
905
  }
825
906
 
907
+ string FindExtension(const string &function_name) {
908
+ auto size = sizeof(EXTENSION_FUNCTIONS) / sizeof(ExtensionFunction);
909
+ auto it = std::lower_bound(
910
+ EXTENSION_FUNCTIONS, EXTENSION_FUNCTIONS + size, function_name,
911
+ [](const ExtensionFunction &element, const string &value) { return element.function < value; });
912
+ if (it != EXTENSION_FUNCTIONS + size && it->function == function_name) {
913
+ return it->extension;
914
+ }
915
+ return "";
916
+ }
826
917
  CatalogException Catalog::CreateMissingEntryException(ClientContext &context, const string &entry_name,
827
918
  CatalogType type, const vector<SchemaCatalogEntry *> &schemas,
828
919
  QueryErrorContext error_context) {
@@ -836,7 +927,12 @@ CatalogException Catalog::CreateMissingEntryException(ClientContext &context, co
836
927
  }
837
928
  });
838
929
  auto unseen_entry = SimilarEntryInSchemas(context, entry_name, type, unseen_schemas);
839
-
930
+ auto extension_name = FindExtension(entry_name);
931
+ if (!extension_name.empty()) {
932
+ return CatalogException("Function with name %s is not on the catalog, but it exists in the %s extension. To "
933
+ "Install and Load the extension, run: INSTALL %s; LOAD %s;",
934
+ entry_name, extension_name, extension_name, extension_name);
935
+ }
840
936
  string did_you_mean;
841
937
  if (unseen_entry.Found() && unseen_entry.distance < entry.distance) {
842
938
  did_you_mean = "\nDid you mean \"" + unseen_entry.GetQualifiedName() + "\"?";
@@ -4934,12 +5030,16 @@ bool CatalogSet::AlterEntry(ClientContext &context, const string &name, AlterInf
4934
5030
  throw CatalogException(rename_err_msg, original_name, value->name);
4935
5031
  }
4936
5032
  }
4937
- PutMapping(context, value->name, entry_index);
4938
- DeleteMapping(context, original_name);
4939
5033
  }
4940
5034
  //! Check the dependency manager to verify that there are no conflicting dependencies with this alter
4941
5035
  catalog.dependency_manager->AlterObject(context, entry, value.get());
4942
5036
 
5037
+ if (value->name != original_name) {
5038
+ // Do PutMapping and DeleteMapping after dependency check
5039
+ PutMapping(context, value->name, entry_index);
5040
+ DeleteMapping(context, original_name);
5041
+ }
5042
+
4943
5043
  value->timestamp = transaction.transaction_id;
4944
5044
  value->child = move(entries[entry_index]);
4945
5045
  value->child->parent = value.get();
@@ -6506,7 +6606,7 @@ static void GetBitPosition(idx_t row_idx, idx_t &current_byte, uint8_t &current_
6506
6606
  }
6507
6607
 
6508
6608
  static void UnsetBit(uint8_t *data, idx_t current_byte, uint8_t current_bit) {
6509
- data[current_byte] &= ~(1 << current_bit);
6609
+ data[current_byte] &= ~((uint64_t)1 << current_bit);
6510
6610
  }
6511
6611
 
6512
6612
  static void NextBit(idx_t &current_byte, uint8_t &current_bit) {
@@ -28558,7 +28658,7 @@ template <idx_t radix_bits>
28558
28658
  struct RadixPartitioningConstants {
28559
28659
  public:
28560
28660
  static constexpr const idx_t NUM_RADIX_BITS = radix_bits;
28561
- static constexpr const idx_t NUM_PARTITIONS = 1 << NUM_RADIX_BITS;
28661
+ static constexpr const idx_t NUM_PARTITIONS = (idx_t)1 << NUM_RADIX_BITS;
28562
28662
  static constexpr const idx_t TMP_BUF_SIZE = 8;
28563
28663
 
28564
28664
  public:
@@ -28576,7 +28676,7 @@ private:
28576
28676
  struct RadixPartitioning {
28577
28677
  public:
28578
28678
  static idx_t NumberOfPartitions(idx_t radix_bits) {
28579
- return 1 << radix_bits;
28679
+ return (idx_t)1 << radix_bits;
28580
28680
  }
28581
28681
 
28582
28682
  //! Partition the data in block_collection/string_heap to multiple partitions
@@ -33336,6 +33436,9 @@ void RowOperations::UnswizzleHeapPointer(const RowLayout &layout, const data_ptr
33336
33436
 
33337
33437
  static inline void VerifyUnswizzledString(const RowLayout &layout, const idx_t &col_idx, const data_ptr_t &row_ptr) {
33338
33438
  #ifdef DEBUG
33439
+ if (layout.GetTypes()[col_idx] == LogicalTypeId::BLOB) {
33440
+ return;
33441
+ }
33339
33442
  idx_t entry_idx;
33340
33443
  idx_t idx_in_entry;
33341
33444
  ValidityBytes::GetEntryIndex(col_idx, entry_idx, idx_in_entry);
@@ -35673,7 +35776,10 @@ struct SortConstants {
35673
35776
 
35674
35777
  struct SortLayout {
35675
35778
  public:
35779
+ SortLayout() {
35780
+ }
35676
35781
  explicit SortLayout(const vector<BoundOrderByNode> &orders);
35782
+ SortLayout GetPrefixComparisonLayout(idx_t num_prefix_cols) const;
35677
35783
 
35678
35784
  public:
35679
35785
  idx_t column_count;
@@ -37324,6 +37430,32 @@ SortLayout::SortLayout(const vector<BoundOrderByNode> &orders)
37324
37430
  blob_layout.Initialize(blob_layout_types);
37325
37431
  }
37326
37432
 
37433
+ SortLayout SortLayout::GetPrefixComparisonLayout(idx_t num_prefix_cols) const {
37434
+ SortLayout result;
37435
+ result.column_count = num_prefix_cols;
37436
+ result.all_constant = true;
37437
+ result.comparison_size = 0;
37438
+ for (idx_t col_idx = 0; col_idx < num_prefix_cols; col_idx++) {
37439
+ result.order_types.push_back(order_types[col_idx]);
37440
+ result.order_by_null_types.push_back(order_by_null_types[col_idx]);
37441
+ result.logical_types.push_back(logical_types[col_idx]);
37442
+
37443
+ result.all_constant = result.all_constant && constant_size[col_idx];
37444
+ result.constant_size.push_back(constant_size[col_idx]);
37445
+
37446
+ result.comparison_size += column_sizes[col_idx];
37447
+ result.column_sizes.push_back(column_sizes[col_idx]);
37448
+
37449
+ result.prefix_lengths.push_back(prefix_lengths[col_idx]);
37450
+ result.stats.push_back(stats[col_idx]);
37451
+ result.has_null.push_back(has_null[col_idx]);
37452
+ }
37453
+ result.entry_size = entry_size;
37454
+ result.blob_layout = blob_layout;
37455
+ result.sorting_to_blob_col = sorting_to_blob_col;
37456
+ return result;
37457
+ }
37458
+
37327
37459
  LocalSortState::LocalSortState() : initialized(false) {
37328
37460
  }
37329
37461
 
@@ -47573,11 +47705,36 @@ Value Value::CreateValue(dtime_t value) {
47573
47705
  return Value::TIME(value);
47574
47706
  }
47575
47707
 
47708
+ template <>
47709
+ Value Value::CreateValue(dtime_tz_t value) {
47710
+ return Value::TIMETZ(value);
47711
+ }
47712
+
47576
47713
  template <>
47577
47714
  Value Value::CreateValue(timestamp_t value) {
47578
47715
  return Value::TIMESTAMP(value);
47579
47716
  }
47580
47717
 
47718
+ template <>
47719
+ Value Value::CreateValue(timestamp_sec_t value) {
47720
+ return Value::TIMESTAMPSEC(value);
47721
+ }
47722
+
47723
+ template <>
47724
+ Value Value::CreateValue(timestamp_ms_t value) {
47725
+ return Value::TIMESTAMPMS(value);
47726
+ }
47727
+
47728
+ template <>
47729
+ Value Value::CreateValue(timestamp_ns_t value) {
47730
+ return Value::TIMESTAMPNS(value);
47731
+ }
47732
+
47733
+ template <>
47734
+ Value Value::CreateValue(timestamp_tz_t value) {
47735
+ return Value::TIMESTAMPTZ(value);
47736
+ }
47737
+
47581
47738
  template <>
47582
47739
  Value Value::CreateValue(const char *value) {
47583
47740
  return Value(string(value));
@@ -49150,19 +49307,6 @@ void Vector::Resize(idx_t cur_size, idx_t new_size) {
49150
49307
  }
49151
49308
  }
49152
49309
 
49153
- // FIXME Just like DECIMAL, it's important that type_info gets considered when determining whether or not to cast
49154
- // just comparing internal type is not always enough
49155
- static bool ValueShouldBeCast(const LogicalType &incoming, const LogicalType &target) {
49156
- if (incoming.InternalType() != target.InternalType()) {
49157
- return true;
49158
- }
49159
- if (incoming.id() == LogicalTypeId::DECIMAL && incoming.id() == target.id()) {
49160
- //! Compare the type_info
49161
- return incoming != target;
49162
- }
49163
- return false;
49164
- }
49165
-
49166
49310
  void Vector::SetValue(idx_t index, const Value &val) {
49167
49311
  if (GetVectorType() == VectorType::DICTIONARY_VECTOR) {
49168
49312
  // dictionary: apply dictionary and forward to child
@@ -49170,10 +49314,11 @@ void Vector::SetValue(idx_t index, const Value &val) {
49170
49314
  auto &child = DictionaryVector::Child(*this);
49171
49315
  return child.SetValue(sel_vector.get_index(index), val);
49172
49316
  }
49173
- if (ValueShouldBeCast(val.type(), GetType())) {
49317
+ if (val.type() != GetType()) {
49174
49318
  SetValue(index, val.CastAs(GetType()));
49175
49319
  return;
49176
49320
  }
49321
+ D_ASSERT(val.type().InternalType() == GetType().InternalType());
49177
49322
 
49178
49323
  validity.EnsureWritable();
49179
49324
  validity.Set(index, !val.IsNull());
@@ -49424,7 +49569,10 @@ Value Vector::GetValue(const Vector &v_p, idx_t index_p) {
49424
49569
  auto value = GetValueInternal(v_p, index_p);
49425
49570
  // set the alias of the type to the correct value, if there is a type alias
49426
49571
  if (v_p.GetType().HasAlias()) {
49427
- value.type().SetAlias(v_p.GetType().GetAlias());
49572
+ value.type().CopyAuxInfo(v_p.GetType());
49573
+ }
49574
+ if (v_p.GetType().id() != LogicalTypeId::AGGREGATE_STATE && value.type().id() != LogicalTypeId::AGGREGATE_STATE) {
49575
+ D_ASSERT(v_p.GetType() == value.type());
49428
49576
  }
49429
49577
  return value;
49430
49578
  }
@@ -51491,6 +51639,7 @@ public:
51491
51639
  if (!alias.empty()) {
51492
51640
  return false;
51493
51641
  }
51642
+ //! We only need to compare aliases when both types have them in this case
51494
51643
  return true;
51495
51644
  }
51496
51645
  if (alias != other_p->alias) {
@@ -51504,8 +51653,7 @@ public:
51504
51653
  if (type != other_p->type) {
51505
51654
  return false;
51506
51655
  }
51507
- auto &other = (ExtraTypeInfo &)*other_p;
51508
- return alias == other.alias && EqualsInternal(other_p);
51656
+ return alias == other_p->alias && EqualsInternal(other_p);
51509
51657
  }
51510
51658
  //! Serializes a ExtraTypeInfo to a stand-alone binary blob
51511
51659
  virtual void Serialize(FieldWriter &writer) const {};
@@ -52184,10 +52332,7 @@ LogicalType LogicalType::Deserialize(Deserializer &source) {
52184
52332
  return LogicalType(id, move(info));
52185
52333
  }
52186
52334
 
52187
- bool LogicalType::operator==(const LogicalType &rhs) const {
52188
- if (id_ != rhs.id_) {
52189
- return false;
52190
- }
52335
+ bool LogicalType::EqualTypeInfo(const LogicalType &rhs) const {
52191
52336
  if (type_info_.get() == rhs.type_info_.get()) {
52192
52337
  return true;
52193
52338
  }
@@ -52199,6 +52344,13 @@ bool LogicalType::operator==(const LogicalType &rhs) const {
52199
52344
  }
52200
52345
  }
52201
52346
 
52347
+ bool LogicalType::operator==(const LogicalType &rhs) const {
52348
+ if (id_ != rhs.id_) {
52349
+ return false;
52350
+ }
52351
+ return EqualTypeInfo(rhs);
52352
+ }
52353
+
52202
52354
  } // namespace duckdb
52203
52355
 
52204
52356
 
@@ -64927,12 +65079,14 @@ public:
64927
65079
 
64928
65080
  WindowGlobalHashGroup(BufferManager &buffer_manager, const Orders &partitions, const Orders &orders,
64929
65081
  const Types &payload_types, idx_t max_mem, bool external)
64930
- : memory_per_thread(max_mem), count(0), partition_layout(partitions) {
65082
+ : memory_per_thread(max_mem), count(0) {
64931
65083
 
64932
65084
  RowLayout payload_layout;
64933
65085
  payload_layout.Initialize(payload_types);
64934
65086
  global_sort = make_unique<GlobalSortState>(buffer_manager, orders, payload_layout);
64935
65087
  global_sort->external = external;
65088
+
65089
+ partition_layout = global_sort->sort_layout.GetPrefixComparisonLayout(partitions.size());
64936
65090
  }
64937
65091
 
64938
65092
  void Combine(LocalSortState &local_sort) {
@@ -80935,7 +81089,7 @@ PerfectAggregateHashTable::PerfectAggregateHashTable(Allocator &allocator, Buffe
80935
81089
  total_required_bits += group_bits;
80936
81090
  }
80937
81091
  // the total amount of groups we allocate space for is 2^required_bits
80938
- total_groups = 1 << total_required_bits;
81092
+ total_groups = (uint64_t)1 << total_required_bits;
80939
81093
  // we don't need to store the groups in a perfect hash table, since the group keys can be deduced by their location
80940
81094
  grouping_columns = group_types_p.size();
80941
81095
  layout.Initialize(move(aggregate_objects_p));
@@ -81119,7 +81273,7 @@ static void ReconstructGroupVectorTemplated(uint32_t group_values[], Value &min,
81119
81273
  static void ReconstructGroupVector(uint32_t group_values[], Value &min, idx_t required_bits, idx_t shift,
81120
81274
  idx_t entry_count, Vector &result) {
81121
81275
  // construct the mask for this entry
81122
- idx_t mask = (1 << required_bits) - 1;
81276
+ idx_t mask = ((uint64_t)1 << required_bits) - 1;
81123
81277
  switch (result.GetType().InternalType()) {
81124
81278
  case PhysicalType::INT8:
81125
81279
  ReconstructGroupVectorTemplated<int8_t>(group_values, min, mask, shift, entry_count, result);
@@ -85366,7 +85520,7 @@ void RadixPartitionedHashTable::SetGroupingValues() {
85366
85520
  for (idx_t i = 0; i < grouping.size(); i++) {
85367
85521
  if (grouping_set.find(grouping[i]) == grouping_set.end()) {
85368
85522
  // we don't group on this value!
85369
- grouping_value += 1 << (grouping.size() - (i + 1));
85523
+ grouping_value += (int64_t)1 << (grouping.size() - (i + 1));
85370
85524
  }
85371
85525
  }
85372
85526
  grouping_values.push_back(Value::BIGINT(grouping_value));
@@ -93281,21 +93435,21 @@ AggregateFunction GetHistogramFunction(const LogicalType &type) {
93281
93435
  case LogicalType::VARCHAR:
93282
93436
  return GetMapType<HistogramStringFunctor, string, IS_ORDERED>(type);
93283
93437
  case LogicalType::TIMESTAMP:
93284
- return GetMapType<HistogramFunctor, int64_t, IS_ORDERED>(type);
93438
+ return GetMapType<HistogramFunctor, timestamp_t, IS_ORDERED>(type);
93285
93439
  case LogicalType::TIMESTAMP_TZ:
93286
- return GetMapType<HistogramFunctor, int64_t, IS_ORDERED>(type);
93440
+ return GetMapType<HistogramFunctor, timestamp_tz_t, IS_ORDERED>(type);
93287
93441
  case LogicalType::TIMESTAMP_S:
93288
- return GetMapType<HistogramFunctor, int64_t, IS_ORDERED>(type);
93442
+ return GetMapType<HistogramFunctor, timestamp_sec_t, IS_ORDERED>(type);
93289
93443
  case LogicalType::TIMESTAMP_MS:
93290
- return GetMapType<HistogramFunctor, int64_t, IS_ORDERED>(type);
93444
+ return GetMapType<HistogramFunctor, timestamp_ms_t, IS_ORDERED>(type);
93291
93445
  case LogicalType::TIMESTAMP_NS:
93292
- return GetMapType<HistogramFunctor, int64_t, IS_ORDERED>(type);
93446
+ return GetMapType<HistogramFunctor, timestamp_ns_t, IS_ORDERED>(type);
93293
93447
  case LogicalType::TIME:
93294
- return GetMapType<HistogramFunctor, int64_t, IS_ORDERED>(type);
93448
+ return GetMapType<HistogramFunctor, dtime_t, IS_ORDERED>(type);
93295
93449
  case LogicalType::TIME_TZ:
93296
- return GetMapType<HistogramFunctor, int64_t, IS_ORDERED>(type);
93450
+ return GetMapType<HistogramFunctor, dtime_tz_t, IS_ORDERED>(type);
93297
93451
  case LogicalType::DATE:
93298
- return GetMapType<HistogramFunctor, int32_t, IS_ORDERED>(type);
93452
+ return GetMapType<HistogramFunctor, date_t, IS_ORDERED>(type);
93299
93453
  default:
93300
93454
  throw InternalException("Unimplemented histogram aggregate");
93301
93455
  }
@@ -96859,7 +97013,8 @@ struct DateDiff {
96859
97013
  struct WeekOperator {
96860
97014
  template <class TA, class TB, class TR>
96861
97015
  static inline TR Operation(TA startdate, TB enddate) {
96862
- return Date::Epoch(enddate) / Interval::SECS_PER_WEEK - Date::Epoch(startdate) / Interval::SECS_PER_WEEK;
97016
+ return Date::Epoch(Date::GetMondayOfCurrentWeek(enddate)) / Interval::SECS_PER_WEEK -
97017
+ Date::Epoch(Date::GetMondayOfCurrentWeek(startdate)) / Interval::SECS_PER_WEEK;
96863
97018
  }
96864
97019
  };
96865
97020
 
@@ -103243,12 +103398,49 @@ static void ListAggregatesFunction(DataChunk &args, ExpressionState &state, Vect
103243
103398
  result, state_vector.state_vector, count);
103244
103399
  break;
103245
103400
  case PhysicalType::INT32:
103246
- FUNCTION_FUNCTOR::template ListExecuteFunction<FinalizeValueFunctor, int32_t>(
103247
- result, state_vector.state_vector, count);
103401
+ if (key_type.id() == LogicalTypeId::DATE) {
103402
+ FUNCTION_FUNCTOR::template ListExecuteFunction<FinalizeValueFunctor, date_t>(
103403
+ result, state_vector.state_vector, count);
103404
+ } else {
103405
+ FUNCTION_FUNCTOR::template ListExecuteFunction<FinalizeValueFunctor, int32_t>(
103406
+ result, state_vector.state_vector, count);
103407
+ }
103248
103408
  break;
103249
103409
  case PhysicalType::INT64:
103250
- FUNCTION_FUNCTOR::template ListExecuteFunction<FinalizeValueFunctor, int64_t>(
103251
- result, state_vector.state_vector, count);
103410
+ switch (key_type.id()) {
103411
+ case LogicalTypeId::TIME:
103412
+ FUNCTION_FUNCTOR::template ListExecuteFunction<FinalizeValueFunctor, dtime_t>(
103413
+ result, state_vector.state_vector, count);
103414
+ break;
103415
+ case LogicalTypeId::TIME_TZ:
103416
+ FUNCTION_FUNCTOR::template ListExecuteFunction<FinalizeValueFunctor, dtime_tz_t>(
103417
+ result, state_vector.state_vector, count);
103418
+ break;
103419
+ case LogicalTypeId::TIMESTAMP:
103420
+ FUNCTION_FUNCTOR::template ListExecuteFunction<FinalizeValueFunctor, timestamp_t>(
103421
+ result, state_vector.state_vector, count);
103422
+ break;
103423
+ case LogicalTypeId::TIMESTAMP_MS:
103424
+ FUNCTION_FUNCTOR::template ListExecuteFunction<FinalizeValueFunctor, timestamp_ms_t>(
103425
+ result, state_vector.state_vector, count);
103426
+ break;
103427
+ case LogicalTypeId::TIMESTAMP_NS:
103428
+ FUNCTION_FUNCTOR::template ListExecuteFunction<FinalizeValueFunctor, timestamp_ns_t>(
103429
+ result, state_vector.state_vector, count);
103430
+ break;
103431
+ case LogicalTypeId::TIMESTAMP_SEC:
103432
+ FUNCTION_FUNCTOR::template ListExecuteFunction<FinalizeValueFunctor, timestamp_sec_t>(
103433
+ result, state_vector.state_vector, count);
103434
+ break;
103435
+ case LogicalTypeId::TIMESTAMP_TZ:
103436
+ FUNCTION_FUNCTOR::template ListExecuteFunction<FinalizeValueFunctor, timestamp_tz_t>(
103437
+ result, state_vector.state_vector, count);
103438
+ break;
103439
+ default:
103440
+ FUNCTION_FUNCTOR::template ListExecuteFunction<FinalizeValueFunctor, int64_t>(
103441
+ result, state_vector.state_vector, count);
103442
+ break;
103443
+ }
103252
103444
  break;
103253
103445
  case PhysicalType::FLOAT:
103254
103446
  FUNCTION_FUNCTOR::template ListExecuteFunction<FinalizeValueFunctor, float>(
@@ -104318,18 +104510,12 @@ void SinkDataChunk(Vector *child_vector, SelectionVector &sel, idx_t offset_list
104318
104510
  static void ListSortFunction(DataChunk &args, ExpressionState &state, Vector &result) {
104319
104511
  D_ASSERT(args.ColumnCount() >= 1 && args.ColumnCount() <= 3);
104320
104512
  auto count = args.size();
104321
- Vector &lists = args.data[0];
104513
+ Vector &input_lists = args.data[0];
104322
104514
 
104323
104515
  result.SetVectorType(VectorType::FLAT_VECTOR);
104324
104516
  auto &result_validity = FlatVector::Validity(result);
104325
104517
 
104326
- for (auto &v : args.data) {
104327
- if (v.GetVectorType() != VectorType::FLAT_VECTOR && v.GetVectorType() != VectorType::CONSTANT_VECTOR) {
104328
- v.Flatten(count);
104329
- }
104330
- }
104331
-
104332
- if (lists.GetType().id() == LogicalTypeId::SQLNULL) {
104518
+ if (input_lists.GetType().id() == LogicalTypeId::SQLNULL) {
104333
104519
  result_validity.SetInvalid(0);
104334
104520
  return;
104335
104521
  }
@@ -104344,15 +104530,18 @@ static void ListSortFunction(DataChunk &args, ExpressionState &state, Vector &re
104344
104530
  LocalSortState local_sort_state;
104345
104531
  local_sort_state.Initialize(global_sort_state, buffer_manager);
104346
104532
 
104533
+ // this ensures that we do not change the order of the entries in the input chunk
104534
+ VectorOperations::Copy(input_lists, result, count, 0, 0);
104535
+
104347
104536
  // get the child vector
104348
- auto lists_size = ListVector::GetListSize(lists);
104349
- auto &child_vector = ListVector::GetEntry(lists);
104537
+ auto lists_size = ListVector::GetListSize(result);
104538
+ auto &child_vector = ListVector::GetEntry(result);
104350
104539
  UnifiedVectorFormat child_data;
104351
104540
  child_vector.ToUnifiedFormat(lists_size, child_data);
104352
104541
 
104353
104542
  // get the lists data
104354
104543
  UnifiedVectorFormat lists_data;
104355
- lists.ToUnifiedFormat(count, lists_data);
104544
+ result.ToUnifiedFormat(count, lists_data);
104356
104545
  auto list_entries = (list_entry_t *)lists_data.data;
104357
104546
 
104358
104547
  // create the lists_indices vector, this contains an element for each list's entry,
@@ -104449,8 +104638,6 @@ static void ListSortFunction(DataChunk &args, ExpressionState &state, Vector &re
104449
104638
  child_vector.Flatten(sel_sorted_idx);
104450
104639
  }
104451
104640
 
104452
- result.Reference(lists);
104453
-
104454
104641
  if (args.AllConstant()) {
104455
104642
  result.SetVectorType(VectorType::CONSTANT_VECTOR);
104456
104643
  }
@@ -117625,6 +117812,7 @@ static void ReadCSVAddNamedParameters(TableFunction &table_function) {
117625
117812
  table_function.named_parameters["skip"] = LogicalType::BIGINT;
117626
117813
  table_function.named_parameters["max_line_size"] = LogicalType::VARCHAR;
117627
117814
  table_function.named_parameters["maximum_line_size"] = LogicalType::VARCHAR;
117815
+ table_function.named_parameters["ignore_errors"] = LogicalType::BOOLEAN;
117628
117816
  }
117629
117817
 
117630
117818
  double CSVReaderProgress(ClientContext &context, const FunctionData *bind_data_p,
@@ -123028,7 +123216,7 @@ bool duckdb_validity_row_is_valid(uint64_t *validity, idx_t row) {
123028
123216
  }
123029
123217
  idx_t entry_idx = row / 64;
123030
123218
  idx_t idx_in_entry = row % 64;
123031
- return validity[entry_idx] & (1 << idx_in_entry);
123219
+ return validity[entry_idx] & ((idx_t)1 << idx_in_entry);
123032
123220
  }
123033
123221
 
123034
123222
  void duckdb_validity_set_row_validity(uint64_t *validity, idx_t row, bool valid) {
@@ -123045,7 +123233,7 @@ void duckdb_validity_set_row_invalid(uint64_t *validity, idx_t row) {
123045
123233
  }
123046
123234
  idx_t entry_idx = row / 64;
123047
123235
  idx_t idx_in_entry = row % 64;
123048
- validity[entry_idx] &= ~(1 << idx_in_entry);
123236
+ validity[entry_idx] &= ~((uint64_t)1 << idx_in_entry);
123049
123237
  }
123050
123238
 
123051
123239
  void duckdb_validity_set_row_valid(uint64_t *validity, idx_t row) {
@@ -123054,7 +123242,7 @@ void duckdb_validity_set_row_valid(uint64_t *validity, idx_t row) {
123054
123242
  }
123055
123243
  idx_t entry_idx = row / 64;
123056
123244
  idx_t idx_in_entry = row % 64;
123057
- validity[entry_idx] |= 1 << idx_in_entry;
123245
+ validity[entry_idx] |= (uint64_t)1 << idx_in_entry;
123058
123246
  }
123059
123247
 
123060
123248
 
@@ -141402,7 +141590,7 @@ Value ForceCompressionSetting::GetSetting(ClientContext &context) {
141402
141590
  //===--------------------------------------------------------------------===//
141403
141591
  void HomeDirectorySetting::SetLocal(ClientContext &context, const Value &input) {
141404
141592
  auto &config = ClientConfig::GetConfig(context);
141405
- config.home_directory = input.IsNull() ? input.ToString() : string();
141593
+ config.home_directory = input.IsNull() ? string() : input.ToString();
141406
141594
  }
141407
141595
 
141408
141596
  Value HomeDirectorySetting::GetSetting(ClientContext &context) {
@@ -151925,6 +152113,7 @@ unique_ptr<NodeStatistics> StatisticsPropagator::PropagateStatistics(LogicalGet
151925
152113
 
151926
152114
 
151927
152115
 
152116
+
151928
152117
  namespace duckdb {
151929
152118
 
151930
152119
  void StatisticsPropagator::PropagateStatistics(LogicalComparisonJoin &join, unique_ptr<LogicalOperator> *node_ptr) {
@@ -151954,10 +152143,15 @@ void StatisticsPropagator::PropagateStatistics(LogicalComparisonJoin &join, uniq
151954
152143
  // semi or inner join on false; entire node can be pruned
151955
152144
  ReplaceWithEmptyResult(*node_ptr);
151956
152145
  return;
151957
- case JoinType::ANTI:
151958
- // anti join: replace entire join with LHS
151959
- *node_ptr = move(join.children[0]);
152146
+ case JoinType::ANTI: {
152147
+ // when the right child has data, return the left child
152148
+ // when the right child has no data, return an empty set
152149
+ auto limit = make_unique<LogicalLimit>(1, 0, nullptr, nullptr);
152150
+ limit->AddChild(move(join.children[1]));
152151
+ auto cross_product = LogicalCrossProduct::Create(move(join.children[0]), move(limit));
152152
+ *node_ptr = move(cross_product);
151960
152153
  return;
152154
+ }
151961
152155
  case JoinType::LEFT:
151962
152156
  // anti/left outer join: replace right side with empty node
151963
152157
  ReplaceWithEmptyResult(join.children[1]);
@@ -151985,10 +152179,15 @@ void StatisticsPropagator::PropagateStatistics(LogicalComparisonJoin &join, uniq
151985
152179
  } else {
151986
152180
  // this is the only condition and it is always true: all conditions are true
151987
152181
  switch (join.join_type) {
151988
- case JoinType::SEMI:
151989
- // semi join on true: replace entire join with LHS
151990
- *node_ptr = move(join.children[0]);
152182
+ case JoinType::SEMI: {
152183
+ // when the right child has data, return the left child
152184
+ // when the right child has no data, return an empty set
152185
+ auto limit = make_unique<LogicalLimit>(1, 0, nullptr, nullptr);
152186
+ limit->AddChild(move(join.children[1]));
152187
+ auto cross_product = LogicalCrossProduct::Create(move(join.children[0]), move(limit));
152188
+ *node_ptr = move(cross_product);
151991
152189
  return;
152190
+ }
151992
152191
  case JoinType::INNER:
151993
152192
  case JoinType::LEFT:
151994
152193
  case JoinType::RIGHT:
@@ -152105,6 +152304,7 @@ unique_ptr<NodeStatistics> StatisticsPropagator::PropagateStatistics(LogicalJoin
152105
152304
  // then propagate into the join conditions
152106
152305
  switch (join.type) {
152107
152306
  case LogicalOperatorType::LOGICAL_COMPARISON_JOIN:
152307
+ case LogicalOperatorType::LOGICAL_DELIM_JOIN:
152108
152308
  PropagateStatistics((LogicalComparisonJoin &)join, node_ptr);
152109
152309
  break;
152110
152310
  case LogicalOperatorType::LOGICAL_ANY_JOIN:
@@ -171348,7 +171548,7 @@ void Transformer::TransformCTE(duckdb_libpgquery::PGWithClause *de_with_clause,
171348
171548
  }
171349
171549
  // we need a query
171350
171550
  if (!cte->ctequery || cte->ctequery->type != duckdb_libpgquery::T_PGSelectStmt) {
171351
- throw InternalException("A CTE needs a SELECT");
171551
+ throw NotImplementedException("A CTE needs a SELECT");
171352
171552
  }
171353
171553
 
171354
171554
  // CTE transformation can either result in inlining for non recursive CTEs, or in recursive CTE bindings
@@ -171765,7 +171965,7 @@ LogicalType Transformer::TransformTypeName(duckdb_libpgquery::PGTypeName *type_n
171765
171965
 
171766
171966
  result_type = LogicalType::MAP(move(children));
171767
171967
  } else {
171768
- int8_t width, scale;
171968
+ int64_t width, scale;
171769
171969
  if (base_type == LogicalTypeId::DECIMAL) {
171770
171970
  // default decimal width/scale
171771
171971
  width = 18;
@@ -179786,11 +179986,13 @@ unique_ptr<BoundCreateTableInfo> Binder::BindCreateTableInfo(unique_ptr<CreateIn
179786
179986
  BindDefaultValues(base.columns, result->bound_defaults);
179787
179987
  }
179788
179988
 
179989
+ idx_t regular_column_count = 0;
179789
179990
  // bind collations to detect any unsupported collation errors
179790
179991
  for (auto &column : base.columns) {
179791
179992
  if (column.Generated()) {
179792
179993
  continue;
179793
179994
  }
179995
+ regular_column_count++;
179794
179996
  if (column.Type().id() == LogicalTypeId::VARCHAR) {
179795
179997
  ExpressionBinder::TestCollation(context, StringType::GetCollation(column.Type()));
179796
179998
  }
@@ -179802,6 +180004,9 @@ unique_ptr<BoundCreateTableInfo> Binder::BindCreateTableInfo(unique_ptr<CreateIn
179802
180004
  result->dependencies.insert(type_dependency);
179803
180005
  }
179804
180006
  }
180007
+ if (regular_column_count == 0) {
180008
+ throw BinderException("Creating a table without physical (non-generated) columns is not supported");
180009
+ }
179805
180010
  properties.allow_stream_result = false;
179806
180011
  return result;
179807
180012
  }
@@ -181189,7 +181394,20 @@ BoundStatement Binder::Bind(VacuumStatement &stmt) {
181189
181394
  auto &get = (LogicalGet &)*ref->get;
181190
181395
  columns.insert(columns.end(), get.names.begin(), get.names.end());
181191
181396
  }
181397
+
181398
+ case_insensitive_set_t column_name_set;
181399
+ vector<string> non_generated_column_names;
181192
181400
  for (auto &col_name : columns) {
181401
+ if (column_name_set.count(col_name) > 0) {
181402
+ throw BinderException("Vacuum the same column twice(same name in column name list)");
181403
+ }
181404
+ column_name_set.insert(col_name);
181405
+ auto &col = ref->table->GetColumn(col_name);
181406
+ // ignore generated column
181407
+ if (col.Generated()) {
181408
+ continue;
181409
+ }
181410
+ non_generated_column_names.push_back(col_name);
181193
181411
  ColumnRefExpression colref(col_name, ref->table->name);
181194
181412
  auto result = bind_context.BindColumn(colref, 0);
181195
181413
  if (result.HasError()) {
@@ -181197,17 +181415,29 @@ BoundStatement Binder::Bind(VacuumStatement &stmt) {
181197
181415
  }
181198
181416
  select_list.push_back(move(result.expression));
181199
181417
  }
181200
- auto table_scan = CreatePlan(*ref);
181201
- D_ASSERT(table_scan->type == LogicalOperatorType::LOGICAL_GET);
181202
- auto &get = (LogicalGet &)*table_scan;
181203
- for (idx_t i = 0; i < get.column_ids.size(); i++) {
181204
- stmt.info->column_id_map[i] = get.column_ids[i];
181205
- }
181418
+ stmt.info->columns = move(non_generated_column_names);
181419
+ if (!select_list.empty()) {
181420
+ auto table_scan = CreatePlan(*ref);
181421
+ D_ASSERT(table_scan->type == LogicalOperatorType::LOGICAL_GET);
181206
181422
 
181207
- auto projection = make_unique<LogicalProjection>(GenerateTableIndex(), move(select_list));
181208
- projection->children.push_back(move(table_scan));
181423
+ auto &get = (LogicalGet &)*table_scan;
181424
+
181425
+ D_ASSERT(select_list.size() == get.column_ids.size());
181426
+ D_ASSERT(stmt.info->columns.size() == get.column_ids.size());
181427
+ for (idx_t i = 0; i < get.column_ids.size(); i++) {
181428
+ stmt.info->column_id_map[i] = ref->table->columns[get.column_ids[i]].StorageOid();
181429
+ }
181430
+
181431
+ auto projection = make_unique<LogicalProjection>(GenerateTableIndex(), move(select_list));
181432
+ projection->children.push_back(move(table_scan));
181209
181433
 
181210
- root = move(projection);
181434
+ root = move(projection);
181435
+ } else {
181436
+ // eg. CREATE TABLE test (x AS (1));
181437
+ // ANALYZE test;
181438
+ // Make it not a SINK so it doesn't have to do anything
181439
+ stmt.info->has_table = false;
181440
+ }
181211
181441
  }
181212
181442
  auto vacuum = make_unique<LogicalSimple>(LogicalOperatorType::LOGICAL_VACUUM, move(stmt.info));
181213
181443
  if (root) {
@@ -322193,6 +322423,8 @@ exit:
322193
322423
  // See the end of this file for a list
322194
322424
 
322195
322425
 
322426
+ // otherwise we have different definitions for mbedtls_pk_context / mbedtls_sha256_context
322427
+ #define MBEDTLS_ALLOW_PRIVATE_ACCESS
322196
322428
 
322197
322429
 
322198
322430