org.apache.calcite.rel.core.JoinRelType Java Examples

The following examples show how to use org.apache.calcite.rel.core.JoinRelType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PigRelBuilderStyleTest.java    From calcite with Apache License 2.0 6 votes vote down vote up
@Disabled("CALCITE-3660")
@Test void testImplWithJoin() throws Exception {
  final SchemaPlus schema = createTestSchema();
  final RelBuilder builder = createRelBuilder(schema);
  final RelNode node = builder.scan("t").scan("s")
      .join(JoinRelType.INNER,
          builder.equals(builder.field(2, 0, "tc1"), builder.field(2, 1, "sc0")))
      .filter(builder.call(GREATER_THAN, builder.field("tc0"), builder.literal("a"))).build();
  final RelNode optimized = optimizeWithVolcano(node);
  assertScriptAndResults("t", getPigScript(optimized, schema),
      "t = LOAD 'target/data.txt"
          + "' USING PigStorage() AS (tc0:chararray, tc1:chararray);\n"
          + "t = FILTER t BY (tc0 > 'a');\n"
          + "s = LOAD 'target/data2.txt"
          + "' USING PigStorage() AS (sc0:chararray, sc1:chararray);\n"
          + "t = JOIN t BY tc1 , s BY sc0;",
      new String[] { "(b,2,2,label2)" });
}
 
Example #2
Source File: RelMdCollation.java    From Bats with Apache License 2.0 6 votes vote down vote up
private static List<RelCollation> enumerableJoin0(RelMetadataQuery mq,
    RelNode left, RelNode right, JoinRelType joinType) {
  // The current implementation can preserve the sort order of the left input if one of the
  // following conditions hold:
  // (i) join type is INNER or LEFT;
  // (ii) RelCollation always orders nulls last.
  final ImmutableList<RelCollation> leftCollations = mq.collations(left);
  switch (joinType) {
  case INNER:
  case LEFT:
    return leftCollations;
  case RIGHT:
  case FULL:
    for (RelCollation collation : leftCollations) {
      for (RelFieldCollation field : collation.getFieldCollations()) {
        if (!(RelFieldCollation.NullDirection.LAST == field.nullDirection)) {
          return ImmutableList.of();
        }
      }
    }
    return leftCollations;
  }
  return ImmutableList.of();
}
 
Example #3
Source File: LogicalCorrelate.java    From calcite with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a LogicalCorrelate.
 * @param cluster      cluster this relational expression belongs to
 * @param left         left input relational expression
 * @param right        right input relational expression
 * @param correlationId variable name for the row of left input
 * @param requiredColumns Required columns
 * @param joinType     join type
 */
public LogicalCorrelate(
    RelOptCluster cluster,
    RelTraitSet traitSet,
    RelNode left,
    RelNode right,
    CorrelationId correlationId,
    ImmutableBitSet requiredColumns,
    JoinRelType joinType) {
  super(
      cluster,
      traitSet,
      left,
      right,
      correlationId,
      requiredColumns,
      joinType);
  assert !CalciteSystemProperty.DEBUG.value() || isValid(Litmus.THROW, null);
}
 
Example #4
Source File: SamzaSqlTableJoinFunction.java    From samza with Apache License 2.0 6 votes vote down vote up
SamzaSqlTableJoinFunction(JoinInputNode streamNode, JoinInputNode tableNode, JoinRelType joinRelType) {
  this.joinRelType = joinRelType;
  this.isTablePosOnRight = tableNode.isPosOnRight();

  Validate.isTrue((joinRelType.compareTo(JoinRelType.LEFT) == 0 && isTablePosOnRight) ||
      (joinRelType.compareTo(JoinRelType.RIGHT) == 0 && !isTablePosOnRight) ||
      joinRelType.compareTo(JoinRelType.INNER) == 0);

  this.streamFieldIds = new ArrayList<>(streamNode.getKeyIds());
  this.tableKeyIds = new ArrayList<>(tableNode.getKeyIds());
  this.tableFieldNames = new ArrayList<>(tableNode.getFieldNames());

  this.outFieldNames = new ArrayList<>();
  if (isTablePosOnRight) {
    outFieldNames.addAll(streamNode.getFieldNames());
    outFieldNames.addAll(tableFieldNames);
  } else {
    outFieldNames.addAll(tableFieldNames);
    outFieldNames.addAll(streamNode.getFieldNames());
  }
}
 
Example #5
Source File: RelBuilderTest.java    From calcite with Apache License 2.0 6 votes vote down vote up
/** Test case for
 * <a href="https://issues.apache.org/jira/browse/CALCITE-1523">[CALCITE-1523]
 * Add RelBuilder field() method to reference aliased relations not on top of
 * stack</a>, accessing tables aliased that are not accessible in the top
 * RelNode. */
@Test void testAliasPastTop() {
  // Equivalent SQL:
  //   SELECT *
  //   FROM emp
  //   LEFT JOIN dept ON emp.deptno = dept.deptno
  //     AND emp.empno = 123
  //     AND dept.deptno IS NOT NULL
  final RelBuilder builder = RelBuilder.create(config().build());
  RelNode root =
      builder.scan("EMP")
          .scan("DEPT")
          .join(JoinRelType.LEFT,
              builder.call(SqlStdOperatorTable.EQUALS,
                  builder.field(2, "EMP", "DEPTNO"),
                  builder.field(2, "DEPT", "DEPTNO")),
              builder.call(SqlStdOperatorTable.EQUALS,
                  builder.field(2, "EMP", "EMPNO"),
                  builder.literal(123)))
          .build();
  final String expected = ""
      + "LogicalJoin(condition=[AND(=($7, $8), =($0, 123))], joinType=[left])\n"
      + "  LogicalTableScan(table=[[scott, EMP]])\n"
      + "  LogicalTableScan(table=[[scott, DEPT]])\n";
  assertThat(root, hasTree(expected));
}
 
Example #6
Source File: EnumerableCorrelate.java    From calcite with Apache License 2.0 6 votes vote down vote up
/** Creates an EnumerableCorrelate. */
public static EnumerableCorrelate create(
    RelNode left,
    RelNode right,
    CorrelationId correlationId,
    ImmutableBitSet requiredColumns,
    JoinRelType joinType) {
  final RelOptCluster cluster = left.getCluster();
  final RelMetadataQuery mq = cluster.getMetadataQuery();
  final RelTraitSet traitSet =
      cluster.traitSetOf(EnumerableConvention.INSTANCE)
          .replaceIfs(RelCollationTraitDef.INSTANCE,
              () -> RelMdCollation.enumerableCorrelate(mq, left, right, joinType));
  return new EnumerableCorrelate(
      cluster,
      traitSet,
      left,
      right,
      correlationId,
      requiredColumns,
      joinType);
}
 
Example #7
Source File: NestedLoopJoinPOP.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
@JsonCreator
public NestedLoopJoinPOP(
    @JsonProperty("props") OpProps props,
    @JsonProperty("probe") PhysicalOperator probe,
    @JsonProperty("build") PhysicalOperator build,
    @JsonProperty("joinType") JoinRelType joinType,
    @JsonProperty("condition") LogicalExpression condition,
    @JsonProperty("vectorized") boolean vectorized,
    @JsonProperty("vectorOp") LogicalExpression vectorOp,
    @JsonProperty("buildProjected") Set<Integer> buildProjected,
    @JsonProperty("probeProjected") Set<Integer> probeProjected) {
  super(props);
  this.probe = probe;
  this.build = build;
  this.joinType = joinType;
  this.condition = condition;
  this.vectorized = vectorized;
  this.vectorOp = vectorOp;
  this.buildProjected = buildProjected;
  this.probeProjected = probeProjected;
}
 
Example #8
Source File: EnumerableNestedLoopJoin.java    From calcite with Apache License 2.0 6 votes vote down vote up
/** Creates an EnumerableNestedLoopJoin. */
public static EnumerableNestedLoopJoin create(
    RelNode left,
    RelNode right,
    RexNode condition,
    Set<CorrelationId> variablesSet,
    JoinRelType joinType) {
  final RelOptCluster cluster = left.getCluster();
  final RelMetadataQuery mq = cluster.getMetadataQuery();
  final RelTraitSet traitSet =
      cluster.traitSetOf(EnumerableConvention.INSTANCE)
          .replaceIfs(RelCollationTraitDef.INSTANCE,
              () -> RelMdCollation.enumerableNestedLoopJoin(mq, left, right, joinType));
  return new EnumerableNestedLoopJoin(cluster, traitSet, left, right, condition,
      variablesSet, joinType);
}
 
Example #9
Source File: BaseTestJoin.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
@Test
public void emptyRightWithLeftJoin() throws Exception {
  JoinInfo joinInfo = getJoinInfo(Arrays.asList(new JoinCondition("EQUALS", f("r_regionKey"), f("key"))),
    JoinRelType.LEFT, ImmutableSet.of(0, 1), ImmutableSet.of(0));

  final Table expected = t(
    th("key", "value", "r_regionKey"),
    false,
    tr(NULL_BIGINT, NULL_BIGINT, 0L),
    tr(NULL_BIGINT, NULL_BIGINT, 1L),
    tr(NULL_BIGINT, NULL_BIGINT, 2L),
    tr(NULL_BIGINT, NULL_BIGINT, 3L),
    tr(NULL_BIGINT, NULL_BIGINT, 4L)
  );


  validateDual(joinInfo.operator, joinInfo.clazz,
    TpchGenerator.singleGenerator(TpchTable.REGION, 0.1, getTestAllocator(), "r_regionKey"),
    new EmptyGenerator(getTestAllocator()), DEFAULT_BATCH, expected);
}
 
Example #10
Source File: SqlValidatorUtil.java    From Bats with Apache License 2.0 6 votes vote down vote up
/**
 * Derives the type of a join relational expression.
 *
 * @param leftType        Row type of left input to join
 * @param rightType       Row type of right input to join
 * @param joinType        Type of join
 * @param typeFactory     Type factory
 * @param fieldNameList   List of names of fields; if null, field names are
 *                        inherited and made unique
 * @param systemFieldList List of system fields that will be prefixed to
 *                        output row type; typically empty but must not be
 *                        null
 * @return join type
 */
public static RelDataType deriveJoinRowType(
    RelDataType leftType,
    RelDataType rightType,
    JoinRelType joinType,
    RelDataTypeFactory typeFactory,
    List<String> fieldNameList,
    List<RelDataTypeField> systemFieldList) {
  assert systemFieldList != null;
  switch (joinType) {
  case LEFT:
    rightType = typeFactory.createTypeWithNullability(rightType, true);
    break;
  case RIGHT:
    leftType = typeFactory.createTypeWithNullability(leftType, true);
    break;
  case FULL:
    leftType = typeFactory.createTypeWithNullability(leftType, true);
    rightType = typeFactory.createTypeWithNullability(rightType, true);
    break;
  default:
    break;
  }
  return createJoinType(typeFactory, leftType, rightType, fieldNameList,
      systemFieldList);
}
 
Example #11
Source File: EnumerableTraitsUtils.java    From calcite with Apache License 2.0 6 votes vote down vote up
/**
 * This function can be reused when a Join's traits derivation shall only
 * derive collation from left input.
 *
 * @param childTraits trait set of the child
 * @param childId id of the child (0 is left join input)
 * @param joinType the join type
 * @param joinTraitSet trait set of the join
 * @param rightTraitSet trait set of the right join input
 */
static Pair<RelTraitSet, List<RelTraitSet>> deriveTraitsForJoin(
    RelTraitSet childTraits, int childId, JoinRelType joinType,
    RelTraitSet joinTraitSet, RelTraitSet rightTraitSet) {
  // should only derive traits (limited to collation for now) from left join input.
  assert childId == 0;

  RelCollation collation = childTraits.getCollation();
  if (collation == null
      || collation == RelCollations.EMPTY
      || joinType == JoinRelType.FULL
      || joinType == JoinRelType.RIGHT) {
    return null;
  }

  RelTraitSet derivedTraits = joinTraitSet.replace(collation);
  return Pair.of(
      derivedTraits,
      ImmutableList.of(derivedTraits, rightTraitSet));
}
 
Example #12
Source File: SwapHashJoinVisitor.java    From Bats with Apache License 2.0 6 votes vote down vote up
@Override
public Prel visitJoin(JoinPrel prel, Double value) throws RuntimeException {
  JoinPrel newJoin = (JoinPrel) visitPrel(prel, value);

  if (prel instanceof HashJoinPrel &&
      !((HashJoinPrel) prel).isRowKeyJoin() /* don't swap for rowkey joins */) {
    // Mark left/right is swapped, when INNER hash join's left row count < ( 1+ margin factor) right row count.
    RelMetadataQuery mq = newJoin.getCluster().getMetadataQuery();
    if (newJoin.getLeft().estimateRowCount(mq) < (1 + value) * newJoin.getRight().estimateRowCount(mq) &&
        newJoin.getJoinType() == JoinRelType.INNER && !newJoin.isSemiJoin()) {
      ((HashJoinPrel) newJoin).setSwapped(true);
    }
  }

  return newJoin;
}
 
Example #13
Source File: RelMdCollation.java    From calcite with Apache License 2.0 6 votes vote down vote up
private static List<RelCollation> enumerableJoin0(RelMetadataQuery mq,
    RelNode left, RelNode right, JoinRelType joinType) {
  // The current implementation can preserve the sort order of the left input if one of the
  // following conditions hold:
  // (i) join type is INNER or LEFT;
  // (ii) RelCollation always orders nulls last.
  final ImmutableList<RelCollation> leftCollations = mq.collations(left);
  switch (joinType) {
  case SEMI:
  case ANTI:
  case INNER:
  case LEFT:
    return leftCollations;
  case RIGHT:
  case FULL:
    for (RelCollation collation : leftCollations) {
      for (RelFieldCollation field : collation.getFieldCollations()) {
        if (!(RelFieldCollation.NullDirection.LAST == field.nullDirection)) {
          return ImmutableList.of();
        }
      }
    }
    return leftCollations;
  }
  return ImmutableList.of();
}
 
Example #14
Source File: NestedLoopJoinPrule.java    From Bats with Apache License 2.0 6 votes vote down vote up
@Override
protected boolean checkPreconditions(DrillJoin join, RelNode left, RelNode right,
                                     PlannerSettings settings) {
  JoinRelType type = join.getJoinType();

  if (!(type == JoinRelType.INNER || type == JoinRelType.LEFT)) {
    return false;
  }

  List<Integer> leftKeys = Lists.newArrayList();
  List<Integer> rightKeys = Lists.newArrayList();
  List<Boolean> filterNulls = Lists.newArrayList();
  JoinCategory category = JoinUtils.getJoinCategory(left, right, join.getCondition(), leftKeys, rightKeys, filterNulls);
  if (category == JoinCategory.EQUALITY
      && (settings.isHashJoinEnabled() || settings.isMergeJoinEnabled())) {
    return false;
  }

  if (settings.isNlJoinForScalarOnly()) {
    return JoinUtils.hasScalarSubqueryInput(left, right);
  }

  return true;
}
 
Example #15
Source File: TestNLJE.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Test
public void nljBatchBoundary() throws Exception {

  DataRow dr = tr(1);

  int rows = 2047;

  DataRow[] t1Data = new DataRow[rows];

  Arrays.fill(t1Data, dr);

  final Table t1 = t(
    th("x"),
    t1Data
  );

  final Table t2 = t(
    th("y"),
    dr
  );

  DataRow expDr = tr(1,1);

  DataRow[] expectedData = new DataRow[rows];

  Arrays.fill(expectedData, expDr);

  final Table expected = t(
    th("y", "x"),
    expectedData
  );


  validateDual(
    new NestedLoopJoinPOP(PROPS, null, null, JoinRelType.INNER, null, true, null, ImmutableSet.of(0), ImmutableSet.of(0, 1)),
    NLJEOperator.class,
    t1.toGenerator(getTestAllocator()),
    t2.toGenerator(getTestAllocator()),
    2047, expected);
}
 
Example #16
Source File: TestMergeJoin.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Test
public void nullEquivalenceInnerSingleCondition() throws Exception{
  JoinInfo joinInfo = getJoinInfo(Arrays.asList(new JoinCondition("EQUALS", f("name1"), f("name2"))), JoinRelType.INNER);
  {
    final Table expected = t(
        th("bool2", "name2", "bool1", "name1"),
        tr(false, "a1", true, "a1"),
        tr(true, "a2", false, "a2"),
        tr(true, "a4", false, "a4"),
        tr(false, "a6", false, "a6")
      );
    nullHighSingleRowsData(joinInfo, expected);
  }
}
 
Example #17
Source File: BaseTestJoin.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Test
public void isNotDistinctWithZeroKey() throws Exception{
  JoinInfo includeZeroKeyInfo = getJoinInfo(Arrays.asList(new JoinCondition("IS_NOT_DISTINCT_FROM", f("id1"), f("id2"))), JoinRelType.INNER, ImmutableSet.of(0, 1), ImmutableSet.of(0, 1));
  final Table expected = t(
    th("id2", "name2", "id1", "name1"),
    tr(Fixtures.NULL_BIGINT, "b1", Fixtures.NULL_BIGINT, "a1"),
    tr(Fixtures.NULL_BIGINT, "b3", Fixtures.NULL_BIGINT, "a1"),
    tr(0l, "b2", 0l, "a2"),
    tr(0l, "b4", 0l, "a2")
  );
  nullWithZeroKey(includeZeroKeyInfo, expected);
}
 
Example #18
Source File: Bindables.java    From calcite with Apache License 2.0 5 votes vote down vote up
/** Creates a BindableJoin. */
protected BindableJoin(RelOptCluster cluster, RelTraitSet traitSet,
    RelNode left, RelNode right, RexNode condition,
    Set<CorrelationId> variablesSet, JoinRelType joinType) {
  super(cluster, traitSet, ImmutableList.of(), left, right,
      condition, variablesSet, joinType);
}
 
Example #19
Source File: JoinAnalyzer.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
private JoinType toJoinType(JoinRelType joinRelType) {
  switch(joinRelType) {
  case LEFT:
    return JoinType.LeftOuter;
  case RIGHT:
    return JoinType.RightOuter;
  case FULL:
    return JoinType.FullOuter;
  case INNER:
    return JoinType.Inner;
  default:
    throw new RuntimeException(String.format("Unknown join type: %s", joinRelType));
  }
}
 
Example #20
Source File: EnumerableStringComparisonTest.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Test void testMergeJoinOnStringSpecialCollation() {
  tester()
      .query("?")
      .withHook(Hook.PLANNER, (Consumer<RelOptPlanner>) planner -> {
        planner.addRule(EnumerableRules.ENUMERABLE_MERGE_JOIN_RULE);
        planner.removeRule(EnumerableRules.ENUMERABLE_JOIN_RULE);
      })
      .withRel(builder -> builder
            .values(createRecordVarcharSpecialCollation(builder),
                "Legal", "presales", "HR", "Administration", "Marketing").as("v1")
            .values(createRecordVarcharSpecialCollation(builder),
                "Marketing", "bureaucracy", "Sales", "HR").as("v2")
            .join(JoinRelType.INNER,
                builder.equals(
                    builder.field(2, 0, "name"),
                    builder.field(2, 1, "name")))
            .project(
                builder.field("v1", "name"),
                builder.field("v2", "name"))
            .build())
      .explainHookMatches("" // It is important that we have MergeJoin in the plan
          + "EnumerableMergeJoin(condition=[=($0, $1)], joinType=[inner])\n"
          + "  EnumerableSort(sort0=[$0], dir0=[ASC])\n"
          + "    EnumerableValues(tuples=[[{ 'Legal' }, { 'presales' }, { 'HR' }, { 'Administration' }, { 'Marketing' }]])\n"
          + "  EnumerableSort(sort0=[$0], dir0=[ASC])\n"
          + "    EnumerableValues(tuples=[[{ 'Marketing' }, { 'bureaucracy' }, { 'Sales' }, { 'HR' }]])\n")
      .returnsOrdered("name=HR; name0=HR\n"
          + "name=Marketing; name0=Marketing");
}
 
Example #21
Source File: MergeJoinPrel.java    From Bats with Apache License 2.0 5 votes vote down vote up
@Override
public Join copy(RelTraitSet traitSet, RexNode conditionExpr, RelNode left, RelNode right, JoinRelType joinType, boolean semiJoinDone) {
  try {
    return new MergeJoinPrel(this.getCluster(), traitSet, left, right, conditionExpr, joinType);
  }catch (InvalidRelException e) {
    throw new AssertionError(e);
  }
}
 
Example #22
Source File: RelToSqlConverter.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
/**
 * @see #dispatch
 */
public Result visit(Join e) {
  final Result leftResult = visitChild(0, e.getLeft()).resetAlias();
  final Result rightResult = visitChild(1, e.getRight()).resetAlias();
  final Context leftContext = leftResult.qualifiedContext();
  final Context rightContext = rightResult.qualifiedContext();
  SqlNode sqlCondition = null;
  SqlLiteral condType = JoinConditionType.ON.symbol(POS);
  JoinType joinType = joinType(e.getJoinType());
  if (e.getJoinType() == JoinRelType.INNER && e.getCondition().isAlwaysTrue()) {
    joinType = JoinType.COMMA;
    condType = JoinConditionType.NONE.symbol(POS);
  } else {
    final RexNode condition = e.getCondition() != null
      ? simplifyDatetimePlus(e.getCondition(), e.getCluster().getRexBuilder())
      : null;
    sqlCondition = convertConditionToSqlNode(
      condition,
      leftContext,
      rightContext,
      e.getLeft().getRowType().getFieldCount());
  }
  SqlNode join =
    new SqlJoin(POS,
      leftResult.asFrom(),
      SqlLiteral.createBoolean(false, POS),
      joinType.symbol(POS),
      rightResult.asFrom(),
      condType,
      sqlCondition);
  return result(join, leftResult, rightResult);
}
 
Example #23
Source File: CalcPythonCorrelateTransposeRule.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public boolean matches(RelOptRuleCall call) {
	FlinkLogicalCorrelate correlate = call.rel(0);
	FlinkLogicalCalc right = call.rel(2);
	JoinRelType joinType = correlate.getJoinType();
	FlinkLogicalCalc mergedCalc = CorrelateUtil.getMergedCalc(right);
	Option<FlinkLogicalTableFunctionScan> scan = CorrelateUtil.getTableFunctionScan(mergedCalc);
	return joinType == JoinRelType.INNER &&
		scan.isDefined() &&
		PythonUtil.isPythonCall(scan.get().getCall(), null) &&
		mergedCalc.getProgram().getCondition() != null;
}
 
Example #24
Source File: LateralJoinPOP.java    From Bats with Apache License 2.0 5 votes vote down vote up
@JsonCreator
public LateralJoinPOP(
    @JsonProperty("left") PhysicalOperator left,
    @JsonProperty("right") PhysicalOperator right,
    @JsonProperty("joinType") JoinRelType joinType,
    @JsonProperty("implicitRIDColumn") String implicitRIDColumn,
    @JsonProperty("excludedColumns") List<SchemaPath> excludedColumns) {
  super(left, right, joinType, false, null, null);
  Preconditions.checkArgument(joinType != JoinRelType.FULL,
    "Full outer join is currently not supported with Lateral Join");
  Preconditions.checkArgument(joinType != JoinRelType.RIGHT,
    "Right join is currently not supported with Lateral Join");
  this.excludedColumns = excludedColumns;
  this.implicitRIDColumn = implicitRIDColumn;
}
 
Example #25
Source File: PythonTableFunctionOperator.java    From flink with Apache License 2.0 5 votes vote down vote up
public PythonTableFunctionOperator(
	Configuration config,
	PythonFunctionInfo tableFunction,
	RowType inputType,
	RowType outputType,
	int[] udtfInputOffsets,
	JoinRelType joinType) {
	super(config, tableFunction, inputType, outputType, udtfInputOffsets, joinType);
}
 
Example #26
Source File: BaseTestJoin.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Test
public void nationRegionPartialKeyOuterSmall() throws Exception {
  runRightAndOuter();
  JoinInfo info = getJoinInfo(Arrays.asList(new JoinCondition("EQUALS", f("n_nationKey"), f("r_regionKey"))), JoinRelType.FULL, ImmutableSet.of(0, 1), ImmutableSet.of(0, 1));

  final Table expected = t(
    th("r_regionKey", "r_name", "n_nationKey", "n_name"),
    tr(0L, "AFRICA", 0L, "ALGERIA"),
    tr(1L, "AMERICA", 1L, "ARGENTINA"),
    tr(2L, "ASIA", 2L, "BRAZIL"),
    tr(3L, "EUROPE", 3L, "CANADA"),
    tr(4L, "MIDDLE EAST", 4L, "EGYPT"),
    tr(NULL_BIGINT, NULL_VARCHAR, 5L, "ETHIOPIA"),
    tr(NULL_BIGINT, NULL_VARCHAR, 6L, "FRANCE"),
    tr(NULL_BIGINT, NULL_VARCHAR, 7L, "GERMANY"),
    tr(NULL_BIGINT, NULL_VARCHAR, 8L, "INDIA"),
    tr(NULL_BIGINT, NULL_VARCHAR, 9L, "INDONESIA"),
    tr(NULL_BIGINT, NULL_VARCHAR, 10L, "IRAN"),
    tr(NULL_BIGINT, NULL_VARCHAR, 11L, "IRAQ"),
    tr(NULL_BIGINT, NULL_VARCHAR, 12L, "JAPAN"),
    tr(NULL_BIGINT, NULL_VARCHAR, 13L, "JORDAN"),
    tr(NULL_BIGINT, NULL_VARCHAR, 14L, "KENYA"),
    tr(NULL_BIGINT, NULL_VARCHAR, 15L, "MOROCCO"),
    tr(NULL_BIGINT, NULL_VARCHAR, 16L, "MOZAMBIQUE"),
    tr(NULL_BIGINT, NULL_VARCHAR, 17L, "PERU"),
    tr(NULL_BIGINT, NULL_VARCHAR, 18L, "CHINA"),
    tr(NULL_BIGINT, NULL_VARCHAR, 19L, "ROMANIA"),
    tr(NULL_BIGINT, NULL_VARCHAR, 20L, "SAUDI ARABIA"),
    tr(NULL_BIGINT, NULL_VARCHAR, 21L, "VIETNAM"),
    tr(NULL_BIGINT, NULL_VARCHAR, 22L, "RUSSIA"),
    tr(NULL_BIGINT, NULL_VARCHAR, 23L, "UNITED KINGDOM"),
    tr(NULL_BIGINT, NULL_VARCHAR, 24L, "UNITED STATES")
  );

  validateDual(
    info.operator, info.clazz,
    TpchGenerator.singleGenerator(TpchTable.NATION, 0.1, getTestAllocator(), "n_nationKey", "n_name"),
    TpchGenerator.singleGenerator(TpchTable.REGION, 0.1, getTestAllocator(), "r_regionKey", "r_name"),
    3, expected);
}
 
Example #27
Source File: JoinAddRedundantSemiJoinRule.java    From Bats with Apache License 2.0 5 votes vote down vote up
public void onMatch(RelOptRuleCall call) {
  Join origJoinRel = call.rel(0);
  if (origJoinRel.isSemiJoinDone()) {
    return;
  }

  // can't process outer joins using semijoins
  if (origJoinRel.getJoinType() != JoinRelType.INNER) {
    return;
  }

  // determine if we have a valid join condition
  final JoinInfo joinInfo = origJoinRel.analyzeCondition();
  if (joinInfo.leftKeys.size() == 0) {
    return;
  }

  RelNode semiJoin =
      SemiJoin.create(origJoinRel.getLeft(),
          origJoinRel.getRight(),
          origJoinRel.getCondition(),
          joinInfo.leftKeys,
          joinInfo.rightKeys);

  RelNode newJoinRel =
      origJoinRel.copy(
          origJoinRel.getTraitSet(),
          origJoinRel.getCondition(),
          semiJoin,
          origJoinRel.getRight(),
          JoinRelType.INNER,
          true);

  call.transformTo(newJoinRel);
}
 
Example #28
Source File: JoinToMultiJoinRule.java    From Bats with Apache License 2.0 5 votes vote down vote up
/**
 * Combines the join filters from the left and right inputs (if they are
 * MultiJoinRels) with the join filter in the joinrel into a single AND'd
 * join filter, unless the inputs correspond to null generating inputs in an
 * outer join
 *
 * @param joinRel join rel
 * @param left    left child of the join
 * @param right   right child of the join
 * @return combined join filters AND-ed together
 */
private List<RexNode> combineJoinFilters(
    Join joinRel,
    RelNode left,
    RelNode right) {
  JoinRelType joinType = joinRel.getJoinType();

  // AND the join condition if this isn't a left or right outer join;
  // in those cases, the outer join condition is already tracked
  // separately
  final List<RexNode> filters = new ArrayList<>();
  if ((joinType != JoinRelType.LEFT) && (joinType != JoinRelType.RIGHT)) {
    filters.add(joinRel.getCondition());
  }
  if (canCombine(left, joinType.generatesNullsOnLeft())) {
    filters.add(((MultiJoin) left).getJoinFilter());
  }
  // Need to adjust the RexInputs of the right child, since
  // those need to shift over to the right
  if (canCombine(right, joinType.generatesNullsOnRight())) {
    MultiJoin multiJoin = (MultiJoin) right;
    filters.add(
        shiftRightFilter(joinRel, left, multiJoin,
            multiJoin.getJoinFilter()));
  }

  return filters;
}
 
Example #29
Source File: LogicalJoin.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Deprecated // to be removed before 2.0
public LogicalJoin(RelOptCluster cluster, RelTraitSet traitSet,
    RelNode left, RelNode right, RexNode condition, Set<CorrelationId> variablesSet,
    JoinRelType joinType, boolean semiJoinDone,
    ImmutableList<RelDataTypeField> systemFieldList) {
  this(cluster, traitSet, ImmutableList.of(), left, right, condition,
      variablesSet, joinType, semiJoinDone, systemFieldList);
}
 
Example #30
Source File: TestNLJ.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Test
public void nljSingleBatch() throws Exception {

  final Table expected = t(
      th("r_name", "r_regionKey"),
      tr("AFRICA", 0L),
      tr("AFRICA", 1L),
      tr("AFRICA", 2L),
      tr("AFRICA", 3L),
      tr("AFRICA", 4L),
      tr("AMERICA", 0L),
      tr("AMERICA", 1L),
      tr("AMERICA", 2L),
      tr("AMERICA", 3L),
      tr("AMERICA", 4L),
      tr("ASIA", 0L),
      tr("ASIA", 1L),
      tr("ASIA", 2L),
      tr("ASIA", 3L),
      tr("ASIA", 4L),
      tr("EUROPE", 0L),
      tr("EUROPE", 1L),
      tr("EUROPE", 2L),
      tr("EUROPE", 3L),
      tr("EUROPE", 4L),
      tr("MIDDLE EAST", 0L),
      tr("MIDDLE EAST", 1L),
      tr("MIDDLE EAST", 2L),
      tr("MIDDLE EAST", 3L),
      tr("MIDDLE EAST", 4L)
      );

  validateDual(
      new NestedLoopJoinPOP(PROPS, null, null, JoinRelType.INNER, null, false, null, ImmutableSet.of(0), ImmutableSet.of(0)),
      NLJOperator.class,
      TpchGenerator.singleGenerator(TpchTable.REGION, 0.1, getTestAllocator(), "r_regionKey"),
      TpchGenerator.singleGenerator(TpchTable.REGION, 0.1, getTestAllocator(), "r_name"),
      100, expected);
}