|
| 1 | +/** |
| 2 | + * The modules in this file automate the schema mapping of JSON or JSONL sources |
| 3 | + * that are configured as part of the json_source_config module. |
| 4 | + * |
| 5 | + * To use this framework, simply populate the json_source_config relation for |
| 6 | + * some *source* with the string values of keys for any one or more of the |
| 7 | + * following types: (string, int, decimal, and object). |
| 8 | + */ |
| 9 | + |
| 10 | +def JsonSourceConfigKey(k) { json_source_config(k, x...) from x... } |
| 11 | + |
| 12 | +def json_source:value[src in JsonSourceConfigKey] = source_catalog[src, _, :value] |
| 13 | +def json_source:child[src in JsonSourceConfigKey] = source_catalog[src, _, :child] |
| 14 | +def json_source:root[src in JsonSourceConfigKey] = source_catalog[src, _, :root] |
| 15 | +def json_source:array[src in JsonSourceConfigKey] = source_catalog[src, _, :array] |
| 16 | + |
| 17 | +def json_source:value[src in JsonSourceConfigKey] = simple_source_catalog[src, :value] |
| 18 | +def json_source:child[src in JsonSourceConfigKey] = simple_source_catalog[src, :child] |
| 19 | +def json_source:root[src in JsonSourceConfigKey] = simple_source_catalog[src, :root] |
| 20 | +def json_source:array[src in JsonSourceConfigKey] = simple_source_catalog[src, :array] |
| 21 | + |
| 22 | +/** |
| 23 | + * [REKS] Note that json_source, json_hash, json_name_sym, and json_schema cannot |
| 24 | + * be further consolidated into a container module because of limits on the |
| 25 | + * use of metafication (i.e., the #(...) operator) inside recursive |
| 26 | + * definitions. |
| 27 | + */ |
| 28 | +def json_hash(src, t, h, s) = |
| 29 | + murmurhash3f(s, x) and |
| 30 | + h = uint128_hash_value_convert[x] and |
| 31 | + json_source_config(src, t, s) |
| 32 | + from x |
| 33 | + |
| 34 | +def json_name_sym[src, x] = #(json_hash[src, _, x]) |
| 35 | + |
| 36 | +module json_schema |
| 37 | + |
| 38 | + def parent(src, y, x, z) { json_source:child(src, x, y, z) } |
| 39 | + |
| 40 | + def value(src, r, o, val) { |
| 41 | + parent(src, r, o, t) and |
| 42 | + json_hash(src, :string, r, _) and |
| 43 | + json_source:value(src, t, val) and |
| 44 | + String(val) |
| 45 | + from t |
| 46 | + } |
| 47 | + |
| 48 | + def value(src, r, o, v) { |
| 49 | + parent(src, r, o, t) and |
| 50 | + json_hash(src, :decimal, r, _) and |
| 51 | + json_source:value(src, t, v) and |
| 52 | + Float(v) |
| 53 | + from t |
| 54 | + } |
| 55 | + |
| 56 | + def value(src, r, o, v) { |
| 57 | + parent(src, r, o, t) and |
| 58 | + json_hash(src, :int, r, _) and |
| 59 | + json_source:value(src, t, v) and |
| 60 | + Int(v) |
| 61 | + from t |
| 62 | + } |
| 63 | + |
| 64 | +end |
0 commit comments