use of org.apache.pig.data.DataByteArray in project phoenix by apache.
the class PhoenixHBaseStorerIT method testStoreWithBinaryDataTypes.
/**
* Test storage of DataByteArray columns to Phoenix
* Maps the DataByteArray with the target PhoenixDataType and persists in HBase.
* @throws Exception
*/
@Test
public void testStoreWithBinaryDataTypes() throws Exception {
final String tableName = "TABLE3";
final Statement stmt = conn.createStatement();
stmt.execute("CREATE TABLE " + tableName + " (col1 BIGINT NOT NULL, col2 INTEGER , col3 FLOAT, col4 DOUBLE , col5 TINYINT , " + " col6 BOOLEAN , col7 VARBINARY CONSTRAINT my_pk PRIMARY KEY (col1))");
final Data data = Storage.resetData(pigServer);
final Collection<Tuple> list = Lists.newArrayList();
int rows = 10;
for (int i = 1; i <= rows; i++) {
Tuple t = tupleFactory.newTuple();
t.append(i);
t.append(new DataByteArray(Bytes.toBytes(i * 5)));
t.append(new DataByteArray(Bytes.toBytes(i * 10.0F)));
t.append(new DataByteArray(Bytes.toBytes(i * 15.0D)));
t.append(new DataByteArray(Bytes.toBytes(i)));
t.append(new DataByteArray(Bytes.toBytes(i % 2 == 0)));
t.append(new DataByteArray(Bytes.toBytes(i)));
list.add(t);
}
data.set("in", "col1:int,col2:bytearray,col3:bytearray,col4:bytearray,col5:bytearray,col6:bytearray,col7:bytearray ", list);
pigServer.setBatchOn();
pigServer.registerQuery("A = LOAD 'in' USING mock.Storage();");
pigServer.registerQuery("Store A into 'hbase://" + tableName + "' using " + PhoenixHBaseStorage.class.getName() + "('" + zkQuorum + "', '-batchSize 1000');");
if (pigServer.executeBatch().get(0).getStatus() != JOB_STATUS.COMPLETED) {
throw new RuntimeException("Job failed", pigServer.executeBatch().get(0).getException());
}
final ResultSet rs = stmt.executeQuery(String.format("SELECT col1 , col2 , col3 , col4 , col5 , col6, col7 FROM %s ORDER BY col1", tableName));
int count = 0;
for (int i = 1; i <= rows; i++) {
assertTrue(rs.next());
assertEquals(i, rs.getInt(1));
assertEquals(i * 5, rs.getInt(2));
assertEquals(i * 10.0F, rs.getFloat(3), 0.0);
assertEquals(i * 15.0D, rs.getInt(4), 0.0);
assertEquals(i, rs.getInt(5));
assertEquals(i % 2 == 0, rs.getBoolean(6));
assertArrayEquals(Bytes.toBytes(i), rs.getBytes(7));
count++;
}
assertEquals(rows, count);
}
Aggregations