Search in sources :

Example 6 with Preconditions.checkArgument

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);
}
Also used : SqlOperator(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlOperator) RexNode(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexNode)

Example 7 with Preconditions.checkArgument

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);
}
Also used : SqlOperator(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlOperator) RexNode(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexNode)

Example 8 with Preconditions.checkArgument

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;
}
Also used : JoinRelType(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.JoinRelType) FieldAccessDescriptor(org.apache.beam.sdk.schemas.FieldAccessDescriptor) Schema(org.apache.beam.sdk.schemas.Schema) Row(org.apache.beam.sdk.values.Row)

Aggregations

RexNode (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexNode)6 SqlOperator (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlOperator)4 ArrayList (java.util.ArrayList)3 RexLiteral (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexLiteral)2 BeamRelMetadataQuery (org.apache.beam.sdk.extensions.sql.impl.planner.BeamRelMetadataQuery)1 BeamRelNode (org.apache.beam.sdk.extensions.sql.impl.rel.BeamRelNode)1 FieldAccessDescriptor (org.apache.beam.sdk.schemas.FieldAccessDescriptor)1 Schema (org.apache.beam.sdk.schemas.Schema)1 Row (org.apache.beam.sdk.values.Row)1 CannotPlanException (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptPlanner.CannotPlanException)1 RelTraitSet (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelTraitSet)1 RelNode (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode)1 RelRoot (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelRoot)1 JoinRelType (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.JoinRelType)1 RelDataType (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataType)1 RexLocalRef (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexLocalRef)1 RexProgram (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexProgram)1 SqlNode (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlNode)1 SqlParseException (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.parser.SqlParseException)1 RelConversionException (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.tools.RelConversionException)1