duckdb 0.4.1-dev204.0 → 0.4.1-dev218.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.4.1-dev204.0",
4
+ "version": "0.4.1-dev218.0",
5
5
  "description": "DuckDB node.js API",
6
6
  "gypfile": true,
7
7
  "dependencies": {
package/src/duckdb.cpp CHANGED
@@ -227,6 +227,10 @@ public:
227
227
  public:
228
228
  //! Serialize the meta information
229
229
  virtual void Serialize(Serializer &serializer) = 0;
230
+
231
+ string ToSQL() override {
232
+ return function->ToSQL(schema->name, name);
233
+ }
230
234
  };
231
235
 
232
236
  } // namespace duckdb
@@ -1643,6 +1647,8 @@ public:
1643
1647
 
1644
1648
  public:
1645
1649
  unique_ptr<MacroFunction> Copy() override;
1650
+
1651
+ string ToSQL(const string &schema, const string &name) override;
1646
1652
  };
1647
1653
 
1648
1654
  } // namespace duckdb
@@ -1656,7 +1662,7 @@ public:
1656
1662
  //===----------------------------------------------------------------------===//
1657
1663
 
1658
1664
 
1659
- //! The SelectStatement of the view
1665
+
1660
1666
 
1661
1667
 
1662
1668
 
@@ -1677,6 +1683,8 @@ public:
1677
1683
 
1678
1684
  public:
1679
1685
  unique_ptr<MacroFunction> Copy() override;
1686
+
1687
+ string ToSQL(const string &schema, const string &name) override;
1680
1688
  };
1681
1689
 
1682
1690
  } // namespace duckdb
@@ -71883,6 +71891,7 @@ public:
71883
71891
 
71884
71892
 
71885
71893
 
71894
+
71886
71895
  #include <algorithm>
71887
71896
  #include <sstream>
71888
71897
 
@@ -71987,6 +71996,7 @@ void PhysicalExport::GetData(ExecutionContext &context, DataChunk &chunk, Global
71987
71996
  vector<CatalogEntry *> tables;
71988
71997
  vector<CatalogEntry *> views;
71989
71998
  vector<CatalogEntry *> indexes;
71999
+ vector<CatalogEntry *> macros;
71990
72000
 
71991
72001
  auto schema_list = Catalog::GetCatalog(ccontext).schemas->GetEntries<SchemaCatalogEntry>(context.client);
71992
72002
  for (auto &schema : schema_list) {
@@ -72006,6 +72016,16 @@ void PhysicalExport::GetData(ExecutionContext &context, DataChunk &chunk, Global
72006
72016
  schema->Scan(context.client, CatalogType::TYPE_ENTRY,
72007
72017
  [&](CatalogEntry *entry) { custom_types.push_back(entry); });
72008
72018
  schema->Scan(context.client, CatalogType::INDEX_ENTRY, [&](CatalogEntry *entry) { indexes.push_back(entry); });
72019
+ schema->Scan(context.client, CatalogType::MACRO_ENTRY, [&](CatalogEntry *entry) {
72020
+ if (!entry->internal && entry->type == CatalogType::MACRO_ENTRY) {
72021
+ macros.push_back(entry);
72022
+ }
72023
+ });
72024
+ schema->Scan(context.client, CatalogType::TABLE_MACRO_ENTRY, [&](CatalogEntry *entry) {
72025
+ if (!entry->internal && entry->type == CatalogType::TABLE_MACRO_ENTRY) {
72026
+ macros.push_back(entry);
72027
+ }
72028
+ });
72009
72029
  }
72010
72030
 
72011
72031
  // consider the order of tables because of foreign key constraint
@@ -72013,6 +72033,10 @@ void PhysicalExport::GetData(ExecutionContext &context, DataChunk &chunk, Global
72013
72033
  tables.push_back((CatalogEntry *)exported_tables.data[i].entry);
72014
72034
  }
72015
72035
 
72036
+ // order macro's by timestamp so nested macro's are imported nicely
72037
+ sort(macros.begin(), macros.end(),
72038
+ [](const CatalogEntry *lhs, const CatalogEntry *rhs) { return lhs->oid < rhs->oid; });
72039
+
72016
72040
  // write the schema.sql file
72017
72041
  // export order is SCHEMA -> SEQUENCE -> TABLE -> VIEW -> INDEX
72018
72042
 
@@ -72023,6 +72047,7 @@ void PhysicalExport::GetData(ExecutionContext &context, DataChunk &chunk, Global
72023
72047
  WriteCatalogEntries(ss, tables);
72024
72048
  WriteCatalogEntries(ss, views);
72025
72049
  WriteCatalogEntries(ss, indexes);
72050
+ WriteCatalogEntries(ss, macros);
72026
72051
 
72027
72052
  WriteStringStreamToFile(fs, opener, ss, fs.JoinPath(info->file_path, "schema.sql"));
72028
72053
 
@@ -88680,6 +88705,18 @@ void MacroFunction::CopyProperties(MacroFunction &other) {
88680
88705
  }
88681
88706
  }
88682
88707
 
88708
+ string MacroFunction::ToSQL(const string &schema, const string &name) {
88709
+ vector<string> param_strings;
88710
+ for (auto &param : parameters) {
88711
+ param_strings.push_back(param->ToString());
88712
+ }
88713
+ for (auto &named_param : default_parameters) {
88714
+ param_strings.push_back(StringUtil::Format("%s := %s", named_param.first, named_param.second->ToString()));
88715
+ }
88716
+
88717
+ return StringUtil::Format("CREATE MACRO %s.%s(%s) AS ", schema, name, StringUtil::Join(param_strings, ", "));
88718
+ }
88719
+
88683
88720
  } // namespace duckdb
88684
88721
  //===----------------------------------------------------------------------===//
88685
88722
  // DuckDB
@@ -105290,6 +105327,8 @@ void ScalarFunction::NopFunction(DataChunk &input, ExpressionState &state, Vecto
105290
105327
 
105291
105328
 
105292
105329
 
105330
+
105331
+
105293
105332
  namespace duckdb {
105294
105333
 
105295
105334
  ScalarMacroFunction::ScalarMacroFunction(unique_ptr<ParsedExpression> expression)
@@ -105307,6 +105346,26 @@ unique_ptr<MacroFunction> ScalarMacroFunction::Copy() {
105307
105346
  return move(result);
105308
105347
  }
105309
105348
 
105349
+ void RemoveQualificationRecursive(unique_ptr<ParsedExpression> &expr) {
105350
+ if (expr->GetExpressionType() == ExpressionType::COLUMN_REF) {
105351
+ auto &col_ref = (ColumnRefExpression &)*expr;
105352
+ auto &col_names = col_ref.column_names;
105353
+ if (col_names.size() == 2 && col_names[0] == MacroBinding::MACRO_NAME) {
105354
+ col_names.erase(col_names.begin());
105355
+ }
105356
+ } else {
105357
+ ParsedExpressionIterator::EnumerateChildren(
105358
+ *expr, [](unique_ptr<ParsedExpression> &child) { RemoveQualificationRecursive(child); });
105359
+ }
105360
+ }
105361
+
105362
+ string ScalarMacroFunction::ToSQL(const string &schema, const string &name) {
105363
+ // In case of nested macro's we need to fix it a bit
105364
+ auto expression_copy = expression->Copy();
105365
+ RemoveQualificationRecursive(expression_copy);
105366
+ return MacroFunction::ToSQL(schema, name) + StringUtil::Format("(%s);", expression_copy->ToString());
105367
+ }
105368
+
105310
105369
  } // namespace duckdb
105311
105370
 
105312
105371
 
@@ -112276,6 +112335,7 @@ TableFunction::TableFunction()
112276
112335
 
112277
112336
 
112278
112337
 
112338
+
112279
112339
  namespace duckdb {
112280
112340
 
112281
112341
  TableMacroFunction::TableMacroFunction(unique_ptr<QueryNode> query_node)
@@ -112292,6 +112352,10 @@ unique_ptr<MacroFunction> TableMacroFunction::Copy() {
112292
112352
  return move(result);
112293
112353
  }
112294
112354
 
112355
+ string TableMacroFunction::ToSQL(const string &schema, const string &name) {
112356
+ return MacroFunction::ToSQL(schema, name) + StringUtil::Format("TABLE (%s);", query_node->ToString());
112357
+ }
112358
+
112295
112359
  } // namespace duckdb
112296
112360
 
112297
112361
 
@@ -126850,23 +126914,23 @@ namespace duckdb {
126850
126914
 
126851
126915
  #ifdef _WIN32
126852
126916
 
126853
- void *dlopen(const char *file, int mode) {
126917
+ inline void *dlopen(const char *file, int mode) {
126854
126918
  D_ASSERT(file);
126855
126919
  return (void *)LoadLibrary(file);
126856
126920
  }
126857
126921
 
126858
- void *dlsym(void *handle, const char *name) {
126922
+ inline void *dlsym(void *handle, const char *name) {
126859
126923
  D_ASSERT(handle);
126860
126924
  return (void *)GetProcAddress((HINSTANCE)handle, name);
126861
126925
  }
126862
126926
 
126863
- std::string GetDLError(void) {
126927
+ inline std::string GetDLError(void) {
126864
126928
  return LocalFileSystem::GetLastErrorAsString();
126865
126929
  }
126866
126930
 
126867
126931
  #else
126868
126932
 
126869
- std::string GetDLError(void) {
126933
+ inline std::string GetDLError(void) {
126870
126934
  return dlerror();
126871
126935
  }
126872
126936
 
package/src/duckdb.hpp CHANGED
@@ -11,8 +11,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
11
11
  #pragma once
12
12
  #define DUCKDB_AMALGAMATION 1
13
13
  #define DUCKDB_AMALGAMATION_EXTENDED 1
14
- #define DUCKDB_SOURCE_ID "78baad646"
15
- #define DUCKDB_VERSION "v0.4.1-dev204"
14
+ #define DUCKDB_SOURCE_ID "038c583ba"
15
+ #define DUCKDB_VERSION "v0.4.1-dev218"
16
16
  //===----------------------------------------------------------------------===//
17
17
  // DuckDB
18
18
  //
@@ -24301,7 +24301,7 @@ struct BoundExportData : public ParseInfo {
24301
24301
  //===----------------------------------------------------------------------===//
24302
24302
 
24303
24303
 
24304
- //! The SelectStatement of the view
24304
+
24305
24305
 
24306
24306
 
24307
24307
 
@@ -24315,11 +24315,9 @@ enum class MacroType : uint8_t { VOID_MACRO = 0, TABLE_MACRO = 1, SCALAR_MACRO =
24315
24315
 
24316
24316
  class MacroFunction {
24317
24317
  public:
24318
- // explicit MacroFunction(unique_ptr<ParsedExpression> expression);
24319
24318
  MacroFunction(MacroType type);
24320
24319
 
24321
- // MacroFunction(void);
24322
- // The type
24320
+ //! The type
24323
24321
  MacroType type;
24324
24322
  //! The positional parameters
24325
24323
  vector<unique_ptr<ParsedExpression>> parameters;
@@ -24338,6 +24336,8 @@ public:
24338
24336
  FunctionExpression &function_expr,
24339
24337
  vector<unique_ptr<ParsedExpression>> &positionals,
24340
24338
  unordered_map<string, unique_ptr<ParsedExpression>> &defaults);
24339
+
24340
+ virtual string ToSQL(const string &schema, const string &name);
24341
24341
  };
24342
24342
 
24343
24343
  } // namespace duckdb