|
18 | 18 | #include "presto_cpp/presto_protocol/core/presto_protocol_core.h"
|
19 | 19 | #include "velox/core/Expressions.h"
|
20 | 20 | #include "velox/type/Type.h"
|
| 21 | +#include "velox/functions/prestosql/types/JsonType.h" |
21 | 22 |
|
22 | 23 | using namespace facebook::presto;
|
23 | 24 | using namespace facebook::velox;
|
24 | 25 | using namespace facebook::velox::core;
|
25 | 26 |
|
26 | 27 | class RowExpressionTest : public ::testing::Test {
|
27 | 28 | public:
|
| 29 | + RowExpressionTest(){ |
| 30 | + registerJsonType(); |
| 31 | + } |
28 | 32 | static void SetUpTestCase() {
|
29 | 33 | memory::MemoryManager::testingSetInstance({});
|
30 | 34 | }
|
@@ -626,6 +630,20 @@ TEST_F(RowExpressionTest, castToVarchar) {
|
626 | 630 | ASSERT_TRUE(returnExpr->nullOnFailure());
|
627 | 631 | ASSERT_EQ(returnExpr->type()->toString(), "VARCHAR");
|
628 | 632 | }
|
| 633 | + // CAST(json AS varchar(3)) |
| 634 | + { |
| 635 | + std::shared_ptr<protocol::CallExpression> p = |
| 636 | + json::parse(makeCastToVarchar(false, "json", "varchar(3)")); |
| 637 | + auto expr = converter_->toVeloxExpr(p); |
| 638 | + auto returnExpr = std::dynamic_pointer_cast<const CallTypedExpr>(expr); |
| 639 | + ASSERT_NE(returnExpr, nullptr); |
| 640 | + ASSERT_EQ(returnExpr->name(), "presto.default.substr"); |
| 641 | + |
| 642 | + auto returnArg = std::dynamic_pointer_cast<const ConstantTypedExpr>( |
| 643 | + returnExpr->inputs()[2]); |
| 644 | + ASSERT_EQ(returnArg->type()->toString(), "BIGINT"); |
| 645 | + ASSERT_EQ(returnArg->value().toJson(returnArg->type()), "3"); |
| 646 | + } |
629 | 647 | }
|
630 | 648 |
|
631 | 649 | TEST_F(RowExpressionTest, special) {
|
|
0 commit comments