/** * Try to find a ResultColumn in the table represented by this FromBaseTable that matches the name * in the given ColumnReference. * * @param columnReference The columnReference whose name we're looking for in the given table. * @return A ResultColumn whose expression is the ColumnNode that matches the ColumnReference. * Returns null if there is no match. * @exception StandardException Thrown on error */ public ResultColumn getMatchingColumn(ColumnReference columnReference) throws StandardException { ResultColumn resultColumn = null; String columnsTableName; /* ** RESOLVE: When we add support for schemas, check to see if ** the column name specifies a schema, and if so, if this ** table is in that schema. */ columnsTableName = columnReference.getTableName(); // post 681, 1 may be no longer needed. 5 is the default case // now but what happens if the condition is false? Investigate. if (columnReference.getGeneratedToReplaceAggregate()) // 1 { resultColumn = resultColumns.getResultColumn(columnReference.getColumnName()); } else if (columnsTableName == null || columnsTableName.equals(correlationName)) // 5? { resultColumn = resultColumns.getAtMostOneResultColumn(columnReference, correlationName, false); } if (resultColumn != null) { columnReference.setTableNumber(tableNumber); columnReference.setColumnNumber(resultColumn.getColumnPosition()); } return resultColumn; }
public void build(Tree t, TreeBuilder builder) throws TreeParsingException, ColumnCallException { if (t.getType() == JdbcGrammarParser.JOINEXPRESSION || t.getType() == JdbcGrammarParser.MULTIJOINEXPRESSION) { this.tokenName = JdbcGrammarParser.tokenNames[t.getType()]; this.tokenType = t.getType(); this.logger.debug("BUILDING " + this.tokenName); for (int i = 0; i < t.getChildCount(); i++) { Tree child = t.getChild(i); switch (child.getType()) { case JdbcGrammarParser.LEFTEXPR: switch (child.getChild(0).getType()) { case JdbcGrammarParser.SUBQUERY: SubQuery subQuery = new SubQuery(child.getChild(0), builder); subQuery.setisPartOfJoin(); this.leftItem = subQuery; break; case JdbcGrammarParser.SOURCETABLE: Resolver resolve = new Resolver(builder); // whats the sourcetable? SourceTable tablenode = new SourceTable(child.getChild(0), builder); String alias = tablenode.getAlias(); // getting the columns for it List<ColumnCall> columnlist = resolve.parseSrcTableForJokers(tablenode); // making a new Subquery with those columns + // fromexpression this.logger.debug("got columns"); tablenode.alias = null; // making a fromexpression with that sourcetable FromExpression fromexpression = new FromExpression(tablenode, builder); Expression expression = new Expression(columnlist, builder); SelectStatement mySelectStatement = new SelectStatement(expression, fromexpression, builder); expression.setSelectStatement(mySelectStatement); SubQuery mySubQuery = null; if (alias != null) { // putting the selectstatement into a subquery mySubQuery = new SubQuery(alias, builder, mySelectStatement); } else { String newalias = ""; if (tablenode.getDataset() != null) { newalias += tablenode.getDataset() + "."; } newalias += tablenode.getName(); mySubQuery = new SubQuery(newalias, builder, mySelectStatement); } // adding the subquery to the fromexpression mySubQuery.setisPartOfJoin(); this.leftItem = mySubQuery; break; default: break; } break; case JdbcGrammarParser.RIGHTEXPR: switch (child.getChild(0).getType()) { case JdbcGrammarParser.SUBQUERY: SubQuery subQuery = new SubQuery(child.getChild(0), builder); subQuery.setisPartOfJoin(); this.rightItem = subQuery; break; case JdbcGrammarParser.SOURCETABLE: Resolver resolve = new Resolver(builder); // whats the sourcetable? SourceTable tablenode = new SourceTable(child.getChild(0), builder); String alias = tablenode.getAlias(); // getting the columns for it List<ColumnCall> columnlist = resolve.parseSrcTableForJokers(tablenode); // making a new Subquery with those columns + // fromexpression this.logger.debug("got columns"); tablenode.alias = null; // making a fromexpression with that sourcetable FromExpression fromexpression = new FromExpression(tablenode, builder); Expression expression = new Expression(columnlist, builder); SelectStatement mySelectStatement = new SelectStatement(expression, fromexpression, builder); expression.setSelectStatement(mySelectStatement); SubQuery mySubQuery = null; if (alias != null) { // putting the selectstatement into a subquery mySubQuery = new SubQuery(alias, builder, mySelectStatement); } else { String newalias = ""; if (tablenode.getDataset() != null) { newalias += tablenode.getDataset() + "."; } newalias += tablenode.getName(); mySubQuery = new SubQuery(newalias, builder, mySelectStatement); } // adding the subquery to the fromexpression mySubQuery.setisPartOfJoin(); this.rightItem = mySubQuery; break; default: break; } break; case JdbcGrammarParser.JOINTYPE: switch (child.getChild(0).getType()) { case JdbcGrammarParser.LEFT_KEYWORD: this.type = JoinType.LEFT; break; case JdbcGrammarParser.RIGHT_KEYWORD: this.type = JoinType.RIGHT; break; case JdbcGrammarParser.FULl_KEYWORD: this.type = JoinType.FULL; break; case JdbcGrammarParser.INNERKEYWORD: this.type = JoinType.INNER; break; default: break; } if (child.getChild(1).getType() == JdbcGrammarParser.EACH) { each = true; } break; default: break; } } for (int i = 0; i < t.getChildCount(); i++) { Tree child = t.getChild(i); switch (child.getType()) { case JdbcGrammarParser.ONCLAUSE: this.onClause = new OnClause(child, builder, this.selectStatement); break; default: break; } } for (Node condition : onClause.children) { OnClauseCondition onClauseCondition = OnClauseCondition.class.cast(condition); ColumnReference left = onClauseCondition.left; ColumnReference right = onClauseCondition.right; left.setPointedNode(left.searchPointedNodeInSubQuery((SubQuery) leftItem)); if (left.getPointedNode() == null) { left.setPointedNode(left.searchPointedNodeInSubQuery((SubQuery) rightItem)); } right.setPointedNode(right.searchPointedNodeInSubQuery((SubQuery) leftItem)); if (right.getPointedNode() == null) { right.setPointedNode(right.searchPointedNodeInSubQuery((SubQuery) rightItem)); } } } else { throw new TreeParsingException("This Tree is not an JOINEXPRESSION"); } }
@Override public void visit(ColumnReference obj) { this.onGoingExpression.push(obj.getMetadataObject()); }
public String getColumn() { return columnReference.getColumn(); }