Skip to content

Commit

Permalink
Add STARROCKS_TYPE_SYSTEM
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaochen-zhou committed Jan 4, 2025
1 parent 1d41ccb commit ece76dc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import org.apache.calcite.avatica.util.TimeUnitRange;
import org.apache.calcite.config.NullCollation;
import org.apache.calcite.rel.type.RelDataType;
import org.apache.calcite.rel.type.RelDataTypeSystem;
import org.apache.calcite.rel.type.RelDataTypeSystemImpl;
import org.apache.calcite.sql.SqlAbstractDateTimeLiteral;
import org.apache.calcite.sql.SqlAlienSystemTypeNameSpec;
import org.apache.calcite.sql.SqlBasicTypeNameSpec;
Expand All @@ -41,9 +43,32 @@
*/
public class StarRocksSqlDialect extends MysqlSqlDialect {

public static final RelDataTypeSystem STARROCKS_TYPE_SYSTEM =
new RelDataTypeSystemImpl() {
@Override public int getMaxPrecision(SqlTypeName typeName) {
switch (typeName) {
case CHAR:
return 255;
case VARCHAR:
return 65533;
case VARBINARY:
return 1048576;
default:
return super.getMaxPrecision(typeName);
}
}
@Override public int getDefaultPrecision(SqlTypeName typeName) {
if (typeName == SqlTypeName.CHAR) {
return RelDataType.PRECISION_NOT_SPECIFIED;
}
return super.getDefaultPrecision(typeName);
}
};

public static final SqlDialect.Context DEFAULT_CONTEXT = SqlDialect.EMPTY_CONTEXT
.withDatabaseProduct(SqlDialect.DatabaseProduct.STARROCKS)
.withIdentifierQuoteString("`")
.withDataTypeSystem(STARROCKS_TYPE_SYSTEM)
.withNullCollation(NullCollation.LOW);

public static final SqlDialect DEFAULT = new StarRocksSqlDialect(DEFAULT_CONTEXT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3758,7 +3758,7 @@ private SqlDialect nonOrdinalDialect() {
@Test void testStarRocksCastToVarcharWithGreaterThanMaxPrecision() {
final String query = "select cast(\"product_id\" as varchar(150000)), \"product_id\" "
+ "from \"product\" ";
final String expected = "SELECT CAST(`product_id` AS VARCHAR(65536)), `product_id`\n"
final String expected = "SELECT CAST(`product_id` AS VARCHAR(65533)), `product_id`\n"
+ "FROM `foodmart`.`product`";
sql(query).withStarRocks().ok(expected);
}
Expand Down

0 comments on commit ece76dc

Please sign in to comment.