当写一个 UDF 比方说一个 EvalFunc 时,是否可以传递一个配置文件
properties = new Properties();
properties.load(new FileInputStream("conf/config.properties"));
在 Hadoop 模式下运行时?
最好的, 将
最佳答案
这是 从 Hadoop DFS 读取和写入文件的简单示例
来自 http://wiki.apache.org/hadoop/HadoopDfsReadWriteExample
也许您可以在其中找到一些有用的代码来完成您的工作。
以下是我的代码,它成功地在 hadoop 中加载了一个属性文件,我使用了 Apache Commons Configuration
http://commons.apache.org/configuration/
public static void loadProperites(String path) throws ConfigurationException, IOException {
Configuration conf = new Configuration();
FileSystem fs = FileSystem.get(conf);
Path inFile = new Path(path);
FSDataInputStream in = fs.open(inFile);
PropertiesConfiguration config = new PropertiesConfiguration();
config.load(in);
in.close();
}
关于hadoop - 在 udf 中加载外部属性文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6032380/