You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tajo.apache.org by hy...@apache.org on 2014/05/08 04:50:26 UTC

git commit: TAJO-800: CLI's meta command should be aware "TABLE_NAME" style. (Hyoungjun Kim via hyunsik)

Repository: tajo
Updated Branches:
  refs/heads/master 3ffb4ee24 -> eb4e54a14


TAJO-800: CLI's meta command should be aware "TABLE_NAME" style. (Hyoungjun Kim via hyunsik)


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

Branch: refs/heads/master
Commit: eb4e54a14a0f62749c4163d7192bdd547bc64e12
Parents: 3ffb4ee
Author: Hyunsik Choi <hy...@apache.org>
Authored: Thu May 8 11:50:00 2014 +0900
Committer: Hyunsik Choi <hy...@apache.org>
Committed: Thu May 8 11:50:00 2014 +0900

----------------------------------------------------------------------
 CHANGES                                         |  3 +
 .../apache/tajo/cli/ConnectDatabaseCommand.java | 11 +--
 .../org/apache/tajo/cli/DescTableCommand.java   |  6 +-
 .../main/java/org/apache/tajo/cli/TajoCli.java  |  2 +
 .../java/org/apache/tajo/cli/TestTajoCli.java   | 83 +++++++++++++++++++-
 .../results/TestTajoCli/testDescTable.result    | 29 +++++++
 6 files changed, 123 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tajo/blob/eb4e54a1/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 8a2e891..3c5237e 100644
--- a/CHANGES
+++ b/CHANGES
@@ -31,6 +31,9 @@ Release 0.9.0 - unreleased
 
   BUG FIXES
 
+    TAJO-800: CLI's meta command should be aware "TABLE_NAME" style. 
+    (Hyoungjun Kim via hyunsik)
+
     TAJO-795: PlannerUtil::joinJoinKeyForEachTable need to handle theta-join. (jaehwa)
 
     TAJO-792: Insert table error with database name. 

http://git-wip-us.apache.org/repos/asf/tajo/blob/eb4e54a1/tajo-client/src/main/java/org/apache/tajo/cli/ConnectDatabaseCommand.java
----------------------------------------------------------------------
diff --git a/tajo-client/src/main/java/org/apache/tajo/cli/ConnectDatabaseCommand.java b/tajo-client/src/main/java/org/apache/tajo/cli/ConnectDatabaseCommand.java
index cb0bfdb..4158d67 100644
--- a/tajo-client/src/main/java/org/apache/tajo/cli/ConnectDatabaseCommand.java
+++ b/tajo-client/src/main/java/org/apache/tajo/cli/ConnectDatabaseCommand.java
@@ -37,12 +37,13 @@ public class ConnectDatabaseCommand extends TajoShellCommand {
       context.getOutput().write(String.format("You are now connected to database \"%s\" as user \"%s\".%n",
           client.getCurrentDatabase(), client.getUserInfo().getUserName()));
     } else if (cmd.length == 2) {
-
-      if (!client.existDatabase(cmd[1])) {
-        context.getOutput().write("Database '" + cmd[1] + "' not found\n");
+      String databaseName = cmd[1];
+      databaseName = databaseName.replace("\"", "");
+      if (!client.existDatabase(databaseName)) {
+        context.getOutput().write("Database '" + databaseName + "'  not found\n");
       } else {
         try {
-          if (client.selectDatabase(cmd[1])) {
+          if (client.selectDatabase(databaseName)) {
             context.setCurrentDatabase(client.getCurrentDatabase());
             context.getOutput().write(String.format("You are now connected to database \"%s\" as user \"%s\".%n",
                 context.getCurrentDatabase(), client.getUserInfo().getUserName()));
@@ -51,7 +52,7 @@ public class ConnectDatabaseCommand extends TajoShellCommand {
           if (se.getMessage() != null) {
             context.getOutput().write(se.getMessage());
           } else {
-            context.getOutput().write(String.format("cannot connect the database \"%s\"", cmd[1]));
+            context.getOutput().write(String.format("cannot connect the database \"%s\"", databaseName));
           }
         }
       }

http://git-wip-us.apache.org/repos/asf/tajo/blob/eb4e54a1/tajo-client/src/main/java/org/apache/tajo/cli/DescTableCommand.java
----------------------------------------------------------------------
diff --git a/tajo-client/src/main/java/org/apache/tajo/cli/DescTableCommand.java b/tajo-client/src/main/java/org/apache/tajo/cli/DescTableCommand.java
index 0907b56..6bda7c9 100644
--- a/tajo-client/src/main/java/org/apache/tajo/cli/DescTableCommand.java
+++ b/tajo-client/src/main/java/org/apache/tajo/cli/DescTableCommand.java
@@ -40,9 +40,11 @@ public class DescTableCommand extends TajoShellCommand {
   @Override
   public void invoke(String[] cmd) throws Exception {
     if (cmd.length == 2) {
-      TableDesc desc = client.getTableDesc(cmd[1]);
+      String tableName = cmd[1];
+      tableName = tableName.replace("\"", "");
+      TableDesc desc = client.getTableDesc(tableName);
       if (desc == null) {
-        context.getOutput().println("Did not find any relation named \"" + cmd[1] + "\"");
+        context.getOutput().println("Did not find any relation named \"" + tableName + "\"");
       } else {
         context.getOutput().println(toFormattedString(desc));
       }

http://git-wip-us.apache.org/repos/asf/tajo/blob/eb4e54a1/tajo-client/src/main/java/org/apache/tajo/cli/TajoCli.java
----------------------------------------------------------------------
diff --git a/tajo-client/src/main/java/org/apache/tajo/cli/TajoCli.java b/tajo-client/src/main/java/org/apache/tajo/cli/TajoCli.java
index 959e9df..2f9d5cf 100644
--- a/tajo-client/src/main/java/org/apache/tajo/cli/TajoCli.java
+++ b/tajo-client/src/main/java/org/apache/tajo/cli/TajoCli.java
@@ -343,6 +343,8 @@ public class TajoCli {
       } catch (Exception e) {
         outputFormatter.printErrorMessage(sout, e);
         return -1;
+      } finally {
+        context.getOutput().flush();
       }
     }
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/eb4e54a1/tajo-core/src/test/java/org/apache/tajo/cli/TestTajoCli.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/cli/TestTajoCli.java b/tajo-core/src/test/java/org/apache/tajo/cli/TestTajoCli.java
index 799f175..b3fbda4 100644
--- a/tajo-core/src/test/java/org/apache/tajo/cli/TestTajoCli.java
+++ b/tajo-core/src/test/java/org/apache/tajo/cli/TestTajoCli.java
@@ -23,6 +23,7 @@ import org.apache.commons.cli.CommandLineParser;
 import org.apache.commons.cli.PosixParser;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
+import org.apache.tajo.TajoTestingCluster;
 import org.apache.tajo.TpchTestBase;
 import org.apache.tajo.conf.TajoConf;
 import org.apache.tajo.conf.TajoConf.ConfVars;
@@ -43,12 +44,13 @@ import static org.junit.Assert.assertTrue;
 
 public class TestTajoCli {
   protected static final TpchTestBase testBase;
+  protected static final TajoTestingCluster cluster;
 
   /** the base path of result directories */
   protected static final Path resultBasePath;
-
   static {
     testBase = TpchTestBase.getInstance();
+    cluster = testBase.getTestingCluster();
     URL resultBaseURL = ClassLoader.getSystemResource("results");
     resultBasePath = new Path(resultBaseURL.toString());
   }
@@ -65,7 +67,7 @@ public class TestTajoCli {
   }
 
   @After
-  public void teadDown() {
+  public void tearDown() {
     if (tajoCli != null) {
       tajoCli.close();
     }
@@ -136,13 +138,86 @@ public class TestTajoCli {
     assertOutputResult(consoleResult);
   }
 
+  @Test
+  public void testConnectDatabase() throws Exception {
+    String databaseName;
+
+    if (cluster.isHCatalogStoreRunning()) {
+      databaseName = "TEST_CONNECTION_DATABASE".toLowerCase();
+    } else {
+      databaseName = "TEST_CONNECTION_DATABASE";
+    }
+    String sql = "create database \"" + databaseName + "\";";
+    TajoConf tajoConf = TpchTestBase.getInstance().getTestingCluster().getConfiguration();
+    tajoConf.setVar(ConfVars.CLI_OUTPUT_FORMATTER_CLASS, TajoCliOutputTestFormatter.class.getName());
+
+    ByteArrayOutputStream out = new ByteArrayOutputStream();
+    tajoCli = new TajoCli(tajoConf, new String[]{}, System.in, out);
+    tajoCli.executeScript(sql);
+
+    tajoCli.executeMetaCommand("\\c " + databaseName);
+    assertEquals(databaseName, tajoCli.getContext().getCurrentDatabase());
+
+    tajoCli.executeMetaCommand("\\c default");
+    assertEquals("default", tajoCli.getContext().getCurrentDatabase());
+
+    tajoCli.executeMetaCommand("\\c \"" + databaseName + "\"");
+    assertEquals(databaseName, tajoCli.getContext().getCurrentDatabase());
+  }
+
+  @Test
+  public void testDescTable() throws Exception {
+    String tableName;
+    if (cluster.isHCatalogStoreRunning()) {
+      tableName = "TEST_DESC_TABLE".toLowerCase();
+    } else {
+      tableName = "TEST_DESC_TABLE";
+    }
+
+    String sql = "create table \"" + tableName + "\" (col1 int4, col2 int4);";
+
+    TajoConf tajoConf = TpchTestBase.getInstance().getTestingCluster().getConfiguration();
+    tajoConf.setVar(ConfVars.CLI_OUTPUT_FORMATTER_CLASS, TajoCliOutputTestFormatter.class.getName());
+
+    ByteArrayOutputStream out = new ByteArrayOutputStream();
+    tajoCli = new TajoCli(tajoConf, new String[]{}, System.in, out);
+    tajoCli.executeScript(sql);
+
+    tajoCli.executeMetaCommand("\\d " + tableName);
+    tajoCli.executeMetaCommand("\\d \"" + tableName + "\"");
+
+    String consoleResult = new String(out.toByteArray());
+
+    FileSystem fs = FileSystem.get(testBase.getTestingCluster().getConfiguration());
+    if (!cluster.isHCatalogStoreRunning()) {
+      assertOutputResult("testDescTable.result", consoleResult, new String[]{"${table.path}"},
+          new String[]{fs.getUri() + "/tajo/warehouse/default/" + tableName});
+    }
+  }
+
   private void assertOutputResult(String actual) throws Exception {
-    String resultFileName = name.getMethodName() + ".result";
+    assertOutputResult(name.getMethodName() + ".result", actual);
+  }
+
+  private void assertOutputResult(String expectedResultFile, String actual) throws Exception {
+    assertOutputResult(expectedResultFile, actual, null, null);
+  }
+
+  private void assertOutputResult(String expectedResultFile, String actual, String[] paramKeys, String[] paramValues)
+      throws Exception {
     FileSystem fs = currentResultPath.getFileSystem(testBase.getTestingCluster().getConfiguration());
-    Path resultFile = StorageUtil.concatPath(currentResultPath, resultFileName);
+    Path resultFile = StorageUtil.concatPath(currentResultPath, expectedResultFile);
     assertTrue(resultFile.toString() + " existence check", fs.exists(resultFile));
 
     String expectedResult = FileUtil.readTextFile(new File(resultFile.toUri()));
+
+    if (paramKeys != null) {
+      for (int i = 0; i < paramKeys.length; i++) {
+        if (i < paramValues.length) {
+          expectedResult = expectedResult.replace(paramKeys[i], paramValues[i]);
+        }
+      }
+    }
     assertEquals(expectedResult, actual);
   }
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/eb4e54a1/tajo-core/src/test/resources/results/TestTajoCli/testDescTable.result
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/resources/results/TestTajoCli/testDescTable.result b/tajo-core/src/test/resources/results/TestTajoCli/testDescTable.result
new file mode 100644
index 0000000..d9319eb
--- /dev/null
+++ b/tajo-core/src/test/resources/results/TestTajoCli/testDescTable.result
@@ -0,0 +1,29 @@
+OK
+
+table name: default.TEST_DESC_TABLE
+table path: ${table.path}
+store type: CSV
+number of rows: 0
+volume: 0 B
+Options: 
+	'csvfile.delimiter'='|'
+
+schema: 
+col1	INT4
+col2	INT4
+
+
+
+table name: default.TEST_DESC_TABLE
+table path: ${table.path}
+store type: CSV
+number of rows: 0
+volume: 0 B
+Options: 
+	'csvfile.delimiter'='|'
+
+schema: 
+col1	INT4
+col2	INT4
+
+