Skip to content

Commit

Permalink
[CALCITE-6699] Invalid unparse for Varchar in StarRocksDialect
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaochen-zhou committed Jan 7, 2025
1 parent f3af90f commit fb7d844
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
*/
public class StarRocksSqlDialect extends MysqlSqlDialect {

/** StarRocks type system. */
public static final RelDataTypeSystem STARROCKS_TYPE_SYSTEM =
new RelDataTypeSystemImpl() {
@Override public int getMaxPrecision(SqlTypeName typeName) {
Expand Down Expand Up @@ -154,10 +155,8 @@ public StarRocksSqlDialect(Context context) {
SqlParserPos.ZERO),
SqlParserPos.ZERO);
case VARCHAR:
int vcMaxPrecision = this.getTypeSystem().getMaxPrecision(SqlTypeName.VARCHAR);
int precision = Math.min(type.getPrecision(), vcMaxPrecision);
return new SqlDataTypeSpec(
new SqlBasicTypeNameSpec(SqlTypeName.VARCHAR, precision, SqlParserPos.ZERO),
new SqlBasicTypeNameSpec(SqlTypeName.VARCHAR, type.getPrecision(), SqlParserPos.ZERO),
SqlParserPos.ZERO);
default:
return super.getCastSpec(type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3747,6 +3747,9 @@ private SqlDialect nonOrdinalDialect() {
sql(query).dialect(mySqlDialect(NullCollation.LAST)).ok(expected);
}

/** Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-6699">[CALCITE-6699]
* Invalid unparse for Varchar in StarRocksDialect </a>. */
@Test void testStarRocksCastToVarcharWithLessThanMaxPrecision() {
final String query = "select cast(\"product_id\" as varchar(50)), \"product_id\" "
+ "from \"product\" ";
Expand All @@ -3755,6 +3758,9 @@ private SqlDialect nonOrdinalDialect() {
sql(query).withStarRocks().ok(expected);
}

/** Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-6699">[CALCITE-6699]
* Invalid unparse for Varchar in StarRocksDialect </a>. */
@Test void testStarRocksCastToVarcharWithGreaterThanMaxPrecision() {
final String query = "select cast(\"product_id\" as varchar(150000)), \"product_id\" "
+ "from \"product\" ";
Expand All @@ -3763,6 +3769,9 @@ private SqlDialect nonOrdinalDialect() {
sql(query).withStarRocks().ok(expected);
}

/** Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-6699">[CALCITE-6699]
* Invalid unparse for Varchar in StarRocksDialect </a>. */
@Test void testStarRocksCastToVarcharWithDefaultPrecision() {
final String query = "select cast(\"product_id\" as varchar), \"product_id\" "
+ "from \"product\" ";
Expand Down

0 comments on commit fb7d844

Please sign in to comment.