private static List<RangePartition> getRangePartitionList(KuduTable table, long deadline) { List<RangePartition> rangePartitions = new ArrayList<>(); if (!table.getPartitionSchema().getRangeSchema().getColumns().isEmpty()) { try { Iterator var4 = table.getTabletsLocations(deadline).iterator(); while (var4.hasNext()) { LocatedTablet tablet = (LocatedTablet) var4.next(); Partition partition = tablet.getPartition(); if (Iterators.all(partition.getHashBuckets().iterator(), Predicates.equalTo(0))) { RangePartition rangePartition = buildRangePartition(table, partition); rangePartitions.add(rangePartition); } } } catch (Exception e) { throw new RuntimeException(e); } } return rangePartitions; }
private void init() { String tableName = kuduScanSpec.getTableName(); Collection<DrillbitEndpoint> endpoints = kuduStoragePlugin.getContext().getBits(); Map<String,DrillbitEndpoint> endpointMap = Maps.newHashMap(); for (DrillbitEndpoint endpoint : endpoints) { endpointMap.put(endpoint.getAddress(), endpoint); } try { List<LocatedTablet> locations = kuduStoragePlugin.getClient().openTable(tableName).getTabletsLocations(10000); for (LocatedTablet tablet : locations) { KuduWork work = new KuduWork(tablet.getPartition().getPartitionKeyStart(), tablet.getPartition().getPartitionKeyEnd()); for (Replica replica : tablet.getReplicas()) { String host = replica.getRpcHost(); DrillbitEndpoint ep = endpointMap.get(host); if (ep != null) { work.getByteMap().add(ep, DEFAULT_TABLET_SIZE); } } kuduWorkList.add(work); } } catch (Exception e) { throw new RuntimeException(e); } }
/** * DEPRECATED: use {@link #getPartition()} */ @Deprecated public byte[] getStartKey() { return getPartition().getPartitionKeyStart(); }
/** * DEPRECATED: use {@link #getPartition()} */ @Deprecated() public byte[] getEndKey() { return getPartition().getPartitionKeyEnd(); }
@Override public byte[] partitionKey() { return tablet.getPartition().getPartitionKeyStart(); }
@Override public int compareTo(KuduScanToken other) { if (!message.getTableName().equals(other.message.getTableName())) { throw new IllegalArgumentException("Scan tokens from different tables may not be compared"); } return tablet.getPartition().compareTo(other.getTablet().getPartition()); }
public void add(Operation operation, int index) { assert Bytes.memcmp(operation.partitionKey(), tablet.getPartition().getPartitionKeyStart()) >= 0 && (tablet.getPartition().getPartitionKeyEnd().length == 0 || Bytes.memcmp(operation.partitionKey(), tablet.getPartition().getPartitionKeyEnd()) < 0); operations.add(operation); operationIndexes.add(index); }
private static List<RangePartition> getRangePartitionList(KuduTable table, long deadline) { List<RangePartition> rangePartitions = new ArrayList(); if (!table.getPartitionSchema().getRangeSchema().getColumns().isEmpty()) { try { Iterator var4 = table.getTabletsLocations(deadline).iterator(); while (var4.hasNext()) { LocatedTablet tablet = (LocatedTablet) var4.next(); Partition partition = tablet.getPartition(); if (Iterators.all(partition.getHashBuckets().iterator(), Predicates.equalTo(0))) { RangePartition rangePartition = buildRangePartition(table, partition); rangePartitions.add(rangePartition); } } } catch (Exception e) { throw new RuntimeException(e); } } return rangePartitions; }
private static List<RangePartition> getRangePartitionList(KuduTable table, long deadline) { List<RangePartition> rangePartitions = new ArrayList<>(); if (!table.getPartitionSchema().getRangeSchema().getColumns().isEmpty()) { try { Iterator var4 = table.getTabletsLocations(deadline).iterator(); while (var4.hasNext()) { LocatedTablet tablet = (LocatedTablet) var4.next(); Partition partition = tablet.getPartition(); if (Iterators.all(partition.getHashBuckets().iterator(), Predicates.equalTo(0))) { RangePartition rangePartition = buildRangePartition(table, partition); rangePartitions.add(rangePartition); } } } catch (Exception e) { throw new RuntimeException(e); } } return rangePartitions; }
/** * Retrieves the partitions of a table. * * @param table the table * @return the partitions of the table */ private List<Partition> getTablePartitions(KuduTable table) { List<Partition> partitions = new ArrayList<>(); for (KuduScanToken token : client.newScanTokenBuilder(table).build()) { partitions.add(token.getTablet().getPartition()); } return partitions; }
/** * 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; } }
assertArrayEquals(getKeyInBytes(0), tablets.get(0).getPartition().getPartitionKeyStart()); assertArrayEquals(getKeyInBytes(50), tablets.get(0).getPartition().getPartitionKeyEnd()); assertArrayEquals(getKeyInBytes(50), tablets.get(1).getPartition().getPartitionKeyStart()); assertArrayEquals(getKeyInBytes(100), tablets.get(1).getPartition().getPartitionKeyEnd()); assertArrayEquals(getKeyInBytes(200), tablets.get(2).getPartition().getPartitionKeyStart()); assertArrayEquals(getKeyInBytes(300), tablets.get(2).getPartition().getPartitionKeyEnd()); assertArrayEquals(getKeyInBytes(0), tablets.get(0).getPartition().getPartitionKeyStart()); assertArrayEquals(getKeyInBytes(50), tablets.get(0).getPartition().getPartitionKeyEnd()); assertArrayEquals(getKeyInBytes(200), tablets.get(0).getPartition().getPartitionKeyStart()); assertArrayEquals(getKeyInBytes(300), tablets.get(0).getPartition().getPartitionKeyEnd()); assertArrayEquals(getKeyInBytes(200), tablets.get(0).getPartition().getPartitionKeyStart()); assertArrayEquals(getKeyInBytes(300), tablets.get(0).getPartition().getPartitionKeyEnd());
} else { pruner.removePartitionKeyRange(newTablets.get(newTablets.size() - 1) .getPartition() .getPartitionKeyEnd()); Client.ScanTokenPB.Builder builder = proto.clone(); builder.setLowerBoundPartitionKey( UnsafeByteOperations.unsafeWrap(tablet.getPartition().getPartitionKeyStart())); builder.setUpperBoundPartitionKey( UnsafeByteOperations.unsafeWrap(tablet.getPartition().getPartitionKeyEnd())); tokens.add(new KuduScanToken(tablet, builder.build()));
assertArrayEquals(getKeyInBytes(300), tablets.get(0).getPartition().getPartitionKeyStart()); assertArrayEquals(getKeyInBytes(400), tablets.get(0).getPartition().getPartitionKeyEnd());
.lowerBoundPartitionKeyRaw(tablet.getPartition().getPartitionKeyStart()) .exclusiveUpperBoundPartitionKeyRaw(tablet.getPartition().getPartitionKeyEnd()) .build(); Set<Row> tabletResults = collectRows(scanner); .lowerBound(lowerBound) .exclusiveUpperBound(upperBound) .lowerBoundPartitionKeyRaw(tablet.getPartition().getPartitionKeyStart()) .exclusiveUpperBoundPartitionKeyRaw(tablet.getPartition().getPartitionKeyEnd()) .build(); Set<Row> tabletResults = collectRows(scanner);