-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: build physical plan for FK table-table joins (#7517)
- Loading branch information
Showing
36 changed files
with
1,150 additions
and
99 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
118 changes: 118 additions & 0 deletions
118
...db-execution/src/main/java/io/confluent/ksql/execution/plan/ForeignKeyTableTableJoin.java
This file contains 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,118 @@ | ||
/* | ||
* Copyright 2021 Confluent Inc. | ||
* | ||
* Licensed under the Confluent Community License; you may not use this file | ||
* except in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.confluent.io/confluent-community-license | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package io.confluent.ksql.execution.plan; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.google.common.collect.ImmutableList; | ||
import com.google.errorprone.annotations.Immutable; | ||
import io.confluent.ksql.name.ColumnName; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
@Immutable | ||
public class ForeignKeyTableTableJoin<KLeftT, KRightT> | ||
implements ExecutionStep<KTableHolder<KLeftT>> { | ||
|
||
private final ExecutionStepPropertiesV1 properties; | ||
private final JoinType joinType; | ||
private final ColumnName leftJoinColumnName; | ||
private final ExecutionStep<KTableHolder<KLeftT>> leftSource; | ||
private final ExecutionStep<KTableHolder<KRightT>> rightSource; | ||
|
||
@JsonCreator | ||
public ForeignKeyTableTableJoin( | ||
@JsonProperty(value = "properties", required = true) | ||
final ExecutionStepPropertiesV1 props, | ||
@JsonProperty(value = "joinType", required = true) | ||
final JoinType joinType, | ||
@JsonProperty(value = "leftJoinColumnName", required = true) | ||
final ColumnName leftJoinColumnName, | ||
@JsonProperty(value = "leftSource", required = true) | ||
final ExecutionStep<KTableHolder<KLeftT>> leftSource, | ||
@JsonProperty(value = "rightSource", required = true) | ||
final ExecutionStep<KTableHolder<KRightT>> rightSource | ||
) { | ||
this.properties = requireNonNull(props, "props"); | ||
this.joinType = requireNonNull(joinType, "joinType"); | ||
if (joinType == JoinType.OUTER) { | ||
throw new IllegalArgumentException("OUTER join not supported."); | ||
} | ||
this.leftJoinColumnName = requireNonNull(leftJoinColumnName, "leftJoinColumnName"); | ||
this.leftSource = requireNonNull(leftSource, "leftSource"); | ||
this.rightSource = requireNonNull(rightSource, "rightSource"); | ||
} | ||
|
||
@Override | ||
public ExecutionStepPropertiesV1 getProperties() { | ||
return properties; | ||
} | ||
|
||
@Override | ||
@JsonIgnore | ||
public List<ExecutionStep<?>> getSources() { | ||
return ImmutableList.of(leftSource, rightSource); | ||
} | ||
|
||
public ExecutionStep<KTableHolder<KLeftT>> getLeftSource() { | ||
return leftSource; | ||
} | ||
|
||
public ExecutionStep<KTableHolder<KRightT>> getRightSource() { | ||
return rightSource; | ||
} | ||
|
||
public JoinType getJoinType() { | ||
return joinType; | ||
} | ||
|
||
public ColumnName getLeftJoinColumnName() { | ||
return leftJoinColumnName; | ||
} | ||
|
||
@Override | ||
public KTableHolder<KLeftT> build(final PlanBuilder builder, final PlanInfo info) { | ||
return builder.visitForeignKeyTableTableJoin(this, info); | ||
} | ||
|
||
@Override | ||
public PlanInfo extractPlanInfo(final PlanInfoExtractor extractor) { | ||
return extractor.visitForeignKeyTableTableJoin(this); | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
final ForeignKeyTableTableJoin<?, ?> that = (ForeignKeyTableTableJoin<?, ?>) o; | ||
return Objects.equals(properties, that.properties) | ||
&& joinType == that.joinType | ||
&& Objects.equals(leftJoinColumnName, that.leftJoinColumnName) | ||
&& Objects.equals(leftSource, that.leftSource) | ||
&& Objects.equals(rightSource, that.rightSource); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(properties, joinType, leftJoinColumnName, leftSource, rightSource); | ||
} | ||
} |
This file contains 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
This file contains 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
71 changes: 71 additions & 0 deletions
71
...xecution/src/test/java/io/confluent/ksql/execution/plan/ForeignKeyTableTableJoinTest.java
This file contains 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,71 @@ | ||
/* | ||
* Copyright 2021 Confluent Inc. | ||
* | ||
* Licensed under the Confluent Community License; you may not use this file | ||
* except in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.confluent.io/confluent-community-license | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package io.confluent.ksql.execution.plan; | ||
|
||
import static io.confluent.ksql.execution.plan.JoinType.INNER; | ||
import static io.confluent.ksql.execution.plan.JoinType.LEFT; | ||
|
||
import com.google.common.testing.EqualsTester; | ||
import io.confluent.ksql.name.ColumnName; | ||
import org.apache.kafka.connect.data.Struct; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class ForeignKeyTableTableJoinTest { | ||
|
||
private static final ColumnName JOIN_COLUMN_NAME = ColumnName.of("Bob"); | ||
private static final ColumnName JOIN_COLUMN_NAME_2 = ColumnName.of("Vic"); | ||
|
||
@Mock | ||
private ExecutionStepPropertiesV1 props1; | ||
@Mock | ||
private ExecutionStepPropertiesV1 props2; | ||
@Mock | ||
private ExecutionStep<KTableHolder<Struct>> left1; | ||
@Mock | ||
private ExecutionStep<KTableHolder<Struct>> right1; | ||
@Mock | ||
private ExecutionStep<KTableHolder<Struct>> left2; | ||
@Mock | ||
private ExecutionStep<KTableHolder<Struct>> right2; | ||
|
||
@SuppressWarnings("UnstableApiUsage") | ||
@Test | ||
public void shouldImplementEquals() { | ||
new EqualsTester() | ||
.addEqualityGroup( | ||
new ForeignKeyTableTableJoin<>(props1, INNER, JOIN_COLUMN_NAME, left1, right1), | ||
new ForeignKeyTableTableJoin<>(props1, INNER, JOIN_COLUMN_NAME, left1, right1) | ||
) | ||
.addEqualityGroup( | ||
new ForeignKeyTableTableJoin<>(props2, INNER, JOIN_COLUMN_NAME, left1, right1) | ||
) | ||
.addEqualityGroup( | ||
new ForeignKeyTableTableJoin<>(props1, LEFT, JOIN_COLUMN_NAME, left1, right1) | ||
) | ||
.addEqualityGroup( | ||
new ForeignKeyTableTableJoin<>(props1, INNER, JOIN_COLUMN_NAME_2, left1, right1) | ||
) | ||
.addEqualityGroup( | ||
new ForeignKeyTableTableJoin<>(props1, INNER, JOIN_COLUMN_NAME, left2, right1) | ||
) | ||
.addEqualityGroup( | ||
new ForeignKeyTableTableJoin<>(props1, INNER, JOIN_COLUMN_NAME, left1, right2) | ||
).testEquals(); | ||
} | ||
} |
This file contains 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
This file contains 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
45 changes: 45 additions & 0 deletions
45
ksqldb-streams/src/main/java/io/confluent/ksql/execution/streams/ForeignKeyJoinParams.java
This file contains 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,45 @@ | ||
/* | ||
* Copyright 2021 Confluent Inc. | ||
* | ||
* Licensed under the Confluent Community License (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.confluent.io/confluent-community-license | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package io.confluent.ksql.execution.streams; | ||
|
||
import io.confluent.ksql.schema.ksql.LogicalSchema; | ||
import java.util.Objects; | ||
|
||
public class ForeignKeyJoinParams<KRightT> { | ||
private final KsqlKeyExtractor<KRightT> keyExtractor; | ||
private final KsqlValueJoiner joiner; | ||
private final LogicalSchema schema; | ||
|
||
ForeignKeyJoinParams(final KsqlKeyExtractor<KRightT> keyExtractor, | ||
final KsqlValueJoiner joiner, | ||
final LogicalSchema schema) { | ||
this.keyExtractor = Objects.requireNonNull(keyExtractor, "keyExtractor"); | ||
this.joiner = Objects.requireNonNull(joiner, "joiner"); | ||
this.schema = Objects.requireNonNull(schema, "schema"); | ||
} | ||
|
||
public LogicalSchema getSchema() { | ||
return schema; | ||
} | ||
|
||
public KsqlKeyExtractor<KRightT> getKeyExtractor() { | ||
return keyExtractor; | ||
} | ||
|
||
public KsqlValueJoiner getJoiner() { | ||
return joiner; | ||
} | ||
} |
Oops, something went wrong.