Java Code Examples for org.apache.flink.api.common.typeinfo.Types#TUPLE

The following examples show how to use org.apache.flink.api.common.typeinfo.Types#TUPLE . 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: CollectStreamResult.java    From flink with Apache License 2.0 6 votes vote down vote up
public CollectStreamResult(
		TableSchema tableSchema,
		ExecutionConfig config,
		InetAddress gatewayAddress,
		int gatewayPort,
		ClassLoader classLoader) {
	resultLock = new Object();

	// create socket stream iterator
	final TypeInformation<Tuple2<Boolean, Row>> socketType = Types.TUPLE(Types.BOOLEAN, tableSchema.toRowType());
	final TypeSerializer<Tuple2<Boolean, Row>> serializer = socketType.createSerializer(config);
	try {
		// pass gateway port and address such that iterator knows where to bind to
		iterator = new SocketStreamIterator<>(gatewayPort, gatewayAddress, serializer);
	} catch (IOException e) {
		throw new SqlClientException("Could not start socket for result retrieval.", e);
	}

	// create table sink
	// pass binding address and port such that sink knows where to send to
	collectTableSink = new CollectStreamTableSink(iterator.getBindAddress(), iterator.getPort(), serializer, tableSchema);
	retrievalThread = new ResultRetrievalThread();

	this.classLoader = checkNotNull(classLoader);
}
 
Example 2
Source File: SiddhiTypeFactoryTest.java    From bahir-flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testTypeInfoParser() {
    TypeInformation<Tuple3<String, Long, Object>> type1 =
            Types.TUPLE(Types.STRING, Types.LONG, Types.GENERIC(Object.class));
    Assert.assertNotNull(type1);
    TypeInformation<Tuple4<String, Long, Object, InnerPojo>> type2 =
            Types.TUPLE(Types.STRING, Types.LONG, Types.GENERIC(Object.class), Types.GENERIC(InnerPojo.class));
    Assert.assertNotNull(type2);
}
 
Example 3
Source File: StreamSchemaTest.java    From bahir-flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testStreamTupleSerializerWithTuple() {
    TypeInformation<Tuple4> typeInfo = Types.GENERIC(Tuple4.class);
    StreamSchema<Tuple4> schema = new StreamSchema<>(typeInfo, "id", "timestamp", "name", "price");
    assertEquals(Tuple4.class, schema.getTypeInfo().getTypeClass());
    TypeInformation<Tuple2<String, Tuple4>> tuple2TypeInformation = Types.TUPLE(Types.STRING, schema.getTypeInfo());
    assertEquals("Java Tuple2<String, GenericType<" + Tuple4.class.getName() + ">>", tuple2TypeInformation.toString());
}
 
Example 4
Source File: StreamSchemaTest.java    From bahir-flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testStreamSchemaWithTuple() {
    TypeInformation<Tuple4<Integer,Long,String,Double>> typeInfo = Types.TUPLE(Types.INT, Types.LONG, Types.STRING, Types.DOUBLE);
    StreamSchema<Tuple4<Integer,Long,String,Double>> schema = new StreamSchema<>(typeInfo, "id", "timestamp", "name", "price");
    assertEquals(Tuple4.class, schema.getTypeInfo().getTypeClass());
    assertEquals(4, schema.getFieldIndexes().length);
    assertEquals(Tuple4.class, schema.getTypeInfo().getTypeClass());
}
 
Example 5
Source File: StreamSchemaTest.java    From flink-siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void testStreamTupleSerializerWithPrimitive() {
    TypeInformation<String> typeInfo = TypeInformation.of(new TypeHint<String>() {});
    StreamSchema<String> schema = new StreamSchema<>(typeInfo, "words");
    assertEquals(String.class, schema.getTypeInfo().getTypeClass());
    TypeInformation<Tuple2<String, String>> tuple2TypeInformation = Types.TUPLE(TypeInformation.of(String.class), schema.getTypeInfo());
    assertEquals("Java Tuple2<String, String>", tuple2TypeInformation.toString());
}
 
Example 6
Source File: StreamSchemaTest.java    From bahir-flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testStreamTupleSerializerWithPrimitive() {
    TypeInformation<String> typeInfo = Types.STRING;
    StreamSchema<String> schema = new StreamSchema<>(typeInfo, "words");
    assertEquals(String.class, schema.getTypeInfo().getTypeClass());
    TypeInformation<Tuple2<String, String>> tuple2TypeInformation = Types.TUPLE(Types.STRING, schema.getTypeInfo());
    assertEquals("Java Tuple2<String, String>", tuple2TypeInformation.toString());
}
 
Example 7
Source File: StreamSchemaTest.java    From flink-siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void testStreamTupleSerializerWithTuple() {
    TypeInformation<Tuple4<Integer,Long,String,Double>> typeInfo = TypeInformation.of(new TypeHint<Tuple4<Integer,Long,String,Double>>() {});
    StreamSchema<Tuple4<Integer,Long,String,Double>> schema = new StreamSchema<>(typeInfo, "id", "timestamp", "name", "price");
    assertEquals(Tuple4.class, schema.getTypeInfo().getTypeClass());
    TypeInformation<Tuple2<String, Tuple4>> tuple2TypeInformation = Types.TUPLE(TypeInformation.of(String.class), schema.getTypeInfo());
    assertEquals("Java Tuple2<String, Java Tuple4<Integer, Long, String, Double>>", tuple2TypeInformation.toString());
}
 
Example 8
Source File: StreamSchemaTest.java    From flink-siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void testStreamTupleSerializerWithPojo() {
    TypeInformation<Event> typeInfo = TypeExtractor.createTypeInfo(Event.class);
    assertTrue("Type information should be PojoTypeInfo", typeInfo instanceof PojoTypeInfo);
    StreamSchema<Event> schema = new StreamSchema<>(typeInfo, "id", "timestamp", "name", "price");
    assertEquals(Event.class, schema.getTypeInfo().getTypeClass());

    TypeInformation<Tuple2<String, Event>> tuple2TypeInformation = Types.TUPLE(TypeInformation.of(String.class), schema.getTypeInfo());
    assertEquals("Java Tuple2<String, PojoType<org.apache.flink.streaming.siddhi.source.Event, fields = [id: Integer, name: String, price: Double, timestamp: Long]>>", tuple2TypeInformation.toString());
}
 
Example 9
Source File: SiddhiTypeFactory.java    From flink-siddhi with Apache License 2.0 5 votes vote down vote up
public static <T extends Tuple> TypeInformation<T> getTupleTypeInformation(AbstractDefinition definition) {
    List<TypeInformation> types = new ArrayList<>();
    for (Attribute attribute : definition.getAttributeList()) {
        types.add(TypeInformation.of(getJavaType(attribute.getType())));
    }
    try {
        return Types.TUPLE(types.toArray(new TypeInformation[0]));
    } catch (IllegalArgumentException ex) {
        throw new IllegalArgumentException("Unable to parse ", ex);
    }
}
 
Example 10
Source File: UDTFStreamOpTest.java    From Alink with Apache License 2.0 4 votes vote down vote up
@Override
public TypeInformation<Tuple2<String, Long>> getResultType() {
    return Types.TUPLE(Types.STRING, Types.LONG);
}
 
Example 11
Source File: ElasticsearchUpsertTableSinkBase.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public TypeInformation<Tuple2<Boolean, Row>> getOutputType() {
	return Types.TUPLE(Types.BOOLEAN, getRecordType());
}
 
Example 12
Source File: SiddhiTypeFactory.java    From flink-siddhi with Apache License 2.0 4 votes vote down vote up
public static <T> TypeInformation<Tuple2<StreamRoute, T>> getStreamTupleTypeInformation(TypeInformation<T> typeInformation) {
    return Types.TUPLE(TypeInformation.of(StreamRoute.class), typeInformation);
}
 
Example 13
Source File: UDTFBatchOpTest.java    From Alink with Apache License 2.0 4 votes vote down vote up
@Override
public TypeInformation<Tuple2<String, Long>> getResultType() {
    return Types.TUPLE(Types.STRING, Types.LONG);
}
 
Example 14
Source File: Elasticsearch6UpsertTableSinkFactoryTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Test
public void testBuilder() {
	final TableSchema schema = createTestSchema();

	final TestElasticsearch6UpsertTableSink testSink = new TestElasticsearch6UpsertTableSink(
		false,
		schema,
		Collections.singletonList(new Host(HOSTNAME, PORT, SCHEMA)),
		INDEX,
		DOC_TYPE,
		KEY_DELIMITER,
		KEY_NULL_LITERAL,
		new JsonRowSerializationSchema(schema.toRowType()),
		XContentType.JSON,
		new DummyFailureHandler(),
		createTestSinkOptions());

	final DataStreamMock dataStreamMock = new DataStreamMock(
			new StreamExecutionEnvironmentMock(),
			Types.TUPLE(Types.BOOLEAN, schema.toRowType()));

	testSink.emitDataStream(dataStreamMock);

	final ElasticsearchSink.Builder<Tuple2<Boolean, Row>> expectedBuilder = new ElasticsearchSink.Builder<>(
		Collections.singletonList(new HttpHost(HOSTNAME, PORT, SCHEMA)),
		new ElasticsearchUpsertSinkFunction(
			INDEX,
			DOC_TYPE,
			KEY_DELIMITER,
			KEY_NULL_LITERAL,
			new JsonRowSerializationSchema(schema.toRowType()),
			XContentType.JSON,
			Elasticsearch6UpsertTableSink.UPDATE_REQUEST_FACTORY,
			new int[0]));
	expectedBuilder.setFailureHandler(new DummyFailureHandler());
	expectedBuilder.setBulkFlushBackoff(true);
	expectedBuilder.setBulkFlushBackoffType(ElasticsearchSinkBase.FlushBackoffType.EXPONENTIAL);
	expectedBuilder.setBulkFlushBackoffDelay(123);
	expectedBuilder.setBulkFlushBackoffRetries(3);
	expectedBuilder.setBulkFlushInterval(100);
	expectedBuilder.setBulkFlushMaxActions(1000);
	expectedBuilder.setBulkFlushMaxSizeMb(1);
	expectedBuilder.setRestClientFactory(new DefaultRestClientFactory(100, "/myapp"));

	assertEquals(expectedBuilder, testSink.builder);
}
 
Example 15
Source File: PeriodicStreamingJob.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public TypeInformation<Tuple> getProducedType() {
	return Types.TUPLE(Types.LONG, Types.STRING);
}
 
Example 16
Source File: PeriodicStreamingJob.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public TypeInformation<Tuple> getProducedType() {
	return Types.TUPLE(Types.LONG, Types.STRING);
}
 
Example 17
Source File: LogicalTypesTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testTypeInformationAnyType() {
	final TypeInformationAnyType<?> anyType = new TypeInformationAnyType<>(Types.TUPLE(Types.STRING, Types.INT));

	testEquality(anyType, new TypeInformationAnyType<>(Types.TUPLE(Types.STRING, Types.LONG)));

	testStringSummary(anyType, "ANY('org.apache.flink.api.java.tuple.Tuple2', ?)");

	testNullability(anyType);

	testJavaSerializability(anyType);

	testConversions(anyType, new Class[]{Tuple2.class}, new Class[]{Tuple.class});

	testInvalidStringSerializability(anyType);
}
 
Example 18
Source File: Elasticsearch6UpsertTableSinkFactoryTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testBuilder() {
	final TableSchema schema = createTestSchema();

	final TestElasticsearch6UpsertTableSink testSink = new TestElasticsearch6UpsertTableSink(
		false,
		schema,
		Collections.singletonList(new Host(HOSTNAME, PORT, SCHEMA)),
		INDEX,
		DOC_TYPE,
		KEY_DELIMITER,
		KEY_NULL_LITERAL,
		new JsonRowSerializationSchema(schema.toRowType()),
		XContentType.JSON,
		new DummyFailureHandler(),
		createTestSinkOptions());

	final DataStreamMock dataStreamMock = new DataStreamMock(
			new StreamExecutionEnvironmentMock(),
			Types.TUPLE(Types.BOOLEAN, schema.toRowType()));

	testSink.emitDataStream(dataStreamMock);

	final ElasticsearchSink.Builder<Tuple2<Boolean, Row>> expectedBuilder = new ElasticsearchSink.Builder<>(
		Collections.singletonList(new HttpHost(HOSTNAME, PORT, SCHEMA)),
		new ElasticsearchUpsertSinkFunction(
			INDEX,
			DOC_TYPE,
			KEY_DELIMITER,
			KEY_NULL_LITERAL,
			new JsonRowSerializationSchema(schema.toRowType()),
			XContentType.JSON,
			Elasticsearch6UpsertTableSink.UPDATE_REQUEST_FACTORY,
			new int[0]));
	expectedBuilder.setFailureHandler(new DummyFailureHandler());
	expectedBuilder.setBulkFlushBackoff(true);
	expectedBuilder.setBulkFlushBackoffType(ElasticsearchSinkBase.FlushBackoffType.EXPONENTIAL);
	expectedBuilder.setBulkFlushBackoffDelay(123);
	expectedBuilder.setBulkFlushBackoffRetries(3);
	expectedBuilder.setBulkFlushInterval(100);
	expectedBuilder.setBulkFlushMaxActions(1000);
	expectedBuilder.setBulkFlushMaxSizeMb(1);
	expectedBuilder.setRestClientFactory(new DefaultRestClientFactory(100, "/myapp"));

	assertEquals(expectedBuilder, testSink.builder);
}
 
Example 19
Source File: LogicalTypesTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testTypeInformationRawType() {
	final TypeInformationRawType<?> rawType = new TypeInformationRawType<>(Types.TUPLE(Types.STRING, Types.INT));

	testEquality(rawType, new TypeInformationRawType<>(Types.TUPLE(Types.STRING, Types.LONG)));

	testStringSummary(rawType, "RAW('org.apache.flink.api.java.tuple.Tuple2', ?)");

	testNullability(rawType);

	testJavaSerializability(rawType);

	testConversions(rawType, new Class[]{Tuple2.class}, new Class[]{Tuple.class});

	testInvalidStringSerializability(rawType);
}
 
Example 20
Source File: ElasticsearchUpsertTableSinkBase.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public TypeInformation<Tuple2<Boolean, Row>> getOutputType() {
	return Types.TUPLE(Types.BOOLEAN, getRecordType());
}