add fiels to feel out using path to extract
This commit is contained in:
parent
809df3ef52
commit
8728809ddc
52
ideas/sql_from_srce_definition.sql
Normal file
52
ideas/sql_from_srce_definition.sql
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
WITH s AS (
|
||||||
|
select
|
||||||
|
$${
|
||||||
|
"name":"DMAPI",
|
||||||
|
"source":"client_file",
|
||||||
|
"loading_function":"csv",
|
||||||
|
"constraint":[
|
||||||
|
"{doc}"
|
||||||
|
],
|
||||||
|
"schema_type":"JSONB_POPULATE",
|
||||||
|
"table_schema":[
|
||||||
|
{
|
||||||
|
"path":"{doc,origin_addresses,0}",
|
||||||
|
"type":"text",
|
||||||
|
"column_name":"origin_address"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path":"{doc,destination_addresses,0}",
|
||||||
|
"type":"text",
|
||||||
|
"column_name":"origin_address"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path":"{doc,status}",
|
||||||
|
"type":"text",
|
||||||
|
"column_name":"status"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path":"{doc,rows,0,elements,0,distance,value}",
|
||||||
|
"type":"numeric",
|
||||||
|
"column_name":"distance"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path":"{doc,rows,0,elements,0,duration,value}",
|
||||||
|
"type":"numeric",
|
||||||
|
"column_name":"duration"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}$$::jsonb->'table_schema' defn
|
||||||
|
)
|
||||||
|
,ext AS (
|
||||||
|
SELECT
|
||||||
|
ae.v->>'path' path
|
||||||
|
,ae.v->>'type' dtype
|
||||||
|
,ae.v->>'column_name' column_name
|
||||||
|
FROM
|
||||||
|
s
|
||||||
|
LEFT JOIN LATERAL JSONB_ARRAY_ELEMENTS(s.defn) ae(v) ON TRUE
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
'SELECT '||string_agg('(rec#>>('''||path||'''::text[]))::'||dtype||' AS '||column_name,', ')||' FROM tps.trans WHERE srce = ''DMAPI'''
|
||||||
|
FROM
|
||||||
|
ext
|
44
perf_test/parse_jsonb_with_path.sql
Normal file
44
perf_test/parse_jsonb_with_path.sql
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
create temp table x as (
|
||||||
|
select
|
||||||
|
t.rec
|
||||||
|
from
|
||||||
|
generate_series(1,1000000,1) s
|
||||||
|
inner join tps.trans t on
|
||||||
|
srce = 'DMAPI'
|
||||||
|
) with data;
|
||||||
|
|
||||||
|
|
||||||
|
create temp table x2 as (
|
||||||
|
select
|
||||||
|
(
|
||||||
|
rec #>>(
|
||||||
|
'{doc,origin_addresses,0}'::text[]
|
||||||
|
)
|
||||||
|
)::text as origin_address,
|
||||||
|
(
|
||||||
|
rec #>>(
|
||||||
|
'{doc,destination_addresses,0}'::text[]
|
||||||
|
)
|
||||||
|
)::text as desatination_address,
|
||||||
|
(
|
||||||
|
rec #>>(
|
||||||
|
'{doc,status}'::text[]
|
||||||
|
)
|
||||||
|
)::text as status,
|
||||||
|
(
|
||||||
|
rec #>>(
|
||||||
|
'{doc,rows,0,elements,0,distance,value}'::text[]
|
||||||
|
)
|
||||||
|
)::numeric as distance,
|
||||||
|
(
|
||||||
|
rec #>>(
|
||||||
|
'{doc,rows,0,elements,0,duration,value}'::text[]
|
||||||
|
)
|
||||||
|
)::numeric as duration
|
||||||
|
from
|
||||||
|
x
|
||||||
|
) with data;
|
||||||
|
|
||||||
|
|
||||||
|
drop table x;
|
||||||
|
drop table x2;
|
Loading…
Reference in New Issue
Block a user