You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by tw...@apache.org on 2019/05/09 12:36:25 UTC

[flink] 03/06: [hotfix][table-common] Add description to user-defined type attributes

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

twalthr pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git

commit 12f34808fd87816726a5a8ce74146bd07265c1c3
Author: Timo Walther <tw...@apache.org>
AuthorDate: Tue May 7 14:55:25 2019 +0200

    [hotfix][table-common] Add description to user-defined type attributes
---
 .../flink/table/types/logical/StructuredType.java   | 21 +++++++++++++++++----
 .../apache/flink/table/types/LogicalTypesTest.java  |  2 +-
 2 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/logical/StructuredType.java b/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/logical/StructuredType.java
index f76ad6b..44bd0ad 100644
--- a/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/logical/StructuredType.java
+++ b/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/logical/StructuredType.java
@@ -71,9 +71,16 @@ public final class StructuredType extends UserDefinedType {
 
 		private final LogicalType type;
 
-		public StructuredAttribute(String name, LogicalType type) {
+		private final @Nullable String description;
+
+		public StructuredAttribute(String name, LogicalType type, @Nullable String description) {
 			this.name = Preconditions.checkNotNull(name, "Attribute name must not be null.");
 			this.type = Preconditions.checkNotNull(type, "Attribute type must not be null.");
+			this.description = description;
+		}
+
+		public StructuredAttribute(String name, LogicalType type) {
+			this(name, type, null);
 		}
 
 		public String getName() {
@@ -84,8 +91,12 @@ public final class StructuredType extends UserDefinedType {
 			return type;
 		}
 
+		public Optional<String> getDescription() {
+			return Optional.ofNullable(description);
+		}
+
 		public StructuredAttribute copy() {
-			return new StructuredAttribute(name, type.copy());
+			return new StructuredAttribute(name, type.copy(), description);
 		}
 
 		@Override
@@ -97,12 +108,14 @@ public final class StructuredType extends UserDefinedType {
 				return false;
 			}
 			StructuredAttribute that = (StructuredAttribute) o;
-			return name.equals(that.name) && type.equals(that.type);
+			return name.equals(that.name) &&
+				type.equals(that.type) &&
+				Objects.equals(description, that.description);
 		}
 
 		@Override
 		public int hashCode() {
-			return Objects.hash(name, type);
+			return Objects.hash(name, type, description);
 		}
 	}
 
diff --git a/flink-table/flink-table-common/src/test/java/org/apache/flink/table/types/LogicalTypesTest.java b/flink-table/flink-table-common/src/test/java/org/apache/flink/table/types/LogicalTypesTest.java
index e03e15d..b8b38c5 100644
--- a/flink-table/flink-table-common/src/test/java/org/apache/flink/table/types/LogicalTypesTest.java
+++ b/flink-table/flink-table-common/src/test/java/org/apache/flink/table/types/LogicalTypesTest.java
@@ -602,7 +602,7 @@ public class LogicalTypesTest {
 		return new StructuredType.Builder(
 				new UserDefinedType.TypeIdentifier("cat", "db", "Human"),
 				Collections.singletonList(
-					new StructuredType.StructuredAttribute("name", UDT_NAME_TYPE)))
+					new StructuredType.StructuredAttribute("name", UDT_NAME_TYPE, "Description.")))
 			.setDescription("Human type desc.")
 			.setFinal(false)
 			.setInstantiable(false)