Skip to content
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

Merged
merged 1 commit into from
Jan 8, 2025

Conversation

xiaochen-zhou
Copy link
Contributor

@xiaochen-zhou xiaochen-zhou commented Jan 4, 2025

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

image

https://docs.starrocks.io/docs/sql-reference/data-types/string-type/VARCHAR/

@ILuffZhe
Copy link
Contributor

ILuffZhe commented Jan 6, 2025

Hi @xiaochen-zhou , you don't need to force-push for every commit, and it helps other reviewers to see the changes better.

@xiaochen-zhou
Copy link
Contributor Author

https://issues.apache.org/jira/projects/CALCITE/issues/CALCITE-6699

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.

@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"
Copy link
Contributor

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?

Copy link
Contributor

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.

@xiaochen-zhou
Copy link
Contributor Author

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:
Copy link
Member

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.

Copy link
Contributor Author

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 are restrictions.

image

Calcite will truncate according to the maximum precision. I have added test cases
image

Copy link
Member

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) {
Copy link
Member

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() {
Copy link
Member

Choose a reason for hiding this comment

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

Add jira link

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Add jira link

Done.

@mihaibudiu mihaibudiu added the LGTM-will-merge-soon Overall PR looks OK. Only minor things left. label Jan 7, 2025
@xiaochen-zhou
Copy link
Contributor Author

I have updated the code. Please take a look when you have time. @mihaibudiu @NobiGo @ILuffZhe @caicancai

@mihaibudiu mihaibudiu merged commit c7724b4 into apache:main Jan 8, 2025
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LGTM-will-merge-soon Overall PR looks OK. Only minor things left.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants