Search in sources :

Example 6 with ValueInspector

use of org.apache.parquet.filter2.recordlevel.IncrementallyUpdatedFilterPredicate.ValueInspector in project parquet-mr by apache.

the class TestIncrementallyUpdatedFilterPredicateResetter method testReset.

@Test
public void testReset() {
    ValueInspector intIsNull = intIsNull();
    ValueInspector intIsEven = intIsEven();
    ValueInspector doubleMoreThan10 = doubleMoreThan10();
    IncrementallyUpdatedFilterPredicate pred = new Or(intIsNull, new And(intIsEven, doubleMoreThan10));
    intIsNull.updateNull();
    intIsEven.update(11);
    doubleMoreThan10.update(20.0D);
    assertTrue(intIsNull.isKnown());
    assertTrue(intIsEven.isKnown());
    assertTrue(doubleMoreThan10.isKnown());
    IncrementallyUpdatedFilterPredicateResetter.reset(pred);
    assertFalse(intIsNull.isKnown());
    assertFalse(intIsEven.isKnown());
    assertFalse(doubleMoreThan10.isKnown());
    intIsNull.updateNull();
    assertTrue(intIsNull.isKnown());
    assertFalse(intIsEven.isKnown());
    assertFalse(doubleMoreThan10.isKnown());
    IncrementallyUpdatedFilterPredicateResetter.reset(pred);
    assertFalse(intIsNull.isKnown());
    assertFalse(intIsEven.isKnown());
    assertFalse(doubleMoreThan10.isKnown());
}
Also used : ValueInspector(org.apache.parquet.filter2.recordlevel.IncrementallyUpdatedFilterPredicate.ValueInspector) Or(org.apache.parquet.filter2.recordlevel.IncrementallyUpdatedFilterPredicate.Or) And(org.apache.parquet.filter2.recordlevel.IncrementallyUpdatedFilterPredicate.And) Test(org.junit.Test)

Example 7 with ValueInspector

use of org.apache.parquet.filter2.recordlevel.IncrementallyUpdatedFilterPredicate.ValueInspector in project parquet-mr by apache.

the class TestValueInspector method testLifeCycle.

@Test
public void testLifeCycle() {
    ValueInspector v = intIsEven();
    // begins in unknown state
    assertFalse(v.isKnown());
    // calling getResult in unknown state throws
    try {
        v.getResult();
        fail("this should throw");
    } catch (IllegalStateException e) {
        assertEquals("getResult() called on a ValueInspector whose result is not yet known!", e.getMessage());
    }
    // update state to known
    v.update(10);
    // v was updated with value 10, so result is known and should be true
    assertTrue(v.isKnown());
    assertTrue(v.getResult());
    // calling update w/o resetting should throw
    try {
        v.update(11);
        fail("this should throw");
    } catch (IllegalStateException e) {
        assertEquals("setResult() called on a ValueInspector whose result is already known!" + " Did you forget to call reset()?", e.getMessage());
    }
    // back to unknown state
    v.reset();
    assertFalse(v.isKnown());
    // calling getResult in unknown state throws
    try {
        v.getResult();
        fail("this should throw");
    } catch (IllegalStateException e) {
        assertEquals("getResult() called on a ValueInspector whose result is not yet known!", e.getMessage());
    }
    // v was updated with value 11, so result is known and should be false
    v.update(11);
    assertTrue(v.isKnown());
    assertFalse(v.getResult());
}
Also used : ValueInspector(org.apache.parquet.filter2.recordlevel.IncrementallyUpdatedFilterPredicate.ValueInspector) Test(org.junit.Test)

Example 8 with ValueInspector

use of org.apache.parquet.filter2.recordlevel.IncrementallyUpdatedFilterPredicate.ValueInspector in project parquet-mr by apache.

the class TestValueInspector method testReusable.

@Test
public void testReusable() {
    List<Integer> values = Arrays.asList(2, 4, 7, 3, 8, 8, 11, 200);
    ValueInspector v = intIsEven();
    for (Integer x : values) {
        v.update(x);
        assertEquals(x % 2 == 0, v.getResult());
        v.reset();
    }
}
Also used : ValueInspector(org.apache.parquet.filter2.recordlevel.IncrementallyUpdatedFilterPredicate.ValueInspector) Test(org.junit.Test)

Aggregations

ValueInspector (org.apache.parquet.filter2.recordlevel.IncrementallyUpdatedFilterPredicate.ValueInspector)8 Test (org.junit.Test)7 And (org.apache.parquet.filter2.recordlevel.IncrementallyUpdatedFilterPredicate.And)2 Or (org.apache.parquet.filter2.recordlevel.IncrementallyUpdatedFilterPredicate.Or)2 ArrayList (java.util.ArrayList)1 ColumnPath (org.apache.parquet.hadoop.metadata.ColumnPath)1 PrimitiveColumnIO (org.apache.parquet.io.PrimitiveColumnIO)1 Converter (org.apache.parquet.io.api.Converter)1 GroupConverter (org.apache.parquet.io.api.GroupConverter)1