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

Refactor create/insert base jdbc client #19224

Merged

Conversation

vlad-lyutenko
Copy link
Contributor

@vlad-lyutenko vlad-lyutenko commented Oct 2, 2023

today we have lots of connectors which override entire beginInsert method for example even though they just want to change the generated query. And then over time the super impl improves to handle bugs or new features for example but the overridden code starts getting stale

Description

Additional context and related issues

Release notes

(x) This is not user-visible or is docs only, and no release notes are required.
( ) Release notes are required. Please propose a release note for me.
( ) Release notes are required, with the following suggested text:

# Section
* Fix some things. ({issue}`issuenumber`)

today we have lots of connectors which override entire beginInsert
method for example even though they just want to change the generated query.
And then over time the super impl improves to handle bugs or new features
for example but the overridden code starts getting stale
@cla-bot cla-bot bot added the cla-signed label Oct 2, 2023
@vlad-lyutenko vlad-lyutenko requested a review from hashhar October 2, 2023 10:52
Comment on lines +662 to +680
for (ColumnMetadata column : columns) {
String columnName = identifierMapping.toRemoteColumnName(remoteIdentifiers, column.getName());
verifyColumnName(connection.getMetaData(), columnName);
columnNames.add(columnName);
columnTypes.add(column.getType());
columnList.add(getColumnDefinitionSql(session, column, columnName));
}

Optional<String> pageSinkIdColumnName = Optional.empty();
if (pageSinkIdColumn.isPresent()) {
String columnName = identifierMapping.toRemoteColumnName(remoteIdentifiers, pageSinkIdColumn.get().getName());
pageSinkIdColumnName = Optional.of(columnName);
verifyColumnName(connection.getMetaData(), columnName);
columnList.add(getColumnDefinitionSql(session, pageSinkIdColumn.get(), columnName));
}

RemoteTableName remoteTableName = new RemoteTableName(Optional.ofNullable(catalog), Optional.ofNullable(remoteSchema), remoteTargetTableName);
for (String sql : createTableSqls(remoteTableName, columnList.build(), tableMetadata)) {
execute(session, connection, sql);
Copy link
Member

Choose a reason for hiding this comment

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

let's keep just this section as the overridable part because this is the section which generates SQL via getColumnDefinitionSql and createTableSqls. Everything above this is something which MUST be common for all base-jdbc connectors anyway since it includes identifier mapping and naming rules.

Same for all the other methods.

@vlad-lyutenko vlad-lyutenko force-pushed the vlad-lyutenko/rfct-insert-merge-jdbc branch from 87a5218 to 5a06e25 Compare October 4, 2023 08:19
@vlad-lyutenko vlad-lyutenko requested a review from hashhar October 4, 2023 19:11
Copy link
Member

@hashhar hashhar left a comment

Choose a reason for hiding this comment

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

Thanks. LGTM.

Can you please squash the commits?

Nevermind, I can use "Squash and merge" button.

@hashhar hashhar merged commit 254457d into trinodb:master Oct 11, 2023
@github-actions github-actions bot added this to the 429 milestone Oct 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants