@@ -1574,3 +1574,84 @@ func TestVariantBuilderUnmarshalJSON(t *testing.T) {
15741574 assert .Equal (t , int8 (5 ), innerVal2 .Value ())
15751575 })
15761576}
1577+
1578+ func TestNewSimpleShreddedVariantType (t * testing.T ) {
1579+ assert .True (t , arrow .TypeEqual (extensions .NewDefaultVariantType (),
1580+ extensions .NewShreddedVariantType (nil )))
1581+
1582+ vt := extensions .NewShreddedVariantType (arrow .PrimitiveTypes .Float32 )
1583+ s := arrow .StructOf (
1584+ arrow.Field {Name : "metadata" , Type : arrow .BinaryTypes .Binary },
1585+ arrow.Field {Name : "value" , Type : arrow .BinaryTypes .Binary , Nullable : true },
1586+ arrow.Field {Name : "typed_value" , Type : arrow .PrimitiveTypes .Float32 , Nullable : true })
1587+
1588+ assert .Truef (t , arrow .TypeEqual (vt .Storage , s ), "expected %s, got %s" , s , vt .Storage )
1589+ }
1590+
1591+ func TestNewShreddedVariantType (t * testing.T ) {
1592+ vt := extensions .NewShreddedVariantType (arrow .StructOf (arrow.Field {
1593+ Name : "event_type" ,
1594+ Type : arrow .BinaryTypes .String ,
1595+ }, arrow.Field {
1596+ Name : "event_ts" ,
1597+ Type : arrow .FixedWidthTypes .Timestamp_us ,
1598+ }))
1599+
1600+ assert .NotNil (t , vt )
1601+ s := arrow .StructOf (
1602+ arrow.Field {Name : "metadata" , Type : arrow .BinaryTypes .Binary },
1603+ arrow.Field {Name : "value" , Type : arrow .BinaryTypes .Binary , Nullable : true },
1604+ arrow.Field {Name : "typed_value" , Type : arrow .StructOf (
1605+ arrow.Field {Name : "event_type" , Type : arrow .StructOf (
1606+ arrow.Field {Name : "value" , Type : arrow .BinaryTypes .Binary , Nullable : true },
1607+ arrow.Field {Name : "typed_value" , Type : arrow .BinaryTypes .String , Nullable : true },
1608+ )},
1609+ arrow.Field {Name : "event_ts" , Type : arrow .StructOf (
1610+ arrow.Field {Name : "value" , Type : arrow .BinaryTypes .Binary , Nullable : true },
1611+ arrow.Field {Name : "typed_value" , Type : arrow .FixedWidthTypes .Timestamp_us , Nullable : true },
1612+ )},
1613+ ), Nullable : true })
1614+
1615+ assert .Truef (t , arrow .TypeEqual (vt .Storage , s ), "expected %s, got %s" , s , vt .Storage )
1616+ }
1617+
1618+ func TestShreddedVariantNested (t * testing.T ) {
1619+ vt := extensions .NewShreddedVariantType (arrow .StructOf (
1620+ arrow.Field {Name : "strval" , Type : arrow .BinaryTypes .String },
1621+ arrow.Field {Name : "bool" , Type : arrow .FixedWidthTypes .Boolean },
1622+ arrow.Field {Name : "location" , Type : arrow .ListOf (arrow .StructOf (
1623+ arrow.Field {Name : "latitude" , Type : arrow .PrimitiveTypes .Float64 },
1624+ arrow.Field {Name : "longitude" , Type : arrow .PrimitiveTypes .Float32 },
1625+ ))}))
1626+
1627+ s := arrow .StructOf (
1628+ arrow.Field {Name : "metadata" , Type : arrow .BinaryTypes .Binary },
1629+ arrow.Field {Name : "value" , Type : arrow .BinaryTypes .Binary , Nullable : true },
1630+ arrow.Field {Name : "typed_value" , Type : arrow .StructOf (
1631+ arrow.Field {Name : "strval" , Type : arrow .StructOf (
1632+ arrow.Field {Name : "value" , Type : arrow .BinaryTypes .Binary , Nullable : true },
1633+ arrow.Field {Name : "typed_value" , Type : arrow .BinaryTypes .String , Nullable : true },
1634+ )},
1635+ arrow.Field {Name : "bool" , Type : arrow .StructOf (
1636+ arrow.Field {Name : "value" , Type : arrow .BinaryTypes .Binary , Nullable : true },
1637+ arrow.Field {Name : "typed_value" , Type : arrow .FixedWidthTypes .Boolean , Nullable : true },
1638+ )},
1639+ arrow.Field {Name : "location" , Type : arrow .StructOf (
1640+ arrow.Field {Name : "value" , Type : arrow .BinaryTypes .Binary , Nullable : true },
1641+ arrow.Field {Name : "typed_value" , Type : arrow .ListOfNonNullable (arrow .StructOf (
1642+ arrow.Field {Name : "value" , Type : arrow .BinaryTypes .Binary , Nullable : true },
1643+ arrow.Field {Name : "typed_value" , Type : arrow .StructOf (
1644+ arrow.Field {Name : "latitude" , Type : arrow .StructOf (
1645+ arrow.Field {Name : "value" , Type : arrow .BinaryTypes .Binary , Nullable : true },
1646+ arrow.Field {Name : "typed_value" , Type : arrow .PrimitiveTypes .Float64 , Nullable : true },
1647+ )},
1648+ arrow.Field {Name : "longitude" , Type : arrow .StructOf (
1649+ arrow.Field {Name : "value" , Type : arrow .BinaryTypes .Binary , Nullable : true },
1650+ arrow.Field {Name : "typed_value" , Type : arrow .PrimitiveTypes .Float32 , Nullable : true },
1651+ )},
1652+ ), Nullable : true },
1653+ )), Nullable : true })},
1654+ ), Nullable : true })
1655+
1656+ assert .Truef (t , arrow .TypeEqual (vt .Storage , s ), "expected %s, got %s" , s , vt .Storage )
1657+ }
0 commit comments