I have a situation to create nested-repeated table by joining 2 normal tables in BigQuery. Here is the context,
I have the input table data contains looks like this: In the below data, v_no is one col, and crit is another col which contains more data in it. cirt col should be splitted for each 6 chars (I dit it in my query below).
v_no crit
v1 EA1 TEMP MR
v2 DRA KM
Another input table contains the data like this:
c_code o_code
TEMP 720
MR D45
EA1 E88
KM 282
DRA 121
Now the need is I need to join these 2 tables and create a nested-repeated table. The expected output should be like this.
v1 EA1 E88
TEMP 720
MR D45
v2 DRA 121
KM 282
I did for some part in creating nested table from table1 by just splitting each 6 chars. Then after I am not sure how to join with other table.
CREATE TABLE
`project.db.table1`
CLUSTER BY
v_no AS
SELECT
v_no,
ARRAY_AGG(STRUCT(crit)) as codes
FROM
`project.db.table2`,unnest(regexp_extract_all(crit, r'.{1,6}')) crit
GROUP BY
v_no
Can anyone please suggest how to achieve it in single query in BigQuery? Generic Query please :-)
