From 94b78e9884bb3492527e67b25afa9f28c45ba4a2 Mon Sep 17 00:00:00 2001 From: Gian Merlino Date: Wed, 19 Jul 2023 16:20:21 -0700 Subject: [PATCH] [CALCITE-5865] ClassCastException with FLOOR and CEIL on conformances that are not builtin CALCITE-5747 introduced some BigQuery-specific logic for FLOOR and CEIL that is keyed off the conformance being SqlConformanceEnum.BIG_QUERY. However, it was implemented in such a way that implementations of SqlConformance that are not SqlConformanceEnum would throw ClassCastException. --- core/src/main/codegen/templates/Parser.jj | 2 +- .../org/apache/calcite/sql/fun/SqlStdOperatorTable.java | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/core/src/main/codegen/templates/Parser.jj b/core/src/main/codegen/templates/Parser.jj index 822f6a407b0d..1ea1cebcf12e 100644 --- a/core/src/main/codegen/templates/Parser.jj +++ b/core/src/main/codegen/templates/Parser.jj @@ -7364,7 +7364,7 @@ SqlNode StandardFloorCeilOptions(Span s, boolean floorFlag) : } )? { - SqlOperator op = SqlStdOperatorTable.floorCeil(floorFlag, (SqlConformanceEnum) this.conformance); + SqlOperator op = SqlStdOperatorTable.floorCeil(floorFlag, this.conformance); function = op.createCall(s.end(this), args); } ( diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlStdOperatorTable.java b/core/src/main/java/org/apache/calcite/sql/fun/SqlStdOperatorTable.java index c4c8afd3a871..86a7cb0a0acc 100644 --- a/core/src/main/java/org/apache/calcite/sql/fun/SqlStdOperatorTable.java +++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlStdOperatorTable.java @@ -2701,11 +2701,10 @@ public static SqlOperator like(boolean negated, boolean caseSensitive) { /** Returns the operator for {@code FLOOR} and {@code CEIL} with given floor flag * and library. */ - public static SqlOperator floorCeil(boolean floor, SqlConformanceEnum conformance) { - switch (conformance) { - case BIG_QUERY: + public static SqlOperator floorCeil(boolean floor, SqlConformance conformance) { + if (SqlConformanceEnum.BIG_QUERY.equals(conformance)) { return floor ? SqlLibraryOperators.FLOOR_BIG_QUERY : SqlLibraryOperators.CEIL_BIG_QUERY; - default: + } else { return floor ? SqlStdOperatorTable.FLOOR : SqlStdOperatorTable.CEIL; } }