static Tuple coerceToString(SinkCall<?, ?> sinkCall) { return sinkCall.getOutgoingEntry().getTuple(); } }
protected void collect( TupleEntry tupleEntry ) { if( copyTupleOnCollect ) tuples.add( tupleEntry.getTupleCopy() ); else tuples.add( tupleEntry.getTuple() ); }
List<Object> elements = Tuple.elements(entry.getTuple()); elements.clear(); elements.addAll(data.values());
@Override public void convert(Object from, BytesArray to) { // expect a tuple holding one field - chararray or bytearray Assert.isTrue(from instanceof SinkCall, String.format("Unexpected object type, expecting [%s], given [%s]", SinkCall.class, from.getClass())); // handle common cases SinkCall sinkCall = (SinkCall) from; Tuple rawTuple = sinkCall.getOutgoingEntry().getTuple(); if (rawTuple == null || rawTuple.isEmpty()) { to.bytes("{}"); return; } Assert.isTrue(rawTuple.size() == 1, "When using JSON input, only one field is expected"); // postpone the coercion Tuple tuple = CascadingUtils.coerceToString(sinkCall); super.convert(tuple.getObject(0), to); } }
List<Object> elements = Tuple.elements(entry.getTuple()); elements.clear(); elements.addAll(data.values());
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; } }
@Override public boolean isRemove( FlowProcess flowProcess, FilterCall filterCall ) { for( Object value : filterCall.getArguments().getTuple() ) { if( value != null ) return true; } return false; } }
@Override public Tuple next() { Tuple tuple = childIterator.next().getTuple(); TupleViews.reset( view, base, tuple ); return view; }
public TupleEntry next() { argumentsEntry.setTuple( argumentsBuilder.makeResult( grouping.joinIterator.next().getTuple(), null ) ); return argumentsEntry; }
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(); } }
@Override public void sink( FlowProcess<? extends Configuration> flowProcess, SinkCall<Object[], OutputCollector> sinkCall ) throws IOException { Text text = (Text) sinkCall.getContext()[ 0 ]; Charset charset = (Charset) sinkCall.getContext()[ 1 ]; String line = sinkCall.getOutgoingEntry().getTuple().toString(); text.set( line.getBytes( charset ) ); // it's ok to use NULL here so the collector does not write anything sinkCall.getOutput().collect( null, text ); }
@Override public void doAssert( FlowProcess flowProcess, ValueAssertionCall assertionCall ) { TupleEntry input = assertionCall.getArguments(); if( input.size() != size ) fail( input.size(), size, input.getTuple().print() ); }
@Override public void doAssert( FlowProcess flowProcess, ValueAssertionCall assertionCall ) { TupleEntry input = assertionCall.getArguments(); if( input.size() <= size ) fail( input.size(), size, input.getTuple().print() ); }
public void aggregate( FlowProcess flowProcess, AggregatorCall aggregatorCall ) { if( !aggregatorCall.getGroup().isUnmodifiable() ) throw new IllegalStateException( "is modifiable" ); if( !aggregatorCall.getGroup().getTuple().isUnmodifiable() ) throw new IllegalStateException( "is modifiable" ); if( !aggregatorCall.getArguments().isUnmodifiable() ) throw new IllegalStateException( "is modifiable" ); if( !aggregatorCall.getArguments().getTuple().isUnmodifiable() ) throw new IllegalStateException( "is modifiable" ); }
@Override public void operate( FlowProcess flowProcess, FunctionCall<Tuple> functionCall ) { functionCall.getContext().set( 0, functionCall.getArguments().getTuple().toString( delimiter, false ) ); functionCall.getOutputCollector().add( functionCall.getContext() ); }
public void operate( FlowProcess flowProcess, FunctionCall functionCall ) { if( !functionCall.getArguments().isUnmodifiable() ) throw new IllegalStateException( "is modifiable" ); if( !functionCall.getArguments().getTuple().isUnmodifiable() ) throw new IllegalStateException( "is modifiable" ); Tuple result = new Tuple( functionCall.getArguments().getTuple() ); functionCall.getOutputCollector().add( result ); if( result.isUnmodifiable() ) throw new IllegalStateException( "is unmodifiable" ); } }
@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() ); } }
@Test public void testSetNull() { TupleEntry entryA = new TupleEntry( new Fields( "a", "b", "c" ), new Tuple( "a", "b", "c" ) ); entryA.setTuple( null ); assertTrue( entryA.getTuple() == null ); }