You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by ja...@apache.org on 2020/04/24 09:29:39 UTC
[flink] 01/04: [FLINK-17169][core] Add shortString() method to
RowKind to get short string representation
This is an automated email from the ASF dual-hosted git repository.
jark pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git
commit 91f4a3c5081a99822430ba0683bce381aec188bd
Author: Jark Wu <ja...@apache.org>
AuthorDate: Fri Apr 17 22:11:44 2020 +0800
[FLINK-17169][core] Add shortString() method to RowKind to get short string representation
This closes #11797
---
.../main/java/org/apache/flink/types/RowKind.java | 67 ++++++++++++++++++++--
1 file changed, 63 insertions(+), 4 deletions(-)
diff --git a/flink-core/src/main/java/org/apache/flink/types/RowKind.java b/flink-core/src/main/java/org/apache/flink/types/RowKind.java
index 3b45001..a1acf7d 100644
--- a/flink-core/src/main/java/org/apache/flink/types/RowKind.java
+++ b/flink-core/src/main/java/org/apache/flink/types/RowKind.java
@@ -29,7 +29,7 @@ public enum RowKind {
/**
* Insertion operation.
*/
- INSERT,
+ INSERT("+I", (byte) 0),
/**
* Update operation with the previous content of the updated row.
@@ -38,7 +38,7 @@ public enum RowKind {
* to retract the previous row first. It is useful in cases of a non-idempotent update, i.e., an
* update of a row that is not uniquely identifiable by a key.
*/
- UPDATE_BEFORE,
+ UPDATE_BEFORE("-U", (byte) 1),
/**
* Update operation with new content of the updated row.
@@ -47,10 +47,69 @@ public enum RowKind {
* needs to retract the previous row first. OR it describes an idempotent update, i.e., an update
* of a row that is uniquely identifiable by a key.
*/
- UPDATE_AFTER,
+ UPDATE_AFTER("+U", (byte) 2),
/**
* Deletion operation.
*/
- DELETE
+ DELETE("-D", (byte) 3);
+
+ private final String shortString;
+
+ private final byte value;
+
+ /**
+ * Creates a {@link RowKind} enum with the given short string and byte value representation of
+ * the {@link RowKind}.
+ */
+ RowKind(String shortString, byte value) {
+ this.shortString = shortString;
+ this.value = value;
+ }
+
+ /**
+ * Returns a short string representation of this {@link RowKind}.
+ *
+ * <p><ul>
+ * <li>"+I" represents {@link #INSERT}.</li>
+ * <li>"-U" represents {@link #UPDATE_BEFORE}.</li>
+ * <li>"+U" represents {@link #UPDATE_AFTER}.</li>
+ * <li>"-D" represents {@link #DELETE}.</li>
+ * </ul>
+ */
+ public String shortString() {
+ return shortString;
+ }
+
+ /**
+ * Returns the byte value representation of this {@link RowKind}. The byte value is used
+ * for serialization and deserialization.
+ *
+ * <p><ul>
+ * <li>"0" represents {@link #INSERT}.</li>
+ * <li>"1" represents {@link #UPDATE_BEFORE}.</li>
+ * <li>"2" represents {@link #UPDATE_AFTER}.</li>
+ * <li>"3" represents {@link #DELETE}.</li>
+ * </ul>
+ */
+ public byte toByteValue() {
+ return value;
+ }
+
+ /**
+ * Creates a {@link RowKind} from the given byte value. Each {@link RowKind} has a byte
+ * value representation.
+ *
+ * @see #toByteValue() for mapping of byte value and {@link RowKind}.
+ */
+ public static RowKind fromByteValue(byte value) {
+ switch (value) {
+ case 0: return INSERT;
+ case 1: return UPDATE_BEFORE;
+ case 2: return UPDATE_AFTER;
+ case 3: return DELETE;
+ default: throw new UnsupportedOperationException(
+ "Unsupported byte value '" + value + "' for row kind.");
+ }
+ }
}