CustomYsonConverter.sql 416 B

1234567891011121314151617181920
  1. --sanitizer ignore memory
  2. /* syntax version 1 */
  3. $script = @@
  4. import json
  5. def yloads(z):
  6. return json.loads(str(z, 'latin-1').replace("=",":"))
  7. def ydumps(z):
  8. return bytes(json.dumps(z).replace(":","="), 'latin-1')
  9. def f(s):
  10. return (s.get("abc",0),s)
  11. f._yql_convert_yson = (yloads,ydumps)
  12. @@;
  13. $udf = Python3::f(Callable<(Yson?)->Tuple<Int64, Yson?>>, $script);
  14. SELECT $udf(cast(@@{"abc"=1}@@ as yson));