public Result implement(EnumerableRelImplementor implementor, Prefer pref) { // Note that representation is ARRAY. This assumes that the table // returns a Object[] for each record. Actually a Table<T> can // return any type T. And, if it is a JdbcTable, we'd like to be // able to generate alternate accessors that return e.g. synthetic // records {T0 f0; T1 f1; ...} and don't box every primitive value. final PhysType physType = PhysTypeImpl.of( implementor.getTypeFactory(), getRowType(), format()); final Expression expression = getExpression(physType); return implementor.result(physType, Blocks.toBlock(expression)); } }
public Result implement(EnumerableRelImplementor implementor, Prefer pref) { // Note that representation is ARRAY. This assumes that the table // returns a Object[] for each record. Actually a Table<T> can // return any type T. And, if it is a JdbcTable, we'd like to be // able to generate alternate accessors that return e.g. synthetic // records {T0 f0; T1 f1; ...} and don't box every primitive value. final PhysType physType = PhysTypeImpl.of( implementor.getTypeFactory(), getRowType(), format()); final Expression expression = getExpression(physType); return implementor.result(physType, Blocks.toBlock(expression)); } }
private Expression toRows(PhysType physType, Expression expression) { if (physType.getFormat() == JavaRowFormat.SCALAR && Object[].class.isAssignableFrom(elementType) && getRowType().getFieldCount() == 1 && (table.unwrap(ScannableTable.class) != null || table.unwrap(FilterableTable.class) != null || table.unwrap(ProjectableFilterableTable.class) != null)) { return Expressions.call(BuiltInMethod.SLICE0.method, expression); } JavaRowFormat oldFormat = format(); if (physType.getFormat() == oldFormat && !hasCollectionField(rowType)) { return expression; } final ParameterExpression row_ = Expressions.parameter(elementType, "row"); final int fieldCount = table.getRowType().getFieldCount(); List<Expression> expressionList = new ArrayList<>(fieldCount); for (int i = 0; i < fieldCount; i++) { expressionList.add(fieldExpression(row_, i, physType, oldFormat)); } return Expressions.call(expression, BuiltInMethod.SELECT.method, Expressions.lambda(Function1.class, physType.record(expressionList), row_)); }
private Expression toRows(PhysType physType, Expression expression) { if (physType.getFormat() == JavaRowFormat.SCALAR && Object[].class.isAssignableFrom(elementType) && getRowType().getFieldCount() == 1 && (table.unwrap(ScannableTable.class) != null || table.unwrap(FilterableTable.class) != null || table.unwrap(ProjectableFilterableTable.class) != null)) { return Expressions.call(BuiltInMethod.SLICE0.method, expression); } JavaRowFormat oldFormat = format(); if (physType.getFormat() == oldFormat && !hasCollectionField(rowType)) { return expression; } final ParameterExpression row_ = Expressions.parameter(elementType, "row"); final int fieldCount = table.getRowType().getFieldCount(); List<Expression> expressionList = new ArrayList<>(fieldCount); for (int i = 0; i < fieldCount; i++) { expressionList.add(fieldExpression(row_, i, physType, oldFormat)); } return Expressions.call(expression, BuiltInMethod.SELECT.method, Expressions.lambda(Function1.class, physType.record(expressionList), row_)); }