org.apache.flink.table.sources.wmstrategies.AscendingTimestamps Java Examples
The following examples show how to use
org.apache.flink.table.sources.wmstrategies.AscendingTimestamps.
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: Watermarks.java From alchemy with Apache License 2.0 | 5 votes |
public WatermarkStrategy get() { if (type == null) { return null; } if (type.equals(Type.PERIODIC_ASCENDING.getType())) { return new AscendingTimestamps(); } else if (type.equals(Type.PERIODIC_BOUNDED.getType())) { return new BoundedOutOfOrderTimestamps(delay); } else if (type.equals(Type.FROM_SOURCE.getType())) { return new PreserveWatermarks(); } return null; }
Example #2
Source File: KafkaTableSourceSinkFactoryTestBase.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
@Test @SuppressWarnings("unchecked") public void testTableSource() { // prepare parameters for Kafka table source final TableSchema schema = TableSchema.builder() .field(FRUIT_NAME, Types.STRING()) .field(COUNT, Types.DECIMAL()) .field(EVENT_TIME, Types.SQL_TIMESTAMP()) .field(PROC_TIME, Types.SQL_TIMESTAMP()) .build(); final List<RowtimeAttributeDescriptor> rowtimeAttributeDescriptors = Collections.singletonList( new RowtimeAttributeDescriptor(EVENT_TIME, new ExistingField(TIME), new AscendingTimestamps())); final Map<String, String> fieldMapping = new HashMap<>(); fieldMapping.put(FRUIT_NAME, NAME); fieldMapping.put(NAME, NAME); fieldMapping.put(COUNT, COUNT); fieldMapping.put(TIME, TIME); final Map<KafkaTopicPartition, Long> specificOffsets = new HashMap<>(); specificOffsets.put(new KafkaTopicPartition(TOPIC, PARTITION_0), OFFSET_0); specificOffsets.put(new KafkaTopicPartition(TOPIC, PARTITION_1), OFFSET_1); final TestDeserializationSchema deserializationSchema = new TestDeserializationSchema( TableSchema.builder() .field(NAME, Types.STRING()) .field(COUNT, Types.DECIMAL()) .field(TIME, Types.SQL_TIMESTAMP()) .build() .toRowType() ); final KafkaTableSourceBase expected = getExpectedKafkaTableSource( schema, Optional.of(PROC_TIME), rowtimeAttributeDescriptors, fieldMapping, TOPIC, KAFKA_PROPERTIES, deserializationSchema, StartupMode.SPECIFIC_OFFSETS, specificOffsets); TableSourceUtil.validateTableSource(expected); // construct table source using descriptors and table source factory final TestTableDescriptor testDesc = new TestTableDescriptor( new Kafka() .version(getKafkaVersion()) .topic(TOPIC) .properties(KAFKA_PROPERTIES) .sinkPartitionerRoundRobin() // test if accepted although not needed .startFromSpecificOffsets(OFFSETS)) .withFormat(new TestTableFormat()) .withSchema( new Schema() .field(FRUIT_NAME, Types.STRING()).from(NAME) .field(COUNT, Types.DECIMAL()) // no from so it must match with the input .field(EVENT_TIME, Types.SQL_TIMESTAMP()).rowtime( new Rowtime().timestampsFromField(TIME).watermarksPeriodicAscending()) .field(PROC_TIME, Types.SQL_TIMESTAMP()).proctime()) .inAppendMode(); final Map<String, String> propertiesMap = testDesc.toProperties(); final TableSource<?> actualSource = TableFactoryService.find(StreamTableSourceFactory.class, propertiesMap) .createStreamTableSource(propertiesMap); assertEquals(expected, actualSource); // test Kafka consumer final KafkaTableSourceBase actualKafkaSource = (KafkaTableSourceBase) actualSource; final StreamExecutionEnvironmentMock mock = new StreamExecutionEnvironmentMock(); actualKafkaSource.getDataStream(mock); assertTrue(getExpectedFlinkKafkaConsumer().isAssignableFrom(mock.sourceFunction.getClass())); }
Example #3
Source File: KafkaTableSourceSinkFactoryTestBase.java From flink with Apache License 2.0 | 4 votes |
@Test @SuppressWarnings("unchecked") public void testTableSource() { // prepare parameters for Kafka table source final TableSchema schema = TableSchema.builder() .field(FRUIT_NAME, Types.STRING()) .field(COUNT, Types.DECIMAL()) .field(EVENT_TIME, Types.SQL_TIMESTAMP()) .field(PROC_TIME, Types.SQL_TIMESTAMP()) .build(); final List<RowtimeAttributeDescriptor> rowtimeAttributeDescriptors = Collections.singletonList( new RowtimeAttributeDescriptor(EVENT_TIME, new ExistingField(TIME), new AscendingTimestamps())); final Map<String, String> fieldMapping = new HashMap<>(); fieldMapping.put(FRUIT_NAME, NAME); fieldMapping.put(NAME, NAME); fieldMapping.put(COUNT, COUNT); fieldMapping.put(TIME, TIME); final Map<KafkaTopicPartition, Long> specificOffsets = new HashMap<>(); specificOffsets.put(new KafkaTopicPartition(TOPIC, PARTITION_0), OFFSET_0); specificOffsets.put(new KafkaTopicPartition(TOPIC, PARTITION_1), OFFSET_1); final TestDeserializationSchema deserializationSchema = new TestDeserializationSchema( TableSchema.builder() .field(NAME, Types.STRING()) .field(COUNT, Types.DECIMAL()) .field(TIME, Types.SQL_TIMESTAMP()) .build() .toRowType() ); final KafkaTableSourceBase expected = getExpectedKafkaTableSource( schema, Optional.of(PROC_TIME), rowtimeAttributeDescriptors, fieldMapping, TOPIC, KAFKA_PROPERTIES, deserializationSchema, StartupMode.SPECIFIC_OFFSETS, specificOffsets); TableSourceValidation.validateTableSource(expected); // construct table source using descriptors and table source factory final TestTableDescriptor testDesc = new TestTableDescriptor( new Kafka() .version(getKafkaVersion()) .topic(TOPIC) .properties(KAFKA_PROPERTIES) .sinkPartitionerRoundRobin() // test if accepted although not needed .startFromSpecificOffsets(OFFSETS)) .withFormat(new TestTableFormat()) .withSchema( new Schema() .field(FRUIT_NAME, Types.STRING()).from(NAME) .field(COUNT, Types.DECIMAL()) // no from so it must match with the input .field(EVENT_TIME, Types.SQL_TIMESTAMP()).rowtime( new Rowtime().timestampsFromField(TIME).watermarksPeriodicAscending()) .field(PROC_TIME, Types.SQL_TIMESTAMP()).proctime()) .inAppendMode(); final Map<String, String> propertiesMap = testDesc.toProperties(); final TableSource<?> actualSource = TableFactoryService.find(StreamTableSourceFactory.class, propertiesMap) .createStreamTableSource(propertiesMap); assertEquals(expected, actualSource); // test Kafka consumer final KafkaTableSourceBase actualKafkaSource = (KafkaTableSourceBase) actualSource; final StreamExecutionEnvironmentMock mock = new StreamExecutionEnvironmentMock(); actualKafkaSource.getDataStream(mock); assertTrue(getExpectedFlinkKafkaConsumer().isAssignableFrom(mock.sourceFunction.getClass())); }
Example #4
Source File: KafkaTableSourceSinkFactoryTestBase.java From flink with Apache License 2.0 | 4 votes |
@Test @SuppressWarnings("unchecked") public void testTableSource() { // prepare parameters for Kafka table source final TableSchema schema = TableSchema.builder() .field(FRUIT_NAME, DataTypes.STRING()) .field(COUNT, DataTypes.DECIMAL(38, 18)) .field(EVENT_TIME, DataTypes.TIMESTAMP(3)) .field(PROC_TIME, DataTypes.TIMESTAMP(3)) .build(); final List<RowtimeAttributeDescriptor> rowtimeAttributeDescriptors = Collections.singletonList( new RowtimeAttributeDescriptor(EVENT_TIME, new ExistingField(TIME), new AscendingTimestamps())); final Map<String, String> fieldMapping = new HashMap<>(); fieldMapping.put(FRUIT_NAME, NAME); fieldMapping.put(NAME, NAME); fieldMapping.put(COUNT, COUNT); fieldMapping.put(TIME, TIME); final Map<KafkaTopicPartition, Long> specificOffsets = new HashMap<>(); specificOffsets.put(new KafkaTopicPartition(TOPIC, PARTITION_0), OFFSET_0); specificOffsets.put(new KafkaTopicPartition(TOPIC, PARTITION_1), OFFSET_1); final TestDeserializationSchema deserializationSchema = new TestDeserializationSchema( TableSchema.builder() .field(NAME, DataTypes.STRING()) .field(COUNT, DataTypes.DECIMAL(38, 18)) .field(TIME, DataTypes.TIMESTAMP(3)) .build().toRowType() ); final KafkaTableSourceBase expected = getExpectedKafkaTableSource( schema, Optional.of(PROC_TIME), rowtimeAttributeDescriptors, fieldMapping, TOPIC, KAFKA_PROPERTIES, deserializationSchema, StartupMode.SPECIFIC_OFFSETS, specificOffsets, 0L); TableSourceValidation.validateTableSource(expected, schema); // construct table source using descriptors and table source factory final Map<String, String> propertiesMap = new HashMap<>(); propertiesMap.putAll(createKafkaSourceProperties()); propertiesMap.put("schema.watermark.0.rowtime", EVENT_TIME); propertiesMap.put("schema.watermark.0.strategy.expr", WATERMARK_EXPRESSION); propertiesMap.put("schema.watermark.0.strategy.data-type", WATERMARK_DATATYPE.toString()); propertiesMap.put("schema.4.name", COMPUTED_COLUMN_NAME); propertiesMap.put("schema.4.data-type", COMPUTED_COLUMN_DATATYPE.toString()); propertiesMap.put("schema.4.expr", COMPUTED_COLUMN_EXPRESSION); final TableSource<?> actualSource = TableFactoryService.find(StreamTableSourceFactory.class, propertiesMap) .createStreamTableSource(propertiesMap); assertEquals(expected, actualSource); // test Kafka consumer final KafkaTableSourceBase actualKafkaSource = (KafkaTableSourceBase) actualSource; final StreamExecutionEnvironmentMock mock = new StreamExecutionEnvironmentMock(); actualKafkaSource.getDataStream(mock); assertTrue(getExpectedFlinkKafkaConsumer().isAssignableFrom(mock.sourceFunction.getClass())); // Test commitOnCheckpoints flag should be true when set consumer group. assertTrue(((FlinkKafkaConsumerBase) mock.sourceFunction).getEnableCommitOnCheckpoints()); }
Example #5
Source File: KafkaTableSourceSinkFactoryTestBase.java From flink with Apache License 2.0 | 4 votes |
@Test @SuppressWarnings("unchecked") public void testTableSourceWithLegacyProperties() { // prepare parameters for Kafka table source final TableSchema schema = TableSchema.builder() .field(FRUIT_NAME, DataTypes.STRING()) .field(COUNT, DataTypes.DECIMAL(38, 18)) .field(EVENT_TIME, DataTypes.TIMESTAMP(3)) .field(PROC_TIME, DataTypes.TIMESTAMP(3)) .build(); final List<RowtimeAttributeDescriptor> rowtimeAttributeDescriptors = Collections.singletonList( new RowtimeAttributeDescriptor(EVENT_TIME, new ExistingField(TIME), new AscendingTimestamps())); final Map<String, String> fieldMapping = new HashMap<>(); fieldMapping.put(FRUIT_NAME, NAME); fieldMapping.put(NAME, NAME); fieldMapping.put(COUNT, COUNT); fieldMapping.put(TIME, TIME); final Map<KafkaTopicPartition, Long> specificOffsets = new HashMap<>(); specificOffsets.put(new KafkaTopicPartition(TOPIC, PARTITION_0), OFFSET_0); specificOffsets.put(new KafkaTopicPartition(TOPIC, PARTITION_1), OFFSET_1); final TestDeserializationSchema deserializationSchema = new TestDeserializationSchema( TableSchema.builder() .field(NAME, DataTypes.STRING()) .field(COUNT, DataTypes.DECIMAL(38, 18)) .field(TIME, DataTypes.TIMESTAMP(3)) .build().toRowType() ); final KafkaTableSourceBase expected = getExpectedKafkaTableSource( schema, Optional.of(PROC_TIME), rowtimeAttributeDescriptors, fieldMapping, TOPIC, KAFKA_PROPERTIES, deserializationSchema, StartupMode.SPECIFIC_OFFSETS, specificOffsets, 0L); TableSourceValidation.validateTableSource(expected, schema); // construct table source using descriptors and table source factory final Map<String, String> legacyPropertiesMap = new HashMap<>(); legacyPropertiesMap.putAll(createKafkaSourceProperties()); // use legacy properties legacyPropertiesMap.remove("connector.specific-offsets"); legacyPropertiesMap.remove("connector.properties.bootstrap.servers"); legacyPropertiesMap.remove("connector.properties.group.id"); // keep compatible with a specified update-mode legacyPropertiesMap.put("update-mode", "append"); // legacy properties for specific-offsets and properties legacyPropertiesMap.put("connector.specific-offsets.0.partition", "0"); legacyPropertiesMap.put("connector.specific-offsets.0.offset", "100"); legacyPropertiesMap.put("connector.specific-offsets.1.partition", "1"); legacyPropertiesMap.put("connector.specific-offsets.1.offset", "123"); legacyPropertiesMap.put("connector.properties.0.key", "bootstrap.servers"); legacyPropertiesMap.put("connector.properties.0.value", "dummy"); legacyPropertiesMap.put("connector.properties.1.key", "group.id"); legacyPropertiesMap.put("connector.properties.1.value", "dummy"); final TableSource<?> actualSource = TableFactoryService.find(StreamTableSourceFactory.class, legacyPropertiesMap) .createStreamTableSource(legacyPropertiesMap); assertEquals(expected, actualSource); // test Kafka consumer final KafkaTableSourceBase actualKafkaSource = (KafkaTableSourceBase) actualSource; final StreamExecutionEnvironmentMock mock = new StreamExecutionEnvironmentMock(); actualKafkaSource.getDataStream(mock); assertTrue(getExpectedFlinkKafkaConsumer().isAssignableFrom(mock.sourceFunction.getClass())); }