duckdb 0.3.5-dev396.0 → 0.3.5-dev411.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.5-dev396.0",
4
+ "version": "0.3.5-dev411.0",
5
5
  "description": "DuckDB node.js API",
6
6
  "gypfile": true,
7
7
  "dependencies": {
package/src/duckdb.cpp CHANGED
@@ -5311,6 +5311,7 @@ public:
5311
5311
  idx_t batch_size;
5312
5312
  vector<LogicalType> column_types;
5313
5313
  vector<string> column_names;
5314
+ string timezone_config;
5314
5315
 
5315
5316
  private:
5316
5317
  static int MyStreamGetSchema(struct ArrowArrayStream *stream, struct ArrowSchema *out);
@@ -5390,7 +5391,7 @@ int ResultArrowArrayStreamWrapper::MyStreamGetSchema(struct ArrowArrayStream *st
5390
5391
  }
5391
5392
  auto my_stream = (ResultArrowArrayStreamWrapper *)stream->private_data;
5392
5393
  if (!my_stream->column_types.empty()) {
5393
- QueryResult::ToArrowSchema(out, my_stream->column_types, my_stream->column_names);
5394
+ QueryResult::ToArrowSchema(out, my_stream->column_types, my_stream->column_names, my_stream->timezone_config);
5394
5395
  return 0;
5395
5396
  }
5396
5397
 
@@ -5410,7 +5411,7 @@ int ResultArrowArrayStreamWrapper::MyStreamGetSchema(struct ArrowArrayStream *st
5410
5411
  my_stream->column_types = result.types;
5411
5412
  my_stream->column_names = result.names;
5412
5413
  }
5413
- QueryResult::ToArrowSchema(out, my_stream->column_types, my_stream->column_names);
5414
+ QueryResult::ToArrowSchema(out, my_stream->column_types, my_stream->column_names, my_stream->timezone_config);
5414
5415
  return 0;
5415
5416
  }
5416
5417
 
@@ -102593,6 +102594,21 @@ LogicalType GetArrowLogicalType(ArrowSchema &schema,
102593
102594
  idx_t fixed_size = std::stoi(parameters);
102594
102595
  arrow_convert_data[col_idx]->variable_sz_type.emplace_back(ArrowVariableSizeType::FIXED_SIZE, fixed_size);
102595
102596
  return LogicalType::BLOB;
102597
+ } else if (format[0] == 't' && format[1] == 's') {
102598
+ // Timestamp with Timezone
102599
+ if (format[2] == 'n') {
102600
+ arrow_convert_data[col_idx]->date_time_precision.emplace_back(ArrowDateTimeType::NANOSECONDS);
102601
+ } else if (format[2] == 'u') {
102602
+ arrow_convert_data[col_idx]->date_time_precision.emplace_back(ArrowDateTimeType::MICROSECONDS);
102603
+ } else if (format[2] == 'm') {
102604
+ arrow_convert_data[col_idx]->date_time_precision.emplace_back(ArrowDateTimeType::MILLISECONDS);
102605
+ } else if (format[2] == 's') {
102606
+ arrow_convert_data[col_idx]->date_time_precision.emplace_back(ArrowDateTimeType::SECONDS);
102607
+ } else {
102608
+ throw NotImplementedException(" Timestamptz precision of not accepted");
102609
+ }
102610
+ // TODO right now we just get the UTC value. We probably want to support this properly in the future
102611
+ return LogicalType::TIMESTAMP_TZ;
102596
102612
  } else {
102597
102613
  throw NotImplementedException("Unsupported Internal Arrow Type %s", format);
102598
102614
  }
@@ -102950,7 +102966,25 @@ void TimeConversion(Vector &vector, ArrowArray &array, ArrowScanState &scan_stat
102950
102966
  continue;
102951
102967
  }
102952
102968
  if (!TryMultiplyOperator::Operation((int64_t)src_ptr[row], conversion, tgt_ptr[row].micros)) {
102953
- throw ConversionException("Could not convert Interval to Microsecond");
102969
+ throw ConversionException("Could not convert Time to Microsecond");
102970
+ }
102971
+ }
102972
+ }
102973
+
102974
+ void TimestampTZConversion(Vector &vector, ArrowArray &array, ArrowScanState &scan_state, int64_t nested_offset,
102975
+ idx_t size, int64_t conversion) {
102976
+ auto tgt_ptr = (timestamp_t *)FlatVector::GetData(vector);
102977
+ auto &validity_mask = FlatVector::Validity(vector);
102978
+ auto src_ptr = (int64_t *)array.buffers[1] + scan_state.chunk_offset + array.offset;
102979
+ if (nested_offset != -1) {
102980
+ src_ptr = (int64_t *)array.buffers[1] + nested_offset + array.offset;
102981
+ }
102982
+ for (idx_t row = 0; row < size; row++) {
102983
+ if (!validity_mask.RowIsValid(row)) {
102984
+ continue;
102985
+ }
102986
+ if (!TryMultiplyOperator::Operation(src_ptr[row], conversion, tgt_ptr[row].value)) {
102987
+ throw ConversionException("Could not convert TimestampTZ to Microsecond");
102954
102988
  }
102955
102989
  }
102956
102990
  }
@@ -103115,6 +103149,37 @@ void ColumnArrowToDuckDB(Vector &vector, ArrowArray &array, ArrowScanState &scan
103115
103149
  }
103116
103150
  break;
103117
103151
  }
103152
+ case LogicalTypeId::TIMESTAMP_TZ: {
103153
+ auto precision = arrow_convert_data[col_idx]->date_time_precision[arrow_convert_idx.second++];
103154
+ switch (precision) {
103155
+ case ArrowDateTimeType::SECONDS: {
103156
+ TimestampTZConversion(vector, array, scan_state, nested_offset, size, 1000000);
103157
+ break;
103158
+ }
103159
+ case ArrowDateTimeType::MILLISECONDS: {
103160
+ TimestampTZConversion(vector, array, scan_state, nested_offset, size, 1000);
103161
+ break;
103162
+ }
103163
+ case ArrowDateTimeType::MICROSECONDS: {
103164
+ DirectConversion(vector, array, scan_state, nested_offset);
103165
+ break;
103166
+ }
103167
+ case ArrowDateTimeType::NANOSECONDS: {
103168
+ auto tgt_ptr = (timestamp_t *)FlatVector::GetData(vector);
103169
+ auto src_ptr = (int64_t *)array.buffers[1] + scan_state.chunk_offset + array.offset;
103170
+ if (nested_offset != -1) {
103171
+ src_ptr = (int64_t *)array.buffers[1] + nested_offset + array.offset;
103172
+ }
103173
+ for (idx_t row = 0; row < size; row++) {
103174
+ tgt_ptr[row].value = src_ptr[row] / 1000;
103175
+ }
103176
+ break;
103177
+ }
103178
+ default:
103179
+ throw std::runtime_error("Unsupported precision for TimestampTZ Type ");
103180
+ }
103181
+ break;
103182
+ }
103118
103183
  case LogicalTypeId::INTERVAL: {
103119
103184
  auto precision = arrow_convert_data[col_idx]->date_time_precision[arrow_convert_idx.second++];
103120
103185
  switch (precision) {
@@ -109206,6 +109271,7 @@ struct PreparedStatementWrapper {
109206
109271
  struct ArrowResultWrapper {
109207
109272
  unique_ptr<MaterializedQueryResult> result;
109208
109273
  unique_ptr<DataChunk> current_chunk;
109274
+ string timezone_config;
109209
109275
  };
109210
109276
 
109211
109277
  struct AppenderWrapper {
@@ -109462,7 +109528,8 @@ duckdb_state duckdb_query_arrow_schema(duckdb_arrow result, duckdb_arrow_schema
109462
109528
  return DuckDBSuccess;
109463
109529
  }
109464
109530
  auto wrapper = (ArrowResultWrapper *)result;
109465
- QueryResult::ToArrowSchema((ArrowSchema *)*out_schema, wrapper->result->types, wrapper->result->names);
109531
+ QueryResult::ToArrowSchema((ArrowSchema *)*out_schema, wrapper->result->types, wrapper->result->names,
109532
+ wrapper->timezone_config);
109466
109533
  return DuckDBSuccess;
109467
109534
  }
109468
109535
 
@@ -109524,6 +109591,14 @@ duckdb_state duckdb_execute_prepared_arrow(duckdb_prepared_statement prepared_st
109524
109591
  return DuckDBError;
109525
109592
  }
109526
109593
  auto arrow_wrapper = new ArrowResultWrapper();
109594
+ if (wrapper->statement->context->config.set_variables.find("TimeZone") ==
109595
+ wrapper->statement->context->config.set_variables.end()) {
109596
+ arrow_wrapper->timezone_config = "UTC";
109597
+ } else {
109598
+ arrow_wrapper->timezone_config =
109599
+ wrapper->statement->context->config.set_variables["TimeZone"].GetValue<std::string>();
109600
+ }
109601
+
109527
109602
  auto result = wrapper->statement->Execute(wrapper->values, false);
109528
109603
  D_ASSERT(result->type == QueryResultType::MATERIALIZED_RESULT);
109529
109604
  arrow_wrapper->result = duckdb::unique_ptr_cast<QueryResult, MaterializedQueryResult>(move(result));
@@ -112463,7 +112538,7 @@ unique_ptr<QueryResult> ClientContext::FetchResultInternal(ClientContextLock &lo
112463
112538
  active_query->progress_bar.reset();
112464
112539
  query_progress = -1;
112465
112540
 
112466
- // successfully compiled SELECT clause and it is the last statement
112541
+ // successfully compiled SELECT clause, and it is the last statement
112467
112542
  // return a StreamQueryResult so the client can call Fetch() on it and stream the result
112468
112543
  auto stream_result = make_unique<StreamQueryResult>(pending.statement_type, pending.properties,
112469
112544
  shared_from_this(), pending.types, pending.names);
@@ -112471,8 +112546,8 @@ unique_ptr<QueryResult> ClientContext::FetchResultInternal(ClientContextLock &lo
112471
112546
  return move(stream_result);
112472
112547
  }
112473
112548
  // create a materialized result by continuously fetching
112474
- auto result =
112475
- make_unique<MaterializedQueryResult>(pending.statement_type, pending.properties, pending.types, pending.names);
112549
+ auto result = make_unique<MaterializedQueryResult>(pending.statement_type, pending.properties, pending.types,
112550
+ pending.names, shared_from_this());
112476
112551
  result->properties = pending.properties;
112477
112552
  while (true) {
112478
112553
  auto chunk = FetchInternal(lock, GetExecutor(), *result);
@@ -112899,7 +112974,7 @@ unique_ptr<QueryResult> ClientContext::Query(const string &query, bool allow_str
112899
112974
  vector<LogicalType> types;
112900
112975
  vector<string> names;
112901
112976
  return make_unique<MaterializedQueryResult>(StatementType::INVALID_STATEMENT, properties, move(types),
112902
- move(names));
112977
+ move(names), shared_from_this());
112903
112978
  }
112904
112979
 
112905
112980
  unique_ptr<QueryResult> result;
@@ -114649,6 +114724,14 @@ void DuckDB::SetExtensionLoaded(const std::string &name) {
114649
114724
  instance->loaded_extensions.insert(name);
114650
114725
  }
114651
114726
 
114727
+ string ClientConfig::ExtractTimezoneFromConfig(ClientConfig &config) {
114728
+ if (config.set_variables.find("TimeZone") == config.set_variables.end()) {
114729
+ return "UTC";
114730
+ } else {
114731
+ return config.set_variables["TimeZone"].GetValue<std::string>();
114732
+ }
114733
+ }
114734
+
114652
114735
  } // namespace duckdb
114653
114736
 
114654
114737
 
@@ -123266,8 +123349,10 @@ Extension::~Extension() {
123266
123349
  namespace duckdb {
123267
123350
 
123268
123351
  MaterializedQueryResult::MaterializedQueryResult(StatementType statement_type, StatementProperties properties,
123269
- vector<LogicalType> types, vector<string> names)
123270
- : QueryResult(QueryResultType::MATERIALIZED_RESULT, statement_type, properties, move(types), move(names)) {
123352
+ vector<LogicalType> types, vector<string> names,
123353
+ const shared_ptr<ClientContext> &context)
123354
+ : QueryResult(QueryResultType::MATERIALIZED_RESULT, statement_type, properties, move(types), move(names)),
123355
+ context(context) {
123271
123356
  }
123272
123357
 
123273
123358
  MaterializedQueryResult::MaterializedQueryResult(string error)
@@ -124193,6 +124278,7 @@ ExpressionRootInfo::ExpressionRootInfo(ExpressionExecutorState &state, string na
124193
124278
 
124194
124279
 
124195
124280
 
124281
+
124196
124282
  namespace duckdb {
124197
124283
 
124198
124284
  BaseQueryResult::BaseQueryResult(QueryResultType type, StatementType statement_type, StatementProperties properties,
@@ -124338,9 +124424,11 @@ void InitializeChild(ArrowSchema &child, const string &name = "") {
124338
124424
  child.metadata = nullptr;
124339
124425
  child.dictionary = nullptr;
124340
124426
  }
124341
- void SetArrowFormat(DuckDBArrowSchemaHolder &root_holder, ArrowSchema &child, const LogicalType &type);
124427
+ void SetArrowFormat(DuckDBArrowSchemaHolder &root_holder, ArrowSchema &child, const LogicalType &type,
124428
+ string &config_timezone);
124342
124429
 
124343
- void SetArrowMapFormat(DuckDBArrowSchemaHolder &root_holder, ArrowSchema &child, const LogicalType &type) {
124430
+ void SetArrowMapFormat(DuckDBArrowSchemaHolder &root_holder, ArrowSchema &child, const LogicalType &type,
124431
+ string &config_timezone) {
124344
124432
  child.format = "+m";
124345
124433
  //! Map has one child which is a struct
124346
124434
  child.n_children = 1;
@@ -124355,10 +124443,11 @@ void SetArrowMapFormat(DuckDBArrowSchemaHolder &root_holder, ArrowSchema &child,
124355
124443
  struct_child_types.push_back(std::make_pair("key", ListType::GetChildType(StructType::GetChildType(type, 0))));
124356
124444
  struct_child_types.push_back(std::make_pair("value", ListType::GetChildType(StructType::GetChildType(type, 1))));
124357
124445
  auto struct_type = LogicalType::STRUCT(move(struct_child_types));
124358
- SetArrowFormat(root_holder, *child.children[0], struct_type);
124446
+ SetArrowFormat(root_holder, *child.children[0], struct_type, config_timezone);
124359
124447
  }
124360
124448
 
124361
- void SetArrowFormat(DuckDBArrowSchemaHolder &root_holder, ArrowSchema &child, const LogicalType &type) {
124449
+ void SetArrowFormat(DuckDBArrowSchemaHolder &root_holder, ArrowSchema &child, const LogicalType &type,
124450
+ string &config_timezone) {
124362
124451
  switch (type.id()) {
124363
124452
  case LogicalTypeId::BOOLEAN:
124364
124453
  child.format = "b";
@@ -124409,9 +124498,19 @@ void SetArrowFormat(DuckDBArrowSchemaHolder &root_holder, ArrowSchema &child, co
124409
124498
  child.format = "ttu";
124410
124499
  break;
124411
124500
  case LogicalTypeId::TIMESTAMP:
124412
- case LogicalTypeId::TIMESTAMP_TZ:
124413
124501
  child.format = "tsu:";
124414
124502
  break;
124503
+ case LogicalTypeId::TIMESTAMP_TZ: {
124504
+ string format = "tsu:" + config_timezone;
124505
+ unique_ptr<char[]> format_ptr = unique_ptr<char[]>(new char[format.size() + 1]);
124506
+ for (size_t i = 0; i < format.size(); i++) {
124507
+ format_ptr[i] = format[i];
124508
+ }
124509
+ format_ptr[format.size()] = '\0';
124510
+ root_holder.owned_type_names.push_back(move(format_ptr));
124511
+ child.format = root_holder.owned_type_names.back().get();
124512
+ break;
124513
+ }
124415
124514
  case LogicalTypeId::TIMESTAMP_SEC:
124416
124515
  child.format = "tss:";
124417
124516
  break;
@@ -124455,7 +124554,7 @@ void SetArrowFormat(DuckDBArrowSchemaHolder &root_holder, ArrowSchema &child, co
124455
124554
  InitializeChild(root_holder.nested_children.back()[0]);
124456
124555
  child.children = &root_holder.nested_children_ptr.back()[0];
124457
124556
  child.children[0]->name = "l";
124458
- SetArrowFormat(root_holder, **child.children, ListType::GetChildType(type));
124557
+ SetArrowFormat(root_holder, **child.children, ListType::GetChildType(type), config_timezone);
124459
124558
  break;
124460
124559
  }
124461
124560
  case LogicalTypeId::STRUCT: {
@@ -124483,12 +124582,12 @@ void SetArrowFormat(DuckDBArrowSchemaHolder &root_holder, ArrowSchema &child, co
124483
124582
  root_holder.owned_type_names.push_back(move(name_ptr));
124484
124583
 
124485
124584
  child.children[type_idx]->name = root_holder.owned_type_names.back().get();
124486
- SetArrowFormat(root_holder, *child.children[type_idx], child_types[type_idx].second);
124585
+ SetArrowFormat(root_holder, *child.children[type_idx], child_types[type_idx].second, config_timezone);
124487
124586
  }
124488
124587
  break;
124489
124588
  }
124490
124589
  case LogicalTypeId::MAP: {
124491
- SetArrowMapFormat(root_holder, child, type);
124590
+ SetArrowMapFormat(root_holder, child, type, config_timezone);
124492
124591
  break;
124493
124592
  }
124494
124593
  case LogicalTypeId::ENUM: {
@@ -124519,7 +124618,8 @@ void SetArrowFormat(DuckDBArrowSchemaHolder &root_holder, ArrowSchema &child, co
124519
124618
  }
124520
124619
  }
124521
124620
 
124522
- void QueryResult::ToArrowSchema(ArrowSchema *out_schema, vector<LogicalType> &types, vector<string> &names) {
124621
+ void QueryResult::ToArrowSchema(ArrowSchema *out_schema, vector<LogicalType> &types, vector<string> &names,
124622
+ string &config_timezone) {
124523
124623
  D_ASSERT(out_schema);
124524
124624
  D_ASSERT(types.size() == names.size());
124525
124625
  idx_t column_count = types.size();
@@ -124547,7 +124647,7 @@ void QueryResult::ToArrowSchema(ArrowSchema *out_schema, vector<LogicalType> &ty
124547
124647
 
124548
124648
  auto &child = root_holder->children[col_idx];
124549
124649
  InitializeChild(child, names[col_idx]);
124550
- SetArrowFormat(*root_holder, child, types[col_idx]);
124650
+ SetArrowFormat(*root_holder, child, types[col_idx], config_timezone);
124551
124651
  }
124552
124652
 
124553
124653
  // Release ownership to caller
@@ -124555,6 +124655,23 @@ void QueryResult::ToArrowSchema(ArrowSchema *out_schema, vector<LogicalType> &ty
124555
124655
  out_schema->release = ReleaseDuckDBArrowSchema;
124556
124656
  }
124557
124657
 
124658
+ string QueryResult::GetConfigTimezone(QueryResult &query_result) {
124659
+ switch (query_result.type) {
124660
+ case QueryResultType::MATERIALIZED_RESULT: {
124661
+ auto actual_context = ((MaterializedQueryResult &)query_result).context.lock();
124662
+ if (!actual_context) {
124663
+ throw std::runtime_error("This connection is closed");
124664
+ }
124665
+ return ClientConfig::ExtractTimezoneFromConfig(actual_context->config);
124666
+ }
124667
+ case QueryResultType::STREAM_RESULT: {
124668
+ return ClientConfig::ExtractTimezoneFromConfig(((StreamQueryResult &)query_result).context->config);
124669
+ }
124670
+ default:
124671
+ throw std::runtime_error("Can't extract timezone configuration from query type ");
124672
+ }
124673
+ }
124674
+
124558
124675
  } // namespace duckdb
124559
124676
  //===----------------------------------------------------------------------===//
124560
124677
  // DuckDB
@@ -127554,7 +127671,7 @@ unique_ptr<MaterializedQueryResult> StreamQueryResult::Materialize() {
127554
127671
  if (!success) {
127555
127672
  return make_unique<MaterializedQueryResult>(error);
127556
127673
  }
127557
- auto result = make_unique<MaterializedQueryResult>(statement_type, properties, types, names);
127674
+ auto result = make_unique<MaterializedQueryResult>(statement_type, properties, types, names, context);
127558
127675
  while (true) {
127559
127676
  auto chunk = Fetch();
127560
127677
  if (!chunk || chunk->size() == 0) {