duckdb 0.7.2-dev3546.0 → 0.7.2-dev3710.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 (94) hide show
  1. package/package.json +1 -1
  2. package/src/database.cpp +1 -0
  3. package/src/duckdb/extension/json/buffered_json_reader.cpp +56 -17
  4. package/src/duckdb/extension/json/include/buffered_json_reader.hpp +56 -31
  5. package/src/duckdb/extension/json/include/json_common.hpp +5 -4
  6. package/src/duckdb/extension/json/include/json_executors.hpp +13 -18
  7. package/src/duckdb/extension/json/include/json_functions.hpp +3 -0
  8. package/src/duckdb/extension/json/include/json_scan.hpp +106 -153
  9. package/src/duckdb/extension/json/include/json_transform.hpp +2 -2
  10. package/src/duckdb/extension/json/json_common.cpp +1 -1
  11. package/src/duckdb/extension/json/json_functions/copy_json.cpp +94 -38
  12. package/src/duckdb/extension/json/json_functions/json_contains.cpp +7 -8
  13. package/src/duckdb/extension/json/json_functions/json_create.cpp +7 -7
  14. package/src/duckdb/extension/json/json_functions/json_merge_patch.cpp +4 -4
  15. package/src/duckdb/extension/json/json_functions/json_serialize_sql.cpp +4 -4
  16. package/src/duckdb/extension/json/json_functions/json_structure.cpp +7 -5
  17. package/src/duckdb/extension/json/json_functions/json_transform.cpp +11 -9
  18. package/src/duckdb/extension/json/json_functions/json_valid.cpp +1 -1
  19. package/src/duckdb/extension/json/json_functions/read_json.cpp +166 -169
  20. package/src/duckdb/extension/json/json_functions/read_json_objects.cpp +37 -16
  21. package/src/duckdb/extension/json/json_functions.cpp +11 -4
  22. package/src/duckdb/extension/json/json_scan.cpp +593 -374
  23. package/src/duckdb/extension/parquet/parquet-extension.cpp +5 -0
  24. package/src/duckdb/src/common/exception.cpp +17 -0
  25. package/src/duckdb/src/common/exception_format_value.cpp +14 -0
  26. package/src/duckdb/src/common/file_system.cpp +78 -36
  27. package/src/duckdb/src/common/local_file_system.cpp +5 -16
  28. package/src/duckdb/src/common/types.cpp +1 -1
  29. package/src/duckdb/src/core_functions/scalar/list/list_lambdas.cpp +1 -1
  30. package/src/duckdb/src/execution/operator/persistent/buffered_csv_reader.cpp +12 -6
  31. package/src/duckdb/src/execution/operator/persistent/csv_reader_options.cpp +10 -0
  32. package/src/duckdb/src/execution/operator/persistent/physical_export.cpp +2 -2
  33. package/src/duckdb/src/function/pragma/pragma_queries.cpp +6 -4
  34. package/src/duckdb/src/function/table/copy_csv.cpp +66 -12
  35. package/src/duckdb/src/function/table/read_csv.cpp +16 -3
  36. package/src/duckdb/src/function/table/version/pragma_version.cpp +8 -2
  37. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/column_dependency_manager.hpp +1 -1
  38. package/src/duckdb/src/include/duckdb/catalog/catalog_search_path.hpp +1 -1
  39. package/src/duckdb/src/include/duckdb/catalog/similar_catalog_entry.hpp +1 -1
  40. package/src/duckdb/src/include/duckdb/common/exception.hpp +3 -3
  41. package/src/duckdb/src/include/duckdb/common/exception_format_value.hpp +26 -0
  42. package/src/duckdb/src/include/duckdb/common/file_system.hpp +11 -0
  43. package/src/duckdb/src/include/duckdb/common/http_state.hpp +2 -1
  44. package/src/duckdb/src/include/duckdb/common/hugeint.hpp +6 -6
  45. package/src/duckdb/src/include/duckdb/common/limits.hpp +46 -46
  46. package/src/duckdb/src/include/duckdb/common/operator/cast_operators.hpp +8 -8
  47. package/src/duckdb/src/include/duckdb/common/operator/comparison_operators.hpp +6 -6
  48. package/src/duckdb/src/include/duckdb/common/operator/convert_to_string.hpp +1 -1
  49. package/src/duckdb/src/include/duckdb/common/operator/decimal_cast_operators.hpp +2 -4
  50. package/src/duckdb/src/include/duckdb/common/operator/string_cast.hpp +1 -1
  51. package/src/duckdb/src/include/duckdb/common/operator/subtract.hpp +1 -1
  52. package/src/duckdb/src/include/duckdb/common/preserved_error.hpp +1 -1
  53. package/src/duckdb/src/include/duckdb/common/re2_regex.hpp +1 -1
  54. package/src/duckdb/src/include/duckdb/common/string_util.hpp +25 -7
  55. package/src/duckdb/src/include/duckdb/common/types/chunk_collection.hpp +10 -10
  56. package/src/duckdb/src/include/duckdb/common/types/column/column_data_collection.hpp +12 -12
  57. package/src/duckdb/src/include/duckdb/common/types/column/column_data_collection_iterators.hpp +2 -2
  58. package/src/duckdb/src/include/duckdb/common/types/value.hpp +1 -1
  59. package/src/duckdb/src/include/duckdb/common/types.hpp +2 -2
  60. package/src/duckdb/src/include/duckdb/common/winapi.hpp +1 -1
  61. package/src/duckdb/src/include/duckdb/execution/expression_executor_state.hpp +1 -1
  62. package/src/duckdb/src/include/duckdb/execution/operator/persistent/csv_reader_options.hpp +8 -3
  63. package/src/duckdb/src/include/duckdb/function/aggregate_function.hpp +10 -14
  64. package/src/duckdb/src/include/duckdb/function/table_function.hpp +1 -1
  65. package/src/duckdb/src/include/duckdb/function/udf_function.hpp +56 -50
  66. package/src/duckdb/src/include/duckdb/main/appender.hpp +2 -2
  67. package/src/duckdb/src/include/duckdb/main/client_context.hpp +2 -2
  68. package/src/duckdb/src/include/duckdb/main/client_data.hpp +3 -1
  69. package/src/duckdb/src/include/duckdb/main/connection.hpp +8 -9
  70. package/src/duckdb/src/include/duckdb/main/extension_entries.hpp +1 -0
  71. package/src/duckdb/src/include/duckdb/main/query_result.hpp +3 -3
  72. package/src/duckdb/src/include/duckdb/main/relation.hpp +6 -7
  73. package/src/duckdb/src/include/duckdb/optimizer/optimizer_extension.hpp +1 -1
  74. package/src/duckdb/src/include/duckdb/parser/column_list.hpp +7 -7
  75. package/src/duckdb/src/include/duckdb/parser/expression/function_expression.hpp +1 -1
  76. package/src/duckdb/src/include/duckdb/parser/expression/operator_expression.hpp +2 -2
  77. package/src/duckdb/src/include/duckdb/parser/keyword_helper.hpp +5 -0
  78. package/src/duckdb/src/include/duckdb/parser/parser_extension.hpp +2 -2
  79. package/src/duckdb/src/include/duckdb/parser/sql_statement.hpp +1 -1
  80. package/src/duckdb/src/include/duckdb/parser/statement/select_statement.hpp +1 -1
  81. package/src/duckdb/src/include/duckdb/planner/operator_extension.hpp +2 -2
  82. package/src/duckdb/src/include/duckdb/storage/storage_extension.hpp +2 -2
  83. package/src/duckdb/src/main/db_instance_cache.cpp +5 -3
  84. package/src/duckdb/src/main/extension/extension_install.cpp +22 -18
  85. package/src/duckdb/src/parser/expression/collate_expression.cpp +1 -1
  86. package/src/duckdb/src/parser/keyword_helper.cpp +11 -1
  87. package/src/duckdb/src/parser/query_node/select_node.cpp +1 -1
  88. package/src/duckdb/src/parser/statement/copy_statement.cpp +2 -2
  89. package/src/duckdb/src/parser/tableref.cpp +1 -1
  90. package/src/duckdb/src/planner/binder/statement/bind_copy.cpp +9 -4
  91. package/src/duckdb/src/planner/binder/tableref/bind_basetableref.cpp +1 -1
  92. package/src/duckdb/src/storage/single_file_block_manager.cpp +0 -4
  93. package/src/duckdb/src/storage/storage_manager.cpp +3 -0
  94. package/src/duckdb/third_party/libpg_query/src_backend_parser_gram.cpp +5735 -5773
@@ -494,9 +494,9 @@ static void CreateValues(const StructNames &names, yyjson_mut_doc *doc, yyjson_m
494
494
 
495
495
  static void ObjectFunction(DataChunk &args, ExpressionState &state, Vector &result) {
496
496
  auto &func_expr = state.expr.Cast<BoundFunctionExpression>();
497
- const auto &info = (JSONCreateFunctionData &)*func_expr.bind_info;
497
+ const auto &info = func_expr.bind_info->Cast<JSONCreateFunctionData>();
498
498
  auto &lstate = JSONFunctionLocalState::ResetAndGet(state);
499
- auto alc = lstate.json_allocator.GetYYJSONAllocator();
499
+ auto alc = lstate.json_allocator.GetYYAlc();
500
500
 
501
501
  // Initialize values
502
502
  const idx_t count = args.size();
@@ -526,9 +526,9 @@ static void ObjectFunction(DataChunk &args, ExpressionState &state, Vector &resu
526
526
 
527
527
  static void ArrayFunction(DataChunk &args, ExpressionState &state, Vector &result) {
528
528
  auto &func_expr = state.expr.Cast<BoundFunctionExpression>();
529
- const auto &info = (JSONCreateFunctionData &)*func_expr.bind_info;
529
+ const auto &info = func_expr.bind_info->Cast<JSONCreateFunctionData>();
530
530
  auto &lstate = JSONFunctionLocalState::ResetAndGet(state);
531
- auto alc = lstate.json_allocator.GetYYJSONAllocator();
531
+ auto alc = lstate.json_allocator.GetYYAlc();
532
532
 
533
533
  // Initialize arrays
534
534
  const idx_t count = args.size();
@@ -585,9 +585,9 @@ static void ToJSONFunctionInternal(const StructNames &names, Vector &input, cons
585
585
 
586
586
  static void ToJSONFunction(DataChunk &args, ExpressionState &state, Vector &result) {
587
587
  auto &func_expr = state.expr.Cast<BoundFunctionExpression>();
588
- const auto &info = (JSONCreateFunctionData &)*func_expr.bind_info;
588
+ const auto &info = func_expr.bind_info->Cast<JSONCreateFunctionData>();
589
589
  auto &lstate = JSONFunctionLocalState::ResetAndGet(state);
590
- auto alc = lstate.json_allocator.GetYYJSONAllocator();
590
+ auto alc = lstate.json_allocator.GetYYAlc();
591
591
 
592
592
  ToJSONFunctionInternal(info.const_struct_names, args.data[0], args.size(), result, alc);
593
593
  }
@@ -649,7 +649,7 @@ public:
649
649
  static bool AnyToJSONCast(Vector &source, Vector &result, idx_t count, CastParameters &parameters) {
650
650
  auto &lstate = parameters.local_state->Cast<JSONFunctionLocalState>();
651
651
  lstate.json_allocator.Reset();
652
- auto alc = lstate.json_allocator.GetYYJSONAllocator();
652
+ auto alc = lstate.json_allocator.GetYYAlc();
653
653
  const auto &names = parameters.cast_data->Cast<NestedToJSONCastData>().const_struct_names;
654
654
 
655
655
  ToJSONFunctionInternal(names, source, count, result, alc);
@@ -3,8 +3,8 @@
3
3
 
4
4
  namespace duckdb {
5
5
 
6
- static duckdb::unique_ptr<FunctionData> JSONMergePatchBind(ClientContext &context, ScalarFunction &bound_function,
7
- vector<duckdb::unique_ptr<Expression>> &arguments) {
6
+ static unique_ptr<FunctionData> JSONMergePatchBind(ClientContext &context, ScalarFunction &bound_function,
7
+ vector<unique_ptr<Expression>> &arguments) {
8
8
  if (arguments.size() < 2) {
9
9
  throw InvalidInputException("json_merge_patch requires at least two parameters");
10
10
  }
@@ -53,9 +53,9 @@ static inline void ReadObjects(yyjson_mut_doc *doc, Vector &input, yyjson_mut_va
53
53
  //! Follows MySQL behaviour
54
54
  static void MergePatchFunction(DataChunk &args, ExpressionState &state, Vector &result) {
55
55
  auto &lstate = JSONFunctionLocalState::ResetAndGet(state);
56
- auto alc = lstate.json_allocator.GetYYJSONAllocator();
56
+ auto alc = lstate.json_allocator.GetYYAlc();
57
57
 
58
- auto doc = JSONCommon::CreateDocument(lstate.json_allocator.GetYYJSONAllocator());
58
+ auto doc = JSONCommon::CreateDocument(lstate.json_allocator.GetYYAlc());
59
59
  const auto count = args.size();
60
60
 
61
61
  // Read the first json arg
@@ -76,7 +76,7 @@ static unique_ptr<FunctionData> JsonSerializeBind(ClientContext &context, Scalar
76
76
 
77
77
  static void JsonSerializeFunction(DataChunk &args, ExpressionState &state, Vector &result) {
78
78
  auto &local_state = JSONFunctionLocalState::ResetAndGet(state);
79
- auto alc = local_state.json_allocator.GetYYJSONAllocator();
79
+ auto alc = local_state.json_allocator.GetYYAlc();
80
80
  auto &inputs = args.data[0];
81
81
 
82
82
  auto &func_expr = state.expr.Cast<BoundFunctionExpression>();
@@ -193,7 +193,7 @@ static unique_ptr<SelectStatement> DeserializeSelectStatement(string_t input, yy
193
193
  static void JsonDeserializeFunction(DataChunk &args, ExpressionState &state, Vector &result) {
194
194
 
195
195
  auto &local_state = JSONFunctionLocalState::ResetAndGet(state);
196
- auto alc = local_state.json_allocator.GetYYJSONAllocator();
196
+ auto alc = local_state.json_allocator.GetYYAlc();
197
197
  auto &inputs = args.data[0];
198
198
 
199
199
  UnaryExecutor::Execute<string_t, string_t>(inputs, result, args.size(), [&](string_t input) {
@@ -214,7 +214,7 @@ ScalarFunctionSet JSONFunctions::GetDeserializeSqlFunction() {
214
214
  //----------------------------------------------------------------------
215
215
  static string ExecuteJsonSerializedSqlPragmaFunction(ClientContext &context, const FunctionParameters &parameters) {
216
216
  JSONFunctionLocalState local_state(context);
217
- auto alc = local_state.json_allocator.GetYYJSONAllocator();
217
+ auto alc = local_state.json_allocator.GetYYAlc();
218
218
 
219
219
  auto input = parameters.values[0].GetValueUnsafe<string_t>();
220
220
  auto stmt = DeserializeSelectStatement(input, alc);
@@ -239,7 +239,7 @@ struct ExecuteSqlTableFunction {
239
239
  static unique_ptr<FunctionData> Bind(ClientContext &context, TableFunctionBindInput &input,
240
240
  vector<LogicalType> &return_types, vector<string> &names) {
241
241
  JSONFunctionLocalState local_state(context);
242
- auto alc = local_state.json_allocator.GetYYJSONAllocator();
242
+ auto alc = local_state.json_allocator.GetYYAlc();
243
243
 
244
244
  auto result = make_uniq<BindData>();
245
245
 
@@ -1,9 +1,9 @@
1
1
  #include "json_structure.hpp"
2
2
 
3
+ #include "duckdb/common/enum_util.hpp"
3
4
  #include "json_executors.hpp"
4
5
  #include "json_scan.hpp"
5
6
  #include "json_transform.hpp"
6
- #include "duckdb/common/enum_util.hpp"
7
7
 
8
8
  namespace duckdb {
9
9
 
@@ -93,7 +93,7 @@ bool JSONStructureNode::ContainsVarchar() const {
93
93
  }
94
94
 
95
95
  void JSONStructureNode::InitializeCandidateTypes(const idx_t max_depth, idx_t depth) {
96
- if (depth > max_depth) {
96
+ if (depth >= max_depth) {
97
97
  return;
98
98
  }
99
99
  if (descriptions.size() != 1) {
@@ -521,11 +521,11 @@ static LogicalType StructureToTypeString(const JSONStructureNode &node) {
521
521
 
522
522
  LogicalType JSONStructure::StructureToType(ClientContext &context, const JSONStructureNode &node, const idx_t max_depth,
523
523
  idx_t depth) {
524
- if (depth > max_depth) {
524
+ if (depth >= max_depth) {
525
525
  return JSONCommon::JSONType();
526
526
  }
527
527
  if (node.descriptions.empty()) {
528
- return LogicalTypeId::SQLNULL;
528
+ return JSONCommon::JSONType();
529
529
  }
530
530
  if (node.descriptions.size() != 1) { // Inconsistent types, so we resort to JSON
531
531
  return JSONCommon::JSONType();
@@ -540,7 +540,9 @@ LogicalType JSONStructure::StructureToType(ClientContext &context, const JSONStr
540
540
  case LogicalTypeId::VARCHAR:
541
541
  return StructureToTypeString(node);
542
542
  case LogicalTypeId::SQLNULL:
543
- return LogicalTypeId::INTEGER;
543
+ return JSONCommon::JSONType();
544
+ case LogicalTypeId::UBIGINT:
545
+ return LogicalTypeId::BIGINT; // We prefer not to return UBIGINT in our type auto-detection
544
546
  default:
545
547
  return desc.type;
546
548
  }
@@ -20,7 +20,7 @@ JSONTransformOptions::JSONTransformOptions(bool strict_cast_p, bool error_duplic
20
20
  error_unknown_key(error_unkown_key_p) {
21
21
  }
22
22
 
23
- void JSONTransformOptions::Serialize(FieldWriter &writer) {
23
+ void JSONTransformOptions::Serialize(FieldWriter &writer) const {
24
24
  writer.WriteField(strict_cast);
25
25
  writer.WriteField(error_duplicate_key);
26
26
  writer.WriteField(error_missing_key);
@@ -98,8 +98,8 @@ static unique_ptr<FunctionData> JSONTransformBind(ClientContext &context, Scalar
98
98
  auto structure_string = structure_val.GetValueUnsafe<string_t>();
99
99
  JSONAllocator json_allocator(Allocator::DefaultAllocator());
100
100
  yyjson_read_err err;
101
- auto doc = JSONCommon::ReadDocumentUnsafe(structure_string, JSONCommon::READ_FLAG,
102
- json_allocator.GetYYJSONAllocator(), &err);
101
+ auto doc =
102
+ JSONCommon::ReadDocumentUnsafe(structure_string, JSONCommon::READ_FLAG, json_allocator.GetYYAlc(), &err);
103
103
  if (err.code != YYJSON_READ_SUCCESS) {
104
104
  JSONCommon::ThrowParseError(structure_string.GetData(), structure_string.GetSize(), err);
105
105
  }
@@ -615,7 +615,7 @@ static bool TransformObjectToMap(yyjson_val *objects[], yyjson_alc *alc, Vector
615
615
  ListVector::SetListSize(result, list_size);
616
616
 
617
617
  auto list_entries = FlatVector::GetData<list_entry_t>(result);
618
- auto list_validity = FlatVector::Validity(result);
618
+ auto &list_validity = FlatVector::Validity(result);
619
619
 
620
620
  auto keys = (yyjson_val **)alc->malloc(alc->ctx, sizeof(yyjson_val *) * list_size);
621
621
  auto vals = (yyjson_val **)alc->malloc(alc->ctx, sizeof(yyjson_val *) * list_size);
@@ -654,11 +654,12 @@ static bool TransformObjectToMap(yyjson_val *objects[], yyjson_alc *alc, Vector
654
654
  list_offset++;
655
655
  }
656
656
  }
657
+ D_ASSERT(list_offset == list_size);
657
658
 
658
659
  // Transform keys
659
660
  if (!JSONTransform::Transform(keys, alc, MapVector::GetKeys(result), list_size, options)) {
660
661
  throw ConversionException(
661
- StringUtil::Format(options.error_message, ". Cannot default to NULL, because map keys cannot be NULL"));
662
+ StringUtil::Format(options.error_message + ". Cannot default to NULL, because map keys cannot be NULL"));
662
663
  }
663
664
 
664
665
  // Transform values
@@ -678,7 +679,7 @@ bool TransformToJSON(yyjson_val *vals[], yyjson_alc *alc, Vector &result, const
678
679
  auto &validity = FlatVector::Validity(result);
679
680
  for (idx_t i = 0; i < count; i++) {
680
681
  const auto &val = vals[i];
681
- if (!val) {
682
+ if (!val || unsafe_yyjson_is_null(val)) {
682
683
  validity.SetInvalid(i);
683
684
  } else {
684
685
  data[i] = JSONCommon::WriteVal(val, alc);
@@ -691,7 +692,8 @@ bool TransformToJSON(yyjson_val *vals[], yyjson_alc *alc, Vector &result, const
691
692
  bool JSONTransform::Transform(yyjson_val *vals[], yyjson_alc *alc, Vector &result, const idx_t count,
692
693
  JSONTransformOptions &options) {
693
694
  auto result_type = result.GetType();
694
- if ((result_type == LogicalTypeId::TIMESTAMP || result_type == LogicalTypeId::DATE) && options.date_format_map) {
695
+ if ((result_type == LogicalTypeId::TIMESTAMP || result_type == LogicalTypeId::DATE) && options.date_format_map &&
696
+ options.date_format_map->HasFormats(result_type.id())) {
695
697
  // Auto-detected date/timestamp format during sampling
696
698
  return TransformFromStringWithFormat(vals, result, count, options);
697
699
  }
@@ -803,7 +805,7 @@ static bool TransformFunctionInternal(Vector &input, const idx_t count, Vector &
803
805
  template <bool strict>
804
806
  static void TransformFunction(DataChunk &args, ExpressionState &state, Vector &result) {
805
807
  auto &lstate = JSONFunctionLocalState::ResetAndGet(state);
806
- auto alc = lstate.json_allocator.GetYYJSONAllocator();
808
+ auto alc = lstate.json_allocator.GetYYAlc();
807
809
 
808
810
  JSONTransformOptions options(strict, strict, strict, false);
809
811
  if (!TransformFunctionInternal(args.data[0], args.size(), result, alc, options)) {
@@ -838,7 +840,7 @@ ScalarFunctionSet JSONFunctions::GetTransformStrictFunction() {
838
840
  static bool JSONToAnyCast(Vector &source, Vector &result, idx_t count, CastParameters &parameters) {
839
841
  auto &lstate = parameters.local_state->Cast<JSONFunctionLocalState>();
840
842
  lstate.json_allocator.Reset();
841
- auto alc = lstate.json_allocator.GetYYJSONAllocator();
843
+ auto alc = lstate.json_allocator.GetYYAlc();
842
844
 
843
845
  JSONTransformOptions options(true, true, true, true);
844
846
  options.delay_error = true;
@@ -4,7 +4,7 @@ namespace duckdb {
4
4
 
5
5
  static void ValidFunction(DataChunk &args, ExpressionState &state, Vector &result) {
6
6
  auto &lstate = JSONFunctionLocalState::ResetAndGet(state);
7
- auto alc = lstate.json_allocator.GetYYJSONAllocator();
7
+ auto alc = lstate.json_allocator.GetYYAlc();
8
8
  auto &inputs = args.data[0];
9
9
  UnaryExecutor::Execute<string_t, bool>(inputs, result, args.size(), [&](string_t input) {
10
10
  return JSONCommon::ReadDocumentUnsafe(input, JSONCommon::READ_FLAG, alc);