| 30 | }; |
| 31 | |
| 32 | TEST_F(VariantFunctionTest, basic) { |
| 33 | // Test parse_json — returns a VariantVector, not SimpleVector<VariantValue>, |
| 34 | // so we evaluate directly instead of using evaluateOnce<VariantValue>. |
| 35 | auto input = makeRowVector( |
| 36 | {makeNullableFlatVector<StringView>({StringView("{\"a\":1}")})}); |
| 37 | auto exprSet = compileExpression("parse_json(c0)", asRowType(input->type())); |
| 38 | auto resultVec = evaluate(*exprSet, input); |
| 39 | |
| 40 | ASSERT_EQ(resultVec->encoding(), VectorEncoding::Simple::VARIANT); |
| 41 | auto* variantVec = resultVec->as<VariantVector>(); |
| 42 | ASSERT_NE(variantVec, nullptr); |
| 43 | ASSERT_FALSE(variantVec->isNullAt(0)); |
| 44 | |
| 45 | auto variant = variantVec->valueAt(0); |
| 46 | // Now it's binary, so we don't expect it to match raw JSON string |
| 47 | EXPECT_NE( |
| 48 | std::string(variant.value.data(), variant.value.size()), "{\"a\":1}"); |
| 49 | EXPECT_FALSE(variant.metadata.empty()); |
| 50 | |
| 51 | // Test variant_get |
| 52 | auto extracted = evaluateOnce<std::string>( |
| 53 | "variant_get(parse_json(c0), '$.a')", |
| 54 | std::optional<std::string>("{\"a\":1}")); |
| 55 | ASSERT_TRUE(extracted.has_value()); |
| 56 | // Now it should extract the value '1' correctly from binary |
| 57 | EXPECT_EQ(extracted.value(), "1"); |
| 58 | } |
| 59 | |
| 60 | TEST_F(VariantFunctionTest, nested) { |
| 61 | // Test nested object |
nothing calls this directly
no test coverage detected