You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lens.apache.org by de...@apache.org on 2016/02/03 13:10:57 UTC

[37/51] [abbrv] lens git commit: LENS-923: CLI should allow query execution without the prefix 'query execute'

LENS-923: CLI should allow query execution without the prefix 'query execute'


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

Branch: refs/heads/current-release-line
Commit: 919936bec58529ad555a2f858bb8eed56b34ac4e
Parents: b1f38d5
Author: Rajat Khandelwal <pr...@apache.org>
Authored: Mon Jan 25 19:36:26 2016 +0800
Committer: Raju Bairishetti <ra...@apache.org>
Committed: Mon Jan 25 19:36:26 2016 +0800

----------------------------------------------------------------------
 .../lens/cli/commands/BaseLensCommand.java      |  9 ++++
 .../cli/commands/LensLogResourceCommands.java   |  4 +-
 .../lens/cli/commands/LensQueryCommands.java    | 56 ++++++++++++--------
 src/site/apt/user/cli.apt                       |  8 ++-
 4 files changed, 51 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lens/blob/919936be/lens-cli/src/main/java/org/apache/lens/cli/commands/BaseLensCommand.java
----------------------------------------------------------------------
diff --git a/lens-cli/src/main/java/org/apache/lens/cli/commands/BaseLensCommand.java b/lens-cli/src/main/java/org/apache/lens/cli/commands/BaseLensCommand.java
index 6437725..66a6c4d 100644
--- a/lens-cli/src/main/java/org/apache/lens/cli/commands/BaseLensCommand.java
+++ b/lens-cli/src/main/java/org/apache/lens/cli/commands/BaseLensCommand.java
@@ -194,4 +194,13 @@ public class BaseLensCommand implements ExecutionProcessor {
     return pathValidator.removePrefixBeforeURI(path);
   }
 
+  public String getOrDefaultQueryHandleString(String queryHandleString) {
+    if (queryHandleString != null) {
+      return queryHandleString;
+    }
+    if (getClient().getStatement().getQuery() != null) {
+      return getClient().getStatement().getQueryHandleString();
+    }
+    throw new IllegalArgumentException("Query handle not provided and no queries interacted with in the session.");
+  }
 }

http://git-wip-us.apache.org/repos/asf/lens/blob/919936be/lens-cli/src/main/java/org/apache/lens/cli/commands/LensLogResourceCommands.java
----------------------------------------------------------------------
diff --git a/lens-cli/src/main/java/org/apache/lens/cli/commands/LensLogResourceCommands.java b/lens-cli/src/main/java/org/apache/lens/cli/commands/LensLogResourceCommands.java
index 59b7355..1a3394a 100644
--- a/lens-cli/src/main/java/org/apache/lens/cli/commands/LensLogResourceCommands.java
+++ b/lens-cli/src/main/java/org/apache/lens/cli/commands/LensLogResourceCommands.java
@@ -46,11 +46,13 @@ public class LensLogResourceCommands extends BaseLensCommand {
 
   @CliCommand(value = "show logs",
     help = "show logs for the given handle <log_handle>. Handle can either be a query handle or request id. "
+      + LensQueryCommands.DEFAULT_QUERY_HANDLE_DESCRIPTION + " "
       + "You can optionally provide a location to save the logs as <save_location>")
   public String getLogs(
-    @CliOption(key = {"", "log_handle"}, mandatory = true, help = "<log_handle>")
+    @CliOption(key = {"", "log_handle"}, mandatory = false, help = "<log_handle>")
     String logFile, @CliOption(key = {"save_location"}, mandatory = false, help = "<save_location>") String location) {
     try {
+      logFile = getOrDefaultQueryHandleString(logFile);
       Response response = getClient().getLogs(logFile);
       if (response.getStatus() == Response.Status.OK.getStatusCode()) {
         if (StringUtils.isBlank(location)) {

http://git-wip-us.apache.org/repos/asf/lens/blob/919936be/lens-cli/src/main/java/org/apache/lens/cli/commands/LensQueryCommands.java
----------------------------------------------------------------------
diff --git a/lens-cli/src/main/java/org/apache/lens/cli/commands/LensQueryCommands.java b/lens-cli/src/main/java/org/apache/lens/cli/commands/LensQueryCommands.java
index a29600d..e2ac3af 100644
--- a/lens-cli/src/main/java/org/apache/lens/cli/commands/LensQueryCommands.java
+++ b/lens-cli/src/main/java/org/apache/lens/cli/commands/LensQueryCommands.java
@@ -61,22 +61,42 @@ import com.google.common.base.Joiner;
     + "  <<<query execute cube select id,name from dim_table where name != \"\"first\"\">>>,\n"
     + "  will be parsed as <<<cube select id,name from dim_table where name != \"first\">>>")
 public class LensQueryCommands extends BaseLensCommand {
-  private static final String DEFAULT_QUERY_HANDLE_DESCRIPTION =
+  public static final String DEFAULT_QUERY_HANDLE_DESCRIPTION =
     "If not provided, takes last query handle interacted with.";
+  private static final String ASYNC_DOC =
+    "If <async> is true, The query is launched in async manner and query handle is returned. It's by default false.";
+  private static final String QUERY_NAME_DOC = "<query name> can also be provided, though not required.";
 
-  /**
-   * Execute query.
-   *
-   * @param sql       the sql
-   * @param async    the asynch
-   * @param queryName the query name
-   * @return the string
-   */
+  @CliCommand(value = "select",
+    help = "Execute query <select query-string-without-select>. " + ASYNC_DOC + " " + QUERY_NAME_DOC)
+  public String executeSelectQuery(
+    @CliOption(key = {""}, mandatory = true, help = "<query-string-without-select>") String sql,
+    @CliOption(key = {"async"}, mandatory = false, unspecifiedDefaultValue = "false",
+      specifiedDefaultValue = "true", help = "<async>") boolean async,
+    @CliOption(key = {"name"}, mandatory = false, help = "<query-name>") String queryName) {
+    return executeQuery("select " + sql, async, queryName);
+  }
+
+  @CliCommand(value = "cube select",
+    help = "Execute cube query <cube select query-string-without-cube-select>. " + ASYNC_DOC + " " + QUERY_NAME_DOC)
+  public String executeCubeSelectQuery(
+    @CliOption(key = {""}, mandatory = true, help = "<query-string-without-cube-select>") String sql,
+    @CliOption(key = {"async"}, mandatory = false, unspecifiedDefaultValue = "false",
+      specifiedDefaultValue = "true", help = "<async>") boolean async,
+    @CliOption(key = {"name"}, mandatory = false, help = "<query-name>") String queryName) {
+    return executeQuery("cube select " + sql, async, queryName);
+  }
+
+    /**
+     * Execute query.
+     *
+     * @param sql       the sql
+     * @param async    the asynch
+     * @param queryName the query name
+     * @return the string
+     */
   @CliCommand(value = "query execute",
-    help = "Execute query <query-string>."
-      +
-      " If <async> is true, The query is launched in async manner and query handle is returned. It's by default false."
-      + " <query name> can also be provided, though not required")
+    help = "Execute query <query-string>. " + ASYNC_DOC + " " + QUERY_NAME_DOC)
   public String executeQuery(
     @CliOption(key = {"", "query"}, mandatory = true, help = "<query-string>") String sql,
     @CliOption(key = {"async"}, mandatory = false, unspecifiedDefaultValue = "false",
@@ -140,16 +160,6 @@ public class LensQueryCommands extends BaseLensCommand {
     return b.toString();
   }
 
-  public String getOrDefaultQueryHandleString(String queryHandleString) {
-    if (queryHandleString != null) {
-      return queryHandleString;
-    }
-    if (getClient().getStatement().getQuery() != null) {
-      return getClient().getStatement().getQueryHandleString();
-    }
-    throw new IllegalArgumentException("Query handle not provided and no queries interacted with in the session.");
-  }
-
   /**
    * Gets the status.
    *

http://git-wip-us.apache.org/repos/asf/lens/blob/919936be/src/site/apt/user/cli.apt
----------------------------------------------------------------------
diff --git a/src/site/apt/user/cli.apt b/src/site/apt/user/cli.apt
index 65380e6..2522e03 100644
--- a/src/site/apt/user/cli.apt
+++ b/src/site/apt/user/cli.apt
@@ -335,6 +335,8 @@ User CLI Commands
 *--+--+
 |<<Command>>|<<Description>>|
 *--+--+
+|cube select \<query-string-without-cube-select\> [--async \<async\>] [--name \<query-name\>]|Execute cube query <<<cube select query-string-without-cube-select>>>. If <<<async>>> is true, The query is launched in async manner and query handle is returned. It's by default false. <<<query name>>> can also be provided, though not required.|
+*--+--+
 |prepQuery destroy [--prepare_handle] \<prepare_handle\>|Destroy prepared query with handle <<<prepare_handle>>>|
 *--+--+
 |prepQuery details [--prepare_handle] \<prepare_handle\>|Get prepared query with handle <<<prepare_handle>>>|
@@ -349,7 +351,7 @@ User CLI Commands
 *--+--+
 |query details [[--query_handle] \<query_handle\>]|Get query details of query with handle <<<query_handle>>>.If not provided, takes last query handle interacted with.|
 *--+--+
-|query execute [--query] \<query-string\> [--async \<async\>] [--name \<query-name\>]|Execute query <<<query-string>>>. If <<<async>>> is true, The query is launched in async manner and query handle is returned. It's by default false. <<<query name>>> can also be provided, though not required|
+|query execute [--query] \<query-string\> [--async \<async\>] [--name \<query-name\>]|Execute query <<<query-string>>>. If <<<async>>> is true, The query is launched in async manner and query handle is returned. It's by default false. <<<query name>>> can also be provided, though not required.|
 *--+--+
 |query explain [--query] \<query-string\> [--save_location \<save_location\>]|Explain execution plan of query <<<query-string>>>. Can optionally save the plan to a file by providing <<<save_location>>>|
 *--+--+
@@ -361,6 +363,8 @@ User CLI Commands
 *--+--+
 |query status [[--query_handle] \<query_handle\>]|Fetch status of executed query having query handle <<<query_handle>>>. If not provided, takes last query handle interacted with.|
 *--+--+
+|select \<query-string-without-select\> [--async \<async\>] [--name \<query-name\>]|Execute query <<<select query-string-without-select>>>. If <<<async>>> is true, The query is launched in async manner and query handle is returned. It's by default false. <<<query name>>> can also be provided, though not required.|
+*--+--+
   <<Lens Query Commands>>
 
 ===
@@ -372,7 +376,7 @@ User CLI Commands
 *--+--+
 |<<Command>>|<<Description>>|
 *--+--+
-|show logs [--log_handle] \<log_handle\> [--save_location \<save_location\>]|show logs for the given handle <<<log_handle>>>. Handle can either be a query handle or request id. You can optionally provide a location to save the logs as <<<save_location>>>|
+|show logs [[--log_handle] \<log_handle\>] [--save_location \<save_location\>]|show logs for the given handle <<<log_handle>>>. Handle can either be a query handle or request id. If not provided, takes last query handle interacted with. You can optionally provide a location to save the logs as <<<save_location>>>|
 *--+--+
   <<Lens Log Resource Commands>>