Search in sources :

Example 6 with XPathToSQL2Converter

use of org.apache.jackrabbit.oak.query.xpath.XPathToSQL2Converter in project jackrabbit-oak by apache.

the class LargeQueryTest method testCombinedOr.

@Test
public void testCombinedOr() throws ParseException {
    StringBuilder buff = new StringBuilder("//*[");
    StringBuilder buff2 = new StringBuilder("select [jcr:path], [jcr:score], * from [nt:base] as a where [x] in(");
    int step = 111;
    for (int i = 0; i < 5000; i++) {
        if (i % step == 2) {
            if (i > 0) {
                buff.append(" or ");
            }
            buff.append("@x>").append(i);
            buff2.append(") union select [jcr:path], [jcr:score], * from [nt:base] as a " + "where [x] > ").append(i);
            buff2.append(" union select [jcr:path], [jcr:score], * from [nt:base] as a " + "where [x] in(");
        } else {
            if (i > 0) {
                buff.append(" or ");
            }
            buff.append("@x=").append(i);
            if (i > 0 && i % step != 3) {
                buff2.append(", ");
            }
            buff2.append(i);
        }
    }
    buff.append("]");
    buff2.append(")");
    String xpath = buff.toString();
    XPathToSQL2Converter conv = new XPathToSQL2Converter();
    String sql2 = conv.convert(xpath);
    buff2.append(" /* xpath: ").append(xpath).append(" */");
    assertEquals(buff2.toString(), sql2);
}
Also used : XPathToSQL2Converter(org.apache.jackrabbit.oak.query.xpath.XPathToSQL2Converter) Test(org.junit.Test)

Example 7 with XPathToSQL2Converter

use of org.apache.jackrabbit.oak.query.xpath.XPathToSQL2Converter in project jackrabbit-oak by apache.

the class LargeQueryTest method testSimpleOr.

@Test
public void testSimpleOr() throws ParseException {
    StringBuilder buff = new StringBuilder("//*[");
    StringBuilder buff2 = new StringBuilder("select [jcr:path], [jcr:score], * from [nt:base] as a where [x] in(");
    for (int i = 0; i < 100000; i++) {
        if (i > 0) {
            buff.append(" or ");
            buff2.append(", ");
        }
        buff.append("@x=").append(i);
        buff2.append(i);
    }
    buff.append("]");
    buff2.append(")");
    String xpath = buff.toString();
    XPathToSQL2Converter conv = new XPathToSQL2Converter();
    String sql2 = conv.convert(xpath);
    buff2.append(" /* xpath: ").append(xpath).append(" */");
    assertEquals(buff2.toString(), sql2);
}
Also used : XPathToSQL2Converter(org.apache.jackrabbit.oak.query.xpath.XPathToSQL2Converter) Test(org.junit.Test)

Example 8 with XPathToSQL2Converter

use of org.apache.jackrabbit.oak.query.xpath.XPathToSQL2Converter in project jackrabbit-oak by apache.

the class SQL2ParserTest method testUnwrappedOr.

// see OAK-OAK-830: XPathToSQL2Converter fails to wrap or clauses
@Test
public void testUnwrappedOr() throws ParseException {
    String q = new XPathToSQL2Converter().convert("/jcr:root/home//test/* [@type='t1' or @type='t2' or @type='t3']");
    String token = "and b.[type] in('t1', 't2', 't3')";
    assertTrue(q.contains(token));
}
Also used : XPathToSQL2Converter(org.apache.jackrabbit.oak.query.xpath.XPathToSQL2Converter) Test(org.junit.Test)

Aggregations

XPathToSQL2Converter (org.apache.jackrabbit.oak.query.xpath.XPathToSQL2Converter)8 Test (org.junit.Test)3 ParseException (java.text.ParseException)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 LineNumberReader (java.io.LineNumberReader)1 OutputStreamWriter (java.io.OutputStreamWriter)1 PrintWriter (java.io.PrintWriter)1 RandomAccessFile (java.io.RandomAccessFile)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Random (java.util.Random)1 LocalNameMapper (org.apache.jackrabbit.oak.namepath.LocalNameMapper)1 NamePathMapper (org.apache.jackrabbit.oak.namepath.NamePathMapper)1 NamePathMapperImpl (org.apache.jackrabbit.oak.namepath.NamePathMapperImpl)1 NodeTypeInfoProvider (org.apache.jackrabbit.oak.query.ast.NodeTypeInfoProvider)1