pengzhiwei2018 commented on a change in pull request #2283:
URL: https://github.com/apache/hudi/pull/2283#discussion_r570326841
##########
File path:
hudi-spark-datasource/hudi-spark/src/main/scala/org/apache/hudi/HoodieSparkSqlWriter.scala
##########
@@ -377,11 +388,71 @@ private[hudi] object HoodieSparkSqlWriter {
hiveSyncConfig.supportTimestamp =
parameters.get(HIVE_SUPPORT_TIMESTAMP).exists(r => r.toBoolean)
hiveSyncConfig.decodePartition =
parameters.getOrElse(URL_ENCODE_PARTITIONING_OPT_KEY,
DEFAULT_URL_ENCODE_PARTITIONING_OPT_VAL).toBoolean
+ hiveSyncConfig.tableProperties =
parameters.getOrElse(HIVE_TABLE_PROPERTIES, null)
+ hiveSyncConfig.serdeProperties = createSqlTableSerdeProperties(parameters,
basePath.toString,
+ hiveSyncConfig.partitionFields.size())
hiveSyncConfig
}
- private def metaSync(parameters: Map[String, String],
- basePath: Path,
+ /**
+ * Add Spark Sql related table properties to the HIVE_TABLE_PROPERTIES.
+ * @param sqlConf
+ * @param schema
+ * @param parameters
+ * @return A new parameters added the HIVE_TABLE_PROPERTIES property.
+ */
+ private def addSqlTableProperties(sqlConf: SQLConf, schema: StructType,
+ parameters: Map[String, String]):
Map[String, String] = {
+ val partitionSet = parameters(HIVE_PARTITION_FIELDS_OPT_KEY)
+ .split(",").map(_.trim).filter(!_.isEmpty).toSet
+ val threshold = sqlConf.getConf(SCHEMA_STRING_LENGTH_THRESHOLD)
+
+ val (partCols, dataCols) = schema.partition(c =>
partitionSet.contains(c.name))
+ val reOrdered = StructType(dataCols ++ partCols)
+ val parts = reOrdered.json.grouped(threshold).toSeq
+
+ var properties = Map(
+ "spark.sql.sources.provider" -> "hudi",
Review comment:
Hi @nsivabalan , we have already put the `org.apache.hudi.DefaultSource`
to the `META-INFO.services/org.apache.spark.sql.sources.DataSourceRegister`, so
it is all right to use the short name.
##########
File path:
hudi-spark-datasource/hudi-spark/src/main/scala/org/apache/hudi/HoodieSparkSqlWriter.scala
##########
@@ -377,11 +388,71 @@ private[hudi] object HoodieSparkSqlWriter {
hiveSyncConfig.supportTimestamp =
parameters.get(HIVE_SUPPORT_TIMESTAMP).exists(r => r.toBoolean)
hiveSyncConfig.decodePartition =
parameters.getOrElse(URL_ENCODE_PARTITIONING_OPT_KEY,
DEFAULT_URL_ENCODE_PARTITIONING_OPT_VAL).toBoolean
+ hiveSyncConfig.tableProperties =
parameters.getOrElse(HIVE_TABLE_PROPERTIES, null)
+ hiveSyncConfig.serdeProperties = createSqlTableSerdeProperties(parameters,
basePath.toString,
+ hiveSyncConfig.partitionFields.size())
hiveSyncConfig
}
- private def metaSync(parameters: Map[String, String],
- basePath: Path,
+ /**
+ * Add Spark Sql related table properties to the HIVE_TABLE_PROPERTIES.
+ * @param sqlConf
+ * @param schema
+ * @param parameters
+ * @return A new parameters added the HIVE_TABLE_PROPERTIES property.
+ */
+ private def addSqlTableProperties(sqlConf: SQLConf, schema: StructType,
+ parameters: Map[String, String]):
Map[String, String] = {
+ val partitionSet = parameters(HIVE_PARTITION_FIELDS_OPT_KEY)
+ .split(",").map(_.trim).filter(!_.isEmpty).toSet
+ val threshold = sqlConf.getConf(SCHEMA_STRING_LENGTH_THRESHOLD)
+
+ val (partCols, dataCols) = schema.partition(c =>
partitionSet.contains(c.name))
+ val reOrdered = StructType(dataCols ++ partCols)
+ val parts = reOrdered.json.grouped(threshold).toSeq
Review comment:
Good suggestions!
##########
File path:
hudi-spark-datasource/hudi-spark/src/main/scala/org/apache/hudi/HoodieSparkSqlWriter.scala
##########
@@ -377,11 +388,71 @@ private[hudi] object HoodieSparkSqlWriter {
hiveSyncConfig.supportTimestamp =
parameters.get(HIVE_SUPPORT_TIMESTAMP).exists(r => r.toBoolean)
hiveSyncConfig.decodePartition =
parameters.getOrElse(URL_ENCODE_PARTITIONING_OPT_KEY,
DEFAULT_URL_ENCODE_PARTITIONING_OPT_VAL).toBoolean
+ hiveSyncConfig.tableProperties =
parameters.getOrElse(HIVE_TABLE_PROPERTIES, null)
+ hiveSyncConfig.serdeProperties = createSqlTableSerdeProperties(parameters,
basePath.toString,
+ hiveSyncConfig.partitionFields.size())
hiveSyncConfig
}
- private def metaSync(parameters: Map[String, String],
- basePath: Path,
+ /**
+ * Add Spark Sql related table properties to the HIVE_TABLE_PROPERTIES.
+ * @param sqlConf
+ * @param schema
+ * @param parameters
+ * @return A new parameters added the HIVE_TABLE_PROPERTIES property.
+ */
+ private def addSqlTableProperties(sqlConf: SQLConf, schema: StructType,
+ parameters: Map[String, String]):
Map[String, String] = {
+ val partitionSet = parameters(HIVE_PARTITION_FIELDS_OPT_KEY)
+ .split(",").map(_.trim).filter(!_.isEmpty).toSet
+ val threshold = sqlConf.getConf(SCHEMA_STRING_LENGTH_THRESHOLD)
+
+ val (partCols, dataCols) = schema.partition(c =>
partitionSet.contains(c.name))
+ val reOrdered = StructType(dataCols ++ partCols)
+ val parts = reOrdered.json.grouped(threshold).toSeq
+
+ var properties = Map(
+ "spark.sql.sources.provider" -> "hudi",
+ "spark.sql.sources.schema.numParts" -> parts.size.toString
+ )
+ parts.zipWithIndex.foreach { case (part, index) =>
Review comment:
Thanks for the advice, I will add the reference and add more comments.
##########
File path:
hudi-sync/hudi-hive-sync/src/main/java/org/apache/hudi/hive/HoodieHiveClient.java
##########
@@ -138,6 +138,27 @@ public void updatePartitionsToTable(String tableName,
List<String> changedPartit
}
}
+ /**
+ * Update the table properties to the table.
+ * @param tableProperties
+ */
+ @Override
+ public void updateTableProperties(String tableName, Map<String, String>
tableProperties) {
+ if (tableProperties == null || tableProperties.size() == 0) {
+ return;
+ }
+ try {
+ Table table = client.getTable(syncConfig.databaseName, tableName);
+ for (Map.Entry<String, String> entry: tableProperties.entrySet()) {
+ table.putToParameters(entry.getKey(), entry.getValue());
+ }
+ client.alter_table(syncConfig.databaseName, tableName, table);
+ } catch (Exception e) {
+ throw new HoodieHiveSyncException("Failed to get update table properties
for table: "
Review comment:
Thanks for your correct.
----------------------------------------------------------------
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:
[email protected]