protected void sourceHandleInput( SourceCall<Object[], RecordReader> sourceCall ) throws IOException { TupleEntry result = sourceCall.getIncomingEntry(); int index = 0; Object[] context = sourceCall.getContext(); // coerce into canonical forms if( getSourceFields().size() == 2 ) result.setLong( index++, ( (LongWritable) context[ 0 ] ).get() ); result.setString( index, makeEncodedString( context ) ); }
protected void sourceHandleInput( SourceCall<Object[], RecordReader> sourceCall ) throws IOException { TupleEntry result = sourceCall.getIncomingEntry(); int index = 0; Object[] context = sourceCall.getContext(); // coerce into canonical forms if( getSourceFields().size() == 2 ) result.setLong( index++, ( (LongWritable) context[ 0 ] ).get() ); result.setString( index, makeEncodedString( context ) ); }
@Override public void operate( FlowProcess flowProcess, FunctionCall<Pair<SimpleDateFormat, TupleEntry>> functionCall ) { TupleEntry output = functionCall.getContext().getRhs(); try { String value = functionCall.getArguments().getString( 0 ); if( value == null ) // if null, return null for the field { output.setObject( 0, null ); // safe to call set, tuple is size of 1 functionCall.getOutputCollector().add( output ); return; } Date date = functionCall.getContext().getLhs().parse( value ); if( calendarFields == null ) output.setLong( 0, date.getTime() ); // safe to call set, tuple is size of 1 else makeCalendarFields( output, date ); } catch( ParseException exception ) { throw new OperationException( "unable to parse input value: " + functionCall.getArguments().getObject( 0 ), exception ); } functionCall.getOutputCollector().add( output ); }
@Test public void testCoerceIterable() { final SimpleDateFormat dateFormat = new SimpleDateFormat( "dd/MMM/yyyy:HH:mm:ss:SSS Z" ); CoercibleType coercible = new DateType( "dd/MMM/yyyy:HH:mm:ss:SSS Z", TimeZone.getDefault() ); Date date = new Date(); String stringDate = dateFormat.format( date ); Tuple tuple = Tuple.size( 4 ); Fields fields = Fields.size( 4 ).applyTypes( coercible, coercible, coercible, String.class ); TupleEntry results = new TupleEntry( fields, tuple ); results.setObject( 0, date ); results.setLong( 1, date.getTime() ); results.setString( 2, stringDate ); results.setString( 3, stringDate ); Iterable<String> iterable = results.asIterableOf( String.class ); int count = 0; for( String s : iterable ) { assertEquals( stringDate, s ); count++; } assertEquals( count, results.size() ); }
results.setLong( 0, date.getTime() ); results.setString( 1, stringDate ); results.setObject( 2, date );