blob: 4150bc7e3f27eb86f78e61df1c27a53e22d0f11e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
use plato;
$input = select * from AS_TABLE([<|a:"foo",b:"123"|>]);
$mapping = select {"a":"String", "b":"Int32"} from Input limit 1;
$transformer = ($type)->{
$t = EvaluateType(ParseTypeHandle($type));
return ($value)->{ return cast($value as $t); };
};
$converter = ($row)->{
return EvaluateCode(LambdaCode(($rowCode)->{
return FuncCode("AsStruct", ListMap(StructMembers($row), ($name)->{
return ListCode(
AtomCode($name),
FuncCode("Apply", QuoteCode($transformer(Unwrap($mapping[$name]))), FuncCode("Member", $rowCode, AtomCode($name)))
);
}));
}))($row);
};
select * from (select $converter(TableRow()) from $input) flatten columns;
|