Search in sources :

Example 1 with KuduRecordWriter

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);
    }
}
Also used : KuduRecordWriter(org.apache.hadoop.hive.kudu.KuduOutputFormat.KuduRecordWriter) PartialRow(org.apache.kudu.client.PartialRow) JobConf(org.apache.hadoop.mapred.JobConf) KuduException(org.apache.kudu.client.KuduException) Test(org.junit.Test)

Example 2 with KuduRecordWriter

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));
}
Also used : KuduRecordWriter(org.apache.hadoop.hive.kudu.KuduOutputFormat.KuduRecordWriter) ArrayList(java.util.ArrayList) PartialRow(org.apache.kudu.client.PartialRow) KuduTable(org.apache.kudu.client.KuduTable) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Timestamp(java.sql.Timestamp) BigDecimal(java.math.BigDecimal) RowResult(org.apache.kudu.client.RowResult) KuduScanner(org.apache.kudu.client.KuduScanner) KuduClient(org.apache.kudu.client.KuduClient) JobConf(org.apache.hadoop.mapred.JobConf) Test(org.junit.Test)

Aggregations

KuduRecordWriter (org.apache.hadoop.hive.kudu.KuduOutputFormat.KuduRecordWriter)2 JobConf (org.apache.hadoop.mapred.JobConf)2 PartialRow (org.apache.kudu.client.PartialRow)2 Test (org.junit.Test)2 BigDecimal (java.math.BigDecimal)1 Timestamp (java.sql.Timestamp)1 ArrayList (java.util.ArrayList)1 KuduClient (org.apache.kudu.client.KuduClient)1 KuduException (org.apache.kudu.client.KuduException)1 KuduScanner (org.apache.kudu.client.KuduScanner)1 KuduTable (org.apache.kudu.client.KuduTable)1 RowResult (org.apache.kudu.client.RowResult)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1