summaryrefslogtreecommitdiffstats
path: root/yql/essentials/tests/sql/suites/expr/yql-21292.yql
blob: c6c5fe3b0099202633c8e0eea309fefabe682319 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
PRAGMA config.flags("TransformCycleDetector","10");

$variant_to_struct = ($v) -> {
    $make_visitor = ($fname) -> (
        ($nothing_struct) -> (
            ($i) -> (StructUnion(SpreadMembers([($fname, Just($i))], [$fname]), $nothing_struct))
        )
    );
    $nothing_struct = StaticMap(
        InstanceOf(VariantUnderlyingType(TypeOf($v))),
        ($i) -> (Nothing(OptionalType(TypeOf($i))))
    );
    RETURN EvaluateCode(
        LambdaCode(
            ($v_code) -> (FuncCode('Visit', $v_code, ListFlatMap(
                StructMembers(InstanceOf(VariantUnderlyingType(TypeOf($v)))),
                ($fname) -> ([AtomCode($fname), QuoteCode($make_visitor($fname)($nothing_struct))])
            )))
        )
    )($v);
};
$struct = $variant_to_struct(Variant(1, 'a', Variant<a: Int32>));
SELECT Unwrap(CAST(FormatType(TypeOf(GatherMembers($struct))) AS Utf8)) AS X;