duckdb 0.5.2-dev2.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 +1 -1
- package/src/duckdb.cpp +140 -36
- package/src/duckdb.hpp +5 -4
- package/src/parquet-amalgamation.cpp +36905 -36905
package/package.json
CHANGED
package/src/duckdb.cpp
CHANGED
|
@@ -43588,12 +43588,16 @@ hash_t Hash(hugeint_t val) {
|
|
|
43588
43588
|
|
|
43589
43589
|
template <>
|
|
43590
43590
|
hash_t Hash(float val) {
|
|
43591
|
-
|
|
43591
|
+
static_assert(sizeof(float) == sizeof(uint32_t), "");
|
|
43592
|
+
uint32_t uval = *((uint32_t *)&val);
|
|
43593
|
+
return murmurhash64(uval);
|
|
43592
43594
|
}
|
|
43593
43595
|
|
|
43594
43596
|
template <>
|
|
43595
43597
|
hash_t Hash(double val) {
|
|
43596
|
-
|
|
43598
|
+
static_assert(sizeof(double) == sizeof(uint64_t), "");
|
|
43599
|
+
uint64_t uval = *((uint64_t *)&val);
|
|
43600
|
+
return murmurhash64(uval);
|
|
43597
43601
|
}
|
|
43598
43602
|
|
|
43599
43603
|
template <>
|
|
@@ -118595,15 +118599,47 @@ void DuckDBColumnsFun::RegisterFunction(BuiltinFunctions &set) {
|
|
|
118595
118599
|
|
|
118596
118600
|
|
|
118597
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
|
+
|
|
118598
118632
|
namespace duckdb {
|
|
118599
118633
|
|
|
118600
118634
|
struct DuckDBConstraintsData : public GlobalTableFunctionState {
|
|
118601
|
-
DuckDBConstraintsData() : offset(0), constraint_offset(0) {
|
|
118635
|
+
DuckDBConstraintsData() : offset(0), constraint_offset(0), unique_constraint_offset(0) {
|
|
118602
118636
|
}
|
|
118603
118637
|
|
|
118604
118638
|
vector<CatalogEntry *> entries;
|
|
118605
118639
|
idx_t offset;
|
|
118606
118640
|
idx_t constraint_offset;
|
|
118641
|
+
idx_t unique_constraint_offset;
|
|
118642
|
+
unordered_map<UniqueKeyInfo, idx_t> known_fk_unique_constraint_offsets;
|
|
118607
118643
|
};
|
|
118608
118644
|
|
|
118609
118645
|
static unique_ptr<FunctionData> DuckDBConstraintsBind(ClientContext &context, TableFunctionBindInput &input,
|
|
@@ -118634,7 +118670,6 @@ static unique_ptr<FunctionData> DuckDBConstraintsBind(ClientContext &context, Ta
|
|
|
118634
118670
|
return_types.emplace_back(LogicalType::VARCHAR);
|
|
118635
118671
|
|
|
118636
118672
|
names.emplace_back("constraint_column_indexes");
|
|
118637
|
-
;
|
|
118638
118673
|
return_types.push_back(LogicalType::LIST(LogicalType::BIGINT));
|
|
118639
118674
|
|
|
118640
118675
|
names.emplace_back("constraint_column_names");
|
|
@@ -118646,15 +118681,29 @@ static unique_ptr<FunctionData> DuckDBConstraintsBind(ClientContext &context, Ta
|
|
|
118646
118681
|
unique_ptr<GlobalTableFunctionState> DuckDBConstraintsInit(ClientContext &context, TableFunctionInitInput &input) {
|
|
118647
118682
|
auto result = make_unique<DuckDBConstraintsData>();
|
|
118648
118683
|
|
|
118649
|
-
// scan all the schemas for tables and collect
|
|
118684
|
+
// scan all the schemas for tables and collect them
|
|
118650
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
|
+
|
|
118651
118693
|
for (auto &schema : schemas) {
|
|
118652
|
-
|
|
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());
|
|
118653
118705
|
};
|
|
118654
118706
|
|
|
118655
|
-
// check the temp schema as well
|
|
118656
|
-
ClientData::Get(context).temporary_objects->Scan(context, CatalogType::TABLE_ENTRY,
|
|
118657
|
-
[&](CatalogEntry *entry) { result->entries.push_back(entry); });
|
|
118658
118707
|
return move(result);
|
|
118659
118708
|
}
|
|
118660
118709
|
|
|
@@ -118669,30 +118718,15 @@ void DuckDBConstraintsFunction(ClientContext &context, TableFunctionInput &data_
|
|
|
118669
118718
|
idx_t count = 0;
|
|
118670
118719
|
while (data.offset < data.entries.size() && count < STANDARD_VECTOR_SIZE) {
|
|
118671
118720
|
auto &entry = data.entries[data.offset];
|
|
118672
|
-
|
|
118673
|
-
if (entry->type != CatalogType::TABLE_ENTRY) {
|
|
118674
|
-
data.offset++;
|
|
118675
|
-
continue;
|
|
118676
|
-
}
|
|
118721
|
+
D_ASSERT(entry->type == CatalogType::TABLE_ENTRY);
|
|
118677
118722
|
|
|
118678
118723
|
auto &table = (TableCatalogEntry &)*entry;
|
|
118679
118724
|
for (; data.constraint_offset < table.constraints.size() && count < STANDARD_VECTOR_SIZE;
|
|
118680
118725
|
data.constraint_offset++) {
|
|
118681
118726
|
auto &constraint = table.constraints[data.constraint_offset];
|
|
118682
118727
|
// return values:
|
|
118683
|
-
// schema_name, LogicalType::VARCHAR
|
|
118684
|
-
output.SetValue(0, count, Value(table.schema->name));
|
|
118685
|
-
// schema_oid, LogicalType::BIGINT
|
|
118686
|
-
output.SetValue(1, count, Value::BIGINT(table.schema->oid));
|
|
118687
|
-
// table_name, LogicalType::VARCHAR
|
|
118688
|
-
output.SetValue(2, count, Value(table.name));
|
|
118689
|
-
// table_oid, LogicalType::BIGINT
|
|
118690
|
-
output.SetValue(3, count, Value::BIGINT(table.oid));
|
|
118691
|
-
|
|
118692
|
-
// constraint_index, BIGINT
|
|
118693
|
-
output.SetValue(4, count, Value::BIGINT(data.constraint_offset));
|
|
118694
|
-
|
|
118695
118728
|
// constraint_type, VARCHAR
|
|
118729
|
+
// Processing this first due to shortcut (early continue)
|
|
118696
118730
|
string constraint_type;
|
|
118697
118731
|
switch (constraint->type) {
|
|
118698
118732
|
case ConstraintType::CHECK:
|
|
@@ -118706,14 +118740,73 @@ void DuckDBConstraintsFunction(ClientContext &context, TableFunctionInput &data_
|
|
|
118706
118740
|
case ConstraintType::NOT_NULL:
|
|
118707
118741
|
constraint_type = "NOT NULL";
|
|
118708
118742
|
break;
|
|
118709
|
-
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
|
+
}
|
|
118710
118750
|
constraint_type = "FOREIGN KEY";
|
|
118711
118751
|
break;
|
|
118752
|
+
}
|
|
118712
118753
|
default:
|
|
118713
118754
|
throw NotImplementedException("Unimplemented constraint for duckdb_constraints");
|
|
118714
118755
|
}
|
|
118715
118756
|
output.SetValue(5, count, Value(constraint_type));
|
|
118716
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
|
+
|
|
118717
118810
|
// constraint_text, VARCHAR
|
|
118718
118811
|
output.SetValue(6, count, Value(constraint->ToString()));
|
|
118719
118812
|
|
|
@@ -118725,7 +118818,6 @@ void DuckDBConstraintsFunction(ClientContext &context, TableFunctionInput &data_
|
|
|
118725
118818
|
}
|
|
118726
118819
|
output.SetValue(7, count, expression_text);
|
|
118727
118820
|
|
|
118728
|
-
auto &bound_constraint = (BoundConstraint &)*table.bound_constraints[data.constraint_offset];
|
|
118729
118821
|
vector<column_t> column_index_list;
|
|
118730
118822
|
switch (bound_constraint.type) {
|
|
118731
118823
|
case ConstraintType::CHECK: {
|
|
@@ -118748,7 +118840,7 @@ void DuckDBConstraintsFunction(ClientContext &context, TableFunctionInput &data_
|
|
|
118748
118840
|
break;
|
|
118749
118841
|
}
|
|
118750
118842
|
case ConstraintType::FOREIGN_KEY: {
|
|
118751
|
-
auto &bound_foreign_key = (BoundForeignKeyConstraint &)bound_constraint;
|
|
118843
|
+
auto &bound_foreign_key = (const BoundForeignKeyConstraint &)bound_constraint;
|
|
118752
118844
|
for (auto &col_idx : bound_foreign_key.info.fk_keys) {
|
|
118753
118845
|
column_index_list.push_back(column_t(col_idx));
|
|
118754
118846
|
}
|
|
@@ -120916,6 +121008,13 @@ static void PragmaStorageInfoFunction(ClientContext &context, TableFunctionInput
|
|
|
120916
121008
|
auto &bind_data = (PragmaStorageFunctionData &)*data_p.bind_data;
|
|
120917
121009
|
auto &data = (PragmaStorageOperatorData &)*data_p.global_state;
|
|
120918
121010
|
idx_t count = 0;
|
|
121011
|
+
map<storage_t, column_t> soid_to_idx;
|
|
121012
|
+
for (idx_t cidx = 0; cidx < bind_data.table_entry->columns.size(); cidx++) {
|
|
121013
|
+
auto &entry = bind_data.table_entry->columns[cidx];
|
|
121014
|
+
if (!entry.Generated()) {
|
|
121015
|
+
soid_to_idx[entry.StorageOid()] = entry.Oid();
|
|
121016
|
+
}
|
|
121017
|
+
}
|
|
120919
121018
|
while (data.offset < bind_data.storage_info.size() && count < STANDARD_VECTOR_SIZE) {
|
|
120920
121019
|
auto &entry = bind_data.storage_info[data.offset++];
|
|
120921
121020
|
D_ASSERT(entry.size() + 1 == output.ColumnCount());
|
|
@@ -120923,8 +121022,9 @@ static void PragmaStorageInfoFunction(ClientContext &context, TableFunctionInput
|
|
|
120923
121022
|
for (idx_t col_idx = 0; col_idx < entry.size(); col_idx++, result_idx++) {
|
|
120924
121023
|
if (col_idx == 1) {
|
|
120925
121024
|
// write the column name
|
|
120926
|
-
auto
|
|
120927
|
-
output.SetValue(result_idx, count,
|
|
121025
|
+
auto storage_column_index = entry[col_idx].GetValue<int64_t>();
|
|
121026
|
+
output.SetValue(result_idx, count,
|
|
121027
|
+
Value(bind_data.table_entry->columns[soid_to_idx[storage_column_index]].Name()));
|
|
120928
121028
|
result_idx++;
|
|
120929
121029
|
}
|
|
120930
121030
|
output.SetValue(result_idx, count, entry[col_idx]);
|
|
@@ -197917,8 +198017,9 @@ void DataTable::VerifyAppendConstraints(TableCatalogEntry &table, ClientContext
|
|
|
197917
198017
|
auto &constraint = table.bound_constraints[i];
|
|
197918
198018
|
switch (base_constraint->type) {
|
|
197919
198019
|
case ConstraintType::NOT_NULL: {
|
|
197920
|
-
auto &
|
|
197921
|
-
|
|
198020
|
+
auto &bound_not_null = *reinterpret_cast<BoundNotNullConstraint *>(constraint.get());
|
|
198021
|
+
auto ¬_null = *reinterpret_cast<NotNullConstraint *>(base_constraint.get());
|
|
198022
|
+
VerifyNotNullConstraint(table, chunk.data[bound_not_null.index], chunk.size(),
|
|
197922
198023
|
table.columns[not_null.index].Name());
|
|
197923
198024
|
break;
|
|
197924
198025
|
}
|
|
@@ -198389,13 +198490,16 @@ static bool CreateMockChunk(TableCatalogEntry &table, const vector<column_t> &co
|
|
|
198389
198490
|
|
|
198390
198491
|
void DataTable::VerifyUpdateConstraints(TableCatalogEntry &table, DataChunk &chunk,
|
|
198391
198492
|
const vector<column_t> &column_ids) {
|
|
198392
|
-
for (
|
|
198493
|
+
for (idx_t i = 0; i < table.bound_constraints.size(); i++) {
|
|
198494
|
+
auto &base_constraint = table.constraints[i];
|
|
198495
|
+
auto &constraint = table.bound_constraints[i];
|
|
198393
198496
|
switch (constraint->type) {
|
|
198394
198497
|
case ConstraintType::NOT_NULL: {
|
|
198395
|
-
auto &
|
|
198498
|
+
auto &bound_not_null = *reinterpret_cast<BoundNotNullConstraint *>(constraint.get());
|
|
198499
|
+
auto ¬_null = *reinterpret_cast<NotNullConstraint *>(base_constraint.get());
|
|
198396
198500
|
// check if the constraint is in the list of column_ids
|
|
198397
198501
|
for (idx_t i = 0; i < column_ids.size(); i++) {
|
|
198398
|
-
if (column_ids[i] ==
|
|
198502
|
+
if (column_ids[i] == bound_not_null.index) {
|
|
198399
198503
|
// found the column id: check the data in
|
|
198400
198504
|
VerifyNotNullConstraint(table, chunk.data[i], chunk.size(), table.columns[not_null.index].Name());
|
|
198401
198505
|
break;
|
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 "
|
|
15
|
-
#define DUCKDB_VERSION "v0.5.2-
|
|
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<
|
|
9494
|
+
vector<storage_t> fk_keys;
|
|
9495
9495
|
};
|
|
9496
9496
|
|
|
9497
9497
|
//! Constraint is the base class of any type of table constraint.
|
|
@@ -11416,6 +11416,7 @@ public:
|
|
|
11416
11416
|
DUCKDB_API ~ColumnDataCollection();
|
|
11417
11417
|
|
|
11418
11418
|
public:
|
|
11419
|
+
//! The types of columns in the ColumnDataCollection
|
|
11419
11420
|
DUCKDB_API vector<LogicalType> &Types() {
|
|
11420
11421
|
return types;
|
|
11421
11422
|
}
|
|
@@ -14409,7 +14410,7 @@ public:
|
|
|
14409
14410
|
ChunkCollection(Allocator &allocator);
|
|
14410
14411
|
ChunkCollection(ClientContext &context);
|
|
14411
14412
|
|
|
14412
|
-
//! The
|
|
14413
|
+
//! The types of columns in the ChunkCollection
|
|
14413
14414
|
DUCKDB_API vector<LogicalType> &Types() {
|
|
14414
14415
|
return types;
|
|
14415
14416
|
}
|