Java Code Examples for org.apache.flink.api.common.typeutils.base.LongSerializer#INSTANCE

The following examples show how to use org.apache.flink.api.common.typeutils.base.LongSerializer#INSTANCE . 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: SerializationProxiesTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testKeyedStateMetaInfoSerialization() throws Exception {

	String name = "test";
	TypeSerializer<?> namespaceSerializer = LongSerializer.INSTANCE;
	TypeSerializer<?> stateSerializer = DoubleSerializer.INSTANCE;

	StateMetaInfoSnapshot metaInfo = new RegisteredKeyValueStateBackendMetaInfo<>(
		StateDescriptor.Type.VALUE, name, namespaceSerializer, stateSerializer).snapshot();

	byte[] serialized;
	try (ByteArrayOutputStreamWithPos out = new ByteArrayOutputStreamWithPos()) {
		StateMetaInfoSnapshotReadersWriters.getWriter().
			writeStateMetaInfoSnapshot(metaInfo, new DataOutputViewStreamWrapper(out));
		serialized = out.toByteArray();
	}

	try (ByteArrayInputStreamWithPos in = new ByteArrayInputStreamWithPos(serialized)) {
		final StateMetaInfoReader reader = StateMetaInfoSnapshotReadersWriters.getReader(
			CURRENT_STATE_META_INFO_SNAPSHOT_VERSION, StateMetaInfoSnapshotReadersWriters.StateTypeHint.KEYED_STATE);
		metaInfo = reader.readStateMetaInfoSnapshot(
			new DataInputViewStreamWrapper(in), Thread.currentThread().getContextClassLoader());
	}

	Assert.assertEquals(name, metaInfo.getName());
}
 
Example 2
Source File: TupleComparatorILDC3Test.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected TupleComparator<Tuple3<Integer, Long, Double>> createComparator(boolean ascending) {
	return new TupleComparator<Tuple3<Integer, Long, Double>>(
			new int[]{2, 0, 1},
			new TypeComparator[]{
				new DoubleComparator(ascending),
				new IntComparator(ascending),
				new LongComparator(ascending)
			},
	new TypeSerializer[]{ IntSerializer.INSTANCE, LongSerializer.INSTANCE, DoubleSerializer.INSTANCE });
}
 
Example 3
Source File: TupleComparatorTTT2Test.java    From flink with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
protected TupleComparator<Tuple3<Tuple2<String, Double>, Tuple2<Long, Long>, Tuple2<Integer, Long>>> createComparator(
		boolean ascending) {
	return new TupleComparator<Tuple3<Tuple2<String, Double>, Tuple2<Long, Long>, Tuple2<Integer, Long>>>(
			new int[] { 0, 2 },
			new TypeComparator[] {
					new TupleComparator<Tuple2<String, Double>>(
							new int[] { 0, 1 },
							new TypeComparator[] {
							new StringComparator(ascending),
							new DoubleComparator(ascending) },
							new TypeSerializer[] {
									StringSerializer.INSTANCE,
									DoubleSerializer.INSTANCE }),
					new TupleComparator<Tuple2<Integer, Long>>(
							new int[] {	0, 1 },
							new TypeComparator[] {
							new IntComparator(ascending),
							new LongComparator(ascending) },
							new TypeSerializer[] {
									IntSerializer.INSTANCE,
									LongSerializer.INSTANCE }) },
			new TypeSerializer[] {
					new TupleSerializer<Tuple2<String, Double>>(
							(Class<Tuple2<String, Double>>) (Class<?>) Tuple2.class,
							new TypeSerializer[] {
									StringSerializer.INSTANCE,
									DoubleSerializer.INSTANCE }),
					new TupleSerializer<Tuple2<Long, Long>>(
							(Class<Tuple2<Long, Long>>) (Class<?>) Tuple2.class,
							new TypeSerializer[] {
									LongSerializer.INSTANCE,
									LongSerializer.INSTANCE }),
					new TupleSerializer<Tuple2<Integer, Long>>(
							(Class<Tuple2<Integer, Long>>) (Class<?>) Tuple2.class,
							new TypeSerializer[] {
									IntSerializer.INSTANCE,
									LongSerializer.INSTANCE }) });
}
 
Example 4
Source File: KvStateRequestSerializerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Tests value serialization utils.
 */
@Test
public void testValueSerialization() throws Exception {
	TypeSerializer<Long> valueSerializer = LongSerializer.INSTANCE;
	long expectedValue = Long.MAX_VALUE - 1292929292L;

	byte[] serializedValue = KvStateSerializer.serializeValue(expectedValue, valueSerializer);
	long actualValue = KvStateSerializer.deserializeValue(serializedValue, valueSerializer);

	assertEquals(expectedValue, actualValue);
}
 
Example 5
Source File: StreamTaskNetworkInputTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private void serializeRecord(long value, BufferBuilder bufferBuilder) throws IOException {
	RecordSerializer<SerializationDelegate<StreamElement>> serializer = new SpanningRecordSerializer<>();
	SerializationDelegate<StreamElement> serializationDelegate =
		new SerializationDelegate<>(
			new StreamElementSerializer<>(LongSerializer.INSTANCE));
	serializationDelegate.setInstance(new StreamRecord<>(value));
	serializer.serializeRecord(serializationDelegate);

	assertFalse(serializer.copyToBufferBuilder(bufferBuilder).isFullBuffer());
}
 
Example 6
Source File: RowDataSerializerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected TypeSerializer<RowData> createSerializer() {
	TypeSerializer<?>[] fieldTypeSerializers = {
		LongSerializer.INSTANCE,
		LongSerializer.INSTANCE
	};

	LogicalType[] fieldTypes = {
		new BigIntType(),
		new BigIntType()
	};
	return new org.apache.flink.table.runtime.typeutils.serializers.python.RowDataSerializer(
		fieldTypes,
		fieldTypeSerializers);
}
 
Example 7
Source File: StateBackendBenchmarkUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
private static RocksDBKeyedStateBackend<Long> createRocksDBKeyedStateBackend(File rootDir) throws IOException {
	File recoveryBaseDir = prepareDirectory(recoveryDirName, rootDir);
	File dbPathFile = prepareDirectory(dbDirName, rootDir);
	ExecutionConfig executionConfig = new ExecutionConfig();
	RocksDBResourceContainer resourceContainer = new RocksDBResourceContainer();
	RocksDBKeyedStateBackendBuilder<Long> builder = new RocksDBKeyedStateBackendBuilder<>(
		"Test",
		Thread.currentThread().getContextClassLoader(),
		dbPathFile,
		resourceContainer,
		stateName -> resourceContainer.getColumnOptions(),
		null,
		LongSerializer.INSTANCE,
		2,
		new KeyGroupRange(0, 1),
		executionConfig,
		new LocalRecoveryConfig(false, new LocalRecoveryDirectoryProviderImpl(recoveryBaseDir, new JobID(), new JobVertexID(), 0)),
		RocksDBStateBackend.PriorityQueueStateType.ROCKSDB,
		TtlTimeProvider.DEFAULT,
		new UnregisteredMetricsGroup(),
		Collections.emptyList(),
		AbstractStateBackend.getCompressionDecorator(executionConfig),
		new CloseableRegistry());
	try {
		return builder.build();
	} catch (Exception e) {
		IOUtils.closeQuietly(resourceContainer);
		throw e;
	}
}
 
Example 8
Source File: TupleComparatorTTT1Test.java    From flink with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
protected TupleComparator<Tuple3<Tuple2<String, Double>, Tuple2<Long, Long>, Tuple2<Integer, Long>>> createComparator(
		boolean ascending) {
	return new TupleComparator<Tuple3<Tuple2<String, Double>, Tuple2<Long, Long>, Tuple2<Integer, Long>>>(
			new int[] { 0 },
			new TypeComparator[] {
					new TupleComparator<Tuple2<String, Double>>(
							new int[] { 0, 1 },
							new TypeComparator[] {
							new StringComparator(ascending),
							new DoubleComparator(ascending) },
							new TypeSerializer[] {
									StringSerializer.INSTANCE,
									DoubleSerializer.INSTANCE }) },
			new TypeSerializer[] {
					new TupleSerializer<Tuple2<String, Double>>(
							(Class<Tuple2<String, Double>>) (Class<?>) Tuple2.class,
							new TypeSerializer[] {
									StringSerializer.INSTANCE,
									DoubleSerializer.INSTANCE }),
					new TupleSerializer<Tuple2<Long, Long>>(
							(Class<Tuple2<Long, Long>>) (Class<?>) Tuple2.class,
							new TypeSerializer[] {
									LongSerializer.INSTANCE,
									LongSerializer.INSTANCE }),
					new TupleSerializer<Tuple2<Integer, Long>>(
							(Class<Tuple2<Integer, Long>>) (Class<?>) Tuple2.class,
							new TypeSerializer[] {
									IntSerializer.INSTANCE,
									LongSerializer.INSTANCE }) });
}
 
Example 9
Source File: TtlStateFactory.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private <IN, OUT> IS createAggregatingState() throws Exception {
	AggregatingStateDescriptor<IN, SV, OUT> aggregatingStateDescriptor =
		(AggregatingStateDescriptor<IN, SV, OUT>) stateDesc;
	TtlAggregateFunction<IN, SV, OUT> ttlAggregateFunction = new TtlAggregateFunction<>(
		aggregatingStateDescriptor.getAggregateFunction(), ttlConfig, timeProvider);
	AggregatingStateDescriptor<IN, TtlValue<SV>, OUT> ttlDescriptor = new AggregatingStateDescriptor<>(
		stateDesc.getName(), ttlAggregateFunction, new TtlSerializer<>(LongSerializer.INSTANCE, stateDesc.getSerializer()));
	return (IS) new TtlAggregatingState<>(createTtlStateContext(ttlDescriptor), ttlAggregateFunction);
}
 
Example 10
Source File: TupleComparatorILDXC2Test.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected TupleComparator<Tuple3<Integer, Long, Double>> createComparator(boolean ascending) {
	return new TupleComparator<Tuple3<Integer, Long, Double>>(
			new int[]{2, 1},
			new TypeComparator[]{
				new DoubleComparator(ascending),
				new LongComparator(ascending)
			},
	new TypeSerializer[]{ IntSerializer.INSTANCE, DoubleSerializer.INSTANCE, LongSerializer.INSTANCE });
}
 
Example 11
Source File: TupleComparatorTTT2Test.java    From flink with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
protected TupleComparator<Tuple3<Tuple2<String, Double>, Tuple2<Long, Long>, Tuple2<Integer, Long>>> createComparator(
		boolean ascending) {
	return new TupleComparator<Tuple3<Tuple2<String, Double>, Tuple2<Long, Long>, Tuple2<Integer, Long>>>(
			new int[] { 0, 2 },
			new TypeComparator[] {
					new TupleComparator<Tuple2<String, Double>>(
							new int[] { 0, 1 },
							new TypeComparator[] {
							new StringComparator(ascending),
							new DoubleComparator(ascending) },
							new TypeSerializer[] {
									StringSerializer.INSTANCE,
									DoubleSerializer.INSTANCE }),
					new TupleComparator<Tuple2<Integer, Long>>(
							new int[] {	0, 1 },
							new TypeComparator[] {
							new IntComparator(ascending),
							new LongComparator(ascending) },
							new TypeSerializer[] {
									IntSerializer.INSTANCE,
									LongSerializer.INSTANCE }) },
			new TypeSerializer[] {
					new TupleSerializer<Tuple2<String, Double>>(
							(Class<Tuple2<String, Double>>) (Class<?>) Tuple2.class,
							new TypeSerializer[] {
									StringSerializer.INSTANCE,
									DoubleSerializer.INSTANCE }),
					new TupleSerializer<Tuple2<Long, Long>>(
							(Class<Tuple2<Long, Long>>) (Class<?>) Tuple2.class,
							new TypeSerializer[] {
									LongSerializer.INSTANCE,
									LongSerializer.INSTANCE }),
					new TupleSerializer<Tuple2<Integer, Long>>(
							(Class<Tuple2<Integer, Long>>) (Class<?>) Tuple2.class,
							new TypeSerializer[] {
									IntSerializer.INSTANCE,
									LongSerializer.INSTANCE }) });
}
 
Example 12
Source File: TtlStateFactory.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private <UK, UV> IS createMapState() throws Exception {
	MapStateDescriptor<UK, UV> mapStateDesc = (MapStateDescriptor<UK, UV>) stateDesc;
	MapStateDescriptor<UK, TtlValue<UV>> ttlDescriptor = new MapStateDescriptor<>(
		stateDesc.getName(),
		mapStateDesc.getKeySerializer(),
		new TtlSerializer<>(LongSerializer.INSTANCE, mapStateDesc.getValueSerializer()));
	return (IS) new TtlMapState<>(createTtlStateContext(ttlDescriptor));
}
 
Example 13
Source File: TtlStateFactory.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private <T> IS createListState() throws Exception {
	ListStateDescriptor<T> listStateDesc = (ListStateDescriptor<T>) stateDesc;
	ListStateDescriptor<TtlValue<T>> ttlDescriptor = new ListStateDescriptor<>(
		stateDesc.getName(), new TtlSerializer<>(LongSerializer.INSTANCE, listStateDesc.getElementSerializer()));
	return (IS) new TtlListState<>(createTtlStateContext(ttlDescriptor));
}
 
Example 14
Source File: UnionSerializerUpgradeTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public TypeSerializer<TaggedUnion<String, Long>> createPriorSerializer() {
	return new UnionSerializer<>(StringSerializer.INSTANCE, LongSerializer.INSTANCE);
}
 
Example 15
Source File: ArrayDataSerializerTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
protected TypeSerializer<ArrayData> createSerializer() {
	return new ArrayDataSerializer(new ArrayType(new BigIntType()),
		new ArrayDataSerializer(new BigIntType(), LongSerializer.INSTANCE));
}
 
Example 16
Source File: InternalSerializers.java    From flink with Apache License 2.0 4 votes vote down vote up
public static TypeSerializer create(LogicalType type, ExecutionConfig config) {
	switch (type.getTypeRoot()) {
		case BOOLEAN:
			return BooleanSerializer.INSTANCE;
		case TINYINT:
			return ByteSerializer.INSTANCE;
		case SMALLINT:
			return ShortSerializer.INSTANCE;
		case INTEGER:
		case DATE:
		case TIME_WITHOUT_TIME_ZONE:
		case INTERVAL_YEAR_MONTH:
			return IntSerializer.INSTANCE;
		case BIGINT:
		case TIMESTAMP_WITHOUT_TIME_ZONE:
		case TIMESTAMP_WITH_LOCAL_TIME_ZONE:
		case INTERVAL_DAY_TIME:
			return LongSerializer.INSTANCE;
		case FLOAT:
			return FloatSerializer.INSTANCE;
		case DOUBLE:
			return DoubleSerializer.INSTANCE;
		case CHAR:
		case VARCHAR:
			return BinaryStringSerializer.INSTANCE;
		case DECIMAL:
			DecimalType decimalType = (DecimalType) type;
			return new DecimalSerializer(decimalType.getPrecision(), decimalType.getScale());
		case ARRAY:
			return new BaseArraySerializer(((ArrayType) type).getElementType(), config);
		case MAP:
			MapType mapType = (MapType) type;
			return new BaseMapSerializer(mapType.getKeyType(), mapType.getValueType(), config);
		case MULTISET:
			return new BaseMapSerializer(((MultisetType) type).getElementType(), new IntType(), config);
		case ROW:
			RowType rowType = (RowType) type;
			return new BaseRowSerializer(config, rowType);
		case BINARY:
		case VARBINARY:
			return BytePrimitiveArraySerializer.INSTANCE;
		case ANY:
			return new BinaryGenericSerializer(
					((TypeInformationAnyType) type).getTypeInformation().createSerializer(config));
		default:
			throw new RuntimeException("Not support type: " + type);
	}
}
 
Example 17
Source File: TtlFoldingStateVerifier.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
TtlFoldingStateVerifier() {
	super(new FoldingStateDescriptor<>(
		TtlFoldingStateVerifier.class.getSimpleName(), INIT_VAL, (v, acc) -> acc + v, LongSerializer.INSTANCE));
}
 
Example 18
Source File: LastValueWithRetractAggFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
private MapViewSerializer<Long, List<T>> getOrderToValueMapViewSerializer() {
	return new MapViewSerializer<>(
			new MapSerializer<>(
					LongSerializer.INSTANCE,
					new ListSerializer<>(createValueSerializer())));
}
 
Example 19
Source File: NullAwareMapSerializerTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
protected TypeSerializer<Map<Long, String>> createSerializer() {
	return new NullAwareMapSerializer<>(LongSerializer.INSTANCE, StringSerializer.INSTANCE);
}
 
Example 20
Source File: KvStateServerHandlerTest.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Tests the failure response on a failure on the {@link InternalKvState#getSerializedValue(byte[], TypeSerializer, TypeSerializer, TypeSerializer)} call.
 */
@Test
public void testFailureOnGetSerializedValue() throws Exception {
	KvStateRegistry registry = new KvStateRegistry();
	AtomicKvStateRequestStats stats = new AtomicKvStateRequestStats();

	MessageSerializer<KvStateInternalRequest, KvStateResponse> serializer =
			new MessageSerializer<>(new KvStateInternalRequest.KvStateInternalRequestDeserializer(), new KvStateResponse.KvStateResponseDeserializer());

	KvStateServerHandler handler = new KvStateServerHandler(testServer, registry, serializer, stats);
	EmbeddedChannel channel = new EmbeddedChannel(getFrameDecoder(), handler);

	// Failing KvState
	InternalKvState<Integer, VoidNamespace, Long> kvState =
			new InternalKvState<Integer, VoidNamespace, Long>() {
				@Override
				public TypeSerializer<Integer> getKeySerializer() {
					return IntSerializer.INSTANCE;
				}

				@Override
				public TypeSerializer<VoidNamespace> getNamespaceSerializer() {
					return VoidNamespaceSerializer.INSTANCE;
				}

				@Override
				public TypeSerializer<Long> getValueSerializer() {
					return LongSerializer.INSTANCE;
				}

				@Override
				public void setCurrentNamespace(VoidNamespace namespace) {
					// do nothing
				}

				@Override
				public byte[] getSerializedValue(
						final byte[] serializedKeyAndNamespace,
						final TypeSerializer<Integer> safeKeySerializer,
						final TypeSerializer<VoidNamespace> safeNamespaceSerializer,
						final TypeSerializer<Long> safeValueSerializer) throws Exception {
					throw new RuntimeException("Expected test Exception");
				}

				@Override
				public StateIncrementalVisitor<Integer, VoidNamespace, Long> getStateIncrementalVisitor(int recommendedMaxNumberOfReturnedRecords) {
					throw new UnsupportedOperationException();
				}

				@Override
				public void clear() {

				}
			};

	KvStateID kvStateId = registry.registerKvState(
			new JobID(),
			new JobVertexID(),
			new KeyGroupRange(0, 0),
			"vanilla",
			kvState);

	KvStateInternalRequest request = new KvStateInternalRequest(kvStateId, new byte[0]);
	ByteBuf serRequest = MessageSerializer.serializeRequest(channel.alloc(), 282872L, request);

	// Write the request and wait for the response
	channel.writeInbound(serRequest);

	ByteBuf buf = (ByteBuf) readInboundBlocking(channel);
	buf.skipBytes(4); // skip frame length

	// Verify the response
	assertEquals(MessageType.REQUEST_FAILURE, MessageSerializer.deserializeHeader(buf));
	RequestFailure response = MessageSerializer.deserializeRequestFailure(buf);
	buf.release();

	assertTrue(response.getCause().getMessage().contains("Expected test Exception"));

	assertEquals(1L, stats.getNumRequests());
	assertEquals(1L, stats.getNumFailed());
}