Ejemplo n.º 1
0
        public void testTimestampSerialization()
        {
            // 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 = typeof(PredicateLeafImpl).getDeclaredField("literal");

            literalField.setAccessible(true);
            assertTrue(literalField.get(sarg2.getLeaves()[0]) is java.util.Date);
            Timestamp ts = (Timestamp)sarg2.getLeaves()[0].getLiteral();

            Assert.Equal(ts, now);
        }
Ejemplo n.º 2
0
        public void testBuilderComplexTypes2()
        {
            SearchArgument sarg =
                SearchArgumentFactory.newBuilder()
                .startAnd()
                .lessThan("x", PredicateLeaf.Type.DATE, Date.Parse("2005-3-12"))
                .lessThanEquals("y", PredicateLeaf.Type.STRING, "hi")
                .equals("z", PredicateLeaf.Type.DECIMAL, HiveDecimal.Parse("1.0"))
                .end()
                .build();

            Assert.Equal("leaf-0 = (LESS_THAN x 2005-03-12), " +
                         "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.DECIMAL, HiveDecimal.Parse("10"), HiveDecimal.Parse("20.0"))
                   .@in("z", PredicateLeaf.Type.LONG, 1L, 2L, 3L)
                   .nullSafeEquals("a", PredicateLeaf.Type.STRING, "stinger")
                   .end()
                   .end()
                   .build();
            Assert.Equal("leaf-0 = (IS_NULL x), " +
                         "leaf-1 = (BETWEEN y 10 20.0), " +
                         "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());
        }
Ejemplo n.º 3
0
        public void testBuilder()
        {
            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();

            Assert.Equal("leaf-0 = (LESS_THAN x 10), " +
                         "leaf-1 = (LESS_THAN_EQUALS y hi), " +
                         "leaf-2 = (EQUALS z 1), " +
                         "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();
            Assert.Equal("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());
        }
Ejemplo n.º 4
0
 public void testBadLiteralList()
 {
     Assert.Throws <ArgumentException>(() => SearchArgumentFactory.newBuilder()
                                       .startAnd()
                                       .@in("x", PredicateLeaf.Type.STRING, "hi", 23)
                                       .end()
                                       .build());
 }
Ejemplo n.º 5
0
 public void testBadLiteral()
 {
     Assert.Throws <ArgumentException>(() => SearchArgumentFactory.newBuilder()
                                       .startAnd()
                                       .lessThan("x", PredicateLeaf.Type.LONG, "hi")
                                       .end()
                                       .build());
 }
Ejemplo n.º 6
0
        public void testBuilderFloat()
        {
            SearchArgument sarg =
                SearchArgumentFactory.newBuilder()
                .startAnd()
                .lessThan("x", PredicateLeaf.Type.LONG, 22L)
                .lessThan("x1", PredicateLeaf.Type.LONG, 22L)
                .lessThanEquals("y", PredicateLeaf.Type.STRING, "hi")
                .equals("z", PredicateLeaf.Type.FLOAT, 0.22)
                .equals("z1", PredicateLeaf.Type.FLOAT, 0.22)
                .end()
                .build();

            Assert.Equal("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());
        }