Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JoinSelect 为什么只支持两张表的连表呢? #1244

Open
bigbaibaibai opened this issue Mar 21, 2024 · 0 comments
Open

JoinSelect 为什么只支持两张表的连表呢? #1244

bigbaibaibai opened this issue Mar 21, 2024 · 0 comments

Comments

@bigbaibaibai
Copy link

public class SqlParser {
  // ...
  public JoinSelect parseJoinSelect(SQLQueryExpr sqlExpr) throws SqlParseException {
      MySqlSelectQueryBlock query = (MySqlSelectQueryBlock) sqlExpr.getSubQuery().getQuery();

      List<From> joinedFrom = findJoinedFrom(query.getFrom());
      if (joinedFrom.size() != 2)
          throw new RuntimeException("currently supports only 2 tables join");

      JoinSelect joinSelect = createBasicJoinSelectAccordingToTableSource((SQLJoinTableSource) query.getFrom());
      List<Hint> hints = parseHints(query.getHints());
      joinSelect.setHints(hints);
      String firstTableAlias = joinedFrom.get(0).getAlias();
      String secondTableAlias = joinedFrom.get(1).getAlias();
      Map<String, Where> aliasToWhere = splitAndFindWhere(query.getWhere(), firstTableAlias, secondTableAlias);
      Map<String, List<SQLSelectOrderByItem>> aliasToOrderBy = splitAndFindOrder(query.getOrderBy(), firstTableAlias, secondTableAlias);
      List<Condition> connectedConditions = getConditionsFlatten(joinSelect.getConnectedWhere());
      joinSelect.setConnectedConditions(connectedConditions);
      fillTableSelectedJoin(joinSelect.getFirstTable(), query, joinedFrom.get(0), aliasToWhere.get(firstTableAlias), aliasToOrderBy.get(firstTableAlias), connectedConditions);
      fillTableSelectedJoin(joinSelect.getSecondTable(), query, joinedFrom.get(1), aliasToWhere.get(secondTableAlias), aliasToOrderBy.get(secondTableAlias), connectedConditions);

      updateJoinLimit(query.getLimit(), joinSelect);

      //todo: throw error feature not supported:  no group bys on joins ?
      return joinSelect;
  }
 // ...
}

这里看出来写死了只支持 2个表的join,为什么不将所有连表以数组或list的方式存储起来呢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant