You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@inlong.apache.org by GitBox <gi...@apache.org> on 2022/02/16 11:35:31 UTC

[GitHub] [incubator-inlong] KevinWen007 opened a new pull request #2525: [INLONG-2524][Feature][InLong-Sort] Support deserialization of json, canal and avro formatted data

KevinWen007 opened a new pull request #2525:
URL: https://github.com/apache/incubator-inlong/pull/2525


   ### Title Name: [INLONG-2524][Feature][InLong-Sort] Support deserialization of json, canal and avro formatted data
   
   Fixes #2524
   
   ### Motivation
   
   *Explain here the context, and why you're making that change. What is the problem you're trying to solve.*
   
   ### Modifications
   
   *Describe the modifications you've done.*
   
   ### Verifying this change
   
   - [ ] Make sure that the change passes the CI checks.
   
   *(Please pick either of the following options)*
   
   This change is a trivial rework / code cleanup without any test coverage.
   
   *(or)*
   
   This change is already covered by existing tests, such as *(please describe tests)*.
   
   *(or)*
   
   This change added tests and can be verified as follows:
   
   *(example:)*
     - *Added integration tests for end-to-end deployment with large payloads (10MB)*
     - *Extended integration test for recovery after broker failure*
   
   ### Documentation
   
     - Does this pull request introduce a new feature? (yes / no)
     - If yes, how is the feature documented? (not applicable / docs / JavaDocs / not documented)
     - If a feature is not applicable for documentation, explain why?
     - If a feature is not documented yet in this PR, please create a followup issue for adding the documentation
   


-- 
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: commits-unsubscribe@inlong.apache.org

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



[GitHub] [incubator-inlong] ywh19911024 commented on a change in pull request #2525: [INLONG-2524][Feature][Sort] Support deserialization of json, canal and avro formatted data

Posted by GitBox <gi...@apache.org>.
ywh19911024 commented on a change in pull request #2525:
URL: https://github.com/apache/incubator-inlong/pull/2525#discussion_r808766698



##########
File path: inlong-sort/sort-single-tenant/src/main/java/org/apache/inlong/sort/singletenant/flink/serialization/CustomDateFormatSerializationSchemaWrapper.java
##########
@@ -0,0 +1,90 @@
+/*
+ * 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.inlong.sort.singletenant.flink.serialization;
+
+import org.apache.commons.lang3.time.FastDateFormat;
+import org.apache.flink.api.common.serialization.SerializationSchema;
+import org.apache.flink.shaded.guava18.com.google.common.annotations.VisibleForTesting;
+import org.apache.flink.types.Row;
+import org.apache.inlong.sort.formats.common.DateFormatInfo;
+import org.apache.inlong.sort.formats.common.FormatInfo;
+import org.apache.inlong.sort.formats.common.TimeFormatInfo;
+import org.apache.inlong.sort.formats.common.TimestampFormatInfo;
+
+import java.sql.Date;
+import java.sql.Time;
+import java.sql.Timestamp;
+
+import static org.apache.flink.shaded.guava18.com.google.common.base.Preconditions.checkNotNull;
+import static org.apache.flink.shaded.guava18.com.google.common.base.Preconditions.checkState;
+import static org.apache.inlong.sort.singletenant.flink.utils.CommonUtils.isStandardTimestampFormat;
+
+public class CustomDateFormatSerializationSchemaWrapper implements SerializationSchema<Row> {
+
+    private static final long serialVersionUID = 7342088340154604198L;
+
+    private final SerializationSchema<Row> innerSchema;
+
+    private final FormatInfo[] formatInfos;
+
+    public CustomDateFormatSerializationSchemaWrapper(SerializationSchema<Row> innerSchema, FormatInfo[] formatInfos) {
+        this.innerSchema = checkNotNull(innerSchema);
+        this.formatInfos = checkNotNull(formatInfos);
+    }
+
+    @Override
+    public void open(InitializationContext context) throws Exception {
+        innerSchema.open(context);
+    }
+
+    @Override
+    public byte[] serialize(Row element) {
+        Row outputRow = fromDateAndTimeToString(element);
+        return innerSchema.serialize(outputRow);
+    }
+
+    @VisibleForTesting
+    Row fromDateAndTimeToString(Row inputRow) {
+        int arity = inputRow.getArity();
+        Row outputRow = new Row(arity);
+        for (int i = 0; i < arity; i++) {
+            outputRow.setField(i, convert(inputRow.getField(i), formatInfos[i]));
+        }
+        outputRow.setKind(inputRow.getKind());
+        return outputRow;
+    }
+
+    private Object convert(Object input, FormatInfo formatInfo) {

Review comment:
       这个是不是可以移动到CommonUtils类中




-- 
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: commits-unsubscribe@inlong.apache.org

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



[GitHub] [incubator-inlong] dockerzhang merged pull request #2525: [INLONG-2524][Feature][Sort] Support deserialization of json, canal and avro formatted data

Posted by GitBox <gi...@apache.org>.
dockerzhang merged pull request #2525:
URL: https://github.com/apache/incubator-inlong/pull/2525


   


-- 
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: commits-unsubscribe@inlong.apache.org

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



[GitHub] [incubator-inlong] KevinWen007 commented on a change in pull request #2525: [INLONG-2524][Feature][Sort] Support deserialization of json, canal and avro formatted data

Posted by GitBox <gi...@apache.org>.
KevinWen007 commented on a change in pull request #2525:
URL: https://github.com/apache/incubator-inlong/pull/2525#discussion_r808830736



##########
File path: inlong-sort/sort-single-tenant/src/main/java/org/apache/inlong/sort/singletenant/flink/serialization/CustomDateFormatSerializationSchemaWrapper.java
##########
@@ -0,0 +1,90 @@
+/*
+ * 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.inlong.sort.singletenant.flink.serialization;
+
+import org.apache.commons.lang3.time.FastDateFormat;
+import org.apache.flink.api.common.serialization.SerializationSchema;
+import org.apache.flink.shaded.guava18.com.google.common.annotations.VisibleForTesting;
+import org.apache.flink.types.Row;
+import org.apache.inlong.sort.formats.common.DateFormatInfo;
+import org.apache.inlong.sort.formats.common.FormatInfo;
+import org.apache.inlong.sort.formats.common.TimeFormatInfo;
+import org.apache.inlong.sort.formats.common.TimestampFormatInfo;
+
+import java.sql.Date;
+import java.sql.Time;
+import java.sql.Timestamp;
+
+import static org.apache.flink.shaded.guava18.com.google.common.base.Preconditions.checkNotNull;
+import static org.apache.flink.shaded.guava18.com.google.common.base.Preconditions.checkState;
+import static org.apache.inlong.sort.singletenant.flink.utils.CommonUtils.isStandardTimestampFormat;
+
+public class CustomDateFormatSerializationSchemaWrapper implements SerializationSchema<Row> {
+
+    private static final long serialVersionUID = 7342088340154604198L;
+
+    private final SerializationSchema<Row> innerSchema;
+
+    private final FormatInfo[] formatInfos;
+
+    public CustomDateFormatSerializationSchemaWrapper(SerializationSchema<Row> innerSchema, FormatInfo[] formatInfos) {
+        this.innerSchema = checkNotNull(innerSchema);
+        this.formatInfos = checkNotNull(formatInfos);
+    }
+
+    @Override
+    public void open(InitializationContext context) throws Exception {
+        innerSchema.open(context);
+    }
+
+    @Override
+    public byte[] serialize(Row element) {
+        Row outputRow = fromDateAndTimeToString(element);
+        return innerSchema.serialize(outputRow);
+    }
+
+    @VisibleForTesting
+    Row fromDateAndTimeToString(Row inputRow) {
+        int arity = inputRow.getArity();
+        Row outputRow = new Row(arity);
+        for (int i = 0; i < arity; i++) {
+            outputRow.setField(i, convert(inputRow.getField(i), formatInfos[i]));
+        }
+        outputRow.setKind(inputRow.getKind());
+        return outputRow;
+    }
+
+    private Object convert(Object input, FormatInfo formatInfo) {

Review comment:
       convert() in CustomDateFormatSerializationSchemaWrapper converts Date, Time and Timestamp to String, while convert() in CustomDateFormatDeserializationSchemaWrapper converts String to Date, Time and Timestamp




-- 
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: commits-unsubscribe@inlong.apache.org

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



[GitHub] [incubator-inlong] KevinWen007 commented on a change in pull request #2525: [INLONG-2524][Feature][Sort] Support deserialization of json, canal and avro formatted data

Posted by GitBox <gi...@apache.org>.
KevinWen007 commented on a change in pull request #2525:
URL: https://github.com/apache/incubator-inlong/pull/2525#discussion_r808830736



##########
File path: inlong-sort/sort-single-tenant/src/main/java/org/apache/inlong/sort/singletenant/flink/serialization/CustomDateFormatSerializationSchemaWrapper.java
##########
@@ -0,0 +1,90 @@
+/*
+ * 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.inlong.sort.singletenant.flink.serialization;
+
+import org.apache.commons.lang3.time.FastDateFormat;
+import org.apache.flink.api.common.serialization.SerializationSchema;
+import org.apache.flink.shaded.guava18.com.google.common.annotations.VisibleForTesting;
+import org.apache.flink.types.Row;
+import org.apache.inlong.sort.formats.common.DateFormatInfo;
+import org.apache.inlong.sort.formats.common.FormatInfo;
+import org.apache.inlong.sort.formats.common.TimeFormatInfo;
+import org.apache.inlong.sort.formats.common.TimestampFormatInfo;
+
+import java.sql.Date;
+import java.sql.Time;
+import java.sql.Timestamp;
+
+import static org.apache.flink.shaded.guava18.com.google.common.base.Preconditions.checkNotNull;
+import static org.apache.flink.shaded.guava18.com.google.common.base.Preconditions.checkState;
+import static org.apache.inlong.sort.singletenant.flink.utils.CommonUtils.isStandardTimestampFormat;
+
+public class CustomDateFormatSerializationSchemaWrapper implements SerializationSchema<Row> {
+
+    private static final long serialVersionUID = 7342088340154604198L;
+
+    private final SerializationSchema<Row> innerSchema;
+
+    private final FormatInfo[] formatInfos;
+
+    public CustomDateFormatSerializationSchemaWrapper(SerializationSchema<Row> innerSchema, FormatInfo[] formatInfos) {
+        this.innerSchema = checkNotNull(innerSchema);
+        this.formatInfos = checkNotNull(formatInfos);
+    }
+
+    @Override
+    public void open(InitializationContext context) throws Exception {
+        innerSchema.open(context);
+    }
+
+    @Override
+    public byte[] serialize(Row element) {
+        Row outputRow = fromDateAndTimeToString(element);
+        return innerSchema.serialize(outputRow);
+    }
+
+    @VisibleForTesting
+    Row fromDateAndTimeToString(Row inputRow) {
+        int arity = inputRow.getArity();
+        Row outputRow = new Row(arity);
+        for (int i = 0; i < arity; i++) {
+            outputRow.setField(i, convert(inputRow.getField(i), formatInfos[i]));
+        }
+        outputRow.setKind(inputRow.getKind());
+        return outputRow;
+    }
+
+    private Object convert(Object input, FormatInfo formatInfo) {

Review comment:
       It cannot be moved to CommonUtils. convert() in CustomDateFormatSerializationSchemaWrapper converts Date, Time and Timestamp to String, while convert() in CustomDateFormatDeserializationSchemaWrapper converts String to Date, Time and Timestamp




-- 
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: commits-unsubscribe@inlong.apache.org

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