Search in sources :

Example 6 with Node

use of io.confluent.ksql.planner.JoinTree.Node in project ksql by confluentinc.

the class JoinTreeTest method shouldIncludeOnlyColFromLastInViableKeyEvenWithoutOverlap.

@Test
public void shouldIncludeOnlyColFromLastInViableKeyEvenWithoutOverlap() {
    // 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(col1);
    when(j2.getRightJoinExpression()).thenReturn(e3);
    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));
}
Also used : JoinInfo(io.confluent.ksql.analyzer.Analysis.JoinInfo) Node(io.confluent.ksql.planner.JoinTree.Node) Test(org.junit.Test)

Example 7 with Node

use of io.confluent.ksql.planner.JoinTree.Node in project ksql by confluentinc.

the class JoinTreeTest method handlesBasicTwoWayJoin.

@Test
public void handlesBasicTwoWayJoin() {
    // Given:
    when(j1.getLeftSource()).thenReturn(a);
    when(j1.getRightSource()).thenReturn(b);
    final List<JoinInfo> joins = ImmutableList.of(j1);
    // When:
    final Node root = JoinTree.build(joins);
    // Then:
    assertThat(root, instanceOf(Join.class));
    assertThat(((Join) root).getLeft(), is(new JoinTree.Leaf(a)));
    assertThat(((Join) root).getRight(), is(new JoinTree.Leaf(b)));
    assertThat(((Join) root).getInfo(), is(j1));
}
Also used : JoinInfo(io.confluent.ksql.analyzer.Analysis.JoinInfo) Node(io.confluent.ksql.planner.JoinTree.Node) Join(io.confluent.ksql.planner.JoinTree.Join) Leaf(io.confluent.ksql.planner.JoinTree.Leaf) Test(org.junit.Test)

Example 8 with Node

use of io.confluent.ksql.planner.JoinTree.Node in project ksql by confluentinc.

the class JoinTreeTest method handlesLeftThreeWayJoin.

@Test
public void handlesLeftThreeWayJoin() {
    // Given:
    when(j1.getLeftSource()).thenReturn(a);
    when(j1.getRightSource()).thenReturn(b);
    when(j2.getLeftSource()).thenReturn(a);
    when(j2.getRightSource()).thenReturn(c);
    final List<JoinInfo> joins = ImmutableList.of(j1, j2);
    // When:
    final Node root = JoinTree.build(joins);
    // Then:
    assertThat(root, instanceOf(Join.class));
    assertThat(root, is(new Join(new Join(new Leaf(a), new Leaf(b), j1), new Leaf(c), j2)));
}
Also used : JoinInfo(io.confluent.ksql.analyzer.Analysis.JoinInfo) Node(io.confluent.ksql.planner.JoinTree.Node) Join(io.confluent.ksql.planner.JoinTree.Join) Leaf(io.confluent.ksql.planner.JoinTree.Leaf) Test(org.junit.Test)

Example 9 with Node

use of io.confluent.ksql.planner.JoinTree.Node in project ksql by confluentinc.

the class JoinTreeTest method shouldIgnoreOuterJoinsWhenComputingEquivalenceSets.

@Test
public void shouldIgnoreOuterJoinsWhenComputingEquivalenceSets() {
    // Given:
    when(j1.getLeftSource()).thenReturn(a);
    when(j1.getRightSource()).thenReturn(b);
    when(j2.getLeftSource()).thenReturn(a);
    when(j2.getRightSource()).thenReturn(c);
    when(j1.getType()).thenReturn(JoinType.OUTER);
    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, e3));
}
Also used : JoinInfo(io.confluent.ksql.analyzer.Analysis.JoinInfo) Node(io.confluent.ksql.planner.JoinTree.Node) Test(org.junit.Test)

Example 10 with Node

use of io.confluent.ksql.planner.JoinTree.Node in project ksql by confluentinc.

the class JoinTreeTest method shouldIgnoreOuterJoinsWhenComputingViableKeys.

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

Aggregations

Node (io.confluent.ksql.planner.JoinTree.Node)16 Test (org.junit.Test)16 JoinInfo (io.confluent.ksql.analyzer.Analysis.JoinInfo)15 Join (io.confluent.ksql.planner.JoinTree.Join)3 Leaf (io.confluent.ksql.planner.JoinTree.Leaf)3