-
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-3486] In JDBC adapter, when generating ROW value expression, generates the ROW keyword only if the dialect allows it (quxiucheng) #1568
Conversation
@@ -3699,6 +3700,14 @@ void checkPeriodPredicate(Checker checker) { | |||
.ok(expected); | |||
} | |||
|
|||
@Test public void testInsertDialect() { | |||
// See [CALCITE-3486] MysqlSqlDialect unparse ROW keyword does not exist |
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.
You don't need this comment. If you actually want to say this test is testing ROW
, you can rename this test as testInsertWithRowDialect
.
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.
Thank you.
modified
bcdaa55
to
0e30131
Compare
LGTM |
@@ -179,6 +179,9 @@ public boolean supportsAliasedValues() { | |||
|
|||
unparseFloor(writer, call); | |||
break; | |||
case ROW: | |||
unparseRow(writer, call); |
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 for the fix @quxiucheng, i think this patch can be promoted a little, we can move this logic to the parent class SqlDialect
, you can get the SqlConformance
from the dialect and decide if we should generates the ROW
keyword based on method SqlConformance#allowExplicitRowValueConstructor
.
[1]
boolean allowExplicitRowValueConstructor(); |
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.
done.
but the class SqlDialect
can't get the method SqlConformance#allowExplicitRowValueConstructor
correctly. I added a field in the class SqlDialect
, Same as the field 'SqlConformance#allowExplicitRowValueConstructor'
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.
What do you mean by "can not get method correctly", for MySQL, the conformance is SqlConformanceEnum.MYSQL_5
which i think is correct.
[1]
@Nonnull public SqlConformance getConformance() { |
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.
We have two ways of creating dialects.
- XxxSqlDialect.DEFAULT
- SqlDialect.DatabaseProduct.XXX.getDialect()
If we only call org.apache.calcite.sql.SqlDialect#getConformance
this method to get conformance
.
Only compatible SqlDialect.DatabaseProduct.XXX.getDialect()
method. So I reset a parameter allowExplicitRowValueConstructor
to be compatible with both ways of creating the dialect.
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.
XxxSqlDialect.DEFAULT
also works, if we have set up the DatabaseProduct
correctly. There is no overridden of method SqlDialect#getConformance
, so i believe the behavior is correct.
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 see.Thanks.
I have a question:
the method SqlConformanceEnum#allowExplicitRowValueConstructor
public boolean allowExplicitRowValueConstructor() {
switch (this) {
case DEFAULT:
case LENIENT:
return true;
default:
return false;
}
}
Only SqlConformanceEnum#DEFAULT
and SqlConformanceEnum#LENIENT
return values are true.
If this standard doesn't change. Test classes are mostly used by default method SqlConformanceEnum#PRAGMATIC_2003
,
unparse
will then have a lot of ROW
keyword changes. Because they don't support the ROW
keyword.
Should I add SqlConformanceEnum#PRAGMATIC_2003
to a method SqlConformanceEnum#allowExplicitRowValueConstructor
or change the test class.
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.
The return value "true" means we would print the "ROW" keyword, for SqlConformanceEnum#PRAGMATIC_2003
, it is expected to not allows that.
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.
Okay, I'm going to rewrite the code
@@ -3699,6 +3700,13 @@ void checkPeriodPredicate(Checker checker) { | |||
.ok(expected); | |||
} | |||
|
|||
@Test public void testInsertWithRowDialect() { | |||
final String expected = "INSERT INTO `emps`\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.
Maybe we can rename this method to testRowValueExpression
and we should test dialect that allows/not allow explicit ROW
keywords.
ce9dffa
to
5357f0c
Compare
@@ -158,6 +158,7 @@ | |||
private final Casing unquotedCasing; | |||
private final Casing quotedCasing; | |||
private final boolean caseSensitive; | |||
private final boolean allowExplicitRowValueConstructor; | |||
|
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.
Remove this allowExplicitRowValueConstructor
flag, we expect to get this info from the SqlConformance
.
expected = "INSERT INTO `emps`\n" | ||
+ "VALUES (1, 'Fred'),\n" | ||
+ "(2, 'Eric')"; | ||
sql("insert into emps values (1,'Fred'),(2, 'Eric')") |
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.
Why different value for sql() method? Shall we use the same.
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.
sorry,I didn't notice that
Write the wrong
d0a6a47
to
bb45dbc
Compare
} | ||
if (writer.isAlwaysUseParentheses()) { | ||
for (SqlNode operand : call.getOperandList()) { | ||
writer.sep(","); |
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.
Can you explain why we need this decision ?
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.
This isAlwaysUseParentheses
parameter will link operations with parentheses.
For example ,
(a + b) * c
.The fully-parenthesized expression, ((a + b) * c)
If this parameter is in the SqlRowOperator
. There will be extra parentheses
For example,
isAlwaysUseParentheses=true
and allowExplicitRowValueConstructor=false
input expression:
insert into emp valuse (1,'a')
unparse result:
insert into emp valuse ((1,'a'))
I think this is a wrong SQL.
@@ -82,7 +82,7 @@ public void unparse( | |||
SqlCall call, | |||
int leftPrec, | |||
int rightPrec) { | |||
SqlUtil.unparseFunctionSyntax(this, writer, call); | |||
writer.getDialect().unparseRow(writer, call, leftPrec, rightPrec); | |||
} |
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.
We should not modify the unparse logic of SqlRowOperator
, instead in SqlDialect
, match the ROW
call and unparse it specifically.
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.
okay. done
… generates the ROW keyword only if the dialect allows it
bb45dbc
to
1b5c110
Compare
… generates the ROW keyword only if the dialect allows it (quxiucheng) In JDBC adapter, unparse the ROW keyword for ROW value expression only if the SQL dialect allows it. Fix-up (by Danny): * Simplify the logic for ROW value expression in SqlDialect#unparseCall * Add test cases in RelToSqlConverterTest * Fix SqlParserTest, there is no need to introduce new kind of SQL dialect close apache#1568
… generates the ROW keyword only if the dialect allows it (quxiucheng) In JDBC adapter, unparse the ROW keyword for ROW value expression only if the SQL dialect allows it. Fix-up (by Danny): * Simplify the logic for ROW value expression in SqlDialect#unparseCall * Add test cases in RelToSqlConverterTest * Fix SqlParserTest, there is no need to introduce new kind of SQL dialect close apache#1568
… generates the ROW keyword only if the dialect allows it (quxiucheng) In JDBC adapter, unparse the ROW keyword for ROW value expression only if the SQL dialect allows it. Fix-up (by Danny): * Simplify the logic for ROW value expression in SqlDialect#unparseCall * Add test cases in RelToSqlConverterTest * Fix SqlParserTest, there is no need to introduce new kind of SQL dialect close apache#1568
… generates the ROW keyword only if the dialect allows it (quxiucheng) In JDBC adapter, unparse the ROW keyword for ROW value expression only if the SQL dialect allows it. Fix-up (by Danny): * Simplify the logic for ROW value expression in SqlDialect#unparseCall * Add test cases in RelToSqlConverterTest * Fix SqlParserTest, there is no need to introduce new kind of SQL dialect close apache#1568
… generates the ROW keyword only if the dialect allows it (quxiucheng) In JDBC adapter, unparse the ROW keyword for ROW value expression only if the SQL dialect allows it. Fix-up (by Danny): * Simplify the logic for ROW value expression in SqlDialect#unparseCall * Add test cases in RelToSqlConverterTest * Fix SqlParserTest, there is no need to introduce new kind of SQL dialect close apache/calcite#1568 (cherry picked from commit ce0118b)
… generates the ROW keyword only if the dialect allows it (quxiucheng) In JDBC adapter, unparse the ROW keyword for ROW value expression only if the SQL dialect allows it. Fix-up (by Danny): * Simplify the logic for ROW value expression in SqlDialect#unparseCall * Add test cases in RelToSqlConverterTest * Fix SqlParserTest, there is no need to introduce new kind of SQL dialect close apache/calcite#1568 (cherry picked from commit ce0118b)
MysqlSqlDialect unparse ROW keyword does not exist