hudi-agent commented on code in PR #19519:
URL: https://github.com/apache/hudi/pull/19519#discussion_r3717995249


##########
hudi-flink-datasource/hudi-flink/src/main/java/org/apache/hudi/configuration/HadoopConfigurations.java:
##########
@@ -49,7 +49,14 @@ public static org.apache.hadoop.conf.Configuration 
getParquetConf(
    */
   public static org.apache.hadoop.conf.Configuration 
getHadoopConf(Configuration conf) {
     org.apache.hadoop.conf.Configuration hadoopConf = 
FlinkClientUtil.getHadoopConf();
+    // If hadoop.conf.dir is explicitly configured, load from that directory.
+    // This enables cross-cluster writes by pointing to a different cluster's 
Hadoop conf.
+    String hadoopConfDir = conf.getString(FlinkOptions.HADOOP_CONF_DIR.key(), 
null);
+    if (hadoopConfDir != null && !hadoopConfDir.isEmpty()) {
+      hadoopConf = FlinkClientUtil.getHadoopConf(hadoopConfDir);
+    }

Review Comment:
   🤖 The `hadoop.conf.dir` key falls inside the `hadoop.` passthrough prefix, 
so it also gets picked up by `getPropertiesWithPrefix(..., HADOOP_PREFIX)` as 
`conf.dir`, forcing this `options.remove("conf.dir")` workaround. That coupling 
is easy to break later. Was naming it outside the prefix (e.g. under a 
`hoodie.`/flink-specific namespace) considered so no special-casing is needed?
   
   <sub><i>⚠️ AI-generated; verify before applying. React 👍/👎 to flag 
quality.</i></sub>



##########
hudi-client/hudi-flink-client/src/main/java/org/apache/hudi/util/FlinkClientUtil.java:
##########
@@ -59,6 +59,15 @@ public static org.apache.hadoop.conf.Configuration 
getHadoopConf() {
     return hadoopConf;
   }
 
+  public static org.apache.hadoop.conf.Configuration getHadoopConf(String 
hadoopConfDir) {
+    org.apache.hadoop.conf.Configuration hadoopConf;
+    hadoopConf = getHadoopConfiguration(hadoopConfDir);
+    if (hadoopConf == null){

Review Comment:
   🤖 When the directory doesn't exist (or is mistyped), 
`getHadoopConfiguration` returns null and this falls back to a bare `new 
Configuration()`. Since `HadoopConfigurations.getHadoopConf` then *replaces* 
the env-derived conf with this result, a typo in `hadoop.conf.dir` would 
silently use the default/local cluster config instead of the intended remote 
one — for a cross-cluster write that could route data to the wrong cluster with 
no error. Could you log a warning (or fail) when the configured dir doesn't 
exist rather than silently falling back?
   
   <sub><i>⚠️ AI-generated; verify before applying. React 👍/👎 to flag 
quality.</i></sub>



##########
hudi-flink-datasource/hudi-flink/src/main/java/org/apache/hudi/configuration/HadoopConfigurations.java:
##########
@@ -49,7 +49,14 @@ public static org.apache.hadoop.conf.Configuration 
getParquetConf(
    */
   public static org.apache.hadoop.conf.Configuration 
getHadoopConf(Configuration conf) {
     org.apache.hadoop.conf.Configuration hadoopConf = 
FlinkClientUtil.getHadoopConf();
+    // If hadoop.conf.dir is explicitly configured, load from that directory.
+    // This enables cross-cluster writes by pointing to a different cluster's 
Hadoop conf.
+    String hadoopConfDir = conf.getString(FlinkOptions.HADOOP_CONF_DIR.key(), 
null);
+    if (hadoopConfDir != null && !hadoopConfDir.isEmpty()) {
+      hadoopConf = FlinkClientUtil.getHadoopConf(hadoopConfDir);
+    }
     Map<String, String> options = 
FlinkOptions.getPropertiesWithPrefix(conf.toMap(), HADOOP_PREFIX);
+    options.remove("conf.dir");

Review Comment:
   🤖 nit: the magic string `"conf.dir"` here is easy to misread — could you add 
an inline comment explaining that this strips the key left over after the 
`hadoop.` prefix is removed from `hadoop.conf.dir`? Something like `// remove 
"conf.dir" — the residual key after stripping the "hadoop." prefix from 
hadoop.conf.dir`.
   
   <sub><i>⚠️ AI-generated; verify before applying. React 👍/👎 to flag 
quality.</i></sub>



##########
hudi-client/hudi-flink-client/src/main/java/org/apache/hudi/util/FlinkClientUtil.java:
##########
@@ -59,6 +59,15 @@ public static org.apache.hadoop.conf.Configuration 
getHadoopConf() {
     return hadoopConf;
   }
 
+  public static org.apache.hadoop.conf.Configuration getHadoopConf(String 
hadoopConfDir) {
+    org.apache.hadoop.conf.Configuration hadoopConf;

Review Comment:
   🤖 nit: could you combine the declaration and assignment into a single line? 
`org.apache.hadoop.conf.Configuration hadoopConf = 
getHadoopConfiguration(hadoopConfDir);` reads more naturally.
   
   <sub><i>⚠️ AI-generated; verify before applying. React 👍/👎 to flag 
quality.</i></sub>



##########
hudi-flink-datasource/hudi-flink/src/test/java/org/apache/hudi/configuration/TestHadoopConfigurations.java:
##########
@@ -0,0 +1,179 @@
+/*
+ * 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.configuration;
+
+import org.apache.flink.configuration.Configuration;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+/**
+ * Tests for {@link HadoopConfigurations} with the hadoop.conf.dir option.
+ */
+public class TestHadoopConfigurations {
+
+    @TempDir
+    File tempDir;
+
+    // 
-------------------------------------------------------------------------
+    //  Helpers
+    // 
-------------------------------------------------------------------------
+
+    /**
+     * Writes a minimal core-site.xml with the given key/value into the 
specified directory.
+     */
+    private void writeCoreSite(File confDir, String key, String value) throws 
IOException {

Review Comment:
   🤖 nit: `writeCoreSite` and `writeHdfsSite` are identical except for the 
filename — have you considered collapsing them into a single `writeSiteXml(File 
dir, String fileName, String key, String value)` helper?
   
   <sub><i>⚠️ AI-generated; verify before applying. React 👍/👎 to flag 
quality.</i></sub>



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