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 2019/06/17 02:52:59 UTC

[GitHub] [flink] godfreyhe commented on a change in pull request #8736: [FLINK-12846][table] Carry primary key and unique key information in TableSchema

godfreyhe commented on a change in pull request #8736: [FLINK-12846][table] Carry primary key and unique key information in TableSchema
URL: https://github.com/apache/flink/pull/8736#discussion_r294118121
 
 

 ##########
 File path: flink-table/flink-table-common/src/main/java/org/apache/flink/table/api/TableSchema.java
 ##########
 @@ -343,13 +412,66 @@ public Builder field(String name, TypeInformation<?> typeInfo) {
 			return field(name, fromLegacyInfoToDataType(typeInfo));
 		}
 
+		/**
+		 * Add a primary key with the given field names.
+		 * There can only be one PRIMARY KEY for a given table
+		 * See the {@link TableSchema} class javadoc for more definition about primary key.
+		 */
+		public Builder primaryKey(String... fields) {
+			Preconditions.checkArgument(
+				fields != null && fields.length > 0,
+				"The primary key fields shouldn't be null or empty.");
+			Preconditions.checkArgument(
+				primaryKey == null,
+				"A primary key " + primaryKey +
+					" have been defined, can not define another primary key " +
+					Arrays.toString(fields));
+			for (String field : fields) {
+				if (!fieldNames.contains(field)) {
+					throw new IllegalArgumentException("The field '" + field +
+						"' is not existed in the schema.");
+				}
+			}
 
 Review comment:
   that means we must build fieldNames first ?

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