use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.base.Preconditions.checkArgument in project beam by apache.
the class SqlNullIfOperatorRewriter method apply.
@Override
public RexNode apply(RexBuilder rexBuilder, List<RexNode> operands) {
Preconditions.checkArgument(operands.size() == 2, "NULLIF should have two arguments in function call.");
SqlOperator op = SqlOperatorMappingTable.ZETASQL_FUNCTION_TO_CALCITE_SQL_OPERATOR.get("$case_no_value").apply(null);
List<RexNode> newOperands = ImmutableList.of(rexBuilder.makeCall(SqlStdOperatorTable.EQUALS, ImmutableList.of(operands.get(0), operands.get(1))), rexBuilder.makeNullLiteral(operands.get(1).getType()), operands.get(0));
return rexBuilder.makeCall(op, newOperands);
}
use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.base.Preconditions.checkArgument in project beam by apache.
the class SqlIfNullOperatorRewriter method apply.
@Override
public RexNode apply(RexBuilder rexBuilder, List<RexNode> operands) {
Preconditions.checkArgument(operands.size() == 2, "IFNULL should have two arguments in function call.");
SqlOperator op = SqlStdOperatorTable.CASE;
List<RexNode> newOperands = ImmutableList.of(rexBuilder.makeCall(SqlStdOperatorTable.IS_NULL, ImmutableList.of(operands.get(0))), operands.get(1), operands.get(0));
return rexBuilder.makeCall(op, newOperands);
}
use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.base.Preconditions.checkArgument in project beam by apache.
the class BeamSideInputJoinRel method sideInputJoin.
public PCollection<Row> sideInputJoin(PCollection<Row> leftRows, PCollection<Row> rightRows, FieldAccessDescriptor leftKeyFields, FieldAccessDescriptor rightKeyFields) {
// we always make the Unbounded table on the left to do the sideInput join
// (will convert the result accordingly before return)
boolean swapped = (leftRows.isBounded() == PCollection.IsBounded.BOUNDED);
JoinRelType realJoinType = joinType;
if (swapped && joinType != JoinRelType.INNER) {
Preconditions.checkArgument(realJoinType != JoinRelType.LEFT);
realJoinType = JoinRelType.LEFT;
}
PCollection<Row> realLeftRows = swapped ? rightRows : leftRows;
PCollection<Row> realRightRows = swapped ? leftRows : rightRows;
FieldAccessDescriptor realLeftKeyFields = swapped ? rightKeyFields : leftKeyFields;
FieldAccessDescriptor realRightKeyFields = swapped ? leftKeyFields : rightKeyFields;
PCollection<Row> joined;
switch(realJoinType) {
case INNER:
joined = realLeftRows.apply(org.apache.beam.sdk.schemas.transforms.Join.<Row, Row>innerBroadcastJoin(realRightRows).on(FieldsEqual.left(realLeftKeyFields).right(realRightKeyFields)));
break;
case LEFT:
joined = realLeftRows.apply(org.apache.beam.sdk.schemas.transforms.Join.<Row, Row>leftOuterBroadcastJoin(realRightRows).on(FieldsEqual.left(realLeftKeyFields).right(realRightKeyFields)));
break;
default:
throw new RuntimeException("Unexpected join type " + realJoinType);
}
Schema schema = CalciteUtils.toSchema(getRowType());
String lhsSelect = org.apache.beam.sdk.schemas.transforms.Join.LHS_TAG + ".*";
String rhsSelect = org.apache.beam.sdk.schemas.transforms.Join.RHS_TAG + ".*";
PCollection<Row> selected = !swapped ? joined.apply(Select.<Row>fieldNames(lhsSelect, rhsSelect).withOutputSchema(schema)) : joined.apply(Select.<Row>fieldNames(rhsSelect, lhsSelect).withOutputSchema(schema));
return selected;
}
Aggregations