Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
More tests
  • Loading branch information
cashmand committed Aug 15, 2025
commit 012463cddaa08305013f88d6f46e24a719196a44
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ class VariantWriteShreddingSuite extends SparkFunSuite with ExpressionEvalHelper
testWithSchema(obj, t, Row(obj.getMetadata, untypedValue(obj), null))
}

testWithSchema(obj, VariantType, Row(obj.getMetadata, untypedValue(obj)))

// Happy path
testWithSchema(obj, StructType.fromDDL("a int, b string"),
Row(obj.getMetadata, null, Row(Row(null, 1), Row(null, "hello"))))
Expand All @@ -228,6 +230,11 @@ class VariantWriteShreddingSuite extends SparkFunSuite with ExpressionEvalHelper
testWithSchema(obj, ArrayType(StructType.fromDDL("a int, b string")),
Row(obj.getMetadata, untypedValue(obj), null))

// Shred with no typed_value in field schema
testWithSchema(obj, StructType.fromDDL("a variant, b variant"),
Row(obj.getMetadata, null,
Row(Row(untypedValue("1")), Row(untypedValue("\"hello\"")))))

// Similar to the case above where "b" was not in the shredding schema, but with the unshredded
// value being an object. Check that the copied value has correct dictionary IDs.
val obj2 = parseJson("""{"a": 1, "b": {"c": "hello"}}""")
Expand All @@ -248,6 +255,9 @@ class VariantWriteShreddingSuite extends SparkFunSuite with ExpressionEvalHelper
StructType.fromDDL("a int, b string")).foreach { t =>
testWithSchema(arr, t, Row(arr.getMetadata, untypedValue(arr), null))
}

testWithSchema(arr, VariantType, Row(arr.getMetadata, untypedValue(arr)))

// First element is shredded
testWithSchema(arr, ArrayType(StructType.fromDDL("a int, b string")),
Row(arr.getMetadata, null, Array(
Expand All @@ -272,6 +282,15 @@ class VariantWriteShreddingSuite extends SparkFunSuite with ExpressionEvalHelper
Row(null, 2),
Row(null, 3)
)))

// No typed_value in element schema
testWithSchema(arr, ArrayType(VariantType),
Row(arr.getMetadata, null, Array(
Row(untypedValue("""{"a": 1, "b": "hello"}""")),
Row(untypedValue("2")),
Row(untypedValue("null")),
Row(untypedValue("4"))
)))
}

}