duckdb 0.5.2-dev18.0 → 0.5.2-dev32.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.5.2-dev18.0",
4
+ "version": "0.5.2-dev32.0",
5
5
  "description": "DuckDB node.js API",
6
6
  "gypfile": true,
7
7
  "dependencies": {
package/src/duckdb.cpp CHANGED
@@ -118599,15 +118599,47 @@ void DuckDBColumnsFun::RegisterFunction(BuiltinFunctions &set) {
118599
118599
 
118600
118600
 
118601
118601
 
118602
+ namespace duckdb {
118603
+
118604
+ struct UniqueKeyInfo {
118605
+ string schema, table;
118606
+ vector<storage_t> columns;
118607
+
118608
+ bool operator==(const UniqueKeyInfo &other) const {
118609
+ return (schema == other.schema) && (table == other.table) && (columns == other.columns);
118610
+ }
118611
+ };
118612
+
118613
+ } // namespace duckdb
118614
+
118615
+ namespace std {
118616
+
118617
+ template <>
118618
+ struct hash<duckdb::UniqueKeyInfo> {
118619
+ template <class X>
118620
+ static size_t ComputeHash(const X &x) {
118621
+ return hash<X>()(x);
118622
+ }
118623
+
118624
+ size_t operator()(const duckdb::UniqueKeyInfo &j) const {
118625
+ D_ASSERT(j.columns.size() > 0);
118626
+ return ComputeHash(j.schema) + ComputeHash(j.table) + ComputeHash(j.columns[0]);
118627
+ }
118628
+ };
118629
+
118630
+ } // namespace std
118631
+
118602
118632
  namespace duckdb {
118603
118633
 
118604
118634
  struct DuckDBConstraintsData : public GlobalTableFunctionState {
118605
- DuckDBConstraintsData() : offset(0), constraint_offset(0) {
118635
+ DuckDBConstraintsData() : offset(0), constraint_offset(0), unique_constraint_offset(0) {
118606
118636
  }
118607
118637
 
118608
118638
  vector<CatalogEntry *> entries;
118609
118639
  idx_t offset;
118610
118640
  idx_t constraint_offset;
118641
+ idx_t unique_constraint_offset;
118642
+ unordered_map<UniqueKeyInfo, idx_t> known_fk_unique_constraint_offsets;
118611
118643
  };
118612
118644
 
118613
118645
  static unique_ptr<FunctionData> DuckDBConstraintsBind(ClientContext &context, TableFunctionBindInput &input,
@@ -118638,7 +118670,6 @@ static unique_ptr<FunctionData> DuckDBConstraintsBind(ClientContext &context, Ta
118638
118670
  return_types.emplace_back(LogicalType::VARCHAR);
118639
118671
 
118640
118672
  names.emplace_back("constraint_column_indexes");
118641
- ;
118642
118673
  return_types.push_back(LogicalType::LIST(LogicalType::BIGINT));
118643
118674
 
118644
118675
  names.emplace_back("constraint_column_names");
@@ -118650,15 +118681,29 @@ static unique_ptr<FunctionData> DuckDBConstraintsBind(ClientContext &context, Ta
118650
118681
  unique_ptr<GlobalTableFunctionState> DuckDBConstraintsInit(ClientContext &context, TableFunctionInitInput &input) {
118651
118682
  auto result = make_unique<DuckDBConstraintsData>();
118652
118683
 
118653
- // scan all the schemas for tables and collect themand collect them
118684
+ // scan all the schemas for tables and collect them
118654
118685
  auto schemas = Catalog::GetCatalog(context).schemas->GetEntries<SchemaCatalogEntry>(context);
118686
+
118687
+ sort(schemas.begin(), schemas.end(), [&](CatalogEntry *x, CatalogEntry *y) { return (x->name < y->name); });
118688
+
118689
+ // check the temp schema as well
118690
+ auto &temp_schema = ClientData::Get(context).temporary_objects;
118691
+ schemas.push_back(temp_schema.get());
118692
+
118655
118693
  for (auto &schema : schemas) {
118656
- schema->Scan(context, CatalogType::TABLE_ENTRY, [&](CatalogEntry *entry) { result->entries.push_back(entry); });
118694
+ vector<CatalogEntry *> entries;
118695
+
118696
+ schema->Scan(context, CatalogType::TABLE_ENTRY, [&](CatalogEntry *entry) {
118697
+ if (entry->type == CatalogType::TABLE_ENTRY) {
118698
+ entries.push_back(entry);
118699
+ }
118700
+ });
118701
+
118702
+ sort(entries.begin(), entries.end(), [&](CatalogEntry *x, CatalogEntry *y) { return (x->name < y->name); });
118703
+
118704
+ result->entries.insert(result->entries.end(), entries.begin(), entries.end());
118657
118705
  };
118658
118706
 
118659
- // check the temp schema as well
118660
- ClientData::Get(context).temporary_objects->Scan(context, CatalogType::TABLE_ENTRY,
118661
- [&](CatalogEntry *entry) { result->entries.push_back(entry); });
118662
118707
  return move(result);
118663
118708
  }
118664
118709
 
@@ -118673,30 +118718,15 @@ void DuckDBConstraintsFunction(ClientContext &context, TableFunctionInput &data_
118673
118718
  idx_t count = 0;
118674
118719
  while (data.offset < data.entries.size() && count < STANDARD_VECTOR_SIZE) {
118675
118720
  auto &entry = data.entries[data.offset];
118676
-
118677
- if (entry->type != CatalogType::TABLE_ENTRY) {
118678
- data.offset++;
118679
- continue;
118680
- }
118721
+ D_ASSERT(entry->type == CatalogType::TABLE_ENTRY);
118681
118722
 
118682
118723
  auto &table = (TableCatalogEntry &)*entry;
118683
118724
  for (; data.constraint_offset < table.constraints.size() && count < STANDARD_VECTOR_SIZE;
118684
118725
  data.constraint_offset++) {
118685
118726
  auto &constraint = table.constraints[data.constraint_offset];
118686
118727
  // return values:
118687
- // schema_name, LogicalType::VARCHAR
118688
- output.SetValue(0, count, Value(table.schema->name));
118689
- // schema_oid, LogicalType::BIGINT
118690
- output.SetValue(1, count, Value::BIGINT(table.schema->oid));
118691
- // table_name, LogicalType::VARCHAR
118692
- output.SetValue(2, count, Value(table.name));
118693
- // table_oid, LogicalType::BIGINT
118694
- output.SetValue(3, count, Value::BIGINT(table.oid));
118695
-
118696
- // constraint_index, BIGINT
118697
- output.SetValue(4, count, Value::BIGINT(data.constraint_offset));
118698
-
118699
118728
  // constraint_type, VARCHAR
118729
+ // Processing this first due to shortcut (early continue)
118700
118730
  string constraint_type;
118701
118731
  switch (constraint->type) {
118702
118732
  case ConstraintType::CHECK:
@@ -118710,14 +118740,73 @@ void DuckDBConstraintsFunction(ClientContext &context, TableFunctionInput &data_
118710
118740
  case ConstraintType::NOT_NULL:
118711
118741
  constraint_type = "NOT NULL";
118712
118742
  break;
118713
- case ConstraintType::FOREIGN_KEY:
118743
+ case ConstraintType::FOREIGN_KEY: {
118744
+ auto &bound_foreign_key =
118745
+ (const BoundForeignKeyConstraint &)*table.bound_constraints[data.constraint_offset];
118746
+ if (bound_foreign_key.info.type == ForeignKeyType::FK_TYPE_PRIMARY_KEY_TABLE) {
118747
+ // Those are already covered by PRIMARY KEY and UNIQUE entries
118748
+ continue;
118749
+ }
118714
118750
  constraint_type = "FOREIGN KEY";
118715
118751
  break;
118752
+ }
118716
118753
  default:
118717
118754
  throw NotImplementedException("Unimplemented constraint for duckdb_constraints");
118718
118755
  }
118719
118756
  output.SetValue(5, count, Value(constraint_type));
118720
118757
 
118758
+ // schema_name, LogicalType::VARCHAR
118759
+ output.SetValue(0, count, Value(table.schema->name));
118760
+ // schema_oid, LogicalType::BIGINT
118761
+ output.SetValue(1, count, Value::BIGINT(table.schema->oid));
118762
+ // table_name, LogicalType::VARCHAR
118763
+ output.SetValue(2, count, Value(table.name));
118764
+ // table_oid, LogicalType::BIGINT
118765
+ output.SetValue(3, count, Value::BIGINT(table.oid));
118766
+
118767
+ // constraint_index, BIGINT
118768
+ auto &bound_constraint = (BoundConstraint &)*table.bound_constraints[data.constraint_offset];
118769
+ UniqueKeyInfo uk_info;
118770
+ switch (bound_constraint.type) {
118771
+ case ConstraintType::UNIQUE: {
118772
+ auto &bound_unique = (BoundUniqueConstraint &)bound_constraint;
118773
+ uk_info = {table.schema->name, table.name, bound_unique.keys};
118774
+ break;
118775
+ }
118776
+ case ConstraintType::FOREIGN_KEY: {
118777
+ const auto &bound_foreign_key = (const BoundForeignKeyConstraint &)bound_constraint;
118778
+ const auto &info = bound_foreign_key.info;
118779
+ uk_info = {info.schema, info.table, info.pk_keys};
118780
+ if (uk_info.schema.empty()) {
118781
+ // FIXME: Can we somehow make use of Binder::BindSchema() here?
118782
+ // From experiments, an omitted schema in REFERENCES ... means "main" or "temp", even if the table
118783
+ // resides in a different schema. Is this guaranteed to be stable?
118784
+ if (entry->temporary) {
118785
+ uk_info.schema = "temp";
118786
+ } else {
118787
+ uk_info.schema = "main";
118788
+ }
118789
+ }
118790
+
118791
+ break;
118792
+ }
118793
+ default:
118794
+ break;
118795
+ }
118796
+
118797
+ if (uk_info.columns.empty()) {
118798
+ output.SetValue(4, count, Value::BIGINT(data.unique_constraint_offset++));
118799
+ } else {
118800
+ auto known_unique_constraint_offset = data.known_fk_unique_constraint_offsets.find(uk_info);
118801
+ if (known_unique_constraint_offset == data.known_fk_unique_constraint_offsets.end()) {
118802
+ data.known_fk_unique_constraint_offsets.insert(make_pair(uk_info, data.unique_constraint_offset));
118803
+ output.SetValue(4, count, Value::BIGINT(data.unique_constraint_offset));
118804
+ data.unique_constraint_offset++;
118805
+ } else {
118806
+ output.SetValue(4, count, Value::BIGINT(known_unique_constraint_offset->second));
118807
+ }
118808
+ }
118809
+
118721
118810
  // constraint_text, VARCHAR
118722
118811
  output.SetValue(6, count, Value(constraint->ToString()));
118723
118812
 
@@ -118729,7 +118818,6 @@ void DuckDBConstraintsFunction(ClientContext &context, TableFunctionInput &data_
118729
118818
  }
118730
118819
  output.SetValue(7, count, expression_text);
118731
118820
 
118732
- auto &bound_constraint = (BoundConstraint &)*table.bound_constraints[data.constraint_offset];
118733
118821
  vector<column_t> column_index_list;
118734
118822
  switch (bound_constraint.type) {
118735
118823
  case ConstraintType::CHECK: {
@@ -118752,7 +118840,7 @@ void DuckDBConstraintsFunction(ClientContext &context, TableFunctionInput &data_
118752
118840
  break;
118753
118841
  }
118754
118842
  case ConstraintType::FOREIGN_KEY: {
118755
- auto &bound_foreign_key = (BoundForeignKeyConstraint &)bound_constraint;
118843
+ auto &bound_foreign_key = (const BoundForeignKeyConstraint &)bound_constraint;
118756
118844
  for (auto &col_idx : bound_foreign_key.info.fk_keys) {
118757
118845
  column_index_list.push_back(column_t(col_idx));
118758
118846
  }
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 "09248843b"
15
- #define DUCKDB_VERSION "v0.5.2-dev18"
14
+ #define DUCKDB_SOURCE_ID "a272c85bc"
15
+ #define DUCKDB_VERSION "v0.5.2-dev32"
16
16
  //===----------------------------------------------------------------------===//
17
17
  // DuckDB
18
18
  //
@@ -9491,7 +9491,7 @@ struct ForeignKeyInfo {
9491
9491
  //! The set of main key table's column's index
9492
9492
  vector<storage_t> pk_keys;
9493
9493
  //! The set of foreign key table's column's index
9494
- vector<idx_t> fk_keys;
9494
+ vector<storage_t> fk_keys;
9495
9495
  };
9496
9496
 
9497
9497
  //! Constraint is the base class of any type of table constraint.