danny0405 commented on code in PR #18384:
URL: https://github.com/apache/hudi/pull/18384#discussion_r3256106821


##########
hudi-common/src/main/java/org/apache/hudi/common/model/HoodieMetaFieldFlags.java:
##########
@@ -0,0 +1,280 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hudi.common.model;
+
+import org.apache.hudi.common.config.HoodieConfig;
+import org.apache.hudi.common.table.HoodieTableConfig;
+import org.apache.hudi.exception.HoodieException;
+
+import java.io.Serializable;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.TreeSet;
+
+/**
+ * Encapsulates which individual meta fields should be populated during writes.
+ * Provides named accessor methods for better readability compared to boolean 
array indexing.
+ *
+ * <p>The flags correspond to the 5 standard Hudi meta columns in {@link 
HoodieRecord#HOODIE_META_COLUMNS}:
+ * commit_time, commit_seqno, record_key, partition_path, file_name.
+ */
+public class HoodieMetaFieldFlags implements Serializable {
+
+  private static final long serialVersionUID = 1L;
+
+  private static final HoodieMetaFieldFlags ALL_POPULATED = new 
HoodieMetaFieldFlags(true, true, true, true, true);
+  private static final HoodieMetaFieldFlags NONE_POPULATED = new 
HoodieMetaFieldFlags(false, false, false, false, false);
+
+  private final boolean commitTimePopulated;
+  private final boolean commitSeqNoPopulated;
+  private final boolean recordKeyPopulated;
+  private final boolean partitionPathPopulated;
+  private final boolean fileNamePopulated;
+
+  private HoodieMetaFieldFlags(boolean commitTimePopulated, boolean 
commitSeqNoPopulated,
+                               boolean recordKeyPopulated, boolean 
partitionPathPopulated,
+                               boolean fileNamePopulated) {
+    this.commitTimePopulated = commitTimePopulated;
+    this.commitSeqNoPopulated = commitSeqNoPopulated;
+    this.recordKeyPopulated = recordKeyPopulated;
+    this.partitionPathPopulated = partitionPathPopulated;
+    this.fileNamePopulated = fileNamePopulated;
+  }
+
+  /**
+   * Returns an instance where all meta fields are populated.
+   */
+  public static HoodieMetaFieldFlags allPopulated() {
+    return ALL_POPULATED;
+  }
+
+  /**
+   * Returns an instance where no meta fields are populated.
+   */
+  public static HoodieMetaFieldFlags nonePopulated() {
+    return NONE_POPULATED;
+  }
+
+  /**
+   * Creates an instance from a set of excluded field names.
+   *
+   * @param excluded set of meta field names to exclude (e.g. 
"_hoodie_record_key")
+   * @return HoodieMetaFieldFlags with excluded fields marked as not populated
+   * @throws IllegalArgumentException if {@code excluded} contains names that 
are not in
+   *         {@link HoodieRecord#HOODIE_META_COLUMNS}, so configuration typos 
fail fast
+   *         rather than being silently ignored.
+   */
+  public static HoodieMetaFieldFlags fromExcludedFields(Set<String> excluded) {
+    if (excluded == null || excluded.isEmpty()) {
+      return ALL_POPULATED;
+    }
+    Set<String> unknown = new HashSet<>(excluded);
+    unknown.removeAll(HoodieRecord.HOODIE_META_COLUMNS);
+    if (!unknown.isEmpty()) {
+      throw new IllegalArgumentException(
+          "Unknown meta field name(s) in exclusion list: " + unknown
+              + ". Valid names are: " + HoodieRecord.HOODIE_META_COLUMNS);
+    }
+    return new HoodieMetaFieldFlags(
+        !excluded.contains(HoodieRecord.COMMIT_TIME_METADATA_FIELD),
+        !excluded.contains(HoodieRecord.COMMIT_SEQNO_METADATA_FIELD),
+        !excluded.contains(HoodieRecord.RECORD_KEY_METADATA_FIELD),
+        !excluded.contains(HoodieRecord.PARTITION_PATH_METADATA_FIELD),
+        !excluded.contains(HoodieRecord.FILENAME_METADATA_FIELD)
+    );
+  }
+
+  /**
+   * Resolves the flags from a {@link HoodieConfig} (typically the merged write
+   * config or the table config). Reads {@link 
HoodieTableConfig#POPULATE_META_FIELDS}
+   * and {@link HoodieTableConfig#META_FIELDS_EXCLUDE_LIST}; the exclusion 
list is
+   * a comma-separated list of meta-field names with whitespace tolerated.
+   */
+  public static HoodieMetaFieldFlags fromConfig(HoodieConfig config) {

Review Comment:
   we better not expose public construction APIs from here and limit the fetch 
of it to be always from the `HoodieTableConfig`, 
`HoodieTableConfig.getHoodieMetaFieldFlags` is the only entrance to fetch it.



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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to