static void setObject(TupleEntry entry, Comparable<?> field, Object object) { if (object != null && entry.getFields().getType(field) instanceof CoercibleType) { entry.setObject(field, object.toString()); } else { entry.setObject(field, object); } }
static Tuple coerceToString(SinkCall<?, ?> sinkCall) { TupleEntry entry = sinkCall.getOutgoingEntry(); Fields fields = entry.getFields(); Tuple tuple = entry.getTuple(); if (fields.hasTypes()) { Type types[] = new Type[fields.size()]; for (int index = 0; index < fields.size(); index++) { Type type = fields.getType(index); if (type instanceof CoercibleType<?>) { types[index] = String.class; } else { types[index] = type; } } tuple = entry.getCoercedTuple(types); } return tuple; } }
/** * Method extract creates a new Tuple from the given selector, but sets the values in the current tuple to null. * * @param tupleEntry of type TupleEntry * @param selector of type Fields * @return Tuple */ public static Tuple extract( TupleEntry tupleEntry, Fields selector ) { return tupleEntry.tuple.extract( tupleEntry.getFields().getPos( selector, tupleEntry.getFields().size() ) ); }
private String print( TupleEntry tupleEntry ) { if( tupleEntry == null || tupleEntry.getFields() == null ) return "[uninitialized]"; else if( tupleEntry.getTuple() == null ) return "fields: " + tupleEntry.getFields().printVerbose(); else return "fields: " + tupleEntry.getFields().printVerbose() + " tuple: " + tupleEntry.getTuple().print(); } }
/** * Method set sets the values from the given tupleEntry into this TupleEntry instance based on the given * tupleEntry field names. * <p> * If type information is given, each incoming value will be coerced from its canonical type to the current type. * * @param tupleEntry of type TupleEntry */ public void set( TupleEntry tupleEntry ) { this.tuple.set( fields, tupleEntry.getFields(), tupleEntry.getTuple(), tupleEntry.coercions ); }
/** * Method entryIterator return a TupleEntry iterator for this collection. * <p> * Note the same TupleEntry will be returned on each next() call. * * @return Iterator */ public Iterator<TupleEntry> entryIterator() { return new TupleEntryChainIterator( tupleEntry.getFields(), tuples.iterator() ); } }
@SuppressWarnings("unchecked") @Override public void sink(FlowProcess<? extends JobConf> fp, SinkCall<Object[], OutputCollector> sc) throws IOException { TupleEntry tuple = sc.getOutgoingEntry(); if (tuple.size() != 1) { throw new RuntimeException("ParquetValueScheme expects tuples with an arity of exactly 1, but found " + tuple.getFields()); } T value = (T) tuple.getObject(0); OutputCollector output = sc.getOutput(); output.collect(null, value); }
private ConcreteCall getOperationCall( TupleEntry tupleEntry ) { ConcreteCall operationCall = new ConcreteCall( tupleEntry.getFields() ); operationCall.setArguments( tupleEntry ); return operationCall; }
@Override public void sink( FlowProcess<? extends Configuration> flowProcess, SinkCall<Object[], OutputCollector> sinkCall ) throws IOException { Fields found = sinkCall.getOutgoingEntry().getFields(); if( !found.equals( expectedFields ) ) throw new RuntimeException( "fields to not match, expect: " + expectedFields + ", found: " + found ); super.sink( flowProcess, sinkCall ); } }
@Override public void sink( FlowProcess<? extends Configuration> flowProcess, SinkCall<Object[], OutputCollector> sinkCall ) throws IOException { Fields found = sinkCall.getOutgoingEntry().getFields(); if( !found.equals( expectedFields ) ) throw new RuntimeException( "fields to not match, expect: " + expectedFields + ", found: " + found ); super.sink( flowProcess, sinkCall ); } }
@Override public void sinkPrepare( FlowProcess<? extends Configuration> flowProcess, SinkCall<Object[], OutputCollector> sinkCall ) throws IOException { Fields found = sinkCall.getOutgoingEntry().getFields(); if( !found.equals( expectedFields ) ) throw new RuntimeException( "fields to not match, expect: " + expectedFields + ", found: " + found ); super.sinkPrepare( flowProcess, sinkCall ); }
public TupleEntry allocateTuple(Fields subSetOfFields, Object... values) { if (resuableEntry == null) { resuableEntry = new TupleEntry(allFields, Tuple.size(allFields.size())); } for (Comparable field : resuableEntry.getFields()) { resuableEntry.setObject(field, null); } for (int i = 0; i < subSetOfFields.size(); i++) { resuableEntry.setObject(subSetOfFields.get(i), values[i]); } return resuableEntry; }
@Override public void doAssert( FlowProcess flowProcess, ValueAssertionCall<Matcher> assertionCall ) { TupleEntry input = assertionCall.getArguments(); int pos = matchEachElementPos( assertionCall.getContext(), input ); if( pos != -1 ) BaseAssertion.throwFail( message, input.getFields().get( pos ), input.getObject( pos ), patternString, input.getTuple().print() ); } }
public void operate( FlowProcess flowProcess, FunctionCall functionCall ) { Set<Tuple> set = new TreeSet<Tuple>(); TupleEntry input = functionCall.getArguments(); for( Fields field : fields ) set.add( input.selectTuple( field ) ); int i = 0; Tuple inputCopy = new Tuple( input.getTuple() ); for( Tuple tuple : set ) inputCopy.put( input.getFields(), fields[ i++ ], tuple ); functionCall.getOutputCollector().add( inputCopy ); }
/** @see Filter#isRemove(cascading.flow.FlowProcess, FilterCall) */ public boolean isRemove( FlowProcess flowProcess, FilterCall<Long> filterCall ) { PrintStream stream = output == Output.STDOUT ? System.out : System.err; if( printFields && filterCall.getContext() % printFieldsEvery == 0 ) print( stream, filterCall.getArguments().getFields().print() ); if( filterCall.getContext() % printTupleEvery == 0 ) print( stream, filterCall.getArguments().getTuple().print() ); filterCall.setContext( filterCall.getContext() + 1 ); return false; }
public static boolean invokeFilter( Filter filter, TupleEntry arguments, Map<Object, Object> properties ) { FlowProcess flowProcess = new TestFlowProcess( properties ); ConcreteCall operationCall = new ConcreteCall( arguments.getFields() ); operationCall.setArguments( arguments ); filter.prepare( flowProcess, operationCall ); boolean isRemove = filter.isRemove( flowProcess, operationCall ); filter.cleanup( flowProcess, operationCall ); return isRemove; }
private Object evaluate( String expression, Class returnType, String[] names, Class[] types, TupleEntry tupleEntry ) { ScriptFunction function = new ScriptFunction( new Fields( "result" ), expression, returnType, names, types ); ConcreteCall<ExpressionOperation.Context> call = new ConcreteCall<ExpressionOperation.Context>( tupleEntry.getFields(), function.getFieldDeclaration() ); function.prepare( FlowProcess.NULL, call ); return function.evaluate( call.getContext(), tupleEntry ); }