aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/udfs/common/python/python3_small/test/cases/CustomYsonConverter.sql
blob: 43dd00cb3df2839b4975b702125bb924bc8641ab (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
--sanitizer ignore memory
/* syntax version 1 */
$script = @@
import json

def yloads(z):
  return json.loads(str(z, 'latin-1').replace("=",":"))

def ydumps(z):
  return bytes(json.dumps(z).replace(":","="), 'latin-1')

def f(s):
    return (s.get("abc",0),s)

f._yql_convert_yson = (yloads,ydumps)
@@;

$udf = Python3::f(Callable<(Yson?)->Tuple<Int64, Yson?>>, $script);

SELECT $udf(cast(@@{"abc"=1}@@ as yson));