-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CALCITE-6699] Invalid unparse for Varchar in StarRocksDialect #4123
Conversation
core/src/main/java/org/apache/calcite/sql/dialect/StarRocksSqlDialect.java
Show resolved
Hide resolved
core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
Show resolved
Hide resolved
ece76dc
to
41d4e9f
Compare
Hi @xiaochen-zhou , you don't need to force-push for every commit, and it helps other reviewers to see the changes better. |
OK. Thank you for your reminder. |
core/src/main/java/org/apache/calcite/sql/dialect/StarRocksSqlDialect.java
Show resolved
Hide resolved
core/src/main/java/org/apache/calcite/sql/dialect/StarRocksSqlDialect.java
Outdated
Show resolved
Hide resolved
core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
Outdated
Show resolved
Hide resolved
core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
Outdated
Show resolved
Hide resolved
@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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this supposed to change the precision silently, or should this at least produce a warning?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mihaibudiu I noticed that our default implementation silently changes the conversion in SQLTypeUtil.convertTypeToSpec
, so I think there is no problem here.
I have updated the code. Please take a look when you have time. @mihaibudiu @NobiGo @ILuffZhe |
@@ -128,6 +153,10 @@ public StarRocksSqlDialect(Context context) { | |||
type.getSqlTypeName(), | |||
SqlParserPos.ZERO), | |||
SqlParserPos.ZERO); | |||
case VARCHAR: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remember we discussed this issue before. Does StarRocks have any restrictions on varchar types, such as varchar(65533)? If so, please explain it, at least add JavaDoc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks
public static final RelDataTypeSystem STARROCKS_TYPE_SYSTEM = | ||
new RelDataTypeSystemImpl() { | ||
@Override public int getMaxPrecision(SqlTypeName typeName) { | ||
switch (typeName) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add JavaDoc
@@ -3747,6 +3747,30 @@ private SqlDialect nonOrdinalDialect() { | |||
sql(query).dialect(mySqlDialect(NullCollation.LAST)).ok(expected); | |||
} | |||
|
|||
@Test void testStarRocksCastToVarcharWithLessThanMaxPrecision() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add jira link
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add jira link
Done.
c0b92bf
to
fb7d844
Compare
fb7d844
to
d60676d
Compare
Quality Gate passedIssues Measures |
I have updated the code. Please take a look when you have time. @mihaibudiu @NobiGo @ILuffZhe @caicancai |
When performing starrocks dialect conversion for varchar, it defaults to using MySQL dialect,MySQL doesn't have a VARCHAR type, only CHAR,So during StarRocks dialect conversion, VARCHAR will also be converted to CHAR
Since StarRocks supports the VARCHAR type, we should modify the StarRocks dialect
https://docs.starrocks.io/docs/sql-reference/data-types/string-type/VARCHAR/