private void statAllColumn(SQLAllColumnExpr x, SQLTableSource tableSource) { if (tableSource instanceof SQLExprTableSource) { statAllColumn(x, (SQLExprTableSource) tableSource); return; } if (tableSource instanceof SQLJoinTableSource) { SQLJoinTableSource join = (SQLJoinTableSource) tableSource; statAllColumn(x, join.getLeft()); statAllColumn(x, join.getRight()); } }
@Override public boolean visit(SQLJoinTableSource x) { x.getLeft().accept(this); if (x.getJoinType() == JoinType.COMMA) { print(','); } else { println(); printJoinType(x.getJoinType()); } print(' '); x.getRight().accept(this); if (x.getCondition() != null) { println(); print0(ucase ? "ON " : "on "); this.indentCount++; x.getCondition().accept(this); this.indentCount--; } if (x.getUsing().size() > 0) { print0(ucase ? " USING (" : " using ("); printAndAccept(x.getUsing(), ", "); print(')'); } if (x.getAlias() != null) { print0(ucase ? " AS " : " as "); print0(x.getAlias()); } return false; }
SQLTableSource b = rightJoin.getLeft(); SQLTableSource c = rightJoin.getRight(); SQLExpr on_ab = condition; SQLExpr on_bc = rightJoin.condition; setLeft(rightJoin); rightJoin.setLeft(a); rightJoin.setRight(b); String rightOwnerName = ((SQLPropertyExpr) on_ab_binaryOpExpr.getRight()).getOwnernName(); if (rightJoin.containsAlias(leftOwnerName) && rightJoin.containsAlias(rightOwnerName)) { on_ab_match = true; rightJoin.setCondition(on_ab); } else { rightJoin.setCondition(null); on_bc = SQLBinaryOpExpr.and(on_bc, on_ab); setRight(c); setCondition(on_bc);
private JoinSelect createBasicJoinSelectAccordingToTableSource(SQLJoinTableSource joinTableSource) throws SqlParseException { JoinSelect joinSelect = new JoinSelect(); if (joinTableSource.getCondition() != null) { Where where = Where.newInstance(); WhereParser whereParser = new WhereParser(this, joinTableSource.getCondition()); whereParser.parseWhere(joinTableSource.getCondition(), where); joinSelect.setConnectedWhere(where); } SQLJoinTableSource.JoinType joinType = joinTableSource.getJoinType(); joinSelect.setJoinType(joinType); return joinSelect; }
public boolean visit(SQLJoinTableSource x) { SQLTableSource left = x.getLeft(), right = x.getRight(); left.accept(this); right.accept(this); SQLExpr condition = x.getCondition(); if (condition != null) { condition.accept(this); } if (x.getUsing().size() > 0 && left instanceof SQLExprTableSource && right instanceof SQLExprTableSource) { SQLExpr leftExpr = ((SQLExprTableSource) left).getExpr(); SQLExpr rightExpr = ((SQLExprTableSource) right).getExpr(); for (SQLExpr expr : x.getUsing()) { if (expr instanceof SQLIdentifierExpr) { String name = ((SQLIdentifierExpr) expr).getName(); SQLPropertyExpr leftPropExpr = new SQLPropertyExpr(leftExpr, name); SQLPropertyExpr rightPropExpr = new SQLPropertyExpr(rightExpr, name); leftPropExpr.setResolvedTableSource(left); rightPropExpr.setResolvedTableSource(right); SQLBinaryOpExpr usingCondition = new SQLBinaryOpExpr(leftPropExpr, SQLBinaryOperator.Equality, rightPropExpr); usingCondition.accept(this); } } } return false; }
public boolean visit(SQLSubqueryTableSource x) { String subViewName = generateSubViewName(); SQLObject parent = x.getParent(); if(parent instanceof SQLSelectQueryBlock) { SQLSelectQueryBlock queryBlock = (SQLSelectQueryBlock) parent; queryBlock.setFrom(subViewName, x.getAlias()); } else if(parent instanceof SQLJoinTableSource) { SQLJoinTableSource join = (SQLJoinTableSource) parent; if (join.getLeft() == x) { join.setLeft(subViewName, x.getAlias()); } else if (join.getRight() == x) { join.setRight(subViewName, x.getAlias()); } } SQLCreateViewStatement stmt = new SQLCreateViewStatement(); stmt.setName(generateSubViewName()); SQLSelect select = x.getSelect(); stmt.setSubQuery(select); targetList.add(0, stmt); stmt.accept(new FromSubqueryResolver(targetList, viewName)); return false; }
tableSource = join.findTableSourceWithColumn(hash); if (tableSource == null) { final SQLTableSource left = join.getLeft(), right = join.getRight();
public SQLName getTableName() { if (tableSource instanceof SQLExprTableSource) { return ((SQLExprTableSource) tableSource).getName(); } if (tableSource instanceof SQLJoinTableSource) { SQLTableSource left = ((SQLJoinTableSource) tableSource).getLeft(); if (left instanceof SQLExprTableSource) { return ((SQLExprTableSource) left).getName(); } } return null; }
private void parseTable(SQLTableSource from) { if (from instanceof SQLExprTableSource) { val source = (SQLExprTableSource) from; if (source.getExpr() instanceof SQLIdentifierExpr) addTableAlias(from, (SQLIdentifierExpr) source.getExpr()); } else if (from instanceof SQLJoinTableSource) { val joinTableSource = (SQLJoinTableSource) from; parseTable(joinTableSource.getLeft()); parseTable(joinTableSource.getRight()); // maybe there are binding variants in connection val conditionOn = joinTableSource.getCondition(); if (conditionOn != null) conditionOn.accept(getAdapter()); } else if (from instanceof SQLSubqueryTableSource) { val tableSource = (SQLSubqueryTableSource) from; val query = tableSource.getSelect().getQuery(); val subParser = createSubQueryParser(query, QueryBelongs.FROM); addTableAlias(from, subParser); } }
SQLExpr condition = join.getCondition(); SQLTableSource right = join.getRight(); if (right instanceof SQLExprTableSource) { SQLExpr tableExpr = ((SQLExprTableSource) right).getExpr(); if (condition != join.getCondition()) { join.setCondition(condition); visitor.setSqlModified(true);
SQLJoinTableSource fromJoinSource = (SQLJoinTableSource) fromSource; System.out.println("SQLJoinTableSource:"); System.out.println("all:" + fromJoinSource.toString()); System.out.println("left:" + fromJoinSource.getLeft().toString() + ",class" + fromJoinSource.getLeft().getClass()); System.out.println("right:" + fromJoinSource.getRight().toString() + ",class" + fromJoinSource.getRight().getClass()); System.out.println("---------------------------");
public static void check(WallVisitor visitor, SQLJoinTableSource x) { SQLExpr condition = x.getCondition(); if (condition instanceof SQLName) { addViolation(visitor, ErrorCode.INVALID_JOIN_CONDITION, "invalid join condition", x); } } }
SQLJoinTableSource join = new SQLJoinTableSource(); join.setLeft(tableSource); join.setJoinType(joinType); join.setRight(rightTableSource); this.exprParser.exprList(join.getUsing(), join); accept(Token.RPAREN); } else if (lexer.token == Token.IDENTIFIER) { lexer.reset(savePoint); join.setRight(rightTableSource); return join; } else { join.setAlias(this.tableAlias()); join.setRight(rightTableSource); join.setNatural(natural); join.setCondition(expr()); } else if (lexer.token == Token.USING || lexer.identifierEquals(FnvHash.Constants.USING)) { if (lexer.token == Token.LPAREN) { lexer.nextToken(); this.exprParser.exprList(join.getUsing(), join); accept(Token.RPAREN); } else {
SQLTableSource right = join.getRight(); if (right instanceof SQLExprTableSource) { SQLExpr tableExpr = ((SQLExprTableSource) right).getExpr();
&& ((SQLJoinTableSource) tableSource).getCondition() == null) { lexer.nextToken(); SQLExpr leftCondidition = this.exprParser.expr(); ((SQLJoinTableSource) tableSource).setCondition(leftCondidition);
private static boolean isJoin(SQLQueryExpr sqlExpr,String sql) { MySqlSelectQueryBlock query = (MySqlSelectQueryBlock) sqlExpr.getSubQuery().getQuery(); return query.getFrom() instanceof SQLJoinTableSource && ((SQLJoinTableSource) query.getFrom()).getJoinType() != SQLJoinTableSource.JoinType.COMMA && sql.toLowerCase().contains("join"); }
public boolean visit(SQLJoinTableSource x) { SQLTableSource left = x.getLeft(), right = x.getRight(); left.accept(this); right.accept(this); SQLExpr condition = x.getCondition(); if (condition != null) { condition.accept(this); } if (x.getUsing().size() > 0 && left instanceof SQLExprTableSource && right instanceof SQLExprTableSource) { SQLExpr leftExpr = ((SQLExprTableSource) left).getExpr(); SQLExpr rightExpr = ((SQLExprTableSource) right).getExpr(); for (SQLExpr expr : x.getUsing()) { if (expr instanceof SQLIdentifierExpr) { String name = ((SQLIdentifierExpr) expr).getName(); SQLPropertyExpr leftPropExpr = new SQLPropertyExpr(leftExpr, name); SQLPropertyExpr rightPropExpr = new SQLPropertyExpr(rightExpr, name); leftPropExpr.setResolvedTableSource(left); rightPropExpr.setResolvedTableSource(right); SQLBinaryOpExpr usingCondition = new SQLBinaryOpExpr(leftPropExpr, SQLBinaryOperator.Equality, rightPropExpr); usingCondition.accept(this); } } } return false; }
SQLTableSource b = rightJoin.getLeft(); SQLTableSource c = rightJoin.getRight(); SQLExpr on_ab = condition; SQLExpr on_bc = rightJoin.condition; setLeft(rightJoin); rightJoin.setLeft(a); rightJoin.setRight(b); String rightOwnerName = ((SQLPropertyExpr) on_ab_binaryOpExpr.getRight()).getOwnernName(); if (rightJoin.containsAlias(leftOwnerName) && rightJoin.containsAlias(rightOwnerName)) { on_ab_match = true; rightJoin.setCondition(on_ab); } else { rightJoin.setCondition(null); on_bc = SQLBinaryOpExpr.and(on_bc, on_ab); setRight(c); setCondition(on_bc);