本文整理了Java中cascading.tuple.Tuple.size()
方法的一些代码示例,展示了Tuple.size()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Tuple.size()
方法的具体详情如下:
包路径:cascading.tuple.Tuple
类名称:Tuple
方法名:size
[英]Method size returns the number of values in this Tuple instance.
[中]方法size返回此元组实例中的值数。
代码示例来源:origin: elastic/elasticsearch-hadoop
@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);
}
}
代码示例来源:origin: elastic/elasticsearch-hadoop
@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();
}
代码示例来源:origin: cwensel/cascading
private boolean areNullsEqual()
{
try
{
Tuple tupleWithNull = Tuple.size( 1 );
return groupComparators[ 0 ].compare( tupleWithNull, tupleWithNull ) == 0;
}
catch( Exception exception )
{
return true; // assume we have an npe or something and they don't expect to see nulls
}
}
代码示例来源:origin: cwensel/cascading
Tuple nulledCopy( int[] pos )
{
if( pos == null )
return size( size() );
Tuple results = new Tuple( this );
for( int i : pos )
results.set( i, null );
return results;
}
代码示例来源:origin: cwensel/cascading
public static Tuple nulledCopy( Fields declarator, Tuple tuple, Fields selector )
{
// use tuple.size() in case declarator is UNKNOWN and selector has relative pos
return tuple.nulledCopy( declarator.getPos( selector, tuple.size() ) );
}
代码示例来源:origin: cwensel/cascading
static CoercibleType[] getCoercions( Fields fields, Tuple tuple )
{
Type[] types = fields.types; // safe to not get a copy
int size = fields.size();
size = size == 0 && tuple != null ? tuple.size() : size;
if( size == 0 )
return EMPTY_COERCIONS;
return Coercions.coercibleArray( size, types );
}
代码示例来源:origin: cwensel/cascading
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() );
}
代码示例来源:origin: cwensel/cascading
@Override
public void prepare( FlowProcess flowProcess, OperationCall<Context> operationCall )
{
operationCall.setContext( new Context( Tuple.size( 1 ), operationCall.getArgumentFields().subtract( Fields.FIRST ) ) );
}
代码示例来源:origin: cwensel/cascading
public CombineInputPartitionTupleEntryIterator( FlowProcess<? extends Configuration> flowProcess, Fields sourceFields,
Partition partition, String parentIdentifier, TupleEntrySchemeIterator childIterator )
{
this.flowProcess = flowProcess;
this.partition = partition;
this.parentIdentifier = parentIdentifier;
this.childIterator = childIterator;
this.sourceFields = sourceFields;
this.partitionEntry = new TupleEntry( partition.getPartitionFields(), Tuple.size( partition.getPartitionFields().size() ) );
}
代码示例来源:origin: cwensel/cascading
@Override
public void prepare( FlowProcess flowProcess, OperationCall<Pair<Matcher, TupleEntry>> operationCall )
{
int size;
if( groups != null )
size = groups.length;
else
size = operationCall.getDeclaredFields().size(); // if Fields.UNKNOWN size will be zero
// TupleEntry allows us to honor the declared field type information
TupleEntry entry = new TupleEntry( operationCall.getDeclaredFields(), Tuple.size( size ) );
operationCall.setContext( new Pair<>( getPattern().matcher( "" ), entry ) );
}
代码示例来源:origin: cwensel/cascading
public static Tuple setOnEmpty( TupleEntry baseEntry, TupleEntry valuesEntry )
{
Tuple emptyTuple = Tuple.size( baseEntry.getFields().size() );
emptyTuple.set( baseEntry.getFields(), valuesEntry.getFields(), valuesEntry.getTuple() );
return emptyTuple;
}
代码示例来源:origin: cwensel/cascading
@Override
public Tuple aggregate( FlowProcess flowProcess, TupleEntry args, Tuple context )
{
if( context == null )
context = Tuple.size( 2 );
if( include == Include.NO_NULLS && args.getObject( 0 ) == null )
return context;
context.set( 0, context.getDouble( 0 ) + args.getDouble( 0 ) );
context.set( 1, context.getLong( 1 ) + 1 );
return context;
}
代码示例来源:origin: cwensel/cascading
@Override
public void prepare( FlowProcess flowProcess, OperationCall<Pair<Pattern, TupleEntry>> operationCall )
{
length = operationCall.getDeclaredFields().isUnknown() ? -1 : operationCall.getDeclaredFields().size();
TupleEntry tupleEntry = new TupleEntry( operationCall.getDeclaredFields(), Tuple.size( Math.max( 1, length ) ) );
operationCall.setContext( new Pair<>( getPattern(), tupleEntry ) );
}
代码示例来源:origin: cwensel/cascading
@Override
public void prepare( FlowProcess flowProcess, OperationCall<Pair<SimpleDateFormat, TupleEntry>> operationCall )
{
operationCall.setContext( new Pair<>( getDateFormat(), new TupleEntry( operationCall.getDeclaredFields(), Tuple.size( getDeclaredSize() ) ) ) );
}
代码示例来源:origin: cwensel/cascading
@Test
public void testLeave()
{
Tuple aTuple = tuple.leave( new int[]{0} );
assertEquals( "not equal: tuple.size()", 1, tuple.size() );
assertEquals( "not equal: tuple.get( 0 )", "a", tuple.getObject( 0 ) );
assertEquals( "not equal: aTuple.size()", 4, aTuple.size() );
assertEquals( "not equal: aTuple.get( 0 )", "b", aTuple.getObject( 0 ) );
assertEquals( "not equal: tuple.get( 1 )", "c", aTuple.getObject( 1 ) );
}
代码示例来源:origin: cwensel/cascading
@Test
public void testGet()
{
Tuple aTuple = tuple.get( new int[]{0} );
assertEquals( "not equal: aTuple.size()", 1, aTuple.size() );
assertEquals( "not equal: aTuple.get( 0 )", "a", aTuple.getObject( 0 ) );
assertEquals( "not equal: tuple.size()", 5, tuple.size() );
assertEquals( "not equal: tuple.get( 0 )", "a", tuple.getObject( 0 ) );
assertEquals( "not equal: tuple.get( 1 )", "b", tuple.getObject( 1 ) );
}
代码示例来源:origin: cwensel/cascading
@Test
public void testGetNull()
{
Tuple aTuple = tuple.get( (int[]) null );
assertEquals( "not equal: aTuple.size()", 5, aTuple.size() );
assertEquals( "not equal: aTuple.get( 0 )", "a", aTuple.getObject( 0 ) );
assertEquals( "not equal: aTuple.get( 1 )", "b", aTuple.getObject( 1 ) );
assertEquals( "not equal: tuple.size()", 5, tuple.size() );
assertEquals( "not equal: tuple.get( 0 )", "a", tuple.getObject( 0 ) );
assertEquals( "not equal: tuple.get( 1 )", "b", tuple.getObject( 1 ) );
}
代码示例来源:origin: cwensel/cascading
@Test
public void testGet() throws Exception
{
TupleEntry entry = new TupleEntry( new Fields( "json", JSONCoercibleType.TYPE ), Tuple.size( 1 ) );
entry.setObject( 0, JSONData.nested );
JSONGetFunction function = new JSONGetFunction( new Fields( "result" ), "/person/name" );
TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) );
Object value = result.iterator().next().getObject( 0 );
assertNotNull( value );
assertEquals( "John Doe", ( (TextNode) value ).textValue() );
}
代码示例来源:origin: cwensel/cascading
@Test
public void testSelectNotComparable()
{
Fields selector = new Fields( 1, "d" );
Object object = new Object();
TupleEntry entryA = new TupleEntry( new Fields( "a", "b" ), new Tuple( "a", object ) );
TupleEntry entryB = new TupleEntry( new Fields( "c", "d" ), new Tuple( "c", "d" ) );
Tuple tuple = TupleEntry.select( selector, entryA, entryB );
assertEquals( "wrong size", 2, tuple.size() );
assertEquals( "not equal: tuple.get(0)", object, tuple.getObject( 0 ) );
assertEquals( "not equal: tuple.get(1)", "d", tuple.getObject( 1 ) );
}
代码示例来源:origin: cwensel/cascading
@Test
public void testPut()
{
Fields aFields = new Fields( "one", "five" );
tuple.put( fields, aFields, new Tuple( "ten", "eleven" ) );
assertEquals( "not equal: tuple.size()", 5, tuple.size() );
assertEquals( "not equal: tuple.get( 0 )", "ten", tuple.getObject( 0 ) );
assertEquals( "not equal: tuple.get( 0 )", "ten", tuple.get( fields, new Fields( "one" ) ).getObject( 0 ) );
assertEquals( "not equal: tuple.get( 0 )", "eleven", tuple.getObject( 4 ) );
assertEquals( "not equal: tuple.get( 0 )", "eleven", tuple.get( fields, new Fields( "five" ) ).getObject( 0 ) );
}
内容来源于网络,如有侵权,请联系作者删除!