use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataTypeField in project hive by apache.
the class HiveSubQRemoveRelBuilder method field.
/**
* As {@link #field(int, int, int)}, but if {@code alias} is true, the method
* may apply an alias to make sure that the field has the same name as in the
* input frame. If no alias is applied the expression is definitely a
* {@link RexInputRef}.
*/
private RexNode field(int inputCount, int inputOrdinal, int fieldOrdinal, boolean alias) {
final Frame frame = peek_(inputCount, inputOrdinal);
final RelNode input = frame.rel;
final RelDataType rowType = input.getRowType();
if (fieldOrdinal < 0 || fieldOrdinal > rowType.getFieldCount()) {
throw new IllegalArgumentException("field ordinal [" + fieldOrdinal + "] out of range; input fields are: " + rowType.getFieldNames());
}
final RelDataTypeField field = rowType.getFieldList().get(fieldOrdinal);
final int offset = inputOffset(inputCount, inputOrdinal);
final RexInputRef ref = cluster.getRexBuilder().makeInputRef(field.getType(), offset + fieldOrdinal);
final RelDataTypeField aliasField = frame.fields().get(fieldOrdinal);
if (!alias || field.getName().equals(aliasField.getName())) {
return ref;
} else {
return alias(ref, aliasField.getName());
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataTypeField in project herddb by diennea.
the class CalcitePlanner method planEnumerableThetaJoin.
private PlannerOp planEnumerableThetaJoin(EnumerableThetaJoin op, RelDataType rowType) {
PlannerOp left = convertRelNode(op.getLeft(), null, false);
PlannerOp right = convertRelNode(op.getRight(), null, false);
CompiledSQLExpression condition = SQLExpressionCompiler.compileExpression(op.getCondition());
boolean generateNullsOnLeft = op.getJoinType().generatesNullsOnLeft();
boolean generateNullsOnRight = op.getJoinType().generatesNullsOnRight();
final RelDataType _rowType = rowType == null ? op.getRowType() : rowType;
List<RelDataTypeField> fieldList = _rowType.getFieldList();
Column[] columns = new Column[fieldList.size()];
String[] fieldNames = new String[columns.length];
int i = 0;
for (RelDataTypeField field : fieldList) {
Column col = Column.column(field.getName().toLowerCase(), convertToHerdType(field.getType()));
fieldNames[i] = col.name;
columns[i++] = col;
}
return new ThetaJoinOp(fieldNames, columns, left, right, condition, generateNullsOnLeft, generateNullsOnRight, false);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataTypeField in project herddb by diennea.
the class CalcitePlanner method planEnumerableJoin.
private PlannerOp planEnumerableJoin(EnumerableJoin op, RelDataType rowType) {
// please note that EnumerableJoin has a condition field which actually is not useful
PlannerOp left = convertRelNode(op.getLeft(), null, false);
PlannerOp right = convertRelNode(op.getRight(), null, false);
int[] leftKeys = op.getLeftKeys().toIntArray();
int[] rightKeys = op.getRightKeys().toIntArray();
boolean generateNullsOnLeft = op.getJoinType().generatesNullsOnLeft();
boolean generateNullsOnRight = op.getJoinType().generatesNullsOnRight();
final RelDataType _rowType = rowType == null ? op.getRowType() : rowType;
List<RelDataTypeField> fieldList = _rowType.getFieldList();
Column[] columns = new Column[fieldList.size()];
String[] fieldNames = new String[columns.length];
int i = 0;
for (RelDataTypeField field : fieldList) {
Column col = Column.column(field.getName().toLowerCase(), convertToHerdType(field.getType()));
fieldNames[i] = col.name;
columns[i++] = col;
}
return new JoinOp(fieldNames, columns, leftKeys, left, rightKeys, right, generateNullsOnLeft, generateNullsOnRight, false);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataTypeField in project herddb by diennea.
the class CalcitePlanner method planValues.
private PlannerOp planValues(EnumerableValues op) {
List<List<CompiledSQLExpression>> tuples = new ArrayList<>(op.getTuples().size());
RelDataType rowType = op.getRowType();
List<RelDataTypeField> fieldList = rowType.getFieldList();
Column[] columns = new Column[fieldList.size()];
for (ImmutableList<RexLiteral> tuple : op.getTuples()) {
List<CompiledSQLExpression> row = new ArrayList<>(tuple.size());
for (RexLiteral node : tuple) {
CompiledSQLExpression exp = SQLExpressionCompiler.compileExpression(node);
row.add(exp);
}
tuples.add(row);
}
int i = 0;
String[] fieldNames = new String[fieldList.size()];
for (RelDataTypeField field : fieldList) {
Column col = Column.column(field.getName(), convertToHerdType(field.getType()));
fieldNames[i] = field.getName();
columns[i++] = col;
}
return new ValuesOp(manager.getNodeId(), fieldNames, columns, tuples);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataTypeField in project herddb by diennea.
the class CalcitePlanner method planAggregate.
private PlannerOp planAggregate(EnumerableAggregate op, RelDataType rowType, boolean returnValues) {
List<RelDataTypeField> fieldList = op.getRowType().getFieldList();
List<AggregateCall> calls = op.getAggCallList();
String[] fieldnames = new String[fieldList.size()];
String[] aggtypes = new String[calls.size()];
Column[] columns = new Column[fieldList.size()];
List<Integer> groupedFiledsIndexes = op.getGroupSet().toList();
List<List<Integer>> argLists = new ArrayList<>(calls.size());
int i = 0;
int idaggcall = 0;
for (RelDataTypeField c : fieldList) {
int type = convertToHerdType(c.getType());
Column co = Column.column(c.getName(), type);
columns[i] = co;
fieldnames[i] = c.getName().toLowerCase();
i++;
}
for (AggregateCall call : calls) {
aggtypes[idaggcall++] = call.getAggregation().getName();
argLists.add(call.getArgList());
}
PlannerOp input = convertRelNode(op.getInput(), null, returnValues, false);
return new AggregateOp(input, fieldnames, columns, aggtypes, argLists, groupedFiledsIndexes);
}
Aggregations