| 1 | //===--------------------------------------------------------------------===// |
| 2 | // comparison_operators.cpp |
| 3 | // Description: This file contains the implementation of the comparison |
| 4 | // operations == != >= <= > < |
| 5 | //===--------------------------------------------------------------------===// |
| 6 | |
| 7 | #include "duckdb/common/operator/comparison_operators.hpp" |
| 8 | |
| 9 | #include "duckdb/common/vector_operations/binary_executor.hpp" |
| 10 | #include "duckdb/common/vector_operations/vector_operations.hpp" |
| 11 | |
| 12 | using namespace duckdb; |
| 13 | using namespace std; |
| 14 | |
| 15 | struct ComparisonExecutor { |
| 16 | private: |
| 17 | template <class T, class OP, bool IGNORE_NULL = false> |
| 18 | static inline void TemplatedExecute(Vector &left, Vector &right, Vector &result, idx_t count) { |
| 19 | BinaryExecutor::Execute<T, T, bool, OP, IGNORE_NULL>(left, right, result, count); |
| 20 | } |
| 21 | |
| 22 | public: |
| 23 | template <class OP> static inline void Execute(Vector &left, Vector &right, Vector &result, idx_t count) { |
| 24 | assert(left.type == right.type && result.type == TypeId::BOOL); |
| 25 | // the inplace loops take the result as the last parameter |
| 26 | switch (left.type) { |
| 27 | case TypeId::BOOL: |
| 28 | case TypeId::INT8: |
| 29 | TemplatedExecute<int8_t, OP>(left, right, result, count); |
| 30 | break; |
| 31 | case TypeId::INT16: |
| 32 | TemplatedExecute<int16_t, OP>(left, right, result, count); |
| 33 | break; |
| 34 | case TypeId::INT32: |
| 35 | TemplatedExecute<int32_t, OP>(left, right, result, count); |
| 36 | break; |
| 37 | case TypeId::INT64: |
| 38 | TemplatedExecute<int64_t, OP>(left, right, result, count); |
| 39 | break; |
| 40 | case TypeId::POINTER: |
| 41 | TemplatedExecute<uintptr_t, OP>(left, right, result, count); |
| 42 | break; |
| 43 | case TypeId::FLOAT: |
| 44 | TemplatedExecute<float, OP>(left, right, result, count); |
| 45 | break; |
| 46 | case TypeId::DOUBLE: |
| 47 | TemplatedExecute<double, OP>(left, right, result, count); |
| 48 | break; |
| 49 | case TypeId::VARCHAR: |
| 50 | TemplatedExecute<string_t, OP, true>(left, right, result, count); |
| 51 | break; |
| 52 | default: |
| 53 | throw InvalidTypeException(left.type, "Invalid type for comparison" ); |
| 54 | } |
| 55 | } |
| 56 | }; |
| 57 | |
| 58 | void VectorOperations::Equals(Vector &left, Vector &right, Vector &result, idx_t count) { |
| 59 | ComparisonExecutor::Execute<duckdb::Equals>(left, right, result, count); |
| 60 | } |
| 61 | |
| 62 | void VectorOperations::NotEquals(Vector &left, Vector &right, Vector &result, idx_t count) { |
| 63 | ComparisonExecutor::Execute<duckdb::NotEquals>(left, right, result, count); |
| 64 | } |
| 65 | |
| 66 | void VectorOperations::GreaterThanEquals(Vector &left, Vector &right, Vector &result, idx_t count) { |
| 67 | ComparisonExecutor::Execute<duckdb::GreaterThanEquals>(left, right, result, count); |
| 68 | } |
| 69 | |
| 70 | void VectorOperations::LessThanEquals(Vector &left, Vector &right, Vector &result, idx_t count) { |
| 71 | ComparisonExecutor::Execute<duckdb::LessThanEquals>(left, right, result, count); |
| 72 | } |
| 73 | |
| 74 | void VectorOperations::GreaterThan(Vector &left, Vector &right, Vector &result, idx_t count) { |
| 75 | ComparisonExecutor::Execute<duckdb::GreaterThan>(left, right, result, count); |
| 76 | } |
| 77 | |
| 78 | void VectorOperations::LessThan(Vector &left, Vector &right, Vector &result, idx_t count) { |
| 79 | ComparisonExecutor::Execute<duckdb::LessThan>(left, right, result, count); |
| 80 | } |
| 81 | |