Search in sources :

Example 6 with JoinInfo

use of io.confluent.ksql.analyzer.Analysis.JoinInfo in project ksql by confluentinc.

the class LogicalPlanner method buildSourceNode.

private PlanNode buildSourceNode(final boolean isWindowed) {
    if (!analysis.isJoin()) {
        return buildNonJoinNode(analysis.getFrom(), isWindowed, ksqlConfig);
    }
    final List<JoinInfo> joinInfo = analysis.getJoin();
    final JoinTree.Node tree = JoinTree.build(joinInfo);
    if (tree instanceof JoinTree.Leaf) {
        throw new IllegalStateException("Expected more than one source:" + analysis.getAllDataSources());
    }
    final JoinNode joinNode = buildJoin((Join) tree, "", isWindowed);
    joinNode.resolveKeyFormats();
    return joinNode;
}
Also used : JoinInfo(io.confluent.ksql.analyzer.Analysis.JoinInfo) JoinNode(io.confluent.ksql.planner.plan.JoinNode) Leaf(io.confluent.ksql.planner.JoinTree.Leaf)

Example 7 with JoinInfo

use of io.confluent.ksql.analyzer.Analysis.JoinInfo in project ksql by confluentinc.

the class JoinTreeTest method shouldThrowOnCircularJoin.

@Test
public void shouldThrowOnCircularJoin() {
    // Given:
    when(j1.getLeftSource()).thenReturn(a);
    when(j1.getRightSource()).thenReturn(b);
    when(j2.getLeftSource()).thenReturn(a);
    when(j2.getRightSource()).thenReturn(b);
    final List<JoinInfo> joins = ImmutableList.of(j1, j2);
    // When:
    final KsqlException e = assertThrows(KsqlException.class, () -> JoinTree.build(joins));
    // Then:
    assertThat(e.getMessage(), containsString("Cannot perform circular join"));
}
Also used : JoinInfo(io.confluent.ksql.analyzer.Analysis.JoinInfo) KsqlException(io.confluent.ksql.util.KsqlException) Test(org.junit.Test)

Example 8 with JoinInfo

use of io.confluent.ksql.analyzer.Analysis.JoinInfo in project ksql by confluentinc.

the class JoinTreeTest method shouldIncludeOnlyColFromFirstInViableKeyIfOverlap.

@Test
public void shouldIncludeOnlyColFromFirstInViableKeyIfOverlap() {
    // Given:
    when(j1.getLeftSource()).thenReturn(a);
    when(j1.getRightSource()).thenReturn(b);
    when(j2.getLeftSource()).thenReturn(a);
    when(j2.getRightSource()).thenReturn(c);
    when(j1.getLeftJoinExpression()).thenReturn(e1);
    when(j1.getRightJoinExpression()).thenReturn(col2);
    when(j2.getLeftJoinExpression()).thenReturn(e1);
    when(j2.getRightJoinExpression()).thenReturn(e2);
    final List<JoinInfo> joins = ImmutableList.of(j1, j2);
    final Node root = JoinTree.build(joins);
    // When:
    final List<?> keys = root.viableKeyColumns();
    // Then:
    assertThat(keys, contains(col2));
}
Also used : JoinInfo(io.confluent.ksql.analyzer.Analysis.JoinInfo) Node(io.confluent.ksql.planner.JoinTree.Node) Test(org.junit.Test)

Example 9 with JoinInfo

use of io.confluent.ksql.analyzer.Analysis.JoinInfo in project ksql by confluentinc.

the class JoinTreeTest method shouldComputeEquivalenceSetWithOverlap.

@Test
public void shouldComputeEquivalenceSetWithOverlap() {
    // Given:
    when(j1.getLeftSource()).thenReturn(a);
    when(j1.getRightSource()).thenReturn(b);
    when(j2.getLeftSource()).thenReturn(a);
    when(j2.getRightSource()).thenReturn(c);
    when(j1.getLeftJoinExpression()).thenReturn(e1);
    when(j1.getRightJoinExpression()).thenReturn(e2);
    when(j2.getLeftJoinExpression()).thenReturn(e1);
    when(j2.getRightJoinExpression()).thenReturn(e3);
    final List<JoinInfo> joins = ImmutableList.of(j1, j2);
    // When:
    final Node root = JoinTree.build(joins);
    // Then:
    assertThat(root.joinEquivalenceSet(), containsInAnyOrder(e1, e2, e3));
}
Also used : JoinInfo(io.confluent.ksql.analyzer.Analysis.JoinInfo) Node(io.confluent.ksql.planner.JoinTree.Node) Test(org.junit.Test)

Example 10 with JoinInfo

use of io.confluent.ksql.analyzer.Analysis.JoinInfo in project ksql by confluentinc.

the class JoinTreeTest method shouldComputeViableKeysWithOverlap.

@Test
public void shouldComputeViableKeysWithOverlap() {
    // Given:
    when(j1.getLeftSource()).thenReturn(a);
    when(j1.getRightSource()).thenReturn(b);
    when(j2.getLeftSource()).thenReturn(a);
    when(j2.getRightSource()).thenReturn(c);
    when(j1.getLeftJoinExpression()).thenReturn(col1);
    when(j1.getRightJoinExpression()).thenReturn(col2);
    when(j2.getLeftJoinExpression()).thenReturn(col1);
    when(j2.getRightJoinExpression()).thenReturn(col3);
    final List<JoinInfo> joins = ImmutableList.of(j1, j2);
    final Node root = JoinTree.build(joins);
    // When:
    final List<?> keys = root.viableKeyColumns();
    // Then:
    assertThat(keys, contains(col1, col2, col3));
}
Also used : JoinInfo(io.confluent.ksql.analyzer.Analysis.JoinInfo) Node(io.confluent.ksql.planner.JoinTree.Node) Test(org.junit.Test)

Aggregations

JoinInfo (io.confluent.ksql.analyzer.Analysis.JoinInfo)19 Test (org.junit.Test)18 Node (io.confluent.ksql.planner.JoinTree.Node)15 Leaf (io.confluent.ksql.planner.JoinTree.Leaf)4 Join (io.confluent.ksql.planner.JoinTree.Join)3 KsqlException (io.confluent.ksql.util.KsqlException)3 JoinNode (io.confluent.ksql.planner.plan.JoinNode)1