duckdb 0.7.2-dev16.0 → 0.7.2-dev314.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/binding.gyp +2 -0
- package/package.json +1 -1
- package/src/duckdb/extension/icu/icu-extension.cpp +2 -0
- package/src/duckdb/extension/icu/icu-table-range.cpp +194 -0
- package/src/duckdb/extension/icu/include/icu-table-range.hpp +17 -0
- package/src/duckdb/extension/parquet/column_reader.cpp +5 -6
- package/src/duckdb/extension/parquet/column_writer.cpp +0 -1
- package/src/duckdb/extension/parquet/include/column_reader.hpp +1 -2
- package/src/duckdb/extension/parquet/include/generated_column_reader.hpp +1 -11
- package/src/duckdb/extension/parquet/parquet-extension.cpp +11 -2
- package/src/duckdb/extension/parquet/parquet_statistics.cpp +26 -32
- package/src/duckdb/src/catalog/catalog_entry/duck_schema_entry.cpp +4 -0
- package/src/duckdb/src/catalog/catalog_entry/scalar_function_catalog_entry.cpp +7 -6
- package/src/duckdb/src/catalog/catalog_entry/table_function_catalog_entry.cpp +20 -1
- package/src/duckdb/src/common/enums/statement_type.cpp +2 -0
- package/src/duckdb/src/common/sort/sort_state.cpp +5 -7
- package/src/duckdb/src/common/types/bit.cpp +95 -58
- package/src/duckdb/src/common/types/value.cpp +149 -53
- package/src/duckdb/src/common/types/vector.cpp +13 -10
- package/src/duckdb/src/execution/column_binding_resolver.cpp +6 -0
- package/src/duckdb/src/execution/operator/aggregate/physical_perfecthash_aggregate.cpp +4 -5
- package/src/duckdb/src/execution/operator/aggregate/physical_window.cpp +1 -1
- package/src/duckdb/src/execution/operator/helper/physical_vacuum.cpp +2 -3
- package/src/duckdb/src/execution/operator/join/physical_blockwise_nl_join.cpp +32 -6
- package/src/duckdb/src/execution/operator/persistent/buffered_csv_reader.cpp +1 -1
- package/src/duckdb/src/execution/physical_plan/plan_aggregate.cpp +15 -15
- package/src/duckdb/src/execution/physical_plan/plan_comparison_join.cpp +18 -12
- package/src/duckdb/src/function/aggregate/algebraic/avg.cpp +0 -6
- package/src/duckdb/src/function/aggregate/distributive/bitagg.cpp +99 -95
- package/src/duckdb/src/function/aggregate/distributive/bitstring_agg.cpp +254 -0
- package/src/duckdb/src/function/aggregate/distributive/count.cpp +2 -4
- package/src/duckdb/src/function/aggregate/distributive/sum.cpp +11 -16
- package/src/duckdb/src/function/aggregate/distributive_functions.cpp +1 -0
- package/src/duckdb/src/function/aggregate/sorted_aggregate_function.cpp +16 -5
- package/src/duckdb/src/function/cast/bit_cast.cpp +0 -2
- package/src/duckdb/src/function/cast/blob_cast.cpp +0 -1
- package/src/duckdb/src/function/scalar/bit/bitstring.cpp +99 -0
- package/src/duckdb/src/function/scalar/date/date_diff.cpp +0 -1
- package/src/duckdb/src/function/scalar/date/date_part.cpp +17 -25
- package/src/duckdb/src/function/scalar/date/date_sub.cpp +0 -1
- package/src/duckdb/src/function/scalar/date/date_trunc.cpp +10 -14
- package/src/duckdb/src/function/scalar/generic/stats.cpp +2 -4
- package/src/duckdb/src/function/scalar/list/flatten.cpp +5 -12
- package/src/duckdb/src/function/scalar/list/list_concat.cpp +3 -8
- package/src/duckdb/src/function/scalar/list/list_extract.cpp +5 -12
- package/src/duckdb/src/function/scalar/list/list_value.cpp +5 -9
- package/src/duckdb/src/function/scalar/map/map_entries.cpp +61 -0
- package/src/duckdb/src/function/scalar/map/map_keys_values.cpp +97 -0
- package/src/duckdb/src/function/scalar/math/numeric.cpp +14 -17
- package/src/duckdb/src/function/scalar/nested_functions.cpp +3 -0
- package/src/duckdb/src/function/scalar/operators/add.cpp +0 -9
- package/src/duckdb/src/function/scalar/operators/arithmetic.cpp +29 -48
- package/src/duckdb/src/function/scalar/operators/bitwise.cpp +0 -63
- package/src/duckdb/src/function/scalar/operators/multiply.cpp +0 -6
- package/src/duckdb/src/function/scalar/operators/subtract.cpp +0 -6
- package/src/duckdb/src/function/scalar/string/caseconvert.cpp +2 -6
- package/src/duckdb/src/function/scalar/string/instr.cpp +2 -6
- package/src/duckdb/src/function/scalar/string/length.cpp +2 -6
- package/src/duckdb/src/function/scalar/string/like.cpp +2 -6
- package/src/duckdb/src/function/scalar/string/substring.cpp +2 -6
- package/src/duckdb/src/function/scalar/string_functions.cpp +1 -0
- package/src/duckdb/src/function/scalar/struct/struct_extract.cpp +4 -9
- package/src/duckdb/src/function/scalar/struct/struct_insert.cpp +10 -13
- package/src/duckdb/src/function/scalar/struct/struct_pack.cpp +5 -6
- package/src/duckdb/src/function/table/read_csv.cpp +9 -0
- package/src/duckdb/src/function/table/version/pragma_version.cpp +2 -2
- package/src/duckdb/src/function/table_function.cpp +19 -0
- package/src/duckdb/src/include/duckdb/catalog/catalog_entry/table_function_catalog_entry.hpp +6 -8
- package/src/duckdb/src/include/duckdb/common/constants.hpp +0 -19
- package/src/duckdb/src/include/duckdb/common/enums/statement_type.hpp +2 -1
- package/src/duckdb/src/include/duckdb/common/enums/tableref_type.hpp +2 -1
- package/src/duckdb/src/include/duckdb/common/types/bit.hpp +5 -1
- package/src/duckdb/src/include/duckdb/common/types/value.hpp +2 -8
- package/src/duckdb/src/include/duckdb/common/types.hpp +1 -2
- package/src/duckdb/src/include/duckdb/execution/operator/aggregate/physical_perfecthash_aggregate.hpp +1 -1
- package/src/duckdb/src/include/duckdb/function/aggregate/distributive_functions.hpp +5 -0
- package/src/duckdb/src/include/duckdb/function/aggregate_function.hpp +12 -3
- package/src/duckdb/src/include/duckdb/function/scalar/bit_functions.hpp +4 -0
- package/src/duckdb/src/include/duckdb/function/scalar/nested_functions.hpp +12 -0
- package/src/duckdb/src/include/duckdb/function/scalar_function.hpp +2 -2
- package/src/duckdb/src/include/duckdb/function/table_function.hpp +2 -0
- package/src/duckdb/src/include/duckdb/main/capi/capi_internal.hpp +2 -0
- package/src/duckdb/src/include/duckdb/main/config.hpp +3 -0
- package/src/duckdb/src/include/duckdb/main/database.hpp +1 -0
- package/src/duckdb/src/include/duckdb/optimizer/join_order/cardinality_estimator.hpp +2 -2
- package/src/duckdb/src/include/duckdb/parser/common_table_expression_info.hpp +2 -0
- package/src/duckdb/src/include/duckdb/parser/parsed_data/alter_info.hpp +2 -1
- package/src/duckdb/src/include/duckdb/parser/parsed_data/{alter_function_info.hpp → alter_scalar_function_info.hpp} +13 -13
- package/src/duckdb/src/include/duckdb/parser/parsed_data/alter_table_function_info.hpp +47 -0
- package/src/duckdb/src/include/duckdb/parser/parsed_data/create_table_function_info.hpp +2 -1
- package/src/duckdb/src/include/duckdb/parser/query_node.hpp +2 -1
- package/src/duckdb/src/include/duckdb/parser/statement/multi_statement.hpp +28 -0
- package/src/duckdb/src/include/duckdb/parser/tableref/list.hpp +1 -0
- package/src/duckdb/src/include/duckdb/parser/tableref/pivotref.hpp +76 -0
- package/src/duckdb/src/include/duckdb/parser/tokens.hpp +2 -0
- package/src/duckdb/src/include/duckdb/parser/transformer.hpp +28 -0
- package/src/duckdb/src/include/duckdb/planner/bind_context.hpp +2 -0
- package/src/duckdb/src/include/duckdb/planner/binder.hpp +8 -0
- package/src/duckdb/src/include/duckdb/storage/buffer/block_handle.hpp +2 -0
- package/src/duckdb/src/include/duckdb/storage/buffer_manager.hpp +76 -44
- package/src/duckdb/src/include/duckdb/storage/checkpoint/table_data_writer.hpp +3 -2
- package/src/duckdb/src/include/duckdb/storage/compression/chimp/chimp_compress.hpp +2 -2
- package/src/duckdb/src/include/duckdb/storage/compression/chimp/chimp_fetch.hpp +1 -1
- package/src/duckdb/src/include/duckdb/storage/compression/chimp/chimp_scan.hpp +1 -1
- package/src/duckdb/src/include/duckdb/storage/compression/patas/patas_compress.hpp +2 -2
- package/src/duckdb/src/include/duckdb/storage/compression/patas/patas_fetch.hpp +1 -1
- package/src/duckdb/src/include/duckdb/storage/compression/patas/patas_scan.hpp +1 -1
- package/src/duckdb/src/include/duckdb/storage/data_pointer.hpp +5 -2
- package/src/duckdb/src/include/duckdb/storage/data_table.hpp +1 -1
- package/src/duckdb/src/include/duckdb/storage/statistics/base_statistics.hpp +93 -29
- package/src/duckdb/src/include/duckdb/storage/statistics/column_statistics.hpp +22 -3
- package/src/duckdb/src/include/duckdb/storage/statistics/distinct_statistics.hpp +6 -6
- package/src/duckdb/src/include/duckdb/storage/statistics/list_stats.hpp +41 -0
- package/src/duckdb/src/include/duckdb/storage/statistics/node_statistics.hpp +26 -0
- package/src/duckdb/src/include/duckdb/storage/statistics/numeric_stats.hpp +157 -0
- package/src/duckdb/src/include/duckdb/storage/statistics/segment_statistics.hpp +2 -7
- package/src/duckdb/src/include/duckdb/storage/statistics/string_stats.hpp +74 -0
- package/src/duckdb/src/include/duckdb/storage/statistics/struct_stats.hpp +42 -0
- package/src/duckdb/src/include/duckdb/storage/string_uncompressed.hpp +2 -3
- package/src/duckdb/src/include/duckdb/storage/table/column_segment.hpp +2 -2
- package/src/duckdb/src/include/duckdb/storage/table/list_column_data.hpp +1 -1
- package/src/duckdb/src/include/duckdb/storage/table/persistent_table_data.hpp +2 -1
- package/src/duckdb/src/include/duckdb/storage/table/row_group.hpp +4 -3
- package/src/duckdb/src/include/duckdb/storage/table/row_group_collection.hpp +3 -2
- package/src/duckdb/src/include/duckdb/storage/table/scan_state.hpp +2 -0
- package/src/duckdb/src/include/duckdb/storage/table/table_statistics.hpp +5 -0
- package/src/duckdb/src/include/duckdb.h +49 -1
- package/src/duckdb/src/include/duckdb.hpp +0 -1
- package/src/duckdb/src/main/capi/pending-c.cpp +16 -3
- package/src/duckdb/src/main/capi/result-c.cpp +27 -1
- package/src/duckdb/src/main/capi/stream-c.cpp +25 -0
- package/src/duckdb/src/main/client_context.cpp +8 -1
- package/src/duckdb/src/main/config.cpp +66 -1
- package/src/duckdb/src/main/database.cpp +10 -2
- package/src/duckdb/src/optimizer/join_order/cardinality_estimator.cpp +98 -67
- package/src/duckdb/src/optimizer/join_order/join_order_optimizer.cpp +16 -3
- package/src/duckdb/src/optimizer/statistics/expression/propagate_aggregate.cpp +9 -3
- package/src/duckdb/src/optimizer/statistics/expression/propagate_and_compress.cpp +6 -7
- package/src/duckdb/src/optimizer/statistics/expression/propagate_cast.cpp +14 -11
- package/src/duckdb/src/optimizer/statistics/expression/propagate_columnref.cpp +1 -1
- package/src/duckdb/src/optimizer/statistics/expression/propagate_comparison.cpp +13 -15
- package/src/duckdb/src/optimizer/statistics/expression/propagate_conjunction.cpp +0 -1
- package/src/duckdb/src/optimizer/statistics/expression/propagate_constant.cpp +3 -75
- package/src/duckdb/src/optimizer/statistics/expression/propagate_function.cpp +7 -2
- package/src/duckdb/src/optimizer/statistics/expression/propagate_operator.cpp +10 -0
- package/src/duckdb/src/optimizer/statistics/operator/propagate_aggregate.cpp +2 -3
- package/src/duckdb/src/optimizer/statistics/operator/propagate_filter.cpp +28 -31
- package/src/duckdb/src/optimizer/statistics/operator/propagate_join.cpp +4 -5
- package/src/duckdb/src/optimizer/statistics/operator/propagate_set_operation.cpp +3 -3
- package/src/duckdb/src/optimizer/statistics_propagator.cpp +1 -1
- package/src/duckdb/src/parser/parsed_data/alter_info.cpp +7 -3
- package/src/duckdb/src/parser/parsed_data/alter_scalar_function_info.cpp +56 -0
- package/src/duckdb/src/parser/parsed_data/alter_table_function_info.cpp +51 -0
- package/src/duckdb/src/parser/parsed_data/create_scalar_function_info.cpp +3 -2
- package/src/duckdb/src/parser/parsed_data/create_table_function_info.cpp +6 -0
- package/src/duckdb/src/parser/parsed_expression_iterator.cpp +8 -0
- package/src/duckdb/src/parser/query_node.cpp +1 -1
- package/src/duckdb/src/parser/statement/multi_statement.cpp +18 -0
- package/src/duckdb/src/parser/tableref/pivotref.cpp +296 -0
- package/src/duckdb/src/parser/tableref.cpp +3 -0
- package/src/duckdb/src/parser/transform/helpers/transform_alias.cpp +12 -6
- package/src/duckdb/src/parser/transform/helpers/transform_cte.cpp +24 -0
- package/src/duckdb/src/parser/transform/statement/transform_create_function.cpp +4 -0
- package/src/duckdb/src/parser/transform/statement/transform_create_view.cpp +4 -0
- package/src/duckdb/src/parser/transform/statement/transform_pivot_stmt.cpp +150 -0
- package/src/duckdb/src/parser/transform/statement/transform_select.cpp +8 -0
- package/src/duckdb/src/parser/transform/statement/transform_select_node.cpp +1 -1
- package/src/duckdb/src/parser/transform/tableref/transform_join.cpp +4 -0
- package/src/duckdb/src/parser/transform/tableref/transform_pivot.cpp +105 -0
- package/src/duckdb/src/parser/transform/tableref/transform_tableref.cpp +2 -0
- package/src/duckdb/src/parser/transformer.cpp +15 -3
- package/src/duckdb/src/planner/bind_context.cpp +16 -0
- package/src/duckdb/src/planner/binder/query_node/bind_select_node.cpp +11 -3
- package/src/duckdb/src/planner/binder/query_node/plan_select_node.cpp +0 -1
- package/src/duckdb/src/planner/binder/statement/bind_create.cpp +1 -1
- package/src/duckdb/src/planner/binder/statement/bind_logical_plan.cpp +17 -0
- package/src/duckdb/src/planner/binder/tableref/bind_joinref.cpp +9 -0
- package/src/duckdb/src/planner/binder/tableref/bind_pivot.cpp +365 -0
- package/src/duckdb/src/planner/binder.cpp +7 -1
- package/src/duckdb/src/planner/bound_result_modifier.cpp +1 -1
- package/src/duckdb/src/planner/expression/bound_window_expression.cpp +1 -1
- package/src/duckdb/src/planner/filter/constant_filter.cpp +4 -6
- package/src/duckdb/src/planner/pragma_handler.cpp +10 -2
- package/src/duckdb/src/storage/buffer_manager.cpp +44 -46
- package/src/duckdb/src/storage/checkpoint/row_group_writer.cpp +1 -1
- package/src/duckdb/src/storage/checkpoint/table_data_reader.cpp +1 -4
- package/src/duckdb/src/storage/checkpoint/table_data_writer.cpp +4 -4
- package/src/duckdb/src/storage/compression/bitpacking.cpp +28 -24
- package/src/duckdb/src/storage/compression/fixed_size_uncompressed.cpp +43 -45
- package/src/duckdb/src/storage/compression/numeric_constant.cpp +9 -10
- package/src/duckdb/src/storage/compression/patas.cpp +1 -1
- package/src/duckdb/src/storage/compression/rle.cpp +19 -15
- package/src/duckdb/src/storage/compression/validity_uncompressed.cpp +5 -5
- package/src/duckdb/src/storage/data_table.cpp +4 -6
- package/src/duckdb/src/storage/statistics/base_statistics.cpp +373 -128
- package/src/duckdb/src/storage/statistics/column_statistics.cpp +58 -3
- package/src/duckdb/src/storage/statistics/distinct_statistics.cpp +4 -9
- package/src/duckdb/src/storage/statistics/list_stats.cpp +117 -0
- package/src/duckdb/src/storage/statistics/numeric_stats.cpp +529 -0
- package/src/duckdb/src/storage/statistics/segment_statistics.cpp +2 -11
- package/src/duckdb/src/storage/statistics/string_stats.cpp +273 -0
- package/src/duckdb/src/storage/statistics/struct_stats.cpp +131 -0
- package/src/duckdb/src/storage/storage_info.cpp +1 -1
- package/src/duckdb/src/storage/table/column_checkpoint_state.cpp +3 -4
- package/src/duckdb/src/storage/table/column_data.cpp +16 -11
- package/src/duckdb/src/storage/table/column_data_checkpointer.cpp +2 -3
- package/src/duckdb/src/storage/table/column_segment.cpp +6 -8
- package/src/duckdb/src/storage/table/list_column_data.cpp +39 -58
- package/src/duckdb/src/storage/table/row_group.cpp +24 -23
- package/src/duckdb/src/storage/table/row_group_collection.cpp +12 -12
- package/src/duckdb/src/storage/table/standard_column_data.cpp +6 -6
- package/src/duckdb/src/storage/table/struct_column_data.cpp +15 -16
- package/src/duckdb/src/storage/table/table_statistics.cpp +27 -7
- package/src/duckdb/src/storage/table/update_segment.cpp +10 -12
- package/src/duckdb/third_party/libpg_query/include/nodes/nodes.hpp +3 -0
- package/src/duckdb/third_party/libpg_query/include/nodes/parsenodes.hpp +34 -1
- package/src/duckdb/third_party/libpg_query/include/parser/gram.hpp +1020 -530
- package/src/duckdb/third_party/libpg_query/include/parser/kwlist.hpp +7 -0
- package/src/duckdb/third_party/libpg_query/src_backend_parser_gram.cpp +23560 -22737
- package/src/duckdb/ub_src_function_aggregate_distributive.cpp +2 -0
- package/src/duckdb/ub_src_function_scalar_bit.cpp +2 -0
- package/src/duckdb/ub_src_function_scalar_map.cpp +4 -0
- package/src/duckdb/ub_src_main_capi.cpp +2 -0
- package/src/duckdb/ub_src_parser_parsed_data.cpp +4 -2
- package/src/duckdb/ub_src_parser_statement.cpp +2 -0
- package/src/duckdb/ub_src_parser_tableref.cpp +2 -0
- package/src/duckdb/ub_src_parser_transform_statement.cpp +2 -0
- package/src/duckdb/ub_src_parser_transform_tableref.cpp +2 -0
- package/src/duckdb/ub_src_planner_binder_tableref.cpp +2 -0
- package/src/duckdb/ub_src_storage_statistics.cpp +4 -6
- package/src/duckdb/src/include/duckdb/main/loadable_extension.hpp +0 -59
- package/src/duckdb/src/include/duckdb/storage/statistics/list_statistics.hpp +0 -36
- package/src/duckdb/src/include/duckdb/storage/statistics/numeric_statistics.hpp +0 -75
- package/src/duckdb/src/include/duckdb/storage/statistics/string_statistics.hpp +0 -49
- package/src/duckdb/src/include/duckdb/storage/statistics/struct_statistics.hpp +0 -36
- package/src/duckdb/src/include/duckdb/storage/statistics/validity_statistics.hpp +0 -45
- package/src/duckdb/src/parser/parsed_data/alter_function_info.cpp +0 -55
- package/src/duckdb/src/storage/statistics/list_statistics.cpp +0 -94
- package/src/duckdb/src/storage/statistics/numeric_statistics.cpp +0 -307
- package/src/duckdb/src/storage/statistics/string_statistics.cpp +0 -220
- package/src/duckdb/src/storage/statistics/struct_statistics.cpp +0 -108
- package/src/duckdb/src/storage/statistics/validity_statistics.cpp +0 -91
@@ -0,0 +1,157 @@
|
|
1
|
+
//===----------------------------------------------------------------------===//
|
2
|
+
// DuckDB
|
3
|
+
//
|
4
|
+
// duckdb/storage/statistics/numeric_stats.hpp
|
5
|
+
//
|
6
|
+
//
|
7
|
+
//===----------------------------------------------------------------------===//
|
8
|
+
|
9
|
+
#pragma once
|
10
|
+
|
11
|
+
#include "duckdb/common/common.hpp"
|
12
|
+
#include "duckdb/common/exception.hpp"
|
13
|
+
#include "duckdb/common/types/hugeint.hpp"
|
14
|
+
#include "duckdb/common/enums/filter_propagate_result.hpp"
|
15
|
+
#include "duckdb/common/enums/expression_type.hpp"
|
16
|
+
#include "duckdb/common/operator/comparison_operators.hpp"
|
17
|
+
#include "duckdb/common/types/value.hpp"
|
18
|
+
|
19
|
+
namespace duckdb {
|
20
|
+
class BaseStatistics;
|
21
|
+
class FieldWriter;
|
22
|
+
class FieldReader;
|
23
|
+
struct SelectionVector;
|
24
|
+
class Vector;
|
25
|
+
|
26
|
+
struct NumericValueUnion {
|
27
|
+
union Val {
|
28
|
+
int8_t boolean;
|
29
|
+
int8_t tinyint;
|
30
|
+
int16_t smallint;
|
31
|
+
int32_t integer;
|
32
|
+
int64_t bigint;
|
33
|
+
uint8_t utinyint;
|
34
|
+
uint16_t usmallint;
|
35
|
+
uint32_t uinteger;
|
36
|
+
uint64_t ubigint;
|
37
|
+
hugeint_t hugeint;
|
38
|
+
float float_;
|
39
|
+
double double_;
|
40
|
+
} value_;
|
41
|
+
|
42
|
+
template <class T>
|
43
|
+
T &GetReferenceUnsafe() {
|
44
|
+
throw InternalException("NumericValueUnion::GetReferenceUnsafe called on unsupported type");
|
45
|
+
}
|
46
|
+
};
|
47
|
+
|
48
|
+
struct NumericStatsData {
|
49
|
+
//! Whether or not the value has a max value
|
50
|
+
bool has_min;
|
51
|
+
//! Whether or not the segment has a min value
|
52
|
+
bool has_max;
|
53
|
+
//! The minimum value of the segment
|
54
|
+
NumericValueUnion min;
|
55
|
+
//! The maximum value of the segment
|
56
|
+
NumericValueUnion max;
|
57
|
+
};
|
58
|
+
|
59
|
+
struct NumericStats {
|
60
|
+
//! Unknown statistics - i.e. "has_min" is false, "has_max" is false
|
61
|
+
DUCKDB_API static BaseStatistics CreateUnknown(LogicalType type);
|
62
|
+
//! Empty statistics - i.e. "min = MaxValue<type>, max = MinValue<type>"
|
63
|
+
DUCKDB_API static BaseStatistics CreateEmpty(LogicalType type);
|
64
|
+
|
65
|
+
//! Returns true if the stats has a constant value
|
66
|
+
DUCKDB_API static bool IsConstant(const BaseStatistics &stats);
|
67
|
+
//! Returns true if the stats has both a min and max value defined
|
68
|
+
DUCKDB_API static bool HasMinMax(const BaseStatistics &stats);
|
69
|
+
//! Returns true if the stats has a min value defined
|
70
|
+
DUCKDB_API static bool HasMin(const BaseStatistics &stats);
|
71
|
+
//! Returns true if the stats has a max value defined
|
72
|
+
DUCKDB_API static bool HasMax(const BaseStatistics &stats);
|
73
|
+
//! Returns the min value - throws an exception if there is no min value
|
74
|
+
DUCKDB_API static Value Min(const BaseStatistics &stats);
|
75
|
+
//! Returns the max value - throws an exception if there is no max value
|
76
|
+
DUCKDB_API static Value Max(const BaseStatistics &stats);
|
77
|
+
//! Sets the min value of the statistics
|
78
|
+
DUCKDB_API static void SetMin(BaseStatistics &stats, const Value &val);
|
79
|
+
//! Sets the max value of the statistics
|
80
|
+
DUCKDB_API static void SetMax(BaseStatistics &stats, const Value &val);
|
81
|
+
|
82
|
+
//! Check whether or not a given comparison with a constant could possibly be satisfied by rows given the statistics
|
83
|
+
DUCKDB_API static FilterPropagateResult CheckZonemap(const BaseStatistics &stats, ExpressionType comparison_type,
|
84
|
+
const Value &constant);
|
85
|
+
|
86
|
+
DUCKDB_API static void Merge(BaseStatistics &stats, const BaseStatistics &other_p);
|
87
|
+
|
88
|
+
DUCKDB_API static void Serialize(const BaseStatistics &stats, FieldWriter &writer);
|
89
|
+
DUCKDB_API static BaseStatistics Deserialize(FieldReader &reader, LogicalType type);
|
90
|
+
|
91
|
+
DUCKDB_API static string ToString(const BaseStatistics &stats);
|
92
|
+
|
93
|
+
template <class T>
|
94
|
+
static inline void UpdateValue(T new_value, T &min, T &max) {
|
95
|
+
if (LessThan::Operation(new_value, min)) {
|
96
|
+
min = new_value;
|
97
|
+
}
|
98
|
+
if (GreaterThan::Operation(new_value, max)) {
|
99
|
+
max = new_value;
|
100
|
+
}
|
101
|
+
}
|
102
|
+
|
103
|
+
template <class T>
|
104
|
+
static inline void Update(BaseStatistics &stats, T new_value) {
|
105
|
+
auto &nstats = NumericStats::GetDataUnsafe(stats);
|
106
|
+
UpdateValue<T>(new_value, nstats.min.GetReferenceUnsafe<T>(), nstats.max.GetReferenceUnsafe<T>());
|
107
|
+
}
|
108
|
+
|
109
|
+
static void Verify(const BaseStatistics &stats, Vector &vector, const SelectionVector &sel, idx_t count);
|
110
|
+
|
111
|
+
template <class T>
|
112
|
+
static T GetMinUnsafe(const BaseStatistics &stats) {
|
113
|
+
return NumericStats::Min(stats).template GetValueUnsafe<T>();
|
114
|
+
}
|
115
|
+
template <class T>
|
116
|
+
static T GetMaxUnsafe(const BaseStatistics &stats) {
|
117
|
+
return NumericStats::Max(stats).template GetValueUnsafe<T>();
|
118
|
+
}
|
119
|
+
|
120
|
+
private:
|
121
|
+
static NumericStatsData &GetDataUnsafe(BaseStatistics &stats);
|
122
|
+
static const NumericStatsData &GetDataUnsafe(const BaseStatistics &stats);
|
123
|
+
static Value MinOrNull(const BaseStatistics &stats);
|
124
|
+
static Value MaxOrNull(const BaseStatistics &stats);
|
125
|
+
template <class T>
|
126
|
+
static void TemplatedVerify(const BaseStatistics &stats, Vector &vector, const SelectionVector &sel, idx_t count);
|
127
|
+
};
|
128
|
+
|
129
|
+
template <>
|
130
|
+
void NumericStats::Update<interval_t>(BaseStatistics &stats, interval_t new_value);
|
131
|
+
template <>
|
132
|
+
void NumericStats::Update<list_entry_t>(BaseStatistics &stats, list_entry_t new_value);
|
133
|
+
|
134
|
+
template <>
|
135
|
+
int8_t &NumericValueUnion::GetReferenceUnsafe();
|
136
|
+
template <>
|
137
|
+
int16_t &NumericValueUnion::GetReferenceUnsafe();
|
138
|
+
template <>
|
139
|
+
int32_t &NumericValueUnion::GetReferenceUnsafe();
|
140
|
+
template <>
|
141
|
+
int64_t &NumericValueUnion::GetReferenceUnsafe();
|
142
|
+
template <>
|
143
|
+
hugeint_t &NumericValueUnion::GetReferenceUnsafe();
|
144
|
+
template <>
|
145
|
+
uint8_t &NumericValueUnion::GetReferenceUnsafe();
|
146
|
+
template <>
|
147
|
+
uint16_t &NumericValueUnion::GetReferenceUnsafe();
|
148
|
+
template <>
|
149
|
+
uint32_t &NumericValueUnion::GetReferenceUnsafe();
|
150
|
+
template <>
|
151
|
+
uint64_t &NumericValueUnion::GetReferenceUnsafe();
|
152
|
+
template <>
|
153
|
+
float &NumericValueUnion::GetReferenceUnsafe();
|
154
|
+
template <>
|
155
|
+
double &NumericValueUnion::GetReferenceUnsafe();
|
156
|
+
|
157
|
+
} // namespace duckdb
|
@@ -17,15 +17,10 @@ namespace duckdb {
|
|
17
17
|
class SegmentStatistics {
|
18
18
|
public:
|
19
19
|
SegmentStatistics(LogicalType type);
|
20
|
-
SegmentStatistics(
|
21
|
-
|
22
|
-
LogicalType type;
|
20
|
+
SegmentStatistics(BaseStatistics statistics);
|
23
21
|
|
24
22
|
//! Type-specific statistics of the segment
|
25
|
-
|
26
|
-
|
27
|
-
public:
|
28
|
-
void Reset();
|
23
|
+
BaseStatistics statistics;
|
29
24
|
};
|
30
25
|
|
31
26
|
} // namespace duckdb
|
@@ -0,0 +1,74 @@
|
|
1
|
+
//===----------------------------------------------------------------------===//
|
2
|
+
// DuckDB
|
3
|
+
//
|
4
|
+
// duckdb/storage/statistics/string_stats.hpp
|
5
|
+
//
|
6
|
+
//
|
7
|
+
//===----------------------------------------------------------------------===//
|
8
|
+
|
9
|
+
#pragma once
|
10
|
+
|
11
|
+
#include "duckdb/common/common.hpp"
|
12
|
+
#include "duckdb/common/exception.hpp"
|
13
|
+
#include "duckdb/common/types/hugeint.hpp"
|
14
|
+
#include "duckdb/common/enums/filter_propagate_result.hpp"
|
15
|
+
#include "duckdb/common/enums/expression_type.hpp"
|
16
|
+
#include "duckdb/common/operator/comparison_operators.hpp"
|
17
|
+
|
18
|
+
namespace duckdb {
|
19
|
+
class BaseStatistics;
|
20
|
+
class FieldWriter;
|
21
|
+
class FieldReader;
|
22
|
+
struct SelectionVector;
|
23
|
+
class Vector;
|
24
|
+
|
25
|
+
struct StringStatsData {
|
26
|
+
constexpr static uint32_t MAX_STRING_MINMAX_SIZE = 8;
|
27
|
+
|
28
|
+
//! The minimum value of the segment, potentially truncated
|
29
|
+
data_t min[MAX_STRING_MINMAX_SIZE];
|
30
|
+
//! The maximum value of the segment, potentially truncated
|
31
|
+
data_t max[MAX_STRING_MINMAX_SIZE];
|
32
|
+
//! Whether or not the column can contain unicode characters
|
33
|
+
bool has_unicode;
|
34
|
+
//! Whether or not the maximum string length is known
|
35
|
+
bool has_max_string_length;
|
36
|
+
//! The maximum string length in bytes
|
37
|
+
uint32_t max_string_length;
|
38
|
+
};
|
39
|
+
|
40
|
+
struct StringStats {
|
41
|
+
//! Unknown statistics - i.e. "has_unicode" is true, "max_string_length" is unknown, "min" is \0, max is \xFF
|
42
|
+
DUCKDB_API static BaseStatistics CreateUnknown(LogicalType type);
|
43
|
+
//! Empty statistics - i.e. "has_unicode" is false, "max_string_length" is 0, "min" is \xFF, max is \x00
|
44
|
+
DUCKDB_API static BaseStatistics CreateEmpty(LogicalType type);
|
45
|
+
//! Whether or not the statistics have a maximum string length defined
|
46
|
+
DUCKDB_API static bool HasMaxStringLength(const BaseStatistics &stats);
|
47
|
+
//! Returns the maximum string length, or throws an exception if !HasMaxStringLength()
|
48
|
+
DUCKDB_API static uint32_t MaxStringLength(const BaseStatistics &stats);
|
49
|
+
//! Whether or not the strings can contain unicode
|
50
|
+
DUCKDB_API static bool CanContainUnicode(const BaseStatistics &stats);
|
51
|
+
|
52
|
+
//! Resets the max string length so HasMaxStringLength() is false
|
53
|
+
DUCKDB_API static void ResetMaxStringLength(BaseStatistics &stats);
|
54
|
+
//! FIXME: make this part of Set on statistics
|
55
|
+
DUCKDB_API static void SetContainsUnicode(BaseStatistics &stats);
|
56
|
+
|
57
|
+
DUCKDB_API static void Serialize(const BaseStatistics &stats, FieldWriter &writer);
|
58
|
+
DUCKDB_API static BaseStatistics Deserialize(FieldReader &reader, LogicalType type);
|
59
|
+
|
60
|
+
DUCKDB_API static string ToString(const BaseStatistics &stats);
|
61
|
+
|
62
|
+
DUCKDB_API static FilterPropagateResult CheckZonemap(const BaseStatistics &stats, ExpressionType comparison_type,
|
63
|
+
const string &value);
|
64
|
+
|
65
|
+
DUCKDB_API static void Update(BaseStatistics &stats, const string_t &value);
|
66
|
+
DUCKDB_API static void Merge(BaseStatistics &stats, const BaseStatistics &other);
|
67
|
+
DUCKDB_API static void Verify(const BaseStatistics &stats, Vector &vector, const SelectionVector &sel, idx_t count);
|
68
|
+
|
69
|
+
private:
|
70
|
+
static StringStatsData &GetDataUnsafe(BaseStatistics &stats);
|
71
|
+
static const StringStatsData &GetDataUnsafe(const BaseStatistics &stats);
|
72
|
+
};
|
73
|
+
|
74
|
+
} // namespace duckdb
|
@@ -0,0 +1,42 @@
|
|
1
|
+
//===----------------------------------------------------------------------===//
|
2
|
+
// DuckDB
|
3
|
+
//
|
4
|
+
// duckdb/storage/statistics/struct_stats.hpp
|
5
|
+
//
|
6
|
+
//
|
7
|
+
//===----------------------------------------------------------------------===//
|
8
|
+
|
9
|
+
#pragma once
|
10
|
+
|
11
|
+
#include "duckdb/common/common.hpp"
|
12
|
+
#include "duckdb/common/exception.hpp"
|
13
|
+
|
14
|
+
namespace duckdb {
|
15
|
+
class BaseStatistics;
|
16
|
+
class FieldWriter;
|
17
|
+
class FieldReader;
|
18
|
+
struct SelectionVector;
|
19
|
+
class Vector;
|
20
|
+
|
21
|
+
struct StructStats {
|
22
|
+
DUCKDB_API static void Construct(BaseStatistics &stats);
|
23
|
+
DUCKDB_API static BaseStatistics CreateUnknown(LogicalType type);
|
24
|
+
DUCKDB_API static BaseStatistics CreateEmpty(LogicalType type);
|
25
|
+
|
26
|
+
DUCKDB_API static const BaseStatistics *GetChildStats(const BaseStatistics &stats);
|
27
|
+
DUCKDB_API static const BaseStatistics &GetChildStats(const BaseStatistics &stats, idx_t i);
|
28
|
+
DUCKDB_API static BaseStatistics &GetChildStats(BaseStatistics &stats, idx_t i);
|
29
|
+
DUCKDB_API static void SetChildStats(BaseStatistics &stats, idx_t i, const BaseStatistics &new_stats);
|
30
|
+
DUCKDB_API static void SetChildStats(BaseStatistics &stats, idx_t i, unique_ptr<BaseStatistics> new_stats);
|
31
|
+
|
32
|
+
DUCKDB_API static void Serialize(const BaseStatistics &stats, FieldWriter &writer);
|
33
|
+
DUCKDB_API static BaseStatistics Deserialize(FieldReader &reader, LogicalType type);
|
34
|
+
|
35
|
+
DUCKDB_API static string ToString(const BaseStatistics &stats);
|
36
|
+
|
37
|
+
DUCKDB_API static void Merge(BaseStatistics &stats, const BaseStatistics &other);
|
38
|
+
DUCKDB_API static void Copy(BaseStatistics &stats, const BaseStatistics &other);
|
39
|
+
DUCKDB_API static void Verify(const BaseStatistics &stats, Vector &vector, const SelectionVector &sel, idx_t count);
|
40
|
+
};
|
41
|
+
|
42
|
+
} // namespace duckdb
|
@@ -9,7 +9,7 @@
|
|
9
9
|
#include "duckdb/storage/buffer_manager.hpp"
|
10
10
|
#include "duckdb/storage/checkpoint/string_checkpoint_state.hpp"
|
11
11
|
#include "duckdb/storage/segment/uncompressed.hpp"
|
12
|
-
|
12
|
+
|
13
13
|
#include "duckdb/storage/string_uncompressed.hpp"
|
14
14
|
#include "duckdb/storage/table/append_state.hpp"
|
15
15
|
#include "duckdb/storage/table/column_segment.hpp"
|
@@ -173,8 +173,7 @@ public:
|
|
173
173
|
|
174
174
|
public:
|
175
175
|
static inline void UpdateStringStats(SegmentStatistics &stats, const string_t &new_value) {
|
176
|
-
|
177
|
-
sstats.Update(new_value);
|
176
|
+
StringStats::Update(stats.statistics, new_value);
|
178
177
|
}
|
179
178
|
|
180
179
|
static void SetDictionary(ColumnSegment &segment, BufferHandle &handle, StringDictionaryContainer dict);
|
@@ -57,7 +57,7 @@ public:
|
|
57
57
|
static unique_ptr<ColumnSegment> CreatePersistentSegment(DatabaseInstance &db, BlockManager &block_manager,
|
58
58
|
block_id_t id, idx_t offset, const LogicalType &type_p,
|
59
59
|
idx_t start, idx_t count, CompressionType compression_type,
|
60
|
-
|
60
|
+
BaseStatistics statistics);
|
61
61
|
static unique_ptr<ColumnSegment> CreateTransientSegment(DatabaseInstance &db, const LogicalType &type, idx_t start,
|
62
62
|
idx_t segment_size = Storage::BLOCK_SIZE);
|
63
63
|
static unique_ptr<ColumnSegment> CreateSegment(ColumnSegment &other, idx_t start);
|
@@ -124,7 +124,7 @@ public:
|
|
124
124
|
|
125
125
|
public:
|
126
126
|
ColumnSegment(DatabaseInstance &db, shared_ptr<BlockHandle> block, LogicalType type, ColumnSegmentType segment_type,
|
127
|
-
idx_t start, idx_t count, CompressionFunction *function,
|
127
|
+
idx_t start, idx_t count, CompressionFunction *function, BaseStatistics statistics,
|
128
128
|
block_id_t block_id, idx_t offset, idx_t segment_size);
|
129
129
|
ColumnSegment(ColumnSegment &other, idx_t start);
|
130
130
|
|
@@ -12,6 +12,7 @@
|
|
12
12
|
#include "duckdb/common/vector.hpp"
|
13
13
|
#include "duckdb/storage/table/segment_tree.hpp"
|
14
14
|
#include "duckdb/storage/data_pointer.hpp"
|
15
|
+
#include "duckdb/storage/table/table_statistics.hpp"
|
15
16
|
|
16
17
|
namespace duckdb {
|
17
18
|
class BaseStatistics;
|
@@ -22,7 +23,7 @@ public:
|
|
22
23
|
~PersistentTableData();
|
23
24
|
|
24
25
|
vector<RowGroupPointer> row_groups;
|
25
|
-
|
26
|
+
TableStatistics table_stats;
|
26
27
|
};
|
27
28
|
|
28
29
|
} // namespace duckdb
|
@@ -29,6 +29,7 @@ struct DataTableInfo;
|
|
29
29
|
class ExpressionExecutor;
|
30
30
|
class RowGroupWriter;
|
31
31
|
class UpdateSegment;
|
32
|
+
class TableStatistics;
|
32
33
|
class TableStorageInfo;
|
33
34
|
class Vector;
|
34
35
|
struct ColumnCheckpointState;
|
@@ -38,7 +39,7 @@ struct VersionNode;
|
|
38
39
|
|
39
40
|
struct RowGroupWriteData {
|
40
41
|
vector<unique_ptr<ColumnCheckpointState>> states;
|
41
|
-
vector<
|
42
|
+
vector<BaseStatistics> statistics;
|
42
43
|
};
|
43
44
|
|
44
45
|
class RowGroup : public SegmentBase {
|
@@ -69,7 +70,7 @@ private:
|
|
69
70
|
//! The column data of the row_group
|
70
71
|
vector<shared_ptr<ColumnData>> columns;
|
71
72
|
//! The segment statistics for each of the columns
|
72
|
-
vector<
|
73
|
+
vector<SegmentStatistics> stats;
|
73
74
|
|
74
75
|
public:
|
75
76
|
DatabaseInstance &GetDatabase();
|
@@ -132,7 +133,7 @@ public:
|
|
132
133
|
idx_t Delete(TransactionData transaction, DataTable *table, row_t *row_ids, idx_t count);
|
133
134
|
|
134
135
|
RowGroupWriteData WriteToDisk(PartialBlockManager &manager, const vector<CompressionType> &compression_types);
|
135
|
-
RowGroupPointer Checkpoint(RowGroupWriter &writer,
|
136
|
+
RowGroupPointer Checkpoint(RowGroupWriter &writer, TableStatistics &global_stats);
|
136
137
|
static void Serialize(RowGroupPointer &pointer, Serializer &serializer);
|
137
138
|
static RowGroupPointer Deserialize(Deserializer &source, const ColumnList &columns);
|
138
139
|
|
@@ -78,7 +78,7 @@ public:
|
|
78
78
|
void UpdateColumn(TransactionData transaction, Vector &row_ids, const vector<column_t> &column_path,
|
79
79
|
DataChunk &updates);
|
80
80
|
|
81
|
-
void Checkpoint(TableDataWriter &writer,
|
81
|
+
void Checkpoint(TableDataWriter &writer, TableStatistics &global_stats);
|
82
82
|
|
83
83
|
void CommitDropColumn(idx_t index);
|
84
84
|
void CommitDropTable();
|
@@ -93,8 +93,9 @@ public:
|
|
93
93
|
vector<column_t> bound_columns, Expression &cast_expr);
|
94
94
|
void VerifyNewConstraint(DataTable &parent, const BoundConstraint &constraint);
|
95
95
|
|
96
|
+
void CopyStats(TableStatistics &stats);
|
96
97
|
unique_ptr<BaseStatistics> CopyStats(column_t column_id);
|
97
|
-
void
|
98
|
+
void SetDistinct(column_t column_id, unique_ptr<DistinctStatistics> distinct_stats);
|
98
99
|
|
99
100
|
private:
|
100
101
|
bool IsEmpty(SegmentLock &) const;
|
@@ -64,6 +64,8 @@ struct ColumnScanState {
|
|
64
64
|
//! We initialize one SegmentScanState per segment, however, if scanning a DataChunk requires us to scan over more
|
65
65
|
//! than one Segment, we need to keep the scan states of the previous segments around
|
66
66
|
vector<unique_ptr<SegmentScanState>> previous_states;
|
67
|
+
//! The last read offset in the child state (used for LIST columns only)
|
68
|
+
idx_t last_offset = 0;
|
67
69
|
|
68
70
|
public:
|
69
71
|
//! Move the scan state forward by "count" rows (including all child states)
|
@@ -14,6 +14,7 @@
|
|
14
14
|
#include "duckdb/storage/statistics/column_statistics.hpp"
|
15
15
|
|
16
16
|
namespace duckdb {
|
17
|
+
class ColumnList;
|
17
18
|
class PersistentTableData;
|
18
19
|
|
19
20
|
class TableStatisticsLock {
|
@@ -38,6 +39,7 @@ public:
|
|
38
39
|
void MergeStats(idx_t i, BaseStatistics &stats);
|
39
40
|
void MergeStats(TableStatisticsLock &lock, idx_t i, BaseStatistics &stats);
|
40
41
|
|
42
|
+
void CopyStats(TableStatistics &other);
|
41
43
|
unique_ptr<BaseStatistics> CopyStats(idx_t i);
|
42
44
|
ColumnStatistics &GetStats(idx_t i);
|
43
45
|
|
@@ -45,6 +47,9 @@ public:
|
|
45
47
|
|
46
48
|
unique_ptr<TableStatisticsLock> GetLock();
|
47
49
|
|
50
|
+
void Serialize(Serializer &serializer);
|
51
|
+
void Deserialize(Deserializer &source, ColumnList &columns);
|
52
|
+
|
48
53
|
private:
|
49
54
|
//! The statistics lock
|
50
55
|
mutex stats_lock;
|
@@ -35,7 +35,10 @@
|
|
35
35
|
#endif
|
36
36
|
#endif
|
37
37
|
|
38
|
-
//
|
38
|
+
// API versions
|
39
|
+
// if no explicit API version is defined, the latest API version is used
|
40
|
+
// Note that using older API versions (i.e. not using DUCKDB_API_LATEST) is deprecated.
|
41
|
+
// These will not be supported long-term, and will be removed in future versions.
|
39
42
|
#ifndef DUCKDB_API_0_3_1
|
40
43
|
#define DUCKDB_API_0_3_1 1
|
41
44
|
#endif
|
@@ -570,6 +573,14 @@ Use `duckdb_result_chunk_count` to figure out how many chunks there are in the r
|
|
570
573
|
*/
|
571
574
|
DUCKDB_API duckdb_data_chunk duckdb_result_get_chunk(duckdb_result result, idx_t chunk_index);
|
572
575
|
|
576
|
+
/*!
|
577
|
+
Checks if the type of the internal result is StreamQueryResult.
|
578
|
+
|
579
|
+
* result: The result object to check.
|
580
|
+
* returns: Whether or not the result object is of the type StreamQueryResult
|
581
|
+
*/
|
582
|
+
DUCKDB_API bool duckdb_result_is_streaming(duckdb_result result);
|
583
|
+
|
573
584
|
/*!
|
574
585
|
Returns the number of data chunks present in the result.
|
575
586
|
|
@@ -1106,6 +1117,21 @@ Note that after calling `duckdb_pending_prepared`, the pending result should alw
|
|
1106
1117
|
DUCKDB_API duckdb_state duckdb_pending_prepared(duckdb_prepared_statement prepared_statement,
|
1107
1118
|
duckdb_pending_result *out_result);
|
1108
1119
|
|
1120
|
+
/*!
|
1121
|
+
Executes the prepared statement with the given bound parameters, and returns a pending result.
|
1122
|
+
This pending result will create a streaming duckdb_result when executed.
|
1123
|
+
The pending result represents an intermediate structure for a query that is not yet fully executed.
|
1124
|
+
|
1125
|
+
Note that after calling `duckdb_pending_prepared_streaming`, the pending result should always be destroyed using
|
1126
|
+
`duckdb_destroy_pending`, even if this function returns DuckDBError.
|
1127
|
+
|
1128
|
+
* prepared_statement: The prepared statement to execute.
|
1129
|
+
* out_result: The pending query result.
|
1130
|
+
* returns: `DuckDBSuccess` on success or `DuckDBError` on failure.
|
1131
|
+
*/
|
1132
|
+
DUCKDB_API duckdb_state duckdb_pending_prepared_streaming(duckdb_prepared_statement prepared_statement,
|
1133
|
+
duckdb_pending_result *out_result);
|
1134
|
+
|
1109
1135
|
/*!
|
1110
1136
|
Closes the pending result and de-allocates all memory allocated for the result.
|
1111
1137
|
|
@@ -2319,6 +2345,28 @@ Returns true if execution of the current query is finished.
|
|
2319
2345
|
*/
|
2320
2346
|
DUCKDB_API bool duckdb_execution_is_finished(duckdb_connection con);
|
2321
2347
|
|
2348
|
+
//===--------------------------------------------------------------------===//
|
2349
|
+
// Streaming Result Interface
|
2350
|
+
//===--------------------------------------------------------------------===//
|
2351
|
+
|
2352
|
+
/*!
|
2353
|
+
Fetches a data chunk from the (streaming) duckdb_result. This function should be called repeatedly until the result is
|
2354
|
+
exhausted.
|
2355
|
+
|
2356
|
+
The result must be destroyed with `duckdb_destroy_data_chunk`.
|
2357
|
+
|
2358
|
+
This function can only be used on duckdb_results created with 'duckdb_pending_prepared_streaming'
|
2359
|
+
|
2360
|
+
If this function is used, none of the other result functions can be used and vice versa (i.e. this function cannot be
|
2361
|
+
mixed with the legacy result functions or the materialized result functions).
|
2362
|
+
|
2363
|
+
It is not known beforehand how many chunks will be returned by this result.
|
2364
|
+
|
2365
|
+
* result: The result object to fetch the data chunk from.
|
2366
|
+
* returns: The resulting data chunk. Returns `NULL` if the result has an error.
|
2367
|
+
*/
|
2368
|
+
DUCKDB_API duckdb_data_chunk duckdb_stream_fetch_chunk(duckdb_result result);
|
2369
|
+
|
2322
2370
|
#ifdef __cplusplus
|
2323
2371
|
}
|
2324
2372
|
#endif
|
@@ -9,14 +9,16 @@ using duckdb::PendingQueryResult;
|
|
9
9
|
using duckdb::PendingStatementWrapper;
|
10
10
|
using duckdb::PreparedStatementWrapper;
|
11
11
|
|
12
|
-
duckdb_state
|
12
|
+
duckdb_state duckdb_pending_prepared_internal(duckdb_prepared_statement prepared_statement,
|
13
|
+
duckdb_pending_result *out_result, bool allow_streaming) {
|
13
14
|
if (!prepared_statement || !out_result) {
|
14
15
|
return DuckDBError;
|
15
16
|
}
|
16
17
|
auto wrapper = (PreparedStatementWrapper *)prepared_statement;
|
17
18
|
auto result = new PendingStatementWrapper();
|
19
|
+
result->allow_streaming = allow_streaming;
|
18
20
|
try {
|
19
|
-
result->statement = wrapper->statement->PendingQuery(wrapper->values,
|
21
|
+
result->statement = wrapper->statement->PendingQuery(wrapper->values, allow_streaming);
|
20
22
|
} catch (const duckdb::Exception &ex) {
|
21
23
|
result->statement = make_unique<PendingQueryResult>(duckdb::PreservedError(ex));
|
22
24
|
} catch (std::exception &ex) {
|
@@ -28,6 +30,15 @@ duckdb_state duckdb_pending_prepared(duckdb_prepared_statement prepared_statemen
|
|
28
30
|
return return_value;
|
29
31
|
}
|
30
32
|
|
33
|
+
duckdb_state duckdb_pending_prepared(duckdb_prepared_statement prepared_statement, duckdb_pending_result *out_result) {
|
34
|
+
return duckdb_pending_prepared_internal(prepared_statement, out_result, false);
|
35
|
+
}
|
36
|
+
|
37
|
+
duckdb_state duckdb_pending_prepared_streaming(duckdb_prepared_statement prepared_statement,
|
38
|
+
duckdb_pending_result *out_result) {
|
39
|
+
return duckdb_pending_prepared_internal(prepared_statement, out_result, true);
|
40
|
+
}
|
41
|
+
|
31
42
|
void duckdb_destroy_pending(duckdb_pending_result *pending_result) {
|
32
43
|
if (!pending_result || !*pending_result) {
|
33
44
|
return;
|
@@ -90,7 +101,9 @@ duckdb_state duckdb_execute_pending(duckdb_pending_result pending_result, duckdb
|
|
90
101
|
if (!wrapper->statement) {
|
91
102
|
return DuckDBError;
|
92
103
|
}
|
93
|
-
|
104
|
+
|
105
|
+
std::unique_ptr<duckdb::QueryResult> result;
|
106
|
+
result = wrapper->statement->Execute();
|
94
107
|
wrapper->statement.reset();
|
95
108
|
return duckdb_translate_result(std::move(result), out_result);
|
96
109
|
}
|
@@ -292,6 +292,10 @@ bool deprecated_materialize_result(duckdb_result *result) {
|
|
292
292
|
// already used as a new result set
|
293
293
|
return false;
|
294
294
|
}
|
295
|
+
if (result_data->result_set_type == CAPIResultSetType::CAPI_RESULT_TYPE_STREAMING) {
|
296
|
+
// already used as a streaming result
|
297
|
+
return false;
|
298
|
+
}
|
295
299
|
// materialize as deprecated result set
|
296
300
|
result_data->result_set_type = CAPIResultSetType::CAPI_RESULT_TYPE_DEPRECATED;
|
297
301
|
auto column_count = result_data->result->ColumnCount();
|
@@ -413,6 +417,10 @@ idx_t duckdb_row_count(duckdb_result *result) {
|
|
413
417
|
return 0;
|
414
418
|
}
|
415
419
|
auto &result_data = *((duckdb::DuckDBResultData *)result->internal_data);
|
420
|
+
if (result_data.result->type == duckdb::QueryResultType::STREAM_RESULT) {
|
421
|
+
// We can't know the row count beforehand
|
422
|
+
return 0;
|
423
|
+
}
|
416
424
|
auto &materialized = (duckdb::MaterializedQueryResult &)*result_data.result;
|
417
425
|
return materialized.RowCount();
|
418
426
|
}
|
@@ -463,7 +471,10 @@ idx_t duckdb_result_chunk_count(duckdb_result result) {
|
|
463
471
|
if (result_data.result_set_type == duckdb::CAPIResultSetType::CAPI_RESULT_TYPE_DEPRECATED) {
|
464
472
|
return 0;
|
465
473
|
}
|
466
|
-
|
474
|
+
if (result_data.result->type != duckdb::QueryResultType::MATERIALIZED_RESULT) {
|
475
|
+
// Can't know beforehand how many chunks are returned.
|
476
|
+
return 0;
|
477
|
+
}
|
467
478
|
auto &materialized = (duckdb::MaterializedQueryResult &)*result_data.result;
|
468
479
|
return materialized.Collection().ChunkCount();
|
469
480
|
}
|
@@ -476,6 +487,10 @@ duckdb_data_chunk duckdb_result_get_chunk(duckdb_result result, idx_t chunk_idx)
|
|
476
487
|
if (result_data.result_set_type == duckdb::CAPIResultSetType::CAPI_RESULT_TYPE_DEPRECATED) {
|
477
488
|
return nullptr;
|
478
489
|
}
|
490
|
+
if (result_data.result->type != duckdb::QueryResultType::MATERIALIZED_RESULT) {
|
491
|
+
// This API is only supported for materialized query results
|
492
|
+
return nullptr;
|
493
|
+
}
|
479
494
|
result_data.result_set_type = duckdb::CAPIResultSetType::CAPI_RESULT_TYPE_MATERIALIZED;
|
480
495
|
auto &materialized = (duckdb::MaterializedQueryResult &)*result_data.result;
|
481
496
|
auto &collection = materialized.Collection();
|
@@ -487,3 +502,14 @@ duckdb_data_chunk duckdb_result_get_chunk(duckdb_result result, idx_t chunk_idx)
|
|
487
502
|
collection.FetchChunk(chunk_idx, *chunk);
|
488
503
|
return reinterpret_cast<duckdb_data_chunk>(chunk.release());
|
489
504
|
}
|
505
|
+
|
506
|
+
bool duckdb_result_is_streaming(duckdb_result result) {
|
507
|
+
if (!result.internal_data) {
|
508
|
+
return false;
|
509
|
+
}
|
510
|
+
if (duckdb_result_error(&result) != nullptr) {
|
511
|
+
return false;
|
512
|
+
}
|
513
|
+
auto &result_data = *((duckdb::DuckDBResultData *)result.internal_data);
|
514
|
+
return result_data.result->type == duckdb::QueryResultType::STREAM_RESULT;
|
515
|
+
}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
#include "duckdb/main/capi/capi_internal.hpp"
|
2
|
+
#include "duckdb/common/types/timestamp.hpp"
|
3
|
+
#include "duckdb/common/allocator.hpp"
|
4
|
+
|
5
|
+
duckdb_data_chunk duckdb_stream_fetch_chunk(duckdb_result result) {
|
6
|
+
if (!result.internal_data) {
|
7
|
+
return nullptr;
|
8
|
+
}
|
9
|
+
auto &result_data = *((duckdb::DuckDBResultData *)result.internal_data);
|
10
|
+
if (result_data.result_set_type == duckdb::CAPIResultSetType::CAPI_RESULT_TYPE_DEPRECATED) {
|
11
|
+
return nullptr;
|
12
|
+
}
|
13
|
+
if (result_data.result->type != duckdb::QueryResultType::STREAM_RESULT) {
|
14
|
+
// We can only fetch from a StreamQueryResult
|
15
|
+
return nullptr;
|
16
|
+
}
|
17
|
+
result_data.result_set_type = duckdb::CAPIResultSetType::CAPI_RESULT_TYPE_STREAMING;
|
18
|
+
auto &streaming = (duckdb::StreamQueryResult &)*result_data.result;
|
19
|
+
if (!streaming.IsOpen()) {
|
20
|
+
return nullptr;
|
21
|
+
}
|
22
|
+
// FetchRaw ? Do we care about flattening them?
|
23
|
+
auto chunk = streaming.Fetch();
|
24
|
+
return reinterpret_cast<duckdb_data_chunk>(chunk.release());
|
25
|
+
}
|