use of org.apache.phoenix.parse.RowValueConstructorParseNode in project phoenix by apache.
the class ExpressionCompiler method visitLeave.
@Override
public Expression visitLeave(ComparisonParseNode node, List<Expression> children) throws SQLException {
ParseNode lhsNode = node.getChildren().get(0);
ParseNode rhsNode = node.getChildren().get(1);
Expression lhsExpr = children.get(0);
Expression rhsExpr = children.get(1);
CompareOp op = node.getFilterOp();
if (lhsNode instanceof RowValueConstructorParseNode && rhsNode instanceof RowValueConstructorParseNode) {
int i = 0;
for (; i < Math.min(lhsExpr.getChildren().size(), rhsExpr.getChildren().size()); i++) {
addBindParamMetaData(lhsNode.getChildren().get(i), rhsNode.getChildren().get(i), lhsExpr.getChildren().get(i), rhsExpr.getChildren().get(i));
}
for (; i < lhsExpr.getChildren().size(); i++) {
addBindParamMetaData(lhsNode.getChildren().get(i), null, lhsExpr.getChildren().get(i), null);
}
for (; i < rhsExpr.getChildren().size(); i++) {
addBindParamMetaData(null, rhsNode.getChildren().get(i), null, rhsExpr.getChildren().get(i));
}
} else if (lhsExpr instanceof RowValueConstructorExpression) {
addBindParamMetaData(lhsNode.getChildren().get(0), rhsNode, lhsExpr.getChildren().get(0), rhsExpr);
for (int i = 1; i < lhsExpr.getChildren().size(); i++) {
addBindParamMetaData(lhsNode.getChildren().get(i), null, lhsExpr.getChildren().get(i), null);
}
} else if (rhsExpr instanceof RowValueConstructorExpression) {
addBindParamMetaData(lhsNode, rhsNode.getChildren().get(0), lhsExpr, rhsExpr.getChildren().get(0));
for (int i = 1; i < rhsExpr.getChildren().size(); i++) {
addBindParamMetaData(null, rhsNode.getChildren().get(i), null, rhsExpr.getChildren().get(i));
}
} else {
addBindParamMetaData(lhsNode, rhsNode, lhsExpr, rhsExpr);
}
return wrapGroupByExpression(ComparisonExpression.create(op, children, context.getTempPtr(), context.getCurrentTable().getTable().rowKeyOrderOptimizable()));
}
use of org.apache.phoenix.parse.RowValueConstructorParseNode in project phoenix by apache.
the class SubqueryRewriter method getJoinConditionNode.
private ParseNode getJoinConditionNode(ParseNode lhs, List<AliasedNode> rhs, String rhsTableAlias) throws SQLException {
List<ParseNode> lhsNodes;
if (lhs instanceof RowValueConstructorParseNode) {
lhsNodes = ((RowValueConstructorParseNode) lhs).getChildren();
} else {
lhsNodes = Collections.singletonList(lhs);
}
if (lhsNodes.size() != (rhs.size() - 1))
throw new SQLExceptionInfo.Builder(SQLExceptionCode.SUBQUERY_RETURNS_DIFFERENT_NUMBER_OF_FIELDS).build().buildException();
int count = lhsNodes.size();
TableName rhsTableName = NODE_FACTORY.table(null, rhsTableAlias);
List<ParseNode> equalNodes = Lists.newArrayListWithExpectedSize(count);
for (int i = 0; i < count; i++) {
ParseNode rhsNode = NODE_FACTORY.column(rhsTableName, rhs.get(i + 1).getAlias(), null);
equalNodes.add(NODE_FACTORY.equal(lhsNodes.get(i), rhsNode));
}
return count == 1 ? equalNodes.get(0) : NODE_FACTORY.and(equalNodes);
}
Aggregations