@Test public void testTimestampSerialization() throws Exception { // There is a kryo which after serialize/deserialize, // Timestamp becomes Date. We get around this issue in // SearchArgumentImpl.getLiteral. Once kryo fixed the issue // We can simplify SearchArgumentImpl.getLiteral Timestamp now = new Timestamp(new java.util.Date().getTime()); SearchArgument sarg = SearchArgumentFactory.newBuilder() .startAnd() .lessThan("x", PredicateLeaf.Type.TIMESTAMP, now) .end() .build(); String serializedSarg = TestInputOutputFormat.toKryo(sarg); SearchArgument sarg2 = ConvertAstToSearchArg.create(serializedSarg); Field literalField = PredicateLeafImpl.class.getDeclaredField("literal"); literalField.setAccessible(true); assertTrue(literalField.get(sarg2.getLeaves().get(0)) instanceof java.util.Date); Timestamp ts = (Timestamp)sarg2.getLeaves().get(0).getLiteral(); assertEquals(ts, now); }
@Test public void testBuilderFloat() throws Exception { SearchArgument sarg = SearchArgumentFactory.newBuilder() .startAnd() .lessThan("x", PredicateLeaf.Type.LONG, 22L) .lessThan("x1", PredicateLeaf.Type.LONG, 22L) .lessThanEquals("y", PredicateLeaf.Type.STRING, new HiveChar("hi", 10).toString()) .equals("z", PredicateLeaf.Type.FLOAT, new Double(0.22)) .equals("z1", PredicateLeaf.Type.FLOAT, new Double(0.22)) .end() .build(); assertEquals("leaf-0 = (LESS_THAN x 22), " + "leaf-1 = (LESS_THAN x1 22), " + "leaf-2 = (LESS_THAN_EQUALS y hi ), " + "leaf-3 = (EQUALS z 0.22), " + "leaf-4 = (EQUALS z1 0.22), " + "expr = (and leaf-0 leaf-1 leaf-2 leaf-3 leaf-4)", sarg.toString()); }
SearchArgumentFactory.newBuilder() .startAnd() .lessThan("z", PredicateLeaf.Type.STRING, new String("foo")) .end() .build();
sargBuilder.lessThan(col, literalPair.second, literalPair.first); sargBuilder.end(); } else { sargBuilder.lessThan(col, literalPair.second, literalPair.first); if (reversed) { sargBuilder.lessThan(col, literalPair.second, literalPair.first); } else { sargBuilder.lessThan(col, literalPair.second, literalPair.first); sargBuilder.end();
break; case LESS_THAN: builder.lessThan(columnName, type, findLiteral(conf, expression, type)); break; case LESS_THAN_EQUALS:
.startAnd() .startNot() .lessThan("int1", PredicateLeaf.Type.LONG, 300000L) .end() .lessThan("int1", PredicateLeaf.Type.LONG, 600000L) .end() .build(); .lessThan("int1", PredicateLeaf.Type.LONG, 0L) .end() .build(); .lessThan("int1", PredicateLeaf.Type.LONG, 300L * 100) .startNot() .lessThan("int1", PredicateLeaf.Type.LONG, 300L * 3400) .end() .end()
break; case LESS_THAN: builder.lessThan(columnName, boxType.type, findLiteral(conf, expression, boxType)); break; case LESS_THAN_EQUALS:
SearchArgumentFactory.newBuilder() .startAnd() .lessThan("z", PredicateLeaf.Type.LONG, new Long(0)) .end() .build();
SearchArgumentFactory.newBuilder() .startAnd() .lessThan("x", PredicateLeaf.Type.DATE, Date.valueOf("1970-1-11")) .lessThanEquals("y", PredicateLeaf.Type.STRING,
SearchArgumentFactory.newBuilder() .startAnd() .lessThan("x", PredicateLeaf.Type.DATE, Date.valueOf("2005-3-12")) .lessThanEquals("y", PredicateLeaf.Type.STRING, new HiveChar("hi", 10).toString())
SearchArgumentFactory.newBuilder() .startAnd() .lessThan("x", PredicateLeaf.Type.DATE, Date.valueOf("1970-1-11")) .lessThanEquals("y", PredicateLeaf.Type.STRING,
SearchArgumentFactory.newBuilder() .startAnd() .lessThan("x", PredicateLeaf.Type.DATE, Date.valueOf("2005-3-12")) .lessThanEquals("y", PredicateLeaf.Type.STRING, new HiveChar("hi", 10).toString())
@Test public void testBuilder() throws Exception { SearchArgument sarg = SearchArgumentFactory.newBuilder() .startAnd() .lessThan("x", PredicateLeaf.Type.LONG, 10L) .lessThanEquals("y", PredicateLeaf.Type.STRING, "hi") .equals("z", PredicateLeaf.Type.FLOAT, 1.0) .end() .build(); assertEquals("leaf-0 = (LESS_THAN x 10), " + "leaf-1 = (LESS_THAN_EQUALS y hi), " + "leaf-2 = (EQUALS z 1.0), " + "expr = (and leaf-0 leaf-1 leaf-2)", sarg.toString()); sarg = SearchArgumentFactory.newBuilder() .startNot() .startOr() .isNull("x", PredicateLeaf.Type.LONG) .between("y", PredicateLeaf.Type.LONG, 10L, 20L) .in("z", PredicateLeaf.Type.LONG, 1L, 2L, 3L) .nullSafeEquals("a", PredicateLeaf.Type.STRING, "stinger") .end() .end() .build(); assertEquals("leaf-0 = (IS_NULL x), " + "leaf-1 = (BETWEEN y 10 20), " + "leaf-2 = (IN z 1 2 3), " + "leaf-3 = (NULL_SAFE_EQUALS a stinger), " + "expr = (and (not leaf-0) (not leaf-1) (not leaf-2) (not leaf-3))", sarg.toString()); }
@Test public void testBuilderFloat() throws Exception { SearchArgument sarg = SearchArgumentFactory.newBuilder() .startAnd() .lessThan("x", PredicateLeaf.Type.LONG, 22L) .lessThan("x1", PredicateLeaf.Type.LONG, 22L) .lessThanEquals("y", PredicateLeaf.Type.STRING, new HiveChar("hi", 10).toString()) .equals("z", PredicateLeaf.Type.FLOAT, new Double(0.22)) .equals("z1", PredicateLeaf.Type.FLOAT, new Double(0.22)) .end() .build(); MessageType schema = MessageTypeParser.parseMessageType("message test {" + " required int32 x; required int32 x1;" + " required binary y; required float z; required float z1;}"); FilterPredicate p = ParquetFilterPredicateConverter.toFilterPredicate(sarg, schema); String expected = "and(and(and(and(lt(x, 22), lt(x1, 22))," + " lteq(y, Binary{\"hi \"})), eq(z, " + "0.22)), eq(z1, 0.22))"; assertEquals(expected, p.toString()); } }
@Test(expected = IllegalArgumentException.class) public void testBadLiteral() throws Exception { SearchArgumentFactory.newBuilder() .startAnd() .lessThan("x", PredicateLeaf.Type.LONG, "hi") .end() .build(); }
@Override protected SearchArgument.Builder add(SearchArgument.Builder builder) { return builder.lessThan(columnName, literalType, castLiteral(literal)); }