SHARKクエリをSPARKに移行します。
以下は、group by 句で関数を使用するサンプルのSHARKクエリです。
select month(dt_cr) as Month,
day(dt_cr) as date_of_created,
count(distinct phone_number) as total_customers
from customer
group by month(dt_cr),day(dt_cr);
これと同じクエリがSPARK sql で機能しないため、以下のエラーが発生します。
エラー: org.apache.spark.sql.catalyst.errors.package$TreeNodeException: 式が GROUP BY にありません。
ソリューションの一部として、以下の SPARK クエリを使用しています。これは機能していますが、コードの変更が必要です。それは私の既存のプロジェクトに大きな影響を与えます。したがって、誰もが最小限の影響でより良いソリューションを手に入れることができます。
SELECT Month,date_of_created,count(distinct phone_number) as total_customers
FROM
(select month(dt_cr) as Month,
day(dt_cr) as date_of_created,
email
from customers)A
group by Month,date_of_created