[
https://issues.apache.org/jira/browse/BEAM-4616?focusedWorklogId=115620&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-115620
]
ASF GitHub Bot logged work on BEAM-4616:
----------------------------------------
Author: ASF GitHub Bot
Created on: 25/Jun/18 20:09
Start Date: 25/Jun/18 20:09
Worklog Time Spent: 10m
Work Description: kennknowles closed pull request #5727: [BEAM-4616]
Customize prompt, welcome and help messages
URL: https://github.com/apache/beam/pull/5727
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/sdks/java/extensions/sql/jdbc/build.gradle
b/sdks/java/extensions/sql/jdbc/build.gradle
index 6083d12b57f..3b34eb870bc 100644
--- a/sdks/java/extensions/sql/jdbc/build.gradle
+++ b/sdks/java/extensions/sql/jdbc/build.gradle
@@ -28,6 +28,7 @@ dependencies {
compile "jline:jline:2.14.6"
compile "sqlline:sqlline:1.3.0"
compile library.java.slf4j_jdk14
+ compile library.java.guava
testCompile library.java.junit
// Depending on outputs so integrationTest can run with only test
dependencies.
// This enables us to test the JDBC jar being loaded on a custom classloader.
@@ -36,6 +37,12 @@ dependencies {
integrationTest library.java.junit
}
+processResources {
+ filter org.apache.tools.ant.filters.ReplaceTokens, tokens: [
+ 'beam.version': version,
+ ]
+}
+
shadowJar {
manifest {
attributes "Main-Class":
"org.apache.beam.sdk.extensions.sql.jdbc.BeamSqlLine"
diff --git
a/sdks/java/extensions/sql/jdbc/src/main/java/org/apache/beam/sdk/extensions/sql/jdbc/BeamSqlLine.java
b/sdks/java/extensions/sql/jdbc/src/main/java/org/apache/beam/sdk/extensions/sql/jdbc/BeamSqlLine.java
index 7952b0620c3..c47ab4106fe 100644
---
a/sdks/java/extensions/sql/jdbc/src/main/java/org/apache/beam/sdk/extensions/sql/jdbc/BeamSqlLine.java
+++
b/sdks/java/extensions/sql/jdbc/src/main/java/org/apache/beam/sdk/extensions/sql/jdbc/BeamSqlLine.java
@@ -19,17 +19,41 @@
import static
org.apache.beam.sdk.extensions.sql.impl.JdbcDriver.CONNECT_STRING_PREFIX;
+import com.google.common.collect.ImmutableList;
import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
+import javax.annotation.Nullable;
import sqlline.SqlLine;
/** {@link BeamSqlLine} provides default arguments to SqlLine. */
public class BeamSqlLine {
+
+ private static final String NICKNAME = "BeamSQL";
+
public static void main(String[] args) throws IOException {
- String[] args2 = new String[2 + args.length];
- args2[0] = "-u";
- args2[1] = CONNECT_STRING_PREFIX;
- System.arraycopy(args, 0, args2, 2, args.length);
- SqlLine.main(args2);
+ // Until we learn otherwise, we expect to add -nn <nickname> -u <url>
+ @Nullable String databaseUrl = null;
+ @Nullable String nickname = null;
+
+ // Provide -u and -nn only if they do not exist
+ for (int i = 0; i < args.length; i++) {
+ if (args[i].equals("-u")) {
+ databaseUrl = args[++i];
+ } else if (args[i].equals("-nn")) {
+ nickname = args[++i];
+ }
+ }
+
+ ImmutableList.Builder wrappedArgs =
ImmutableList.builder().addAll(Arrays.asList(args));
+ if (databaseUrl == null) {
+ wrappedArgs.add("-u").add(CONNECT_STRING_PREFIX);
+ }
+ if (nickname == null) {
+ wrappedArgs.add("-nn").add(NICKNAME);
+ }
+ List<String> wrappedArgList = wrappedArgs.build();
+ SqlLine.main(wrappedArgList.toArray(new String[wrappedArgList.size()]));
}
}
diff --git
a/sdks/java/extensions/sql/jdbc/src/main/resources/sqlline/SqlLine.properties
b/sdks/java/extensions/sql/jdbc/src/main/resources/sqlline/SqlLine.properties
new file mode 100644
index 00000000000..c1013f61eb0
--- /dev/null
+++
b/sdks/java/extensions/sql/jdbc/src/main/resources/sqlline/SqlLine.properties
@@ -0,0 +1,256 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+##########################################################################
+# Modified SqlLine.properties to hardcode Beam specializations
+#
+# TODO: Only store the modifications here, and wrap the ResourceBundle
+##########################################################################
+
+# Printed when BeamSqlLine starts up
+app-introduction: Welcome to Beam SQL @beam.version@ (based on sqlline version
{1})
+
+# Not generally applicable to Beam, but still available for power users or
vendors:
+#
+# -u <database url> the JDBC URL to connect to\n \
+# -n <username> the username to connect as\n \
+# -p <password> the password to connect as\n \
+# -d <driver class> the driver class to use\n \
+# -nn <nickname> nickname for the connection\n \
+# --autoCommit=[true/false] enable/disable automatic transaction
commit\n \
+# --isolation=LEVEL set the transaction isolation level\n \
+cmd-usage: Usage: java -jar
[email protected]@.jar \n \
+\ Usage: java org.apache.beam.sdk.java.extensions.sql.jdbc.BeamSqlLine \n \
+\ -f <file> script file to execute (same as --run)\n \
+\ --color=[true/false] control whether color is used for display\n
\
+\ --showHeader=[true/false] show column names in query results\n \
+\ --headerInterval=ROWS the interval between which headers are
displayed\n \
+\ --fastConnect=[true/false] skip building table/column list for
tab-completion\n \
+\ --verbose=[true/false] show verbose error messages and debug
info\n \
+\ --showTime=[true/false] display execution time when verbose\n \
+\ --showWarnings=[true/false] display connection warnings\n \
+\ --showNestedErrs=[true/false] display nested errors\n \
+\ --numberFormat=[pattern] format numbers using DecimalFormat
pattern\n \
+\ --force=[true/false] continue running script even after errors\n
\
+\ --maxWidth=MAXWIDTH the maximum width of the terminal\n \
+\ --maxColumnWidth=MAXCOLWIDTH the maximum width to use when displaying
columns\n \
+\ --silent=[true/false] be more silent\n \
+\ --autosave=[true/false] automatically save preferences\n \
+\ --outputformat=[table/vertical/csv/tsv] format mode for result display\n \
+\ --run=/path/to/file run one script and then exit
+\ --help display this message
+
+# Similar to command line, hiding help for irrelevant things,
+# some of which already do not work (like !set propertiesFile)
+#
+# \nautoCommit true/false Enable/disable automatic\
+# \n transaction commit\
+# \nisolation LEVEL Set transaction isolation level\
+# \npropertiesFile path File from which SqlLine reads\
+# properties on startup; default is\
+# $HOME/.sqlline/sqlline.properties\
+# (UNIX, Linux, Mac OS),\
+# $HOME/sqlline/sqlline.properties\
+# (Windows)\
+help-set: Set a sqlline variable\
+\n\
+\nVariable Value Description\
+\n=============== ========== ================================\
+\nautoSave true/false Automatically save preferences\
+\ncolor true/false Control whether color is used\
+\n for display\
+\nfastConnect true/false Skip building table/column list\
+\n for tab-completion\
+\nforce true/false Continue running script even\
+\n after errors\
+\nheaderInterval integer The interval between which\
+\n headers are displayed\
+\nhistoryFile path File in which to save command\
+\n history. Default is\
+\n $HOME/.sqlline/history (UNIX,\
+\n Linux, Mac OS),\
+\n $HOME/sqlline/history (Windows)\
+\nincremental true/false Do not receive all rows from\
+\n server before printing the first\
+\n row. Uses fewer resources,\
+\n especially for long-running\
+\n queries, but column widths may\
+\n be incorrect.\
+\nmaxColumnWidth integer The maximum width to use when\
+\n displaying columns\
+\nmaxHeight integer The maximum height of the\
+\n terminal\
+\nmaxWidth integer The maximum width of the\
+\n terminal\
+\nnumberFormat pattern Format numbers using\
+\n DecimalFormat pattern\
+\noutputFormat table/vertical/csv/tsv Format mode for\
+\n result display\
+\nrowLimit integer Maximum number of rows returned\
+\n from a query; zero means no\
+\n limit\
+\nshowElapsedTime true/false Display execution time when\
+\n verbose\
+\nshowHeader true/false Show column names in query\
+\n results\
+\nshowNestedErrs true/false Display nested errors\
+\nshowWarnings true/false Display connection warnings\
+\nsilent true/false Be more silent\
+\ntimeout integer Query timeout in seconds; less\
+\n than zero means no timeout\
+\ntrimScripts true/false Remove trailing spaces from\
+\n lines read from script files\
+\nverbose true/false Show verbose error messages and\
+\n debug info
+
+#### UNMODIFIED PROPERTIES BELOW HERE ####
+jline-version: The version of the required {0} library is too old. Version \
+ "{1}" was found, but "{2}" is required.
+
+enter-for-more: [ Hit "enter" for more ("q" to exit) ]
+no-manual: Could not find manual resource.
+executing-command: Executing command: {0}
+unknown-command: Unknown command: {0}
+autocommit-needs-off: Operation requires that autocommit be turned off.
+no-current-connection: No current connection
+connection-is-closed: Connection is closed
+reconnecting: Reconnecting to "{0}"...
+connecting: Connecting to "{0}"...
+no-driver: No known driver to handle "{0}"
+setting-prop: Setting property: {0}
+saving-options: Saving preferences to: {0}
+loaded-options: Loaded preferences from: {0}
+
+jdbc-level: JDBC level
+compliant: Compliant
+jdbc-version: Version
+driver-class: Driver Class
+
+help-quit: Exits the program
+help-dropall: Drop all tables in the current database
+help-connect: Open a new connection to the database.
+help-manual: Display the SQLLine manual
+help-typeinfo: Display the type map for the current connection
+help-describe: Describe a table
+help-reconnect: Reconnect to the database
+help-metadata: Obtain metadata information
+help-dbinfo: Give metadata information about the database
+help-rehash: Fetch table and column names for command completion
+help-verbose: Set verbose mode on
+help-run: Run a script from the specified file
+help-list: List the current connections
+help-all: Execute the specified SQL against all the current connections
+help-go: Select the current connection
+help-script: Start saving a script to a file
+help-brief: Set verbose mode off
+help-close: Close the current connection to the database
+help-closeall: Close all current open connections
+help-isolation: Set the transaction isolation for this connection
+help-nativesql: Show the native SQL for the specified statement
+help-call: Execute a callable statement
+help-autocommit: Set autocommit mode on or off
+help-commit: Commit the current transaction (if autocommit is off)
+help-rollback: Roll back the current transaction (if autocommit is off)
+help-batch: Start or execute a batch of statements
+help-help: Print a summary of command usage
+help-save: Save the current variabes and aliases
+help-native: Show the database''s native SQL for a command
+help-alias: Create a new command alias
+help-unalias: Unset a command alias
+help-scan: Scan for installed JDBC drivers
+help-sql: Execute a SQL command
+help-history: Display the command history
+help-record: Record all output to the specified file
+help-indexes: List all the indexes for the specified table
+help-primarykeys: List all the primary keys for the specified table
+help-exportedkeys: List all the exported keys for the specified table
+help-importedkeys: List all the imported keys for the specified table
+help-procedures: List all the procedures
+help-tables: List all the tables in the database
+help-columns: List all the columns for the specified table
+help-properties: Connect to the database specified in the properties file(s)
+help-outputformat: Set the output format for displaying results
(table,vertical,csv,tsv,xmlattrs,xmlelements)
+help-nickname: Create a friendly name for the connection (updates command
prompt)
+
+jline-missing: SQLLine static class check reports the {0} class was not found.
Please ensure JLine is on classpath.
+
+batch-start: Batching SQL statements. Run "batch" again to execute the batch.
+running-batch: Running batched SQL statements...
+
+arg-usage: Usage: {0} <{1}>
+
+scanning: Scanning {0}...
+no-such-method: No such method "{0}"
+possible-methods: Possible methods:
+
+closing: Closing: {0}
+already-closed: Connection is already closed.
+error-setting: Error setting configuration: {0}: {1}
+no-method: No method matching "{0}" was found in {1}.
+
+
+connected: Connected to: {0} (version {1})
+driver: Driver: {0} (version {1})
+autocommit-status: Autocommit status: {0}
+isolation-status: Transaction isolation: {0}
+unknown-format: Unknown output format "{0}". Possible values: {1}
+
+closed: closed
+open: open
+
+executing-con: Executing SQL against: {0}
+comments: Comments, bug reports, and patches go to {0}
+building-tables: Building list of tables and columns for tab-completion \
+ (set fastconnect to true to skip)...
+done: Done
+state: state
+code: code
+
+invalid-connections: Invalid connection: {0}
+
+script-closed: Script closed. Enter "run {0}" to replay it.
+script-already-running: Script ({0}) is already running. Enter "script" with
no arguments to stop it.
+script-started: Saving command script to "{0}". Enter "script" with no
arguments to stop it.
+
+command-canceled: Command canceled.
+
+record-closed: Recording stopped.
+record-already-running: Output already being saved to ({0}). Enter "record"
with no arguments to stop it.
+record-started: Saving all output to "{0}". Enter "record" with no arguments
to stop it.
+
+autoloading-known-drivers: No known driver to handle "{0}". Searching for
known drivers...
+
+Warning: Warning: {0} (state={1},code={2,number,#})
+Error: Error: {0} (state={1},code={2,number,#})
+
+commit-complete: Commit complete
+rollback-complete: Rollback complete
+
+halt-query: Canceling query
+
+abort-on-error: Aborting command set because "force" is false and \
+ command failed: "{0}"
+
+multiple-matches: Ambiguous command: {0}
+
+really-drop-all: Really drop every table in the database? (y/n)\
+abort-drop-all: Aborting drop all tables.
+
+drivers-found-count: 0#No driver classes found|1#{0} driver class found|1<{0}
driver classes found
+rows-selected: 0#No rows selected|1#{0} row selected|1<{0} rows selected
+rows-affected: 0#No rows affected|1#{0} row affected|1<{0} rows
affected|0>Unknown rows affected
+active-connections: 0#No active connections|1#{0} active connection:|1<{0}
active connections:
+
+time-ms: ({0,number,#.###} seconds)
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 115620)
Time Spent: 1h 10m (was: 1h)
> Customize welcome and help messages for Beam SQL shell
> ------------------------------------------------------
>
> Key: BEAM-4616
> URL: https://issues.apache.org/jira/browse/BEAM-4616
> Project: Beam
> Issue Type: Bug
> Components: dsl-sql
> Reporter: Kenneth Knowles
> Assignee: Kenneth Knowles
> Priority: Major
> Time Spent: 1h 10m
> Remaining Estimate: 0h
>
> Currently the shell includes a lot of SqlLine stuff that may not be relevant
> or accurate, such as isolation levels and whatnot. We could hide some of this
> and generally make SqlLine more of an implementation detail.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)