duckdb 0.3.5-dev677.0 → 0.3.5-dev703.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-dev677.0",
4
+ "version": "0.3.5-dev703.0",
5
5
  "description": "DuckDB node.js API",
6
6
  "gypfile": true,
7
7
  "dependencies": {
@@ -363,6 +363,13 @@ struct ExecTask : public Task {
363
363
  }
364
364
  }
365
365
  }
366
+
367
+ void Callback() override {
368
+ auto env = object.Env();
369
+ Napi::HandleScope scope(env);
370
+ callback.Value().MakeCallback(object.Value(), {success ? env.Null() : Napi::String::New(env, error)});
371
+ };
372
+
366
373
  std::string sql;
367
374
  bool success;
368
375
  std::string error;
package/src/duckdb.cpp CHANGED
@@ -18728,6 +18728,7 @@ duckdb::string_t StringCastTZ::Operation(timestamp_t input, Vector &result);
18728
18728
 
18729
18729
 
18730
18730
 
18731
+ #include <cmath>
18731
18732
 
18732
18733
  namespace duckdb {
18733
18734
 
@@ -18786,10 +18787,21 @@ bool TryCastWithOverflowCheckFloat(SRC value, T &result, SRC min, SRC max) {
18786
18787
  if (!(value >= min && value < max)) {
18787
18788
  return false;
18788
18789
  }
18789
- result = T(value);
18790
+ // PG FLOAT => INT casts use statistical rounding.
18791
+ result = std::nearbyint(value);
18790
18792
  return true;
18791
18793
  }
18792
18794
 
18795
+ template <>
18796
+ bool TryCastWithOverflowCheck(float value, int8_t &result) {
18797
+ return TryCastWithOverflowCheckFloat<float, int8_t>(value, result, -128.0f, 128.0f);
18798
+ }
18799
+
18800
+ template <>
18801
+ bool TryCastWithOverflowCheck(float value, int16_t &result) {
18802
+ return TryCastWithOverflowCheckFloat<float, int16_t>(value, result, -32768.0f, 32768.0f);
18803
+ }
18804
+
18793
18805
  template <>
18794
18806
  bool TryCastWithOverflowCheck(float value, int32_t &result) {
18795
18807
  return TryCastWithOverflowCheckFloat<float, int32_t>(value, result, -2147483648.0f, 2147483648.0f);
@@ -18801,6 +18813,21 @@ bool TryCastWithOverflowCheck(float value, int64_t &result) {
18801
18813
  9223372036854775808.0f);
18802
18814
  }
18803
18815
 
18816
+ template <>
18817
+ bool TryCastWithOverflowCheck(double value, int8_t &result) {
18818
+ return TryCastWithOverflowCheckFloat<double, int8_t>(value, result, -128.0, 128.0);
18819
+ }
18820
+
18821
+ template <>
18822
+ bool TryCastWithOverflowCheck(double value, int16_t &result) {
18823
+ return TryCastWithOverflowCheckFloat<double, int16_t>(value, result, -32768.0, 32768.0);
18824
+ }
18825
+
18826
+ template <>
18827
+ bool TryCastWithOverflowCheck(double value, int32_t &result) {
18828
+ return TryCastWithOverflowCheckFloat<double, int32_t>(value, result, -2147483648.0, 2147483648.0);
18829
+ }
18830
+
18804
18831
  template <>
18805
18832
  bool TryCastWithOverflowCheck(double value, int64_t &result) {
18806
18833
  return TryCastWithOverflowCheckFloat<double, int64_t>(value, result, -9223372036854775808.0, 9223372036854775808.0);
@@ -19026,12 +19053,12 @@ bool TryCastWithOverflowCheck(uint64_t value, hugeint_t &result) {
19026
19053
 
19027
19054
  template <>
19028
19055
  bool TryCastWithOverflowCheck(float value, hugeint_t &result) {
19029
- return Hugeint::TryConvert(value, result);
19056
+ return Hugeint::TryConvert(std::nearbyintf(value), result);
19030
19057
  }
19031
19058
 
19032
19059
  template <>
19033
19060
  bool TryCastWithOverflowCheck(double value, hugeint_t &result) {
19034
- return Hugeint::TryConvert(value, result);
19061
+ return Hugeint::TryConvert(std::nearbyint(value), result);
19035
19062
  }
19036
19063
 
19037
19064
  template <>
@@ -23282,7 +23309,7 @@ struct IntegerCastOperation {
23282
23309
  if (dbl_res < NumericLimits<result_t>::Minimum() || dbl_res > NumericLimits<result_t>::Maximum()) {
23283
23310
  return false;
23284
23311
  }
23285
- state.result = (result_t)dbl_res;
23312
+ state.result = (result_t)std::nearbyint(dbl_res);
23286
23313
  return true;
23287
23314
  }
23288
23315
 
@@ -41269,11 +41296,11 @@ inline uint64_t TemplatedHash(const string_t &elem) {
41269
41296
  data_ptr_t data = (data_ptr_t)elem.GetDataUnsafe();
41270
41297
  const auto &len = elem.GetSize();
41271
41298
  uint64_t h = 0;
41272
- for (idx_t i = 0; i < len / 8; i += 8) {
41299
+ for (idx_t i = 0; i + sizeof(uint64_t) <= len; i += sizeof(uint64_t)) {
41273
41300
  h ^= TemplatedHash<uint64_t>(Load<uint64_t>(data));
41274
- data += 8;
41301
+ data += sizeof(uint64_t);
41275
41302
  }
41276
- switch (len & 7) {
41303
+ switch (len & (sizeof(uint64_t) - 1)) {
41277
41304
  case 4:
41278
41305
  h ^= TemplatedHash<uint32_t>(Load<uint32_t>(data));
41279
41306
  break;
@@ -46233,7 +46260,6 @@ const SelectionVector *ConstantVector::ZeroSelectionVector(idx_t count, Selectio
46233
46260
  }
46234
46261
 
46235
46262
  void ConstantVector::Reference(Vector &vector, Vector &source, idx_t position, idx_t count) {
46236
- D_ASSERT(position < count);
46237
46263
  auto &source_type = source.GetType();
46238
46264
  switch (source_type.InternalType()) {
46239
46265
  case PhysicalType::LIST: {
@@ -46281,7 +46307,7 @@ void ConstantVector::Reference(Vector &vector, Vector &source, idx_t position, i
46281
46307
  auto &source_entries = StructVector::GetEntries(source);
46282
46308
  auto &target_entries = StructVector::GetEntries(vector);
46283
46309
  for (idx_t i = 0; i < source_entries.size(); i++) {
46284
- ConstantVector::Reference(*target_entries[i], *source_entries[i], position, count);
46310
+ ConstantVector::Reference(*target_entries[i], *source_entries[i], struct_index, count);
46285
46311
  }
46286
46312
  vector.SetVectorType(VectorType::CONSTANT_VECTOR);
46287
46313
  break;
@@ -51713,6 +51739,7 @@ static inline void TemplatedLoopHash(Vector &input, Vector &result, const Select
51713
51739
 
51714
51740
  template <bool HAS_RSEL, bool FIRST_HASH>
51715
51741
  static inline void StructLoopHash(Vector &input, Vector &hashes, const SelectionVector *rsel, idx_t count) {
51742
+ input.Normalify(count);
51716
51743
  auto &children = StructVector::GetEntries(input);
51717
51744
 
51718
51745
  D_ASSERT(!children.empty());
@@ -114848,6 +114875,9 @@ void ClientContext::LogQueryInternal(ClientContextLock &, const string &query) {
114848
114875
 
114849
114876
  unique_ptr<QueryResult> ClientContext::Query(unique_ptr<SQLStatement> statement, bool allow_stream_result) {
114850
114877
  auto pending_query = PendingQuery(move(statement), allow_stream_result);
114878
+ if (!pending_query->success) {
114879
+ return make_unique<MaterializedQueryResult>(pending_query->error);
114880
+ }
114851
114881
  return pending_query->Execute();
114852
114882
  }
114853
114883
 
@@ -181028,6 +181058,8 @@ void BaseStatistics::Verify(Vector &vector, idx_t count) const {
181028
181058
 
181029
181059
 
181030
181060
 
181061
+ #include <math.h>
181062
+
181031
181063
  namespace duckdb {
181032
181064
 
181033
181065
  DistinctStatistics::DistinctStatistics()
@@ -181088,7 +181120,7 @@ void DistinctStatistics::Update(VectorData &vdata, const LogicalType &type, idx_
181088
181120
  return;
181089
181121
  }
181090
181122
  total_count += count;
181091
- count = MaxValue<idx_t>(idx_t(SAMPLE_RATE * double(count)), 1);
181123
+ count = MinValue<idx_t>(idx_t(SAMPLE_RATE * MaxValue<idx_t>(STANDARD_VECTOR_SIZE, count)), count);
181092
181124
  sample_count += count;
181093
181125
 
181094
181126
  uint64_t indices[STANDARD_VECTOR_SIZE];
@@ -181106,12 +181138,17 @@ idx_t DistinctStatistics::GetCount() const {
181106
181138
  if (sample_count == 0 || total_count == 0) {
181107
181139
  return 0;
181108
181140
  }
181109
- // Estimate HLL count because we use sampling
181110
- double hll_count = log->Count();
181111
- double unique_proportion = hll_count / double(sample_count);
181112
- double actual_sample_rate = double(sample_count) / double(total_count);
181113
- double multiplier = double(1) + unique_proportion * (double(1) / actual_sample_rate - double(1));
181114
- return idx_t(multiplier * hll_count);
181141
+
181142
+ double u = MinValue<idx_t>(log->Count(), sample_count);
181143
+ double s = sample_count;
181144
+ double n = total_count;
181145
+
181146
+ // Assume this proportion of the the sampled values occurred only once
181147
+ double u1 = pow(u / s, 2) * u;
181148
+
181149
+ // Estimate total uniques using Good Turing Estimation
181150
+ idx_t estimate = u + u1 / s * (n - s);
181151
+ return MinValue<idx_t>(estimate, total_count);
181115
181152
  }
181116
181153
 
181117
181154
  } // namespace duckdb