use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexInputRef in project drill by apache.
the class DrillRelOptUtil method analyzeSimpleEquiJoin.
/**
* Returns whether the join condition is a simple equi-join or not. A simple equi-join is
* defined as an two-table equality join (no self-join)
* @param join input join
* @param joinFieldOrdinals join field ordinal w.r.t. the underlying inputs to the join
* @return TRUE if the join is a simple equi-join (not a self-join), FALSE otherwise
*/
public static boolean analyzeSimpleEquiJoin(Join join, int[] joinFieldOrdinals) {
RexNode joinExp = join.getCondition();
if (joinExp.getKind() != SqlKind.EQUALS) {
return false;
} else {
RexCall binaryExpression = (RexCall) joinExp;
RexNode leftComparand = binaryExpression.operands.get(0);
RexNode rightComparand = binaryExpression.operands.get(1);
if (!(leftComparand instanceof RexInputRef)) {
return false;
} else if (!(rightComparand instanceof RexInputRef)) {
return false;
} else {
int leftFieldCount = join.getLeft().getRowType().getFieldCount();
int rightFieldCount = join.getRight().getRowType().getFieldCount();
RexInputRef leftFieldAccess = (RexInputRef) leftComparand;
RexInputRef rightFieldAccess = (RexInputRef) rightComparand;
if (leftFieldAccess.getIndex() >= leftFieldCount + rightFieldCount || rightFieldAccess.getIndex() >= leftFieldCount + rightFieldCount) {
return false;
}
/* Both columns reference same table */
if ((leftFieldAccess.getIndex() >= leftFieldCount && rightFieldAccess.getIndex() >= leftFieldCount) || (leftFieldAccess.getIndex() < leftFieldCount && rightFieldAccess.getIndex() < leftFieldCount)) {
return false;
} else {
if (leftFieldAccess.getIndex() < leftFieldCount) {
joinFieldOrdinals[0] = leftFieldAccess.getIndex();
joinFieldOrdinals[1] = rightFieldAccess.getIndex() - leftFieldCount;
} else {
joinFieldOrdinals[0] = rightFieldAccess.getIndex();
joinFieldOrdinals[1] = leftFieldAccess.getIndex() - leftFieldCount;
}
return true;
}
}
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexInputRef in project drill by apache.
the class DrillProjectRelBase method getSimpleFieldCount.
private int getSimpleFieldCount() {
int cnt = 0;
final ComplexFieldWithNamedSegmentIdentifier complexFieldIdentifer = new ComplexFieldWithNamedSegmentIdentifier();
// a + b, a * 10 + b, etc are not simple fields, since they are expressions.
for (RexNode expr : this.getProjects()) {
if (expr instanceof RexInputRef) {
// Simple Field reference.
cnt++;
} else if (expr instanceof RexCall && expr.accept(complexFieldIdentifer)) {
// Complex field with named segments only.
cnt++;
}
}
return cnt;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexInputRef in project drill by apache.
the class DrillRelOptUtil method containIdentity.
/**
* Returns whether the leading edge of a given array of expressions is
* wholly {@link RexInputRef} objects with types and names corresponding
* to the underlying row type.
*/
private static boolean containIdentity(List<? extends RexNode> exps, RelDataType rowType, RelDataType childRowType) {
List<RelDataTypeField> fields = rowType.getFieldList();
List<RelDataTypeField> childFields = childRowType.getFieldList();
int fieldCount = childFields.size();
if (exps.size() != fieldCount) {
return false;
}
for (int i = 0; i < exps.size(); i++) {
RexNode exp = exps.get(i);
if (!(exp instanceof RexInputRef)) {
return false;
}
RexInputRef var = (RexInputRef) exp;
if (var.getIndex() != i) {
return false;
}
if (!fields.get(i).getName().equals(childFields.get(i).getName())) {
return false;
}
if (!fields.get(i).getType().equals(childFields.get(i).getType())) {
return false;
}
}
return true;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexInputRef in project drill by apache.
the class DrillRelMdSelectivity method findRexInputRef.
private static RexInputRef findRexInputRef(final RexNode node) {
try {
RexVisitor<Void> visitor = new RexVisitorImpl<Void>(true) {
@Override
public Void visitCall(RexCall call) {
for (RexNode child : call.getOperands()) {
child.accept(this);
}
return super.visitCall(call);
}
@Override
public Void visitInputRef(RexInputRef inputRef) {
throw new Util.FoundOne(inputRef);
}
};
node.accept(visitor);
return null;
} catch (Util.FoundOne e) {
Util.swallow(e, null);
return (RexInputRef) e.getNode();
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexInputRef in project drill by apache.
the class FieldsReWriterUtil method getFieldNameFromItemStarField.
/**
* Checks if operator call is using item star field.
* Will return field name if true. null otherwise.
*
* @param rexCall operator call
* @param fieldNames list of field names
* @return field name, null otherwise
*/
public static String getFieldNameFromItemStarField(RexCall rexCall, List<String> fieldNames) {
if (!SqlStdOperatorTable.ITEM.equals(rexCall.getOperator())) {
return null;
}
if (rexCall.getOperands().size() != 2) {
return null;
}
if (!(rexCall.getOperands().get(0) instanceof RexInputRef && rexCall.getOperands().get(1) instanceof RexLiteral)) {
return null;
}
// get parent field reference from the first operand (ITEM($0, 'col_name' -> $0)
// and check if it corresponds to the dynamic star
RexInputRef rexInputRef = (RexInputRef) rexCall.getOperands().get(0);
String parentFieldName = fieldNames.get(rexInputRef.getIndex());
if (!SchemaPath.DYNAMIC_STAR.equals(parentFieldName)) {
return null;
}
// get field name from the second operand (ITEM($0, 'col_name') -> col_name)
RexLiteral rexLiteral = (RexLiteral) rexCall.getOperands().get(1);
if (SqlTypeName.CHAR.equals(rexLiteral.getType().getSqlTypeName())) {
return RexLiteral.stringValue(rexLiteral);
}
return null;
}
Aggregations