use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode in project calcite by apache.
the class RelMdMemory method cumulativeMemoryWithinPhase.
/**
* Catch-all implementation for
* {@link BuiltInMetadata.Memory#cumulativeMemoryWithinPhase()},
* invoked using reflection.
*
* @see org.apache.calcite.rel.metadata.RelMetadataQuery#memory
*/
public Double cumulativeMemoryWithinPhase(RelNode rel, RelMetadataQuery mq) {
Double nullable = mq.memory(rel);
if (nullable == null) {
return null;
}
Boolean isPhaseTransition = mq.isPhaseTransition(rel);
if (isPhaseTransition == null) {
return null;
}
double d = nullable;
if (!isPhaseTransition) {
for (RelNode input : rel.getInputs()) {
nullable = mq.cumulativeMemoryWithinPhase(input);
if (nullable == null) {
return null;
}
d += nullable;
}
}
return d;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode in project calcite by apache.
the class RelMdNodeTypes method getNodeTypes.
private static Multimap<Class<? extends RelNode>, RelNode> getNodeTypes(RelNode rel, Class<? extends RelNode> c, RelMetadataQuery mq) {
final Multimap<Class<? extends RelNode>, RelNode> nodeTypeCount = ArrayListMultimap.create();
for (RelNode input : rel.getInputs()) {
Multimap<Class<? extends RelNode>, RelNode> partialNodeTypeCount = mq.getNodeTypes(input);
if (partialNodeTypeCount == null) {
return null;
}
nodeTypeCount.putAll(partialNodeTypeCount);
}
nodeTypeCount.put(c, rel);
return nodeTypeCount;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode in project calcite by apache.
the class RelJson method create.
public RelNode create(Map<String, Object> map) {
String type = (String) map.get("type");
Constructor constructor = getConstructor(type);
try {
return (RelNode) constructor.newInstance(map);
} catch (InstantiationException e) {
throw new RuntimeException("while invoking constructor for type '" + type + "'", e);
} catch (IllegalAccessException e) {
throw new RuntimeException("while invoking constructor for type '" + type + "'", e);
} catch (InvocationTargetException e) {
throw new RuntimeException("while invoking constructor for type '" + type + "'", e);
} catch (ClassCastException e) {
throw new RuntimeException("while invoking constructor for type '" + type + "'", e);
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode in project calcite by apache.
the class RelJsonReader method readRel.
private void readRel(final Map<String, Object> jsonRel) {
String id = (String) jsonRel.get("id");
String type = (String) jsonRel.get("relOp");
Constructor constructor = relJson.getConstructor(type);
RelInput input = new RelInput() {
public RelOptCluster getCluster() {
return cluster;
}
public RelTraitSet getTraitSet() {
return cluster.traitSetOf(Convention.NONE);
}
public RelOptTable getTable(String table) {
final List<String> list = getStringList(table);
return relOptSchema.getTableForMember(list);
}
public RelNode getInput() {
final List<RelNode> inputs = getInputs();
assert inputs.size() == 1;
return inputs.get(0);
}
public List<RelNode> getInputs() {
final List<String> jsonInputs = getStringList("inputs");
if (jsonInputs == null) {
return ImmutableList.of(lastRel);
}
final List<RelNode> inputs = new ArrayList<>();
for (String jsonInput : jsonInputs) {
inputs.add(lookupInput(jsonInput));
}
return inputs;
}
public RexNode getExpression(String tag) {
return relJson.toRex(this, jsonRel.get(tag));
}
public ImmutableBitSet getBitSet(String tag) {
return ImmutableBitSet.of(getIntegerList(tag));
}
public List<ImmutableBitSet> getBitSetList(String tag) {
List<List<Integer>> list = getIntegerListList(tag);
if (list == null) {
return null;
}
final ImmutableList.Builder<ImmutableBitSet> builder = ImmutableList.builder();
for (List<Integer> integers : list) {
builder.add(ImmutableBitSet.of(integers));
}
return builder.build();
}
public List<String> getStringList(String tag) {
// noinspection unchecked
return (List<String>) jsonRel.get(tag);
}
public List<Integer> getIntegerList(String tag) {
// noinspection unchecked
return (List<Integer>) jsonRel.get(tag);
}
public List<List<Integer>> getIntegerListList(String tag) {
// noinspection unchecked
return (List<List<Integer>>) jsonRel.get(tag);
}
public List<AggregateCall> getAggregateCalls(String tag) {
@SuppressWarnings("unchecked") final List<Map<String, Object>> jsonAggs = (List) jsonRel.get(tag);
final List<AggregateCall> inputs = new ArrayList<>();
for (Map<String, Object> jsonAggCall : jsonAggs) {
inputs.add(toAggCall(jsonAggCall));
}
return inputs;
}
public Object get(String tag) {
return jsonRel.get(tag);
}
public String getString(String tag) {
return (String) jsonRel.get(tag);
}
public float getFloat(String tag) {
return ((Number) jsonRel.get(tag)).floatValue();
}
public boolean getBoolean(String tag, boolean default_) {
final Boolean b = (Boolean) jsonRel.get(tag);
return b != null ? b : default_;
}
public <E extends Enum<E>> E getEnum(String tag, Class<E> enumClass) {
return Util.enumVal(enumClass, getString(tag).toUpperCase(Locale.ROOT));
}
public List<RexNode> getExpressionList(String tag) {
@SuppressWarnings("unchecked") final List<Object> jsonNodes = (List) jsonRel.get(tag);
final List<RexNode> nodes = new ArrayList<>();
for (Object jsonNode : jsonNodes) {
nodes.add(relJson.toRex(this, jsonNode));
}
return nodes;
}
public RelDataType getRowType(String tag) {
final Object o = jsonRel.get(tag);
return relJson.toType(cluster.getTypeFactory(), o);
}
public RelDataType getRowType(String expressionsTag, String fieldsTag) {
final List<RexNode> expressionList = getExpressionList(expressionsTag);
@SuppressWarnings("unchecked") final List<String> names = (List<String>) get(fieldsTag);
return cluster.getTypeFactory().createStructType(new AbstractList<Map.Entry<String, RelDataType>>() {
@Override
public Map.Entry<String, RelDataType> get(int index) {
return Pair.of(names.get(index), expressionList.get(index).getType());
}
@Override
public int size() {
return names.size();
}
});
}
public RelCollation getCollation() {
// noinspection unchecked
return relJson.toCollation((List) get("collation"));
}
public RelDistribution getDistribution() {
return relJson.toDistribution(get("distribution"));
}
public ImmutableList<ImmutableList<RexLiteral>> getTuples(String tag) {
// noinspection unchecked
final List<List> jsonTuples = (List) get(tag);
final ImmutableList.Builder<ImmutableList<RexLiteral>> builder = ImmutableList.builder();
for (List jsonTuple : jsonTuples) {
builder.add(getTuple(jsonTuple));
}
return builder.build();
}
public ImmutableList<RexLiteral> getTuple(List jsonTuple) {
final ImmutableList.Builder<RexLiteral> builder = ImmutableList.builder();
for (Object jsonValue : jsonTuple) {
builder.add((RexLiteral) relJson.toRex(this, jsonValue));
}
return builder.build();
}
};
try {
final RelNode rel = (RelNode) constructor.newInstance(input);
relMap.put(id, rel);
lastRel = rel;
} catch (InstantiationException | IllegalAccessException e) {
throw new RuntimeException(e);
} catch (InvocationTargetException e) {
final Throwable e2 = e.getCause();
if (e2 instanceof RuntimeException) {
throw (RuntimeException) e2;
}
throw new RuntimeException(e2);
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode in project calcite by apache.
the class RelJsonWriter method explainInputs.
private List<Object> explainInputs(List<RelNode> inputs) {
final List<Object> list = jsonBuilder.list();
for (RelNode input : inputs) {
String id = relIdMap.get(input);
if (id == null) {
input.explain(this);
id = previousId;
}
list.add(id);
}
return list;
}
Aggregations