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 planEnumerableNestedLoopJoin.
private PlannerOp planEnumerableNestedLoopJoin(EnumerableNestedLoopJoin op, RelDataType rowType) {
PlannerOp left = convertRelNode(op.getLeft(), null, false, false);
PlannerOp right = convertRelNode(op.getRight(), null, false, false);
CompiledSQLExpression condition = SQLExpressionCompiler.compileExpression(op.getCondition());
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 NestedLoopJoinOp(fieldNames, columns, left, right, condition, op.getJoinType(), false);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataTypeField in project calcite by apache.
the class ElasticsearchSort method implement.
@Override
public void implement(Implementor implementor) {
implementor.visitChild(0, getInput());
if (!collation.getFieldCollations().isEmpty()) {
final List<String> keys = new ArrayList<>();
if (input instanceof Project) {
final List<RexNode> projects = ((Project) input).getProjects();
for (RelFieldCollation fieldCollation : collation.getFieldCollations()) {
RexNode project = projects.get(fieldCollation.getFieldIndex());
String name = project.accept(MapProjectionFieldVisitor.INSTANCE);
keys.add(ElasticsearchRules.quote(name) + ": " + direction(fieldCollation));
}
} else {
final List<RelDataTypeField> fields = getRowType().getFieldList();
for (RelFieldCollation fieldCollation : collation.getFieldCollations()) {
final String name = fields.get(fieldCollation.getFieldIndex()).getName();
keys.add(ElasticsearchRules.quote(name) + ": " + direction(fieldCollation));
}
}
implementor.add("\"sort\": [ " + Util.toString(keys, "{", "}, {", "}") + "]");
}
if (offset != null) {
implementor.add("\"from\": " + ((RexLiteral) offset).getValue());
}
if (fetch != null) {
implementor.add("\"size\": " + ((RexLiteral) fetch).getValue());
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataTypeField in project calcite by apache.
the class TableScanNode method createEnumerable.
private static TableScanNode createEnumerable(Compiler compiler, TableScan rel, Enumerable<Row> enumerable, final ImmutableIntList acceptedProjects, List<RexNode> rejectedFilters, final ImmutableIntList rejectedProjects) {
if (!rejectedFilters.isEmpty()) {
final RexNode filter = RexUtil.composeConjunction(rel.getCluster().getRexBuilder(), rejectedFilters, false);
assert filter != null;
// Re-map filter for the projects that have been applied already
final RexNode filter2;
final RelDataType inputRowType;
if (acceptedProjects == null) {
filter2 = filter;
inputRowType = rel.getRowType();
} else {
final Mapping mapping = Mappings.target(acceptedProjects, rel.getTable().getRowType().getFieldCount());
filter2 = RexUtil.apply(mapping, filter);
final RelDataTypeFactory.Builder builder = rel.getCluster().getTypeFactory().builder();
final List<RelDataTypeField> fieldList = rel.getTable().getRowType().getFieldList();
for (int acceptedProject : acceptedProjects) {
builder.add(fieldList.get(acceptedProject));
}
inputRowType = builder.build();
}
final Scalar condition = compiler.compile(ImmutableList.of(filter2), inputRowType);
final Context context = compiler.createContext();
enumerable = enumerable.where(new Predicate1<Row>() {
@Override
public boolean apply(Row row) {
context.values = row.getValues();
Boolean b = (Boolean) condition.execute(context);
return b != null && b;
}
});
}
if (rejectedProjects != null) {
enumerable = enumerable.select(new Function1<Row, Row>() {
final Object[] values = new Object[rejectedProjects.size()];
@Override
public Row apply(Row row) {
final Object[] inValues = row.getValues();
for (int i = 0; i < rejectedProjects.size(); i++) {
values[i] = inValues[rejectedProjects.get(i)];
}
return Row.asCopy(values);
}
});
}
return new TableScanNode(compiler, rel, enumerable);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataTypeField in project calcite by apache.
the class CalciteMetaImpl method columns.
public Enumerable<MetaColumn> columns(final MetaTable table_) {
final CalciteMetaTable table = (CalciteMetaTable) table_;
final RelDataType rowType = table.calciteTable.getRowType(getConnection().typeFactory);
return Linq4j.asEnumerable(rowType.getFieldList()).select(new Function1<RelDataTypeField, MetaColumn>() {
public MetaColumn apply(RelDataTypeField field) {
final int precision = field.getType().getSqlTypeName().allowsPrec() && !(field.getType() instanceof RelDataTypeFactoryImpl.JavaType) ? field.getType().getPrecision() : -1;
return new MetaColumn(table.tableCat, table.tableSchem, table.tableName, field.getName(), field.getType().getSqlTypeName().getJdbcOrdinal(), field.getType().getFullTypeString(), precision, field.getType().getSqlTypeName().allowsScale() ? field.getType().getScale() : null, 10, field.getType().isNullable() ? DatabaseMetaData.columnNullable : DatabaseMetaData.columnNoNulls, precision, field.getIndex() + 1, field.getType().isNullable() ? "YES" : "NO");
}
});
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataTypeField in project calcite by apache.
the class RelMdSize method averageColumnSizes.
public List<Double> averageColumnSizes(Values rel, RelMetadataQuery mq) {
final List<RelDataTypeField> fields = rel.getRowType().getFieldList();
final ImmutableList.Builder<Double> list = ImmutableList.builder();
for (int i = 0; i < fields.size(); i++) {
RelDataTypeField field = fields.get(i);
double d;
if (rel.getTuples().isEmpty()) {
d = averageTypeValueSize(field.getType());
} else {
d = 0;
for (ImmutableList<RexLiteral> literals : rel.getTuples()) {
d += typeValueSize(field.getType(), literals.get(i).getValueAs(Comparable.class));
}
d /= rel.getTuples().size();
}
list.add(d);
}
return list.build();
}
Aggregations