duckdb 0.3.2-dev483.0 → 0.3.2-dev488.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-dev483.0",
4
+ "version": "0.3.2-dev488.0",
5
5
  "description": "DuckDB node.js API",
6
6
  "gypfile": true,
7
7
  "dependencies": {
package/src/duckdb.cpp CHANGED
@@ -40386,6 +40386,16 @@ Value Value::LIST(vector<Value> values) {
40386
40386
  return result;
40387
40387
  }
40388
40388
 
40389
+ Value Value::LIST(LogicalType child_type, vector<Value> values) {
40390
+ if (values.empty()) {
40391
+ return Value::EMPTYLIST(move(child_type));
40392
+ }
40393
+ for (auto &val : values) {
40394
+ val = val.CastAs(child_type);
40395
+ }
40396
+ return Value::LIST(move(values));
40397
+ }
40398
+
40389
40399
  Value Value::EMPTYLIST(LogicalType child_type) {
40390
40400
  Value result;
40391
40401
  result.type_ = LogicalType::LIST(move(child_type));
@@ -97206,6 +97216,10 @@ struct DuckDBDependenciesFun {
97206
97216
  static void RegisterFunction(BuiltinFunctions &set);
97207
97217
  };
97208
97218
 
97219
+ struct DuckDBFunctionsFun {
97220
+ static void RegisterFunction(BuiltinFunctions &set);
97221
+ };
97222
+
97209
97223
  struct DuckDBIndexesFun {
97210
97224
  static void RegisterFunction(BuiltinFunctions &set);
97211
97225
  };
@@ -98921,6 +98935,420 @@ void DuckDBDependenciesFun::RegisterFunction(BuiltinFunctions &set) {
98921
98935
 
98922
98936
 
98923
98937
 
98938
+
98939
+
98940
+ namespace duckdb {
98941
+
98942
+ struct DuckDBFunctionsData : public FunctionOperatorData {
98943
+ DuckDBFunctionsData() : offset(0), offset_in_entry(0) {
98944
+ }
98945
+
98946
+ vector<CatalogEntry *> entries;
98947
+ idx_t offset;
98948
+ idx_t offset_in_entry;
98949
+ };
98950
+
98951
+ static unique_ptr<FunctionData> DuckDBFunctionsBind(ClientContext &context, vector<Value> &inputs,
98952
+ unordered_map<string, Value> &named_parameters,
98953
+ vector<LogicalType> &input_table_types,
98954
+ vector<string> &input_table_names,
98955
+ vector<LogicalType> &return_types, vector<string> &names) {
98956
+ names.emplace_back("schema_name");
98957
+ return_types.emplace_back(LogicalType::VARCHAR);
98958
+
98959
+ names.emplace_back("function_name");
98960
+ return_types.emplace_back(LogicalType::VARCHAR);
98961
+
98962
+ names.emplace_back("function_type");
98963
+ return_types.emplace_back(LogicalType::VARCHAR);
98964
+
98965
+ names.emplace_back("description");
98966
+ return_types.emplace_back(LogicalType::VARCHAR);
98967
+
98968
+ names.emplace_back("return_type");
98969
+ return_types.emplace_back(LogicalType::VARCHAR);
98970
+
98971
+ names.emplace_back("parameters");
98972
+ return_types.push_back(LogicalType::LIST(LogicalType::VARCHAR));
98973
+
98974
+ names.emplace_back("parameter_types");
98975
+ return_types.push_back(LogicalType::LIST(LogicalType::VARCHAR));
98976
+
98977
+ names.emplace_back("varargs");
98978
+ return_types.emplace_back(LogicalType::VARCHAR);
98979
+
98980
+ names.emplace_back("macro_definition");
98981
+ return_types.emplace_back(LogicalType::VARCHAR);
98982
+
98983
+ return nullptr;
98984
+ }
98985
+
98986
+ static void ExtractFunctionsFromSchema(ClientContext &context, SchemaCatalogEntry &schema,
98987
+ DuckDBFunctionsData &result) {
98988
+ schema.Scan(context, CatalogType::SCALAR_FUNCTION_ENTRY,
98989
+ [&](CatalogEntry *entry) { result.entries.push_back(entry); });
98990
+ schema.Scan(context, CatalogType::TABLE_FUNCTION_ENTRY,
98991
+ [&](CatalogEntry *entry) { result.entries.push_back(entry); });
98992
+ schema.Scan(context, CatalogType::PRAGMA_FUNCTION_ENTRY,
98993
+ [&](CatalogEntry *entry) { result.entries.push_back(entry); });
98994
+ }
98995
+
98996
+ unique_ptr<FunctionOperatorData> DuckDBFunctionsInit(ClientContext &context, const FunctionData *bind_data,
98997
+ const vector<column_t> &column_ids,
98998
+ TableFilterCollection *filters) {
98999
+ auto result = make_unique<DuckDBFunctionsData>();
99000
+
99001
+ // scan all the schemas for tables and collect themand collect them
99002
+ auto schemas = Catalog::GetCatalog(context).schemas->GetEntries<SchemaCatalogEntry>(context);
99003
+ for (auto &schema : schemas) {
99004
+ ExtractFunctionsFromSchema(context, *schema, *result);
99005
+ };
99006
+ ExtractFunctionsFromSchema(context, *context.temporary_objects, *result);
99007
+
99008
+ std::sort(result->entries.begin(), result->entries.end(),
99009
+ [&](CatalogEntry *a, CatalogEntry *b) { return (int)a->type < (int)b->type; });
99010
+ return move(result);
99011
+ }
99012
+
99013
+ struct ScalarFunctionExtractor {
99014
+ static idx_t FunctionCount(ScalarFunctionCatalogEntry &entry) {
99015
+ return entry.functions.size();
99016
+ }
99017
+
99018
+ static Value GetFunctionType() {
99019
+ return Value("scalar");
99020
+ }
99021
+
99022
+ static Value GetFunctionDescription(ScalarFunctionCatalogEntry &entry, idx_t offset) {
99023
+ return Value();
99024
+ }
99025
+
99026
+ static Value GetReturnType(ScalarFunctionCatalogEntry &entry, idx_t offset) {
99027
+ return Value(entry.functions[offset].return_type.ToString());
99028
+ }
99029
+
99030
+ static Value GetParameters(ScalarFunctionCatalogEntry &entry, idx_t offset) {
99031
+ vector<Value> results;
99032
+ for (idx_t i = 0; i < entry.functions[offset].arguments.size(); i++) {
99033
+ results.emplace_back("col" + to_string(i));
99034
+ }
99035
+ return Value::LIST(LogicalType::VARCHAR, move(results));
99036
+ }
99037
+
99038
+ static Value GetParameterTypes(ScalarFunctionCatalogEntry &entry, idx_t offset) {
99039
+ vector<Value> results;
99040
+ for (idx_t i = 0; i < entry.functions[offset].arguments.size(); i++) {
99041
+ results.emplace_back(entry.functions[offset].arguments[i].ToString());
99042
+ }
99043
+ return Value::LIST(LogicalType::VARCHAR, move(results));
99044
+ }
99045
+
99046
+ static Value GetVarArgs(ScalarFunctionCatalogEntry &entry, idx_t offset) {
99047
+ return entry.functions[offset].varargs.id() == LogicalTypeId::INVALID
99048
+ ? Value()
99049
+ : Value(entry.functions[offset].varargs.ToString());
99050
+ }
99051
+
99052
+ static Value GetMacroDefinition(ScalarFunctionCatalogEntry &entry, idx_t offset) {
99053
+ return Value();
99054
+ }
99055
+ };
99056
+
99057
+ struct AggregateFunctionExtractor {
99058
+ static idx_t FunctionCount(AggregateFunctionCatalogEntry &entry) {
99059
+ return entry.functions.size();
99060
+ }
99061
+
99062
+ static Value GetFunctionType() {
99063
+ return Value("aggregate");
99064
+ }
99065
+
99066
+ static Value GetFunctionDescription(AggregateFunctionCatalogEntry &entry, idx_t offset) {
99067
+ return Value();
99068
+ }
99069
+
99070
+ static Value GetReturnType(AggregateFunctionCatalogEntry &entry, idx_t offset) {
99071
+ return Value(entry.functions[offset].return_type.ToString());
99072
+ }
99073
+
99074
+ static Value GetParameters(AggregateFunctionCatalogEntry &entry, idx_t offset) {
99075
+ vector<Value> results;
99076
+ for (idx_t i = 0; i < entry.functions[offset].arguments.size(); i++) {
99077
+ results.emplace_back("col" + to_string(i));
99078
+ }
99079
+ return Value::LIST(LogicalType::VARCHAR, move(results));
99080
+ }
99081
+
99082
+ static Value GetParameterTypes(AggregateFunctionCatalogEntry &entry, idx_t offset) {
99083
+ vector<Value> results;
99084
+ for (idx_t i = 0; i < entry.functions[offset].arguments.size(); i++) {
99085
+ results.emplace_back(entry.functions[offset].arguments[i].ToString());
99086
+ }
99087
+ return Value::LIST(LogicalType::VARCHAR, move(results));
99088
+ }
99089
+
99090
+ static Value GetVarArgs(AggregateFunctionCatalogEntry &entry, idx_t offset) {
99091
+ return entry.functions[offset].varargs.id() == LogicalTypeId::INVALID
99092
+ ? Value()
99093
+ : Value(entry.functions[offset].varargs.ToString());
99094
+ }
99095
+
99096
+ static Value GetMacroDefinition(AggregateFunctionCatalogEntry &entry, idx_t offset) {
99097
+ return Value();
99098
+ }
99099
+ };
99100
+
99101
+ struct MacroExtractor {
99102
+ static idx_t FunctionCount(MacroCatalogEntry &entry) {
99103
+ return 1;
99104
+ }
99105
+
99106
+ static Value GetFunctionType() {
99107
+ return Value("macro");
99108
+ }
99109
+
99110
+ static Value GetFunctionDescription(MacroCatalogEntry &entry, idx_t offset) {
99111
+ return Value();
99112
+ }
99113
+
99114
+ static Value GetReturnType(MacroCatalogEntry &entry, idx_t offset) {
99115
+ return Value();
99116
+ }
99117
+
99118
+ static Value GetParameters(MacroCatalogEntry &entry, idx_t offset) {
99119
+ vector<Value> results;
99120
+ for (auto &param : entry.function->parameters) {
99121
+ D_ASSERT(param->type == ExpressionType::COLUMN_REF);
99122
+ auto &colref = (ColumnRefExpression &)*param;
99123
+ results.emplace_back(colref.GetColumnName());
99124
+ }
99125
+ for (auto &param_entry : entry.function->default_parameters) {
99126
+ results.emplace_back(param_entry.first);
99127
+ }
99128
+ return Value::LIST(LogicalType::VARCHAR, move(results));
99129
+ }
99130
+
99131
+ static Value GetParameterTypes(MacroCatalogEntry &entry, idx_t offset) {
99132
+ vector<Value> results;
99133
+ for (idx_t i = 0; i < entry.function->parameters.size(); i++) {
99134
+ results.emplace_back(LogicalType::VARCHAR);
99135
+ }
99136
+ for (idx_t i = 0; i < entry.function->default_parameters.size(); i++) {
99137
+ results.emplace_back(LogicalType::VARCHAR);
99138
+ }
99139
+ return Value::LIST(LogicalType::VARCHAR, move(results));
99140
+ }
99141
+
99142
+ static Value GetVarArgs(MacroCatalogEntry &entry, idx_t offset) {
99143
+ return Value();
99144
+ }
99145
+
99146
+ static Value GetMacroDefinition(MacroCatalogEntry &entry, idx_t offset) {
99147
+ return entry.function->expression->ToString();
99148
+ }
99149
+ };
99150
+
99151
+ struct TableFunctionExtractor {
99152
+ static idx_t FunctionCount(TableFunctionCatalogEntry &entry) {
99153
+ return entry.functions.size();
99154
+ }
99155
+
99156
+ static Value GetFunctionType() {
99157
+ return Value("table");
99158
+ }
99159
+
99160
+ static Value GetFunctionDescription(TableFunctionCatalogEntry &entry, idx_t offset) {
99161
+ return Value();
99162
+ }
99163
+
99164
+ static Value GetReturnType(TableFunctionCatalogEntry &entry, idx_t offset) {
99165
+ return Value();
99166
+ }
99167
+
99168
+ static Value GetParameters(TableFunctionCatalogEntry &entry, idx_t offset) {
99169
+ vector<Value> results;
99170
+ for (idx_t i = 0; i < entry.functions[offset].arguments.size(); i++) {
99171
+ results.emplace_back("col" + to_string(i));
99172
+ }
99173
+ for (auto &param : entry.functions[offset].named_parameters) {
99174
+ results.emplace_back(param.first);
99175
+ }
99176
+ return Value::LIST(LogicalType::VARCHAR, move(results));
99177
+ }
99178
+
99179
+ static Value GetParameterTypes(TableFunctionCatalogEntry &entry, idx_t offset) {
99180
+ vector<Value> results;
99181
+ for (idx_t i = 0; i < entry.functions[offset].arguments.size(); i++) {
99182
+ results.emplace_back(entry.functions[offset].arguments[i].ToString());
99183
+ }
99184
+ for (auto &param : entry.functions[offset].named_parameters) {
99185
+ results.emplace_back(param.second.ToString());
99186
+ }
99187
+ return Value::LIST(LogicalType::VARCHAR, move(results));
99188
+ }
99189
+
99190
+ static Value GetVarArgs(TableFunctionCatalogEntry &entry, idx_t offset) {
99191
+ return entry.functions[offset].varargs.id() == LogicalTypeId::INVALID
99192
+ ? Value()
99193
+ : Value(entry.functions[offset].varargs.ToString());
99194
+ }
99195
+
99196
+ static Value GetMacroDefinition(TableFunctionCatalogEntry &entry, idx_t offset) {
99197
+ return Value();
99198
+ }
99199
+ };
99200
+
99201
+ struct PragmaFunctionExtractor {
99202
+ static idx_t FunctionCount(PragmaFunctionCatalogEntry &entry) {
99203
+ return entry.functions.size();
99204
+ }
99205
+
99206
+ static Value GetFunctionType() {
99207
+ return Value("pragma");
99208
+ }
99209
+
99210
+ static Value GetFunctionDescription(PragmaFunctionCatalogEntry &entry, idx_t offset) {
99211
+ return Value();
99212
+ }
99213
+
99214
+ static Value GetReturnType(PragmaFunctionCatalogEntry &entry, idx_t offset) {
99215
+ return Value();
99216
+ }
99217
+
99218
+ static Value GetParameters(PragmaFunctionCatalogEntry &entry, idx_t offset) {
99219
+ vector<Value> results;
99220
+ for (idx_t i = 0; i < entry.functions[offset].arguments.size(); i++) {
99221
+ results.emplace_back("col" + to_string(i));
99222
+ }
99223
+ for (auto &param : entry.functions[offset].named_parameters) {
99224
+ results.emplace_back(param.first);
99225
+ }
99226
+ return Value::LIST(LogicalType::VARCHAR, move(results));
99227
+ }
99228
+
99229
+ static Value GetParameterTypes(PragmaFunctionCatalogEntry &entry, idx_t offset) {
99230
+ vector<Value> results;
99231
+ for (idx_t i = 0; i < entry.functions[offset].arguments.size(); i++) {
99232
+ results.emplace_back(entry.functions[offset].arguments[i].ToString());
99233
+ }
99234
+ for (auto &param : entry.functions[offset].named_parameters) {
99235
+ results.emplace_back(param.second.ToString());
99236
+ }
99237
+ return Value::LIST(LogicalType::VARCHAR, move(results));
99238
+ }
99239
+
99240
+ static Value GetVarArgs(PragmaFunctionCatalogEntry &entry, idx_t offset) {
99241
+ return entry.functions[offset].varargs.id() == LogicalTypeId::INVALID
99242
+ ? Value()
99243
+ : Value(entry.functions[offset].varargs.ToString());
99244
+ }
99245
+
99246
+ static Value GetMacroDefinition(PragmaFunctionCatalogEntry &entry, idx_t offset) {
99247
+ return Value();
99248
+ }
99249
+ };
99250
+
99251
+ template <class T, class OP>
99252
+ bool ExtractFunctionData(StandardEntry *entry, idx_t function_idx, DataChunk &output, idx_t output_offset) {
99253
+ auto &function = (T &)*entry;
99254
+ // schema_name, LogicalType::VARCHAR
99255
+ output.SetValue(0, output_offset, Value(entry->schema->name));
99256
+
99257
+ // function_name, LogicalType::VARCHAR
99258
+ output.SetValue(1, output_offset, Value(entry->name));
99259
+
99260
+ // function_type, LogicalType::VARCHAR
99261
+ output.SetValue(2, output_offset, Value(OP::GetFunctionType()));
99262
+
99263
+ // function_description, LogicalType::VARCHAR
99264
+ output.SetValue(3, output_offset, OP::GetFunctionDescription(function, function_idx));
99265
+
99266
+ // return_type, LogicalType::VARCHAR
99267
+ output.SetValue(4, output_offset, OP::GetReturnType(function, function_idx));
99268
+
99269
+ // parameters, LogicalType::LIST(LogicalType::VARCHAR)
99270
+ output.SetValue(5, output_offset, OP::GetParameters(function, function_idx));
99271
+
99272
+ // parameter_types, LogicalType::LIST(LogicalType::VARCHAR)
99273
+ output.SetValue(6, output_offset, OP::GetParameterTypes(function, function_idx));
99274
+
99275
+ // varargs, LogicalType::VARCHAR
99276
+ output.SetValue(7, output_offset, OP::GetVarArgs(function, function_idx));
99277
+
99278
+ // macro_definition, LogicalType::VARCHAR
99279
+ output.SetValue(8, output_offset, OP::GetMacroDefinition(function, function_idx));
99280
+
99281
+ return function_idx + 1 == OP::FunctionCount(function);
99282
+ }
99283
+
99284
+ void DuckDBFunctionsFunction(ClientContext &context, const FunctionData *bind_data,
99285
+ FunctionOperatorData *operator_state, DataChunk *input, DataChunk &output) {
99286
+ auto &data = (DuckDBFunctionsData &)*operator_state;
99287
+ if (data.offset >= data.entries.size()) {
99288
+ // finished returning values
99289
+ return;
99290
+ }
99291
+ // start returning values
99292
+ // either fill up the chunk or return all the remaining columns
99293
+ idx_t count = 0;
99294
+ while (data.offset < data.entries.size() && count < STANDARD_VECTOR_SIZE) {
99295
+ auto &entry = data.entries[data.offset];
99296
+ auto standard_entry = (StandardEntry *)entry;
99297
+ bool finished = false;
99298
+
99299
+ switch (entry->type) {
99300
+ case CatalogType::SCALAR_FUNCTION_ENTRY:
99301
+ finished = ExtractFunctionData<ScalarFunctionCatalogEntry, ScalarFunctionExtractor>(
99302
+ standard_entry, data.offset_in_entry, output, count);
99303
+ break;
99304
+ case CatalogType::AGGREGATE_FUNCTION_ENTRY:
99305
+ finished = ExtractFunctionData<AggregateFunctionCatalogEntry, AggregateFunctionExtractor>(
99306
+ standard_entry, data.offset_in_entry, output, count);
99307
+ break;
99308
+ case CatalogType::MACRO_ENTRY:
99309
+ finished = ExtractFunctionData<MacroCatalogEntry, MacroExtractor>(standard_entry, data.offset_in_entry,
99310
+ output, count);
99311
+ break;
99312
+ case CatalogType::TABLE_FUNCTION_ENTRY:
99313
+ finished = ExtractFunctionData<TableFunctionCatalogEntry, TableFunctionExtractor>(
99314
+ standard_entry, data.offset_in_entry, output, count);
99315
+ break;
99316
+ case CatalogType::PRAGMA_FUNCTION_ENTRY:
99317
+ finished = ExtractFunctionData<PragmaFunctionCatalogEntry, PragmaFunctionExtractor>(
99318
+ standard_entry, data.offset_in_entry, output, count);
99319
+ break;
99320
+ default:
99321
+ throw InternalException("FIXME: unrecognized function type in duckdb_functions");
99322
+ }
99323
+ if (finished) {
99324
+ // finished with this function, move to the next function
99325
+ data.offset++;
99326
+ data.offset_in_entry = 0;
99327
+ } else {
99328
+ // more functions remain
99329
+ data.offset_in_entry++;
99330
+ }
99331
+ count++;
99332
+ }
99333
+ output.SetCardinality(count);
99334
+ }
99335
+
99336
+ void DuckDBFunctionsFun::RegisterFunction(BuiltinFunctions &set) {
99337
+ set.AddFunction(
99338
+ TableFunction("duckdb_functions", {}, DuckDBFunctionsFunction, DuckDBFunctionsBind, DuckDBFunctionsInit));
99339
+ }
99340
+
99341
+ } // namespace duckdb
99342
+
99343
+
99344
+
99345
+
99346
+
99347
+
99348
+
99349
+
99350
+
99351
+
98924
99352
  namespace duckdb {
98925
99353
 
98926
99354
  struct DuckDBIndexesData : public FunctionOperatorData {
@@ -100547,6 +100975,7 @@ void BuiltinFunctions::RegisterSQLiteFunctions() {
100547
100975
 
100548
100976
  DuckDBColumnsFun::RegisterFunction(*this);
100549
100977
  DuckDBConstraintsFun::RegisterFunction(*this);
100978
+ DuckDBFunctionsFun::RegisterFunction(*this);
100550
100979
  DuckDBIndexesFun::RegisterFunction(*this);
100551
100980
  DuckDBSchemasFun::RegisterFunction(*this);
100552
100981
  DuckDBDependenciesFun::RegisterFunction(*this);
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 "9ee0227d8"
14
- #define DUCKDB_VERSION "0.3.2-dev483"
13
+ #define DUCKDB_SOURCE_ID "5dec41339"
14
+ #define DUCKDB_VERSION "0.3.2-dev488"
15
15
  //===----------------------------------------------------------------------===//
16
16
  // DuckDB
17
17
  //
@@ -2621,8 +2621,11 @@ public:
2621
2621
  DUCKDB_API static Value DOUBLE(double value);
2622
2622
  //! Create a struct value with given list of entries
2623
2623
  DUCKDB_API static Value STRUCT(child_list_t<Value> values);
2624
- //! Create a list value with the given entries
2624
+ //! Create a list value with the given entries, list type is inferred from children
2625
+ //! Cannot be called with an empty list, use either EMPTYLIST or LIST with a type instead
2625
2626
  DUCKDB_API static Value LIST(vector<Value> values);
2627
+ //! Create a list value with the given entries
2628
+ DUCKDB_API static Value LIST(LogicalType child_type, vector<Value> values);
2626
2629
  //! Create an empty list with the specified type
2627
2630
  DUCKDB_API static Value EMPTYLIST(LogicalType child_type);
2628
2631
  //! Creat a map value from a (key, value) pair