-
Notifications
You must be signed in to change notification settings - Fork 136
Add Join operator support for Generic JDBC platform #708
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
mohit-devlogs
wants to merge
4
commits into
apache:main
Choose a base branch
from
mohit-devlogs:jdbc-join-operator
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
dfa48fe
Wayang-707 Add Generic JDBC Join operator
mohit-devlogs cf057f9
Add unit test for GenericJdbcJoinOperator
mohit-devlogs 7e7870d
Fix GenericJdbcTableSource jdbcName handling causing incorrect config…
mohit-devlogs 96319fc
Fix GenericJdbcJoinOperatorTest and GenericJdbcFilterOperatorTest SQL…
mohit-devlogs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
.../wayang-generic-jdbc/src/main/java/org/apache/wayang/genericjdbc/mapping/JoinMapping.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.wayang.genericjdbc.mapping; | ||
|
|
||
| import org.apache.wayang.basic.data.Record; | ||
| import org.apache.wayang.basic.operators.JoinOperator; | ||
| import org.apache.wayang.core.mapping.Mapping; | ||
| import org.apache.wayang.core.mapping.OperatorPattern; | ||
| import org.apache.wayang.core.mapping.PlanTransformation; | ||
| import org.apache.wayang.core.mapping.ReplacementSubplanFactory; | ||
| import org.apache.wayang.core.mapping.SubplanPattern; | ||
| import org.apache.wayang.core.types.DataSetType; | ||
| import org.apache.wayang.genericjdbc.operators.GenericJdbcJoinOperator; | ||
| import org.apache.wayang.genericjdbc.platform.GenericJdbcPlatform; | ||
|
|
||
| import java.util.Collection; | ||
| import java.util.Collections; | ||
|
|
||
| /** | ||
| * Mapping from {@link JoinOperator} to {@link GenericJdbcJoinOperator}. | ||
| */ | ||
| @SuppressWarnings("unchecked") | ||
| public class JoinMapping implements Mapping { | ||
|
|
||
| @Override | ||
| public Collection<PlanTransformation> getTransformations() { | ||
| return Collections.singleton(new PlanTransformation( | ||
| this.createSubplanPattern(), | ||
| this.createReplacementSubplanFactory(), | ||
| GenericJdbcPlatform.getInstance() | ||
| )); | ||
| } | ||
|
|
||
| private SubplanPattern createSubplanPattern() { | ||
|
|
||
| final OperatorPattern<JoinOperator<Record, Record, ?>> operatorPattern = | ||
| new OperatorPattern<>( | ||
| "join", | ||
| new JoinOperator<>(null, null, | ||
| DataSetType.createDefault(Record.class), | ||
| DataSetType.createDefault(Record.class)), | ||
| false | ||
| ); | ||
|
|
||
| return SubplanPattern.createSingleton(operatorPattern); | ||
| } | ||
|
|
||
| private ReplacementSubplanFactory createReplacementSubplanFactory() { | ||
| return new ReplacementSubplanFactory.OfSingleOperators<JoinOperator>( | ||
| (matchedOperator, epoch) -> | ||
| new GenericJdbcJoinOperator<>(matchedOperator).at(epoch) | ||
| ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...c-jdbc/src/main/java/org/apache/wayang/genericjdbc/operators/GenericJdbcJoinOperator.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.wayang.genericjdbc.operators; | ||
|
|
||
| import org.apache.wayang.basic.data.Record; | ||
| import org.apache.wayang.basic.operators.JoinOperator; | ||
| import org.apache.wayang.core.function.TransformationDescriptor; | ||
| import org.apache.wayang.jdbc.operators.JdbcJoinOperator; | ||
|
|
||
| /** | ||
| * Generic JDBC implementation of the {@link JoinOperator}. | ||
| */ | ||
| public class GenericJdbcJoinOperator<KeyType> | ||
| extends JdbcJoinOperator<KeyType> | ||
| implements GenericJdbcExecutionOperator { | ||
|
|
||
| public GenericJdbcJoinOperator( | ||
| TransformationDescriptor<Record, KeyType> keyDescriptor0, | ||
| TransformationDescriptor<Record, KeyType> keyDescriptor1) { | ||
| super(keyDescriptor0, keyDescriptor1); | ||
| } | ||
|
|
||
| public GenericJdbcJoinOperator(JoinOperator<Record, Record, KeyType> that) { | ||
| super(that); | ||
| } | ||
|
|
||
| @Override | ||
| protected GenericJdbcJoinOperator<KeyType> createCopy() { | ||
| return new GenericJdbcJoinOperator<>(this); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
...bc/src/test/java/org/apache/wayang/genericjdbc/operators/GenericJdbcJoinOperatorTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| package org.apache.wayang.genericjdbc.operators; | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to you under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| import org.apache.wayang.basic.data.Record; | ||
| import org.apache.wayang.basic.data.Tuple2; | ||
| import org.apache.wayang.basic.operators.JoinOperator; | ||
| import org.apache.wayang.basic.operators.LocalCallbackSink; | ||
| import org.apache.wayang.core.api.Configuration; | ||
| import org.apache.wayang.core.api.WayangContext; | ||
| import org.apache.wayang.core.function.TransformationDescriptor; | ||
| import org.apache.wayang.core.plan.wayangplan.WayangPlan; | ||
| import org.apache.wayang.genericjdbc.GenericJdbc; | ||
| import org.apache.wayang.genericjdbc.platform.GenericJdbcPlatform; | ||
| import org.apache.wayang.java.platform.JavaPlatform; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.sql.Connection; | ||
| import java.sql.DriverManager; | ||
| import java.sql.Statement; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
|
||
| class GenericJdbcJoinOperatorTest { | ||
|
|
||
| @Test | ||
| void testJoinExecution() throws Exception { | ||
|
|
||
| String url = "jdbc:hsqldb:mem:wayang_test_db;DB_CLOSE_DELAY=-1"; | ||
|
|
||
| Class.forName("org.hsqldb.jdbcDriver"); | ||
|
|
||
| try (Connection conn = DriverManager.getConnection(url, "SA", "")) { | ||
| Statement stmt = conn.createStatement(); | ||
|
|
||
| stmt.execute("CREATE TABLE T1 (A INT, VAL1 VARCHAR(20));"); | ||
| stmt.execute("INSERT INTO T1 VALUES (1, 'Apache');"); | ||
|
|
||
| stmt.execute("CREATE TABLE T2 (A INT, VAL2 INT);"); | ||
| stmt.execute("INSERT INTO T2 VALUES (1, 2026);"); | ||
| } | ||
|
|
||
| Configuration config = new Configuration(); | ||
| config.setProperty("wayang.genericjdbc.jdbc.url", url); | ||
| config.setProperty("wayang.genericjdbc.jdbc.user", "SA"); | ||
| config.setProperty("wayang.genericjdbc.jdbc.password", ""); | ||
| config.setProperty("wayang.genericjdbc.jdbc.driverName", "org.hsqldb.jdbcDriver"); | ||
|
|
||
| GenericJdbcTableSource source1 = new GenericJdbcTableSource("T1", "A", "VAL1"); | ||
| GenericJdbcTableSource source2 = new GenericJdbcTableSource("T2", "A", "VAL2"); | ||
|
|
||
| TransformationDescriptor<Record, Integer> keyExtractor0 = | ||
| new TransformationDescriptor<>( | ||
| r -> (Integer) r.getField(0), | ||
| Record.class, | ||
| Integer.class | ||
| ).withSqlImplementation("T1", "A"); | ||
|
|
||
| TransformationDescriptor<Record, Integer> keyExtractor1 = | ||
| new TransformationDescriptor<>( | ||
| r -> (Integer) r.getField(0), | ||
| Record.class, | ||
| Integer.class | ||
| ).withSqlImplementation("T2", "A"); | ||
|
|
||
| JoinOperator<Record, Record, Integer> join = | ||
| new JoinOperator<>(keyExtractor0, keyExtractor1); | ||
|
|
||
| List<Tuple2<Record, Record>> results = new ArrayList<>(); | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| LocalCallbackSink<Tuple2<Record, Record>> sink = | ||
| LocalCallbackSink.createCollectingSink( | ||
| results, | ||
| (Class<Tuple2<Record, Record>>) (Class<?>) Tuple2.class | ||
| ); | ||
|
|
||
| source1.addTargetPlatform(GenericJdbcPlatform.getInstance()); | ||
| source2.addTargetPlatform(GenericJdbcPlatform.getInstance()); | ||
| join.addTargetPlatform(JavaPlatform.getInstance()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The join happens in Java for this test. So it's not the genericjdbcjoin operator that is being tested. |
||
| sink.addTargetPlatform(JavaPlatform.getInstance()); | ||
|
|
||
| source1.connectTo(0, join, 0); | ||
| source2.connectTo(0, join, 1); | ||
| join.connectTo(0, sink, 0); | ||
|
|
||
| WayangContext ctx = new WayangContext(config) | ||
| .with(GenericJdbc.plugin()) | ||
| .with(org.apache.wayang.java.Java.basicPlugin()); | ||
|
|
||
| ctx.execute(new WayangPlan(sink)); | ||
|
|
||
| assertEquals(1, results.size()); | ||
| } | ||
| } | ||
25 changes: 25 additions & 0 deletions
25
wayang-platforms/wayang-generic-jdbc/src/test/resources/wayang.properties
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # | ||
| # Licensed to the Apache Software Foundation (ASF) under one or more | ||
| # contributor license agreements. See the NOTICE file distributed with | ||
| # this work for additional information regarding copyright ownership. | ||
| # The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| # (the "License"); you may not use this file except in compliance with | ||
| # the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
| wayang.T1.jdbc.url=jdbc:hsqldb:mem:wayang_test_db;DB_CLOSE_DELAY=-1 | ||
| wayang.T1.jdbc.user=SA | ||
| wayang.T1.jdbc.password= | ||
| wayang.T1.jdbc.driverName=org.hsqldb.jdbcDriver | ||
|
|
||
| wayang.T2.jdbc.url=jdbc:hsqldb:mem:wayang_test_db;DB_CLOSE_DELAY=-1 | ||
| wayang.T2.jdbc.user=SA | ||
| wayang.T2.jdbc.password= | ||
| wayang.T2.jdbc.driverName=org.hsqldb.jdbcDriver |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to introduce all these line breaks