This is an automated email from the ASF dual-hosted git repository. lqc pushed a commit to branch release-1.4.0-rc in repository https://gitbox.apache.org/repos/asf/pinot.git
commit 27b4def4a8a08796f21aa5a57a5d83a16f43aeda Author: Xiaotian (Jackie) Jiang <[email protected]> AuthorDate: Wed Jul 30 14:57:59 2025 -0600 Make VARIANT/UUID non reserved keyword (#16471) --- pinot-common/src/main/codegen/config.fmpp | 21 +++++--- .../pinot/sql/parsers/CalciteSqlParserTest.java | 56 ++++++++++++++++------ .../transform/function/CastTransformFunction.java | 14 +++--- 3 files changed, 63 insertions(+), 28 deletions(-) diff --git a/pinot-common/src/main/codegen/config.fmpp b/pinot-common/src/main/codegen/config.fmpp index 65de367c242..29f10c29198 100644 --- a/pinot-common/src/main/codegen/config.fmpp +++ b/pinot-common/src/main/codegen/config.fmpp @@ -44,10 +44,15 @@ data: { keywords: [ "FILE" "ARCHIVE" - "BIG_DECIMAL" - "BYTES" + # Pinot types allowed in CAST function + # LONG - for BIGINT + # BIG_DECIMAL - for DECIMAL + # STRING - for VARCHAR + # BYTES - for VARBINARY "LONG" + "BIG_DECIMAL" "STRING" + "BYTES" ] # List of non-reserved keywords to add; @@ -55,14 +60,16 @@ data: { nonReservedKeywordsToAdd: [ "FILE" "ARCHIVE" - "BIG_DECIMAL" - "BYTES" - "LONG" - "STRING" # Pinot allows using DEFAULT as the catalog name "DEFAULT_" - # Pinot allows using DATETIME as column name + # Pinot allows using LONG/BIG_DECIMAL/STRING/BYTES/DATETIME/VARIANT/UUID as column name + "LONG" + "BIG_DECIMAL" + "STRING" + "BYTES" "DATETIME" + "VARIANT" + "UUID" # The following keywords are reserved in core Calcite, # are reserved in some version of SQL, diff --git a/pinot-common/src/test/java/org/apache/pinot/sql/parsers/CalciteSqlParserTest.java b/pinot-common/src/test/java/org/apache/pinot/sql/parsers/CalciteSqlParserTest.java index e0ec9f18c12..64479b8c313 100644 --- a/pinot-common/src/test/java/org/apache/pinot/sql/parsers/CalciteSqlParserTest.java +++ b/pinot-common/src/test/java/org/apache/pinot/sql/parsers/CalciteSqlParserTest.java @@ -18,38 +18,66 @@ */ package org.apache.pinot.sql.parsers; +import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import static org.apache.pinot.sql.parsers.CalciteSqlParser.CALCITE_SQL_PARSER_IDENTIFIER_MAX_LENGTH; import static org.testng.Assert.assertThrows; -import static org.testng.Assert.fail; + public class CalciteSqlParserTest { private static final String SINGLE_CHAR = "a"; + private static final String QUERY_TEMPLATE = "SELECT %s FROM %s"; @Test public void testIdentifierLength() { String tableName = extendIdentifierToMaxLength("exampleTable"); String columnName = extendIdentifierToMaxLength("exampleColumn"); - try { - final String validQuery = "SELECT count(" + columnName + ") FROM " + tableName + " WHERE " + columnName - + " IS NOT NULL"; - CalciteSqlParser.compileToPinotQuery(validQuery); - } catch (Exception ignore) { - // Should not reach this line - fail(); - } - - final String invalidTableNameQuery = "SELECT count(" + columnName + ") FROM " + tableName + SINGLE_CHAR + " WHERE " - + columnName + " IS NOT NULL"; - final String invalidColumnNameQuery = "SELECT count(" + columnName + SINGLE_CHAR + ") FROM " + tableName + " WHERE " - + columnName + SINGLE_CHAR + " IS NOT NULL"; + String validQuery = createQuery(tableName, columnName); + CalciteSqlParser.compileToPinotQuery(validQuery); + + String invalidTableNameQuery = createQuery(columnName, tableName + SINGLE_CHAR); assertThrows(SqlCompilationException.class, () -> CalciteSqlParser.compileToPinotQuery(invalidTableNameQuery)); + String invalidColumnNameQuery = createQuery(columnName + SINGLE_CHAR, tableName); assertThrows(SqlCompilationException.class, () -> CalciteSqlParser.compileToPinotQuery(invalidColumnNameQuery)); } private String extendIdentifierToMaxLength(String identifier) { return identifier + SINGLE_CHAR.repeat(CALCITE_SQL_PARSER_IDENTIFIER_MAX_LENGTH - identifier.length()); } + + private String createQuery(String columnName, String tableName) { + return String.format(QUERY_TEMPLATE, columnName, tableName); + } + + @Test(dataProvider = "nonReservedKeywords") + public void testNonReservedKeywords(String keyword) { + CalciteSqlParser.compileToPinotQuery(createQuery(keyword, "testTable")); + CalciteSqlParser.compileToPinotQuery(createQuery(keyword.toUpperCase(), "testTable")); + } + + @DataProvider + public static Object[][] nonReservedKeywords() { + return new Object[][]{ + new Object[]{"int"}, + new Object[]{"integer"}, + new Object[]{"long"}, + new Object[]{"bigint"}, + new Object[]{"float"}, + new Object[]{"double"}, + new Object[]{"big_decimal"}, + new Object[]{"decimal"}, + new Object[]{"boolean"}, + // TODO: Revisit if we should make "timestamp" non reserved +// new Object[]{"timestamp"}, + new Object[]{"string"}, + new Object[]{"varchar"}, + new Object[]{"bytes"}, + new Object[]{"binary"}, + new Object[]{"varbinary"}, + new Object[]{"variant"}, + new Object[]{"uuid"} + }; + } } diff --git a/pinot-core/src/main/java/org/apache/pinot/core/operator/transform/function/CastTransformFunction.java b/pinot-core/src/main/java/org/apache/pinot/core/operator/transform/function/CastTransformFunction.java index fd51113f06b..0c2bd7e1d64 100644 --- a/pinot-core/src/main/java/org/apache/pinot/core/operator/transform/function/CastTransformFunction.java +++ b/pinot-core/src/main/java/org/apache/pinot/core/operator/transform/function/CastTransformFunction.java @@ -57,10 +57,6 @@ public class CastTransformFunction extends BaseTransformFunction { if (castFormatTransformFunction instanceof LiteralTransformFunction) { String targetType = ((LiteralTransformFunction) castFormatTransformFunction).getStringLiteral().toUpperCase(); switch (targetType) { - case "BYTES": - case "VARBINARY": - _resultMetadata = sourceSV ? BYTES_SV_NO_DICTIONARY_METADATA : BYTES_MV_NO_DICTIONARY_METADATA; - break; case "INT": case "INTEGER": _resultMetadata = sourceSV ? INT_SV_NO_DICTIONARY_METADATA : INT_MV_NO_DICTIONARY_METADATA; @@ -93,6 +89,13 @@ public class CastTransformFunction extends BaseTransformFunction { case "VARCHAR": _resultMetadata = sourceSV ? STRING_SV_NO_DICTIONARY_METADATA : STRING_MV_NO_DICTIONARY_METADATA; break; + case "JSON": + _resultMetadata = sourceSV ? JSON_SV_NO_DICTIONARY_METADATA : JSON_MV_NO_DICTIONARY_METADATA; + break; + case "BYTES": + case "VARBINARY": + _resultMetadata = sourceSV ? BYTES_SV_NO_DICTIONARY_METADATA : BYTES_MV_NO_DICTIONARY_METADATA; + break; case "INT_ARRAY": case "INTEGER_ARRAY": _resultMetadata = INT_MV_NO_DICTIONARY_METADATA; @@ -110,9 +113,6 @@ public class CastTransformFunction extends BaseTransformFunction { case "VARCHAR_ARRAY": _resultMetadata = STRING_MV_NO_DICTIONARY_METADATA; break; - case "JSON": - _resultMetadata = sourceSV ? JSON_SV_NO_DICTIONARY_METADATA : JSON_MV_NO_DICTIONARY_METADATA; - break; default: throw new IllegalArgumentException("Unable to cast expression to type - " + targetType); } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
