@SuppressWarnings("unchecked") @Override public Result write(SinkCall<Object[], ?> sinkCall, Generator generator) { Tuple tuple = CascadingUtils.coerceToString(sinkCall); // consider names (in case of aliases these are already applied) List<String> names = (List<String>) sinkCall.getContext()[SINK_CTX_ALIASES]; generator.writeBeginObject(); for (int i = 0; i < tuple.size(); i++) { String name = (i < names.size() ? names.get(i) : "tuple" + i); // filter out fields if (shouldKeep(generator.getParentPath(), name)) { generator.writeFieldName(name); Object object = tuple.getObject(i); Result result = jdkWriter.write(object, generator); if (!result.isSuccesful()) { if (object instanceof Writable) { return writableWriter.write((Writable) object, generator); } return Result.FAILED(object); } } } generator.writeEndObject(); return Result.SUCCESFUL(); }
@Override public void sinkPrepare( FlowProcess<? extends Configuration> flowProcess, SinkCall<Object[], OutputCollector> sinkCall ) throws IOException { sinkCall.setContext( new Object[ 2 ] ); sinkCall.getContext()[ 0 ] = new Text(); sinkCall.getContext()[ 1 ] = Charset.forName( charsetName ); }
@Override public void sinkPrepare( FlowProcess<? extends Configuration> flowProcess, SinkCall<Object[], OutputCollector> sinkCall ) throws IOException { sinkCall.setContext( new Object[ 2 ] ); sinkCall.getContext()[ 0 ] = new Text(); sinkCall.getContext()[ 1 ] = Charset.forName( charsetName ); }
@Override public void sinkPrepare( FlowProcess<? extends Configuration> flowProcess, SinkCall<Object[], OutputCollector> sinkCall ) throws IOException { sinkCall.setContext( new Object[ 3 ] ); sinkCall.getContext()[ 0 ] = new Text(); sinkCall.getContext()[ 1 ] = new StringBuilder( 4 * 1024 ); sinkCall.getContext()[ 2 ] = Charset.forName( charsetName ); if( writeHeader ) writeHeader( sinkCall ); }
@Override public void sinkPrepare( FlowProcess<? extends Configuration> flowProcess, SinkCall<Object[], OutputCollector> sinkCall ) throws IOException { sinkCall.setContext( new Object[ 3 ] ); sinkCall.getContext()[ 0 ] = new Text(); sinkCall.getContext()[ 1 ] = new StringBuilder( 4 * 1024 ); sinkCall.getContext()[ 2 ] = Charset.forName( charsetName ); if( writeHeader ) writeHeader( sinkCall ); }
@Override public void sinkCleanup( FlowProcess<? extends Properties> flowProcess, SinkCall<PrintWriter, OutputStream> sinkCall ) throws IOException { sinkCall.getContext().flush(); sinkCall.setContext( null ); }
@Override public void sinkCleanup( FlowProcess<? extends Properties> flowProcess, SinkCall<PrintWriter, OutputStream> sinkCall ) { sinkCall.getContext().flush(); sinkCall.setContext( null ); }
@Override public void sinkCleanup(FlowProcess<Properties> flowProcess, SinkCall<SolrCollector, OutputStream> sinkCall) throws IOException { SolrCollector collector = sinkCall.getContext(); collector.cleanup(); }
protected void writeHeader( SinkCall<Object[], OutputCollector> sinkCall ) throws IOException { Fields fields = sinkCall.getOutgoingEntry().getFields(); Text text = (Text) sinkCall.getContext()[ 0 ]; StringBuilder line = (StringBuilder) sinkCall.getContext()[ 1 ]; Charset charset = (Charset) sinkCall.getContext()[ 2 ]; line = (StringBuilder) delimitedParser.joinFirstLine( fields, line ); text.set( line.toString().getBytes( charset ) ); sinkCall.getOutput().collect( null, text ); line.setLength( 0 ); }
@Override public void sink( FlowProcess<? extends Properties> flowProcess, SinkCall<PrintWriter, OutputStream> sinkCall ) throws IOException { TupleEntry tupleEntry = sinkCall.getOutgoingEntry(); Iterable<String> strings = tupleEntry.asIterableOf( String.class ); delimitedParser.joinLine( strings, sinkCall.getContext() ); sinkCall.getContext().println(); }
protected void writeHeader( SinkCall<Object[], OutputCollector> sinkCall ) throws IOException { Fields fields = sinkCall.getOutgoingEntry().getFields(); Text text = (Text) sinkCall.getContext()[ 0 ]; StringBuilder line = (StringBuilder) sinkCall.getContext()[ 1 ]; Charset charset = (Charset) sinkCall.getContext()[ 2 ]; line = (StringBuilder) delimitedParser.joinFirstLine( fields, line ); text.set( line.toString().getBytes( charset ) ); sinkCall.getOutput().collect( null, text ); line.setLength( 0 ); }
@Override public void sink( FlowProcess<? extends Properties> flowProcess, SinkCall<PrintWriter, OutputStream> sinkCall ) throws IOException { JsonNode jsonNode = (JsonNode) sinkCall.getOutgoingEntry().getTuple().getObject( 0 ); if( jsonNode == null ) { sinkCall.getContext().println(); } else { String string = mapper.writeValueAsString( jsonNode ); sinkCall.getContext().println( string ); } }
@Override public void sink( FlowProcess<? extends Configuration> flowProcess, SinkCall<Object[], OutputCollector> sinkCall ) throws IOException { TupleEntry tupleEntry = sinkCall.getOutgoingEntry(); Text text = (Text) sinkCall.getContext()[ 0 ]; StringBuilder line = (StringBuilder) sinkCall.getContext()[ 1 ]; Charset charset = (Charset) sinkCall.getContext()[ 2 ]; Iterable<String> strings = tupleEntry.asIterableOf( String.class ); line = (StringBuilder) delimitedParser.joinLine( strings, line ); text.set( line.toString().getBytes( charset ) ); sinkCall.getOutput().collect( null, text ); line.setLength( 0 ); }
@Override public void sink( FlowProcess<? extends Configuration> flowProcess, SinkCall<Object[], OutputCollector> sinkCall ) throws IOException { TupleEntry tupleEntry = sinkCall.getOutgoingEntry(); Text text = (Text) sinkCall.getContext()[ 0 ]; StringBuilder line = (StringBuilder) sinkCall.getContext()[ 1 ]; Charset charset = (Charset) sinkCall.getContext()[ 2 ]; Iterable<String> strings = tupleEntry.asIterableOf( String.class ); line = (StringBuilder) delimitedParser.joinLine( strings, line ); text.set( line.toString().getBytes( charset ) ); sinkCall.getOutput().collect( null, text ); line.setLength( 0 ); }
@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 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 sink( FlowProcess<? extends Properties> flowProcess, SinkCall<PrintWriter, OutputStream> sinkCall ) throws IOException { sinkCall.getContext().println( sinkCall.getOutgoingEntry().getTuple().toString() ); }
@Override public void sinkPrepare( FlowProcess<? extends Properties> flowProcess, SinkCall<PrintWriter, OutputStream> sinkCall ) { OutputStream originalOutput = sinkCall.getOutput(); sinkCall.setContext( createOutput( originalOutput ) ); if( writeHeader && !isAppendingFile( sinkCall, originalOutput ) ) { Fields fields = sinkCall.getOutgoingEntry().getFields(); delimitedParser.joinFirstLine( fields, sinkCall.getContext() ); sinkCall.getContext().println(); } }
@Override public void sink(FlowProcess<JobConf> flowProcess, SinkCall<T, OutputCollector> sinkCall) throws IOException { OutputCollector collector = sinkCall.getOutput(); TupleEntry entry = sinkCall.getOutgoingEntry(); T writable = sinkCall.getContext(); writable.set((M) entry.getTuple().getObject(0)); collector.collect(null, writable); }
@Override public void sink(FlowProcess<? extends Configuration> flowProcess, SinkCall<T, OutputCollector> sinkCall) throws IOException { OutputCollector collector = sinkCall.getOutput(); TupleEntry entry = sinkCall.getOutgoingEntry(); T writable = sinkCall.getContext(); writable.set((M) entry.getTuple().getObject(0)); collector.collect(null, writable); }