Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-6695

Add Source SQL Dialect to RelToSqlConverterTest

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Duplicate
    • 1.38.0
    • 1.39.0
    • core
    • None

    Description

      Currently, RelToSqlConverterTest converts the original SQL to RelNode using the default validator config and the target dialect's type system. This is confusing because it's unclear whether the test is meant to verify the SQL conversion between different dialects or within the same dialect. I believe it should verify the conversion between source and target dialects. Therefore, we should clearly define the source and target dialects and provide a way to set them. The code would look like

      @Test void testNullCollation() {
        final String query = "select * from \"product\" order by \"brand_name\"";
        final String expected = "SELECT *\n"
            + "FROM \"foodmart\".\"product\"\n"
            + "ORDER BY \"brand_name\"";
        final String sparkExpected = "SELECT *\n"
            + "FROM `foodmart`.`product`\n"
            + "ORDER BY `brand_name` NULLS LAST";
        sql(query)
            .sourceDialect(PrestoSqlDialect.DEFAULT)
            .withPresto().ok(expected)
            .withSpark().ok(sparkExpected);
      } 

      We need also set correct null collation config using source dialect due to the source and target dialect have different null collations.

      For the case that the source dialect equals the target dialect

      @Test void testCastDecimalBigPrecision() {
        final String query = "select cast(\"product_id\" as decimal(60,2)) "
            + "from \"product\" ";
        final String expectedRedshift = "SELECT CAST(\"product_id\" AS DECIMAL(38, 2))\n"
            + "FROM \"foodmart\".\"product\"";
        sql(query)
            .withRedshift()
            .withSourceDialectEqualsTargetDialect()
            .ok(expectedRedshift);
      } 

      Attachments

        Activity

          People

            yanjing.wang yanjing.wang
            yanjing.wang yanjing.wang
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: