예제 #1
0
 @Test
 public void testIdQuery() throws Exception {
   Reference ref = createReference("_id", DataTypes.STRING);
   Query query = convert(whereClause(EqOperator.NAME, ref, Literal.newLiteral("i1")));
   assertThat(query, instanceOf(TermQuery.class));
   assertThat(query.toString(), is("_uid:default#i1"));
 }
예제 #2
0
 @Test
 public void testAnyEqArrayReference() throws Exception {
   Reference ref = createReference("d_array", new ArrayType(DataTypes.DOUBLE));
   Literal doubleLiteral = Literal.newLiteral(1.5d);
   Query query = convert(whereClause(AnyEqOperator.NAME, doubleLiteral, ref));
   assertThat(query.toString(), is("d_array:[1.5 TO 1.5]"));
 }
예제 #3
0
 @Test
 public void testGteQuery() throws Exception {
   Query query =
       convert(
           new WhereClause(
               createFunction(
                   GteOperator.NAME,
                   DataTypes.BOOLEAN,
                   createReference("x", DataTypes.INTEGER),
                   Literal.newLiteral(10))));
   assertThat(query, instanceOf(NumericRangeQuery.class));
   assertThat(query.toString(), is("x:[10 TO *}"));
 }
예제 #4
0
  @Test
  public void testAnyGreaterAndSmaller() throws Exception {

    Reference arrayRef = createReference("d_array", new ArrayType(DataTypes.DOUBLE));
    Literal doubleLiteral = Literal.newLiteral(1.5d);

    Reference ref = createReference("d", DataTypes.DOUBLE);
    Literal arrayLiteral =
        Literal.newLiteral(new Object[] {1.2d, 3.5d}, new ArrayType(DataTypes.DOUBLE));

    // 1.5d < ANY (d_array)
    Query ltQuery = convert(whereClause(AnyLtOperator.NAME, doubleLiteral, arrayRef));
    assertThat(ltQuery.toString(), is("d_array:{1.5 TO *}"));

    // d < ANY ([1.2, 3.5])
    Query ltQuery2 = convert(whereClause(AnyLtOperator.NAME, ref, arrayLiteral));
    assertThat(ltQuery2.toString(), is("(d:{* TO 1.2} d:{* TO 3.5})~1"));

    // 1.5d <= ANY (d_array)
    Query lteQuery = convert(whereClause(AnyLteOperator.NAME, doubleLiteral, arrayRef));
    assertThat(lteQuery.toString(), is("d_array:[1.5 TO *}"));

    // d <= ANY ([1.2, 3.5])
    Query lteQuery2 = convert(whereClause(AnyLteOperator.NAME, ref, arrayLiteral));
    assertThat(lteQuery2.toString(), is("(d:{* TO 1.2] d:{* TO 3.5])~1"));

    // 1.5d > ANY (d_array)
    Query gtQuery = convert(whereClause(AnyGtOperator.NAME, doubleLiteral, arrayRef));
    assertThat(gtQuery.toString(), is("d_array:{* TO 1.5}"));

    // d > ANY ([1.2, 3.5])
    Query gtQuery2 = convert(whereClause(AnyGtOperator.NAME, ref, arrayLiteral));
    assertThat(gtQuery2.toString(), is("(d:{1.2 TO *} d:{3.5 TO *})~1"));

    // 1.5d >= ANY (d_array)
    Query gteQuery = convert(whereClause(AnyGteOperator.NAME, doubleLiteral, arrayRef));
    assertThat(gteQuery.toString(), is("d_array:{* TO 1.5]"));

    // d >= ANY ([1.2, 3.5])
    Query gteQuery2 = convert(whereClause(AnyGteOperator.NAME, ref, arrayLiteral));
    assertThat(gteQuery2.toString(), is("(d:[1.2 TO *} d:[3.5 TO *})~1"));
  }