[
https://issues.apache.org/jira/browse/CALCITE-1527?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15721810#comment-15721810
]
Christian Tzolov commented on CALCITE-1527:
-------------------------------------------
Here is the first PR: https://github.com/apache/calcite/pull/334
* I had to align the SqlUpdate's RowType with the rest of DML operations
[https://github.com/apache/calcite/pull/334/commits/42a5461c6341ae89f444fdccb99f10e744fa4393].
Note that the DML operations (update including) return rowcount instead of
ResultSet
* UPDATE implementation requires access to the SET source expressions. While
TableModify provides the SET column names it misses the set value expressions.
Therefore I've added a new field: List<RexNode> sourceExpressionList to
TableModify (and updated many impacted classes )
[https://github.com/apache/calcite/pull/334/commits/9c8f141771709b2ab2d2461b7f37f6cb48d0a1c4].
The sourceExpressionList is initialized from the SqlUpdate:
{code}
private RelNode convertUpdate(SqlUpdate call) {
final SqlValidatorScope scope =
validator.getWhereScope(call.getSourceSelect());
Blackboard bb = createBlackboard(scope, null, false);
Builder<RexNode> rexNodeSourceExpressionListBuilder =
ImmutableList.builder();
for (SqlNode n: call.getSourceExpressionList()) {
RexNode rn = bb.convertExpression(n);
rexNodeSourceExpressionListBuilder.add(rn);
}
....
{code}
It works for the common use cases but failed with update sub-queries. Check the
RelToSqlConverter#testUpdateSubQuery! I guess there is a better way to resolve
the source expressions for sub-query?
*
[https://github.com/apache/calcite/pull/334/commits/658cc90461e3e822638405c19bfa463b5cbc1d77]
Implements the Rel to SQL for the INSERT, UPDATE and DELETE operations. Note
that DML returns row count instead of ResultSet. To support DML result i had to
change the hardcoded statement.executeQuery(sql) (in ResultSetEnumerable) into
boolean isResultSetProvided = statement.execute(sql) and handle the result
according to the isResultSetProvided.
To Support the Insert i had to make the JdbcTable a ModifiableTable - later is
marked as experimental?
Also i had to lower the JdbcTableModify cost (super.computeSelfCost(planner,
mq).multiplyBy(.1)) to make it win over the EnumberableTableModify.
> Support DML in the JDBC adapter
> -------------------------------
>
> Key: CALCITE-1527
> URL: https://issues.apache.org/jira/browse/CALCITE-1527
> Project: Calcite
> Issue Type: Bug
> Components: jdbc-adapter
> Reporter: Christian Tzolov
>
> Currently the JDBC adapter does not support the DML operations: *INSERT*,
> *DELETE* and *UPDATE*.
> Solution needs to convert the parsed *Modify* and *Values* RelNodes into
> *JdbcTableModify*, *JdbcValues* ... such and then in turn into corresponding
> SqlInsert, SqlUpdate and SqlDelete.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)