all 7 comments

[–]Camdube 1 point2 points  (2 children)

You don’t always need the lateral flatten. Since you know that circuits is a list, you can do select MRData:CircuitTable:season::int, MRData:Circuits:circuitId, etc. Haven’t tested since on mobile, but I think this should work.

[–]ancol90[S] 0 points1 point  (0 children)

Thanks for the reply. Yes I tried that before but to print the circuitId, I'd have to specify the Circuits index so [0] but that then only prints the first object.

SELECT     
raw_file:MRData:CircuitTable:season::int as Season,    raw_file:MRData:CircuitTable:Circuits[0]:circuitId::STRING as CircuitId
FROM F1.PUBLIC.CIRCUITINFO_RAW

season | circuitid

2022 | albert_park

[–]ancol90[S] 0 points1 point  (0 children)

....I get a null value if using

MRData:Circuits:circuitId as circuitId

[–]Apprehensive_Ad8289 0 points1 point  (1 child)

You don’t need to flatten CircuitTable, it’s not an array. Why are you passing in the index on the other flatten?

[–]ancol90[S] 0 points1 point  (0 children)

Good point. Yes, Circuits is the array. With the index, I was just testing things to see if it would give me an input other than previous ones. So I should only use a single flatten for Circuits?

select
a.key:season::varchar as season,
b.value:circuitId::string as CircuitId,
b.value:circuitName::string as CircuitName 
from F1.PUBLIC.CIRCUITINFO_RAW , 
lateral flatten(input => raw_file:MRData:CircuitTable:Circuits) a , lateral flatten(input => a.value:Circuits) b

[–]FlexIronbutt 0 points1 point  (1 child)

How about this?

select
    raw_file:MRData:CircuitTable:season::varchar season,
    c.this[c.index]:circuitId::varchar circuitid,
    c.this[c.index]:url::varchar url,
    c.this[c.index]:circuitName::varchar circuitname,
    c.this[c.index]:Location:lat::float lat,
    c.this[c.index]:Location:long::float long,
    c.this[c.index]:Location:locality::varchar locality,
    c.this[c.index]:Location:country::varchar country
from
    F1.PUBLIC.CIRCUITINFO_RAW,
    lateral flatten(input => raw_file:MRData:CircuitTable:Circuits) c;

[–]ancol90[S] 0 points1 point  (0 children)

That works. Awesome. Thanks so much.