This is an automated email from the ASF dual-hosted git repository.

arina pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/drill.git

commit a61eddc12eef19f0bb68cc453719cf17076e11c7
Author: Arina Ielchiieva <arina.yelchiy...@gmail.com>
AuthorDate: Tue Feb 5 13:51:13 2019 +0200

    DRILL-6989: Upgrade to SqlLine 1.7
    
    closes #1717
---
 distribution/src/resources/sqlline                 |  2 +-
 distribution/src/resources/sqlline.bat             |  2 +-
 .../drill/exec/client/DrillSqlLineApplication.java | 32 ++++++++++++++++++++--
 .../src/main/resources/drill-sqlline.conf          |  4 ++-
 pom.xml                                            |  2 +-
 5 files changed, 36 insertions(+), 6 deletions(-)

diff --git a/distribution/src/resources/sqlline 
b/distribution/src/resources/sqlline
index 67232bc..8defce9 100644
--- a/distribution/src/resources/sqlline
+++ b/distribution/src/resources/sqlline
@@ -84,7 +84,7 @@ if [[ ( ! $(ps -o stat= -p $$) =~ "+" ) && ! ( -p /dev/stdin 
) ]]; then
 fi
 
 SHELL_OPTS="$DRILL_SHELL_JAVA_OPTS $SQLLINE_JAVA_OPTS $DRILL_SHELL_LOG_OPTS 
$CLIENT_GC_OPTS"
-CMD="$JAVA $SHELL_OPTS -cp $CP sqlline.SqlLine -ac 
org.apache.drill.exec.client.DrillSqlLineApplication -d 
org.apache.drill.jdbc.Driver"
+CMD="$JAVA $SHELL_OPTS -cp $CP sqlline.SqlLine -ac 
org.apache.drill.exec.client.DrillSqlLineApplication"
 
 # The wrapper is purely for unit testing.
 
diff --git a/distribution/src/resources/sqlline.bat 
b/distribution/src/resources/sqlline.bat
index 360b758..6f79395 100755
--- a/distribution/src/resources/sqlline.bat
+++ b/distribution/src/resources/sqlline.bat
@@ -208,7 +208,7 @@ if errorlevel 1 (
   set DRILL_SHELL_JAVA_OPTS=%DRILL_SHELL_JAVA_OPTS% --illegal-access=permit
 )
 
-set SQLLINE_CALL=sqlline.SqlLine -ac 
org.apache.drill.exec.client.DrillSqlLineApplication -d 
org.apache.drill.jdbc.Driver
+set SQLLINE_CALL=sqlline.SqlLine -ac 
org.apache.drill.exec.client.DrillSqlLineApplication
 if NOT "test%QUERY%"=="test" (
   "%JAVA_CMD%" %DRILL_SHELL_JAVA_OPTS% %DRILL_JAVA_OPTS% -cp "%DRILL_CP%" 
%SQLLINE_CALL% %DRILL_ARGS% -e "%QUERY%"
 ) else (
diff --git 
a/exec/java-exec/src/main/java/org/apache/drill/exec/client/DrillSqlLineApplication.java
 
b/exec/java-exec/src/main/java/org/apache/drill/exec/client/DrillSqlLineApplication.java
index cc0426b..8a687f3 100644
--- 
a/exec/java-exec/src/main/java/org/apache/drill/exec/client/DrillSqlLineApplication.java
+++ 
b/exec/java-exec/src/main/java/org/apache/drill/exec/client/DrillSqlLineApplication.java
@@ -23,9 +23,13 @@ import org.apache.drill.common.scanner.ClassPathScanner;
 import org.apache.drill.common.util.DrillVersionInfo;
 import 
org.apache.drill.shaded.guava.com.google.common.annotations.VisibleForTesting;
 import org.jline.reader.impl.completer.StringsCompleter;
+import org.jline.utils.AttributedString;
+import org.jline.utils.AttributedStringBuilder;
 import sqlline.Application;
 import sqlline.CommandHandler;
+import sqlline.ConnectionMetadata;
 import sqlline.OutputFormat;
+import sqlline.PromptHandler;
 import sqlline.ReflectiveCommandHandler;
 import sqlline.SqlLine;
 import sqlline.SqlLineOpts;
@@ -61,6 +65,7 @@ public class DrillSqlLineApplication extends Application {
   private static final String CONNECTION_URL_EXAMPLES_CONF = 
"drill.sqlline.connection_url_examples";
   private static final String COMMANDS_TO_EXCLUDE_CONF = 
"drill.sqlline.commands.exclude";
   private static final String OPTS_CONF = "drill.sqlline.opts";
+  private static final String PROMPT_WITH_SCHEMA = 
"drill.sqlline.prompt.with_schema";
 
   private final Config config;
 
@@ -100,11 +105,11 @@ public class DrillSqlLineApplication extends Application {
   }
 
   @Override
-  public Collection<String> initDrivers() {
+  public List<String> allowedDrivers() {
     if (config.hasPath(DRIVERS_CONF)) {
       return config.getStringList(DRIVERS_CONF);
     }
-    return super.initDrivers();
+    return super.allowedDrivers();
   }
 
   @Override
@@ -169,6 +174,29 @@ public class DrillSqlLineApplication extends Application {
     return opts;
   }
 
+  @Override
+  public PromptHandler getPromptHandler(SqlLine sqlLine) {
+    if (config.hasPath(PROMPT_WITH_SCHEMA) && 
config.getBoolean(PROMPT_WITH_SCHEMA)) {
+      return new PromptHandler(sqlLine) {
+        @Override
+        protected AttributedString getDefaultPrompt(int connectionIndex, 
String url, String defaultPrompt) {
+          AttributedStringBuilder builder = new AttributedStringBuilder();
+          builder.style(resolveStyle("f:y"));
+          builder.append("apache drill");
+
+          ConnectionMetadata meta = sqlLine.getConnectionMetadata();
+
+          String currentSchema = meta.getCurrentSchema();
+          if (currentSchema != null) {
+            builder.append(" (").append(currentSchema).append(")");
+          }
+          return 
builder.style(resolveStyle("default")).append(">").toAttributedString();
+        }
+      };
+    }
+    return super.getPromptHandler(sqlLine);
+  }
+
   private Config loadConfig(String configName) {
     Set<URL> urls = ClassPathScanner.forResource(configName, false);
     if (urls.size() != 1) {
diff --git a/exec/java-exec/src/main/resources/drill-sqlline.conf 
b/exec/java-exec/src/main/resources/drill-sqlline.conf
index 703944d..58d0413 100644
--- a/exec/java-exec/src/main/resources/drill-sqlline.conf
+++ b/exec/java-exec/src/main/resources/drill-sqlline.conf
@@ -88,5 +88,7 @@ drill.sqlline {
     colorScheme: obsidian,
     # display null values for varchar / char / boolean as null
     nullValue: "null"
-  }
+  },
+  # display prompt as `apache drill>` or when schema is set as `apache drill 
(dfs.tmp)>`
+  prompt.with_schema: true
 }
diff --git a/pom.xml b/pom.xml
index f979690..5991089 100644
--- a/pom.xml
+++ b/pom.xml
@@ -53,7 +53,7 @@
     <calcite.version>1.18.0-drill-r0</calcite.version>
     <avatica.version>1.13.0</avatica.version>
     <janino.version>3.0.11</janino.version>
-    <sqlline.version>1.6.0</sqlline.version>
+    <sqlline.version>1.7.0</sqlline.version>
     <jackson.version>2.9.5</jackson.version>
     <jackson.databind.version>2.9.5</jackson.databind.version>
     <zookeeper.version>3.4.12</zookeeper.version>

Reply via email to