Source:
private List<ConnectorSplit> dynamicallyFilterSplits(List<ConnectorSplit> splits) { List<DynamicFilterDescription> dynamicFilterDescriptions = null; try { dynamicFilterDescriptions = filters.get(); } catch (Exception e) { } if (dynamicFilterDescriptions == null || dynamicFilterDescriptions.size() == 0) { return splits; } Iterator<ConnectorSplit> iter = splits.iterator(); while (iter.hasNext()) { HiveSplit hiveSplit = (HiveSplit) iter.next(); for (DynamicFilterDescription dynamicFilter : dynamicFilterDescriptions) { Optional<Map<ColumnHandle, Domain>> domains = dynamicFilter.getTupleDomain().getDomains(); if (!domains.isPresent()) { continue; } for (HivePartitionKey partitionKey : hiveSplit.getPartitionKeys()) { Map<HiveColumnHandle, Domain> relevantDomains = domains.get().entrySet().stream().filter(entry -> ((HiveColumnHandle) entry.getKey()).getName().equals(partitionKey.getName())).collect(toMap(e -> (HiveColumnHandle) e.getKey(), e -> e.getValue())); boolean matched = false; for (Domain predicateDomain : relevantDomains.values()) { Type type = partitionKey.getHiveType().getType(typeManager); Object objectToWrite; try { objectToWrite = HiveUtil.parsePartitionValue(partitionKey.getName(), partitionKey.getValue(), type, timeZone).getValue(); } catch (PrestoException e) { if (e.getErrorCode().equals(NOT_SUPPORTED)) { continue; } throw e; } if (predicateDomain.overlaps(Domain.singleValue(type, objectToWrite))) { matched = true; break; } } if (!matched) { iter.remove(); } } } } return splits; }

Target:
private List<ConnectorSplit> dynamicallyFilterSplits(List<ConnectorSplit> splits) { List<DynamicFilterDescription> dynamicFilterDescriptions = getAvailableDynamicFilterDescriptions(); TupleDomain<HiveColumnHandle> runtimeTupleDomain = dynamicFilterDescriptions.stream() .map(DynamicFilterDescription::getTupleDomain) .map(domain -> domain.transform(HiveColumnHandle.class::cast)) .reduce(TupleDomain.all(), TupleDomain::columnWiseUnion); Optional<Map<HiveColumnHandle, Domain>> domains = runtimeTupleDomain.getDomains(); if (!domains.isPresent() || domains.get().size() == 0) { return splits; } DomainsCache domainsCache = new DomainsCache(domains.get()); ImmutableList.Builder<ConnectorSplit> result = ImmutableList.builder(); for (ConnectorSplit split : splits) { HiveSplit hiveSplit = (HiveSplit) split; for (HivePartitionKey partitionKey : hiveSplit.getPartitionKeys()) { String partitionKeyName = partitionKey.getName().toLowerCase(Locale.ENGLISH); Collection<Domain> relevantDomains = domainsCache.getDomains(partitionKeyName); for (Domain predicateDomain : relevantDomains) { Type type = partitionKey.getHiveType().getType(typeManager); Object objectToWrite; try { objectToWrite = HiveUtil.parsePartitionValue(partitionKey.getName(), partitionKey.getValue(), type, timeZone).getValue(); } catch (PrestoException e) { if (e.getErrorCode().equals(NOT_SUPPORTED)) { continue; } throw e; } if (predicateDomain.overlaps(Domain.singleValue(type, objectToWrite))) { result.add(new HiveSplit( hiveSplit.getClientId(), hiveSplit.getDatabase(), hiveSplit.getTable(), hiveSplit.getPartitionName(), hiveSplit.getPath(), hiveSplit.getStart(), hiveSplit.getLength(), hiveSplit.getFileSize(), hiveSplit.getSchema(), hiveSplit.getPartitionKeys(), hiveSplit.getAddresses(), hiveSplit.getBucketNumber(), hiveSplit.isForceLocalScheduling(), hiveSplit.getEffectivePredicate().intersect(runtimeTupleDomain), hiveSplit.getColumnCoercions())); break; } } } } return result.build(); }