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); }
public ComparisonParseNode comparison(CompareOp op, ParseNode lhs, ParseNode rhs) { switch (op){ case LESS: return lt(lhs,rhs); case LESS_OR_EQUAL: return lte(lhs,rhs); case EQUAL: return equal(lhs,rhs); case NOT_EQUAL: return notEqual(lhs,rhs); case GREATER_OR_EQUAL: return gte(lhs,rhs); case GREATER: return gt(lhs,rhs); default: throw new IllegalArgumentException("Unexpcted CompareOp of " + op); } }
@Override public Void visitLeave(ComparisonParseNode node, List<Void> l) throws SQLException { if (!(node instanceof EqualParseNode)) return leaveBooleanNode(node, l); columnRefVisitor.reset(); node.getLHS().accept(columnRefVisitor); ColumnRefParseNodeVisitor.ColumnRefType lhsType = columnRefVisitor.getContentType(joinTable.getTableRefs()); Set<TableRef> lhsTableRefSet = Sets.newHashSet(columnRefVisitor.getTableRefSet()); columnRefVisitor.reset(); node.getRHS().accept(columnRefVisitor); ColumnRefParseNodeVisitor.ColumnRefType rhsType = columnRefVisitor.getContentType(joinTable.getTableRefs()); Set<TableRef> rhsTableRefSet = Sets.newHashSet(columnRefVisitor.getTableRefSet()); if ((lhsType == ColumnRefParseNodeVisitor.ColumnRefType.SELF_ONLY || lhsType == ColumnRefParseNodeVisitor.ColumnRefType.NONE) && (rhsType == ColumnRefParseNodeVisitor.ColumnRefType.SELF_ONLY || rhsType == ColumnRefParseNodeVisitor.ColumnRefType.NONE)) { joinTable.addFilter(node); } else if (lhsType == ColumnRefParseNodeVisitor.ColumnRefType.FOREIGN_ONLY && rhsType == ColumnRefParseNodeVisitor.ColumnRefType.SELF_ONLY) { onConditions.add((EqualParseNode) node); dependencies.addAll(lhsTableRefSet); } else if (rhsType == ColumnRefParseNodeVisitor.ColumnRefType.FOREIGN_ONLY && lhsType == ColumnRefParseNodeVisitor.ColumnRefType.SELF_ONLY) { onConditions.add(NODE_FACTORY.equal(node.getRHS(), node.getLHS())); dependencies.addAll(rhsTableRefSet); } else { throwAmbiguousJoinConditionException(); } return null; }
this.additionalSelectNodes.add(NODE_FACTORY.aliasedNode(alias, node.getLHS())); ParseNode lhsNode = NODE_FACTORY.column(tableName, alias, null); this.joinConditions.add(NODE_FACTORY.equal(lhsNode, node.getRHS())); return null; this.additionalSelectNodes.add(NODE_FACTORY.aliasedNode(alias, node.getRHS())); ParseNode rhsNode = NODE_FACTORY.column(tableName, alias, null); this.joinConditions.add(NODE_FACTORY.equal(node.getLHS(), rhsNode)); return null;
state._fsp--; if (state.failed) return ret; if ( state.backtracking==0 ) {w.add(t);w.add(factory.equal(e1,e2));}
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); }
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); }
public ComparisonParseNode comparison(CompareOp op, ParseNode lhs, ParseNode rhs) { switch (op){ case LESS: return lt(lhs,rhs); case LESS_OR_EQUAL: return lte(lhs,rhs); case EQUAL: return equal(lhs,rhs); case NOT_EQUAL: return notEqual(lhs,rhs); case GREATER_OR_EQUAL: return gte(lhs,rhs); case GREATER: return gt(lhs,rhs); default: throw new IllegalArgumentException("Unexpcted CompareOp of " + op); } }
public ComparisonParseNode comparison(CompareOp op, ParseNode lhs, ParseNode rhs) { switch (op){ case LESS: return lt(lhs,rhs); case LESS_OR_EQUAL: return lte(lhs,rhs); case EQUAL: return equal(lhs,rhs); case NOT_EQUAL: return notEqual(lhs,rhs); case GREATER_OR_EQUAL: return gte(lhs,rhs); case GREATER: return gt(lhs,rhs); default: throw new IllegalArgumentException("Unexpcted CompareOp of " + op); } }
this.additionalSelectNodes.add(NODE_FACTORY.aliasedNode(alias, node.getLHS())); ParseNode lhsNode = NODE_FACTORY.column(tableName, alias, null); this.joinConditions.add(NODE_FACTORY.equal(lhsNode, node.getRHS())); return null; this.additionalSelectNodes.add(NODE_FACTORY.aliasedNode(alias, node.getRHS())); ParseNode rhsNode = NODE_FACTORY.column(tableName, alias, null); this.joinConditions.add(NODE_FACTORY.equal(node.getLHS(), rhsNode)); return null;
@Override public Void visitLeave(ComparisonParseNode node, List<Void> l) throws SQLException { if (!(node instanceof EqualParseNode)) return leaveBooleanNode(node, l); columnRefVisitor.reset(); node.getLHS().accept(columnRefVisitor); ColumnRefParseNodeVisitor.ColumnRefType lhsType = columnRefVisitor.getContentType(joinTable.getTableRefs()); Set<TableRef> lhsTableRefSet = Sets.newHashSet(columnRefVisitor.getTableRefSet()); columnRefVisitor.reset(); node.getRHS().accept(columnRefVisitor); ColumnRefParseNodeVisitor.ColumnRefType rhsType = columnRefVisitor.getContentType(joinTable.getTableRefs()); Set<TableRef> rhsTableRefSet = Sets.newHashSet(columnRefVisitor.getTableRefSet()); if ((lhsType == ColumnRefParseNodeVisitor.ColumnRefType.SELF_ONLY || lhsType == ColumnRefParseNodeVisitor.ColumnRefType.NONE) && (rhsType == ColumnRefParseNodeVisitor.ColumnRefType.SELF_ONLY || rhsType == ColumnRefParseNodeVisitor.ColumnRefType.NONE)) { joinTable.addFilter(node); } else if (lhsType == ColumnRefParseNodeVisitor.ColumnRefType.FOREIGN_ONLY && rhsType == ColumnRefParseNodeVisitor.ColumnRefType.SELF_ONLY) { onConditions.add((EqualParseNode) node); dependencies.addAll(lhsTableRefSet); } else if (rhsType == ColumnRefParseNodeVisitor.ColumnRefType.FOREIGN_ONLY && lhsType == ColumnRefParseNodeVisitor.ColumnRefType.SELF_ONLY) { onConditions.add(NODE_FACTORY.equal(node.getRHS(), node.getLHS())); dependencies.addAll(rhsTableRefSet); } else { throwAmbiguousJoinConditionException(); } return null; }
@Override public Void visitLeave(ComparisonParseNode node, List<Void> l) throws SQLException { if (!(node instanceof EqualParseNode)) return leaveBooleanNode(node, l); columnRefVisitor.reset(); node.getLHS().accept(columnRefVisitor); ColumnRefParseNodeVisitor.ColumnRefType lhsType = columnRefVisitor.getContentType(joinTable.getTableRefs()); Set<TableRef> lhsTableRefSet = Sets.newHashSet(columnRefVisitor.getTableRefSet()); columnRefVisitor.reset(); node.getRHS().accept(columnRefVisitor); ColumnRefParseNodeVisitor.ColumnRefType rhsType = columnRefVisitor.getContentType(joinTable.getTableRefs()); Set<TableRef> rhsTableRefSet = Sets.newHashSet(columnRefVisitor.getTableRefSet()); if ((lhsType == ColumnRefParseNodeVisitor.ColumnRefType.SELF_ONLY || lhsType == ColumnRefParseNodeVisitor.ColumnRefType.NONE) && (rhsType == ColumnRefParseNodeVisitor.ColumnRefType.SELF_ONLY || rhsType == ColumnRefParseNodeVisitor.ColumnRefType.NONE)) { joinTable.addFilter(node); } else if (lhsType == ColumnRefParseNodeVisitor.ColumnRefType.FOREIGN_ONLY && rhsType == ColumnRefParseNodeVisitor.ColumnRefType.SELF_ONLY) { onConditions.add((EqualParseNode) node); dependencies.addAll(lhsTableRefSet); } else if (rhsType == ColumnRefParseNodeVisitor.ColumnRefType.FOREIGN_ONLY && lhsType == ColumnRefParseNodeVisitor.ColumnRefType.SELF_ONLY) { onConditions.add(NODE_FACTORY.equal(node.getRHS(), node.getLHS())); dependencies.addAll(rhsTableRefSet); } else { throwAmbiguousJoinConditionException(); } return null; }
this.additionalSelectNodes.add(NODE_FACTORY.aliasedNode(alias, node.getLHS())); ParseNode lhsNode = NODE_FACTORY.column(tableName, alias, null); this.joinConditions.add(NODE_FACTORY.equal(lhsNode, node.getRHS())); return null; this.additionalSelectNodes.add(NODE_FACTORY.aliasedNode(alias, node.getRHS())); ParseNode rhsNode = NODE_FACTORY.column(tableName, alias, null); this.joinConditions.add(NODE_FACTORY.equal(node.getLHS(), rhsNode)); return null;
state._fsp--; if (state.failed) return ret; if ( state.backtracking==0 ) {w.add(t);w.add(factory.equal(e1,e2));}
state._fsp--; if (state.failed) return ret; if ( state.backtracking==0 ) {w.add(t);w.add(factory.equal(e1,e2));}