duckdb 0.3.2-dev660.0 → 0.3.2-dev665.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "duckdb",
3
3
  "main": "./lib/duckdb.js",
4
- "version": "0.3.2-dev660.0",
4
+ "version": "0.3.2-dev665.0",
5
5
  "description": "DuckDB node.js API",
6
6
  "gypfile": true,
7
7
  "dependencies": {
package/src/duckdb.cpp CHANGED
@@ -37647,6 +37647,19 @@ T Value::GetValueInternal() const {
37647
37647
  return Cast::Operation<interval_t, T>(value_.interval);
37648
37648
  case LogicalTypeId::DECIMAL:
37649
37649
  return CastAs(LogicalType::DOUBLE).GetValueInternal<T>();
37650
+ case LogicalTypeId::ENUM: {
37651
+ switch (type_.InternalType()) {
37652
+ case PhysicalType::UINT8:
37653
+ return Cast::Operation<uint8_t, T>(value_.utinyint);
37654
+ case PhysicalType::UINT16:
37655
+ return Cast::Operation<uint16_t, T>(value_.usmallint);
37656
+ case PhysicalType::UINT32:
37657
+ return Cast::Operation<uint32_t, T>(value_.uinteger);
37658
+ default:
37659
+ throw InternalException("Invalid Internal Type for ENUMs");
37660
+ }
37661
+ }
37662
+
37650
37663
  default:
37651
37664
  throw NotImplementedException("Unimplemented type \"%s\" for GetValue()", type_.ToString());
37652
37665
  }
@@ -77539,6 +77552,7 @@ void BuiltinFunctions::Initialize() {
77539
77552
  RegisterRegressiveAggregates();
77540
77553
 
77541
77554
  RegisterDateFunctions();
77555
+ RegisterEnumFunctions();
77542
77556
  RegisterGenericFunctions();
77543
77557
  RegisterMathFunctions();
77544
77558
  RegisterOperators();
@@ -82043,6 +82057,163 @@ void BuiltinFunctions::RegisterDateFunctions() {
82043
82057
  Register<ToIntervalFun>();
82044
82058
  }
82045
82059
 
82060
+ } // namespace duckdb
82061
+ //===----------------------------------------------------------------------===//
82062
+ // DuckDB
82063
+ //
82064
+ // duckdb/function/scalar/enum_functions.hpp
82065
+ //
82066
+ //
82067
+ //===----------------------------------------------------------------------===//
82068
+
82069
+
82070
+
82071
+
82072
+
82073
+
82074
+ namespace duckdb {
82075
+
82076
+ struct EnumFirst {
82077
+ static void RegisterFunction(BuiltinFunctions &set);
82078
+ };
82079
+
82080
+ struct EnumLast {
82081
+ static void RegisterFunction(BuiltinFunctions &set);
82082
+ };
82083
+
82084
+ struct EnumRange {
82085
+ static void RegisterFunction(BuiltinFunctions &set);
82086
+ };
82087
+
82088
+ struct EnumRangeBoundary {
82089
+ static void RegisterFunction(BuiltinFunctions &set);
82090
+ };
82091
+
82092
+ } // namespace duckdb
82093
+
82094
+
82095
+ namespace duckdb {
82096
+
82097
+ static void EnumFirstFunction(DataChunk &input, ExpressionState &state, Vector &result) {
82098
+ D_ASSERT(input.GetTypes().size() == 1);
82099
+ auto &enum_vector = EnumType::GetValuesInsertOrder(input.GetTypes()[0]);
82100
+ auto val = Value(enum_vector.GetValue(0));
82101
+ result.Reference(val);
82102
+ }
82103
+
82104
+ static void EnumLastFunction(DataChunk &input, ExpressionState &state, Vector &result) {
82105
+ D_ASSERT(input.GetTypes().size() == 1);
82106
+ auto enum_size = EnumType::GetSize(input.GetTypes()[0]);
82107
+ auto &enum_vector = EnumType::GetValuesInsertOrder(input.GetTypes()[0]);
82108
+ auto val = Value(enum_vector.GetValue(enum_size - 1));
82109
+ result.Reference(val);
82110
+ }
82111
+
82112
+ static void EnumRangeFunction(DataChunk &input, ExpressionState &state, Vector &result) {
82113
+ D_ASSERT(input.GetTypes().size() == 1);
82114
+ auto enum_size = EnumType::GetSize(input.GetTypes()[0]);
82115
+ auto &enum_vector = EnumType::GetValuesInsertOrder(input.GetTypes()[0]);
82116
+ vector<Value> enum_values;
82117
+ for (idx_t i = 0; i < enum_size; i++) {
82118
+ enum_values.emplace_back(enum_vector.GetValue(i));
82119
+ }
82120
+ auto val = Value::LIST(enum_values);
82121
+ result.Reference(val);
82122
+ }
82123
+
82124
+ static void EnumRangeBoundaryFunction(DataChunk &input, ExpressionState &state, Vector &result) {
82125
+ D_ASSERT(input.GetTypes().size() == 2);
82126
+ idx_t start, end;
82127
+ auto first_param = input.GetValue(0, 0);
82128
+ auto second_param = input.GetValue(1, 0);
82129
+
82130
+ auto &enum_vector = first_param.is_null ? EnumType::GetValuesInsertOrder(input.GetTypes()[1])
82131
+ : EnumType::GetValuesInsertOrder(input.GetTypes()[0]);
82132
+
82133
+ if (first_param.is_null) {
82134
+ start = 0;
82135
+ } else {
82136
+ start = first_param.GetValue<uint32_t>();
82137
+ }
82138
+ if (second_param.is_null) {
82139
+ end = EnumType::GetSize(input.GetTypes()[0]);
82140
+ } else {
82141
+ end = second_param.GetValue<uint32_t>() + 1;
82142
+ }
82143
+ vector<Value> enum_values;
82144
+ for (idx_t i = start; i < end; i++) {
82145
+ enum_values.emplace_back(enum_vector.GetValue(i));
82146
+ }
82147
+ Value val;
82148
+ if (enum_values.empty()) {
82149
+ val = Value::EMPTYLIST(LogicalType::VARCHAR);
82150
+ } else {
82151
+ val = Value::LIST(enum_values);
82152
+ }
82153
+ result.Reference(val);
82154
+ }
82155
+
82156
+ unique_ptr<FunctionData> BindEnumFunction(ClientContext &context, ScalarFunction &bound_function,
82157
+ vector<unique_ptr<Expression>> &arguments) {
82158
+ if (arguments[0]->return_type.id() != LogicalTypeId::ENUM) {
82159
+ throw BinderException("This function needs an ENUM as an argument");
82160
+ }
82161
+ return nullptr;
82162
+ }
82163
+
82164
+ unique_ptr<FunctionData> BindEnumRangeBoundaryFunction(ClientContext &context, ScalarFunction &bound_function,
82165
+ vector<unique_ptr<Expression>> &arguments) {
82166
+ if (arguments[0]->return_type.id() != LogicalTypeId::ENUM && arguments[0]->return_type != LogicalType::SQLNULL) {
82167
+ throw BinderException("This function needs an ENUM as an argument");
82168
+ }
82169
+ if (arguments[1]->return_type.id() != LogicalTypeId::ENUM && arguments[1]->return_type != LogicalType::SQLNULL) {
82170
+ throw BinderException("This function needs an ENUM as an argument");
82171
+ }
82172
+ if (arguments[0]->return_type == LogicalType::SQLNULL && arguments[1]->return_type == LogicalType::SQLNULL) {
82173
+ throw BinderException("This function needs an ENUM as an argument");
82174
+ }
82175
+ if (arguments[0]->return_type.id() == LogicalTypeId::ENUM &&
82176
+ arguments[1]->return_type.id() == LogicalTypeId::ENUM &&
82177
+ arguments[0]->return_type != arguments[1]->return_type) {
82178
+
82179
+ throw BinderException("The parameters need to link to ONLY one enum OR be NULL ");
82180
+ }
82181
+ return nullptr;
82182
+ }
82183
+
82184
+ void EnumFirst::RegisterFunction(BuiltinFunctions &set) {
82185
+ set.AddFunction(ScalarFunction("enum_first", {LogicalType::ANY}, LogicalType::VARCHAR, EnumFirstFunction, false,
82186
+ BindEnumFunction));
82187
+ }
82188
+
82189
+ void EnumLast::RegisterFunction(BuiltinFunctions &set) {
82190
+ set.AddFunction(ScalarFunction("enum_last", {LogicalType::ANY}, LogicalType::VARCHAR, EnumLastFunction, false,
82191
+ BindEnumFunction));
82192
+ }
82193
+
82194
+ void EnumRange::RegisterFunction(BuiltinFunctions &set) {
82195
+ set.AddFunction(ScalarFunction("enum_range", {LogicalType::ANY}, LogicalType::LIST(LogicalType::VARCHAR),
82196
+ EnumRangeFunction, false, BindEnumFunction));
82197
+ }
82198
+
82199
+ void EnumRangeBoundary::RegisterFunction(BuiltinFunctions &set) {
82200
+ set.AddFunction(ScalarFunction("enum_range_boundary", {LogicalType::ANY, LogicalType::ANY},
82201
+ LogicalType::LIST(LogicalType::VARCHAR), EnumRangeBoundaryFunction, false,
82202
+ BindEnumRangeBoundaryFunction));
82203
+ }
82204
+
82205
+ } // namespace duckdb
82206
+
82207
+
82208
+ namespace duckdb {
82209
+
82210
+ void BuiltinFunctions::RegisterEnumFunctions() {
82211
+ Register<EnumFirst>();
82212
+ Register<EnumLast>();
82213
+ Register<EnumRange>();
82214
+ Register<EnumRangeBoundary>();
82215
+ }
82216
+
82046
82217
  } // namespace duckdb
82047
82218
  //===----------------------------------------------------------------------===//
82048
82219
  // DuckDB
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 "f6fb08886"
14
- #define DUCKDB_VERSION "0.3.2-dev660"
13
+ #define DUCKDB_SOURCE_ID "dd2f405ae"
14
+ #define DUCKDB_VERSION "0.3.2-dev665"
15
15
  //===----------------------------------------------------------------------===//
16
16
  // DuckDB
17
17
  //
@@ -5742,6 +5742,7 @@ private:
5742
5742
 
5743
5743
  // scalar functions
5744
5744
  void RegisterDateFunctions();
5745
+ void RegisterEnumFunctions();
5745
5746
  void RegisterGenericFunctions();
5746
5747
  void RegisterMathFunctions();
5747
5748
  void RegisterOperators();