use of org.apache.hadoop.hive.kudu.KuduOutputFormat.KuduRecordWriter in project hive by apache.
the class TestKuduOutputFormat method testBadRow.
@Test
public void testBadRow() throws Exception {
KuduOutputFormat outputFormat = new KuduOutputFormat();
KuduRecordWriter writer = (KuduRecordWriter) outputFormat.getHiveRecordWriter(new JobConf(BASE_CONF), null, null, false, TBL_PROPS, null);
// Write an empty row.
try {
PartialRow row = SCHEMA.newPartialRow();
KuduWritable writable = new KuduWritable(row);
writer.write(writable);
} catch (KuduException ex) {
assertThat(ex.getMessage(), containsString("Primary key column key is not set"));
} finally {
writer.close(false);
}
}
use of org.apache.hadoop.hive.kudu.KuduOutputFormat.KuduRecordWriter in project hive by apache.
the class TestKuduOutputFormat method testGoodRow.
@Test
public void testGoodRow() throws Exception {
KuduOutputFormat outputFormat = new KuduOutputFormat();
KuduRecordWriter writer = (KuduRecordWriter) outputFormat.getHiveRecordWriter(new JobConf(BASE_CONF), null, null, false, TBL_PROPS, null);
// Write a good row.
try {
PartialRow row = SCHEMA.newPartialRow();
row.addByte("key", (byte) 1);
row.addShort("int16", (short) 1);
row.addInt("int32", 1);
row.addLong("int64", 1L);
row.addBoolean("bool", true);
row.addFloat("float", 1.1f);
row.addDouble("double", 1.1d);
row.addString("string", "one");
row.addBinary("binary", "one".getBytes(UTF_8));
row.addTimestamp("timestamp", new Timestamp(NOW_MS));
row.addDecimal("decimal", new BigDecimal("1.111"));
row.setNull("null");
// Not setting the "default" column.
KuduWritable writable = new KuduWritable(row);
writer.write(writable);
} finally {
writer.close(false);
}
// Verify the written row.
KuduClient client = harness.getClient();
KuduTable table = client.openTable(TABLE_NAME);
KuduScanner scanner = client.newScannerBuilder(table).build();
List<RowResult> results = new ArrayList<>();
for (RowResult result : scanner) {
results.add(result);
}
assertEquals(1, results.size());
RowResult result = results.get(0);
assertEquals((byte) 1, result.getByte(0));
assertEquals((short) 1, result.getShort(1));
assertEquals(1, result.getInt(2));
assertEquals(1L, result.getLong(3));
assertTrue(result.getBoolean(4));
assertEquals(1.1f, result.getFloat(5), 0);
assertEquals(1.1d, result.getDouble(6), 0);
assertEquals("one", result.getString(7));
assertEquals("one", new String(result.getBinaryCopy(8), UTF_8));
assertEquals(NOW_MS, result.getTimestamp(9).getTime());
assertEquals(new BigDecimal("1.111"), result.getDecimal(10));
assertTrue(result.isNull(11));
// default.
assertEquals(1, result.getInt(12));
}
Aggregations