duckdb 0.3.2-dev24.0 → 0.3.2-dev31.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.2-dev24.0",
4
+ "version": "0.3.2-dev31.0",
5
5
  "description": "DuckDB node.js API",
6
6
  "gypfile": true,
7
7
  "dependencies": {
package/src/duckdb.cpp CHANGED
@@ -18315,7 +18315,7 @@ struct RegexpFun {
18315
18315
 
18316
18316
  struct SubstringFun {
18317
18317
  static void RegisterFunction(BuiltinFunctions &set);
18318
- static string_t SubstringScalarFunction(Vector &result, string_t input, int32_t offset, int32_t length);
18318
+ static string_t SubstringScalarFunction(Vector &result, string_t input, int64_t offset, int64_t length);
18319
18319
  };
18320
18320
 
18321
18321
  struct PrintfFun {
@@ -61228,15 +61228,9 @@ struct BufferedCSVReaderOptions {
61228
61228
  //! Whether or not a type format is specified
61229
61229
  std::map<LogicalTypeId, bool> has_format = {{LogicalTypeId::DATE, false}, {LogicalTypeId::TIMESTAMP, false}};
61230
61230
 
61231
- std::string toString() const {
61232
- return "DELIMITER='" + delimiter + (has_delimiter ? "'" : (auto_detect ? "' (auto detected)" : "' (default)")) +
61233
- ", QUOTE='" + quote + (has_quote ? "'" : (auto_detect ? "' (auto detected)" : "' (default)")) +
61234
- ", ESCAPE='" + escape + (has_escape ? "'" : (auto_detect ? "' (auto detected)" : "' (default)")) +
61235
- ", HEADER=" + std::to_string(header) +
61236
- (has_header ? "" : (auto_detect ? " (auto detected)" : "' (default)")) +
61237
- ", SAMPLE_SIZE=" + std::to_string(sample_chunk_size * sample_chunks) +
61238
- ", ALL_VARCHAR=" + std::to_string(all_varchar);
61239
- }
61231
+ void SetDelimiter(const string &delimiter);
61232
+
61233
+ std::string ToString() const;
61240
61234
  };
61241
61235
 
61242
61236
  enum class ParserMode : uint8_t { PARSING = 0, SNIFFING_DIALECT = 1, SNIFFING_DATATYPES = 2, PARSING_HEADER = 3 };
@@ -61389,6 +61383,24 @@ private:
61389
61383
 
61390
61384
  namespace duckdb {
61391
61385
 
61386
+ void BufferedCSVReaderOptions::SetDelimiter(const string &input) {
61387
+ this->delimiter = StringUtil::Replace(input, "\\t", "\t");
61388
+ this->has_delimiter = true;
61389
+ if (input.empty()) {
61390
+ throw BinderException("DELIM or SEP must not be empty");
61391
+ }
61392
+ }
61393
+
61394
+ std::string BufferedCSVReaderOptions::ToString() const {
61395
+ return "DELIMITER='" + delimiter + (has_delimiter ? "'" : (auto_detect ? "' (auto detected)" : "' (default)")) +
61396
+ ", QUOTE='" + quote + (has_quote ? "'" : (auto_detect ? "' (auto detected)" : "' (default)")) +
61397
+ ", ESCAPE='" + escape + (has_escape ? "'" : (auto_detect ? "' (auto detected)" : "' (default)")) +
61398
+ ", HEADER=" + std::to_string(header) +
61399
+ (has_header ? "" : (auto_detect ? " (auto detected)" : "' (default)")) +
61400
+ ", SAMPLE_SIZE=" + std::to_string(sample_chunk_size * sample_chunks) +
61401
+ ", ALL_VARCHAR=" + std::to_string(all_varchar);
61402
+ }
61403
+
61392
61404
  static string GetLineNumberStr(idx_t linenr, bool linenr_estimated) {
61393
61405
  string estimated = (linenr_estimated ? string(" (estimated)") : string(""));
61394
61406
  return to_string(linenr + 1) + estimated;
@@ -62202,7 +62214,7 @@ vector<LogicalType> BufferedCSVReader::RefineTypeDetection(const vector<LogicalT
62202
62214
  if (requested_types.size() != options.num_cols) {
62203
62215
  throw InvalidInputException(
62204
62216
  "Error while determining column types: found %lld columns but expected %d. (%s)", options.num_cols,
62205
- requested_types.size(), options.toString());
62217
+ requested_types.size(), options.ToString());
62206
62218
  } else {
62207
62219
  detected_types = requested_types;
62208
62220
  }
@@ -62460,7 +62472,7 @@ in_quotes:
62460
62472
  } while (ReadBuffer(start));
62461
62473
  // still in quoted state at the end of the file, error:
62462
62474
  error_message = StringUtil::Format("Error in file \"%s\" on line %s: unterminated quotes. (%s)", options.file_path,
62463
- GetLineNumberStr(linenr, linenr_estimated).c_str(), options.toString());
62475
+ GetLineNumberStr(linenr, linenr_estimated).c_str(), options.ToString());
62464
62476
  return false;
62465
62477
  unquote:
62466
62478
  /* state: unquote */
@@ -62490,7 +62502,7 @@ unquote:
62490
62502
  error_message = StringUtil::Format(
62491
62503
  "Error in file \"%s\" on line %s: quote should be followed by end of value, end "
62492
62504
  "of row or another quote. (%s)",
62493
- options.file_path, GetLineNumberStr(linenr, linenr_estimated).c_str(), options.toString());
62505
+ options.file_path, GetLineNumberStr(linenr, linenr_estimated).c_str(), options.ToString());
62494
62506
  return false;
62495
62507
  }
62496
62508
  if (delimiter_pos == options.delimiter.size()) {
@@ -62507,7 +62519,7 @@ unquote:
62507
62519
  } while (ReadBuffer(start));
62508
62520
  error_message = StringUtil::Format(
62509
62521
  "Error in file \"%s\" on line %s: quote should be followed by end of value, end of row or another quote. (%s)",
62510
- options.file_path, GetLineNumberStr(linenr, linenr_estimated).c_str(), options.toString());
62522
+ options.file_path, GetLineNumberStr(linenr, linenr_estimated).c_str(), options.ToString());
62511
62523
  return false;
62512
62524
  handle_escape:
62513
62525
  escape_pos = 0;
@@ -62522,7 +62534,7 @@ handle_escape:
62522
62534
  if (count > escape_pos && count > quote_pos) {
62523
62535
  error_message = StringUtil::Format(
62524
62536
  "Error in file \"%s\" on line %s: neither QUOTE nor ESCAPE is proceeded by ESCAPE. (%s)",
62525
- options.file_path, GetLineNumberStr(linenr, linenr_estimated).c_str(), options.toString());
62537
+ options.file_path, GetLineNumberStr(linenr, linenr_estimated).c_str(), options.ToString());
62526
62538
  return false;
62527
62539
  }
62528
62540
  if (quote_pos == options.quote.size() || escape_pos == options.escape.size()) {
@@ -62533,7 +62545,7 @@ handle_escape:
62533
62545
  } while (ReadBuffer(start));
62534
62546
  error_message =
62535
62547
  StringUtil::Format("Error in file \"%s\" on line %s: neither QUOTE nor ESCAPE is proceeded by ESCAPE. (%s)",
62536
- options.file_path, GetLineNumberStr(linenr, linenr_estimated).c_str(), options.toString());
62548
+ options.file_path, GetLineNumberStr(linenr, linenr_estimated).c_str(), options.ToString());
62537
62549
  return false;
62538
62550
  carriage_return:
62539
62551
  /* state: carriage_return */
@@ -62665,7 +62677,7 @@ in_quotes:
62665
62677
  } while (ReadBuffer(start));
62666
62678
  // still in quoted state at the end of the file, error:
62667
62679
  throw InvalidInputException("Error in file \"%s\" on line %s: unterminated quotes. (%s)", options.file_path,
62668
- GetLineNumberStr(linenr, linenr_estimated).c_str(), options.toString());
62680
+ GetLineNumberStr(linenr, linenr_estimated).c_str(), options.ToString());
62669
62681
  unquote:
62670
62682
  /* state: unquote */
62671
62683
  // this state handles the state directly after we unquote
@@ -62692,7 +62704,7 @@ unquote:
62692
62704
  error_message = StringUtil::Format(
62693
62705
  "Error in file \"%s\" on line %s: quote should be followed by end of value, end of "
62694
62706
  "row or another quote. (%s)",
62695
- options.file_path, GetLineNumberStr(linenr, linenr_estimated).c_str(), options.toString());
62707
+ options.file_path, GetLineNumberStr(linenr, linenr_estimated).c_str(), options.ToString());
62696
62708
  return false;
62697
62709
  }
62698
62710
  handle_escape:
@@ -62702,13 +62714,13 @@ handle_escape:
62702
62714
  if (position >= buffer_size && !ReadBuffer(start)) {
62703
62715
  error_message = StringUtil::Format(
62704
62716
  "Error in file \"%s\" on line %s: neither QUOTE nor ESCAPE is proceeded by ESCAPE. (%s)", options.file_path,
62705
- GetLineNumberStr(linenr, linenr_estimated).c_str(), options.toString());
62717
+ GetLineNumberStr(linenr, linenr_estimated).c_str(), options.ToString());
62706
62718
  return false;
62707
62719
  }
62708
62720
  if (buffer[position] != options.quote[0] && buffer[position] != options.escape[0]) {
62709
62721
  error_message = StringUtil::Format(
62710
62722
  "Error in file \"%s\" on line %s: neither QUOTE nor ESCAPE is proceeded by ESCAPE. (%s)", options.file_path,
62711
- GetLineNumberStr(linenr, linenr_estimated).c_str(), options.toString());
62723
+ GetLineNumberStr(linenr, linenr_estimated).c_str(), options.ToString());
62712
62724
  return false;
62713
62725
  }
62714
62726
  // escape was followed by quote or escape, go back to quoted state
@@ -62848,7 +62860,7 @@ void BufferedCSVReader::AddValue(char *str_val, idx_t length, idx_t &column, vec
62848
62860
  if (column >= sql_types.size()) {
62849
62861
  throw InvalidInputException("Error on line %s: expected %lld values per row, but got more. (%s)",
62850
62862
  GetLineNumberStr(linenr, linenr_estimated).c_str(), sql_types.size(),
62851
- options.toString());
62863
+ options.ToString());
62852
62864
  }
62853
62865
 
62854
62866
  // insert the line number into the chunk
@@ -62903,7 +62915,7 @@ bool BufferedCSVReader::AddRow(DataChunk &insert_chunk, idx_t &column) {
62903
62915
  if (column < sql_types.size() && mode != ParserMode::SNIFFING_DIALECT) {
62904
62916
  throw InvalidInputException("Error on line %s: expected %lld values per row, but got %d. (%s)",
62905
62917
  GetLineNumberStr(linenr, linenr_estimated).c_str(), sql_types.size(), column,
62906
- options.toString());
62918
+ options.ToString());
62907
62919
  }
62908
62920
 
62909
62921
  if (mode == ParserMode::SNIFFING_DIALECT) {
@@ -62956,7 +62968,7 @@ void BufferedCSVReader::Flush(DataChunk &insert_chunk) {
62956
62968
  throw InvalidInputException("Error in file \"%s\" between line %llu and %llu in column \"%s\": "
62957
62969
  "file is not valid UTF8. Parser options: %s",
62958
62970
  options.file_path, linenr - parse_chunk.size(), linenr, col_name,
62959
- options.toString());
62971
+ options.ToString());
62960
62972
  }
62961
62973
  }
62962
62974
  }
@@ -62990,11 +63002,11 @@ void BufferedCSVReader::Flush(DataChunk &insert_chunk) {
62990
63002
  "(SAMPLE_SIZE=X [X rows] or SAMPLE_SIZE=-1 [all rows]), "
62991
63003
  "or skipping column conversion (ALL_VARCHAR=1)",
62992
63004
  error_message, col_name, linenr - parse_chunk.size() + 1, linenr,
62993
- options.toString());
63005
+ options.ToString());
62994
63006
  } else {
62995
63007
  throw InvalidInputException("%s between line %llu and %llu in column %s. Parser options: %s ",
62996
63008
  error_message, linenr - parse_chunk.size(), linenr, col_name,
62997
- options.toString());
63009
+ options.ToString());
62998
63010
  }
62999
63011
  }
63000
63012
  }
@@ -92198,7 +92210,7 @@ string_t SubstringASCII(Vector &result, string_t input, int64_t offset, int64_t
92198
92210
  return SubstringSlice(result, input_data, start, end - start);
92199
92211
  }
92200
92212
 
92201
- string_t SubstringFun::SubstringScalarFunction(Vector &result, string_t input, int32_t offset, int32_t length) {
92213
+ string_t SubstringFun::SubstringScalarFunction(Vector &result, string_t input, int64_t offset, int64_t length) {
92202
92214
  auto input_data = input.GetDataUnsafe();
92203
92215
  auto input_size = input.GetSize();
92204
92216
 
@@ -92265,16 +92277,16 @@ static void SubstringFunction(DataChunk &args, ExpressionState &state, Vector &r
92265
92277
  if (args.ColumnCount() == 3) {
92266
92278
  auto &length_vector = args.data[2];
92267
92279
 
92268
- TernaryExecutor::Execute<string_t, int32_t, int32_t, string_t>(
92280
+ TernaryExecutor::Execute<string_t, int64_t, int64_t, string_t>(
92269
92281
  input_vector, offset_vector, length_vector, result, args.size(),
92270
- [&](string_t input_string, int32_t offset, int32_t length) {
92282
+ [&](string_t input_string, int64_t offset, int64_t length) {
92271
92283
  return SubstringFun::SubstringScalarFunction(result, input_string, offset, length);
92272
92284
  });
92273
92285
  } else {
92274
- BinaryExecutor::Execute<string_t, int32_t, string_t>(
92275
- input_vector, offset_vector, result, args.size(), [&](string_t input_string, int32_t offset) {
92286
+ BinaryExecutor::Execute<string_t, int64_t, string_t>(
92287
+ input_vector, offset_vector, result, args.size(), [&](string_t input_string, int64_t offset) {
92276
92288
  return SubstringFun::SubstringScalarFunction(result, input_string, offset,
92277
- NumericLimits<int32_t>::Maximum());
92289
+ NumericLimits<int64_t>::Maximum() - offset);
92278
92290
  });
92279
92291
  }
92280
92292
  }
@@ -92285,15 +92297,15 @@ static void SubstringFunctionASCII(DataChunk &args, ExpressionState &state, Vect
92285
92297
  if (args.ColumnCount() == 3) {
92286
92298
  auto &length_vector = args.data[2];
92287
92299
 
92288
- TernaryExecutor::Execute<string_t, int32_t, int32_t, string_t>(
92300
+ TernaryExecutor::Execute<string_t, int64_t, int64_t, string_t>(
92289
92301
  input_vector, offset_vector, length_vector, result, args.size(),
92290
- [&](string_t input_string, int32_t offset, int32_t length) {
92302
+ [&](string_t input_string, int64_t offset, int64_t length) {
92291
92303
  return SubstringASCII(result, input_string, offset, length);
92292
92304
  });
92293
92305
  } else {
92294
- BinaryExecutor::Execute<string_t, int32_t, string_t>(
92295
- input_vector, offset_vector, result, args.size(), [&](string_t input_string, int32_t offset) {
92296
- return SubstringASCII(result, input_string, offset, NumericLimits<int32_t>::Maximum());
92306
+ BinaryExecutor::Execute<string_t, int64_t, string_t>(
92307
+ input_vector, offset_vector, result, args.size(), [&](string_t input_string, int64_t offset) {
92308
+ return SubstringASCII(result, input_string, offset, NumericLimits<int64_t>::Maximum() - offset);
92297
92309
  });
92298
92310
  }
92299
92311
  }
@@ -92315,10 +92327,10 @@ static unique_ptr<BaseStatistics> SubstringPropagateStats(ClientContext &context
92315
92327
 
92316
92328
  void SubstringFun::RegisterFunction(BuiltinFunctions &set) {
92317
92329
  ScalarFunctionSet substr("substring");
92318
- substr.AddFunction(ScalarFunction({LogicalType::VARCHAR, LogicalType::INTEGER, LogicalType::INTEGER},
92330
+ substr.AddFunction(ScalarFunction({LogicalType::VARCHAR, LogicalType::BIGINT, LogicalType::BIGINT},
92319
92331
  LogicalType::VARCHAR, SubstringFunction, false, nullptr, nullptr,
92320
92332
  SubstringPropagateStats));
92321
- substr.AddFunction(ScalarFunction({LogicalType::VARCHAR, LogicalType::INTEGER}, LogicalType::VARCHAR,
92333
+ substr.AddFunction(ScalarFunction({LogicalType::VARCHAR, LogicalType::BIGINT}, LogicalType::VARCHAR,
92322
92334
  SubstringFunction, false, nullptr, nullptr, SubstringPropagateStats));
92323
92335
  set.AddFunction(substr);
92324
92336
  substr.name = "substr";
@@ -94500,11 +94512,7 @@ static int64_t ParseInteger(vector<Value> &set) {
94500
94512
  //===--------------------------------------------------------------------===//
94501
94513
  static bool ParseBaseOption(BufferedCSVReaderOptions &options, string &loption, vector<Value> &set) {
94502
94514
  if (StringUtil::StartsWith(loption, "delim") || StringUtil::StartsWith(loption, "sep")) {
94503
- options.delimiter = ParseString(set);
94504
- options.has_delimiter = true;
94505
- if (options.delimiter.length() == 0) {
94506
- throw BinderException("DELIM or SEP must not be empty");
94507
- }
94515
+ options.SetDelimiter(ParseString(set));
94508
94516
  } else if (loption == "quote") {
94509
94517
  options.quote = ParseString(set);
94510
94518
  options.has_quote = true;
@@ -95789,8 +95797,7 @@ static unique_ptr<FunctionData> ReadCSVBind(ClientContext &context, vector<Value
95789
95797
  if (kv.first == "auto_detect") {
95790
95798
  options.auto_detect = kv.second.value_.boolean;
95791
95799
  } else if (kv.first == "sep" || kv.first == "delim") {
95792
- options.delimiter = kv.second.str_value;
95793
- options.has_delimiter = true;
95800
+ options.SetDelimiter(kv.second.str_value);
95794
95801
  } else if (kv.first == "header") {
95795
95802
  options.header = kv.second.value_.boolean;
95796
95803
  options.has_header = true;
@@ -212139,7 +212146,6 @@ unsigned char *unicode_to_utf8(pg_wchar c, unsigned char *utf8string);
212139
212146
 
212140
212147
  // max parse tree size approx 100 MB, should be enough
212141
212148
  #define PG_MALLOC_SIZE 10240
212142
- #define PG_MALLOC_LIMIT 1000
212143
212149
 
212144
212150
  namespace duckdb_libpgquery {
212145
212151
 
@@ -212151,7 +212157,8 @@ struct pg_parser_state_str {
212151
212157
 
212152
212158
  size_t malloc_pos;
212153
212159
  size_t malloc_ptr_idx;
212154
- char *malloc_ptrs[PG_MALLOC_LIMIT];
212160
+ char **malloc_ptrs;
212161
+ size_t malloc_ptr_size;
212155
212162
  };
212156
212163
 
212157
212164
  static __thread parser_state pg_parser_state;
@@ -212161,8 +212168,13 @@ __thread PGNode *duckdb_newNodeMacroHolder;
212161
212168
  #endif
212162
212169
 
212163
212170
  static void allocate_new(parser_state *state, size_t n) {
212164
- if (state->malloc_ptr_idx + 1 >= PG_MALLOC_LIMIT) {
212165
- throw std::runtime_error("Memory allocation failure");
212171
+ if (state->malloc_ptr_idx >= state->malloc_ptr_size) {
212172
+ size_t new_size = state->malloc_ptr_size * 2;
212173
+ auto new_malloc_ptrs = (char **) malloc(sizeof(char *) * new_size);
212174
+ memcpy(new_malloc_ptrs, state->malloc_ptrs, state->malloc_ptr_size * sizeof(char*));
212175
+ free(state->malloc_ptrs);
212176
+ state->malloc_ptr_size = new_size;
212177
+ state->malloc_ptrs = new_malloc_ptrs;
212166
212178
  }
212167
212179
  if (n < PG_MALLOC_SIZE) {
212168
212180
  n = PG_MALLOC_SIZE;
@@ -212193,6 +212205,8 @@ void pg_parser_init() {
212193
212205
  pg_parser_state.pg_err_code = PGUNDEFINED;
212194
212206
  pg_parser_state.pg_err_msg[0] = '\0';
212195
212207
 
212208
+ pg_parser_state.malloc_ptr_size = 4;
212209
+ pg_parser_state.malloc_ptrs = (char **) malloc(sizeof(char *) * pg_parser_state.malloc_ptr_size);
212196
212210
  pg_parser_state.malloc_ptr_idx = 0;
212197
212211
  allocate_new(&pg_parser_state, 1);
212198
212212
  }
@@ -212202,8 +212216,16 @@ void pg_parser_parse(const char *query, parse_result *res) {
212202
212216
  try {
212203
212217
  res->parse_tree = duckdb_libpgquery::raw_parser(query);
212204
212218
  res->success = pg_parser_state.pg_err_code == PGUNDEFINED;
212205
- } catch (...) {
212219
+ } catch (std::exception &ex) {
212206
212220
  res->success = false;
212221
+ // copy the error message of the exception
212222
+ auto error_message = ex.what();
212223
+ uint32_t pos = 0;
212224
+ while(pos < 1023 && error_message[pos]) {
212225
+ pg_parser_state.pg_err_msg[pos] = error_message[pos];
212226
+ pos++;
212227
+ }
212228
+ pg_parser_state.pg_err_msg[pos] = '\0';
212207
212229
  }
212208
212230
  res->error_message = pg_parser_state.pg_err_msg;
212209
212231
  res->error_location = pg_parser_state.pg_err_pos;
@@ -212217,6 +212239,7 @@ void pg_parser_cleanup() {
212217
212239
  pg_parser_state.malloc_ptrs[ptr_idx] = nullptr;
212218
212240
  }
212219
212241
  }
212242
+ free(pg_parser_state.malloc_ptrs);
212220
212243
  }
212221
212244
 
212222
212245
  int ereport(int code, ...) {
package/src/duckdb.hpp CHANGED
@@ -10,8 +10,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
10
10
 
11
11
  #pragma once
12
12
  #define DUCKDB_AMALGAMATION 1
13
- #define DUCKDB_SOURCE_ID "6926d0118"
14
- #define DUCKDB_VERSION "0.3.2-dev24"
13
+ #define DUCKDB_SOURCE_ID "275e368e7"
14
+ #define DUCKDB_VERSION "0.3.2-dev31"
15
15
  //===----------------------------------------------------------------------===//
16
16
  // DuckDB
17
17
  //