use of org.apache.calcite.rel.type.RelDataType in project storm by apache.
the class RelNodeCompiler method visitFilter.
@Override
public Void visitFilter(Filter filter, List<Void> inputStreams) throws Exception {
beginStage(filter);
List<RexNode> childExps = filter.getChildExps();
RelDataType inputRowType = filter.getInput(0).getRowType();
pw.print("Context context = new StormContext(Processor.dataContext);\n");
pw.print("context.values = _data.toArray();\n");
pw.print("Object[] outputValues = new Object[1];\n");
pw.write(rexCompiler.compileToBlock(childExps, inputRowType).toString());
String r = "((Boolean) outputValues[0])";
if (filter.getCondition().getType().isNullable()) {
pw.print(String.format(" if (%s != null && %s) { ctx.emit(_data); }\n", r, r));
} else {
pw.print(String.format(" if (%s) { ctx.emit(_data); }\n", r, r));
}
endStage();
return null;
}
use of org.apache.calcite.rel.type.RelDataType in project storm by apache.
the class RelNodeCompiler method visitProject.
@Override
public Void visitProject(Project project, List<Void> inputStreams) throws Exception {
beginStage(project);
List<RexNode> childExps = project.getChildExps();
RelDataType inputRowType = project.getInput(0).getRowType();
int outputCount = project.getRowType().getFieldCount();
pw.print("Context context = new StormContext(Processor.dataContext);\n");
pw.print("context.values = _data.toArray();\n");
pw.print(String.format("Object[] outputValues = new Object[%d];\n", outputCount));
pw.write(rexCompiler.compileToBlock(childExps, inputRowType).toString());
pw.print(" ctx.emit(new Values(outputValues));\n");
endStage();
return null;
}
use of org.apache.calcite.rel.type.RelDataType in project hive by apache.
the class HiveCalciteUtil method createSingleArgAggCall.
public static AggregateCall createSingleArgAggCall(String funcName, RelOptCluster cluster, PrimitiveTypeInfo typeInfo, Integer pos, RelDataType aggFnRetType) {
ImmutableList.Builder<RelDataType> aggArgRelDTBldr = new ImmutableList.Builder<RelDataType>();
aggArgRelDTBldr.add(TypeConverter.convert(typeInfo, cluster.getTypeFactory()));
SqlAggFunction aggFunction = SqlFunctionConverter.getCalciteAggFn(funcName, false, aggArgRelDTBldr.build(), aggFnRetType);
List<Integer> argList = new ArrayList<Integer>();
argList.add(pos);
return new AggregateCall(aggFunction, false, argList, aggFnRetType, null);
}
use of org.apache.calcite.rel.type.RelDataType in project hive by apache.
the class HiveSubQRemoveRelBuilder method values.
/** Creates a {@link Values}.
*
* <p>The {@code values} array must have the same number of entries as
* {@code fieldNames}, or an integer multiple if you wish to create multiple
* rows.
*
* <p>If there are zero rows, or if all values of a any column are
* null, this method cannot deduce the type of columns. For these cases,
* call {@link #values(Iterable, RelDataType)}.
*
* @param fieldNames Field names
* @param values Values
*/
public HiveSubQRemoveRelBuilder values(String[] fieldNames, Object... values) {
if (fieldNames == null || fieldNames.length == 0 || values.length % fieldNames.length != 0 || values.length < fieldNames.length) {
throw new IllegalArgumentException("Value count must be a positive multiple of field count");
}
final int rowCount = values.length / fieldNames.length;
for (Ord<String> fieldName : Ord.zip(fieldNames)) {
if (allNull(values, fieldName.i, fieldNames.length)) {
throw new IllegalArgumentException("All values of field '" + fieldName.e + "' are null; cannot deduce type");
}
}
final ImmutableList<ImmutableList<RexLiteral>> tupleList = tupleList(fieldNames.length, values);
final RelDataTypeFactory.FieldInfoBuilder rowTypeBuilder = cluster.getTypeFactory().builder();
for (final Ord<String> fieldName : Ord.zip(fieldNames)) {
final String name = fieldName.e != null ? fieldName.e : "expr$" + fieldName.i;
final RelDataType type = cluster.getTypeFactory().leastRestrictive(new AbstractList<RelDataType>() {
public RelDataType get(int index) {
return tupleList.get(index).get(fieldName.i).getType();
}
public int size() {
return rowCount;
}
});
rowTypeBuilder.add(name, type);
}
final RelDataType rowType = rowTypeBuilder.build();
return values(tupleList, rowType);
}
use of org.apache.calcite.rel.type.RelDataType 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());
}
}
Aggregations