aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/tests/sql/suites/action/runtime_apply_quoted_code.sql
blob: 8a4a92b35325277c3bbfd818822ab2d77b7c43ba (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/* syntax version 1 */
/* postgres can not */
$func = ($x)->{
    return $x == 1;
};

$structApply = ($strValue, $f)->{
    $code = EvaluateCode(LambdaCode(($strCode)->{
        $members = StructTypeComponents(TypeHandle(TypeOf($strValue)));
       
        return Yql::Fold($members, ReprCode(false), ($item, $state)->{
            $member = FuncCode("Member", $strCode, AtomCode($item.Name));
            $apply = FuncCode("Apply", QuoteCode($f), $member);
            return FuncCode("Or", $state, $apply);
        });
    }));
    return $code($strValue);
};

select $structApply(AsStruct(1 as a,2 as b,3 as c), $func);
select $structApply(AsStruct(4 as a,2 as b,3 as c), $func);