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

DRILL-8303: Add support for inserts into JDBC storage #2646

Merged
merged 2 commits into from
Sep 14, 2022

Conversation

vvysotskyi
Copy link
Member

DRILL-8303: Add support for inserts into JDBC storage

Description

This PR contains changes required for adding support for inserts into JDBC storage.
Inserting data is implemented based on generating and executing INSERT INTO ... VALUES() statements.
It is also possible to push down the complete INSERT INTO statement where possible (when using insert from values or another JDBC table).
Rewritten existing code for JDBC CTAS to use Calcite for generating CREATE TABLE and INSERT INTO statements, simplified reading values to write.
Added ability to match JDBC rules to both NONE and DRILL_LOGICAL conventions to allow the planner to push down more cases than before.

Documentation

Insert statement syntax completely matches Calcites definition and is the following:

{ INSERT | UPSERT } INTO tablePrimary [ '(' column [, column ]* ')' ] query

Where query is an arbitrary SQL query.

Testing

Added unit tests for inserts, existing tests pass.

@vvysotskyi vvysotskyi added the enhancement PRs that add a new functionality to Drill label Sep 10, 2022
@vvysotskyi vvysotskyi self-assigned this Sep 10, 2022
@cgivre cgivre added the doc-impacting PRs that affect the documentation label Sep 11, 2022
@cgivre cgivre linked an issue Sep 11, 2022 that may be closed by this pull request
@jnturton jnturton self-requested a review September 13, 2022 11:47
@@ -219,11 +220,14 @@ private static PhysicalPlan getQueryPlan(QueryContext context, String sql, Point
handler = new SetOptionHandler(context);
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like this case could be merged with default case on line 227. But then the code would be less explicit so I'm not requesting a change, just making a note.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, fixed it.

import org.slf4j.LoggerFactory;

/**
* Constructs plan to be executed for collecting metadata and storing it to the Metastore.
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this comment belongs here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, thanks, fixed.

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.JDBCType;
import java.util.List;

public class CreateTableStmtBuilder {
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for all the refactoring and clean up in this area.

import org.apache.drill.exec.record.BatchSchema;

@JsonTypeName("table_modify")
public class TableModify extends AbstractSingle {
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 operator called table_modify rather than, say, table_insert because it might be applied for other operations e.g. an upsert?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I see, the name table_modify comes from Calcite.

@@ -188,7 +188,7 @@ public RelNode convertChild(final RelNode topRel, final RelNode input) throws In
if (indexDesc.getCollation() != null &&
!settings.isIndexForceSortNonCovering()) {
collation = IndexPlanUtils.buildCollationNonCoveringIndexScan(indexDesc, indexScanRowType, dbscanRowType, indexContext);
if (restrictedScanTraitSet.contains(RelCollationTraitDef.INSTANCE)) { // replace existing trait
if (restrictedScanTraitSet.getTrait(RelCollationTraitDef.INSTANCE) != null) { // replace existing trait
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm curious about the benefit of rewriting this test this way...

Copy link
Member Author

Choose a reason for hiding this comment

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

The existing code wouldn't work as expected, trait set doesn't contain RelCollationTraitDef instances.

return b.build();
}

private static void foreachRule(JdbcConvention out,
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you give a short explanation of how this change relates to adding INSERT support? I can't trace it.

Copy link
Member Author

Choose a reason for hiding this comment

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

It is related not only to INSERT but to general JDBC functionality. With this change, rules will match not only to the NONE convention but also to the DRILL_LOGICAL one, so as a result, Drill will be able to push down more operators for complex queries, where possible.

Copy link
Contributor

@jnturton jnturton left a comment

Choose a reason for hiding this comment

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

Thanks for making changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc-impacting PRs that affect the documentation enhancement PRs that add a new functionality to Drill
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support RDBMS update, INSERT,delete
3 participants