duckdb 0.6.2-dev2350.0 → 0.6.2-dev2405.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
@@ -2,7 +2,7 @@
2
2
  "name": "duckdb",
3
3
  "main": "./lib/duckdb.js",
4
4
  "types": "./lib/duckdb.d.ts",
5
- "version": "0.6.2-dev2350.0",
5
+ "version": "0.6.2-dev2405.0",
6
6
  "description": "DuckDB node.js API",
7
7
  "gypfile": true,
8
8
  "dependencies": {
@@ -125,21 +125,13 @@ ColumnDataRowCollection::ColumnDataRowCollection(const ColumnDataCollection &col
125
125
  }
126
126
  // read all the chunks
127
127
  ColumnDataScanState temp_scan_state;
128
- collection.InitializeScan(temp_scan_state);
128
+ collection.InitializeScan(temp_scan_state, ColumnDataScanProperties::DISALLOW_ZERO_COPY);
129
129
  while (true) {
130
130
  auto chunk = make_unique<DataChunk>();
131
131
  collection.InitializeScanChunk(*chunk);
132
132
  if (!collection.Scan(temp_scan_state, *chunk)) {
133
133
  break;
134
134
  }
135
- // we keep the BufferHandles that are needed for the materialized collection pinned in the supplied scan_state
136
- auto &temp_handles = temp_scan_state.current_chunk_state.handles;
137
- auto &scan_handles = scan_state.current_chunk_state.handles;
138
- for (auto &temp_handle_pair : temp_handles) {
139
- auto handle_copy =
140
- make_pair<uint32_t, BufferHandle>(scan_handles.size(), std::move(temp_handle_pair.second));
141
- scan_state.current_chunk_state.handles.insert(std::move(handle_copy));
142
- }
143
135
  chunks.push_back(std::move(chunk));
144
136
  }
145
137
  // now create all of the column data rows
@@ -1584,6 +1584,10 @@ bool Value::DefaultTryCastAs(const LogicalType &target_type, bool strict) {
1584
1584
  return TryCastAs(set, get_input, target_type, strict);
1585
1585
  }
1586
1586
 
1587
+ void Value::Reinterpret(LogicalType new_type) {
1588
+ this->type_ = std::move(new_type);
1589
+ }
1590
+
1587
1591
  void Value::Serialize(Serializer &main_serializer) const {
1588
1592
  FieldWriter writer(main_serializer);
1589
1593
  writer.WriteSerializable(type_);
@@ -588,7 +588,7 @@ Value Vector::GetValue(const Vector &v_p, idx_t index_p) {
588
588
  auto value = GetValueInternal(v_p, index_p);
589
589
  // set the alias of the type to the correct value, if there is a type alias
590
590
  if (v_p.GetType().HasAlias()) {
591
- value.type().CopyAuxInfo(v_p.GetType());
591
+ value.GetTypeMutable().CopyAuxInfo(v_p.GetType());
592
592
  }
593
593
  if (v_p.GetType().id() != LogicalTypeId::AGGREGATE_STATE && value.type().id() != LogicalTypeId::AGGREGATE_STATE) {
594
594
 
@@ -98,7 +98,7 @@ void WindowSegmentTree::ExtractFrame(idx_t begin, idx_t end) {
98
98
 
99
99
  void WindowSegmentTree::WindowSegmentValue(idx_t l_idx, idx_t begin, idx_t end) {
100
100
  D_ASSERT(begin <= end);
101
- if (begin == end) {
101
+ if (begin == end || inputs.ColumnCount() == 0) {
102
102
  return;
103
103
  }
104
104
 
@@ -107,6 +107,7 @@ void WindowSegmentTree::WindowSegmentValue(idx_t l_idx, idx_t begin, idx_t end)
107
107
  if (l_idx == 0) {
108
108
  ExtractFrame(begin, end);
109
109
  AggregateInputData aggr_input_data(bind_info, Allocator::DefaultAllocator());
110
+ D_ASSERT(inputs.data.size() > 0);
110
111
  aggregate.update(&inputs.data[0], aggr_input_data, input_ref->ColumnCount(), s, inputs.size());
111
112
  } else {
112
113
  // find out where the states begin
@@ -1216,6 +1216,9 @@ static const Value &CheckQuantile(const Value &quantile_val) {
1216
1216
  if (quantile < -1 || quantile > 1) {
1217
1217
  throw BinderException("QUANTILE can only take parameters in the range [-1, 1]");
1218
1218
  }
1219
+ if (Value::IsNan(quantile)) {
1220
+ throw BinderException("QUANTILE parameter cannot be NaN");
1221
+ }
1219
1222
 
1220
1223
  return quantile_val;
1221
1224
  }
@@ -259,7 +259,7 @@ char *StrfTimeFormat::WriteDateSpecifier(StrTimeSpecifier specifier, date_t date
259
259
  }
260
260
 
261
261
  char *StrfTimeFormat::WriteStandardSpecifier(StrTimeSpecifier specifier, int32_t data[], const char *tz_name,
262
- char *target) {
262
+ size_t tz_len, char *target) {
263
263
  // data contains [0] year, [1] month, [2] day, [3] hour, [4] minute, [5] second, [6] msec, [7] utc
264
264
  switch (specifier) {
265
265
  case StrTimeSpecifier::DAY_OF_MONTH_PADDED:
@@ -338,7 +338,7 @@ char *StrfTimeFormat::WriteStandardSpecifier(StrTimeSpecifier specifier, int32_t
338
338
  }
339
339
  case StrTimeSpecifier::TZ_NAME:
340
340
  if (tz_name) {
341
- strcpy(target, tz_name);
341
+ memcpy(target, tz_name, tz_len);
342
342
  target += strlen(tz_name);
343
343
  }
344
344
  break;
@@ -391,7 +391,8 @@ void StrfTimeFormat::FormatString(date_t date, int32_t data[8], const char *tz_n
391
391
  if (is_date_specifier[i]) {
392
392
  target = WriteDateSpecifier(specifiers[i], date, target);
393
393
  } else {
394
- target = WriteStandardSpecifier(specifiers[i], data, tz_name, target);
394
+ auto tz_len = tz_name ? strlen(tz_name) : 0;
395
+ target = WriteStandardSpecifier(specifiers[i], data, tz_name, tz_len, target);
395
396
  }
396
397
  }
397
398
  // copy the final literal into the target
@@ -1,8 +1,8 @@
1
1
  #ifndef DUCKDB_VERSION
2
- #define DUCKDB_VERSION "0.6.2-dev2350"
2
+ #define DUCKDB_VERSION "0.6.2-dev2405"
3
3
  #endif
4
4
  #ifndef DUCKDB_SOURCE_ID
5
- #define DUCKDB_SOURCE_ID "6bfbe238d4"
5
+ #define DUCKDB_SOURCE_ID "2eb46acc6e"
6
6
  #endif
7
7
  #include "duckdb/function/table/system_functions.hpp"
8
8
  #include "duckdb/main/database.hpp"
@@ -63,7 +63,7 @@ public:
63
63
  // move assignment
64
64
  DUCKDB_API Value &operator=(Value &&other) noexcept;
65
65
 
66
- inline LogicalType &type() {
66
+ inline LogicalType &GetTypeMutable() {
67
67
  return type_;
68
68
  }
69
69
  inline const LogicalType &type() const {
@@ -221,6 +221,8 @@ public:
221
221
  DUCKDB_API bool TryCastAs(ClientContext &context, const LogicalType &target_type, bool strict = false);
222
222
  DUCKDB_API bool DefaultTryCastAs(const LogicalType &target_type, bool strict = false);
223
223
 
224
+ DUCKDB_API void Reinterpret(LogicalType new_type);
225
+
224
226
  //! Serializes a Value to a stand-alone binary blob
225
227
  DUCKDB_API void Serialize(Serializer &serializer) const;
226
228
  //! Deserializes a Value from a blob
@@ -112,7 +112,8 @@ protected:
112
112
  char *WritePadded(char *target, uint32_t value, size_t padding);
113
113
  bool IsDateSpecifier(StrTimeSpecifier specifier);
114
114
  char *WriteDateSpecifier(StrTimeSpecifier specifier, date_t date, char *target);
115
- char *WriteStandardSpecifier(StrTimeSpecifier specifier, int32_t data[], const char *tz_name, char *target);
115
+ char *WriteStandardSpecifier(StrTimeSpecifier specifier, int32_t data[], const char *tz_name, size_t tz_len,
116
+ char *target);
116
117
  };
117
118
 
118
119
  struct StrpTimeFormat : public StrTimeFormat {
@@ -83,7 +83,7 @@ public:
83
83
 
84
84
  //! Adds a base table with the given alias to the BindContext.
85
85
  void AddBaseTable(idx_t index, const string &alias, const vector<string> &names, const vector<LogicalType> &types,
86
- vector<column_t> &bound_column_ids, StandardEntry *entry);
86
+ vector<column_t> &bound_column_ids, StandardEntry *entry, bool add_row_id = true);
87
87
  //! Adds a call to a table function with the given alias to the BindContext.
88
88
  void AddTableFunction(idx_t index, const string &alias, const vector<string> &names,
89
89
  const vector<LogicalType> &types, vector<column_t> &bound_column_ids, StandardEntry *entry);
@@ -20,10 +20,6 @@ public:
20
20
  protected:
21
21
  BindResult BindExpression(unique_ptr<ParsedExpression> *expr_ptr, idx_t depth,
22
22
  bool root_expression = false) override;
23
-
24
- // check certain column ref Names to make sure they are supported in the returning statement
25
- // (i.e rowid)
26
- BindResult BindColumnRef(unique_ptr<ParsedExpression> *expr_ptr, idx_t depth);
27
23
  };
28
24
 
29
25
  } // namespace duckdb
@@ -170,6 +170,12 @@ string ExtensionHelper::ExtractExtensionPrefixFromPath(const string &path) {
170
170
  return "";
171
171
  }
172
172
  auto extension = path.substr(0, first_colon);
173
+
174
+ if (path.substr(first_colon, 3) == "://") {
175
+ // these are not extensions
176
+ return "";
177
+ }
178
+
173
179
  D_ASSERT(extension.size() > 1);
174
180
  // needs to be alphanumeric
175
181
  for (auto &ch : extension) {
@@ -177,10 +183,6 @@ string ExtensionHelper::ExtractExtensionPrefixFromPath(const string &path) {
177
183
  return "";
178
184
  }
179
185
  }
180
- if (extension == "http" || extension == "https" || extension == "s3") {
181
- // these are not extensions
182
- return "";
183
- }
184
186
  return extension;
185
187
  }
186
188
 
@@ -582,7 +582,7 @@ FilterResult FilterCombiner::AddBoundComparisonFilter(Expression *expr) {
582
582
  comparison.type != ExpressionType::COMPARE_GREATERTHAN &&
583
583
  comparison.type != ExpressionType::COMPARE_GREATERTHANOREQUALTO &&
584
584
  comparison.type != ExpressionType::COMPARE_EQUAL && comparison.type != ExpressionType::COMPARE_NOTEQUAL) {
585
- // only support [>, >=, <, <=, ==] expressions
585
+ // only support [>, >=, <, <=, ==, !=] expressions
586
586
  return FilterResult::UNSUPPORTED;
587
587
  }
588
588
  // check if one of the sides is a scalar value
@@ -610,6 +610,7 @@ FilterResult FilterCombiner::AddBoundComparisonFilter(Expression *expr) {
610
610
  // get the current bucket of constant values
611
611
  D_ASSERT(constant_values.find(equivalence_set) != constant_values.end());
612
612
  auto &info_list = constant_values.find(equivalence_set)->second;
613
+ D_ASSERT(node->return_type == info.constant.type());
613
614
  // check the existing constant comparisons to see if we can do any pruning
614
615
  auto ret = AddConstantComparison(info_list, info);
615
616
 
@@ -795,7 +796,8 @@ FilterResult FilterCombiner::AddTransitiveFilters(BoundComparisonExpression &com
795
796
  for (auto &stored_exp : stored_expressions) {
796
797
  if (stored_exp.first->type == ExpressionType::BOUND_COLUMN_REF) {
797
798
  auto &st_col_ref = (BoundColumnRefExpression &)*stored_exp.second;
798
- if (st_col_ref.binding == col_ref.binding) {
799
+ if (st_col_ref.binding == col_ref.binding &&
800
+ bound_cast_expr.return_type == stored_exp.second->return_type) {
799
801
  bound_cast_expr.child = stored_exp.second->Copy();
800
802
  right_node = GetNode(bound_cast_expr.child.get());
801
803
  break;
@@ -454,8 +454,8 @@ void BindContext::AddBinding(const string &alias, unique_ptr<Binding> binding) {
454
454
 
455
455
  void BindContext::AddBaseTable(idx_t index, const string &alias, const vector<string> &names,
456
456
  const vector<LogicalType> &types, vector<column_t> &bound_column_ids,
457
- StandardEntry *entry) {
458
- AddBinding(alias, make_unique<TableBinding>(alias, types, names, bound_column_ids, entry, index, true));
457
+ StandardEntry *entry, bool add_row_id) {
458
+ AddBinding(alias, make_unique<TableBinding>(alias, types, names, bound_column_ids, entry, index, add_row_id));
459
459
  }
460
460
 
461
461
  void BindContext::AddTableFunction(idx_t index, const string &alias, const vector<string> &names,
@@ -449,7 +449,7 @@ BoundStatement Binder::BindReturning(vector<unique_ptr<ParsedExpression>> return
449
449
  column_count++;
450
450
  }
451
451
 
452
- binder->bind_context.AddBaseTable(update_table_index, table->name, names, types, bound_columns, table);
452
+ binder->bind_context.AddBaseTable(update_table_index, table->name, names, types, bound_columns, table, false);
453
453
  ReturningBinder returning_binder(*binder, context);
454
454
 
455
455
  vector<unique_ptr<Expression>> projection_expressions;
@@ -7,14 +7,6 @@ namespace duckdb {
7
7
  ReturningBinder::ReturningBinder(Binder &binder, ClientContext &context) : ExpressionBinder(binder, context) {
8
8
  }
9
9
 
10
- BindResult ReturningBinder::BindColumnRef(unique_ptr<ParsedExpression> *expr_ptr, idx_t depth) {
11
- auto &expr = **expr_ptr;
12
- if (expr.GetName() == "rowid") {
13
- return BindResult("rowid is not supported in returning statements");
14
- }
15
- return ExpressionBinder::BindExpression(expr_ptr, depth);
16
- }
17
-
18
10
  BindResult ReturningBinder::BindExpression(unique_ptr<ParsedExpression> *expr_ptr, idx_t depth, bool root_expression) {
19
11
  auto &expr = **expr_ptr;
20
12
  switch (expr.GetExpressionClass()) {
@@ -23,7 +15,7 @@ BindResult ReturningBinder::BindExpression(unique_ptr<ParsedExpression> *expr_pt
23
15
  case ExpressionClass::BOUND_SUBQUERY:
24
16
  return BindResult("BOUND SUBQUERY is not supported in returning statements");
25
17
  case ExpressionClass::COLUMN_REF:
26
- return BindColumnRef(expr_ptr, depth);
18
+ return ExpressionBinder::BindExpression(expr_ptr, depth);
27
19
  default:
28
20
  return ExpressionBinder::BindExpression(expr_ptr, depth);
29
21
  }
@@ -124,15 +124,113 @@ bool NumericStatistics::IsConstant() const {
124
124
  return max <= min;
125
125
  }
126
126
 
127
+ void SerializeNumericStatsValue(const Value &val, FieldWriter &writer) {
128
+ writer.WriteField<bool>(val.IsNull());
129
+ if (val.IsNull()) {
130
+ return;
131
+ }
132
+ switch (val.type().InternalType()) {
133
+ case PhysicalType::BOOL:
134
+ writer.WriteField<bool>(BooleanValue::Get(val));
135
+ break;
136
+ case PhysicalType::INT8:
137
+ writer.WriteField<int8_t>(TinyIntValue::Get(val));
138
+ break;
139
+ case PhysicalType::INT16:
140
+ writer.WriteField<int16_t>(SmallIntValue::Get(val));
141
+ break;
142
+ case PhysicalType::INT32:
143
+ writer.WriteField<int32_t>(IntegerValue::Get(val));
144
+ break;
145
+ case PhysicalType::INT64:
146
+ writer.WriteField<int64_t>(BigIntValue::Get(val));
147
+ break;
148
+ case PhysicalType::UINT8:
149
+ writer.WriteField<int8_t>(UTinyIntValue::Get(val));
150
+ break;
151
+ case PhysicalType::UINT16:
152
+ writer.WriteField<int16_t>(USmallIntValue::Get(val));
153
+ break;
154
+ case PhysicalType::UINT32:
155
+ writer.WriteField<int32_t>(UIntegerValue::Get(val));
156
+ break;
157
+ case PhysicalType::UINT64:
158
+ writer.WriteField<int64_t>(UBigIntValue::Get(val));
159
+ break;
160
+ case PhysicalType::INT128:
161
+ writer.WriteField<hugeint_t>(HugeIntValue::Get(val));
162
+ break;
163
+ case PhysicalType::FLOAT:
164
+ writer.WriteField<float>(FloatValue::Get(val));
165
+ break;
166
+ case PhysicalType::DOUBLE:
167
+ writer.WriteField<double>(DoubleValue::Get(val));
168
+ break;
169
+ default:
170
+ throw InternalException("Unsupported type for serializing numeric statistics");
171
+ }
172
+ }
173
+
127
174
  void NumericStatistics::Serialize(FieldWriter &writer) const {
128
- writer.WriteSerializable(min);
129
- writer.WriteSerializable(max);
175
+ SerializeNumericStatsValue(min, writer);
176
+ SerializeNumericStatsValue(max, writer);
177
+ }
178
+
179
+ Value DeserializeNumericStatsValue(const LogicalType &type, FieldReader &reader) {
180
+ auto is_null = reader.ReadRequired<bool>();
181
+ if (is_null) {
182
+ return Value(type);
183
+ }
184
+ Value result;
185
+ switch (type.InternalType()) {
186
+ case PhysicalType::BOOL:
187
+ result = Value::BOOLEAN(reader.ReadRequired<bool>());
188
+ break;
189
+ case PhysicalType::INT8:
190
+ result = Value::TINYINT(reader.ReadRequired<int8_t>());
191
+ break;
192
+ case PhysicalType::INT16:
193
+ result = Value::SMALLINT(reader.ReadRequired<int16_t>());
194
+ break;
195
+ case PhysicalType::INT32:
196
+ result = Value::INTEGER(reader.ReadRequired<int32_t>());
197
+ break;
198
+ case PhysicalType::INT64:
199
+ result = Value::BIGINT(reader.ReadRequired<int64_t>());
200
+ break;
201
+ case PhysicalType::UINT8:
202
+ result = Value::UTINYINT(reader.ReadRequired<uint8_t>());
203
+ break;
204
+ case PhysicalType::UINT16:
205
+ result = Value::USMALLINT(reader.ReadRequired<uint16_t>());
206
+ break;
207
+ case PhysicalType::UINT32:
208
+ result = Value::UINTEGER(reader.ReadRequired<uint32_t>());
209
+ break;
210
+ case PhysicalType::UINT64:
211
+ result = Value::UBIGINT(reader.ReadRequired<uint64_t>());
212
+ break;
213
+ case PhysicalType::INT128:
214
+ result = Value::HUGEINT(reader.ReadRequired<hugeint_t>());
215
+ break;
216
+ case PhysicalType::FLOAT:
217
+ result = Value::FLOAT(reader.ReadRequired<float>());
218
+ break;
219
+ case PhysicalType::DOUBLE:
220
+ result = Value::DOUBLE(reader.ReadRequired<double>());
221
+ break;
222
+ default:
223
+ throw InternalException("Unsupported type for deserializing numeric statistics");
224
+ }
225
+ result.Reinterpret(type);
226
+ return result;
130
227
  }
131
228
 
132
229
  unique_ptr<BaseStatistics> NumericStatistics::Deserialize(FieldReader &reader, LogicalType type) {
133
- auto min = reader.ReadRequiredSerializable<Value, Value>();
134
- auto max = reader.ReadRequiredSerializable<Value, Value>();
135
- return make_unique_base<BaseStatistics, NumericStatistics>(std::move(type), min, max, StatisticsType::LOCAL_STATS);
230
+ auto min = DeserializeNumericStatsValue(type, reader);
231
+ auto max = DeserializeNumericStatsValue(type, reader);
232
+ return make_unique_base<BaseStatistics, NumericStatistics>(std::move(type), std::move(min), std::move(max),
233
+ StatisticsType::LOCAL_STATS);
136
234
  }
137
235
 
138
236
  string NumericStatistics::ToString() const {
@@ -2,7 +2,7 @@
2
2
 
3
3
  namespace duckdb {
4
4
 
5
- const uint64_t VERSION_NUMBER = 42;
5
+ const uint64_t VERSION_NUMBER = 43;
6
6
 
7
7
  struct StorageVersionInfo {
8
8
  const char *version_name;