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/05/09 08:08:36 UTC

[GitHub] [flink] lirui-apache commented on a change in pull request #12017: [FLINK-17452][hive] Support creating Hive tables with constraints

lirui-apache commented on a change in pull request #12017:
URL: https://github.com/apache/flink/pull/12017#discussion_r422467472



##########
File path: flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/catalog/hive/HiveCatalog.java
##########
@@ -374,8 +375,30 @@ public void createTable(ObjectPath tablePath, CatalogBaseTable table, boolean ig
 
 		Table hiveTable = instantiateHiveTable(tablePath, table);
 
+		UniqueConstraint pkConstraint = null;
+		List<String> notNullCols = new ArrayList<>();
+		boolean isGeneric = isGenericForCreate(table.getOptions());
+		if (!isGeneric) {
+			pkConstraint = table.getSchema().getPrimaryKey().orElse(null);
+			for (int i = 0; i < table.getSchema().getFieldDataTypes().length; i++) {
+				if (!table.getSchema().getFieldDataTypes()[i].getLogicalType().isNullable()) {
+					notNullCols.add(table.getSchema().getFieldNames()[i]);
+				}
+			}
+		}
+
 		try {
-			client.createTable(hiveTable);
+			if (pkConstraint != null || !notNullCols.isEmpty()) {
+				// for now we just create constraints that are DISABLE, NOVALIDATE, RELY
+				Byte[] pkTraits = new Byte[pkConstraint == null ? 0 : pkConstraint.getColumns().size()];
+				Arrays.fill(pkTraits, HiveTableUtil.relyConstraint((byte) 0));
+				Byte[] nnTraits = new Byte[notNullCols.size()];
+				Arrays.fill(nnTraits, HiveTableUtil.relyConstraint((byte) 0));
+				client.createTableWithConstraints(hiveTable, hiveConf,

Review comment:
       The client is meant to be just a wrapper of `IMetaStoreClient`. So I think it's more natural to keep such logic in `HiveCatalog`. We can add util method if that logic has to be repeated somewhere else.




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