Java Code Examples for org.apache.flink.api.java.typeutils.runtime.RowSerializer

The following examples show how to use org.apache.flink.api.java.typeutils.runtime.RowSerializer. These examples are extracted from open source projects. 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 Project: flink   Source File: PythonScalarFunctionOperatorTest.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public PythonFunctionRunner<Row> createPythonFunctionRunner(
		FnDataReceiver<byte[]> resultReceiver,
		PythonEnvironmentManager pythonEnvironmentManager,
		Map<String, String> jobOptions) {
	return new PassThroughPythonScalarFunctionRunner<Row>(
		getRuntimeContext().getTaskName(),
		resultReceiver,
		scalarFunctions,
		PythonTestUtils.createTestEnvironmentManager(),
		userDefinedFunctionInputType,
		userDefinedFunctionOutputType,
		jobOptions,
		PythonTestUtils.createMockFlinkMetricContainer()) {
		@Override
		public TypeSerializer<Row> getInputTypeSerializer() {
			return (RowSerializer) PythonTypeUtils.toFlinkTypeSerializer(getInputType());
		}
	};
}
 
Example 2
Source Project: Flink-CEPplus   Source File: CassandraRowWriteAheadSink.java    License: Apache License 2.0 5 votes vote down vote up
public void open() throws Exception {
	super.open();
	if (!getRuntimeContext().isCheckpointingEnabled()) {
		throw new IllegalStateException("The write-ahead log requires checkpointing to be enabled.");
	}
	cluster = builder.getCluster();
	session = cluster.connect();
	preparedStatement = session.prepare(insertQuery);

	arity = ((RowSerializer) serializer).getArity();
	fields = new Object[arity];
}
 
Example 3
Source Project: Flink-CEPplus   Source File: RowTypeInfo.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public TypeSerializer<Row> createSerializer(ExecutionConfig config) {
	int len = getArity();
	TypeSerializer<?>[] fieldSerializers = new TypeSerializer[len];
	for (int i = 0; i < len; i++) {
		fieldSerializers[i] = types[i].createSerializer(config);
	}
	return new RowSerializer(fieldSerializers);
}
 
Example 4
Source Project: flink   Source File: CassandraRowWriteAheadSink.java    License: Apache License 2.0 5 votes vote down vote up
public void open() throws Exception {
	super.open();
	if (!getRuntimeContext().isCheckpointingEnabled()) {
		throw new IllegalStateException("The write-ahead log requires checkpointing to be enabled.");
	}
	cluster = builder.getCluster();
	session = cluster.connect();
	preparedStatement = session.prepare(insertQuery);

	arity = ((RowSerializer) serializer).getArity();
	fields = new Object[arity];
}
 
Example 5
Source Project: flink   Source File: RowTypeInfo.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public TypeSerializer<Row> createSerializer(ExecutionConfig config) {
	int len = getArity();
	TypeSerializer<?>[] fieldSerializers = new TypeSerializer[len];
	for (int i = 0; i < len; i++) {
		fieldSerializers[i] = types[i].createSerializer(config);
	}
	return new RowSerializer(fieldSerializers);
}
 
Example 6
Source Project: flink   Source File: CassandraRowWriteAheadSink.java    License: Apache License 2.0 5 votes vote down vote up
public void open() throws Exception {
	super.open();
	if (!getRuntimeContext().isCheckpointingEnabled()) {
		throw new IllegalStateException("The write-ahead log requires checkpointing to be enabled.");
	}
	cluster = builder.getCluster();
	session = cluster.connect();
	preparedStatement = session.prepare(insertQuery);

	arity = ((RowSerializer) serializer).getArity();
	fields = new Object[arity];
}
 
Example 7
Source Project: flink   Source File: PythonTypeUtils.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public TypeSerializer visit(RowType rowType) {
	final TypeSerializer[] fieldTypeSerializers = rowType.getFields()
		.stream()
		.map(f -> f.getType().accept(this))
		.toArray(TypeSerializer[]::new);
	return new RowSerializer(fieldTypeSerializers, true);
}
 
Example 8
Source Project: flink   Source File: PythonTypeUtilsTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testLogicalTypeToFlinkTypeSerializer() {
	List<RowType.RowField> rowFields = new ArrayList<>();
	rowFields.add(new RowType.RowField("f1", new BigIntType()));
	RowType rowType = new RowType(rowFields);
	TypeSerializer rowSerializer = PythonTypeUtils.toFlinkTypeSerializer(rowType);
	assertTrue(rowSerializer instanceof RowSerializer);

	assertEquals(1, ((RowSerializer) rowSerializer).getArity());
}
 
Example 9
Source Project: flink   Source File: PythonTableFunctionRunnerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testInputOutputDataTypeConstructedProperlyForSingleUDTF() throws Exception {
	final AbstractPythonTableFunctionRunner<Row> runner = createUDTFRunner();

	// check input TypeSerializer
	TypeSerializer inputTypeSerializer = runner.getInputTypeSerializer();
	assertTrue(inputTypeSerializer instanceof RowSerializer);

	assertEquals(1, ((RowSerializer) inputTypeSerializer).getArity());
}
 
Example 10
Source Project: flink   Source File: PythonScalarFunctionRunnerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testInputOutputDataTypeConstructedProperlyForSingleUDF() throws Exception {
	final PythonScalarFunctionRunner runner = (PythonScalarFunctionRunner) createSingleUDFRunner();

	// check input TypeSerializer
	TypeSerializer inputTypeSerializer = runner.getInputTypeSerializer();
	assertEquals(1, ((RowSerializer) inputTypeSerializer).getArity());
}
 
Example 11
Source Project: flink   Source File: PythonScalarFunctionRunnerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testInputOutputDataTypeConstructedProperlyForMultipleUDFs() throws Exception {
	final PythonScalarFunctionRunner runner = (PythonScalarFunctionRunner) createMultipleUDFRunner();

	// check input TypeSerializer
	TypeSerializer inputTypeSerializer = runner.getInputTypeSerializer();
	assertEquals(3, ((RowSerializer) inputTypeSerializer).getArity());
}
 
Example 12
Source Project: flink   Source File: PythonScalarFunctionRunnerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testInputOutputDataTypeConstructedProperlyForChainedUDFs() throws Exception {
	final PythonScalarFunctionRunner runner = (PythonScalarFunctionRunner) createChainedUDFRunner();

	// check input TypeSerializer
	TypeSerializer inputTypeSerializer = runner.getInputTypeSerializer();
	assertEquals(5, ((RowSerializer) inputTypeSerializer).getArity());
}
 
Example 13
Source Project: flink   Source File: PythonScalarFunctionRunnerTest.java    License: Apache License 2.0 5 votes vote down vote up
private AbstractGeneralPythonScalarFunctionRunner<Row> createUDFRunner(
	JobBundleFactory jobBundleFactory, FnDataReceiver<byte[]> receiver) {
	PythonFunctionInfo[] pythonFunctionInfos = new PythonFunctionInfo[] {
		new PythonFunctionInfo(
			DummyPythonFunction.INSTANCE,
			new Integer[]{0})
	};

	RowType rowType = new RowType(Collections.singletonList(new RowType.RowField("f1", new BigIntType())));

	final PythonEnvironmentManager environmentManager = createTestEnvironmentManager();

	return new PassThroughPythonScalarFunctionRunner<Row>(
		"testPythonRunner",
		receiver,
		pythonFunctionInfos,
		environmentManager,
		rowType,
		rowType,
		Collections.emptyMap(),
		jobBundleFactory,
		PythonTestUtils.createMockFlinkMetricContainer()) {
		@Override
		public TypeSerializer<Row> getInputTypeSerializer() {
			return (RowSerializer) PythonTypeUtils.toFlinkTypeSerializer(getInputType());
		}
	};
}
 
Example 14
Source Project: flink   Source File: RowTypeInfo.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public TypeSerializer<Row> createSerializer(ExecutionConfig config) {
	int len = getArity();
	TypeSerializer<?>[] fieldSerializers = new TypeSerializer[len];
	for (int i = 0; i < len; i++) {
		fieldSerializers[i] = types[i].createSerializer(config);
	}
	return new RowSerializer(fieldSerializers);
}
 
Example 15
Source Project: flink   Source File: RowTypeInfo.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates a serializer for the old {@link Row} format before Flink 1.11.
 *
 * <p>The serialization format has changed from 1.10 to 1.11 and added {@link Row#getKind()}.
 */
@Deprecated
public TypeSerializer<Row> createLegacySerializer(ExecutionConfig config) {
	int len = getArity();
	TypeSerializer<?>[] fieldSerializers = new TypeSerializer[len];
	for (int i = 0; i < len; i++) {
		fieldSerializers[i] = types[i].createSerializer(config);
	}
	return new RowSerializer(fieldSerializers, true);
}
 
Example 16
Source Project: flink   Source File: PythonTableFunctionRunner.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public TypeSerializer<Row> getInputTypeSerializer() {
	return (RowSerializer) PythonTypeUtils.toFlinkTypeSerializer(getInputType());
}
 
Example 17
Source Project: flink   Source File: PythonScalarFunctionRunner.java    License: Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public RowSerializer getInputTypeSerializer() {
	return (RowSerializer) PythonTypeUtils.toFlinkTypeSerializer(getInputType());
}
 
Example 18
Source Project: flink   Source File: RowArrowSourceFunctionTest.java    License: Apache License 2.0 4 votes vote down vote up
public RowArrowSourceFunctionTest() {
	super(VectorSchemaRoot.create(ArrowUtils.toArrowSchema(rowType), allocator),
		new RowSerializer(new TypeSerializer[]{StringSerializer.INSTANCE}, true),
		Comparator.comparing(o -> (String) (o.getField(0))));
}