NobiGo commented on code in PR #4123:
URL: https://github.com/apache/calcite/pull/4123#discussion_r1903391019
##########
core/src/main/java/org/apache/calcite/sql/dialect/StarRocksSqlDialect.java:
##########
@@ -128,6 +153,15 @@ public StarRocksSqlDialect(Context context) {
type.getSqlTypeName(),
SqlParserPos.ZERO),
SqlParserPos.ZERO);
+ case VARCHAR:
+ int vcMaxPrecision =
this.getTypeSystem().getMaxPrecision(SqlTypeName.VARCHAR);
+ int precision = type.getPrecision();
+ if (vcMaxPrecision > 0 && precision > vcMaxPrecision) {
Review Comment:
The precision can be negative? Maybe we don't need `vcMaxPrecision > 0`?
##########
core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java:
##########
@@ -3747,6 +3747,46 @@ private SqlDialect nonOrdinalDialect() {
sql(query).dialect(mySqlDialect(NullCollation.LAST)).ok(expected);
}
+ @Test void testStarRocksCastToVarcharWithLessThanMaxPrecision() {
+ final String query = "select cast(\"product_id\" as varchar(50)),
\"product_id\" "
+ + "from \"product\" ";
+ final String expected = "SELECT CAST(`product_id` AS VARCHAR(50)),
`product_id`\n"
+ + "FROM `foodmart`.`product`";
+ sql(query).withStarRocks().ok(expected);
+ }
+
+ @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(65533)),
`product_id`\n"
+ + "FROM `foodmart`.`product`";
+ sql(query).withStarRocks().ok(expected);
+ }
+
+ @Test void testStarRocksCastToVarcharWithOutPrecision() {
Review Comment:
testStarRocksCastToVarcharWithDefaultPrecision?
##########
core/src/main/java/org/apache/calcite/sql/dialect/StarRocksSqlDialect.java:
##########
@@ -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:
Review Comment:
This info is very helpful. Please add the link in the Jira.
##########
core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java:
##########
@@ -3747,6 +3747,46 @@ private SqlDialect nonOrdinalDialect() {
sql(query).dialect(mySqlDialect(NullCollation.LAST)).ok(expected);
}
+ @Test void testStarRocksCastToVarcharWithLessThanMaxPrecision() {
+ final String query = "select cast(\"product_id\" as varchar(50)),
\"product_id\" "
+ + "from \"product\" ";
+ final String expected = "SELECT CAST(`product_id` AS VARCHAR(50)),
`product_id`\n"
+ + "FROM `foodmart`.`product`";
+ sql(query).withStarRocks().ok(expected);
+ }
+
+ @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(65533)),
`product_id`\n"
+ + "FROM `foodmart`.`product`";
+ sql(query).withStarRocks().ok(expected);
+ }
+
+ @Test void testStarRocksCastToVarcharWithOutPrecision() {
+ final String query = "select cast(\"product_id\" as varchar),
\"product_id\" "
+ + "from \"product\" ";
+ final String expected = "SELECT CAST(`product_id` AS VARCHAR),
`product_id`\n"
+ + "FROM `foodmart`.`product`";
+ sql(query).withStarRocks().ok(expected);
+ }
+
+ @Test void testStarRocksCastToVarbinaryWithLessThanMaxPrecision() {
+ final String query = "select CAST(x'ABCDEF12' AS VARBINARY(2)),
\"product_id\" "
Review Comment:
Why do we need constant literal to test this?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]