/** * Test for the existence of columns in the table, as specified by the Gets. * <p> * This will return a list of booleans. Each value will be true if the related Get matches one or * more keys, false if not. * <p> * This is a server-side call so it prevents any data from being transferred to the client. * @param gets the Gets * @return A list of {@link CompletableFuture}s that represent the existence for each get. */ default List<CompletableFuture<Boolean>> exists(List<Get> gets) { return get(toCheckExistenceOnly(gets)).stream() .<CompletableFuture<Boolean>> map(f -> f.thenApply(r -> r.getExists())).collect(toList()); }
/** * Test for the existence of columns in the table, as specified by the Get. * <p> * This will return true if the Get matches one or more keys, false if not. * <p> * This is a server-side call so it prevents any data from being transfered to the client. * @return true if the specified Get matches one or more keys, false if not. The return value will * be wrapped by a {@link CompletableFuture}. */ default CompletableFuture<Boolean> exists(Get get) { return get(toCheckExistenceOnly(get)).thenApply(r -> r.getExists()); }
@Override public boolean[] exists(List<Get> gets) throws IOException { if (gets.isEmpty()) return new boolean[]{}; if (gets.size() == 1) return new boolean[]{exists(gets.get(0))}; ArrayList<Get> exists = new ArrayList<>(gets.size()); for (Get g: gets){ Get ge = new Get(g); ge.setCheckExistenceOnly(true); exists.add(ge); } Object[] r1= new Object[exists.size()]; try { batch(exists, r1, readRpcTimeoutMs); } catch (InterruptedException e) { throw (InterruptedIOException)new InterruptedIOException().initCause(e); } // translate. boolean[] results = new boolean[r1.length]; int i = 0; for (Object o : r1) { // batch ensures if there is a failure we get an exception instead results[i++] = ((Result)o).getExists(); } return results; }
private Result internalGetFromHTable(Table table, String path, boolean fetchContent, boolean fetchTimestamp) throws IOException { byte[] rowkey = Bytes.toBytes(path); Get get = new Get(rowkey); if (!fetchContent && !fetchTimestamp) { get.setCheckExistenceOnly(true); } else { if (fetchContent) get.addColumn(B_FAMILY, B_COLUMN); if (fetchTimestamp) get.addColumn(B_FAMILY, B_COLUMN_TS); } Result result = table.get(get); boolean exists = result != null && (!result.isEmpty() || (result.getExists() != null && result.getExists())); return exists ? result : null; }
/** * Convert a client Result to a protocol buffer Result. * The pb Result does not include the Cell data. That is for transport otherwise. * * @param result the client Result to convert * @return the converted protocol buffer Result */ public static ClientProtos.Result toResultNoData(final Result result) { if (result.getExists() != null) return toResult(result.getExists(), result.isStale()); int size = result.size(); if (size == 0) return result.isStale() ? EMPTY_RESULT_PB_STALE : EMPTY_RESULT_PB; ClientProtos.Result.Builder builder = ClientProtos.Result.newBuilder(); builder.setAssociatedCellCount(size); builder.setStale(result.isStale()); return builder.build(); }
/** * Convert a client Result to a protocol buffer Result. * The pb Result does not include the Cell data. That is for transport otherwise. * * @param result the client Result to convert * @return the converted protocol buffer Result */ public static ClientProtos.Result toResultNoData(final Result result) { if (result.getExists() != null) return toResult(result.getExists(), result.isStale()); int size = result.size(); if (size == 0) return result.isStale() ? EMPTY_RESULT_PB_STALE : EMPTY_RESULT_PB; ClientProtos.Result.Builder builder = ClientProtos.Result.newBuilder(); builder.setAssociatedCellCount(size); builder.setStale(result.isStale()); return builder.build(); }
System.arraycopy(r.rawCells(), len, remainingCells, 0, r.size() - len); partialResults.addFirst( Result.create(remainingCells, r.getExists(), r.isStale(), r.mayHaveMoreCellsInRow())); break;
@Override public CompletableFuture<Boolean> thenMutate(RowMutations mutation) { preCheck(); return RawAsyncTableImpl.this.<Boolean> newCaller(mutation, rpcTimeoutNs) .action((controller, loc, stub) -> RawAsyncTableImpl.<Boolean> mutateRow(controller, loc, stub, mutation, (rn, rm) -> RequestConverter.buildMutateRequest(rn, row, family, qualifier, new BinaryComparator(value), CompareType.valueOf(op.name()), timeRange, rm), resp -> resp.getExists())) .call(); } }
/** * Convert a client Result to a protocol buffer Result * * @param result the client Result to convert * @return the converted protocol buffer Result */ public static ClientProtos.Result toResult(final Result result) { if (result.getExists() != null) { return toResult(result.getExists(), result.isStale()); } Cell[] cells = result.rawCells(); if (cells == null || cells.length == 0) { return result.isStale() ? EMPTY_RESULT_PB_STALE : EMPTY_RESULT_PB; } ClientProtos.Result.Builder builder = ClientProtos.Result.newBuilder(); for (Cell c : cells) { builder.addCell(toCell(c)); } builder.setStale(result.isStale()); builder.setPartial(result.mayHaveMoreCellsInRow()); return builder.build(); }
/** * Convert a client Result to a protocol buffer Result * * @param result the client Result to convert * @return the converted protocol buffer Result */ public static ClientProtos.Result toResult(final Result result) { if (result.getExists() != null) { return toResult(result.getExists(), result.isStale()); } Cell[] cells = result.rawCells(); if (cells == null || cells.length == 0) { return result.isStale() ? EMPTY_RESULT_PB_STALE : EMPTY_RESULT_PB; } ClientProtos.Result.Builder builder = ClientProtos.Result.newBuilder(); for (Cell c : cells) { builder.addCell(toCell(c)); } builder.setStale(result.isStale()); builder.setPartial(result.mayHaveMoreCellsInRow()); return builder.build(); }
r = table.get(g); Assert.assertFalse(r.isStale()); Assert.assertTrue(r.getExists()); LOG.info("exists not stale done"); r = table.get(g); Assert.assertTrue(r.isStale()); Assert.assertFalse("The secondary has stale data", r.getExists()); SlowMeCopro.getPrimaryCdl().get().countDown(); LOG.info("exists stale before flush done"); r = table.get(g); Assert.assertTrue(r.isStale()); Assert.assertTrue(r.getExists()); SlowMeCopro.getPrimaryCdl().get().countDown(); LOG.info("exists stale after flush done");
return ((Result)results[0]).getExists();
Assert.assertTrue(((Result)r).getExists());
Result r = results.get(lastIdx); if (r.mayHaveMoreCellsInRow()) { results.set(lastIdx, Result.create(r.rawCells(), r.getExists(), r.isStale(), false));
/** * Test for the existence of columns in the table, as specified by the Gets. * <p> * This will return a list of booleans. Each value will be true if the related Get matches one or * more keys, false if not. * <p> * This is a server-side call so it prevents any data from being transferred to the client. * @param gets the Gets * @return A list of {@link CompletableFuture}s that represent the existence for each get. */ default List<CompletableFuture<Boolean>> exists(List<Get> gets) { return get(toCheckExistenceOnly(gets)).stream() .<CompletableFuture<Boolean>> map(f -> f.thenApply(r -> r.getExists())).collect(toList()); }
/** * Test for the existence of columns in the table, as specified by the Get. * <p> * This will return true if the Get matches one or more keys, false if not. * <p> * This is a server-side call so it prevents any data from being transfered to the client. * @return true if the specified Get matches one or more keys, false if not. The return value will * be wrapped by a {@link CompletableFuture}. */ default CompletableFuture<Boolean> exists(Get get) { return get(toCheckExistenceOnly(get)).thenApply(r -> r.getExists()); }
boolean exists = r.getExists(); if (region.getCoprocessorHost() != null) { exists = region.getCoprocessorHost().postExists(clientGet, exists);
@Override public CompletableFuture<Boolean> thenMutate(RowMutations mutation) { preCheck(); return RawAsyncTableImpl.this.<Boolean> newCaller(mutation, rpcTimeoutNs) .action((controller, loc, stub) -> RawAsyncTableImpl.<Boolean> mutateRow(controller, loc, stub, mutation, (rn, rm) -> RequestConverter.buildMutateRequest(rn, row, family, qualifier, new BinaryComparator(value), CompareType.valueOf(op.name()), timeRange, rm), resp -> resp.getExists())) .call(); } }