Exemplo n.º 1
0
 @Test
 public void testGetLong() throws Exception {
   List<Query.Type> types = Arrays.asList(Query.Type.UINT32, Query.Type.INT64);
   for (Query.Type type : types) {
     try (Cursor cursor =
         new SimpleCursor(
             QueryResult.newBuilder()
                 .addFields(Field.newBuilder().setName("col1").setType(type).build())
                 .addFields(Field.newBuilder().setName("null").setType(type).build())
                 .addRows(
                     Query.Row.newBuilder()
                         .addLengths("12345".length())
                         .addLengths(-1) // SQL NULL
                         .setValues(ByteString.copyFromUtf8("12345")))
                 .build())) {
       Row row = cursor.next();
       Assert.assertNotNull(row);
       Assert.assertEquals(12345L, row.getLong("col1"));
       Assert.assertFalse(row.wasNull());
       Assert.assertEquals(0L, row.getLong("null"));
       Assert.assertTrue(row.wasNull());
       Assert.assertEquals(null, row.getObject("null", Long.class));
       Assert.assertTrue(row.wasNull());
     }
   }
 }
Exemplo n.º 2
0
 @Test
 public void testCrosstab() {
   DataFrame df = context.table("testData2");
   DataFrame crosstab = df.stat().crosstab("a", "b");
   String[] columnNames = crosstab.schema().fieldNames();
   Assert.assertEquals("a_b", columnNames[0]);
   Assert.assertEquals("2", columnNames[1]);
   Assert.assertEquals("1", columnNames[2]);
   Row[] rows = crosstab.collect();
   Arrays.sort(rows, crosstabRowComparator);
   Integer count = 1;
   for (Row row : rows) {
     Assert.assertEquals(row.get(0).toString(), count.toString());
     Assert.assertEquals(1L, row.getLong(1));
     Assert.assertEquals(1L, row.getLong(2));
     count++;
   }
 }