у меня есть этот запрос на Афине
trip.id as tripid
, segment.id as segmentid
, segment.distance as mileage
, segment.maxspeed as maxspeed
, segment.duration as duration
, segment.roadtype as roadtype
, segment.timeslotdata as timeslots
, extract( week from (from_unixtime(trip.referencedate /1000))) as weekyear
, extract( year from (from_unixtime(trip.referencedate /1000))) as year
, extract( month from (from_unixtime(trip.referencedate/1000))) as month
, unn.firstpositionlat
, unn.firstpositionlong
from
trip
, UNNEST(segments) as t(segment)
left join
(
select
position.latitude as firstpositionlat
, position.longitude as firstpositionlong
, position.id as id
from
trip
, UNNEST(segments) as t(segment)
, UNNEST(segment.positions) as t(position)
where
anno = 2021
and mese = 01
and giorno = 01
and tscid = 'XXX'
)
unn
on
segment.startpositionid = unn.id
where
anno = 2021
and mese = 01
and giorno = 01
and tscid = 'XXX'
проблема в том, что я не могу присоединиться из-за ошибки в строке 16:19, и у меня есть эта ошибка
SYNTAX_ERROR: line 16:19: Column 'segments' cannot be resolved
не могу понять где проблема. Без оператора НА это работает хорошо.
заранее спасибо
Presto (основной механизм SQL для Athena) поддерживает UNNEST
только справа от CROSS JOIN
. Например:
-- sample data
WITH dataset (id, animals) AS (
values (1, ARRAY['dog', 'cat', 'bird']),
(2, ARRAY['cow', 'pig'])
)
-- query
SELECT id, animals, a
FROM dataset
CROSS JOIN UNNEST(animals) AS t (a);
Выход:
я бы | животные | а |
---|---|---|
1 | [собака, кошка, птица] | собака |
1 | [собака, кошка, птица] | Кот |
1 | [собака, кошка, птица] | птица |
2 | [корова, свинья] | корова |
2 | [корова, свинья] | свинья |
Похоже, что сокращенная запись (from trip, UNNEST(segments) as t(segment)
) работает некорректно, когда за ней следует другое соединение с условием on
, попробуйте просто расширить его до полной формы:
from trip
cross join UNNEST(segments) as t(segment)
left join (...)
on ...