Bugfix: Escape Column Name in Generated Spark SQL #85
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue #, if available:
#84
Description of changes:
This PR properly escapes column names in generated Spark SQL code.
Currently, when executing a
isContainedIn
Check
on anyDataFrame
that contains any column whose name contains any characters that make up any reserved keyword in Spark SQL will cause a runtime failure. Digging into it, the runtime failure will show the root cause is a Spark SQL syntax error (specifically aorg.apache.spark.sql.catalyst.parser.ParseException
) due to incorrectly parsing the column name.E.g. if the column name starts with
[
, then the exception will read as:The fix for this bug is to wrap all bare column names in generated Spark SQL with backticks: ``. I.e. a query such as
$column IS NULL
is unsafe, but it's escaped variant is ok to execute, regardless of the value of$column
:A new test showcasing this functionality is in the
CheckTest
class
named"Check on column names with special characters"
. This test executes theisContainedIn
Check
on both a value list as well as a (minimum, maximum) boundary. It succeeds only when the associated generated Spark SQL code has the escaped column name.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.