You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2022/01/20 03:50:58 UTC

[GitHub] [flink] imaffe commented on a change in pull request #18406: [FLINK-25686][pulsar]: add schema evolution support for pulsar source connector

imaffe commented on a change in pull request #18406:
URL: https://github.com/apache/flink/pull/18406#discussion_r788330029



##########
File path: flink-connectors/flink-connector-pulsar/src/test/java/org/apache/flink/connector/pulsar/source/reader/deserializer/PulsarDeserializationSchemaTest.java
##########
@@ -64,27 +59,6 @@ void createFromFlinkDeserializationSchema() throws Exception {
         assertEquals(collector.result, "some-sample-message");
     }
 
-    @Test
-    void createFromPulsarSchema() throws Exception {

Review comment:
       We don't need this test as we are not using `PulsarSchemaWrapper` to really decode any messages

##########
File path: flink-connectors/flink-connector-pulsar/src/main/java/org/apache/flink/connector/pulsar/source/reader/deserializer/PulsarDeserializationSchema.java
##########
@@ -67,7 +67,13 @@ default void open(InitializationContext context) throws Exception {
      * @param message The message decoded by pulsar.
      * @param out The collector to put the resulting messages.
      */
-    void deserialize(Message<byte[]> message, Collector<T> out) throws Exception;
+    void deserialize(Message<?> message, Collector<T> out) throws Exception;
+
+    /** @return The related Pulsar Schema for this serializer. */
+    default Schema<T> schema() {

Review comment:
       We decided to use try catch to determine if we are using Pulsar Schema , though this is a bit weird as we are using "exception as control flow". Welcome some other options~

##########
File path: flink-connectors/flink-connector-pulsar/src/test/java/org/apache/flink/connector/pulsar/source/PulsarSourceDeserializationTest.java
##########
@@ -0,0 +1,283 @@
+/*
+ * 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.connector.pulsar.source;
+
+import org.apache.flink.api.common.eventtime.WatermarkStrategy;
+import org.apache.flink.api.common.serialization.SimpleStringSchema;
+import org.apache.flink.connector.pulsar.source.enumerator.cursor.StopCursor;
+import org.apache.flink.connector.pulsar.source.enumerator.topic.TopicNameUtils;
+import org.apache.flink.connector.pulsar.source.reader.deserializer.PulsarDeserializationSchema;
+import org.apache.flink.connector.pulsar.testutils.PulsarTestSuiteBase;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.util.CloseableIterator;
+
+import org.apache.pulsar.client.api.Schema;
+import org.apache.pulsar.common.schema.KeyValue;
+import org.junit.jupiter.api.Test;
+
+import java.io.Serializable;
+import java.util.Objects;
+import java.util.concurrent.ThreadLocalRandom;
+
+import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
+import static org.apache.flink.connector.pulsar.source.reader.deserializer.PulsarDeserializationSchema.flinkSchema;
+import static org.apache.flink.connector.pulsar.source.reader.deserializer.PulsarDeserializationSchema.pulsarSchema;
+import static org.apache.pulsar.client.api.SubscriptionType.Exclusive;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatCode;
+
+/** Testing the pulsar schema used by source. */
+public class PulsarSourceDeserializationTest extends PulsarTestSuiteBase {

Review comment:
       This class can be put together to `PulsarSourceITCase` like Kafka did, it also can be put to another directory. Where do you think it's the best place to put this class ?

##########
File path: flink-connectors/flink-connector-pulsar/src/main/java/org/apache/flink/connector/pulsar/common/schema/factories/KeyValueSchemaFactory.java
##########
@@ -69,11 +69,8 @@ public SchemaType type() {
     public TypeInformation<KeyValue<K, V>> createTypeInfo(SchemaInfo info) {
         KeyValue<SchemaInfo, SchemaInfo> kvSchemaInfo = decodeKeyValueSchemaInfo(info);
 
-        Schema<K> keySchema = PulsarSchemaUtils.createSchema(kvSchemaInfo.getKey());
-        Class<K> keyClass = decodeClassInfo(keySchema.getSchemaInfo());
-
-        Schema<V> valueSchema = PulsarSchemaUtils.createSchema(kvSchemaInfo.getValue());
-        Class<V> valueClass = decodeClassInfo(valueSchema.getSchemaInfo());
+        Class<K> keyClass = decodeClassInfo(kvSchemaInfo.getKey());
+        Class<V> valueClass = decodeClassInfo(kvSchemaInfo.getValue());

Review comment:
       @syhily Hi Yufan, I'm not sure if this modification makes sense, I was wondering why we first create a schema from SchemaInfo and then get SchemaInfo from the schema ?




-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org