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/03/04 03:17:40 UTC

[GitHub] [incubator-inlong] chantccc commented on a change in pull request #2876: [INLONG-2872][Sort] Support field mapping when transforming

chantccc commented on a change in pull request #2876:
URL: https://github.com/apache/incubator-inlong/pull/2876#discussion_r819234649



##########
File path: inlong-sort/sort-single-tenant/src/test/java/org/apache/inlong/sort/singletenant/flink/transformation/TransformerTest.java
##########
@@ -0,0 +1,177 @@
+/*
+ * 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.transformation;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.streaming.api.TimerService;
+import org.apache.flink.types.Row;
+import org.apache.flink.util.OutputTag;
+import org.apache.inlong.sort.formats.common.IntFormatInfo;
+import org.apache.inlong.sort.formats.common.LongFormatInfo;
+import org.apache.inlong.sort.formats.common.StringFormatInfo;
+import org.apache.inlong.sort.protocol.FieldInfo;
+import org.apache.inlong.sort.protocol.transformation.FieldMappingRule;
+import org.apache.inlong.sort.protocol.transformation.FieldMappingRule.FieldMappingUnit;
+import org.apache.inlong.sort.protocol.transformation.TransformationInfo;
+import org.apache.inlong.sort.singletenant.flink.deserialization.ListCollector;
+import org.junit.Test;
+
+public class TransformerTest {
+
+    private static final FieldInfo[] sourceFieldInfos = new FieldInfo[] {
+            new FieldInfo("name", StringFormatInfo.INSTANCE),
+            new FieldInfo("age", IntFormatInfo.INSTANCE),
+            new FieldInfo("height", LongFormatInfo.INSTANCE),
+    };
+
+    private static final FieldInfo[] sinkFieldInfos = new FieldInfo[] {
+            new FieldInfo("age_out", IntFormatInfo.INSTANCE),
+            new FieldInfo("name_out", StringFormatInfo.INSTANCE)
+    };
+
+    @Test
+    public void testTransform() {
+        TransformationInfo transformationInfo = new TransformationInfo(
+                new FieldMappingRule(new FieldMappingUnit[] {
+                        new FieldMappingUnit(
+                                new FieldInfo("age", StringFormatInfo.INSTANCE),
+                                new FieldInfo("age_out", StringFormatInfo.INSTANCE)),
+                        new FieldMappingUnit(
+                                new FieldInfo("name", StringFormatInfo.INSTANCE),
+                                new FieldInfo("name_out", StringFormatInfo.INSTANCE))
+                }));
+        Transformer transformer = new Transformer(
+                transformationInfo,
+                sourceFieldInfos,
+                sinkFieldInfos);
+
+        transformer.open(new Configuration());
+
+        Row input = Row.of("name", 29, 179);
+        ListCollector<Row> collector = new ListCollector<>();
+        transformer.processElement(
+                input,
+                transformer.new Context() {

Review comment:
       ok

##########
File path: inlong-sort/sort-common/src/main/java/org/apache/inlong/sort/protocol/DataFlowInfo.java
##########
@@ -75,6 +87,12 @@ public SourceInfo getSourceInfo() {
         return sourceInfo;
     }
 
+    @Nullable

Review comment:
       @JsonInclude(Include.NON_NULL) is used when serializing the object into json string
   @Nullable is used for marking that the field's value can be nulll




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