duckdb 0.3.1-dev283.0 → 0.3.1-dev291.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.cpp +164 -2
- package/src/duckdb.hpp +2 -2
package/package.json
CHANGED
package/src/duckdb.cpp
CHANGED
|
@@ -74973,6 +74973,11 @@ string_t CastInterpolation::Cast(const std::string &src, Vector &result) {
|
|
|
74973
74973
|
return StringVector::AddString(result, src);
|
|
74974
74974
|
}
|
|
74975
74975
|
|
|
74976
|
+
template <>
|
|
74977
|
+
string_t CastInterpolation::Cast(const string_t &src, Vector &result) {
|
|
74978
|
+
return StringVector::AddString(result, src);
|
|
74979
|
+
}
|
|
74980
|
+
|
|
74976
74981
|
template <class INPUT_TYPE, class TARGET_TYPE, bool DISCRETE>
|
|
74977
74982
|
struct Interpolator {
|
|
74978
74983
|
Interpolator(const double q, const idx_t n_p) : n(n_p), RN((double)(n_p - 1) * q), FRN(floor(RN)), CRN(ceil(RN)) {
|
|
@@ -91397,6 +91402,26 @@ void TrimFun::RegisterFunction(BuiltinFunctions &set) {
|
|
|
91397
91402
|
} // namespace duckdb
|
|
91398
91403
|
|
|
91399
91404
|
|
|
91405
|
+
//===----------------------------------------------------------------------===//
|
|
91406
|
+
// DuckDB
|
|
91407
|
+
//
|
|
91408
|
+
// duckdb/function/scalar/uuid_functions.hpp
|
|
91409
|
+
//
|
|
91410
|
+
//
|
|
91411
|
+
//===----------------------------------------------------------------------===//
|
|
91412
|
+
|
|
91413
|
+
|
|
91414
|
+
|
|
91415
|
+
|
|
91416
|
+
|
|
91417
|
+
namespace duckdb {
|
|
91418
|
+
|
|
91419
|
+
struct UUIDFun {
|
|
91420
|
+
static void RegisterFunction(BuiltinFunctions &set);
|
|
91421
|
+
};
|
|
91422
|
+
|
|
91423
|
+
} // namespace duckdb
|
|
91424
|
+
|
|
91400
91425
|
|
|
91401
91426
|
namespace duckdb {
|
|
91402
91427
|
|
|
@@ -91436,6 +91461,9 @@ void BuiltinFunctions::RegisterStringFunctions() {
|
|
|
91436
91461
|
// blob functions
|
|
91437
91462
|
Register<Base64Fun>();
|
|
91438
91463
|
Register<EncodeFun>();
|
|
91464
|
+
|
|
91465
|
+
// uuid functions
|
|
91466
|
+
Register<UUIDFun>();
|
|
91439
91467
|
}
|
|
91440
91468
|
|
|
91441
91469
|
} // namespace duckdb
|
|
@@ -91783,6 +91811,79 @@ void BuiltinFunctions::RegisterTrigonometricsFunctions() {
|
|
|
91783
91811
|
|
|
91784
91812
|
|
|
91785
91813
|
|
|
91814
|
+
namespace duckdb {
|
|
91815
|
+
|
|
91816
|
+
struct UUIDRandomBindData : public FunctionData {
|
|
91817
|
+
ClientContext &context;
|
|
91818
|
+
std::uniform_int_distribution<uint32_t> dist;
|
|
91819
|
+
|
|
91820
|
+
UUIDRandomBindData(ClientContext &context, std::uniform_int_distribution<uint32_t> dist)
|
|
91821
|
+
: context(context), dist(dist) {
|
|
91822
|
+
}
|
|
91823
|
+
|
|
91824
|
+
unique_ptr<FunctionData> Copy() override {
|
|
91825
|
+
return make_unique<UUIDRandomBindData>(context, dist);
|
|
91826
|
+
}
|
|
91827
|
+
};
|
|
91828
|
+
|
|
91829
|
+
static unique_ptr<FunctionData> UUIDRandomBind(ClientContext &context, ScalarFunction &bound_function,
|
|
91830
|
+
vector<unique_ptr<Expression>> &arguments) {
|
|
91831
|
+
std::uniform_int_distribution<uint32_t> dist;
|
|
91832
|
+
return make_unique<UUIDRandomBindData>(context, dist);
|
|
91833
|
+
}
|
|
91834
|
+
|
|
91835
|
+
static void GenerateUUIDFunction(DataChunk &args, ExpressionState &state, Vector &result) {
|
|
91836
|
+
D_ASSERT(args.ColumnCount() == 0);
|
|
91837
|
+
auto &func_expr = (BoundFunctionExpression &)state.expr;
|
|
91838
|
+
auto &info = (UUIDRandomBindData &)*func_expr.bind_info;
|
|
91839
|
+
|
|
91840
|
+
result.SetVectorType(VectorType::FLAT_VECTOR);
|
|
91841
|
+
auto result_data = FlatVector::GetData<hugeint_t>(result);
|
|
91842
|
+
for (idx_t i = 0; i < args.size(); i++) {
|
|
91843
|
+
uint8_t bytes[16];
|
|
91844
|
+
for (int i = 0; i < 16; i += 4) {
|
|
91845
|
+
*reinterpret_cast<uint32_t *>(bytes + i) = info.dist(info.context.random_engine);
|
|
91846
|
+
}
|
|
91847
|
+
// variant must be 10xxxxxx
|
|
91848
|
+
bytes[8] &= 0xBF;
|
|
91849
|
+
bytes[8] |= 0x80;
|
|
91850
|
+
// version must be 0100xxxx
|
|
91851
|
+
bytes[6] &= 0x4F;
|
|
91852
|
+
bytes[6] |= 0x40;
|
|
91853
|
+
|
|
91854
|
+
result_data[i].upper = 0;
|
|
91855
|
+
result_data[i].upper |= ((int64_t)bytes[0] << 56);
|
|
91856
|
+
result_data[i].upper |= ((int64_t)bytes[1] << 48);
|
|
91857
|
+
result_data[i].upper |= ((int64_t)bytes[3] << 40);
|
|
91858
|
+
result_data[i].upper |= ((int64_t)bytes[4] << 32);
|
|
91859
|
+
result_data[i].upper |= ((int64_t)bytes[5] << 24);
|
|
91860
|
+
result_data[i].upper |= ((int64_t)bytes[6] << 16);
|
|
91861
|
+
result_data[i].upper |= ((int64_t)bytes[7] << 8);
|
|
91862
|
+
result_data[i].upper |= bytes[8];
|
|
91863
|
+
result_data[i].lower = 0;
|
|
91864
|
+
result_data[i].lower |= ((uint64_t)bytes[8] << 56);
|
|
91865
|
+
result_data[i].lower |= ((uint64_t)bytes[9] << 48);
|
|
91866
|
+
result_data[i].lower |= ((uint64_t)bytes[10] << 40);
|
|
91867
|
+
result_data[i].lower |= ((uint64_t)bytes[11] << 32);
|
|
91868
|
+
result_data[i].lower |= ((uint64_t)bytes[12] << 24);
|
|
91869
|
+
result_data[i].lower |= ((uint64_t)bytes[13] << 16);
|
|
91870
|
+
result_data[i].lower |= ((uint64_t)bytes[14] << 8);
|
|
91871
|
+
result_data[i].lower |= bytes[15];
|
|
91872
|
+
}
|
|
91873
|
+
}
|
|
91874
|
+
|
|
91875
|
+
void UUIDFun::RegisterFunction(BuiltinFunctions &set) {
|
|
91876
|
+
// generate a random uuid
|
|
91877
|
+
set.AddFunction(
|
|
91878
|
+
ScalarFunction("gen_random_uuid", {}, LogicalType::UUID, GenerateUUIDFunction, true, UUIDRandomBind));
|
|
91879
|
+
}
|
|
91880
|
+
|
|
91881
|
+
} // namespace duckdb
|
|
91882
|
+
|
|
91883
|
+
|
|
91884
|
+
|
|
91885
|
+
|
|
91886
|
+
|
|
91786
91887
|
|
|
91787
91888
|
|
|
91788
91889
|
|
|
@@ -130027,16 +130128,23 @@ unique_ptr<ParsedExpression> Transformer::TransformFuncCall(duckdb_libpgquery::P
|
|
|
130027
130128
|
throw ParserException("Cannot use multiple ORDER BY clauses with WITHIN GROUP");
|
|
130028
130129
|
}
|
|
130029
130130
|
if (lowercase_name == "percentile_cont") {
|
|
130131
|
+
if (children.size() != 1) {
|
|
130132
|
+
throw ParserException("Wrong number of arguments for PERCENTILE_CONT");
|
|
130133
|
+
}
|
|
130030
130134
|
lowercase_name = "quantile_cont";
|
|
130031
130135
|
} else if (lowercase_name == "percentile_disc") {
|
|
130136
|
+
if (children.size() != 1) {
|
|
130137
|
+
throw ParserException("Wrong number of arguments for PERCENTILE_DISC");
|
|
130138
|
+
}
|
|
130032
130139
|
lowercase_name = "quantile_disc";
|
|
130033
130140
|
} else if (lowercase_name == "mode") {
|
|
130141
|
+
if (!children.empty()) {
|
|
130142
|
+
throw ParserException("Wrong number of arguments for MODE");
|
|
130143
|
+
}
|
|
130034
130144
|
lowercase_name = "mode";
|
|
130035
130145
|
} else {
|
|
130036
130146
|
throw ParserException("Unknown ordered aggregate \"%s\".", function_name);
|
|
130037
130147
|
}
|
|
130038
|
-
children.insert(children.begin(), move(order_bys->orders[0].expression));
|
|
130039
|
-
order_bys->orders.clear();
|
|
130040
130148
|
}
|
|
130041
130149
|
|
|
130042
130150
|
// star gets eaten in the parser
|
|
@@ -134148,6 +134256,7 @@ void BindContext::AddContext(BindContext other) {
|
|
|
134148
134256
|
|
|
134149
134257
|
|
|
134150
134258
|
|
|
134259
|
+
|
|
134151
134260
|
//===----------------------------------------------------------------------===//
|
|
134152
134261
|
// DuckDB
|
|
134153
134262
|
//
|
|
@@ -134365,8 +134474,30 @@ public:
|
|
|
134365
134474
|
|
|
134366
134475
|
|
|
134367
134476
|
|
|
134477
|
+
|
|
134368
134478
|
namespace duckdb {
|
|
134369
134479
|
|
|
134480
|
+
static void InvertPercentileFractions(unique_ptr<ParsedExpression> &fractions) {
|
|
134481
|
+
D_ASSERT(fractions.get());
|
|
134482
|
+
D_ASSERT(fractions->expression_class == ExpressionClass::BOUND_EXPRESSION);
|
|
134483
|
+
auto &bound = (BoundExpression &)*fractions;
|
|
134484
|
+
|
|
134485
|
+
if (!bound.expr->IsFoldable()) {
|
|
134486
|
+
return;
|
|
134487
|
+
}
|
|
134488
|
+
|
|
134489
|
+
Value value = ExpressionExecutor::EvaluateScalar(*bound.expr);
|
|
134490
|
+
if (value.type().id() == LogicalTypeId::LIST) {
|
|
134491
|
+
vector<Value> values;
|
|
134492
|
+
for (const auto &element_val : value.list_value) {
|
|
134493
|
+
values.emplace_back(Value(1) - element_val);
|
|
134494
|
+
}
|
|
134495
|
+
bound.expr = make_unique<BoundConstantExpression>(Value::LIST(values));
|
|
134496
|
+
} else {
|
|
134497
|
+
bound.expr = make_unique<BoundConstantExpression>(Value(1) - value);
|
|
134498
|
+
}
|
|
134499
|
+
}
|
|
134500
|
+
|
|
134370
134501
|
BindResult SelectBinder::BindAggregate(FunctionExpression &aggr, AggregateFunctionCatalogEntry *func, idx_t depth) {
|
|
134371
134502
|
// first bind the child of the aggregate expression (if any)
|
|
134372
134503
|
this->bound_aggregate = true;
|
|
@@ -134379,8 +134510,28 @@ BindResult SelectBinder::BindAggregate(FunctionExpression &aggr, AggregateFuncti
|
|
|
134379
134510
|
aggregate_binder.BindChild(aggr.filter, 0, error);
|
|
134380
134511
|
}
|
|
134381
134512
|
|
|
134513
|
+
// Handle ordered-set aggregates by moving the single ORDER BY expression to the front of the children.
|
|
134514
|
+
// https://www.postgresql.org/docs/current/functions-aggregate.html#FUNCTIONS-ORDEREDSET-TABLE
|
|
134515
|
+
bool ordered_set_agg = false;
|
|
134516
|
+
bool invert_fractions = false;
|
|
134517
|
+
if (aggr.order_bys && aggr.order_bys->orders.size() == 1) {
|
|
134518
|
+
const auto &func_name = aggr.function_name;
|
|
134519
|
+
ordered_set_agg = (func_name == "quantile_cont" || func_name == "quantile_disc" || func_name == "mode");
|
|
134520
|
+
|
|
134521
|
+
if (ordered_set_agg) {
|
|
134522
|
+
auto &config = DBConfig::GetConfig(context);
|
|
134523
|
+
const auto &order = aggr.order_bys->orders[0];
|
|
134524
|
+
const auto sense = (order.type == OrderType::ORDER_DEFAULT) ? config.default_order_type : order.type;
|
|
134525
|
+
invert_fractions = (sense == OrderType::DESCENDING);
|
|
134526
|
+
}
|
|
134527
|
+
}
|
|
134528
|
+
|
|
134382
134529
|
for (auto &child : aggr.children) {
|
|
134383
134530
|
aggregate_binder.BindChild(child, 0, error);
|
|
134531
|
+
// We have to invert the fractions for PERCENTILE_XXXX DESC
|
|
134532
|
+
if (invert_fractions) {
|
|
134533
|
+
InvertPercentileFractions(child);
|
|
134534
|
+
}
|
|
134384
134535
|
}
|
|
134385
134536
|
|
|
134386
134537
|
// Bind the ORDER BYs, if any
|
|
@@ -134442,6 +134593,17 @@ BindResult SelectBinder::BindAggregate(FunctionExpression &aggr, AggregateFuncti
|
|
|
134442
134593
|
vector<LogicalType> types;
|
|
134443
134594
|
vector<LogicalType> arguments;
|
|
134444
134595
|
vector<unique_ptr<Expression>> children;
|
|
134596
|
+
|
|
134597
|
+
if (ordered_set_agg) {
|
|
134598
|
+
for (auto &order : aggr.order_bys->orders) {
|
|
134599
|
+
auto &child = (BoundExpression &)*order.expression;
|
|
134600
|
+
types.push_back(child.expr->return_type);
|
|
134601
|
+
arguments.push_back(child.expr->return_type);
|
|
134602
|
+
children.push_back(move(child.expr));
|
|
134603
|
+
}
|
|
134604
|
+
aggr.order_bys->orders.clear();
|
|
134605
|
+
}
|
|
134606
|
+
|
|
134445
134607
|
for (idx_t i = 0; i < aggr.children.size(); i++) {
|
|
134446
134608
|
auto &child = (BoundExpression &)*aggr.children[i];
|
|
134447
134609
|
types.push_back(child.expr->return_type);
|
package/src/duckdb.hpp
CHANGED
|
@@ -10,8 +10,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|
|
10
10
|
|
|
11
11
|
#pragma once
|
|
12
12
|
#define DUCKDB_AMALGAMATION 1
|
|
13
|
-
#define DUCKDB_SOURCE_ID "
|
|
14
|
-
#define DUCKDB_VERSION "0.3.1-
|
|
13
|
+
#define DUCKDB_SOURCE_ID "041bb3216"
|
|
14
|
+
#define DUCKDB_VERSION "0.3.1-dev291"
|
|
15
15
|
//===----------------------------------------------------------------------===//
|
|
16
16
|
// DuckDB
|
|
17
17
|
//
|