@Override public void visit( Join join ) { join.getLeft().accept(this); // if (join.getType() != JoinType.INNER) { sb.append(' ').append(join.type().symbol()); // } else { // sb.append(','); // } append(' '); join.getRight().accept(this); append(" ON "); join.getJoinCondition().accept(this); }
@Override public void visit( Join join ) { join.getLeft().accept(this); // if (join.getType() != JoinType.INNER) { sb.append(' ').append(join.type().symbol()); // } else { // sb.append(','); // } append(' '); join.getRight().accept(this); append(" ON "); join.getJoinCondition().accept(this); }
@Override public void visit( Join join ) { strategy.visit(join); enqueue(join.getLeft()); enqueue(join.getJoinCondition()); enqueue(join.getRight()); visitNext(); }
protected boolean usesSelector( Join join, SelectorName selector ) { Source left = join.getLeft(); if (left instanceof Selector && selector.equals(((Selector)left).aliasOrName())) return true; if (left instanceof Join && usesSelector((Join)left, selector)) return true; Source right = join.getRight(); if (right instanceof Selector && selector.equals(((Selector)right).aliasOrName())) return true; if (right instanceof Join && usesSelector((Join)right, selector)) return true; return false; }
@Override public void visit( Join join ) { strategy.visit(join); enqueue(join.getLeft()); enqueue(join.getJoinCondition()); enqueue(join.getRight()); visitNext(); }
protected boolean usesSelector( Join join, SelectorName selector ) { Source left = join.getLeft(); if (left instanceof Selector && selector.equals(((Selector)left).aliasOrName())) return true; if (left instanceof Join && usesSelector((Join)left, selector)) return true; Source right = join.getRight(); if (right instanceof Selector && selector.equals(((Selector)right).aliasOrName())) return true; if (right instanceof Join && usesSelector((Join)right, selector)) return true; return false; }
protected QueryBuilder createJoin( JoinCondition condition ) { // CROSS joins have a higher precedence, so we may need to adjust the existing left side in this case... if (type == JoinType.CROSS && source instanceof Join && ((Join)source).type() != JoinType.CROSS) { // A CROSS join follows a non-CROSS join, so the CROSS join becomes precendent ... Join left = (Join)source; Join cross = new Join(left.getRight(), type, rightSource, condition); source = new Join(left.getLeft(), left.type(), cross, left.getJoinCondition()); } else { // Otherwise, just create using usual precedence ... source = new Join(source, type, rightSource, condition); } return QueryBuilder.this; } }
protected QueryBuilder createJoin( JoinCondition condition ) { // CROSS joins have a higher precedence, so we may need to adjust the existing left side in this case... if (type == JoinType.CROSS && source instanceof Join && ((Join)source).type() != JoinType.CROSS) { // A CROSS join follows a non-CROSS join, so the CROSS join becomes precendent ... Join left = (Join)source; Join cross = new Join(left.getRight(), type, rightSource, condition); source = new Join(left.getLeft(), left.type(), cross, left.getJoinCondition()); } else { // Otherwise, just create using usual precedence ... source = new Join(source, type, rightSource, condition); } return QueryBuilder.this; } }
@Test public void shouldParseDescendantNodeJoinWithNoCriteria() { query = parse("select * from [lom:Metadata] as lom join [lom:LangString] as lang on isdescendantnode(lang,lom)"); // SELECT * ... assertThat(query.columns().isEmpty(), is(true)); // FROM ... Join join = isJoin(query.source()); assertThat(join.getLeft(), is((Source)namedSelector(selectorName("lom:Metadata"), selectorName("lom")))); assertThat(join.getRight(), is((Source)namedSelector(selectorName("lom:LangString"), selectorName("lang")))); assertThat(join.type(), is(JoinType.INNER)); DescendantNodeJoinCondition joinCondition = isDescendantNodeJoinCondition(join.getJoinCondition()); assertThat(joinCondition.ancestorSelectorName(), is(selectorName("lom"))); assertThat(joinCondition.descendantSelectorName(), is(selectorName("lang"))); }
@Test public void shouldParseQuery() { query = parse("SELECT post.\"jcr:uuid\", post.\"text\", post.\"user\" FROM [fincayra.Post] AS post JOIN [fincayra.User] AS u ON post.\"user\"=u.\"jcr:uuid\""); System.out.println(query); // SELECT * ... assertThat(query.columns().size(), is(3)); assertThat(query.columns().get(0).selectorName(), is(selectorName("post"))); assertThat(query.columns().get(0).getColumnName(), is("jcr:uuid")); assertThat(query.columns().get(0).getPropertyName(), is("jcr:uuid")); assertThat(query.columns().get(1).selectorName(), is(selectorName("post"))); assertThat(query.columns().get(1).getColumnName(), is("text")); assertThat(query.columns().get(1).getPropertyName(), is("text")); assertThat(query.columns().get(2).selectorName(), is(selectorName("post"))); assertThat(query.columns().get(2).getColumnName(), is("user")); assertThat(query.columns().get(2).getPropertyName(), is("user")); // FROM ... Join join = isJoin(query.source()); assertThat(join.getLeft(), is((Source)namedSelector(selectorName("fincayra.Post"), selectorName("post")))); assertThat(join.getRight(), is((Source)namedSelector(selectorName("fincayra.User"), selectorName("u")))); assertThat(join.type(), is(JoinType.INNER)); EquiJoinCondition joinCondition = isEquiJoinCondition(join.getJoinCondition()); assertThat(joinCondition.getSelector1Name(), is("post")); assertThat(joinCondition.getSelector2Name(), is("u")); assertThat(joinCondition.getProperty1Name(), is("user")); assertThat(joinCondition.getProperty2Name(), is("jcr:uuid")); // WHERE ... assertThat(query.constraint(), is(nullValue())); }
@Test public void shouldParseSelectStarFromTwoJoinedSourcesWithWhereContainingJoinCriteria() { query = parse("SELECT * FROM [mgnl:content] JOIN [acme:stuff] ON ISSAMENODE([mgnl:content],[acme:stuff])"); // SELECT * ... assertThat(query.columns().isEmpty(), is(true)); // FROM ... Join join = isJoin(query.source()); assertThat(join.getLeft(), is((Source)namedSelector(selectorName("mgnl:content")))); assertThat(join.getRight(), is((Source)namedSelector(selectorName("acme:stuff")))); assertThat(join.type(), is(JoinType.INNER)); SameNodeJoinCondition joinCondition = isSameNodeJoinCondition(join.getJoinCondition()); assertThat(joinCondition.selector1Name(), is(selectorName("mgnl:content"))); assertThat(joinCondition.selector2Name(), is(selectorName("acme:stuff"))); assertThat(joinCondition.getSelector2Path(), is(nullValue())); // WHERE ... assertThat(query.constraint(), is(nullValue())); }
@Test public void shouldParseSelectStarFromTwoJoinedSourcesWithWhereContainingJoinCriteria() { query = parse("SELECT * FROM mgnl:content, acme:stuff WHERE mgnl:content.jcr:path = acme:stuff.jcr:path"); // SELECT * ... assertThat(query.columns().isEmpty(), is(true)); // FROM ... Join join = isJoin(query.source()); assertThat(join.getLeft(), is((Source)namedSelector(selectorName("mgnl:content")))); assertThat(join.getRight(), is((Source)namedSelector(selectorName("acme:stuff")))); assertThat(join.type(), is(JoinType.INNER)); SameNodeJoinCondition joinCondition = isSameNodeJoinCondition(join.getJoinCondition()); assertThat(joinCondition.selector1Name(), is(selectorName("mgnl:content"))); assertThat(joinCondition.selector2Name(), is(selectorName("acme:stuff"))); assertThat(joinCondition.getSelector2Path(), is(nullValue())); // WHERE ... assertThat(query.constraint(), is(nullValue())); }
@Test public void shouldParseSelectStarFromThreeJoinedSourcesWithWhereContainingJoinCriteria() { query = parse("SELECT * FROM mgnl:content, acme:stuff, foo:bar WHERE mgnl:content.jcr:path = acme:stuff.jcr:path AND mgnl:content.jcr:path = foo:bar.jcr:path"); // SELECT * ... assertThat(query.columns().isEmpty(), is(true)); // FROM ... Join join = isJoin(query.source()); Join join2 = isJoin(join.getLeft()); assertThat(join2.getLeft(), is((Source)namedSelector(selectorName("mgnl:content")))); assertThat(join2.getRight(), is((Source)namedSelector(selectorName("acme:stuff")))); assertThat(join2.type(), is(JoinType.INNER)); SameNodeJoinCondition joinCondition2 = isSameNodeJoinCondition(join2.getJoinCondition()); assertThat(joinCondition2.selector1Name(), is(selectorName("mgnl:content"))); assertThat(joinCondition2.selector2Name(), is(selectorName("acme:stuff"))); assertThat(joinCondition2.getSelector2Path(), is(nullValue())); assertThat(join.getRight(), is((Source)namedSelector(selectorName("foo:bar")))); assertThat(join.type(), is(JoinType.INNER)); SameNodeJoinCondition joinCondition = isSameNodeJoinCondition(join.getJoinCondition()); assertThat(joinCondition.selector1Name(), is(selectorName("mgnl:content"))); assertThat(joinCondition.selector2Name(), is(selectorName("foo:bar"))); assertThat(joinCondition.getSelector2Path(), is(nullValue())); // WHERE ... assertThat(query.constraint(), is(nullValue())); }
@Test public void shouldParseSelectStarFromThreeJoinedSourcesWithWhereContainingJoinCriteria() { query = parse("SELECT * FROM [mgnl:content] JOIN [acme:stuff] ON ISSAMENODE([mgnl:content],[acme:stuff]) JOIN [foo:bar] ON ISSAMENODE([mgnl:content],[foo:bar])"); // SELECT * ... assertThat(query.columns().isEmpty(), is(true)); // FROM ... Join join = isJoin(query.source()); Join join2 = isJoin(join.getLeft()); assertThat(join2.getLeft(), is((Source)namedSelector(selectorName("mgnl:content")))); assertThat(join2.getRight(), is((Source)namedSelector(selectorName("acme:stuff")))); assertThat(join2.type(), is(JoinType.INNER)); SameNodeJoinCondition joinCondition2 = isSameNodeJoinCondition(join2.getJoinCondition()); assertThat(joinCondition2.selector1Name(), is(selectorName("mgnl:content"))); assertThat(joinCondition2.selector2Name(), is(selectorName("acme:stuff"))); assertThat(joinCondition2.getSelector2Path(), is(nullValue())); assertThat(join.getRight(), is((Source)namedSelector(selectorName("foo:bar")))); assertThat(join.type(), is(JoinType.INNER)); SameNodeJoinCondition joinCondition = isSameNodeJoinCondition(join.getJoinCondition()); assertThat(joinCondition.selector1Name(), is(selectorName("mgnl:content"))); assertThat(joinCondition.selector2Name(), is(selectorName("foo:bar"))); assertThat(joinCondition.getSelector2Path(), is(nullValue())); // WHERE ... assertThat(query.constraint(), is(nullValue())); }
@Test public void shouldParseSelectStarFromEquijoinAndAdditionalCriteria() { query = parse("SELECT * FROM modetest:queryable, mix:referenceable WHERE modetest:queryable.jcr:path = mix:referenceable.jcr:path AND jcr:path LIKE '/testroot/someQueryableNodeD/%'"); // SELECT * ... assertThat(query.columns().isEmpty(), is(true)); // FROM ... Join join = isJoin(query.source()); assertThat(join.getLeft(), is((Source)namedSelector(selectorName("modetest:queryable")))); assertThat(join.getRight(), is((Source)namedSelector(selectorName("mix:referenceable")))); assertThat(join.type(), is(JoinType.INNER)); SameNodeJoinCondition joinCondition = isSameNodeJoinCondition(join.getJoinCondition()); assertThat(joinCondition.selector1Name(), is(selectorName("modetest:queryable"))); assertThat(joinCondition.selector2Name(), is(selectorName("mix:referenceable"))); assertThat(joinCondition.getSelector2Path(), is(nullValue())); // WHERE ... Comparison comparison = isComparison(query.constraint()); assertThat(comparison.getOperand1(), is((DynamicOperand)nodePath(selectorName("modetest:queryable")))); assertThat(comparison.getOperand2(), is((StaticOperand)literal("/testroot/someQueryableNodeD/%"))); }
@Test public void shouldParseSelectStarFromEquijoinAndAdditionalCriteria() { query = parse("SELECT * FROM [modetest:queryable] JOIN [mix:referenceable] ON ISSAMENODE([modetest:queryable],[mix:referenceable]) WHERE PATH([modetest:queryable]) LIKE '/testroot/someQueryableNodeD/%'"); // SELECT * ... assertThat(query.columns().isEmpty(), is(true)); // FROM ... Join join = isJoin(query.source()); assertThat(join.getLeft(), is((Source)namedSelector(selectorName("modetest:queryable")))); assertThat(join.getRight(), is((Source)namedSelector(selectorName("mix:referenceable")))); assertThat(join.type(), is(JoinType.INNER)); SameNodeJoinCondition joinCondition = isSameNodeJoinCondition(join.getJoinCondition()); assertThat(joinCondition.selector1Name(), is(selectorName("modetest:queryable"))); assertThat(joinCondition.selector2Name(), is(selectorName("mix:referenceable"))); assertThat(joinCondition.getSelector2Path(), is(nullValue())); // WHERE ... Comparison comparison = isComparison(query.constraint()); assertThat(comparison.getOperand1(), is((DynamicOperand)nodePath(selectorName("modetest:queryable")))); assertThat(comparison.getOperand2(), is((StaticOperand)literal("/testroot/someQueryableNodeD/%"))); }
Source[] clauses = new Source[] {join.getLeft(), join.getRight()}; for (int i = 0; i < 2; i++) { PlanNode sourceNode = createPlanNode(context, clauses[i], usedSelectors);
Source[] clauses = new Source[] {join.getLeft(), join.getRight()}; for (int i = 0; i < 2; i++) { PlanNode sourceNode = createPlanNode(context, clauses[i], usedSelectors);