Updated String Expression Factory Type to BigQuery SQL#1575
Merged
Conversation
28e5247 to
0551988
Compare
tivv
reviewed
Apr 12, 2022
|
|
||
| // If the BigQuery capability is required, ensure the SQL engine supports this capability. | ||
| return requiresBigQueryCapability ? | ||
| ctx.getEngine().getExpressionFactory(StringExpressionFactoryType.SQL, StandardSQLCapabilities.BIGQUERY) : |
Contributor
There was a problem hiding this comment.
nit: you don't need to check for SQL as I suppose BigQuery would imply SQL.
core-plugins/src/main/java/io/cdap/plugin/batch/aggregator/DedupAggregatorUtils.java
Show resolved
Hide resolved
| put(GroupByConfig.Function.COUNT, "COUNT(%s)"); | ||
| put(GroupByConfig.Function.COUNTNULLS, "SUM(CASE WHEN %s IS NULL THEN 1 END)"); | ||
| put(GroupByConfig.Function.COUNTDISTINCT, | ||
| "COUNT(DISTINCT %s) + IF(SUM(CASE WHEN %s IS NULL THEN 1 END) > 0, 1, 0)"); |
Contributor
There was a problem hiding this comment.
It's better to use case instead of if to be ansi compatible
core-plugins/src/main/java/io/cdap/plugin/batch/aggregator/GroupByAggregator.java
Show resolved
Hide resolved
0551988 to
10bdde8
Compare
tivv
reviewed
Apr 12, 2022
core-plugins/src/main/java/io/cdap/plugin/batch/aggregator/DedupAggregatorUtils.java
Show resolved
Hide resolved
d2b0686 to
80367a4
Compare
tivv
approved these changes
Apr 13, 2022
| put(GroupByConfig.Function.COUNT, "COUNT(%s)"); | ||
| put(GroupByConfig.Function.COUNTNULLS, "SUM(CASE WHEN %s IS NULL THEN 1 ELSE 0 END)"); | ||
| put(GroupByConfig.Function.COUNTDISTINCT, | ||
| "COUNT(DISTINCT %s) + CASE WHEN SUM(CASE WHEN %>s IS NULL THEN 1 ELSE 0 END) > 0 THEN 1 ELSE 0 END"); |
Contributor
There was a problem hiding this comment.
nit: can this be COUNT(DISTINCT %s) + MAX(CASE WHEN %>s IS NULL THEN 1 ELSE 0 END) or it would produce a wrong result for empty set? Two nested CASE are hard to read
Member
Author
There was a problem hiding this comment.
This expression can be made safe by adding a Coalesce:
COUNT(DISTINCT %s) + COALESCE(MAX(CASE WHEN %>s IS NULL THEN 1 ELSE 0 END), 0)
ca123bd to
8df3615
Compare
56215bf to
cdcdfa3
Compare
cdcdfa3 to
e12c313
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Depends on cdapio/cdap#14178