Java Code Examples for org.apache.flink.table.descriptors.SchemaValidator#deriveProctimeAttribute()

The following examples show how to use org.apache.flink.table.descriptors.SchemaValidator#deriveProctimeAttribute() . 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: KafkaTableSourceSinkFactoryBase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public StreamTableSink<Row> createStreamTableSink(Map<String, String> properties) {
	final DescriptorProperties descriptorProperties = getValidatedProperties(properties);

	final TableSchema schema = descriptorProperties.getTableSchema(SCHEMA());
	final String topic = descriptorProperties.getString(CONNECTOR_TOPIC);
	final Optional<String> proctime = SchemaValidator.deriveProctimeAttribute(descriptorProperties);
	final List<RowtimeAttributeDescriptor> rowtimeAttributeDescriptors =
		SchemaValidator.deriveRowtimeAttributes(descriptorProperties);

	// see also FLINK-9870
	if (proctime.isPresent() || !rowtimeAttributeDescriptors.isEmpty() ||
			checkForCustomFieldMapping(descriptorProperties, schema)) {
		throw new TableException("Time attributes and custom field mappings are not supported yet.");
	}

	return createKafkaTableSink(
		schema,
		topic,
		getKafkaProperties(descriptorProperties),
		getFlinkKafkaPartitioner(descriptorProperties),
		getSerializationSchema(properties));
}
 
Example 2
Source File: KafkaTableSourceSinkFactoryBase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public StreamTableSink<Row> createStreamTableSink(Map<String, String> properties) {
	final DescriptorProperties descriptorProperties = getValidatedProperties(properties);

	final TableSchema schema = descriptorProperties.getTableSchema(SCHEMA);
	final String topic = descriptorProperties.getString(CONNECTOR_TOPIC);
	final Optional<String> proctime = SchemaValidator.deriveProctimeAttribute(descriptorProperties);
	final List<RowtimeAttributeDescriptor> rowtimeAttributeDescriptors =
		SchemaValidator.deriveRowtimeAttributes(descriptorProperties);

	// see also FLINK-9870
	if (proctime.isPresent() || !rowtimeAttributeDescriptors.isEmpty() ||
			checkForCustomFieldMapping(descriptorProperties, schema)) {
		throw new TableException("Time attributes and custom field mappings are not supported yet.");
	}

	return createKafkaTableSink(
		schema,
		topic,
		getKafkaProperties(descriptorProperties),
		getFlinkKafkaPartitioner(descriptorProperties),
		getSerializationSchema(properties));
}
 
Example 3
Source File: KafkaTableSourceSinkFactoryBase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public StreamTableSink<Row> createStreamTableSink(Map<String, String> properties) {
	final DescriptorProperties descriptorProperties = getValidatedProperties(properties);

	final TableSchema schema = TableSchemaUtils.getPhysicalSchema(
		descriptorProperties.getTableSchema(SCHEMA));
	final String topic = descriptorProperties.getString(CONNECTOR_TOPIC);
	final Optional<String> proctime = SchemaValidator.deriveProctimeAttribute(descriptorProperties);
	final List<RowtimeAttributeDescriptor> rowtimeAttributeDescriptors =
		SchemaValidator.deriveRowtimeAttributes(descriptorProperties);

	// see also FLINK-9870
	if (proctime.isPresent() || !rowtimeAttributeDescriptors.isEmpty() ||
			checkForCustomFieldMapping(descriptorProperties, schema)) {
		throw new TableException("Time attributes and custom field mappings are not supported yet.");
	}

	return createKafkaTableSink(
		schema,
		topic,
		getKafkaProperties(descriptorProperties),
		getFlinkKafkaPartitioner(descriptorProperties),
		getSerializationSchema(properties));
}
 
Example 4
Source File: TestTableSourceFactoryBase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public StreamTableSource<Row> createStreamTableSource(Map<String, String> properties) {
	final DescriptorProperties params = new DescriptorProperties(true);
	params.putProperties(properties);
	final Optional<String> proctime = SchemaValidator.deriveProctimeAttribute(params);
	final List<RowtimeAttributeDescriptor> rowtime = SchemaValidator.deriveRowtimeAttributes(params);
	return new TestTableSource(
		params.getTableSchema(SCHEMA()),
		properties.get(testProperty),
		proctime.orElse(null),
		rowtime);
}
 
Example 5
Source File: TestTableSourceFactoryBase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public StreamTableSource<Row> createStreamTableSource(Map<String, String> properties) {
	final DescriptorProperties params = new DescriptorProperties(true);
	params.putProperties(properties);
	final Optional<String> proctime = SchemaValidator.deriveProctimeAttribute(params);
	final List<RowtimeAttributeDescriptor> rowtime = SchemaValidator.deriveRowtimeAttributes(params);
	return new TestTableSource(
		params.getTableSchema(SCHEMA),
		properties.get(testProperty),
		proctime.orElse(null),
		rowtime);
}
 
Example 6
Source File: TestTableSourceFactoryBase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public StreamTableSource<Row> createTableSource(TableSourceFactory.Context context) {
	TableSchema schema = context.getTable().getSchema();
	final DescriptorProperties params = new DescriptorProperties(true);
	params.putProperties(context.getTable().toProperties());
	final Optional<String> proctime = SchemaValidator.deriveProctimeAttribute(params);
	final List<RowtimeAttributeDescriptor> rowtime = SchemaValidator.deriveRowtimeAttributes(params);
	return new TestTableSource(
		schema,
		context.getTable().getProperties().get(testProperty),
		proctime.orElse(null),
		rowtime);
}
 
Example 7
Source File: FlinkPravegaTableFactoryBase.java    From flink-connectors with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
protected FlinkPravegaTableSource createFlinkPravegaTableSource(Map<String, String> properties) {
    final DescriptorProperties descriptorProperties = getValidatedProperties(properties);
    final TableSchema schema = TableSchemaUtils.getPhysicalSchema(descriptorProperties.getTableSchema(SCHEMA));
    final DeserializationSchema<Row> deserializationSchema = getDeserializationSchema(properties);

    ConnectorConfigurations connectorConfigurations = new ConnectorConfigurations();
    connectorConfigurations.parseConfigurations(descriptorProperties, ConnectorConfigurations.ConfigurationType.READER);

    // create source from the reader builder by using the supplied properties
    TableSourceReaderBuilder tableSourceReaderBuilder = new Pravega().tableSourceReaderBuilder();
    tableSourceReaderBuilder.withDeserializationSchema(deserializationSchema);

    if (connectorConfigurations.getAssignerWithTimeWindows().isPresent()) {
        tableSourceReaderBuilder.withTimestampAssigner(connectorConfigurations.getAssignerWithTimeWindows().get());
    }

    if (connectorConfigurations.getUid().isPresent()) {
        tableSourceReaderBuilder.uid(connectorConfigurations.getUid().get());
    }
    if (connectorConfigurations.getRgScope().isPresent()) {
        tableSourceReaderBuilder.withReaderGroupScope(connectorConfigurations.getRgScope().get());
    }
    if (connectorConfigurations.getRgName().isPresent()) {
        tableSourceReaderBuilder.withReaderGroupName(connectorConfigurations.getRgName().get());
    }
    if (connectorConfigurations.getRefreshInterval().isPresent()) {
        tableSourceReaderBuilder.withReaderGroupRefreshTime(Time.milliseconds(connectorConfigurations.getRefreshInterval().get()));
    }
    if (connectorConfigurations.getEventReadTimeoutInterval().isPresent()) {
        tableSourceReaderBuilder.withEventReadTimeout(Time.milliseconds(connectorConfigurations.getEventReadTimeoutInterval().get()));
    }
    if (connectorConfigurations.getCheckpointInitiateTimeoutInterval().isPresent()) {
        tableSourceReaderBuilder.withCheckpointInitiateTimeout(Time.milliseconds(connectorConfigurations.getCheckpointInitiateTimeoutInterval().get()));
    }

    tableSourceReaderBuilder.withPravegaConfig(connectorConfigurations.getPravegaConfig());
    if (connectorConfigurations.getMetrics().isPresent()) {
        tableSourceReaderBuilder.enableMetrics(connectorConfigurations.getMetrics().get());
    }
    tableSourceReaderBuilder.withPravegaConfig(connectorConfigurations.getPravegaConfig());
    for (StreamWithBoundaries streamWithBoundaries: connectorConfigurations.getReaderStreams()) {
        if (streamWithBoundaries.getFrom() != StreamCut.UNBOUNDED && streamWithBoundaries.getTo() != StreamCut.UNBOUNDED) {
            tableSourceReaderBuilder.forStream(streamWithBoundaries.getStream(), streamWithBoundaries.getFrom(), streamWithBoundaries.getTo());
        } else if (streamWithBoundaries.getFrom() != StreamCut.UNBOUNDED) {
            tableSourceReaderBuilder.forStream(streamWithBoundaries.getStream(), streamWithBoundaries.getFrom());
        } else {
            tableSourceReaderBuilder.forStream(streamWithBoundaries.getStream());
        }
    }

    FlinkPravegaTableSource flinkPravegaTableSource = new FlinkPravegaTableSource(
                                                                tableSourceReaderBuilder::buildSourceFunction,
                                                                tableSourceReaderBuilder::buildInputFormat, schema);
    flinkPravegaTableSource.setRowtimeAttributeDescriptors(SchemaValidator.deriveRowtimeAttributes(descriptorProperties));
    Optional<String> procTimeAttribute = SchemaValidator.deriveProctimeAttribute(descriptorProperties);
    if (procTimeAttribute.isPresent()) {
        flinkPravegaTableSource.setProctimeAttribute(procTimeAttribute.get());
    }

    return flinkPravegaTableSource;
}