Java Code Examples for org.apache.flink.types.Row#setKind()

The following examples show how to use org.apache.flink.types.Row#setKind() . 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: RowSerializerTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testRowSerializer() {
	TypeInformation<Row> typeInfo = new RowTypeInfo(
		BasicTypeInfo.INT_TYPE_INFO,
		BasicTypeInfo.STRING_TYPE_INFO);
	Row row1 = new Row(2);
	row1.setKind(RowKind.UPDATE_BEFORE);
	row1.setField(0, 1);
	row1.setField(1, "a");

	Row row2 = new Row(2);
	row2.setKind(RowKind.INSERT);
	row2.setField(0, 2);
	row2.setField(1, null);

	TypeSerializer<Row> serializer = typeInfo.createSerializer(new ExecutionConfig());
	RowSerializerTestInstance instance = new RowSerializerTestInstance(serializer, row1, row2);
	instance.testAll();
}
 
Example 2
Source File: Flink111Shims.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
@Override
public boolean rowEquals(Object row1, Object row2) {
  Row r1 = (Row) row1;
  Row r2 = (Row) row2;
  r1.setKind(RowKind.INSERT);
  r2.setKind(RowKind.INSERT);
  return r1.equals(r2);
}
 
Example 3
Source File: StreamSelectTableSink.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public Row next() {
	// convert Tuple2<Boolean, Row> to Row
	Tuple2<Boolean, Row> tuple2 = iterator.next();
	RowKind rowKind = tuple2.f0 ? RowKind.INSERT : RowKind.DELETE;
	Row row = tuple2.f1;
	row.setKind(rowKind);
	return row;
}
 
Example 4
Source File: RowSerializer.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public Row deserialize(Row reuse, DataInputView source) throws IOException {
	final int len = fieldSerializers.length;

	if (reuse.getArity() != len) {
		throw new RuntimeException("Row arity of from does not match serializers.");
	}

	// read bitmask
	readIntoMask(source, mask);
	if (!legacyModeEnabled) {
		reuse.setKind(readKindFromMask(mask));
	}

	// deserialize fields
	for (int fieldPos = 0; fieldPos < len; fieldPos++) {
		if (mask[legacyOffset + fieldPos]) {
			reuse.setField(fieldPos, null);
		} else {
			Object reuseField = reuse.getField(fieldPos);
			if (reuseField != null) {
				reuse.setField(fieldPos, fieldSerializers[fieldPos].deserialize(reuseField, source));
			}
			else {
				reuse.setField(fieldPos, fieldSerializers[fieldPos].deserialize(source));
			}
		}
	}

	return reuse;
}