duckdb 0.5.2-dev874.0 → 0.5.2-dev880.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/.mocharc.json ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "extension": ["js", "ts"],
3
+ "spec": ["test/*.js", "test/*.ts"],
4
+ "require": "ts-node/register"
5
+ }
@@ -0,0 +1,94 @@
1
+ /**
2
+ * TypeScript declarations for Node.JS bindings for DuckDb.
3
+ * See https://duckdb.org/docs/api/nodejs/overview for details
4
+ * on Node.JS API
5
+ */
6
+ export class DuckDbError extends Error {
7
+ errno: number;
8
+ code: string;
9
+ }
10
+
11
+ type Callback<T> = (err: DuckDbError | null, res: T) => void;
12
+
13
+ export type RowData = {
14
+ [columnName: string]: any;
15
+ };
16
+
17
+ export type TableData = RowData[];
18
+
19
+ export class Connection {
20
+ constructor(db: Database, callback?: Callback<any>);
21
+
22
+ all(sql: string, ...args: [...any, Callback<TableData>] | []): void;
23
+ each(sql: string, ...args: [...any, Callback<RowData>] | []): void;
24
+ exec(sql: string, ...args: [...any, Callback<void>] | []): void;
25
+
26
+ prepare(sql: string, ...args: [...any, Callback<Statement>] | []): Statement;
27
+ run(sql: string, ...args: [...any, Callback<void>] | []): Statement;
28
+
29
+ register(
30
+ name: string,
31
+ return_type: string,
32
+ fun: (...args: any[]) => any
33
+ ): void;
34
+
35
+ register_bulk(
36
+ name: string,
37
+ return_type: string,
38
+ fun: (...args: any[]) => any
39
+ ): void;
40
+ unregister(name: string, callback: Callback<any>): void;
41
+
42
+ stream(sql: any, ...args: any[]): QueryResult;
43
+ }
44
+
45
+ export class QueryResult {
46
+ [Symbol.asyncIterator](): AsyncIterator<RowData>;
47
+ }
48
+
49
+ export class Database {
50
+ constructor(path: string, callback?: Callback<any>);
51
+
52
+ close(callback: Callback<void>): void;
53
+
54
+ connect(): Connection;
55
+
56
+ all(sql: string, ...args: [...any, Callback<TableData>] | []): void;
57
+ each(sql: string, ...args: [...any, Callback<RowData>] | []): void;
58
+ exec(sql: string, ...args: [...any, Callback<void>] | []): void;
59
+
60
+ prepare(sql: string, ...args: [...any, Callback<Statement>] | []): Statement;
61
+ run(sql: string, ...args: [...any, Callback<void>] | []): Statement;
62
+
63
+ register(
64
+ name: string,
65
+ return_type: string,
66
+ fun: (...args: any[]) => any
67
+ ): void;
68
+ unregister(name: string, callback: Callback<any>): void;
69
+ }
70
+
71
+ export class Statement {
72
+ constructor();
73
+
74
+ all(...args: [...any, Callback<TableData>] | []): void;
75
+ each(...args: [...any, Callback<RowData>] | []): void;
76
+
77
+ finalize(callback?: Callback<void>): void;
78
+
79
+ run(...args: [...any, Callback<void>] | []): Statement;
80
+ }
81
+
82
+ export const ERROR: number;
83
+
84
+ export const OPEN_CREATE: number;
85
+
86
+ export const OPEN_FULLMUTEX: number;
87
+
88
+ export const OPEN_PRIVATECACHE: number;
89
+
90
+ export const OPEN_READONLY: number;
91
+
92
+ export const OPEN_READWRITE: number;
93
+
94
+ export const OPEN_SHAREDCACHE: number;
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "duckdb",
3
3
  "main": "./lib/duckdb.js",
4
- "version": "0.5.2-dev874.0",
4
+ "types": "./lib/duckdb.d.ts",
5
+ "version": "0.5.2-dev880.0",
5
6
  "description": "DuckDB node.js API",
6
7
  "gypfile": true,
7
8
  "dependencies": {
@@ -25,15 +26,25 @@
25
26
  "test": "test"
26
27
  },
27
28
  "devDependencies": {
29
+ "@types/mocha": "^10.0.0",
30
+ "@types/node": "^18.11.0",
28
31
  "aws-sdk": "^2.790.0",
29
32
  "chai": "^4.3.6",
30
33
  "jsdoc3-parser": "^2.0.0",
31
- "mocha": "^8.3.0"
34
+ "mocha": "^8.3.0",
35
+ "ts-node": "^10.9.1",
36
+ "tsconfig-paths": "^4.0.0",
37
+ "typescript": "^4.8.4"
32
38
  },
33
39
  "repository": {
34
40
  "type": "git",
35
41
  "url": "git+https://github.com/cwida/duckdb.git"
36
42
  },
43
+ "ts-node": {
44
+ "require": [
45
+ "tsconfig-paths/register"
46
+ ]
47
+ },
37
48
  "keywords": [
38
49
  "database",
39
50
  "sql",
package/src/duckdb.cpp CHANGED
@@ -69964,7 +69964,7 @@ string PhysicalComparisonJoin::ParamsToString() const {
69964
69964
  string op = ExpressionTypeToOperator(it.comparison);
69965
69965
  extra_info += it.left->GetName() + " " + op + " " + it.right->GetName() + "\n";
69966
69966
  }
69967
- extra_info += "\nEC = " + std::to_string(estimated_props->GetCardinality()) + "\n";
69967
+ extra_info += "\nEC = " + std::to_string(estimated_props->GetCardinality<double>()) + "\n";
69968
69968
  extra_info += "COST = " + std::to_string(estimated_props->GetCost()) + "\n";
69969
69969
  return extra_info;
69970
69970
  }
@@ -85747,7 +85747,7 @@ unique_ptr<PhysicalOperator> PhysicalPlanGenerator::CreatePlan(LogicalOperator &
85747
85747
  }
85748
85748
 
85749
85749
  if (op.estimated_props) {
85750
- plan->estimated_cardinality = op.estimated_props->GetCardinality();
85750
+ plan->estimated_cardinality = op.estimated_props->GetCardinality<idx_t>();
85751
85751
  plan->estimated_props = op.estimated_props->Copy();
85752
85752
  } else {
85753
85753
  plan->estimated_props = make_unique<EstimatedProperties>();
@@ -145624,13 +145624,13 @@ void CardinalityEstimator::InitEquivalentRelations(vector<unique_ptr<FilterInfo>
145624
145624
  }
145625
145625
 
145626
145626
  void CardinalityEstimator::VerifySymmetry(JoinNode *result, JoinNode *entry) {
145627
- if (result->GetCardinality() != entry->GetCardinality()) {
145627
+ if (result->GetCardinality<double>() != entry->GetCardinality<double>()) {
145628
145628
  // Currently it's possible that some entries are cartesian joins.
145629
145629
  // When this is the case, you don't always have symmetry, but
145630
145630
  // if the cost of the result is less, then just assure the cardinality
145631
145631
  // is also less, then you have the same effect of symmetry.
145632
- D_ASSERT(ceil(result->GetCardinality()) <= ceil(entry->GetCardinality()) ||
145633
- floor(result->GetCardinality()) <= floor(entry->GetCardinality()));
145632
+ D_ASSERT(ceil(result->GetCardinality<double>()) <= ceil(entry->GetCardinality<double>()) ||
145633
+ floor(result->GetCardinality<double>()) <= floor(entry->GetCardinality<double>()));
145634
145634
  }
145635
145635
  }
145636
145636
 
@@ -145647,9 +145647,9 @@ double CardinalityEstimator::ComputeCost(JoinNode *left, JoinNode *right, double
145647
145647
  double CardinalityEstimator::EstimateCrossProduct(const JoinNode *left, const JoinNode *right) {
145648
145648
  // need to explicity use double here, otherwise auto converts it to an int, then
145649
145649
  // there is an autocast in the return.
145650
- return left->GetCardinality() >= (NumericLimits<double>::Maximum() / right->GetCardinality())
145650
+ return left->GetCardinality<double>() >= (NumericLimits<double>::Maximum() / right->GetCardinality<double>())
145651
145651
  ? NumericLimits<double>::Maximum()
145652
- : left->GetCardinality() * right->GetCardinality();
145652
+ : left->GetCardinality<double>() * right->GetCardinality<double>();
145653
145653
  }
145654
145654
 
145655
145655
  void CardinalityEstimator::AddRelationColumnMapping(LogicalGet *get, idx_t relation_id) {
@@ -145874,7 +145874,7 @@ void CardinalityEstimator::InitCardinalityEstimatorProps(vector<struct NodeOp> *
145874
145874
 
145875
145875
  void CardinalityEstimator::UpdateTotalDomains(JoinNode *node, LogicalOperator *op) {
145876
145876
  auto relation_id = node->set->relations[0];
145877
- relation_attributes[relation_id].cardinality = node->GetCardinality();
145877
+ relation_attributes[relation_id].cardinality = node->GetCardinality<double>();
145878
145878
  TableCatalogEntry *catalog_table = nullptr;
145879
145879
  auto get = GetLogicalGet(op);
145880
145880
  if (get) {
@@ -145906,7 +145906,7 @@ void CardinalityEstimator::UpdateTotalDomains(JoinNode *node, LogicalOperator *o
145906
145906
  // We decrease the total domain for all columns in the equivalence set because filter pushdown
145907
145907
  // will mean all columns are affected.
145908
145908
  if (direct_filter) {
145909
- count = node->GetCardinality();
145909
+ count = node->GetCardinality<idx_t>();
145910
145910
  }
145911
145911
 
145912
145912
  // HLL has estimation error, count can't be greater than cardinality of the table before filters
@@ -145917,7 +145917,7 @@ void CardinalityEstimator::UpdateTotalDomains(JoinNode *node, LogicalOperator *o
145917
145917
  // No HLL. So if we know there is a direct filter, reduce count to cardinality with filter
145918
145918
  // otherwise assume the total domain is still the cardinality
145919
145919
  if (direct_filter) {
145920
- count = node->GetCardinality();
145920
+ count = node->GetCardinality<idx_t>();
145921
145921
  } else {
145922
145922
  count = node->GetBaseTableCardinality();
145923
145923
  }
@@ -147016,10 +147016,18 @@ bool Deliminator::RemoveInequalityCandidate(unique_ptr<LogicalOperator> *plan, u
147016
147016
 
147017
147017
  namespace duckdb {
147018
147018
 
147019
- double EstimatedProperties::GetCardinality() {
147019
+ template <>
147020
+ double EstimatedProperties::GetCardinality() const {
147020
147021
  return cardinality;
147021
147022
  }
147022
- double EstimatedProperties::GetCost() {
147023
+
147024
+ template <>
147025
+ idx_t EstimatedProperties::GetCardinality() const {
147026
+ auto max_idx_t = NumericLimits<idx_t>::Maximum() - 10000;
147027
+ return MinValue<double>(cardinality, max_idx_t);
147028
+ }
147029
+
147030
+ double EstimatedProperties::GetCost() const {
147023
147031
  return cost;
147024
147032
  }
147025
147033
 
@@ -149170,10 +149178,6 @@ unique_ptr<EstimatedProperties> EstimatedProperties::Copy() {
149170
149178
  return result;
149171
149179
  }
149172
149180
 
149173
- double JoinNode::GetCardinality() const {
149174
- return estimated_props->GetCardinality();
149175
- }
149176
-
149177
149181
  double JoinNode::GetCost() {
149178
149182
  return estimated_props->GetCost();
149179
149183
  }
@@ -149203,10 +149207,10 @@ string JoinNode::ToString() {
149203
149207
  }
149204
149208
  string result = "-------------------------------\n";
149205
149209
  result += set->ToString() + "\n";
149206
- result += "card = " + to_string(GetCardinality()) + "\n";
149210
+ result += "card = " + to_string(GetCardinality<double>()) + "\n";
149207
149211
  bool is_cartesian = false;
149208
149212
  if (left && right) {
149209
- is_cartesian = (GetCardinality() == left->GetCardinality() * right->GetCardinality());
149213
+ is_cartesian = (GetCardinality<double>() == left->GetCardinality<double>() * right->GetCardinality<double>());
149210
149214
  }
149211
149215
  result += "cartesian = " + to_string(is_cartesian) + "\n";
149212
149216
  result += "cost = " + to_string(estimated_props->GetCost()) + "\n";
@@ -149749,14 +149753,14 @@ unique_ptr<JoinNode> JoinOrderOptimizer::CreateJoinTree(JoinRelationSet *set,
149749
149753
  auto plan = plans.find(set);
149750
149754
  // if we have already calculated an expected cardinality for this set,
149751
149755
  // just re-use that cardinality
149752
- if (left->GetCardinality() < right->GetCardinality()) {
149756
+ if (left->GetCardinality<double>() < right->GetCardinality<double>()) {
149753
149757
  return CreateJoinTree(set, possible_connections, right, left);
149754
149758
  }
149755
149759
  if (plan != plans.end()) {
149756
149760
  if (!plan->second) {
149757
149761
  throw InternalException("No plan: internal error in join order optimizer");
149758
149762
  }
149759
- expected_cardinality = plan->second->GetCardinality();
149763
+ expected_cardinality = plan->second->GetCardinality<double>();
149760
149764
  best_connection = possible_connections.back();
149761
149765
  } else if (possible_connections.empty()) {
149762
149766
  // cross product
@@ -150121,7 +150125,8 @@ void JoinOrderOptimizer::SolveJoinOrderApproximately() {
150121
150125
  auto current_plan = plans[join_relations[i]].get();
150122
150126
  // check if the cardinality is smaller than the smallest two found so far
150123
150127
  for (idx_t j = 0; j < 2; j++) {
150124
- if (!smallest_plans[j] || smallest_plans[j]->GetCardinality() > current_plan->GetCardinality()) {
150128
+ if (!smallest_plans[j] ||
150129
+ smallest_plans[j]->GetCardinality<double>() > current_plan->GetCardinality<double>()) {
150125
150130
  smallest_plans[j] = current_plan;
150126
150131
  smallest_index[j] = i;
150127
150132
  break;
@@ -150256,8 +150261,7 @@ JoinOrderOptimizer::GenerateJoins(vector<unique_ptr<LogicalOperator>> &extracted
150256
150261
  result_relation = node->set;
150257
150262
  result_operator = move(extracted_relations[node->set->relations[0]]);
150258
150263
  }
150259
- auto max_idx_t = NumericLimits<idx_t>::Maximum() - 10000;
150260
- result_operator->estimated_cardinality = MinValue<idx_t>(node->GetCardinality(), max_idx_t);
150264
+ result_operator->estimated_cardinality = node->GetCardinality<idx_t>();
150261
150265
  result_operator->has_estimated_cardinality = true;
150262
150266
  result_operator->estimated_props = node->estimated_props->Copy();
150263
150267
  // check if we should do a pushdown on this node