@Test public void testFlush() throws IOException { byte[] row = Bytes.toBytes("row"); byte[] cf = Bytes.toBytes("cf"); byte[] cq = Bytes.toBytes("cq"); byte[] value = Bytes.toBytes("value"); TableName name = TableName.valueOf(getClass().getSimpleName()); Table t = util.createTable(name, cf); t.put(new Put(row).addColumn(cf, cq, value)); util.getAdmin().flush(name); assertArrayEquals(value, t.get(new Get(row)).getValue(cf, cq)); } }
private void getVersionRangeAndVerifyGreaterThan(Table ht, byte [] row, byte [] family, byte [] qualifier, long [] stamps, byte [][] values, int start, int end) throws IOException { Get get = new Get(row); get.addColumn(family, qualifier); get.setMaxVersions(Integer.MAX_VALUE); get.setTimeRange(stamps[start+1], Long.MAX_VALUE); Result result = ht.get(get); assertNResult(result, row, family, qualifier, stamps, values, start+1, end); }
@Test public void testGet_NonExistentRow() throws IOException { Table table = TEST_UTIL.createTable(TableName.valueOf(name.getMethodName()), FAMILY); Put put = new Put(ROW); put.addColumn(FAMILY, QUALIFIER, VALUE); table.put(put); LOG.info("Row put"); Get get = new Get(ROW); get.addFamily(FAMILY); Result r = table.get(get); assertFalse(r.isEmpty()); System.out.println("Row retrieved successfully"); byte [] missingrow = Bytes.toBytes("missingrow"); get = new Get(missingrow); get.addFamily(FAMILY); r = table.get(get); assertTrue(r.isEmpty()); LOG.info("Row missing as it should be"); }
/** * Creates Get to retrieve incremental backup table set from backup system table * @return get operation * @throws IOException exception */ private Get createGetForIncrBackupTableSet(String backupRoot) throws IOException { Get get = new Get(rowkey(INCR_BACKUP_SET, backupRoot)); get.addFamily(BackupSystemTable.META_FAMILY); get.setMaxVersions(1); return get; }
private Result getRegionFromMeta(Connection connection, List<RegionInfo> regionsOfTable) throws IOException { byte[] metaKeyForRegion = MetaTableAccessor.getMetaKeyForRegion(regionsOfTable.get(0)); Get get = new Get(metaKeyForRegion); get.addFamily(HConstants.CATALOG_FAMILY); Table metaTable = MetaTableAccessor.getMetaHTable(connection); Result r = metaTable.get(get); return r; }
this(get.getRow()); this.setFilter(get.getFilter()); this.setReplicaId(get.getReplicaId()); this.setConsistency(get.getConsistency()); this.cacheBlocks = get.getCacheBlocks(); this.maxVersions = get.getMaxVersions(); this.storeLimit = get.getMaxResultsPerColumnFamily(); this.storeOffset = get.getRowOffsetPerColumnFamily(); this.tr = get.getTimeRange(); this.checkExistenceOnly = get.isCheckExistenceOnly(); this.loadColumnFamiliesOnDemand = get.getLoadColumnFamiliesOnDemandValue(); Map<byte[], NavigableSet<byte[]>> fams = get.getFamilyMap(); for (Map.Entry<byte[],NavigableSet<byte[]>> entry : fams.entrySet()) { byte [] fam = entry.getKey(); if (cols != null && cols.size() > 0) { for (byte[] col : cols) { addColumn(fam, col); addFamily(fam); for (Map.Entry<String, byte[]> attr : get.getAttributesMap().entrySet()) { setAttribute(attr.getKey(), attr.getValue()); for (Map.Entry<byte[], TimeRange> entry : get.getColumnFamilyTimeRange().entrySet()) { TimeRange tr = entry.getValue(); setColumnFamilyTimeRange(entry.getKey(), tr.getMin(), tr.getMax());
Table ht = TEST_UTIL.createTable(TableName.valueOf(TABLE), FAMILIES, Integer.MAX_VALUE); p.addColumn(FAMILY, Bytes.toBytes("column4"), 2L, Bytes.toBytes("value4-2")); p.addColumn(FAMILY, Bytes.toBytes("column4"), 3L, Bytes.toBytes("value4-3")); ht.put(p); TimestampsFilter filter = new TimestampsFilter(timestamps); Get g = new Get(Bytes.toBytes("row")); g.setFilter(filter); g.setMaxVersions(); g.addColumn(FAMILY, Bytes.toBytes("column2")); g.addColumn(FAMILY, Bytes.toBytes("column4")); Result result = ht.get(g); for (Cell kv : result.listCells()) { System.out.println("found row " + Bytes.toString(CellUtil.cloneRow(kv)) + ", column " + Bytes.toString(CellUtil.cloneQualifier(kv)) + ", value " assertEquals(2, result.listCells().size()); assertTrue(CellUtil.matchingValue(result.listCells().get(0), Bytes.toBytes("value2-3"))); assertTrue(CellUtil.matchingValue(result.listCells().get(1), Bytes.toBytes("value4-3"))); ht.close();
final TableName tableName = TableName.valueOf(name.getMethodName()); final byte[] FAMILY = Bytes.toBytes("family"); final byte[] C0 = Bytes.toBytes("c0"); final byte[] T1 = Bytes.toBytes("T1"); TEST_UTIL.getAdmin().createTable(desc); Table h = TEST_UTIL.getConnection().getTable(tableName); h.put(p); Get g = new Get(T1); g.setTimeRange(0, ts + 3); Result r = h.get(g); assertArrayEquals(T2, r.getValue(FAMILY, C0)); Cell[] kvs = scanner.next().rawCells(); assertArrayEquals(T2, CellUtil.cloneValue(kvs[0])); assertArrayEquals(T1, CellUtil.cloneValue(kvs[1])); kvs = scanner.next().rawCells(); assertTrue(PrivateCellUtil.isDeleteFamily(kvs[0])); assertArrayEquals(T3, CellUtil.cloneValue(kvs[1]));
@Test public void testEmptyFilterList() throws Exception { final TableName tableName = TableName.valueOf(name.getMethodName()); Table table = TEST_UTIL.createTable(tableName, FAMILY); Put put = new Put(Bytes.toBytes("row")); put.addColumn(FAMILY, QUALIFIER, VALUE); table.put(put); try (ResultScanner scanner = table.getScanner(scan)) { for (Result r : scanner) { scanResults.add(r); Get g = new Get(Bytes.toBytes("row")); g.setFilter(new FilterList()); Result getResult = table.get(g); Result scanResult = scanResults.get(0); assertEquals(scanResult.rawCells().length, getResult.rawCells().length); for (int i = 0; i != scanResult.rawCells().length; ++i) { Cell scanCell = scanResult.rawCells()[i]; Cell getCell = getResult.rawCells()[i]; assertEquals(0, Bytes.compareTo(CellUtil.cloneRow(scanCell), CellUtil.cloneRow(getCell))); assertEquals(0, Bytes.compareTo(CellUtil.cloneFamily(scanCell), CellUtil.cloneFamily(getCell))); assertEquals(0, Bytes.compareTo(CellUtil.cloneQualifier(scanCell), CellUtil.cloneQualifier(getCell)));
@Test public void testDeleteRow() throws IOException { Admin admin = TEST_UTIL.getAdmin(); admin.createNamespace(NamespaceDescriptor.create(HelloHBase.MY_NAMESPACE_NAME).build()); Table table = TEST_UTIL.createTable(HelloHBase.MY_TABLE_NAME, HelloHBase.MY_COLUMN_FAMILY_NAME); table.put(new Put(HelloHBase.MY_ROW_ID). addColumn(HelloHBase.MY_COLUMN_FAMILY_NAME, HelloHBase.MY_FIRST_COLUMN_QUALIFIER, Bytes.toBytes("xyz"))); HelloHBase.deleteRow(table); Result row = table.get(new Get(HelloHBase.MY_ROW_ID)); assertEquals("#deleteRow failed to delete row.", true, row.isEmpty()); TEST_UTIL.deleteTable(HelloHBase.MY_TABLE_NAME); admin.deleteNamespace(HelloHBase.MY_NAMESPACE_NAME); } }
@Test public void testHTableExistsBeforeGet() throws Exception { Table table = TEST_UTIL.createTable(TableName.valueOf(name.getMethodName()), new byte[][] { FAMILY }); try { Put put = new Put(ROW); put.addColumn(FAMILY, QUALIFIER, VALUE); table.put(put); Get get = new Get(ROW); boolean exist = table.exists(get); assertEquals(true, exist); Result result = table.get(get); assertEquals(false, result.isEmpty()); assertTrue(Bytes.equals(VALUE, result.getValue(FAMILY, QUALIFIER))); } finally { table.close(); } }
@Test public void testDeleteWithFailed() throws Exception { final TableName tableName = TableName.valueOf(name.getMethodName()); byte [][] FAMILIES = makeNAscii(FAMILY, 3); byte [][] VALUES = makeN(VALUE, 5); long [] ts = {1000, 2000, 3000, 4000, 5000}; Table ht = TEST_UTIL.createTable(tableName, FAMILIES, 3); Put put = new Put(ROW); put.addColumn(FAMILIES[0], QUALIFIER, ts[0], VALUES[0]); ht.put(put); // delete wrong family Delete delete = new Delete(ROW); delete.addFamily(FAMILIES[1], ts[0]); ht.delete(delete); Get get = new Get(ROW); get.addFamily(FAMILIES[0]); get.readAllVersions(); Result result = ht.get(get); assertTrue(Bytes.equals(result.getValue(FAMILIES[0], QUALIFIER), VALUES[0])); }
@Test public void testDisabledWAL() throws Exception { LOG.info("Writing data to table " + tableName); Put p = new Put(Bytes.toBytes("row")); p.addColumn(fam, Bytes.toBytes("qual"), Bytes.toBytes("val")); table.put(p); LOG.info("Flushing table " + tableName); TEST_UTIL.flush(tableName); LOG.info("Getting data from table " + tableName); Get get = new Get(Bytes.toBytes("row")); Result result = table.get(get); assertNotNull(result.getValue(fam, Bytes.toBytes("qual"))); } }
@Test public void testPeriodicFlush() throws InterruptedException, ExecutionException { AsyncBufferedMutator mutator = CONN.getBufferedMutatorBuilder(TABLE_NAME) .setWriteBufferPeriodicFlush(1, TimeUnit.SECONDS).build(); Put put = new Put(Bytes.toBytes(0)).addColumn(CF, CQ, VALUE); CompletableFuture<?> future = mutator.mutate(put); future.get(); AsyncTable<?> table = CONN.getTable(TABLE_NAME); assertArrayEquals(VALUE, table.get(new Get(Bytes.toBytes(0))).get().getValue(CF, CQ)); }
@Override boolean testRow(final int i) throws IOException { Get get = new Get(format(i)); for (int family = 0; family < opts.families; family++) { byte[] familyName = Bytes.toBytes(FAMILY_NAME_BASE + family); if (opts.addColumns) { for (int column = 0; column < opts.columns; column++) { byte [] qualifier = column == 0? COLUMN_ZERO: Bytes.toBytes("" + column); get.addColumn(familyName, qualifier); } } else { get.addFamily(familyName); } } if (opts.filterAll) { get.setFilter(new FilterAllFilter()); } updateValueSize(table.get(get)); return true; } }
@Test public void testGetWithFilter() throws IOException, InterruptedException { byte[] row1 = Bytes.toBytes("row1"); byte[] fam1 = Bytes.toBytes("fam1"); byte[] col1 = Bytes.toBytes("col1"); Put put = new Put(row1, ts); put.addColumn(fam1, col1, value1); region.put(put); put = new Put(row1, ts + 1); region.put(put); Get get = new Get(row1); get.setMaxVersions(); Result res = region.get(get); assertEquals(maxVersions, res.size()); get.setFilter(new ValueFilter(CompareOp.EQUAL, new SubstringComparator("value"))); res = region.get(get); assertEquals(1, res.size()); assertTrue(CellUtil.matchingValue(new KeyValue(row1, fam1, col1, value2), res.rawCells()[0]));
@Test public void testMultiPut() throws Exception { List<Put> puts = IntStream.range(0, 10) .mapToObj(i -> new Put(ROW).addColumn(FAMILY, Bytes.toBytes(i), VALUE)) .collect(Collectors.toList()); table.put(puts); assertResult(table.get(new Get(ROW)), VALUE); assertObserverHasExecuted(); List<Delete> deletes = IntStream.range(0, 10) .mapToObj(i -> new Delete(ROW).addColumn(FAMILY, Bytes.toBytes(i))) .collect(Collectors.toList()); table.delete(deletes); assertTrue(table.get(new Get(ROW)).isEmpty()); assertObserverHasExecuted(); }
private void getOneRowAndAssertAllExist(final Table table) throws IOException { Get get = new Get(ROWKEY); Result result = table.get(get); assertTrue("Column A value should be a", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("A"))).equals("a")); assertTrue("Column B value should be b", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("B"))).equals("b")); assertTrue("Column C value should be c", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("C"))).equals("c")); }
@Test public void testHTableExistsMethodSingleRegionMultipleGets() throws Exception { Table table = TEST_UTIL.createTable(TableName.valueOf( name.getMethodName()), new byte[][] { FAMILY }); Put put = new Put(ROW); put.addColumn(FAMILY, QUALIFIER, VALUE); table.put(put); List<Get> gets = new ArrayList<>(); gets.add(new Get(ROW)); gets.add(new Get(ANOTHERROW)); boolean[] results = table.exists(gets); assertTrue(results[0]); assertFalse(results[1]); }