Search in sources :

Example 11 with JoinInfo

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

the class JoinTreeTest method shouldThrowOnSelfJoin.

@Test
public void shouldThrowOnSelfJoin() {
    // Given:
    when(j1.getLeftSource()).thenReturn(a);
    when(j1.getRightSource()).thenReturn(a);
    final List<JoinInfo> joins = ImmutableList.of(j1);
    // 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 12 with JoinInfo

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

the class JoinTreeTest method shouldNotIncludeOnlyColFromFirstInViableKeysIfNoOverlap.

@Test
public void shouldNotIncludeOnlyColFromFirstInViableKeysIfNoOverlap() {
    // 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(e2);
    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, is(empty()));
}
Also used : JoinInfo(io.confluent.ksql.analyzer.Analysis.JoinInfo) Node(io.confluent.ksql.planner.JoinTree.Node) Test(org.junit.Test)

Example 13 with JoinInfo

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

the class JoinTreeTest method shouldComputeEquivalenceSetWithoutOverlap.

@Test
public void shouldComputeEquivalenceSetWithoutOverlap() {
    // 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(e3);
    when(j2.getRightJoinExpression()).thenReturn(e4);
    final List<JoinInfo> joins = ImmutableList.of(j1, j2);
    // When:
    final Node root = JoinTree.build(joins);
    // Then:
    assertThat(root.joinEquivalenceSet(), containsInAnyOrder(e3, e4));
}
Also used : JoinInfo(io.confluent.ksql.analyzer.Analysis.JoinInfo) Node(io.confluent.ksql.planner.JoinTree.Node) Test(org.junit.Test)

Example 14 with JoinInfo

use of io.confluent.ksql.analyzer.Analysis.JoinInfo 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 15 with JoinInfo

use of io.confluent.ksql.analyzer.Analysis.JoinInfo 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)

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