I am trying to create a Python script which can convert the SQL query into a Python script using a regex. Can someone throw some ideas to achieve this in Python?
============SQL Query========
SELECT
alert_id,
Count(star_rating) as total_rating,
Max(star_rating) AS best_rating,
Min(star_rating) AS worst_rating
FROM
alerts
WHERE
verified_purchase = 'Y'
AND review_date BETWEEN '1995-07-22' AND '2015-08-31'
AND country IN
(
'DE','US','UK','FR','JP'
)
GROUP BY
alert_id
ORDER BY
total_rating asc,
alert_id desc,
best_rating
LIMIT 10;
Below are the expected result:
alerts.filter("verified_purchase = 'Y' AND review_date BETWEEN '1995-07-22' AND '2015-08-31' AND country IN ('DE', 'US', 'UK', 'FR', 'JP')")
.groupBy("alert_id")
.agg(count(col("star_rating")).alias('total_rating'),max(col("star_rating")).alias('best_rating'),min(col("star_rating")).alias('worst_rating')")
.select("alert_id","total_rating","best_rating","worst_rating")
.orderBy(col("total_rating").asc(),col("alert_id").desc(),col("best_rating").asc())
.limit(10)