20 #define BINARY_OP_FN(NAME, TYPE, OP) \
21 TYPE Operators::NAME##_##TYPE##_##TYPE(\
22 FunctionContext* c, const TYPE& v1, const TYPE& v2) {\
23 if (v1.is_null || v2.is_null) return TYPE::null();\
24 return TYPE(v1.val OP v2.val);\
27 #define BINARY_OP_CHECK_ZERO_FN(NAME, TYPE, OP) \
28 TYPE Operators::NAME##_##TYPE##_##TYPE(\
29 FunctionContext* c, const TYPE& v1, const TYPE& v2) {\
30 if (v1.is_null || v2.is_null || v2.val == 0) return TYPE::null();\
31 return TYPE(v1.val OP v2.val);\
34 #define BITNOT_FN(TYPE)\
35 TYPE Operators::Bitnot_##TYPE(FunctionContext* c, const TYPE& v) {\
36 if (v.is_null) return TYPE::null();\
40 #define BINARY_PREDICATE_NUMERIC_FN(NAME, TYPE, OP) \
41 BooleanVal Operators::NAME##_##TYPE##_##TYPE(\
42 FunctionContext* c, const TYPE& v1, const TYPE& v2) {\
43 if (v1.is_null || v2.is_null) return BooleanVal::null();\
44 return BooleanVal(v1.val OP v2.val);\
47 #define BINARY_PREDICATE_NONNUMERIC_FN(NAME, TYPE, IMPALA_TYPE, OP) \
48 BooleanVal Operators::NAME##_##TYPE##_##TYPE(\
49 FunctionContext* c, const TYPE& v1, const TYPE& v2) {\
50 if (v1.is_null || v2.is_null) return BooleanVal::null();\
51 IMPALA_TYPE iv1 = IMPALA_TYPE::From##TYPE(v1);\
52 IMPALA_TYPE iv2 = IMPALA_TYPE::From##TYPE(v2);\
53 return BooleanVal(iv1 OP iv2);\
56 #define BINARY_PREDICATE_CHAR(NAME, OP) \
57 BooleanVal Operators::NAME##_Char_Char(\
58 FunctionContext* c, const StringVal& v1, const StringVal& v2) {\
59 if (v1.is_null || v2.is_null) return BooleanVal::null();\
60 const ColumnType& v1_type = AnyValUtil::TypeDescToColumnType(*c->GetArgType(0));\
61 const ColumnType& v2_type = AnyValUtil::TypeDescToColumnType(*c->GetArgType(1));\
62 StringValue iv1 = StringValue::FromStringVal(v1);\
63 StringValue iv2 = StringValue::FromStringVal(v2);\
64 iv1.len = StringValue::UnpaddedCharLength(iv1.ptr, v1_type.len);\
65 iv2.len = StringValue::UnpaddedCharLength(iv2.ptr, v2_type.len);\
66 return BooleanVal(iv1 OP iv2);\
69 #define BINARY_OP_NUMERIC_TYPES(NAME, OP) \
70 BINARY_OP_FN(NAME, TinyIntVal, OP); \
71 BINARY_OP_FN(NAME, SmallIntVal, OP);\
72 BINARY_OP_FN(NAME, IntVal, OP);\
73 BINARY_OP_FN(NAME, BigIntVal, OP);\
74 BINARY_OP_FN(NAME, FloatVal, OP);\
75 BINARY_OP_FN(NAME, DoubleVal, OP);
77 #define BINARY_OP_INT_TYPES(NAME, OP) \
78 BINARY_OP_FN(NAME, TinyIntVal, OP); \
79 BINARY_OP_FN(NAME, SmallIntVal, OP);\
80 BINARY_OP_FN(NAME, IntVal, OP);\
81 BINARY_OP_FN(NAME, BigIntVal, OP);\
83 #define BINARY_OP_CHECK_ZERO_INT_TYPES(NAME, OP) \
84 BINARY_OP_CHECK_ZERO_FN(NAME, TinyIntVal, OP); \
85 BINARY_OP_CHECK_ZERO_FN(NAME, SmallIntVal, OP);\
86 BINARY_OP_CHECK_ZERO_FN(NAME, IntVal, OP);\
87 BINARY_OP_CHECK_ZERO_FN(NAME, BigIntVal, OP);\
89 #define BINARY_PREDICATE_ALL_TYPES(NAME, OP) \
90 BINARY_PREDICATE_NUMERIC_FN(NAME, BooleanVal, OP); \
91 BINARY_PREDICATE_NUMERIC_FN(NAME, TinyIntVal, OP); \
92 BINARY_PREDICATE_NUMERIC_FN(NAME, SmallIntVal, OP);\
93 BINARY_PREDICATE_NUMERIC_FN(NAME, IntVal, OP);\
94 BINARY_PREDICATE_NUMERIC_FN(NAME, BigIntVal, OP);\
95 BINARY_PREDICATE_NUMERIC_FN(NAME, FloatVal, OP);\
96 BINARY_PREDICATE_NUMERIC_FN(NAME, DoubleVal, OP);\
97 BINARY_PREDICATE_NONNUMERIC_FN(NAME, StringVal, StringValue, OP);\
98 BINARY_PREDICATE_NONNUMERIC_FN(NAME, TimestampVal, TimestampValue, OP);\
99 BINARY_PREDICATE_CHAR(NAME, OP);
BINARY_OP_INT_TYPES(Bitand,&)
BINARY_PREDICATE_ALL_TYPES(Eq,==)
BINARY_OP_NUMERIC_TYPES(Add,+)
BINARY_OP_CHECK_ZERO_INT_TYPES(Int_divide,/)
BINARY_OP_FN(Divide, DoubleVal,/)