| 65 | bool is_null() const { return is_null_; } |
| 66 | |
| 67 | std::string ToString() const override { |
| 68 | std::stringstream ss; |
| 69 | if (return_type_ == NULLPTR) { |
| 70 | ss << "(const untyped) " << gandiva::ToString(holder_); |
| 71 | return ss.str(); |
| 72 | } |
| 73 | |
| 74 | ss << "(const " << return_type()->ToString() << ") "; |
| 75 | if (is_null()) { |
| 76 | ss << std::string("null"); |
| 77 | return ss.str(); |
| 78 | } |
| 79 | |
| 80 | if (return_type()->id() == arrow::Type::STRING || |
| 81 | return_type()->id() == arrow::Type::LARGE_STRING) { |
| 82 | ss << "'" << gandiva::ToString(holder_) << "'"; |
| 83 | } else { |
| 84 | ss << gandiva::ToString(holder_); |
| 85 | } |
| 86 | // The default formatter prints in decimal can cause a loss in precision. so, |
| 87 | // print in hex. Can't use hexfloat since gcc 4.9 doesn't support it. |
| 88 | if (return_type()->id() == arrow::Type::DOUBLE) { |
| 89 | double dvalue = std::get<double>(holder_); |
| 90 | uint64_t bits; |
| 91 | memcpy(&bits, &dvalue, sizeof(bits)); |
| 92 | ss << " raw(" << std::hex << bits << ")"; |
| 93 | } else if (return_type()->id() == arrow::Type::FLOAT) { |
| 94 | float fvalue = std::get<float>(holder_); |
| 95 | uint32_t bits; |
| 96 | memcpy(&bits, &fvalue, sizeof(bits)); |
| 97 | ss << " raw(" << std::hex << bits << ")"; |
| 98 | } |
| 99 | return ss.str(); |
| 100 | } |
| 101 | |
| 102 | private: |
| 103 | LiteralHolder holder_; |