duckdb 0.8.1-dev341.0 → 0.8.1-dev407.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 +1 -1
- package/src/duckdb/extension/icu/icu-datepart.cpp +1 -1
- package/src/duckdb/extension/icu/icu-extension.cpp +1 -1
- package/src/duckdb/extension/icu/icu-strptime.cpp +1 -1
- package/src/duckdb/extension/icu/third_party/icu/i18n/nfsubs.cpp +0 -2
- package/src/duckdb/extension/json/include/json_scan.hpp +2 -1
- package/src/duckdb/extension/json/json_functions/json_contains.cpp +5 -0
- package/src/duckdb/extension/json/json_scan.cpp +3 -2
- package/src/duckdb/extension/parquet/parquet-extension.cpp +2 -1
- package/src/duckdb/src/common/exception_format_value.cpp +6 -2
- package/src/duckdb/src/common/random_engine.cpp +1 -1
- package/src/duckdb/src/common/types/time.cpp +2 -8
- package/src/duckdb/src/common/types.cpp +4 -0
- package/src/duckdb/src/core_functions/aggregate/distributive/string_agg.cpp +1 -1
- package/src/duckdb/src/core_functions/aggregate/holistic/approximate_quantile.cpp +1 -1
- package/src/duckdb/src/core_functions/aggregate/holistic/quantile.cpp +1 -1
- package/src/duckdb/src/core_functions/aggregate/holistic/reservoir_quantile.cpp +1 -1
- package/src/duckdb/src/core_functions/scalar/date/date_part.cpp +1 -1
- package/src/duckdb/src/core_functions/scalar/date/make_date.cpp +3 -0
- package/src/duckdb/src/core_functions/scalar/list/array_slice.cpp +1 -1
- package/src/duckdb/src/core_functions/scalar/list/list_aggregates.cpp +23 -6
- package/src/duckdb/src/core_functions/scalar/list/list_lambdas.cpp +1 -2
- package/src/duckdb/src/core_functions/scalar/math/numeric.cpp +3 -3
- package/src/duckdb/src/execution/index/art/leaf.cpp +1 -0
- package/src/duckdb/src/execution/index/art/node.cpp +1 -0
- package/src/duckdb/src/execution/join_hashtable.cpp +2 -0
- package/src/duckdb/src/execution/operator/projection/physical_tableinout_function.cpp +1 -0
- package/src/duckdb/src/execution/operator/projection/physical_unnest.cpp +8 -3
- package/src/duckdb/src/execution/operator/schema/physical_attach.cpp +0 -1
- package/src/duckdb/src/execution/reservoir_sample.cpp +18 -4
- package/src/duckdb/src/function/aggregate/distributive/count.cpp +1 -1
- package/src/duckdb/src/function/aggregate/distributive/first.cpp +2 -1
- package/src/duckdb/src/function/aggregate/sorted_aggregate_function.cpp +1 -1
- package/src/duckdb/src/function/scalar/list/list_extract.cpp +1 -1
- package/src/duckdb/src/function/scalar/operators/arithmetic.cpp +1 -1
- package/src/duckdb/src/function/scalar/system/aggregate_export.cpp +2 -2
- package/src/duckdb/src/function/table/checkpoint.cpp +3 -0
- package/src/duckdb/src/function/table/read_csv.cpp +1 -1
- package/src/duckdb/src/function/table/table_scan.cpp +2 -2
- package/src/duckdb/src/function/table/version/pragma_version.cpp +2 -2
- package/src/duckdb/src/include/duckdb/common/types/time.hpp +2 -0
- package/src/duckdb/src/include/duckdb/function/aggregate_function.hpp +1 -1
- package/src/duckdb/src/include/duckdb/function/function_serialization.hpp +1 -1
- package/src/duckdb/src/include/duckdb/function/scalar/nested_functions.hpp +1 -1
- package/src/duckdb/src/include/duckdb/function/scalar_function.hpp +2 -1
- package/src/duckdb/src/include/duckdb/function/table_function.hpp +1 -1
- package/src/duckdb/src/include/duckdb/main/attached_database.hpp +4 -1
- package/src/duckdb/src/include/duckdb/main/extension_entries.hpp +142 -136
- package/src/duckdb/src/include/duckdb/planner/bound_result_modifier.hpp +3 -0
- package/src/duckdb/src/main/attached_database.cpp +8 -0
- package/src/duckdb/src/main/database.cpp +1 -0
- package/src/duckdb/src/main/database_manager.cpp +5 -0
- package/src/duckdb/src/parser/transform/expression/transform_operator.cpp +3 -0
- package/src/duckdb/src/planner/binder/expression/bind_function_expression.cpp +0 -2
- package/src/duckdb/src/planner/binder/query_node/bind_select_node.cpp +31 -15
- package/src/duckdb/src/planner/binder/tableref/bind_pivot.cpp +3 -0
- package/src/duckdb/src/planner/bound_result_modifier.cpp +14 -0
- package/src/duckdb/src/planner/expression/bound_aggregate_expression.cpp +6 -5
- package/src/duckdb/src/planner/expression/bound_default_expression.cpp +7 -1
- package/src/duckdb/src/planner/expression.cpp +3 -0
- package/src/duckdb/src/planner/operator/logical_distinct.cpp +5 -4
- package/src/duckdb/src/storage/storage_manager.cpp +6 -0
@@ -14,6 +14,7 @@
|
|
14
14
|
#include "duckdb/common/vector_operations/vector_operations.hpp"
|
15
15
|
#include "duckdb/execution/expression_executor_state.hpp"
|
16
16
|
#include "duckdb/function/function.hpp"
|
17
|
+
#include "duckdb/planner/plan_serialization.hpp"
|
17
18
|
#include "duckdb/storage/statistics/base_statistics.hpp"
|
18
19
|
#include "duckdb/common/optional_ptr.hpp"
|
19
20
|
|
@@ -65,7 +66,7 @@ typedef void (*dependency_function_t)(BoundFunctionExpression &expr, DependencyL
|
|
65
66
|
|
66
67
|
typedef void (*function_serialize_t)(FieldWriter &writer, const FunctionData *bind_data,
|
67
68
|
const ScalarFunction &function);
|
68
|
-
typedef unique_ptr<FunctionData> (*function_deserialize_t)(
|
69
|
+
typedef unique_ptr<FunctionData> (*function_deserialize_t)(PlanDeserializationState &state, FieldReader &reader,
|
69
70
|
ScalarFunction &function);
|
70
71
|
|
71
72
|
class ScalarFunction : public BaseScalarFunction {
|
@@ -204,7 +204,7 @@ typedef string (*table_function_to_string_t)(const FunctionData *bind_data);
|
|
204
204
|
|
205
205
|
typedef void (*table_function_serialize_t)(FieldWriter &writer, const FunctionData *bind_data,
|
206
206
|
const TableFunction &function);
|
207
|
-
typedef unique_ptr<FunctionData> (*table_function_deserialize_t)(
|
207
|
+
typedef unique_ptr<FunctionData> (*table_function_deserialize_t)(PlanDeserializationState &context, FieldReader &reader,
|
208
208
|
TableFunction &function);
|
209
209
|
|
210
210
|
class TableFunction : public SimpleNamedParameterFunction {
|
@@ -40,7 +40,7 @@ public:
|
|
40
40
|
//! Create an attached database instance with the specified storage extension
|
41
41
|
AttachedDatabase(DatabaseInstance &db, Catalog &catalog, StorageExtension &ext, string name, AttachInfo &info,
|
42
42
|
AccessMode access_mode);
|
43
|
-
~AttachedDatabase();
|
43
|
+
~AttachedDatabase() override;
|
44
44
|
|
45
45
|
void Initialize();
|
46
46
|
|
@@ -57,6 +57,8 @@ public:
|
|
57
57
|
bool IsSystem() const;
|
58
58
|
bool IsTemporary() const;
|
59
59
|
bool IsReadOnly() const;
|
60
|
+
bool IsInitialDatabase() const;
|
61
|
+
void SetInitialDatabase();
|
60
62
|
|
61
63
|
static string ExtractDatabaseName(const string &dbpath);
|
62
64
|
|
@@ -67,6 +69,7 @@ private:
|
|
67
69
|
unique_ptr<TransactionManager> transaction_manager;
|
68
70
|
AttachedDatabaseType type;
|
69
71
|
optional_ptr<Catalog> parent_catalog;
|
72
|
+
bool is_initial_database = false;
|
70
73
|
};
|
71
74
|
|
72
75
|
} // namespace duckdb
|
@@ -17,142 +17,148 @@ struct ExtensionEntry {
|
|
17
17
|
char extension[48];
|
18
18
|
};
|
19
19
|
|
20
|
-
static constexpr ExtensionEntry EXTENSION_FUNCTIONS[] = {
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
}
|
20
|
+
static constexpr ExtensionEntry EXTENSION_FUNCTIONS[] = {{"->>", "json"},
|
21
|
+
{"array_to_json", "json"},
|
22
|
+
{"create_fts_index", "fts"},
|
23
|
+
{"current_localtime", "icu"},
|
24
|
+
{"current_localtimestamp", "icu"},
|
25
|
+
{"dbgen", "tpch"},
|
26
|
+
{"drop_fts_index", "fts"},
|
27
|
+
{"dsdgen", "tpcds"},
|
28
|
+
{"excel_text", "excel"},
|
29
|
+
{"from_json", "json"},
|
30
|
+
{"from_json_strict", "json"},
|
31
|
+
{"from_substrait", "substrait"},
|
32
|
+
{"from_substrait_json", "substrait"},
|
33
|
+
{"get_substrait", "substrait"},
|
34
|
+
{"get_substrait_json", "substrait"},
|
35
|
+
{"icu_calendar_names", "icu"},
|
36
|
+
{"icu_sort_key", "icu"},
|
37
|
+
{"json", "json"},
|
38
|
+
{"json_array", "json"},
|
39
|
+
{"json_array_length", "json"},
|
40
|
+
{"json_contains", "json"},
|
41
|
+
{"json_extract", "json"},
|
42
|
+
{"json_extract_path", "json"},
|
43
|
+
{"json_extract_path_text", "json"},
|
44
|
+
{"json_extract_string", "json"},
|
45
|
+
{"json_group_array", "json"},
|
46
|
+
{"json_group_object", "json"},
|
47
|
+
{"json_group_structure", "json"},
|
48
|
+
{"json_keys", "json"},
|
49
|
+
{"json_merge_patch", "json"},
|
50
|
+
{"json_object", "json"},
|
51
|
+
{"json_quote", "json"},
|
52
|
+
{"json_structure", "json"},
|
53
|
+
{"json_transform", "json"},
|
54
|
+
{"json_transform_strict", "json"},
|
55
|
+
{"json_type", "json"},
|
56
|
+
{"json_valid", "json"},
|
57
|
+
{"json_serialize_sql", "json"},
|
58
|
+
{"json_deserialize_sql", "json"},
|
59
|
+
{"json_serialize_sql", "json"},
|
60
|
+
{"json_execute_serialized_sql", "json"},
|
61
|
+
{"make_timestamptz", "icu"},
|
62
|
+
{"parquet_metadata", "parquet"},
|
63
|
+
{"parquet_scan", "parquet"},
|
64
|
+
{"parquet_schema", "parquet"},
|
65
|
+
{"pg_timezone_names", "icu"},
|
66
|
+
{"postgres_attach", "postgres_scanner"},
|
67
|
+
{"postgres_scan", "postgres_scanner"},
|
68
|
+
{"postgres_scan_pushdown", "postgres_scanner"},
|
69
|
+
{"read_json", "json"},
|
70
|
+
{"read_json_auto", "json"},
|
71
|
+
{"read_json_objects", "json"},
|
72
|
+
{"read_json_objects_auto", "json"},
|
73
|
+
{"read_ndjson", "json"},
|
74
|
+
{"read_ndjson_auto", "json"},
|
75
|
+
{"read_ndjson_objects", "json"},
|
76
|
+
{"read_parquet", "parquet"},
|
77
|
+
{"row_to_json", "json"},
|
78
|
+
{"scan_arrow_ipc", "arrow"},
|
79
|
+
{"sqlite_attach", "sqlite_scanner"},
|
80
|
+
{"sqlite_scan", "sqlite_scanner"},
|
81
|
+
{"stem", "fts"},
|
82
|
+
{"text", "excel"},
|
83
|
+
{"to_arrow_ipc", "arrow"},
|
84
|
+
{"to_json", "json"},
|
85
|
+
{"tpcds", "tpcds"},
|
86
|
+
{"tpcds_answers", "tpcds"},
|
87
|
+
{"tpcds_queries", "tpcds"},
|
88
|
+
{"tpch", "tpch"},
|
89
|
+
{"tpch_answers", "tpch"},
|
90
|
+
{"tpch_queries", "tpch"},
|
91
|
+
{"visualize_diff_profiling_output", "visualizer"},
|
92
|
+
{"visualize_json_profiling_output", "visualizer"},
|
93
|
+
{"visualize_last_profiling_output", "visualizer"},
|
94
|
+
{"st_distance_spheroid", "spatial"},
|
95
|
+
{"st_boundary", "spatial"},
|
96
|
+
{"st_makeline", "spatial"},
|
97
|
+
{"st_buffer", "spatial"},
|
98
|
+
{"st_x", "spatial"},
|
99
|
+
{"st_isring", "spatial"},
|
100
|
+
{"st_centroid", "spatial"},
|
101
|
+
{"st_read", "spatial"},
|
102
|
+
{"st_geomfromwkb", "spatial"},
|
103
|
+
{"st_list_proj_crs", "spatial"},
|
104
|
+
{"st_isvalid", "spatial"},
|
105
|
+
{"st_polygon2dfromwkb", "spatial"},
|
106
|
+
{"st_disjoint", "spatial"},
|
107
|
+
{"st_length", "spatial"},
|
108
|
+
{"st_difference", "spatial"},
|
109
|
+
{"st_area", "spatial"},
|
110
|
+
{"st_union", "spatial"},
|
111
|
+
{"st_isclosed", "spatial"},
|
112
|
+
{"st_asgeojson", "spatial"},
|
113
|
+
{"st_intersection", "spatial"},
|
114
|
+
{"st_transform", "spatial"},
|
115
|
+
{"st_dwithin", "spatial"},
|
116
|
+
{"st_perimeter", "spatial"},
|
117
|
+
{"st_issimple", "spatial"},
|
118
|
+
{"st_geometrytype", "spatial"},
|
119
|
+
{"st_simplifypreservetopology", "spatial"},
|
120
|
+
{"st_distance", "spatial"},
|
121
|
+
{"st_astext", "spatial"},
|
122
|
+
{"st_overlaps", "spatial"},
|
123
|
+
{"st_convexhull", "spatial"},
|
124
|
+
{"st_normalize", "spatial"},
|
125
|
+
{"st_drivers", "spatial"},
|
126
|
+
{"st_point2dfromwkb", "spatial"},
|
127
|
+
{"st_point2d", "spatial"},
|
128
|
+
{"st_y", "spatial"},
|
129
|
+
{"st_dwithin_spheroid", "spatial"},
|
130
|
+
{"st_isempty", "spatial"},
|
131
|
+
{"st_simplify", "spatial"},
|
132
|
+
{"st_area_spheroid", "spatial"},
|
133
|
+
{"st_within", "spatial"},
|
134
|
+
{"st_length_spheroid", "spatial"},
|
135
|
+
{"st_point3d", "spatial"},
|
136
|
+
{"st_containsproperly", "spatial"},
|
137
|
+
{"st_contains", "spatial"},
|
138
|
+
{"st_collect", "spatial"},
|
139
|
+
{"st_touches", "spatial"},
|
140
|
+
{"st_linestring2dfromwkb", "spatial"},
|
141
|
+
{"st_flipcoordinates", "spatial"},
|
142
|
+
{"st_ashexwkb", "spatial"},
|
143
|
+
{"st_geomfromtext", "spatial"},
|
144
|
+
{"st_point4d", "spatial"},
|
145
|
+
{"st_point", "spatial"},
|
146
|
+
{"st_coveredby", "spatial"},
|
147
|
+
{"st_perimeter_spheroid", "spatial"},
|
148
|
+
{"st_intersects", "spatial"},
|
149
|
+
{"st_crosses", "spatial"},
|
150
|
+
{"st_covers", "spatial"},
|
151
|
+
{"st_envelope", "spatial"},
|
152
|
+
{"st_aswkb", "spatial"},
|
153
|
+
{"st_equals", "spatial"},
|
154
|
+
{"st_collectionextract", "spatial"},
|
155
|
+
{"st_npoints", "spatial"},
|
156
|
+
{"st_pointonsurface", "spatial"},
|
157
|
+
{"st_dimension", "spatial"},
|
158
|
+
{"st_removerepeatedpoints", "spatial"},
|
159
|
+
{"st_geomfromgeojson", "spatial"},
|
160
|
+
{"st_readosm", "spatial"},
|
161
|
+
{"st_numpoints", "spatial"}};
|
156
162
|
|
157
163
|
static constexpr ExtensionEntry EXTENSION_SETTINGS[] = {
|
158
164
|
{"binary_as_string", "parquet"},
|
@@ -95,6 +95,9 @@ public:
|
|
95
95
|
unique_ptr<BoundOrderModifier> Copy() const;
|
96
96
|
static bool Equals(const BoundOrderModifier &left, const BoundOrderModifier &right);
|
97
97
|
static bool Equals(const unique_ptr<BoundOrderModifier> &left, const unique_ptr<BoundOrderModifier> &right);
|
98
|
+
|
99
|
+
void Serialize(Serializer &serializer) const;
|
100
|
+
static unique_ptr<BoundOrderModifier> Deserialize(Deserializer &source, PlanDeserializationState &state);
|
98
101
|
};
|
99
102
|
|
100
103
|
enum class DistinctType : uint8_t { DISTINCT = 0, DISTINCT_ON = 1 };
|
@@ -124,4 +124,12 @@ Catalog &AttachedDatabase::ParentCatalog() {
|
|
124
124
|
return *parent_catalog;
|
125
125
|
}
|
126
126
|
|
127
|
+
bool AttachedDatabase::IsInitialDatabase() const {
|
128
|
+
return is_initial_database;
|
129
|
+
}
|
130
|
+
|
131
|
+
void AttachedDatabase::SetInitialDatabase() {
|
132
|
+
is_initial_database = true;
|
133
|
+
}
|
134
|
+
|
127
135
|
} // namespace duckdb
|
@@ -43,6 +43,11 @@ void DatabaseManager::AddDatabase(ClientContext &context, unique_ptr<AttachedDat
|
|
43
43
|
}
|
44
44
|
|
45
45
|
void DatabaseManager::DetachDatabase(ClientContext &context, const string &name, OnEntryNotFound if_not_found) {
|
46
|
+
if (GetDefaultDatabase(context) == name) {
|
47
|
+
throw BinderException("Cannot detach database \"%s\" because it is the default database. Select a different "
|
48
|
+
"database using `USE` to allow detaching this database",
|
49
|
+
name);
|
50
|
+
}
|
46
51
|
if (!databases->DropEntry(context, name, false, true)) {
|
47
52
|
if (if_not_found == OnEntryNotFound::THROW_EXCEPTION) {
|
48
53
|
throw BinderException("Failed to detach database with name \"%s\": database not found", name);
|
@@ -82,6 +82,9 @@ unique_ptr<ParsedExpression> Transformer::TransformAExprInternal(duckdb_libpgque
|
|
82
82
|
subquery_expr->child = std::move(left_expr);
|
83
83
|
subquery_expr->comparison_type = OperatorToExpressionType(name);
|
84
84
|
subquery_expr->query_location = root.location;
|
85
|
+
if (subquery_expr->comparison_type == ExpressionType::INVALID) {
|
86
|
+
throw ParserException("Unsupported comparison \"%s\" for ANY/ALL subquery", name);
|
87
|
+
}
|
85
88
|
|
86
89
|
if (root.kind == duckdb_libpgquery::PG_AEXPR_OP_ALL) {
|
87
90
|
// ALL sublink is equivalent to NOT(ANY) with inverted comparison
|
@@ -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
|
|
@@ -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
|
412
|
+
qualify_binder = make_uniq<QualifyBinder>(*this, context, *result, info, alias_map);
|
409
413
|
ExpressionBinder::QualifyColumnNames(*this, statement.qualify);
|
410
|
-
result->qualify = qualify_binder
|
411
|
-
if (qualify_binder
|
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
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
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
|
|
@@ -546,6 +546,9 @@ unique_ptr<BoundTableRef> Binder::Bind(PivotRef &ref) {
|
|
546
546
|
|
547
547
|
// bind the source of the pivot
|
548
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
|
+
}
|
549
552
|
auto copied_source = ref.source->Copy();
|
550
553
|
auto star_binder = Binder::CreateBinder(context, this);
|
551
554
|
star_binder->Bind(*copied_source);
|
@@ -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
|
-
|
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
|
-
|
103
|
-
|
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
|
-
|
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;
|
@@ -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
|
-
|
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
|
-
|
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
|