r/apachespark • u/Quirky_Comb_4426 • 23h ago
I got tired of waiting 8 minutes for a cluster just to find a typo in my Spark SQL, so I built a checker
When I submit a Spark SQL job, I have to wait 7 to 8 minutes for the cluster to spin up, only to find out the query was incorrect/buggy and then I have to dig through a long trace to find out what was wrong. This happened 10 to 15 times a month, so that's an hour or two of just waiting, plus the digging.
I looked around for something that would catch these before submitting. SQLFluff has a Spark dialect, but it's mostly about style, and nothing gave me a clear message like, "this is what's wrong."
So I built QueryGate. It checks the query locally in about 1 ms, with no cluster and no API key. Additionally, if you turn on the optional LLM mode, it explains errors in plain English. For example, for an unclosed IN list, Spark just says "Syntax error at or near 'IN'", and QueryGate says the list is missing its closing parenthesis.
While testing it against Spark 4.0.1, I found other problems as well: queries that run fine but give wrong answers, like a WHERE that quietly turns a LEFT JOIN into an inner join. EXPLAIN accepted all 36 of those in my benchmark. I added additional rules to catch 12 of them; with the LLM mode enabled, it catches 33, and it never marked any of the 68 correct queries as invalid.
I have open-sourced it (Apache-2.0), and it has a CLI plus a pre-commit hook:
pip install querygate-spark
https://github.com/vchaurasia95/querygate-spark-sql
What Spark SQL bugs have bitten you? Would love to hear your thoughts on this.