// First check if we have a load with a map in it or not
List<Operator> sources = currentPlan.getSources();
for( Operator source : sources ) {
LogicalSchema schema = ((LogicalRelationalOperator)source).getSchema();
// If any of the loads has a null schema we dont know the ramifications here
// so we skip this optimization
if( schema == null ) {
return false;
}
}
// Now we check what keys are needed
MapMarker marker = new MapMarker(currentPlan);
marker.visit();
// If the uid is the input uid of LOStore, LOCogroup, LOUnion, UserFunc, that means
// the entire map may be used. For simplicity, we do not prune any map key in this case
Set<Long> fullMapUids = new HashSet<Long>();
FullMapCollector collector = new FullMapCollector(currentPlan, fullMapUids);
collector.visit();
// If we have found specific keys which are needed then we return true;
// Else if we dont have any specific keys we return false
boolean hasAnnotation = false;
for( Operator source : sources ) {
Map<Integer,Set<String>> annotationValue =
(Map<Integer, Set<String>>) ((LogicalRelationalOperator)source).getAnnotation(REQUIRED_MAPKEYS);
// Now for all full maps found in sinks we cannot prune them at source
if( ! fullMapUids.isEmpty() && annotationValue != null &&
!annotationValue.isEmpty() ) {
Integer[] annotationKeyArray = annotationValue.keySet().toArray( new Integer[0] );
LogicalSchema sourceSchema = ((LogicalRelationalOperator)source).getSchema();
for( Integer col : annotationKeyArray ) {
if( fullMapUids.contains(sourceSchema.getField(col).uid)) {
annotationValue.remove( col );
}
}
}