Index: ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFInFile.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFInFile.java (revision 2e818152a5cc6898c5a734087788bab655c2d343) +++ ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFInFile.java (revision ) @@ -19,11 +19,13 @@ package org.apache.hadoop.hive.ql.udf.generic; import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; +import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.nio.charset.Charset; +import java.nio.file.FileSystems; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.HashSet; import org.apache.hadoop.hive.ql.exec.Description; @@ -106,29 +108,48 @@ arguments[0].get(), strObjectInspector).toString(); if (set == null) { - String fileName = (String)ObjectInspectorUtils.copyToStandardJavaObject( + String filePath = (String)ObjectInspectorUtils.copyToStandardJavaObject( arguments[1].get(), fileObjectInspector); - try { - load(new FileInputStream((new File(fileName)).getName())); - } catch (FileNotFoundException e) { - throw new HiveException(e); + load(getReaderFor(filePath)); - } + } + + return set.contains(str); - } + } - return Boolean.valueOf(set.contains(str)); + private BufferedReader getReaderFor(String filePath) throws HiveException { + try { + + Path fullFilePath = FileSystems.getDefault().getPath(filePath); + Path fileName = fullFilePath.getFileName(); + + if (Files.exists(fileName)) { + return Files.newBufferedReader(fileName, Charset.defaultCharset()); - } + } + else + if (Files.exists(fullFilePath)) { + return Files.newBufferedReader(fullFilePath, Charset.defaultCharset()); + } + else { + throw new HiveException("Could not find \"" + fileName + "\" or \"" + fullFilePath + "\" in IN_FILE() UDF."); + } + } + catch(IOException exception) { + throw new HiveException(exception); + } + } /** * Load the file from an InputStream. * @param is The InputStream contains the file data. * @throws HiveException */ + @Deprecated public void load(InputStream is) throws HiveException { - BufferedReader reader = - new BufferedReader(new InputStreamReader(is)); + load(new BufferedReader(new InputStreamReader(is))); + } + private void load(BufferedReader reader) throws HiveException { set = new HashSet(); - try { String line; while((line = reader.readLine()) != null) {