duckdb 0.7.2-dev16.0 → 0.7.2-dev225.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_writer.cpp +0 -1
- package/src/duckdb/extension/parquet/parquet-extension.cpp +11 -2
- 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/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/operator/persistent/buffered_csv_reader.cpp +1 -1
- 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 +261 -0
- package/src/duckdb/src/function/aggregate/distributive/sum.cpp +0 -3
- 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/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/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 +2 -14
- 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_functions.cpp +1 -0
- 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/function/aggregate/distributive_functions.hpp +5 -0
- 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/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/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/statistics/base_statistics.hpp +2 -0
- package/src/duckdb/src/include/duckdb/storage/statistics/node_statistics.hpp +26 -0
- package/src/duckdb/src/include/duckdb/storage/table/list_column_data.hpp +1 -1
- package/src/duckdb/src/include/duckdb/storage/table/scan_state.hpp +2 -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/database.cpp +10 -2
- package/src/duckdb/src/optimizer/join_order/cardinality_estimator.cpp +98 -66
- package/src/duckdb/src/optimizer/join_order/join_order_optimizer.cpp +16 -3
- 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_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/binder/query_node/bind_select_node.cpp +11 -3
- 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_pivot.cpp +365 -0
- package/src/duckdb/src/planner/binder.cpp +5 -0
- 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/compression/bitpacking.cpp +25 -21
- package/src/duckdb/src/storage/compression/fixed_size_uncompressed.cpp +41 -43
- package/src/duckdb/src/storage/compression/rle.cpp +17 -13
- package/src/duckdb/src/storage/statistics/base_statistics.cpp +3 -3
- package/src/duckdb/src/storage/storage_info.cpp +1 -1
- package/src/duckdb/src/storage/table/column_data.cpp +5 -2
- package/src/duckdb/src/storage/table/list_column_data.cpp +32 -47
- 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 +1016 -530
- package/src/duckdb/third_party/libpg_query/include/parser/kwlist.hpp +5 -0
- package/src/duckdb/third_party/libpg_query/src_backend_parser_gram.cpp +22697 -21987
- 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/src/include/duckdb/main/loadable_extension.hpp +0 -59
- package/src/duckdb/src/parser/parsed_data/alter_function_info.cpp +0 -55
@@ -0,0 +1,99 @@
|
|
1
|
+
#include "duckdb/common/types/bit.hpp"
|
2
|
+
#include "duckdb/function/scalar/bit_functions.hpp"
|
3
|
+
#include "duckdb/common/types/cast_helpers.hpp"
|
4
|
+
|
5
|
+
namespace duckdb {
|
6
|
+
|
7
|
+
//===--------------------------------------------------------------------===//
|
8
|
+
// BitStringFunction
|
9
|
+
//===--------------------------------------------------------------------===//
|
10
|
+
|
11
|
+
static void BitStringFunction(DataChunk &args, ExpressionState &state, Vector &result) {
|
12
|
+
BinaryExecutor::Execute<string_t, int32_t, string_t>(
|
13
|
+
args.data[0], args.data[1], result, args.size(), [&](string_t input, int32_t n) {
|
14
|
+
if (n < 0) {
|
15
|
+
throw InvalidInputException("The bitstring length cannot be negative");
|
16
|
+
}
|
17
|
+
if ((idx_t)n < input.GetSize()) {
|
18
|
+
throw InvalidInputException("Length must be equal or larger than input string");
|
19
|
+
}
|
20
|
+
idx_t len;
|
21
|
+
Bit::TryGetBitStringSize(input, len, nullptr); // string verification
|
22
|
+
|
23
|
+
len = Bit::ComputeBitstringLen(n);
|
24
|
+
string_t target = StringVector::EmptyString(result, len);
|
25
|
+
|
26
|
+
Bit::BitString(input, n, target);
|
27
|
+
return target;
|
28
|
+
});
|
29
|
+
}
|
30
|
+
|
31
|
+
void BitStringFun::RegisterFunction(BuiltinFunctions &set) {
|
32
|
+
// bitstring creates a new bitstring from varchar with a fixed-length
|
33
|
+
set.AddFunction(
|
34
|
+
ScalarFunction("bitstring", {LogicalType::VARCHAR, LogicalType::INTEGER}, LogicalType::BIT, BitStringFunction));
|
35
|
+
}
|
36
|
+
|
37
|
+
//===--------------------------------------------------------------------===//
|
38
|
+
// get_bit
|
39
|
+
//===--------------------------------------------------------------------===//
|
40
|
+
struct GetBitOperator {
|
41
|
+
template <class TA, class TB, class TR>
|
42
|
+
static inline TR Operation(TA input, TB n) {
|
43
|
+
if (n < 0 || (idx_t)n > Bit::BitLength(input) - 1) {
|
44
|
+
throw OutOfRangeException("bit index %s out of valid range (0..%s)", NumericHelper::ToString(n),
|
45
|
+
NumericHelper::ToString(Bit::BitLength(input) - 1));
|
46
|
+
}
|
47
|
+
return Bit::GetBit(input, n);
|
48
|
+
}
|
49
|
+
};
|
50
|
+
|
51
|
+
void GetBitFun::RegisterFunction(BuiltinFunctions &set) {
|
52
|
+
set.AddFunction(ScalarFunction("get_bit", {LogicalType::BIT, LogicalType::INTEGER}, LogicalType::INTEGER,
|
53
|
+
ScalarFunction::BinaryFunction<string_t, int32_t, int32_t, GetBitOperator>));
|
54
|
+
}
|
55
|
+
|
56
|
+
//===--------------------------------------------------------------------===//
|
57
|
+
// set_bit
|
58
|
+
//===--------------------------------------------------------------------===//
|
59
|
+
static void SetBitOperation(DataChunk &args, ExpressionState &state, Vector &result) {
|
60
|
+
TernaryExecutor::Execute<string_t, int32_t, int32_t, string_t>(
|
61
|
+
args.data[0], args.data[1], args.data[2], result, args.size(),
|
62
|
+
[&](string_t input, int32_t n, int32_t new_value) {
|
63
|
+
if (new_value != 0 && new_value != 1) {
|
64
|
+
throw InvalidInputException("The new bit must be 1 or 0");
|
65
|
+
}
|
66
|
+
if (n < 0 || (idx_t)n > Bit::BitLength(input) - 1) {
|
67
|
+
throw OutOfRangeException("bit index %s out of valid range (0..%s)", NumericHelper::ToString(n),
|
68
|
+
NumericHelper::ToString(Bit::BitLength(input) - 1));
|
69
|
+
}
|
70
|
+
string_t target = StringVector::EmptyString(result, input.GetSize());
|
71
|
+
Bit::SetBit(input, n, new_value, target);
|
72
|
+
return target;
|
73
|
+
});
|
74
|
+
}
|
75
|
+
|
76
|
+
void SetBitFun::RegisterFunction(BuiltinFunctions &set) {
|
77
|
+
set.AddFunction(ScalarFunction("set_bit", {LogicalType::BIT, LogicalType::INTEGER, LogicalType::INTEGER},
|
78
|
+
LogicalType::BIT, SetBitOperation));
|
79
|
+
}
|
80
|
+
|
81
|
+
//===--------------------------------------------------------------------===//
|
82
|
+
// bit_position
|
83
|
+
//===--------------------------------------------------------------------===//
|
84
|
+
struct BitPositionOperator {
|
85
|
+
template <class TA, class TB, class TR>
|
86
|
+
static inline TR Operation(TA substring, TB input) {
|
87
|
+
if (substring.GetSize() > input.GetSize()) {
|
88
|
+
return 0;
|
89
|
+
}
|
90
|
+
return Bit::BitPosition(substring, input);
|
91
|
+
}
|
92
|
+
};
|
93
|
+
|
94
|
+
void BitPositionFun::RegisterFunction(BuiltinFunctions &set) {
|
95
|
+
set.AddFunction(ScalarFunction("bit_position", {LogicalType::BIT, LogicalType::BIT}, LogicalType::INTEGER,
|
96
|
+
ScalarFunction::BinaryFunction<string_t, string_t, int32_t, BitPositionOperator>));
|
97
|
+
}
|
98
|
+
|
99
|
+
} // namespace duckdb
|
@@ -0,0 +1,61 @@
|
|
1
|
+
#include "duckdb/planner/expression/bound_function_expression.hpp"
|
2
|
+
#include "duckdb/common/string_util.hpp"
|
3
|
+
#include "duckdb/parser/expression/bound_expression.hpp"
|
4
|
+
#include "duckdb/function/scalar/nested_functions.hpp"
|
5
|
+
#include "duckdb/common/types/data_chunk.hpp"
|
6
|
+
#include "duckdb/common/pair.hpp"
|
7
|
+
|
8
|
+
namespace duckdb {
|
9
|
+
|
10
|
+
// Reverse of map_from_entries
|
11
|
+
static void MapEntriesFunction(DataChunk &args, ExpressionState &state, Vector &result) {
|
12
|
+
idx_t count = args.size();
|
13
|
+
|
14
|
+
result.Reinterpret(args.data[0]);
|
15
|
+
|
16
|
+
if (args.AllConstant()) {
|
17
|
+
result.SetVectorType(VectorType::CONSTANT_VECTOR);
|
18
|
+
}
|
19
|
+
result.Verify(count);
|
20
|
+
}
|
21
|
+
|
22
|
+
static unique_ptr<FunctionData> MapEntriesBind(ClientContext &context, ScalarFunction &bound_function,
|
23
|
+
vector<unique_ptr<Expression>> &arguments) {
|
24
|
+
child_list_t<LogicalType> child_types;
|
25
|
+
|
26
|
+
if (arguments.size() != 1) {
|
27
|
+
throw InvalidInputException("Too many arguments provided, only expecting a single map");
|
28
|
+
}
|
29
|
+
auto &map = arguments[0]->return_type;
|
30
|
+
|
31
|
+
if (map.id() == LogicalTypeId::UNKNOWN) {
|
32
|
+
// Prepared statement
|
33
|
+
bound_function.arguments.emplace_back(LogicalTypeId::UNKNOWN);
|
34
|
+
bound_function.return_type = LogicalType(LogicalTypeId::SQLNULL);
|
35
|
+
return nullptr;
|
36
|
+
}
|
37
|
+
|
38
|
+
if (map.id() != LogicalTypeId::MAP) {
|
39
|
+
throw InvalidInputException("The provided argument is not a map");
|
40
|
+
}
|
41
|
+
auto &key_type = MapType::KeyType(map);
|
42
|
+
auto &value_type = MapType::ValueType(map);
|
43
|
+
|
44
|
+
child_types.push_back(make_pair("k", key_type));
|
45
|
+
child_types.push_back(make_pair("v", value_type));
|
46
|
+
|
47
|
+
auto row_type = LogicalType::STRUCT(std::move(child_types));
|
48
|
+
|
49
|
+
bound_function.return_type = LogicalType::LIST(row_type);
|
50
|
+
return make_unique<VariableReturnBindData>(bound_function.return_type);
|
51
|
+
}
|
52
|
+
|
53
|
+
void MapEntriesFun::RegisterFunction(BuiltinFunctions &set) {
|
54
|
+
//! the arguments and return types are actually set in the binder function
|
55
|
+
ScalarFunction fun("map_entries", {}, LogicalTypeId::LIST, MapEntriesFunction, MapEntriesBind);
|
56
|
+
fun.null_handling = FunctionNullHandling::DEFAULT_NULL_HANDLING;
|
57
|
+
fun.varargs = LogicalType::ANY;
|
58
|
+
set.AddFunction(fun);
|
59
|
+
}
|
60
|
+
|
61
|
+
} // namespace duckdb
|
@@ -0,0 +1,97 @@
|
|
1
|
+
#include "duckdb/planner/expression/bound_function_expression.hpp"
|
2
|
+
#include "duckdb/common/string_util.hpp"
|
3
|
+
#include "duckdb/parser/expression/bound_expression.hpp"
|
4
|
+
#include "duckdb/function/scalar/nested_functions.hpp"
|
5
|
+
#include "duckdb/common/types/data_chunk.hpp"
|
6
|
+
#include "duckdb/common/pair.hpp"
|
7
|
+
|
8
|
+
namespace duckdb {
|
9
|
+
|
10
|
+
static void MapKeyValueFunction(DataChunk &args, ExpressionState &state, Vector &result,
|
11
|
+
Vector &(*get_child_vector)(Vector &)) {
|
12
|
+
D_ASSERT(result.GetType().id() == LogicalTypeId::LIST);
|
13
|
+
auto count = args.size();
|
14
|
+
|
15
|
+
auto &map = args.data[0];
|
16
|
+
D_ASSERT(map.GetType().id() == LogicalTypeId::MAP);
|
17
|
+
auto child = get_child_vector(map);
|
18
|
+
|
19
|
+
auto &entries = ListVector::GetEntry(result);
|
20
|
+
entries.Reference(child);
|
21
|
+
|
22
|
+
UnifiedVectorFormat map_data;
|
23
|
+
map.ToUnifiedFormat(count, map_data);
|
24
|
+
|
25
|
+
D_ASSERT(result.GetVectorType() == VectorType::FLAT_VECTOR);
|
26
|
+
FlatVector::SetData(result, map_data.data);
|
27
|
+
FlatVector::SetValidity(result, map_data.validity);
|
28
|
+
auto list_size = ListVector::GetListSize(map);
|
29
|
+
ListVector::SetListSize(result, list_size);
|
30
|
+
if (map.GetVectorType() == VectorType::DICTIONARY_VECTOR) {
|
31
|
+
result.Slice(*map_data.sel, count);
|
32
|
+
}
|
33
|
+
if (args.AllConstant()) {
|
34
|
+
result.SetVectorType(VectorType::CONSTANT_VECTOR);
|
35
|
+
}
|
36
|
+
result.Verify(count);
|
37
|
+
}
|
38
|
+
|
39
|
+
static void MapKeysFunction(DataChunk &args, ExpressionState &state, Vector &result) {
|
40
|
+
MapKeyValueFunction(args, state, result, MapVector::GetKeys);
|
41
|
+
}
|
42
|
+
|
43
|
+
static void MapValuesFunction(DataChunk &args, ExpressionState &state, Vector &result) {
|
44
|
+
MapKeyValueFunction(args, state, result, MapVector::GetValues);
|
45
|
+
}
|
46
|
+
|
47
|
+
static unique_ptr<FunctionData> MapKeyValueBind(ClientContext &context, ScalarFunction &bound_function,
|
48
|
+
vector<unique_ptr<Expression>> &arguments,
|
49
|
+
const LogicalType &(*type_func)(const LogicalType &)) {
|
50
|
+
if (arguments.size() != 1) {
|
51
|
+
throw InvalidInputException("Too many arguments provided, only expecting a single map");
|
52
|
+
}
|
53
|
+
auto &map = arguments[0]->return_type;
|
54
|
+
|
55
|
+
if (map.id() == LogicalTypeId::UNKNOWN) {
|
56
|
+
// Prepared statement
|
57
|
+
bound_function.arguments.emplace_back(LogicalTypeId::UNKNOWN);
|
58
|
+
bound_function.return_type = LogicalType(LogicalTypeId::SQLNULL);
|
59
|
+
return nullptr;
|
60
|
+
}
|
61
|
+
|
62
|
+
if (map.id() != LogicalTypeId::MAP) {
|
63
|
+
throw InvalidInputException("The provided argument is not a map");
|
64
|
+
}
|
65
|
+
|
66
|
+
auto &type = type_func(map);
|
67
|
+
|
68
|
+
bound_function.return_type = LogicalType::LIST(type);
|
69
|
+
return make_unique<VariableReturnBindData>(bound_function.return_type);
|
70
|
+
}
|
71
|
+
|
72
|
+
static unique_ptr<FunctionData> MapKeysBind(ClientContext &context, ScalarFunction &bound_function,
|
73
|
+
vector<unique_ptr<Expression>> &arguments) {
|
74
|
+
return MapKeyValueBind(context, bound_function, arguments, MapType::KeyType);
|
75
|
+
}
|
76
|
+
|
77
|
+
static unique_ptr<FunctionData> MapValuesBind(ClientContext &context, ScalarFunction &bound_function,
|
78
|
+
vector<unique_ptr<Expression>> &arguments) {
|
79
|
+
return MapKeyValueBind(context, bound_function, arguments, MapType::ValueType);
|
80
|
+
}
|
81
|
+
|
82
|
+
void MapKeysFun::RegisterFunction(BuiltinFunctions &set) {
|
83
|
+
//! the arguments and return types are actually set in the binder function
|
84
|
+
ScalarFunction fun("map_keys", {}, LogicalTypeId::LIST, MapKeysFunction, MapKeysBind);
|
85
|
+
fun.null_handling = FunctionNullHandling::DEFAULT_NULL_HANDLING;
|
86
|
+
fun.varargs = LogicalType::ANY;
|
87
|
+
set.AddFunction(fun);
|
88
|
+
}
|
89
|
+
|
90
|
+
void MapValuesFun::RegisterFunction(BuiltinFunctions &set) {
|
91
|
+
ScalarFunction fun("map_values", {}, LogicalTypeId::LIST, MapValuesFunction, MapValuesBind);
|
92
|
+
fun.null_handling = FunctionNullHandling::DEFAULT_NULL_HANDLING;
|
93
|
+
fun.varargs = LogicalType::ANY;
|
94
|
+
set.AddFunction(fun);
|
95
|
+
}
|
96
|
+
|
97
|
+
} // namespace duckdb
|
@@ -22,6 +22,9 @@ void BuiltinFunctions::RegisterNestedFunctions() {
|
|
22
22
|
Register<ListFlattenFun>();
|
23
23
|
Register<MapFun>();
|
24
24
|
Register<MapFromEntriesFun>();
|
25
|
+
Register<MapEntriesFun>();
|
26
|
+
Register<MapValuesFun>();
|
27
|
+
Register<MapKeysFun>();
|
25
28
|
Register<MapExtractFun>();
|
26
29
|
Register<UnionValueFun>();
|
27
30
|
Register<UnionExtractFun>();
|
@@ -7,9 +7,6 @@
|
|
7
7
|
#include "duckdb/common/types/interval.hpp"
|
8
8
|
#include "duckdb/common/types/timestamp.hpp"
|
9
9
|
#include "duckdb/common/types/hugeint.hpp"
|
10
|
-
#include "duckdb/common/windows_undefs.hpp"
|
11
|
-
|
12
|
-
#include <limits>
|
13
10
|
|
14
11
|
namespace duckdb {
|
15
12
|
|
@@ -19,18 +16,12 @@ namespace duckdb {
|
|
19
16
|
template <>
|
20
17
|
float AddOperator::Operation(float left, float right) {
|
21
18
|
auto result = left + right;
|
22
|
-
if (!Value::FloatIsFinite(result)) {
|
23
|
-
throw OutOfRangeException("Overflow in addition of float!");
|
24
|
-
}
|
25
19
|
return result;
|
26
20
|
}
|
27
21
|
|
28
22
|
template <>
|
29
23
|
double AddOperator::Operation(double left, double right) {
|
30
24
|
auto result = left + right;
|
31
|
-
if (!Value::DoubleIsFinite(result)) {
|
32
|
-
throw OutOfRangeException("Overflow in addition of double!");
|
33
|
-
}
|
34
25
|
return result;
|
35
26
|
}
|
36
27
|
|
@@ -431,12 +431,12 @@ struct NegateOperator {
|
|
431
431
|
|
432
432
|
template <>
|
433
433
|
bool NegateOperator::CanNegate(float input) {
|
434
|
-
return
|
434
|
+
return true;
|
435
435
|
}
|
436
436
|
|
437
437
|
template <>
|
438
438
|
bool NegateOperator::CanNegate(double input) {
|
439
|
-
return
|
439
|
+
return true;
|
440
440
|
}
|
441
441
|
|
442
442
|
template <>
|
@@ -803,18 +803,12 @@ void MultiplyFun::RegisterFunction(BuiltinFunctions &set) {
|
|
803
803
|
template <>
|
804
804
|
float DivideOperator::Operation(float left, float right) {
|
805
805
|
auto result = left / right;
|
806
|
-
if (!Value::FloatIsFinite(result)) {
|
807
|
-
throw OutOfRangeException("Overflow in division of float!");
|
808
|
-
}
|
809
806
|
return result;
|
810
807
|
}
|
811
808
|
|
812
809
|
template <>
|
813
810
|
double DivideOperator::Operation(double left, double right) {
|
814
811
|
auto result = left / right;
|
815
|
-
if (!Value::DoubleIsFinite(result)) {
|
816
|
-
throw OutOfRangeException("Overflow in division of double!");
|
817
|
-
}
|
818
812
|
return result;
|
819
813
|
}
|
820
814
|
|
@@ -946,9 +940,6 @@ template <>
|
|
946
940
|
float ModuloOperator::Operation(float left, float right) {
|
947
941
|
D_ASSERT(right != 0);
|
948
942
|
auto result = std::fmod(left, right);
|
949
|
-
if (!Value::FloatIsFinite(result)) {
|
950
|
-
throw OutOfRangeException("Overflow in modulo of float!");
|
951
|
-
}
|
952
943
|
return result;
|
953
944
|
}
|
954
945
|
|
@@ -956,9 +947,6 @@ template <>
|
|
956
947
|
double ModuloOperator::Operation(double left, double right) {
|
957
948
|
D_ASSERT(right != 0);
|
958
949
|
auto result = std::fmod(left, right);
|
959
|
-
if (!Value::DoubleIsFinite(result)) {
|
960
|
-
throw OutOfRangeException("Overflow in modulo of double!");
|
961
|
-
}
|
962
950
|
return result;
|
963
951
|
}
|
964
952
|
|
@@ -107,7 +107,6 @@ void BitwiseAndFun::RegisterFunction(BuiltinFunctions &set) {
|
|
107
107
|
ScalarFunction({type, type}, type, GetScalarIntegerBinaryFunction<BitwiseANDOperator>(type)));
|
108
108
|
}
|
109
109
|
functions.AddFunction(ScalarFunction({LogicalType::BIT, LogicalType::BIT}, LogicalType::BIT, BitwiseANDOperation));
|
110
|
-
|
111
110
|
set.AddFunction(functions);
|
112
111
|
}
|
113
112
|
|
@@ -306,66 +305,4 @@ void RightShiftFun::RegisterFunction(BuiltinFunctions &set) {
|
|
306
305
|
set.AddFunction(functions);
|
307
306
|
}
|
308
307
|
|
309
|
-
//===--------------------------------------------------------------------===//
|
310
|
-
// get_bit
|
311
|
-
//===--------------------------------------------------------------------===//
|
312
|
-
struct GetBitOperator {
|
313
|
-
template <class TA, class TB, class TR>
|
314
|
-
static inline TR Operation(TA input, TB n) {
|
315
|
-
if (n < 0 || (idx_t)n > Bit::BitLength(input) - 1) {
|
316
|
-
throw OutOfRangeException("bit index %s out of valid range (0..%s)", NumericHelper::ToString(n),
|
317
|
-
NumericHelper::ToString(Bit::BitLength(input) - 1));
|
318
|
-
}
|
319
|
-
return Bit::GetBit(input, n);
|
320
|
-
}
|
321
|
-
};
|
322
|
-
|
323
|
-
void GetBitFun::RegisterFunction(BuiltinFunctions &set) {
|
324
|
-
set.AddFunction(ScalarFunction("get_bit", {LogicalType::BIT, LogicalType::INTEGER}, LogicalType::INTEGER,
|
325
|
-
ScalarFunction::BinaryFunction<string_t, int32_t, int32_t, GetBitOperator>));
|
326
|
-
}
|
327
|
-
|
328
|
-
//===--------------------------------------------------------------------===//
|
329
|
-
// set_bit
|
330
|
-
//===--------------------------------------------------------------------===//
|
331
|
-
static void SetBitOperation(DataChunk &args, ExpressionState &state, Vector &result) {
|
332
|
-
TernaryExecutor::Execute<string_t, int32_t, int32_t, string_t>(
|
333
|
-
args.data[0], args.data[1], args.data[2], result, args.size(),
|
334
|
-
[&](string_t input, int32_t n, int32_t new_value) {
|
335
|
-
if (new_value != 0 && new_value != 1) {
|
336
|
-
throw InvalidInputException("The new bit must be 1 or 0");
|
337
|
-
}
|
338
|
-
if (n < 0 || (idx_t)n > Bit::BitLength(input) - 1) {
|
339
|
-
throw OutOfRangeException("bit index %s out of valid range (0..%s)", NumericHelper::ToString(n),
|
340
|
-
NumericHelper::ToString(Bit::BitLength(input) - 1));
|
341
|
-
}
|
342
|
-
string_t target = StringVector::EmptyString(result, input.GetSize());
|
343
|
-
Bit::SetBit(input, n, new_value, target);
|
344
|
-
return target;
|
345
|
-
});
|
346
|
-
}
|
347
|
-
|
348
|
-
void SetBitFun::RegisterFunction(BuiltinFunctions &set) {
|
349
|
-
set.AddFunction(ScalarFunction("set_bit", {LogicalType::BIT, LogicalType::INTEGER, LogicalType::INTEGER},
|
350
|
-
LogicalType::BIT, SetBitOperation));
|
351
|
-
}
|
352
|
-
|
353
|
-
//===--------------------------------------------------------------------===//
|
354
|
-
// bit_position
|
355
|
-
//===--------------------------------------------------------------------===//
|
356
|
-
struct BitPositionOperator {
|
357
|
-
template <class TA, class TB, class TR>
|
358
|
-
static inline TR Operation(TA substring, TB input) {
|
359
|
-
if (substring.GetSize() > input.GetSize()) {
|
360
|
-
return 0;
|
361
|
-
}
|
362
|
-
return Bit::BitPosition(substring, input);
|
363
|
-
}
|
364
|
-
};
|
365
|
-
|
366
|
-
void BitPositionFun::RegisterFunction(BuiltinFunctions &set) {
|
367
|
-
set.AddFunction(ScalarFunction("bit_position", {LogicalType::BIT, LogicalType::BIT}, LogicalType::INTEGER,
|
368
|
-
ScalarFunction::BinaryFunction<string_t, string_t, int32_t, BitPositionOperator>));
|
369
|
-
}
|
370
|
-
|
371
308
|
} // namespace duckdb
|
@@ -16,18 +16,12 @@ namespace duckdb {
|
|
16
16
|
template <>
|
17
17
|
float MultiplyOperator::Operation(float left, float right) {
|
18
18
|
auto result = left * right;
|
19
|
-
if (!Value::FloatIsFinite(result)) {
|
20
|
-
throw OutOfRangeException("Overflow in multiplication of float!");
|
21
|
-
}
|
22
19
|
return result;
|
23
20
|
}
|
24
21
|
|
25
22
|
template <>
|
26
23
|
double MultiplyOperator::Operation(double left, double right) {
|
27
24
|
auto result = left * right;
|
28
|
-
if (!Value::DoubleIsFinite(result)) {
|
29
|
-
throw OutOfRangeException("Overflow in multiplication of double!");
|
30
|
-
}
|
31
25
|
return result;
|
32
26
|
}
|
33
27
|
|
@@ -15,18 +15,12 @@ namespace duckdb {
|
|
15
15
|
template <>
|
16
16
|
float SubtractOperator::Operation(float left, float right) {
|
17
17
|
auto result = left - right;
|
18
|
-
if (!Value::FloatIsFinite(result)) {
|
19
|
-
throw OutOfRangeException("Overflow in subtraction of float!");
|
20
|
-
}
|
21
18
|
return result;
|
22
19
|
}
|
23
20
|
|
24
21
|
template <>
|
25
22
|
double SubtractOperator::Operation(double left, double right) {
|
26
23
|
auto result = left - right;
|
27
|
-
if (!Value::DoubleIsFinite(result)) {
|
28
|
-
throw OutOfRangeException("Overflow in subtraction of double!");
|
29
|
-
}
|
30
24
|
return result;
|
31
25
|
}
|
32
26
|
|
@@ -31,6 +31,9 @@ void ReadCSVData::InitializeFiles(ClientContext &context, const vector<string> &
|
|
31
31
|
auto found_files = fs.GlobFiles(file_pattern, context);
|
32
32
|
files.insert(files.end(), found_files.begin(), found_files.end());
|
33
33
|
}
|
34
|
+
if (files.empty()) {
|
35
|
+
throw IOException("CSV reader needs at least one file to read");
|
36
|
+
}
|
34
37
|
}
|
35
38
|
|
36
39
|
void ReadCSVData::FinalizeRead(ClientContext &context) {
|
@@ -61,9 +64,15 @@ static unique_ptr<FunctionData> ReadCSVBind(ClientContext &context, TableFunctio
|
|
61
64
|
auto &options = result->options;
|
62
65
|
|
63
66
|
vector<string> patterns;
|
67
|
+
if (input.inputs[0].IsNull()) {
|
68
|
+
throw ParserException("CSV reader cannot take NULL as parameter");
|
69
|
+
}
|
64
70
|
if (input.inputs[0].type().id() == LogicalTypeId::LIST) {
|
65
71
|
// list of globs
|
66
72
|
for (auto &val : ListValue::GetChildren(input.inputs[0])) {
|
73
|
+
if (val.IsNull()) {
|
74
|
+
throw ParserException("CSV reader cannot take NULL input as parameter");
|
75
|
+
}
|
67
76
|
patterns.push_back(StringValue::Get(val));
|
68
77
|
}
|
69
78
|
} else {
|
@@ -1,8 +1,8 @@
|
|
1
1
|
#ifndef DUCKDB_VERSION
|
2
|
-
#define DUCKDB_VERSION "0.7.2-
|
2
|
+
#define DUCKDB_VERSION "0.7.2-dev225"
|
3
3
|
#endif
|
4
4
|
#ifndef DUCKDB_SOURCE_ID
|
5
|
-
#define DUCKDB_SOURCE_ID "
|
5
|
+
#define DUCKDB_SOURCE_ID "96a1cada02"
|
6
6
|
#endif
|
7
7
|
#include "duckdb/function/table/system_functions.hpp"
|
8
8
|
#include "duckdb/main/database.hpp"
|
@@ -35,4 +35,23 @@ TableFunction::TableFunction()
|
|
35
35
|
filter_pushdown(false), filter_prune(false) {
|
36
36
|
}
|
37
37
|
|
38
|
+
bool TableFunction::Equal(const TableFunction &rhs) const {
|
39
|
+
// number of types
|
40
|
+
if (this->arguments.size() != rhs.arguments.size()) {
|
41
|
+
return false;
|
42
|
+
}
|
43
|
+
// argument types
|
44
|
+
for (idx_t i = 0; i < this->arguments.size(); ++i) {
|
45
|
+
if (this->arguments[i] != rhs.arguments[i]) {
|
46
|
+
return false;
|
47
|
+
}
|
48
|
+
}
|
49
|
+
// varargs
|
50
|
+
if (this->varargs != rhs.varargs) {
|
51
|
+
return false;
|
52
|
+
}
|
53
|
+
|
54
|
+
return true; // they are equal
|
55
|
+
}
|
56
|
+
|
38
57
|
} // namespace duckdb
|
package/src/duckdb/src/include/duckdb/catalog/catalog_entry/table_function_catalog_entry.hpp
CHANGED
@@ -9,17 +9,12 @@
|
|
9
9
|
#pragma once
|
10
10
|
|
11
11
|
#include "duckdb/catalog/standard_entry.hpp"
|
12
|
-
#include "duckdb/
|
13
|
-
#include "duckdb/
|
14
|
-
#include "duckdb/
|
12
|
+
#include "duckdb/catalog/catalog_set.hpp"
|
13
|
+
#include "duckdb/function/function.hpp"
|
14
|
+
#include "duckdb/parser/parsed_data/create_table_function_info.hpp"
|
15
15
|
|
16
16
|
namespace duckdb {
|
17
17
|
|
18
|
-
class Catalog;
|
19
|
-
class Constraint;
|
20
|
-
|
21
|
-
struct CreateTableFunctionInfo;
|
22
|
-
|
23
18
|
//! A table function in the catalog
|
24
19
|
class TableFunctionCatalogEntry : public StandardEntry {
|
25
20
|
public:
|
@@ -31,5 +26,8 @@ public:
|
|
31
26
|
|
32
27
|
//! The table function
|
33
28
|
TableFunctionSet functions;
|
29
|
+
|
30
|
+
public:
|
31
|
+
unique_ptr<CatalogEntry> AlterEntry(ClientContext &context, AlterInfo *info) override;
|
34
32
|
};
|
35
33
|
} // namespace duckdb
|
@@ -15,25 +15,6 @@
|
|
15
15
|
|
16
16
|
namespace duckdb {
|
17
17
|
|
18
|
-
// API versions
|
19
|
-
// if no explicit API version is defined, the latest API version is used
|
20
|
-
// Note that using older API versions (i.e. not using DUCKDB_API_LATEST) is deprecated.
|
21
|
-
// These will not be supported long-term, and will be removed in future versions.
|
22
|
-
|
23
|
-
#ifndef DUCKDB_API_0_3_1
|
24
|
-
#define DUCKDB_API_0_3_1 1
|
25
|
-
#endif
|
26
|
-
#ifndef DUCKDB_API_0_3_2
|
27
|
-
#define DUCKDB_API_0_3_2 2
|
28
|
-
#endif
|
29
|
-
#ifndef DUCKDB_API_LATEST
|
30
|
-
#define DUCKDB_API_LATEST DUCKDB_API_0_3_2
|
31
|
-
#endif
|
32
|
-
|
33
|
-
#ifndef DUCKDB_API_VERSION
|
34
|
-
#define DUCKDB_API_VERSION DUCKDB_API_LATEST
|
35
|
-
#endif
|
36
|
-
|
37
18
|
//! inline std directives that we use frequently
|
38
19
|
#ifndef DUCKDB_DEBUG_MOVE
|
39
20
|
using std::move;
|
@@ -23,7 +23,8 @@ enum class TableReferenceType : uint8_t {
|
|
23
23
|
TABLE_FUNCTION = 5, // table producing function
|
24
24
|
EXPRESSION_LIST = 6, // expression list
|
25
25
|
CTE = 7, // Recursive CTE
|
26
|
-
EMPTY = 8
|
26
|
+
EMPTY = 8, // placeholder for empty FROM
|
27
|
+
PIVOT = 9 // pivot statement
|
27
28
|
};
|
28
29
|
|
29
30
|
} // namespace duckdb
|
@@ -26,6 +26,7 @@ public:
|
|
26
26
|
DUCKDB_API static idx_t GetBit(string_t bit_string, idx_t n);
|
27
27
|
//! Sets the nth bit in bit string to newvalue; the first (leftmost) bit is indexed 0
|
28
28
|
DUCKDB_API static void SetBit(const string_t &bit_string, idx_t n, idx_t new_value, string_t &result);
|
29
|
+
DUCKDB_API static void SetBit(string_t &bit_string, idx_t n, idx_t new_value);
|
29
30
|
//! Returns first starting index of the specified substring within bits, or zero if it's not present.
|
30
31
|
DUCKDB_API static idx_t BitPosition(string_t substring, string_t bits);
|
31
32
|
//! Converts bits to a string, writing the output to the designated output string.
|
@@ -38,7 +39,11 @@ public:
|
|
38
39
|
//! perform data validation.
|
39
40
|
DUCKDB_API static void ToBit(string_t str, data_ptr_t output);
|
40
41
|
DUCKDB_API static string ToBit(string_t str);
|
42
|
+
//! Creates a new bitstring of determined length
|
43
|
+
DUCKDB_API static void BitString(const string_t &input, const idx_t &len, string_t &result);
|
41
44
|
DUCKDB_API static void SetEmptyBitString(string_t &target, string_t &input);
|
45
|
+
DUCKDB_API static void SetEmptyBitString(string_t &target, idx_t len);
|
46
|
+
DUCKDB_API static idx_t ComputeBitstringLen(idx_t len);
|
42
47
|
|
43
48
|
DUCKDB_API static void RightShift(const string_t &bit_string, const idx_t &shif, string_t &result);
|
44
49
|
DUCKDB_API static void LeftShift(const string_t &bit_string, const idx_t &shift, string_t &result);
|
@@ -52,6 +57,5 @@ private:
|
|
52
57
|
//! the bitstring.
|
53
58
|
DUCKDB_API static idx_t GetPadding(const string_t &bit_string);
|
54
59
|
DUCKDB_API static idx_t GetBitSize(string_t str);
|
55
|
-
DUCKDB_API static void SetBit(string_t &bit_string, idx_t n, idx_t new_value);
|
56
60
|
};
|
57
61
|
} // namespace duckdb
|
@@ -23,6 +23,7 @@ class CastFunctionSet;
|
|
23
23
|
class Deserializer;
|
24
24
|
class Serializer;
|
25
25
|
struct GetCastFunctionInput;
|
26
|
+
struct ExtraValueInfo;
|
26
27
|
|
27
28
|
//! The Value object holds a single arbitrary value of any type that can be
|
28
29
|
//! stored in the database.
|
@@ -279,9 +280,6 @@ private:
|
|
279
280
|
//! The logical of the value
|
280
281
|
LogicalType type_;
|
281
282
|
|
282
|
-
#if DUCKDB_API_VERSION < DUCKDB_API_0_3_2
|
283
|
-
public:
|
284
|
-
#endif
|
285
283
|
//! Whether or not the value is NULL
|
286
284
|
bool is_null;
|
287
285
|
|
@@ -307,11 +305,7 @@ public:
|
|
307
305
|
interval_t interval;
|
308
306
|
} value_;
|
309
307
|
|
310
|
-
|
311
|
-
string str_value;
|
312
|
-
|
313
|
-
vector<Value> struct_value;
|
314
|
-
vector<Value> list_value;
|
308
|
+
shared_ptr<ExtraValueInfo> value_info_;
|
315
309
|
|
316
310
|
private:
|
317
311
|
template <class T>
|