This is an automated email from the ASF dual-hosted git repository.

cancai pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
     new ff50d1d427 [CALCITE-6820] Trino dialect implementation
ff50d1d427 is described below

commit ff50d1d42790c93050c62ca949913ce542f51d09
Author: Yu Xu <[email protected]>
AuthorDate: Sun Mar 16 12:38:50 2025 +0800

    [CALCITE-6820] Trino dialect implementation
---
 .../java/org/apache/calcite/sql/SqlDialect.java    |  1 +
 .../apache/calcite/sql/SqlDialectFactoryImpl.java  |  3 +
 .../calcite/sql/dialect/PrestoSqlDialect.java      |  4 +-
 .../calcite/sql/dialect/TrinoSqlDialect.java       | 64 +++++++++++++++
 .../calcite/rel/rel2sql/RelToSqlConverterTest.java | 95 ++++++++++++++++++++--
 5 files changed, 156 insertions(+), 11 deletions(-)

diff --git a/core/src/main/java/org/apache/calcite/sql/SqlDialect.java 
b/core/src/main/java/org/apache/calcite/sql/SqlDialect.java
index c2fe7acdad..e8ed8e7a49 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlDialect.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlDialect.java
@@ -1435,6 +1435,7 @@ public enum DatabaseProduct {
     PHOENIX("Phoenix", "\"", NullCollation.HIGH),
     POSTGRESQL("PostgreSQL", "\"", NullCollation.HIGH),
     PRESTO("Presto", "\"", NullCollation.LAST),
+    TRINO("Trino", "\"", NullCollation.LAST),
     NETEZZA("Netezza", "\"", NullCollation.HIGH),
     INFOBRIGHT("Infobright", "`", NullCollation.HIGH),
     NEOVIEW("Neoview", null, NullCollation.HIGH),
diff --git 
a/core/src/main/java/org/apache/calcite/sql/SqlDialectFactoryImpl.java 
b/core/src/main/java/org/apache/calcite/sql/SqlDialectFactoryImpl.java
index b22f8fb466..6555482d71 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlDialectFactoryImpl.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlDialectFactoryImpl.java
@@ -50,6 +50,7 @@
 import org.apache.calcite.sql.dialect.StarRocksSqlDialect;
 import org.apache.calcite.sql.dialect.SybaseSqlDialect;
 import org.apache.calcite.sql.dialect.TeradataSqlDialect;
+import org.apache.calcite.sql.dialect.TrinoSqlDialect;
 import org.apache.calcite.sql.dialect.VerticaSqlDialect;
 
 import org.checkerframework.checker.nullness.qual.Nullable;
@@ -237,6 +238,8 @@ public class SqlDialectFactoryImpl implements 
SqlDialectFactory {
       return SybaseSqlDialect.DEFAULT;
     case TERADATA:
       return TeradataSqlDialect.DEFAULT;
+    case TRINO:
+      return TrinoSqlDialect.DEFAULT;
     case VERTICA:
       return VerticaSqlDialect.DEFAULT;
     case SQLSTREAM:
diff --git 
a/core/src/main/java/org/apache/calcite/sql/dialect/PrestoSqlDialect.java 
b/core/src/main/java/org/apache/calcite/sql/dialect/PrestoSqlDialect.java
index f739e7e891..a7c142725a 100644
--- a/core/src/main/java/org/apache/calcite/sql/dialect/PrestoSqlDialect.java
+++ b/core/src/main/java/org/apache/calcite/sql/dialect/PrestoSqlDialect.java
@@ -196,7 +196,7 @@ private static void unparseUsingLimit(SqlWriter writer, 
@Nullable SqlNode offset
   /**
    * change map open/close symbol from default [] to ().
    */
-  private static void unparseMapValue(SqlWriter writer, SqlCall call,
+  public static void unparseMapValue(SqlWriter writer, SqlCall call,
       int leftPrec, int rightPrec) {
     call = convertMapValueCall(call);
     writer.keyword(call.getOperator().getName());
@@ -213,7 +213,7 @@ private static void unparseMapValue(SqlWriter writer, 
SqlCall call,
    * from {@code MAP['k1', 'v1', 'k2', 'v2']}
    * to {@code MAP[ARRAY['k1', 'k2'], ARRAY['v1', 'v2']]}.
    */
-  private static SqlCall convertMapValueCall(SqlCall call) {
+  public static SqlCall convertMapValueCall(SqlCall call) {
     boolean unnestMap = call.operandCount() > 0
         && call.getOperandList().stream().allMatch(operand -> operand 
instanceof SqlLiteral);
     if (!unnestMap) {
diff --git 
a/core/src/main/java/org/apache/calcite/sql/dialect/TrinoSqlDialect.java 
b/core/src/main/java/org/apache/calcite/sql/dialect/TrinoSqlDialect.java
new file mode 100644
index 0000000000..5e5beac9e3
--- /dev/null
+++ b/core/src/main/java/org/apache/calcite/sql/dialect/TrinoSqlDialect.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.calcite.sql.dialect;
+
+import org.apache.calcite.avatica.util.Casing;
+import org.apache.calcite.config.NullCollation;
+import org.apache.calcite.sql.SqlCall;
+import org.apache.calcite.sql.SqlDialect;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.SqlWriter;
+import org.apache.calcite.sql.fun.SqlStdOperatorTable;
+import org.apache.calcite.util.RelToSqlConverterUtil;
+
+import org.checkerframework.checker.nullness.qual.Nullable;
+
+/**
+ * A <code>SqlDialect</code> implementation for the Trino database.
+ */
+public class TrinoSqlDialect extends PrestoSqlDialect {
+  public static final Context DEFAULT_CONTEXT = SqlDialect.EMPTY_CONTEXT
+      .withDatabaseProduct(DatabaseProduct.TRINO)
+      .withIdentifierQuoteString("\"")
+      .withUnquotedCasing(Casing.UNCHANGED)
+      .withNullCollation(NullCollation.LAST);
+
+  public static final SqlDialect DEFAULT = new 
TrinoSqlDialect(DEFAULT_CONTEXT);
+
+  /**
+   * Creates a TrinoSqlDialect.
+   */
+  public TrinoSqlDialect(Context context) {
+    super(context);
+  }
+
+  @Override public void unparseOffsetFetch(SqlWriter writer, @Nullable SqlNode 
offset,
+      @Nullable SqlNode fetch) {
+    unparseFetchUsingAnsi(writer, offset, fetch);
+  }
+
+  @Override public void unparseCall(SqlWriter writer, SqlCall call,
+      int leftPrec, int rightPrec) {
+    if (call.getOperator() == SqlStdOperatorTable.SUBSTRING) {
+      RelToSqlConverterUtil.specialOperatorByName("SUBSTRING")
+          .unparse(writer, call, 0, 0);
+    } else {
+      super.unparseCall(writer, call, leftPrec, rightPrec);
+    }
+  }
+
+}
diff --git 
a/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java 
b/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
index ff49aac7fc..a0fa34cf37 100644
--- 
a/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
+++ 
b/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
@@ -70,7 +70,6 @@
 import org.apache.calcite.sql.dialect.MysqlSqlDialect;
 import org.apache.calcite.sql.dialect.OracleSqlDialect;
 import org.apache.calcite.sql.dialect.PostgresqlSqlDialect;
-import org.apache.calcite.sql.dialect.PrestoSqlDialect;
 import org.apache.calcite.sql.fun.SqlLibrary;
 import org.apache.calcite.sql.fun.SqlStdOperatorTable;
 import org.apache.calcite.sql.parser.SqlParser;
@@ -202,6 +201,7 @@ private static Map<SqlDialect, DatabaseProduct> dialects() {
         .put(DatabaseProduct.POSTGRESQL.getDialect(), 
DatabaseProduct.POSTGRESQL)
         .put(DatabaseProduct.PRESTO.getDialect(), DatabaseProduct.PRESTO)
         .put(DatabaseProduct.STARROCKS.getDialect(), DatabaseProduct.STARROCKS)
+        .put(DatabaseProduct.TRINO.getDialect(), DatabaseProduct.TRINO)
         .build();
   }
 
@@ -400,6 +400,7 @@ private static String toSql(RelNode root, SqlDialect 
dialect,
     final String expectedClickHouse = "SELECT PI()";
     final String expectedPresto = "SELECT PI()\n"
         + "FROM (VALUES (0)) AS \"t\" (\"ZERO\")";
+    final String expectTrino = expectedPresto;
     final String expectedOracle = "SELECT PI\n"
         + "FROM \"DUAL\"";
     sql(query)
@@ -410,6 +411,7 @@ private static String toSql(RelNode root, SqlDialect 
dialect,
         .withMysql().ok(expectedMysql)
         .withClickHouse().ok(expectedClickHouse)
         .withPresto().ok(expectedPresto)
+        .withTrino().ok(expectedPresto)
         .withOracle().ok(expectedOracle);
   }
 
@@ -426,6 +428,7 @@ private static String toSql(RelNode root, SqlDialect 
dialect,
     final String expectedClickHouse = "SELECT PI() AS `PI`";
     final String expectedPresto = "SELECT PI() AS \"PI\"\n"
         + "FROM (VALUES (0)) AS \"t\" (\"ZERO\")";
+    final String expectedTrino = expectedPresto;
     final String expectedOracle = "SELECT PI \"PI\"\n"
         + "FROM \"DUAL\"";
     sql(query)
@@ -436,6 +439,7 @@ private static String toSql(RelNode root, SqlDialect 
dialect,
         .withMysql().ok(expectedMysql)
         .withClickHouse().ok(expectedClickHouse)
         .withPresto().ok(expectedPresto)
+        .withTrino().ok(expectedTrino)
         .withOracle().ok(expectedOracle);
   }
 
@@ -684,17 +688,20 @@ private static String toSql(RelNode root, SqlDialect 
dialect,
         + "FROM `foodmart`.`product`";
     final String expectedPresto = "SELECT COUNT(*)\n"
         + "FROM \"foodmart\".\"product\"";
+    final String expectedTrino = expectedPresto;
     final String expectedStarRocks = "SELECT COUNT(*)\n"
         + "FROM `foodmart`.`product`";
     sql(sql0)
         .ok(expected)
         .withMysql().ok(expectedMysql)
         .withPresto().ok(expectedPresto)
+        .withTrino().ok(expectedTrino)
         .withStarRocks().ok(expectedStarRocks);
     sql(sql1)
         .ok(expected)
         .withMysql().ok(expectedMysql)
         .withPresto().ok(expectedPresto)
+        .withTrino().ok(expectedTrino)
         .withStarRocks().ok(expectedStarRocks);
   }
 
@@ -762,7 +769,8 @@ private static String toSql(RelNode root, SqlDialect 
dialect,
     relFn(relFn)
         .ok(expected)
         .withMysql().ok(expectedMysql)
-        .withPresto().ok(expected);
+        .withPresto().ok(expected)
+        .withTrino().ok(expected);
   }
 
   /** Test case for
@@ -1146,6 +1154,7 @@ private static String toSql(RelNode root, SqlDialect 
dialect,
         + "FROM \"foodmart\".\"product\"\n"
         + "GROUP BY ROLLUP(\"product_class_id\")\n"
         + "ORDER BY \"product_class_id\", 2";
+    final String expectdTrino = expectedPresto;
     final String expectedStarRocks = "SELECT `product_class_id`, COUNT(*) AS 
`C`\n"
         + "FROM `foodmart`.`product`\n"
         + "GROUP BY ROLLUP(`product_class_id`)\n"
@@ -1154,6 +1163,7 @@ private static String toSql(RelNode root, SqlDialect 
dialect,
         .ok(expected)
         .withMysql().ok(expectedMysql)
         .withPresto().ok(expectedPresto)
+        .withTrino().ok(expectdTrino)
         .withStarRocks().ok(expectedStarRocks);
   }
 
@@ -1172,6 +1182,7 @@ private static String toSql(RelNode root, SqlDialect 
dialect,
     final String expectedPresto = "SELECT \"product_class_id\", COUNT(*) AS 
\"C\"\n"
         + "FROM \"foodmart\".\"product\"\n"
         + "GROUP BY ROLLUP(\"product_class_id\")";
+    final String expectedTrino = expectedPresto;
     final String expectedStarRocks = "SELECT `product_class_id`, COUNT(*) AS 
`C`\n"
         + "FROM `foodmart`.`product`\n"
         + "GROUP BY ROLLUP(`product_class_id`)";
@@ -1179,6 +1190,7 @@ private static String toSql(RelNode root, SqlDialect 
dialect,
         .ok(expected)
         .withMysql().ok(expectedMysql)
         .withPresto().ok(expectedPresto)
+        .withTrino().ok(expectedTrino)
         .withStarRocks().ok(expectedStarRocks);
   }
 
@@ -1233,6 +1245,10 @@ private static String toSql(RelNode root, SqlDialect 
dialect,
         + "FROM \"foodmart\".\"product\"\n"
         + "GROUP BY ROLLUP(\"product_class_id\")\n"
         + "LIMIT 5";
+    final String expectedTrino = "SELECT \"product_class_id\", COUNT(*) AS 
\"C\"\n"
+        + "FROM \"foodmart\".\"product\"\n"
+        + "GROUP BY ROLLUP(\"product_class_id\")\n"
+        + "FETCH NEXT 5 ROWS ONLY";
     final String expectedStarRocks = "SELECT `product_class_id`, COUNT(*) AS 
`C`\n"
         + "FROM `foodmart`.`product`\n"
         + "GROUP BY ROLLUP(`product_class_id`)\n"
@@ -1241,6 +1257,7 @@ private static String toSql(RelNode root, SqlDialect 
dialect,
         .ok(expected)
         .withMysql().ok(expectedMysql)
         .withPresto().ok(expectedPresto)
+        .withTrino().ok(expectedTrino)
         .withStarRocks().ok(expectedStarRocks);
   }
 
@@ -2381,12 +2398,15 @@ private SqlDialect nonOrdinalDialect() {
         + "FROM \"foodmart\".\"product\"\n"
         + "GROUP BY \"product_id\"\n"
         + "ORDER BY 2";
+    final String trinoExpected = prestoExpected;
     sql(query)
         .ok(ordinalExpected)
         .dialect(nonOrdinalDialect())
         .ok(nonOrdinalExpected)
-        .dialect(PrestoSqlDialect.DEFAULT)
-        .ok(prestoExpected);
+        .withPresto()
+        .ok(prestoExpected)
+        .withTrino()
+        .ok(trinoExpected);
   }
 
   /**
@@ -2919,6 +2939,7 @@ private SqlDialect nonOrdinalDialect() {
     final String expectedPresto = "SELECT *\n"
         + "FROM \"foodmart\".\"employee\"\n"
         + "WHERE (\"hire_date\" - INTERVAL '19800' SECOND) > 
CAST(\"hire_date\" AS TIMESTAMP)";
+    final String expectedTrino = expectedPresto;
     final String expectedStarRocks = "SELECT *\n"
         + "FROM `foodmart`.`employee`\n"
         + "WHERE (`hire_date` - INTERVAL '19800' SECOND) > CAST(`hire_date` AS 
DATETIME)";
@@ -2928,6 +2949,7 @@ private SqlDialect nonOrdinalDialect() {
     sql(query)
         .withSpark().ok(expectedSpark)
         .withPresto().ok(expectedPresto)
+        .withTrino().ok(expectedTrino)
         .withStarRocks().ok(expectedStarRocks)
         .withHive().ok(expectedHive);
   }
@@ -3047,10 +3069,21 @@ private SqlDialect nonOrdinalDialect() {
         + "FROM \"foodmart\".\"product\"\n"
         + "LIMIT 100\n"
         + "OFFSET 10";
+    final String expectedPresto = "SELECT \"product_id\"\n"
+        + "FROM \"foodmart\".\"product\"\n"
+        + "OFFSET 10\n"
+        + "LIMIT 100";
+    final String expectedTrino = "SELECT \"product_id\"\n"
+        + "FROM \"foodmart\".\"product\"\n"
+        + "OFFSET 10 ROWS\n"
+        + "FETCH NEXT 100 ROWS ONLY";
+
     sql(query).withHive().ok(expected)
         .withVertica().ok(expectedVertica)
         .withStarRocks().ok(expectedStarRocks)
-        .withSnowflake().ok(expectedSnowflake);
+        .withSnowflake().ok(expectedSnowflake)
+        .withPresto().ok(expectedPresto)
+        .withTrino().ok(expectedTrino);
   }
 
   @Test void testPositionFunctionForHive() {
@@ -3953,6 +3986,10 @@ private SqlDialect nonOrdinalDialect() {
         + "FROM \"foodmart\".\"product\"\n"
         + "OFFSET 10\n"
         + "LIMIT 100";
+    final String expectedTrino = "SELECT \"product_id\"\n"
+        + "FROM \"foodmart\".\"product\"\n"
+        + "OFFSET 10 ROWS\n"
+        + "FETCH NEXT 100 ROWS ONLY";
     final String expectedStarRocks = "SELECT `product_id`\n"
         + "FROM `foodmart`.`product`\n"
         + "LIMIT 100\n"
@@ -3961,6 +3998,7 @@ private SqlDialect nonOrdinalDialect() {
         .ok(expected)
         .withClickHouse().ok(expectedClickHouse)
         .withPresto().ok(expectedPresto)
+        .withTrino().ok(expectedTrino)
         .withStarRocks().ok(expectedStarRocks);
   }
 
@@ -5196,6 +5234,7 @@ private void checkLiteral2(String expression, String 
expected) {
         + "FROM \"foodmart\".\"employee\"";
     String expectedPresto = "SELECT DATE_TRUNC('MINUTE', \"hire_date\")\n"
         + "FROM \"foodmart\".\"employee\"";
+    String expectedTrino = expectedPresto;
     String expectedFirebolt = expectedPostgresql;
     String expectedStarRocks = "SELECT DATE_TRUNC('MINUTE', `hire_date`)\n"
         + "FROM `foodmart`.`employee`";
@@ -5206,6 +5245,7 @@ private void checkLiteral2(String expression, String 
expected) {
         .withOracle().ok(expectedOracle)
         .withPostgresql().ok(expectedPostgresql)
         .withPresto().ok(expectedPresto)
+        .withTrino().ok(expectedTrino)
         .withStarRocks().ok(expectedStarRocks);
   }
 
@@ -5228,6 +5268,10 @@ private void checkLiteral2(String expression, String 
expected) {
         + "FROM \"foodmart\".\"employee\"\n"
         + "OFFSET 1\n"
         + "LIMIT 1";
+    final String expectedTrino = "SELECT *\n"
+        + "FROM \"foodmart\".\"employee\"\n"
+        + "OFFSET 1 ROWS\n"
+        + "FETCH NEXT 1 ROWS ONLY";
     final String expectedStarRocks = "SELECT *\n"
         + "FROM `foodmart`.`employee`\n"
         + "LIMIT 1\n"
@@ -5236,6 +5280,7 @@ private void checkLiteral2(String expression, String 
expected) {
         .withMssql().ok(expectedMssql)
         .withSybase().ok(expectedSybase)
         .withPresto().ok(expectedPresto)
+        .withTrino().ok(expectedTrino)
         .withStarRocks().ok(expectedStarRocks);
   }
 
@@ -5497,6 +5542,8 @@ private void checkLiteral2(String expression, String 
expected) {
         + "FROM \"foodmart\".\"product\"";
     final String expectedPresto = "SELECT SUBSTR(\"brand_name\", 2)\n"
         + "FROM \"foodmart\".\"product\"";
+    final String expectedTrino = "SELECT SUBSTRING(\"brand_name\", 2)\n"
+        + "FROM \"foodmart\".\"product\"";
     final String expectedSnowflake = expectedPostgresql;
     final String expectedRedshift = expectedPostgresql;
     final String expectedFirebolt = expectedPresto;
@@ -5515,6 +5562,7 @@ private void checkLiteral2(String expression, String 
expected) {
         .withOracle().ok(expectedOracle)
         .withPostgresql().ok(expectedPostgresql)
         .withPresto().ok(expectedPresto)
+        .withTrino().ok(expectedTrino)
         .withRedshift().ok(expectedRedshift)
         .withSnowflake().ok(expectedSnowflake)
         .withStarRocks().ok(expectedStarRocks);
@@ -5533,6 +5581,8 @@ private void checkLiteral2(String expression, String 
expected) {
         + "FROM \"foodmart\".\"product\"";
     final String expectedPresto = "SELECT SUBSTR(\"brand_name\", 2, 3)\n"
         + "FROM \"foodmart\".\"product\"";
+    final String expectedTrino = "SELECT SUBSTRING(\"brand_name\", 2, 3)\n"
+        + "FROM \"foodmart\".\"product\"";
     final String expectedSnowflake = expectedPostgresql;
     final String expectedRedshift = expectedPostgresql;
     final String expectedFirebolt = expectedPresto;
@@ -5551,6 +5601,7 @@ private void checkLiteral2(String expression, String 
expected) {
         .withOracle().ok(expectedOracle)
         .withPostgresql().ok(expectedPostgresql)
         .withPresto().ok(expectedPresto)
+        .withTrino().ok(expectedTrino)
         .withRedshift().ok(expectedRedshift)
         .withSnowflake().ok(expectedSnowflake)
         .withStarRocks().ok(expectedStarRocks);
@@ -7616,7 +7667,9 @@ private void checkLiteral2(String expression, String 
expected) {
         + "from \"product\"";
     final String expected = "SELECT LENGTH(\"brand_name\")\n"
         + "FROM \"foodmart\".\"product\"";
-    sql(query).withPresto().ok(expected);
+    sql(query)
+        .withPresto().ok(expected)
+        .withTrino().ok(expected);
   }
 
   /** Test case for
@@ -7686,6 +7739,7 @@ private void checkLiteral2(String expression, String 
expected) {
     sql(query)
         .ok(expected)
         .withPresto().ok(expected)
+        .withTrino().ok(expected)
         .withSpark().ok(expectedSpark);
   }
 
@@ -7705,6 +7759,7 @@ private void checkLiteral2(String expression, String 
expected) {
     sql(query)
         .ok(expected)
         .withPresto().ok(expected)
+        .withTrino().ok(expected)
         .withSpark().ok(expectedSpark)
         .withStarRocks().ok(expectedStarRocks);
   }
@@ -8119,9 +8174,11 @@ private void checkLiteral2(String expression, String 
expected) {
         + "FROM \"foodmart\".\"employee\"\n"
         + "WHERE 10 = CAST('10' AS INTEGER) AND \"birth_date\" = 
CAST('1914-02-02' AS DATE) OR "
         + "\"hire_date\" = CAST('1996-01-01 ' || '00:00:00' AS TIMESTAMP)";
+    final String expectedTrino  = expectedPresto;
     sql(query)
         .ok(expected)
-        .withPresto().ok(expectedPresto);
+        .withPresto().ok(expectedPresto)
+        .withTrino().ok(expectedTrino);
   }
 
   @Test void testDialectQuoteStringLiteral() {
@@ -8163,6 +8220,7 @@ private void checkLiteral2(String expression, String 
expected) {
         + "FROM \"foodmart\".\"product\"";
     final String expectedPrestoSql = "SELECT APPROX_DISTINCT(\"product_id\")\n"
         + "FROM \"foodmart\".\"product\"";
+    final String expectedTrino = expectedPrestoSql;
     final String expectedStarRocksSql = expectedApprox;
     final String expectedMssql = "SELECT APPROX_COUNT_DISTINCT([product_id])\n"
         + "FROM [foodmart].[product]";
@@ -8177,6 +8235,7 @@ private void checkLiteral2(String expression, String 
expected) {
         .withOracle().ok(expectedApproxQuota)
         .withSnowflake().ok(expectedApproxQuota)
         .withPresto().ok(expectedPrestoSql)
+        .withTrino().ok(expectedTrino)
         .withStarRocks().ok(expectedStarRocksSql)
         .withMssql().ok(expectedMssql)
         .withPhoenix().ok(expectedPhoenix)
@@ -8861,6 +8920,7 @@ private void checkLiteral2(String expression, String 
expected) {
         + "ORDER BY `brand_name` NULLS LAST";
     sql(query)
         .withPresto().ok(expected)
+        .withTrino().ok(expected)
         .withSpark().ok(sparkExpected);
   }
 
@@ -8874,6 +8934,7 @@ private void checkLiteral2(String expression, String 
expected) {
         + "ORDER BY `brand_name` NULLS LAST";
     sql(query)
         .withPresto().ok(expected)
+        .withTrino().ok(expected)
         .withSpark().ok(sparkExpected);
   }
 
@@ -8887,6 +8948,7 @@ private void checkLiteral2(String expression, String 
expected) {
         + "ORDER BY `brand_name` NULLS LAST";
     sql(query)
         .withPresto().ok(expected)
+        .withTrino().ok(expected)
         .withSpark().ok(sparkExpected);
   }
 
@@ -8922,6 +8984,7 @@ private void checkLiteral2(String expression, String 
expected) {
         + "ORDER BY `brand_name`";
     sql(query)
         .withPresto().ok(expected)
+        .withTrino().ok(expected)
         .withSpark().ok(sparkExpected);
   }
 
@@ -8935,6 +8998,7 @@ private void checkLiteral2(String expression, String 
expected) {
         + "ORDER BY `brand_name` DESC NULLS FIRST";
     sql(query)
         .withPresto().ok(expected)
+        .withTrino().ok(expected)
         .withSpark().ok(sparkExpected);
   }
 
@@ -8948,6 +9012,7 @@ private void checkLiteral2(String expression, String 
expected) {
         + "ORDER BY `brand_name` DESC";
     sql(query)
         .withPresto().ok(expected)
+        .withTrino().ok(expected)
         .withSpark().ok(sparkExpected);
   }
 
@@ -8961,6 +9026,7 @@ private void checkLiteral2(String expression, String 
expected) {
         + "ORDER BY `brand_name` DESC NULLS FIRST";
     sql(query)
         .withPresto().ok(expected)
+        .withTrino().ok(expected)
         .withSpark().ok(sparkExpected);
   }
 
@@ -8971,12 +9037,14 @@ private void checkLiteral2(String expression, String 
expected) {
     final String query = "SELECT MAP['k1', 'v1', 'k2', 'v2']";
     final String expectedPresto = "SELECT MAP (ARRAY['k1', 'k2'], ARRAY['v1', 
'v2'])\n"
         + "FROM (VALUES (0)) AS \"t\" (\"ZERO\")";
+    final String expectedTrino = expectedPresto;
     final String expectedStarRocks = "SELECT MAP { 'k1' : 'v1', 'k2' : 'v2' }";
     final String expectedSpark = "SELECT MAP ('k1', 'v1', 'k2', 'v2')\n"
         + "FROM (VALUES (0)) `t` (`ZERO`)";
     final String expectedHive = "SELECT MAP ('k1', 'v1', 'k2', 'v2')";
     sql(query)
         .withPresto().ok(expectedPresto)
+        .withTrino().ok(expectedTrino)
         .withStarRocks().ok(expectedStarRocks)
         .withSpark().ok(expectedSpark)
         .withHive().ok(expectedHive);
@@ -8986,10 +9054,12 @@ private void checkLiteral2(String expression, String 
expected) {
     final String query = "SELECT MAP[ARRAY['k1', 'k2'], ARRAY['v1', 'v2']]";
     final String expectedPresto = "SELECT MAP (ARRAY['k1', 'k2'], ARRAY['v1', 
'v2'])\n"
         + "FROM (VALUES (0)) AS \"t\" (\"ZERO\")";
+    final String expectedTrino = expectedPresto;
     final String expectedSpark = "SELECT MAP (ARRAY ('k1', 'k2'), ARRAY ('v1', 
'v2'))\n"
         + "FROM (VALUES (0)) `t` (`ZERO`)";
     sql(query)
         .withPresto().ok(expectedPresto)
+        .withTrino().ok(expectedTrino)
         .withSpark().ok(expectedSpark);
   }
 
@@ -9297,7 +9367,9 @@ private void checkLiteral2(String expression, String 
expected) {
         + "from \"foodmart\".\"reserve_employee\" ";
     String expected = "SELECT CAST(CAST(\"employee_id\" AS VARCHAR) AS 
VARBINARY)"
         + "\nFROM \"foodmart\".\"reserve_employee\"";
-    sql(query).withPresto().ok(expected);
+    sql(query)
+        .withPresto().ok(expected)
+        .withTrino().ok(expected);
   }
 
   /** Test case for
@@ -9311,7 +9383,8 @@ private void checkLiteral2(String expression, String 
expected) {
         + "CAST(\"department_id\" AS DOUBLE), "
         + "CAST(\"department_id\" AS REAL)\nFROM \"foodmart\".\"employee\"";
     sql(query)
-        .withPresto().ok(expected);
+        .withPresto().ok(expected)
+        .withTrino().ok(expected);
   }
 
   /** Test case for
@@ -9607,6 +9680,10 @@ Sql withPresto() {
       return dialect(DatabaseProduct.PRESTO.getDialect());
     }
 
+    Sql withTrino() {
+      return dialect(DatabaseProduct.TRINO.getDialect());
+    }
+
     Sql withRedshift() {
       return dialect(DatabaseProduct.REDSHIFT.getDialect());
     }

Reply via email to