DefaultHBaseSerde implements HBaseSerde { @Override public Query convertToQuery(Row row) { if (filtersEntireRowKey(row)) { return convertToGet(row); } else if (filtersRowKeyPrefix(row)) { return convertToScan(row); } else { throw new RuntimeException("Default HBase serde only supports full row key or prefix row key reads."); } }  void configure(Config config); @Override Query convertToQuery(Row row); @Override Row convertFromResult(Result result); @Override List<Row> convertFromResults(Iterable<Result> results); @Override Put convertToPut(Row row); @Override List<Put> convertToPuts(List<Row> rows); @Override Delete convertToDelete(Row row); @Override List<Delete> convertToDeletes(List<Row> rows);  }
@Test public void testConvertToGetRowKeyColumns() { Row filterRow = new RowWithSchema(filterSchema1, "GOOG", 1_000_000_000L); Get get = (Get)serde.convertToQuery(filterRow); byte[] row = get.getRow(); assertEquals("Row Key should contain symbol and transacttime separated by :", "GOOG:" + new String(Bytes.toBytes(1_000_000_000L)), new String(row)); Set<byte[]> families = get.familySet(); assertEquals("Should be zero column families", 0, families.size()); Filter filter = get.getFilter(); assertNull("No filters", filter); }
@Test public void testConvertToGetRowKeyAndColumnFilters() { Row filterRow = new RowWithSchema(filterSchema2, "GOOG", 1_000_000_000L, "abcd"); Get get = (Get)serde.convertToQuery(filterRow); byte[] row = get.getRow(); assertEquals("Row Key should contain symbol and transacttime separated by :", "GOOG:" + new String(Bytes.toBytes(1_000_000_000L)), new String(row)); Set<byte[]> families = get.familySet(); assertEquals("Should be one column family", 1, families.size()); assertTrue("Column family should be cf1", families.contains("cf1".getBytes())); FilterList filter = (FilterList) get.getFilter(); assertEquals("One filter", 1, filter.getFilters().size()); assertArrayEquals("Filtering for cf1:clordid = abcd", ((SingleColumnValueFilter)filter.getFilters().get(0)).getFamily(), "cf1".getBytes()); assertArrayEquals("Filtering for cf1:clordid = abcd", ((SingleColumnValueFilter)filter.getFilters().get(0)).getQualifier(), "clordid".getBytes()); assertArrayEquals("Filtering for cf1:clordid = abcd", ((SingleColumnValueFilter)filter.getFilters().get(0)).getComparator().getValue(), "abcd".getBytes()); }
@Test public void testConvertToScanPrefixKey() { Row filterRow = new RowWithSchema(filterSchemaPrefix, "AAPL"); Scan scan = (Scan)serde.convertToQuery(filterRow); assertEquals("Should be start row 'AAPL'", "AAPL", Bytes.toString(scan.getStartRow())); assertEquals("Should be stop row 'AAPM'", "AAPM", Bytes.toString(scan.getStopRow())); }