Я хотел бы сделать SQL-соединение между двумя таблицами в spark, и я получил неожиданную ошибку:
>>> cyclistes.printSchema()
root
|-- id: string (nullable = true)
|-- age: string (nullable = true)
(...)
>>> voyages.printSchema()
root
|-- id: string (nullable = true)
|-- vitesse: string (nullable = true)
(...)
>>> requete_sql = """
SELECT c.id, c.age, mean(v.vitesse)
FROM cyclistes as c , voyages as v
WHERE c.id == v.id
GROUP BY c.id
"""
>>> spark.sql(requete_sql)
AnalysisException: "grouping expressions sequence is empty, and
'c.`age`' is not an aggregate function. Wrap '(avg(CAST(v.`vitesse`
AS DOUBLE)) AS `avg(CAST(vitesse AS DOUBLE))`)' in windowing
function(s) or wrap 'c.`age`' in first() (or first_value) if you
don't care which value you get.;
Есть идеи?
ОТВЕТ:
Базовая ошибка в SQL-запросе: необходимо добавить максимум около возраста:
>>> requete_sql = """
SELECT c.id, max(c.age), mean(v.vitesse)
FROM cyclistes as c , voyages as v
WHERE c.id == v.id GROUP BY c.id """
>>> spark.sql(requete_sql)