duckdb 0.3.2-dev481.0 → 0.3.2-dev499.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 +720 -88
- package/src/duckdb.hpp +18 -6
package/package.json
CHANGED
package/src/duckdb.cpp
CHANGED
|
@@ -421,7 +421,7 @@ public:
|
|
|
421
421
|
string schema_name;
|
|
422
422
|
//! Table name
|
|
423
423
|
string table_name;
|
|
424
|
-
//!
|
|
424
|
+
//! Aliases for the column names
|
|
425
425
|
vector<string> column_name_alias;
|
|
426
426
|
|
|
427
427
|
public:
|
|
@@ -2380,7 +2380,7 @@ namespace duckdb {
|
|
|
2380
2380
|
enum class AlterType : uint8_t { INVALID = 0, ALTER_TABLE = 1, ALTER_VIEW = 2 };
|
|
2381
2381
|
|
|
2382
2382
|
struct AlterInfo : public ParseInfo {
|
|
2383
|
-
AlterInfo(AlterType type, string schema, string name) : type(type), schema(schema), name(name) {
|
|
2383
|
+
AlterInfo(AlterType type, string schema, string name) : type(type), schema(move(schema)), name(move(name)) {
|
|
2384
2384
|
}
|
|
2385
2385
|
~AlterInfo() override {
|
|
2386
2386
|
}
|
|
@@ -11690,6 +11690,14 @@ const char *Exception::what() const noexcept {
|
|
|
11690
11690
|
return exception_message_.c_str();
|
|
11691
11691
|
}
|
|
11692
11692
|
|
|
11693
|
+
bool Exception::UncaughtException() {
|
|
11694
|
+
#if __cplusplus >= 201703L
|
|
11695
|
+
return std::uncaught_exceptions() > 0;
|
|
11696
|
+
#else
|
|
11697
|
+
return std::uncaught_exception();
|
|
11698
|
+
#endif
|
|
11699
|
+
}
|
|
11700
|
+
|
|
11693
11701
|
string Exception::ConstructMessageRecursive(const string &msg, vector<ExceptionFormatValue> &values) {
|
|
11694
11702
|
return ExceptionFormatValue::Format(msg, values);
|
|
11695
11703
|
}
|
|
@@ -20653,7 +20661,7 @@ public:
|
|
|
20653
20661
|
|
|
20654
20662
|
MiniZStreamWrapper::~MiniZStreamWrapper() {
|
|
20655
20663
|
// avoid closing if destroyed during stack unwinding
|
|
20656
|
-
if (
|
|
20664
|
+
if (Exception::UncaughtException()) {
|
|
20657
20665
|
return;
|
|
20658
20666
|
}
|
|
20659
20667
|
try {
|
|
@@ -39860,6 +39868,7 @@ hugeint_t ModuloOperator::Operation(hugeint_t left, hugeint_t right);
|
|
|
39860
39868
|
|
|
39861
39869
|
|
|
39862
39870
|
|
|
39871
|
+
|
|
39863
39872
|
namespace duckdb {
|
|
39864
39873
|
|
|
39865
39874
|
Value::Value(LogicalType type) : type_(move(type)), is_null(true) {
|
|
@@ -39928,66 +39937,47 @@ Value Value::MinimumValue(const LogicalType &type) {
|
|
|
39928
39937
|
case LogicalTypeId::UBIGINT:
|
|
39929
39938
|
return Value::UBIGINT(NumericLimits<uint64_t>::Minimum());
|
|
39930
39939
|
case LogicalTypeId::DATE:
|
|
39931
|
-
return Value::DATE(
|
|
39940
|
+
return Value::DATE(Date::FromDate(Date::DATE_MIN_YEAR, Date::DATE_MIN_MONTH, Date::DATE_MIN_DAY));
|
|
39932
39941
|
case LogicalTypeId::TIME:
|
|
39933
39942
|
return Value::TIME(dtime_t(0));
|
|
39934
39943
|
case LogicalTypeId::TIMESTAMP:
|
|
39935
|
-
return Value::TIMESTAMP(
|
|
39944
|
+
return Value::TIMESTAMP(Date::FromDate(Timestamp::MIN_YEAR, Timestamp::MIN_MONTH, Timestamp::MIN_DAY),
|
|
39945
|
+
dtime_t(0));
|
|
39936
39946
|
case LogicalTypeId::TIMESTAMP_SEC:
|
|
39937
|
-
return
|
|
39947
|
+
return MinimumValue(LogicalType::TIMESTAMP).CastAs(LogicalType::TIMESTAMP_S);
|
|
39938
39948
|
case LogicalTypeId::TIMESTAMP_MS:
|
|
39939
|
-
return
|
|
39949
|
+
return MinimumValue(LogicalType::TIMESTAMP).CastAs(LogicalType::TIMESTAMP_MS);
|
|
39940
39950
|
case LogicalTypeId::TIMESTAMP_NS:
|
|
39941
|
-
return Value::
|
|
39951
|
+
return Value::TIMESTAMPNS(timestamp_t(NumericLimits<int64_t>::Minimum()));
|
|
39942
39952
|
case LogicalTypeId::DATE_TZ:
|
|
39943
39953
|
return Value::DATETZ(date_t(NumericLimits<int32_t>::Minimum()));
|
|
39944
39954
|
case LogicalTypeId::TIME_TZ:
|
|
39945
39955
|
return Value::TIMETZ(dtime_t(0));
|
|
39946
39956
|
case LogicalTypeId::TIMESTAMP_TZ:
|
|
39947
|
-
return Value::TIMESTAMPTZ(
|
|
39957
|
+
return Value::TIMESTAMPTZ(Timestamp::FromDatetime(
|
|
39958
|
+
Date::FromDate(Timestamp::MIN_YEAR, Timestamp::MIN_MONTH, Timestamp::MIN_DAY), dtime_t(0)));
|
|
39948
39959
|
case LogicalTypeId::FLOAT:
|
|
39949
39960
|
return Value::FLOAT(NumericLimits<float>::Minimum());
|
|
39950
39961
|
case LogicalTypeId::DOUBLE:
|
|
39951
39962
|
return Value::DOUBLE(NumericLimits<double>::Minimum());
|
|
39952
39963
|
case LogicalTypeId::DECIMAL: {
|
|
39953
|
-
|
|
39964
|
+
auto width = DecimalType::GetWidth(type);
|
|
39965
|
+
auto scale = DecimalType::GetScale(type);
|
|
39954
39966
|
switch (type.InternalType()) {
|
|
39955
39967
|
case PhysicalType::INT16:
|
|
39956
|
-
|
|
39957
|
-
break;
|
|
39968
|
+
return Value::DECIMAL(int16_t(-NumericHelper::POWERS_OF_TEN[width] + 1), width, scale);
|
|
39958
39969
|
case PhysicalType::INT32:
|
|
39959
|
-
|
|
39960
|
-
break;
|
|
39970
|
+
return Value::DECIMAL(int32_t(-NumericHelper::POWERS_OF_TEN[width] + 1), width, scale);
|
|
39961
39971
|
case PhysicalType::INT64:
|
|
39962
|
-
|
|
39963
|
-
break;
|
|
39972
|
+
return Value::DECIMAL(int64_t(-NumericHelper::POWERS_OF_TEN[width] + 1), width, scale);
|
|
39964
39973
|
case PhysicalType::INT128:
|
|
39965
|
-
|
|
39966
|
-
break;
|
|
39974
|
+
return Value::DECIMAL(-Hugeint::POWERS_OF_TEN[width] + 1, width, scale);
|
|
39967
39975
|
default:
|
|
39968
39976
|
throw InternalException("Unknown decimal type");
|
|
39969
39977
|
}
|
|
39970
|
-
result.type_ = type;
|
|
39971
|
-
return result;
|
|
39972
|
-
}
|
|
39973
|
-
case LogicalTypeId::ENUM: {
|
|
39974
|
-
Value result;
|
|
39975
|
-
switch (type.InternalType()) {
|
|
39976
|
-
case PhysicalType::UINT8:
|
|
39977
|
-
result = Value::MinimumValue(LogicalType::UTINYINT);
|
|
39978
|
-
break;
|
|
39979
|
-
case PhysicalType::UINT16:
|
|
39980
|
-
result = Value::MinimumValue(LogicalType::USMALLINT);
|
|
39981
|
-
break;
|
|
39982
|
-
case PhysicalType::UINT32:
|
|
39983
|
-
result = Value::MinimumValue(LogicalType::UINTEGER);
|
|
39984
|
-
break;
|
|
39985
|
-
default:
|
|
39986
|
-
throw InternalException("ENUM can only have unsigned integers (except UINT64) as physical types");
|
|
39987
|
-
}
|
|
39988
|
-
result.type_ = type;
|
|
39989
|
-
return result;
|
|
39990
39978
|
}
|
|
39979
|
+
case LogicalTypeId::ENUM:
|
|
39980
|
+
return Value::ENUM(0, type);
|
|
39991
39981
|
default:
|
|
39992
39982
|
throw InvalidTypeException(type, "MinimumValue requires numeric type");
|
|
39993
39983
|
}
|
|
@@ -39996,7 +39986,7 @@ Value Value::MinimumValue(const LogicalType &type) {
|
|
|
39996
39986
|
Value Value::MaximumValue(const LogicalType &type) {
|
|
39997
39987
|
switch (type.id()) {
|
|
39998
39988
|
case LogicalTypeId::BOOLEAN:
|
|
39999
|
-
return Value::BOOLEAN(
|
|
39989
|
+
return Value::BOOLEAN(true);
|
|
40000
39990
|
case LogicalTypeId::TINYINT:
|
|
40001
39991
|
return Value::TINYINT(NumericLimits<int8_t>::Maximum());
|
|
40002
39992
|
case LogicalTypeId::SMALLINT:
|
|
@@ -40019,21 +40009,21 @@ Value Value::MaximumValue(const LogicalType &type) {
|
|
|
40019
40009
|
case LogicalTypeId::UBIGINT:
|
|
40020
40010
|
return Value::UBIGINT(NumericLimits<uint64_t>::Maximum());
|
|
40021
40011
|
case LogicalTypeId::DATE:
|
|
40022
|
-
return Value::DATE(
|
|
40012
|
+
return Value::DATE(Date::FromDate(Date::DATE_MAX_YEAR, Date::DATE_MAX_MONTH, Date::DATE_MAX_DAY));
|
|
40023
40013
|
case LogicalTypeId::TIME:
|
|
40024
|
-
return Value::TIME(dtime_t(Interval::SECS_PER_DAY * Interval::MICROS_PER_SEC));
|
|
40014
|
+
return Value::TIME(dtime_t(Interval::SECS_PER_DAY * Interval::MICROS_PER_SEC - 1));
|
|
40025
40015
|
case LogicalTypeId::TIMESTAMP:
|
|
40026
40016
|
return Value::TIMESTAMP(timestamp_t(NumericLimits<int64_t>::Maximum()));
|
|
40027
40017
|
case LogicalTypeId::TIMESTAMP_MS:
|
|
40028
|
-
return
|
|
40018
|
+
return MaximumValue(LogicalType::TIMESTAMP).CastAs(LogicalType::TIMESTAMP_MS);
|
|
40029
40019
|
case LogicalTypeId::TIMESTAMP_NS:
|
|
40030
|
-
return Value::
|
|
40020
|
+
return Value::TIMESTAMPNS(timestamp_t(NumericLimits<int64_t>::Maximum()));
|
|
40031
40021
|
case LogicalTypeId::TIMESTAMP_SEC:
|
|
40032
|
-
return
|
|
40022
|
+
return MaximumValue(LogicalType::TIMESTAMP).CastAs(LogicalType::TIMESTAMP_S);
|
|
40033
40023
|
case LogicalTypeId::DATE_TZ:
|
|
40034
40024
|
return Value::DATETZ(date_t(NumericLimits<int32_t>::Maximum()));
|
|
40035
40025
|
case LogicalTypeId::TIME_TZ:
|
|
40036
|
-
return Value::TIMETZ(dtime_t(Interval::SECS_PER_DAY * Interval::MICROS_PER_SEC));
|
|
40026
|
+
return Value::TIMETZ(dtime_t(Interval::SECS_PER_DAY * Interval::MICROS_PER_SEC - 1));
|
|
40037
40027
|
case LogicalTypeId::TIMESTAMP_TZ:
|
|
40038
40028
|
return Value::TIMESTAMPTZ(timestamp_t(NumericLimits<int64_t>::Maximum()));
|
|
40039
40029
|
case LogicalTypeId::FLOAT:
|
|
@@ -40041,44 +40031,23 @@ Value Value::MaximumValue(const LogicalType &type) {
|
|
|
40041
40031
|
case LogicalTypeId::DOUBLE:
|
|
40042
40032
|
return Value::DOUBLE(NumericLimits<double>::Maximum());
|
|
40043
40033
|
case LogicalTypeId::DECIMAL: {
|
|
40044
|
-
|
|
40034
|
+
auto width = DecimalType::GetWidth(type);
|
|
40035
|
+
auto scale = DecimalType::GetScale(type);
|
|
40045
40036
|
switch (type.InternalType()) {
|
|
40046
40037
|
case PhysicalType::INT16:
|
|
40047
|
-
|
|
40048
|
-
break;
|
|
40038
|
+
return Value::DECIMAL(int16_t(NumericHelper::POWERS_OF_TEN[width] - 1), width, scale);
|
|
40049
40039
|
case PhysicalType::INT32:
|
|
40050
|
-
|
|
40051
|
-
break;
|
|
40040
|
+
return Value::DECIMAL(int32_t(NumericHelper::POWERS_OF_TEN[width] - 1), width, scale);
|
|
40052
40041
|
case PhysicalType::INT64:
|
|
40053
|
-
|
|
40054
|
-
break;
|
|
40042
|
+
return Value::DECIMAL(int64_t(NumericHelper::POWERS_OF_TEN[width] - 1), width, scale);
|
|
40055
40043
|
case PhysicalType::INT128:
|
|
40056
|
-
|
|
40057
|
-
break;
|
|
40044
|
+
return Value::DECIMAL(Hugeint::POWERS_OF_TEN[width] - 1, width, scale);
|
|
40058
40045
|
default:
|
|
40059
40046
|
throw InternalException("Unknown decimal type");
|
|
40060
40047
|
}
|
|
40061
|
-
result.type_ = type;
|
|
40062
|
-
return result;
|
|
40063
|
-
}
|
|
40064
|
-
case LogicalTypeId::ENUM: {
|
|
40065
|
-
Value result;
|
|
40066
|
-
switch (type.InternalType()) {
|
|
40067
|
-
case PhysicalType::UINT8:
|
|
40068
|
-
result = Value::MaximumValue(LogicalType::UTINYINT);
|
|
40069
|
-
break;
|
|
40070
|
-
case PhysicalType::UINT16:
|
|
40071
|
-
result = Value::MaximumValue(LogicalType::USMALLINT);
|
|
40072
|
-
break;
|
|
40073
|
-
case PhysicalType::UINT32:
|
|
40074
|
-
result = Value::MaximumValue(LogicalType::UINTEGER);
|
|
40075
|
-
break;
|
|
40076
|
-
default:
|
|
40077
|
-
throw InternalException("ENUM can only have unsigned integers (except UINT64) as physical types");
|
|
40078
|
-
}
|
|
40079
|
-
result.type_ = type;
|
|
40080
|
-
return result;
|
|
40081
40048
|
}
|
|
40049
|
+
case LogicalTypeId::ENUM:
|
|
40050
|
+
return Value::ENUM(EnumType::GetSize(type) - 1, type);
|
|
40082
40051
|
default:
|
|
40083
40052
|
throw InvalidTypeException(type, "MaximumValue requires numeric type");
|
|
40084
40053
|
}
|
|
@@ -40311,21 +40280,21 @@ Value Value::TIMESTAMPTZ(timestamp_t value) {
|
|
|
40311
40280
|
return result;
|
|
40312
40281
|
}
|
|
40313
40282
|
|
|
40314
|
-
Value Value::
|
|
40283
|
+
Value Value::TIMESTAMPNS(timestamp_t timestamp) {
|
|
40315
40284
|
Value result(LogicalType::TIMESTAMP_NS);
|
|
40316
40285
|
result.value_.timestamp = timestamp;
|
|
40317
40286
|
result.is_null = false;
|
|
40318
40287
|
return result;
|
|
40319
40288
|
}
|
|
40320
40289
|
|
|
40321
|
-
Value Value::
|
|
40290
|
+
Value Value::TIMESTAMPMS(timestamp_t timestamp) {
|
|
40322
40291
|
Value result(LogicalType::TIMESTAMP_MS);
|
|
40323
40292
|
result.value_.timestamp = timestamp;
|
|
40324
40293
|
result.is_null = false;
|
|
40325
40294
|
return result;
|
|
40326
40295
|
}
|
|
40327
40296
|
|
|
40328
|
-
Value Value::
|
|
40297
|
+
Value Value::TIMESTAMPSEC(timestamp_t timestamp) {
|
|
40329
40298
|
Value result(LogicalType::TIMESTAMP_S);
|
|
40330
40299
|
result.value_.timestamp = timestamp;
|
|
40331
40300
|
result.is_null = false;
|
|
@@ -40386,6 +40355,16 @@ Value Value::LIST(vector<Value> values) {
|
|
|
40386
40355
|
return result;
|
|
40387
40356
|
}
|
|
40388
40357
|
|
|
40358
|
+
Value Value::LIST(LogicalType child_type, vector<Value> values) {
|
|
40359
|
+
if (values.empty()) {
|
|
40360
|
+
return Value::EMPTYLIST(move(child_type));
|
|
40361
|
+
}
|
|
40362
|
+
for (auto &val : values) {
|
|
40363
|
+
val = val.CastAs(child_type);
|
|
40364
|
+
}
|
|
40365
|
+
return Value::LIST(move(values));
|
|
40366
|
+
}
|
|
40367
|
+
|
|
40389
40368
|
Value Value::EMPTYLIST(LogicalType child_type) {
|
|
40390
40369
|
Value result;
|
|
40391
40370
|
result.type_ = LogicalType::LIST(move(child_type));
|
|
@@ -40729,11 +40708,17 @@ Value Value::Numeric(const LogicalType &type, int64_t value) {
|
|
|
40729
40708
|
case LogicalTypeId::TIMESTAMP:
|
|
40730
40709
|
return Value::TIMESTAMP(timestamp_t(value));
|
|
40731
40710
|
case LogicalTypeId::TIMESTAMP_NS:
|
|
40732
|
-
return Value::
|
|
40711
|
+
return Value::TIMESTAMPNS(timestamp_t(value));
|
|
40733
40712
|
case LogicalTypeId::TIMESTAMP_MS:
|
|
40734
|
-
return Value::
|
|
40713
|
+
return Value::TIMESTAMPMS(timestamp_t(value));
|
|
40735
40714
|
case LogicalTypeId::TIMESTAMP_SEC:
|
|
40736
|
-
return Value::
|
|
40715
|
+
return Value::TIMESTAMPSEC(timestamp_t(value));
|
|
40716
|
+
case LogicalTypeId::DATE_TZ:
|
|
40717
|
+
return Value::DATETZ(date_t(value));
|
|
40718
|
+
case LogicalTypeId::TIME_TZ:
|
|
40719
|
+
return Value::TIMETZ(dtime_t(value));
|
|
40720
|
+
case LogicalTypeId::TIMESTAMP_TZ:
|
|
40721
|
+
return Value::TIMESTAMPTZ(timestamp_t(value));
|
|
40737
40722
|
case LogicalTypeId::ENUM:
|
|
40738
40723
|
switch (type.InternalType()) {
|
|
40739
40724
|
case PhysicalType::UINT8:
|
|
@@ -41763,11 +41748,11 @@ Value Vector::GetValue(idx_t index) const {
|
|
|
41763
41748
|
case LogicalTypeId::TIMESTAMP:
|
|
41764
41749
|
return Value::TIMESTAMP(((timestamp_t *)data)[index]);
|
|
41765
41750
|
case LogicalTypeId::TIMESTAMP_NS:
|
|
41766
|
-
return Value::
|
|
41751
|
+
return Value::TIMESTAMPNS(((timestamp_t *)data)[index]);
|
|
41767
41752
|
case LogicalTypeId::TIMESTAMP_MS:
|
|
41768
|
-
return Value::
|
|
41753
|
+
return Value::TIMESTAMPMS(((timestamp_t *)data)[index]);
|
|
41769
41754
|
case LogicalTypeId::TIMESTAMP_SEC:
|
|
41770
|
-
return Value::
|
|
41755
|
+
return Value::TIMESTAMPSEC(((timestamp_t *)data)[index]);
|
|
41771
41756
|
case LogicalTypeId::TIMESTAMP_TZ:
|
|
41772
41757
|
return Value::TIMESTAMPTZ(((timestamp_t *)data)[index]);
|
|
41773
41758
|
case LogicalTypeId::HUGEINT:
|
|
@@ -41948,7 +41933,7 @@ void Vector::Normalify(idx_t count) {
|
|
|
41948
41933
|
// allocate a new buffer for the vector
|
|
41949
41934
|
auto old_buffer = move(buffer);
|
|
41950
41935
|
auto old_data = data;
|
|
41951
|
-
buffer = VectorBuffer::CreateStandardVector(type);
|
|
41936
|
+
buffer = VectorBuffer::CreateStandardVector(type, MaxValue<idx_t>(STANDARD_VECTOR_SIZE, count));
|
|
41952
41937
|
data = buffer->GetData();
|
|
41953
41938
|
vector_type = VectorType::FLAT_VECTOR;
|
|
41954
41939
|
if (is_null) {
|
|
@@ -44495,6 +44480,13 @@ LogicalType LogicalType::MAP(child_list_t<LogicalType> children) {
|
|
|
44495
44480
|
return LogicalType(LogicalTypeId::MAP, move(info));
|
|
44496
44481
|
}
|
|
44497
44482
|
|
|
44483
|
+
LogicalType LogicalType::MAP(LogicalType key, LogicalType value) {
|
|
44484
|
+
child_list_t<LogicalType> child_types;
|
|
44485
|
+
child_types.push_back({"key", LogicalType::LIST(move(key))});
|
|
44486
|
+
child_types.push_back({"value", LogicalType::LIST(move(value))});
|
|
44487
|
+
return LogicalType::MAP(move(child_types));
|
|
44488
|
+
}
|
|
44489
|
+
|
|
44498
44490
|
//===--------------------------------------------------------------------===//
|
|
44499
44491
|
// User Type
|
|
44500
44492
|
//===--------------------------------------------------------------------===//
|
|
@@ -97206,6 +97198,10 @@ struct DuckDBDependenciesFun {
|
|
|
97206
97198
|
static void RegisterFunction(BuiltinFunctions &set);
|
|
97207
97199
|
};
|
|
97208
97200
|
|
|
97201
|
+
struct DuckDBFunctionsFun {
|
|
97202
|
+
static void RegisterFunction(BuiltinFunctions &set);
|
|
97203
|
+
};
|
|
97204
|
+
|
|
97209
97205
|
struct DuckDBIndexesFun {
|
|
97210
97206
|
static void RegisterFunction(BuiltinFunctions &set);
|
|
97211
97207
|
};
|
|
@@ -97230,6 +97226,10 @@ struct DuckDBViewsFun {
|
|
|
97230
97226
|
static void RegisterFunction(BuiltinFunctions &set);
|
|
97231
97227
|
};
|
|
97232
97228
|
|
|
97229
|
+
struct TestAllTypesFun {
|
|
97230
|
+
static void RegisterFunction(BuiltinFunctions &set);
|
|
97231
|
+
};
|
|
97232
|
+
|
|
97233
97233
|
} // namespace duckdb
|
|
97234
97234
|
|
|
97235
97235
|
|
|
@@ -98921,6 +98921,420 @@ void DuckDBDependenciesFun::RegisterFunction(BuiltinFunctions &set) {
|
|
|
98921
98921
|
|
|
98922
98922
|
|
|
98923
98923
|
|
|
98924
|
+
|
|
98925
|
+
|
|
98926
|
+
namespace duckdb {
|
|
98927
|
+
|
|
98928
|
+
struct DuckDBFunctionsData : public FunctionOperatorData {
|
|
98929
|
+
DuckDBFunctionsData() : offset(0), offset_in_entry(0) {
|
|
98930
|
+
}
|
|
98931
|
+
|
|
98932
|
+
vector<CatalogEntry *> entries;
|
|
98933
|
+
idx_t offset;
|
|
98934
|
+
idx_t offset_in_entry;
|
|
98935
|
+
};
|
|
98936
|
+
|
|
98937
|
+
static unique_ptr<FunctionData> DuckDBFunctionsBind(ClientContext &context, vector<Value> &inputs,
|
|
98938
|
+
unordered_map<string, Value> &named_parameters,
|
|
98939
|
+
vector<LogicalType> &input_table_types,
|
|
98940
|
+
vector<string> &input_table_names,
|
|
98941
|
+
vector<LogicalType> &return_types, vector<string> &names) {
|
|
98942
|
+
names.emplace_back("schema_name");
|
|
98943
|
+
return_types.emplace_back(LogicalType::VARCHAR);
|
|
98944
|
+
|
|
98945
|
+
names.emplace_back("function_name");
|
|
98946
|
+
return_types.emplace_back(LogicalType::VARCHAR);
|
|
98947
|
+
|
|
98948
|
+
names.emplace_back("function_type");
|
|
98949
|
+
return_types.emplace_back(LogicalType::VARCHAR);
|
|
98950
|
+
|
|
98951
|
+
names.emplace_back("description");
|
|
98952
|
+
return_types.emplace_back(LogicalType::VARCHAR);
|
|
98953
|
+
|
|
98954
|
+
names.emplace_back("return_type");
|
|
98955
|
+
return_types.emplace_back(LogicalType::VARCHAR);
|
|
98956
|
+
|
|
98957
|
+
names.emplace_back("parameters");
|
|
98958
|
+
return_types.push_back(LogicalType::LIST(LogicalType::VARCHAR));
|
|
98959
|
+
|
|
98960
|
+
names.emplace_back("parameter_types");
|
|
98961
|
+
return_types.push_back(LogicalType::LIST(LogicalType::VARCHAR));
|
|
98962
|
+
|
|
98963
|
+
names.emplace_back("varargs");
|
|
98964
|
+
return_types.emplace_back(LogicalType::VARCHAR);
|
|
98965
|
+
|
|
98966
|
+
names.emplace_back("macro_definition");
|
|
98967
|
+
return_types.emplace_back(LogicalType::VARCHAR);
|
|
98968
|
+
|
|
98969
|
+
return nullptr;
|
|
98970
|
+
}
|
|
98971
|
+
|
|
98972
|
+
static void ExtractFunctionsFromSchema(ClientContext &context, SchemaCatalogEntry &schema,
|
|
98973
|
+
DuckDBFunctionsData &result) {
|
|
98974
|
+
schema.Scan(context, CatalogType::SCALAR_FUNCTION_ENTRY,
|
|
98975
|
+
[&](CatalogEntry *entry) { result.entries.push_back(entry); });
|
|
98976
|
+
schema.Scan(context, CatalogType::TABLE_FUNCTION_ENTRY,
|
|
98977
|
+
[&](CatalogEntry *entry) { result.entries.push_back(entry); });
|
|
98978
|
+
schema.Scan(context, CatalogType::PRAGMA_FUNCTION_ENTRY,
|
|
98979
|
+
[&](CatalogEntry *entry) { result.entries.push_back(entry); });
|
|
98980
|
+
}
|
|
98981
|
+
|
|
98982
|
+
unique_ptr<FunctionOperatorData> DuckDBFunctionsInit(ClientContext &context, const FunctionData *bind_data,
|
|
98983
|
+
const vector<column_t> &column_ids,
|
|
98984
|
+
TableFilterCollection *filters) {
|
|
98985
|
+
auto result = make_unique<DuckDBFunctionsData>();
|
|
98986
|
+
|
|
98987
|
+
// scan all the schemas for tables and collect themand collect them
|
|
98988
|
+
auto schemas = Catalog::GetCatalog(context).schemas->GetEntries<SchemaCatalogEntry>(context);
|
|
98989
|
+
for (auto &schema : schemas) {
|
|
98990
|
+
ExtractFunctionsFromSchema(context, *schema, *result);
|
|
98991
|
+
};
|
|
98992
|
+
ExtractFunctionsFromSchema(context, *context.temporary_objects, *result);
|
|
98993
|
+
|
|
98994
|
+
std::sort(result->entries.begin(), result->entries.end(),
|
|
98995
|
+
[&](CatalogEntry *a, CatalogEntry *b) { return (int)a->type < (int)b->type; });
|
|
98996
|
+
return move(result);
|
|
98997
|
+
}
|
|
98998
|
+
|
|
98999
|
+
struct ScalarFunctionExtractor {
|
|
99000
|
+
static idx_t FunctionCount(ScalarFunctionCatalogEntry &entry) {
|
|
99001
|
+
return entry.functions.size();
|
|
99002
|
+
}
|
|
99003
|
+
|
|
99004
|
+
static Value GetFunctionType() {
|
|
99005
|
+
return Value("scalar");
|
|
99006
|
+
}
|
|
99007
|
+
|
|
99008
|
+
static Value GetFunctionDescription(ScalarFunctionCatalogEntry &entry, idx_t offset) {
|
|
99009
|
+
return Value();
|
|
99010
|
+
}
|
|
99011
|
+
|
|
99012
|
+
static Value GetReturnType(ScalarFunctionCatalogEntry &entry, idx_t offset) {
|
|
99013
|
+
return Value(entry.functions[offset].return_type.ToString());
|
|
99014
|
+
}
|
|
99015
|
+
|
|
99016
|
+
static Value GetParameters(ScalarFunctionCatalogEntry &entry, idx_t offset) {
|
|
99017
|
+
vector<Value> results;
|
|
99018
|
+
for (idx_t i = 0; i < entry.functions[offset].arguments.size(); i++) {
|
|
99019
|
+
results.emplace_back("col" + to_string(i));
|
|
99020
|
+
}
|
|
99021
|
+
return Value::LIST(LogicalType::VARCHAR, move(results));
|
|
99022
|
+
}
|
|
99023
|
+
|
|
99024
|
+
static Value GetParameterTypes(ScalarFunctionCatalogEntry &entry, idx_t offset) {
|
|
99025
|
+
vector<Value> results;
|
|
99026
|
+
for (idx_t i = 0; i < entry.functions[offset].arguments.size(); i++) {
|
|
99027
|
+
results.emplace_back(entry.functions[offset].arguments[i].ToString());
|
|
99028
|
+
}
|
|
99029
|
+
return Value::LIST(LogicalType::VARCHAR, move(results));
|
|
99030
|
+
}
|
|
99031
|
+
|
|
99032
|
+
static Value GetVarArgs(ScalarFunctionCatalogEntry &entry, idx_t offset) {
|
|
99033
|
+
return entry.functions[offset].varargs.id() == LogicalTypeId::INVALID
|
|
99034
|
+
? Value()
|
|
99035
|
+
: Value(entry.functions[offset].varargs.ToString());
|
|
99036
|
+
}
|
|
99037
|
+
|
|
99038
|
+
static Value GetMacroDefinition(ScalarFunctionCatalogEntry &entry, idx_t offset) {
|
|
99039
|
+
return Value();
|
|
99040
|
+
}
|
|
99041
|
+
};
|
|
99042
|
+
|
|
99043
|
+
struct AggregateFunctionExtractor {
|
|
99044
|
+
static idx_t FunctionCount(AggregateFunctionCatalogEntry &entry) {
|
|
99045
|
+
return entry.functions.size();
|
|
99046
|
+
}
|
|
99047
|
+
|
|
99048
|
+
static Value GetFunctionType() {
|
|
99049
|
+
return Value("aggregate");
|
|
99050
|
+
}
|
|
99051
|
+
|
|
99052
|
+
static Value GetFunctionDescription(AggregateFunctionCatalogEntry &entry, idx_t offset) {
|
|
99053
|
+
return Value();
|
|
99054
|
+
}
|
|
99055
|
+
|
|
99056
|
+
static Value GetReturnType(AggregateFunctionCatalogEntry &entry, idx_t offset) {
|
|
99057
|
+
return Value(entry.functions[offset].return_type.ToString());
|
|
99058
|
+
}
|
|
99059
|
+
|
|
99060
|
+
static Value GetParameters(AggregateFunctionCatalogEntry &entry, idx_t offset) {
|
|
99061
|
+
vector<Value> results;
|
|
99062
|
+
for (idx_t i = 0; i < entry.functions[offset].arguments.size(); i++) {
|
|
99063
|
+
results.emplace_back("col" + to_string(i));
|
|
99064
|
+
}
|
|
99065
|
+
return Value::LIST(LogicalType::VARCHAR, move(results));
|
|
99066
|
+
}
|
|
99067
|
+
|
|
99068
|
+
static Value GetParameterTypes(AggregateFunctionCatalogEntry &entry, idx_t offset) {
|
|
99069
|
+
vector<Value> results;
|
|
99070
|
+
for (idx_t i = 0; i < entry.functions[offset].arguments.size(); i++) {
|
|
99071
|
+
results.emplace_back(entry.functions[offset].arguments[i].ToString());
|
|
99072
|
+
}
|
|
99073
|
+
return Value::LIST(LogicalType::VARCHAR, move(results));
|
|
99074
|
+
}
|
|
99075
|
+
|
|
99076
|
+
static Value GetVarArgs(AggregateFunctionCatalogEntry &entry, idx_t offset) {
|
|
99077
|
+
return entry.functions[offset].varargs.id() == LogicalTypeId::INVALID
|
|
99078
|
+
? Value()
|
|
99079
|
+
: Value(entry.functions[offset].varargs.ToString());
|
|
99080
|
+
}
|
|
99081
|
+
|
|
99082
|
+
static Value GetMacroDefinition(AggregateFunctionCatalogEntry &entry, idx_t offset) {
|
|
99083
|
+
return Value();
|
|
99084
|
+
}
|
|
99085
|
+
};
|
|
99086
|
+
|
|
99087
|
+
struct MacroExtractor {
|
|
99088
|
+
static idx_t FunctionCount(MacroCatalogEntry &entry) {
|
|
99089
|
+
return 1;
|
|
99090
|
+
}
|
|
99091
|
+
|
|
99092
|
+
static Value GetFunctionType() {
|
|
99093
|
+
return Value("macro");
|
|
99094
|
+
}
|
|
99095
|
+
|
|
99096
|
+
static Value GetFunctionDescription(MacroCatalogEntry &entry, idx_t offset) {
|
|
99097
|
+
return Value();
|
|
99098
|
+
}
|
|
99099
|
+
|
|
99100
|
+
static Value GetReturnType(MacroCatalogEntry &entry, idx_t offset) {
|
|
99101
|
+
return Value();
|
|
99102
|
+
}
|
|
99103
|
+
|
|
99104
|
+
static Value GetParameters(MacroCatalogEntry &entry, idx_t offset) {
|
|
99105
|
+
vector<Value> results;
|
|
99106
|
+
for (auto ¶m : entry.function->parameters) {
|
|
99107
|
+
D_ASSERT(param->type == ExpressionType::COLUMN_REF);
|
|
99108
|
+
auto &colref = (ColumnRefExpression &)*param;
|
|
99109
|
+
results.emplace_back(colref.GetColumnName());
|
|
99110
|
+
}
|
|
99111
|
+
for (auto ¶m_entry : entry.function->default_parameters) {
|
|
99112
|
+
results.emplace_back(param_entry.first);
|
|
99113
|
+
}
|
|
99114
|
+
return Value::LIST(LogicalType::VARCHAR, move(results));
|
|
99115
|
+
}
|
|
99116
|
+
|
|
99117
|
+
static Value GetParameterTypes(MacroCatalogEntry &entry, idx_t offset) {
|
|
99118
|
+
vector<Value> results;
|
|
99119
|
+
for (idx_t i = 0; i < entry.function->parameters.size(); i++) {
|
|
99120
|
+
results.emplace_back(LogicalType::VARCHAR);
|
|
99121
|
+
}
|
|
99122
|
+
for (idx_t i = 0; i < entry.function->default_parameters.size(); i++) {
|
|
99123
|
+
results.emplace_back(LogicalType::VARCHAR);
|
|
99124
|
+
}
|
|
99125
|
+
return Value::LIST(LogicalType::VARCHAR, move(results));
|
|
99126
|
+
}
|
|
99127
|
+
|
|
99128
|
+
static Value GetVarArgs(MacroCatalogEntry &entry, idx_t offset) {
|
|
99129
|
+
return Value();
|
|
99130
|
+
}
|
|
99131
|
+
|
|
99132
|
+
static Value GetMacroDefinition(MacroCatalogEntry &entry, idx_t offset) {
|
|
99133
|
+
return entry.function->expression->ToString();
|
|
99134
|
+
}
|
|
99135
|
+
};
|
|
99136
|
+
|
|
99137
|
+
struct TableFunctionExtractor {
|
|
99138
|
+
static idx_t FunctionCount(TableFunctionCatalogEntry &entry) {
|
|
99139
|
+
return entry.functions.size();
|
|
99140
|
+
}
|
|
99141
|
+
|
|
99142
|
+
static Value GetFunctionType() {
|
|
99143
|
+
return Value("table");
|
|
99144
|
+
}
|
|
99145
|
+
|
|
99146
|
+
static Value GetFunctionDescription(TableFunctionCatalogEntry &entry, idx_t offset) {
|
|
99147
|
+
return Value();
|
|
99148
|
+
}
|
|
99149
|
+
|
|
99150
|
+
static Value GetReturnType(TableFunctionCatalogEntry &entry, idx_t offset) {
|
|
99151
|
+
return Value();
|
|
99152
|
+
}
|
|
99153
|
+
|
|
99154
|
+
static Value GetParameters(TableFunctionCatalogEntry &entry, idx_t offset) {
|
|
99155
|
+
vector<Value> results;
|
|
99156
|
+
for (idx_t i = 0; i < entry.functions[offset].arguments.size(); i++) {
|
|
99157
|
+
results.emplace_back("col" + to_string(i));
|
|
99158
|
+
}
|
|
99159
|
+
for (auto ¶m : entry.functions[offset].named_parameters) {
|
|
99160
|
+
results.emplace_back(param.first);
|
|
99161
|
+
}
|
|
99162
|
+
return Value::LIST(LogicalType::VARCHAR, move(results));
|
|
99163
|
+
}
|
|
99164
|
+
|
|
99165
|
+
static Value GetParameterTypes(TableFunctionCatalogEntry &entry, idx_t offset) {
|
|
99166
|
+
vector<Value> results;
|
|
99167
|
+
for (idx_t i = 0; i < entry.functions[offset].arguments.size(); i++) {
|
|
99168
|
+
results.emplace_back(entry.functions[offset].arguments[i].ToString());
|
|
99169
|
+
}
|
|
99170
|
+
for (auto ¶m : entry.functions[offset].named_parameters) {
|
|
99171
|
+
results.emplace_back(param.second.ToString());
|
|
99172
|
+
}
|
|
99173
|
+
return Value::LIST(LogicalType::VARCHAR, move(results));
|
|
99174
|
+
}
|
|
99175
|
+
|
|
99176
|
+
static Value GetVarArgs(TableFunctionCatalogEntry &entry, idx_t offset) {
|
|
99177
|
+
return entry.functions[offset].varargs.id() == LogicalTypeId::INVALID
|
|
99178
|
+
? Value()
|
|
99179
|
+
: Value(entry.functions[offset].varargs.ToString());
|
|
99180
|
+
}
|
|
99181
|
+
|
|
99182
|
+
static Value GetMacroDefinition(TableFunctionCatalogEntry &entry, idx_t offset) {
|
|
99183
|
+
return Value();
|
|
99184
|
+
}
|
|
99185
|
+
};
|
|
99186
|
+
|
|
99187
|
+
struct PragmaFunctionExtractor {
|
|
99188
|
+
static idx_t FunctionCount(PragmaFunctionCatalogEntry &entry) {
|
|
99189
|
+
return entry.functions.size();
|
|
99190
|
+
}
|
|
99191
|
+
|
|
99192
|
+
static Value GetFunctionType() {
|
|
99193
|
+
return Value("pragma");
|
|
99194
|
+
}
|
|
99195
|
+
|
|
99196
|
+
static Value GetFunctionDescription(PragmaFunctionCatalogEntry &entry, idx_t offset) {
|
|
99197
|
+
return Value();
|
|
99198
|
+
}
|
|
99199
|
+
|
|
99200
|
+
static Value GetReturnType(PragmaFunctionCatalogEntry &entry, idx_t offset) {
|
|
99201
|
+
return Value();
|
|
99202
|
+
}
|
|
99203
|
+
|
|
99204
|
+
static Value GetParameters(PragmaFunctionCatalogEntry &entry, idx_t offset) {
|
|
99205
|
+
vector<Value> results;
|
|
99206
|
+
for (idx_t i = 0; i < entry.functions[offset].arguments.size(); i++) {
|
|
99207
|
+
results.emplace_back("col" + to_string(i));
|
|
99208
|
+
}
|
|
99209
|
+
for (auto ¶m : entry.functions[offset].named_parameters) {
|
|
99210
|
+
results.emplace_back(param.first);
|
|
99211
|
+
}
|
|
99212
|
+
return Value::LIST(LogicalType::VARCHAR, move(results));
|
|
99213
|
+
}
|
|
99214
|
+
|
|
99215
|
+
static Value GetParameterTypes(PragmaFunctionCatalogEntry &entry, idx_t offset) {
|
|
99216
|
+
vector<Value> results;
|
|
99217
|
+
for (idx_t i = 0; i < entry.functions[offset].arguments.size(); i++) {
|
|
99218
|
+
results.emplace_back(entry.functions[offset].arguments[i].ToString());
|
|
99219
|
+
}
|
|
99220
|
+
for (auto ¶m : entry.functions[offset].named_parameters) {
|
|
99221
|
+
results.emplace_back(param.second.ToString());
|
|
99222
|
+
}
|
|
99223
|
+
return Value::LIST(LogicalType::VARCHAR, move(results));
|
|
99224
|
+
}
|
|
99225
|
+
|
|
99226
|
+
static Value GetVarArgs(PragmaFunctionCatalogEntry &entry, idx_t offset) {
|
|
99227
|
+
return entry.functions[offset].varargs.id() == LogicalTypeId::INVALID
|
|
99228
|
+
? Value()
|
|
99229
|
+
: Value(entry.functions[offset].varargs.ToString());
|
|
99230
|
+
}
|
|
99231
|
+
|
|
99232
|
+
static Value GetMacroDefinition(PragmaFunctionCatalogEntry &entry, idx_t offset) {
|
|
99233
|
+
return Value();
|
|
99234
|
+
}
|
|
99235
|
+
};
|
|
99236
|
+
|
|
99237
|
+
template <class T, class OP>
|
|
99238
|
+
bool ExtractFunctionData(StandardEntry *entry, idx_t function_idx, DataChunk &output, idx_t output_offset) {
|
|
99239
|
+
auto &function = (T &)*entry;
|
|
99240
|
+
// schema_name, LogicalType::VARCHAR
|
|
99241
|
+
output.SetValue(0, output_offset, Value(entry->schema->name));
|
|
99242
|
+
|
|
99243
|
+
// function_name, LogicalType::VARCHAR
|
|
99244
|
+
output.SetValue(1, output_offset, Value(entry->name));
|
|
99245
|
+
|
|
99246
|
+
// function_type, LogicalType::VARCHAR
|
|
99247
|
+
output.SetValue(2, output_offset, Value(OP::GetFunctionType()));
|
|
99248
|
+
|
|
99249
|
+
// function_description, LogicalType::VARCHAR
|
|
99250
|
+
output.SetValue(3, output_offset, OP::GetFunctionDescription(function, function_idx));
|
|
99251
|
+
|
|
99252
|
+
// return_type, LogicalType::VARCHAR
|
|
99253
|
+
output.SetValue(4, output_offset, OP::GetReturnType(function, function_idx));
|
|
99254
|
+
|
|
99255
|
+
// parameters, LogicalType::LIST(LogicalType::VARCHAR)
|
|
99256
|
+
output.SetValue(5, output_offset, OP::GetParameters(function, function_idx));
|
|
99257
|
+
|
|
99258
|
+
// parameter_types, LogicalType::LIST(LogicalType::VARCHAR)
|
|
99259
|
+
output.SetValue(6, output_offset, OP::GetParameterTypes(function, function_idx));
|
|
99260
|
+
|
|
99261
|
+
// varargs, LogicalType::VARCHAR
|
|
99262
|
+
output.SetValue(7, output_offset, OP::GetVarArgs(function, function_idx));
|
|
99263
|
+
|
|
99264
|
+
// macro_definition, LogicalType::VARCHAR
|
|
99265
|
+
output.SetValue(8, output_offset, OP::GetMacroDefinition(function, function_idx));
|
|
99266
|
+
|
|
99267
|
+
return function_idx + 1 == OP::FunctionCount(function);
|
|
99268
|
+
}
|
|
99269
|
+
|
|
99270
|
+
void DuckDBFunctionsFunction(ClientContext &context, const FunctionData *bind_data,
|
|
99271
|
+
FunctionOperatorData *operator_state, DataChunk *input, DataChunk &output) {
|
|
99272
|
+
auto &data = (DuckDBFunctionsData &)*operator_state;
|
|
99273
|
+
if (data.offset >= data.entries.size()) {
|
|
99274
|
+
// finished returning values
|
|
99275
|
+
return;
|
|
99276
|
+
}
|
|
99277
|
+
// start returning values
|
|
99278
|
+
// either fill up the chunk or return all the remaining columns
|
|
99279
|
+
idx_t count = 0;
|
|
99280
|
+
while (data.offset < data.entries.size() && count < STANDARD_VECTOR_SIZE) {
|
|
99281
|
+
auto &entry = data.entries[data.offset];
|
|
99282
|
+
auto standard_entry = (StandardEntry *)entry;
|
|
99283
|
+
bool finished = false;
|
|
99284
|
+
|
|
99285
|
+
switch (entry->type) {
|
|
99286
|
+
case CatalogType::SCALAR_FUNCTION_ENTRY:
|
|
99287
|
+
finished = ExtractFunctionData<ScalarFunctionCatalogEntry, ScalarFunctionExtractor>(
|
|
99288
|
+
standard_entry, data.offset_in_entry, output, count);
|
|
99289
|
+
break;
|
|
99290
|
+
case CatalogType::AGGREGATE_FUNCTION_ENTRY:
|
|
99291
|
+
finished = ExtractFunctionData<AggregateFunctionCatalogEntry, AggregateFunctionExtractor>(
|
|
99292
|
+
standard_entry, data.offset_in_entry, output, count);
|
|
99293
|
+
break;
|
|
99294
|
+
case CatalogType::MACRO_ENTRY:
|
|
99295
|
+
finished = ExtractFunctionData<MacroCatalogEntry, MacroExtractor>(standard_entry, data.offset_in_entry,
|
|
99296
|
+
output, count);
|
|
99297
|
+
break;
|
|
99298
|
+
case CatalogType::TABLE_FUNCTION_ENTRY:
|
|
99299
|
+
finished = ExtractFunctionData<TableFunctionCatalogEntry, TableFunctionExtractor>(
|
|
99300
|
+
standard_entry, data.offset_in_entry, output, count);
|
|
99301
|
+
break;
|
|
99302
|
+
case CatalogType::PRAGMA_FUNCTION_ENTRY:
|
|
99303
|
+
finished = ExtractFunctionData<PragmaFunctionCatalogEntry, PragmaFunctionExtractor>(
|
|
99304
|
+
standard_entry, data.offset_in_entry, output, count);
|
|
99305
|
+
break;
|
|
99306
|
+
default:
|
|
99307
|
+
throw InternalException("FIXME: unrecognized function type in duckdb_functions");
|
|
99308
|
+
}
|
|
99309
|
+
if (finished) {
|
|
99310
|
+
// finished with this function, move to the next function
|
|
99311
|
+
data.offset++;
|
|
99312
|
+
data.offset_in_entry = 0;
|
|
99313
|
+
} else {
|
|
99314
|
+
// more functions remain
|
|
99315
|
+
data.offset_in_entry++;
|
|
99316
|
+
}
|
|
99317
|
+
count++;
|
|
99318
|
+
}
|
|
99319
|
+
output.SetCardinality(count);
|
|
99320
|
+
}
|
|
99321
|
+
|
|
99322
|
+
void DuckDBFunctionsFun::RegisterFunction(BuiltinFunctions &set) {
|
|
99323
|
+
set.AddFunction(
|
|
99324
|
+
TableFunction("duckdb_functions", {}, DuckDBFunctionsFunction, DuckDBFunctionsBind, DuckDBFunctionsInit));
|
|
99325
|
+
}
|
|
99326
|
+
|
|
99327
|
+
} // namespace duckdb
|
|
99328
|
+
|
|
99329
|
+
|
|
99330
|
+
|
|
99331
|
+
|
|
99332
|
+
|
|
99333
|
+
|
|
99334
|
+
|
|
99335
|
+
|
|
99336
|
+
|
|
99337
|
+
|
|
98924
99338
|
namespace duckdb {
|
|
98925
99339
|
|
|
98926
99340
|
struct DuckDBIndexesData : public FunctionOperatorData {
|
|
@@ -100428,6 +100842,222 @@ void PragmaTableInfo::RegisterFunction(BuiltinFunctions &set) {
|
|
|
100428
100842
|
} // namespace duckdb
|
|
100429
100843
|
|
|
100430
100844
|
|
|
100845
|
+
|
|
100846
|
+
namespace duckdb {
|
|
100847
|
+
|
|
100848
|
+
struct TestAllTypesData : public FunctionOperatorData {
|
|
100849
|
+
TestAllTypesData() : offset(0) {
|
|
100850
|
+
}
|
|
100851
|
+
|
|
100852
|
+
vector<vector<Value>> entries;
|
|
100853
|
+
idx_t offset;
|
|
100854
|
+
};
|
|
100855
|
+
|
|
100856
|
+
struct TestType {
|
|
100857
|
+
TestType(LogicalType type_p, string name_p)
|
|
100858
|
+
: type(move(type_p)), name(move(name_p)), min_value(Value::MinimumValue(type)),
|
|
100859
|
+
max_value(Value::MaximumValue(type)) {
|
|
100860
|
+
}
|
|
100861
|
+
TestType(LogicalType type_p, string name_p, Value min, Value max)
|
|
100862
|
+
: type(move(type_p)), name(move(name_p)), min_value(move(min)), max_value(move(max)) {
|
|
100863
|
+
}
|
|
100864
|
+
|
|
100865
|
+
LogicalType type;
|
|
100866
|
+
string name;
|
|
100867
|
+
Value min_value;
|
|
100868
|
+
Value max_value;
|
|
100869
|
+
};
|
|
100870
|
+
|
|
100871
|
+
static vector<TestType> GetTestTypes() {
|
|
100872
|
+
vector<TestType> result;
|
|
100873
|
+
// scalar types/numerics
|
|
100874
|
+
result.emplace_back(LogicalType::BOOLEAN, "bool");
|
|
100875
|
+
result.emplace_back(LogicalType::TINYINT, "tinyint");
|
|
100876
|
+
result.emplace_back(LogicalType::SMALLINT, "smallint");
|
|
100877
|
+
result.emplace_back(LogicalType::INTEGER, "int");
|
|
100878
|
+
result.emplace_back(LogicalType::BIGINT, "bigint");
|
|
100879
|
+
result.emplace_back(LogicalType::HUGEINT, "hugeint");
|
|
100880
|
+
result.emplace_back(LogicalType::UTINYINT, "utinyint");
|
|
100881
|
+
result.emplace_back(LogicalType::USMALLINT, "usmallint");
|
|
100882
|
+
result.emplace_back(LogicalType::UINTEGER, "uint");
|
|
100883
|
+
result.emplace_back(LogicalType::UBIGINT, "ubigint");
|
|
100884
|
+
result.emplace_back(LogicalType::DATE, "date");
|
|
100885
|
+
result.emplace_back(LogicalType::TIME, "time");
|
|
100886
|
+
result.emplace_back(LogicalType::TIMESTAMP, "timestamp");
|
|
100887
|
+
result.emplace_back(LogicalType::TIMESTAMP_S, "timestamp_s");
|
|
100888
|
+
result.emplace_back(LogicalType::TIMESTAMP_MS, "timestamp_ms");
|
|
100889
|
+
result.emplace_back(LogicalType::TIMESTAMP_NS, "timestamp_ns");
|
|
100890
|
+
result.emplace_back(LogicalType::DATE_TZ, "date_tz");
|
|
100891
|
+
result.emplace_back(LogicalType::TIME_TZ, "time_tz");
|
|
100892
|
+
result.emplace_back(LogicalType::TIMESTAMP_TZ, "timestamp_tz");
|
|
100893
|
+
result.emplace_back(LogicalType::FLOAT, "float");
|
|
100894
|
+
result.emplace_back(LogicalType::DOUBLE, "double");
|
|
100895
|
+
result.emplace_back(LogicalType::DECIMAL(4, 1), "dec_4_1");
|
|
100896
|
+
result.emplace_back(LogicalType::DECIMAL(9, 4), "dec_9_4");
|
|
100897
|
+
result.emplace_back(LogicalType::DECIMAL(18, 6), "dec_18_3");
|
|
100898
|
+
result.emplace_back(LogicalType::DECIMAL(38, 10), "dec38_10");
|
|
100899
|
+
result.emplace_back(LogicalType::UUID, "uuid");
|
|
100900
|
+
// interval
|
|
100901
|
+
interval_t min_interval;
|
|
100902
|
+
min_interval.months = 0;
|
|
100903
|
+
min_interval.days = 0;
|
|
100904
|
+
min_interval.micros = 0;
|
|
100905
|
+
|
|
100906
|
+
interval_t max_interval;
|
|
100907
|
+
max_interval.months = 999;
|
|
100908
|
+
max_interval.days = 999;
|
|
100909
|
+
max_interval.micros = 999999999;
|
|
100910
|
+
result.emplace_back(LogicalType::INTERVAL, "interval", Value::INTERVAL(min_interval),
|
|
100911
|
+
Value::INTERVAL(max_interval));
|
|
100912
|
+
// strings/blobs
|
|
100913
|
+
result.emplace_back(LogicalType::VARCHAR, "varchar", Value("🦆🦆🦆🦆🦆🦆"), Value("goose"));
|
|
100914
|
+
result.emplace_back(LogicalType::BLOB, "blob", Value::BLOB("thisisalongblob\\x00withnullbytes"),
|
|
100915
|
+
Value("\\x00\\x00\\x00a"));
|
|
100916
|
+
|
|
100917
|
+
// enums
|
|
100918
|
+
vector<string> small_enum {"DUCK_DUCK_ENUM", "GOOSE"};
|
|
100919
|
+
result.emplace_back(LogicalType::ENUM("small_enum", small_enum), "small_enum");
|
|
100920
|
+
|
|
100921
|
+
vector<string> medium_enum;
|
|
100922
|
+
for (idx_t i = 0; i < 300; i++) {
|
|
100923
|
+
medium_enum.push_back(string("enum_") + to_string(i));
|
|
100924
|
+
}
|
|
100925
|
+
result.emplace_back(LogicalType::ENUM("medium_enum", medium_enum), "medium_enum");
|
|
100926
|
+
|
|
100927
|
+
// this is a big one... not sure if we should push this one here, but it's required for completeness
|
|
100928
|
+
vector<string> large_enum;
|
|
100929
|
+
for (idx_t i = 0; i < 70000; i++) {
|
|
100930
|
+
large_enum.push_back(string("enum_") + to_string(i));
|
|
100931
|
+
}
|
|
100932
|
+
result.emplace_back(LogicalType::ENUM("large_enum", large_enum), "large_enum");
|
|
100933
|
+
|
|
100934
|
+
// arrays
|
|
100935
|
+
auto int_list_type = LogicalType::LIST(LogicalType::INTEGER);
|
|
100936
|
+
auto empty_int_list = Value::EMPTYLIST(LogicalType::INTEGER);
|
|
100937
|
+
auto int_list = Value::LIST({Value::INTEGER(42), Value::INTEGER(999), Value(LogicalType::INTEGER),
|
|
100938
|
+
Value(LogicalType::INTEGER), Value::INTEGER(-42)});
|
|
100939
|
+
result.emplace_back(int_list_type, "int_array", empty_int_list, int_list);
|
|
100940
|
+
|
|
100941
|
+
auto varchar_list_type = LogicalType::LIST(LogicalType::VARCHAR);
|
|
100942
|
+
auto empty_varchar_list = Value::EMPTYLIST(LogicalType::VARCHAR);
|
|
100943
|
+
auto varchar_list =
|
|
100944
|
+
Value::LIST({Value("🦆🦆🦆🦆🦆🦆"), Value("goose"), Value(LogicalType::VARCHAR), Value("")});
|
|
100945
|
+
result.emplace_back(varchar_list_type, "varchar_array", empty_varchar_list, varchar_list);
|
|
100946
|
+
|
|
100947
|
+
// nested arrays
|
|
100948
|
+
auto nested_list_type = LogicalType::LIST(int_list_type);
|
|
100949
|
+
auto empty_nested_list = Value::EMPTYLIST(int_list_type);
|
|
100950
|
+
auto nested_int_list = Value::LIST({empty_int_list, int_list, Value(int_list_type), empty_int_list, int_list});
|
|
100951
|
+
result.emplace_back(nested_list_type, "nested_int_array", empty_nested_list, nested_int_list);
|
|
100952
|
+
|
|
100953
|
+
// structs
|
|
100954
|
+
child_list_t<LogicalType> struct_type_list;
|
|
100955
|
+
struct_type_list.push_back(make_pair("a", LogicalType::INTEGER));
|
|
100956
|
+
struct_type_list.push_back(make_pair("b", LogicalType::VARCHAR));
|
|
100957
|
+
auto struct_type = LogicalType::STRUCT(move(struct_type_list));
|
|
100958
|
+
|
|
100959
|
+
child_list_t<Value> min_struct_list;
|
|
100960
|
+
min_struct_list.push_back(make_pair("a", Value(LogicalType::INTEGER)));
|
|
100961
|
+
min_struct_list.push_back(make_pair("b", Value(LogicalType::VARCHAR)));
|
|
100962
|
+
auto min_struct_val = Value::STRUCT(move(min_struct_list));
|
|
100963
|
+
|
|
100964
|
+
child_list_t<Value> max_struct_list;
|
|
100965
|
+
max_struct_list.push_back(make_pair("a", Value::INTEGER(42)));
|
|
100966
|
+
max_struct_list.push_back(make_pair("b", Value("🦆🦆🦆🦆🦆🦆")));
|
|
100967
|
+
auto max_struct_val = Value::STRUCT(move(max_struct_list));
|
|
100968
|
+
|
|
100969
|
+
result.emplace_back(struct_type, "struct", min_struct_val, max_struct_val);
|
|
100970
|
+
|
|
100971
|
+
// structs with lists
|
|
100972
|
+
child_list_t<LogicalType> struct_list_type_list;
|
|
100973
|
+
struct_list_type_list.push_back(make_pair("a", int_list_type));
|
|
100974
|
+
struct_list_type_list.push_back(make_pair("b", varchar_list_type));
|
|
100975
|
+
auto struct_list_type = LogicalType::STRUCT(move(struct_list_type_list));
|
|
100976
|
+
|
|
100977
|
+
child_list_t<Value> min_struct_vl_list;
|
|
100978
|
+
min_struct_vl_list.push_back(make_pair("a", Value(int_list_type)));
|
|
100979
|
+
min_struct_vl_list.push_back(make_pair("b", Value(varchar_list_type)));
|
|
100980
|
+
auto min_struct_val_list = Value::STRUCT(move(min_struct_vl_list));
|
|
100981
|
+
|
|
100982
|
+
child_list_t<Value> max_struct_vl_list;
|
|
100983
|
+
max_struct_vl_list.push_back(make_pair("a", int_list));
|
|
100984
|
+
max_struct_vl_list.push_back(make_pair("b", varchar_list));
|
|
100985
|
+
auto max_struct_val_list = Value::STRUCT(move(max_struct_vl_list));
|
|
100986
|
+
|
|
100987
|
+
result.emplace_back(struct_list_type, "struct_of_arrays", move(min_struct_val_list), move(max_struct_val_list));
|
|
100988
|
+
|
|
100989
|
+
// array of structs
|
|
100990
|
+
auto array_of_structs_type = LogicalType::LIST(struct_type);
|
|
100991
|
+
auto min_array_of_struct_val = Value::EMPTYLIST(struct_type);
|
|
100992
|
+
auto max_array_of_struct_val = Value::LIST({min_struct_val, max_struct_val, Value(struct_type)});
|
|
100993
|
+
result.emplace_back(array_of_structs_type, "array_of_structs", move(min_array_of_struct_val),
|
|
100994
|
+
move(max_array_of_struct_val));
|
|
100995
|
+
|
|
100996
|
+
// map
|
|
100997
|
+
auto map_type = LogicalType::MAP(LogicalType::VARCHAR, LogicalType::VARCHAR);
|
|
100998
|
+
auto min_map_value = Value::MAP(Value::EMPTYLIST(LogicalType::VARCHAR), Value::EMPTYLIST(LogicalType::VARCHAR));
|
|
100999
|
+
auto max_map_value = Value::MAP(Value::LIST({Value("key1"), Value("key2")}),
|
|
101000
|
+
Value::LIST({Value("🦆🦆🦆🦆🦆🦆"), Value("goose")}));
|
|
101001
|
+
result.emplace_back(map_type, "map", move(min_map_value), move(max_map_value));
|
|
101002
|
+
|
|
101003
|
+
return result;
|
|
101004
|
+
}
|
|
101005
|
+
|
|
101006
|
+
static unique_ptr<FunctionData> TestAllTypesBind(ClientContext &context, vector<Value> &inputs,
|
|
101007
|
+
unordered_map<string, Value> &named_parameters,
|
|
101008
|
+
vector<LogicalType> &input_table_types,
|
|
101009
|
+
vector<string> &input_table_names, vector<LogicalType> &return_types,
|
|
101010
|
+
vector<string> &names) {
|
|
101011
|
+
auto test_types = GetTestTypes();
|
|
101012
|
+
for (auto &test_type : test_types) {
|
|
101013
|
+
return_types.push_back(move(test_type.type));
|
|
101014
|
+
names.push_back(move(test_type.name));
|
|
101015
|
+
}
|
|
101016
|
+
return nullptr;
|
|
101017
|
+
}
|
|
101018
|
+
|
|
101019
|
+
unique_ptr<FunctionOperatorData> TestAllTypesInit(ClientContext &context, const FunctionData *bind_data,
|
|
101020
|
+
const vector<column_t> &column_ids, TableFilterCollection *filters) {
|
|
101021
|
+
auto result = make_unique<TestAllTypesData>();
|
|
101022
|
+
auto test_types = GetTestTypes();
|
|
101023
|
+
// 3 rows: min, max and NULL
|
|
101024
|
+
result->entries.resize(3);
|
|
101025
|
+
// initialize the values
|
|
101026
|
+
for (auto &test_type : test_types) {
|
|
101027
|
+
result->entries[0].push_back(move(test_type.min_value));
|
|
101028
|
+
result->entries[1].push_back(move(test_type.max_value));
|
|
101029
|
+
result->entries[2].emplace_back(move(test_type.type));
|
|
101030
|
+
}
|
|
101031
|
+
return move(result);
|
|
101032
|
+
}
|
|
101033
|
+
|
|
101034
|
+
void TestAllTypesFunction(ClientContext &context, const FunctionData *bind_data, FunctionOperatorData *operator_state,
|
|
101035
|
+
DataChunk *input, DataChunk &output) {
|
|
101036
|
+
auto &data = (TestAllTypesData &)*operator_state;
|
|
101037
|
+
if (data.offset >= data.entries.size()) {
|
|
101038
|
+
// finished returning values
|
|
101039
|
+
return;
|
|
101040
|
+
}
|
|
101041
|
+
// start returning values
|
|
101042
|
+
// either fill up the chunk or return all the remaining columns
|
|
101043
|
+
idx_t count = 0;
|
|
101044
|
+
while (data.offset < data.entries.size() && count < STANDARD_VECTOR_SIZE) {
|
|
101045
|
+
auto &vals = data.entries[data.offset++];
|
|
101046
|
+
for (idx_t col_idx = 0; col_idx < vals.size(); col_idx++) {
|
|
101047
|
+
output.SetValue(col_idx, count, vals[col_idx]);
|
|
101048
|
+
}
|
|
101049
|
+
count++;
|
|
101050
|
+
}
|
|
101051
|
+
output.SetCardinality(count);
|
|
101052
|
+
}
|
|
101053
|
+
|
|
101054
|
+
void TestAllTypesFun::RegisterFunction(BuiltinFunctions &set) {
|
|
101055
|
+
set.AddFunction(TableFunction("test_all_types", {}, TestAllTypesFunction, TestAllTypesBind, TestAllTypesInit));
|
|
101056
|
+
}
|
|
101057
|
+
|
|
101058
|
+
} // namespace duckdb
|
|
101059
|
+
|
|
101060
|
+
|
|
100431
101061
|
//===----------------------------------------------------------------------===//
|
|
100432
101062
|
// DuckDB
|
|
100433
101063
|
//
|
|
@@ -100547,6 +101177,7 @@ void BuiltinFunctions::RegisterSQLiteFunctions() {
|
|
|
100547
101177
|
|
|
100548
101178
|
DuckDBColumnsFun::RegisterFunction(*this);
|
|
100549
101179
|
DuckDBConstraintsFun::RegisterFunction(*this);
|
|
101180
|
+
DuckDBFunctionsFun::RegisterFunction(*this);
|
|
100550
101181
|
DuckDBIndexesFun::RegisterFunction(*this);
|
|
100551
101182
|
DuckDBSchemasFun::RegisterFunction(*this);
|
|
100552
101183
|
DuckDBDependenciesFun::RegisterFunction(*this);
|
|
@@ -100555,6 +101186,7 @@ void BuiltinFunctions::RegisterSQLiteFunctions() {
|
|
|
100555
101186
|
DuckDBTablesFun::RegisterFunction(*this);
|
|
100556
101187
|
DuckDBTypesFun::RegisterFunction(*this);
|
|
100557
101188
|
DuckDBViewsFun::RegisterFunction(*this);
|
|
101189
|
+
TestAllTypesFun::RegisterFunction(*this);
|
|
100558
101190
|
}
|
|
100559
101191
|
|
|
100560
101192
|
} // namespace duckdb
|
|
@@ -101152,7 +101784,7 @@ BaseAppender::~BaseAppender() {
|
|
|
101152
101784
|
}
|
|
101153
101785
|
|
|
101154
101786
|
void BaseAppender::Destructor() {
|
|
101155
|
-
if (
|
|
101787
|
+
if (Exception::UncaughtException()) {
|
|
101156
101788
|
return;
|
|
101157
101789
|
}
|
|
101158
101790
|
// flush any remaining chunks, but only if we are not cleaning up the appender as part of an exception stack unwind
|
|
@@ -103436,7 +104068,7 @@ ClientContext::ClientContext(shared_ptr<DatabaseInstance> database)
|
|
|
103436
104068
|
}
|
|
103437
104069
|
|
|
103438
104070
|
ClientContext::~ClientContext() {
|
|
103439
|
-
if (
|
|
104071
|
+
if (Exception::UncaughtException()) {
|
|
103440
104072
|
return;
|
|
103441
104073
|
}
|
|
103442
104074
|
// destroy the client context and rollback if there is an active transaction
|
|
@@ -105328,7 +105960,7 @@ DatabaseInstance::DatabaseInstance() {
|
|
|
105328
105960
|
}
|
|
105329
105961
|
|
|
105330
105962
|
DatabaseInstance::~DatabaseInstance() {
|
|
105331
|
-
if (
|
|
105963
|
+
if (Exception::UncaughtException()) {
|
|
105332
105964
|
return;
|
|
105333
105965
|
}
|
|
105334
105966
|
|
|
@@ -114513,7 +115145,7 @@ public:
|
|
|
114513
115145
|
|
|
114514
115146
|
//! The subquery
|
|
114515
115147
|
unique_ptr<SelectStatement> subquery;
|
|
114516
|
-
//!
|
|
115148
|
+
//! Aliases for the column names
|
|
114517
115149
|
vector<string> column_name_alias;
|
|
114518
115150
|
|
|
114519
115151
|
public:
|
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.2-
|
|
13
|
+
#define DUCKDB_SOURCE_ID "915530a92"
|
|
14
|
+
#define DUCKDB_VERSION "0.3.2-dev499"
|
|
15
15
|
//===----------------------------------------------------------------------===//
|
|
16
16
|
// DuckDB
|
|
17
17
|
//
|
|
@@ -1039,6 +1039,7 @@ public:
|
|
|
1039
1039
|
DUCKDB_API static LogicalType LIST( LogicalType child); // NOLINT
|
|
1040
1040
|
DUCKDB_API static LogicalType STRUCT( child_list_t<LogicalType> children); // NOLINT
|
|
1041
1041
|
DUCKDB_API static LogicalType MAP( child_list_t<LogicalType> children); // NOLINT
|
|
1042
|
+
DUCKDB_API static LogicalType MAP(LogicalType key, LogicalType value); // NOLINT
|
|
1042
1043
|
DUCKDB_API static LogicalType ENUM(const string &enum_name, const vector<string> &ordered_data); // NOLINT
|
|
1043
1044
|
DUCKDB_API static LogicalType USER(const string &user_type_name); // NOLINT
|
|
1044
1045
|
//! A list of all NUMERIC types (integral and floating point types)
|
|
@@ -1299,6 +1300,8 @@ public:
|
|
|
1299
1300
|
return ConstructMessageRecursive(msg, values, params...);
|
|
1300
1301
|
}
|
|
1301
1302
|
|
|
1303
|
+
DUCKDB_API static bool UncaughtException();
|
|
1304
|
+
|
|
1302
1305
|
private:
|
|
1303
1306
|
string exception_message_;
|
|
1304
1307
|
};
|
|
@@ -2597,9 +2600,9 @@ public:
|
|
|
2597
2600
|
DUCKDB_API static Value TIMESTAMP(date_t date, dtime_t time);
|
|
2598
2601
|
//! Create a timestamp Value from a specified timestamp
|
|
2599
2602
|
DUCKDB_API static Value TIMESTAMP(timestamp_t timestamp);
|
|
2600
|
-
DUCKDB_API static Value
|
|
2601
|
-
DUCKDB_API static Value
|
|
2602
|
-
DUCKDB_API static Value
|
|
2603
|
+
DUCKDB_API static Value TIMESTAMPNS(timestamp_t timestamp);
|
|
2604
|
+
DUCKDB_API static Value TIMESTAMPMS(timestamp_t timestamp);
|
|
2605
|
+
DUCKDB_API static Value TIMESTAMPSEC(timestamp_t timestamp);
|
|
2603
2606
|
DUCKDB_API static Value TIMESTAMPTZ(timestamp_t timestamp);
|
|
2604
2607
|
//! Create a timestamp Value from a specified timestamp in separate values
|
|
2605
2608
|
DUCKDB_API static Value TIMESTAMP(int32_t year, int32_t month, int32_t day, int32_t hour, int32_t min, int32_t sec,
|
|
@@ -2621,8 +2624,11 @@ public:
|
|
|
2621
2624
|
DUCKDB_API static Value DOUBLE(double value);
|
|
2622
2625
|
//! Create a struct value with given list of entries
|
|
2623
2626
|
DUCKDB_API static Value STRUCT(child_list_t<Value> values);
|
|
2624
|
-
//! Create a list value with the given entries
|
|
2627
|
+
//! Create a list value with the given entries, list type is inferred from children
|
|
2628
|
+
//! Cannot be called with an empty list, use either EMPTYLIST or LIST with a type instead
|
|
2625
2629
|
DUCKDB_API static Value LIST(vector<Value> values);
|
|
2630
|
+
//! Create a list value with the given entries
|
|
2631
|
+
DUCKDB_API static Value LIST(LogicalType child_type, vector<Value> values);
|
|
2626
2632
|
//! Create an empty list with the specified type
|
|
2627
2633
|
DUCKDB_API static Value EMPTYLIST(LogicalType child_type);
|
|
2628
2634
|
//! Creat a map value from a (key, value) pair
|
|
@@ -11814,6 +11820,12 @@ struct timestamp_struct {
|
|
|
11814
11820
|
//! The Timestamp class is a static class that holds helper functions for the Timestamp
|
|
11815
11821
|
//! type.
|
|
11816
11822
|
class Timestamp {
|
|
11823
|
+
public:
|
|
11824
|
+
// min timestamp is 290308-12-22 (BC)
|
|
11825
|
+
constexpr static const int32_t MIN_YEAR = -290308;
|
|
11826
|
+
constexpr static const int32_t MIN_MONTH = 12;
|
|
11827
|
+
constexpr static const int32_t MIN_DAY = 22;
|
|
11828
|
+
|
|
11817
11829
|
public:
|
|
11818
11830
|
//! Convert a string in the format "YYYY-MM-DD hh:mm:ss" to a timestamp object
|
|
11819
11831
|
DUCKDB_API static timestamp_t FromString(const string &str);
|