use of io.prestosql.execution.SplitCacheMap in project hetu-core by openlookeng.
the class TestOrcCache method testDropCacheWithPredicates.
@Test
public void testDropCacheWithPredicates() {
SplitCacheMap splitCacheMap = SplitCacheMap.getInstance();
assertQuerySucceeds("CACHE TABLE test_drop_cache_3 WHERE p1 = 1");
assertTrue(splitCacheMap.tableCacheInfoMap().get("hive.tpch.test_drop_cache_3").showPredicates().contains("(p1 = 1)"));
assertQuerySucceeds("CACHE TABLE test_drop_cache_4 WHERE p3 = 3");
assertTrue(splitCacheMap.tableCacheInfoMap().get("hive.tpch.test_drop_cache_4").showPredicates().contains("(p3 = 3)"));
assertQuerySucceeds("CACHE TABLE test_drop_cache_4 WHERE p3 = 4");
assertTrue(splitCacheMap.tableCacheInfoMap().get("hive.tpch.test_drop_cache_4").showPredicates().contains("(p3 = 4)"));
assertQuerySucceeds("CACHE TABLE test_drop_cache_3 WHERE p2 = 2");
assertTrue(splitCacheMap.tableCacheInfoMap().get("hive.tpch.test_drop_cache_3").showPredicates().contains("(p2 = 2)"));
assertQuerySucceeds("DROP CACHE test_drop_cache_3 WHERE p1 = 1");
assertFalse(splitCacheMap.tableCacheInfoMap().get("hive.tpch.test_drop_cache_3").showPredicates().contains("(p1 = 1)"));
assertTrue(splitCacheMap.tableCacheInfoMap().get("hive.tpch.test_drop_cache_3").showPredicates().contains("(p2 = 2)"));
assertQuerySucceeds("DROP CACHE test_drop_cache_4 WHERE p3 = 4");
assertTrue(splitCacheMap.tableCacheInfoMap().get("hive.tpch.test_drop_cache_4").showPredicates().contains("(p3 = 3)"));
assertFalse(splitCacheMap.tableCacheInfoMap().get("hive.tpch.test_drop_cache_4").showPredicates().contains("(p3 = 4)"));
}
use of io.prestosql.execution.SplitCacheMap in project hetu-core by openlookeng.
the class SplitCacheAwareNodeSelector method computeAssignments.
@Override
public SplitPlacementResult computeAssignments(Set<Split> splits, List<RemoteTask> existingTasks, Optional<SqlStageExecution> stage) {
Multimap<InternalNode, Split> assignment = HashMultimap.create();
NodeMap nodeMapSlice = this.nodeMap.get().get();
Map<CatalogName, Map<String, InternalNode>> activeNodesByCatalog = new HashMap<>();
NodeAssignmentStats assignmentStats = new NodeAssignmentStats(nodeTaskMap, nodeMapSlice, existingTasks);
Set<Split> uncacheableSplits = new HashSet<>();
Set<Split> newCacheableSplits = new HashSet<>();
SplitCacheMap splitCacheMap = SplitCacheMap.getInstance();
for (Split split : splits) {
Optional<String> assignedNodeId = Optional.empty();
SplitKey splitKey = createSplitKey(split);
if (splitKey != null) {
assignedNodeId = splitCacheMap.getCachedNodeId(splitKey);
}
if (!split.getConnectorSplit().isCacheable() || splitKey == null) {
// uncacheable splits will be scheduled using default node selector
uncacheableSplits.add(split);
continue;
}
Map<String, InternalNode> activeNodes = activeNodesByCatalog.computeIfAbsent(split.getCatalogName(), catalogName -> nodeManager.getActiveConnectorNodes(catalogName).stream().collect(Collectors.toMap(InternalNode::getNodeIdentifier, Function.identity())));
InternalNode assignedNode = assignedNodeId.map(activeNodes::get).orElse(null);
// check if a node has been assigned and ensure it is still active before scheduling
if (assignedNode != null) {
// split has been previously assigned to a node
// assign the split to the same node as before
assignment.put(assignedNode, split);
assignmentStats.addAssignedSplit(assignedNode);
} else {
// splits that have not be previously cached or the assigned node is now inactive
newCacheableSplits.add(split);
}
}
log.info("%d out of %d splits already cached. %d new splits to be cached. %d splits cannot be cached.", assignment.size(), splits.size(), newCacheableSplits.size(), uncacheableSplits.size());
Set<Split> unassignedSplits = new HashSet<>();
unassignedSplits.addAll(newCacheableSplits);
unassignedSplits.addAll(uncacheableSplits);
// Compute split assignments for splits that cannot be cached, newly cacheable, and already cached but cached worker is inactive now.
SplitPlacementResult defaultSplitPlacementResult = defaultNodeSelector.computeAssignments(unassignedSplits, existingTasks, stage);
defaultSplitPlacementResult.getAssignments().forEach(((internalNode, split) -> {
// Set or Update cached node id only if split is cacheable
if (newCacheableSplits.contains(split)) {
SplitKey splitKey = createSplitKey(split);
if (splitKey != null) {
splitCacheMap.addCachedNode(splitKey, internalNode.getNodeIdentifier());
}
}
assignmentStats.addAssignedSplit(internalNode);
}));
assignment.putAll(defaultSplitPlacementResult.getAssignments());
// Check if its CTE node and its feeder
if (stage.isPresent() && stage.get().getFragment().getFeederCTEId().isPresent()) {
updateFeederNodeAndSplitCount(stage.get(), assignment);
}
return new SplitPlacementResult(defaultSplitPlacementResult.getBlocked(), assignment);
}
use of io.prestosql.execution.SplitCacheMap in project boostkit-bigdata by kunpengcompute.
the class TestOrcCache method testCacheTableWithComplexPredicate.
@Test
public void testCacheTableWithComplexPredicate() {
SplitCacheMap splitCacheMap = SplitCacheMap.getInstance();
assertQuerySucceeds("CACHE TABLE employee WHERE dob BETWEEN DATE '1980-01-01' AND DATE '2000-01-01' AND perf < DOUBLE '9.0'");
assertQueryOrdered("SELECT * FROM employee WHERE dob BETWEEN DATE '1980-01-01' AND DATE '2000-01-01' AND perf < DOUBLE '9.0' ORDER BY id", "VALUES (0, 'Alice', '1995-10-09', 8.0), (4, 'Lenard', '1980-06-24', 8.8)");
assertTrue(splitCacheMap.tableCacheInfoMap().get("hive.tpch.employee").showPredicates().contains("((dob BETWEEN DATE '1980-01-01' AND DATE '2000-01-01') AND (perf < DOUBLE '9.0'))"));
assertQuerySucceeds("CACHE TABLE employee WHERE dob < DATE '1980-01-01' AND perf < DOUBLE '8.0'");
assertQueryOrdered("SELECT * FROM employee WHERE dob < DATE '1980-01-01' AND perf < DOUBLE '8.0' ORDER BY id", "VALUES (6, 'Trump', '1945-08-15', 2.5)");
assertTrue(splitCacheMap.tableCacheInfoMap().get("hive.tpch.employee").showPredicates().contains("((dob < DATE '1980-01-01') AND (perf < DOUBLE '8.0'))"));
}
use of io.prestosql.execution.SplitCacheMap in project boostkit-bigdata by kunpengcompute.
the class TestOrcCache method testDropCacheWithPredicates.
@Test
public void testDropCacheWithPredicates() {
SplitCacheMap splitCacheMap = SplitCacheMap.getInstance();
assertQuerySucceeds("CACHE TABLE test_drop_cache_3 WHERE p1 = 1");
assertTrue(splitCacheMap.tableCacheInfoMap().get("hive.tpch.test_drop_cache_3").showPredicates().contains("(p1 = 1)"));
assertQuerySucceeds("CACHE TABLE test_drop_cache_4 WHERE p3 = 3");
assertTrue(splitCacheMap.tableCacheInfoMap().get("hive.tpch.test_drop_cache_4").showPredicates().contains("(p3 = 3)"));
assertQuerySucceeds("CACHE TABLE test_drop_cache_4 WHERE p3 = 4");
assertTrue(splitCacheMap.tableCacheInfoMap().get("hive.tpch.test_drop_cache_4").showPredicates().contains("(p3 = 4)"));
assertQuerySucceeds("CACHE TABLE test_drop_cache_3 WHERE p2 = 2");
assertTrue(splitCacheMap.tableCacheInfoMap().get("hive.tpch.test_drop_cache_3").showPredicates().contains("(p2 = 2)"));
assertQuerySucceeds("DROP CACHE test_drop_cache_3 WHERE p1 = 1");
assertFalse(splitCacheMap.tableCacheInfoMap().get("hive.tpch.test_drop_cache_3").showPredicates().contains("(p1 = 1)"));
assertTrue(splitCacheMap.tableCacheInfoMap().get("hive.tpch.test_drop_cache_3").showPredicates().contains("(p2 = 2)"));
assertQuerySucceeds("DROP CACHE test_drop_cache_4 WHERE p3 = 4");
assertTrue(splitCacheMap.tableCacheInfoMap().get("hive.tpch.test_drop_cache_4").showPredicates().contains("(p3 = 3)"));
assertFalse(splitCacheMap.tableCacheInfoMap().get("hive.tpch.test_drop_cache_4").showPredicates().contains("(p3 = 4)"));
}
use of io.prestosql.execution.SplitCacheMap in project boostkit-bigdata by kunpengcompute.
the class TestOrcCache method testShowCache.
@Test
public void testShowCache() {
SplitCacheMap splitCacheMap = SplitCacheMap.getInstance();
assertQuerySucceeds("CACHE TABLE employee WHERE dob BETWEEN DATE '1980-01-01' AND DATE '2000-01-01'");
assertTrue(splitCacheMap.tableCacheInfoMap().get("hive.tpch.employee").showPredicates().contains("(dob BETWEEN DATE '1980-01-01' AND DATE '2000-01-01')"));
assertQuerySucceeds("CACHE TABLE employee WHERE perf > DOUBLE '9.0'");
assertTrue(splitCacheMap.tableCacheInfoMap().get("hive.tpch.employee").showPredicates().contains("(dob BETWEEN DATE '1980-01-01' AND DATE '2000-01-01')"));
assertTrue(splitCacheMap.tableCacheInfoMap().get("hive.tpch.employee").showPredicates().contains("(perf > DOUBLE '9.0')"));
}
Aggregations