duckdb 0.8.1-dev96.0 → 0.8.2-dev1.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 (243) hide show
  1. package/binding.gyp +8 -8
  2. package/package.json +3 -1
  3. package/src/duckdb/extension/icu/icu-datepart.cpp +1 -1
  4. package/src/duckdb/extension/icu/icu-extension.cpp +1 -1
  5. package/src/duckdb/extension/icu/icu-makedate.cpp +5 -4
  6. package/src/duckdb/extension/icu/icu-strptime.cpp +1 -1
  7. package/src/duckdb/extension/icu/third_party/icu/i18n/nfsubs.cpp +0 -2
  8. package/src/duckdb/extension/json/buffered_json_reader.cpp +23 -14
  9. package/src/duckdb/extension/json/include/buffered_json_reader.hpp +6 -6
  10. package/src/duckdb/extension/json/include/json_common.hpp +12 -2
  11. package/src/duckdb/extension/json/include/json_scan.hpp +5 -2
  12. package/src/duckdb/extension/json/json_functions/json_contains.cpp +5 -0
  13. package/src/duckdb/extension/json/json_functions/json_create.cpp +10 -10
  14. package/src/duckdb/extension/json/json_functions/json_merge_patch.cpp +2 -2
  15. package/src/duckdb/extension/json/json_functions/json_serialize_sql.cpp +2 -2
  16. package/src/duckdb/extension/json/json_functions/json_structure.cpp +5 -3
  17. package/src/duckdb/extension/json/json_functions/json_transform.cpp +11 -11
  18. package/src/duckdb/extension/json/json_functions/read_json.cpp +2 -1
  19. package/src/duckdb/extension/json/json_functions.cpp +6 -3
  20. package/src/duckdb/extension/json/json_scan.cpp +43 -27
  21. package/src/duckdb/extension/parquet/column_reader.cpp +5 -1
  22. package/src/duckdb/extension/parquet/include/decode_utils.hpp +6 -0
  23. package/src/duckdb/extension/parquet/parquet-extension.cpp +26 -1
  24. package/src/duckdb/src/catalog/catalog.cpp +5 -17
  25. package/src/duckdb/src/catalog/catalog_entry/duck_table_entry.cpp +7 -1
  26. package/src/duckdb/src/catalog/catalog_entry/table_catalog_entry.cpp +121 -0
  27. package/src/duckdb/src/catalog/catalog_search_path.cpp +49 -12
  28. package/src/duckdb/src/catalog/default/default_types.cpp +9 -84
  29. package/src/duckdb/src/common/adbc/adbc.cpp +118 -12
  30. package/src/duckdb/src/common/adbc/driver_manager.cpp +0 -20
  31. package/src/duckdb/src/common/arrow/arrow_converter.cpp +11 -12
  32. package/src/duckdb/src/common/arrow/arrow_wrapper.cpp +4 -3
  33. package/src/duckdb/src/common/exception.cpp +4 -1
  34. package/src/duckdb/src/common/exception_format_value.cpp +24 -15
  35. package/src/duckdb/src/common/multi_file_reader.cpp +3 -0
  36. package/src/duckdb/src/common/random_engine.cpp +1 -1
  37. package/src/duckdb/src/common/types/row/row_data_collection_scanner.cpp +5 -4
  38. package/src/duckdb/src/common/types/row/tuple_data_scatter_gather.cpp +44 -7
  39. package/src/duckdb/src/common/types/time.cpp +2 -8
  40. package/src/duckdb/src/common/types/timestamp.cpp +37 -1
  41. package/src/duckdb/src/common/types/value.cpp +1 -0
  42. package/src/duckdb/src/common/types.cpp +4 -0
  43. package/src/duckdb/src/core_functions/aggregate/algebraic/avg.cpp +30 -33
  44. package/src/duckdb/src/core_functions/aggregate/algebraic/covar.cpp +0 -4
  45. package/src/duckdb/src/core_functions/aggregate/distributive/approx_count.cpp +30 -33
  46. package/src/duckdb/src/core_functions/aggregate/distributive/arg_min_max.cpp +52 -65
  47. package/src/duckdb/src/core_functions/aggregate/distributive/bitagg.cpp +48 -48
  48. package/src/duckdb/src/core_functions/aggregate/distributive/bitstring_agg.cpp +39 -40
  49. package/src/duckdb/src/core_functions/aggregate/distributive/bool.cpp +32 -32
  50. package/src/duckdb/src/core_functions/aggregate/distributive/entropy.cpp +34 -34
  51. package/src/duckdb/src/core_functions/aggregate/distributive/kurtosis.cpp +30 -31
  52. package/src/duckdb/src/core_functions/aggregate/distributive/minmax.cpp +88 -100
  53. package/src/duckdb/src/core_functions/aggregate/distributive/product.cpp +17 -17
  54. package/src/duckdb/src/core_functions/aggregate/distributive/skew.cpp +25 -27
  55. package/src/duckdb/src/core_functions/aggregate/distributive/string_agg.cpp +37 -38
  56. package/src/duckdb/src/core_functions/aggregate/distributive/sum.cpp +22 -22
  57. package/src/duckdb/src/core_functions/aggregate/holistic/approximate_quantile.cpp +44 -80
  58. package/src/duckdb/src/core_functions/aggregate/holistic/mode.cpp +49 -51
  59. package/src/duckdb/src/core_functions/aggregate/holistic/quantile.cpp +104 -122
  60. package/src/duckdb/src/core_functions/aggregate/holistic/reservoir_quantile.cpp +57 -93
  61. package/src/duckdb/src/core_functions/aggregate/nested/histogram.cpp +22 -23
  62. package/src/duckdb/src/core_functions/aggregate/nested/list.cpp +18 -19
  63. package/src/duckdb/src/core_functions/aggregate/regression/regr_avg.cpp +16 -18
  64. package/src/duckdb/src/core_functions/aggregate/regression/regr_intercept.cpp +22 -25
  65. package/src/duckdb/src/core_functions/aggregate/regression/regr_r2.cpp +19 -24
  66. package/src/duckdb/src/core_functions/aggregate/regression/regr_sxx_syy.cpp +18 -23
  67. package/src/duckdb/src/core_functions/aggregate/regression/regr_sxy.cpp +14 -18
  68. package/src/duckdb/src/core_functions/function_list.cpp +1 -0
  69. package/src/duckdb/src/core_functions/scalar/date/date_part.cpp +1 -1
  70. package/src/duckdb/src/core_functions/scalar/date/make_date.cpp +3 -0
  71. package/src/duckdb/src/core_functions/scalar/generic/system_functions.cpp +14 -0
  72. package/src/duckdb/src/core_functions/scalar/list/array_slice.cpp +1 -1
  73. package/src/duckdb/src/core_functions/scalar/list/list_aggregates.cpp +23 -6
  74. package/src/duckdb/src/core_functions/scalar/list/list_lambdas.cpp +1 -2
  75. package/src/duckdb/src/core_functions/scalar/map/map_concat.cpp +3 -0
  76. package/src/duckdb/src/core_functions/scalar/math/numeric.cpp +3 -3
  77. package/src/duckdb/src/execution/index/art/art.cpp +80 -7
  78. package/src/duckdb/src/execution/index/art/fixed_size_allocator.cpp +20 -1
  79. package/src/duckdb/src/execution/index/art/leaf.cpp +11 -11
  80. package/src/duckdb/src/execution/index/art/leaf_segment.cpp +10 -0
  81. package/src/duckdb/src/execution/index/art/node.cpp +48 -35
  82. package/src/duckdb/src/execution/index/art/node16.cpp +3 -0
  83. package/src/duckdb/src/execution/index/art/node256.cpp +1 -0
  84. package/src/duckdb/src/execution/index/art/node4.cpp +3 -0
  85. package/src/duckdb/src/execution/index/art/node48.cpp +2 -0
  86. package/src/duckdb/src/execution/index/art/prefix.cpp +2 -0
  87. package/src/duckdb/src/execution/join_hashtable.cpp +2 -0
  88. package/src/duckdb/src/execution/operator/aggregate/physical_window.cpp +26 -9
  89. package/src/duckdb/src/execution/operator/helper/physical_reset.cpp +5 -2
  90. package/src/duckdb/src/execution/operator/helper/physical_set.cpp +5 -1
  91. package/src/duckdb/src/execution/operator/join/physical_iejoin.cpp +3 -6
  92. package/src/duckdb/src/execution/operator/projection/physical_tableinout_function.cpp +1 -0
  93. package/src/duckdb/src/execution/operator/projection/physical_unnest.cpp +8 -3
  94. package/src/duckdb/src/execution/operator/schema/physical_attach.cpp +0 -1
  95. package/src/duckdb/src/execution/operator/schema/physical_create_index.cpp +29 -3
  96. package/src/duckdb/src/execution/reservoir_sample.cpp +18 -4
  97. package/src/duckdb/src/function/aggregate/distributive/count.cpp +159 -21
  98. package/src/duckdb/src/function/aggregate/distributive/first.cpp +67 -74
  99. package/src/duckdb/src/function/aggregate/sorted_aggregate_function.cpp +7 -7
  100. package/src/duckdb/src/function/cast/list_casts.cpp +2 -4
  101. package/src/duckdb/src/function/pragma/pragma_queries.cpp +33 -23
  102. package/src/duckdb/src/function/scalar/list/list_extract.cpp +1 -1
  103. package/src/duckdb/src/function/scalar/operators/arithmetic.cpp +1 -1
  104. package/src/duckdb/src/function/scalar/string/regexp/regexp_util.cpp +6 -2
  105. package/src/duckdb/src/function/scalar/system/aggregate_export.cpp +2 -2
  106. package/src/duckdb/src/function/table/arrow.cpp +2 -2
  107. package/src/duckdb/src/function/table/checkpoint.cpp +3 -0
  108. package/src/duckdb/src/function/table/read_csv.cpp +15 -17
  109. package/src/duckdb/src/function/table/repeat.cpp +3 -0
  110. package/src/duckdb/src/function/table/repeat_row.cpp +8 -1
  111. package/src/duckdb/src/function/table/system/pragma_storage_info.cpp +4 -4
  112. package/src/duckdb/src/function/table/system/test_vector_types.cpp +81 -25
  113. package/src/duckdb/src/function/table/table_scan.cpp +2 -2
  114. package/src/duckdb/src/function/table/version/pragma_version.cpp +2 -2
  115. package/src/duckdb/src/include/duckdb/catalog/catalog.hpp +0 -3
  116. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/duck_table_entry.hpp +2 -0
  117. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/table_catalog_entry.hpp +11 -1
  118. package/src/duckdb/src/include/duckdb/catalog/catalog_search_path.hpp +8 -2
  119. package/src/duckdb/src/include/duckdb/catalog/default/builtin_types/types.hpp +97 -0
  120. package/src/duckdb/src/include/duckdb/common/arrow/arrow_appender.hpp +1 -1
  121. package/src/duckdb/src/include/duckdb/common/arrow/arrow_converter.hpp +2 -3
  122. package/src/duckdb/src/include/duckdb/common/arrow/arrow_options.hpp +8 -1
  123. package/src/duckdb/src/include/duckdb/common/arrow/result_arrow_wrapper.hpp +0 -1
  124. package/src/duckdb/src/include/duckdb/common/bit_utils.hpp +16 -22
  125. package/src/duckdb/src/include/duckdb/common/exception.hpp +3 -0
  126. package/src/duckdb/src/include/duckdb/common/types/time.hpp +2 -0
  127. package/src/duckdb/src/include/duckdb/common/types/timestamp.hpp +4 -14
  128. package/src/duckdb/src/include/duckdb/common/vector_operations/aggregate_executor.hpp +92 -57
  129. package/src/duckdb/src/include/duckdb/core_functions/aggregate/algebraic/corr.hpp +20 -24
  130. package/src/duckdb/src/include/duckdb/core_functions/aggregate/algebraic/covar.hpp +36 -39
  131. package/src/duckdb/src/include/duckdb/core_functions/aggregate/algebraic/stddev.hpp +57 -53
  132. package/src/duckdb/src/include/duckdb/core_functions/aggregate/regression/regr_count.hpp +8 -9
  133. package/src/duckdb/src/include/duckdb/core_functions/aggregate/regression/regr_slope.hpp +16 -18
  134. package/src/duckdb/src/include/duckdb/core_functions/aggregate/sum_helpers.hpp +7 -8
  135. package/src/duckdb/src/include/duckdb/core_functions/scalar/generic_functions.hpp +9 -0
  136. package/src/duckdb/src/include/duckdb/core_functions/scalar/map_functions.hpp +2 -6
  137. package/src/duckdb/src/include/duckdb/core_functions/scalar/string_functions.hpp +16 -36
  138. package/src/duckdb/src/include/duckdb/execution/index/art/art.hpp +10 -4
  139. package/src/duckdb/src/include/duckdb/execution/index/art/fixed_size_allocator.hpp +3 -0
  140. package/src/duckdb/src/include/duckdb/execution/index/art/leaf.hpp +1 -1
  141. package/src/duckdb/src/include/duckdb/execution/index/art/leaf_segment.hpp +2 -0
  142. package/src/duckdb/src/include/duckdb/execution/index/art/node.hpp +13 -3
  143. package/src/duckdb/src/include/duckdb/execution/index/art/node48.hpp +1 -0
  144. package/src/duckdb/src/include/duckdb/function/aggregate_function.hpp +9 -30
  145. package/src/duckdb/src/include/duckdb/function/aggregate_state.hpp +95 -0
  146. package/src/duckdb/src/include/duckdb/function/function_serialization.hpp +4 -2
  147. package/src/duckdb/src/include/duckdb/function/scalar/nested_functions.hpp +1 -1
  148. package/src/duckdb/src/include/duckdb/function/scalar_function.hpp +2 -1
  149. package/src/duckdb/src/include/duckdb/function/table_function.hpp +3 -2
  150. package/src/duckdb/src/include/duckdb/main/attached_database.hpp +4 -1
  151. package/src/duckdb/src/include/duckdb/main/capi/capi_internal.hpp +3 -1
  152. package/src/duckdb/src/include/duckdb/main/config.hpp +5 -0
  153. package/src/duckdb/src/include/duckdb/main/database_manager.hpp +1 -0
  154. package/src/duckdb/src/include/duckdb/main/extension_entries.hpp +142 -136
  155. package/src/duckdb/src/include/duckdb/main/query_result.hpp +6 -0
  156. package/src/duckdb/src/include/duckdb/main/settings.hpp +19 -0
  157. package/src/duckdb/src/include/duckdb/optimizer/unnest_rewriter.hpp +4 -0
  158. package/src/duckdb/src/include/duckdb/parallel/meta_pipeline.hpp +12 -3
  159. package/src/duckdb/src/include/duckdb/parser/parser.hpp +2 -0
  160. package/src/duckdb/src/include/duckdb/parser/tableref/emptytableref.hpp +1 -1
  161. package/src/duckdb/src/include/duckdb/parser/tableref/pivotref.hpp +2 -2
  162. package/src/duckdb/src/include/duckdb/parser/transformer.hpp +0 -2
  163. package/src/duckdb/src/include/duckdb/planner/bind_context.hpp +1 -1
  164. package/src/duckdb/src/include/duckdb/planner/bound_result_modifier.hpp +3 -0
  165. package/src/duckdb/src/include/duckdb/planner/expression_binder.hpp +1 -1
  166. package/src/duckdb/src/include/duckdb/planner/logical_operator.hpp +5 -0
  167. package/src/duckdb/src/include/duckdb/planner/operator/logical_copy_to_file.hpp +6 -2
  168. package/src/duckdb/src/include/duckdb/planner/operator/logical_execute.hpp +4 -0
  169. package/src/duckdb/src/include/duckdb/planner/operator/logical_explain.hpp +5 -1
  170. package/src/duckdb/src/include/duckdb/planner/operator/logical_get.hpp +5 -1
  171. package/src/duckdb/src/include/duckdb/planner/operator/logical_pragma.hpp +6 -2
  172. package/src/duckdb/src/include/duckdb/planner/operator/logical_prepare.hpp +4 -0
  173. package/src/duckdb/src/include/duckdb/storage/compression/chimp/algorithm/byte_reader.hpp +4 -0
  174. package/src/duckdb/src/include/duckdb/storage/data_table.hpp +1 -1
  175. package/src/duckdb/src/include/duckdb/storage/in_memory_block_manager.hpp +13 -13
  176. package/src/duckdb/src/include/duckdb/storage/index.hpp +4 -2
  177. package/src/duckdb/src/include/duckdb/storage/storage_extension.hpp +0 -6
  178. package/src/duckdb/src/include/duckdb/storage/table/column_data.hpp +1 -1
  179. package/src/duckdb/src/include/duckdb/storage/table/list_column_data.hpp +2 -1
  180. package/src/duckdb/src/include/duckdb/storage/table/row_group.hpp +2 -2
  181. package/src/duckdb/src/include/duckdb/storage/table/row_group_collection.hpp +2 -1
  182. package/src/duckdb/src/include/duckdb/storage/table/standard_column_data.hpp +2 -1
  183. package/src/duckdb/src/include/duckdb/storage/table/struct_column_data.hpp +2 -1
  184. package/src/duckdb/src/include/duckdb/storage/table_storage_info.hpp +0 -2
  185. package/src/duckdb/src/main/attached_database.cpp +8 -0
  186. package/src/duckdb/src/main/capi/arrow-c.cpp +4 -4
  187. package/src/duckdb/src/main/capi/config-c.cpp +2 -5
  188. package/src/duckdb/src/main/client_context.cpp +4 -3
  189. package/src/duckdb/src/main/config.cpp +2 -0
  190. package/src/duckdb/src/main/database.cpp +1 -0
  191. package/src/duckdb/src/main/database_manager.cpp +21 -0
  192. package/src/duckdb/src/main/query_result.cpp +6 -2
  193. package/src/duckdb/src/main/settings/settings.cpp +41 -6
  194. package/src/duckdb/src/optimizer/unnest_rewriter.cpp +27 -16
  195. package/src/duckdb/src/parallel/executor.cpp +38 -14
  196. package/src/duckdb/src/parallel/meta_pipeline.cpp +17 -3
  197. package/src/duckdb/src/parser/column_definition.cpp +5 -8
  198. package/src/duckdb/src/parser/parsed_data/create_info.cpp +0 -3
  199. package/src/duckdb/src/parser/parser.cpp +95 -35
  200. package/src/duckdb/src/parser/transform/expression/transform_function.cpp +1 -0
  201. package/src/duckdb/src/parser/transform/expression/transform_operator.cpp +3 -0
  202. package/src/duckdb/src/parser/transform/helpers/nodetype_to_string.cpp +0 -2
  203. package/src/duckdb/src/parser/transform/statement/transform_drop.cpp +0 -3
  204. package/src/duckdb/src/parser/transform/tableref/transform_pivot.cpp +3 -0
  205. package/src/duckdb/src/parser/transformer.cpp +0 -2
  206. package/src/duckdb/src/planner/bind_context.cpp +3 -4
  207. package/src/duckdb/src/planner/binder/expression/bind_function_expression.cpp +0 -2
  208. package/src/duckdb/src/planner/binder/expression/bind_positional_reference_expression.cpp +8 -3
  209. package/src/duckdb/src/planner/binder/query_node/bind_select_node.cpp +31 -15
  210. package/src/duckdb/src/planner/binder/statement/bind_create.cpp +0 -27
  211. package/src/duckdb/src/planner/binder/statement/bind_create_table.cpp +18 -1
  212. package/src/duckdb/src/planner/binder/statement/bind_drop.cpp +0 -25
  213. package/src/duckdb/src/planner/binder/statement/bind_update.cpp +2 -114
  214. package/src/duckdb/src/planner/binder/tableref/bind_pivot.cpp +6 -1
  215. package/src/duckdb/src/planner/binder/tableref/bind_table_function.cpp +5 -0
  216. package/src/duckdb/src/planner/bound_result_modifier.cpp +14 -0
  217. package/src/duckdb/src/planner/expression/bound_aggregate_expression.cpp +6 -5
  218. package/src/duckdb/src/planner/expression/bound_default_expression.cpp +7 -1
  219. package/src/duckdb/src/planner/expression.cpp +3 -0
  220. package/src/duckdb/src/planner/expression_binder.cpp +3 -2
  221. package/src/duckdb/src/planner/operator/logical_distinct.cpp +5 -4
  222. package/src/duckdb/src/planner/operator/logical_pivot.cpp +14 -2
  223. package/src/duckdb/src/planner/planner.cpp +5 -15
  224. package/src/duckdb/src/storage/data_table.cpp +10 -8
  225. package/src/duckdb/src/storage/index.cpp +13 -0
  226. package/src/duckdb/src/storage/storage_manager.cpp +6 -0
  227. package/src/duckdb/src/storage/table/column_data.cpp +7 -3
  228. package/src/duckdb/src/storage/table/list_column_data.cpp +5 -4
  229. package/src/duckdb/src/storage/table/row_group.cpp +4 -3
  230. package/src/duckdb/src/storage/table/row_group_collection.cpp +6 -3
  231. package/src/duckdb/src/storage/table/standard_column_data.cpp +4 -3
  232. package/src/duckdb/src/storage/table/struct_column_data.cpp +4 -3
  233. package/src/duckdb/src/storage/wal_replay.cpp +4 -5
  234. package/src/duckdb/third_party/libpg_query/include/nodes/nodes.hpp +0 -1
  235. package/src/duckdb/third_party/libpg_query/include/nodes/parsenodes.hpp +0 -14
  236. package/src/duckdb/third_party/libpg_query/src_backend_parser_gram.cpp +12828 -12956
  237. package/src/duckdb/third_party/zstd/compress/zstd_compress.cpp +3 -0
  238. package/src/duckdb/third_party/zstd/include/zstd/compress/zstd_cwksp.h +4 -0
  239. package/src/duckdb/ub_extension_icu_third_party_icu_i18n.cpp +5 -5
  240. package/src/duckdb/ub_src_parser_transform_statement.cpp +0 -2
  241. package/test/extension.test.ts +11 -0
  242. package/src/duckdb/src/include/duckdb/parser/parsed_data/create_database_info.hpp +0 -46
  243. package/src/duckdb/src/parser/transform/statement/transform_create_database.cpp +0 -27
@@ -87,6 +87,9 @@ unique_ptr<TableRef> Transformer::TransformPivot(duckdb_libpgquery::PGPivotExpr
87
87
  result->unpivot_names = TransformStringList(root.unpivots);
88
88
  }
89
89
  result->pivots = TransformPivotList(*root.pivots);
90
+ if (!result->unpivot_names.empty() && result->pivots.size() > 1) {
91
+ throw ParserException("UNPIVOT requires a single pivot element");
92
+ }
90
93
  if (root.groups) {
91
94
  result->groups = TransformStringList(root.groups);
92
95
  }
@@ -204,8 +204,6 @@ unique_ptr<SQLStatement> Transformer::TransformStatementInternal(duckdb_libpgque
204
204
  return TransformDetach(PGCast<duckdb_libpgquery::PGDetachStmt>(stmt));
205
205
  case duckdb_libpgquery::T_PGUseStmt:
206
206
  return TransformUse(PGCast<duckdb_libpgquery::PGUseStmt>(stmt));
207
- case duckdb_libpgquery::T_PGCreateDatabaseStmt:
208
- return TransformCreateDatabase(PGCast<duckdb_libpgquery::PGCreateDatabaseStmt>(stmt));
209
207
  default:
210
208
  throw NotImplementedException(NodetypeToString(stmt.type));
211
209
  }
@@ -286,15 +286,14 @@ string BindContext::BindColumn(PositionalReferenceExpression &ref, string &table
286
286
  return StringUtil::Format("Positional reference %d out of range (total %d columns)", ref.index, total_columns);
287
287
  }
288
288
 
289
- BindResult BindContext::BindColumn(PositionalReferenceExpression &ref, idx_t depth) {
289
+ unique_ptr<ColumnRefExpression> BindContext::PositionToColumn(PositionalReferenceExpression &ref) {
290
290
  string table_name, column_name;
291
291
 
292
292
  string error = BindColumn(ref, table_name, column_name);
293
293
  if (!error.empty()) {
294
- return BindResult(error);
294
+ throw BinderException(error);
295
295
  }
296
- auto column_ref = make_uniq<ColumnRefExpression>(column_name, table_name);
297
- return BindColumn(*column_ref, depth);
296
+ return make_uniq<ColumnRefExpression>(column_name, table_name);
298
297
  }
299
298
 
300
299
  bool BindContext::CheckExclusionList(StarExpression &expr, const string &column_name,
@@ -218,7 +218,6 @@ BindResult ExpressionBinder::BindLambdaFunction(FunctionExpression &function, Sc
218
218
  D_ASSERT(binding.names.size() == 1);
219
219
  D_ASSERT(binding.types.size() == 1);
220
220
 
221
- bound_function_expr.function.arguments.push_back(binding.types[0]);
222
221
  auto bound_lambda_param =
223
222
  make_uniq<BoundReferenceExpression>(binding.names[0], binding.types[0], lambda_index);
224
223
  bound_function_expr.children.push_back(std::move(bound_lambda_param));
@@ -227,7 +226,6 @@ BindResult ExpressionBinder::BindLambdaFunction(FunctionExpression &function, Sc
227
226
 
228
227
  // push back the captures into the children vector and the correct return types into the bound_function arguments
229
228
  for (auto &capture : bound_lambda.captures) {
230
- bound_function_expr.function.arguments.push_back(capture->return_type);
231
229
  bound_function_expr.children.push_back(std::move(capture));
232
230
  }
233
231
 
@@ -4,11 +4,16 @@
4
4
 
5
5
  namespace duckdb {
6
6
 
7
- BindResult ExpressionBinder::BindExpression(PositionalReferenceExpression &ref, idx_t depth) {
7
+ BindResult ExpressionBinder::BindPositionalReference(unique_ptr<ParsedExpression> &expr, idx_t depth,
8
+ bool root_expression) {
9
+ auto &ref = expr->Cast<PositionalReferenceExpression>();
8
10
  if (depth != 0) {
9
- return BindResult("Positional reference expression could not be bound");
11
+ throw InternalException("Positional reference expression could not be bound");
10
12
  }
11
- return binder.bind_context.BindColumn(ref, depth);
13
+ // replace the positional reference with a column
14
+ auto column = binder.bind_context.PositionToColumn(ref);
15
+ expr = std::move(column);
16
+ return BindExpression(expr, depth, root_expression);
12
17
  }
13
18
 
14
19
  } // namespace duckdb
@@ -288,6 +288,9 @@ void Binder::BindWhereStarExpression(unique_ptr<ParsedExpression> &expr) {
288
288
  // expand the stars for this expression
289
289
  vector<unique_ptr<ParsedExpression>> new_conditions;
290
290
  ExpandStarExpression(std::move(expr), new_conditions);
291
+ if (new_conditions.empty()) {
292
+ throw ParserException("COLUMNS expansion resulted in empty set of columns");
293
+ }
291
294
 
292
295
  // set up an AND conjunction between the expanded conditions
293
296
  expr = std::move(new_conditions[0]);
@@ -401,14 +404,15 @@ unique_ptr<BoundQueryNode> Binder::BindSelectNode(SelectNode &statement, unique_
401
404
  }
402
405
 
403
406
  // bind the QUALIFY clause, if any
407
+ unique_ptr<QualifyBinder> qualify_binder;
404
408
  if (statement.qualify) {
405
409
  if (statement.aggregate_handling == AggregateHandling::FORCE_AGGREGATES) {
406
410
  throw BinderException("Combining QUALIFY with GROUP BY ALL is not supported yet");
407
411
  }
408
- QualifyBinder qualify_binder(*this, context, *result, info, alias_map);
412
+ qualify_binder = make_uniq<QualifyBinder>(*this, context, *result, info, alias_map);
409
413
  ExpressionBinder::QualifyColumnNames(*this, statement.qualify);
410
- result->qualify = qualify_binder.Bind(statement.qualify);
411
- if (qualify_binder.HasBoundColumns() && qualify_binder.BoundAggregates()) {
414
+ result->qualify = qualify_binder->Bind(statement.qualify);
415
+ if (qualify_binder->HasBoundColumns() && qualify_binder->BoundAggregates()) {
412
416
  throw BinderException("Cannot mix aggregates with non-aggregated columns!");
413
417
  }
414
418
  }
@@ -487,19 +491,31 @@ unique_ptr<BoundQueryNode> Binder::BindSelectNode(SelectNode &statement, unique_
487
491
  !result->groups.grouping_sets.empty()) {
488
492
  if (statement.aggregate_handling == AggregateHandling::NO_AGGREGATES_ALLOWED) {
489
493
  throw BinderException("Aggregates cannot be present in a Project relation!");
490
- } else if (select_binder.HasBoundColumns()) {
491
- auto &bound_columns = select_binder.GetBoundColumns();
492
- string error;
493
- error = "column \"%s\" must appear in the GROUP BY clause or must be part of an aggregate function.";
494
- if (statement.aggregate_handling == AggregateHandling::FORCE_AGGREGATES) {
495
- error += "\nGROUP BY ALL will only group entries in the SELECT list. Add it to the SELECT list or "
496
- "GROUP BY this entry explicitly.";
497
- } else {
498
- error += "\nEither add it to the GROUP BY list, or use \"ANY_VALUE(%s)\" if the exact value of \"%s\" "
499
- "is not important.";
494
+ } else {
495
+ vector<reference<BaseSelectBinder>> to_check_binders;
496
+ to_check_binders.push_back(select_binder);
497
+ if (qualify_binder) {
498
+ to_check_binders.push_back(*qualify_binder);
499
+ }
500
+ for (auto &binder : to_check_binders) {
501
+ auto &sel_binder = binder.get();
502
+ if (!sel_binder.HasBoundColumns()) {
503
+ continue;
504
+ }
505
+ auto &bound_columns = sel_binder.GetBoundColumns();
506
+ string error;
507
+ error = "column \"%s\" must appear in the GROUP BY clause or must be part of an aggregate function.";
508
+ if (statement.aggregate_handling == AggregateHandling::FORCE_AGGREGATES) {
509
+ error += "\nGROUP BY ALL will only group entries in the SELECT list. Add it to the SELECT list or "
510
+ "GROUP BY this entry explicitly.";
511
+ } else {
512
+ error +=
513
+ "\nEither add it to the GROUP BY list, or use \"ANY_VALUE(%s)\" if the exact value of \"%s\" "
514
+ "is not important.";
515
+ }
516
+ throw BinderException(FormatError(bound_columns[0].query_location, error, bound_columns[0].name,
517
+ bound_columns[0].name, bound_columns[0].name));
500
518
  }
501
- throw BinderException(FormatError(bound_columns[0].query_location, error, bound_columns[0].name,
502
- bound_columns[0].name, bound_columns[0].name));
503
519
  }
504
520
  }
505
521
 
@@ -13,7 +13,6 @@
13
13
  #include "duckdb/parser/parsed_data/create_index_info.hpp"
14
14
  #include "duckdb/parser/parsed_data/create_macro_info.hpp"
15
15
  #include "duckdb/parser/parsed_data/create_view_info.hpp"
16
- #include "duckdb/parser/parsed_data/create_database_info.hpp"
17
16
  #include "duckdb/parser/tableref/table_function_ref.hpp"
18
17
  #include "duckdb/parser/parsed_expression_iterator.hpp"
19
18
  #include "duckdb/parser/statement/create_statement.hpp"
@@ -656,32 +655,6 @@ BoundStatement Binder::Bind(CreateStatement &stmt) {
656
655
  }
657
656
  break;
658
657
  }
659
- case CatalogType::DATABASE_ENTRY: {
660
- // not supported in DuckDB yet but allow extensions to intercept and implement this functionality
661
- auto &base = stmt.info->Cast<CreateDatabaseInfo>();
662
- string database_name = base.name;
663
- string source_path = base.path;
664
-
665
- auto &config = DBConfig::GetConfig(context);
666
-
667
- if (config.storage_extensions.empty()) {
668
- throw NotImplementedException("CREATE DATABASE not supported in DuckDB yet");
669
- }
670
- // for now assume only one storage extension provides the custom create_database impl
671
- for (auto &extension_entry : config.storage_extensions) {
672
- if (extension_entry.second->create_database != nullptr) {
673
- auto &storage_extension = extension_entry.second;
674
- auto create_database_function_ref = storage_extension->create_database(
675
- storage_extension->storage_info.get(), context, database_name, source_path);
676
- if (create_database_function_ref) {
677
- auto bound_create_database_func = Bind(*create_database_function_ref);
678
- result.plan = CreatePlan(*bound_create_database_func);
679
- break;
680
- }
681
- }
682
- }
683
- break;
684
- }
685
658
  default:
686
659
  throw Exception("Unrecognized type!");
687
660
  }
@@ -294,9 +294,26 @@ unique_ptr<BoundCreateTableInfo> Binder::BindCreateTableInfo(unique_ptr<CreateIn
294
294
  BindLogicalType(context, column.TypeMutable(), &result->schema.catalog);
295
295
  // We add a catalog dependency
296
296
  auto type_dependency = EnumType::GetCatalog(column.Type());
297
+
297
298
  if (type_dependency) {
298
299
  // Only if the USER comes from a create type
299
- result->dependencies.AddDependency(*type_dependency);
300
+ if (!schema.catalog.IsTemporaryCatalog()) {
301
+ // If it is not a TEMP table we add a dependency
302
+ result->dependencies.AddDependency(*type_dependency);
303
+ } else {
304
+ auto enum_type = type_dependency->user_type;
305
+ auto &enum_entries = EnumType::GetValuesInsertOrder(enum_type);
306
+ auto enum_size = EnumType::GetSize(enum_type);
307
+ Vector copy_enum_entries_vec(LogicalType::VARCHAR, enum_size);
308
+ auto copy_enum_entries_ptr = FlatVector::GetData<string_t>(copy_enum_entries_vec);
309
+ auto enum_entries_ptr = FlatVector::GetData<string_t>(enum_entries);
310
+ for (idx_t enum_idx = 0; enum_idx < enum_size; enum_idx++) {
311
+ copy_enum_entries_ptr[enum_idx] =
312
+ StringVector::AddStringOrBlob(copy_enum_entries_vec, enum_entries_ptr[enum_idx]);
313
+ }
314
+ auto copy_type = LogicalType::ENUM(EnumType::GetTypeName(enum_type), copy_enum_entries_vec, enum_size);
315
+ column.SetType(copy_type);
316
+ }
300
317
  }
301
318
  }
302
319
  result->dependencies.VerifyDependencies(schema.catalog, result->Base().table);
@@ -47,31 +47,6 @@ BoundStatement Binder::Bind(DropStatement &stmt) {
47
47
  stmt.info->schema = entry->ParentSchema().name;
48
48
  break;
49
49
  }
50
- case CatalogType::DATABASE_ENTRY: {
51
- auto &base = (DropInfo &)*stmt.info;
52
- string database_name = base.name;
53
-
54
- auto &config = DBConfig::GetConfig(context);
55
- // for now assume only one storage extension provides the custom drop_database impl
56
- for (auto &extension_entry : config.storage_extensions) {
57
- if (extension_entry.second->drop_database == nullptr) {
58
- continue;
59
- }
60
- auto &storage_extension = extension_entry.second;
61
- auto drop_database_function_ref =
62
- storage_extension->drop_database(storage_extension->storage_info.get(), context, database_name);
63
- if (drop_database_function_ref) {
64
- auto bound_drop_database_func = Bind(*drop_database_function_ref);
65
- result.plan = CreatePlan(*bound_drop_database_func);
66
- result.names = {"Success"};
67
- result.types = {LogicalType::BIGINT};
68
- properties.allow_stream_result = false;
69
- properties.return_type = StatementReturnType::NOTHING;
70
- return result;
71
- }
72
- }
73
- throw BinderException("Drop is not supported for this database!");
74
- }
75
50
  default:
76
51
  throw BinderException("Unknown catalog type for drop statement!");
77
52
  }
@@ -20,119 +20,6 @@
20
20
 
21
21
  namespace duckdb {
22
22
 
23
- static void BindExtraColumns(TableCatalogEntry &table, LogicalGet &get, LogicalProjection &proj, LogicalUpdate &update,
24
- physical_index_set_t &bound_columns) {
25
- if (bound_columns.size() <= 1) {
26
- return;
27
- }
28
- idx_t found_column_count = 0;
29
- physical_index_set_t found_columns;
30
- for (idx_t i = 0; i < update.columns.size(); i++) {
31
- if (bound_columns.find(update.columns[i]) != bound_columns.end()) {
32
- // this column is referenced in the CHECK constraint
33
- found_column_count++;
34
- found_columns.insert(update.columns[i]);
35
- }
36
- }
37
- if (found_column_count > 0 && found_column_count != bound_columns.size()) {
38
- // columns in this CHECK constraint were referenced, but not all were part of the UPDATE
39
- // add them to the scan and update set
40
- for (auto &check_column_id : bound_columns) {
41
- if (found_columns.find(check_column_id) != found_columns.end()) {
42
- // column is already projected
43
- continue;
44
- }
45
- // column is not projected yet: project it by adding the clause "i=i" to the set of updated columns
46
- auto &column = table.GetColumns().GetColumn(check_column_id);
47
- update.expressions.push_back(make_uniq<BoundColumnRefExpression>(
48
- column.Type(), ColumnBinding(proj.table_index, proj.expressions.size())));
49
- proj.expressions.push_back(make_uniq<BoundColumnRefExpression>(
50
- column.Type(), ColumnBinding(get.table_index, get.column_ids.size())));
51
- get.column_ids.push_back(check_column_id.index);
52
- update.columns.push_back(check_column_id);
53
- }
54
- }
55
- }
56
-
57
- static bool TypeSupportsRegularUpdate(const LogicalType &type) {
58
- switch (type.id()) {
59
- case LogicalTypeId::LIST:
60
- case LogicalTypeId::MAP:
61
- case LogicalTypeId::UNION:
62
- // lists and maps and unions don't support updates directly
63
- return false;
64
- case LogicalTypeId::STRUCT: {
65
- auto &child_types = StructType::GetChildTypes(type);
66
- for (auto &entry : child_types) {
67
- if (!TypeSupportsRegularUpdate(entry.second)) {
68
- return false;
69
- }
70
- }
71
- return true;
72
- }
73
- default:
74
- return true;
75
- }
76
- }
77
-
78
- static void BindUpdateConstraints(TableCatalogEntry &table, LogicalGet &get, LogicalProjection &proj,
79
- LogicalUpdate &update) {
80
- if (!table.IsDuckTable()) {
81
- return;
82
- }
83
- // check the constraints and indexes of the table to see if we need to project any additional columns
84
- // we do this for indexes with multiple columns and CHECK constraints in the UPDATE clause
85
- // suppose we have a constraint CHECK(i + j < 10); now we need both i and j to check the constraint
86
- // if we are only updating one of the two columns we add the other one to the UPDATE set
87
- // with a "useless" update (i.e. i=i) so we can verify that the CHECK constraint is not violated
88
- for (auto &constraint : table.GetBoundConstraints()) {
89
- if (constraint->type == ConstraintType::CHECK) {
90
- auto &check = constraint->Cast<BoundCheckConstraint>();
91
- // check constraint! check if we need to add any extra columns to the UPDATE clause
92
- BindExtraColumns(table, get, proj, update, check.bound_columns);
93
- }
94
- }
95
- auto &storage = table.GetStorage();
96
- if (update.return_chunk) {
97
- physical_index_set_t all_columns;
98
- for (idx_t i = 0; i < storage.column_definitions.size(); i++) {
99
- all_columns.insert(PhysicalIndex(i));
100
- }
101
- BindExtraColumns(table, get, proj, update, all_columns);
102
- }
103
- // for index updates we always turn any update into an insert and a delete
104
- // we thus need all the columns to be available, hence we check if the update touches any index columns
105
- // If the returning keyword is used, we need access to the whole row in case the user requests it.
106
- // Therefore switch the update to a delete and insert.
107
- update.update_is_del_and_insert = false;
108
- storage.info->indexes.Scan([&](Index &index) {
109
- if (index.IndexIsUpdated(update.columns)) {
110
- update.update_is_del_and_insert = true;
111
- return true;
112
- }
113
- return false;
114
- });
115
-
116
- // we also convert any updates on LIST columns into delete + insert
117
- for (auto &col_index : update.columns) {
118
- auto &column = table.GetColumns().GetColumn(col_index);
119
- if (!TypeSupportsRegularUpdate(column.Type())) {
120
- update.update_is_del_and_insert = true;
121
- break;
122
- }
123
- }
124
-
125
- if (update.update_is_del_and_insert) {
126
- // the update updates a column required by an index or requires returning the updated rows,
127
- // push projections for all columns
128
- physical_index_set_t all_columns;
129
- for (idx_t i = 0; i < storage.column_definitions.size(); i++) {
130
- all_columns.insert(PhysicalIndex(i));
131
- }
132
- BindExtraColumns(table, get, proj, update, all_columns);
133
- }
134
- }
135
-
136
23
  // This creates a LogicalProjection and moves 'root' into it as a child
137
24
  // unless there are no expressions to project, in which case it just returns 'root'
138
25
  unique_ptr<LogicalOperator> Binder::BindUpdateSet(LogicalOperator &op, unique_ptr<LogicalOperator> root,
@@ -239,7 +126,8 @@ BoundStatement Binder::Bind(UpdateStatement &stmt) {
239
126
  auto proj = unique_ptr_cast<LogicalOperator, LogicalProjection>(std::move(proj_tmp));
240
127
 
241
128
  // bind any extra columns necessary for CHECK constraints or indexes
242
- BindUpdateConstraints(table, *get, *proj, *update);
129
+ table.BindUpdateConstraints(*get, *proj, *update, context);
130
+
243
131
  // finally add the row id column to the projection list
244
132
  proj->expressions.push_back(make_uniq<BoundColumnRefExpression>(
245
133
  LogicalType::ROW_TYPE, ColumnBinding(get->table_index, get->column_ids.size())));
@@ -250,7 +250,9 @@ unique_ptr<BoundTableRef> Binder::BindBoundPivot(PivotRef &ref) {
250
250
  auto &aggregates = result->bound_pivot.aggregates;
251
251
  ExtractPivotAggregates(*result->child, aggregates);
252
252
  if (aggregates.size() != ref.bound_aggregate_names.size()) {
253
- throw InternalException("Pivot - aggregate count mismatch");
253
+ throw BinderException("Pivot aggregate count mismatch. Expected %llu aggregates but found %llu. Are all pivot "
254
+ "expressions aggregate functions?",
255
+ ref.bound_aggregate_names.size(), aggregates.size());
254
256
  }
255
257
 
256
258
  vector<string> child_names;
@@ -544,6 +546,9 @@ unique_ptr<BoundTableRef> Binder::Bind(PivotRef &ref) {
544
546
 
545
547
  // bind the source of the pivot
546
548
  // we need to do this to be able to expand star expressions
549
+ if (ref.source->type == TableReferenceType::SUBQUERY && ref.source->alias.empty()) {
550
+ ref.source->alias = "__internal_pivot_alias_" + to_string(GenerateTableIndex());
551
+ }
547
552
  auto copied_source = ref.source->Copy();
548
553
  auto star_binder = Binder::CreateBinder(context, this);
549
554
  star_binder->Bind(*copied_source);
@@ -97,6 +97,8 @@ bool Binder::BindTableFunctionParameters(TableFunctionCatalogEntry &table_functi
97
97
  subquery = make_uniq<BoundSubqueryRef>(std::move(binder), std::move(node));
98
98
  seen_subquery = true;
99
99
  arguments.emplace_back(LogicalTypeId::TABLE);
100
+ parameters.emplace_back(
101
+ Value(LogicalType::INVALID)); // this is a dummy value so the lengths of arguments and parameter match
100
102
  continue;
101
103
  }
102
104
 
@@ -161,6 +163,9 @@ Binder::BindTableFunctionInternal(TableFunction &table_function, const string &f
161
163
  table_function.extra_info = "(Multi-Threaded)";
162
164
  }
163
165
  }
166
+ } else {
167
+ throw InvalidInputException("Cannot call function \"%s\" directly - it has no bind function",
168
+ table_function.name);
164
169
  }
165
170
  if (return_types.size() != return_names.size()) {
166
171
  throw InternalException("Failed to bind \"%s\": return_types/names must have same size", table_function.name);
@@ -16,6 +16,20 @@ BoundOrderByNode::BoundOrderByNode(OrderType type, OrderByNullType null_order, u
16
16
  unique_ptr<BaseStatistics> stats)
17
17
  : type(type), null_order(null_order), expression(std::move(expression)), stats(std::move(stats)) {
18
18
  }
19
+ void BoundOrderModifier::Serialize(Serializer &serializer) const {
20
+ FieldWriter writer(serializer);
21
+ writer.WriteRegularSerializableList(orders);
22
+ writer.Finalize();
23
+ }
24
+ unique_ptr<BoundOrderModifier> BoundOrderModifier::Deserialize(Deserializer &source, PlanDeserializationState &state) {
25
+ auto x = make_uniq<BoundOrderModifier>();
26
+
27
+ FieldReader reader(source);
28
+ x->orders = reader.ReadRequiredSerializableList<BoundOrderByNode, BoundOrderByNode>(state);
29
+ reader.Finalize();
30
+
31
+ return x;
32
+ }
19
33
 
20
34
  BoundOrderByNode BoundOrderByNode::Copy() const {
21
35
  if (stats) {
@@ -84,9 +84,7 @@ unique_ptr<Expression> BoundAggregateExpression::Copy() {
84
84
  void BoundAggregateExpression::Serialize(FieldWriter &writer) const {
85
85
  writer.WriteField(IsDistinct());
86
86
  writer.WriteOptional(filter);
87
- if (order_bys) {
88
- throw NotImplementedException("Serialization of ORDER BY aggregate not yet supported");
89
- }
87
+ writer.WriteOptional(order_bys);
90
88
  FunctionSerializer::Serialize<AggregateFunction>(writer, function, return_type, children, bind_info.get());
91
89
  }
92
90
 
@@ -94,13 +92,16 @@ unique_ptr<Expression> BoundAggregateExpression::Deserialize(ExpressionDeseriali
94
92
  FieldReader &reader) {
95
93
  auto distinct = reader.ReadRequired<bool>();
96
94
  auto filter = reader.ReadOptional<Expression>(nullptr, state.gstate);
95
+ auto order_bys = reader.ReadOptional<BoundOrderModifier>(nullptr, state.gstate);
97
96
  vector<unique_ptr<Expression>> children;
98
97
  unique_ptr<FunctionData> bind_info;
99
98
  auto function = FunctionSerializer::Deserialize<AggregateFunction, AggregateFunctionCatalogEntry>(
100
99
  reader, state, CatalogType::AGGREGATE_FUNCTION_ENTRY, children, bind_info);
101
100
 
102
- return make_uniq<BoundAggregateExpression>(function, std::move(children), std::move(filter), std::move(bind_info),
103
- distinct ? AggregateType::DISTINCT : AggregateType::NON_DISTINCT);
101
+ auto x = make_uniq<BoundAggregateExpression>(function, std::move(children), std::move(filter), std::move(bind_info),
102
+ distinct ? AggregateType::DISTINCT : AggregateType::NON_DISTINCT);
103
+ x->order_bys = std::move(order_bys);
104
+ return std::move(x);
104
105
  }
105
106
 
106
107
  } // namespace duckdb
@@ -1,10 +1,16 @@
1
1
  #include "duckdb/planner/expression/bound_default_expression.hpp"
2
2
  #include "duckdb/common/exception.hpp"
3
+ #include "duckdb/common/field_writer.hpp"
3
4
 
4
5
  namespace duckdb {
5
6
 
6
7
  void BoundDefaultExpression::Serialize(FieldWriter &writer) const {
7
- throw NotImplementedException(ExpressionTypeToString(type));
8
+ writer.WriteSerializable(return_type);
9
+ }
10
+
11
+ unique_ptr<Expression> BoundDefaultExpression::Deserialize(ExpressionDeserializationState &state, FieldReader &reader) {
12
+ auto return_type = reader.ReadRequiredSerializable<LogicalType, LogicalType>();
13
+ return make_uniq<BoundDefaultExpression>(return_type);
8
14
  }
9
15
 
10
16
  } // namespace duckdb
@@ -130,6 +130,9 @@ unique_ptr<Expression> Expression::Deserialize(Deserializer &source, PlanDeseria
130
130
  case ExpressionClass::BOUND_CONSTANT:
131
131
  result = BoundConstantExpression::Deserialize(state, reader);
132
132
  break;
133
+ case ExpressionClass::BOUND_DEFAULT:
134
+ result = BoundDefaultExpression::Deserialize(state, reader);
135
+ break;
133
136
  case ExpressionClass::BOUND_FUNCTION:
134
137
  result = BoundFunctionExpression::Deserialize(state, reader);
135
138
  break;
@@ -64,8 +64,9 @@ BindResult ExpressionBinder::BindExpression(unique_ptr<ParsedExpression> &expr,
64
64
  return BindExpression(expr_ref.Cast<SubqueryExpression>(), depth);
65
65
  case ExpressionClass::PARAMETER:
66
66
  return BindExpression(expr_ref.Cast<ParameterExpression>(), depth);
67
- case ExpressionClass::POSITIONAL_REFERENCE:
68
- return BindExpression(expr_ref.Cast<PositionalReferenceExpression>(), depth);
67
+ case ExpressionClass::POSITIONAL_REFERENCE: {
68
+ return BindPositionalReference(expr, depth, root_expression);
69
+ }
69
70
  case ExpressionClass::STAR:
70
71
  return BindResult(binder.FormatError(expr_ref, "STAR expression is not supported here"));
71
72
  default:
@@ -16,15 +16,16 @@ string LogicalDistinct::ParamsToString() const {
16
16
  void LogicalDistinct::Serialize(FieldWriter &writer) const {
17
17
  writer.WriteField<DistinctType>(distinct_type);
18
18
  writer.WriteSerializableList(distinct_targets);
19
- if (order_by) {
20
- throw NotImplementedException("Serializing ORDER BY not yet supported");
21
- }
19
+ writer.WriteOptional(order_by);
22
20
  }
23
21
 
24
22
  unique_ptr<LogicalOperator> LogicalDistinct::Deserialize(LogicalDeserializationState &state, FieldReader &reader) {
25
23
  auto distinct_type = reader.ReadRequired<DistinctType>();
26
24
  auto distinct_targets = reader.ReadRequiredSerializableList<Expression>(state.gstate);
27
- return make_uniq<LogicalDistinct>(std::move(distinct_targets), distinct_type);
25
+ auto order_by = reader.ReadOptional<BoundOrderModifier>(nullptr, state.gstate);
26
+ auto ret = make_uniq<LogicalDistinct>(std::move(distinct_targets), distinct_type);
27
+ ret->order_by = std::move(order_by);
28
+ return std::move(ret);
28
29
  }
29
30
 
30
31
  } // namespace duckdb
@@ -19,11 +19,23 @@ vector<ColumnBinding> LogicalPivot::GetColumnBindings() {
19
19
  }
20
20
 
21
21
  void LogicalPivot::Serialize(FieldWriter &writer) const {
22
- throw NotImplementedException("Serializing pivot is not supported yet");
22
+ writer.WriteField(pivot_index);
23
+ writer.WriteOptional<LogicalOperator>(children.back());
24
+ writer.WriteField(bound_pivot.group_count);
25
+ writer.WriteRegularSerializableList<LogicalType>(bound_pivot.types);
26
+ writer.WriteList<string>(bound_pivot.pivot_values);
27
+ writer.WriteSerializableList<Expression>(bound_pivot.aggregates);
23
28
  }
24
29
 
25
30
  unique_ptr<LogicalOperator> LogicalPivot::Deserialize(LogicalDeserializationState &state, FieldReader &reader) {
26
- throw NotImplementedException("Deserializing pivot is not supported yet");
31
+ auto pivot_index = reader.ReadRequired<idx_t>();
32
+ auto plan = reader.ReadOptional<LogicalOperator>(nullptr, state.gstate);
33
+ BoundPivotInfo info;
34
+ info.group_count = reader.ReadRequired<idx_t>();
35
+ info.types = reader.ReadRequiredSerializableList<LogicalType, LogicalType>();
36
+ info.pivot_values = reader.ReadRequiredList<string>();
37
+ info.aggregates = reader.ReadRequiredSerializableList<Expression>(state.gstate);
38
+ return make_uniq<LogicalPivot>(pivot_index, std::move(plan), std::move(info));
27
39
  }
28
40
 
29
41
  vector<idx_t> LogicalPivot::GetTableIndex() const {
@@ -1,14 +1,15 @@
1
1
  #include "duckdb/planner/planner.hpp"
2
- #include "duckdb/main/query_profiler.hpp"
2
+
3
3
  #include "duckdb/common/serializer.hpp"
4
+ #include "duckdb/common/serializer/buffered_deserializer.hpp"
5
+ #include "duckdb/execution/expression_executor.hpp"
4
6
  #include "duckdb/main/client_context.hpp"
5
7
  #include "duckdb/main/client_data.hpp"
6
8
  #include "duckdb/main/database.hpp"
7
9
  #include "duckdb/main/prepared_statement_data.hpp"
10
+ #include "duckdb/main/query_profiler.hpp"
8
11
  #include "duckdb/planner/binder.hpp"
9
12
  #include "duckdb/planner/expression/bound_parameter_expression.hpp"
10
- #include "duckdb/execution/expression_executor.hpp"
11
- #include "duckdb/common/serializer/buffered_deserializer.hpp"
12
13
  #include "duckdb/transaction/meta_transaction.hpp"
13
14
 
14
15
  namespace duckdb {
@@ -142,23 +143,12 @@ void Planner::CreatePlan(unique_ptr<SQLStatement> statement) {
142
143
  }
143
144
 
144
145
  static bool OperatorSupportsSerialization(LogicalOperator &op) {
145
- switch (op.type) {
146
- case LogicalOperatorType::LOGICAL_PREPARE:
147
- case LogicalOperatorType::LOGICAL_EXECUTE:
148
- case LogicalOperatorType::LOGICAL_PRAGMA:
149
- case LogicalOperatorType::LOGICAL_EXPLAIN:
150
- case LogicalOperatorType::LOGICAL_COPY_TO_FILE:
151
- // unsupported (for now)
152
- return false;
153
- default:
154
- break;
155
- }
156
146
  for (auto &child : op.children) {
157
147
  if (!OperatorSupportsSerialization(*child)) {
158
148
  return false;
159
149
  }
160
150
  }
161
- return true;
151
+ return op.SupportSerialization();
162
152
  }
163
153
 
164
154
  void Planner::VerifyPlan(ClientContext &context, unique_ptr<LogicalOperator> &op, bound_parameter_map_t *map) {