[ https://issues.apache.org/jira/browse/FLINK-3872?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15324377#comment-15324377 ]
ASF GitHub Bot commented on FLINK-3872: --------------------------------------- Github user uce commented on a diff in the pull request: https://github.com/apache/flink/pull/2069#discussion_r66606072 --- Diff: flink-streaming-connectors/flink-connector-kafka-base/src/main/java/org/apache/flink/streaming/connectors/kafka/KafkaTableSource.java --- @@ -0,0 +1,156 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.streaming.connectors.kafka; + +import org.apache.flink.api.common.typeinfo.TypeInformation; +import org.apache.flink.api.java.typeutils.TypeExtractor; +import org.apache.flink.api.table.Row; +import org.apache.flink.api.table.sources.StreamTableSource; +import org.apache.flink.api.table.typeutils.RowTypeInfo; +import org.apache.flink.streaming.api.datastream.DataStream; +import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; +import org.apache.flink.streaming.util.serialization.DeserializationSchema; +import org.apache.flink.util.Preconditions; + +import java.util.Properties; + +/** + * A version-agnostic Kafka {@link StreamTableSource}. + * + * <p>The version-specific Kafka consumers need to extend this class and + * override {@link #getKafkaConsumer(String, Properties, DeserializationSchema)}}. + */ +abstract class KafkaTableSource implements StreamTableSource<Row> { + + /** The Kafka topic to consume. */ + private final String topic; + + /** Properties for the Kafka consumer. */ + private final Properties properties; + + /** Deserialization schema to use for Kafka records. */ + private final DeserializationSchema<Row> deserializationSchema; + + /** Row field names. */ + private final String[] fieldNames; + + /** Row field types. */ + private final TypeInformation<?>[] fieldTypes; + + /** + * Creates a generic Kafka {@link StreamTableSource}. + * + * @param topic Kafka topic to consume. + * @param properties Properties for the Kafka consumer. + * @param deserializationSchema Deserialization schema to use for Kafka records. + * @param fieldNames Row field names. + * @param fieldTypes Row field types. + */ + KafkaTableSource( + String topic, + Properties properties, + DeserializationSchema<Row> deserializationSchema, + String[] fieldNames, + Class<?>[] fieldTypes) { + + this(topic, properties, deserializationSchema, fieldNames, toTypeInfo(fieldTypes)); + } + + /** + * Creates a generic Kafka {@link StreamTableSource}. + * + * @param topic Kafka topic to consume. + * @param properties Properties for the Kafka consumer. + * @param deserializationSchema Deserialization schema to use for Kafka records. + * @param fieldNames Row field names. + * @param fieldTypes Row field types. + */ + KafkaTableSource( + String topic, + Properties properties, + DeserializationSchema<Row> deserializationSchema, + String[] fieldNames, + TypeInformation<?>[] fieldTypes) { + + this.topic = Preconditions.checkNotNull(topic, "Topic"); + this.properties = Preconditions.checkNotNull(properties, "Properties"); + this.deserializationSchema = Preconditions.checkNotNull(deserializationSchema, "Deserialization schema"); + this.fieldNames = Preconditions.checkNotNull(fieldNames, "Field names"); + this.fieldTypes = Preconditions.checkNotNull(fieldTypes, "Field types"); + + Preconditions.checkArgument(fieldNames.length == fieldNames.length, --- End diff -- Yes! Good catch > Add Kafka TableSource with JSON serialization > --------------------------------------------- > > Key: FLINK-3872 > URL: https://issues.apache.org/jira/browse/FLINK-3872 > Project: Flink > Issue Type: New Feature > Components: Table API > Reporter: Fabian Hueske > Assignee: Ufuk Celebi > Fix For: 1.1.0 > > > Add a Kafka TableSource which reads JSON serialized data. -- This message was sent by Atlassian JIRA (v6.3.4#6332)