Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ public OracleSqlDialect(Context context) {
case DOUBLE:
castSpec = "DOUBLE PRECISION";
break;
case VARCHAR:
if (type.getPrecision() == RelDataType.PRECISION_NOT_SPECIFIED) {
final int precision = getTypeSystem().getMaxPrecision(SqlTypeName.VARCHAR);
castSpec = "VARCHAR(" + precision + ")";
break;
}
return super.getCastSpec(type);
default:
return super.getCastSpec(type);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1708,6 +1708,21 @@ private static String toSql(RelNode root, SqlDialect dialect,
.ok(expectedOracle);
}

/** Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-7563">[CALCITE-7563]
* Oracle dialect generates invalid CAST to VARCHAR without precision</a>. */
@Test void testCastVarcharWithoutPrecisionOracle() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume you have already tested these sql in Oracle.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review. I have tested the SQL against a real Oracle instance and here https://onecompiler.com/oracle/44qmsuytf

final String query = "select cast(\"store_id\" as VARCHAR)\n"
+ " from \"expense_fact\"";
final String expected = "SELECT CAST(\"store_id\" AS VARCHAR(4000))\n"
+ "FROM \"foodmart\".\"expense_fact\"";
final String expectedModifiedTypeSystem = "SELECT CAST(\"store_id\" AS VARCHAR(512))\n"
+ "FROM \"foodmart\".\"expense_fact\"";
sql(query)
.withOracle().ok(expected)
.withOracleModifiedTypeSystem().ok(expectedModifiedTypeSystem);
}

/** Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-1174">[CALCITE-1174]
* When generating SQL, translate SUM0(x) to COALESCE(SUM(x), 0)</a>. */
Expand Down
Loading