duckdb 0.3.5-dev1272.0 → 0.3.5-dev1285.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.5-dev1272.0",
4
+ "version": "0.3.5-dev1285.0",
5
5
  "description": "DuckDB node.js API",
6
6
  "gypfile": true,
7
7
  "dependencies": {
package/src/duckdb.cpp CHANGED
@@ -3951,6 +3951,7 @@ unique_ptr<CatalogEntry> TableCatalogEntry::ChangeColumnType(ClientContext &cont
3951
3951
  }
3952
3952
  auto change_idx = GetColumnIndex(info.column_name);
3953
3953
  auto create_info = make_unique<CreateTableInfo>(schema->name, name);
3954
+ create_info->temporary = temporary;
3954
3955
 
3955
3956
  for (idx_t i = 0; i < columns.size(); i++) {
3956
3957
  auto copy = columns[i].Copy();
@@ -4032,6 +4033,7 @@ unique_ptr<CatalogEntry> TableCatalogEntry::ChangeColumnType(ClientContext &cont
4032
4033
 
4033
4034
  unique_ptr<CatalogEntry> TableCatalogEntry::SetForeignKeyConstraint(ClientContext &context, AlterForeignKeyInfo &info) {
4034
4035
  auto create_info = make_unique<CreateTableInfo>(schema->name, name);
4036
+ create_info->temporary = temporary;
4035
4037
 
4036
4038
  for (idx_t i = 0; i < columns.size(); i++) {
4037
4039
  create_info->columns.push_back(columns[i].Copy());
@@ -23773,7 +23775,7 @@ template <typename T>
23773
23775
  struct IntegerCastData {
23774
23776
  using Result = T;
23775
23777
  Result result;
23776
- uint8_t decimal_count;
23778
+ bool seen_decimal;
23777
23779
  };
23778
23780
 
23779
23781
  struct IntegerCastOperation {
@@ -23807,14 +23809,27 @@ struct IntegerCastOperation {
23807
23809
 
23808
23810
  template <class T, bool NEGATIVE>
23809
23811
  static bool HandleDecimal(T &state, uint8_t digit) {
23810
- if (!state.decimal_count) {
23811
- if (NEGATIVE) {
23812
- state.result -= (digit >= 5);
23813
- } else {
23814
- state.result += (digit >= 5);
23812
+ if (state.seen_decimal) {
23813
+ return true;
23814
+ }
23815
+ state.seen_decimal = true;
23816
+ // round the integer based on what is after the decimal point
23817
+ // if digit >= 5, then we round up (or down in case of negative numbers)
23818
+ auto increment = digit >= 5;
23819
+ if (!increment) {
23820
+ return true;
23821
+ }
23822
+ if (NEGATIVE) {
23823
+ if (state.result == NumericLimits<typename T::Result>::Minimum()) {
23824
+ return false;
23825
+ }
23826
+ state.result--;
23827
+ } else {
23828
+ if (state.result == NumericLimits<typename T::Result>::Maximum()) {
23829
+ return false;
23815
23830
  }
23831
+ state.result++;
23816
23832
  }
23817
- ++state.decimal_count;
23818
23833
  return true;
23819
23834
  }
23820
23835
 
@@ -24512,7 +24527,7 @@ struct DecimalCastOperation {
24512
24527
  static bool HandleExponent(T &state, int32_t exponent) {
24513
24528
  Finalize<T>(state);
24514
24529
  if (exponent < 0) {
24515
- for (idx_t i = 0; i < idx_t(-exponent); i++) {
24530
+ for (idx_t i = 0; i < idx_t(-int64_t(exponent)); i++) {
24516
24531
  state.result /= 10;
24517
24532
  if (state.result == 0) {
24518
24533
  break;
@@ -126004,7 +126019,8 @@ PreparedStatementData::~PreparedStatementData() {
126004
126019
 
126005
126020
  void PreparedStatementData::Bind(vector<Value> values) {
126006
126021
  // set parameters
126007
- const auto required = unbound_statement ? unbound_statement->n_param : 0;
126022
+ const auto required = properties.parameter_count;
126023
+ D_ASSERT(!unbound_statement || unbound_statement->n_param == properties.parameter_count);
126008
126024
  if (values.size() != required) {
126009
126025
  throw BinderException("Parameter/argument count mismatch for prepared statement. Expected %llu, got %llu",
126010
126026
  required, values.size());
@@ -157859,6 +157875,9 @@ namespace duckdb {
157859
157875
  unique_ptr<ParsedExpression> Transformer::TransformParamRef(duckdb_libpgquery::PGParamRef *node) {
157860
157876
  D_ASSERT(node);
157861
157877
  auto expr = make_unique<ParameterExpression>();
157878
+ if (node->number < 0) {
157879
+ throw ParserException("Parameter numbers cannot be negative");
157880
+ }
157862
157881
  if (node->number == 0) {
157863
157882
  expr->parameter_nr = ParamCount() + 1;
157864
157883
  } else {
@@ -158901,6 +158920,14 @@ static void CheckGroupingSetMax(idx_t count) {
158901
158920
  }
158902
158921
  }
158903
158922
 
158923
+ static void CheckGroupingSetCubes(idx_t current_count, idx_t cube_count) {
158924
+ idx_t combinations = 1;
158925
+ for (idx_t i = 0; i < cube_count; i++) {
158926
+ combinations *= 2;
158927
+ CheckGroupingSetMax(current_count + combinations);
158928
+ }
158929
+ }
158930
+
158904
158931
  struct GroupingExpressionMap {
158905
158932
  expression_map_t<idx_t> map;
158906
158933
  };
@@ -159005,6 +159032,8 @@ void Transformer::TransformGroupByNode(duckdb_libpgquery::PGNode *n, GroupingExp
159005
159032
  cube_sets.push_back(VectorToGroupingSet(cube_set));
159006
159033
  }
159007
159034
  // generate the subsets of the rollup set and add them to the grouping sets
159035
+ CheckGroupingSetCubes(result_sets.size(), cube_sets.size());
159036
+
159008
159037
  GroupingSet current_set;
159009
159038
  AddCubeSets(current_set, cube_sets, result_sets, 0);
159010
159039
  break;
@@ -163256,6 +163285,7 @@ BindResult ExpressionBinder::BindExpression(OperatorExpression &op, idx_t depth)
163256
163285
  namespace duckdb {
163257
163286
 
163258
163287
  BindResult ExpressionBinder::BindExpression(ParameterExpression &expr, idx_t depth) {
163288
+ D_ASSERT(expr.parameter_nr > 0);
163259
163289
  auto bound_parameter = make_unique<BoundParameterExpression>(expr.parameter_nr);
163260
163290
  if (!binder.parameters) {
163261
163291
  throw std::runtime_error("Unexpected prepared parameter. This type of statement can't be prepared!");
@@ -166062,6 +166092,8 @@ BoundStatement Binder::Bind(CreateStatement &stmt) {
166062
166092
  // If there is a foreign key constraint, resolve primary key column's index from primary key column's name
166063
166093
  auto &create_info = (CreateTableInfo &)*stmt.info;
166064
166094
  auto &catalog = Catalog::GetCatalog(context);
166095
+ // We first check if there are any user types, if yes we check to which custom types they refer.
166096
+ unordered_set<SchemaCatalogEntry *> fk_schemas;
166065
166097
  for (idx_t i = 0; i < create_info.constraints.size(); i++) {
166066
166098
  auto &cond = create_info.constraints[i];
166067
166099
  if (cond->type != ConstraintType::FOREIGN_KEY) {
@@ -166078,6 +166110,7 @@ BoundStatement Binder::Bind(CreateStatement &stmt) {
166078
166110
  } else {
166079
166111
  // have to resolve referenced table
166080
166112
  auto pk_table_entry_ptr = catalog.GetEntry<TableCatalogEntry>(context, fk.info.schema, fk.info.table);
166113
+ fk_schemas.insert(pk_table_entry_ptr->schema);
166081
166114
  D_ASSERT(fk.info.pk_keys.empty());
166082
166115
  FindMatchingPrimaryKeyColumns(pk_table_entry_ptr->constraints, fk);
166083
166116
  for (auto &keyname : fk.pk_columns) {
@@ -166102,10 +166135,15 @@ BoundStatement Binder::Bind(CreateStatement &stmt) {
166102
166135
  if (AnyConstraintReferencesGeneratedColumn(create_info)) {
166103
166136
  throw BinderException("Constraints on generated columns are not supported yet");
166104
166137
  }
166105
- // We first check if there are any user types, if yes we check to which custom types they refer.
166106
166138
  auto bound_info = BindCreateTableInfo(move(stmt.info));
166107
166139
  auto root = move(bound_info->query);
166108
166140
 
166141
+ for (auto &fk_schema : fk_schemas) {
166142
+ if (fk_schema != bound_info->schema) {
166143
+ throw BinderException("Creating foreign keys across different schemas is not supported");
166144
+ }
166145
+ }
166146
+
166109
166147
  // create the logical operator
166110
166148
  auto &schema = bound_info->schema;
166111
166149
  auto create_table = make_unique<LogicalCreateTable>(schema, move(bound_info));
@@ -172822,6 +172860,7 @@ Planner::Planner(ClientContext &context) : binder(Binder::CreateBinder(context))
172822
172860
 
172823
172861
  void Planner::CreatePlan(SQLStatement &statement) {
172824
172862
  auto &profiler = QueryProfiler::Get(context);
172863
+ auto parameter_count = statement.n_param;
172825
172864
 
172826
172865
  vector<BoundParameterExpression *> bound_parameters;
172827
172866
 
@@ -172833,6 +172872,7 @@ void Planner::CreatePlan(SQLStatement &statement) {
172833
172872
  profiler.EndPhase();
172834
172873
 
172835
172874
  this->properties = binder->properties;
172875
+ this->properties.parameter_count = parameter_count;
172836
172876
  this->names = bound_statement.names;
172837
172877
  this->types = bound_statement.types;
172838
172878
  this->plan = move(bound_statement.plan);
@@ -172877,6 +172917,7 @@ shared_ptr<PreparedStatementData> Planner::PrepareSQLStatement(unique_ptr<SQLSta
172877
172917
 
172878
172918
  void Planner::PlanExecute(unique_ptr<SQLStatement> statement) {
172879
172919
  auto &stmt = (ExecuteStatement &)*statement;
172920
+ auto parameter_count = stmt.n_param;
172880
172921
 
172881
172922
  // bind the prepared statement
172882
172923
  auto &client_data = ClientData::Get(context);
@@ -172915,6 +172956,12 @@ void Planner::PlanExecute(unique_ptr<SQLStatement> statement) {
172915
172956
  D_ASSERT(prepared->properties.bound_all_parameters);
172916
172957
  rebound = true;
172917
172958
  }
172959
+ // copy the properties of the prepared statement into the planner
172960
+ this->properties = prepared->properties;
172961
+ this->properties.parameter_count = parameter_count;
172962
+ this->names = prepared->names;
172963
+ this->types = prepared->types;
172964
+
172918
172965
  // add casts to the prepared statement parameters as required
172919
172966
  for (idx_t i = 0; i < bind_values.size(); i++) {
172920
172967
  if (prepared->value_map.count(i + 1) == 0) {
@@ -172931,10 +172978,6 @@ void Planner::PlanExecute(unique_ptr<SQLStatement> statement) {
172931
172978
  return;
172932
172979
  }
172933
172980
 
172934
- // copy the properties of the prepared statement into the planner
172935
- this->properties = prepared->properties;
172936
- this->names = prepared->names;
172937
- this->types = prepared->types;
172938
172981
  this->plan = make_unique<LogicalExecute>(move(prepared));
172939
172982
  }
172940
172983
 
@@ -172950,6 +172993,7 @@ void Planner::PlanPrepare(unique_ptr<SQLStatement> statement) {
172950
172993
  properties.requires_valid_transaction = false;
172951
172994
  properties.allow_stream_result = false;
172952
172995
  properties.bound_all_parameters = true;
172996
+ properties.parameter_count = 0;
172953
172997
  properties.return_type = StatementReturnType::NOTHING;
172954
172998
  this->names = {"Success"};
172955
172999
  this->types = {LogicalType::BOOLEAN};
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 "2000fbe90"
15
- #define DUCKDB_VERSION "v0.3.5-dev1272"
14
+ #define DUCKDB_SOURCE_ID "2c3c08da3"
15
+ #define DUCKDB_VERSION "v0.3.5-dev1285"
16
16
  //===----------------------------------------------------------------------===//
17
17
  // DuckDB
18
18
  //
@@ -9897,7 +9897,7 @@ enum class StatementReturnType : uint8_t {
9897
9897
  struct StatementProperties {
9898
9898
  StatementProperties()
9899
9899
  : read_only(true), requires_valid_transaction(true), allow_stream_result(false), bound_all_parameters(true),
9900
- return_type(StatementReturnType::QUERY_RESULT) {
9900
+ return_type(StatementReturnType::QUERY_RESULT), parameter_count(0) {
9901
9901
  }
9902
9902
 
9903
9903
  //! Whether or not the statement is a read-only statement, or whether it can result in changes to the database
@@ -9911,6 +9911,8 @@ struct StatementProperties {
9911
9911
  bool bound_all_parameters;
9912
9912
  //! What type of data the statement returns
9913
9913
  StatementReturnType return_type;
9914
+ //! The number of prepared statement parameters
9915
+ idx_t parameter_count;
9914
9916
  };
9915
9917
 
9916
9918
  } // namespace duckdb
@@ -14157,11 +14159,11 @@ public:
14157
14159
  //! The statement type
14158
14160
  StatementType type;
14159
14161
  //! The statement location within the query string
14160
- idx_t stmt_location;
14162
+ idx_t stmt_location = 0;
14161
14163
  //! The statement length within the query string
14162
- idx_t stmt_length;
14164
+ idx_t stmt_length = 0;
14163
14165
  //! The number of prepared statement parameters (if any)
14164
- idx_t n_param;
14166
+ idx_t n_param = 0;
14165
14167
  //! The query text that corresponds to this SQL statement
14166
14168
  string query;
14167
14169