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 2020/04/13 07:15:23 UTC

[GitHub] [flink] KurtYoung commented on a change in pull request #11674: [FLINK-16887][table-planner-blink] Refactor retraction rules to support inferring ChangelogMode

KurtYoung commented on a change in pull request #11674: [FLINK-16887][table-planner-blink] Refactor retraction rules to support inferring ChangelogMode
URL: https://github.com/apache/flink/pull/11674#discussion_r407348957
 
 

 ##########
 File path: flink-table/flink-table-planner-blink/src/main/java/org/apache/flink/table/planner/plan/trait/ModifyKindSet.java
 ##########
 @@ -0,0 +1,192 @@
+/*
+ * 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.planner.plan.trait;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.List;
+import java.util.Objects;
+import java.util.Set;
+
+/**
+ * The set of modify operations contained in a changelog.
+ *
+ * @see ModifyKind
+ */
+public class ModifyKindSet {
+
+	/**
+	 * Insert-only modify kind set.
+	 */
+	public static final ModifyKindSet INSERT_ONLY = ModifyKindSet.newBuilder()
+		.addContainedKind(ModifyKind.INSERT)
+		.build();
+
+	/**
+	 * A modify kind set contains all change operations.
+	 */
+	public static final ModifyKindSet ALL_CHANGES = ModifyKindSet.newBuilder()
+		.addContainedKind(ModifyKind.INSERT)
+		.addContainedKind(ModifyKind.UPDATE)
+		.addContainedKind(ModifyKind.DELETE)
+		.build();
+
+	private final Set<ModifyKind> kinds;
+
+	private ModifyKindSet(Set<ModifyKind> kinds) {
+		this.kinds = Collections.unmodifiableSet(kinds);
+	}
+
+	public Set<ModifyKind> getContainedKinds() {
+		return kinds;
+	}
+
+	public boolean contains(ModifyKind kind) {
+		return kinds.contains(kind);
+	}
+
+	public boolean containsOnly(ModifyKind kind) {
+		return kinds.size() == 1 && kinds.contains(kind);
+	}
+
+	public boolean isInsertOnly() {
+		return containsOnly(ModifyKind.INSERT);
+	}
+
+	public int size() {
+		return kinds.size();
+	}
+
+	public boolean isEmpty() {
+		return kinds.isEmpty();
+	}
+
+	/**
+	 * Returns a new set of ModifyKind which is the difference between two sets.
+	 * It is also equal to {@code this.kinds - that.kinds}. For example:
+	 * [I,U,D] diff [I] = [U,D]
+	 * [I,U] diff [U,D] = [I]
+	 * [I,U,D] diff [I,U,D] = []
+	 */
+	public ModifyKindSet diff(ModifyKindSet other) {
+		Set<ModifyKind> result = EnumSet.noneOf(ModifyKind.class);
+		result.addAll(this.kinds);
+		result.removeAll(other.kinds);
+		return new ModifyKindSet(result);
+	}
+
+	/**
+	 * Returns a new ModifyKindSet with all kinds set in both this set and in another set.
+	 */
+	public ModifyKindSet intersect(ModifyKindSet other) {
+		Builder builder = new Builder();
+		for (ModifyKind kind : other.getContainedKinds()) {
+			if (this.contains(kind)) {
+				builder.addContainedKind(kind);
+			}
+		}
+		return builder.build();
+	}
+
+	/**
+	 * Returns a new ModifyKindSet with the union of the other ModifyKindSet.
+	 */
+	public ModifyKindSet union(ModifyKindSet other) {
+		return union(this, other);
+	}
+
+	@Override
+	public boolean equals(Object o) {
+		if (this == o) {
+			return true;
+		}
+		if (o == null || getClass() != o.getClass()) {
+			return false;
+		}
+		ModifyKindSet that = (ModifyKindSet) o;
+		return Objects.equals(kinds, that.kinds);
+	}
+
+	@Override
+	public int hashCode() {
+		return Objects.hash(kinds);
+	}
+
+	@Override
+	public String toString() {
+		if (kinds.isEmpty()) {
 
 Review comment:
   I think we should protect this class to let it be always non-empty.
   Does an empty `ModifyKindSet` make any sense?

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services