Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Changes to support Join Pushdown for JDBC Connectors #24992

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Haritha-Koloth
Copy link
Contributor

@Haritha-Koloth Haritha-Koloth commented Apr 28, 2025

Description

This PR implements connector-side support for join pushdown in JDBC connectors, leveraging the foundational changes introduced in 24115. The changes enable JDBC connectors to perform join pushdown by rebuilding the query to execute joins directly on the remote datasource.

Motivation and Context

Fixes 23152

Impact

This update includes the connector-side changes required to enable join pushdown in JDBC connectors, building on the foundational SPI and core changes introduced earlier.

Detailed RFC - prestodb/rfcs#32

Test Plan

Unit tests added for newly added logic

Contributor checklist

  • Please make sure your submission complies with our contributing guide, in particular code style and commit standards.
  • PR description addresses the issue accurately and concisely. If the change is non-trivial, a GitHub Issue is referenced.
  • Documented new properties (with its default value), SQL syntax, functions, or other functionality.
  • If release notes are required, they follow the release notes guidelines.
  • Adequate tests were added if applicable.
  • CI passed.

Release Notes

Please follow release notes guidelines and fill in the release notes below.

== NO RELEASE NOTE ==

@prestodb-ci prestodb-ci added the from:IBM PR from IBM label Apr 28, 2025
@Haritha-Koloth Haritha-Koloth force-pushed the pushdown_jdbc_connector branch 6 times, most recently from 0c6e27c to a707a80 Compare April 30, 2025 04:23
Co-Authored-By: Haritha Koloth <[email protected]>
Co-Authored-By: Glerin Pinhero <[email protected]>
Co-Authored-By: Thanzeel Hassan <[email protected]>
Co-Authored-By: Anant Aneja <[email protected]>
@Haritha-Koloth Haritha-Koloth force-pushed the pushdown_jdbc_connector branch from a707a80 to 70f9851 Compare April 30, 2025 05:02
@Haritha-Koloth Haritha-Koloth marked this pull request as ready for review April 30, 2025 06:45
@prestodb-ci prestodb-ci requested review from a team, namya28 and sh-shamsan and removed request for a team April 30, 2025 06:45
@aaneja aaneja self-requested a review April 30, 2025 06:53
Copy link
Contributor

@aaneja aaneja left a comment

Choose a reason for hiding this comment

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

Please refactor QueryBuilder to smaller methods that can be unit tested better. This will remove the need for large tests like TestJdbcQueryBuilderJoinPushdown IMO

@@ -2631,7 +2631,7 @@ private Session inferNullsFromJoinFiltersWithUseFunctionMetadata()
.build();
}

private long getTableRowCount(String tableName)
protected long getTableRowCount(String tableName)
Copy link
Contributor

Choose a reason for hiding this comment

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

This can remain private ?

}

@Test
public void testRowFieldAccessorInJoin()
Copy link
Contributor

Choose a reason for hiding this comment

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

The tests below this line are all identical to the base class. For these tests, please create a test class where AbstractTestQueryFramework#getSession is overriden and optimizer_inner_join_pushdown_enabled is enabled

@@ -88,7 +88,7 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<scope>test</scope>
<scope>provided</scope>
Copy link
Contributor

Choose a reason for hiding this comment

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

Was this accidental ?

@@ -58,13 +58,15 @@ public Map<ConnectorId, Set<ConnectorPlanOptimizer>> getOptimizers(PlanPhase pha
return ImmutableMap.copyOf(transformValues(planOptimizerProviders, ConnectorPlanOptimizerProvider::getLogicalPlanOptimizers));
case PHYSICAL:
return ImmutableMap.copyOf(transformValues(planOptimizerProviders, ConnectorPlanOptimizerProvider::getPhysicalPlanOptimizers));
case STRUCTURAL:
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's discuss offline on the need for STRUCTURAL. I think we can make do with just LOGICAL

columns1.get(1), Domain.onlyNull(DOUBLE)));

Connection connection = database.getConnection();
try (PreparedStatement preparedStatement = new QueryBuilder("\"").buildSql(jdbcClient, session, connection, "", "test_schema", "test_table_1", Optional.empty(), columns1, ImmutableMap.of(), tupleDomain, Optional.empty());
Copy link
Contributor

Choose a reason for hiding this comment

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

Please split parameters on different lines and keep line length under 180


List<ConnectorTableHandle> newConnectorTableHandles = new ArrayList<>();
Map<VariableReferenceExpression, ColumnHandle> groupAssignments = new HashMap<>();
final String aliasPrefix = "T";
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a comment here -
Generate aliases for each table being joined to avoid any ambuigious column name references. These aliases are used in QueryBuilder#buildSql

handle.getSchemaName(), handle.getTableName(), handle.getJoinTables(), Optional.of(aliasPrefix + (++tableCount)));
newConnectorTableHandles.add(newHandle);

// Update column handles using Streams
Copy link
Contributor

Choose a reason for hiding this comment

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

I couldn't understand this comment


/**
* JdbcJoinPushdown Optimizer:
* This Optimizer converts ConnectorHandleSet with various TableHandles to JdbcTableHandle which has list of all the JdbcTableHandles that can be pushed down.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* This Optimizer converts ConnectorHandleSet with various TableHandles to JdbcTableHandle which has list of all the JdbcTableHandles that can be pushed down.
* This Optimizer converts a {@link JoinTableSet} to a {@link JdbcTableHandle} with it's {@link JdbcTableHandle#joinTables} set to the
* those from {@link JoinTableSet#innerJoinTableInfos}


RowExpression remainingPredicates = logicalRowExpressions.combineConjuncts(remainingExpressions);
/// !!! For now, we only create a new FilterNode with the remaining predicates
// As per https://github.com/prestodb/presto/pull/16864, this is not sufficient and we should re-use the existing filter predicate for correctness
Copy link
Contributor

Choose a reason for hiding this comment

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

@rschlussel @NikhilCollooru
Do you recall what was the scenario where a partial pushdown of a filter (while retaining the non-pushed down part in Presto) was causing correctness issues mentioned in #16864 ?

We want to reintroduce the changes from #16412, and we'd like to know if we need to put these behind a feature-flag

Map<VariableReferenceExpression, ColumnHandle> symbolToColumnHandleMap)
{
if (tableHandle instanceof JoinTableSet) {
// We now have all relevant pieces to build a JdbcJoinPredicateToSqlTranslator to test if the passed in filter will translate to SQL
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this comment can be removed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
from:IBM PR from IBM
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement Jdbc join pushdown capabilities in presto
4 participants