aljoscha commented on a change in pull request #12724: URL: https://github.com/apache/flink/pull/12724#discussion_r443508462
########## File path: flink-examples/flink-examples-table/src/main/java/org/apache/flink/table/examples/java/connectors/SocketDynamicTableSource.java ########## @@ -0,0 +1,88 @@ +/* + * 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.table.examples.java.connectors; + +import org.apache.flink.api.common.serialization.DeserializationSchema; +import org.apache.flink.streaming.api.functions.source.SourceFunction; +import org.apache.flink.table.connector.ChangelogMode; +import org.apache.flink.table.connector.format.DecodingFormat; +import org.apache.flink.table.connector.source.DynamicTableSource; +import org.apache.flink.table.connector.source.ScanTableSource; +import org.apache.flink.table.connector.source.SourceFunctionProvider; +import org.apache.flink.table.data.RowData; +import org.apache.flink.table.types.DataType; + +/** + * The {@link SocketDynamicTableSource} is used during planning. + * + * <p>In our example, we don't implement any of the available ability interfaces. Therefore, the main Review comment: Here the reader will not know what "ability interfaces" are. ########## File path: flink-examples/flink-examples-table/src/main/java/org/apache/flink/table/examples/java/connectors/SocketSourceFunction.java ########## @@ -0,0 +1,106 @@ +/* + * 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.table.examples.java.connectors; + +import org.apache.flink.api.common.serialization.DeserializationSchema; +import org.apache.flink.api.common.typeinfo.TypeInformation; +import org.apache.flink.api.java.typeutils.ResultTypeQueryable; +import org.apache.flink.configuration.Configuration; +import org.apache.flink.streaming.api.functions.source.RichSourceFunction; +import org.apache.flink.table.data.RowData; + +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.net.InetSocketAddress; +import java.net.Socket; + +/** + * The {@link SocketSourceFunction} opens a socket and consumes bytes. + * + * <p>It splits records by the given byte delimiter (`\n` by default) and delegates the decoding to a + * pluggable {@link DeserializationSchema}. + * + * <p>Note: The source function can only work with a parallelism of 1. Review comment: Maybe also say that it's not fault-tolerant and shouldn't be used in production. ########## File path: flink-examples/flink-examples-table/src/main/java/org/apache/flink/table/examples/java/connectors/ChangelogSocketExample.java ########## @@ -0,0 +1,100 @@ +/* + * 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.table.examples.java.connectors; + +import org.apache.flink.api.java.utils.ParameterTool; +import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; +import org.apache.flink.streaming.api.functions.source.SourceFunction; +import org.apache.flink.table.api.Table; +import org.apache.flink.table.api.bridge.java.StreamTableEnvironment; +import org.apache.flink.table.connector.format.DecodingFormat; +import org.apache.flink.table.connector.source.DynamicTableSource; +import org.apache.flink.table.factories.FactoryUtil; +import org.apache.flink.types.Row; + +/** + * Example for implementing a custom {@link DynamicTableSource} and a {@link DecodingFormat}. + * + * <p>The example implements a table source with a decoding format that supports changelog semantics. + * + * <p>The {@link SocketDynamicTableFactory} illustrates how connector components play together. It can + * serve as a reference implementation for implementing own connectors and/or formats. + * + * <p>The {@link SocketDynamicTableSource} uses a simple single-threaded {@link SourceFunction} to open + * a socket that listens for incoming bytes. The raw bytes are decoded into rows by a pluggable format. + * The format expects a changelog flag as the first column. + * + * <p>In particular, the example shows how to + * <ul> + * <li>create factories that parse and validate options, + * <li>implement table connectors, + * <li>implement and discover custom formats, + * <li>and use provided utilities such as data structure converters and the {@link FactoryUtil}. + * </ul> + * + * <p>Usage: <code>ChangelogSocketExample --hostname <localhost> --port <9999></code> + * + * <p>Use the following command to ingest data in a terminal: + * <pre> + * nc -lk 9999 + * INSERT|Alice|12 + * INSERT|Bob|5 + * DELETE|Alice|12 + * INSERT|Alice|18 + * </pre> + * + * <p>The result is written to stdout. + */ +public final class ChangelogSocketExample { + + // ************************************************************************* Review comment: I don't think this `PROGRAM` comment is necessary here since we only have a `main()` function. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
