20 #include <boost/assign/list_of.hpp>
21 #include <boost/date_time/c_local_time_adjustor.hpp>
22 #include <boost/date_time/posix_time/posix_time.hpp>
23 #include <boost/lexical_cast.hpp>
24 #include <boost/random/mersenne_twister.hpp>
25 #include <boost/unordered_map.hpp>
26 #include <gtest/gtest.h>
36 #include "gen-cpp/Exprs_types.h"
37 #include "gen-cpp/hive_metastore_types.h"
60 namespace posix_time = boost::posix_time;
61 using boost::assign::list_of;
62 using boost::bad_lexical_cast;
63 using boost::date_time::c_local_adjustor;
64 using boost::posix_time::from_time_t;
65 using boost::posix_time::ptime;
66 using namespace Apache::Hadoop::Hive;
67 using namespace impala;
74 template <
typename ORIGINAL_TYPE,
typename VAL_TYPE>
76 return lexical_cast<
string>(val);
83 << lexical_cast<
string>(val)
92 << lexical_cast<
string>(val)
101 << lexical_cast<
string>(val)
112 original_time_zone_ = getenv(
"TZ");
113 setenv(
"TZ", time_zone.c_str(),
true);
118 if (original_time_zone_ == NULL) {
121 setenv(
"TZ", original_time_zone_,
true);
134 FLAGS_use_local_tz_for_unix_timestamp_conversions =
true;
138 FLAGS_use_local_tz_for_unix_timestamp_conversions =
false;
176 static_cast<int64_t
>(numeric_limits<int8_t>::max()) + 1;
177 min_int_values_[
TYPE_INT] =
static_cast<int64_t
>(numeric_limits<int16_t>::max()) + 1;
179 static_cast<int64_t
>(numeric_limits<int32_t>::max()) + 1;
183 static_cast<double>(numeric_limits<float>::max()) + 1.1;
186 default_bool_str_ =
"false";
187 default_string_str_ =
"'abc'";
188 default_timestamp_str_ =
"cast('2011-01-01 09:01:01' as timestamp)";
189 default_decimal_str_ =
"1.23";
190 default_bool_val_ =
false;
191 default_string_val_ =
"abc";
198 lexical_cast<
string>(min_int_values_[
TYPE_INT]);
200 lexical_cast<
string>(min_int_values_[
TYPE_BIGINT]);
205 << lexical_cast<
string>(min_float_values_[
TYPE_FLOAT]) <<
" as float)";
209 << lexical_cast<
string>(min_float_values_[
TYPE_FLOAT]) <<
" as double)";
212 default_type_strs_[
TYPE_STRING] = default_string_str_;
214 default_type_strs_[
TYPE_DECIMAL] = default_decimal_str_;
218 void** interpreted_value,
bool expect_error =
false) {
219 string stmt =
"select " + expr;
220 vector<FieldSchema> result_types;
223 ASSERT_FALSE(status.
ok()) <<
"Expected error\nstmt: " << stmt;
226 ASSERT_TRUE(status.
ok()) <<
"stmt: " << stmt <<
"\nerror: " << status.
GetDetail();
230 *interpreted_value = ConvertValue(expr_type, result_row);
235 if (value.compare(
"NULL") == 0)
return NULL;
243 expr_value_.string_val = value;
244 return &expr_value_.string_val;
246 expr_value_.tinyint_val =
247 StringParser::StringToInt<int8_t>(&value[0], value.size(), &result);
248 return &expr_value_.tinyint_val;
250 expr_value_.smallint_val =
251 StringParser::StringToInt<int16_t>(&value[0], value.size(), &result);
252 return &expr_value_.smallint_val;
254 expr_value_.int_val =
255 StringParser::StringToInt<int32_t>(&value[0], value.size(), &result);
256 return &expr_value_.int_val;
258 expr_value_.bigint_val =
259 StringParser::StringToInt<int64_t>(&value[0], value.size(), &result);
260 return &expr_value_.bigint_val;
262 expr_value_.bool_val = value.compare(
"false");
263 return &expr_value_.bool_val;
265 expr_value_.timestamp_val =
TimestampValue(&value[0], value.size());
266 return &expr_value_.timestamp_val;
270 expr_value_.decimal4_val = StringParser::StringToDecimal<int32_t>(
271 &value[0], value.size(), type, &result);
272 return &expr_value_.decimal4_val;
274 expr_value_.decimal8_val = StringParser::StringToDecimal<int64_t>(
275 &value[0], value.size(), type, &result);
276 return &expr_value_.decimal8_val;
278 expr_value_.decimal16_val = StringParser::StringToDecimal<int128_t>(
279 &value[0], value.size(), type, &result);
280 return &expr_value_.decimal16_val;
282 DCHECK(
false) << type;
285 DCHECK(
false) << type;
292 GetValue(expr,
TYPE_STRING, reinterpret_cast<void**>(&result));
293 string tmp(result->
ptr, result->
len);
294 EXPECT_EQ(tmp, expected_result) << expr;
300 GetValue(expr, type, reinterpret_cast<void**>(&result));
301 string tmp(result->
ptr, result->
len);
302 EXPECT_EQ(tmp, expected_result) << expr;
308 const int64_t tolerance_in_seconds = 0) {
310 GetValue(expr,
TYPE_TIMESTAMP, reinterpret_cast<void**>(&result));
311 if (tolerance_in_seconds == 0) {
312 EXPECT_EQ(*result, expected_result);
315 EXPECT_LE(delta, tolerance_in_seconds);
323 GetValue(expr,
TYPE_TIMESTAMP, reinterpret_cast<void**>(&result));
333 string local_time_at_unix_epoch) {
334 TestValue(
"unix_timestamp(cast('" + local_time_at_unix_epoch +
"' as timestamp))",
336 TestValue(
"unix_timestamp('" + local_time_at_unix_epoch +
"')",
TYPE_BIGINT, 0);
337 TestValue(
"unix_timestamp('" + local_time_at_unix_epoch +
339 TestValue(
"unix_timestamp('1970-01-01', 'yyyy-MM-dd')",
TYPE_BIGINT,
340 unix_time_at_local_epoch);
341 TestValue(
"unix_timestamp('1970-01-01 10:10:10', 'yyyy-MM-dd')",
TYPE_BIGINT,
342 unix_time_at_local_epoch);
343 TestValue(
"unix_timestamp('" + local_time_at_unix_epoch
344 +
" extra text', 'yyyy-MM-dd HH:mm:ss')",
TYPE_BIGINT, 0);
345 TestStringValue(
"cast(cast(0 as timestamp) as string)", local_time_at_unix_epoch);
346 TestStringValue(
"cast(cast(0 as timestamp) as string)", local_time_at_unix_epoch);
347 TestStringValue(
"from_unixtime(0)", local_time_at_unix_epoch);
348 TestStringValue(
"from_unixtime(cast(0 as bigint))", local_time_at_unix_epoch);
350 TestStringValue(
"from_unixtime(0, 'yyyy-MM-dd HH:mm:ss')",
351 local_time_at_unix_epoch);
352 TestStringValue(
"from_unixtime(cast(0 as bigint), 'yyyy-MM-dd HH:mm:ss')",
353 local_time_at_unix_epoch);
354 TestStringValue(
"from_unixtime(" + lexical_cast<string>(unix_time_at_local_epoch)
355 +
", 'yyyy-MM-dd')",
"1970-01-01");
356 TestStringValue(
"from_unixtime(cast(" + lexical_cast<string>(unix_time_at_local_epoch)
357 +
" as bigint), 'yyyy-MM-dd')",
"1970-01-01");
362 template <
typename T>
366 GetValue(expr, expected_type, reinterpret_cast<void**>(&result));
367 EXPECT_EQ(result->value(), expected_result.value()) << expr
368 <<
": values did not match. Expected: "
369 << expected_result.ToString(expected_type)
370 <<
" Actual: " << result->ToString(expected_type);
374 const T& expected_result) {
376 GetValue(expr, expr_type, &result);
379 float expected_float;
380 double expected_double;
381 switch (expr_type.
type) {
383 EXPECT_EQ(*reinterpret_cast<bool*>(result), expected_result) << expr;
386 EXPECT_EQ(*reinterpret_cast<int8_t*>(result), expected_result) << expr;
389 EXPECT_EQ(*reinterpret_cast<int16_t*>(result), expected_result) << expr;
392 EXPECT_EQ(*reinterpret_cast<int32_t*>(result), expected_result) << expr;
395 EXPECT_EQ(*reinterpret_cast<int64_t*>(result), expected_result) << expr;
401 expected_float =
static_cast<float>(expected_result);
402 RawValue::PrintValue(reinterpret_cast<const void*>(&expected_float),
404 EXPECT_EQ(*reinterpret_cast<string*>(result), expected_str) << expr;
407 expected_double =
static_cast<double>(expected_result);
408 RawValue::PrintValue(reinterpret_cast<const void*>(&expected_double),
410 EXPECT_EQ(*reinterpret_cast<string*>(result), expected_str) << expr;
413 ASSERT_TRUE(
false) <<
"invalid TestValue() type: " << expr_type;
419 GetValue(expr, expr_type, &result);
420 EXPECT_TRUE(result == NULL) << expr;
429 string stmt =
"select " + expr;
430 vector<FieldSchema> result_types;
432 ASSERT_FALSE(status.
ok()) <<
"stmt: " << stmt <<
"\nunexpected Status::OK.";
436 int64_t t_min = numeric_limits<T>::min();
437 int64_t t_max = numeric_limits<T>::max();
438 TestComparison(lexical_cast<string>(t_min), lexical_cast<string>(t_max),
true);
439 TestBinaryPredicates(lexical_cast<string>(t_min),
true);
440 TestBinaryPredicates(lexical_cast<string>(t_max),
true);
441 if (test_boundaries) {
443 TestComparison(lexical_cast<string>(t_min - 1),
444 lexical_cast<string>(t_max),
true);
446 TestComparison(lexical_cast<string>(t_min),
447 lexical_cast<string>(t_max + 1),
true);
453 T t_min = numeric_limits<T>::min();
454 T t_max = numeric_limits<T>::max();
455 TestComparison(lexical_cast<string>(t_min), lexical_cast<string>(t_max),
true);
456 TestComparison(lexical_cast<string>(-1.0 * t_max), lexical_cast<string>(t_max),
true);
457 TestBinaryPredicates(lexical_cast<string>(t_min),
true);
458 TestBinaryPredicates(lexical_cast<string>(t_max),
true);
459 if (test_boundaries) {
461 TestComparison(lexical_cast<string>(numeric_limits<T>::min() - 1),
462 lexical_cast<string>(numeric_limits<T>::max()),
true);
464 TestComparison(lexical_cast<string>(numeric_limits<T>::min()),
465 lexical_cast<string>(numeric_limits<T>::max() + 1),
true);
469 TestValue(lexical_cast<string>(t_min) +
" < 0/0",
TYPE_BOOLEAN,
false);
470 TestValue(lexical_cast<string>(t_min) +
" > 0/0",
TYPE_BOOLEAN,
false);
471 TestValue(lexical_cast<string>(t_min) +
" = 0/0",
TYPE_BOOLEAN,
false);
472 TestValue(lexical_cast<string>(t_max) +
" < 0/0",
TYPE_BOOLEAN,
false);
473 TestValue(lexical_cast<string>(t_max) +
" > 0/0",
TYPE_BOOLEAN,
false);
474 TestValue(lexical_cast<string>(t_max) +
" = 0/0",
TYPE_BOOLEAN,
false);
480 TestValue(lexical_cast<string>(t_max) +
" < 1/0",
TYPE_BOOLEAN,
true);
481 TestValue(lexical_cast<string>(t_min) +
" > -1/0",
TYPE_BOOLEAN,
true);
494 TestValue<bool>(
"'abcd' < 'abcd'",
TYPE_BOOLEAN,
false);
497 TestValue<bool>(
"'abcd' > 'abcd'",
TYPE_BOOLEAN,
false);
499 TestValue<bool>(
"'abcd' <= 'abc'",
TYPE_BOOLEAN,
false);
500 TestValue<bool>(
"'abcd' <= 'abcd'",
TYPE_BOOLEAN,
true);
501 TestValue<bool>(
"'abc' >= 'abcd'",
TYPE_BOOLEAN,
false);
503 TestValue<bool>(
"'abcd' >= 'abcd'",
TYPE_BOOLEAN,
true);
518 TestValue(
"1.23 = 1.230000000000000000000",
TYPE_BOOLEAN,
true);
519 TestValue(
"1.2300 != 1.230000000000000000001",
TYPE_BOOLEAN,
true);
520 TestValue(
"cast(1 as decimal(38,0)) = cast(1 as decimal(38,37))",
TYPE_BOOLEAN,
true);
521 TestValue(
"cast(1 as decimal(38,0)) = cast(0.1 as decimal(38,38))",
523 TestValue(
"cast(1 as decimal(38,0)) > cast(0.1 as decimal(38,38))",
525 TestBinaryPredicates(
"cast(1 as decimal(8,0))",
false);
526 TestBinaryPredicates(
"cast(1 as decimal(10,0))",
false);
527 TestBinaryPredicates(
"cast(1 as decimal(38,0))",
false);
552 unordered_map<int, string>::iterator def_iter;
553 for(def_iter = default_type_strs_.begin(); def_iter != default_type_strs_.end();
555 TestNullComparison(def_iter->second);
557 TestNullComparison(
"NULL");
562 void TestComparison(
const string& smaller,
const string& larger,
bool compare_strings) {
566 compare_strings =
false;
567 string eq_pred = smaller +
" = " + larger;
569 if (compare_strings) {
570 eq_pred = smaller +
" = '" + larger +
"'";
573 string ne_pred = smaller +
" != " + larger;
575 if (compare_strings) {
576 ne_pred = smaller +
" != '" + larger +
"'";
579 string ne2_pred = smaller +
" <> " + larger;
581 if (compare_strings) {
582 ne2_pred = smaller +
" <> '" + larger +
"'";
585 string lt_pred = smaller +
" < " + larger;
587 if (compare_strings) {
588 lt_pred = smaller +
" < '" + larger +
"'";
591 string le_pred = smaller +
" <= " + larger;
593 if (compare_strings) {
594 le_pred = smaller +
" <= '" + larger +
"'";
597 string gt_pred = smaller +
" > " + larger;
599 if (compare_strings) {
600 gt_pred = smaller +
" > '" + larger +
"'";
603 string ge_pred = smaller +
" >= " + larger;
605 if (compare_strings) {
606 ge_pred = smaller +
" >= '" + larger +
"'";
617 compare_strings =
false;
618 string eq_pred = value +
" = " + value;
620 if (compare_strings) {
621 eq_pred = value +
" = '" + value +
"'";
624 string ne_pred = value +
" != " + value;
626 if (compare_strings) {
627 ne_pred = value +
" != '" + value +
"'";
630 string ne2_pred = value +
" <> " + value;
632 if (compare_strings) {
633 ne2_pred = value +
" <> '" + value +
"'";
636 string lt_pred = value +
" < " + value;
638 if (compare_strings) {
639 lt_pred = value +
" < '" + value +
"'";
642 string le_pred = value +
" <= " + value;
644 if (compare_strings) {
645 le_pred = value +
" <= '" + value +
"'";
648 string gt_pred = value +
" > " + value;
650 if (compare_strings) {
651 gt_pred = value +
" > '" + value +
"'";
654 string ge_pred = value +
" >= " + value;
656 if (compare_strings) {
657 ge_pred = value +
" >= '" + value +
"'";
665 int64_t t_min = numeric_limits<T>::min();
666 int64_t t_max = numeric_limits<T>::max();
667 TestValue(lexical_cast<string>(t_min), type, numeric_limits<T>::min());
668 TestValue(lexical_cast<string>(t_max), type, numeric_limits<T>::max());
673 TestValue(lexical_cast<string>(numeric_limits<T>::min()), type,
674 numeric_limits<T>::min());
675 TestValue(lexical_cast<string>(-1.0 * numeric_limits<T>::min()), type,
676 -1.0 * numeric_limits<T>::min());
677 TestValue(lexical_cast<string>(-1.0 * numeric_limits<T>::max()), type,
678 -1.0 * numeric_limits<T>::max());
679 TestValue(lexical_cast<string>(numeric_limits<T>::max() - 1.0), type,
680 numeric_limits<T>::max());
688 template <
typename LeftOp,
typename RightOp,
typename Result>
690 Result cast_a =
static_cast<Result
>(a);
691 Result cast_b =
static_cast<Result
>(b);
692 string a_str = LiteralToString<Result>(cast_a);
693 string b_str = LiteralToString<Result>(cast_b);
694 TestValue(a_str +
" + " + b_str, expected_type,
695 static_cast<Result>(cast_a + cast_b));
696 TestValue(a_str +
" - " + b_str, expected_type,
697 static_cast<Result>(cast_a - cast_b));
698 TestValue(a_str +
" * " + b_str, expected_type,
699 static_cast<Result>(cast_a * cast_b));
701 static_cast<double>(a) / static_cast<double>(b));
707 template <
typename LeftOp,
typename RightOp>
710 RightOp cast_a =
static_cast<RightOp
>(a);
711 RightOp cast_b =
static_cast<RightOp
>(b);
712 string a_str = lexical_cast<
string>(
static_cast<int64_t
>(a));
713 string b_str = lexical_cast<
string>(
static_cast<int64_t
>(b));
714 TestValue(a_str +
" & " + b_str, expected_type, cast_a & cast_b);
715 TestValue(a_str +
" | " + b_str, expected_type, cast_a | cast_b);
716 TestValue(a_str +
" ^ " + b_str, expected_type, cast_a ^ cast_b);
718 TestValue(
"~" + b_str, expected_type, ~cast_b);
719 TestValue(a_str +
" DIV " + b_str, expected_type, cast_a / cast_b);
720 TestValue(a_str +
" % " + b_str, expected_type, cast_a % cast_b);
726 template <
typename NonNullOp,
typename CastType>
728 CastType cast_op =
static_cast<CastType
>(op);
729 string op_str = LiteralToString<CastType>(cast_op);
731 TestIsNull(op_str +
" + NULL", expected_type);
732 TestIsNull(op_str +
" - NULL", expected_type);
733 TestIsNull(op_str +
" * NULL", expected_type);
736 TestIsNull(
"NULL + " + op_str, expected_type);
737 TestIsNull(
"NULL - " + op_str, expected_type);
738 TestIsNull(
"NULL * " + op_str, expected_type);
744 template <
typename NonNullOp>
747 string op_str = lexical_cast<
string>(
static_cast<int64_t
>(op));
749 TestIsNull(op_str +
" & NULL", expected_type);
750 TestIsNull(op_str +
" | NULL", expected_type);
751 TestIsNull(op_str +
" ^ NULL", expected_type);
752 TestIsNull(op_str +
" DIV NULL", expected_type);
753 TestIsNull(op_str +
" % NULL", expected_type);
755 TestIsNull(
"NULL & " + op_str, expected_type);
756 TestIsNull(
"NULL | " + op_str, expected_type);
757 TestIsNull(
"NULL ^ " + op_str, expected_type);
758 TestIsNull(
"NULL DIV " + op_str, expected_type);
759 TestIsNull(
"NULL % " + op_str, expected_type);
769 TestIsNull(
"NULL & NULL",
TYPE_INT);
770 TestIsNull(
"NULL | NULL",
TYPE_INT);
771 TestIsNull(
"NULL ^ NULL",
TYPE_INT);
772 TestIsNull(
"NULL DIV NULL",
TYPE_INT);
779 void TestCast(
const string& stmt, T val,
bool timestamp_out_of_range =
false) {
780 TestValue(
"cast(" + stmt +
" as boolean)",
TYPE_BOOLEAN, static_cast<bool>(val));
781 TestValue(
"cast(" + stmt +
" as tinyint)",
TYPE_TINYINT, static_cast<int8_t>(val));
782 TestValue(
"cast(" + stmt +
" as smallint)",
TYPE_SMALLINT, static_cast<int16_t>(val));
783 TestValue(
"cast(" + stmt +
" as int)",
TYPE_INT, static_cast<int32_t>(val));
784 TestValue(
"cast(" + stmt +
" as integer)",
TYPE_INT, static_cast<int32_t>(val));
785 TestValue(
"cast(" + stmt +
" as bigint)",
TYPE_BIGINT, static_cast<int64_t>(val));
786 TestValue(
"cast(" + stmt +
" as float)",
TYPE_FLOAT, static_cast<float>(val));
787 TestValue(
"cast(" + stmt +
" as double)",
TYPE_DOUBLE, static_cast<double>(val));
788 TestValue(
"cast(" + stmt +
" as real)",
TYPE_DOUBLE, static_cast<double>(val));
789 TestStringValue(
"cast(" + stmt +
" as string)", lexical_cast<string>(val));
790 if (!timestamp_out_of_range) {
791 TestTimestampValue(
"cast(" + stmt +
" as timestamp)",
TimestampValue(val));
801 void ExprTest::TestCast(
const string& stmt,
const char* val,
802 bool timestamp_out_of_range) {
804 int8_t val8 =
static_cast<int8_t
>(lexical_cast<int16_t>(val));
807 TestValue(stmt +
" as boolean)",
TYPE_BOOLEAN, lexical_cast<bool>(val));
809 TestValue(
"cast(" + stmt +
" as tinyint)",
TYPE_TINYINT, val8);
810 TestValue(
"cast(" + stmt +
" as smallint)",
TYPE_SMALLINT, lexical_cast<int16_t>(val));
811 TestValue(
"cast(" + stmt +
" as int)",
TYPE_INT, lexical_cast<int32_t>(val));
812 TestValue(
"cast(" + stmt +
" as bigint)",
TYPE_BIGINT, lexical_cast<int64_t>(val));
813 TestValue(
"cast(" + stmt +
" as float)",
TYPE_FLOAT, lexical_cast<float>(val));
814 TestValue(
"cast(" + stmt +
" as double)",
TYPE_DOUBLE, lexical_cast<double>(val));
815 TestStringValue(
"cast(" + stmt +
" as string)", lexical_cast<string>(val));
816 }
catch (bad_lexical_cast& e) {
817 EXPECT_TRUE(
false) << e.what();
822 const ColumnType& type,
const T& value,
const string& string_val) {
825 RuntimeState state(TPlanFragmentInstanceCtx(),
"", NULL);
830 ctx.
Prepare(&state, desc, &tracker);
832 EXPECT_TRUE(status.
ok());
833 EXPECT_EQ(RawValue::Compare(ctx.
GetValue(NULL), &value, type), 0)
834 <<
"type: " << type <<
", value: " << value;
840 NullLiteral expr(static_cast<PrimitiveType>(type));
842 RuntimeState state(TPlanFragmentInstanceCtx(),
"", NULL);
845 EXPECT_TRUE(status.
ok());
846 status = ctx.
Open(&state);
847 EXPECT_TRUE(status.ok());
848 EXPECT_TRUE(ctx.
GetValue(NULL) == NULL);
858 int64_t l_val = 1234;
860 double d_val_1 = 1.23;
861 double d_val_2 = 7e6;
862 double d_val_3 = 5.9e-3;
863 string str_input =
"Hello";
864 StringValue str_val(const_cast<char*>(str_input.data()), str_input.length());
885 const char c_array_max[] = {(
const char)127};
886 string c_input_max(c_array_max, 1);
889 l_val = 9223372036854775807l;
895 const char c_array_min[] = {(
const char)(-128)};
896 string c_input_min(c_array_min, 1);
900 l_val = -9223372036854775807l-1;
911 TestFixedPointLimits<int32_t>(
TYPE_INT);
920 TestStringValue(
"'test'",
"test");
926 TestFixedResultTypeOps<float, float, double>(min_float_values_[
TYPE_FLOAT],
928 TestFixedResultTypeOps<float, double, double>(min_float_values_[
TYPE_FLOAT],
930 TestFixedResultTypeOps<double, double, double>(min_float_values_[
TYPE_DOUBLE],
935 TestFixedResultTypeOps<float, float, double>(numeric_limits<float>::min(),
937 TestFixedResultTypeOps<float, float, double>(numeric_limits<float>::max(),
939 TestFixedResultTypeOps<float, float, double>(numeric_limits<float>::min(),
941 TestFixedResultTypeOps<float, float, double>(numeric_limits<float>::max(),
943 TestFixedResultTypeOps<double, double, double>(numeric_limits<double>::min(),
945 TestFixedResultTypeOps<double, double, double>(numeric_limits<double>::max(),
947 TestFixedResultTypeOps<double, double, double>(numeric_limits<double>::min(),
949 TestFixedResultTypeOps<double, double, double>(numeric_limits<double>::max(),
953 TestFixedResultTypeOps<float, float, double>(min_float_values_[
TYPE_FLOAT],
955 TestFixedResultTypeOps<double, double, double>(min_float_values_[
TYPE_DOUBLE],
959 TestFixedResultTypeOps<int8_t, int8_t, int16_t>(min_int_values_[
TYPE_TINYINT],
961 TestFixedResultTypeOps<int8_t, int16_t, int32_t>(min_int_values_[
TYPE_TINYINT],
963 TestFixedResultTypeOps<int8_t, int32_t, int64_t>(min_int_values_[
TYPE_TINYINT],
965 TestFixedResultTypeOps<int8_t, int64_t, int64_t>(min_int_values_[
TYPE_TINYINT],
967 TestFixedResultTypeOps<int16_t, int16_t, int32_t>(min_int_values_[
TYPE_SMALLINT],
969 TestFixedResultTypeOps<int16_t, int32_t, int64_t>(min_int_values_[
TYPE_SMALLINT],
971 TestFixedResultTypeOps<int16_t, int64_t, int64_t>(min_int_values_[
TYPE_SMALLINT],
973 TestFixedResultTypeOps<int32_t, int32_t, int64_t>(min_int_values_[
TYPE_INT],
975 TestFixedResultTypeOps<int32_t, int64_t, int64_t>(min_int_values_[
TYPE_INT],
977 TestFixedResultTypeOps<int64_t, int64_t, int64_t>(min_int_values_[
TYPE_BIGINT],
981 TestFixedResultTypeOps<int64_t, int64_t, int64_t>(numeric_limits<int64_t>::min()+1,
983 TestFixedResultTypeOps<int64_t, int64_t, int64_t>(numeric_limits<int64_t>::max(),
985 TestFixedResultTypeOps<int64_t, int64_t, int64_t>(numeric_limits<int64_t>::min()+1,
987 TestFixedResultTypeOps<int64_t, int64_t, int64_t>(numeric_limits<int64_t>::max(),
991 TestNullOperandFixedResultTypeOps<float, double>(min_float_values_[
TYPE_FLOAT],
993 TestNullOperandFixedResultTypeOps<double, double>(min_float_values_[
TYPE_DOUBLE],
995 TestNullOperandFixedResultTypeOps<int8_t, int64_t>(min_int_values_[
TYPE_TINYINT],
997 TestNullOperandFixedResultTypeOps<int16_t, int64_t>(min_int_values_[
TYPE_SMALLINT],
999 TestNullOperandFixedResultTypeOps<int32_t, int64_t>(min_int_values_[
TYPE_INT],
1001 TestNullOperandFixedResultTypeOps<int64_t, int64_t>(min_int_values_[
TYPE_BIGINT],
1005 TestVariableResultTypeIntOps<int8_t, int8_t>(min_int_values_[
TYPE_TINYINT],
1007 TestVariableResultTypeIntOps<int8_t, int16_t>(min_int_values_[
TYPE_TINYINT],
1009 TestVariableResultTypeIntOps<int8_t, int32_t>(min_int_values_[
TYPE_TINYINT],
1011 TestVariableResultTypeIntOps<int8_t, int64_t>(min_int_values_[
TYPE_TINYINT],
1013 TestVariableResultTypeIntOps<int16_t, int16_t>(min_int_values_[
TYPE_SMALLINT],
1015 TestVariableResultTypeIntOps<int16_t, int32_t>(min_int_values_[
TYPE_SMALLINT],
1017 TestVariableResultTypeIntOps<int16_t, int64_t>(min_int_values_[
TYPE_SMALLINT],
1019 TestVariableResultTypeIntOps<int32_t, int32_t>(min_int_values_[
TYPE_INT],
1021 TestVariableResultTypeIntOps<int32_t, int64_t>(min_int_values_[
TYPE_INT],
1023 TestVariableResultTypeIntOps<int64_t, int64_t>(min_int_values_[
TYPE_BIGINT],
1027 IntValMap::iterator int_iter;
1028 for(int_iter = min_int_values_.begin(); int_iter != min_int_values_.end();
1030 string& val = default_type_strs_[int_iter->first];
1031 TestIsNull(val +
" DIV 0", static_cast<PrimitiveType>(int_iter->first));
1032 TestIsNull(val +
" % 0", static_cast<PrimitiveType>(int_iter->first));
1036 TestNullOperandVariableResultTypeIntOps<int8_t>(min_int_values_[
TYPE_TINYINT],
1038 TestNullOperandVariableResultTypeIntOps<int16_t>(min_int_values_[
TYPE_SMALLINT],
1040 TestNullOperandVariableResultTypeIntOps<int32_t>(min_int_values_[
TYPE_INT],
1042 TestNullOperandVariableResultTypeIntOps<int64_t>(min_int_values_[
TYPE_BIGINT],
1057 TestNullOperandsArithmeticOps();
1061 TestDecimalValue(
"1.23 + cast(1 as decimal(4,3))",
1063 TestDecimalValue(
"1.23 - cast(0.23 as decimal(10,3))",
1065 TestDecimalValue(
"1.23 * cast(1 as decimal(20,3))",
1066 Decimal4Value(123000), ColumnType::CreateDecimalType(23,5));
1067 TestDecimalValue(
"cast(1.23 as decimal(8,2)) / cast(1 as decimal(4,3))",
1068 Decimal4Value(12300000), ColumnType::CreateDecimalType(16,7));
1069 TestDecimalValue(
"cast(1.23 as decimal(8,2)) % cast(1 as decimal(10,3))",
1071 TestDecimalValue(
"cast(1.23 as decimal(8,2)) + cast(1 as decimal(20,3))",
1073 TestDecimalValue(
"cast(1.23 as decimal(30,2)) - cast(1 as decimal(4,3))",
1075 TestDecimalValue(
"cast(1.23 as decimal(30,2)) * cast(1 as decimal(10,3))",
1076 Decimal4Value(123000), ColumnType::CreateDecimalType(38,5));
1077 TestDecimalValue(
"cast(1.23 as decimal(30,2)) / cast(1 as decimal(20,3))",
1079 TestDecimalValue(
"cast(1 as decimal(38,0)) + cast(.2 as decimal(38,1))",
1081 TestDecimalValue(
"cast(1 as decimal(38,0)) / cast(.2 as decimal(38,1))",
1085 TestDecimalValue(
"mod(cast('1' as decimal(2,0)), cast('10' as decimal(2,0)))",
1087 TestDecimalValue(
"mod(cast('1.1' as decimal(2,1)), cast('1.0' as decimal(2,1)))",
1089 TestDecimalValue(
"mod(cast('-1.23' as decimal(5,2)), cast('1.0' as decimal(5,2)))",
1091 TestDecimalValue(
"mod(cast('1' as decimal(12,0)), cast('10' as decimal(12,0)))",
1093 TestDecimalValue(
"mod(cast('1.1' as decimal(12,1)), cast('1.0' as decimal(12,1)))",
1095 TestDecimalValue(
"mod(cast('-1.23' as decimal(12,2)), cast('1.0' as decimal(12,2)))",
1097 TestDecimalValue(
"mod(cast('1' as decimal(32,0)), cast('10' as decimal(32,0)))",
1099 TestDecimalValue(
"mod(cast('1.1' as decimal(32,1)), cast('1.0' as decimal(32,1)))",
1101 TestDecimalValue(
"mod(cast('-1.23' as decimal(32,2)), cast('1.0' as decimal(32,2)))",
1103 TestIsNull(
"mod(cast(NULL as decimal(2,0)), cast('10' as decimal(2,0)))",
1104 ColumnType::CreateDecimalType(2,0));
1105 TestIsNull(
"mod(cast('10' as decimal(2,0)), cast(NULL as decimal(2,0)))",
1106 ColumnType::CreateDecimalType(2,0));
1107 TestIsNull(
"mod(cast('10' as decimal(2,0)), cast('0' as decimal(2,0)))",
1108 ColumnType::CreateDecimalType(2,0));
1109 TestIsNull(
"mod(cast('10' as decimal(2,0)), cast('0' as decimal(2,0)))",
1110 ColumnType::CreateDecimalType(2,0));
1111 TestIsNull(
"mod(cast(NULL as decimal(2,0)), NULL)",
1112 ColumnType::CreateDecimalType(2,0));
1118 TestComparison(
"false",
"true",
false);
1119 TestBinaryPredicates(
"false",
false);
1120 TestBinaryPredicates(
"true",
false);
1121 TestFixedPointComparisons<int8_t>(
true);
1122 TestFixedPointComparisons<int16_t>(
true);
1123 TestFixedPointComparisons<int32_t>(
true);
1124 TestFixedPointComparisons<int64_t>(
false);
1125 TestFloatingPointComparisons<float>(
true);
1126 TestFloatingPointComparisons<double>(
false);
1127 TestStringComparisons();
1128 TestDecimalComparisons();
1129 TestNullComparisons();
1135 TestCast(
"cast(0 as tinyint)", 0);
1136 TestCast(
"cast(5 as tinyint)", 5);
1137 TestCast(
"cast(-5 as tinyint)", -5);
1140 TestCast(
"cast(0 as smallint)", 0);
1141 TestCast(
"cast(5 as smallint)", 5);
1142 TestCast(
"cast(-5 as smallint)", -5);
1145 TestCast(
"cast(0 as int)", 0);
1146 TestCast(
"cast(5 as int)", 5);
1147 TestCast(
"cast(-5 as int)", -5);
1150 TestCast(
"cast(0 as bigint)", 0);
1151 TestCast(
"cast(5 as bigint)", 5);
1152 TestCast(
"cast(-5 as bigint)", -5);
1155 TestCast(
"cast(0 as boolean)", 0);
1156 TestCast(
"cast(5 as boolean)", 1);
1157 TestCast(
"cast(-5 as boolean)", 1);
1160 TestCast(
"cast(0.0 as float)", 0.0f);
1161 TestCast(
"cast(5.0 as float)", 5.0f);
1162 TestCast(
"cast(-5.0 as float)", -5.0f);
1163 TestCast(
"cast(0.1234567890123 as float)", 0.1234567890123f);
1164 TestCast(
"cast(0.1234567890123 as float)", 0.123456791f);
1165 TestCast(
"cast(0.00000000001234567890123 as float)", 0.00000000001234567890123f);
1166 TestCast(
"cast(123456 as float)", 123456.0f);
1170 TestCast(
"cast(1.1754944e-38 as float)", 1.1754944e-38f);
1172 TestCast(
"cast(3.4028234e38 as float)", 3.4028234e38f,
true);
1176 TestCast(
"cast(0.0 as double)", 0.0);
1177 TestCast(
"cast(5.0 as double)", 5.0);
1178 TestCast(
"cast(-5.0 as double)", -5.0);
1179 TestCast(
"cast(0.123e10 as double)", 0.123e10);
1180 TestCast(
"cast(123.123e10 as double)", 123.123e10,
true);
1181 TestCast(
"cast(1.01234567890123456789 as double)", 1.01234567890123456789);
1182 TestCast(
"cast(1.01234567890123456789 as double)", 1.0123456789012346);
1183 TestCast(
"cast(0.01234567890123456789 as double)", 0.01234567890123456789);
1184 TestCast(
"cast(0.1234567890123456789 as double)", 0.1234567890123456789);
1185 TestCast(
"cast(-2.2250738585072020E-308 as double)", -2.2250738585072020e-308);
1189 TestCast(
"cast(4.9406564584124654e-324 as double)", 4.9406564584124654e-324);
1191 TestCast(
"cast(2.2250738585072009e-308 as double)", 2.2250738585072009e-308);
1193 TestCast(
"cast(2.2250738585072014e-308 as double)", 2.2250738585072014e-308);
1195 TestCast(
"cast(1.7976931348623157e+308 as double)", 1.7976931348623157e308,
true);
1198 TestCast(
"'0'",
"0");
1199 TestCast(
"'5'",
"5");
1200 TestCast(
"'-5'",
"-5");
1201 TestStringValue(
"cast(\"abc\" as string)",
"abc");
1204 TestStringValue(
"cast(cast(cast('2012-01-01 09:10:11.123456789' as timestamp) as"
1205 " timestamp) as string)",
"2012-01-01 09:10:11.123456789");
1209 TestIsNull(
"cast(cast('09:10:11.000000' as timestamp) as int)",
TYPE_INT);
1210 TestValue(
"cast(cast('2000-01-01' as timestamp) as int)",
TYPE_INT, 946684800);
1213 TestValue(
"cast(cast('2000-01-01' as timestamp) as tinyint)",
TYPE_TINYINT, -128);
1214 TestValue(
"cast(946684800 as tinyint)",
TYPE_TINYINT, -128);
1215 TestValue(
"cast(cast('2000-01-01 09:10:11.000000' as timestamp) as int)",
TYPE_INT,
1217 TestTimestampValue(
"cast(946717811 as timestamp)",
1219 TestValue(
"cast(cast('1400-01-01' as timestamp) as bigint)",
TYPE_BIGINT, -17987443200);
1220 TestTimestampValue(
"cast(-17987443200 as timestamp)",
TimestampValue(
"1400-01-01", 10));
1223 TestIsNull(
"cast(cast('09:10:11.000000' as timestamp) as float)",
TYPE_FLOAT);
1224 TestValue(
"cast(cast('2000-01-01' as timestamp) as double)",
TYPE_DOUBLE, 946684800);
1225 TestValue(
"cast(cast('2000-01-01' as timestamp) as float)",
TYPE_FLOAT, 946684800);
1226 TestValue(
"cast(cast('2000-01-01 09:10:11.720000' as timestamp) as double)",
1228 TestTimestampValue(
"cast(cast(946717811.033 as double) as timestamp)",
1230 TestValue(
"cast(cast('1400-01-01' as timestamp) as double)",
TYPE_DOUBLE,
1232 TestIsNull(
"cast(cast(-17987443201.03 as double) as timestamp)",
TYPE_TIMESTAMP);
1234 TestValue(
"cast(cast('9999-12-31 23:59:59' as timestamp) + interval 1 year as bigint)",
1236 TestTimestampValue(
"cast(253433923199 as timestamp) - interval 1 year",
1239 TestIsNull(
"cast(cast(null as bigint) as timestamp)",
TYPE_TIMESTAMP);
1240 TestIsNull(
"cast(cast(null as timestamp) as bigint)",
TYPE_BIGINT);
1247 TestValue<int8_t>(
"cast(10000000 as tinyint)",
TYPE_TINYINT, val & 0xff);
1248 TestValue<int8_t>(
"cast(-10000000 as tinyint)",
TYPE_TINYINT, -val & 0xff);
1249 TestValue<int16_t>(
"cast(10000000 as smallint)",
TYPE_SMALLINT, val & 0xffff);
1250 TestValue<int16_t>(
"cast(-10000000 as smallint)",
TYPE_SMALLINT, -val & 0xffff);
1275 TestValue(
"TRUE AND (TRUE OR FALSE)",
TYPE_BOOLEAN,
true);
1276 TestValue(
"(TRUE AND TRUE) OR FALSE",
TYPE_BOOLEAN,
true);
1277 TestValue(
"(TRUE OR FALSE) AND TRUE",
TYPE_BOOLEAN,
true);
1278 TestValue(
"TRUE OR (FALSE AND TRUE)",
TYPE_BOOLEAN,
true);
1279 TestValue(
"TRUE AND TRUE OR FALSE",
TYPE_BOOLEAN,
true);
1280 TestValue(
"TRUE && (TRUE || FALSE)",
TYPE_BOOLEAN,
true);
1281 TestValue(
"(TRUE && TRUE) || FALSE",
TYPE_BOOLEAN,
true);
1282 TestValue(
"(TRUE || FALSE) && TRUE",
TYPE_BOOLEAN,
true);
1283 TestValue(
"TRUE || (FALSE && TRUE)",
TYPE_BOOLEAN,
true);
1284 TestValue(
"TRUE && TRUE || FALSE",
TYPE_BOOLEAN,
true);
1316 TestValue(
"'abcde' LIKE 'abcde%'",
TYPE_BOOLEAN,
true);
1317 TestValue(
"'abcde' LIKE '%abcde'",
TYPE_BOOLEAN,
true);
1318 TestValue(
"'abcde' LIKE '%abcde%'",
TYPE_BOOLEAN,
true);
1320 TestValue(
"'abcde' LIKE '%%bc%%'",
TYPE_BOOLEAN,
true);
1321 TestValue(
"'abcde' LIKE '%%cb%%'",
TYPE_BOOLEAN,
false);
1323 TestValue(
"'abcde' LIKE 'cba%%'",
TYPE_BOOLEAN,
false);
1324 TestValue(
"'abcde' LIKE '%%bcde'",
TYPE_BOOLEAN,
true);
1325 TestValue(
"'abcde' LIKE '%%cbde'",
TYPE_BOOLEAN,
false);
1326 TestValue(
"'abcde' LIKE '%%bc%%'",
TYPE_BOOLEAN,
true);
1327 TestValue(
"'abcde' LIKE '%%cb%%'",
TYPE_BOOLEAN,
false);
1328 TestValue(
"'abcde' LIKE '%%abcde%%'",
TYPE_BOOLEAN,
true);
1329 TestValue(
"'abcde' LIKE '%%edcba%%'",
TYPE_BOOLEAN,
false);
1331 TestValue(
"'abcde' NOT LIKE '%%'",
TYPE_BOOLEAN,
false);
1333 TestValue(
"'abcde' NOT LIKE '%%%'",
TYPE_BOOLEAN,
false);
1334 TestValue(
"'abcde' LIKE '%%cd%%'",
TYPE_BOOLEAN,
true);
1335 TestValue(
"'abcde' LIKE '%%dc%%'",
TYPE_BOOLEAN,
false);
1350 TestValue(
"'LARGE BRUSHED BRASS' LIKE '%BRASS'",
TYPE_BOOLEAN,
true);
1351 TestValue(
"'BRASS LARGE BRUSHED' LIKE '%BRASS'",
TYPE_BOOLEAN,
false);
1352 TestValue(
"'BRASS LARGE BRUSHED' LIKE 'BRUSHED%'",
TYPE_BOOLEAN,
false);
1353 TestValue(
"'BRASS LARGE BRUSHED' LIKE 'BRASS%'",
TYPE_BOOLEAN,
true);
1354 TestValue(
"'prefix1234' LIKE 'prefix%'",
TYPE_BOOLEAN,
true);
1355 TestValue(
"'1234suffix' LIKE '%suffix'",
TYPE_BOOLEAN,
true);
1356 TestValue(
"'1234substr5678' LIKE '%substr%'",
TYPE_BOOLEAN,
true);
1358 TestValue(
"'a123a' LIKE 'a\\%a'",
TYPE_BOOLEAN,
false);
1363 TestValue(
"'abxcy1234a' LIKE 'a_x_y%a'",
TYPE_BOOLEAN,
true);
1364 TestValue(
"'axcy1234a' LIKE 'a_x_y%a'",
TYPE_BOOLEAN,
false);
1365 TestValue(
"'abxcy1234a' REGEXP 'a.x.y.*a'",
TYPE_BOOLEAN,
true);
1366 TestValue(
"'a.x.y.*a' REGEXP 'a\\\\.x\\\\.y\\\\.\\\\*a'",
TYPE_BOOLEAN,
true);
1367 TestValue(
"'abxcy1234a' REGEXP '\\a\\.x\\\\.y\\\\.\\\\*a'",
TYPE_BOOLEAN,
false);
1368 TestValue(
"'abxcy1234a' RLIKE 'a.x.y.*a'",
TYPE_BOOLEAN,
true);
1369 TestValue(
"'axcy1234a' REGEXP 'a.x.y.*a'",
TYPE_BOOLEAN,
false);
1370 TestValue(
"'axcy1234a' RLIKE 'a.x.y.*a'",
TYPE_BOOLEAN,
false);
1372 TestValue(
"'english' REGEXP 'en'",
TYPE_BOOLEAN,
true);
1373 TestValue(
"'english' REGEXP 'lis'",
TYPE_BOOLEAN,
true);
1374 TestValue(
"'english' REGEXP 'english'",
TYPE_BOOLEAN,
true);
1375 TestValue(
"'english' REGEXP 'engilsh'",
TYPE_BOOLEAN,
false);
1376 TestValue(
"'english' REGEXP '^english$'",
TYPE_BOOLEAN,
true);
1377 TestValue(
"'english' REGEXP '^lish$'",
TYPE_BOOLEAN,
false);
1378 TestValue(
"'english' REGEXP '^eng'",
TYPE_BOOLEAN,
true);
1379 TestValue(
"'english' REGEXP '^ng'",
TYPE_BOOLEAN,
false);
1380 TestValue(
"'english' REGEXP 'lish$'",
TYPE_BOOLEAN,
true);
1381 TestValue(
"'english' REGEXP 'lis$'",
TYPE_BOOLEAN,
false);
1384 TestValue(
"'.[]{}()x\\\\*+?|^$' LIKE '.[]{}()_\\\\\\\\*+?|^$'",
TYPE_BOOLEAN,
true);
1386 TestValue(
"'\\\\_' LIKE '\\\\_'",
TYPE_BOOLEAN,
false);
1390 TestValue(
"'\\\\a' LIKE '\\\\\\_'",
TYPE_BOOLEAN,
true);
1393 TestValue(
"'\\\\_' LIKE '\\\\\\\\\\_'",
TYPE_BOOLEAN,
true);
1394 TestValue(
"'\\\\\\\\a' LIKE '\\\\\\\\\\_'",
TYPE_BOOLEAN,
false);
1396 TestNonOkStatus(
"'a' RLIKE '(./'");
1397 TestNonOkStatus(
"'a' REGEXP '(./'");
1418 TestValue(
"5 not between 0 and 10",
TYPE_BOOLEAN,
false);
1419 TestValue(
"5 not between 5 and 5",
TYPE_BOOLEAN,
false);
1420 TestValue(
"5 not between 6 and 10",
TYPE_BOOLEAN,
true);
1423 TestValue(
"5+1 not between 4 and 10",
TYPE_BOOLEAN,
false);
1425 TestValue(
"cast('2011-10-22 09:10:11' as timestamp) between "
1426 "cast('2011-09-22 09:10:11' as timestamp) and "
1427 "cast('2011-12-22 09:10:11' as timestamp)",
TYPE_BOOLEAN,
true);
1428 TestValue(
"cast('2011-10-22 09:10:11' as timestamp) between "
1429 "cast('2011-11-22 09:10:11' as timestamp) and "
1430 "cast('2011-12-22 09:10:11' as timestamp)",
TYPE_BOOLEAN,
false);
1431 TestValue(
"cast('2011-10-22 09:10:11' as timestamp) not between "
1432 "cast('2011-09-22 09:10:11' as timestamp) and "
1433 "cast('2011-12-22 09:10:11' as timestamp)",
TYPE_BOOLEAN,
false);
1434 TestValue(
"cast('2011-10-22 09:10:11' as timestamp) not between "
1435 "cast('2011-11-22 09:10:11' as timestamp) and "
1436 "cast('2011-12-22 09:10:11' as timestamp)",
TYPE_BOOLEAN,
true);
1438 TestValue(
"'abc' between 'a' and 'z'",
TYPE_BOOLEAN,
true);
1439 TestValue(
"'abc' between 'aaa' and 'aab'",
TYPE_BOOLEAN,
false);
1440 TestValue(
"'abc' not between 'a' and 'z'",
TYPE_BOOLEAN,
false);
1441 TestValue(
"'abc' not between 'aaa' and 'aab'",
TYPE_BOOLEAN,
true);
1447 TestIsNull(
"NULL between NULL and NULL",
TYPE_BOOLEAN);
1453 IntValMap::iterator int_iter;
1454 for(int_iter = min_int_values_.begin(); int_iter != min_int_values_.end();
1456 string& val = default_type_strs_[int_iter->first];
1457 TestValue(val +
" in (2, 3, " + val +
")",
TYPE_BOOLEAN,
true);
1459 TestValue(val +
" not in (2, 3, " + val +
")",
TYPE_BOOLEAN,
false);
1460 TestValue(val +
" not in (2, 3, 4)",
TYPE_BOOLEAN,
true);
1464 unordered_map<int, double>::iterator float_iter;
1465 for(float_iter = min_float_values_.begin(); float_iter != min_float_values_.end();
1467 string& val = default_type_strs_[float_iter->first];
1468 TestValue(val +
" in (2, 3, " + val +
")",
TYPE_BOOLEAN,
true);
1470 TestValue(val +
" not in (2, 3, " + val +
")",
TYPE_BOOLEAN,
false);
1471 TestValue(val +
" not in (2, 3, 4)",
TYPE_BOOLEAN,
true);
1475 TestValue(
"true in (true, false, false)",
TYPE_BOOLEAN,
true);
1476 TestValue(
"true in (false, false, false)",
TYPE_BOOLEAN,
false);
1477 TestValue(
"true not in (true, false, false)",
TYPE_BOOLEAN,
false);
1478 TestValue(
"true not in (false, false, false)",
TYPE_BOOLEAN,
true);
1481 TestValue(
"'ab' in ('ab', 'cd', 'efg')",
TYPE_BOOLEAN,
true);
1482 TestValue(
"'ab' in ('cd', 'efg', 'h')",
TYPE_BOOLEAN,
false);
1483 TestValue(
"'ab' not in ('ab', 'cd', 'efg')",
TYPE_BOOLEAN,
false);
1484 TestValue(
"'ab' not in ('cd', 'efg', 'h')",
TYPE_BOOLEAN,
true);
1487 TestValue(
"cast('ab' as char(2)) in (cast('ab' as char(2)), cast('cd' as char(2)))",
1491 TestValue(default_timestamp_str_ +
" "
1492 "in (cast('2011-11-23 09:10:11' as timestamp), "
1493 "cast('2011-11-24 09:11:12' as timestamp), " +
1495 TestValue(default_timestamp_str_ +
" "
1496 "in (cast('2011-11-22 09:10:11' as timestamp), "
1497 "cast('2011-11-23 09:11:12' as timestamp), "
1498 "cast('2011-11-24 09:12:13' as timestamp))",
TYPE_BOOLEAN,
false);
1499 TestValue(default_timestamp_str_ +
" "
1500 "not in (cast('2011-11-22 09:10:11' as timestamp), "
1501 "cast('2011-11-23 09:11:12' as timestamp), " +
1503 TestValue(default_timestamp_str_ +
" "
1504 "not in (cast('2011-11-22 09:10:11' as timestamp), "
1505 "cast('2011-11-23 09:11:12' as timestamp), "
1506 "cast('2011-11-24 09:12:13' as timestamp))",
TYPE_BOOLEAN,
true);
1509 vector<string> dec_strs;
1510 dec_strs.push_back(
"cast(-1.23 as decimal(8,2))");
1511 dec_strs.push_back(
"cast(-1.23 as decimal(9,2))");
1512 dec_strs.push_back(
"cast(-1.23 as decimal(10,2))");
1513 dec_strs.push_back(
"cast(-1.23 as decimal(17,2))");
1514 dec_strs.push_back(
"cast(-1.23 as decimal(18,2))");
1515 dec_strs.push_back(
"cast(-1.23 as decimal(19,2))");
1516 dec_strs.push_back(
"cast(-1.23 as decimal(32,2))");
1517 BOOST_FOREACH(
const string& dec_str, dec_strs) {
1520 TestValue(dec_str +
"in (-1.230)",
TYPE_BOOLEAN,
true);
1521 TestValue(dec_str +
"in (-1.23, 1)",
TYPE_BOOLEAN,
true);
1522 TestValue(dec_str +
"in (1, 1, 1, 1, 1, -1.23, 1, 1, 1, 1, 1, 1, -1.23)",
1524 TestValue(dec_str +
"in (1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1.23)",
1527 TestValue(dec_str +
"in (1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)",
TYPE_BOOLEAN,
false);
1530 TestIsNull(dec_str +
"in (1, 1, 1, 1, 1, 1, 1, 1, 1, 1, NULL)",
TYPE_BOOLEAN);
1531 TestValue(dec_str +
"in (1, 1, 1, 1, 1, NULL, 1, 1, 1, 1, 1, 1, -1.23)",
1537 TestValue(
"5+1 not in (3, 6, 10)",
TYPE_BOOLEAN,
false);
1546 TestValue(
"'hello' in ('hello', NULL)",
TYPE_BOOLEAN,
true);
1552 TestStringValue(
"substring('Hello', 1)",
"Hello");
1553 TestStringValue(
"substring('Hello', -2)",
"lo");
1554 TestStringValue(
"substring('Hello', cast(0 as bigint))",
"");
1555 TestStringValue(
"substring('Hello', -5)",
"Hello");
1556 TestStringValue(
"substring('Hello', cast(-6 as bigint))",
"");
1557 TestStringValue(
"substring('Hello', 100)",
"");
1558 TestStringValue(
"substring('Hello', -100)",
"");
1560 TestIsNull(
"substring('Hello', NULL)",
TYPE_STRING);
1563 TestStringValue(
"substring('Hello', 1, 1)",
"H");
1564 TestStringValue(
"substring('Hello', cast(2 as bigint), 100)",
"ello");
1565 TestStringValue(
"substring('Hello', -3, cast(2 as bigint))",
"ll");
1566 TestStringValue(
"substring('Hello', 1, 0)",
"");
1567 TestStringValue(
"substring('Hello', cast(1 as bigint), cast(-1 as bigint))",
"");
1568 TestIsNull(
"substring(NULL, 1, 100)",
TYPE_STRING);
1569 TestIsNull(
"substring('Hello', NULL, 100)",
TYPE_STRING);
1570 TestIsNull(
"substring('Hello', 1, NULL)",
TYPE_STRING);
1571 TestIsNull(
"substring(NULL, NULL, NULL)",
TYPE_STRING);
1573 TestStringValue(
"lower('')",
"");
1574 TestStringValue(
"lower('HELLO')",
"hello");
1575 TestStringValue(
"lower('Hello')",
"hello");
1576 TestStringValue(
"lower('hello!')",
"hello!");
1577 TestStringValue(
"lcase('HELLO')",
"hello");
1581 TestStringValue(
"upper('')",
"");
1582 TestStringValue(
"upper('HELLO')",
"HELLO");
1583 TestStringValue(
"upper('Hello')",
"HELLO");
1584 TestStringValue(
"upper('hello!')",
"HELLO!");
1585 TestStringValue(
"ucase('hello')",
"HELLO");
1589 TestStringValue(
"initcap('')",
"");
1590 TestStringValue(
"initcap('a')",
"A");
1591 TestStringValue(
"initcap('hello')",
"Hello");
1592 TestStringValue(
"initcap('h e l l o')",
"H E L L O");
1593 TestStringValue(
"initcap('hello this is a message')",
"Hello This Is A Message");
1594 TestStringValue(
"initcap('Hello This Is A Message')",
"Hello This Is A Message");
1595 TestStringValue(
"initcap(' hello tHis IS A _ MeSsAgE')",
" Hello This "
1597 TestStringValue(
"initcap('HELLO THIS IS A MESSAGE')",
"Hello This Is A Message");
1598 TestStringValue(
"initcap(' hello\vthis\nis\ra\tlong\fmessage')",
" Hello\vThis"
1599 "\nIs\rA\tLong\fMessage");
1602 string length_aliases[] = {
"length",
"char_length",
"character_length"};
1603 for (
int i = 0; i < 3; i++) {
1604 TestValue(length_aliases[i] +
"('')",
TYPE_INT, 0);
1605 TestValue(length_aliases[i] +
"('a')",
TYPE_INT, 1);
1606 TestValue(length_aliases[i] +
"('abcdefg')",
TYPE_INT, 7);
1607 TestIsNull(length_aliases[i] +
"(NULL)",
TYPE_INT);
1610 TestStringValue(
"reverse('abcdefg')",
"gfedcba");
1611 TestStringValue(
"reverse('')",
"");
1613 TestStringValue(
"strleft('abcdefg', 0)",
"");
1614 TestStringValue(
"strleft('abcdefg', 3)",
"abc");
1615 TestStringValue(
"strleft('abcdefg', cast(10 as bigint))",
"abcdefg");
1616 TestStringValue(
"strleft('abcdefg', -1)",
"");
1617 TestStringValue(
"strleft('abcdefg', cast(-9 as bigint))",
"");
1619 TestIsNull(
"strleft('abcdefg', NULL)",
TYPE_STRING);
1621 TestStringValue(
"strright('abcdefg', 0)",
"");
1622 TestStringValue(
"strright('abcdefg', 3)",
"efg");
1623 TestStringValue(
"strright('abcdefg', cast(10 as bigint))",
"abcdefg");
1624 TestStringValue(
"strright('abcdefg', -1)",
"");
1625 TestStringValue(
"strright('abcdefg', cast(-9 as bigint))",
"");
1627 TestIsNull(
"strright('abcdefg', NULL)",
TYPE_STRING);
1630 TestStringValue(
"translate('', '', '')",
"");
1631 TestStringValue(
"translate('abcd', '', '')",
"abcd");
1632 TestStringValue(
"translate('abcd', 'xyz', '')",
"abcd");
1633 TestStringValue(
"translate('abcd', 'a', '')",
"bcd");
1634 TestStringValue(
"translate('abcd', 'aa', '')",
"bcd");
1635 TestStringValue(
"translate('abcd', 'aba', '')",
"cd");
1636 TestStringValue(
"translate('abcd', 'cd', '')",
"ab");
1637 TestStringValue(
"translate('abcd', 'cd', 'xy')",
"abxy");
1638 TestStringValue(
"translate('abcdabcd', 'cd', 'xy')",
"abxyabxy");
1639 TestStringValue(
"translate('abcd', 'abc', 'xy')",
"xyd");
1640 TestStringValue(
"translate('abcd', 'abc', 'wxyz')",
"wxyd");
1641 TestStringValue(
"translate('x', 'xx', 'ab')",
"a");
1642 TestIsNull(
"translate(NULL, '', '')",
TYPE_STRING);
1643 TestIsNull(
"translate('', NULL, '')",
TYPE_STRING);
1644 TestIsNull(
"translate('', '', NULL)",
TYPE_STRING);
1646 TestStringValue(
"trim('')",
"");
1647 TestStringValue(
"trim(' ')",
"");
1648 TestStringValue(
"trim(' abcdefg ')",
"abcdefg");
1649 TestStringValue(
"trim('abcdefg ')",
"abcdefg");
1650 TestStringValue(
"trim(' abcdefg')",
"abcdefg");
1651 TestStringValue(
"trim('abc defg')",
"abc defg");
1653 TestStringValue(
"ltrim('')",
"");
1654 TestStringValue(
"ltrim(' ')",
"");
1655 TestStringValue(
"ltrim(' abcdefg ')",
"abcdefg ");
1656 TestStringValue(
"ltrim('abcdefg ')",
"abcdefg ");
1657 TestStringValue(
"ltrim(' abcdefg')",
"abcdefg");
1658 TestStringValue(
"ltrim('abc defg')",
"abc defg");
1660 TestStringValue(
"rtrim('')",
"");
1661 TestStringValue(
"rtrim(' ')",
"");
1662 TestStringValue(
"rtrim(' abcdefg ')",
" abcdefg");
1663 TestStringValue(
"rtrim('abcdefg ')",
"abcdefg");
1664 TestStringValue(
"rtrim(' abcdefg')",
" abcdefg");
1665 TestStringValue(
"rtrim('abc defg')",
"abc defg");
1668 TestStringValue(
"space(0)",
"");
1669 TestStringValue(
"space(-1)",
"");
1670 TestStringValue(
"space(cast(1 as bigint))",
" ");
1671 TestStringValue(
"space(6)",
" ");
1674 TestStringValue(
"repeat('', 0)",
"");
1675 TestStringValue(
"repeat('', cast(6 as bigint))",
"");
1676 TestStringValue(
"repeat('ab', 0)",
"");
1677 TestStringValue(
"repeat('ab', -1)",
"");
1678 TestStringValue(
"repeat('ab', -100)",
"");
1679 TestStringValue(
"repeat('ab', 1)",
"ab");
1680 TestStringValue(
"repeat('ab', cast(6 as bigint))",
"abababababab");
1685 TestValue(
"ascii('')",
TYPE_INT, 0);
1686 TestValue(
"ascii('abcde')",
TYPE_INT,
'a');
1687 TestValue(
"ascii('Abcde')",
TYPE_INT,
'A');
1688 TestValue(
"ascii('dddd')",
TYPE_INT,
'd');
1689 TestValue(
"ascii(' ')",
TYPE_INT,
' ');
1690 TestIsNull(
"ascii(NULL)",
TYPE_INT);
1692 TestStringValue(
"lpad('', 0, '')",
"");
1693 TestStringValue(
"lpad('abc', 0, '')",
"");
1694 TestStringValue(
"lpad('abc', cast(3 as bigint), '')",
"abc");
1695 TestStringValue(
"lpad('abc', 2, 'xyz')",
"ab");
1696 TestStringValue(
"lpad('abc', 6, 'xyz')",
"xyzabc");
1697 TestStringValue(
"lpad('abc', cast(5 as bigint), 'xyz')",
"xyabc");
1698 TestStringValue(
"lpad('abc', 10, 'xyz')",
"xyzxyzxabc");
1699 TestIsNull(
"lpad('abc', -10, 'xyz')",
TYPE_STRING);
1701 TestIsNull(
"lpad('abc', NULL, 'xyz')",
TYPE_STRING);
1703 TestIsNull(
"lpad(NULL, NULL, NULL)",
TYPE_STRING);
1704 TestStringValue(
"rpad('', 0, '')",
"");
1705 TestStringValue(
"rpad('abc', 0, '')",
"");
1706 TestStringValue(
"rpad('abc', cast(3 as bigint), '')",
"abc");
1707 TestStringValue(
"rpad('abc', 2, 'xyz')",
"ab");
1708 TestStringValue(
"rpad('abc', 6, 'xyz')",
"abcxyz");
1709 TestStringValue(
"rpad('abc', cast(5 as bigint), 'xyz')",
"abcxy");
1710 TestStringValue(
"rpad('abc', 10, 'xyz')",
"abcxyzxyzx");
1711 TestIsNull(
"rpad('abc', -10, 'xyz')",
TYPE_STRING);
1713 TestIsNull(
"rpad('abc', NULL, 'xyz')",
TYPE_STRING);
1715 TestIsNull(
"rpad(NULL, NULL, NULL)",
TYPE_STRING);
1719 TestValue(
"instr('', '')",
TYPE_INT, 0);
1720 TestValue(
"instr('', 'abc')",
TYPE_INT, 0);
1721 TestValue(
"instr('abc', '')",
TYPE_INT, 0);
1722 TestValue(
"instr('abc', 'abc')",
TYPE_INT, 1);
1723 TestValue(
"instr('xyzabc', 'abc')",
TYPE_INT, 4);
1724 TestValue(
"instr('xyzabcxyz', 'bcx')",
TYPE_INT, 5);
1725 TestIsNull(
"instr(NULL, 'bcx')",
TYPE_INT);
1726 TestIsNull(
"instr('xyzabcxyz', NULL)",
TYPE_INT);
1727 TestIsNull(
"instr(NULL, NULL)",
TYPE_INT);
1728 TestValue(
"locate('', '')",
TYPE_INT, 0);
1729 TestValue(
"locate('abc', '')",
TYPE_INT, 0);
1730 TestValue(
"locate('', 'abc')",
TYPE_INT, 0);
1731 TestValue(
"locate('abc', 'abc')",
TYPE_INT, 1);
1732 TestValue(
"locate('abc', 'xyzabc')",
TYPE_INT, 4);
1733 TestValue(
"locate('bcx', 'xyzabcxyz')",
TYPE_INT, 5);
1734 TestIsNull(
"locate(NULL, 'xyzabcxyz')",
TYPE_INT);
1735 TestIsNull(
"locate('bcx', NULL)",
TYPE_INT);
1736 TestIsNull(
"locate(NULL, NULL)",
TYPE_INT);
1740 TestValue(
"locate('', '', 0)",
TYPE_INT, 0);
1741 TestValue(
"locate('abc', '', cast(0 as bigint))",
TYPE_INT, 0);
1742 TestValue(
"locate('', 'abc', 0)",
TYPE_INT, 0);
1743 TestValue(
"locate('', 'abc', -1)",
TYPE_INT, 0);
1744 TestValue(
"locate('', '', 1)",
TYPE_INT, 0);
1745 TestValue(
"locate('', 'abcde', cast(10 as bigint))",
TYPE_INT, 0);
1746 TestValue(
"locate('abcde', 'abcde', -1)",
TYPE_INT, 0);
1747 TestValue(
"locate('abcde', 'abcde', 10)",
TYPE_INT, 0);
1748 TestValue(
"locate('abc', 'abcdef', 0)",
TYPE_INT, 0);
1749 TestValue(
"locate('abc', 'abcdef', 1)",
TYPE_INT, 1);
1750 TestValue(
"locate('abc', 'xyzabcdef', 3)",
TYPE_INT, 4);
1751 TestValue(
"locate('abc', 'xyzabcdef', 4)",
TYPE_INT, 4);
1752 TestValue(
"locate('abc', 'abcabcabc', cast(5 as bigint))",
TYPE_INT, 7);
1753 TestIsNull(
"locate(NULL, 'abcabcabc', 5)",
TYPE_INT);
1754 TestIsNull(
"locate('abc', NULL, 5)",
TYPE_INT);
1755 TestIsNull(
"locate('abc', 'abcabcabc', NULL)",
TYPE_INT);
1756 TestIsNull(
"locate(NULL, NULL, NULL)",
TYPE_INT);
1758 TestStringValue(
"concat('a')",
"a");
1759 TestStringValue(
"concat('a', 'b')",
"ab");
1760 TestStringValue(
"concat('a', 'b', 'cde')",
"abcde");
1761 TestStringValue(
"concat('a', 'b', 'cde', 'fg')",
"abcdefg");
1762 TestStringValue(
"concat('a', 'b', 'cde', '', 'fg', '')",
"abcdefg");
1764 TestIsNull(
"concat('a', NULL, 'b')",
TYPE_STRING);
1765 TestIsNull(
"concat('a', 'b', NULL)",
TYPE_STRING);
1767 TestStringValue(
"concat_ws(',', 'a')",
"a");
1768 TestStringValue(
"concat_ws(',', 'a', 'b')",
"a,b");
1769 TestStringValue(
"concat_ws(',', 'a', 'b', 'cde')",
"a,b,cde");
1770 TestStringValue(
"concat_ws('', 'a', '', 'b', 'cde')",
"abcde");
1771 TestStringValue(
"concat_ws('%%', 'a', 'b', 'cde', 'fg')",
"a%%b%%cde%%fg");
1772 TestStringValue(
"concat_ws('|','a', 'b', 'cde', '', 'fg', '')",
"a|b|cde||fg|");
1773 TestStringValue(
"concat_ws('', '', '', '')",
"");
1775 TestIsNull(
"concat_ws(',', NULL, 'b')",
TYPE_STRING);
1776 TestIsNull(
"concat_ws(',', 'b', NULL)",
TYPE_STRING);
1778 TestValue(
"find_in_set('ab', 'ab,ab,ab,ade,cde')",
TYPE_INT, 1);
1779 TestValue(
"find_in_set('ab', 'abc,xyz,abc,ade,ab')",
TYPE_INT, 5);
1780 TestValue(
"find_in_set('ab', 'abc,ad,ab,ade,cde')",
TYPE_INT, 3);
1781 TestValue(
"find_in_set('xyz', 'abc,ad,ab,ade,cde')",
TYPE_INT, 0);
1782 TestValue(
"find_in_set('ab', ',,,,ab,,,,')",
TYPE_INT, 5);
1783 TestValue(
"find_in_set('', ',ad,ab,ade,cde')",
TYPE_INT,1);
1784 TestValue(
"find_in_set('', 'abc,ad,ab,ade,,')",
TYPE_INT, 5);
1785 TestValue(
"find_in_set('', 'abc,ad,,ade,cde,')",
TYPE_INT,3);
1787 TestValue(
"find_in_set('abc,def', 'abc,ad,,ade,cde,')",
TYPE_INT, 0);
1788 TestIsNull(
"find_in_set(NULL, 'abc,ad,,ade,cde')",
TYPE_INT);
1789 TestIsNull(
"find_in_set('abc,def', NULL)",
TYPE_INT);
1790 TestIsNull(
"find_in_set(NULL, NULL)",
TYPE_INT);
1792 TestStringValue(
"cast('HELLO' as VARCHAR(3))",
"HEL");
1793 TestStringValue(
"cast('HELLO' as VARCHAR(15))",
"HELLO");
1794 TestStringValue(
"lower(cast('HELLO' as VARCHAR(3)))",
"hel");
1795 TestStringValue(
"lower(cast(123456 as VARCHAR(3)))",
"123");
1796 TestIsNull(
"cast(NULL as VARCHAR(3))",
TYPE_STRING);
1797 TestCharValue(
"cast('12345' as CHAR(130))",
1800 ColumnType::CreateCharType(130));
1802 TestCharValue(
"cast(cast('HELLO' as VARCHAR(3)) as CHAR(3))",
"HEL",
1803 ColumnType::CreateCharType(3));
1804 TestStringValue(
"cast(cast('HELLO' as CHAR(3)) as VARCHAR(3))",
"HEL");
1805 TestCharValue(
"cast(cast('HELLO' as VARCHAR(7)) as CHAR(7))",
"HELLO ",
1806 ColumnType::CreateCharType(7));
1807 TestCharValue(
"cast(cast('HELLO' as STRING) as CHAR(7))",
"HELLO ",
1808 ColumnType::CreateCharType(7));
1809 TestStringValue(
"cast(cast('HELLO' as CHAR(7)) as VARCHAR(7))",
"HELLO ");
1810 TestStringValue(
"cast(cast('HELLO' as CHAR(5)) as VARCHAR(3))",
"HEL");
1811 TestCharValue(
"cast(cast('HELLO' as VARCHAR(7)) as CHAR(3))",
"HEL",
1812 ColumnType::CreateCharType(3));
1814 TestCharValue(
"cast(5 as char(5))",
"5 ", ColumnType::CreateCharType(5));
1815 TestCharValue(
"cast(5.1 as char(5))",
"5.1 ", ColumnType::CreateCharType(5));
1816 TestCharValue(
"cast(cast(1 as decimal(2,1)) as char(5))",
"1.0 ",
1817 ColumnType::CreateCharType(5));
1818 TestCharValue(
"cast(cast('2014-09-30 10:35:10.632995000' as TIMESTAMP) as char(35))",
1819 "2014-09-30 10:35:10.632995000 ",
1820 ColumnType::CreateCharType(35));
1822 TestCharValue(
"cast('HELLO' as CHAR(3))",
"HEL",
1823 ColumnType::CreateCharType(3));
1824 TestCharValue(
"cast('HELLO' as CHAR(7))",
"HELLO ",
1825 ColumnType::CreateCharType(7));
1826 TestCharValue(
"cast('HELLO' as CHAR(70))",
1828 ColumnType::CreateCharType(70));
1829 TestValue(
"cast('HELLO' as CHAR(7)) = 'HELLO '",
TYPE_BOOLEAN,
true);
1830 TestValue(
"cast('HELLO' as CHAR(7)) = cast('HELLO' as CHAR(5))",
TYPE_BOOLEAN,
true);
1831 TestStringValue(
"lower(cast('HELLO' as CHAR(3)))",
"hel");
1832 TestStringValue(
"lower(cast(123456 as CHAR(3)))",
"123");
1833 TestStringValue(
"cast(cast(123456 as CHAR(3)) as VARCHAR(3))",
"123");
1834 TestStringValue(
"cast(cast(123456 as CHAR(3)) as VARCHAR(65355))",
"123");
1835 TestIsNull(
"cast(NULL as CHAR(3))", ColumnType::CreateCharType(3));
1837 TestCharValue(
"cast('HELLO' as CHAR(255))",
1841 " ", ColumnType::CreateCharType(255));
1843 TestStringValue(
"CASE cast('1.1' as char(3)) when cast('1.1' as char(3)) then "
1844 "cast('1' as char(1)) when cast('2.22' as char(4)) then "
1845 "cast('2' as char(1)) else cast('3' as char(1)) end",
"1");
1848 char query[ColumnType::MAX_VARCHAR_LENGTH + 1024];
1849 char big_str[ColumnType::MAX_VARCHAR_LENGTH+1];
1850 for (
int i = 0 ; i < ColumnType::MAX_VARCHAR_LENGTH; i++) {
1853 big_str[ColumnType::MAX_VARCHAR_LENGTH] =
'\0';
1854 sprintf(query,
"cast('%sxxx' as VARCHAR(%d))", big_str, ColumnType::MAX_VARCHAR_LENGTH);
1855 TestStringValue(query, big_str);
1860 TestStringValue(
"regexp_extract('abxcy1234a', 'a.x', 0)",
"abx");
1861 TestStringValue(
"regexp_extract('abxcy1234a', 'a.x.*a', 0)",
"abxcy1234a");
1862 TestStringValue(
"regexp_extract('abxcy1234a', 'a.x.y.*a', 0)",
"abxcy1234a");
1863 TestStringValue(
"regexp_extract('a.x.y.*a',"
1864 "'a\\\\.x\\\\.y\\\\.\\\\*a', 0)",
"a.x.y.*a");
1865 TestStringValue(
"regexp_extract('abxcy1234a', 'abczy', cast(0 as bigint))",
"");
1866 TestStringValue(
"regexp_extract('abxcy1234a', 'a\\\\.x\\\\.y\\\\.\\\\*a', 0)",
"");
1867 TestStringValue(
"regexp_extract('axcy1234a', 'a.x.y.*a', 0)",
"");
1869 TestStringValue(
"regexp_extract('abxcy1234a', 'a.x', cast(2 as bigint))",
"");
1870 TestStringValue(
"regexp_extract('abxcy1234a', 'a.x.*a', 1)",
"");
1871 TestStringValue(
"regexp_extract('abxcy1234a', 'a.x.y.*a', 5)",
"");
1872 TestStringValue(
"regexp_extract('abxcy1234a', 'a.x', -1)",
"");
1874 TestStringValue(
"regexp_extract('abxcy1234a', '(a.x)(.y.*)(3.*a)', 0)",
"abxcy1234a");
1875 TestStringValue(
"regexp_extract('abxcy1234a', '(a.x)(.y.*)(3.*a)', 1)",
"abx");
1876 TestStringValue(
"regexp_extract('abxcy1234a', '(a.x)(.y.*)(3.*a)', 2)",
"cy12");
1877 TestStringValue(
"regexp_extract('abxcy1234a', '(a.x)(.y.*)(3.*a)',"
1878 "cast(3 as bigint))",
"34a");
1879 TestStringValue(
"regexp_extract('abxcy1234a', '(a.x)(.y.*)(3.*a)',"
1880 "cast(4 as bigint))",
"");
1882 TestStringValue(
"regexp_extract('', '', 0)",
"");
1883 TestStringValue(
"regexp_extract('abxcy1234a', '', 0)",
"");
1884 TestStringValue(
"regexp_extract('', 'abx', 0)",
"");
1886 TestStringValue(
"regexp_extract('I001=-200,I003=-210,I007=0', 'I001=-?[0-9]+', 0)",
1889 TestError(
"regexp_extract('abxcy1234a', '(/.', 0)");
1891 TestIsNull(
"regexp_extract(NULL, 'a.x', 2)",
TYPE_STRING);
1892 TestIsNull(
"regexp_extract('abxcy1234a', NULL, 2)",
TYPE_STRING);
1893 TestIsNull(
"regexp_extract('abxcy1234a', 'a.x', NULL)",
TYPE_STRING);
1894 TestIsNull(
"regexp_extract(NULL, NULL, NULL)",
TYPE_STRING);
1896 TestStringValue(
"regexp_extract('abxcy1234a', '[[:lower:]]*', 0)",
"abxcy");
1897 TestStringValue(
"regexp_extract('abxcy1234a', '[[:digit:]]+', 0)",
"1234");
1898 TestStringValue(
"regexp_extract('abxcy1234a', '[[:lower:]][[:digit:]]', 0)",
"y1");
1899 TestStringValue(
"regexp_extract('aBcDeF', '[[:upper:]][[:lower:]]', 0)",
"Bc");
1901 TestStringValue(
"regexp_extract('abxcy1234a', '\\\\w*', 0)",
"abxcy1234a");
1902 TestStringValue(
"regexp_extract('abxcy1234a', '\\\\d+', 0)",
"1234");
1903 TestStringValue(
"regexp_extract('abxcy1234a', '\\\\d\\\\D', 0)",
"4a");
1905 TestStringValue(
"regexp_extract('abcabcd', '(a|ab|abc|abcd)', 0)",
"abc");
1907 TestStringValue(
"regexp_replace('axcaycazc', 'a.c', 'a')",
"aaa");
1908 TestStringValue(
"regexp_replace('axcaycazc', 'a.c', '')",
"");
1909 TestStringValue(
"regexp_replace('axcaycazc', 'a.*', 'abcde')",
"abcde");
1910 TestStringValue(
"regexp_replace('axcaycazc', 'a.*y.*z', 'xyz')",
"xyzc");
1912 TestStringValue(
"regexp_replace('axcaycazc', 'a.z', 'xyz')",
"axcaycazc");
1913 TestStringValue(
"regexp_replace('axcaycazc', 'a.*y.z', 'xyz')",
"axcaycazc");
1915 TestStringValue(
"regexp_replace('', '', '')",
"");
1916 TestStringValue(
"regexp_replace('axcaycazc', '', '')",
"axcaycazc");
1917 TestStringValue(
"regexp_replace('', 'err', '')",
"");
1918 TestStringValue(
"regexp_replace('', '', 'abc')",
"abc");
1919 TestStringValue(
"regexp_replace('axcaycazc', '', 'r')",
"rarxrcraryrcrarzrcr");
1921 TestError(
"regexp_replace('abxcy1234a', '(/.', 'x')");
1923 TestIsNull(
"regexp_replace(NULL, 'a.*', 'abcde')",
TYPE_STRING);
1924 TestIsNull(
"regexp_replace('axcaycazc', NULL, 'abcde')",
TYPE_STRING);
1925 TestIsNull(
"regexp_replace('axcaycazc', 'a.*', NULL)",
TYPE_STRING);
1926 TestIsNull(
"regexp_replace(NULL, NULL, NULL)",
TYPE_STRING);
1936 TestStringValue(
"parse_url('http://user:pass@example.com:80/docs/books/tutorial/"
1937 "index.html?name=networking#DOWNLOADING', 'AUTHORITY')",
1938 "user:pass@example.com:80");
1939 TestStringValue(
"parse_url('http://user:pass@example.com/docs/books/tutorial/"
1940 "index.html?name=networking#DOWNLOADING', 'AUTHORITY')",
"user:pass@example.com");
1942 TestStringValue(
"parse_url('http://example.com:80/docs/books/tutorial/"
1943 "index.html?name=networking#DOWNLOADING', 'AUTHORITY')",
"example.com:80");
1944 TestStringValue(
"parse_url('http://example.com/docs/books/tutorial/"
1945 "index.html?name=networking#DOWNLOADING', 'AUTHORITY')",
"example.com");
1947 TestStringValue(
"parse_url('http://example.com_xyzabc^&*', 'AUTHORITY')",
1948 "example.com_xyzabc^&*");
1950 TestIsNull(
"parse_url('example.com/docs/books/tutorial/"
1951 "index.html?name=networking#DOWNLOADING', 'HOST')",
TYPE_STRING);
1954 TestStringValue(
"parse_url('http://user:pass@example.com:80/docs/books/tutorial/"
1955 "index.html?name=networking#DOWNLOADING', 'FILE')",
1956 "/docs/books/tutorial/index.html?name=networking");
1957 TestStringValue(
"parse_url('http://user:pass@example.com/docs/books/tutorial/"
1958 "index.html?name=networking#DOWNLOADING', 'FILE')",
1959 "/docs/books/tutorial/index.html?name=networking");
1961 TestStringValue(
"parse_url('http://example.com:80/docs/books/tutorial/"
1962 "index.html?name=networking#DOWNLOADING', 'FILE')",
1963 "/docs/books/tutorial/index.html?name=networking");
1964 TestStringValue(
"parse_url('http://example.com/docs/books/tutorial/"
1965 "index.html?name=networking#DOWNLOADING', 'FILE')",
1966 "/docs/books/tutorial/index.html?name=networking");
1968 TestStringValue(
"parse_url('http://example.com/docs/books/tutorial/"
1969 "index.html?name=networking ', 'FILE')",
1970 "/docs/books/tutorial/index.html?name=networking");
1972 TestStringValue(
"parse_url('http://example.com/docs/books/tutorial/"
1973 "index.html#something', 'FILE')",
1974 "/docs/books/tutorial/index.html");
1976 TestStringValue(
"parse_url('http://example.com/docs/books/tutorial/"
1977 "index.htmlsomething', 'FILE')",
1978 "/docs/books/tutorial/index.htmlsomething");
1980 TestIsNull(
"parse_url('example.com/docs/books/tutorial/"
1981 "index.html?name=networking#DOWNLOADING', 'FILE')",
TYPE_STRING);
1984 TestStringValue(
"parse_url('http://user:pass@example.com:80/docs/books/tutorial/"
1985 "index.html?name=networking#DOWNLOADING', 'HOST')",
"example.com");
1986 TestStringValue(
"parse_url('http://user:pass@example.com/docs/books/tutorial/"
1987 "index.html?name=networking#DOWNLOADING', 'HOST')",
"example.com");
1989 TestStringValue(
"parse_url('http://example.com:80/docs/books/tutorial/"
1990 "index.html?name=networking#DOWNLOADING', 'HOST')",
"example.com");
1991 TestStringValue(
"parse_url('http://example.com/docs/books/tutorial/"
1992 "index.html?name=networking#DOWNLOADING', 'HOST')",
"example.com");
1994 TestStringValue(
"parse_url('http://example.com_xyzabc^&*', 'HOST')",
1995 "example.com_xyzabc^&*");
1997 TestStringValue(
"parse_url('http://user:pass@example.com:80/docs/books/tutorial/"
1998 "index.html?name:networking#DOWNLOADING', 'HOST')",
"example.com");
2000 TestStringValue(
"parse_url('http://user:pass@example.com/docs/books/tutorial/"
2001 "index.html?name:networking#DOWNLOADING', 'HOST')",
"example.com");
2003 TestStringValue(
"parse_url('http://user:pass@example.com"
2004 "?name:networking#DOWNLOADING', 'HOST')",
"example.com");
2006 TestStringValue(
"parse_url('http://user:pass@example.com:80"
2007 "?name:networking#DOWNLOADING', 'HOST')",
"example.com");
2009 TestStringValue(
"parse_url('http://user:pass@example.com:80"
2010 "?name:networking/DOWNLOADING', 'HOST')",
"example.com");
2012 TestIsNull(
"parse_url('example.com/docs/books/tutorial/"
2013 "index.html?name=networking#DOWNLOADING', 'HOST')",
TYPE_STRING);
2016 TestStringValue(
"parse_url('http://user:pass@example.com:80/docs/books/tutorial/"
2017 "index.html?name=networking#DOWNLOADING', 'PATH')",
2018 "/docs/books/tutorial/index.html");
2019 TestStringValue(
"parse_url('http://user:pass@example.com/docs/books/tutorial/"
2020 "index.html?name=networking#DOWNLOADING', 'PATH')",
2021 "/docs/books/tutorial/index.html");
2023 TestStringValue(
"parse_url('http://example.com:80/docs/books/tutorial/"
2024 "index.html?name=networking#DOWNLOADING', 'PATH')",
2025 "/docs/books/tutorial/index.html");
2026 TestStringValue(
"parse_url('http://example.com/docs/books/tutorial/"
2027 "index.html?name=networking#DOWNLOADING', 'PATH')",
2028 "/docs/books/tutorial/index.html");
2030 TestStringValue(
"parse_url('http://user:pass@example.com/docs/books/tutorial/"
2031 "index.html ', 'PATH')",
2032 "/docs/books/tutorial/index.html");
2034 TestStringValue(
"parse_url('http://example.com/docs/books/tutorial/"
2035 "index.html#something', 'PATH')",
2036 "/docs/books/tutorial/index.html");
2038 TestStringValue(
"parse_url('http://example.com/docs/books/tutorial/"
2039 "index.htmlsomething', 'PATH')",
2040 "/docs/books/tutorial/index.htmlsomething");
2042 TestIsNull(
"parse_url('example.com/docs/books/tutorial/"
2043 "index.html?name=networking#DOWNLOADING', 'PATH')",
TYPE_STRING);
2046 TestStringValue(
"parse_url('http://user:pass@example.com:80/docs/books/tutorial/"
2047 "index.html?name=networking#DOWNLOADING', 'PROTOCOL')",
"http");
2048 TestStringValue(
"parse_url('https://user:pass@example.com/docs/books/tutorial/"
2049 "index.html?name=networking#DOWNLOADING', 'PROTOCOL')",
"https");
2051 TestStringValue(
"parse_url('http://example.com:80/docs/books/tutorial/"
2052 "index.html?name=networking#DOWNLOADING', 'PROTOCOL')",
"http");
2053 TestStringValue(
"parse_url('https://example.com/docs/books/tutorial/"
2054 "index.html?name=networking#DOWNLOADING', 'PROTOCOL')",
"https");
2056 TestStringValue(
"parse_url(' https://user:pass@example.com/docs/books/tutorial/"
2057 "index.html?name=networking#DOWNLOADING', 'PROTOCOL')",
"https");
2059 TestIsNull(
"parse_url('user:pass@example.com/docs/books/tutorial/"
2060 "index.html?name=networking#DOWNLOADING', 'PROTOCOL')",
TYPE_STRING);
2063 TestStringValue(
"parse_url('http://user:pass@example.com:80/docs/books/tutorial/"
2064 "index.html?name=networking#DOWNLOADING', 'QUERY')",
"name=networking");
2065 TestStringValue(
"parse_url('http://user:pass@example.com/docs/books/tutorial/"
2066 "index.html?name=networking#DOWNLOADING', 'QUERY')",
"name=networking");
2068 TestStringValue(
"parse_url('http://example.com:80/docs/books/tutorial/"
2069 "index.html?name=networking#DOWNLOADING', 'QUERY')",
"name=networking");
2070 TestStringValue(
"parse_url('http://example.com/docs/books/tutorial/"
2071 "index.html?name=networking#DOWNLOADING', 'QUERY')",
"name=networking");
2073 TestStringValue(
"parse_url('http://example.com/docs/books/tutorial/"
2074 "index.html?name=networking ', 'QUERY')",
"name=networking");
2076 TestIsNull(
"parse_url('http://example.com_xyzabc^&*', 'QUERY')",
TYPE_STRING);
2078 TestIsNull(
"parse_url('example.com/docs/books/tutorial/"
2079 "index.html?name=networking#DOWNLOADING', 'QUERY')",
TYPE_STRING);
2082 TestStringValue(
"parse_url('http://user:pass@example.com:80/docs/books/tutorial/"
2083 "index.html?name=networking#DOWNLOADING', 'PATH')",
2084 "/docs/books/tutorial/index.html");
2085 TestStringValue(
"parse_url('http://user:pass@example.com/docs/books/tutorial/"
2086 "index.html?name=networking#DOWNLOADING', 'PATH')",
2087 "/docs/books/tutorial/index.html");
2089 TestStringValue(
"parse_url('http://example.com:80/docs/books/tutorial/"
2090 "index.html?name=networking#DOWNLOADING', 'PATH')",
2091 "/docs/books/tutorial/index.html");
2092 TestStringValue(
"parse_url('http://example.com/docs/books/tutorial/"
2093 "index.html?name=networking#DOWNLOADING', 'PATH')",
2094 "/docs/books/tutorial/index.html");
2096 TestStringValue(
"parse_url('http://user:pass@example.com/docs/books/tutorial/"
2097 "index.html ', 'PATH')",
2098 "/docs/books/tutorial/index.html");
2100 TestStringValue(
"parse_url('http://example.com/docs/books/tutorial/"
2101 "index.html#something', 'PATH')",
2102 "/docs/books/tutorial/index.html");
2104 TestStringValue(
"parse_url('http://example.com/docs/books/tutorial/"
2105 "index.htmlsomething', 'PATH')",
2106 "/docs/books/tutorial/index.htmlsomething");
2108 TestIsNull(
"parse_url('example.com/docs/books/tutorial/"
2109 "index.html?name=networking#DOWNLOADING', 'PATH')",
TYPE_STRING);
2112 TestStringValue(
"parse_url('http://user:pass@example.com:80/docs/books/tutorial/"
2113 "index.html?name=networking#DOWNLOADING', 'USERINFO')",
"user:pass");
2114 TestStringValue(
"parse_url('http://user:pass@example.com/docs/books/tutorial/"
2115 "index.html?name=networking#DOWNLOADING', 'USERINFO')",
"user:pass");
2117 TestStringValue(
"parse_url('http://user@example.com/docs/books/tutorial/"
2118 "index.html?name=networking#DOWNLOADING', 'USERINFO')",
"user");
2120 TestIsNull(
"parse_url('http://example.com:80/docs/books/tutorial/"
2121 "index.html?name=networking#DOWNLOADING', 'USERINFO')",
TYPE_STRING);
2123 TestIsNull(
"parse_url('example.com/docs/books/tutorial/"
2124 "index.html?name=networking#DOWNLOADING', 'USERINFO')",
TYPE_STRING);
2128 TestError(
"parse_url('http://example.com', 'authority')");
2129 TestError(
"parse_url('http://example.com', 'Authority')");
2130 TestError(
"parse_url('http://example.com', 'AUTHORITYXYZ')");
2131 TestError(
"parse_url('http://example.com', 'file')");
2132 TestError(
"parse_url('http://example.com', 'File')");
2133 TestError(
"parse_url('http://example.com', 'FILEXYZ')");
2134 TestError(
"parse_url('http://example.com', 'host')");
2135 TestError(
"parse_url('http://example.com', 'Host')");
2136 TestError(
"parse_url('http://example.com', 'HOSTXYZ')");
2137 TestError(
"parse_url('http://example.com', 'path')");
2138 TestError(
"parse_url('http://example.com', 'Path')");
2139 TestError(
"parse_url('http://example.com', 'PATHXYZ')");
2140 TestError(
"parse_url('http://example.com', 'protocol')");
2141 TestError(
"parse_url('http://example.com', 'Protocol')");
2142 TestError(
"parse_url('http://example.com', 'PROTOCOLXYZ')");
2143 TestError(
"parse_url('http://example.com', 'query')");
2144 TestError(
"parse_url('http://example.com', 'Query')");
2145 TestError(
"parse_url('http://example.com', 'QUERYXYZ')");
2146 TestError(
"parse_url('http://example.com', 'ref')");
2147 TestError(
"parse_url('http://example.com', 'Ref')");
2148 TestError(
"parse_url('http://example.com', 'REFXYZ')");
2149 TestError(
"parse_url('http://example.com', 'userinfo')");
2150 TestError(
"parse_url('http://example.com', 'Userinfo')");
2151 TestError(
"parse_url('http://example.com', 'USERINFOXYZ')");
2154 TestIsNull(
"parse_url(NULL, 'AUTHORITY')",
TYPE_STRING);
2155 TestIsNull(
"parse_url('http://user:pass@example.com:80/docs/books/tutorial/"
2156 "index.html?name=networking#DOWNLOADING', NULL)",
TYPE_STRING);
2160 TestStringValue(
"parse_url('http://example.com:80/docs/books/tutorial/"
2161 "index.html?name=networking#DOWNLOADING', 'QUERY', 'name')",
"networking");
2163 TestStringValue(
"parse_url('http://example.com:80/docs/books/tutorial/"
2164 "index.html?name=networking', 'QUERY', 'name')",
"networking");
2166 TestStringValue(
"parse_url('http://example.com:80/docs/books/tutorial/"
2167 "index.html?name=networking ', 'QUERY', 'name')",
"networking");
2169 TestStringValue(
"parse_url('http://example.com:80/docs/books/tutorial/"
2170 "index.html?name=networking&test=true', 'QUERY', 'name')",
"networking");
2172 TestStringValue(
"parse_url('http://example.com:80/docs/books/tutorial/"
2173 "index.html?test=true&name=networking&op=true', 'QUERY', 'name')",
"networking");
2175 TestStringValue(
"parse_url('http://name.name:80/name/books/tutorial/"
2176 "name.html?name_fake=true&name=networking&op=true#name', 'QUERY', 'name')",
2179 TestStringValue(
"parse_url('http://example.com:80/docs/books/tutorial/"
2180 "index.htmltest=true&name=networking&op=true', 'QUERY', 'name')",
"networking");
2182 TestIsNull(
"parse_url('http://example.com:80/docs/books/tutorial/"
2183 "index.html?test=true&name=networking&op=true', 'QUERY', 'error')",
TYPE_STRING);
2185 TestIsNull(
"parse_url('http://example.com:80/docs/books/tutorial/"
2186 "name.html?test=true&op=true', 'QUERY', 'name')",
TYPE_STRING);
2188 TestIsNull(
"parse_url('http://example.com:80/docs/books/tutorial/"
2189 "name.html?test=true&op=name', 'QUERY', 'name')",
TYPE_STRING);
2191 TestStringValue(
"parse_url('http://example.com:80/docs/books/tutorial/"
2192 "index.html?test=true&name=net?working&op=true', 'QUERY', 'name')",
"net?working");
2193 TestStringValue(
"parse_url('http://example.com:80/docs/books/tutorial/"
2194 "index.html?test=true&name=net=working&op=true', 'QUERY', 'name')",
"net=working");
2196 TestIsNull(
"parse_url('http://example.com:80/docs/books/tutorial/"
2197 "index.html?test=true&name=networking&op=true', 'AUTHORITY', 'name')",
TYPE_STRING);
2198 TestIsNull(
"parse_url('http://example.com:80/docs/books/tutorial/"
2199 "index.html?test=true&name=networking&op=true', 'FILE', 'name')",
TYPE_STRING);
2200 TestIsNull(
"parse_url('http://example.com:80/docs/books/tutorial/"
2201 "index.html?test=true&name=networking&op=true', 'PATH', 'name')",
TYPE_STRING);
2202 TestIsNull(
"parse_url('http://example.com:80/docs/books/tutorial/"
2203 "index.html?test=true&name=networking&op=true', 'PROTOCOL', 'name')",
TYPE_STRING);
2204 TestIsNull(
"parse_url('http://example.com:80/docs/books/tutorial/"
2205 "index.html?test=true&name=networking&op=true', 'REF', 'name')",
TYPE_STRING);
2206 TestError(
"parse_url('http://example.com:80/docs/books/tutorial/"
2207 "index.html?test=true&name=networking&op=true', 'XYZ', 'name')");
2211 TestStringValue(
"current_database()",
"default");
2212 TestStringValue(
"user()",
"impala_test_user");
2218 TestStringValue(
"typeOf(!true)",
"BOOLEAN");
2219 TestStringValue(
"typeOf(1)",
"TINYINT");
2220 TestStringValue(
"typeOf(0)",
"TINYINT");
2221 TestStringValue(
"typeOf(-1)",
"TINYINT");
2222 TestStringValue(
"typeOf(128)",
"SMALLINT");
2223 TestStringValue(
"typeOf(32768)",
"INT");
2224 TestStringValue(
"typeOf(2147483648)",
"BIGINT");
2225 TestStringValue(
"typeOf(4294967296)",
"BIGINT");
2226 TestStringValue(
"typeOf(-4294967296)",
"BIGINT");
2227 TestStringValue(
"typeOf(9223372036854775807)",
"BIGINT");
2228 TestStringValue(
"typeOf(-9223372036854775808)",
"BIGINT");
2229 TestStringValue(
"typeOf(cast(10 as FLOAT))",
"FLOAT");
2230 TestStringValue(
"typeOf(cast(10 as DOUBLE))",
"DOUBLE");
2231 TestStringValue(
"typeOf(current_database())",
"STRING");
2232 TestStringValue(
"typeOf(now())",
"TIMESTAMP");
2233 TestStringValue(
"typeOf(cast(10 as DECIMAL))",
"DECIMAL(9,0)");
2234 TestStringValue(
"typeOf(0.0)",
"DECIMAL(1,1)");
2235 TestStringValue(
"typeOf(3.14)",
"DECIMAL(3,2)");
2236 TestStringValue(
"typeOf(-1.23)",
"DECIMAL(3,2)");
2237 TestStringValue(
"typeOf(cast(NULL as STRING))",
"STRING");
2238 TestStringValue(
"typeOf(\"\")",
"STRING");
2239 TestStringValue(
"typeOf(NULL)",
"BOOLEAN");
2240 TestStringValue(
"typeOf(34 < NULL)",
"BOOLEAN");
2241 TestStringValue(
"typeOf(cast('a' as CHAR(2)))",
"CHAR(2)");
2242 TestStringValue(
"typeOf(cast('abcdef' as CHAR(4)))",
"CHAR(4)");
2243 TestStringValue(
"typeOf(cast('a' as VARCHAR(2)))",
"VARCHAR(2)");
2244 TestStringValue(
"typeOf(cast('abcdef' as VARCHAR(4)))",
"VARCHAR(4)");
2245 TestStringValue(
"typeOf(cast(NULL as CHAR(2)))",
"CHAR(2)");
2246 TestStringValue(
"typeOf(cast(NULL as VARCHAR(4)))",
"VARCHAR(4)");
2249 string s(
"hello world");
2250 uint64_t expected = HashUtil::FnvHash64(s.data(), s.size(), HashUtil::FNV_SEED);
2251 TestValue(
"fnv_hash('hello world')",
TYPE_BIGINT, expected);
2253 expected = HashUtil::FnvHash64(s.data(), s.size(), HashUtil::FNV_SEED);
2256 IntValMap::iterator int_iter;
2257 for(int_iter = min_int_values_.begin(); int_iter != min_int_values_.end();
2260 expected = HashUtil::FnvHash64(
2261 &int_iter->second, t.
GetByteSize(), HashUtil::FNV_SEED);
2262 string& val = default_type_strs_[int_iter->first];
2263 TestValue(
"fnv_hash(" + val +
")",
TYPE_BIGINT, expected);
2268 float float_val = 42;
2269 expected = HashUtil::FnvHash64(&float_val,
sizeof(
float), HashUtil::FNV_SEED);
2270 TestValue(
"fnv_hash(CAST(42 as FLOAT))",
TYPE_BIGINT, expected);
2272 double double_val = 42;
2273 expected = HashUtil::FnvHash64(&double_val,
sizeof(
double), HashUtil::FNV_SEED);
2274 TestValue(
"fnv_hash(CAST(42 as DOUBLE))",
TYPE_BIGINT, expected);
2276 expected = HashUtil::FnvHash64(&default_timestamp_val_, 12, HashUtil::FNV_SEED);
2277 TestValue(
"fnv_hash(" + default_timestamp_str_ +
")",
TYPE_BIGINT, expected);
2279 bool bool_val =
false;
2280 expected = HashUtil::FnvHash64(&bool_val, 1, HashUtil::FNV_SEED);
2281 TestValue(
"fnv_hash(FALSE)",
TYPE_BIGINT, expected);
2299 TestValue(
"CAST(1/0 AS FLOAT)",
TYPE_FLOAT, numeric_limits<float>::infinity());
2300 TestValue(
"CAST(1/0 AS DOUBLE)",
TYPE_DOUBLE, numeric_limits<double>::infinity());
2301 TestValue(
"CAST(CAST(1/0 as FLOAT) as DOUBLE)",
TYPE_DOUBLE,
2302 numeric_limits<double>::infinity());
2303 TestStringValue(
"CAST(1/0 AS STRING)",
"inf");
2304 TestStringValue(
"CAST(CAST(1/0 AS FLOAT) AS STRING)",
"inf");
2306 TestValue(
"CAST('inf' AS FLOAT)",
TYPE_FLOAT, numeric_limits<float>::infinity());
2307 TestValue(
"CAST('inf' AS DOUBLE)",
TYPE_DOUBLE, numeric_limits<double>::infinity());
2308 TestValue(
"CAST('Infinity' AS FLOAT)",
TYPE_FLOAT, numeric_limits<float>::infinity());
2309 TestValue(
"CAST('-Infinity' AS DOUBLE)",
TYPE_DOUBLE,
2310 -numeric_limits<double>::infinity());
2313 TestStringValue(
"CAST(CAST('nan' AS FLOAT) AS STRING)",
string(
"nan"));
2314 TestStringValue(
"CAST(CAST('nan' AS DOUBLE) AS STRING)",
string(
"nan"));
2316 TestStringValue(
"CAST(0/0 AS STRING)",
string(
"nan"));
2325 TestValue(
"sin(pi() / 2.0)",
TYPE_DOUBLE, sin(M_PI / 2.0));
2332 TestValue(
"tan(pi() * -1.0)",
TYPE_DOUBLE, tan(M_PI * -1.0));
2335 TestValue(
"atan(pi() * - 1.0)",
TYPE_DOUBLE, atan(M_PI * -1.0));
2354 TestStringValue(
"bin(0)",
"0");
2355 TestStringValue(
"bin(1)",
"1");
2356 TestStringValue(
"bin(12)",
"1100");
2357 TestStringValue(
"bin(1234567)",
"100101101011010000111");
2358 TestStringValue(
"bin(" + lexical_cast<string>(numeric_limits<int64_t>::max()) +
")",
2359 "111111111111111111111111111111111111111111111111111111111111111");
2360 TestStringValue(
"bin(" + lexical_cast<string>(numeric_limits<int64_t>::min()+1) +
")",
2361 "1000000000000000000000000000000000000000000000000000000000000001");
2363 TestStringValue(
"hex(0)",
"0");
2364 TestStringValue(
"hex(15)",
"F");
2365 TestStringValue(
"hex(16)",
"10");
2366 TestStringValue(
"hex(" + lexical_cast<string>(numeric_limits<int64_t>::max()) +
")",
2367 "7FFFFFFFFFFFFFFF");
2368 TestStringValue(
"hex(" + lexical_cast<string>(numeric_limits<int64_t>::min()+1) +
")",
2369 "8000000000000001");
2370 TestStringValue(
"hex('0')",
"30");
2371 TestStringValue(
"hex('aAzZ')",
"61417A5A");
2372 TestStringValue(
"hex('Impala')",
"496D70616C61");
2373 TestStringValue(
"hex('impalA')",
"696D70616C41");
2375 TestStringValue(
"hex(unhex('D3'))",
"D3");
2377 TestStringValue(
"hex(unhex('0303'))",
"0303");
2378 TestStringValue(
"hex(unhex('D303D303'))",
"D303D303");
2380 TestStringValue(
"unhex('30')",
"0");
2381 TestStringValue(
"unhex('61417A5A')",
"aAzZ");
2382 TestStringValue(
"unhex('496D70616C61')",
"Impala");
2383 TestStringValue(
"unhex('696D70616C41')",
"impalA");
2385 TestStringValue(
"unhex('30GA')",
"");
2387 TestStringValue(
"unhex('30A')",
"");
2391 for (
int i = 0; i < 2; ++i) {
2393 string q = (i == 0) ?
"" :
"'";
2395 TestIsNull(
"conv(" + q +
"10" + q +
", 10, 37)",
TYPE_STRING);
2396 TestIsNull(
"conv(" + q +
"10" + q +
", 37, 10)",
TYPE_STRING);
2397 TestIsNull(
"conv(" + q +
"10" + q +
", 10, -37)",
TYPE_STRING);
2398 TestIsNull(
"conv(" + q +
"10" + q +
", -37, 10)",
TYPE_STRING);
2400 TestIsNull(
"conv(" + q +
"10" + q +
", 10, 1)",
TYPE_STRING);
2401 TestIsNull(
"conv(" + q +
"10" + q +
", 1, 10)",
TYPE_STRING);
2402 TestIsNull(
"conv(" + q +
"10" + q +
", 10, -1)",
TYPE_STRING);
2403 TestIsNull(
"conv(" + q +
"10" + q +
", -1, 10)",
TYPE_STRING);
2405 TestIsNull(
"conv(" + q +
"10" + q +
", -10, 10)",
TYPE_STRING);
2407 TestStringValue(
"conv(" + q +
"10" + q +
", 10, 10)",
"10");
2408 TestStringValue(
"conv(" + q +
"10" + q +
", 2, 10)",
"2");
2409 TestStringValue(
"conv(" + q +
"11" + q +
", 36, 10)",
"37");
2410 TestStringValue(
"conv(" + q +
"11" + q +
", 36, 2)",
"100101");
2411 TestStringValue(
"conv(" + q +
"100101" + q +
", 2, 36)",
"11");
2412 TestStringValue(
"conv(" + q +
"0" + q +
", 10, 2)",
"0");
2415 TestStringValue(
"conv(" + q +
"-641" + q +
", 10, -10)",
"-641");
2416 TestStringValue(
"conv(" + q +
"1011" + q +
", 2, -16)",
"B");
2417 TestStringValue(
"conv(" + q +
"-1" + q +
", 10, 16)",
"FFFFFFFFFFFFFFFF");
2418 TestStringValue(
"conv(" + q +
"-15" + q +
", 10, 16)",
"FFFFFFFFFFFFFFF1");
2422 TestStringValue(
"conv(" + q +
"17" + q +
", 7, 10)",
"1");
2423 TestStringValue(
"conv(" + q +
"371" + q +
", 7, 10)",
"3");
2424 TestStringValue(
"conv(" + q +
"371" + q +
", 7, 10)",
"3");
2425 TestStringValue(
"conv(" + q +
"445" + q +
", 5, 10)",
"24");
2429 TestStringValue(
"conv(" + q + lexical_cast<string>(numeric_limits<int64_t>::max())
2430 + q +
", 36, 16)",
"FFFFFFFFFFFFFFFF");
2431 TestStringValue(
"conv(" + q + lexical_cast<string>(numeric_limits<int64_t>::max())
2432 + q +
", 36, -16)",
"-1");
2433 TestStringValue(
"conv(" + q + lexical_cast<string>(numeric_limits<int64_t>::min()+1)
2434 + q +
", 36, 16)",
"FFFFFFFFFFFFFFFF");
2435 TestStringValue(
"conv(" + q + lexical_cast<string>(numeric_limits<int64_t>::min()+1)
2436 + q +
", 36, -16)",
"-1");
2440 TestStringValue(
"conv('@', 16, 10)",
"0");
2441 TestStringValue(
"conv('$123', 12, 2)",
"0");
2442 TestStringValue(
"conv('*12g', 32, 5)",
"0");
2451 TestIsNull(
"conv(NULL, NULL, NULL)",
TYPE_STRING);
2457 TestValue(
"abs(cast(-1.0 as double))",
TYPE_DOUBLE, 1.0);
2458 TestValue(
"abs(cast(1.0 as double))",
TYPE_DOUBLE, 1.0);
2474 TestValue(
"log10(50.0)",
TYPE_DOUBLE, log10(50.0));
2476 TestValue(
"log2(678.0)",
TYPE_DOUBLE, log(678.0) / log(2.0));
2477 TestValue(
"log(10.0, 1000.0)",
TYPE_DOUBLE, log(1000.0) / log(10.0));
2479 TestValue(
"pow(2.0, 10.0)",
TYPE_DOUBLE, pow(2.0, 10.0));
2480 TestValue(
"pow(e(), 2.0)",
TYPE_DOUBLE, M_E * M_E);
2481 TestValue(
"power(2.0, 10.0)",
TYPE_DOUBLE, pow(2.0, 10.0));
2482 TestValue(
"power(e(), 2.0)",
TYPE_DOUBLE, M_E * M_E);
2488 double expected =
static_cast<double>(rand_r(&seed)) / static_cast<double>(RAND_MAX);
2492 expected =
static_cast<double>(rand_r(&seed)) / static_cast<double>(RAND_MAX);
2501 TestValue(
"pmod(1234567890, 13)",
TYPE_BIGINT, 10);
2502 TestValue(
"pmod(-1234567890, 13)",
TYPE_BIGINT, 3);
2503 TestValue(
"pmod(1234567890, -13)",
TYPE_BIGINT, -3);
2504 TestValue(
"pmod(-1234567890, -13)",
TYPE_BIGINT, -10);
2506 TestValue(
"pmod(12.3, 4.0)",
TYPE_DOUBLE, fmod(fmod(12.3, 4.0) + 4.0, 4.0));
2507 TestValue(
"pmod(-12.3, 4.0)",
TYPE_DOUBLE, fmod(fmod(-12.3, 4.0) + 4.0, 4.0));
2508 TestValue(
"pmod(12.3, -4.0)",
TYPE_DOUBLE, fmod(fmod(12.3, -4.0) - 4.0, -4.0));
2509 TestValue(
"pmod(-12.3, -4.0)",
TYPE_DOUBLE, fmod(fmod(-12.3, -4.0) - 4.0, -4.0));
2510 TestValue(
"pmod(123456.789, 13.456)",
TYPE_DOUBLE,
2511 fmod(fmod(123456.789, 13.456) + 13.456, 13.456));
2512 TestValue(
"pmod(-123456.789, 13.456)",
TYPE_DOUBLE,
2513 fmod(fmod(-123456.789, 13.456) + 13.456, 13.456));
2514 TestValue(
"pmod(123456.789, -13.456)",
TYPE_DOUBLE,
2515 fmod(fmod(123456.789, -13.456) - 13.456, -13.456));
2516 TestValue(
"pmod(-123456.789, -13.456)",
TYPE_DOUBLE,
2517 fmod(fmod(-123456.789, -13.456) - 13.456, -13.456));
2520 TestValue(
"fmod(cast(12345.345 as float), cast(7 as float))",
2522 TestValue(
"fmod(cast(-12345.345 as float), cast(7 as float))",
2524 TestValue(
"fmod(cast(-12345.345 as float), cast(-7 as float))",
2526 TestValue(
"fmod(cast(12345.345 as double), 7)",
TYPE_DOUBLE, fmod(12345.345, 7.0));
2527 TestValue(
"fmod(-12345.345, cast(7 as double))",
TYPE_DOUBLE, fmod(-12345.345, 7.0));
2528 TestValue(
"fmod(cast(-12345.345 as double), -7)",
TYPE_DOUBLE, fmod(-12345.345, -7.0));
2530 TestValue(
"cast(12345.345 as float) % cast(7 as float)",
2532 TestValue(
"cast(-12345.345 as float) % cast(7 as float)",
2534 TestValue(
"cast(-12345.345 as float) % cast(-7 as float)",
2536 TestValue(
"cast(12345.345 as double) % 7",
TYPE_DOUBLE, fmod(12345.345, 7.0));
2537 TestValue(
"-12345.345 % cast(7 as double)",
TYPE_DOUBLE, fmod(-12345.345, 7.0));
2538 TestValue(
"cast(-12345.345 as double) % -7",
TYPE_DOUBLE, fmod(-12345.345, -7.0));
2540 TestIsNull(
"fmod(cast(-12345.345 as float), cast(0 as float))",
TYPE_FLOAT);
2541 TestIsNull(
"fmod(cast(-12345.345 as double), 0)",
TYPE_DOUBLE);
2542 TestIsNull(
"cast(-12345.345 as float) % cast(0 as float)",
TYPE_FLOAT);
2543 TestIsNull(
"cast(-12345.345 as double) % 0",
TYPE_DOUBLE);
2546 TestValue(
"mod(cast(10 as tinyint), cast(3 as tinyint))",
TYPE_TINYINT, 10 % 3);
2547 TestValue(
"mod(cast(10 as smallint), cast(3 as smallint))",
TYPE_SMALLINT, 10 % 3);
2548 TestValue(
"mod(cast(10 as int), cast(3 as int))",
TYPE_INT, 10 % 3);
2549 TestValue(
"mod(cast(10 as bigint), cast(3 as bigint))",
TYPE_BIGINT, 10 % 3);
2550 TestIsNull(
"mod(cast(123 as tinyint), 0)",
TYPE_TINYINT);
2552 TestIsNull(
"mod(cast(123 as int), 0)",
TYPE_INT);
2553 TestIsNull(
"mod(cast(123 as bigint), 0)",
TYPE_BIGINT);
2554 TestIsNull(
"mod(cast(123 as tinyint), NULL)",
TYPE_TINYINT);
2555 TestIsNull(
"mod(cast(123 as smallint), NULL)",
TYPE_SMALLINT);
2556 TestIsNull(
"mod(cast(123 as int), NULL)",
TYPE_INT);
2557 TestIsNull(
"mod(cast(123 as bigint), NULL)",
TYPE_BIGINT);
2558 TestIsNull(
"mod(cast(NULL as int), NULL)",
TYPE_INT);
2560 TestValue(
"mod(cast(12.3 as float), cast(4.0 as float))",
TYPE_FLOAT, fmodf(12.3f, 4.0f));
2561 TestValue(
"mod(cast(12.3 as double), cast(4.0 as double))",
TYPE_DOUBLE, fmod(12.3, 4.0));
2562 TestIsNull(
"mod(cast(12345.345 as float), cast(0 as float))",
TYPE_FLOAT);
2563 TestIsNull(
"mod(cast(12345.345 as double), cast(0 as double))",
TYPE_DOUBLE);
2564 TestIsNull(
"mod(cast(12345.345 as float), NULL)",
TYPE_FLOAT);
2565 TestIsNull(
"mod(cast(12345.345 as double), NULL)",
TYPE_DOUBLE);
2566 TestIsNull(
"mod(cast(NULL as float), NULL)",
TYPE_FLOAT);
2569 TestValue(
"positive(cast(123 as tinyint))",
TYPE_TINYINT, 123);
2570 TestValue(
"positive(cast(123 as smallint))",
TYPE_SMALLINT, 123);
2571 TestValue(
"positive(cast(123 as int))",
TYPE_INT, 123);
2572 TestValue(
"positive(cast(123 as bigint))",
TYPE_BIGINT, 123);
2573 TestValue(
"positive(cast(3.1415 as float))",
TYPE_FLOAT, 3.1415f);
2574 TestValue(
"positive(cast(3.1415 as double))",
TYPE_DOUBLE, 3.1415);
2575 TestValue(
"positive(cast(-123 as tinyint))",
TYPE_TINYINT, -123);
2576 TestValue(
"positive(cast(-123 as smallint))",
TYPE_SMALLINT, -123);
2577 TestValue(
"positive(cast(-123 as int))",
TYPE_INT, -123);
2578 TestValue(
"positive(cast(-123 as bigint))",
TYPE_BIGINT, -123);
2579 TestValue(
"positive(cast(-3.1415 as float))",
TYPE_FLOAT, -3.1415f);
2580 TestValue(
"positive(cast(-3.1415 as double))",
TYPE_DOUBLE, -3.1415);
2582 TestValue(
"negative(cast(123 as tinyint))",
TYPE_TINYINT, -123);
2583 TestValue(
"negative(cast(123 as smallint))",
TYPE_SMALLINT, -123);
2584 TestValue(
"negative(cast(123 as int))",
TYPE_INT, -123);
2585 TestValue(
"negative(cast(123 as bigint))",
TYPE_BIGINT, -123);
2586 TestValue(
"negative(cast(3.1415 as float))",
TYPE_FLOAT, -3.1415f);
2587 TestValue(
"negative(cast(3.1415 as double))",
TYPE_DOUBLE, -3.1415);
2588 TestValue(
"negative(cast(-123 as tinyint))",
TYPE_TINYINT, 123);
2589 TestValue(
"negative(cast(-123 as smallint))",
TYPE_SMALLINT, 123);
2590 TestValue(
"negative(cast(-123 as int))",
TYPE_INT, 123);
2591 TestValue(
"negative(cast(-123 as bigint))",
TYPE_BIGINT, 123);
2592 TestValue(
"negative(cast(-3.1415 as float))",
TYPE_FLOAT, 3.1415f);
2593 TestValue(
"negative(cast(-3.1415 as double))",
TYPE_DOUBLE, 3.1415);
2600 TestValue(
"quotient(30.5, 2.5)",
TYPE_BIGINT, 15);
2601 TestValue(
"quotient(-30.5, 2.5)",
TYPE_BIGINT, -15);
2602 TestIsNull(
"quotient(-30.5, 0.000999)",
TYPE_BIGINT);
2608 TestValue<float>(
"least(cast(1.25 as float))",
TYPE_FLOAT, 1.25f);
2612 TestValue<float>(
"least(cast(500.25 as float), 300.25)",
TYPE_FLOAT, 300.25f);
2613 TestValue<float>(
"least(cast(300.25 as float), 500.25)",
TYPE_FLOAT, 300.25f);
2616 TestValue<float>(
"least(cast(1.25 as float), 3.25, 4.25, 0.25, 6.25)",
2620 TestValue<float>(
"least(cast(1.0 as float), 1.0, 1.0, 1.0)",
TYPE_FLOAT, 1.0f);
2624 TestValue<float>(
"least(cast(2.0 as float), 2.0, 1.0, 1.0)",
TYPE_FLOAT, 1.0f);
2625 TestValue<float>(
"least(cast(0.0 as float), -2.0, 1.0)",
TYPE_FLOAT, -2.0f);
2629 BOOST_FOREACH(IntValMap::value_type& entry, min_int_values_) {
2630 string val_str = lexical_cast<
string>(entry.second);
2631 val_list.append(
", " + val_str);
2633 TestValue<int64_t>(
"least(" + val_list +
")", t, 0);
2636 TestValue<double>(
"least(0.0, cast(-2.0 as double), 1.0)",
TYPE_DOUBLE, -2.0f);
2638 TestStringValue(
"cast(least(cast('2014-09-26 12:00:00' as timestamp), "
2639 "cast('2013-09-26 12:00:00' as timestamp)) as string)",
"2013-09-26 12:00:00");
2641 TestStringValue(
"least('2', '5', '12', '3')",
"12");
2642 TestStringValue(
"least('apples', 'oranges', 'bananas')",
"apples");
2643 TestStringValue(
"least('apples', 'applis', 'applas')",
"applas");
2644 TestStringValue(
"least('apples', '!applis', 'applas')",
"!applis");
2645 TestStringValue(
"least('apples', 'apples', 'apples')",
"apples");
2646 TestStringValue(
"least('apples')",
"apples");
2647 TestStringValue(
"least('A')",
"A");
2648 TestStringValue(
"least('A', 'a')",
"A");
2650 TestStringValue(
"least('a', 'A')",
"A");
2651 TestStringValue(
"least('APPLES', 'APPLES')",
"APPLES");
2652 TestStringValue(
"least('apples', 'APPLES')",
"APPLES");
2653 TestStringValue(
"least('apples', 'app\nles')",
"app\nles");
2654 TestStringValue(
"least('apples', 'app les')",
"app les");
2655 TestStringValue(
"least('apples', 'app\nles')",
"app\nles");
2656 TestStringValue(
"least('apples', 'app\tles')",
"app\tles");
2657 TestStringValue(
"least('apples', 'app\fles')",
"app\fles");
2658 TestStringValue(
"least('apples', 'app\vles')",
"app\vles");
2659 TestStringValue(
"least('apples', 'app\rles')",
"app\rles");
2664 TestValue<float>(
"greatest(cast(1.25 as float))",
TYPE_FLOAT, 1.25f);
2668 TestValue<float>(
"greatest(cast(500.25 as float), 300.25)",
TYPE_FLOAT, 500.25f);
2669 TestValue<float>(
"greatest(cast(300.25 as float), 500.25)",
TYPE_FLOAT, 500.25f);
2672 TestValue<float>(
"greatest(cast(1.25 as float), 3.25, 4.25, 0.25, 6.25)",
2676 TestValue<float>(
"greatest(cast(1.0 as float), 1.0, 1.0, 1.0)",
TYPE_FLOAT, 1.0f);
2680 TestValue<float>(
"greatest(cast(2.0 as float), 2.0, 1.0, 1.0)",
TYPE_FLOAT, 2.0f);
2681 TestValue<float>(
"greatest(cast(0.0 as float), -2.0, 1.0)",
TYPE_FLOAT, 1.0f);
2685 BOOST_FOREACH(IntValMap::value_type& entry, min_int_values_) {
2686 string val_str = lexical_cast<
string>(entry.second);
2687 val_list.append(
", " + val_str);
2689 TestValue<int64_t>(
"greatest(" + val_list +
")", t, entry.second);
2692 TestValue<double>(
"greatest(cast(0.0 as float), cast(-2.0 as double), 1.0)",
2695 TestStringValue(
"cast(greatest(cast('2014-09-26 12:00:00' as timestamp), "
2696 "cast('2013-09-26 12:00:00' as timestamp)) as string)",
"2014-09-26 12:00:00");
2698 TestStringValue(
"greatest('2', '5', '12', '3')",
"5");
2699 TestStringValue(
"greatest('apples', 'oranges', 'bananas')",
"oranges");
2700 TestStringValue(
"greatest('apples', 'applis', 'applas')",
"applis");
2701 TestStringValue(
"greatest('apples', '!applis', 'applas')",
"apples");
2702 TestStringValue(
"greatest('apples', 'apples', 'apples')",
"apples");
2703 TestStringValue(
"greatest('apples')",
"apples");
2704 TestStringValue(
"greatest('A')",
"A");
2705 TestStringValue(
"greatest('A', 'a')",
"a");
2707 TestStringValue(
"greatest('a', 'A')",
"a");
2708 TestStringValue(
"greatest('APPLES', 'APPLES')",
"APPLES");
2709 TestStringValue(
"greatest('apples', 'APPLES')",
"apples");
2710 TestStringValue(
"greatest('apples', 'app\nles')",
"apples");
2711 TestStringValue(
"greatest('apples', 'app les')",
"apples");
2712 TestStringValue(
"greatest('apples', 'app\nles')",
"apples");
2713 TestStringValue(
"greatest('apples', 'app\tles')",
"apples");
2714 TestStringValue(
"greatest('apples', 'app\fles')",
"apples");
2715 TestStringValue(
"greatest('apples', 'app\vles')",
"apples");
2716 TestStringValue(
"greatest('apples', 'app\rles')",
"apples");
2720 TestIsNull(
"sign(NULL)", TYPE_FLOAT);
2721 TestIsNull(
"exp(NULL)", TYPE_DOUBLE);
2722 TestIsNull(
"ln(NULL)", TYPE_DOUBLE);
2723 TestIsNull(
"log10(NULL)", TYPE_DOUBLE);
2724 TestIsNull(
"log2(NULL)", TYPE_DOUBLE);
2725 TestIsNull(
"log(NULL, 64.0)", TYPE_DOUBLE);
2726 TestIsNull(
"log(2.0, NULL)", TYPE_DOUBLE);
2727 TestIsNull(
"log(NULL, NULL)", TYPE_DOUBLE);
2728 TestIsNull(
"pow(NULL, 10.0)", TYPE_DOUBLE);
2729 TestIsNull(
"pow(2.0, NULL)", TYPE_DOUBLE);
2730 TestIsNull(
"pow(NULL, NULL)", TYPE_DOUBLE);
2731 TestIsNull(
"power(NULL, 10.0)", TYPE_DOUBLE);
2732 TestIsNull(
"power(2.0, NULL)", TYPE_DOUBLE);
2733 TestIsNull(
"power(NULL, NULL)", TYPE_DOUBLE);
2734 TestIsNull(
"sqrt(NULL)", TYPE_DOUBLE);
2735 TestIsNull(
"rand(NULL)", TYPE_DOUBLE);
2739 TestIsNull(
"fmod(NULL, cast(3.2 as float))", TYPE_FLOAT);
2740 TestIsNull(
"fmod(cast(10.3 as float), NULL)", TYPE_FLOAT);
2741 TestIsNull(
"fmod(NULL, cast(3.2 as double))", TYPE_DOUBLE);
2742 TestIsNull(
"fmod(cast(10.3 as double), NULL)", TYPE_DOUBLE);
2743 TestIsNull(
"NULL % cast(3.2 as float)", TYPE_FLOAT);
2744 TestIsNull(
"cast(10.3 as float) % NULL", TYPE_FLOAT);
2745 TestIsNull(
"NULL % cast(3.2 as double)", TYPE_DOUBLE);
2746 TestIsNull(
"cast(10.3 as double) % NULL", TYPE_DOUBLE);
2747 TestIsNull(
"fmod(NULL, NULL)", TYPE_FLOAT);
2748 TestIsNull(
"NULL % NULL", TYPE_DOUBLE);
2755 TestIsNull(
"least(cast(NULL as tinyint))",
TYPE_TINYINT);
2757 TestIsNull(
"least(cast(NULL as int))",
TYPE_INT);
2758 TestIsNull(
"least(cast(NULL as bigint))",
TYPE_BIGINT);
2759 TestIsNull(
"least(cast(NULL as float))", TYPE_FLOAT);
2760 TestIsNull(
"least(cast(NULL as double))", TYPE_DOUBLE);
2763 TestIsNull(
"greatest(cast(NULL as tinyint))",
TYPE_TINYINT);
2764 TestIsNull(
"greatest(cast(NULL as smallint))",
TYPE_SMALLINT);
2765 TestIsNull(
"greatest(cast(NULL as int))",
TYPE_INT);
2766 TestIsNull(
"greatest(cast(NULL as bigint))",
TYPE_BIGINT);
2767 TestIsNull(
"greatest(cast(NULL as float))", TYPE_FLOAT);
2768 TestIsNull(
"greatest(cast(NULL as double))", TYPE_DOUBLE);
2773 TestValue(
"ceil(cast(0.1 as double))",
TYPE_BIGINT, 1);
2774 TestValue(
"ceil(cast(-10.05 as double))",
TYPE_BIGINT, -10);
2775 TestValue(
"ceiling(cast(0.1 as double))",
TYPE_BIGINT, 1);
2776 TestValue(
"ceiling(cast(-10.05 as double))",
TYPE_BIGINT, -10);
2777 TestValue(
"floor(cast(0.1 as double))",
TYPE_BIGINT, 0);
2778 TestValue(
"floor(cast(-10.007 as double))",
TYPE_BIGINT, -11);
2780 TestValue(
"round(cast(1.499999 as double))",
TYPE_BIGINT, 1);
2781 TestValue(
"round(cast(1.5 as double))",
TYPE_BIGINT, 2);
2782 TestValue(
"round(cast(1.500001 as double))",
TYPE_BIGINT, 2);
2783 TestValue(
"round(cast(-1.499999 as double))",
TYPE_BIGINT, -1);
2784 TestValue(
"round(cast(-1.5 as double))",
TYPE_BIGINT, -2);
2785 TestValue(
"round(cast(-1.500001 as double))",
TYPE_BIGINT, -2);
2787 TestValue(
"round(cast(3.14159265 as double), 0)",
TYPE_DOUBLE, 3.0);
2788 TestValue(
"round(cast(3.14159265 as double), 1)",
TYPE_DOUBLE, 3.1);
2789 TestValue(
"round(cast(3.14159265 as double), 2)",
TYPE_DOUBLE, 3.14);
2790 TestValue(
"round(cast(3.14159265 as double), 3)",
TYPE_DOUBLE, 3.142);
2791 TestValue(
"round(cast(3.14159265 as double), 4)",
TYPE_DOUBLE, 3.1416);
2792 TestValue(
"round(cast(3.14159265 as double), 5)",
TYPE_DOUBLE, 3.14159);
2793 TestValue(
"round(cast(-3.14159265 as double), 0)",
TYPE_DOUBLE, -3.0);
2794 TestValue(
"round(cast(-3.14159265 as double), 1)",
TYPE_DOUBLE, -3.1);
2795 TestValue(
"round(cast(-3.14159265 as double), 2)",
TYPE_DOUBLE, -3.14);
2796 TestValue(
"round(cast(-3.14159265 as double), 3)",
TYPE_DOUBLE, -3.142);
2797 TestValue(
"round(cast(-3.14159265 as double), 4)",
TYPE_DOUBLE, -3.1416);
2798 TestValue(
"round(cast(-3.14159265 as double), 5)",
TYPE_DOUBLE, -3.14159);
2801 TestIsNull(
"ceil(cast(NULL as double))",
TYPE_BIGINT);
2802 TestIsNull(
"ceiling(cast(NULL as double))",
TYPE_BIGINT);
2803 TestIsNull(
"floor(cast(NULL as double))",
TYPE_BIGINT);
2804 TestIsNull(
"round(cast(NULL as double))",
TYPE_BIGINT);
2805 TestIsNull(
"round(cast(NULL as double), 1)",
TYPE_DOUBLE);
2806 TestIsNull(
"round(cast(3.14159265 as double), NULL)",
TYPE_DOUBLE);
2807 TestIsNull(
"round(cast(NULL as double), NULL)",
TYPE_DOUBLE);
2817 TestValue(
"+cast(1. as float)",
TYPE_FLOAT, 1.0f);
2818 TestValue(
"+cast(1.0 as float)",
TYPE_FLOAT, 1.0f);
2819 TestValue(
"-cast(1.0 as float)",
TYPE_DOUBLE, -1.0);
2827 TestStringValue(
"cast(from_utc_timestamp(cast(1301180400 as timestamp),"
2828 "'Europe/Moscow') as string)",
"2011-03-27 03:00:00");
2829 TestStringValue(
"cast(from_utc_timestamp(cast(1301180399 as timestamp),"
2830 "'Europe/Moscow') as string)",
"2011-03-27 01:59:59");
2831 TestStringValue(
"cast(from_utc_timestamp(cast(1288404000 as timestamp),"
2832 "'Europe/Moscow') as string)",
"2010-10-30 06:00:00");
2833 TestStringValue(
"cast(from_utc_timestamp(cast(1288584000 as timestamp),"
2834 "'Europe/Moscow') as string)",
"2010-11-01 07:00:00");
2835 TestStringValue(
"cast(from_utc_timestamp(cast(1301104740 as timestamp),"
2836 "'Europe/Moscow') as string)",
"2011-03-26 04:59:00");
2837 TestStringValue(
"cast(from_utc_timestamp(cast(1301277600 as timestamp),"
2838 "'Europe/Moscow') as string)",
"2011-03-28 06:00:00");
2839 TestStringValue(
"cast(from_utc_timestamp(cast(1324947600 as timestamp),"
2840 "'Europe/Moscow') as string)",
"2011-12-27 05:00:00");
2841 TestStringValue(
"cast(from_utc_timestamp(cast(1325725200 as timestamp),"
2842 "'Europe/Moscow') as string)",
"2012-01-05 05:00:00");
2843 TestStringValue(
"cast(from_utc_timestamp(cast(1333594800 as timestamp),"
2844 "'Europe/Moscow') as string)",
"2012-04-05 07:00:00");
2847 TestIsNull(
"cast(cast('NOTATIMESTAMP' as timestamp) as string)",
TYPE_STRING);
2849 TestStringValue(
"cast(cast('2012-01-01 09:10:11.123456789' as timestamp) as string)",
2850 "2012-01-01 09:10:11.123456789");
2852 TestStringValue(
"cast(date_add(cast('2012-01-01 09:10:11.123456789' "
2853 "as timestamp), interval 10 years) as string)",
2854 "2022-01-01 09:10:11.123456789");
2855 TestStringValue(
"cast(date_sub(cast('2012-01-01 09:10:11.123456789' "
2856 "as timestamp), interval 10 years) as string)",
2857 "2002-01-01 09:10:11.123456789");
2858 TestStringValue(
"cast(date_add(cast('2012-01-01 09:10:11.123456789' "
2859 "as timestamp), interval cast(10 as bigint) years) as string)",
2860 "2022-01-01 09:10:11.123456789");
2861 TestStringValue(
"cast(date_sub(cast('2012-01-01 09:10:11.123456789' "
2862 "as timestamp), interval cast(10 as bigint) years) as string)",
2863 "2002-01-01 09:10:11.123456789");
2868 "CAST('2005-10-11 00:00:00' AS TIMESTAMP) - INTERVAL 718 YEAR",
TYPE_TIMESTAMP);
2870 "CAST('2005-10-11 00:00:00' AS TIMESTAMP) + INTERVAL -718 YEAR",
TYPE_TIMESTAMP);
2872 "CAST('2005-10-11 00:00:00' AS TIMESTAMP) + INTERVAL 9718 YEAR",
TYPE_TIMESTAMP);
2874 "CAST('2005-10-11 00:00:00' AS TIMESTAMP) - INTERVAL -9718 YEAR",
TYPE_TIMESTAMP);
2876 TestStringValue(
"cast(date_add(cast('2012-01-01 09:10:11.123456789' "
2877 "as timestamp), interval 13 months) as string)",
2878 "2013-02-01 09:10:11.123456789");
2879 TestStringValue(
"cast(date_sub(cast('2013-02-01 09:10:11.123456789' "
2880 "as timestamp), interval 13 months) as string)",
2881 "2012-01-01 09:10:11.123456789");
2882 TestStringValue(
"cast(date_add(cast('2012-01-31 09:10:11.123456789' "
2883 "as timestamp), interval cast(1 as bigint) month) as string)",
2884 "2012-02-29 09:10:11.123456789");
2885 TestStringValue(
"cast(date_sub(cast('2012-02-29 09:10:11.123456789' "
2886 "as timestamp), interval cast(1 as bigint) month) as string)",
2887 "2012-01-31 09:10:11.123456789");
2889 TestStringValue(
"cast(date_add(cast('2012-01-01 09:10:11.123456789' "
2890 "as timestamp), interval 2 weeks) as string)",
2891 "2012-01-15 09:10:11.123456789");
2892 TestStringValue(
"cast(date_sub(cast('2012-01-15 09:10:11.123456789' "
2893 "as timestamp), interval 2 weeks) as string)",
2894 "2012-01-01 09:10:11.123456789");
2895 TestStringValue(
"cast(date_add(cast('2012-01-01 09:10:11.123456789' "
2896 "as timestamp), interval cast(53 as bigint) weeks) as string)",
2897 "2013-01-06 09:10:11.123456789");
2898 TestStringValue(
"cast(date_sub(cast('2013-01-06 09:10:11.123456789' "
2899 "as timestamp), interval cast(53 as bigint) weeks) as string)",
2900 "2012-01-01 09:10:11.123456789");
2902 TestStringValue(
"cast(date_add(cast('2012-01-01 09:10:11.123456789' "
2903 "as timestamp), interval 10 days) as string)",
2904 "2012-01-11 09:10:11.123456789");
2905 TestStringValue(
"cast(date_sub(cast('2012-01-01 09:10:11.123456789' "
2906 "as timestamp), interval 10 days) as string)",
2907 "2011-12-22 09:10:11.123456789");
2908 TestStringValue(
"cast(date_add(cast('2011-12-22 09:10:11.12345678' "
2909 "as timestamp), interval cast(10 as bigint) days) as string)",
2910 "2012-01-01 09:10:11.123456780");
2911 TestStringValue(
"cast(date_sub(cast('2011-12-22 09:10:11.12345678' "
2912 "as timestamp), interval cast(365 as bigint) days) as string)",
2913 "2010-12-22 09:10:11.123456780");
2915 TestStringValue(
"cast(date_add(cast('2012-01-01 09:10:11.123456789' "
2916 "as timestamp), 10) as string)",
2917 "2012-01-11 09:10:11.123456789");
2919 "cast(date_sub(cast('2012-01-01 09:10:11.123456789' as timestamp), 10) as string)",
2920 "2011-12-22 09:10:11.123456789");
2922 "cast(date_add(cast('2011-12-22 09:10:11.12345678' as timestamp),"
2923 "cast(10 as bigint)) as string)",
"2012-01-01 09:10:11.123456780");
2925 "cast(date_sub(cast('2011-12-22 09:10:11.12345678' as timestamp),"
2926 "cast(365 as bigint)) as string)",
"2010-12-22 09:10:11.123456780");
2928 TestStringValue(
"cast(date_add(cast('2012-01-01 00:00:00.123456789' "
2929 "as timestamp), interval 25 hours) as string)",
2930 "2012-01-02 01:00:00.123456789");
2931 TestStringValue(
"cast(date_sub(cast('2012-01-02 01:00:00.123456789' "
2932 "as timestamp), interval 25 hours) as string)",
2933 "2012-01-01 00:00:00.123456789");
2934 TestStringValue(
"cast(date_add(cast('2012-01-01 00:00:00.123456789' "
2935 "as timestamp), interval cast(25 as bigint) hours) as string)",
2936 "2012-01-02 01:00:00.123456789");
2937 TestStringValue(
"cast(date_sub(cast('2012-01-02 01:00:00.123456789' "
2938 "as timestamp), interval cast(25 as bigint) hours) as string)",
2939 "2012-01-01 00:00:00.123456789");
2941 TestStringValue(
"cast(date_add(cast('2012-01-01 00:00:00.123456789' "
2942 "as timestamp), interval 1533 minutes) as string)",
2943 "2012-01-02 01:33:00.123456789");
2944 TestStringValue(
"cast(date_sub(cast('2012-01-02 01:33:00.123456789' "
2945 "as timestamp), interval 1533 minutes) as string)",
2946 "2012-01-01 00:00:00.123456789");
2947 TestStringValue(
"cast(date_add(cast('2012-01-01 00:00:00.123456789' "
2948 "as timestamp), interval cast(1533 as bigint) minutes) as string)",
2949 "2012-01-02 01:33:00.123456789");
2950 TestStringValue(
"cast(date_sub(cast('2012-01-02 01:33:00.123456789' "
2951 "as timestamp), interval cast(1533 as bigint) minutes) as string)",
2952 "2012-01-01 00:00:00.123456789");
2954 TestStringValue(
"cast(date_add(cast('2012-01-01 00:00:00.123456789' "
2955 "as timestamp), interval 90033 seconds) as string)",
2956 "2012-01-02 01:00:33.123456789");
2957 TestStringValue(
"cast(date_sub(cast('2012-01-02 01:00:33.123456789' "
2958 "as timestamp), interval 90033 seconds) as string)",
2959 "2012-01-01 00:00:00.123456789");
2960 TestStringValue(
"cast(date_add(cast('2012-01-01 00:00:00.123456789' "
2961 "as timestamp), interval cast(90033 as bigint) seconds) as string)",
2962 "2012-01-02 01:00:33.123456789");
2963 TestStringValue(
"cast(date_sub(cast('2012-01-02 01:00:33.123456789' "
2964 "as timestamp), interval cast(90033 as bigint) seconds) as string)",
2965 "2012-01-01 00:00:00.123456789");
2967 TestStringValue(
"cast(date_add(cast('2012-01-01 00:00:00.000000001' "
2968 "as timestamp), interval 90000033 milliseconds) as string)",
2969 "2012-01-02 01:00:00.033000001");
2970 TestStringValue(
"cast(date_sub(cast('2012-01-02 01:00:00.033000001' "
2971 "as timestamp), interval 90000033 milliseconds) as string)",
2972 "2012-01-01 00:00:00.000000001");
2973 TestStringValue(
"cast(date_add(cast('2012-01-01 00:00:00.000000001' "
2974 "as timestamp), interval cast(90000033 as bigint) milliseconds) as string)",
2975 "2012-01-02 01:00:00.033000001");
2976 TestStringValue(
"cast(date_sub(cast('2012-01-02 01:00:00.033000001' "
2977 "as timestamp), interval cast(90000033 as bigint) milliseconds) as string)",
2978 "2012-01-01 00:00:00.000000001");
2980 TestStringValue(
"cast(date_add(cast('2012-01-01 00:00:00.000000001' "
2981 "as timestamp), interval 1033 microseconds) as string)",
2982 "2012-01-01 00:00:00.001033001");
2983 TestStringValue(
"cast(date_sub(cast('2012-01-01 00:00:00.001033001' "
2984 "as timestamp), interval 1033 microseconds) as string)",
2985 "2012-01-01 00:00:00.000000001");
2986 TestStringValue(
"cast(date_add(cast('2012-01-01 00:00:00.000000001' "
2987 "as timestamp), interval cast(1033 as bigint) microseconds) as string)",
2988 "2012-01-01 00:00:00.001033001");
2989 TestStringValue(
"cast(date_sub(cast('2012-01-01 00:00:00.001033001' "
2990 "as timestamp), interval cast(1033 as bigint) microseconds) as string)",
2991 "2012-01-01 00:00:00.000000001");
2993 TestStringValue(
"cast(date_add(cast('2012-01-01 00:00:00.000000001' "
2994 "as timestamp), interval 1033 nanoseconds) as string)",
2995 "2012-01-01 00:00:00.000001034");
2996 TestStringValue(
"cast(date_sub(cast('2012-01-01 00:00:00.000001034' "
2997 "as timestamp), interval 1033 nanoseconds) as string)",
2998 "2012-01-01 00:00:00.000000001");
2999 TestStringValue(
"cast(date_add(cast('2012-01-01 00:00:00.000000001' "
3000 "as timestamp), interval cast(1033 as bigint) nanoseconds) as string)",
3001 "2012-01-01 00:00:00.000001034");
3002 TestStringValue(
"cast(date_sub(cast('2012-01-01 00:00:00.000001034' "
3003 "as timestamp), interval cast(1033 as bigint) nanoseconds) as string)",
3004 "2012-01-01 00:00:00.000000001");
3008 TestIsNull(
"date_add(cast('2012-01-01 09:10:11.123456789' as timestamp),"
3010 TestIsNull(
"date_add(NULL, interval NULL years)",
TYPE_TIMESTAMP);
3012 TestIsNull(
"date_sub(cast('2012-01-01 09:10:11.123456789' as timestamp),"
3014 TestIsNull(
"date_sub(NULL, interval NULL years)",
TYPE_TIMESTAMP);
3017 string max_int = lexical_cast<
string>(numeric_limits<int32_t>::max());
3018 string max_long = lexical_cast<
string>(numeric_limits<int32_t>::max());
3020 "cast(years_add(cast('2000-01-01 00:00:00' "
3021 "as timestamp), " + max_int +
") as string)",
3022 "1999-01-01 00:00:00");
3024 "cast(years_sub(cast('2000-01-01 00:00:00' "
3025 "as timestamp), " + max_long +
") as string)",
3026 "2001-01-01 00:00:00");
3028 "cast(years_add(cast('2000-01-01 00:00:00' "
3029 "as timestamp), " + max_int +
") as string)",
3030 "1999-01-01 00:00:00");
3032 "cast(years_sub(cast('2000-01-01 00:00:00' "
3033 "as timestamp), " + max_long +
") as string)",
3034 "2001-01-01 00:00:00");
3037 TestTimestampUnixEpochConversions(0,
"1970-01-01 00:00:00");
3040 TestValue(
"unix_timestamp('2038-01-19 03:14:07')",
TYPE_BIGINT, 2147483647);
3041 TestValue(
"unix_timestamp('2038-01-19 03:14:08')",
TYPE_BIGINT, 2147483648);
3042 TestValue(
"unix_timestamp('2038/01/19 03:14:08', 'yyyy/MM/dd HH:mm:ss')",
TYPE_BIGINT,
3044 TestValue(
"unix_timestamp(cast('2038-01-19 03:14:08' as timestamp))",
TYPE_BIGINT,
3052 ptime local_time_at_epoch = c_local_adjustor<ptime>::utc_to_local(from_time_t(0));
3054 string local_time_at_epoch_as_str = to_iso_extended_string(local_time_at_epoch.date())
3055 +
" " + to_simple_string(local_time_at_epoch.time_of_day());
3058 int64_t unix_time_at_local_epoch =
3059 (from_time_t(0) - local_time_at_epoch).total_seconds();
3060 TestTimestampUnixEpochConversions(unix_time_at_local_epoch,
3061 local_time_at_epoch_as_str);
3066 TestValue(
"unix_timestamp('2015-01-01')",
TYPE_BIGINT, 1420099200);
3067 TestValue(
"unix_timestamp('2015-07-01')",
TYPE_BIGINT, 1435734000);
3071 TestValue(
"unix_timestamp('2015-01-01')",
TYPE_BIGINT, 1420088400);
3072 TestValue(
"unix_timestamp('2015-07-01')",
TYPE_BIGINT, 1435723200);
3076 TestIsNull(
"from_unixtime(NULL, 'yyyy-MM-dd')",
TYPE_STRING);
3077 TestStringValue(
"from_unixtime(unix_timestamp('1999-01-01 10:10:10'), \
3078 'yyyy-MM-dd')",
"1999-01-01");
3079 TestStringValue(
"from_unixtime(unix_timestamp('1999-01-01 10:10:10'), \
3080 'yyyy-MM-dd HH:mm:ss')",
"1999-01-01 10:10:10");
3081 TestStringValue(
"from_unixtime(unix_timestamp('1999-01-01 10:10:10') + (60*60*24), \
3082 'yyyy-MM-dd')",
"1999-01-02");
3083 TestStringValue(
"from_unixtime(unix_timestamp('1999-01-01 10:10:10') + 10, \
3084 'yyyy-MM-dd HH:mm:ss')",
"1999-01-01 10:10:20");
3085 TestValue(
"cast('2011-12-22 09:10:11.123456789' as timestamp) > \
3086 cast('2011-12-22 09:10:11.12345678' as timestamp)",
TYPE_BOOLEAN,
true);
3087 TestValue(
"cast('2011-12-22 08:10:11.123456789' as timestamp) > \
3088 cast('2011-12-22 09:10:11.12345678' as timestamp)",
TYPE_BOOLEAN,
false);
3089 TestValue(
"cast('2011-12-22 09:10:11.000000' as timestamp) = \
3090 cast('2011-12-22 09:10:11' as timestamp)",
TYPE_BOOLEAN,
true);
3091 TestValue(
"year(cast('2011-12-22 09:10:11.000000' as timestamp))",
TYPE_INT, 2011);
3092 TestValue(
"month(cast('2011-12-22 09:10:11.000000' as timestamp))",
TYPE_INT, 12);
3093 TestValue(
"dayofmonth(cast('2011-12-22 09:10:11.000000' as timestamp))",
TYPE_INT, 22);
3094 TestValue(
"day(cast('2011-12-22 09:10:11.000000' as timestamp))",
TYPE_INT, 22);
3095 TestValue(
"dayofyear(cast('2011-12-22 09:10:11.000000' as timestamp))",
TYPE_INT, 356);
3096 TestValue(
"weekofyear(cast('2011-12-22 09:10:11.000000' as timestamp))",
TYPE_INT, 51);
3097 TestValue(
"dayofweek(cast('2011-12-18 09:10:11.000000' as timestamp))",
TYPE_INT, 1);
3098 TestValue(
"dayofweek(cast('2011-12-22 09:10:11.000000' as timestamp))",
TYPE_INT, 5);
3099 TestValue(
"dayofweek(cast('2011-12-24 09:10:11.000000' as timestamp))",
TYPE_INT, 7);
3100 TestValue(
"hour(cast('2011-12-22 09:10:11.000000' as timestamp))",
TYPE_INT, 9);
3101 TestValue(
"minute(cast('2011-12-22 09:10:11.000000' as timestamp))",
TYPE_INT, 10);
3102 TestValue(
"second(cast('2011-12-22 09:10:11.000000' as timestamp))",
TYPE_INT, 11);
3103 TestValue(
"year(cast('2011-12-22' as timestamp))",
TYPE_INT, 2011);
3104 TestValue(
"month(cast('2011-12-22' as timestamp))",
TYPE_INT, 12);
3105 TestValue(
"dayofmonth(cast('2011-12-22' as timestamp))",
TYPE_INT, 22);
3106 TestValue(
"day(cast('2011-12-22' as timestamp))",
TYPE_INT, 22);
3107 TestValue(
"dayofyear(cast('2011-12-22' as timestamp))",
TYPE_INT, 356);
3108 TestValue(
"weekofyear(cast('2011-12-22' as timestamp))",
TYPE_INT, 51);
3109 TestValue(
"dayofweek(cast('2011-12-18' as timestamp))",
TYPE_INT, 1);
3110 TestValue(
"dayofweek(cast('2011-12-22' as timestamp))",
TYPE_INT, 5);
3111 TestValue(
"dayofweek(cast('2011-12-24' as timestamp))",
TYPE_INT, 7);
3112 TestValue(
"hour(cast('09:10:11.000000' as timestamp))",
TYPE_INT, 9);
3113 TestValue(
"minute(cast('09:10:11.000000' as timestamp))",
TYPE_INT, 10);
3114 TestValue(
"second(cast('09:10:11.000000' as timestamp))",
TYPE_INT, 11);
3116 "to_date(cast('2011-12-22 09:10:11.12345678' as timestamp))",
"2011-12-22");
3118 TestValue(
"datediff(cast('2011-12-22 09:10:11.12345678' as timestamp), \
3119 cast('2012-12-22' as timestamp))",
TYPE_INT, -366);
3120 TestValue(
"datediff(cast('2012-12-22' as timestamp), \
3121 cast('2011-12-22 09:10:11.12345678' as timestamp))",
TYPE_INT, 366);
3125 TestIsNull(
"cast('10000-12-31 23:59:59' as timestamp)",
TYPE_TIMESTAMP);
3126 TestIsNull(
"cast('2000-12-31 24:59:59' as timestamp)",
TYPE_TIMESTAMP);
3128 TestIsNull(
"year(cast('09:10:11.000000' as timestamp))",
TYPE_INT);
3129 TestIsNull(
"month(cast('09:10:11.000000' as timestamp))",
TYPE_INT);
3130 TestIsNull(
"dayofmonth(cast('09:10:11.000000' as timestamp))",
TYPE_INT);
3131 TestIsNull(
"day(cast('09:10:11.000000' as timestamp))",
TYPE_INT);
3132 TestIsNull(
"dayofyear(cast('09:10:11.000000' as timestamp))",
TYPE_INT);
3133 TestIsNull(
"dayofweek(cast('09:10:11.000000' as timestamp))",
TYPE_INT);
3134 TestIsNull(
"weekofyear(cast('09:10:11.000000' as timestamp))",
TYPE_INT);
3135 TestIsNull(
"datediff(cast('09:10:11.12345678' as timestamp), "
3136 "cast('2012-12-22' as timestamp))",
TYPE_INT);
3138 TestIsNull(
"year(NULL)",
TYPE_INT);
3139 TestIsNull(
"month(NULL)",
TYPE_INT);
3140 TestIsNull(
"dayofmonth(NULL)",
TYPE_INT);
3142 TestIsNull(
"dayofweek(NULL)",
TYPE_INT);
3143 TestIsNull(
"dayofyear(NULL)",
TYPE_INT);
3144 TestIsNull(
"weekofyear(NULL)",
TYPE_INT);
3145 TestIsNull(
"datediff(NULL, cast('2011-12-22 09:10:11.12345678' as timestamp))",
3147 TestIsNull(
"datediff(cast('2012-12-22' as timestamp), NULL)",
TYPE_INT);
3148 TestIsNull(
"datediff(NULL, NULL)",
TYPE_INT);
3150 TestStringValue(
"dayname(cast('2011-12-18 09:10:11.000000' as timestamp))",
"Sunday");
3151 TestStringValue(
"dayname(cast('2011-12-19 09:10:11.000000' as timestamp))",
"Monday");
3152 TestStringValue(
"dayname(cast('2011-12-20 09:10:11.000000' as timestamp))",
"Tuesday");
3153 TestStringValue(
"dayname(cast('2011-12-21 09:10:11.000000' as timestamp))",
3155 TestStringValue(
"dayname(cast('2011-12-22 09:10:11.000000' as timestamp))",
3157 TestStringValue(
"dayname(cast('2011-12-23 09:10:11.000000' as timestamp))",
"Friday");
3158 TestStringValue(
"dayname(cast('2011-12-24 09:10:11.000000' as timestamp))",
3160 TestStringValue(
"dayname(cast('2011-12-25 09:10:11.000000' as timestamp))",
"Sunday");
3168 TestValue(
"cast(to_utc_timestamp(cast('2011-01-01 01:01:01' as timestamp), 'PST') "
3170 TestValue(
"cast(to_utc_timestamp(cast('2011-01-01 01:01:01' as timestamp), 'PST') "
3172 TestValue(
"cast(to_utc_timestamp(cast('2011-01-01 01:01:01' as timestamp), 'PST') "
3174 TestValue(
"cast(to_utc_timestamp(cast('2011-01-01 01:01:01' as timestamp), 'PST') "
3176 TestValue(
"cast(to_utc_timestamp(cast('2011-01-01 01:01:01' as timestamp), 'PST') "
3179 TestStringValue(
"cast(cast (to_utc_timestamp(cast('2011-01-01 01:01:01' "
3180 "as timestamp), 'PST') as float) as string)",
"1.29387251e+09");
3181 TestValue(
"cast(to_utc_timestamp(cast('2011-01-01 01:01:01' as timestamp), 'PST') "
3183 TestValue(
"cast(to_utc_timestamp(cast('2011-01-01 01:01:01.1' as timestamp), 'PST') "
3185 TestValue(
"cast(to_utc_timestamp(cast('2011-01-01 01:01:01.0001' as timestamp), 'PST') "
3188 TestStringValue(
"cast(from_utc_timestamp(cast(1.3041352164485E9 as timestamp), 'PST') "
3189 "as string)",
"2011-04-29 20:46:56.448499917");
3192 TestIsNull(
"from_utc_timestamp(cast('2011-01-01 01:01:01.1' as timestamp), NULL)",
3201 TestValue(
"cast(cast('2011-01-01 01:01:01' as timestamp) as boolean)",
TYPE_BOOLEAN,
3203 TestValue(
"cast(cast('2011-01-01 01:01:01' as timestamp) as tinyint)",
TYPE_TINYINT,
3205 TestValue(
"cast(cast('2011-01-01 01:01:01' as timestamp) as smallint)",
TYPE_SMALLINT,
3207 TestValue(
"cast(cast('2011-01-01 01:01:01' as timestamp) as int)",
TYPE_INT,
3209 TestValue(
"cast(cast('2011-01-01 01:01:01' as timestamp) as bigint)",
TYPE_BIGINT,
3212 TestStringValue(
"cast(cast(cast('2011-01-01 01:01:01' as timestamp) as float)"
3213 " as string)",
"1.29387251e+09");
3214 TestValue(
"cast(cast('2011-01-01 01:01:01' as timestamp) as double)",
TYPE_DOUBLE,
3216 TestValue(
"cast(cast('2011-01-01 01:01:01.1' as timestamp) as double)",
TYPE_DOUBLE,
3218 TestValue(
"cast(cast('2011-01-01 01:01:01.0001' as timestamp) as double)",
3221 TestStringValue(
"cast(cast(1.3041352164485E9 as timestamp) as string)",
3222 "2011-04-29 20:46:56.448499917");
3225 TestIsNull(
"from_utc_timestamp(cast('2011-01-01 01:01:01.1' as timestamp), NULL)",
3232 "cast(from_utc_timestamp("
3233 "cast('1970-01-01 00:00:00' as timestamp), 'FOOBAR') as string)",
3234 "1970-01-01 00:00:00");
3238 "cast(cast('1999-01-10' as timestamp) as string)",
"1999-01-10 00:00:00");
3241 TestValidTimestampValue(
"now()");
3242 TestValidTimestampValue(
"current_timestamp()");
3243 TestValidTimestampValue(
"cast(unix_timestamp() as timestamp)");
3247 int tolerance_in_seconds = 5;
3248 time_t unix_time = (posix_time::microsec_clock::local_time() - from_time_t(0))
3250 stringstream expr_sql;
3251 expr_sql <<
"unix_timestamp() between " << unix_time - tolerance_in_seconds
3252 <<
" and " << unix_time + tolerance_in_seconds;
3256 unix_time = time(NULL);
3258 expr_sql <<
"unix_timestamp() between " << unix_time - tolerance_in_seconds
3259 <<
" and " << unix_time + tolerance_in_seconds;
3263 ptime local_time = c_local_adjustor<ptime>::utc_to_local(from_time_t(unix_time));
3264 TestTimestampValue(
"now()",
TimestampValue(local_time), tolerance_in_seconds);
3265 TestTimestampValue(
"current_timestamp()",
TimestampValue(local_time),
3266 tolerance_in_seconds);
3267 TestTimestampValue(
"cast(unix_timestamp() as timestamp)",
TimestampValue(local_time),
3268 tolerance_in_seconds);
3271 TestValue(
"now() = current_timestamp()",
TYPE_BOOLEAN,
true);
3274 TestValue(
"unix_timestamp('1970|01|01 00|00|00', 'yyyy|MM|dd HH|mm|ss')",
TYPE_BIGINT,
3276 TestValue(
"unix_timestamp('01,Jan,1970,00,00,00', 'dd,MMM,yyyy,HH,mm,ss')",
TYPE_BIGINT,
3280 TestValue<int64_t>(
"unix_timestamp('1983-08-05T05:00:00.000Z', "
3281 "'yyyy-MM-ddTHH:mm:ss.SSSZ')",
TYPE_BIGINT, 428907600);
3283 TestStringValue(
"from_unixtime(0, 'yyyy|MM|dd HH|mm|ss')",
"1970|01|01 00|00|00");
3284 TestStringValue(
"from_unixtime(0, 'dd,MMM,yyyy,HH,mm,ss')",
"01,Jan,1970,00,00,00");
3287 TestError(
"unix_timestamp('1970-01-01 00:00:00', 'yyyy-MM-dd hh:mm:ss')");
3288 TestError(
"unix_timestamp('1970-01-01 10:10:10', NULL)");
3289 TestError(
"unix_timestamp(NULL, NULL)");
3291 TestError(
"from_unixtime(cast(0 as bigint), NULL)");
3293 TestError(
"unix_timestamp('1970-01-01 00:00:00', ' ')");
3294 TestError(
"unix_timestamp('1970-01-01 00:00:00', ' -===-')");
3295 TestError(
"unix_timestamp('1970-01-01', '\"foo\"')");
3296 TestError(
"from_unixtime(0, 'YY-MM-dd HH:mm:dd')");
3297 TestError(
"from_unixtime(0, 'yyyy-MM-dd hh::dd')");
3298 TestError(
"from_unixtime(cast(0 as bigint), 'YY-MM-dd HH:mm:dd')");
3299 TestError(
"from_unixtime(cast(0 as bigint), 'yyyy-MM-dd hh::dd')");
3303 TestError(
"from_unixtime(0, ' -=++=- ')");
3306 TestIsNull(
"unix_timestamp('1970-01-01', 'yyyy-MM-dd HH:mm:ss')", TYPE_BIGINT);
3307 TestIsNull(
"unix_timestamp('1970', 'yyyy-MM-dd')", TYPE_BIGINT);
3308 TestIsNull(
"unix_timestamp('', 'yyyy-MM-dd')", TYPE_BIGINT);
3309 TestIsNull(
"unix_timestamp('|1|1 00|00|00', 'yyyy|M|d HH|MM|ss')", TYPE_BIGINT);
3311 TestIsNull(
"unix_timestamp('1970-01', 'yyyy-MM-dd')", TYPE_BIGINT);
3312 TestIsNull(
"unix_timestamp('1970-20-01', 'yyyy-MM-dd')", TYPE_BIGINT);
3316 TestIsNull(
"cast(trunc('2014-07-22 01:34:55 +0100', 'year') as STRING)",
TYPE_STRING);
3317 TestStringValue(
"cast(trunc(cast('2014-04-01' as timestamp), 'SYYYY') as string)",
3318 "2014-01-01 00:00:00");
3319 TestIsNull(
"cast(trunc('01:34:55', 'year') as STRING)",
TYPE_STRING);
3320 TestStringValue(
"cast(trunc(cast('07:02:03' as timestamp), 'MI') as string)",
3323 TestStringValue(
"cast(trunc(cast('2014-01-01' as timestamp), 'MI') as string)",
3324 "2014-01-01 00:00:00");
3327 "cast(trunc(cast('2014-04-01 01:01:01' as timestamp), 'SYYYY') as string)",
3328 "2014-01-01 00:00:00");
3330 "cast(trunc(cast('2014-04-01 01:01:01' as timestamp), 'YYYY') as string)",
3331 "2014-01-01 00:00:00");
3333 "cast(trunc(cast('2014-04-01 01:01:01' as timestamp), 'YEAR') as string)",
3334 "2014-01-01 00:00:00");
3336 "cast(trunc(cast('2014-04-01 01:01:01' as timestamp), 'SYEAR') as string)",
3337 "2014-01-01 00:00:00");
3339 "cast(trunc(cast('2014-04-01 01:01:01' as timestamp), 'YYY') as string)",
3340 "2014-01-01 00:00:00");
3342 "cast(trunc(cast('2014-04-01 01:01:01' as timestamp), 'YY') as string)",
3343 "2014-01-01 00:00:00");
3345 "cast(trunc(cast('2014-04-01 01:01:01' as timestamp), 'Y') as string)",
3346 "2014-01-01 00:00:00");
3348 "cast(trunc(cast('2000-01-01 00:00:00' as timestamp), 'Y') as string)",
3349 "2000-01-01 00:00:00");
3351 "cast(trunc(cast('2000-01-01 00:00:00' as timestamp), 'Q') as string)",
3352 "2000-01-01 00:00:00");
3354 "cast(trunc(cast('2000-01-01 01:00:00' as timestamp), 'Q') as string)",
3355 "2000-01-01 00:00:00");
3357 "cast(trunc(cast('2000-02-01 01:00:00' as timestamp), 'Q') as string)",
3358 "2000-01-01 00:00:00");
3360 "cast(trunc(cast('2000-03-01 01:00:00' as timestamp), 'Q') as string)",
3361 "2000-01-01 00:00:00");
3363 "cast(trunc(cast('2000-04-01 01:00:00' as timestamp), 'Q') as string)",
3364 "2000-04-01 00:00:00");
3366 "cast(trunc(cast('2000-05-01 01:00:00' as timestamp), 'Q') as string)",
3367 "2000-04-01 00:00:00");
3369 "cast(trunc(cast('2000-06-01 01:00:00' as timestamp), 'Q') as string)",
3370 "2000-04-01 00:00:00");
3372 "cast(trunc(cast('2000-07-01 01:00:00' as timestamp), 'Q') as string)",
3373 "2000-07-01 00:00:00");
3375 "cast(trunc(cast('2000-08-01 01:00:00' as timestamp), 'Q') as string)",
3376 "2000-07-01 00:00:00");
3378 "cast(trunc(cast('2000-09-01 01:00:00' as timestamp), 'Q') as string)",
3379 "2000-07-01 00:00:00");
3381 "cast(trunc(cast('2000-10-01 01:00:00' as timestamp), 'Q') as string)",
3382 "2000-10-01 00:00:00");
3384 "cast(trunc(cast('2000-11-01 01:00:00' as timestamp), 'Q') as string)",
3385 "2000-10-01 00:00:00");
3387 "cast(trunc(cast('2000-12-01 01:00:00' as timestamp), 'Q') as string)",
3388 "2000-10-01 00:00:00");
3390 "cast(trunc(cast('2001-02-05 01:01:01' as timestamp), 'MONTH') as string)",
3391 "2001-02-01 00:00:00");
3393 "cast(trunc(cast('2001-02-05 01:01:01' as timestamp), 'MON') as string)",
3394 "2001-02-01 00:00:00");
3396 "cast(trunc(cast('2001-02-05 01:01:01' as timestamp), 'MM') as string)",
3397 "2001-02-01 00:00:00");
3399 "cast(trunc(cast('2001-02-05 01:01:01' as timestamp), 'RM') as string)",
3400 "2001-02-01 00:00:00");
3402 "cast(trunc(cast('2001-01-01 00:00:00' as timestamp), 'MM') as string)",
3403 "2001-01-01 00:00:00");
3405 "cast(trunc(cast('2001-12-29 00:00:00' as timestamp), 'MM') as string)",
3406 "2001-12-01 00:00:00");
3408 "cast(trunc(cast('2014-01-08 01:02:03' as timestamp), 'WW') as string)",
3409 "2014-01-08 00:00:00");
3411 "cast(trunc(cast('2014-01-07 00:00:00' as timestamp), 'WW') as string)",
3412 "2014-01-01 00:00:00");
3414 "cast(trunc(cast('2014-01-08 00:00:00' as timestamp), 'WW') as string)",
3415 "2014-01-08 00:00:00");
3417 "cast(trunc(cast('2014-01-09 00:00:00' as timestamp), 'WW') as string)",
3418 "2014-01-08 00:00:00");
3420 "cast(trunc(cast('2014-01-14 00:00:00' as timestamp), 'WW') as string)",
3421 "2014-01-08 00:00:00");
3423 "cast(trunc(cast('2014-01-08 01:02:03' as timestamp), 'W') as string)",
3424 "2014-01-08 00:00:00");
3426 "cast(trunc(cast('2014-01-07 00:00:00' as timestamp), 'W') as string)",
3427 "2014-01-01 00:00:00");
3429 "cast(trunc(cast('2014-01-08 00:00:00' as timestamp), 'W') as string)",
3430 "2014-01-08 00:00:00");
3432 "cast(trunc(cast('2014-01-09 00:00:00' as timestamp), 'W') as string)",
3433 "2014-01-08 00:00:00");
3435 "cast(trunc(cast('2014-01-14 00:00:00' as timestamp), 'W') as string)",
3436 "2014-01-08 00:00:00");
3438 "cast(trunc(cast('2014-02-01 01:02:03' as timestamp), 'W') as string)",
3439 "2014-02-01 00:00:00");
3441 "cast(trunc(cast('2014-02-02 00:00:00' as timestamp), 'W') as string)",
3442 "2014-02-01 00:00:00");
3444 "cast(trunc(cast('2014-02-03 00:00:00' as timestamp), 'W') as string)",
3445 "2014-02-01 00:00:00");
3447 "cast(trunc(cast('2014-02-07 00:00:00' as timestamp), 'W') as string)",
3448 "2014-02-01 00:00:00");
3450 "cast(trunc(cast('2014-02-08 00:00:00' as timestamp), 'W') as string)",
3451 "2014-02-08 00:00:00");
3453 "cast(trunc(cast('2014-02-24 00:00:00' as timestamp), 'W') as string)",
3454 "2014-02-22 00:00:00");
3456 "cast(trunc(cast('2014-01-08 01:02:03' as timestamp), 'DDD') as string)",
3457 "2014-01-08 00:00:00");
3459 "cast(trunc(cast('2014-01-08 01:02:03' as timestamp), 'DD') as string)",
3460 "2014-01-08 00:00:00");
3462 "cast(trunc(cast('2014-02-08 01:02:03' as timestamp), 'J') as string)",
3463 "2014-02-08 00:00:00");
3465 "cast(trunc(cast('2014-02-08 00:00:00' as timestamp), 'J') as string)",
3466 "2014-02-08 00:00:00");
3468 "cast(trunc(cast('2014-02-19 00:00:00' as timestamp), 'J') as string)",
3469 "2014-02-19 00:00:00");
3471 "cast(trunc(cast('2012-09-10 01:02:03' as timestamp), 'DAY') as string)",
3472 "2012-09-10 00:00:00");
3474 "cast(trunc(cast('2012-09-10 01:02:03' as timestamp), 'DY') as string)",
3475 "2012-09-10 00:00:00");
3477 "cast(trunc(cast('2012-09-10 01:02:03' as timestamp), 'D') as string)",
3478 "2012-09-10 00:00:00");
3480 "cast(trunc(cast('2012-09-11 01:02:03' as timestamp), 'D') as string)",
3481 "2012-09-10 00:00:00");
3483 "cast(trunc(cast('2012-09-12 01:02:03' as timestamp), 'D') as string)",
3484 "2012-09-10 00:00:00");
3486 "cast(trunc(cast('2012-09-16 01:02:03' as timestamp), 'D') as string)",
3487 "2012-09-10 00:00:00");
3489 "cast(trunc(cast('2012-09-10 07:02:03' as timestamp), 'HH') as string)",
3490 "2012-09-10 07:00:00");
3492 "cast(trunc(cast('2012-09-10 07:02:03' as timestamp), 'HH12') as string)",
3493 "2012-09-10 07:00:00");
3495 "cast(trunc(cast('2012-09-10 07:02:03' as timestamp), 'HH24') as string)",
3496 "2012-09-10 07:00:00");
3498 "cast(trunc(cast('2012-09-10 00:02:03' as timestamp), 'HH') as string)",
3499 "2012-09-10 00:00:00");
3501 "cast(trunc(cast('2012-09-10 23:02:03' as timestamp), 'HH') as string)",
3502 "2012-09-10 23:00:00");
3504 "cast(trunc(cast('2012-09-10 23:59:59' as timestamp), 'HH') as string)",
3505 "2012-09-10 23:00:00");
3507 "cast(trunc(cast('2012-09-10 07:02:03' as timestamp), 'MI') as string)",
3508 "2012-09-10 07:02:00");
3510 "cast(trunc(cast('2012-09-10 07:00:03' as timestamp), 'MI') as string)",
3511 "2012-09-10 07:00:00");
3513 "cast(trunc(cast('2012-09-10 07:00:00' as timestamp), 'MI') as string)",
3514 "2012-09-10 07:00:00");
3516 "cast(trunc(cast('2012-09-10 07:59:03' as timestamp), 'MI') as string)",
3517 "2012-09-10 07:59:00");
3519 "cast(trunc(cast('2012-09-10 07:59:59' as timestamp), 'MI') as string)",
3520 "2012-09-10 07:59:00");
3522 "cast(trunc(cast('2012-09-10 07:59:59' as timestamp), 'MIN') as string)");
3524 "cast(trunc(cast('2012-09-10 07:59:59' as timestamp), 'XXYYZZ') as string)");
3527 TestValue(
"extract(cast('2006-05-12 18:27:28.12345' as timestamp), 'YEAR')",
3529 TestValue(
"extract('2006-05-12 18:27:28.12345', 'YEAR')",
TYPE_INT, 2006);
3530 TestValue(
"extract(cast('2006-05-12 18:27:28.12345' as timestamp), 'MoNTH')",
3532 TestValue(
"extract(cast('2006-05-12 18:27:28.12345' as timestamp), 'DaY')",
3534 TestValue(
"extract(cast('2006-05-12 06:27:28.12345' as timestamp), 'hour')",
3536 TestValue(
"extract(cast('2006-05-12 18:27:28.12345' as timestamp), 'MINUTE')",
3538 TestValue(
"extract(cast('2006-05-12 18:27:28.12345' as timestamp), 'SECOND')",
3540 TestValue(
"extract(cast('2006-05-12 18:27:28.12345' as timestamp), 'MILLISECOND')",
3542 TestValue(
"extract(cast('2006-05-13 01:27:28.12345' as timestamp), 'EPOCH')",
3544 TestNonOkStatus(
"extract(cast('2006-05-13 01:27:28.12345' as timestamp), 'foo')");
3545 TestNonOkStatus(
"extract(cast('2006-05-13 01:27:28.12345' as timestamp), NULL)");
3546 TestIsNull(
"extract(NULL, 'EPOCH')",
TYPE_INT);
3547 TestNonOkStatus(
"extract(NULL, NULL)");
3550 TestValue(
"extract(YEAR from cast('2006-05-12 18:27:28.12345' as timestamp))",
3552 TestValue(
"extract(MoNTH from cast('2006-05-12 18:27:28.12345' as timestamp))",
3554 TestValue(
"extract(DaY from cast('2006-05-12 18:27:28.12345' as timestamp))",
3556 TestValue(
"extract(hour from cast('2006-05-12 06:27:28.12345' as timestamp))",
3558 TestValue(
"extract(MINUTE from cast('2006-05-12 18:27:28.12345' as timestamp))",
3560 TestValue(
"extract(SECOND from cast('2006-05-12 18:27:28.12345' as timestamp))",
3562 TestValue(
"extract(MILLISECOND from cast('2006-05-12 18:27:28.12345' as timestamp))",
3564 TestValue(
"extract(EPOCH from cast('2006-05-13 01:27:28.12345' as timestamp))",
3566 TestNonOkStatus(
"extract(foo from cast('2006-05-13 01:27:28.12345' as timestamp))");
3567 TestNonOkStatus(
"extract(NULL from cast('2006-05-13 01:27:28.12345' as timestamp))");
3568 TestIsNull(
"extract(EPOCH from NULL)",
TYPE_INT);
3571 TestValue(
"date_part('YEAR', cast('2006-05-12 18:27:28.12345' as timestamp))",
3573 TestValue(
"date_part('MoNTH', cast('2006-05-12 18:27:28.12345' as timestamp))",
3575 TestValue(
"date_part('DaY', cast('2006-05-12 18:27:28.12345' as timestamp))",
3577 TestValue(
"date_part('hour', cast('2006-05-12 06:27:28.12345' as timestamp))",
3579 TestValue(
"date_part('MINUTE', cast('2006-05-12 18:27:28.12345' as timestamp))",
3581 TestValue(
"date_part('SECOND', cast('2006-05-12 18:27:28.12345' as timestamp))",
3583 TestValue(
"date_part('MILLISECOND', cast('2006-05-12 18:27:28.12345' as timestamp))",
3585 TestValue(
"date_part('EPOCH', cast('2006-05-13 01:27:28.12345' as timestamp))",
3587 TestNonOkStatus(
"date_part('foo', cast('2006-05-13 01:27:28.12345' as timestamp))");
3588 TestNonOkStatus(
"date_part(NULL, cast('2006-05-13 01:27:28.12345' as timestamp))");
3589 TestIsNull(
"date_part('EPOCH', NULL)",
TYPE_INT);
3590 TestNonOkStatus(
"date_part(NULL, NULL)");
3596 TestValue(
"if(TRUE, FALSE, TRUE)",
TYPE_BOOLEAN,
false);
3597 TestValue(
"if(FALSE, FALSE, TRUE)",
TYPE_BOOLEAN,
true);
3600 TestValue(
"if(TRUE, cast(5.5 as double), cast(8.8 as double))",
TYPE_DOUBLE, 5.5);
3601 TestValue(
"if(FALSE, cast(5.5 as double), cast(8.8 as double))",
TYPE_DOUBLE, 8.8);
3602 TestStringValue(
"if(TRUE, 'abc', 'defgh')",
"abc");
3603 TestStringValue(
"if(FALSE, 'abc', 'defgh')",
"defgh");
3606 TestTimestampValue(
"if(TRUE, cast('2011-01-01 09:01:01' as timestamp), "
3607 "cast('1999-06-14 19:07:25' as timestamp))", then_val);
3608 TestTimestampValue(
"if(FALSE, cast('2011-01-01 09:01:01' as timestamp), "
3609 "cast('1999-06-14 19:07:25' as timestamp))", else_val);
3621 TestIsNull(
"nullif(cast(10.10 as double), cast(10.10 as double))",
TYPE_DOUBLE);
3622 TestValue(
"nullif(cast(10.10 as double), cast(20.20 as double))",
TYPE_DOUBLE, 10.10);
3623 TestIsNull(
"nullif(cast(NULL as double), 10.10)",
TYPE_DOUBLE);
3624 TestValue(
"nullif(cast(10.10 as double), NULL)",
TYPE_DOUBLE, 10.10);
3626 TestStringValue(
"nullif('abc', 'def')",
"abc");
3628 TestStringValue(
"nullif('abc', NULL)",
"abc");
3629 TestIsNull(
"nullif(cast('2011-01-01 09:01:01' as timestamp), "
3632 TestTimestampValue(
"nullif(cast('2011-01-01 09:01:01' as timestamp), "
3633 "cast('1999-06-14 19:07:25' as timestamp))", testlhs);
3634 TestIsNull(
"nullif(NULL, "
3636 TestTimestampValue(
"nullif(cast('2011-01-01 09:01:01' as timestamp), "
3640 string isnull_aliases[] = {
"IsNull",
"IfNull",
"Nvl"};
3641 for (
int i = 0; i < 3; ++i) {
3642 string& f = isnull_aliases[i];
3645 TestValue(f +
"(cast(1 as smallint), NULL)",
TYPE_SMALLINT, 1);
3646 TestValue(f +
"(cast(1 as int), NULL)",
TYPE_INT, 1);
3647 TestValue(f +
"(cast(1 as bigint), NULL)",
TYPE_BIGINT, 1);
3648 TestValue(f +
"(cast(10.0 as float), NULL)",
TYPE_FLOAT, 10.0f);
3649 TestValue(f +
"(cast(10.0 as double), NULL)",
TYPE_DOUBLE, 10.0);
3650 TestStringValue(f +
"('abc', NULL)",
"abc");
3651 TestTimestampValue(f +
"(" + default_timestamp_str_ +
", NULL)",
3652 default_timestamp_val_);
3656 TestValue(f +
"(NULL, cast(1 as smallint))",
TYPE_SMALLINT, 1);
3657 TestValue(f +
"(NULL, cast(1 as int))",
TYPE_INT, 1);
3658 TestValue(f +
"(NULL, cast(1 as bigint))",
TYPE_BIGINT, 1);
3659 TestValue(f +
"(NULL, cast(10.0 as float))",
TYPE_FLOAT, 10.0f);
3660 TestValue(f +
"(NULL, cast(10.0 as double))",
TYPE_DOUBLE, 10.0);
3661 TestStringValue(f +
"(NULL, 'abc')",
"abc");
3662 TestTimestampValue(f +
"(NULL, " + default_timestamp_str_ +
")",
3663 default_timestamp_val_);
3671 TestValue(
"coalesce(NULL, TRUE, NULL)",
TYPE_BOOLEAN,
true);
3672 TestValue(
"coalesce(FALSE, NULL, TRUE, NULL)",
TYPE_BOOLEAN,
false);
3673 TestValue(
"coalesce(NULL, NULL, NULL, TRUE, NULL, NULL)",
TYPE_BOOLEAN,
true);
3677 TestValue(
"coalesce(NULL, 10, NULL)",
TYPE_TINYINT, 10);
3678 TestValue(
"coalesce(20, NULL, 10, NULL)",
TYPE_TINYINT, 20);
3679 TestValue(
"coalesce(20, NULL, cast(10 as smallint), NULL)",
TYPE_SMALLINT, 20);
3680 TestValue(
"coalesce(20, NULL, cast(10 as int), NULL)",
TYPE_INT, 20);
3681 TestValue(
"coalesce(20, NULL, cast(10 as bigint), NULL)",
TYPE_BIGINT, 20);
3682 TestValue(
"coalesce(cast(5.5 as float))",
TYPE_FLOAT, 5.5f);
3683 TestValue(
"coalesce(NULL, cast(5.5 as float))",
TYPE_FLOAT, 5.5f);
3684 TestValue(
"coalesce(cast(5.5 as float), NULL)",
TYPE_FLOAT, 5.5f);
3685 TestValue(
"coalesce(NULL, cast(5.5 as float), NULL)",
TYPE_FLOAT, 5.5f);
3686 TestValue(
"coalesce(cast(9.8 as float), NULL, cast(5.5 as float), NULL)",
3688 TestValue(
"coalesce(cast(9.8 as double), NULL, cast(5.5 as double), NULL)",
3690 TestStringValue(
"coalesce('abc')",
"abc");
3691 TestStringValue(
"coalesce(NULL, 'abc', NULL)",
"abc");
3692 TestStringValue(
"coalesce('defgh', NULL, 'abc', NULL)",
"defgh");
3693 TestStringValue(
"coalesce(NULL, NULL, NULL, 'abc', NULL, NULL)",
"abc");
3696 TestTimestampValue(
"coalesce(cast('2011-01-01 09:01:01' as timestamp))", ats);
3697 TestTimestampValue(
"coalesce(NULL, cast('2011-01-01 09:01:01' as timestamp),"
3699 TestTimestampValue(
"coalesce(cast('1999-06-14 19:07:25' as timestamp), NULL,"
3700 "cast('2011-01-01 09:01:01' as timestamp), NULL)", bts);
3701 TestTimestampValue(
"coalesce(NULL, NULL, NULL,"
3702 "cast('2011-01-01 09:01:01' as timestamp), NULL, NULL)", ats);
3706 TestValue(
"case when true then 1 end",
TYPE_TINYINT, 1);
3707 TestValue(
"case when false then 1 when true then 2 end",
TYPE_TINYINT, 2);
3708 TestValue(
"case when false then 1 when false then 2 when true then 3 end",
3711 TestValue(
"case when false then 1 else 10 end",
TYPE_TINYINT, 10);
3712 TestValue(
"case when false then 1 when false then 2 else 10 end",
TYPE_TINYINT, 10);
3713 TestValue(
"case when false then 1 when false then 2 when false then 3 else 10 end",
3715 TestIsNull(
"case when false then 1 end",
TYPE_TINYINT);
3717 TestValue(
"case 21 when 21 then 1 end",
TYPE_TINYINT, 1);
3718 TestValue(
"case 21 when 20 then 1 when 21 then 2 end",
TYPE_TINYINT, 2);
3719 TestValue(
"case 21 when 20 then 1 when 19 then 2 when 21 then 3 end",
TYPE_TINYINT, 3);
3722 TestIsNull(
"case when NULL then 1 else NULL end",
TYPE_TINYINT);
3723 TestValue(
"case when NULL then 1 else 2 end",
TYPE_TINYINT, 2);
3724 TestValue(
"case when NULL then 1 when true then 2 else 3 end",
TYPE_TINYINT, 2);
3726 TestIsNull(
"case NULL when 1 then 1 end",
TYPE_TINYINT);
3727 TestIsNull(
"case NULL when 1 then 1 else NULL end",
TYPE_TINYINT);
3728 TestValue(
"case NULL when 1 then 1 else 2 end",
TYPE_TINYINT, 2);
3729 TestValue(
"case 10 when NULL then 1 else 2 end",
TYPE_TINYINT, 2);
3730 TestValue(
"case 10 when NULL then 1 when 10 then 2 else 3 end",
TYPE_TINYINT, 2);
3731 TestValue(
"case 'abc' when NULL then 1 when NULL then 2 else 3 end",
TYPE_TINYINT, 3);
3733 TestIsNull(
"case NULL when NULL then true end",
TYPE_BOOLEAN);
3734 TestIsNull(
"case NULL when NULL then true else NULL end",
TYPE_BOOLEAN);
3736 TestIsNull(
"case NULL when NULL then NULL end",
TYPE_BOOLEAN);
3737 TestIsNull(
"case NULL when NULL then NULL else NULL end",
TYPE_BOOLEAN);
3740 unordered_map<int, string>::iterator def_iter;
3741 for(def_iter = default_type_strs_.begin(); def_iter != default_type_strs_.end();
3743 TestValue(
"case " + def_iter->second +
" when " + def_iter->second +
3749 IntValMap::iterator int_iter;
3750 for (int_iter = min_int_values_.begin(); int_iter != min_int_values_.end();
3753 string& s = default_type_strs_[t];
3754 TestValue(
"case when true then " + s +
" end", t, int_iter->second);
3755 TestValue(
"case when false then 1 else " + s +
" end", t, int_iter->second);
3756 TestValue(
"case when true then 1 else " + s +
" end", t, 1);
3757 TestValue(
"case 0 when " + s +
" then true else false end",
TYPE_BOOLEAN,
false);
3763 TestValue(
"zeroifnull(cast (NULL as TINYINT))",
TYPE_TINYINT, 0);
3764 TestValue(
"zeroifnull(cast (5 as TINYINT))",
TYPE_TINYINT, 5);
3765 TestValue(
"zeroifnull(cast (NULL as SMALLINT))",
TYPE_SMALLINT, 0);
3766 TestValue(
"zeroifnull(cast (5 as SMALLINT))",
TYPE_SMALLINT, 5);
3767 TestValue(
"zeroifnull(cast (NULL as INT))",
TYPE_INT, 0);
3768 TestValue(
"zeroifnull(cast (5 as INT))",
TYPE_INT, 5);
3769 TestValue(
"zeroifnull(cast (NULL as BIGINT))",
TYPE_BIGINT, 0);
3770 TestValue(
"zeroifnull(cast (5 as BIGINT))",
TYPE_BIGINT, 5);
3771 TestValue<float>(
"zeroifnull(cast (NULL as FLOAT))",
TYPE_FLOAT, 0.0f);
3772 TestValue<float>(
"zeroifnull(cast (5 as FLOAT))",
TYPE_FLOAT, 5.0f);
3773 TestValue<double>(
"zeroifnull(cast (NULL as DOUBLE))",
TYPE_DOUBLE, 0.0);
3774 TestValue<double>(
"zeroifnull(cast (5 as DOUBLE))",
TYPE_DOUBLE, 5.0);
3778 TestIsNull(
"nullifzero(cast (0 as TINYINT))",
TYPE_TINYINT);
3779 TestIsNull(
"nullifzero(cast (NULL as TINYINT))",
TYPE_TINYINT);
3780 TestIsNull(
"nullifzero(cast (0 as SMALLINT))",
TYPE_SMALLINT);
3781 TestIsNull(
"nullifzero(cast (NULL as SMALLINT))",
TYPE_SMALLINT);
3782 TestIsNull(
"nullifzero(cast (0 as INT))",
TYPE_INT);
3783 TestIsNull(
"nullifzero(cast (NULL as INT))",
TYPE_INT);
3784 TestIsNull(
"nullifzero(cast (0 as BIGINT))",
TYPE_BIGINT);
3785 TestIsNull(
"nullifzero(cast (NULL as BIGINT))",
TYPE_BIGINT);
3786 TestIsNull(
"nullifzero(cast (0 as FLOAT))", TYPE_FLOAT);
3787 TestIsNull(
"nullifzero(cast (NULL as FLOAT))", TYPE_FLOAT);
3788 TestIsNull(
"nullifzero(cast (0 as DOUBLE))", TYPE_DOUBLE);
3789 TestIsNull(
"nullifzero(cast (NULL as DOUBLE))", TYPE_DOUBLE);
3792 TestValue(
"nullifzero(cast (5 as TINYINT))",
TYPE_TINYINT, 5);
3793 TestValue(
"nullifzero(cast (5 as SMALLINT))",
TYPE_SMALLINT, 5);
3794 TestValue(
"nullifzero(cast (5 as INT))",
TYPE_INT, 5);
3795 TestValue(
"nullifzero(cast (5 as BIGINT))",
TYPE_BIGINT, 5);
3796 TestValue<float>(
"nullifzero(cast (5 as FLOAT))",
TYPE_FLOAT, 5.0f);
3797 TestValue<double>(
"nullifzero(cast (5 as DOUBLE))",
TYPE_DOUBLE, 5.0);
3804 unordered_map<int, double>::iterator float_iter;
3805 for (float_iter = min_float_values_.begin(); float_iter != min_float_values_.end();
3808 string& s = default_type_strs_[t];
3809 TestValue(
"case when true then " + s +
" end", t, float_iter->second);
3810 TestValue(
"case when false then 1 else " + s +
" end", t, float_iter->second);
3811 TestValue(
"case when true then 1 else " + s +
" end", t, 1.0);
3812 TestValue(
"case 0 when " + s +
" then true else false end",
TYPE_BOOLEAN,
false);
3818 TestValue(
"case when true then " + default_bool_str_ +
" end",
TYPE_BOOLEAN,
3820 TestValue(
"case when false then true else " + default_bool_str_ +
" end",
TYPE_BOOLEAN,
3823 TestStringValue(
"case when true then " + default_string_str_ +
" end",
3824 default_string_val_);
3825 TestStringValue(
"case when false then '1' else " + default_string_str_ +
" end",
3826 default_string_val_);
3828 TestTimestampValue(
"case when true then " + default_timestamp_str_ +
" end",
3829 default_timestamp_val_);
3830 TestTimestampValue(
"case when false then cast('1999-06-14 19:07:25' as timestamp) "
3831 "else " + default_timestamp_str_ +
" end", default_timestamp_val_);
3837 TestValue(
"decode(NULL + 1, NULL + 2, 3)",
TYPE_TINYINT, 3);
3844 TestValue(
"istrue(cast(false as boolean))",
TYPE_BOOLEAN,
false);
3845 TestValue(
"istrue(cast(true as boolean))",
TYPE_BOOLEAN,
true);
3846 TestValue(
"istrue(cast(NULL as boolean))",
TYPE_BOOLEAN,
false);
3847 TestValue(
"istrue(cast(0 as boolean))",
TYPE_BOOLEAN,
false);
3848 TestValue(
"istrue(cast(5 as boolean))",
TYPE_BOOLEAN,
true);
3849 TestValue(
"istrue(cast(-5 as boolean))",
TYPE_BOOLEAN,
true);
3850 TestValue(
"istrue(cast(0.0 as boolean))",
TYPE_BOOLEAN,
false);
3851 TestValue(
"istrue(cast(5.0 as boolean))",
TYPE_BOOLEAN,
true);
3852 TestValue(
"istrue(cast(-5.0 as boolean))",
TYPE_BOOLEAN,
true);
3862 TestError(
"istrue(cast('2012-01-01 09:10:11.123456789' as timestamp))");
3864 TestError(
"istrue(999999999999999999999999999999999999999)");
3865 TestError(
"istrue(-99999999999999999999999999999999999999)");
3866 TestError(
"istrue(99999999999999999999999999999999999999.9)");
3867 TestError(
"istrue(-9999999999999999999999999999999999999.9)");
3871 TestValue(
"isfalse(cast(false as boolean))",
TYPE_BOOLEAN,
true);
3872 TestValue(
"isfalse(cast(true as boolean))",
TYPE_BOOLEAN,
false);
3873 TestValue(
"isfalse(cast(NULL as boolean))",
TYPE_BOOLEAN,
false);
3875 TestValue(
"isfalse(cast(0 as boolean))",
TYPE_BOOLEAN,
true);
3876 TestValue(
"isfalse(cast(5 as boolean))",
TYPE_BOOLEAN,
false);
3877 TestValue(
"isfalse(cast(-5 as boolean))",
TYPE_BOOLEAN,
false);
3879 TestValue(
"isfalse(cast(0.0 as boolean))",
TYPE_BOOLEAN,
true);
3880 TestValue(
"isfalse(cast(5.0 as boolean))",
TYPE_BOOLEAN,
false);
3881 TestValue(
"isfalse(cast(-5.0 as boolean))",
TYPE_BOOLEAN,
false);
3891 TestError(
"isfalse(cast('2012-01-01 09:10:11.123456789' as timestamp))");
3893 TestError(
"isfalse(999999999999999999999999999999999999999)");
3894 TestError(
"isfalse(-99999999999999999999999999999999999999)");
3895 TestError(
"isfalse(99999999999999999999999999999999999999.9)");
3896 TestError(
"isfalse(-9999999999999999999999999999999999999.9)");
3900 TestValue(
"isnottrue(cast(false as boolean))",
TYPE_BOOLEAN,
true);
3901 TestValue(
"isnottrue(cast(true as boolean))",
TYPE_BOOLEAN,
false);
3902 TestValue(
"isnottrue(cast(NULL as boolean))",
TYPE_BOOLEAN,
true);
3904 TestValue(
"isnottrue(cast(0 as boolean))",
TYPE_BOOLEAN,
true);
3905 TestValue(
"isnottrue(cast(5 as boolean))",
TYPE_BOOLEAN,
false);
3906 TestValue(
"isnottrue(cast(-5 as boolean))",
TYPE_BOOLEAN,
false);
3908 TestValue(
"isnottrue(cast(0.0 as boolean))",
TYPE_BOOLEAN,
true);
3909 TestValue(
"isnottrue(cast(5.0 as boolean))",
TYPE_BOOLEAN,
false);
3910 TestValue(
"isnottrue(cast(-5.0 as boolean))",
TYPE_BOOLEAN,
false);
3920 TestError(
"isnottrue(cast('2012-01-01 09:10:11.123456789' as timestamp))");
3922 TestError(
"isnottrue(999999999999999999999999999999999999999)");
3923 TestError(
"isnottrue(-99999999999999999999999999999999999999)");
3924 TestError(
"isnottrue(99999999999999999999999999999999999999.9)");
3925 TestError(
"isnottrue(-9999999999999999999999999999999999999.9)");
3929 TestValue(
"isnotfalse(cast(false as boolean))",
TYPE_BOOLEAN,
false);
3930 TestValue(
"isnotfalse(cast(true as boolean))",
TYPE_BOOLEAN,
true);
3931 TestValue(
"isnotfalse(cast(NULL as boolean))",
TYPE_BOOLEAN,
true);
3932 TestValue(
"isnotfalse(cast(0 as boolean))",
TYPE_BOOLEAN,
false);
3933 TestValue(
"isnotfalse(cast(5 as boolean))",
TYPE_BOOLEAN,
true);
3934 TestValue(
"isnotfalse(cast(-5 as boolean))",
TYPE_BOOLEAN,
true);
3935 TestValue(
"isnotfalse(cast(0.0 as boolean))",
TYPE_BOOLEAN,
false);
3936 TestValue(
"isnotfalse(cast(5.0 as boolean))",
TYPE_BOOLEAN,
true);
3937 TestValue(
"isnotfalse(cast(-5.0 as boolean))",
TYPE_BOOLEAN,
true);
3947 TestError(
"isnotfalse(cast('2012-01-01 09:10:11.123456789' as timestamp))");
3949 TestError(
"isnotfalse(999999999999999999999999999999999999999)");
3950 TestError(
"isnotfalse(-99999999999999999999999999999999999999)");
3951 TestError(
"isnotfalse(99999999999999999999999999999999999999.9)");
3952 TestError(
"isnotfalse(-9999999999999999999999999999999999999.9)");
3961 int expected_var_begin,
const map<
int, set<int> >& expected_offsets) {
3963 vector<int> offsets;
3964 set<int> offsets_found;
3967 int byte_size = Expr::ComputeResultsLayout(exprs, &offsets, &var_begin);
3969 EXPECT_EQ(byte_size, expected_byte_size);
3970 EXPECT_EQ(var_begin, expected_var_begin);
3973 for (
int i = 0; i < exprs.size(); ++i) {
3974 int expr_byte_size = exprs[i]->type().GetByteSize();
3975 map<int, set<int> >::const_iterator iter = expected_offsets.find(expr_byte_size);
3976 EXPECT_TRUE(iter != expected_offsets.end());
3978 const set<int>& possible_offsets = iter->second;
3979 int computed_offset = offsets[i];
3982 EXPECT_TRUE(possible_offsets.find(computed_offset) != possible_offsets.end());
3984 EXPECT_TRUE(offsets_found.find(computed_offset) == offsets_found.end());
3985 offsets_found.insert(computed_offset);
3992 vector<Expr*> exprs;
3993 map<int, set<int> > expected_offsets;
3999 expected_offsets.clear();
4003 expected_offsets.clear();
4006 exprs.push_back(pool.
Add(Literal::CreateLiteral(t,
"0")));
4014 int expected_byte_size = 0;
4015 int expected_var_begin = 0;
4016 expected_offsets.clear();
4024 expected_offsets[1].insert(expected_byte_size);
4025 expected_offsets[1].insert(expected_byte_size + 1);
4026 expected_offsets[1].insert(expected_byte_size + 2);
4027 expected_byte_size += 3 * 1 + 1;
4030 expected_offsets[2].insert(expected_byte_size);
4031 expected_byte_size += 1 * 2 + 2;
4033 exprs.push_back(pool.
Add(Literal::CreateLiteral(
TYPE_INT,
"0")));
4034 exprs.push_back(pool.
Add(Literal::CreateLiteral(
TYPE_FLOAT,
"0")));
4035 exprs.push_back(pool.
Add(Literal::CreateLiteral(
TYPE_FLOAT,
"0")));
4036 expected_offsets[4].insert(expected_byte_size);
4037 expected_offsets[4].insert(expected_byte_size + 4);
4038 expected_offsets[4].insert(expected_byte_size + 8);
4039 expected_byte_size += 3 * 4 + 4;
4041 exprs.push_back(pool.
Add(Literal::CreateLiteral(
TYPE_BIGINT,
"0")));
4042 exprs.push_back(pool.
Add(Literal::CreateLiteral(
TYPE_BIGINT,
"0")));
4043 exprs.push_back(pool.
Add(Literal::CreateLiteral(
TYPE_BIGINT,
"0")));
4044 exprs.push_back(pool.
Add(Literal::CreateLiteral(
TYPE_DOUBLE,
"0")));
4045 expected_offsets[8].insert(expected_byte_size);
4046 expected_offsets[8].insert(expected_byte_size + 8);
4047 expected_offsets[8].insert(expected_byte_size + 16);
4048 expected_offsets[8].insert(expected_byte_size + 24);
4049 expected_byte_size += 4 * 8;
4053 expected_offsets[16].insert(expected_byte_size);
4054 expected_offsets[16].insert(expected_byte_size + 16);
4055 expected_byte_size += 2 * 16;
4057 exprs.push_back(pool.
Add(Literal::CreateLiteral(
TYPE_STRING,
"0")));
4058 exprs.push_back(pool.
Add(Literal::CreateLiteral(
TYPE_STRING,
"0")));
4059 expected_offsets[0].insert(expected_byte_size);
4060 expected_offsets[0].insert(expected_byte_size + 16);
4061 expected_var_begin = expected_byte_size;
4062 expected_byte_size += 2 * 16;
4065 ValidateLayout(exprs, expected_byte_size, expected_var_begin, expected_offsets);
4072 for (
int i = 0; i < 10; ++i) {
4073 std::random_shuffle(exprs.begin(), exprs.end());
4074 ValidateLayout(exprs, expected_byte_size, expected_var_begin, expected_offsets);
4080 TestValue(
"precision(cast (1 as decimal(10,2)))",
TYPE_INT, 10);
4081 TestValue(
"scale(cast(1 as decimal(10,2)))",
TYPE_INT, 2);
4083 TestValue(
"precision(1)",
TYPE_INT, 3);
4084 TestValue(
"precision(cast(1 as smallint))",
TYPE_INT, 5);
4085 TestValue(
"precision(cast(123 as bigint))",
TYPE_INT, 19);
4086 TestValue(
"precision(123.45)",
TYPE_INT, 5);
4087 TestValue(
"scale(123.45)",
TYPE_INT, 2);
4088 TestValue(
"precision(1 + 1)",
TYPE_INT, 5);
4089 TestValue(
"scale(1 + 1)",
TYPE_INT, 0);
4090 TestValue(
"precision(1 + 1)",
TYPE_INT, 5);
4092 TestValue(
"scale(cast(NULL as decimal(10, 2)))",
TYPE_INT, 2);
4095 TestValue(
"scale(round(123.456, 3))",
TYPE_INT, 3);
4096 TestValue(
"precision(round(cast(\"123.456\" as decimal(6, 3)), 3))",
TYPE_INT, 6);
4098 TestValue(
"scale(truncate(123.456, 1))",
TYPE_INT, 1);
4099 TestValue(
"precision(truncate(123.456, 1))",
TYPE_INT, 4);
4101 TestValue(
"scale(round(cast(\"123.456\" as decimal(6, 3)), -2))",
TYPE_INT, 0);
4102 TestValue(
"precision(round(123.456, -2))",
TYPE_INT, 4);
4104 TestValue(
"scale(truncate(123.456, 10))",
TYPE_INT, 10);
4105 TestValue(
"precision(truncate(cast(\"123.456\" as decimal(6, 3)), 10))",
TYPE_INT, 13);
4107 TestValue(
"scale(round(123.456, -10))",
TYPE_INT, 0);
4108 TestValue(
"precision(round(cast(\"123.456\" as decimal(6, 3)), -10))",
TYPE_INT, 4);
4111 TestDecimalValue(
"abs(cast('0' as decimal(2,0)))",
Decimal4Value(0),
4112 ColumnType::CreateDecimalType(2, 0));
4113 TestDecimalValue(
"abs(cast('1.1' as decimal(2,1)))",
Decimal4Value(11),
4114 ColumnType::CreateDecimalType(2,1));
4115 TestDecimalValue(
"abs(cast('-1.23' as decimal(5,2)))",
Decimal4Value(123),
4116 ColumnType::CreateDecimalType(5,2));
4117 TestDecimalValue(
"abs(cast('0' as decimal(12,0)))",
Decimal8Value(0),
4118 ColumnType::CreateDecimalType(12, 0));
4119 TestDecimalValue(
"abs(cast('1.1' as decimal(12,1)))",
Decimal8Value(11),
4120 ColumnType::CreateDecimalType(12,1));
4121 TestDecimalValue(
"abs(cast('-1.23' as decimal(12,2)))",
Decimal8Value(123),
4122 ColumnType::CreateDecimalType(12,2));
4123 TestDecimalValue(
"abs(cast('0' as decimal(32,0)))",
Decimal16Value(0),
4124 ColumnType::CreateDecimalType(32, 0));
4125 TestDecimalValue(
"abs(cast('1.1' as decimal(32,1)))",
Decimal8Value(11),
4126 ColumnType::CreateDecimalType(32,1));
4127 TestDecimalValue(
"abs(cast('-1.23' as decimal(32,2)))",
Decimal8Value(123),
4128 ColumnType::CreateDecimalType(32,2));
4129 TestIsNull(
"abs(cast(NULL as decimal(2,0)))", ColumnType::CreateDecimalType(2,0));
4136 TestDecimalValue(
"isnull(cast('0' as decimal(2,0)), NULL)",
Decimal4Value(0),
4137 ColumnType::CreateDecimalType(2, 0));
4138 TestDecimalValue(
"isnull(cast('1.1' as decimal(18,1)), NULL)",
Decimal8Value(11),
4139 ColumnType::CreateDecimalType(18,1));
4140 TestDecimalValue(
"isnull(cast('-1.23' as decimal(32,2)), NULL)",
Decimal8Value(-123),
4141 ColumnType::CreateDecimalType(32,2));
4142 TestDecimalValue(
"isnull(NULL, cast('0' as decimal(2,0)))",
Decimal4Value(0),
4143 ColumnType::CreateDecimalType(2, 0));
4144 TestDecimalValue(
"isnull(NULL, cast('1.1' as decimal(18,1)))",
Decimal8Value(11),
4145 ColumnType::CreateDecimalType(18,1));
4146 TestDecimalValue(
"isnull(NULL, cast('-1.23' as decimal(32,2)))",
Decimal8Value(-123),
4147 ColumnType::CreateDecimalType(32,2));
4148 TestIsNull(
"isnull(cast(NULL as decimal(2,0)), NULL)",
4149 ColumnType::CreateDecimalType(2,0));
4152 TestDecimalValue(
"isnull(cast('0' as decimal(2,0)), NULL)",
Decimal4Value(0),
4153 ColumnType::CreateDecimalType(2, 0));
4154 TestDecimalValue(
"isnull(cast('1.1' as decimal(18,1)), NULL)",
Decimal8Value(11),
4155 ColumnType::CreateDecimalType(18,1));
4156 TestDecimalValue(
"isnull(cast('-1.23' as decimal(32,2)), NULL)",
Decimal8Value(-123),
4157 ColumnType::CreateDecimalType(32,2));
4158 TestDecimalValue(
"isnull(NULL, cast('0' as decimal(2,0)))",
Decimal4Value(0),
4159 ColumnType::CreateDecimalType(2, 0));
4160 TestDecimalValue(
"isnull(NULL, cast('1.1' as decimal(18,1)))",
Decimal8Value(11),
4161 ColumnType::CreateDecimalType(18,1));
4162 TestDecimalValue(
"isnull(NULL, cast('-1.23' as decimal(32,2)))",
Decimal8Value(-123),
4163 ColumnType::CreateDecimalType(32,2));
4164 TestIsNull(
"isnull(cast(NULL as decimal(2,0)), NULL)",
4165 ColumnType::CreateDecimalType(2,0));
4168 TestDecimalValue(
"nullifzero(cast('10' as decimal(2,0)))",
Decimal4Value(10),
4169 ColumnType::CreateDecimalType(2, 0));
4170 TestDecimalValue(
"nullifzero(cast('1.1' as decimal(18,1)))",
Decimal8Value(11),
4171 ColumnType::CreateDecimalType(18,1));
4172 TestDecimalValue(
"nullifzero(cast('-1.23' as decimal(32,2)))",
Decimal8Value(-123),
4173 ColumnType::CreateDecimalType(32,2));
4174 TestIsNull(
"nullifzero(cast('0' as decimal(2,0)))",
4175 ColumnType::CreateDecimalType(2, 0));
4176 TestIsNull(
"nullifzero(cast('0' as decimal(18,1)))",
4177 ColumnType::CreateDecimalType(18,1));
4178 TestIsNull(
"nullifzero(cast('0' as decimal(32,2)))",
4179 ColumnType::CreateDecimalType(32,2));
4182 TestDecimalValue(
"if(TRUE, cast('0' as decimal(2,0)), NULL)",
Decimal4Value(0),
4183 ColumnType::CreateDecimalType(2, 0));
4184 TestDecimalValue(
"if(TRUE, cast('1.1' as decimal(18,1)), NULL)",
Decimal8Value(11),
4185 ColumnType::CreateDecimalType(18,1));
4186 TestDecimalValue(
"if(TRUE, cast('-1.23' as decimal(32,2)), NULL)",
Decimal8Value(-123),
4187 ColumnType::CreateDecimalType(32,2));
4188 TestDecimalValue(
"if(FALSE, NULL, cast('0' as decimal(2,0)))",
Decimal4Value(0),
4189 ColumnType::CreateDecimalType(2, 0));
4190 TestDecimalValue(
"if(FALSE, NULL, cast('1.1' as decimal(18,1)))",
Decimal8Value(11),
4191 ColumnType::CreateDecimalType(18,1));
4192 TestDecimalValue(
"if(FALSE, NULL, cast('-1.23' as decimal(32,2)))",
Decimal8Value(-123),
4193 ColumnType::CreateDecimalType(32,2));
4194 TestIsNull(
"if(TRUE, cast(NULL as decimal(32,2)), NULL)",
4195 ColumnType::CreateDecimalType(32,2));
4196 TestIsNull(
"if(FALSE, cast('-1.23' as decimal(32,2)), NULL)",
4197 ColumnType::CreateDecimalType(32,2));
4200 TestDecimalValue(
"zeroifnull(cast('10' as decimal(2,0)))",
Decimal4Value(10),
4201 ColumnType::CreateDecimalType(2, 0));
4202 TestDecimalValue(
"zeroifnull(cast('1.1' as decimal(18,1)))",
Decimal8Value(11),
4203 ColumnType::CreateDecimalType(18,1));
4204 TestDecimalValue(
"zeroifnull(cast('-1.23' as decimal(32,2)))",
Decimal8Value(-123),
4205 ColumnType::CreateDecimalType(32,2));
4206 TestDecimalValue(
"zeroifnull(cast(NULL as decimal(2,0)))",
Decimal4Value(0),
4207 ColumnType::CreateDecimalType(2, 0));
4208 TestDecimalValue(
"zeroifnull(cast(NULL as decimal(18,1)))",
Decimal8Value(0),
4209 ColumnType::CreateDecimalType(18,1));
4210 TestDecimalValue(
"zeroifnull(cast(NULL as decimal(32,2)))",
Decimal16Value(0),
4211 ColumnType::CreateDecimalType(32,2));
4214 TestDecimalValue(
"coalesce(NULL, cast('0' as decimal(2,0)))",
Decimal4Value(0),
4215 ColumnType::CreateDecimalType(2, 0));
4216 TestDecimalValue(
"coalesce(NULL, cast('0' as decimal(18,0)))",
Decimal8Value(0),
4217 ColumnType::CreateDecimalType(18, 0));
4218 TestDecimalValue(
"coalesce(NULL, cast('1.1' as decimal(18,1)))",
Decimal8Value(11),
4219 ColumnType::CreateDecimalType(18,1));
4220 TestDecimalValue(
"coalesce(NULL, cast('-1.23' as decimal(18,2)))",
Decimal8Value(-123),
4221 ColumnType::CreateDecimalType(18,2));
4222 TestDecimalValue(
"coalesce(NULL, cast('0' as decimal(32,0)))",
Decimal16Value(0),
4223 ColumnType::CreateDecimalType(32, 0));
4224 TestDecimalValue(
"coalesce(NULL, cast('1.1' as decimal(32,1)))",
Decimal8Value(11),
4225 ColumnType::CreateDecimalType(32,1));
4226 TestDecimalValue(
"coalesce(NULL, cast('-1.23' as decimal(32,2)))",
Decimal8Value(-123),
4227 ColumnType::CreateDecimalType(32,2));
4228 TestIsNull(
"coalesce(cast(NULL as decimal(2,0)), NULL)",
4229 ColumnType::CreateDecimalType(2,0));
4232 TestDecimalValue(
"CASE when true then cast('10' as decimal(2,0)) end",
4234 TestDecimalValue(
"CASE when true then cast('1.1' as decimal(18,1)) end",
4236 TestDecimalValue(
"CASE when true then cast('-1.23' as decimal(32,2)) end",
4238 TestDecimalValue(
"CASE when false then NULL else cast('10' as decimal(2,0)) end",
4240 TestDecimalValue(
"CASE when false then NULL else cast('1.1' as decimal(18,1)) end",
4242 TestDecimalValue(
"CASE when false then NULL else cast('-1.23' as decimal(32,2)) end",
4245 TestValue(
"CASE 1.1 when 1.1 then 1 when 2.22 then 2 else 3 end",
TYPE_TINYINT, 1);
4246 TestValue(
"CASE 2.22 when 1.1 then 1 when 2.22 then 2 else 3 end",
TYPE_TINYINT, 2);
4247 TestValue(
"CASE 2.21 when 1.1 then 1 when 2.22 then 2 else 3 end",
TYPE_TINYINT, 3);
4248 TestValue(
"CASE NULL when 1.1 then 1 when 2.22 then 2 else 3 end",
TYPE_TINYINT, 3);
4250 TestDecimalValue(
"CASE 2.21 when 1.1 then 1.1 when 2.21 then 2.2 else 3.3 end",
4254 TestDecimalValue(
"positive(cast('10' as decimal(2,0)))",
4256 TestDecimalValue(
"positive(cast('1.1' as decimal(18,1)))",
4258 TestDecimalValue(
"positive(cast('-1.23' as decimal(32,2)))",
4260 TestIsNull(
"positive(cast(NULL as decimal(32,2)))",
4261 ColumnType::CreateDecimalType(32,2));
4264 TestDecimalValue(
"negative(cast('10' as decimal(2,0)))",
4266 TestDecimalValue(
"negative(cast('1.1' as decimal(18,1)))",
4268 TestDecimalValue(
"negative(cast('-1.23' as decimal(32,2)))",
4270 TestIsNull(
"negative(cast(NULL as decimal(32,2)))",
4271 ColumnType::CreateDecimalType(32,2));
4275 TestDecimalValue(
"least(cast('10' as decimal(2,0)), cast('-10' as decimal(2,0)))",
4277 TestDecimalValue(
"least(cast('1.1' as decimal(18,1)), cast('-1.1' as decimal(18,1)))",
4279 TestDecimalValue(
"least(cast('-1.23' as decimal(32,2)), cast('1.23' as decimal(32,2)))",
4281 TestIsNull(
"least(cast(NULL as decimal(32,2)), cast('1.23' as decimal(32,2)))",
4282 ColumnType::CreateDecimalType(32,2));
4283 TestIsNull(
"least(cast('1.23' as decimal(32,2)), NULL)",
4284 ColumnType::CreateDecimalType(32,2));
4285 TestIsNull(
"least(cast(NULl as decimal(32,2)), NULL)",
4286 ColumnType::CreateDecimalType(32,2));
4289 TestDecimalValue(
"greatest(cast('10' as decimal(2,0)), cast('-10' as decimal(2,0)))",
4292 "greatest(cast('1.1' as decimal(18,1)), cast('-1.1' as decimal(18,1)))",
4295 "greatest(cast('-1.23' as decimal(32,2)), cast('1.23' as decimal(32,2)))",
4297 TestIsNull(
"greatest(cast(NULL as decimal(32,2)), cast('1.23' as decimal(32,2)))",
4298 ColumnType::CreateDecimalType(32,2));
4299 TestIsNull(
"greatest(cast('1.23' as decimal(32,2)), NULL)",
4300 ColumnType::CreateDecimalType(32,2));
4301 TestIsNull(
"greatest(cast(NULl as decimal(32,2)), NULL)",
4302 ColumnType::CreateDecimalType(32,2));
4306 uint64_t expected = HashUtil::FnvHash64(&dec4, 4, HashUtil::FNV_SEED);
4307 TestValue(
"fnv_hash(cast('10' as decimal(2,0)))",
TYPE_BIGINT, expected);
4310 expected = HashUtil::FnvHash64(&dec8, 8, HashUtil::FNV_SEED);
4311 TestValue(
"fnv_hash(cast('1.1' as decimal(18,1)))",
TYPE_BIGINT, expected);
4314 expected = HashUtil::FnvHash64(&dec16, 16, HashUtil::FNV_SEED);
4315 TestValue(
"fnv_hash(cast('-1.23' as decimal(32,2)))",
TYPE_BIGINT, expected);
4322 TestDecimalValue(
"ceil(cast('0' as decimal(6,5)))",
Decimal4Value(0),
4323 ColumnType::CreateDecimalType(6, 0));
4324 TestDecimalValue(
"ceil(cast('3.14159' as decimal(6,5)))",
Decimal4Value(4),
4325 ColumnType::CreateDecimalType(6, 0));
4326 TestDecimalValue(
"ceil(cast('-3.14159' as decimal(6,5)))",
Decimal4Value(-3),
4327 ColumnType::CreateDecimalType(6, 0));
4328 TestDecimalValue(
"ceil(cast('3' as decimal(6,5)))",
Decimal4Value(3),
4329 ColumnType::CreateDecimalType(6, 0));
4330 TestDecimalValue(
"ceil(cast('3.14159' as decimal(13,5)))",
Decimal8Value(4),
4331 ColumnType::CreateDecimalType(13, 0));
4332 TestDecimalValue(
"ceil(cast('-3.14159' as decimal(13,5)))",
Decimal8Value(-3),
4333 ColumnType::CreateDecimalType(13, 0));
4334 TestDecimalValue(
"ceil(cast('3' as decimal(13,5)))",
Decimal8Value(3),
4335 ColumnType::CreateDecimalType(13, 0));
4336 TestDecimalValue(
"ceil(cast('3.14159' as decimal(33,5)))",
Decimal16Value(4),
4337 ColumnType::CreateDecimalType(33, 0));
4338 TestDecimalValue(
"ceil(cast('-3.14159' as decimal(33,5)))",
Decimal16Value(-3),
4339 ColumnType::CreateDecimalType(33, 0));
4340 TestDecimalValue(
"ceil(cast('3' as decimal(33,5)))",
Decimal16Value(3),
4341 ColumnType::CreateDecimalType(33, 0));
4342 TestDecimalValue(
"ceil(cast('9.14159' as decimal(6,5)))",
Decimal4Value(10),
4343 ColumnType::CreateDecimalType(2, 0));
4344 TestIsNull(
"ceil(cast(NULL as decimal(2,0)))", ColumnType::CreateDecimalType(2,0));
4347 TestDecimalValue(
"floor(cast('3.14159' as decimal(6,5)))",
Decimal4Value(3),
4348 ColumnType::CreateDecimalType(6, 0));
4349 TestDecimalValue(
"floor(cast('-3.14159' as decimal(6,5)))",
Decimal4Value(-4),
4350 ColumnType::CreateDecimalType(6, 0));
4351 TestDecimalValue(
"floor(cast('3' as decimal(6,5)))",
Decimal4Value(3),
4352 ColumnType::CreateDecimalType(6, 0));
4353 TestDecimalValue(
"floor(cast('3.14159' as decimal(13,5)))",
Decimal8Value(3),
4354 ColumnType::CreateDecimalType(13, 0));
4355 TestDecimalValue(
"floor(cast('-3.14159' as decimal(13,5)))",
Decimal8Value(-4),
4356 ColumnType::CreateDecimalType(13, 0));
4357 TestDecimalValue(
"floor(cast('3' as decimal(13,5)))",
Decimal8Value(3),
4358 ColumnType::CreateDecimalType(13, 0));
4359 TestDecimalValue(
"floor(cast('3.14159' as decimal(33,5)))",
Decimal16Value(3),
4360 ColumnType::CreateDecimalType(33, 0));
4361 TestDecimalValue(
"floor(cast('-3.14159' as decimal(33,5)))",
Decimal16Value(-4),
4362 ColumnType::CreateDecimalType(33, 0));
4363 TestDecimalValue(
"floor(cast('3' as decimal(33,5)))",
Decimal16Value(3),
4364 ColumnType::CreateDecimalType(33, 0));
4365 TestDecimalValue(
"floor(cast('-9.14159' as decimal(6,5)))",
Decimal4Value(-10),
4366 ColumnType::CreateDecimalType(2, 0));
4367 TestIsNull(
"floor(cast(NULL as decimal(2,0)))", ColumnType::CreateDecimalType(2,0));
4370 TestDecimalValue(
"round(cast('3.14159' as decimal(6,5)))",
Decimal4Value(3),
4371 ColumnType::CreateDecimalType(6, 0));
4372 TestDecimalValue(
"round(cast('-3.14159' as decimal(6,5)))",
Decimal4Value(-3),
4373 ColumnType::CreateDecimalType(6, 0));
4374 TestDecimalValue(
"round(cast('3' as decimal(6,5)))",
Decimal4Value(3),
4375 ColumnType::CreateDecimalType(6, 0));
4376 TestDecimalValue(
"round(cast('3.14159' as decimal(13,5)))",
Decimal8Value(3),
4377 ColumnType::CreateDecimalType(13, 0));
4378 TestDecimalValue(
"round(cast('-3.14159' as decimal(13,5)))",
Decimal8Value(-3),
4379 ColumnType::CreateDecimalType(13, 0));
4380 TestDecimalValue(
"round(cast('3' as decimal(13,5)))",
Decimal8Value(3),
4381 ColumnType::CreateDecimalType(13, 0));
4382 TestDecimalValue(
"round(cast('3.14159' as decimal(33,5)))",
Decimal16Value(3),
4383 ColumnType::CreateDecimalType(33, 0));
4384 TestDecimalValue(
"round(cast('-3.14159' as decimal(33,5)))",
Decimal16Value(-3),
4385 ColumnType::CreateDecimalType(33, 0));
4386 TestDecimalValue(
"round(cast('3' as decimal(33,5)))",
Decimal16Value(3),
4387 ColumnType::CreateDecimalType(33, 0));
4388 TestDecimalValue(
"round(cast('9.54159' as decimal(6,5)))",
Decimal4Value(10),
4389 ColumnType::CreateDecimalType(2, 0));
4390 TestDecimalValue(
"round(cast('-9.54159' as decimal(6,5)))",
Decimal4Value(-10),
4391 ColumnType::CreateDecimalType(2, 0));
4392 TestIsNull(
"round(cast(NULL as decimal(2,0)))", ColumnType::CreateDecimalType(2,0));
4395 TestDecimalValue(
"truncate(cast('3.54159' as decimal(6,5)))",
Decimal4Value(3),
4396 ColumnType::CreateDecimalType(6, 0));
4397 TestDecimalValue(
"truncate(cast('-3.54159' as decimal(6,5)))",
Decimal4Value(-3),
4398 ColumnType::CreateDecimalType(6, 0));
4399 TestDecimalValue(
"truncate(cast('3' as decimal(6,5)))",
Decimal4Value(3),
4400 ColumnType::CreateDecimalType(6, 0));
4401 TestDecimalValue(
"truncate(cast('3.54159' as decimal(13,5)))",
Decimal8Value(3),
4402 ColumnType::CreateDecimalType(13, 0));
4403 TestDecimalValue(
"truncate(cast('-3.54159' as decimal(13,5)))",
Decimal8Value(-3),
4404 ColumnType::CreateDecimalType(13, 0));
4405 TestDecimalValue(
"truncate(cast('3' as decimal(13,5)))",
Decimal8Value(3),
4406 ColumnType::CreateDecimalType(13, 0));
4407 TestDecimalValue(
"truncate(cast('3.54159' as decimal(33,5)))",
Decimal16Value(3),
4408 ColumnType::CreateDecimalType(33, 0));
4409 TestDecimalValue(
"truncate(cast('-3.54159' as decimal(33,5)))",
Decimal16Value(-3),
4410 ColumnType::CreateDecimalType(33, 0));
4411 TestDecimalValue(
"truncate(cast('3' as decimal(33,5)))",
Decimal16Value(3),
4412 ColumnType::CreateDecimalType(33, 0));
4413 TestDecimalValue(
"truncate(cast('9.54159' as decimal(6,5)))",
Decimal4Value(9),
4414 ColumnType::CreateDecimalType(1, 0));
4415 TestIsNull(
"truncate(cast(NULL as decimal(2,0)))", ColumnType::CreateDecimalType(2,0));
4418 TestIsNull(
"round(cast(NULL as decimal(2,0)), 1)", ColumnType::CreateDecimalType(2,0));
4420 TestDecimalValue(
"round(cast('3.1615' as decimal(6,4)), 0)",
Decimal4Value(3),
4421 ColumnType::CreateDecimalType(2, 0));
4422 TestDecimalValue(
"round(cast('-3.1615' as decimal(6,4)), 1)",
Decimal4Value(-32),
4423 ColumnType::CreateDecimalType(3, 1));
4424 TestDecimalValue(
"round(cast('3.1615' as decimal(6,4)), 2)",
Decimal4Value(316),
4425 ColumnType::CreateDecimalType(4, 2));
4426 TestDecimalValue(
"round(cast('3.1615' as decimal(6,4)), 3)",
Decimal4Value(3162),
4427 ColumnType::CreateDecimalType(5, 3));
4428 TestDecimalValue(
"round(cast('-3.1615' as decimal(6,4)), 3)",
Decimal4Value(-3162),
4429 ColumnType::CreateDecimalType(5, 3));
4430 TestDecimalValue(
"round(cast('3.1615' as decimal(6,4)), 4)",
Decimal4Value(31615),
4431 ColumnType::CreateDecimalType(6, 4));
4432 TestDecimalValue(
"round(cast('-3.1615' as decimal(6,4)), 5)",
Decimal4Value(-316150),
4433 ColumnType::CreateDecimalType(7, 5));
4434 TestDecimalValue(
"round(cast('175.0' as decimal(6,1)), 0)",
Decimal4Value(175),
4435 ColumnType::CreateDecimalType(6, 0));
4436 TestDecimalValue(
"round(cast('-175.0' as decimal(6,1)), -1)",
Decimal4Value(-180),
4437 ColumnType::CreateDecimalType(6, 0));
4438 TestDecimalValue(
"round(cast('175.0' as decimal(6,1)), -2)",
Decimal4Value(200),
4439 ColumnType::CreateDecimalType(6, 0));
4440 TestDecimalValue(
"round(cast('-175.0' as decimal(6,1)), -3)",
Decimal4Value(0),
4441 ColumnType::CreateDecimalType(6, 0));
4442 TestDecimalValue(
"round(cast('175.0' as decimal(6,1)), -4)",
Decimal4Value(0),
4443 ColumnType::CreateDecimalType(6, 0));
4444 TestDecimalValue(
"round(cast('999.951' as decimal(6,3)), 1)",
Decimal4Value(10000),
4445 ColumnType::CreateDecimalType(5, 1));
4447 TestDecimalValue(
"round(cast('-3.1615' as decimal(16,4)), 0)",
Decimal8Value(-3),
4448 ColumnType::CreateDecimalType(12, 0));
4449 TestDecimalValue(
"round(cast('3.1615' as decimal(16,4)), 1)",
Decimal8Value(32),
4450 ColumnType::CreateDecimalType(13, 1));
4451 TestDecimalValue(
"round(cast('-3.1615' as decimal(16,4)), 2)",
Decimal8Value(-316),
4452 ColumnType::CreateDecimalType(14, 2));
4453 TestDecimalValue(
"round(cast('3.1615' as decimal(16,4)), 3)",
Decimal8Value(3162),
4454 ColumnType::CreateDecimalType(15, 3));
4455 TestDecimalValue(
"round(cast('-3.1615' as decimal(16,4)), 3)",
Decimal8Value(-3162),
4456 ColumnType::CreateDecimalType(15, 3));
4457 TestDecimalValue(
"round(cast('-3.1615' as decimal(16,4)), 4)",
Decimal8Value(-31615),
4458 ColumnType::CreateDecimalType(16, 4));
4459 TestDecimalValue(
"round(cast('3.1615' as decimal(16,4)), 5)",
Decimal8Value(316150),
4460 ColumnType::CreateDecimalType(17, 5));
4461 TestDecimalValue(
"round(cast('-999.951' as decimal(16,3)), 1)",
Decimal8Value(-10000),
4462 ColumnType::CreateDecimalType(17, 1));
4464 TestDecimalValue(
"round(cast('-175.0' as decimal(15,1)), 0)",
Decimal8Value(-175),
4465 ColumnType::CreateDecimalType(15, 0));
4466 TestDecimalValue(
"round(cast('175.0' as decimal(15,1)), -1)",
Decimal8Value(180),
4467 ColumnType::CreateDecimalType(15, 0));
4468 TestDecimalValue(
"round(cast('-175.0' as decimal(15,1)), -2)",
Decimal8Value(-200),
4469 ColumnType::CreateDecimalType(15, 0));
4470 TestDecimalValue(
"round(cast('175.0' as decimal(15,1)), -3)",
Decimal8Value(0),
4471 ColumnType::CreateDecimalType(15, 0));
4472 TestDecimalValue(
"round(cast('-175.0' as decimal(15,1)), -4)",
Decimal8Value(0),
4473 ColumnType::CreateDecimalType(15, 0));
4475 TestDecimalValue(
"round(cast('3.1615' as decimal(32,4)), 0)",
Decimal16Value(3),
4476 ColumnType::CreateDecimalType(32, 0));
4477 TestDecimalValue(
"round(cast('-3.1615' as decimal(32,4)), 1)",
Decimal16Value(-32),
4478 ColumnType::CreateDecimalType(33, 1));
4479 TestDecimalValue(
"round(cast('3.1615' as decimal(32,4)), 2)",
Decimal16Value(316),
4480 ColumnType::CreateDecimalType(34, 2));
4481 TestDecimalValue(
"round(cast('3.1615' as decimal(32,4)), 3)",
Decimal16Value(3162),
4482 ColumnType::CreateDecimalType(35, 3));
4483 TestDecimalValue(
"round(cast('-3.1615' as decimal(32,4)), 3)",
Decimal16Value(-3162),
4484 ColumnType::CreateDecimalType(36, 3));
4485 TestDecimalValue(
"round(cast('3.1615' as decimal(32,4)), 4)",
Decimal16Value(31615),
4486 ColumnType::CreateDecimalType(37, 4));
4487 TestDecimalValue(
"round(cast('-3.1615' as decimal(32,5)), 5)",
Decimal16Value(-316150),
4488 ColumnType::CreateDecimalType(38, 5));
4489 TestDecimalValue(
"round(cast('-175.0' as decimal(35,1)), 0)",
Decimal16Value(-175),
4490 ColumnType::CreateDecimalType(35, 0));
4491 TestDecimalValue(
"round(cast('175.0' as decimal(35,1)), -1)",
Decimal16Value(180),
4492 ColumnType::CreateDecimalType(35, 0));
4493 TestDecimalValue(
"round(cast('-175.0' as decimal(35,1)), -2)",
Decimal16Value(-200),
4494 ColumnType::CreateDecimalType(35, 0));
4495 TestDecimalValue(
"round(cast('175.0' as decimal(35,1)), -3)",
Decimal16Value(0),
4496 ColumnType::CreateDecimalType(35, 0));
4497 TestDecimalValue(
"round(cast('-175.0' as decimal(35,1)), -4)",
Decimal16Value(0),
4498 ColumnType::CreateDecimalType(35, 0));
4499 TestDecimalValue(
"round(cast('99999.9951' as decimal(35,4)), 2)",
4503 TestIsNull(
"truncate(cast(NULL as decimal(2,0)), 1)",
4504 ColumnType::CreateDecimalType(2,0));
4506 TestDecimalValue(
"truncate(cast('-3.1615' as decimal(6,4)), 0)",
Decimal4Value(-3),
4507 ColumnType::CreateDecimalType(6, 0));
4508 TestDecimalValue(
"truncate(cast('3.1615' as decimal(6,4)), 1)",
Decimal4Value(31),
4509 ColumnType::CreateDecimalType(6, 1));
4510 TestDecimalValue(
"truncate(cast('-3.1615' as decimal(6,4)), 2)",
Decimal4Value(-316),
4511 ColumnType::CreateDecimalType(6, 2));
4512 TestDecimalValue(
"truncate(cast('3.1615' as decimal(6,4)), 3)",
Decimal4Value(3161),
4513 ColumnType::CreateDecimalType(6, 3));
4514 TestDecimalValue(
"truncate(cast('-3.1615' as decimal(6,4)), 4)",
Decimal4Value(-31615),
4515 ColumnType::CreateDecimalType(6, 4));
4516 TestDecimalValue(
"truncate(cast('3.1615' as decimal(6,4)), 5)",
Decimal4Value(316150),
4517 ColumnType::CreateDecimalType(7, 5));
4518 TestDecimalValue(
"truncate(cast('175.0' as decimal(6,1)), 0)",
Decimal4Value(175),
4519 ColumnType::CreateDecimalType(6, 0));
4520 TestDecimalValue(
"truncate(cast('-175.0' as decimal(6,1)), -1)",
Decimal4Value(-170),
4521 ColumnType::CreateDecimalType(6, 0));
4522 TestDecimalValue(
"truncate(cast('175.0' as decimal(6,1)), -2)",
Decimal4Value(100),
4523 ColumnType::CreateDecimalType(6, 0));
4524 TestDecimalValue(
"truncate(cast('-175.0' as decimal(6,1)), -3)",
Decimal4Value(0),
4525 ColumnType::CreateDecimalType(6, 0));
4526 TestDecimalValue(
"truncate(cast('175.0' as decimal(6,1)), -4)",
Decimal4Value(0),
4527 ColumnType::CreateDecimalType(6, 0));
4529 TestDecimalValue(
"truncate(cast('-3.1615' as decimal(16,4)), 0)",
Decimal8Value(-3),
4530 ColumnType::CreateDecimalType(12, 0));
4531 TestDecimalValue(
"truncate(cast('3.1615' as decimal(16,4)), 1)",
Decimal8Value(31),
4532 ColumnType::CreateDecimalType(13, 1));
4533 TestDecimalValue(
"truncate(cast('-3.1615' as decimal(16,4)), 2)",
Decimal8Value(-316),
4534 ColumnType::CreateDecimalType(14, 2));
4535 TestDecimalValue(
"truncate(cast('3.1615' as decimal(16,4)), 3)",
Decimal8Value(3161),
4536 ColumnType::CreateDecimalType(15, 3));
4537 TestDecimalValue(
"truncate(cast('3.1615' as decimal(16,4)), 4)",
4538 Decimal8Value(31615), ColumnType::CreateDecimalType(16, 4));
4539 TestDecimalValue(
"truncate(cast('-3.1615' as decimal(16,4)), 5)",
4540 Decimal8Value(-316150), ColumnType::CreateDecimalType(17, 5));
4541 TestDecimalValue(
"truncate(cast('-175.0' as decimal(15,1)), 0)",
Decimal8Value(-175),
4542 ColumnType::CreateDecimalType(15, 0));
4543 TestDecimalValue(
"truncate(cast('175.0' as decimal(15,1)), -1)",
Decimal8Value(170),
4544 ColumnType::CreateDecimalType(15, 0));
4545 TestDecimalValue(
"truncate(cast('-175.0' as decimal(15,1)), -2)",
Decimal8Value(-100),
4546 ColumnType::CreateDecimalType(15, 0));
4547 TestDecimalValue(
"truncate(cast('175.0' as decimal(15,1)), -3)",
Decimal8Value(0),
4548 ColumnType::CreateDecimalType(15, 0));
4549 TestDecimalValue(
"truncate(cast('-175.0' as decimal(15,1)), -4)",
Decimal8Value(0),
4550 ColumnType::CreateDecimalType(15, 0));
4552 TestDecimalValue(
"truncate(cast('-3.1615' as decimal(32,4)), 0)",
4554 TestDecimalValue(
"truncate(cast('3.1615' as decimal(32,4)), 1)",
4556 TestDecimalValue(
"truncate(cast('-3.1615' as decimal(32,4)), 2)",
4558 TestDecimalValue(
"truncate(cast('3.1615' as decimal(32,4)), 3)",
4560 TestDecimalValue(
"truncate(cast('-3.1615' as decimal(32,4)), 4)",
4562 TestDecimalValue(
"truncate(cast('3.1615' as decimal(32,4)), 5)",
4564 TestDecimalValue(
"truncate(cast('-175.0' as decimal(35,1)), 0)",
4566 TestDecimalValue(
"truncate(cast('175.0' as decimal(35,1)), -1)",
4568 TestDecimalValue(
"truncate(cast('-175.0' as decimal(35,1)), -2)",
4570 TestDecimalValue(
"truncate(cast('175.0' as decimal(35,1)), -3)",
4572 TestDecimalValue(
"truncate(cast('-175.0' as decimal(35,1)), -4)",
4578 TestIsNull(
"round(99999999999999999999999999999999999999., -1)",
4579 ColumnType::CreateDecimalType(38, 0));
4580 TestIsNull(
"round(-99999999999999999999999999999999000000., -7)",
4581 ColumnType::CreateDecimalType(38, 0));
4587 TestDecimalValue(
"cast(123.456 as decimal(6,3))",
4588 Decimal4Value(123456), ColumnType::CreateDecimalType(6, 3));
4589 TestDecimalValue(
"cast(-123.456 as decimal(6,1))",
4591 TestDecimalValue(
"cast(123.456 as decimal(6,0))",
4593 TestDecimalValue(
"cast(-123.456 as decimal(3,0))",
4596 TestDecimalValue(
"cast(123.4567890 as decimal(10,7))",
4597 Decimal8Value(1234567890L), ColumnType::CreateDecimalType(10, 7));
4599 TestDecimalValue(
"cast(cast(\"123.01234567890123456789\" as decimal(23,20))\
4601 ColumnType::CreateDecimalType(12, 9));
4602 TestDecimalValue(
"cast(cast(\"123.01234567890123456789\" as decimal(23,20))\
4603 as decimal(4,1))",
Decimal4Value(1230), ColumnType::CreateDecimalType(4, 1));
4605 TestDecimalValue(
"cast(cast(\"123.0123456789\" as decimal(13,10))\
4606 as decimal(5,2))",
Decimal4Value(12301), ColumnType::CreateDecimalType(5, 2));
4609 TestIsNull(
"cast(123.456 as decimal(2,0))", ColumnType::CreateDecimalType(2, 0));
4610 TestIsNull(
"cast(123.456 as decimal(2,1))", ColumnType::CreateDecimalType(2, 2));
4611 TestIsNull(
"cast(123.456 as decimal(2,2))", ColumnType::CreateDecimalType(2, 2));
4612 TestIsNull(
"cast(99.99 as decimal(2,2))", ColumnType::CreateDecimalType(2, 2));
4613 TestDecimalValue(
"cast(99.99 as decimal(2,0))",
4615 TestIsNull(
"cast(-99.99 as decimal(2,2))", ColumnType::CreateDecimalType(2, 2));
4616 TestDecimalValue(
"cast(-99.99 as decimal(3,1))",
4619 TestDecimalValue(
"cast(999.99 as decimal(6,3))",
4620 Decimal4Value(999990), ColumnType::CreateDecimalType(6, 3));
4621 TestDecimalValue(
"cast(-999.99 as decimal(7,4))",
4622 Decimal4Value(-9999900), ColumnType::CreateDecimalType(7, 4));
4623 TestIsNull(
"cast(9990.99 as decimal(6,3))", ColumnType::CreateDecimalType(6, 3));
4624 TestIsNull(
"cast(-9990.99 as decimal(7,4))", ColumnType::CreateDecimalType(7, 4));
4626 TestDecimalValue(
"cast(123.4567890 as decimal(4, 1))",
4628 TestDecimalValue(
"cast(-123.4567890 as decimal(5, 2))",
4629 Decimal4Value(-12345), ColumnType::CreateDecimalType(5, 2));
4630 TestIsNull(
"cast(123.4567890 as decimal(2, 1))", ColumnType::CreateDecimalType(2, 1));
4631 TestIsNull(
"cast(123.4567890 as decimal(6, 5))", ColumnType::CreateDecimalType(6, 5));
4633 TestDecimalValue(
"cast(pi() as decimal(1, 0))",
4635 TestDecimalValue(
"cast(pi() as decimal(4, 1))",
4637 TestDecimalValue(
"cast(pi() as decimal(30, 1))",
4639 TestIsNull(
"cast(pi() as decimal(4, 4))", ColumnType::CreateDecimalType(4, 4));
4640 TestIsNull(
"cast(pi() as decimal(11, 11))", ColumnType::CreateDecimalType(11, 11));
4641 TestIsNull(
"cast(pi() as decimal(31, 31))", ColumnType::CreateDecimalType(31, 31));
4643 TestIsNull(
"cast(140573315541874605.4665184383287 as decimal(17, 13))",
4644 ColumnType::CreateDecimalType(17, 13));
4645 TestIsNull(
"cast(140573315541874605.4665184383287 as decimal(9, 3))",
4646 ColumnType::CreateDecimalType(17, 13));
4649 TestIsNull(
"cast(99999999999999999999999999999.9 as decimal(29, 1))",
4650 ColumnType::CreateDecimalType(29, 1));
4653 TestIsNull(
"cast(regexp_replace('','a','b') as decimal(15,2))",
4654 ColumnType::CreateDecimalType(15,2));
4658 TestValue(
"nullvalue(cast(NULL as boolean))",
TYPE_BOOLEAN,
true);
4659 TestValue(
"nullvalue(cast(0 as boolean))",
TYPE_BOOLEAN,
false);
4660 TestValue(
"nullvalue(cast(5 as boolean))",
TYPE_BOOLEAN,
false);
4661 TestValue(
"nullvalue(cast(-5 as boolean))",
TYPE_BOOLEAN,
false);
4662 TestValue(
"nullvalue(cast(NULL as int))",
TYPE_BOOLEAN,
true);
4664 TestValue(
"nullvalue(cast(0 as int))",
TYPE_BOOLEAN,
false);
4665 TestValue(
"nullvalue(cast(5 as int))",
TYPE_BOOLEAN,
false);
4666 TestValue(
"nullvalue(cast(-5 as int))",
TYPE_BOOLEAN,
false);
4668 TestValue(
"nullvalue(cast(NULL as tinyint))",
TYPE_BOOLEAN,
true);
4669 TestValue(
"nullvalue(cast(0 as tinyint))",
TYPE_BOOLEAN,
false);
4670 TestValue(
"nullvalue(cast(5 as tinyint))",
TYPE_BOOLEAN,
false);
4671 TestValue(
"nullvalue(cast(-5 as tinyint))",
TYPE_BOOLEAN,
false);
4673 TestValue(
"nullvalue(cast(NULL as smallint))",
TYPE_BOOLEAN,
true);
4674 TestValue(
"nullvalue(cast(0 as smallint))",
TYPE_BOOLEAN,
false);
4675 TestValue(
"nullvalue(cast(5 as smallint))",
TYPE_BOOLEAN,
false);
4676 TestValue(
"nullvalue(cast(-5 as smallint))",
TYPE_BOOLEAN,
false);
4678 TestValue(
"nullvalue(cast(NULL as bigint))",
TYPE_BOOLEAN,
true);
4679 TestValue(
"nullvalue(cast(0 as bigint))",
TYPE_BOOLEAN,
false);
4680 TestValue(
"nullvalue(cast(5 as bigint))",
TYPE_BOOLEAN,
false);
4681 TestValue(
"nullvalue(cast(-5 as bigint))",
TYPE_BOOLEAN,
false);
4683 TestValue(
"nullvalue(cast(NULL as float))",
TYPE_BOOLEAN,
true);
4684 TestValue(
"nullvalue(cast(0 as float))",
TYPE_BOOLEAN,
false);
4685 TestValue(
"nullvalue(cast(5.0 as float))",
TYPE_BOOLEAN,
false);
4686 TestValue(
"nullvalue(cast(-5.0 as float))",
TYPE_BOOLEAN,
false);
4688 TestValue(
"nullvalue(cast(NULL as double))",
TYPE_BOOLEAN,
true);
4689 TestValue(
"nullvalue(cast(0.0 as double))",
TYPE_BOOLEAN,
false);
4690 TestValue(
"nullvalue(cast(5.0 as double))",
TYPE_BOOLEAN,
false);
4691 TestValue(
"nullvalue(cast(-5.0 as double))",
TYPE_BOOLEAN,
false);
4693 TestValue(
"nullvalue(cast(NULL as decimal(38,0)))",
TYPE_BOOLEAN,
true);
4694 TestValue(
"nullvalue(cast(0 as decimal(38,0)))",
TYPE_BOOLEAN,
false);
4695 TestValue(
"nullvalue(cast(5 as decimal(38,0)))",
TYPE_BOOLEAN,
false);
4696 TestValue(
"nullvalue(cast(-5 as decimal(38,0)))",
TYPE_BOOLEAN,
false);
4697 TestValue(
"nullvalue(cast(0.0 as decimal(38,38)))",
TYPE_BOOLEAN,
false);
4698 TestValue(
"nullvalue(cast(0.1 as decimal(38,38)))",
TYPE_BOOLEAN,
false);
4699 TestValue(
"nullvalue(cast(-0.1 as decimal(38,38)))",
TYPE_BOOLEAN,
false);
4701 TestValue(
"nullvalue(cast(NULL as string))",
TYPE_BOOLEAN,
true);
4702 TestValue(
"nullvalue(cast('0' as string))",
TYPE_BOOLEAN,
false);
4703 TestValue(
"nullvalue(cast('5' as string))",
TYPE_BOOLEAN,
false);
4704 TestValue(
"nullvalue(cast('-5' as string))",
TYPE_BOOLEAN,
false);
4705 TestValue(
"nullvalue(cast(\"abc\" as string))",
TYPE_BOOLEAN,
false);
4706 TestValue(
"nullvalue(cast(\"\" as string))",
TYPE_BOOLEAN,
false);
4708 TestValue(
"nullvalue(cast(NULL as timestamp))",
TYPE_BOOLEAN,
true);
4709 TestValue(
"nullvalue(cast('2012-01-01 09:10:11.123456789' as timestamp))",
4721 TestValue(
"nullvalue(99999999999999999999999999999999999)",
TYPE_BOOLEAN,
false);
4722 TestValue(
"nullvalue(-99999999999999999999999999999999999)",
TYPE_BOOLEAN,
false);
4723 TestValue(
"nullvalue(99999999999999999999999999999999999.9)",
TYPE_BOOLEAN,
false);
4724 TestValue(
"nullvalue(-99999999999999999999999999999999999.9)",
TYPE_BOOLEAN,
false);
4728 TestValue(
"nonnullvalue(cast(NULL as boolean))",
TYPE_BOOLEAN,
false);
4729 TestValue(
"nonnullvalue(cast(0 as boolean))",
TYPE_BOOLEAN,
true);
4730 TestValue(
"nonnullvalue(cast(5 as boolean))",
TYPE_BOOLEAN,
true);
4731 TestValue(
"nonnullvalue(cast(-5 as boolean))",
TYPE_BOOLEAN,
true);
4733 TestValue(
"nonnullvalue(cast(NULL as int))",
TYPE_BOOLEAN,
false);
4734 TestValue(
"nonnullvalue(cast(0 as int))",
TYPE_BOOLEAN,
true);
4735 TestValue(
"nonnullvalue(cast(5 as int))",
TYPE_BOOLEAN,
true);
4736 TestValue(
"nonnullvalue(cast(-5 as int))",
TYPE_BOOLEAN,
true);
4738 TestValue(
"nonnullvalue(cast(NULL as tinyint))",
TYPE_BOOLEAN,
false);
4739 TestValue(
"nonnullvalue(cast(0 as tinyint))",
TYPE_BOOLEAN,
true);
4740 TestValue(
"nonnullvalue(cast(5 as tinyint))",
TYPE_BOOLEAN,
true);
4741 TestValue(
"nonnullvalue(cast(-5 as tinyint))",
TYPE_BOOLEAN,
true);
4743 TestValue(
"nonnullvalue(cast(NULL as smallint))",
TYPE_BOOLEAN,
false);
4744 TestValue(
"nonnullvalue(cast(0 as smallint))",
TYPE_BOOLEAN,
true);
4745 TestValue(
"nonnullvalue(cast(5 as smallint))",
TYPE_BOOLEAN,
true);
4746 TestValue(
"nonnullvalue(cast(-5 as smallint))",
TYPE_BOOLEAN,
true);
4748 TestValue(
"nonnullvalue(cast(NULL as bigint))",
TYPE_BOOLEAN,
false);
4749 TestValue(
"nonnullvalue(cast(0 as bigint))",
TYPE_BOOLEAN,
true);
4750 TestValue(
"nonnullvalue(cast(5 as bigint))",
TYPE_BOOLEAN,
true);
4751 TestValue(
"nonnullvalue(cast(-5 as bigint))",
TYPE_BOOLEAN,
true);
4753 TestValue(
"nonnullvalue(cast(NULL as float))",
TYPE_BOOLEAN,
false);
4754 TestValue(
"nonnullvalue(cast(0 as float))",
TYPE_BOOLEAN,
true);
4755 TestValue(
"nonnullvalue(cast(5.0 as float))",
TYPE_BOOLEAN,
true);
4756 TestValue(
"nonnullvalue(cast(-5.0 as float))",
TYPE_BOOLEAN,
true);
4758 TestValue(
"nonnullvalue(cast(NULL as double))",
TYPE_BOOLEAN,
false);
4759 TestValue(
"nonnullvalue(cast(0.0 as double))",
TYPE_BOOLEAN,
true);
4760 TestValue(
"nonnullvalue(cast(5.0 as double))",
TYPE_BOOLEAN,
true);
4761 TestValue(
"nonnullvalue(cast(-5.0 as double))",
TYPE_BOOLEAN,
true);
4763 TestValue(
"nonnullvalue(cast(NULL as decimal(38,0)))",
TYPE_BOOLEAN,
false);
4764 TestValue(
"nonnullvalue(cast(0 as decimal(38,0)))",
TYPE_BOOLEAN,
true);
4765 TestValue(
"nonnullvalue(cast(5 as decimal(38,0)))",
TYPE_BOOLEAN,
true);
4766 TestValue(
"nonnullvalue(cast(-5 as decimal(38,0)))",
TYPE_BOOLEAN,
true);
4767 TestValue(
"nonnullvalue(cast(0.0 as decimal(38,38)))",
TYPE_BOOLEAN,
true);
4768 TestValue(
"nonnullvalue(cast(0.1 as decimal(38,38)))",
TYPE_BOOLEAN,
true);
4769 TestValue(
"nonnullvalue(cast(-0.1 as decimal(38,38)))",
TYPE_BOOLEAN,
true);
4771 TestValue(
"nonnullvalue(cast(NULL as string))",
TYPE_BOOLEAN,
false);
4772 TestValue(
"nonnullvalue(cast('0' as string))",
TYPE_BOOLEAN,
true);
4773 TestValue(
"nonnullvalue(cast('5' as string))",
TYPE_BOOLEAN,
true);
4774 TestValue(
"nonnullvalue(cast('-5' as string))",
TYPE_BOOLEAN,
true);
4775 TestValue(
"nonnullvalue(cast(\"abc\" as string))",
TYPE_BOOLEAN,
true);
4776 TestValue(
"nonnullvalue(cast(\"\" as string))",
TYPE_BOOLEAN,
true);
4778 TestValue(
"nonnullvalue(cast(NULL as timestamp))",
TYPE_BOOLEAN,
false);
4779 TestValue(
"nonnullvalue(cast('2012-01-01 09:10:11.123456789' as timestamp))",
4786 TestValue(
"nonnullvalue(-1.2345)",
TYPE_BOOLEAN,
true);
4789 TestValue(
"nonnullvalue(\"abc\")",
TYPE_BOOLEAN,
true);
4791 TestValue(
"nonnullvalue(99999999999999999999999999999999999)",
TYPE_BOOLEAN,
true);
4792 TestValue(
"nonnullvalue(-99999999999999999999999999999999999)",
TYPE_BOOLEAN,
true);
4793 TestValue(
"nonnullvalue(99999999999999999999999999999999999.9)",
TYPE_BOOLEAN,
true);
4794 TestValue(
"nonnullvalue(-99999999999999999999999999999999999.9)",
TYPE_BOOLEAN,
true);
4800 TestStringValue(
"udf_lower('Hello_WORLD')",
"hello_world");
4802 TestValue(
"max_tinyint()",
TYPE_TINYINT, numeric_limits<int8_t>::max());
4803 TestValue(
"max_smallint()",
TYPE_SMALLINT, numeric_limits<int16_t>::max());
4804 TestValue(
"max_int()",
TYPE_INT, numeric_limits<int32_t>::max());
4805 TestValue(
"max_bigint()",
TYPE_BIGINT, numeric_limits<int64_t>::max());
4807 TestValue(
"min_tinyint()",
TYPE_TINYINT, numeric_limits<int8_t>::min());
4808 TestValue(
"min_smallint()",
TYPE_SMALLINT, numeric_limits<int16_t>::min());
4809 TestValue(
"min_int()",
TYPE_INT, numeric_limits<int32_t>::min());
4810 TestValue(
"min_bigint()",
TYPE_BIGINT, numeric_limits<int64_t>::min());
4814 TestStringValue(
"madlib_encode_vector(madlib_vector(1.0, 2.0, 3.0))",
4815 "aaaaaipdaaaaaaaeaaaaaeae");
4816 TestStringValue(
"madlib_print_vector(madlib_vector(1, 2, 3))",
"<1, 2, 3>");
4818 "madlib_encode_vector(madlib_decode_vector(madlib_encode_vector("
4819 "madlib_vector(1.0, 2.0, 3.0))))",
4820 "aaaaaipdaaaaaaaeaaaaaeae");
4821 TestValue(
"madlib_vector_get(0, madlib_vector(1.0, 2.0, 3.0))",
TYPE_DOUBLE, 1.0);
4822 TestValue(
"madlib_vector_get(1, madlib_vector(1.0, 2.0, 3.0))",
TYPE_DOUBLE, 2.0);
4823 TestValue(
"madlib_vector_get(2, madlib_vector(1.0, 2.0, 3.0))",
TYPE_DOUBLE, 3.0);
4824 TestIsNull(
"madlib_vector_get(3, madlib_vector(1.0, 2.0, 3.0))",
TYPE_DOUBLE);
4825 TestIsNull(
"madlib_vector_get(-1, madlib_vector(1.0, 2.0, 3.0))",
TYPE_DOUBLE);
4827 "madlib_vector_get(2, madlib_decode_vector(madlib_encode_vector("
4828 "madlib_vector(1.0, 2.0, 3.0))))",
4835 ::testing::InitGoogleTest(&argc, argv);
4842 char* optimizations = getenv(
"EXPR_TEST_ENABLE_OPTIMIZATIONS");
4843 if (optimizations != NULL && strcmp(optimizations,
"true") == 0) {
4844 cout <<
"Running with optimization passes." << endl;
4845 FLAGS_disable_optimization_passes =
false;
4847 cout <<
"Running without optimization passes." << endl;
4848 FLAGS_disable_optimization_passes =
true;
4853 FLAGS_impalad =
"localhost:21000";
4854 FLAGS_abort_on_config_error =
false;
4866 vector<string> options;
4867 options.push_back(
"DISABLE_CODEGEN=1");
4871 cout <<
"Running without codegen" << endl;
4872 int ret = RUN_ALL_TESTS();
4873 if (ret != 0)
return ret;
4875 options.push_back(
"DISABLE_CODEGEN=0");
4878 cout << endl <<
"Running with codegen" << endl;
4879 return RUN_ALL_TESTS();
Status Exec(const std::string &query_string, std::vector< Apache::Hadoop::Hive::FieldSchema > *col_types)
void TestTimestampUnixEpochConversions(int64_t unix_time_at_local_epoch, string local_time_at_unix_epoch)
string default_timestamp_str_
void TestVariableResultTypeIntOps(LeftOp a, RightOp b, const ColumnType &expected_type)
void TestNullOperandFixedResultTypeOps(NonNullOp op, const ColumnType &expected_type)
const std::string GetDetail() const
void TestValidTimestampValue(const string &expr)
string default_decimal_str_
This class handles the Like, Regexp, and Rlike predicates and uses the udf interface.
int128_t abs(const int128_t &x)
void GetValue(const string &expr, const ColumnType &expr_type, void **interpreted_value, bool expect_error=false)
void TestFixedPointComparisons(bool test_boundaries)
DecimalValue< int128_t > Decimal16Value
string GetVersionString(bool compact)
Returns "<program short name> version <GetBuildVersion(compact)>".
void TestNullComparison(const string &op)
void InitCommonRuntime(int argc, char **argv, bool init_jvm, TestInfo::Mode m=TestInfo::NON_TEST)
void TestTimestampValue(const string &expr, const TimestampValue &expected_result, const int64_t tolerance_in_seconds=0)
TimestampValue default_timestamp_val_
The materialized value returned by ExprContext::GetValue().
void * GetValue(TupleRow *row)
char * original_time_zone_
bool HasDateOrTime() const
void TestCharValue(const string &expr, const string &expected_result, const ColumnType &type)
void TestNullOperandsArithmeticOps()
ScopedLocalUnixTimestampConversionOverride()
int main(int argc, char **argv)
string TypeToOdbcString(PrimitiveType t)
void TestNonOkStatus(const string &expr)
string LiteralToString< float, double >(double val)
unordered_map< int, double > FloatValMap
void TestNullComparisons()
void TestStringValue(const string &expr, const string &expected_result)
Status Prepare(RuntimeState *state, const RowDescriptor &row_desc, MemTracker *tracker)
void TestComparison(const string &smaller, const string &larger, bool compare_strings)
string LiteralToString(VAL_TYPE val)
DecimalValue< int64_t > Decimal8Value
map< int, int64_t > IntValMap
Conditional functions that can be expressed as UDFs.
void TestDecimalValue(const string &expr, const T &expected_result, const ColumnType &expected_type)
FloatValMap min_float_values_
void ValidateLayout(const vector< Expr * > &exprs, int expected_byte_size, int expected_var_begin, const map< int, set< int > > &expected_offsets)
string default_string_val_
void TestDecimalComparisons()
void TestFixedPointLimits(const ColumnType &type)
DecimalValue< int32_t > Decimal4Value
void TestBinaryPredicates(const string &value, bool compare_strings)
IntValMap min_int_values_
int GetByteSize() const
Returns the byte size of this type. Returns 0 for variable length types.
string default_string_str_
void SetCatalogInitialized()
#define EXIT_IF_ERROR(stmt)
~ScopedTimeZoneOverride()
This is the superclass of all expr evaluation nodes.
This class is thread-safe.
void TestSingleLiteralConstruction(const ColumnType &type, const T &value, const string &string_val)
void * ConvertValue(const ColumnType &type, const string &value)
void TestFixedResultTypeOps(LeftOp a, RightOp b, const ColumnType &expected_type)
string LiteralToString< float, float >(float val)
BooleanVal TestError(FunctionContext *context)
void TestError(const string &expr)
TODO: Reconsider whether this class needs to exist.
uint64_t Test(T *ht, const ProbeTuple *input, uint64_t num_tuples)
void TestCast(const string &stmt, T val, bool timestamp_out_of_range=false)
Query execution against running impalad process.
DECLARE_bool(abort_on_config_error)
void TestFloatingPointLimits(const ColumnType &type)
void TestFloatingPointComparisons(bool test_boundaries)
static void InitializeLlvm(bool load_backend=false)
void TestStringComparisons()
void setExecOptions(const std::vector< std::string > &exec_options)
Status StartWithClientServers(int beeswax_port, int hs2_port, bool use_statestore)
void TestNullOperandVariableResultTypeIntOps(NonNullOp op, const ColumnType &expected_type)
unordered_map< int, string > default_type_strs_
~ScopedLocalUnixTimestampConversionOverride()
ScopedTimeZoneOverride(string time_zone)
ImpaladQueryExecutor * executor_
execution state of coordinator fragment
string LiteralToString< double, double >(double val)
void TestValue(const string &expr, const ColumnType &expr_type, const T &expected_result)
Status Open(RuntimeState *state)
Must be called after calling Prepare(). Should not be called on clones.
Predicate for evaluating expressions of the form "val [NOT] IN (x1, x2, x3...)".
time_t ToUnixTime() const
void Close(RuntimeState *state)
Closes all FunctionContexts. Must be called on every ExprContext, including clones.
Status FetchResult(RowBatch **batch)
void TestIsNull(const string &expr, const ColumnType &expr_type)