@Override protected Class<? extends Operation> getType( FlowElement flowElement ) { if( !( flowElement instanceof Operator ) ) return null; return ( (Operator) flowElement ).getOperation().getClass(); } }
protected Operator( Operation operation ) { this.operation = operation; verifyOperation(); }
@Override public boolean applies( PlannerContext plannerContext, ElementGraph elementGraph, FlowElement flowElement ) { if( !( flowElement instanceof Operator ) ) return false; Operator operator = (Operator) flowElement; if( !operator.hasPlannerLevel() ) return false; PlannerLevel plannerLevel = plannerContext.getPlannerLevelFor( plannerLevelClass ); if( plannerLevel == null ) return false; if( !( (PlannedOperation) operator.getOperation() ).supportsPlannerLevel( plannerLevel ) ) return false; return operator.getPlannerLevel().isStricterThan( plannerLevel ); } }
Fields resolveDeclared( Set<Scope> incomingScopes, Fields arguments ) Fields fieldDeclaration = getFieldDeclaration(); if( getOutputSelector().isReplace() ) Scope incomingScope = getFirst( incomingScopes ); return resolveIncomingOperationPassThroughFields( incomingScope );
Fields resolveArgumentSelector( Set<Scope> incomingScopes ) { Fields argumentSelector = getArgumentSelector(); try { Scope incomingScope = getFirst( incomingScopes ); if( argumentSelector.isAll() ) return resolveIncomingOperationArgumentFields( incomingScope ); if( argumentSelector.isGroup() ) return incomingScope.getOutGroupingFields(); if( argumentSelector.isValues() ) return incomingScope.getOutGroupingValueFields(); return resolveIncomingOperationArgumentFields( incomingScope ).select( argumentSelector ); } catch( FieldsResolverException exception ) { throw new OperatorException( this, OperatorException.Kind.argument, exception.getSourceFields(), argumentSelector, exception ); } catch( Exception exception ) { throw new OperatorException( this, "unable to resolve argument selector: " + argumentSelector.printVerbose(), exception ); } }
Fields resolveOutgoingSelector( Set<Scope> incomingScopes, Fields argumentFields, Fields declaredFields ) { Scope incomingScope = getFirst( incomingScopes ); Fields outputSelector = getOutputSelector(); if( outputSelector.isResults() ) return declaredFields; if( outputSelector.isArguments() ) return argumentFields; if( outputSelector.isGroup() ) return incomingScope.getOutGroupingFields(); if( outputSelector.isValues() ) return incomingScope.getOutGroupingValueFields(); Fields incomingFields = resolveIncomingOperationPassThroughFields( incomingScope ); // not part of resolve as we need the argumentFields if( outputSelector.isSwap() ) return Fields.asDeclaration( incomingFields.subtract( argumentFields ) ).append( declaredFields ); try { return Fields.resolve( outputSelector, Fields.asDeclaration( incomingFields ), declaredFields ); } catch( TupleException exception ) { throw new OperatorException( this, incomingFields, declaredFields, outputSelector, exception ); } }
protected Fields resolveRemainderFields( Set<Scope> incomingScopes, Fields argumentFields ) { Fields fields = resolveIncomingOperationArgumentFields( getFirst( incomingScopes ) ); if( fields.isUnknown() ) return fields; return fields.subtract( argumentFields ); }
if( operator.getOutputSelector().isResults() ) return new TupleBuilder() if( operator.getOutputSelector().isAll() && !( incomingFields.isUnknown() || declaredFields.isUnknown() ) ) return new TupleBuilder() if( operator.getOutputSelector().isReplace() ) Fields resultFields = operator.getFieldDeclaration().isArguments() ? argumentSelector : declaredFields; Fields resultFields = operator.getFieldDeclaration().isArguments() ? argumentSelector : declaredFields; Tuple result = createOverride( inputDeclarationFields, resultFields ); if( operator.getOutputSelector().isSwap() ) Fields inputFields = operator.getFieldDeclaration().isArguments() ? Fields.mask( inputDeclarationFields, declaredFields ) : inputDeclarationFields; Tuple appended = createComposite( inputFields, declaredFields ); Fields allFields = Fields.resolve( Fields.ALL, inputFields, declaredFields );
void verifyDeclaredFields( Fields declared ) { if( declared.isDefined() && declared.size() == 0 ) throw new OperatorException( this, "field declaration: " + getFieldDeclaration().printVerbose() + ", resolves to an empty field set, current grouping is on all fields" ); }
void verifyOutputSelector( Fields outputSelector ) { if( outputSelector.isDefined() && outputSelector.size() == 0 ) throw new OperatorException( this, "output selector: " + getOutputSelector().printVerbose() + ", resolves to an empty field set, current grouping is on all fields" ); }
private static int hash( FlowElement flowElement ) { int lhs = flowElement.getClass().getName().hashCode(); int rhs = 0; if( flowElement instanceof Operator && ( (Operator) flowElement ).getOperation() != null ) rhs = ( (Operator) flowElement ).getOperation().getClass().getName().hashCode(); else if( flowElement instanceof Tap && ( (Tap) flowElement ).getScheme() != null ) rhs = ( (Tap) flowElement ).getScheme().getClass().getName().hashCode(); else if( flowElement instanceof Splice ) rhs = ( (Splice) flowElement ).getJoiner().getClass().getName().hashCode() + 31 * ( (Splice) flowElement ).getNumSelfJoins(); return pair( lhs, rhs ); }
protected Operator( Pipe previous, Fields argumentSelector, Operation operation ) { super( previous ); this.operation = operation; this.argumentSelector = argumentSelector; verifyOperation(); }
public Collection<Operation> getAllOperations() { Set<FlowElement> vertices = getElementGraph().vertexSet(); List<Operation> operations = new ArrayList<Operation>(); // operations impl equals, so two instance may be the same for( FlowElement vertex : vertices ) { if( vertex instanceof Operator ) operations.add( ( (Operator) vertex ).getOperation() ); } return operations; }
protected Operator( Pipe previous, Operation operation, Fields outputSelector ) { super( previous ); this.operation = operation; this.outputSelector = outputSelector; verifyOperation(); }
@Override public boolean applies( PlannerContext flowPlanner, ElementGraph elementGraph, FlowElement flowElement ) { boolean applies = super.applies( flowPlanner, elementGraph, flowElement ); return applies && !( (Operator) flowElement ).getOperation().isSafe(); } }
protected Operator( String name, PlannerLevel plannerLevel, PlannedOperation operation, Fields outputSelector ) { super( name ); this.plannerLevel = plannerLevel; this.operation = operation; this.outputSelector = outputSelector; verifyOperation(); }
private void verifyAllOperationsAreSerializable(ElementGraph elementGraph) { for (FlowElement flowElement : elementGraph.vertexSet()) { if (flowElement instanceof Operator) { Operator operator = (Operator) flowElement; verifySingleOperationIsSerializable(operator.getOperation()); } } }
protected Operator( Pipe previous, PlannerLevel plannerLevel, PlannedOperation operation, Fields outputSelector ) { super( previous ); this.plannerLevel = plannerLevel; this.operation = operation; this.outputSelector = outputSelector; verifyOperation(); }
@Override public void complete( Duct previous ) { try { ( (Operator) getFlowElement() ).getOperation().flush( flowProcess, operationCall ); } finally { super.complete( previous ); } }
protected Operator( String name, Operation operation, Fields outputSelector ) { super( name ); this.operation = operation; this.outputSelector = outputSelector; verifyOperation(); }