You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@inlong.apache.org by do...@apache.org on 2022/04/19 08:18:39 UTC

[incubator-inlong] branch master updated: [INLONG-3789][Sort] Add NodeRelationShip definition to support transform (#3798)

This is an automated email from the ASF dual-hosted git repository.

dockerzhang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-inlong.git


The following commit(s) were added to refs/heads/master by this push:
     new 641ddce71 [INLONG-3789][Sort] Add NodeRelationShip definition to support transform (#3798)
641ddce71 is described below

commit 641ddce71158238ab228829f2f04c1eb99b33a18
Author: yunqingmoswu <44...@users.noreply.github.com>
AuthorDate: Tue Apr 19 16:18:33 2022 +0800

    [INLONG-3789][Sort] Add NodeRelationShip definition to support transform (#3798)
    
    Co-authored-by: yunqingmo <yu...@tencent.com>
---
 .../transformation/relation/NodeRelationShip.java  | 57 ++++++++++++++++++++++
 .../transformation/relation/NodeRelationTest.java  | 46 +++++++++++++++++
 2 files changed, 103 insertions(+)

diff --git a/inlong-sort/sort-common/src/main/java/org/apache/inlong/sort/protocol/transformation/relation/NodeRelationShip.java b/inlong-sort/sort-common/src/main/java/org/apache/inlong/sort/protocol/transformation/relation/NodeRelationShip.java
new file mode 100644
index 000000000..d6803b213
--- /dev/null
+++ b/inlong-sort/sort-common/src/main/java/org/apache/inlong/sort/protocol/transformation/relation/NodeRelationShip.java
@@ -0,0 +1,57 @@
+/*
+ * 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.protocol.transformation.relation;
+
+import com.google.common.base.Preconditions;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonCreator;
+import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty;
+import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonSubTypes;
+import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonTypeInfo;
+
+import java.io.Serializable;
+import java.util.List;
+
+@JsonTypeInfo(
+        use = JsonTypeInfo.Id.NAME,
+        include = JsonTypeInfo.As.PROPERTY,
+        property = "type")
+@JsonSubTypes({
+        @JsonSubTypes.Type(value = NodeRelationShip.class, name = "baseRelation")
+})
+@Data
+@NoArgsConstructor
+public class NodeRelationShip implements Serializable {
+
+    private static final long serialVersionUID = 5491943876653981952L;
+
+    @JsonProperty("inputs")
+    private List<String> inputs;
+    @JsonProperty("outputs")
+    private List<String> outputs;
+
+    @JsonCreator
+    public NodeRelationShip(@JsonProperty("inputs") List<String> inputs,
+            @JsonProperty("outputs") List<String> outputs) {
+        this.inputs = Preconditions.checkNotNull(inputs, "inputs is null");
+        Preconditions.checkState(!inputs.isEmpty(), "inputs is empty");
+        this.outputs = Preconditions.checkNotNull(outputs, "outputs is null");
+        Preconditions.checkState(!outputs.isEmpty(), "outputs is empty");
+    }
+}
diff --git a/inlong-sort/sort-common/src/test/java/org/apache/inlong/sort/protocol/transformation/relation/NodeRelationTest.java b/inlong-sort/sort-common/src/test/java/org/apache/inlong/sort/protocol/transformation/relation/NodeRelationTest.java
new file mode 100644
index 000000000..79d625ab9
--- /dev/null
+++ b/inlong-sort/sort-common/src/test/java/org/apache/inlong/sort/protocol/transformation/relation/NodeRelationTest.java
@@ -0,0 +1,46 @@
+/*
+ * 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.protocol.transformation.relation;
+
+import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException;
+import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper;
+import org.junit.Test;
+
+import java.util.Arrays;
+import static org.junit.Assert.assertEquals;
+
+public class NodeRelationTest {
+
+    @Test
+    public void testSerialize() throws JsonProcessingException {
+        NodeRelationShip relationShip = new NodeRelationShip(Arrays.asList("1", "2"), Arrays.asList("3", "4"));
+        ObjectMapper objectMapper = new ObjectMapper();
+        String expected = "{\"type\":\"baseRelation\",\"inputs\":[\"1\",\"2\"],\"outputs\":[\"3\",\"4\"]}";
+        assertEquals(expected, objectMapper.writeValueAsString(relationShip));
+    }
+
+    @Test
+    public void testDeserialize() throws JsonProcessingException {
+        NodeRelationShip relationShip = new NodeRelationShip(Arrays.asList("1", "2"), Arrays.asList("3", "4"));
+        ObjectMapper objectMapper = new ObjectMapper();
+        String relationShipStr = "{\"type\":\"baseRelation\",\"inputs\":[\"1\",\"2\"],\"outputs\":[\"3\",\"4\"]}";
+        NodeRelationShip expected = objectMapper.readValue(relationShipStr, NodeRelationShip.class);
+        assertEquals(expected, relationShip);
+    }
+
+}