You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hudi.apache.org by GitBox <gi...@apache.org> on 2021/05/04 14:52:08 UTC

[GitHub] [hudi] nsivabalan commented on a change in pull request #2904: [HUDI-1818] Validate and check required option for HoodieTable (Azure CI)

nsivabalan commented on a change in pull request #2904:
URL: https://github.com/apache/hudi/pull/2904#discussion_r625851911



##########
File path: hudi-flink/src/main/java/org/apache/hudi/table/HoodieTableFactory.java
##########
@@ -98,6 +102,33 @@ public String factoryIdentifier() {
   //  Utilities
   // -------------------------------------------------------------------------
 
+  /** Validate required options. e.g record key and pre combine key.
+   *
+   * @param conf The table options
+   * @param schema The table schema
+   */
+  private void validateRequiredOptions(Configuration conf, TableSchema schema) {
+    List<String> fields = Arrays.stream(schema.getFieldNames()).collect(Collectors.toList());
+
+    // validate record key in pk absence.
+    if (!schema.getPrimaryKey().isPresent()) {
+      Arrays.stream(conf.get(FlinkOptions.RECORD_KEY_FIELD).split(","))
+              .filter(field -> !fields.contains(field))
+              .findAny()
+              .ifPresent(e -> {
+                throw new ValidationException("The " + e + " field not exists in table schema."
+                        + "Please define primary key or modify hoodie.datasource.write.recordkey.field option.");
+              });
+    }
+
+    // validate pre combine key

Review comment:
       can we add a UT for this.




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