Skip to content

Instantly share code, notes, and snippets.

@prateeka
Last active September 18, 2021 10:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prateeka/a2621bd82d4eeeaf616a2fb7bc7c0fbb to your computer and use it in GitHub Desktop.
Save prateeka/a2621bd82d4eeeaf616a2fb7bc7c0fbb to your computer and use it in GitHub Desktop.
atscale-4654: missing group-by clause in outbound query. reason for missing the group-by clause for the ticket are listed here compared to other cases which have group-by clause
def makeSelectColumn(gb: GroupByType): Option[SelectColumn] = {
gb match {
case GroupByIgnore => None
case _: GroupByColumnNumber => None
case gbv@GroupByValue(_: ConstantValue, _) if findGroupByTypeColumn(gbv).isEmpty => None
case _ =>
val (exposed, expr) =
gb match {
case GroupByColumnName(name, _, Some(expression)) => (Some(name), expression)
case GroupByValue(_, expression) => (None, expression)
case _ => throw new IllegalStateException("")
}
val (sc, gbo) = getSelectColumn(exposed, expr, None, gbl)
Some(sc.copy(aggType = new AggregateGrouped(false)))
}
}
@prateeka
Copy link
Author

prateeka commented Sep 18, 2021

query-1 inbound query:

SELECT TO_DATE('2020-01-01') e2
FROM `bq`.`test sales cube` `tsc`
GROUP BY CAST(TO_DATE('2021-01-01') AS DATE);

query-1 outbound query:

  SELECT
     SAFE_CAST(SAFE_CAST(SAFE_CAST('2020-01-01' AS TIMESTAMP) AS DATE) AS STRING) AS e2
  FROM
     as_adventure.factinternetsales AS factinternetsales_t1
  WHERE
     true
  GROUP BY
     SAFE_CAST(SAFE_CAST(SAFE_CAST(SAFE_CAST('2021-01-01' AS TIMESTAMP) AS DATE) AS STRING) AS DATE)

query-2 inbound query:

  SELECT TO_DATE('2212-09-09') AS `d`
  FROM `bq`.`test sales cube` `tsc`
  GROUP BY 1.10001;

query-2 outbound query:

  SELECT
   SAFE_CAST(SAFE_CAST(SAFE_CAST('2212-09-09' AS TIMESTAMP) AS DATE) AS STRING) AS d
FROM
   as_adventure.factinternetsales AS factinternetsales_t1
WHERE
   true
  • Query-2 is pulling >1 rows due to missing group-by compared to query-1.
  • Query-2 is missing group-by as code flows to line 5 above compared to line 10 for query-1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment