org.teiid.query.sql.lang.Query.getFrom()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(10.3k)|赞(0)|评价(0)|浏览(483)

本文整理了Java中org.teiid.query.sql.lang.Query.getFrom方法的一些代码示例,展示了Query.getFrom的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.getFrom方法的具体详情如下:
包路径:org.teiid.query.sql.lang.Query
类名称:Query
方法名:getFrom

Query.getFrom介绍

[英]Get the from clause for the query.
[中]获取查询的from子句。

代码示例

代码示例来源:origin: org.jboss.teiid/teiid-engine

private boolean isSimpleJoin(Query query) {
  if (query.getFrom() != null) {
    for (FromClause clause : query.getFrom().getClauses()) {
      if (RuleCollapseSource.hasOuterJoins(clause)) {
        return false;
      }
    }
  }
  return true;
}

代码示例来源:origin: teiid/teiid

private boolean isSimpleJoin(Query query) {
  if (query.getFrom() != null) {
    for (FromClause clause : query.getFrom().getClauses()) {
      if (RuleCollapseSource.hasOuterJoins(clause)) {
        return false;
      }
    }
  }
  return true;
}

代码示例来源:origin: org.teiid/teiid-engine

private boolean isSimpleJoin(Query query) {
  if (query.getFrom() != null) {
    for (FromClause clause : query.getFrom().getClauses()) {
      if (RuleCollapseSource.hasOuterJoins(clause)) {
        return false;
      }
    }
  }
  return true;
}

代码示例来源:origin: org.jboss.teiid/teiid-engine

@Override
  public void visit(Query query) {
    //don't allow confusion with deep nesting by removing intermediate groups
    List<GroupSymbol> fromGroups = null;
    if (query.getFrom() != null) {
      fromGroups = query.getFrom().getGroups();
      HashMap<GroupSymbol, GroupSymbol> groupMap = new HashMap<GroupSymbol, GroupSymbol>();
      for (GroupSymbol g : fromGroups) {
        groupMap.put(g, g);
      }
      visitor.outerGroups.add(groupMap);
    }
    super.visit(query);
    if (fromGroups != null) {
      visitor.outerGroups.remove(visitor.outerGroups.size() - 1);
    }
  }
});

代码示例来源:origin: teiid/teiid

@Override
  public void visit(Query query) {
    //don't allow confusion with deep nesting by removing intermediate groups
    List<GroupSymbol> fromGroups = null;
    if (query.getFrom() != null) {
      fromGroups = query.getFrom().getGroups();
      HashMap<GroupSymbol, GroupSymbol> groupMap = new HashMap<GroupSymbol, GroupSymbol>();
      for (GroupSymbol g : fromGroups) {
        groupMap.put(g, g);
      }
      visitor.outerGroups.add(groupMap);
    }
    super.visit(query);
    if (fromGroups != null) {
      visitor.outerGroups.remove(visitor.outerGroups.size() - 1);
    }
  }
});

代码示例来源:origin: org.teiid/teiid-engine

@Override
  public void visit(Query query) {
    //don't allow confusion with deep nesting by removing intermediate groups
    List<GroupSymbol> fromGroups = null;
    if (query.getFrom() != null) {
      fromGroups = query.getFrom().getGroups();
      HashMap<GroupSymbol, GroupSymbol> groupMap = new HashMap<GroupSymbol, GroupSymbol>();
      for (GroupSymbol g : fromGroups) {
        groupMap.put(g, g);
      }
      visitor.outerGroups.add(groupMap);
    }
    super.visit(query);
    if (fromGroups != null) {
      visitor.outerGroups.remove(visitor.outerGroups.size() - 1);
    }
  }
});

代码示例来源:origin: org.jboss.teiid/teiid-engine

private Map<Integer, Object> createXMLColumnMetadata(Query xmlCommand) {
  GroupSymbol doc = xmlCommand.getFrom().getGroups().get(0);
  Map<Integer, Object> xmlMetadata = getDefaultColumn(doc.getName(), XML_COLUMN_NAME, XMLType.class);
  // Override size as XML may be big        
  xmlMetadata.put(ResultsMetadataConstants.DISPLAY_SIZE, JDBCSQLTypeInfo.XML_COLUMN_LENGTH);
  
  return xmlMetadata;
}

代码示例来源:origin: org.teiid/teiid-engine

/**
 * This validation is more convoluted than needed since it is being run before rewrite/planning.
 * Ideally we would already have correlated references set on the subqueries.
 */
private void validateCorrelatedReferences(Query query,
    final List<GroupSymbol> correlationGroups, final Set<Expression> groupingSymbols, LanguageObject object, LinkedHashSet<Expression> invalid) {
  if (query.getFrom() == null) {
    return;
  }
  ElementCollectorVisitor ecv = new ElementCollectorVisitor(invalid) {
    public void visit(ElementSymbol obj) {
      if (obj.isExternalReference() && correlationGroups.contains(obj.getGroupSymbol())
           && (groupingSymbols == null || !groupingSymbols.contains(obj))) {
        super.visit(obj);
      }
    }
  };
  AggregateStopNavigator asn = new AggregateStopNavigator(ecv, groupingSymbols);
  object.acceptVisitor(asn);
}

代码示例来源:origin: org.teiid/teiid-engine

/**
* Take the query, built straight from the subtree, and rebuild as a simple query
* if possible.
* @param query Query built from collapsing the source nodes
* @return Same query with simplified from clause if possible 
*/
private void simplifyFromClause(Query query) {
  From from = query.getFrom();
  List<FromClause> clauses = from.getClauses();
  FromClause rootClause = clauses.get(0);
    // If all joins are inner joins, move criteria to WHERE and make 
  // FROM a list of groups instead of a tree of JoinPredicates
  if(! hasOuterJoins(rootClause)) {
    from.setClauses(new ArrayList<FromClause>());
    shredJoinTree(rootClause, query);
  } // else leave as is
}

代码示例来源:origin: org.jboss.teiid/teiid-engine

/**
* Take the query, built straight from the subtree, and rebuild as a simple query
* if possible.
* @param query Query built from collapsing the source nodes
* @return Same query with simplified from clause if possible 
*/
private void simplifyFromClause(Query query) {
  From from = query.getFrom();
  List<FromClause> clauses = from.getClauses();
  FromClause rootClause = clauses.get(0);
    // If all joins are inner joins, move criteria to WHERE and make 
  // FROM a list of groups instead of a tree of JoinPredicates
  if(! hasOuterJoins(rootClause)) {
    from.setClauses(new ArrayList<FromClause>());
    shredJoinTree(rootClause, query);
  } // else leave as is
}

代码示例来源:origin: teiid/teiid

/**
* Take the query, built straight from the subtree, and rebuild as a simple query
* if possible.
* @param query Query built from collapsing the source nodes
* @return Same query with simplified from clause if possible 
*/
private void simplifyFromClause(Query query) {
  From from = query.getFrom();
  List<FromClause> clauses = from.getClauses();
  FromClause rootClause = clauses.get(0);
    // If all joins are inner joins, move criteria to WHERE and make 
  // FROM a list of groups instead of a tree of JoinPredicates
  if(! hasOuterJoins(rootClause)) {
    from.setClauses(new ArrayList<FromClause>());
    shredJoinTree(rootClause, query);
  } // else leave as is
}

代码示例来源:origin: teiid/teiid

private void helpCheckFrom(Query query, String[] groupIDs) { 
  From from = query.getFrom();
  List<GroupSymbol> groups = from.getGroups();            
  assertEquals("Wrong number of group IDs: ", groupIDs.length, groups.size()); //$NON-NLS-1$
  
  for(int i=0; i<groups.size(); i++) { 
    GroupSymbol group = groups.get(i);
    assertNotNull(group.getMetadataID());
    assertEquals("Group ID does not match: ", groupIDs[i].toUpperCase(), group.getNonCorrelationName().toUpperCase()); //$NON-NLS-1$
  }
}

代码示例来源:origin: teiid/teiid

@Test public void testOptionMakedep() throws Exception {
  String sql = "SELECT A.alert_id " + //$NON-NLS-1$
    "FROM (FSK_ALERT AS A MAKEDEP INNER JOIN Core.FSC_PARTY_DIM AS C ON A.primary_entity_key = C.PARTY_KEY) " +//$NON-NLS-1$
    "LEFT OUTER JOIN FSK_SCENARIO AS S ON A.scenario_id = S.scenario_id ";//$NON-NLS-1$ 
  Query command = (Query)new QueryParser().parseCommand(sql);
  JoinPredicate predicate = (JoinPredicate)command.getFrom().getClauses().get(0);
  assertTrue(((JoinPredicate)predicate.getLeftClause()).getLeftClause().isMakeDep());
}

代码示例来源:origin: teiid/teiid

@Test public void testTableAliasString() throws Exception {
  String sql = "select \"pm1g2\".* from pm1.g1 as \"pm1g2\"";
  Query query = (Query)helpResolve(sql);
  UnaryFromClause ufc = (UnaryFromClause)query.getFrom().getClauses().get(0);
  GroupSymbol gs = ufc.getGroup();
  assertEquals("pm1g2", gs.getName());
  assertEquals("SELECT pm1g2.* FROM pm1.g1 AS pm1g2", query.toString());
}

代码示例来源:origin: teiid/teiid

@Test public void testSubqueryAliasWithPeriod() throws Exception {
  String sql = "select \"pm1.g2\".x from (select 1 as x) as \"pm1.g2\"";
  Query query = (Query)helpResolve(sql);
  SubqueryFromClause sfc = (SubqueryFromClause)query.getFrom().getClauses().get(0);
  GroupSymbol gs = sfc.getGroupSymbol();
  assertEquals("pm1.g2", gs.getName());
  assertNull(gs.getDefinition());
  assertEquals("SELECT \"pm1.g2\".x FROM (SELECT 1 AS x) AS \"pm1.g2\"", query.toString());
  assertEquals("SELECT \"pm1.g2\".x FROM (SELECT 1 AS x) AS \"pm1.g2\"", query.clone().toString());
  assertEquals("[\"pm1.g2\".x]", query.getProjectedSymbols().toString());
}

代码示例来源:origin: teiid/teiid

@Test public void testTableAliasWithMultiplePeriods() throws Exception {
  String sql = "select \"pm1..g2\".e1 from pm1.g1 as \"pm1..g2\"";
  Query query = (Query)helpResolve(sql);
  UnaryFromClause ufc = (UnaryFromClause)query.getFrom().getClauses().get(0);
  GroupSymbol gs = ufc.getGroup();
  assertEquals("pm1..g2", gs.getName());
  assertEquals("pm1.g1", gs.getDefinition());
  assertEquals("SELECT \"pm1..g2\".e1 FROM pm1.g1 AS \"pm1..g2\"", query.toString());
  assertEquals("[\"pm1..g2\".e1]", query.getProjectedSymbols().toString());
}

代码示例来源:origin: teiid/teiid

@Test public void testTableAliasWithPeriod() throws Exception {
  String sql = "select \"pm1.g2\".*, e1, \"pm1.g2\".e2, pm1.g2.e2 from pm1.g1 as \"pm1.g2\"";
  Query query = (Query)helpResolve(sql);
  UnaryFromClause ufc = (UnaryFromClause)query.getFrom().getClauses().get(0);
  GroupSymbol gs = ufc.getGroup();
  assertEquals("pm1.g2", gs.getName());
  assertEquals("pm1.g1", gs.getDefinition());
  assertFalse(gs.isTempTable());
  assertEquals("SELECT \"pm1.g2\".*, e1, \"pm1.g2\".e2, \"pm1.g2\".e2 FROM pm1.g1 AS \"pm1.g2\"", query.toString());
  assertEquals("[\"pm1.g2\".e1, \"pm1.g2\".e2, \"pm1.g2\".e3, \"pm1.g2\".e4, e1, \"pm1.g2\".e2, \"pm1.g2\".e2]", query.getProjectedSymbols().toString());
}

代码示例来源:origin: org.teiid/teiid-engine

public void visit(Query obj) {
  preVisitVisitor(obj);
  visitNodes(obj.getWith());
  visitNode(obj.getSelect());
  visitNode(obj.getInto());
  visitNode(obj.getFrom());
  visitNode(obj.getCriteria());
  visitNode(obj.getGroupBy());
  visitNode(obj.getHaving());
  visitNode(obj.getOrderBy());
  visitNode(obj.getLimit());
  visitNode(obj.getOption());
  postVisitVisitor(obj);
}
public void visit(RaiseStatement obj) {

代码示例来源:origin: teiid/teiid

public void visit(Query obj) {
  preVisitVisitor(obj);
  visitNodes(obj.getWith());
  visitNode(obj.getSelect());
  visitNode(obj.getInto());
  visitNode(obj.getFrom());
  visitNode(obj.getCriteria());
  visitNode(obj.getGroupBy());
  visitNode(obj.getHaving());
  visitNode(obj.getOrderBy());
  visitNode(obj.getLimit());
  visitNode(obj.getOption());
  postVisitVisitor(obj);
}
public void visit(RaiseStatement obj) {

代码示例来源:origin: org.jboss.teiid/teiid-engine

public void visit(Query obj) {
  preVisitVisitor(obj);
  visitNodes(obj.getWith());
  visitNode(obj.getSelect());
  visitNode(obj.getInto());
  visitNode(obj.getFrom());
  visitNode(obj.getCriteria());
  visitNode(obj.getGroupBy());
  visitNode(obj.getHaving());
  visitNode(obj.getOrderBy());
  visitNode(obj.getLimit());
  visitNode(obj.getOption());
  postVisitVisitor(obj);
}
public void visit(RaiseStatement obj) {

相关文章