[CALCITE-6555] RelBuilder.aggregateRex wrongly thinks aggregate functions of "GROUP BY ()" queries are NOT NULL

In RelBuilder, the aggregateRex method (added in CALCITE-5802)
wrongly thinks that aggregate functions in a `GROUP BY ()`
query are NOT NULL. Consider the query

  SELECT SUM(empno) AS s, COUNT(empno) AS c
  FROM emp
  GROUP BY ()

`SUM(empno)` should be nullable, even though `empno` has type
`SMALLINT NOT NULL`, because `GROUP BY ()` will return one row
even if `emp` has no rows, and therefore `SUM` will be
evaluated over the empty set. A RelBuilder test that attempts
to build an equivalent query gets the following error stack:

  java.lang.AssertionError: type mismatch:
  ref:
  SMALLINT NOT NULL
  input:
  SMALLINT

We add a test case for measure queries, because measures are
the only code path that uses `aggregateRex` at present.
3 files changed
tree: 8397ff25af83dc9c70d93b74cabdd6e001b88ab7
  1. .github/
  2. .idea/
  3. arrow/
  4. babel/
  5. bom/
  6. buildSrc/
  7. cassandra/
  8. core/
  9. druid/
  10. elasticsearch/
  11. example/
  12. file/
  13. geode/
  14. gradle/
  15. innodb/
  16. kafka/
  17. linq4j/
  18. mongodb/
  19. pig/
  20. piglet/
  21. plus/
  22. redis/
  23. release/
  24. server/
  25. site/
  26. spark/
  27. splunk/
  28. src/
  29. testkit/
  30. ubenchmark/
  31. .asf.yaml
  32. .editorconfig
  33. .gitattributes
  34. .gitignore
  35. .mailmap
  36. .ratignore
  37. build.gradle.kts
  38. gradle.properties
  39. gradlew
  40. gradlew.bat
  41. Jenkinsfile
  42. LICENSE
  43. NOTICE
  44. README
  45. README.md
  46. settings.gradle.kts
  47. sqlline
  48. sqlline.bat
  49. sqlsh
  50. sqlsh.bat
README.md

Maven Central CI Status

Apache Calcite

Apache Calcite is a dynamic data management framework.

It contains many of the pieces that comprise a typical database management system but omits the storage primitives. It provides an industry standard SQL parser and validator, a customisable optimizer with pluggable rules and cost functions, logical and physical algebraic operators, various transformation algorithms from SQL to algebra (and the opposite), and many adapters for executing SQL queries over Cassandra, Druid, Elasticsearch, MongoDB, Kafka, and others, with minimal configuration.

For more details, see the home page.

The project uses JIRA for issue tracking. For further information, please see the JIRA accounts guide.