Skip to content

Commit

Permalink
Merge pull request alibaba#614 from yakolee/master
Browse files Browse the repository at this point in the history
bugfix for into outfile alibaba#582
  • Loading branch information
yakolee committed Aug 19, 2014
2 parents ff81384 + 2bb7018 commit 10b56be
Showing 1 changed file with 62 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,63 +125,8 @@ public SQLSelectQuery query() {
}

parseSelectList(queryBlock);

if (lexer.token() == (Token.INTO)) {
lexer.nextToken();

if (identifierEquals("OUTFILE")) {
lexer.nextToken();

MySqlOutFileExpr outFile = new MySqlOutFileExpr();
outFile.setFile(expr());

queryBlock.setInto(outFile);

if (identifierEquals("FIELDS") || identifierEquals("COLUMNS")) {
lexer.nextToken();

if (identifierEquals("TERMINATED")) {
lexer.nextToken();
accept(Token.BY);
}
outFile.setColumnsTerminatedBy((SQLLiteralExpr) expr());

if (identifierEquals("OPTIONALLY")) {
lexer.nextToken();
outFile.setColumnsEnclosedOptionally(true);
}

if (identifierEquals("ENCLOSED")) {
lexer.nextToken();
accept(Token.BY);
outFile.setColumnsEnclosedBy((SQLLiteralExpr) expr());
}

if (identifierEquals("ESCAPED")) {
lexer.nextToken();
accept(Token.BY);
outFile.setColumnsEscaped((SQLLiteralExpr) expr());
}
}

if (identifierEquals("LINES")) {
lexer.nextToken();

if (identifierEquals("STARTING")) {
lexer.nextToken();
accept(Token.BY);
outFile.setLinesStartingBy((SQLLiteralExpr) expr());
} else {
identifierEquals("TERMINATED");
lexer.nextToken();
accept(Token.BY);
outFile.setLinesTerminatedBy((SQLLiteralExpr) expr());
}
}
} else {
queryBlock.setInto(this.exprParser.name());
}
}

parseInto(queryBlock);
}

parseFrom(queryBlock);
Expand All @@ -201,11 +146,7 @@ public SQLSelectQuery query() {
throw new ParserException("TODO");
}

if (lexer.token() == Token.INTO) {
lexer.nextToken();
SQLExpr expr = this.exprParser.name();
queryBlock.setInto(expr);
}
parseInto(queryBlock);

if (lexer.token() == Token.FOR) {
lexer.nextToken();
Expand All @@ -224,6 +165,65 @@ public SQLSelectQuery query() {

return queryRest(queryBlock);
}

protected void parseInto(SQLSelectQueryBlock queryBlock) {
if (lexer.token() == (Token.INTO)) {
lexer.nextToken();

if (identifierEquals("OUTFILE")) {
lexer.nextToken();

MySqlOutFileExpr outFile = new MySqlOutFileExpr();
outFile.setFile(expr());

queryBlock.setInto(outFile);

if (identifierEquals("FIELDS") || identifierEquals("COLUMNS")) {
lexer.nextToken();

if (identifierEquals("TERMINATED")) {
lexer.nextToken();
accept(Token.BY);
}
outFile.setColumnsTerminatedBy((SQLLiteralExpr) expr());

if (identifierEquals("OPTIONALLY")) {
lexer.nextToken();
outFile.setColumnsEnclosedOptionally(true);
}

if (identifierEquals("ENCLOSED")) {
lexer.nextToken();
accept(Token.BY);
outFile.setColumnsEnclosedBy((SQLLiteralExpr) expr());
}

if (identifierEquals("ESCAPED")) {
lexer.nextToken();
accept(Token.BY);
outFile.setColumnsEscaped((SQLLiteralExpr) expr());
}
}

if (identifierEquals("LINES")) {
lexer.nextToken();

if (identifierEquals("STARTING")) {
lexer.nextToken();
accept(Token.BY);
outFile.setLinesStartingBy((SQLLiteralExpr) expr());
} else {
identifierEquals("TERMINATED");
lexer.nextToken();
accept(Token.BY);
outFile.setLinesTerminatedBy((SQLLiteralExpr) expr());
}
}
} else {
queryBlock.setInto(this.exprParser.name());
}
}
}

protected void parseGroupBy(SQLSelectQueryBlock queryBlock) {
SQLSelectGroupByClause groupBy = null;
Expand Down

0 comments on commit 10b56be

Please sign in to comment.