tajo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From blrun...@apache.org
Subject tajo git commit: TAJO-1580: Error line number is incorrect.
Date Mon, 27 Apr 2015 05:31:34 GMT
Repository: tajo
Updated Branches:
  refs/heads/branch-0.10.1 b488a5e09 -> 9ca7688f6


TAJO-1580: Error line number is incorrect.

Signed-off-by: JaeHwa Jung <blrunner@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/tajo/repo
Commit: http://git-wip-us.apache.org/repos/asf/tajo/commit/9ca7688f
Tree: http://git-wip-us.apache.org/repos/asf/tajo/tree/9ca7688f
Diff: http://git-wip-us.apache.org/repos/asf/tajo/diff/9ca7688f

Branch: refs/heads/branch-0.10.1
Commit: 9ca7688f648d433d0a0eaf5dedb1919b67f106d8
Parents: b488a5e
Author: Jongyoung Park <eminency@gmail.com>
Authored: Mon Apr 27 14:16:54 2015 +0900
Committer: JaeHwa Jung <blrunner@apache.org>
Committed: Mon Apr 27 14:16:54 2015 +0900

----------------------------------------------------------------------
 CHANGES                                         |  3 +++
 .../org/apache/tajo/cli/tsql/SimpleParser.java  | 11 ++++++-----
 .../apache/tajo/cli/tsql/TestSimpleParser.java  | 20 ++++++++++++++++----
 3 files changed, 25 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tajo/blob/9ca7688f/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index be3c1f8..b7012c8 100644
--- a/CHANGES
+++ b/CHANGES
@@ -27,6 +27,9 @@ Release 0.10.1 - unreleased
 
   BUG FIXES
 
+    TAJO-1580: Error line number is incorrect.
+    (Contributed by Jongyoung Park. Committed by jaehwa)
+    
     TAJO-1419: Tsql session command doesn't work. (Contributed by DaeMyung Kang,
     Committed by jihoon)
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/9ca7688f/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/SimpleParser.java
----------------------------------------------------------------------
diff --git a/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/SimpleParser.java b/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/SimpleParser.java
index cc772a3..940a5ff 100644
--- a/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/SimpleParser.java
+++ b/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/SimpleParser.java
@@ -89,7 +89,10 @@ public class SimpleParser {
 
     // if parsing continues, it means that the previous line is broken by '\n'.
     // So, we should add new line to rawAppender.
-    if (isStatementContinue()) {
+    int appenderLen = rawAppender.length();
+    if (appenderLen != 0
+      && rawAppender.charAt(appenderLen - 1) != '\n'
+      && isStatementContinue()) {
       rawAppender.append("\n");
     }
 
@@ -180,7 +183,7 @@ public class SimpleParser {
             appendToBothStatements(chars, lineStartIdx, idx, 2); // omit two dash characters
'--' from history statement
             int commentStartIdx = idx;
             idx = consumeInlineComment(chars, idx);
-            appendToRawStatement(str.subSequence(commentStartIdx, idx).toString(), true);
+            appendToRawStatement(str.subSequence(commentStartIdx, idx).toString(), false);
             lineStartIdx = idx;
           }
           ///////////////////////////////////////////////////////
@@ -281,6 +284,7 @@ public class SimpleParser {
   private void appendToRawStatement(String str, boolean addLF) {
     if (!str.isEmpty() && !"\n".equals(str) &&
         rawAppender.length() > 0 && addLF && rawAppender.charAt(rawAppender.length()
- 1) != '\n') {
+      rawAppender.append("\n");
       rawAppender.append(str);
     } else {
       rawAppender.append(str);
@@ -297,9 +301,6 @@ public class SimpleParser {
 
   /**
    * It checks if inline comment '--' begins.
-   * @param chars
-   * @param idx
-   * @return
    */
   private boolean isInlineCommentStart(char[] chars, int idx) {
     if (idx >= chars.length - 1) {

http://git-wip-us.apache.org/repos/asf/tajo/blob/9ca7688f/tajo-core/src/test/java/org/apache/tajo/cli/tsql/TestSimpleParser.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/cli/tsql/TestSimpleParser.java b/tajo-core/src/test/java/org/apache/tajo/cli/tsql/TestSimpleParser.java
index 33a5621..69bf30a 100644
--- a/tajo-core/src/test/java/org/apache/tajo/cli/tsql/TestSimpleParser.java
+++ b/tajo-core/src/test/java/org/apache/tajo/cli/tsql/TestSimpleParser.java
@@ -18,9 +18,6 @@
 
 package org.apache.tajo.cli.tsql;
 
-import org.apache.tajo.cli.tsql.InvalidStatementException;
-import org.apache.tajo.cli.tsql.ParsedResult;
-import org.apache.tajo.cli.tsql.SimpleParser;
 import org.junit.Test;
 
 import java.util.List;
@@ -159,6 +156,8 @@ public class TestSimpleParser {
     assertEquals("select * from test1", res1.get(0).getHistoryStatement());
     assertEquals("select * from test2", res1.get(1).getHistoryStatement());
 
+    // select * from
+    // test1; select * from test2;
     simpleParser = new SimpleParser();
     res1 = simpleParser.parseLines("select * from ");
     assertEquals(0, res1.size());
@@ -182,7 +181,6 @@ public class TestSimpleParser {
     assertEquals("select * from test3", res1.get(0).getHistoryStatement());
     assertEquals("select * from \n--test1; select * from test2;\ntest3", res1.get(0).getStatement());
 
-
     // select * from
     // test1 --select * from test2;
     // where col1 = '123';
@@ -195,6 +193,20 @@ public class TestSimpleParser {
     assertEquals(1, res1.size());
     assertEquals("select * from test1 where col1 = '123'", res1.get(0).getHistoryStatement());
     assertEquals("select * from \ntest1 --select * from test2;\nwhere col1 = '123'", res1.get(0).getStatement());
+
+    // Case for sql statement already including '\n'
+    // This test is important for tsql because CLI input always has '\n'.
+    simpleParser = new SimpleParser();
+    res1 = simpleParser.parseLines("select\n");
+    assertEquals(0, res1.size());
+    res1 = simpleParser.parseLines("*\n");
+    assertEquals(0, res1.size());
+    res1 = simpleParser.parseLines("from\n");
+    assertEquals(0, res1.size());
+    res1 = simpleParser.parseLines("test1;\n");
+    assertEquals(1, res1.size());
+    assertEquals("select\n*\nfrom\ntest1", res1.get(0).getStatement());
+    assertEquals("select * from test1", res1.get(0).getHistoryStatement());
   }
 
   @Test


Mime
View raw message