Java Code Examples for cascading.tuple.Tuple#size()

The following examples show how to use cascading.tuple.Tuple#size() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefinedTupleSerializer.java    From cascading-flink with Apache License 2.0 6 votes vote down vote up
@Override
public Tuple copy(Tuple from) {
	Tuple target = Tuple.size(from.size());
	for (int i = 0; i < from.size(); i++) {
		try {
			Object orig = from.getObject(i);
			if (orig != null) {
				target.set(i, fieldSers[i].copy(orig));
			}
			else {
				target.set(i, null);
			}
		}
		catch(ClassCastException cce) {
			throw new FlowException("Unexpected type of field \""+fields.get(i)+"\" encountered. " +
									"Should have been "+fields.getType(i)+" but was "+from.getObject(i).getClass()+".", cce);
		}
	}
	return target;
}
 
Example 2
Source File: DefinedTupleSerializer.java    From cascading-flink with Apache License 2.0 6 votes vote down vote up
@Override
public Tuple copy(Tuple from) {
	Tuple target = Tuple.size(from.size());
	for (int i = 0; i < from.size(); i++) {
		try {
			Object orig = from.getObject(i);
			if (orig != null) {
				target.set(i, fieldSers[i].copy(orig));
			}
			else {
				target.set(i, null);
			}
		}
		catch(ClassCastException cce) {
			throw new FlowException("Unexpected type of field \""+fields.get(i)+"\" encountered. " +
									"Should have been "+fields.getType(i)+" but was "+from.getObject(i).getClass()+".", cce);
		}
	}
	return target;
}
 
Example 3
Source File: DefinedTupleSerializer.java    From cascading-flink with Apache License 2.0 6 votes vote down vote up
@Override
public void serialize(Tuple value, DataOutputView target) throws IOException {

	// write null mask
	NullMaskSerDeUtils.writeNullMask(value, target);

	for (int i = 0; i < value.size(); i++) {
		Object o = value.getObject(i);
		if(o != null) {
			try {
				fieldSers[i].serialize(o, target);
			}
			catch(ClassCastException cce) {
				throw new FlowException("Unexpected type of field \""+fields.get(i)+"\" encountered. " +
										"Should have been "+fields.getType(i)+" but was "+o.getClass()+".", cce);
			}
		}
	}
}
 
Example 4
Source File: DefinedTupleSerializer.java    From cascading-flink with Apache License 2.0 6 votes vote down vote up
@Override
public Tuple deserialize(DataInputView source) throws IOException {

	// read null mask
	NullMaskSerDeUtils.readNullMask(this.nullFields, this.length, source);

	// read non-null fields
	Tuple tuple = Tuple.size(this.length);
	for (int i = 0; i < this.length; i++) {
		Object field;
		if(!this.nullFields[i]) {
			field = fieldSers[i].deserialize(source);
		}
		else {
			field = null;
		}
		tuple.set(i, field);
	}

	return tuple;
}
 
Example 5
Source File: UnknownTupleSerializer.java    From cascading-flink with Apache License 2.0 6 votes vote down vote up
@Override
public void serialize(Tuple value, DataOutputView target) throws IOException {

	// write length
	target.writeInt(value.size());

	// write null mask
	NullMaskSerDeUtils.writeNullMask(value, target);

	for (int i = 0; i < value.size(); i++) {
		Object o = value.getObject(i);
		if(o != null) {
			fieldSer.serialize(o, target);
		}
	}
}
 
Example 6
Source File: NullMaskSerDeUtils.java    From cascading-flink with Apache License 2.0 6 votes vote down vote up
public static void writeNullMask(
		Tuple t, DataOutputView target) throws IOException {

	final int length = t.size();
	int b;
	int bytePos;

	for(int fieldPos = 0; fieldPos < length; ) {
		b = 0x00;
		// set bits in byte
		for(bytePos = 0; bytePos < 8 && fieldPos < length; bytePos++, fieldPos++) {
			b = b << 1;
			// set bit if field is null
			if(t.getObject(fieldPos) == null) {
				b |= 0x01;
			}
		}
		// shift bits if last byte is not completely filled
		for(; bytePos < 8; bytePos++) {
			b = b << 1;
		}
		// write byte
		target.writeByte(b);
	}
}
 
Example 7
Source File: UnknownTupleSerializer.java    From cascading-flink with Apache License 2.0 5 votes vote down vote up
@Override
public Tuple deserialize(DataInputView source) throws IOException {

	// read length
	int arity = source.readInt();

	// initialize or resize null fields if necessary
	if(this.nullFields == null || this.nullFields.length < arity) {
		this.nullFields = new boolean[arity];
	}

	// read null mask
	NullMaskSerDeUtils.readNullMask(this.nullFields, arity, source);

	// read non-null fields
	Tuple tuple = Tuple.size(arity);
	for (int i = 0; i < arity; i++) {
		Object field;
		if(!this.nullFields[i]) {
			field = fieldSer.deserialize(source);
		}
		else {
			field = null;
		}
		tuple.set(i, field);
	}

	return tuple;
}
 
Example 8
Source File: JDBCScheme.java    From SpyGlass with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor JDBCScheme creates a new JDBCScheme instance.
 *
 * @param inputFormatClass  of type Class<? extends DBInputFormat>
 * @param outputFormatClass of type Class<? extends DBOutputFormat>
 * @param columnFields      of type Fields
 * @param columns           of type String[]
 * @param orderBy           of type String[]
 * @param conditions        of type String
 * @param limit             of type long
 * @param updateByFields    of type Fields
 * @param updateBy          of type String[]
 */
public JDBCScheme( Class<? extends DBInputFormat> inputFormatClass, Class<? extends DBOutputFormat> outputFormatClass, Fields columnFields, String[] columns, String[] orderBy, String conditions, long limit, Fields updateByFields, String[] updateBy )
{
    this.columnFields = columnFields;

    verifyColumns( columnFields, columns );

    setSinkFields( columnFields );
    setSourceFields( columnFields );

    if( updateBy != null && updateBy.length != 0 )
    {
        this.updateBy = updateBy;
        this.updateByFields = updateByFields;

        if( updateByFields.size() != updateBy.length )
            throw new IllegalArgumentException( "updateByFields and updateBy must be the same size" );

        if( !this.columnFields.contains( this.updateByFields ) )
            throw new IllegalArgumentException( "columnFields must contain updateByFields column names" );

        this.updateValueFields = columnFields.subtract( updateByFields ).append( updateByFields );
        this.updateIfTuple = Tuple.size( updateByFields.size() ); // all nulls
    }

    this.columns = columns;
    this.orderBy = orderBy;
    this.conditions = conditions;
    this.limit = limit;

    this.inputFormatClass = inputFormatClass;
    this.outputFormatClass = outputFormatClass;
}
 
Example 9
Source File: FunctionCallStub.java    From plunger with Apache License 2.0 5 votes vote down vote up
public Builder<C> addTuple(Object... values) {
  values = FieldTypeValidator.validateValues(fieldMask, values);
  TupleEntry newTuple = new TupleEntry(fields, Tuple.size(fields.size()));
  newTuple.setTuple(fieldMask, new Tuple(values));
  tuples.add(newTuple);
  return this;
}
 
Example 10
Source File: AbstractOperationCallStub.java    From plunger with Apache License 2.0 5 votes vote down vote up
@Override
public void add(Tuple tuple) {
  if (tuple.size() != getDeclaredFields().size()) {
    throw new IllegalArgumentException("Tuple size != declared fields size: " + tuple + ", " + getDeclaredFields());
  }
  collected.add(new TupleEntry(getDeclaredFields(), new Tuple(tuple)));
}
 
Example 11
Source File: PlungerAssert.java    From plunger with Apache License 2.0 5 votes vote down vote up
public static Matcher<TupleEntry> tupleEntry(Fields fields, Tuple tuple) {
  if (fields.size() != tuple.size()) {
    throw new IllegalArgumentException("Fields size (" + fields.size() + ") does not match tuple size ("
        + tuple.size() + ")");
  }
  return tupleEntry(new TupleEntry(fields, tuple));
}
 
Example 12
Source File: CoGroupBufferClosure.java    From cascading-flink with Apache License 2.0 5 votes vote down vote up
public CoGroupBufferClosure(FlowProcess flowProcess, int numSelfJoins, Fields[] joinFields, Fields[] valueFields) {
	super(flowProcess, joinFields, valueFields);
	this.numSelfJoins = numSelfJoins;

	this.emptyTuple = Tuple.size( joinFields[0].size() );
	FactoryLoader loader = FactoryLoader.getInstance();

	this.tupleCollectionFactory = loader.loadFactoryFrom( flowProcess, TUPLE_COLLECTION_FACTORY, SpillingTupleCollectionFactory.class );

	initLists();
}
 
Example 13
Source File: UnknownTupleSerializer.java    From cascading-flink with Apache License 2.0 5 votes vote down vote up
private Tuple getReuseOrNew(Tuple reuse, int arity) {

		if(reuse.isUnmodifiable() || reuse.size() != arity) {
			return Tuple.size(arity);
		}
		else {
			return reuse;
		}
	}
 
Example 14
Source File: UnknownTupleSerializer.java    From cascading-flink with Apache License 2.0 5 votes vote down vote up
private Tuple getReuseOrNew(Tuple reuse, int arity) {

		if(reuse.isUnmodifiable() || reuse.size() != arity) {
			return Tuple.size(arity);
		}
		else {
			return reuse;
		}
	}
 
Example 15
Source File: UnknownTupleSerializer.java    From cascading-flink with Apache License 2.0 5 votes vote down vote up
@Override
public Tuple createInstance() {
	try {
		return Tuple.size(0);
	} catch (Exception e) {
		throw new RuntimeException("Cannot instantiate tuple.", e);
	}
}
 
Example 16
Source File: DefinedTupleSerializer.java    From cascading-flink with Apache License 2.0 5 votes vote down vote up
private Tuple getReuseOrNew(Tuple reuse) {
	if(reuse.isUnmodifiable()) {
		return Tuple.size(this.length);
	}
	else {
		return reuse;
	}
}
 
Example 17
Source File: DefinedTupleSerializer.java    From cascading-flink with Apache License 2.0 5 votes vote down vote up
@Override
public Tuple createInstance() {
	try {
		return Tuple.size(length);
	} catch (Exception e) {
		throw new RuntimeException("Cannot instantiate tuple.", e);
	}
}
 
Example 18
Source File: JoinClosure.java    From cascading-flink with Apache License 2.0 4 votes vote down vote up
public JoinClosure(FlowProcess flowProcess, Fields[] joinFields, Fields[] valueFields) {
	super(flowProcess, joinFields, valueFields);
	this.emptyKeyTuple = Tuple.size( joinFields[0].size() );
	this.keyTuples = new Tuple[joinFields.length];
	this.joinedKeysTupleBuilder = makeJoinedBuilder( joinFields );
}
 
Example 19
Source File: TupleConverter.java    From parquet-mr with Apache License 2.0 4 votes vote down vote up
@Override
final public void start() {
  currentTuple = Tuple.size(converters.length);
}