duckdb 0.7.2-dev1034.0 → 0.7.2-dev1146.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.
Files changed (96) hide show
  1. package/package.json +1 -1
  2. package/src/duckdb/extension/icu/third_party/icu/stubdata/stubdata.cpp +1 -1
  3. package/src/duckdb/extension/parquet/parquet-extension.cpp +2 -1
  4. package/src/duckdb/src/common/hive_partitioning.cpp +3 -1
  5. package/src/duckdb/src/common/progress_bar/progress_bar.cpp +7 -0
  6. package/src/duckdb/src/common/serializer/enum_serializer.cpp +6 -6
  7. package/src/duckdb/src/common/sort/comparators.cpp +14 -5
  8. package/src/duckdb/src/common/types/column_data_collection_segment.cpp +1 -4
  9. package/src/duckdb/src/common/types/interval.cpp +0 -41
  10. package/src/duckdb/src/common/types/list_segment.cpp +658 -0
  11. package/src/duckdb/src/common/types/string_heap.cpp +1 -1
  12. package/src/duckdb/src/common/types/string_type.cpp +1 -1
  13. package/src/duckdb/src/common/types/validity_mask.cpp +24 -7
  14. package/src/duckdb/src/common/types/vector.cpp +3 -7
  15. package/src/duckdb/src/common/value_operations/comparison_operations.cpp +14 -22
  16. package/src/duckdb/src/common/vector_operations/comparison_operators.cpp +10 -10
  17. package/src/duckdb/src/common/vector_operations/is_distinct_from.cpp +11 -10
  18. package/src/duckdb/src/execution/expression_executor/execute_comparison.cpp +2 -2
  19. package/src/duckdb/src/execution/index/art/art.cpp +13 -0
  20. package/src/duckdb/src/execution/operator/aggregate/physical_hash_aggregate.cpp +1 -1
  21. package/src/duckdb/src/execution/operator/join/physical_hash_join.cpp +2 -0
  22. package/src/duckdb/src/execution/operator/join/physical_index_join.cpp +1 -0
  23. package/src/duckdb/src/execution/operator/join/physical_join.cpp +0 -3
  24. package/src/duckdb/src/execution/operator/persistent/base_csv_reader.cpp +5 -1
  25. package/src/duckdb/src/execution/operator/persistent/buffered_csv_reader.cpp +18 -5
  26. package/src/duckdb/src/execution/operator/persistent/csv_reader_options.cpp +3 -0
  27. package/src/duckdb/src/execution/operator/persistent/physical_batch_insert.cpp +2 -1
  28. package/src/duckdb/src/execution/operator/persistent/physical_delete.cpp +1 -3
  29. package/src/duckdb/src/execution/operator/persistent/physical_insert.cpp +1 -0
  30. package/src/duckdb/src/execution/operator/set/physical_recursive_cte.cpp +0 -4
  31. package/src/duckdb/src/execution/physical_plan/plan_aggregate.cpp +1 -0
  32. package/src/duckdb/src/execution/physical_plan/plan_comparison_join.cpp +1 -1
  33. package/src/duckdb/src/execution/physical_plan/plan_create_index.cpp +2 -1
  34. package/src/duckdb/src/execution/radix_partitioned_hashtable.cpp +18 -10
  35. package/src/duckdb/src/function/aggregate/nested/list.cpp +6 -712
  36. package/src/duckdb/src/function/cast_rules.cpp +9 -4
  37. package/src/duckdb/src/function/scalar/list/list_sort.cpp +25 -18
  38. package/src/duckdb/src/function/table/read_csv.cpp +5 -0
  39. package/src/duckdb/src/function/table/table_scan.cpp +8 -11
  40. package/src/duckdb/src/function/table/version/pragma_version.cpp +2 -2
  41. package/src/duckdb/src/include/duckdb/common/helper.hpp +1 -1
  42. package/src/duckdb/src/include/duckdb/common/operator/comparison_operators.hpp +45 -149
  43. package/src/duckdb/src/include/duckdb/common/progress_bar/progress_bar.hpp +2 -0
  44. package/src/duckdb/src/include/duckdb/common/types/interval.hpp +39 -3
  45. package/src/duckdb/src/include/duckdb/common/types/list_segment.hpp +70 -0
  46. package/src/duckdb/src/include/duckdb/common/types/string_type.hpp +73 -3
  47. package/src/duckdb/src/include/duckdb/common/types/validity_mask.hpp +4 -1
  48. package/src/duckdb/src/include/duckdb/execution/index/art/art.hpp +1 -12
  49. package/src/duckdb/src/include/duckdb/execution/operator/persistent/csv_reader_options.hpp +4 -0
  50. package/src/duckdb/src/include/duckdb/main/client_config.hpp +2 -0
  51. package/src/duckdb/src/include/duckdb/storage/compression/chimp/chimp_scan.hpp +1 -0
  52. package/src/duckdb/src/include/duckdb/storage/compression/patas/patas_scan.hpp +1 -0
  53. package/src/duckdb/src/include/duckdb/storage/data_pointer.hpp +0 -2
  54. package/src/duckdb/src/include/duckdb/storage/data_table.hpp +1 -0
  55. package/src/duckdb/src/include/duckdb/storage/index.hpp +1 -1
  56. package/src/duckdb/src/include/duckdb/storage/string_uncompressed.hpp +1 -1
  57. package/src/duckdb/src/include/duckdb/storage/table/column_data.hpp +18 -7
  58. package/src/duckdb/src/include/duckdb/storage/table/column_segment.hpp +0 -3
  59. package/src/duckdb/src/include/duckdb/storage/table/column_segment_tree.hpp +18 -0
  60. package/src/duckdb/src/include/duckdb/storage/table/persistent_table_data.hpp +0 -1
  61. package/src/duckdb/src/include/duckdb/storage/table/row_group.hpp +35 -43
  62. package/src/duckdb/src/include/duckdb/storage/table/row_group_collection.hpp +18 -5
  63. package/src/duckdb/src/include/duckdb/storage/table/row_group_segment_tree.hpp +2 -4
  64. package/src/duckdb/src/include/duckdb/storage/table/scan_state.hpp +12 -29
  65. package/src/duckdb/src/include/duckdb/storage/table/segment_base.hpp +2 -3
  66. package/src/duckdb/src/include/duckdb/storage/table/segment_tree.hpp +11 -1
  67. package/src/duckdb/src/include/duckdb/storage/table/standard_column_data.hpp +0 -4
  68. package/src/duckdb/src/include/duckdb/transaction/local_storage.hpp +4 -1
  69. package/src/duckdb/src/include/duckdb.h +21 -0
  70. package/src/duckdb/src/main/capi/table_function-c.cpp +23 -0
  71. package/src/duckdb/src/main/settings/settings.cpp +20 -8
  72. package/src/duckdb/src/optimizer/filter_combiner.cpp +2 -5
  73. package/src/duckdb/src/optimizer/join_order/cardinality_estimator.cpp +2 -0
  74. package/src/duckdb/src/optimizer/join_order/join_order_optimizer.cpp +1 -0
  75. package/src/duckdb/src/parallel/meta_pipeline.cpp +0 -3
  76. package/src/duckdb/src/parser/transform/expression/transform_function.cpp +22 -0
  77. package/src/duckdb/src/planner/binder/statement/bind_create_table.cpp +1 -0
  78. package/src/duckdb/src/storage/compression/bitpacking.cpp +1 -1
  79. package/src/duckdb/src/storage/compression/fixed_size_uncompressed.cpp +2 -1
  80. package/src/duckdb/src/storage/compression/numeric_constant.cpp +1 -1
  81. package/src/duckdb/src/storage/compression/rle.cpp +1 -0
  82. package/src/duckdb/src/storage/compression/validity_uncompressed.cpp +1 -1
  83. package/src/duckdb/src/storage/data_table.cpp +3 -3
  84. package/src/duckdb/src/storage/local_storage.cpp +7 -0
  85. package/src/duckdb/src/storage/storage_info.cpp +1 -1
  86. package/src/duckdb/src/storage/table/column_data.cpp +75 -18
  87. package/src/duckdb/src/storage/table/column_data_checkpointer.cpp +3 -1
  88. package/src/duckdb/src/storage/table/column_segment.cpp +17 -31
  89. package/src/duckdb/src/storage/table/list_column_data.cpp +9 -12
  90. package/src/duckdb/src/storage/table/row_group.cpp +200 -136
  91. package/src/duckdb/src/storage/table/row_group_collection.cpp +75 -45
  92. package/src/duckdb/src/storage/table/scan_state.cpp +31 -38
  93. package/src/duckdb/src/storage/table/standard_column_data.cpp +4 -6
  94. package/src/duckdb/src/storage/table/struct_column_data.cpp +11 -18
  95. package/src/duckdb/src/storage/table/update_segment.cpp +3 -0
  96. package/src/duckdb/ub_src_common_types.cpp +2 -0
@@ -207,6 +207,15 @@ int64_t CastRules::ImplicitCast(const LogicalType &from, const LogicalType &to)
207
207
  // if aliases are different, an implicit cast is not possible
208
208
  return -1;
209
209
  }
210
+ if (from.id() == LogicalTypeId::LIST && to.id() == LogicalTypeId::LIST) {
211
+ // Lists can be cast if their child types can be cast
212
+ auto child_cost = ImplicitCast(ListType::GetChildType(from), ListType::GetChildType(to));
213
+ if (child_cost >= 100) {
214
+ // subtract one from the cost because we prefer LIST[X] -> LIST[VARCHAR] over LIST[X] -> VARCHAR
215
+ child_cost--;
216
+ }
217
+ return child_cost;
218
+ }
210
219
  if (from.id() == to.id()) {
211
220
  // arguments match: do nothing
212
221
  return 0;
@@ -219,10 +228,6 @@ int64_t CastRules::ImplicitCast(const LogicalType &from, const LogicalType &to)
219
228
  // everything can be cast to VARCHAR, but this cast has a high cost
220
229
  return TargetTypeCost(to);
221
230
  }
222
- if (from.id() == LogicalTypeId::LIST && to.id() == LogicalTypeId::LIST) {
223
- // Lists can be cast if their child types can be cast
224
- return ImplicitCast(ListType::GetChildType(from), ListType::GetChildType(to));
225
- }
226
231
 
227
232
  if (from.id() == LogicalTypeId::UNION && to.id() == LogicalTypeId::UNION) {
228
233
  // Unions can be cast if the source tags are a subset of the target tags
@@ -1,4 +1,5 @@
1
1
  #include "duckdb/function/scalar/nested_functions.hpp"
2
+ #include "duckdb/common/serializer/enum_serializer.hpp"
2
3
  #include "duckdb/common/types/chunk_collection.hpp"
3
4
  #include "duckdb/planner/expression/bound_function_expression.hpp"
4
5
  #include "duckdb/execution/expression_executor.hpp"
@@ -243,28 +244,30 @@ static unique_ptr<FunctionData> ListSortBind(ClientContext &context, ScalarFunct
243
244
  return make_unique<ListSortBindData>(order, null_order, bound_function.return_type, child_type, context);
244
245
  }
245
246
 
246
- OrderByNullType GetNullOrder(ClientContext &context, vector<unique_ptr<Expression>> &arguments, idx_t idx) {
247
+ static OrderByNullType GetNullOrder(ClientContext &context, vector<unique_ptr<Expression>> &arguments, idx_t idx) {
247
248
 
248
249
  if (!arguments[idx]->IsFoldable()) {
249
250
  throw InvalidInputException("Null sorting order must be a constant");
250
251
  }
251
252
  Value null_order_value = ExpressionExecutor::EvaluateScalar(context, *arguments[idx]);
252
253
  auto null_order_name = StringUtil::Upper(null_order_value.ToString());
253
- if (null_order_name != "NULLS FIRST" && null_order_name != "NULLS LAST") {
254
- throw InvalidInputException("Null sorting order must be either NULLS FIRST or NULLS LAST");
254
+ const auto null_order_arg = EnumSerializer::StringToEnum<OrderByNullType>(null_order_name.c_str());
255
+ switch (null_order_arg) {
256
+ case OrderByNullType::NULLS_FIRST:
257
+ case OrderByNullType::NULLS_LAST:
258
+ return null_order_arg;
259
+ case OrderByNullType::ORDER_DEFAULT:
260
+ return DBConfig::GetConfig(context).options.default_null_order;
261
+ default:
262
+ throw InvalidInputException("Null sorting order must be either NULLS FIRST, NULLS LAST or DEFAULT");
255
263
  }
256
-
257
- if (null_order_name == "NULLS LAST") {
258
- return OrderByNullType::NULLS_LAST;
259
- }
260
- return OrderByNullType::NULLS_FIRST;
261
264
  }
262
265
 
263
266
  static unique_ptr<FunctionData> ListNormalSortBind(ClientContext &context, ScalarFunction &bound_function,
264
267
  vector<unique_ptr<Expression>> &arguments) {
265
268
 
266
- D_ASSERT(bound_function.arguments.size() >= 1 && bound_function.arguments.size() <= 3);
267
- D_ASSERT(arguments.size() >= 1 && arguments.size() <= 3);
269
+ D_ASSERT(!bound_function.arguments.empty() && bound_function.arguments.size() <= 3);
270
+ D_ASSERT(!arguments.empty() && arguments.size() <= 3);
268
271
 
269
272
  // set default values
270
273
  auto &config = DBConfig::GetConfig(context);
@@ -278,14 +281,18 @@ static unique_ptr<FunctionData> ListNormalSortBind(ClientContext &context, Scala
278
281
  throw InvalidInputException("Sorting order must be a constant");
279
282
  }
280
283
  Value order_value = ExpressionExecutor::EvaluateScalar(context, *arguments[1]);
281
- auto order_name = StringUtil::Upper(order_value.ToString());
282
- if (order_name != "DESC" && order_name != "ASC") {
283
- throw InvalidInputException("Sorting order must be either ASC or DESC");
284
- }
285
- if (order_name == "DESC") {
286
- order = OrderType::DESCENDING;
287
- } else {
288
- order = OrderType::ASCENDING;
284
+
285
+ const auto order_name = StringUtil::Upper(order_value.ToString());
286
+ const auto order_arg = EnumSerializer::StringToEnum<OrderType>(order_name.c_str());
287
+ switch (order_arg) {
288
+ case OrderType::ASCENDING:
289
+ case OrderType::DESCENDING:
290
+ order = order_arg;
291
+ break;
292
+ case OrderType::ORDER_DEFAULT:
293
+ break;
294
+ default:
295
+ throw InvalidInputException("Sorting order must be either ASC, DESC or DEFAULT");
289
296
  }
290
297
  }
291
298
 
@@ -861,6 +861,7 @@ static void ReadCSVAddNamedParameters(TableFunction &table_function) {
861
861
  table_function.named_parameters["buffer_size"] = LogicalType::UBIGINT;
862
862
  table_function.named_parameters["decimal_separator"] = LogicalType::VARCHAR;
863
863
  table_function.named_parameters["parallel"] = LogicalType::BOOLEAN;
864
+ table_function.named_parameters["null_padding"] = LogicalType::BOOLEAN;
864
865
  }
865
866
 
866
867
  double CSVReaderProgress(ClientContext &context, const FunctionData *bind_data_p,
@@ -928,6 +929,7 @@ void BufferedCSVReaderOptions::Serialize(FieldWriter &writer) const {
928
929
  // read options
929
930
  writer.WriteList<string>(names);
930
931
  writer.WriteField<idx_t>(skip_rows);
932
+ writer.WriteField<bool>(skip_rows_set);
931
933
  writer.WriteField<idx_t>(maximum_line_size);
932
934
  writer.WriteField<bool>(normalize_names);
933
935
  writer.WriteListNoReference<bool>(force_not_null);
@@ -939,6 +941,7 @@ void BufferedCSVReaderOptions::Serialize(FieldWriter &writer) const {
939
941
  writer.WriteField<bool>(include_file_name);
940
942
  writer.WriteField<bool>(include_parsed_hive_partitions);
941
943
  writer.WriteString(decimal_separator);
944
+ writer.WriteField<bool>(null_padding);
942
945
  // write options
943
946
  writer.WriteListNoReference<bool>(force_quote);
944
947
  }
@@ -961,6 +964,7 @@ void BufferedCSVReaderOptions::Deserialize(FieldReader &reader) {
961
964
  // read options
962
965
  names = reader.ReadRequiredList<string>();
963
966
  skip_rows = reader.ReadRequired<idx_t>();
967
+ skip_rows_set = reader.ReadRequired<bool>();
964
968
  maximum_line_size = reader.ReadRequired<idx_t>();
965
969
  normalize_names = reader.ReadRequired<bool>();
966
970
  force_not_null = reader.ReadRequiredList<bool>();
@@ -972,6 +976,7 @@ void BufferedCSVReaderOptions::Deserialize(FieldReader &reader) {
972
976
  include_file_name = reader.ReadRequired<bool>();
973
977
  include_parsed_hive_partitions = reader.ReadRequired<bool>();
974
978
  decimal_separator = reader.ReadRequired<string>();
979
+ null_padding = reader.ReadRequired<bool>();
975
980
  // write options
976
981
  force_quote = reader.ReadRequiredList<bool>();
977
982
  }
@@ -1,6 +1,5 @@
1
1
  #include "duckdb/function/table/table_scan.hpp"
2
2
 
3
- #include "duckdb/catalog/catalog_entry/schema_catalog_entry.hpp"
4
3
  #include "duckdb/catalog/catalog_entry/duck_table_entry.hpp"
5
4
  #include "duckdb/common/field_writer.hpp"
6
5
  #include "duckdb/common/mutex.hpp"
@@ -15,6 +14,7 @@
15
14
  #include "duckdb/main/attached_database.hpp"
16
15
  #include "duckdb/catalog/dependency_list.hpp"
17
16
  #include "duckdb/function/function_set.hpp"
17
+ #include "duckdb/storage/table/scan_state.hpp"
18
18
 
19
19
  namespace duckdb {
20
20
 
@@ -40,17 +40,14 @@ static storage_t GetStorageIndex(TableCatalogEntry &table, column_t column_id) {
40
40
  }
41
41
 
42
42
  struct TableScanGlobalState : public GlobalTableFunctionState {
43
- TableScanGlobalState(ClientContext &context, const FunctionData *bind_data_p) : row_count(0) {
43
+ TableScanGlobalState(ClientContext &context, const FunctionData *bind_data_p) {
44
44
  D_ASSERT(bind_data_p);
45
45
  auto &bind_data = (const TableScanBindData &)*bind_data_p;
46
46
  max_threads = bind_data.table->GetStorage().MaxThreads(context);
47
47
  }
48
48
 
49
49
  ParallelTableScanState state;
50
- mutex lock;
51
50
  idx_t max_threads;
52
- //! How many rows we already scanned
53
- atomic<idx_t> row_count;
54
51
 
55
52
  vector<idx_t> projection_ids;
56
53
  vector<LogicalType> scanned_types;
@@ -131,7 +128,6 @@ static void TableScanFunc(ClientContext &context, TableFunctionInput &data_p, Da
131
128
  storage.Scan(transaction, output, state.scan_state);
132
129
  }
133
130
  if (output.size() > 0) {
134
- gstate.row_count += output.size();
135
131
  return;
136
132
  }
137
133
  if (!TableScanParallelStateNext(context, data_p.bind_data, data_p.local_state, data_p.global_state)) {
@@ -147,7 +143,6 @@ bool TableScanParallelStateNext(ClientContext &context, const FunctionData *bind
147
143
  auto &state = (TableScanLocalState &)*local_state;
148
144
  auto &storage = bind_data.table->GetStorage();
149
145
 
150
- lock_guard<mutex> parallel_lock(parallel_state.lock);
151
146
  return storage.NextParallelScan(context, parallel_state.state, state.scan_state);
152
147
  }
153
148
 
@@ -161,7 +156,9 @@ double TableScanProgress(ClientContext &context, const FunctionData *bind_data_p
161
156
  //! Table is either empty or smaller than a vector size, so it is finished
162
157
  return 100;
163
158
  }
164
- auto percentage = 100 * (double(gstate.row_count) / total_rows);
159
+ idx_t scanned_rows = gstate.state.scan_state.processed_rows;
160
+ scanned_rows += gstate.state.local_state.processed_rows;
161
+ auto percentage = 100 * (double(scanned_rows) / total_rows);
165
162
  if (percentage > 100) {
166
163
  //! In case the last chunk has less elements than STANDARD_VECTOR_SIZE, if our percentage is over 100
167
164
  //! It means we finished this table.
@@ -171,12 +168,12 @@ double TableScanProgress(ClientContext &context, const FunctionData *bind_data_p
171
168
  }
172
169
 
173
170
  idx_t TableScanGetBatchIndex(ClientContext &context, const FunctionData *bind_data_p,
174
- LocalTableFunctionState *local_state, GlobalTableFunctionState *global_state) {
171
+ LocalTableFunctionState *local_state, GlobalTableFunctionState *gstate_p) {
175
172
  auto &state = (TableScanLocalState &)*local_state;
176
- if (state.scan_state.table_state.row_group_state.row_group) {
173
+ if (state.scan_state.table_state.row_group) {
177
174
  return state.scan_state.table_state.batch_index;
178
175
  }
179
- if (state.scan_state.local_state.row_group_state.row_group) {
176
+ if (state.scan_state.local_state.row_group) {
180
177
  return state.scan_state.table_state.batch_index + state.scan_state.local_state.batch_index;
181
178
  }
182
179
  return 0;
@@ -1,8 +1,8 @@
1
1
  #ifndef DUCKDB_VERSION
2
- #define DUCKDB_VERSION "0.7.2-dev1034"
2
+ #define DUCKDB_VERSION "0.7.2-dev1146"
3
3
  #endif
4
4
  #ifndef DUCKDB_SOURCE_ID
5
- #define DUCKDB_SOURCE_ID "18142dcc4b"
5
+ #define DUCKDB_SOURCE_ID "b8cf6a98e2"
6
6
  #endif
7
7
  #include "duckdb/function/table/system_functions.hpp"
8
8
  #include "duckdb/main/database.hpp"
@@ -114,7 +114,7 @@ const T Load(const_data_ptr_t ptr) {
114
114
  }
115
115
 
116
116
  template <typename T>
117
- void Store(const T val, data_ptr_t ptr) {
117
+ void Store(const T &val, data_ptr_t ptr) {
118
118
  memcpy(ptr, (void *)&val, sizeof(val));
119
119
  }
120
120
 
@@ -23,120 +23,122 @@ namespace duckdb {
23
23
  //===--------------------------------------------------------------------===//
24
24
  struct Equals {
25
25
  template <class T>
26
- DUCKDB_API static inline bool Operation(T left, T right) {
26
+ DUCKDB_API static inline bool Operation(const T &left, const T &right) {
27
27
  return left == right;
28
28
  }
29
29
  };
30
30
  struct NotEquals {
31
31
  template <class T>
32
- DUCKDB_API static inline bool Operation(T left, T right) {
32
+ DUCKDB_API static inline bool Operation(const T &left, const T &right) {
33
33
  return !Equals::Operation(left, right);
34
34
  }
35
35
  };
36
36
 
37
37
  struct GreaterThan {
38
38
  template <class T>
39
- DUCKDB_API static inline bool Operation(T left, T right) {
39
+ DUCKDB_API static inline bool Operation(const T &left, const T &right) {
40
40
  return left > right;
41
41
  }
42
42
  };
43
43
 
44
44
  struct GreaterThanEquals {
45
45
  template <class T>
46
- DUCKDB_API static inline bool Operation(T left, T right) {
47
- return left >= right;
46
+ DUCKDB_API static inline bool Operation(const T &left, const T &right) {
47
+ return !GreaterThan::Operation(right, left);
48
48
  }
49
49
  };
50
50
 
51
51
  struct LessThan {
52
52
  template <class T>
53
- DUCKDB_API static inline bool Operation(T left, T right) {
53
+ DUCKDB_API static inline bool Operation(const T &left, const T &right) {
54
54
  return GreaterThan::Operation(right, left);
55
55
  }
56
56
  };
57
57
 
58
58
  struct LessThanEquals {
59
59
  template <class T>
60
- DUCKDB_API static inline bool Operation(T left, T right) {
61
- return GreaterThanEquals::Operation(right, left);
60
+ DUCKDB_API static inline bool Operation(const T &left, const T &right) {
61
+ return !GreaterThan::Operation(left, right);
62
62
  }
63
63
  };
64
64
 
65
65
  template <>
66
- DUCKDB_API bool Equals::Operation(float left, float right);
66
+ DUCKDB_API bool Equals::Operation(const float &left, const float &right);
67
67
  template <>
68
- DUCKDB_API bool Equals::Operation(double left, double right);
68
+ DUCKDB_API bool Equals::Operation(const double &left, const double &right);
69
69
 
70
70
  template <>
71
- DUCKDB_API bool GreaterThan::Operation(float left, float right);
71
+ DUCKDB_API bool GreaterThan::Operation(const float &left, const float &right);
72
72
  template <>
73
- DUCKDB_API bool GreaterThan::Operation(double left, double right);
73
+ DUCKDB_API bool GreaterThan::Operation(const double &left, const double &right);
74
74
 
75
75
  template <>
76
- DUCKDB_API bool GreaterThanEquals::Operation(float left, float right);
76
+ DUCKDB_API bool GreaterThanEquals::Operation(const float &left, const float &right);
77
77
  template <>
78
- DUCKDB_API bool GreaterThanEquals::Operation(double left, double right);
78
+ DUCKDB_API bool GreaterThanEquals::Operation(const double &left, const double &right);
79
79
 
80
80
  // Distinct semantics are from Postgres record sorting. NULL = NULL and not-NULL < NULL
81
81
  // Deferring to the non-distinct operations removes the need for further specialisation.
82
82
  // TODO: To reverse the semantics, swap left_null and right_null for comparisons
83
83
  struct DistinctFrom {
84
84
  template <class T>
85
- static inline bool Operation(T left, T right, bool left_null, bool right_null) {
86
- return (left_null != right_null) || (!left_null && !right_null && NotEquals::Operation(left, right));
85
+ static inline bool Operation(const T &left, const T &right, bool left_null, bool right_null) {
86
+ if (left_null || right_null) {
87
+ return left_null != right_null;
88
+ }
89
+ return NotEquals::Operation(left, right);
87
90
  }
88
91
  };
89
92
 
90
93
  struct NotDistinctFrom {
91
94
  template <class T>
92
- static inline bool Operation(T left, T right, bool left_null, bool right_null) {
93
- return (left_null && right_null) || (!left_null && !right_null && Equals::Operation(left, right));
95
+ static inline bool Operation(const T &left, const T &right, bool left_null, bool right_null) {
96
+ return !DistinctFrom::Operation(left, right, left_null, right_null);
94
97
  }
95
98
  };
96
99
 
97
100
  struct DistinctGreaterThan {
98
101
  template <class T>
99
- static inline bool Operation(T left, T right, bool left_null, bool right_null) {
100
- return GreaterThan::Operation(left_null, right_null) ||
101
- (!left_null && !right_null && GreaterThan::Operation(left, right));
102
+ static inline bool Operation(const T &left, const T &right, bool left_null, bool right_null) {
103
+ if (left_null || right_null) {
104
+ return !right_null;
105
+ }
106
+ return GreaterThan::Operation(left, right);
102
107
  }
103
108
  };
104
109
 
105
110
  struct DistinctGreaterThanNullsFirst {
106
111
  template <class T>
107
- static inline bool Operation(T left, T right, bool left_null, bool right_null) {
108
- return GreaterThan::Operation(right_null, left_null) ||
109
- (!left_null && !right_null && GreaterThan::Operation(left, right));
112
+ static inline bool Operation(const T &left, const T &right, bool left_null, bool right_null) {
113
+ return DistinctGreaterThan::Operation(left, right, right_null, left_null);
110
114
  }
111
115
  };
112
116
 
113
117
  struct DistinctGreaterThanEquals {
114
118
  template <class T>
115
- static inline bool Operation(T left, T right, bool left_null, bool right_null) {
116
- return left_null || (!left_null && !right_null && GreaterThanEquals::Operation(left, right));
119
+ static inline bool Operation(const T &left, const T &right, bool left_null, bool right_null) {
120
+ return !DistinctGreaterThan::Operation(right, left, right_null, left_null);
117
121
  }
118
122
  };
119
123
 
120
124
  struct DistinctLessThan {
121
125
  template <class T>
122
- static inline bool Operation(T left, T right, bool left_null, bool right_null) {
123
- return LessThan::Operation(left_null, right_null) ||
124
- (!left_null && !right_null && LessThan::Operation(left, right));
126
+ static inline bool Operation(const T &left, const T &right, bool left_null, bool right_null) {
127
+ return DistinctGreaterThan::Operation(right, left, right_null, left_null);
125
128
  }
126
129
  };
127
130
 
128
131
  struct DistinctLessThanNullsFirst {
129
132
  template <class T>
130
- static inline bool Operation(T left, T right, bool left_null, bool right_null) {
131
- return LessThan::Operation(right_null, left_null) ||
132
- (!left_null && !right_null && LessThan::Operation(left, right));
133
+ static inline bool Operation(const T &left, const T &right, bool left_null, bool right_null) {
134
+ return DistinctGreaterThan::Operation(right, left, left_null, right_null);
133
135
  }
134
136
  };
135
137
 
136
138
  struct DistinctLessThanEquals {
137
139
  template <class T>
138
- static inline bool Operation(T left, T right, bool left_null, bool right_null) {
139
- return right_null || (!left_null && !right_null && LessThanEquals::Operation(left, right));
140
+ static inline bool Operation(const T &left, const T &right, bool left_null, bool right_null) {
141
+ return !DistinctGreaterThan::Operation(left, right, left_null, right_null);
140
142
  }
141
143
  };
142
144
 
@@ -144,124 +146,34 @@ struct DistinctLessThanEquals {
144
146
  // Specialized Boolean Comparison Operators
145
147
  //===--------------------------------------------------------------------===//
146
148
  template <>
147
- inline bool GreaterThan::Operation(bool left, bool right) {
149
+ inline bool GreaterThan::Operation(const bool &left, const bool &right) {
148
150
  return !right && left;
149
151
  }
150
- template <>
151
- inline bool LessThan::Operation(bool left, bool right) {
152
- return !left && right;
153
- }
154
152
  //===--------------------------------------------------------------------===//
155
153
  // Specialized String Comparison Operations
156
154
  //===--------------------------------------------------------------------===//
157
- struct StringComparisonOperators {
158
- template <bool INVERSE>
159
- static inline bool EqualsOrNot(const string_t a, const string_t b) {
160
- if (a.IsInlined()) {
161
- // small string: compare entire string
162
- if (memcmp(&a, &b, sizeof(string_t)) == 0) {
163
- // entire string is equal
164
- return INVERSE ? false : true;
165
- }
166
- } else {
167
- // large string: first check prefix and length
168
- if (memcmp(&a, &b, string_t::HEADER_SIZE) == 0) {
169
- // prefix and length are equal: check main string
170
- if (memcmp(a.value.pointer.ptr, b.value.pointer.ptr, a.GetSize()) == 0) {
171
- // entire string is equal
172
- return INVERSE ? false : true;
173
- }
174
- }
175
- }
176
- // not equal
177
- return INVERSE ? true : false;
178
- }
179
- };
180
-
181
- template <>
182
- inline bool Equals::Operation(string_t left, string_t right) {
183
- return StringComparisonOperators::EqualsOrNot<false>(left, right);
184
- }
185
- template <>
186
- inline bool NotEquals::Operation(string_t left, string_t right) {
187
- return StringComparisonOperators::EqualsOrNot<true>(left, right);
188
- }
189
-
190
- template <>
191
- inline bool NotDistinctFrom::Operation(string_t left, string_t right, bool left_null, bool right_null) {
192
- return (left_null && right_null) ||
193
- (!left_null && !right_null && StringComparisonOperators::EqualsOrNot<false>(left, right));
194
- }
195
- template <>
196
- inline bool DistinctFrom::Operation(string_t left, string_t right, bool left_null, bool right_null) {
197
- return (left_null != right_null) ||
198
- (!left_null && !right_null && StringComparisonOperators::EqualsOrNot<true>(left, right));
199
- }
200
-
201
- // compare up to shared length. if still the same, compare lengths
202
- template <class OP>
203
- static bool templated_string_compare_op(string_t left, string_t right) {
204
- auto memcmp_res =
205
- memcmp(left.GetDataUnsafe(), right.GetDataUnsafe(), MinValue<idx_t>(left.GetSize(), right.GetSize()));
206
- auto final_res = memcmp_res == 0 ? OP::Operation(left.GetSize(), right.GetSize()) : OP::Operation(memcmp_res, 0);
207
- return final_res;
208
- }
209
-
210
- template <>
211
- inline bool GreaterThan::Operation(string_t left, string_t right) {
212
- return templated_string_compare_op<GreaterThan>(left, right);
213
- }
214
-
215
155
  template <>
216
- inline bool GreaterThanEquals::Operation(string_t left, string_t right) {
217
- return templated_string_compare_op<GreaterThanEquals>(left, right);
156
+ inline bool Equals::Operation(const string_t &left, const string_t &right) {
157
+ return left == right;
218
158
  }
219
159
 
220
160
  template <>
221
- inline bool LessThan::Operation(string_t left, string_t right) {
222
- return templated_string_compare_op<LessThan>(left, right);
161
+ inline bool GreaterThan::Operation(const string_t &left, const string_t &right) {
162
+ return left > right;
223
163
  }
224
164
 
225
- template <>
226
- inline bool LessThanEquals::Operation(string_t left, string_t right) {
227
- return templated_string_compare_op<LessThanEquals>(left, right);
228
- }
229
165
  //===--------------------------------------------------------------------===//
230
166
  // Specialized Interval Comparison Operators
231
167
  //===--------------------------------------------------------------------===//
232
168
  template <>
233
- inline bool Equals::Operation(interval_t left, interval_t right) {
169
+ inline bool Equals::Operation(const interval_t &left, const interval_t &right) {
234
170
  return Interval::Equals(left, right);
235
171
  }
236
172
  template <>
237
- inline bool NotEquals::Operation(interval_t left, interval_t right) {
238
- return !Equals::Operation(left, right);
239
- }
240
- template <>
241
- inline bool GreaterThan::Operation(interval_t left, interval_t right) {
173
+ inline bool GreaterThan::Operation(const interval_t &left, const interval_t &right) {
242
174
  return Interval::GreaterThan(left, right);
243
175
  }
244
- template <>
245
- inline bool GreaterThanEquals::Operation(interval_t left, interval_t right) {
246
- return Interval::GreaterThanEquals(left, right);
247
- }
248
- template <>
249
- inline bool LessThan::Operation(interval_t left, interval_t right) {
250
- return GreaterThan::Operation(right, left);
251
- }
252
- template <>
253
- inline bool LessThanEquals::Operation(interval_t left, interval_t right) {
254
- return GreaterThanEquals::Operation(right, left);
255
- }
256
176
 
257
- template <>
258
- inline bool NotDistinctFrom::Operation(interval_t left, interval_t right, bool left_null, bool right_null) {
259
- return (left_null && right_null) || (!left_null && !right_null && Interval::Equals(left, right));
260
- }
261
- template <>
262
- inline bool DistinctFrom::Operation(interval_t left, interval_t right, bool left_null, bool right_null) {
263
- return (left_null != right_null) || (!left_null && !right_null && !Equals::Operation(left, right));
264
- }
265
177
  inline bool operator<(const interval_t &lhs, const interval_t &rhs) {
266
178
  return LessThan::Operation(lhs, rhs);
267
179
  }
@@ -270,27 +182,11 @@ inline bool operator<(const interval_t &lhs, const interval_t &rhs) {
270
182
  // Specialized Hugeint Comparison Operators
271
183
  //===--------------------------------------------------------------------===//
272
184
  template <>
273
- inline bool Equals::Operation(hugeint_t left, hugeint_t right) {
185
+ inline bool Equals::Operation(const hugeint_t &left, const hugeint_t &right) {
274
186
  return Hugeint::Equals(left, right);
275
187
  }
276
188
  template <>
277
- inline bool NotEquals::Operation(hugeint_t left, hugeint_t right) {
278
- return Hugeint::NotEquals(left, right);
279
- }
280
- template <>
281
- inline bool GreaterThan::Operation(hugeint_t left, hugeint_t right) {
189
+ inline bool GreaterThan::Operation(const hugeint_t &left, const hugeint_t &right) {
282
190
  return Hugeint::GreaterThan(left, right);
283
191
  }
284
- template <>
285
- inline bool GreaterThanEquals::Operation(hugeint_t left, hugeint_t right) {
286
- return Hugeint::GreaterThanEquals(left, right);
287
- }
288
- template <>
289
- inline bool LessThan::Operation(hugeint_t left, hugeint_t right) {
290
- return Hugeint::LessThan(left, right);
291
- }
292
- template <>
293
- inline bool LessThanEquals::Operation(hugeint_t left, hugeint_t right) {
294
- return Hugeint::LessThanEquals(left, right);
295
- }
296
192
  } // namespace duckdb
@@ -16,11 +16,13 @@
16
16
 
17
17
  namespace duckdb {
18
18
 
19
+ struct ClientConfig;
19
20
  typedef unique_ptr<ProgressBarDisplay> (*progress_bar_display_create_func_t)();
20
21
 
21
22
  class ProgressBar {
22
23
  public:
23
24
  static unique_ptr<ProgressBarDisplay> DefaultProgressBarDisplay();
25
+ static void SystemOverrideCheck(ClientConfig &config);
24
26
 
25
27
  explicit ProgressBar(
26
28
  Executor &executor, idx_t show_progress_after,
@@ -101,8 +101,44 @@ public:
101
101
  static dtime_t Add(dtime_t left, interval_t right, date_t &date);
102
102
 
103
103
  //! Comparison operators
104
- static bool Equals(interval_t left, interval_t right);
105
- static bool GreaterThan(interval_t left, interval_t right);
106
- static bool GreaterThanEquals(interval_t left, interval_t right);
104
+ inline static bool Equals(const interval_t &left, const interval_t &right);
105
+ inline static bool GreaterThan(const interval_t &left, const interval_t &right);
107
106
  };
107
+ static void NormalizeIntervalEntries(interval_t input, int64_t &months, int64_t &days, int64_t &micros) {
108
+ int64_t extra_months_d = input.days / Interval::DAYS_PER_MONTH;
109
+ int64_t extra_months_micros = input.micros / Interval::MICROS_PER_MONTH;
110
+ input.days -= extra_months_d * Interval::DAYS_PER_MONTH;
111
+ input.micros -= extra_months_micros * Interval::MICROS_PER_MONTH;
112
+
113
+ int64_t extra_days_micros = input.micros / Interval::MICROS_PER_DAY;
114
+ input.micros -= extra_days_micros * Interval::MICROS_PER_DAY;
115
+
116
+ months = input.months + extra_months_d + extra_months_micros;
117
+ days = input.days + extra_days_micros;
118
+ micros = input.micros;
119
+ }
120
+
121
+ bool Interval::Equals(const interval_t &left, const interval_t &right) {
122
+ return left.months == right.months && left.days == right.days && left.micros == right.micros;
123
+ }
124
+
125
+ bool Interval::GreaterThan(const interval_t &left, const interval_t &right) {
126
+ int64_t lmonths, ldays, lmicros;
127
+ int64_t rmonths, rdays, rmicros;
128
+ NormalizeIntervalEntries(left, lmonths, ldays, lmicros);
129
+ NormalizeIntervalEntries(right, rmonths, rdays, rmicros);
130
+
131
+ if (lmonths > rmonths) {
132
+ return true;
133
+ } else if (lmonths < rmonths) {
134
+ return false;
135
+ }
136
+ if (ldays > rdays) {
137
+ return true;
138
+ } else if (ldays < rdays) {
139
+ return false;
140
+ }
141
+ return lmicros > rmicros;
142
+ }
143
+
108
144
  } // namespace duckdb