Java Code Examples for org.apache.calcite.rel.RelNode#getTable()

The following examples show how to use org.apache.calcite.rel.RelNode#getTable() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SamzaSqlApplicationConfig.java    From samza with Apache License 2.0 6 votes vote down vote up
private static void populateSystemStreams(RelNode relNode, List<String> inputSystemStreams,
    List<String> outputSystemStreams) {
  if (relNode instanceof TableModify) {
    outputSystemStreams.add(getSystemStreamName(relNode));
  } else {
    if (relNode instanceof BiRel) {
      BiRel biRelNode = (BiRel) relNode;
      populateSystemStreams(biRelNode.getLeft(), inputSystemStreams, outputSystemStreams);
      populateSystemStreams(biRelNode.getRight(), inputSystemStreams, outputSystemStreams);
    } else {
      if (relNode.getTable() != null) {
        inputSystemStreams.add(getSystemStreamName(relNode));
      }
    }
  }
  List<RelNode> relNodes = relNode.getInputs();
  if (relNodes == null || relNodes.isEmpty()) {
    return;
  }
  relNodes.forEach(node -> populateSystemStreams(node, inputSystemStreams, outputSystemStreams));
}
 
Example 2
Source File: RelMdColumnOrigins.java    From Bats with Apache License 2.0 5 votes vote down vote up
public Set<RelColumnOrigin> getColumnOrigins(RelNode rel,
    RelMetadataQuery mq, int iOutputColumn) {
  // NOTE jvs 28-Mar-2006: We may get this wrong for a physical table
  // expression which supports projections.  In that case,
  // it's up to the plugin writer to override with the
  // correct information.

  if (rel.getInputs().size() > 0) {
    // No generic logic available for non-leaf rels.
    return null;
  }

  final Set<RelColumnOrigin> set = new HashSet<>();

  RelOptTable table = rel.getTable();
  if (table == null) {
    // Somebody is making column values up out of thin air, like a
    // VALUES clause, so we return an empty set.
    return set;
  }

  // Detect the case where a physical table expression is performing
  // projection, and say we don't know instead of making any assumptions.
  // (Theoretically we could try to map the projection using column
  // names.)  This detection assumes the table expression doesn't handle
  // rename as well.
  if (table.getRowType() != rel.getRowType()) {
    return null;
  }

  set.add(new RelColumnOrigin(table, iOutputColumn, false));
  return set;
}
 
Example 3
Source File: TableAccessMap.java    From Bats with Apache License 2.0 5 votes vote down vote up
public void visit(
    RelNode p,
    int ordinal,
    RelNode parent) {
  super.visit(p, ordinal, parent);
  RelOptTable table = p.getTable();
  if (table == null) {
    return;
  }
  Mode newAccess;

  // FIXME jvs 1-Feb-2006:  Don't rely on object type here;
  // eventually someone is going to write a rule which transforms
  // to something which doesn't inherit TableModify,
  // and this will break.  Need to make this explicit in
  // the RelNode interface.
  if (p instanceof TableModify) {
    newAccess = Mode.WRITE_ACCESS;
  } else {
    newAccess = Mode.READ_ACCESS;
  }
  List<String> key = getQualifiedName(table);
  Mode oldAccess = accessMap.get(key);
  if ((oldAccess != null) && (oldAccess != newAccess)) {
    newAccess = Mode.READWRITE_ACCESS;
  }
  accessMap.put(key, newAccess);
}
 
Example 4
Source File: SqlQueryParser.java    From quark with Apache License 2.0 5 votes vote down vote up
@Override
public void visit(RelNode node, int ordinal, RelNode parent) {
  if (node instanceof TableScan) {
    //TODO Implement some asserts here ? For e.g. usedTable should be null.
    usedTable = node.getTable();
  }
  super.visit(node, ordinal, parent);
}
 
Example 5
Source File: RelMdColumnOrigins.java    From calcite with Apache License 2.0 5 votes vote down vote up
public Set<RelColumnOrigin> getColumnOrigins(RelNode rel,
    RelMetadataQuery mq, int iOutputColumn) {
  // NOTE jvs 28-Mar-2006: We may get this wrong for a physical table
  // expression which supports projections.  In that case,
  // it's up to the plugin writer to override with the
  // correct information.

  if (rel.getInputs().size() > 0) {
    // No generic logic available for non-leaf rels.
    return null;
  }

  final Set<RelColumnOrigin> set = new HashSet<>();

  RelOptTable table = rel.getTable();
  if (table == null) {
    // Somebody is making column values up out of thin air, like a
    // VALUES clause, so we return an empty set.
    return set;
  }

  // Detect the case where a physical table expression is performing
  // projection, and say we don't know instead of making any assumptions.
  // (Theoretically we could try to map the projection using column
  // names.)  This detection assumes the table expression doesn't handle
  // rename as well.
  if (table.getRowType() != rel.getRowType()) {
    return null;
  }

  set.add(new RelColumnOrigin(table, iOutputColumn, false));
  return set;
}
 
Example 6
Source File: TableAccessMap.java    From calcite with Apache License 2.0 5 votes vote down vote up
public void visit(
    RelNode p,
    int ordinal,
    RelNode parent) {
  super.visit(p, ordinal, parent);
  RelOptTable table = p.getTable();
  if (table == null) {
    return;
  }
  Mode newAccess;

  // FIXME jvs 1-Feb-2006:  Don't rely on object type here;
  // eventually someone is going to write a rule which transforms
  // to something which doesn't inherit TableModify,
  // and this will break.  Need to make this explicit in
  // the RelNode interface.
  if (p instanceof TableModify) {
    newAccess = Mode.WRITE_ACCESS;
  } else {
    newAccess = Mode.READ_ACCESS;
  }
  List<String> key = getQualifiedName(table);
  Mode oldAccess = accessMap.get(key);
  if ((oldAccess != null) && (oldAccess != newAccess)) {
    newAccess = Mode.READWRITE_ACCESS;
  }
  accessMap.put(key, newAccess);
}
 
Example 7
Source File: MaterializationTest.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Override public void visit(RelNode node, int ordinal, RelNode parent) {
  if (node instanceof TableScan) {
    RelOptTable table = node.getTable();
    List<String> qName = table.getQualifiedName();
    names.add(qName);
  }
  super.visit(node, ordinal, parent);
}
 
Example 8
Source File: ScanPrel.java    From Bats with Apache License 2.0 4 votes vote down vote up
public static ScanPrel create(RelNode old, RelTraitSet traitSets,
    GroupScan scan, RelDataType rowType) {
  return new ScanPrel(old.getCluster(), traitSets,
      getCopy(scan), rowType, old.getTable());
}
 
Example 9
Source File: RelNodeConvertor.java    From Mycat2 with GNU General Public License v3.0 4 votes vote down vote up
public static Schema convertRelNode(RelNode relNode) {

        List<RelNode> inputs = relNode.getInputs();
        String relTypeName = relNode.getRelTypeName();
        String correlVariable = relNode.getCorrelVariable();
        RelOptTable table = relNode.getTable();
        Set<CorrelationId> variablesSet = relNode.getVariablesSet();
        switch (relTypeName) {
            case "LogicalValues": {
                return logicValues(relNode);
            }
            case "LogicalProject": {
                return logicProject(relNode);
            }
            case "LogicalAggregate": {
                return logicalAggregate(relNode);
            }
            case "LogicalTableScan": {
                return logicalTableScan(relNode);
            }
            case "LogicalIntersect":
            case "LogicalMinus":
            case "LogicalUnion": {
                return logicalSetOp(relNode);
            }
            case "LogicalSort": {
                return logicalSort(relNode);
            }
            case "LogicalFilter": {
                return logicalFilter(relNode);
            }
            case "LogicalJoin": {
                return logicalJoin(relNode);
            }
            case "LogicalCorrelate": {
                return logicalCorrelate(relNode);
            }
        }
        if (relNode instanceof TableScan) {
            List<FieldType> fields = getFields(relNode);
            TableScan relNode1 = (TableScan) relNode;
            MycatSQLTableScan unwrap = relNode1.getTable().unwrap(MycatSQLTableScan.class);
            if (unwrap != null) {
                return new FromSqlSchema(fields, unwrap.getTargetName(), unwrap.getSql());
            }
        }
        throw new UnsupportedOperationException();
    }
 
Example 10
Source File: DruidQuery.java    From calcite with Apache License 2.0 4 votes vote down vote up
@Override public boolean isValid(Litmus litmus, Context context) {
  if (!super.isValid(litmus, context)) {
    return false;
  }
  final String signature = signature();
  if (!isValidSignature(signature)) {
    return litmus.fail("invalid signature [{}]", signature);
  }
  if (rels.isEmpty()) {
    return litmus.fail("must have at least one rel");
  }
  for (int i = 0; i < rels.size(); i++) {
    final RelNode r = rels.get(i);
    if (i == 0) {
      if (!(r instanceof TableScan)) {
        return litmus.fail("first rel must be TableScan, was ", r);
      }
      if (r.getTable() != table) {
        return litmus.fail("first rel must be based on table table");
      }
    } else {
      final List<RelNode> inputs = r.getInputs();
      if (inputs.size() != 1 || inputs.get(0) != rels.get(i - 1)) {
        return litmus.fail("each rel must have a single input");
      }
      if (r instanceof Aggregate) {
        final Aggregate aggregate = (Aggregate) r;
        if (aggregate.getGroupSets().size() != 1) {
          return litmus.fail("no grouping sets");
        }
      }
      if (r instanceof Filter) {
        final Filter filter = (Filter) r;
        final DruidJsonFilter druidJsonFilter = DruidJsonFilter
            .toDruidFilters(filter.getCondition(), filter.getInput().getRowType(), this);
        if (druidJsonFilter == null) {
          return litmus.fail("invalid filter [{}]", filter.getCondition());
        }
      }
      if (r instanceof Sort) {
        final Sort sort = (Sort) r;
        if (sort.offset != null && RexLiteral.intValue(sort.offset) != 0) {
          return litmus.fail("offset not supported");
        }
      }
    }
  }
  return true;
}