Skip to content

Commit

Permalink
Handle tildes when importing CSVs
Browse files Browse the repository at this point in the history
  • Loading branch information
fabuzaid21 committed Mar 18, 2018
1 parent de08881 commit 0c9e334
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,22 @@ public CSVDataFrameParser(CsvParser parser, List<String> requiredColumns) {
this.parser = parser;
}

public CSVDataFrameParser(String fileName, List<String> requiredColumns) throws IOException {
public CSVDataFrameParser(String filename, List<String> requiredColumns) throws IOException {
this.requiredColumns = requiredColumns;
CsvParserSettings settings = new CsvParserSettings();
settings.getFormat().setLineSeparator("\n");
CsvParser csvParser = new CsvParser(settings);
csvParser.beginParsing(getReader(fileName));
csvParser.beginParsing(getReader(filename));
this.parser = csvParser;
}

public CSVDataFrameParser(String fileName, Map<String, Schema.ColType> types) throws IOException {
public CSVDataFrameParser(String filename, Map<String, Schema.ColType> types) throws IOException {
this.requiredColumns = new ArrayList<>(types.keySet());
this.columnTypes = types;
CsvParserSettings settings = new CsvParserSettings();
settings.getFormat().setLineSeparator("\n");
CsvParser csvParser = new CsvParser(settings);
csvParser.beginParsing(getReader(fileName));
csvParser.beginParsing(getReader(filename));
this.parser = csvParser;
}

Expand Down Expand Up @@ -132,7 +132,8 @@ public DataFrame load() throws Exception {

private static Reader getReader(String path) {
try {
InputStream targetStream = new FileInputStream(path);
InputStream targetStream = new FileInputStream(
path.replaceFirst("^~", System.getProperty("user.home")));
return new InputStreamReader(targetStream, "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException("File " + path + "is not encoded using UTF-8", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ private void executeQueries(final String queries, final boolean fromFile) {
}
} catch (ParsingException | MacroBaseException e) {
e.printStackTrace(System.err);
//System.err.println(e.getMessage());
System.err.println();
}
}
Expand Down

0 comments on commit 0c9e334

Please sign in to comment.