/** * Method add adds a new element value to this instance. * * @param value of type Comparable */ public void add( Comparable value ) { add( (Object) value ); }
/** * Creates a new Tuple from the given positions, but sets the values in the current tuple to null. * * @param pos of type int[] * @return Tuple */ Tuple extract( int[] pos ) { Tuple results = new Tuple(); for( int i : pos ) results.add( elements.set( i, null ) ); return results; }
public void readFields( ResultSet resultSet ) throws SQLException { tuple = new Tuple(); for( int i = 0; i < resultSet.getMetaData().getColumnCount(); i++ ) tuple.add( resultSet.getObject( i + 1 ) ); }
@Override public Tuple toTuple(Number[] values) { Tuple tuple = new Tuple(); for (Number value : values) { tuple.add(value); } return tuple; }
/** * Method size returns a new Tuple instance of the given size with the given Comparable as its element values. * * @param size of type int * @param value of type Comparable * @return Tuple */ public static Tuple size( int size, Comparable value ) { Tuple result = new Tuple( new ArrayList<Object>( size ) ); for( int i = 0; i < size; i++ ) result.add( value ); return result; }
private TupleEntry getDiagnostics( Throwable throwable ) { if( !recordAnyDiagnostics ) return TupleEntry.NULL; Tuple diagnostics = new Tuple(); if( recordElementTrace ) diagnostics.add( elementTrace ); if( recordThrowableMessage ) diagnostics.add( throwable.getMessage() ); if( recordThrowableStackTrace ) diagnostics.add( TraceUtil.stringifyStackTrace( throwable, stackTraceLineDelimiter, stackTraceTrimLine, -1 ) ); diagnosticEntry.setTuple( diagnostics ); return diagnosticEntry; }
/** * Method get will return a new Tuple instance populated with element values from the given array of positions. * * @param pos of type int[] * @return Tuple */ public Tuple get( int[] pos ) { if( pos == null || pos.length == 0 ) return new Tuple( this ); Tuple results = new Tuple(); for( int i : pos ) results.add( elements.get( i ) ); return results; }
protected void performOperation( Tuple[] context, TupleEntry entry ) { if( context[ 0 ] == null ) context[ 0 ] = new Tuple(); if( context[ 0 ].size() < firstN ) context[ 0 ].add( entry.getTupleCopy() ); }
public class SampleFunction extends BaseOperation implements Function { public void operate( FlowProcess flowProcess, FunctionCall functionCall ) { TupleEntry argument = functionCall.getArguments(); String regex = argument.getString( 0 ); String argument = argument.getString( 1 ); String parsed = someRegexOperation(); Tuple result = new Tuple(); result.add( parsed ); functionCall.getOutputCollector().add( result ); } }
@Override public boolean source(FlowProcess<JobConf> flowProcess, SourceCall<Object[], RecordReader> sourceCall) throws IOException { BytesWritable key = (BytesWritable) sourceCall.getContext()[0]; BytesWritable value = (BytesWritable) sourceCall.getContext()[1]; boolean result = sourceCall.getInput().next(key, value); if (!result) { return false; } Tuple tuple = sourceCall.getIncomingEntry().getTuple(); tuple.clear(); tuple.add(getBytes(key)); tuple.add(getBytes(value)); return true; }
static Tuple parse( String string ) { if( string == null || string.length() == 0 ) return null; string = string.replaceAll( "^ *\\[*", "" ); string = string.replaceAll( "\\]* *$", "" ); Scanner scanner = new Scanner( new StringReader( string ) ); scanner.useDelimiter( "(' *, *')|(^ *')|(' *$)" ); Tuple result = new Tuple(); while( scanner.hasNext() ) { if( scanner.hasNextInt() ) result.add( scanner.nextInt() ); else if( scanner.hasNextDouble() ) result.add( scanner.nextDouble() ); else result.add( scanner.next() ); } scanner.close(); return result; }
@Override public boolean source(FlowProcess<JobConf> flowProcess, SourceCall<Object[], RecordReader> sourceCall) throws IOException { BytesWritable key = (BytesWritable) sourceCall.getContext()[0]; BytesWritable value = (BytesWritable) sourceCall.getContext()[1]; boolean result = sourceCall.getInput().next(key, value); if (!result) { return false; } Tuple tuple = sourceCall.getIncomingEntry().getTuple(); tuple.clear(); tuple.add(getBytes(key)); tuple.add(getBytes(value)); return true; }
@Override public void operate(FlowProcess flowProcess, FunctionCall funCall) { TupleEntry args = funCall.getArguments(); String keyword = args.getString(0); List<String> urls = parseSearchResult(keyword); for (String url : urls) { Tuple t = new Tuple(); t.add(url); funCall.getOutputCollector().add(t); } }
@Override public void operate(FlowProcess flowProcess, FunctionCall funCall) { TupleEntry args = funCall.getArguments(); String url = args.getString(1); String rawText = download(url); String plainText = parse(rawText); List<String> keywords = extractKeywords(plainText); for (String keyword : keywords) { Tuple t = new Tuple(); t.add(keyword); funCall.getOutputCollector().add(t); } }
@Test public void testCompare() { Fields fields = new Fields( "a" ); fields.setComparator( "a", comparator ); Tuple aTuple = new Tuple( "a" ); Tuple bTuple = new Tuple( "b" ); assertTrue( "not less than: aTuple < bTuple", fields.compare( aTuple, bTuple ) < 0 ); assertTrue( "not less than: bTuple < aTuple", fields.compare( bTuple, aTuple ) > 0 ); aTuple.add( "b" ); assertTrue( "not greater than: aTuple > bTuple", fields.compare( aTuple, bTuple ) > 0 ); aTuple = new Tuple( bTuple, "a" ); assertTrue( "not greater than: aTuple > bTuple", fields.compare( aTuple, bTuple ) > 0 ); }
@Test public void testCompare2() { Fields fields = new Fields( "a" ); fields.setComparators( new Comparator[]{comparator} ); Tuple aTuple = new Tuple( "a" ); Tuple bTuple = new Tuple( "b" ); assertTrue( "not less than: aTuple < bTuple", fields.compare( aTuple, bTuple ) < 0 ); assertTrue( "not less than: bTuple < aTuple", fields.compare( bTuple, aTuple ) > 0 ); aTuple.add( "b" ); assertTrue( "not greater than: aTuple > bTuple", fields.compare( aTuple, bTuple ) > 0 ); aTuple = new Tuple( bTuple, "a" ); assertTrue( "not greater than: aTuple > bTuple", fields.compare( aTuple, bTuple ) > 0 ); } }
@Test public void testCompare() { Tuple aTuple = new Tuple( "a" ); Tuple bTuple = new Tuple( "b" ); assertTrue( "not less than: aTuple < bTuple", aTuple.compareTo( bTuple ) < 0 ); assertTrue( "not less than: bTuple < aTuple", bTuple.compareTo( aTuple ) > 0 ); aTuple.add( "b" ); assertTrue( "not greater than: aTuple > bTuple", aTuple.compareTo( bTuple ) > 0 ); aTuple = new Tuple( bTuple, "a" ); assertTrue( "not greater than: aTuple > bTuple", aTuple.compareTo( bTuple ) > 0 ); bTuple = new Tuple( bTuple, "b" ); assertTrue( "not less than: aTuple < bTuple", aTuple.compareTo( bTuple ) < 0 ); }