Search in sources :

Example 1 with InParseNode

use of org.apache.phoenix.parse.InParseNode in project phoenix by apache.

the class SubqueryRewriter method visitLeave.

@Override
public ParseNode visitLeave(InParseNode node, List<ParseNode> l) throws SQLException {
    boolean isTopNode = topNode == node;
    if (isTopNode) {
        topNode = null;
    }
    SubqueryParseNode subqueryNode = (SubqueryParseNode) l.get(1);
    SelectStatement subquery = fixSubqueryStatement(subqueryNode.getSelectNode());
    String rhsTableAlias = ParseNodeFactory.createTempAlias();
    List<AliasedNode> selectNodes = fixAliasedNodes(subquery.getSelect(), true);
    subquery = NODE_FACTORY.select(subquery, !node.isSubqueryDistinct(), selectNodes);
    ParseNode onNode = getJoinConditionNode(l.get(0), selectNodes, rhsTableAlias);
    TableNode rhsTable = NODE_FACTORY.derivedTable(rhsTableAlias, subquery);
    JoinType joinType = isTopNode ? (node.isNegate() ? JoinType.Anti : JoinType.Semi) : JoinType.Left;
    ParseNode ret = isTopNode ? null : NODE_FACTORY.isNull(NODE_FACTORY.column(NODE_FACTORY.table(null, rhsTableAlias), selectNodes.get(0).getAlias(), null), !node.isNegate());
    tableNode = NODE_FACTORY.join(joinType, tableNode, rhsTable, onNode, false);
    return ret;
}
Also used : SelectStatement(org.apache.phoenix.parse.SelectStatement) SubqueryParseNode(org.apache.phoenix.parse.SubqueryParseNode) TableNode(org.apache.phoenix.parse.TableNode) LiteralParseNode(org.apache.phoenix.parse.LiteralParseNode) AndParseNode(org.apache.phoenix.parse.AndParseNode) ExistsParseNode(org.apache.phoenix.parse.ExistsParseNode) SubqueryParseNode(org.apache.phoenix.parse.SubqueryParseNode) RowValueConstructorParseNode(org.apache.phoenix.parse.RowValueConstructorParseNode) CompoundParseNode(org.apache.phoenix.parse.CompoundParseNode) ComparisonParseNode(org.apache.phoenix.parse.ComparisonParseNode) ColumnParseNode(org.apache.phoenix.parse.ColumnParseNode) InParseNode(org.apache.phoenix.parse.InParseNode) ParseNode(org.apache.phoenix.parse.ParseNode) JoinType(org.apache.phoenix.parse.JoinTableNode.JoinType) AliasedNode(org.apache.phoenix.parse.AliasedNode)

Aggregations

AliasedNode (org.apache.phoenix.parse.AliasedNode)1 AndParseNode (org.apache.phoenix.parse.AndParseNode)1 ColumnParseNode (org.apache.phoenix.parse.ColumnParseNode)1 ComparisonParseNode (org.apache.phoenix.parse.ComparisonParseNode)1 CompoundParseNode (org.apache.phoenix.parse.CompoundParseNode)1 ExistsParseNode (org.apache.phoenix.parse.ExistsParseNode)1 InParseNode (org.apache.phoenix.parse.InParseNode)1 JoinType (org.apache.phoenix.parse.JoinTableNode.JoinType)1 LiteralParseNode (org.apache.phoenix.parse.LiteralParseNode)1 ParseNode (org.apache.phoenix.parse.ParseNode)1 RowValueConstructorParseNode (org.apache.phoenix.parse.RowValueConstructorParseNode)1 SelectStatement (org.apache.phoenix.parse.SelectStatement)1 SubqueryParseNode (org.apache.phoenix.parse.SubqueryParseNode)1 TableNode (org.apache.phoenix.parse.TableNode)1