/** * Method fieldToInt returns a {@link Function} that returns the int in the given named field or position. * * @param name the field to select * @return the int value in the selected field */ public static ToIntFunction<TupleEntry> fieldToInt( Comparable name ) { Objects.requireNonNull( name ); return value -> value.getInteger( name ); }
/** * Method fieldToInt returns a {@link Function} that returns the int in the given named field or position. * * @param fields the field to select, only first field will be honored * @return the int value in the selected field */ public static ToIntFunction<TupleEntry> fieldToInt( Fields fields ) { Objects.requireNonNull( fields ); return value -> value.getInteger( fields ); }
@Override public boolean isRemove(FlowProcess flowProcess, FilterCall filterCall) { return !id.equals(filterCall.getArguments().getInteger(0)); } }
protected boolean shouldUseThisCombiner(CombinerAggregatorContext context, AggregatorCall<CombinerAggregatorContext> aggregatorCall) { return context.getDefinition().getId() == aggregatorCall.getGroup().getInteger(MultiCombiner.ID_FIELD); }
public void operate(FlowProcess process, BufferCall call) { Iterator<TupleEntry> it = call.getArgumentsIterator(); int bounces = 0; int visits = 0; Integer lastTime = null; int numInCurrVisit = 0; while(it.hasNext()) { TupleEntry tuple = it.next(); int timeSecs = tuple.getInteger(0); if(lastTime == null || (timeSecs - lastTime) > VISIT_LENGTH_SECS) { visits++; if(numInCurrVisit == 1) { bounces++; } numInCurrVisit = 0; } numInCurrVisit++; } if(numInCurrVisit==1) { bounces++; } call.getOutputCollector().add(new Tuple(visits, bounces)); } }
public void operate(FlowProcess process, FunctionCall call) { int timestamp = call.getArguments().getInteger(0); int hourBucket = timestamp / HOUR_SECS; call.getOutputCollector().add(new Tuple(hourBucket)); } }
@Override public void sink(FlowProcess<JobConf> jobConfFlowProcess, SinkCall<Void, OutputCollector> sinkCall) throws IOException { TupleEntry tupleEntry = sinkCall.getOutgoingEntry(); IntWritable partition = new IntWritable(tupleEntry.getInteger(partitionFieldName)); BytesWritable key = (BytesWritable) tupleEntry.getObject(keyFieldName); BytesWritable value = (BytesWritable) tupleEntry.getObject(valueFieldName); KeyAndPartitionWritable keyAndPartitionWritable = new KeyAndPartitionWritable(key, partition); ValueWritable valueWritable = new ValueWritable(value); sinkCall.getOutput().collect(keyAndPartitionWritable, valueWritable); } }
public void operate(FlowProcess process, FunctionCall call) { String url = call.getArguments().getString(0); String gran = call.getArguments().getString(1); Integer bucket = call.getArguments().getInteger(2); String keyStr = url + "/" + gran + "-" + bucket; try { call.getOutputCollector().add( new Tuple(keyStr.getBytes("UTF-8"))); } catch(UnsupportedEncodingException e) { throw new RuntimeException(e); } } }
@Test(expected = TupleException.class) public void testCoerceCanonicalUnknownFail() { Tuple tuple = new Tuple( 1 ); TupleEntry results = new TupleEntry( Fields.UNKNOWN, tuple ); assertEquals( 1, results.getInteger( 1 ) ); }
private void writePrimitive(TupleEntry record, PrimitiveType field) { switch (field.getPrimitiveTypeName()) { case BINARY: recordConsumer.addBinary(Binary.fromString(record.getString(field.getName()))); break; case BOOLEAN: recordConsumer.addBoolean(record.getBoolean(field.getName())); break; case INT32: recordConsumer.addInteger(record.getInteger(field.getName())); break; case INT64: recordConsumer.addLong(record.getLong(field.getName())); break; case DOUBLE: recordConsumer.addDouble(record.getDouble(field.getName())); break; case FLOAT: recordConsumer.addFloat(record.getFloat(field.getName())); break; case FIXED_LEN_BYTE_ARRAY: throw new UnsupportedOperationException("Fixed len byte array type not implemented"); case INT96: throw new UnsupportedOperationException("Int96 type not implemented"); default: throw new UnsupportedOperationException(field.getName() + " type not implemented"); } } }
private void writePrimitive(TupleEntry record, PrimitiveType field) { switch (field.getPrimitiveTypeName()) { case BINARY: recordConsumer.addBinary(Binary.fromString(record.getString(field.getName()))); break; case BOOLEAN: recordConsumer.addBoolean(record.getBoolean(field.getName())); break; case INT32: recordConsumer.addInteger(record.getInteger(field.getName())); break; case INT64: recordConsumer.addLong(record.getLong(field.getName())); break; case DOUBLE: recordConsumer.addDouble(record.getDouble(field.getName())); break; case FLOAT: recordConsumer.addFloat(record.getFloat(field.getName())); break; case FIXED_LEN_BYTE_ARRAY: throw new UnsupportedOperationException("Fixed len byte array type not implemented"); case INT96: throw new UnsupportedOperationException("Int96 type not implemented"); default: throw new UnsupportedOperationException(field.getName() + " type not implemented"); } } }
private void writePrimitive(TupleEntry record, PrimitiveType field) { switch (field.getPrimitiveTypeName()) { case BINARY: recordConsumer.addBinary(Binary.fromString(record.getString(field.getName()))); break; case BOOLEAN: recordConsumer.addBoolean(record.getBoolean(field.getName())); break; case INT32: recordConsumer.addInteger(record.getInteger(field.getName())); break; case INT64: recordConsumer.addLong(record.getLong(field.getName())); break; case DOUBLE: recordConsumer.addDouble(record.getDouble(field.getName())); break; case FLOAT: recordConsumer.addFloat(record.getFloat(field.getName())); break; case FIXED_LEN_BYTE_ARRAY: throw new UnsupportedOperationException("Fixed len byte array type not implemented"); case INT96: throw new UnsupportedOperationException("Int96 type not implemented"); default: throw new UnsupportedOperationException(field.getName() + " type not implemented"); } } }
public void operate(FlowProcess process, FunctionCall call) { int hourBucket = call.getArguments().getInteger(0); int dayBucket = hourBucket / 24; int weekBucket = dayBucket / 7; int monthBucket = dayBucket / 28; call.getOutputCollector().add(new Tuple("h", hourBucket)); call.getOutputCollector().add(new Tuple("d", dayBucket)); call.getOutputCollector().add(new Tuple("w", weekBucket)); call.getOutputCollector().add(new Tuple("m", monthBucket)); } }
private void writePrimitive(TupleEntry record, PrimitiveType field) { switch (field.getPrimitiveTypeName()) { case BINARY: recordConsumer.addBinary(Binary.fromString(record.getString(field.getName()))); break; case BOOLEAN: recordConsumer.addBoolean(record.getBoolean(field.getName())); break; case INT32: recordConsumer.addInteger(record.getInteger(field.getName())); break; case INT64: recordConsumer.addLong(record.getLong(field.getName())); break; case DOUBLE: recordConsumer.addDouble(record.getDouble(field.getName())); break; case FLOAT: recordConsumer.addFloat(record.getFloat(field.getName())); break; case FIXED_LEN_BYTE_ARRAY: throw new UnsupportedOperationException("Fixed len byte array type not implemented"); case INT96: throw new UnsupportedOperationException("Int96 type not implemented"); default: throw new UnsupportedOperationException(field.getName() + " type not implemented"); } } }
@Override public void operate( FlowProcess flowProcess, FunctionCall functionCall ) { TupleEntry argument = functionCall.getArguments(); int num = argument.getInteger( 0 ); String chr = argument.getString( 1 ); Tuple result; if( num == number ) result = new Tuple( null, chr ); else result = new Tuple( num, chr ); functionCall.getOutputCollector().add( result ); } }
@Override public void operate( FlowProcess flowProcess, FunctionCall functionCall ) { TupleEntry argument = functionCall.getArguments(); int num = argument.getInteger( 0 ); String chr = argument.getString( 1 ); Tuple result; if( num == number ) result = new Tuple( null, chr ); else result = new Tuple( num, chr ); functionCall.getOutputCollector().add( result ); } }
assertEquals( (int) date.getTime(), results.getInteger( 4 ) ); assertEquals( Long.toString( date.getTime() ), results.getString( 4 ) );
@Test public void testCoerceCanonicalUnknown() { Tuple tuple = new Tuple( 1 ); TupleEntry results = new TupleEntry( Fields.UNKNOWN, tuple ); assertEquals( 1, results.getObject( 0 ) ); assertEquals( 1, results.getInteger( 0 ) ); assertEquals( 1, results.getShort( 0 ) ); assertEquals( 1L, results.getLong( 0 ) ); assertEquals( 1.0F, results.getFloat( 0 ) ); assertEquals( 1.0D, results.getDouble( 0 ) ); assertEquals( "1", results.getString( 0 ) ); }