Navigation Menu

Skip to content

Commit

Permalink
IMPALA-2257: fix broken build caused by IMPALA-2251 fix
Browse files Browse the repository at this point in the history
The expected behavior when creating a table with the same delimiter and
escape character is to ignore the escape character.  This patch issues a
warning instead of an error when creating text tables with an escape
character that is the same as a delimiter.

Change-Id: I5cbdfbe96b321fbea727478146232449960ca52b
Reviewed-on: http://gerrit.cloudera.org:8080/700
Reviewed-by: Tim Armstrong <tarmstrong@cloudera.com>
Reviewed-by: Alex Behm <alex.behm@cloudera.com>
Tested-by: Internal Jenkins
  • Loading branch information
Tim Armstrong authored and Internal Jenkins committed Aug 28, 2015
1 parent a9c90f9 commit 8fcdff0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
Expand Up @@ -209,7 +209,7 @@ public void analyze(Analyzer analyzer) throws AnalysisException {
location_.analyze(analyzer, Privilege.ALL, FsAction.READ_WRITE);
}

analyzeRowFormat();
analyzeRowFormat(analyzer);

// Check that all the column names are valid and unique.
analyzeColumnDefs(analyzer);
Expand All @@ -227,24 +227,25 @@ public void analyze(Analyzer analyzer) throws AnalysisException {
if (cachingOp_ != null) cachingOp_.analyze(analyzer);
}

private void analyzeRowFormat() throws AnalysisException {
private void analyzeRowFormat(Analyzer analyzer) throws AnalysisException {
Byte fieldDelim = analyzeRowFormatValue(rowFormat_.getFieldDelimiter());
Byte lineDelim = analyzeRowFormatValue(rowFormat_.getLineDelimiter());
Byte escapeChar = analyzeRowFormatValue(rowFormat_.getEscapeChar());
if (fileFormat_ == THdfsFileFormat.TEXT) {
if (fieldDelim == null) fieldDelim = HdfsStorageDescriptor.DEFAULT_FIELD_DELIM;
if (lineDelim == null) lineDelim = HdfsStorageDescriptor.DEFAULT_LINE_DELIM;
if (escapeChar == null) escapeChar = HdfsStorageDescriptor.DEFAULT_ESCAPE_CHAR;
if (fieldDelim != null && lineDelim != null && fieldDelim.equals(lineDelim)) {
throw new AnalysisException("Field delimiter and line delimiter have same " +
"value: byte " + fieldDelim);
}
if (fieldDelim != null && escapeChar != null && fieldDelim.equals(escapeChar)) {
throw new AnalysisException("Field delimiter and escape character have same " +
"value: byte " + fieldDelim);
analyzer.addWarning("Field delimiter and escape character have same value: " +
"byte " + fieldDelim + ". Escape character will be ignored");
}
if (lineDelim != null && escapeChar != null && lineDelim.equals(escapeChar)) {
throw new AnalysisException("Line delimiter and escape character have same " +
"value: byte " + lineDelim);
analyzer.addWarning("Line delimiter and escape character have same value: " +
"byte " + lineDelim + ". Escape character will be ignored");
}
}
}
Expand Down
Expand Up @@ -1128,12 +1128,14 @@ public void TestCreateTable() throws AnalysisException {
AnalysisError("create table functional.broken_text_table (c int) " +
"row format delimited fields terminated by '\012'",
"Field delimiter and line delimiter have same value: byte 10");
AnalysisError("create table functional.broken_text_table (c int) " +
AnalyzesOk("create table functional.broken_text_table (c int) " +
"row format delimited escaped by '\001'",
"Field delimiter and escape character have same value: byte 1");
AnalysisError("create table functional.broken_text_table (c int) " +
"Field delimiter and escape character have same value: byte 1. " +
"Escape character will be ignored");
AnalyzesOk("create table functional.broken_text_table (c int) " +
"row format delimited escaped by 'x' lines terminated by 'x'",
"Line delimiter and escape character have same value: byte 120");
"Line delimiter and escape character have same value: byte 120. " +
"Escape character will be ignored");

AnalysisError("create table db_does_not_exist.new_table (i int)",
"Database does not exist: db_does_not_exist");
Expand Down

0 comments on commit 8fcdff0

Please sign in to comment.