pulsar-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [pulsar] jerrypeng commented on a change in pull request #4888: [pulsar-sql] Make partition as internal column
Date Tue, 06 Aug 2019 17:18:56 GMT
jerrypeng commented on a change in pull request #4888: [pulsar-sql] Make partition as internal
column
URL: https://github.com/apache/pulsar/pull/4888#discussion_r311179471
 
 

 ##########
 File path: pulsar-sql/presto-pulsar/src/main/java/org/apache/pulsar/sql/presto/PulsarSplitManager.java
 ##########
 @@ -136,45 +137,85 @@ public ConnectorSplitSource getSplits(ConnectorTransactionHandle transactionHand
     @VisibleForTesting
     Collection<PulsarSplit> getSplitsPartitionedTopic(int numSplits, TopicName topicName,
PulsarTableHandle
             tableHandle, SchemaInfo schemaInfo, TupleDomain<ColumnHandle> tupleDomain)
throws Exception {
-        int numPartitions;
-        try {
-            numPartitions = (this.pulsarAdmin.topics().getPartitionedTopicMetadata(topicName.toString())).partitions;
-        } catch (PulsarAdminException e) {
-            if (e.getStatusCode() == 401) {
-                throw new PrestoException(QUERY_REJECTED,
-                        String.format("Failed to get metadata for partitioned topic %s: Unauthorized",
topicName));
-            }
 
-            throw new RuntimeException("Failed to get metadata for partitioned topic "
-                + topicName + ": " + ExceptionUtils.getRootCause(e).getLocalizedMessage(),
e);
+        List<Integer> predicatedPartitions = getPredicatedPartitions(topicName, tupleDomain);
+        if (log.isDebugEnabled()) {
+            log.debug("Partition filter result %s", predicatedPartitions);
         }
 
-        int actualNumSplits = Math.max(numPartitions, numSplits);
+        int actualNumSplits = Math.max(predicatedPartitions.size(), numSplits);
 
-        int splitsPerPartition = actualNumSplits / numPartitions;
+        int splitsPerPartition = actualNumSplits / predicatedPartitions.size();
 
-        int splitRemainder = actualNumSplits % numPartitions;
+        int splitRemainder = actualNumSplits % predicatedPartitions.size();
 
         ManagedLedgerFactory managedLedgerFactory = PulsarConnectorCache.getConnectorCache(pulsarConnectorConfig)
                 .getManagedLedgerFactory();
 
         List<PulsarSplit> splits = new LinkedList<>();
-        for (int i = 0; i < numPartitions; i++) {
-
+        for (int i = 0; i < predicatedPartitions.size(); i++) {
             int splitsForThisPartition = (splitRemainder > i) ? splitsPerPartition + 1
: splitsPerPartition;
             splits.addAll(
-                    getSplitsForTopic(
-                            topicName.getPartition(i).getPersistenceNamingEncoding(),
-                            managedLedgerFactory,
-                            splitsForThisPartition,
-                            tableHandle,
-                            schemaInfo,
-                            topicName.getPartition(i).getLocalName(),
-                            tupleDomain));
+                getSplitsForTopic(
+                    topicName.getPartition(predicatedPartitions.get(i)).getPersistenceNamingEncoding(),
+                    managedLedgerFactory,
+                    splitsForThisPartition,
+                    tableHandle,
+                    schemaInfo,
+                    topicName.getPartition(predicatedPartitions.get(i)).getLocalName(),
+                    tupleDomain));
         }
         return splits;
     }
 
+    private List<Integer> getPredicatedPartitions(TopicName topicName, TupleDomain<ColumnHandle>
tupleDomain) {
+        int numPartitions;
+        try {
+            numPartitions = (this.pulsarAdmin.topics().getPartitionedTopicMetadata(topicName.toString())).partitions;
+        } catch (PulsarAdminException e) {
+            if (e.getStatusCode() == 401) {
+                throw new PrestoException(QUERY_REJECTED,
+                    String.format("Failed to get metadata for partitioned topic %s: Unauthorized",
topicName));
+            }
+
+            throw new RuntimeException("Failed to get metadata for partitioned topic "
+                + topicName + ": " + ExceptionUtils.getRootCause(e).getLocalizedMessage(),e);
+        }
+        List<Integer> predicatePartitions = new ArrayList<>();
+        if (tupleDomain.getDomains().isPresent()) {
+            Domain domain = tupleDomain.getDomains().get().get(PulsarInternalColumn.PARTITION
+                .getColumnHandle(connectorId, false));
+            if (domain != null) {
+                domain.getValues().getValuesProcessor().consume(
+                    ranges -> domain.getValues().getRanges().getOrderedRanges().forEach(range
-> {
+                        Integer low = 0;
+                        Integer high = numPartitions;
+                        if (!range.getLow().isLowerUnbounded() && range.getLow().getValueBlock().isPresent())
{
+                            low = range.getLow().getValueBlock().get().getInt(0, 0);
+                        }
+                        if (!range.getHigh().isLowerUnbounded() && range.getHigh().getValueBlock().isPresent())
{
+                            high = range.getHigh().getValueBlock().get().getInt(0, 0);
+                        }
+                        for (int i = low; i <= high; i++) {
+                            predicatePartitions.add(i);
+                            low++;
 
 Review comment:
   do we need to do this?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message