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/02/04 07:16:20 UTC

[GitHub] [flink] JingsongLi commented on a change in pull request #11012: [FLINK-15858][hive] Store generic table schema as properties

JingsongLi commented on a change in pull request #11012: [FLINK-15858][hive] Store generic table schema as properties
URL: https://github.com/apache/flink/pull/11012#discussion_r374505837
 
 

 ##########
 File path: flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/catalog/hive/HiveCatalog.java
 ##########
 @@ -587,57 +599,67 @@ protected static Table instantiateHiveTable(ObjectPath tablePath, CatalogBaseTab
 		// When creating a table, A hive table needs explicitly have a key is_generic = false
 		// otherwise, this is a generic table if 1) the key is missing 2) is_generic = true
 		// this is opposite to reading a table and instantiating a CatalogTable. See instantiateCatalogTable()
+		boolean isGeneric;
 		if (!properties.containsKey(CatalogConfig.IS_GENERIC)) {
-			// must be a generic catalog
+			// must be a generic table
+			isGeneric = true;
 			properties.put(CatalogConfig.IS_GENERIC, String.valueOf(true));
-			properties = maskFlinkProperties(properties);
 		} else {
-			boolean isGeneric = Boolean.valueOf(properties.get(CatalogConfig.IS_GENERIC));
-
-			if (isGeneric) {
-				properties = maskFlinkProperties(properties);
-			}
+			isGeneric = Boolean.parseBoolean(properties.get(CatalogConfig.IS_GENERIC));
 		}
 
-		// Table properties
-		hiveTable.setParameters(properties);
-
 		// Hive table's StorageDescriptor
 		StorageDescriptor sd = hiveTable.getSd();
 		setStorageFormat(sd, properties);
 
-		List<FieldSchema> allColumns = HiveTableUtil.createHiveColumns(table.getSchema());
-
-		// Table columns and partition keys
-		if (table instanceof CatalogTableImpl) {
-			CatalogTable catalogTable = (CatalogTableImpl) table;
-
-			if (catalogTable.isPartitioned()) {
-				int partitionKeySize = catalogTable.getPartitionKeys().size();
-				List<FieldSchema> regularColumns = allColumns.subList(0, allColumns.size() - partitionKeySize);
-				List<FieldSchema> partitionColumns = allColumns.subList(allColumns.size() - partitionKeySize, allColumns.size());
+		if (isGeneric) {
+			DescriptorProperties tableSchemaProps = new DescriptorProperties(true);
+			tableSchemaProps.putTableSchema(HiveCatalogConfig.GENERIC_TABLE_SCHEMA_PREFIX, table.getSchema());
+			properties.putAll(tableSchemaProps.asMap());
+
+			if (table instanceof CatalogTableImpl) {
+				List<String> partColNames = ((CatalogTableImpl) table).getPartitionKeys();
+				if (!partColNames.isEmpty()) {
+					properties.put(HiveCatalogConfig.GENERIC_PART_COL_NAMES, String.join(",", partColNames));
 
 Review comment:
   For compatibility issue, should throw exception now.

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