-
Notifications
You must be signed in to change notification settings - Fork 154
Issue #243 - Add CustomSql analyzer #244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ | |
| Compliance, | ||
| Correlation, | ||
| CountDistinct, | ||
| CustomSql, | ||
| DataType, | ||
| Distinctness, | ||
| Entropy, | ||
|
|
@@ -111,6 +112,14 @@ def CountDistinct(self, columns): | |
| df_from_json = self.spark.read.json(self.sc.parallelize([result_json])) | ||
| self.assertEqual(df_from_json.select("value").collect(), result_df.select("value").collect()) | ||
| return result_df.select("value").collect() | ||
|
|
||
| def CustomSql(self, expression, disambiguator="*"): | ||
| result = self.AnalysisRunner.onData(self.df).addAnalyzer(CustomSql(expression, disambiguator)).run() | ||
| result_df = AnalyzerContext.successMetricsAsDataFrame(self.spark, result) | ||
| result_json = AnalyzerContext.successMetricsAsJson(self.spark, result) | ||
| df_from_json = self.spark.read.json(self.sc.parallelize([result_json])) | ||
| self.assertEqual(df_from_json.select("value").collect(), result_df.select("value").collect()) | ||
| return result_df.select("value", "instance").collect() | ||
|
|
||
| def Datatype(self, column, where=None): | ||
| result = self.AnalysisRunner.onData(self.df).addAnalyzer(DataType(column, where)).run() | ||
|
|
@@ -298,6 +307,26 @@ def test_CountDistinct(self): | |
| def test_fail_CountDistinct(self): | ||
| self.assertEqual(self.CountDistinct("b"), [Row(value=1.0)]) | ||
|
|
||
| def test_CustomSql(self): | ||
| self.df.createOrReplaceTempView("input_table") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. EDGE_CASE: The test
|
||
| self.assertEqual(self.CustomSql("SELECT SUM(b) FROM input_table"), [Row(value=6.0, instance="*")]) | ||
| self.assertEqual( | ||
| self.CustomSql("SELECT AVG(LENGTH(a)) FROM input_table", disambiguator="foo"), | ||
| [Row(value=3.0, instance="foo")] | ||
| ) | ||
| self.assertEqual( | ||
| self.CustomSql("SELECT MAX(c) FROM input_table", disambiguator="bar"), | ||
| [Row(value=6.0, instance="bar")] | ||
| ) | ||
|
|
||
| @pytest.mark.xfail(reason="@unittest.expectedFailure") | ||
| def test_fail_CustomSql(self): | ||
| self.assertEqual(self.CustomSql("SELECT SUM(b) FROM input_table"), [Row(value=1.0)]) | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. MISSING_TEST: The test
|
||
| @pytest.mark.xfail(reason="@unittest.expectedFailure") | ||
| def test_fail_CustomSql_incorrect_query(self): | ||
| self.CustomSql("SELECT SUM(b)") | ||
|
|
||
| def test_DataType(self): | ||
| self.assertEqual( | ||
| self.Datatype("b"), | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EDGE_CASE: The
CustomSqlanalyzer passesself.expressionandself.disambiguatordirectly to the ScalaCustomSqlconstructor. However, looking at the Deequ Scala source for CustomSql, the constructor signature isCustomSql(expression: String, disambiguator: Option[String])in some versions. If the Scala API expects anOption[String]for disambiguator, passing a plain Python string would cause a Py4J type mismatch error at runtime.