MCPcopy Create free account
hub / github.com/bytedance/bolt / TEST_F

Function TEST_F

bolt/functions/sparksql/tests/VariantFunctionTest.cpp:32–58  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30};
31
32TEST_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
60TEST_F(VariantFunctionTest, nested) {
61 // Test nested object

Callers

nothing calls this directly

Calls 13

compileExpressionFunction · 0.85
asRowTypeFunction · 0.85
evaluateFunction · 0.85
has_valueMethod · 0.80
StringViewClass · 0.50
typeMethod · 0.45
encodingMethod · 0.45
isNullAtMethod · 0.45
valueAtMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected