Skip to content

[CALCITE-1527] Support DML in the JDBC adapter#334

Closed
tzolov wants to merge 7 commits intoapache:masterfrom
tzolov:CALCITE-1527
Closed

[CALCITE-1527] Support DML in the JDBC adapter#334
tzolov wants to merge 7 commits intoapache:masterfrom
tzolov:CALCITE-1527

Conversation

@tzolov
Copy link
Copy Markdown
Contributor

@tzolov tzolov commented Dec 5, 2016

  • I had to align the SqlUpdate's RowType with the rest of DML operations [42a5461]. 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 ) [9c8f141].
    The sourceExpressionList is initialized from the SqlUpdate:
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);
    }
....

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?

  • [658cc90] 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.

@tzolov
Copy link
Copy Markdown
Contributor Author

tzolov commented Dec 5, 2016

Note: [edc28ad] resolves a strange problem that i unintentionally have caused. Apparently we need to keep the connection and statement open after the execute(sql). By setting their fields to null we prevent the final block from closing them.

@asfgit asfgit closed this in a283782 Dec 20, 2016
ldming pushed a commit to ldming/mycalcite that referenced this pull request Sep 13, 2018
…ger modulo N (Julian Feinauer)

Close apache/calcite#339

A previous PR I forgot to close:
Close apache/calcite#334
jamesstarr pushed a commit to jamesstarr/calcite that referenced this pull request Mar 16, 2026
apache#334)

…so that rule match order is deterministic across runs

Co-authored-by: botong.huang <botong.huang@alibaba-inc.com>
jamesstarr pushed a commit to jamesstarr/calcite that referenced this pull request Mar 16, 2026
apache#334)

…so that rule match order is deterministic across runs

Co-authored-by: botong.huang <botong.huang@alibaba-inc.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant