duckdb 0.3.3-dev1251.0 → 0.3.3-dev1275.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 +496 -295
- package/src/duckdb.hpp +42 -16
- package/src/parquet-amalgamation.cpp +36564 -36576
package/src/duckdb.cpp
CHANGED
|
@@ -18236,10 +18236,14 @@ duckdb::string_t StringCastTZ::Operation(timestamp_t input, Vector &result);
|
|
|
18236
18236
|
|
|
18237
18237
|
|
|
18238
18238
|
|
|
18239
|
+
|
|
18239
18240
|
namespace duckdb {
|
|
18240
18241
|
|
|
18241
18242
|
template <class SRC, class DST>
|
|
18242
18243
|
static bool TryCastWithOverflowCheck(SRC value, DST &result) {
|
|
18244
|
+
if (!Value::IsFinite<SRC>(value)) {
|
|
18245
|
+
return false;
|
|
18246
|
+
}
|
|
18243
18247
|
if (NumericLimits<SRC>::IsSigned() != NumericLimits<DST>::IsSigned()) {
|
|
18244
18248
|
if (NumericLimits<SRC>::IsSigned()) {
|
|
18245
18249
|
// signed to unsigned conversion
|
|
@@ -18282,40 +18286,58 @@ static bool TryCastWithOverflowCheck(SRC value, DST &result) {
|
|
|
18282
18286
|
}
|
|
18283
18287
|
}
|
|
18284
18288
|
|
|
18285
|
-
template
|
|
18286
|
-
bool
|
|
18287
|
-
if (!(value
|
|
18289
|
+
template <class SRC, class T>
|
|
18290
|
+
bool TryCastWithOverflowCheckFloat(SRC value, T &result, SRC min, SRC max) {
|
|
18291
|
+
if (!Value::IsFinite<SRC>(value)) {
|
|
18288
18292
|
return false;
|
|
18289
18293
|
}
|
|
18290
|
-
|
|
18294
|
+
if (!(value >= min && value < max)) {
|
|
18295
|
+
return false;
|
|
18296
|
+
}
|
|
18297
|
+
result = T(value);
|
|
18291
18298
|
return true;
|
|
18292
18299
|
}
|
|
18293
18300
|
|
|
18301
|
+
template <>
|
|
18302
|
+
bool TryCastWithOverflowCheck(float value, int32_t &result) {
|
|
18303
|
+
return TryCastWithOverflowCheckFloat<float, int32_t>(value, result, -2147483648.0f, 2147483648.0f);
|
|
18304
|
+
}
|
|
18305
|
+
|
|
18294
18306
|
template <>
|
|
18295
18307
|
bool TryCastWithOverflowCheck(float value, int64_t &result) {
|
|
18296
|
-
|
|
18297
|
-
|
|
18298
|
-
}
|
|
18299
|
-
result = int64_t(value);
|
|
18300
|
-
return true;
|
|
18308
|
+
return TryCastWithOverflowCheckFloat<float, int64_t>(value, result, -9223372036854775808.0f,
|
|
18309
|
+
9223372036854775808.0f);
|
|
18301
18310
|
}
|
|
18302
18311
|
|
|
18303
18312
|
template <>
|
|
18304
18313
|
bool TryCastWithOverflowCheck(double value, int64_t &result) {
|
|
18305
|
-
|
|
18306
|
-
|
|
18307
|
-
|
|
18308
|
-
|
|
18314
|
+
return TryCastWithOverflowCheckFloat<double, int64_t>(value, result, -9223372036854775808.0, 9223372036854775808.0);
|
|
18315
|
+
}
|
|
18316
|
+
|
|
18317
|
+
template <>
|
|
18318
|
+
bool TryCastWithOverflowCheck(float input, float &result) {
|
|
18319
|
+
result = input;
|
|
18320
|
+
return true;
|
|
18321
|
+
}
|
|
18322
|
+
template <>
|
|
18323
|
+
bool TryCastWithOverflowCheck(float input, double &result) {
|
|
18324
|
+
result = double(input);
|
|
18325
|
+
return true;
|
|
18326
|
+
}
|
|
18327
|
+
template <>
|
|
18328
|
+
bool TryCastWithOverflowCheck(double input, double &result) {
|
|
18329
|
+
result = input;
|
|
18309
18330
|
return true;
|
|
18310
18331
|
}
|
|
18311
18332
|
|
|
18312
18333
|
template <>
|
|
18313
18334
|
bool TryCastWithOverflowCheck(double input, float &result) {
|
|
18314
|
-
if (
|
|
18315
|
-
|
|
18335
|
+
if (!Value::IsFinite(input)) {
|
|
18336
|
+
result = float(input);
|
|
18337
|
+
return true;
|
|
18316
18338
|
}
|
|
18317
|
-
auto res = (
|
|
18318
|
-
if (
|
|
18339
|
+
auto res = float(input);
|
|
18340
|
+
if (!Value::FloatIsFinite(input)) {
|
|
18319
18341
|
return false;
|
|
18320
18342
|
}
|
|
18321
18343
|
result = res;
|
|
@@ -22956,19 +22978,6 @@ bool TryCast::Operation(string_t input, uint64_t &result, bool strict) {
|
|
|
22956
22978
|
return TryIntegerCast<uint64_t, false>(input.GetDataUnsafe(), input.GetSize(), result, strict);
|
|
22957
22979
|
}
|
|
22958
22980
|
|
|
22959
|
-
template <class T>
|
|
22960
|
-
bool CheckDoubleValidity(T value);
|
|
22961
|
-
|
|
22962
|
-
template <>
|
|
22963
|
-
bool CheckDoubleValidity(float value) {
|
|
22964
|
-
return Value::FloatIsValid(value);
|
|
22965
|
-
}
|
|
22966
|
-
|
|
22967
|
-
template <>
|
|
22968
|
-
bool CheckDoubleValidity(double value) {
|
|
22969
|
-
return Value::DoubleIsValid(value);
|
|
22970
|
-
}
|
|
22971
|
-
|
|
22972
22981
|
template <class T>
|
|
22973
22982
|
static bool TryDoubleCast(const char *buf, idx_t len, T &result, bool strict) {
|
|
22974
22983
|
// skip any spaces at the start
|
|
@@ -22985,9 +22994,6 @@ static bool TryDoubleCast(const char *buf, idx_t len, T &result, bool strict) {
|
|
|
22985
22994
|
}
|
|
22986
22995
|
auto endptr = buf + len;
|
|
22987
22996
|
auto parse_result = duckdb_fast_float::from_chars(buf, buf + len, result);
|
|
22988
|
-
if (!CheckDoubleValidity<T>(result)) {
|
|
22989
|
-
return false;
|
|
22990
|
-
}
|
|
22991
22997
|
if (parse_result.ec != std::errc()) {
|
|
22992
22998
|
return false;
|
|
22993
22999
|
}
|
|
@@ -24679,6 +24685,8 @@ void ProgressBar::Update(bool final) {
|
|
|
24679
24685
|
} // namespace duckdb
|
|
24680
24686
|
|
|
24681
24687
|
|
|
24688
|
+
|
|
24689
|
+
|
|
24682
24690
|
#include <cfloat>
|
|
24683
24691
|
#include <cstring> // strlen() on Solaris
|
|
24684
24692
|
#include <limits.h>
|
|
@@ -24707,15 +24715,17 @@ uint32_t EncodeFloat(float x) {
|
|
|
24707
24715
|
buff |= (1u << 31);
|
|
24708
24716
|
return buff;
|
|
24709
24717
|
}
|
|
24718
|
+
// nan
|
|
24719
|
+
if (Value::IsNan(x)) {
|
|
24720
|
+
return UINT_MAX;
|
|
24721
|
+
}
|
|
24710
24722
|
//! infinity
|
|
24711
24723
|
if (x > FLT_MAX) {
|
|
24712
|
-
|
|
24713
|
-
// return UINT_MAX;
|
|
24724
|
+
return UINT_MAX - 1;
|
|
24714
24725
|
}
|
|
24715
24726
|
//! -infinity
|
|
24716
24727
|
if (x < -FLT_MAX) {
|
|
24717
|
-
|
|
24718
|
-
// return 0;
|
|
24728
|
+
return 0;
|
|
24719
24729
|
}
|
|
24720
24730
|
buff = Load<uint32_t>((const_data_ptr_t)&x);
|
|
24721
24731
|
if ((buff & (1u << 31)) == 0) { //! +0 and positive numbers
|
|
@@ -24735,15 +24745,17 @@ uint64_t EncodeDouble(double x) {
|
|
|
24735
24745
|
buff += (1ull << 63);
|
|
24736
24746
|
return buff;
|
|
24737
24747
|
}
|
|
24748
|
+
// nan
|
|
24749
|
+
if (Value::IsNan(x)) {
|
|
24750
|
+
return ULLONG_MAX;
|
|
24751
|
+
}
|
|
24738
24752
|
//! infinity
|
|
24739
24753
|
if (x > DBL_MAX) {
|
|
24740
|
-
|
|
24741
|
-
// return ULLONG_MAX;
|
|
24754
|
+
return ULLONG_MAX - 1;
|
|
24742
24755
|
}
|
|
24743
24756
|
//! -infinity
|
|
24744
24757
|
if (x < -DBL_MAX) {
|
|
24745
|
-
|
|
24746
|
-
// return 0;
|
|
24758
|
+
return 0;
|
|
24747
24759
|
}
|
|
24748
24760
|
buff = Load<uint64_t>((const_data_ptr_t)&x);
|
|
24749
24761
|
if (buff < (1ull << 63)) { //! +0 and positive numbers
|
|
@@ -34687,6 +34699,7 @@ hash_t Hash(uint8_t *val, size_t size) {
|
|
|
34687
34699
|
|
|
34688
34700
|
|
|
34689
34701
|
|
|
34702
|
+
|
|
34690
34703
|
#include <cmath>
|
|
34691
34704
|
#include <limits>
|
|
34692
34705
|
|
|
@@ -35226,6 +35239,9 @@ bool Hugeint::TryConvert(float value, hugeint_t &result) {
|
|
|
35226
35239
|
|
|
35227
35240
|
template <class REAL_T>
|
|
35228
35241
|
bool ConvertFloatingToBigint(REAL_T value, hugeint_t &result) {
|
|
35242
|
+
if (!Value::IsFinite<REAL_T>(value)) {
|
|
35243
|
+
return false;
|
|
35244
|
+
}
|
|
35229
35245
|
if (value <= -170141183460469231731687303715884105728.0 || value >= 170141183460469231731687303715884105727.0) {
|
|
35230
35246
|
return false;
|
|
35231
35247
|
}
|
|
@@ -37382,8 +37398,6 @@ void ValidityMask::Slice(const ValidityMask &other, idx_t offset) {
|
|
|
37382
37398
|
}
|
|
37383
37399
|
|
|
37384
37400
|
} // namespace duckdb
|
|
37385
|
-
#include <utility>
|
|
37386
|
-
|
|
37387
37401
|
|
|
37388
37402
|
|
|
37389
37403
|
|
|
@@ -37493,6 +37507,9 @@ hugeint_t ModuloOperator::Operation(hugeint_t left, hugeint_t right);
|
|
|
37493
37507
|
|
|
37494
37508
|
|
|
37495
37509
|
|
|
37510
|
+
#include <utility>
|
|
37511
|
+
#include <cmath>
|
|
37512
|
+
|
|
37496
37513
|
namespace duckdb {
|
|
37497
37514
|
|
|
37498
37515
|
Value::Value(LogicalType type) : type_(move(type)), is_null(true) {
|
|
@@ -37507,16 +37524,10 @@ Value::Value(int64_t val) : type_(LogicalType::BIGINT), is_null(false) {
|
|
|
37507
37524
|
}
|
|
37508
37525
|
|
|
37509
37526
|
Value::Value(float val) : type_(LogicalType::FLOAT), is_null(false) {
|
|
37510
|
-
if (!Value::FloatIsValid(val)) {
|
|
37511
|
-
throw OutOfRangeException("Invalid float value %f", val);
|
|
37512
|
-
}
|
|
37513
37527
|
value_.float_ = val;
|
|
37514
37528
|
}
|
|
37515
37529
|
|
|
37516
37530
|
Value::Value(double val) : type_(LogicalType::DOUBLE), is_null(false) {
|
|
37517
|
-
if (!Value::DoubleIsValid(val)) {
|
|
37518
|
-
throw OutOfRangeException("Invalid double value %f", val);
|
|
37519
|
-
}
|
|
37520
37531
|
value_.double_ = val;
|
|
37521
37532
|
}
|
|
37522
37533
|
|
|
@@ -37790,14 +37801,34 @@ Value Value::UBIGINT(uint64_t value) {
|
|
|
37790
37801
|
return result;
|
|
37791
37802
|
}
|
|
37792
37803
|
|
|
37793
|
-
bool Value::
|
|
37804
|
+
bool Value::FloatIsFinite(float value) {
|
|
37794
37805
|
return !(std::isnan(value) || std::isinf(value));
|
|
37795
37806
|
}
|
|
37796
37807
|
|
|
37797
|
-
bool Value::
|
|
37808
|
+
bool Value::DoubleIsFinite(double value) {
|
|
37798
37809
|
return !(std::isnan(value) || std::isinf(value));
|
|
37799
37810
|
}
|
|
37800
37811
|
|
|
37812
|
+
template <>
|
|
37813
|
+
bool Value::IsNan(float input) {
|
|
37814
|
+
return std::isnan(input);
|
|
37815
|
+
}
|
|
37816
|
+
|
|
37817
|
+
template <>
|
|
37818
|
+
bool Value::IsNan(double input) {
|
|
37819
|
+
return std::isnan(input);
|
|
37820
|
+
}
|
|
37821
|
+
|
|
37822
|
+
template <>
|
|
37823
|
+
bool Value::IsFinite(float input) {
|
|
37824
|
+
return Value::FloatIsFinite(input);
|
|
37825
|
+
}
|
|
37826
|
+
|
|
37827
|
+
template <>
|
|
37828
|
+
bool Value::IsFinite(double input) {
|
|
37829
|
+
return Value::DoubleIsFinite(input);
|
|
37830
|
+
}
|
|
37831
|
+
|
|
37801
37832
|
bool Value::StringIsValid(const char *str, idx_t length) {
|
|
37802
37833
|
auto utf_type = Utf8Proc::Analyze(str, length);
|
|
37803
37834
|
return utf_type != UnicodeType::INVALID;
|
|
@@ -37850,9 +37881,6 @@ Value Value::DECIMAL(hugeint_t value, uint8_t width, uint8_t scale) {
|
|
|
37850
37881
|
}
|
|
37851
37882
|
|
|
37852
37883
|
Value Value::FLOAT(float value) {
|
|
37853
|
-
if (!Value::FloatIsValid(value)) {
|
|
37854
|
-
throw OutOfRangeException("Invalid float value %f", value);
|
|
37855
|
-
}
|
|
37856
37884
|
Value result(LogicalType::FLOAT);
|
|
37857
37885
|
result.value_.float_ = value;
|
|
37858
37886
|
result.is_null = false;
|
|
@@ -37860,9 +37888,6 @@ Value Value::FLOAT(float value) {
|
|
|
37860
37888
|
}
|
|
37861
37889
|
|
|
37862
37890
|
Value Value::DOUBLE(double value) {
|
|
37863
|
-
if (!Value::DoubleIsValid(value)) {
|
|
37864
|
-
throw OutOfRangeException("Invalid double value %f", value);
|
|
37865
|
-
}
|
|
37866
37891
|
Value result(LogicalType::DOUBLE);
|
|
37867
37892
|
result.value_.double_ = value;
|
|
37868
37893
|
result.is_null = false;
|
|
@@ -38863,6 +38888,22 @@ string Value::ToSQLString() const {
|
|
|
38863
38888
|
ret += "}";
|
|
38864
38889
|
return ret;
|
|
38865
38890
|
}
|
|
38891
|
+
case LogicalTypeId::FLOAT:
|
|
38892
|
+
if (!FloatIsFinite(FloatValue::Get(*this))) {
|
|
38893
|
+
return "'" + ToString() + "'::" + type_.ToString();
|
|
38894
|
+
}
|
|
38895
|
+
return ToString();
|
|
38896
|
+
case LogicalTypeId::DOUBLE: {
|
|
38897
|
+
double val = DoubleValue::Get(*this);
|
|
38898
|
+
if (!DoubleIsFinite(val)) {
|
|
38899
|
+
if (!Value::IsNan(val)) {
|
|
38900
|
+
// to infinity and beyond
|
|
38901
|
+
return val < 0 ? "-1e1000" : "1e1000";
|
|
38902
|
+
}
|
|
38903
|
+
return "'" + ToString() + "'::" + type_.ToString();
|
|
38904
|
+
}
|
|
38905
|
+
return ToString();
|
|
38906
|
+
}
|
|
38866
38907
|
case LogicalTypeId::LIST: {
|
|
38867
38908
|
string ret = "[";
|
|
38868
38909
|
for (size_t i = 0; i < list_value.size(); i++) {
|
|
@@ -39242,16 +39283,6 @@ bool Value::ValuesAreEqual(const Value &result_value, const Value &value) {
|
|
|
39242
39283
|
}
|
|
39243
39284
|
}
|
|
39244
39285
|
|
|
39245
|
-
template <>
|
|
39246
|
-
bool Value::IsValid(float value) {
|
|
39247
|
-
return Value::FloatIsValid(value);
|
|
39248
|
-
}
|
|
39249
|
-
|
|
39250
|
-
template <>
|
|
39251
|
-
bool Value::IsValid(double value) {
|
|
39252
|
-
return Value::DoubleIsValid(value);
|
|
39253
|
-
}
|
|
39254
|
-
|
|
39255
39286
|
} // namespace duckdb
|
|
39256
39287
|
|
|
39257
39288
|
|
|
@@ -40239,30 +40270,6 @@ void Vector::Verify(const SelectionVector &sel, idx_t count) {
|
|
|
40239
40270
|
(GetVectorType() == VectorType::CONSTANT_VECTOR || GetVectorType() == VectorType::FLAT_VECTOR)) {
|
|
40240
40271
|
D_ASSERT(!auxiliary);
|
|
40241
40272
|
}
|
|
40242
|
-
if (GetType().InternalType() == PhysicalType::DOUBLE) {
|
|
40243
|
-
// verify that there are no INF or NAN values
|
|
40244
|
-
switch (GetVectorType()) {
|
|
40245
|
-
case VectorType::CONSTANT_VECTOR: {
|
|
40246
|
-
auto dbl = ConstantVector::GetData<double>(*this);
|
|
40247
|
-
if (!ConstantVector::IsNull(*this)) {
|
|
40248
|
-
D_ASSERT(Value::DoubleIsValid(*dbl));
|
|
40249
|
-
}
|
|
40250
|
-
break;
|
|
40251
|
-
}
|
|
40252
|
-
case VectorType::FLAT_VECTOR: {
|
|
40253
|
-
auto doubles = FlatVector::GetData<double>(*this);
|
|
40254
|
-
for (idx_t i = 0; i < count; i++) {
|
|
40255
|
-
auto oidx = sel.get_index(i);
|
|
40256
|
-
if (validity.RowIsValid(oidx)) {
|
|
40257
|
-
D_ASSERT(Value::DoubleIsValid(doubles[oidx]));
|
|
40258
|
-
}
|
|
40259
|
-
}
|
|
40260
|
-
break;
|
|
40261
|
-
}
|
|
40262
|
-
default:
|
|
40263
|
-
break;
|
|
40264
|
-
}
|
|
40265
|
-
}
|
|
40266
40273
|
if (GetType().id() == LogicalTypeId::VARCHAR || GetType().id() == LogicalTypeId::JSON) {
|
|
40267
40274
|
// verify that there are no '\0' bytes in string values
|
|
40268
40275
|
switch (GetVectorType()) {
|
|
@@ -41763,11 +41770,23 @@ void LogicalType::Verify() const {
|
|
|
41763
41770
|
}
|
|
41764
41771
|
|
|
41765
41772
|
bool ApproxEqual(float ldecimal, float rdecimal) {
|
|
41773
|
+
if (Value::IsNan(ldecimal) && Value::IsNan(rdecimal)) {
|
|
41774
|
+
return true;
|
|
41775
|
+
}
|
|
41776
|
+
if (!Value::FloatIsFinite(ldecimal) || !Value::FloatIsFinite(rdecimal)) {
|
|
41777
|
+
return ldecimal == rdecimal;
|
|
41778
|
+
}
|
|
41766
41779
|
float epsilon = std::fabs(rdecimal) * 0.01;
|
|
41767
41780
|
return std::fabs(ldecimal - rdecimal) <= epsilon;
|
|
41768
41781
|
}
|
|
41769
41782
|
|
|
41770
41783
|
bool ApproxEqual(double ldecimal, double rdecimal) {
|
|
41784
|
+
if (Value::IsNan(ldecimal) && Value::IsNan(rdecimal)) {
|
|
41785
|
+
return true;
|
|
41786
|
+
}
|
|
41787
|
+
if (!Value::DoubleIsFinite(ldecimal) || !Value::DoubleIsFinite(rdecimal)) {
|
|
41788
|
+
return ldecimal == rdecimal;
|
|
41789
|
+
}
|
|
41771
41790
|
double epsilon = std::fabs(rdecimal) * 0.01;
|
|
41772
41791
|
return std::fabs(ldecimal - rdecimal) <= epsilon;
|
|
41773
41792
|
}
|
|
@@ -42847,8 +42866,101 @@ void VectorOperations::Not(Vector &input, Vector &result, idx_t count) {
|
|
|
42847
42866
|
|
|
42848
42867
|
|
|
42849
42868
|
|
|
42869
|
+
//===----------------------------------------------------------------------===//
|
|
42870
|
+
// DuckDB
|
|
42871
|
+
//
|
|
42872
|
+
// duckdb/common/likely.hpp
|
|
42873
|
+
//
|
|
42874
|
+
//
|
|
42875
|
+
//===----------------------------------------------------------------------===//
|
|
42876
|
+
|
|
42877
|
+
|
|
42878
|
+
|
|
42879
|
+
#if __GNUC__
|
|
42880
|
+
#define DUCKDB_BUILTIN_EXPECT(cond, expected_value) (__builtin_expect(cond, expected_value))
|
|
42881
|
+
#else
|
|
42882
|
+
#define DUCKDB_BUILTIN_EXPECT(cond, expected_value) (cond)
|
|
42883
|
+
#endif
|
|
42884
|
+
|
|
42885
|
+
#define DUCKDB_LIKELY(...) DUCKDB_BUILTIN_EXPECT((__VA_ARGS__), 1)
|
|
42886
|
+
#define DUCKDB_UNLIKELY(...) DUCKDB_BUILTIN_EXPECT((__VA_ARGS__), 0)
|
|
42887
|
+
|
|
42888
|
+
|
|
42850
42889
|
namespace duckdb {
|
|
42851
42890
|
|
|
42891
|
+
template <class T>
|
|
42892
|
+
bool EqualsFloat(T left, T right) {
|
|
42893
|
+
if (DUCKDB_UNLIKELY(Value::IsNan(left) && Value::IsNan(right))) {
|
|
42894
|
+
return true;
|
|
42895
|
+
}
|
|
42896
|
+
return left == right;
|
|
42897
|
+
}
|
|
42898
|
+
|
|
42899
|
+
template <>
|
|
42900
|
+
bool Equals::Operation(float left, float right) {
|
|
42901
|
+
return EqualsFloat<float>(left, right);
|
|
42902
|
+
}
|
|
42903
|
+
|
|
42904
|
+
template <>
|
|
42905
|
+
bool Equals::Operation(double left, double right) {
|
|
42906
|
+
return EqualsFloat<double>(left, right);
|
|
42907
|
+
}
|
|
42908
|
+
|
|
42909
|
+
template <class T>
|
|
42910
|
+
bool GreaterThanFloat(T left, T right) {
|
|
42911
|
+
// handle nans
|
|
42912
|
+
// nan is always bigger than everything else
|
|
42913
|
+
bool left_is_nan = Value::IsNan(left);
|
|
42914
|
+
bool right_is_nan = Value::IsNan(right);
|
|
42915
|
+
// if right is nan, there is no number that is bigger than right
|
|
42916
|
+
if (DUCKDB_UNLIKELY(right_is_nan)) {
|
|
42917
|
+
return false;
|
|
42918
|
+
}
|
|
42919
|
+
// if left is nan, but right is not, left is always bigger
|
|
42920
|
+
if (DUCKDB_UNLIKELY(left_is_nan)) {
|
|
42921
|
+
return true;
|
|
42922
|
+
}
|
|
42923
|
+
return left > right;
|
|
42924
|
+
}
|
|
42925
|
+
|
|
42926
|
+
template <>
|
|
42927
|
+
bool GreaterThan::Operation(float left, float right) {
|
|
42928
|
+
return GreaterThanFloat<float>(left, right);
|
|
42929
|
+
}
|
|
42930
|
+
|
|
42931
|
+
template <>
|
|
42932
|
+
bool GreaterThan::Operation(double left, double right) {
|
|
42933
|
+
return GreaterThanFloat<double>(left, right);
|
|
42934
|
+
}
|
|
42935
|
+
|
|
42936
|
+
template <class T>
|
|
42937
|
+
bool GreaterThanEqualsFloat(T left, T right) {
|
|
42938
|
+
// handle nans
|
|
42939
|
+
// nan is always bigger than everything else
|
|
42940
|
+
bool left_is_nan = Value::IsNan(left);
|
|
42941
|
+
bool right_is_nan = Value::IsNan(right);
|
|
42942
|
+
// if right is nan, there is no bigger number
|
|
42943
|
+
// we only return true if left is also nan (in which case the numbers are equal)
|
|
42944
|
+
if (DUCKDB_UNLIKELY(right_is_nan)) {
|
|
42945
|
+
return left_is_nan;
|
|
42946
|
+
}
|
|
42947
|
+
// if left is nan, but right is not, left is always bigger
|
|
42948
|
+
if (DUCKDB_UNLIKELY(left_is_nan)) {
|
|
42949
|
+
return true;
|
|
42950
|
+
}
|
|
42951
|
+
return left >= right;
|
|
42952
|
+
}
|
|
42953
|
+
|
|
42954
|
+
template <>
|
|
42955
|
+
bool GreaterThanEquals::Operation(float left, float right) {
|
|
42956
|
+
return GreaterThanEqualsFloat<float>(left, right);
|
|
42957
|
+
}
|
|
42958
|
+
|
|
42959
|
+
template <>
|
|
42960
|
+
bool GreaterThanEquals::Operation(double left, double right) {
|
|
42961
|
+
return GreaterThanEqualsFloat<double>(left, right);
|
|
42962
|
+
}
|
|
42963
|
+
|
|
42852
42964
|
struct ComparisonSelector {
|
|
42853
42965
|
template <typename OP>
|
|
42854
42966
|
static idx_t Select(Vector &left, Vector &right, const SelectionVector *sel, idx_t count, SelectionVector *true_sel,
|
|
@@ -44696,24 +44808,6 @@ static bool DecimalCastSwitch(Vector &source, Vector &result, idx_t count, strin
|
|
|
44696
44808
|
} // namespace duckdb
|
|
44697
44809
|
|
|
44698
44810
|
|
|
44699
|
-
//===----------------------------------------------------------------------===//
|
|
44700
|
-
// DuckDB
|
|
44701
|
-
//
|
|
44702
|
-
// duckdb/common/likely.hpp
|
|
44703
|
-
//
|
|
44704
|
-
//
|
|
44705
|
-
//===----------------------------------------------------------------------===//
|
|
44706
|
-
|
|
44707
|
-
|
|
44708
|
-
|
|
44709
|
-
#if __GNUC__
|
|
44710
|
-
#define DUCKDB_BUILTIN_EXPECT(cond, expected_value) (__builtin_expect(cond, expected_value))
|
|
44711
|
-
#else
|
|
44712
|
-
#define DUCKDB_BUILTIN_EXPECT(cond, expected_value) (cond)
|
|
44713
|
-
#endif
|
|
44714
|
-
|
|
44715
|
-
#define DUCKDB_LIKELY(...) DUCKDB_BUILTIN_EXPECT((__VA_ARGS__), 1)
|
|
44716
|
-
#define DUCKDB_UNLIKELY(...) DUCKDB_BUILTIN_EXPECT((__VA_ARGS__), 0)
|
|
44717
44811
|
|
|
44718
44812
|
|
|
44719
44813
|
namespace duckdb {
|
|
@@ -72380,7 +72474,7 @@ struct NumericAverageOperation : public BaseSumOperation<AverageSetOperation, Re
|
|
|
72380
72474
|
if (state->count == 0) {
|
|
72381
72475
|
mask.SetInvalid(idx);
|
|
72382
72476
|
} else {
|
|
72383
|
-
if (!Value::
|
|
72477
|
+
if (!Value::DoubleIsFinite(state->value)) {
|
|
72384
72478
|
throw OutOfRangeException("AVG is out of range!");
|
|
72385
72479
|
}
|
|
72386
72480
|
target[idx] = (state->value / state->count);
|
|
@@ -72394,7 +72488,7 @@ struct KahanAverageOperation : public BaseSumOperation<AverageSetOperation, Kaha
|
|
|
72394
72488
|
if (state->count == 0) {
|
|
72395
72489
|
mask.SetInvalid(idx);
|
|
72396
72490
|
} else {
|
|
72397
|
-
if (!Value::
|
|
72491
|
+
if (!Value::DoubleIsFinite(state->value)) {
|
|
72398
72492
|
throw OutOfRangeException("AVG is out of range!");
|
|
72399
72493
|
}
|
|
72400
72494
|
target[idx] = (state->value / state->count) + (state->err / state->count);
|
|
@@ -72638,7 +72732,7 @@ struct VarSampOperation : public STDDevBaseOperation {
|
|
|
72638
72732
|
mask.SetInvalid(idx);
|
|
72639
72733
|
} else {
|
|
72640
72734
|
target[idx] = state->dsquared / (state->count - 1);
|
|
72641
|
-
if (!Value::
|
|
72735
|
+
if (!Value::DoubleIsFinite(target[idx])) {
|
|
72642
72736
|
throw OutOfRangeException("VARSAMP is out of range!");
|
|
72643
72737
|
}
|
|
72644
72738
|
}
|
|
@@ -72652,7 +72746,7 @@ struct VarPopOperation : public STDDevBaseOperation {
|
|
|
72652
72746
|
mask.SetInvalid(idx);
|
|
72653
72747
|
} else {
|
|
72654
72748
|
target[idx] = state->count > 1 ? (state->dsquared / state->count) : 0;
|
|
72655
|
-
if (!Value::
|
|
72749
|
+
if (!Value::DoubleIsFinite(target[idx])) {
|
|
72656
72750
|
throw OutOfRangeException("VARPOP is out of range!");
|
|
72657
72751
|
}
|
|
72658
72752
|
}
|
|
@@ -72666,7 +72760,7 @@ struct STDDevSampOperation : public STDDevBaseOperation {
|
|
|
72666
72760
|
mask.SetInvalid(idx);
|
|
72667
72761
|
} else {
|
|
72668
72762
|
target[idx] = sqrt(state->dsquared / (state->count - 1));
|
|
72669
|
-
if (!Value::
|
|
72763
|
+
if (!Value::DoubleIsFinite(target[idx])) {
|
|
72670
72764
|
throw OutOfRangeException("STDDEV_SAMP is out of range!");
|
|
72671
72765
|
}
|
|
72672
72766
|
}
|
|
@@ -72680,7 +72774,7 @@ struct STDDevPopOperation : public STDDevBaseOperation {
|
|
|
72680
72774
|
mask.SetInvalid(idx);
|
|
72681
72775
|
} else {
|
|
72682
72776
|
target[idx] = state->count > 1 ? sqrt(state->dsquared / state->count) : 0;
|
|
72683
|
-
if (!Value::
|
|
72777
|
+
if (!Value::DoubleIsFinite(target[idx])) {
|
|
72684
72778
|
throw OutOfRangeException("STDDEV_POP is out of range!");
|
|
72685
72779
|
}
|
|
72686
72780
|
}
|
|
@@ -72694,7 +72788,7 @@ struct StandardErrorOfTheMeanOperation : public STDDevBaseOperation {
|
|
|
72694
72788
|
mask.SetInvalid(idx);
|
|
72695
72789
|
} else {
|
|
72696
72790
|
target[idx] = sqrt(state->dsquared / state->count) / sqrt((state->count));
|
|
72697
|
-
if (!Value::
|
|
72791
|
+
if (!Value::DoubleIsFinite(target[idx])) {
|
|
72698
72792
|
throw OutOfRangeException("SEM is out of range!");
|
|
72699
72793
|
}
|
|
72700
72794
|
}
|
|
@@ -72758,12 +72852,12 @@ struct CorrOperation {
|
|
|
72758
72852
|
} else {
|
|
72759
72853
|
auto cov = state->cov_pop.co_moment / state->cov_pop.count;
|
|
72760
72854
|
auto std_x = state->dev_pop_x.count > 1 ? sqrt(state->dev_pop_x.dsquared / state->dev_pop_x.count) : 0;
|
|
72761
|
-
if (!Value::
|
|
72762
|
-
throw OutOfRangeException("STDDEV_POP for X is
|
|
72855
|
+
if (!Value::DoubleIsFinite(std_x)) {
|
|
72856
|
+
throw OutOfRangeException("STDDEV_POP for X is out of range!");
|
|
72763
72857
|
}
|
|
72764
72858
|
auto std_y = state->dev_pop_y.count > 1 ? sqrt(state->dev_pop_y.dsquared / state->dev_pop_y.count) : 0;
|
|
72765
|
-
if (!Value::
|
|
72766
|
-
throw OutOfRangeException("STDDEV_POP for Y is
|
|
72859
|
+
if (!Value::DoubleIsFinite(std_y)) {
|
|
72860
|
+
throw OutOfRangeException("STDDEV_POP for Y is out of range!");
|
|
72767
72861
|
}
|
|
72768
72862
|
if (std_x * std_y == 0) {
|
|
72769
72863
|
mask.SetInvalid(idx);
|
|
@@ -74327,8 +74421,8 @@ struct KurtosisOperation {
|
|
|
74327
74421
|
mask.SetInvalid(idx);
|
|
74328
74422
|
} // LCOV_EXCL_STOP
|
|
74329
74423
|
target[idx] = (n - 1) * ((n + 1) * m4 / (m2 * m2) - 3 * (n - 1)) / ((n - 2) * (n - 3));
|
|
74330
|
-
if (!Value::
|
|
74331
|
-
|
|
74424
|
+
if (!Value::DoubleIsFinite(target[idx])) {
|
|
74425
|
+
throw OutOfRangeException("Kurtosis is out of range!");
|
|
74332
74426
|
}
|
|
74333
74427
|
}
|
|
74334
74428
|
|
|
@@ -75041,8 +75135,8 @@ struct SkewnessOperation {
|
|
|
75041
75135
|
target[idx] = temp1 * temp *
|
|
75042
75136
|
(state->sum_cub - 3 * state->sum_sqr * state->sum * temp + 2 * pow(state->sum, 3) * temp * temp) /
|
|
75043
75137
|
div;
|
|
75044
|
-
if (!Value::
|
|
75045
|
-
|
|
75138
|
+
if (!Value::DoubleIsFinite(target[idx])) {
|
|
75139
|
+
throw OutOfRangeException("SKEW is out of range!");
|
|
75046
75140
|
}
|
|
75047
75141
|
}
|
|
75048
75142
|
|
|
@@ -75251,7 +75345,7 @@ struct DoubleSumOperation : public BaseSumOperation<SumSetOperation, ADD_OPERATO
|
|
|
75251
75345
|
if (!state->isset) {
|
|
75252
75346
|
mask.SetInvalid(idx);
|
|
75253
75347
|
} else {
|
|
75254
|
-
if (!Value::
|
|
75348
|
+
if (!Value::DoubleIsFinite(state->value)) {
|
|
75255
75349
|
throw OutOfRangeException("SUM is out of range!");
|
|
75256
75350
|
}
|
|
75257
75351
|
target[idx] = state->value;
|
|
@@ -78931,7 +79025,7 @@ struct RegrSlopeOperation {
|
|
|
78931
79025
|
} else {
|
|
78932
79026
|
auto cov = state->cov_pop.co_moment / state->cov_pop.count;
|
|
78933
79027
|
auto var_pop = state->var_pop.count > 1 ? (state->var_pop.dsquared / state->var_pop.count) : 0;
|
|
78934
|
-
if (!Value::
|
|
79028
|
+
if (!Value::DoubleIsFinite(var_pop)) {
|
|
78935
79029
|
throw OutOfRangeException("VARPOP is out of range!");
|
|
78936
79030
|
}
|
|
78937
79031
|
if (var_pop == 0) {
|
|
@@ -79056,7 +79150,7 @@ struct RegrR2Operation {
|
|
|
79056
79150
|
template <class T, class STATE>
|
|
79057
79151
|
static void Finalize(Vector &result, FunctionData *fd, STATE *state, T *target, ValidityMask &mask, idx_t idx) {
|
|
79058
79152
|
auto var_pop_x = state->var_pop_x.count > 1 ? (state->var_pop_x.dsquared / state->var_pop_x.count) : 0;
|
|
79059
|
-
if (!Value::
|
|
79153
|
+
if (!Value::DoubleIsFinite(var_pop_x)) {
|
|
79060
79154
|
throw OutOfRangeException("VARPOP(X) is out of range!");
|
|
79061
79155
|
}
|
|
79062
79156
|
if (var_pop_x == 0) {
|
|
@@ -79064,7 +79158,7 @@ struct RegrR2Operation {
|
|
|
79064
79158
|
return;
|
|
79065
79159
|
}
|
|
79066
79160
|
auto var_pop_y = state->var_pop_y.count > 1 ? (state->var_pop_y.dsquared / state->var_pop_y.count) : 0;
|
|
79067
|
-
if (!Value::
|
|
79161
|
+
if (!Value::DoubleIsFinite(var_pop_y)) {
|
|
79068
79162
|
throw OutOfRangeException("VARPOP(Y) is out of range!");
|
|
79069
79163
|
}
|
|
79070
79164
|
if (var_pop_y == 0) {
|
|
@@ -79145,7 +79239,7 @@ struct RegrBaseOperation {
|
|
|
79145
79239
|
return;
|
|
79146
79240
|
}
|
|
79147
79241
|
auto var_pop = state->var_pop.count > 1 ? (state->var_pop.dsquared / state->var_pop.count) : 0;
|
|
79148
|
-
if (!Value::
|
|
79242
|
+
if (!Value::DoubleIsFinite(var_pop)) {
|
|
79149
79243
|
throw OutOfRangeException("VARPOP is out of range!");
|
|
79150
79244
|
}
|
|
79151
79245
|
RegrCountFunction::Finalize<T, size_t>(result, fd, &state->count, target, mask, idx);
|
|
@@ -84693,12 +84787,13 @@ struct StrfTimeBindData : public FunctionData {
|
|
|
84693
84787
|
}
|
|
84694
84788
|
};
|
|
84695
84789
|
|
|
84790
|
+
template <bool REVERSED>
|
|
84696
84791
|
static unique_ptr<FunctionData> StrfTimeBindFunction(ClientContext &context, ScalarFunction &bound_function,
|
|
84697
84792
|
vector<unique_ptr<Expression>> &arguments) {
|
|
84698
84793
|
if (!arguments[1]->IsFoldable()) {
|
|
84699
84794
|
throw InvalidInputException("strftime format must be a constant");
|
|
84700
84795
|
}
|
|
84701
|
-
Value options_str = ExpressionExecutor::EvaluateScalar(*arguments[1]);
|
|
84796
|
+
Value options_str = ExpressionExecutor::EvaluateScalar(*arguments[REVERSED ? 0 : 1]);
|
|
84702
84797
|
StrfTimeFormat format;
|
|
84703
84798
|
if (!options_str.IsNull() && options_str.type().id() == LogicalTypeId::VARCHAR) {
|
|
84704
84799
|
auto format_string = options_str.GetValue<string>();
|
|
@@ -84710,16 +84805,17 @@ static unique_ptr<FunctionData> StrfTimeBindFunction(ClientContext &context, Sca
|
|
|
84710
84805
|
return make_unique<StrfTimeBindData>(format);
|
|
84711
84806
|
}
|
|
84712
84807
|
|
|
84808
|
+
template <bool REVERSED>
|
|
84713
84809
|
static void StrfTimeFunctionDate(DataChunk &args, ExpressionState &state, Vector &result) {
|
|
84714
84810
|
auto &func_expr = (BoundFunctionExpression &)state.expr;
|
|
84715
84811
|
auto &info = (StrfTimeBindData &)*func_expr.bind_info;
|
|
84716
84812
|
|
|
84717
|
-
if (ConstantVector::IsNull(args.data[1])) {
|
|
84813
|
+
if (ConstantVector::IsNull(args.data[REVERSED ? 0 : 1])) {
|
|
84718
84814
|
result.SetVectorType(VectorType::CONSTANT_VECTOR);
|
|
84719
84815
|
ConstantVector::SetNull(result, true);
|
|
84720
84816
|
return;
|
|
84721
84817
|
}
|
|
84722
|
-
UnaryExecutor::Execute<date_t, string_t>(args.data[0], result, args.size(), [&](date_t input) {
|
|
84818
|
+
UnaryExecutor::Execute<date_t, string_t>(args.data[REVERSED ? 1 : 0], result, args.size(), [&](date_t input) {
|
|
84723
84819
|
dtime_t time(0);
|
|
84724
84820
|
idx_t len = info.format.GetLength(input, time);
|
|
84725
84821
|
string_t target = StringVector::EmptyString(result, len);
|
|
@@ -84729,36 +84825,44 @@ static void StrfTimeFunctionDate(DataChunk &args, ExpressionState &state, Vector
|
|
|
84729
84825
|
});
|
|
84730
84826
|
}
|
|
84731
84827
|
|
|
84828
|
+
template <bool REVERSED>
|
|
84732
84829
|
static void StrfTimeFunctionTimestamp(DataChunk &args, ExpressionState &state, Vector &result) {
|
|
84733
84830
|
auto &func_expr = (BoundFunctionExpression &)state.expr;
|
|
84734
84831
|
auto &info = (StrfTimeBindData &)*func_expr.bind_info;
|
|
84735
84832
|
|
|
84736
|
-
if (ConstantVector::IsNull(args.data[1])) {
|
|
84833
|
+
if (ConstantVector::IsNull(args.data[REVERSED ? 0 : 1])) {
|
|
84737
84834
|
result.SetVectorType(VectorType::CONSTANT_VECTOR);
|
|
84738
84835
|
ConstantVector::SetNull(result, true);
|
|
84739
84836
|
return;
|
|
84740
84837
|
}
|
|
84741
84838
|
|
|
84742
|
-
UnaryExecutor::Execute<timestamp_t, string_t>(args.data[0], result, args.size(),
|
|
84743
|
-
|
|
84744
|
-
|
|
84745
|
-
|
|
84746
|
-
|
|
84747
|
-
|
|
84748
|
-
|
|
84749
|
-
|
|
84750
|
-
|
|
84751
|
-
|
|
84839
|
+
UnaryExecutor::Execute<timestamp_t, string_t>(args.data[REVERSED ? 1 : 0], result, args.size(),
|
|
84840
|
+
[&](timestamp_t input) {
|
|
84841
|
+
date_t date;
|
|
84842
|
+
dtime_t time;
|
|
84843
|
+
Timestamp::Convert(input, date, time);
|
|
84844
|
+
idx_t len = info.format.GetLength(date, time);
|
|
84845
|
+
string_t target = StringVector::EmptyString(result, len);
|
|
84846
|
+
info.format.FormatString(date, time, target.GetDataWriteable());
|
|
84847
|
+
target.Finalize();
|
|
84848
|
+
return target;
|
|
84849
|
+
});
|
|
84752
84850
|
}
|
|
84753
84851
|
|
|
84754
84852
|
void StrfTimeFun::RegisterFunction(BuiltinFunctions &set) {
|
|
84755
84853
|
ScalarFunctionSet strftime("strftime");
|
|
84756
84854
|
|
|
84757
84855
|
strftime.AddFunction(ScalarFunction({LogicalType::DATE, LogicalType::VARCHAR}, LogicalType::VARCHAR,
|
|
84758
|
-
StrfTimeFunctionDate
|
|
84856
|
+
StrfTimeFunctionDate<false>, false, StrfTimeBindFunction<false>));
|
|
84759
84857
|
|
|
84760
84858
|
strftime.AddFunction(ScalarFunction({LogicalType::TIMESTAMP, LogicalType::VARCHAR}, LogicalType::VARCHAR,
|
|
84761
|
-
StrfTimeFunctionTimestamp
|
|
84859
|
+
StrfTimeFunctionTimestamp<false>, false, StrfTimeBindFunction<false>));
|
|
84860
|
+
|
|
84861
|
+
strftime.AddFunction(ScalarFunction({LogicalType::VARCHAR, LogicalType::DATE}, LogicalType::VARCHAR,
|
|
84862
|
+
StrfTimeFunctionDate<true>, false, StrfTimeBindFunction<true>));
|
|
84863
|
+
|
|
84864
|
+
strftime.AddFunction(ScalarFunction({LogicalType::VARCHAR, LogicalType::TIMESTAMP}, LogicalType::VARCHAR,
|
|
84865
|
+
StrfTimeFunctionTimestamp<true>, false, StrfTimeBindFunction<true>));
|
|
84762
84866
|
|
|
84763
84867
|
set.AddFunction(strftime);
|
|
84764
84868
|
}
|
|
@@ -87750,6 +87854,18 @@ struct EvenFun {
|
|
|
87750
87854
|
static void RegisterFunction(BuiltinFunctions &set);
|
|
87751
87855
|
};
|
|
87752
87856
|
|
|
87857
|
+
struct IsNanFun {
|
|
87858
|
+
static void RegisterFunction(BuiltinFunctions &set);
|
|
87859
|
+
};
|
|
87860
|
+
|
|
87861
|
+
struct IsInfiniteFun {
|
|
87862
|
+
static void RegisterFunction(BuiltinFunctions &set);
|
|
87863
|
+
};
|
|
87864
|
+
|
|
87865
|
+
struct IsFiniteFun {
|
|
87866
|
+
static void RegisterFunction(BuiltinFunctions &set);
|
|
87867
|
+
};
|
|
87868
|
+
|
|
87753
87869
|
} // namespace duckdb
|
|
87754
87870
|
|
|
87755
87871
|
|
|
@@ -87808,6 +87924,7 @@ struct Atan2Fun {
|
|
|
87808
87924
|
|
|
87809
87925
|
|
|
87810
87926
|
|
|
87927
|
+
|
|
87811
87928
|
#include <cmath>
|
|
87812
87929
|
#include <errno.h>
|
|
87813
87930
|
|
|
@@ -87838,51 +87955,6 @@ static scalar_function_t GetScalarIntegerUnaryFunctionFixedReturn(const LogicalT
|
|
|
87838
87955
|
return function;
|
|
87839
87956
|
}
|
|
87840
87957
|
|
|
87841
|
-
template <class OP>
|
|
87842
|
-
struct UnaryDoubleWrapper {
|
|
87843
|
-
template <class INPUT_TYPE, class RESULT_TYPE>
|
|
87844
|
-
static RESULT_TYPE Operation(INPUT_TYPE input, ValidityMask &mask, idx_t idx, void *dataptr) {
|
|
87845
|
-
RESULT_TYPE result = OP::template Operation<INPUT_TYPE, RESULT_TYPE>(input);
|
|
87846
|
-
if (std::isnan(result) || std::isinf(result) || errno != 0) {
|
|
87847
|
-
errno = 0;
|
|
87848
|
-
mask.SetInvalid(idx);
|
|
87849
|
-
return 0;
|
|
87850
|
-
}
|
|
87851
|
-
return result;
|
|
87852
|
-
}
|
|
87853
|
-
};
|
|
87854
|
-
|
|
87855
|
-
template <class T, class OP>
|
|
87856
|
-
static void UnaryDoubleFunctionWrapper(DataChunk &input, ExpressionState &state, Vector &result) {
|
|
87857
|
-
D_ASSERT(input.ColumnCount() >= 1);
|
|
87858
|
-
errno = 0;
|
|
87859
|
-
UnaryExecutor::GenericExecute<T, T, UnaryDoubleWrapper<OP>>(input.data[0], result, input.size(), nullptr, true);
|
|
87860
|
-
}
|
|
87861
|
-
|
|
87862
|
-
struct BinaryDoubleWrapper {
|
|
87863
|
-
template <class FUNC, class OP, class TA, class TB, class TR>
|
|
87864
|
-
static inline TR Operation(FUNC fun, TA left, TB right, ValidityMask &mask, idx_t idx) {
|
|
87865
|
-
TR result = OP::template Operation<TA, TB, TR>(left, right);
|
|
87866
|
-
if (std::isnan(result) || std::isinf(result) || errno != 0) {
|
|
87867
|
-
errno = 0;
|
|
87868
|
-
mask.SetInvalid(idx);
|
|
87869
|
-
return 0;
|
|
87870
|
-
}
|
|
87871
|
-
return result;
|
|
87872
|
-
}
|
|
87873
|
-
|
|
87874
|
-
static bool AddsNulls() {
|
|
87875
|
-
return true;
|
|
87876
|
-
}
|
|
87877
|
-
};
|
|
87878
|
-
|
|
87879
|
-
template <class T, class OP>
|
|
87880
|
-
static void BinaryDoubleFunctionWrapper(DataChunk &input, ExpressionState &state, Vector &result) {
|
|
87881
|
-
D_ASSERT(input.ColumnCount() >= 2);
|
|
87882
|
-
errno = 0;
|
|
87883
|
-
BinaryExecutor::Execute<T, T, T, OP, BinaryDoubleWrapper>(input.data[0], input.data[1], result, input.size());
|
|
87884
|
-
}
|
|
87885
|
-
|
|
87886
87958
|
//===--------------------------------------------------------------------===//
|
|
87887
87959
|
// nextafter
|
|
87888
87960
|
//===--------------------------------------------------------------------===//
|
|
@@ -87903,23 +87975,14 @@ struct NextAfterOperator {
|
|
|
87903
87975
|
}
|
|
87904
87976
|
};
|
|
87905
87977
|
|
|
87906
|
-
unique_ptr<FunctionData> BindNextAfter(ClientContext &context, ScalarFunction &function,
|
|
87907
|
-
vector<unique_ptr<Expression>> &arguments) {
|
|
87908
|
-
if ((arguments[0]->return_type != arguments[1]->return_type) ||
|
|
87909
|
-
(arguments[0]->return_type != LogicalType::FLOAT && arguments[0]->return_type != LogicalType::DOUBLE)) {
|
|
87910
|
-
throw NotImplementedException("Unimplemented type for NextAfter Function");
|
|
87911
|
-
}
|
|
87912
|
-
return nullptr;
|
|
87913
|
-
}
|
|
87914
|
-
|
|
87915
87978
|
void NextAfterFun::RegisterFunction(BuiltinFunctions &set) {
|
|
87916
87979
|
ScalarFunctionSet next_after_fun("nextafter");
|
|
87917
87980
|
next_after_fun.AddFunction(
|
|
87918
87981
|
ScalarFunction("nextafter", {LogicalType::DOUBLE, LogicalType::DOUBLE}, LogicalType::DOUBLE,
|
|
87919
|
-
|
|
87982
|
+
ScalarFunction::BinaryFunction<double, double, double, NextAfterOperator>, false));
|
|
87920
87983
|
next_after_fun.AddFunction(ScalarFunction("nextafter", {LogicalType::FLOAT, LogicalType::FLOAT}, LogicalType::FLOAT,
|
|
87921
|
-
|
|
87922
|
-
|
|
87984
|
+
ScalarFunction::BinaryFunction<float, float, float, NextAfterOperator>,
|
|
87985
|
+
false));
|
|
87923
87986
|
set.AddFunction(next_after_fun);
|
|
87924
87987
|
}
|
|
87925
87988
|
|
|
@@ -87996,10 +88059,10 @@ void BitCountFun::RegisterFunction(BuiltinFunctions &set) {
|
|
|
87996
88059
|
//===--------------------------------------------------------------------===//
|
|
87997
88060
|
struct SignOperator {
|
|
87998
88061
|
template <class TA, class TR>
|
|
87999
|
-
static
|
|
88000
|
-
if (
|
|
88062
|
+
static TR Operation(TA input) {
|
|
88063
|
+
if (input == TA(0)) {
|
|
88001
88064
|
return 0;
|
|
88002
|
-
} else if (
|
|
88065
|
+
} else if (input > TA(0)) {
|
|
88003
88066
|
return 1;
|
|
88004
88067
|
} else {
|
|
88005
88068
|
return -1;
|
|
@@ -88007,6 +88070,28 @@ struct SignOperator {
|
|
|
88007
88070
|
}
|
|
88008
88071
|
};
|
|
88009
88072
|
|
|
88073
|
+
template <>
|
|
88074
|
+
int8_t SignOperator::Operation(float input) {
|
|
88075
|
+
if (input == 0 || Value::IsNan(input)) {
|
|
88076
|
+
return 0;
|
|
88077
|
+
} else if (input > 0) {
|
|
88078
|
+
return 1;
|
|
88079
|
+
} else {
|
|
88080
|
+
return -1;
|
|
88081
|
+
}
|
|
88082
|
+
}
|
|
88083
|
+
|
|
88084
|
+
template <>
|
|
88085
|
+
int8_t SignOperator::Operation(double input) {
|
|
88086
|
+
if (input == 0 || Value::IsNan(input)) {
|
|
88087
|
+
return 0;
|
|
88088
|
+
} else if (input > 0) {
|
|
88089
|
+
return 1;
|
|
88090
|
+
} else {
|
|
88091
|
+
return -1;
|
|
88092
|
+
}
|
|
88093
|
+
}
|
|
88094
|
+
|
|
88010
88095
|
void SignFun::RegisterFunction(BuiltinFunctions &set) {
|
|
88011
88096
|
ScalarFunctionSet sign("sign");
|
|
88012
88097
|
for (auto &type : LogicalType::Numeric()) {
|
|
@@ -88386,7 +88471,7 @@ struct ExpOperator {
|
|
|
88386
88471
|
|
|
88387
88472
|
void ExpFun::RegisterFunction(BuiltinFunctions &set) {
|
|
88388
88473
|
set.AddFunction(ScalarFunction("exp", {LogicalType::DOUBLE}, LogicalType::DOUBLE,
|
|
88389
|
-
|
|
88474
|
+
ScalarFunction::UnaryFunction<double, double, ExpOperator>));
|
|
88390
88475
|
}
|
|
88391
88476
|
|
|
88392
88477
|
//===--------------------------------------------------------------------===//
|
|
@@ -88401,7 +88486,7 @@ struct PowOperator {
|
|
|
88401
88486
|
|
|
88402
88487
|
void PowFun::RegisterFunction(BuiltinFunctions &set) {
|
|
88403
88488
|
ScalarFunction power_function("pow", {LogicalType::DOUBLE, LogicalType::DOUBLE}, LogicalType::DOUBLE,
|
|
88404
|
-
|
|
88489
|
+
ScalarFunction::BinaryFunction<double, double, double, PowOperator>);
|
|
88405
88490
|
set.AddFunction(power_function);
|
|
88406
88491
|
power_function.name = "power";
|
|
88407
88492
|
set.AddFunction(power_function);
|
|
@@ -88416,14 +88501,17 @@ void PowFun::RegisterFunction(BuiltinFunctions &set) {
|
|
|
88416
88501
|
//===--------------------------------------------------------------------===//
|
|
88417
88502
|
struct SqrtOperator {
|
|
88418
88503
|
template <class TA, class TR>
|
|
88419
|
-
static inline TR Operation(TA
|
|
88420
|
-
|
|
88504
|
+
static inline TR Operation(TA input) {
|
|
88505
|
+
if (input < 0) {
|
|
88506
|
+
throw OutOfRangeException("cannot take square root of a negative number");
|
|
88507
|
+
}
|
|
88508
|
+
return std::sqrt(input);
|
|
88421
88509
|
}
|
|
88422
88510
|
};
|
|
88423
88511
|
|
|
88424
88512
|
void SqrtFun::RegisterFunction(BuiltinFunctions &set) {
|
|
88425
88513
|
set.AddFunction(ScalarFunction("sqrt", {LogicalType::DOUBLE}, LogicalType::DOUBLE,
|
|
88426
|
-
|
|
88514
|
+
ScalarFunction::UnaryFunction<double, double, SqrtOperator>));
|
|
88427
88515
|
}
|
|
88428
88516
|
|
|
88429
88517
|
//===--------------------------------------------------------------------===//
|
|
@@ -88438,7 +88526,7 @@ struct CbRtOperator {
|
|
|
88438
88526
|
|
|
88439
88527
|
void CbrtFun::RegisterFunction(BuiltinFunctions &set) {
|
|
88440
88528
|
set.AddFunction(ScalarFunction("cbrt", {LogicalType::DOUBLE}, LogicalType::DOUBLE,
|
|
88441
|
-
|
|
88529
|
+
ScalarFunction::UnaryFunction<double, double, CbRtOperator>));
|
|
88442
88530
|
}
|
|
88443
88531
|
|
|
88444
88532
|
//===--------------------------------------------------------------------===//
|
|
@@ -88447,14 +88535,20 @@ void CbrtFun::RegisterFunction(BuiltinFunctions &set) {
|
|
|
88447
88535
|
|
|
88448
88536
|
struct LnOperator {
|
|
88449
88537
|
template <class TA, class TR>
|
|
88450
|
-
static inline TR Operation(TA
|
|
88451
|
-
|
|
88538
|
+
static inline TR Operation(TA input) {
|
|
88539
|
+
if (input < 0) {
|
|
88540
|
+
throw OutOfRangeException("cannot take logarithm of a negative number");
|
|
88541
|
+
}
|
|
88542
|
+
if (input == 0) {
|
|
88543
|
+
throw OutOfRangeException("cannot take logarithm of zero");
|
|
88544
|
+
}
|
|
88545
|
+
return std::log(input);
|
|
88452
88546
|
}
|
|
88453
88547
|
};
|
|
88454
88548
|
|
|
88455
88549
|
void LnFun::RegisterFunction(BuiltinFunctions &set) {
|
|
88456
88550
|
set.AddFunction(ScalarFunction("ln", {LogicalType::DOUBLE}, LogicalType::DOUBLE,
|
|
88457
|
-
|
|
88551
|
+
ScalarFunction::UnaryFunction<double, double, LnOperator>));
|
|
88458
88552
|
}
|
|
88459
88553
|
|
|
88460
88554
|
//===--------------------------------------------------------------------===//
|
|
@@ -88462,14 +88556,20 @@ void LnFun::RegisterFunction(BuiltinFunctions &set) {
|
|
|
88462
88556
|
//===--------------------------------------------------------------------===//
|
|
88463
88557
|
struct Log10Operator {
|
|
88464
88558
|
template <class TA, class TR>
|
|
88465
|
-
static inline TR Operation(TA
|
|
88466
|
-
|
|
88559
|
+
static inline TR Operation(TA input) {
|
|
88560
|
+
if (input < 0) {
|
|
88561
|
+
throw OutOfRangeException("cannot take logarithm of a negative number");
|
|
88562
|
+
}
|
|
88563
|
+
if (input == 0) {
|
|
88564
|
+
throw OutOfRangeException("cannot take logarithm of zero");
|
|
88565
|
+
}
|
|
88566
|
+
return std::log10(input);
|
|
88467
88567
|
}
|
|
88468
88568
|
};
|
|
88469
88569
|
|
|
88470
88570
|
void Log10Fun::RegisterFunction(BuiltinFunctions &set) {
|
|
88471
88571
|
set.AddFunction({"log10", "log"}, ScalarFunction({LogicalType::DOUBLE}, LogicalType::DOUBLE,
|
|
88472
|
-
|
|
88572
|
+
ScalarFunction::UnaryFunction<double, double, Log10Operator>));
|
|
88473
88573
|
}
|
|
88474
88574
|
|
|
88475
88575
|
//===--------------------------------------------------------------------===//
|
|
@@ -88477,14 +88577,20 @@ void Log10Fun::RegisterFunction(BuiltinFunctions &set) {
|
|
|
88477
88577
|
//===--------------------------------------------------------------------===//
|
|
88478
88578
|
struct Log2Operator {
|
|
88479
88579
|
template <class TA, class TR>
|
|
88480
|
-
static inline TR Operation(TA
|
|
88481
|
-
|
|
88580
|
+
static inline TR Operation(TA input) {
|
|
88581
|
+
if (input < 0) {
|
|
88582
|
+
throw OutOfRangeException("cannot take logarithm of a negative number");
|
|
88583
|
+
}
|
|
88584
|
+
if (input == 0) {
|
|
88585
|
+
throw OutOfRangeException("cannot take logarithm of zero");
|
|
88586
|
+
}
|
|
88587
|
+
return std::log2(input);
|
|
88482
88588
|
}
|
|
88483
88589
|
};
|
|
88484
88590
|
|
|
88485
88591
|
void Log2Fun::RegisterFunction(BuiltinFunctions &set) {
|
|
88486
88592
|
set.AddFunction(ScalarFunction("log2", {LogicalType::DOUBLE}, LogicalType::DOUBLE,
|
|
88487
|
-
|
|
88593
|
+
ScalarFunction::UnaryFunction<double, double, Log2Operator>));
|
|
88488
88594
|
}
|
|
88489
88595
|
|
|
88490
88596
|
//===--------------------------------------------------------------------===//
|
|
@@ -88512,7 +88618,7 @@ struct DegreesOperator {
|
|
|
88512
88618
|
|
|
88513
88619
|
void DegreesFun::RegisterFunction(BuiltinFunctions &set) {
|
|
88514
88620
|
set.AddFunction(ScalarFunction("degrees", {LogicalType::DOUBLE}, LogicalType::DOUBLE,
|
|
88515
|
-
|
|
88621
|
+
ScalarFunction::UnaryFunction<double, double, DegreesOperator>));
|
|
88516
88622
|
}
|
|
88517
88623
|
|
|
88518
88624
|
//===--------------------------------------------------------------------===//
|
|
@@ -88527,12 +88633,83 @@ struct RadiansOperator {
|
|
|
88527
88633
|
|
|
88528
88634
|
void RadiansFun::RegisterFunction(BuiltinFunctions &set) {
|
|
88529
88635
|
set.AddFunction(ScalarFunction("radians", {LogicalType::DOUBLE}, LogicalType::DOUBLE,
|
|
88530
|
-
|
|
88636
|
+
ScalarFunction::UnaryFunction<double, double, RadiansOperator>));
|
|
88637
|
+
}
|
|
88638
|
+
|
|
88639
|
+
//===--------------------------------------------------------------------===//
|
|
88640
|
+
// isnan
|
|
88641
|
+
//===--------------------------------------------------------------------===//
|
|
88642
|
+
struct IsNanOperator {
|
|
88643
|
+
template <class TA, class TR>
|
|
88644
|
+
static inline TR Operation(TA input) {
|
|
88645
|
+
return Value::IsNan(input);
|
|
88646
|
+
}
|
|
88647
|
+
};
|
|
88648
|
+
|
|
88649
|
+
void IsNanFun::RegisterFunction(BuiltinFunctions &set) {
|
|
88650
|
+
ScalarFunctionSet funcs("isnan");
|
|
88651
|
+
funcs.AddFunction(ScalarFunction({LogicalType::FLOAT}, LogicalType::BOOLEAN,
|
|
88652
|
+
ScalarFunction::UnaryFunction<float, bool, IsNanOperator>));
|
|
88653
|
+
funcs.AddFunction(ScalarFunction({LogicalType::DOUBLE}, LogicalType::BOOLEAN,
|
|
88654
|
+
ScalarFunction::UnaryFunction<double, bool, IsNanOperator>));
|
|
88655
|
+
set.AddFunction(funcs);
|
|
88656
|
+
}
|
|
88657
|
+
|
|
88658
|
+
//===--------------------------------------------------------------------===//
|
|
88659
|
+
// isinf
|
|
88660
|
+
//===--------------------------------------------------------------------===//
|
|
88661
|
+
struct IsInfiniteOperator {
|
|
88662
|
+
template <class TA, class TR>
|
|
88663
|
+
static inline TR Operation(TA input) {
|
|
88664
|
+
return !Value::IsNan(input) && !Value::IsFinite(input);
|
|
88665
|
+
}
|
|
88666
|
+
};
|
|
88667
|
+
|
|
88668
|
+
void IsInfiniteFun::RegisterFunction(BuiltinFunctions &set) {
|
|
88669
|
+
ScalarFunctionSet funcs("isinf");
|
|
88670
|
+
funcs.AddFunction(ScalarFunction({LogicalType::FLOAT}, LogicalType::BOOLEAN,
|
|
88671
|
+
ScalarFunction::UnaryFunction<float, bool, IsInfiniteOperator>));
|
|
88672
|
+
funcs.AddFunction(ScalarFunction({LogicalType::DOUBLE}, LogicalType::BOOLEAN,
|
|
88673
|
+
ScalarFunction::UnaryFunction<double, bool, IsInfiniteOperator>));
|
|
88674
|
+
set.AddFunction(funcs);
|
|
88675
|
+
}
|
|
88676
|
+
|
|
88677
|
+
//===--------------------------------------------------------------------===//
|
|
88678
|
+
// isfinite
|
|
88679
|
+
//===--------------------------------------------------------------------===//
|
|
88680
|
+
struct IsFiniteOperator {
|
|
88681
|
+
template <class TA, class TR>
|
|
88682
|
+
static inline TR Operation(TA input) {
|
|
88683
|
+
return Value::IsFinite(input);
|
|
88684
|
+
}
|
|
88685
|
+
};
|
|
88686
|
+
|
|
88687
|
+
void IsFiniteFun::RegisterFunction(BuiltinFunctions &set) {
|
|
88688
|
+
ScalarFunctionSet funcs("isfinite");
|
|
88689
|
+
funcs.AddFunction(ScalarFunction({LogicalType::FLOAT}, LogicalType::BOOLEAN,
|
|
88690
|
+
ScalarFunction::UnaryFunction<float, bool, IsFiniteOperator>));
|
|
88691
|
+
funcs.AddFunction(ScalarFunction({LogicalType::DOUBLE}, LogicalType::BOOLEAN,
|
|
88692
|
+
ScalarFunction::UnaryFunction<double, bool, IsFiniteOperator>));
|
|
88693
|
+
set.AddFunction(funcs);
|
|
88531
88694
|
}
|
|
88532
88695
|
|
|
88533
88696
|
//===--------------------------------------------------------------------===//
|
|
88534
88697
|
// sin
|
|
88535
88698
|
//===--------------------------------------------------------------------===//
|
|
88699
|
+
template <class OP>
|
|
88700
|
+
struct NoInfiniteDoubleWrapper {
|
|
88701
|
+
template <class INPUT_TYPE, class RESULT_TYPE>
|
|
88702
|
+
static RESULT_TYPE Operation(INPUT_TYPE input) {
|
|
88703
|
+
if (DUCKDB_UNLIKELY(!Value::IsFinite(input))) {
|
|
88704
|
+
if (Value::IsNan(input)) {
|
|
88705
|
+
return input;
|
|
88706
|
+
}
|
|
88707
|
+
throw OutOfRangeException("input value %lf is out of range for numeric function", input);
|
|
88708
|
+
}
|
|
88709
|
+
return OP::template Operation<INPUT_TYPE, RESULT_TYPE>(input);
|
|
88710
|
+
}
|
|
88711
|
+
};
|
|
88712
|
+
|
|
88536
88713
|
struct SinOperator {
|
|
88537
88714
|
template <class TA, class TR>
|
|
88538
88715
|
static inline TR Operation(TA input) {
|
|
@@ -88541,8 +88718,9 @@ struct SinOperator {
|
|
|
88541
88718
|
};
|
|
88542
88719
|
|
|
88543
88720
|
void SinFun::RegisterFunction(BuiltinFunctions &set) {
|
|
88544
|
-
set.AddFunction(
|
|
88545
|
-
|
|
88721
|
+
set.AddFunction(
|
|
88722
|
+
ScalarFunction("sin", {LogicalType::DOUBLE}, LogicalType::DOUBLE,
|
|
88723
|
+
ScalarFunction::UnaryFunction<double, double, NoInfiniteDoubleWrapper<SinOperator>>));
|
|
88546
88724
|
}
|
|
88547
88725
|
|
|
88548
88726
|
//===--------------------------------------------------------------------===//
|
|
@@ -88556,8 +88734,9 @@ struct CosOperator {
|
|
|
88556
88734
|
};
|
|
88557
88735
|
|
|
88558
88736
|
void CosFun::RegisterFunction(BuiltinFunctions &set) {
|
|
88559
|
-
set.AddFunction(
|
|
88560
|
-
|
|
88737
|
+
set.AddFunction(
|
|
88738
|
+
ScalarFunction("cos", {LogicalType::DOUBLE}, LogicalType::DOUBLE,
|
|
88739
|
+
ScalarFunction::UnaryFunction<double, double, NoInfiniteDoubleWrapper<CosOperator>>));
|
|
88561
88740
|
}
|
|
88562
88741
|
|
|
88563
88742
|
//===--------------------------------------------------------------------===//
|
|
@@ -88571,8 +88750,9 @@ struct TanOperator {
|
|
|
88571
88750
|
};
|
|
88572
88751
|
|
|
88573
88752
|
void TanFun::RegisterFunction(BuiltinFunctions &set) {
|
|
88574
|
-
set.AddFunction(
|
|
88575
|
-
|
|
88753
|
+
set.AddFunction(
|
|
88754
|
+
ScalarFunction("tan", {LogicalType::DOUBLE}, LogicalType::DOUBLE,
|
|
88755
|
+
ScalarFunction::UnaryFunction<double, double, NoInfiniteDoubleWrapper<TanOperator>>));
|
|
88576
88756
|
}
|
|
88577
88757
|
|
|
88578
88758
|
//===--------------------------------------------------------------------===//
|
|
@@ -88589,8 +88769,9 @@ struct ASinOperator {
|
|
|
88589
88769
|
};
|
|
88590
88770
|
|
|
88591
88771
|
void AsinFun::RegisterFunction(BuiltinFunctions &set) {
|
|
88592
|
-
set.AddFunction(
|
|
88593
|
-
|
|
88772
|
+
set.AddFunction(
|
|
88773
|
+
ScalarFunction("asin", {LogicalType::DOUBLE}, LogicalType::DOUBLE,
|
|
88774
|
+
ScalarFunction::UnaryFunction<double, double, NoInfiniteDoubleWrapper<ASinOperator>>));
|
|
88594
88775
|
}
|
|
88595
88776
|
|
|
88596
88777
|
//===--------------------------------------------------------------------===//
|
|
@@ -88605,7 +88786,7 @@ struct ATanOperator {
|
|
|
88605
88786
|
|
|
88606
88787
|
void AtanFun::RegisterFunction(BuiltinFunctions &set) {
|
|
88607
88788
|
set.AddFunction(ScalarFunction("atan", {LogicalType::DOUBLE}, LogicalType::DOUBLE,
|
|
88608
|
-
|
|
88789
|
+
ScalarFunction::UnaryFunction<double, double, ATanOperator>));
|
|
88609
88790
|
}
|
|
88610
88791
|
|
|
88611
88792
|
//===--------------------------------------------------------------------===//
|
|
@@ -88620,7 +88801,7 @@ struct ATan2 {
|
|
|
88620
88801
|
|
|
88621
88802
|
void Atan2Fun::RegisterFunction(BuiltinFunctions &set) {
|
|
88622
88803
|
set.AddFunction(ScalarFunction("atan2", {LogicalType::DOUBLE, LogicalType::DOUBLE}, LogicalType::DOUBLE,
|
|
88623
|
-
|
|
88804
|
+
ScalarFunction::BinaryFunction<double, double, double, ATan2>));
|
|
88624
88805
|
}
|
|
88625
88806
|
|
|
88626
88807
|
//===--------------------------------------------------------------------===//
|
|
@@ -88634,8 +88815,8 @@ struct ACos {
|
|
|
88634
88815
|
};
|
|
88635
88816
|
|
|
88636
88817
|
void AcosFun::RegisterFunction(BuiltinFunctions &set) {
|
|
88637
|
-
set.AddFunction(
|
|
88638
|
-
|
|
88818
|
+
set.AddFunction(ScalarFunction("acos", {LogicalType::DOUBLE}, LogicalType::DOUBLE,
|
|
88819
|
+
ScalarFunction::UnaryFunction<double, double, NoInfiniteDoubleWrapper<ACos>>));
|
|
88639
88820
|
}
|
|
88640
88821
|
|
|
88641
88822
|
//===--------------------------------------------------------------------===//
|
|
@@ -88649,8 +88830,9 @@ struct CotOperator {
|
|
|
88649
88830
|
};
|
|
88650
88831
|
|
|
88651
88832
|
void CotFun::RegisterFunction(BuiltinFunctions &set) {
|
|
88652
|
-
set.AddFunction(
|
|
88653
|
-
|
|
88833
|
+
set.AddFunction(
|
|
88834
|
+
ScalarFunction("cot", {LogicalType::DOUBLE}, LogicalType::DOUBLE,
|
|
88835
|
+
ScalarFunction::UnaryFunction<double, double, NoInfiniteDoubleWrapper<CotOperator>>));
|
|
88654
88836
|
}
|
|
88655
88837
|
|
|
88656
88838
|
//===--------------------------------------------------------------------===//
|
|
@@ -88658,14 +88840,17 @@ void CotFun::RegisterFunction(BuiltinFunctions &set) {
|
|
|
88658
88840
|
//===--------------------------------------------------------------------===//
|
|
88659
88841
|
struct GammaOperator {
|
|
88660
88842
|
template <class TA, class TR>
|
|
88661
|
-
static inline TR Operation(TA
|
|
88662
|
-
|
|
88843
|
+
static inline TR Operation(TA input) {
|
|
88844
|
+
if (input == 0) {
|
|
88845
|
+
throw OutOfRangeException("cannot take gamma of zero");
|
|
88846
|
+
}
|
|
88847
|
+
return std::tgamma(input);
|
|
88663
88848
|
}
|
|
88664
88849
|
};
|
|
88665
88850
|
|
|
88666
88851
|
void GammaFun::RegisterFunction(BuiltinFunctions &set) {
|
|
88667
88852
|
set.AddFunction(ScalarFunction("gamma", {LogicalType::DOUBLE}, LogicalType::DOUBLE,
|
|
88668
|
-
|
|
88853
|
+
ScalarFunction::UnaryFunction<double, double, GammaOperator>));
|
|
88669
88854
|
}
|
|
88670
88855
|
|
|
88671
88856
|
//===--------------------------------------------------------------------===//
|
|
@@ -88673,14 +88858,17 @@ void GammaFun::RegisterFunction(BuiltinFunctions &set) {
|
|
|
88673
88858
|
//===--------------------------------------------------------------------===//
|
|
88674
88859
|
struct LogGammaOperator {
|
|
88675
88860
|
template <class TA, class TR>
|
|
88676
|
-
static inline TR Operation(TA
|
|
88677
|
-
|
|
88861
|
+
static inline TR Operation(TA input) {
|
|
88862
|
+
if (input == 0) {
|
|
88863
|
+
throw OutOfRangeException("cannot take log gamma of zero");
|
|
88864
|
+
}
|
|
88865
|
+
return std::lgamma(input);
|
|
88678
88866
|
}
|
|
88679
88867
|
};
|
|
88680
88868
|
|
|
88681
88869
|
void LogGammaFun::RegisterFunction(BuiltinFunctions &set) {
|
|
88682
88870
|
set.AddFunction(ScalarFunction("lgamma", {LogicalType::DOUBLE}, LogicalType::DOUBLE,
|
|
88683
|
-
|
|
88871
|
+
ScalarFunction::UnaryFunction<double, double, LogGammaOperator>));
|
|
88684
88872
|
}
|
|
88685
88873
|
|
|
88686
88874
|
//===--------------------------------------------------------------------===//
|
|
@@ -88730,7 +88918,7 @@ struct EvenOperator {
|
|
|
88730
88918
|
|
|
88731
88919
|
void EvenFun::RegisterFunction(BuiltinFunctions &set) {
|
|
88732
88920
|
set.AddFunction(ScalarFunction("even", {LogicalType::DOUBLE}, LogicalType::DOUBLE,
|
|
88733
|
-
|
|
88921
|
+
ScalarFunction::UnaryFunction<double, double, EvenOperator>));
|
|
88734
88922
|
}
|
|
88735
88923
|
|
|
88736
88924
|
} // namespace duckdb
|
|
@@ -88870,6 +89058,10 @@ void BuiltinFunctions::RegisterMathFunctions() {
|
|
|
88870
89058
|
Register<NextAfterFun>();
|
|
88871
89059
|
|
|
88872
89060
|
Register<EvenFun>();
|
|
89061
|
+
|
|
89062
|
+
Register<IsNanFun>();
|
|
89063
|
+
Register<IsInfiniteFun>();
|
|
89064
|
+
Register<IsFiniteFun>();
|
|
88873
89065
|
}
|
|
88874
89066
|
|
|
88875
89067
|
} // namespace duckdb
|
|
@@ -88915,7 +89107,7 @@ namespace duckdb {
|
|
|
88915
89107
|
template <>
|
|
88916
89108
|
float AddOperator::Operation(float left, float right) {
|
|
88917
89109
|
auto result = left + right;
|
|
88918
|
-
if (!Value::
|
|
89110
|
+
if (!Value::FloatIsFinite(result)) {
|
|
88919
89111
|
throw OutOfRangeException("Overflow in addition of float!");
|
|
88920
89112
|
}
|
|
88921
89113
|
return result;
|
|
@@ -88924,7 +89116,7 @@ float AddOperator::Operation(float left, float right) {
|
|
|
88924
89116
|
template <>
|
|
88925
89117
|
double AddOperator::Operation(double left, double right) {
|
|
88926
89118
|
auto result = left + right;
|
|
88927
|
-
if (!Value::
|
|
89119
|
+
if (!Value::DoubleIsFinite(result)) {
|
|
88928
89120
|
throw OutOfRangeException("Overflow in addition of double!");
|
|
88929
89121
|
}
|
|
88930
89122
|
return result;
|
|
@@ -89551,6 +89743,16 @@ struct NegateOperator {
|
|
|
89551
89743
|
}
|
|
89552
89744
|
};
|
|
89553
89745
|
|
|
89746
|
+
template <>
|
|
89747
|
+
bool NegateOperator::CanNegate(float input) {
|
|
89748
|
+
return Value::FloatIsFinite(input);
|
|
89749
|
+
}
|
|
89750
|
+
|
|
89751
|
+
template <>
|
|
89752
|
+
bool NegateOperator::CanNegate(double input) {
|
|
89753
|
+
return Value::DoubleIsFinite(input);
|
|
89754
|
+
}
|
|
89755
|
+
|
|
89554
89756
|
template <>
|
|
89555
89757
|
interval_t NegateOperator::Operation(interval_t input) {
|
|
89556
89758
|
interval_t result;
|
|
@@ -89876,7 +90078,7 @@ void MultiplyFun::RegisterFunction(BuiltinFunctions &set) {
|
|
|
89876
90078
|
template <>
|
|
89877
90079
|
float DivideOperator::Operation(float left, float right) {
|
|
89878
90080
|
auto result = left / right;
|
|
89879
|
-
if (!Value::
|
|
90081
|
+
if (!Value::FloatIsFinite(result)) {
|
|
89880
90082
|
throw OutOfRangeException("Overflow in division of float!");
|
|
89881
90083
|
}
|
|
89882
90084
|
return result;
|
|
@@ -89885,7 +90087,7 @@ float DivideOperator::Operation(float left, float right) {
|
|
|
89885
90087
|
template <>
|
|
89886
90088
|
double DivideOperator::Operation(double left, double right) {
|
|
89887
90089
|
auto result = left / right;
|
|
89888
|
-
if (!Value::
|
|
90090
|
+
if (!Value::DoubleIsFinite(result)) {
|
|
89889
90091
|
throw OutOfRangeException("Overflow in division of double!");
|
|
89890
90092
|
}
|
|
89891
90093
|
return result;
|
|
@@ -89997,13 +90199,21 @@ void DivideFun::RegisterFunction(BuiltinFunctions &set) {
|
|
|
89997
90199
|
template <>
|
|
89998
90200
|
float ModuloOperator::Operation(float left, float right) {
|
|
89999
90201
|
D_ASSERT(right != 0);
|
|
90000
|
-
|
|
90202
|
+
auto result = std::fmod(left, right);
|
|
90203
|
+
if (!Value::FloatIsFinite(result)) {
|
|
90204
|
+
throw OutOfRangeException("Overflow in modulo of float!");
|
|
90205
|
+
}
|
|
90206
|
+
return result;
|
|
90001
90207
|
}
|
|
90002
90208
|
|
|
90003
90209
|
template <>
|
|
90004
90210
|
double ModuloOperator::Operation(double left, double right) {
|
|
90005
90211
|
D_ASSERT(right != 0);
|
|
90006
|
-
|
|
90212
|
+
auto result = std::fmod(left, right);
|
|
90213
|
+
if (!Value::DoubleIsFinite(result)) {
|
|
90214
|
+
throw OutOfRangeException("Overflow in modulo of double!");
|
|
90215
|
+
}
|
|
90216
|
+
return result;
|
|
90007
90217
|
}
|
|
90008
90218
|
|
|
90009
90219
|
template <>
|
|
@@ -90246,7 +90456,7 @@ namespace duckdb {
|
|
|
90246
90456
|
template <>
|
|
90247
90457
|
float MultiplyOperator::Operation(float left, float right) {
|
|
90248
90458
|
auto result = left * right;
|
|
90249
|
-
if (!Value::
|
|
90459
|
+
if (!Value::FloatIsFinite(result)) {
|
|
90250
90460
|
throw OutOfRangeException("Overflow in multiplication of float!");
|
|
90251
90461
|
}
|
|
90252
90462
|
return result;
|
|
@@ -90255,7 +90465,7 @@ float MultiplyOperator::Operation(float left, float right) {
|
|
|
90255
90465
|
template <>
|
|
90256
90466
|
double MultiplyOperator::Operation(double left, double right) {
|
|
90257
90467
|
auto result = left * right;
|
|
90258
|
-
if (!Value::
|
|
90468
|
+
if (!Value::DoubleIsFinite(result)) {
|
|
90259
90469
|
throw OutOfRangeException("Overflow in multiplication of double!");
|
|
90260
90470
|
}
|
|
90261
90471
|
return result;
|
|
@@ -90479,7 +90689,7 @@ namespace duckdb {
|
|
|
90479
90689
|
template <>
|
|
90480
90690
|
float SubtractOperator::Operation(float left, float right) {
|
|
90481
90691
|
auto result = left - right;
|
|
90482
|
-
if (!Value::
|
|
90692
|
+
if (!Value::FloatIsFinite(result)) {
|
|
90483
90693
|
throw OutOfRangeException("Overflow in subtraction of float!");
|
|
90484
90694
|
}
|
|
90485
90695
|
return result;
|
|
@@ -90488,7 +90698,7 @@ float SubtractOperator::Operation(float left, float right) {
|
|
|
90488
90698
|
template <>
|
|
90489
90699
|
double SubtractOperator::Operation(double left, double right) {
|
|
90490
90700
|
auto result = left - right;
|
|
90491
|
-
if (!Value::
|
|
90701
|
+
if (!Value::DoubleIsFinite(result)) {
|
|
90492
90702
|
throw OutOfRangeException("Overflow in subtraction of double!");
|
|
90493
90703
|
}
|
|
90494
90704
|
return result;
|
|
@@ -97190,6 +97400,7 @@ void ColumnArrowToDuckDB(Vector &vector, ArrowArray &array, ArrowScanState &scan
|
|
|
97190
97400
|
case LogicalTypeId::SMALLINT:
|
|
97191
97401
|
case LogicalTypeId::INTEGER:
|
|
97192
97402
|
case LogicalTypeId::FLOAT:
|
|
97403
|
+
case LogicalTypeId::DOUBLE:
|
|
97193
97404
|
case LogicalTypeId::UTINYINT:
|
|
97194
97405
|
case LogicalTypeId::USMALLINT:
|
|
97195
97406
|
case LogicalTypeId::UINTEGER:
|
|
@@ -97203,18 +97414,6 @@ void ColumnArrowToDuckDB(Vector &vector, ArrowArray &array, ArrowScanState &scan
|
|
|
97203
97414
|
DirectConversion(vector, array, scan_state, nested_offset);
|
|
97204
97415
|
break;
|
|
97205
97416
|
}
|
|
97206
|
-
case LogicalTypeId::DOUBLE: {
|
|
97207
|
-
DirectConversion(vector, array, scan_state, nested_offset);
|
|
97208
|
-
//! Need to check if there are NaNs, if yes, must turn that to null
|
|
97209
|
-
auto data = (double *)vector.GetData();
|
|
97210
|
-
auto &mask = FlatVector::Validity(vector);
|
|
97211
|
-
for (idx_t row_idx = 0; row_idx < size; row_idx++) {
|
|
97212
|
-
if (!Value::DoubleIsValid(data[row_idx])) {
|
|
97213
|
-
mask.SetInvalid(row_idx);
|
|
97214
|
-
}
|
|
97215
|
-
}
|
|
97216
|
-
break;
|
|
97217
|
-
}
|
|
97218
97417
|
case LogicalTypeId::JSON:
|
|
97219
97418
|
case LogicalTypeId::VARCHAR: {
|
|
97220
97419
|
auto original_type = arrow_convert_data[col_idx]->variable_sz_type[arrow_convert_idx.first++];
|
|
@@ -102200,6 +102399,8 @@ void PragmaTableInfo::RegisterFunction(BuiltinFunctions &set) {
|
|
|
102200
102399
|
} // namespace duckdb
|
|
102201
102400
|
|
|
102202
102401
|
|
|
102402
|
+
#include <cmath>
|
|
102403
|
+
#include <limits>
|
|
102203
102404
|
|
|
102204
102405
|
namespace duckdb {
|
|
102205
102406
|
|
|
@@ -102302,6 +102503,13 @@ static vector<TestType> GetTestTypes() {
|
|
|
102302
102503
|
Value(LogicalType::INTEGER), Value::INTEGER(-42)});
|
|
102303
102504
|
result.emplace_back(int_list_type, "int_array", empty_int_list, int_list);
|
|
102304
102505
|
|
|
102506
|
+
auto double_list_type = LogicalType::LIST(LogicalType::DOUBLE);
|
|
102507
|
+
auto empty_double_list = Value::EMPTYLIST(LogicalType::DOUBLE);
|
|
102508
|
+
auto double_list = Value::LIST(
|
|
102509
|
+
{Value::DOUBLE(42), Value::DOUBLE(NAN), Value::DOUBLE(std::numeric_limits<double>::infinity()),
|
|
102510
|
+
Value::DOUBLE(-std::numeric_limits<double>::infinity()), Value(LogicalType::DOUBLE), Value::DOUBLE(-42)});
|
|
102511
|
+
result.emplace_back(double_list_type, "double_array", empty_double_list, double_list);
|
|
102512
|
+
|
|
102305
102513
|
auto varchar_list_type = LogicalType::LIST(LogicalType::VARCHAR);
|
|
102306
102514
|
auto empty_varchar_list = Value::EMPTYLIST(LogicalType::VARCHAR);
|
|
102307
102515
|
auto varchar_list =
|
|
@@ -103339,17 +103547,11 @@ void BaseAppender::Append(string_t value) {
|
|
|
103339
103547
|
|
|
103340
103548
|
template <>
|
|
103341
103549
|
void BaseAppender::Append(float value) {
|
|
103342
|
-
if (!Value::FloatIsValid(value)) {
|
|
103343
|
-
throw InvalidInputException("Float value is out of range!");
|
|
103344
|
-
}
|
|
103345
103550
|
AppendValueInternal<float>(value);
|
|
103346
103551
|
}
|
|
103347
103552
|
|
|
103348
103553
|
template <>
|
|
103349
103554
|
void BaseAppender::Append(double value) {
|
|
103350
|
-
if (!Value::DoubleIsValid(value)) {
|
|
103351
|
-
throw InvalidInputException("Double value is out of range!");
|
|
103352
|
-
}
|
|
103353
103555
|
AppendValueInternal<double>(value);
|
|
103354
103556
|
}
|
|
103355
103557
|
|
|
@@ -104435,7 +104637,7 @@ double duckdb_hugeint_to_double(duckdb_hugeint val) {
|
|
|
104435
104637
|
|
|
104436
104638
|
duckdb_hugeint duckdb_double_to_hugeint(double val) {
|
|
104437
104639
|
hugeint_t internal_result;
|
|
104438
|
-
if (!Value::
|
|
104640
|
+
if (!Value::DoubleIsFinite(val) || !Hugeint::TryConvert<double>(val, internal_result)) {
|
|
104439
104641
|
internal_result.lower = 0;
|
|
104440
104642
|
internal_result.upper = 0;
|
|
104441
104643
|
}
|
|
@@ -104725,16 +104927,10 @@ duckdb_state duckdb_bind_uint64(duckdb_prepared_statement prepared_statement, id
|
|
|
104725
104927
|
}
|
|
104726
104928
|
|
|
104727
104929
|
duckdb_state duckdb_bind_float(duckdb_prepared_statement prepared_statement, idx_t param_idx, float val) {
|
|
104728
|
-
if (!Value::FloatIsValid(val)) {
|
|
104729
|
-
return DuckDBError;
|
|
104730
|
-
}
|
|
104731
104930
|
return duckdb_bind_value(prepared_statement, param_idx, Value::FLOAT(val));
|
|
104732
104931
|
}
|
|
104733
104932
|
|
|
104734
104933
|
duckdb_state duckdb_bind_double(duckdb_prepared_statement prepared_statement, idx_t param_idx, double val) {
|
|
104735
|
-
if (!Value::DoubleIsValid(val)) {
|
|
104736
|
-
return DuckDBError;
|
|
104737
|
-
}
|
|
104738
104934
|
return duckdb_bind_value(prepared_statement, param_idx, Value::DOUBLE(val));
|
|
104739
104935
|
}
|
|
104740
104936
|
|
|
@@ -117960,7 +118156,7 @@ void OperatorProfiler::AddTiming(const PhysicalOperator *op, double time, idx_t
|
|
|
117960
118156
|
if (!enabled) {
|
|
117961
118157
|
return;
|
|
117962
118158
|
}
|
|
117963
|
-
if (!Value::
|
|
118159
|
+
if (!Value::DoubleIsFinite(time)) {
|
|
117964
118160
|
return;
|
|
117965
118161
|
}
|
|
117966
118162
|
auto entry = timings.find(op);
|
|
@@ -146715,9 +146911,6 @@ unique_ptr<ConstantExpression> Transformer::TransformValue(duckdb_libpgquery::PG
|
|
|
146715
146911
|
}
|
|
146716
146912
|
// if there is a decimal or the value is too big to cast as either hugeint or bigint
|
|
146717
146913
|
double dbl_value = Cast::Operation<string_t, double>(str_val);
|
|
146718
|
-
if (!Value::DoubleIsValid(dbl_value)) {
|
|
146719
|
-
throw ParserException("Double value \"%s\" is out of range!", val.val.str);
|
|
146720
|
-
}
|
|
146721
146914
|
return make_unique<ConstantExpression>(Value::DOUBLE(dbl_value));
|
|
146722
146915
|
}
|
|
146723
146916
|
case duckdb_libpgquery::T_PGNull:
|
|
@@ -164173,6 +164366,7 @@ void WriteOverflowStringsToDisk::AllocateNewBlock(block_id_t new_block_id) {
|
|
|
164173
164366
|
|
|
164174
164367
|
|
|
164175
164368
|
|
|
164369
|
+
|
|
164176
164370
|
|
|
164177
164371
|
|
|
164178
164372
|
namespace duckdb {
|
|
@@ -164322,38 +164516,41 @@ void CheckpointManager::WriteSchema(SchemaCatalogEntry &schema) {
|
|
|
164322
164516
|
}
|
|
164323
164517
|
});
|
|
164324
164518
|
|
|
164519
|
+
FieldWriter writer(*metadata_writer);
|
|
164520
|
+
writer.WriteField<uint32_t>(custom_types.size());
|
|
164521
|
+
writer.WriteField<uint32_t>(sequences.size());
|
|
164522
|
+
writer.WriteField<uint32_t>(tables.size());
|
|
164523
|
+
writer.WriteField<uint32_t>(views.size());
|
|
164524
|
+
writer.WriteField<uint32_t>(macros.size());
|
|
164525
|
+
writer.WriteField<uint32_t>(table_macros.size());
|
|
164526
|
+
writer.Finalize();
|
|
164527
|
+
|
|
164325
164528
|
// write the custom_types
|
|
164326
|
-
metadata_writer->Write<uint32_t>(custom_types.size());
|
|
164327
164529
|
for (auto &custom_type : custom_types) {
|
|
164328
164530
|
WriteType(*custom_type);
|
|
164329
164531
|
}
|
|
164330
164532
|
|
|
164331
164533
|
// write the sequences
|
|
164332
|
-
metadata_writer->Write<uint32_t>(sequences.size());
|
|
164333
164534
|
for (auto &seq : sequences) {
|
|
164334
164535
|
WriteSequence(*seq);
|
|
164335
164536
|
}
|
|
164336
164537
|
// reorder tables because of foreign key constraint
|
|
164337
164538
|
ReorderTableEntries(tables);
|
|
164338
164539
|
// now write the tables
|
|
164339
|
-
metadata_writer->Write<uint32_t>(tables.size());
|
|
164340
164540
|
for (auto &table : tables) {
|
|
164341
164541
|
WriteTable(*table);
|
|
164342
164542
|
}
|
|
164343
164543
|
// now write the views
|
|
164344
|
-
metadata_writer->Write<uint32_t>(views.size());
|
|
164345
164544
|
for (auto &view : views) {
|
|
164346
164545
|
WriteView(*view);
|
|
164347
164546
|
}
|
|
164348
164547
|
|
|
164349
164548
|
// finally write the macro's
|
|
164350
|
-
metadata_writer->Write<uint32_t>(macros.size());
|
|
164351
164549
|
for (auto ¯o : macros) {
|
|
164352
164550
|
WriteMacro(*macro);
|
|
164353
164551
|
}
|
|
164354
164552
|
|
|
164355
164553
|
// finally write the macro's
|
|
164356
|
-
metadata_writer->Write<uint32_t>(table_macros.size());
|
|
164357
164554
|
for (auto ¯o : table_macros) {
|
|
164358
164555
|
WriteTableMacro(*macro);
|
|
164359
164556
|
}
|
|
@@ -164368,35 +164565,39 @@ void CheckpointManager::ReadSchema(ClientContext &context, MetaBlockReader &read
|
|
|
164368
164565
|
info->on_conflict = OnCreateConflict::IGNORE_ON_CONFLICT;
|
|
164369
164566
|
catalog.CreateSchema(context, info.get());
|
|
164370
164567
|
|
|
164568
|
+
// first read all the counts
|
|
164569
|
+
FieldReader field_reader(reader);
|
|
164570
|
+
uint32_t enum_count = field_reader.ReadRequired<uint32_t>();
|
|
164571
|
+
uint32_t seq_count = field_reader.ReadRequired<uint32_t>();
|
|
164572
|
+
uint32_t table_count = field_reader.ReadRequired<uint32_t>();
|
|
164573
|
+
uint32_t view_count = field_reader.ReadRequired<uint32_t>();
|
|
164574
|
+
uint32_t macro_count = field_reader.ReadRequired<uint32_t>();
|
|
164575
|
+
uint32_t table_macro_count = field_reader.ReadRequired<uint32_t>();
|
|
164576
|
+
field_reader.Finalize();
|
|
164577
|
+
|
|
164371
164578
|
// now read the enums
|
|
164372
|
-
uint32_t enum_count = reader.Read<uint32_t>();
|
|
164373
164579
|
for (uint32_t i = 0; i < enum_count; i++) {
|
|
164374
164580
|
ReadType(context, reader);
|
|
164375
164581
|
}
|
|
164376
164582
|
|
|
164377
164583
|
// read the sequences
|
|
164378
|
-
uint32_t seq_count = reader.Read<uint32_t>();
|
|
164379
164584
|
for (uint32_t i = 0; i < seq_count; i++) {
|
|
164380
164585
|
ReadSequence(context, reader);
|
|
164381
164586
|
}
|
|
164382
164587
|
// read the table count and recreate the tables
|
|
164383
|
-
uint32_t table_count = reader.Read<uint32_t>();
|
|
164384
164588
|
for (uint32_t i = 0; i < table_count; i++) {
|
|
164385
164589
|
ReadTable(context, reader);
|
|
164386
164590
|
}
|
|
164387
164591
|
// now read the views
|
|
164388
|
-
uint32_t view_count = reader.Read<uint32_t>();
|
|
164389
164592
|
for (uint32_t i = 0; i < view_count; i++) {
|
|
164390
164593
|
ReadView(context, reader);
|
|
164391
164594
|
}
|
|
164392
164595
|
|
|
164393
164596
|
// finally read the macro's
|
|
164394
|
-
uint32_t macro_count = reader.Read<uint32_t>();
|
|
164395
164597
|
for (uint32_t i = 0; i < macro_count; i++) {
|
|
164396
164598
|
ReadMacro(context, reader);
|
|
164397
164599
|
}
|
|
164398
164600
|
|
|
164399
|
-
uint32_t table_macro_count = reader.Read<uint32_t>();
|
|
164400
164601
|
for (uint32_t i = 0; i < table_macro_count; i++) {
|
|
164401
164602
|
ReadTableMacro(context, reader);
|
|
164402
164603
|
}
|
|
@@ -172777,7 +172978,7 @@ string ValidityStatistics::ToString() const {
|
|
|
172777
172978
|
|
|
172778
172979
|
namespace duckdb {
|
|
172779
172980
|
|
|
172780
|
-
const uint64_t VERSION_NUMBER =
|
|
172981
|
+
const uint64_t VERSION_NUMBER = 33;
|
|
172781
172982
|
|
|
172782
172983
|
} // namespace duckdb
|
|
172783
172984
|
|