本文整理汇总了Java中org.apache.flink.table.sources.RowtimeAttributeDescriptor类的典型用法代码示例。如果您正苦于以下问题:Java RowtimeAttributeDescriptor类的具体用法?Java RowtimeAttributeDescriptor怎么用?Java RowtimeAttributeDescriptor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RowtimeAttributeDescriptor类属于org.apache.flink.table.sources包,在下文中一共展示了RowtimeAttributeDescriptor类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: withRowtimeAttribute
import org.apache.flink.table.sources.RowtimeAttributeDescriptor; //导入依赖的package包/类
/**
* Configures a field of the table to be a rowtime attribute.
* The configured field must be present in the table schema and of type {@link Types#SQL_TIMESTAMP()}.
*
* @param rowtimeAttribute The name of the rowtime attribute in the table schema.
* @param timestampExtractor The {@link TimestampExtractor} to extract the rowtime attribute from the physical type.
* @param watermarkStrategy The {@link WatermarkStrategy} to generate watermarks for the rowtime attribute.
* @return The builder.
*/
public B withRowtimeAttribute(
String rowtimeAttribute,
TimestampExtractor timestampExtractor,
WatermarkStrategy watermarkStrategy) {
Preconditions.checkNotNull(rowtimeAttribute, "Rowtime attribute must not be null.");
Preconditions.checkArgument(!rowtimeAttribute.isEmpty(), "Rowtime attribute must not be empty.");
Preconditions.checkNotNull(timestampExtractor, "Timestamp extractor must not be null.");
Preconditions.checkNotNull(watermarkStrategy, "Watermark assigner must not be null.");
Preconditions.checkArgument(this.rowtimeAttributeDescriptor == null,
"Currently, only one rowtime attribute is supported.");
this.rowtimeAttributeDescriptor = new RowtimeAttributeDescriptor(
rowtimeAttribute,
timestampExtractor,
watermarkStrategy);
return builder();
}
示例2: withKafkaTimestampAsRowtimeAttribute
import org.apache.flink.table.sources.RowtimeAttributeDescriptor; //导入依赖的package包/类
/**
* Configures the Kafka timestamp to be a rowtime attribute.
*
* <p>Note: Kafka supports message timestamps only since version 0.10.</p>
*
* @param rowtimeAttribute The name of the rowtime attribute in the table schema.
* @param watermarkStrategy The {@link WatermarkStrategy} to generate watermarks for the rowtime attribute.
* @return The builder.
*/
public B withKafkaTimestampAsRowtimeAttribute(
String rowtimeAttribute,
WatermarkStrategy watermarkStrategy) {
Preconditions.checkNotNull(rowtimeAttribute, "Rowtime attribute must not be null.");
Preconditions.checkArgument(!rowtimeAttribute.isEmpty(), "Rowtime attribute must not be empty.");
Preconditions.checkNotNull(watermarkStrategy, "Watermark assigner must not be null.");
Preconditions.checkArgument(this.rowtimeAttributeDescriptor == null,
"Currently, only one rowtime attribute is supported.");
Preconditions.checkArgument(supportsKafkaTimestamps(), "Kafka timestamps are only supported since Kafka 0.10.");
this.rowtimeAttributeDescriptor = new RowtimeAttributeDescriptor(
rowtimeAttribute,
new StreamRecordTimestamp(),
watermarkStrategy);
return builder();
}
示例3: testRowtimeAttribute
import org.apache.flink.table.sources.RowtimeAttributeDescriptor; //导入依赖的package包/类
@Test
public void testRowtimeAttribute() {
KafkaTableSource.Builder b = getBuilder();
configureBuilder(b);
b.withRowtimeAttribute("time2", new ExistingField("time2"), new AscendingTimestamps());
KafkaTableSource source = b.build();
// assert no proctime
assertNull(source.getProctimeAttribute());
// assert correct rowtime descriptor
List<RowtimeAttributeDescriptor> descs = source.getRowtimeAttributeDescriptors();
assertNotNull(descs);
assertEquals(1, descs.size());
RowtimeAttributeDescriptor desc = descs.get(0);
assertEquals("time2", desc.getAttributeName());
// assert timestamp extractor
assertTrue(desc.getTimestampExtractor() instanceof ExistingField);
assertEquals(1, desc.getTimestampExtractor().getArgumentFields().length);
assertEquals("time2", desc.getTimestampExtractor().getArgumentFields()[0]);
// assert watermark strategy
assertTrue(desc.getWatermarkStrategy() instanceof AscendingTimestamps);
}
示例4: setRowtimeAttributeDescriptors
import org.apache.flink.table.sources.RowtimeAttributeDescriptor; //导入依赖的package包/类
/**
* Declares a list of fields to be rowtime attributes.
*
* @param rowtimeAttributeDescriptors The descriptors of the rowtime attributes.
*/
protected void setRowtimeAttributeDescriptors(List<RowtimeAttributeDescriptor> rowtimeAttributeDescriptors) {
// validate that all declared fields exist and are of correct type
for (RowtimeAttributeDescriptor desc : rowtimeAttributeDescriptors) {
String rowtimeAttribute = desc.getAttributeName();
Option<TypeInformation<?>> tpe = schema.getType(rowtimeAttribute);
if (tpe.isEmpty()) {
throw new ValidationException("Rowtime attribute " + rowtimeAttribute + " is not present in TableSchema.");
} else if (tpe.get() != Types.SQL_TIMESTAMP()) {
throw new ValidationException("Rowtime attribute " + rowtimeAttribute + " is not of type SQL_TIMESTAMP.");
}
}
this.rowtimeAttributeDescriptors = rowtimeAttributeDescriptors;
}
示例5: testRowtimeAttribute2
import org.apache.flink.table.sources.RowtimeAttributeDescriptor; //导入依赖的package包/类
@Test
public void testRowtimeAttribute2() {
KafkaTableSource.Builder b = getBuilder();
configureBuilder(b);
try {
b.withKafkaTimestampAsRowtimeAttribute("time2", new AscendingTimestamps());
KafkaTableSource source = b.build();
// assert no proctime
assertNull(source.getProctimeAttribute());
// assert correct rowtime descriptor
List<RowtimeAttributeDescriptor> descs = source.getRowtimeAttributeDescriptors();
assertNotNull(descs);
assertEquals(1, descs.size());
RowtimeAttributeDescriptor desc = descs.get(0);
assertEquals("time2", desc.getAttributeName());
// assert timestamp extractor
assertTrue(desc.getTimestampExtractor() instanceof StreamRecordTimestamp);
assertTrue(desc.getTimestampExtractor().getArgumentFields().length == 0);
// assert watermark strategy
assertTrue(desc.getWatermarkStrategy() instanceof AscendingTimestamps);
} catch (Exception e) {
if (b.supportsKafkaTimestamps()) {
// builder should support Kafka timestamps
fail();
}
}
}
示例6: getRowtimeAttributeDescriptors
import org.apache.flink.table.sources.RowtimeAttributeDescriptor; //导入依赖的package包/类
@Override
public List<RowtimeAttributeDescriptor> getRowtimeAttributeDescriptors() {
return rowtimeAttributeDescriptors;
}
示例7: getRowtimeAttributeDescriptors
import org.apache.flink.table.sources.RowtimeAttributeDescriptor; //导入依赖的package包/类
@Override
public List<RowtimeAttributeDescriptor> getRowtimeAttributeDescriptors() {
RowtimeAttributeDescriptor descriptor = new RowtimeAttributeDescriptor("eventTime", new StreamRecordTimestamp(), new PreserveWatermarks());
return Collections.singletonList(descriptor);
}
示例8: setRowtimeAttributeDescriptor
import org.apache.flink.table.sources.RowtimeAttributeDescriptor; //导入依赖的package包/类
/**
* Declares a field of the schema to be a rowtime attribute.
*
* @param rowtimeAttributeDescriptor The descriptor of the rowtime attribute.
*/
public void setRowtimeAttributeDescriptor(RowtimeAttributeDescriptor rowtimeAttributeDescriptor) {
Preconditions.checkNotNull(rowtimeAttributeDescriptor, "Rowtime attribute descriptor must not be null.");
super.setRowtimeAttributeDescriptors(Collections.singletonList(rowtimeAttributeDescriptor));
}