/** * Retrieves this table's range partitions. The range partitions will be returned * in sorted order by value, and will contain no duplicates. * * @param timeout the timeout of the operation * @return a list of the formatted range partitions */ @InterfaceAudience.Private @InterfaceStability.Unstable public List<Partition> getRangePartitions(long timeout) throws Exception { // TODO: This could be moved into the RangeSchemaPB returned from server // to avoid an extra call to get the range partitions. List<Partition> rangePartitions = new ArrayList<>(); List<KuduScanToken> scanTokens = new KuduScanToken.KuduScanTokenBuilder(client, this) .setTimeout(timeout) .build(); for (KuduScanToken token : scanTokens) { Partition partition = token.getTablet().getPartition(); // Filter duplicate range partitions by taking only the tablets whose hash // partitions are all 0s. if (!Iterators.all(partition.getHashBuckets().iterator(), Predicates.equalTo(0))) { continue; } rangePartitions.add(partition); } return rangePartitions; } }
/** Test that scanRequestTimeout makes it from the scan token to the underlying Scanner class. */ @Test public void testScanRequestTimeout() throws IOException { final int NUM_ROWS_DESIRED = 100; final int SCAN_REQUEST_TIMEOUT_MS = 20; KuduTable table = createDefaultTable(client, testTableName); loadDefaultTable(client, testTableName, NUM_ROWS_DESIRED); KuduScanToken.KuduScanTokenBuilder builder = new KuduScanToken.KuduScanTokenBuilder(asyncClient, table); builder.scanRequestTimeout(SCAN_REQUEST_TIMEOUT_MS); List<KuduScanToken> tokens = builder.build(); for (KuduScanToken token : tokens) { byte[] serialized = token.serialize(); KuduScanner scanner = KuduScanToken.deserializeIntoScanner(serialized, client); assertEquals(SCAN_REQUEST_TIMEOUT_MS, scanner.getScanRequestTimeout()); } } }
/** * Creates a new {@link KuduScanToken.KuduScanTokenBuilder} for a particular table. * Used for integrations with compute frameworks. * @param table the table you intend to scan * @return a new scan token builder for the table */ public KuduScanToken.KuduScanTokenBuilder newScanTokenBuilder(KuduTable table) { return new KuduScanToken.KuduScanTokenBuilder(asyncClient, table); }