Search in sources :

Example 11 with Node

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

the class JoinTreeTest method outputsCorrectJoinTreeString.

@Test
public void outputsCorrectJoinTreeString() {
    // 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.debugString(0), is("⋈\n" + "+--⋈\n" + "   +--a\n" + "   +--b\n" + "+--c"));
}
Also used : JoinInfo(io.confluent.ksql.analyzer.Analysis.JoinInfo) Node(io.confluent.ksql.planner.JoinTree.Node) Test(org.junit.Test)

Example 12 with Node

use of io.confluent.ksql.planner.JoinTree.Node 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 13 with Node

use of io.confluent.ksql.planner.JoinTree.Node 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 14 with Node

use of io.confluent.ksql.planner.JoinTree.Node 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)

Example 15 with Node

use of io.confluent.ksql.planner.JoinTree.Node 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)

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