Return-Path: X-Original-To: apmail-tajo-commits-archive@minotaur.apache.org Delivered-To: apmail-tajo-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C2F5117736 for ; Fri, 31 Oct 2014 05:59:06 +0000 (UTC) Received: (qmail 31688 invoked by uid 500); 31 Oct 2014 05:59:06 -0000 Delivered-To: apmail-tajo-commits-archive@tajo.apache.org Received: (qmail 31600 invoked by uid 500); 31 Oct 2014 05:59:06 -0000 Mailing-List: contact commits-help@tajo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@tajo.apache.org Delivered-To: mailing list commits@tajo.apache.org Received: (qmail 31428 invoked by uid 99); 31 Oct 2014 05:59:06 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 31 Oct 2014 05:59:06 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 32530A07210; Fri, 31 Oct 2014 05:59:06 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: hyunsik@apache.org To: commits@tajo.apache.org Date: Fri, 31 Oct 2014 05:59:10 -0000 Message-Id: In-Reply-To: <95a2863fa29d4dd39a201e7d192743a6@git.apache.org> References: <95a2863fa29d4dd39a201e7d192743a6@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [5/5] git commit: TAJO-1141: Refactor the packages hierarchy of tajo-client. TAJO-1141: Refactor the packages hierarchy of tajo-client. Closes #217 Project: http://git-wip-us.apache.org/repos/asf/tajo/repo Commit: http://git-wip-us.apache.org/repos/asf/tajo/commit/c59baa3a Tree: http://git-wip-us.apache.org/repos/asf/tajo/tree/c59baa3a Diff: http://git-wip-us.apache.org/repos/asf/tajo/diff/c59baa3a Branch: refs/heads/master Commit: c59baa3ad60e92da2ebd1fb636f301e5ca4f585d Parents: 154da1e Author: Hyunsik Choi Authored: Thu Oct 30 22:55:34 2014 -0700 Committer: Hyunsik Choi Committed: Thu Oct 30 22:56:29 2014 -0700 ---------------------------------------------------------------------- CHANGES | 2 + .../apache/tajo/cli/ConnectDatabaseCommand.java | 71 -- .../org/apache/tajo/cli/CopyrightCommand.java | 63 -- .../tajo/cli/DefaultTajoCliOutputFormatter.java | 210 ------ .../apache/tajo/cli/DescFunctionCommand.java | 135 ---- .../org/apache/tajo/cli/DescTableCommand.java | 135 ---- .../tajo/cli/ExecExternalShellCommand.java | 122 ---- .../java/org/apache/tajo/cli/ExitCommand.java | 47 -- .../java/org/apache/tajo/cli/HdfsCommand.java | 57 -- .../java/org/apache/tajo/cli/HelpCommand.java | 132 ---- .../tajo/cli/InvalidStatementException.java | 25 - .../apache/tajo/cli/ListDatabaseCommand.java | 48 -- .../java/org/apache/tajo/cli/ParsedResult.java | 53 -- .../java/org/apache/tajo/cli/SetCommand.java | 126 ---- .../java/org/apache/tajo/cli/SimpleParser.java | 388 ----------- .../org/apache/tajo/cli/TajoAdminCommand.java | 57 -- .../main/java/org/apache/tajo/cli/TajoCli.java | 690 ------------------ .../apache/tajo/cli/TajoCliOutputFormatter.java | 97 --- .../org/apache/tajo/cli/TajoFileHistory.java | 39 -- .../org/apache/tajo/cli/TajoGetConfCommand.java | 57 -- .../org/apache/tajo/cli/TajoHAAdminCommand.java | 57 -- .../org/apache/tajo/cli/TajoShellCommand.java | 128 ---- .../java/org/apache/tajo/cli/UnsetCommand.java | 52 -- .../org/apache/tajo/cli/VersionCommand.java | 48 -- .../org/apache/tajo/cli/tools/TajoAdmin.java | 457 ++++++++++++ .../org/apache/tajo/cli/tools/TajoDump.java | 188 +++++ .../org/apache/tajo/cli/tools/TajoGetConf.java | 161 +++++ .../org/apache/tajo/cli/tools/TajoHAAdmin.java | 211 ++++++ .../cli/tsql/DefaultTajoCliOutputFormatter.java | 210 ++++++ .../cli/tsql/InvalidStatementException.java | 25 + .../org/apache/tajo/cli/tsql/ParsedResult.java | 53 ++ .../org/apache/tajo/cli/tsql/SimpleParser.java | 388 +++++++++++ .../java/org/apache/tajo/cli/tsql/TajoCli.java | 691 +++++++++++++++++++ .../tajo/cli/tsql/TajoCliOutputFormatter.java | 98 +++ .../apache/tajo/cli/tsql/TajoFileHistory.java | 39 ++ .../tsql/commands/ConnectDatabaseCommand.java | 72 ++ .../cli/tsql/commands/CopyrightCommand.java | 65 ++ .../cli/tsql/commands/DescFunctionCommand.java | 136 ++++ .../cli/tsql/commands/DescTableCommand.java | 136 ++++ .../tsql/commands/ExecExternalShellCommand.java | 124 ++++ .../tajo/cli/tsql/commands/ExitCommand.java | 49 ++ .../tajo/cli/tsql/commands/HdfsCommand.java | 58 ++ .../tajo/cli/tsql/commands/HelpCommand.java | 133 ++++ .../cli/tsql/commands/ListDatabaseCommand.java | 50 ++ .../tajo/cli/tsql/commands/SetCommand.java | 127 ++++ .../cli/tsql/commands/TajoAdminCommand.java | 58 ++ .../cli/tsql/commands/TajoGetConfCommand.java | 58 ++ .../cli/tsql/commands/TajoHAAdminCommand.java | 58 ++ .../cli/tsql/commands/TajoShellCommand.java | 129 ++++ .../tajo/cli/tsql/commands/UnsetCommand.java | 53 ++ .../tajo/cli/tsql/commands/VersionCommand.java | 49 ++ .../java/org/apache/tajo/client/TajoAdmin.java | 456 ------------ .../java/org/apache/tajo/client/TajoDump.java | 186 ----- .../org/apache/tajo/client/TajoGetConf.java | 159 ----- .../org/apache/tajo/client/TajoHAAdmin.java | 210 ------ .../apache/tajo/client/TajoHAClientUtil.java | 2 +- .../java/org/apache/tajo/conf/TajoConf.java | 2 +- .../java/org/apache/tajo/QueryTestCaseBase.java | 4 +- .../tajo/cli/TestDefaultCliOutputFormatter.java | 178 ----- .../tajo/cli/TestExecExternalShellCommand.java | 44 -- .../org/apache/tajo/cli/TestHdfsCommand.java | 46 -- .../org/apache/tajo/cli/TestSimpleParser.java | 271 -------- .../java/org/apache/tajo/cli/TestTajoCli.java | 354 ---------- .../apache/tajo/cli/tools/TestDDLBuilder.java | 133 ++++ .../org/apache/tajo/cli/tools/TestTajoDump.java | 47 ++ .../cli/tsql/TestDefaultCliOutputFormatter.java | 180 +++++ .../apache/tajo/cli/tsql/TestSimpleParser.java | 274 ++++++++ .../org/apache/tajo/cli/tsql/TestTajoCli.java | 356 ++++++++++ .../commands/TestExecExternalShellCommand.java | 45 ++ .../tajo/cli/tsql/commands/TestHdfsCommand.java | 47 ++ .../org/apache/tajo/client/TestDDLBuilder.java | 133 ---- .../org/apache/tajo/client/TestTajoDump.java | 46 -- .../apache/tajo/engine/eval/ExprTestBase.java | 6 +- 73 files changed, 4967 insertions(+), 4927 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tajo/blob/c59baa3a/CHANGES ---------------------------------------------------------------------- diff --git a/CHANGES b/CHANGES index 49c267b..cbbf492 100644 --- a/CHANGES +++ b/CHANGES @@ -41,6 +41,8 @@ Release 0.9.1 - unreleased TASKS + TAJO-1141: Refactor the packages hierarchy of tajo-client. (hyunsik) + Release 0.9.0 http://git-wip-us.apache.org/repos/asf/tajo/blob/c59baa3a/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 deleted file mode 100644 index 4158d67..0000000 --- a/tajo-client/src/main/java/org/apache/tajo/cli/ConnectDatabaseCommand.java +++ /dev/null @@ -1,71 +0,0 @@ -/** - * 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. - */ - -package org.apache.tajo.cli; - -import com.google.protobuf.ServiceException; - -public class ConnectDatabaseCommand extends TajoShellCommand { - - public ConnectDatabaseCommand(TajoCli.TajoCliContext context) { - super(context); - } - - @Override - public String getCommand() { - return "\\c"; - } - - @Override - public void invoke(String[] cmd) throws Exception { - if (cmd.length == 1) { - 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) { - String databaseName = cmd[1]; - databaseName = databaseName.replace("\"", ""); - if (!client.existDatabase(databaseName)) { - context.getOutput().write("Database '" + databaseName + "' not found\n"); - } else { - try { - 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())); - } - } catch (ServiceException se) { - if (se.getMessage() != null) { - context.getOutput().write(se.getMessage()); - } else { - context.getOutput().write(String.format("cannot connect the database \"%s\"", databaseName)); - } - } - } - } - } - - @Override - public String getUsage() { - return ""; - } - - @Override - public String getDescription() { - return "connect to new database"; - } -} http://git-wip-us.apache.org/repos/asf/tajo/blob/c59baa3a/tajo-client/src/main/java/org/apache/tajo/cli/CopyrightCommand.java ---------------------------------------------------------------------- diff --git a/tajo-client/src/main/java/org/apache/tajo/cli/CopyrightCommand.java b/tajo-client/src/main/java/org/apache/tajo/cli/CopyrightCommand.java deleted file mode 100644 index 07a3b51..0000000 --- a/tajo-client/src/main/java/org/apache/tajo/cli/CopyrightCommand.java +++ /dev/null @@ -1,63 +0,0 @@ -/** - * 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. - */ - -package org.apache.tajo.cli; - -public class CopyrightCommand extends TajoShellCommand { - public CopyrightCommand(TajoCli.TajoCliContext context) { - super(context); - } - - @Override - public String getCommand() { - return "\\copyright"; - } - - @Override - public void invoke(String[] cmd) throws Exception { - context.getOutput().println(); - context.getOutput().println( - " Licensed to the Apache Software Foundation (ASF) under one\n" + - " or more contributor license agreements. See the NOTICE file\n" + - " distributed with this work for additional information\n" + - " regarding copyright ownership. The ASF licenses this file\n" + - " to you under the Apache License, Version 2.0 (the\n" + - " \"License\"); you may not use this file except in compliance\n" + - " with the License. You may obtain a copy of the License at\n" + - "\n" + - " http://www.apache.org/licenses/LICENSE-2.0\n" + - "\n" + - " Unless required by applicable law or agreed to in writing, software\n" + - " distributed under the License is distributed on an \"AS IS\" BASIS,\n" + - " WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n" + - " See the License for the specific language governing permissions and\n" + - " limitations under the License."); - context.getOutput().println(); - } - - @Override - public String getUsage() { - return ""; - } - - @Override - public String getDescription() { - return "show Apache License 2.0"; - } - -} http://git-wip-us.apache.org/repos/asf/tajo/blob/c59baa3a/tajo-client/src/main/java/org/apache/tajo/cli/DefaultTajoCliOutputFormatter.java ---------------------------------------------------------------------- diff --git a/tajo-client/src/main/java/org/apache/tajo/cli/DefaultTajoCliOutputFormatter.java b/tajo-client/src/main/java/org/apache/tajo/cli/DefaultTajoCliOutputFormatter.java deleted file mode 100644 index c583aa2..0000000 --- a/tajo-client/src/main/java/org/apache/tajo/cli/DefaultTajoCliOutputFormatter.java +++ /dev/null @@ -1,210 +0,0 @@ -/** - * 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. - */ - -package org.apache.tajo.cli; - -import org.apache.commons.lang.exception.ExceptionUtils; -import org.apache.tajo.QueryId; -import org.apache.tajo.SessionVars; -import org.apache.tajo.catalog.TableDesc; -import org.apache.tajo.catalog.statistics.TableStats; -import org.apache.tajo.client.QueryClient; -import org.apache.tajo.client.QueryStatus; -import org.apache.tajo.util.FileUtil; - -import java.io.InputStream; -import java.io.PrintWriter; -import java.sql.ResultSet; -import java.sql.ResultSetMetaData; - -public class DefaultTajoCliOutputFormatter implements TajoCliOutputFormatter { - private int printPauseRecords; - private boolean printPause; - private boolean printErrorTrace; - private String nullChar; - - @Override - public void init(TajoCli.TajoCliContext context) { - this.printPause = context.getBool(SessionVars.CLI_PAGING_ENABLED); - this.printPauseRecords = context.getInt(SessionVars.CLI_PAGE_ROWS); - this.printErrorTrace = context.getBool(SessionVars.CLI_DISPLAY_ERROR_TRACE); - this.nullChar = context.get(SessionVars.CLI_NULL_CHAR); - } - - @Override - public void setScirptMode() { - this.printPause = false; - } - - private String getQuerySuccessMessage(TableDesc tableDesc, float responseTime, int totalPrintedRows, String postfix, - boolean endOfTuple) { - TableStats stat = tableDesc.getStats(); - String volume = stat == null ? (endOfTuple ? "0 B" : "unknown bytes") : - FileUtil.humanReadableByteCount(stat.getNumBytes(), false); - long resultRows = stat == null ? QueryClient.UNKNOWN_ROW_NUMBER : stat.getNumRows(); - - String displayRowNum; - if (resultRows == QueryClient.UNKNOWN_ROW_NUMBER) { - - if (endOfTuple) { - displayRowNum = totalPrintedRows + " rows"; - } else { - displayRowNum = "unknown row number"; - } - - } else { - displayRowNum = resultRows + " rows"; - } - return "(" + displayRowNum + ", " + getResponseTimeReadable(responseTime) + ", " + volume + " " + postfix + ")"; - } - - protected String getResponseTimeReadable(float responseTime) { - return responseTime + " sec"; - } - - @Override - public void printResult(PrintWriter sout, InputStream sin, TableDesc tableDesc, - float responseTime, ResultSet res) throws Exception { - long resultRows = tableDesc.getStats() == null ? -1 : tableDesc.getStats().getNumRows(); - if (resultRows == -1) { - resultRows = Integer.MAX_VALUE; - } - - if (res == null) { - sout.println(getQuerySuccessMessage(tableDesc, responseTime, 0, "inserted", true)); - return; - } - ResultSetMetaData rsmd = res.getMetaData(); - int numOfColumns = rsmd.getColumnCount(); - for (int i = 1; i <= numOfColumns; i++) { - if (i > 1) sout.print(", "); - String columnName = rsmd.getColumnName(i); - sout.print(columnName); - } - sout.println("\n-------------------------------"); - - int numOfPrintedRows = 0; - int totalPrintedRows = 0; - boolean endOfTuple = true; - while (res.next()) { - for (int i = 1; i <= numOfColumns; i++) { - if (i > 1) sout.print(", "); - String columnValue = res.getString(i); - if(res.wasNull()){ - sout.print(nullChar); - } else { - sout.print(columnValue); - } - } - sout.println(); - sout.flush(); - numOfPrintedRows++; - totalPrintedRows++; - if (printPause && printPauseRecords > 0 && totalPrintedRows < resultRows && numOfPrintedRows >= printPauseRecords) { - if (resultRows < Integer.MAX_VALUE) { - sout.print("(" + totalPrintedRows + "/" + resultRows + " rows, continue... 'q' is quit)"); - } else { - sout.print("(" + totalPrintedRows + " rows, continue... 'q' is quit)"); - } - sout.flush(); - if (sin != null) { - if (sin.read() == 'q') { - endOfTuple = false; - sout.println(); - break; - } - } - numOfPrintedRows = 0; - sout.println(); - } - } - sout.println(getQuerySuccessMessage(tableDesc, responseTime, totalPrintedRows, "selected", endOfTuple)); - sout.flush(); - } - - @Override - public void printNoResult(PrintWriter sout) { - sout.println("(0 rows)"); - sout.flush(); - } - - @Override - public void printProgress(PrintWriter sout, QueryStatus status) { - sout.println("Progress: " + (int)(status.getProgress() * 100.0f) - + "%, response time: " - + getResponseTimeReadable((float)((status.getFinishTime() - status.getSubmitTime()) / 1000.0))); - sout.flush(); - } - - @Override - public void printMessage(PrintWriter sout, String message) { - sout.println(message); - sout.flush(); - } - - @Override - public void printErrorMessage(PrintWriter sout, Throwable t) { - sout.println(parseErrorMessage(t.getMessage())); - if (printErrorTrace) { - sout.println(ExceptionUtils.getStackTrace(t)); - } - sout.flush(); - } - - @Override - public void printErrorMessage(PrintWriter sout, String message) { - sout.println(parseErrorMessage(message)); - sout.flush(); - } - - @Override - public void printKilledMessage(PrintWriter sout, QueryId queryId) { - sout.println(TajoCli.KILL_PREFIX + queryId); - sout.flush(); - } - - @Override - public void printErrorMessage(PrintWriter sout, QueryStatus status) { - if (status.getErrorMessage() != null && !status.getErrorMessage().isEmpty()) { - printErrorMessage(sout, parseErrorMessage(status.getErrorMessage())); - } else { - printErrorMessage(sout, "No error message"); - } - if (printErrorTrace && status.getErrorTrace() != null && !status.getErrorTrace().isEmpty()) { - sout.println(status.getErrorTrace()); - } - sout.flush(); - } - - public static String parseErrorMessage(String message) { - if (message == null) { - return TajoCli.ERROR_PREFIX + "No error message"; - } - String[] lines = message.split("\n"); - message = lines[0]; - - int index = message.lastIndexOf(TajoCli.ERROR_PREFIX); - if (index < 0) { - message = TajoCli.ERROR_PREFIX + message; - } else { - message = message.substring(index); - } - - return message; - } -} http://git-wip-us.apache.org/repos/asf/tajo/blob/c59baa3a/tajo-client/src/main/java/org/apache/tajo/cli/DescFunctionCommand.java ---------------------------------------------------------------------- diff --git a/tajo-client/src/main/java/org/apache/tajo/cli/DescFunctionCommand.java b/tajo-client/src/main/java/org/apache/tajo/cli/DescFunctionCommand.java deleted file mode 100644 index c72f48d..0000000 --- a/tajo-client/src/main/java/org/apache/tajo/cli/DescFunctionCommand.java +++ /dev/null @@ -1,135 +0,0 @@ -/** - * 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. - */ - -package org.apache.tajo.cli; - -import org.apache.tajo.catalog.proto.CatalogProtos; -import org.apache.tajo.function.FunctionUtil; - -import java.util.*; - -import static org.apache.tajo.common.TajoDataTypes.DataType; - -public class DescFunctionCommand extends TajoShellCommand { - public DescFunctionCommand(TajoCli.TajoCliContext context) { - super(context); - } - - @Override - public String getCommand() { - return "\\df"; - } - - @Override - public void invoke(String[] cmd) throws Exception { - boolean printDetail = false; - String functionName = ""; - if(cmd.length == 0) { - throw new IllegalArgumentException(); - } - - if (cmd.length == 2) { - printDetail = true; - functionName = cmd[1]; - } - - List functions = - new ArrayList(client.getFunctions(functionName)); - - Collections.sort(functions, new Comparator() { - @Override - public int compare(CatalogProtos.FunctionDescProto f1, CatalogProtos.FunctionDescProto f2) { - int nameCompared = f1.getSignature().getName().compareTo(f2.getSignature().getName()); - if (nameCompared != 0) { - return nameCompared; - } else { - return f1.getSignature().getReturnType().getType().compareTo(f2.getSignature().getReturnType().getType()); - } - } - }); - - String[] headers = new String[]{"Name", "Result type", "Argument types", "Description", "Type"}; - float[] columnWidthRates = new float[]{0.15f, 0.15f, 0.2f, 0.4f, 0.1f}; - int[] columnWidths = printHeader(headers, columnWidthRates); - - for(CatalogProtos.FunctionDescProto eachFunction: functions) { - String name = eachFunction.getSignature().getName(); - String resultDataType = eachFunction.getSignature().getReturnType().getType().toString(); - String arguments = FunctionUtil.buildParamTypeString( - eachFunction.getSignature().getParameterTypesList().toArray( - new DataType[eachFunction.getSignature().getParameterTypesCount()])); - String functionType = eachFunction.getSignature().getType().toString(); - String description = eachFunction.getSupplement().getShortDescription(); - - int index = 0; - printLeft(" " + name, columnWidths[index++]); - context.getOutput().print("|"); - printLeft(" " + resultDataType, columnWidths[index++]); - context.getOutput().print("|"); - printLeft(" " + arguments, columnWidths[index++]); - context.getOutput().print("|"); - printLeft(" " + description, columnWidths[index++]); - context.getOutput().print("|"); - printLeft(" " + functionType, columnWidths[index++]); - - println(); - } - - println(); - context.getOutput().println("(" + functions.size() + ") rows"); - println(); - - if (printDetail && !functions.isEmpty()) { - Map functionMap = - new HashMap(); - - for (CatalogProtos.FunctionDescProto eachFunction: functions) { - if (!functionMap.containsKey(eachFunction.getSupplement().getShortDescription())) { - functionMap.put(eachFunction.getSupplement().getShortDescription(), eachFunction); - } - } - - for (CatalogProtos.FunctionDescProto eachFunction: functionMap.values()) { - String signature = eachFunction.getSignature().getReturnType().getType() + " " + - FunctionUtil.buildSimpleFunctionSignature(eachFunction.getSignature().getName(), - eachFunction.getSignature().getParameterTypesList()); - String fullDescription = eachFunction.getSupplement().getShortDescription(); - if(eachFunction.getSupplement().getDetail() != null && !eachFunction.getSupplement().getDetail().isEmpty()) { - fullDescription += "\n" + eachFunction.getSupplement().getDetail(); - } - - context.getOutput().println("Function: " + signature); - context.getOutput().println("Description: " + fullDescription); - context.getOutput().println("Example:\n" + eachFunction.getSupplement().getExample()); - println(); - } - } - } - - @Override - public String getUsage() { - return "[function_name]"; - } - - @Override - public String getDescription() { - return "show function description"; - } - - -} http://git-wip-us.apache.org/repos/asf/tajo/blob/c59baa3a/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 deleted file mode 100644 index 4b34858..0000000 --- a/tajo-client/src/main/java/org/apache/tajo/cli/DescTableCommand.java +++ /dev/null @@ -1,135 +0,0 @@ -/** - * 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. - */ - -package org.apache.tajo.cli; - -import org.apache.commons.lang.CharUtils; -import org.apache.commons.lang.StringEscapeUtils; -import org.apache.tajo.catalog.Column; -import org.apache.tajo.catalog.TableDesc; -import org.apache.tajo.catalog.partition.PartitionMethodDesc; -import org.apache.tajo.client.QueryClient; -import org.apache.tajo.util.FileUtil; -import org.apache.tajo.util.TUtil; - -import java.util.List; -import java.util.Map; - -public class DescTableCommand extends TajoShellCommand { - public DescTableCommand(TajoCli.TajoCliContext context) { - super(context); - } - - @Override - public String getCommand() { - return "\\d"; - } - - @Override - public void invoke(String[] cmd) throws Exception { - if (cmd.length == 2) { - String tableName = cmd[1]; - tableName = tableName.replace("\"", ""); - TableDesc desc = client.getTableDesc(tableName); - if (desc == null) { - context.getOutput().println("Did not find any relation named \"" + tableName + "\""); - } else { - context.getOutput().println(toFormattedString(desc)); - } - } else if (cmd.length == 1) { - List tableList = client.getTableList(null); - if (tableList.size() == 0) { - context.getOutput().println("No Relation Found"); - } - for (String table : tableList) { - context.getOutput().println(table); - } - } else { - throw new IllegalArgumentException(); - } - } - - @Override - public String getUsage() { - return "[table_name]"; - } - - @Override - public String getDescription() { - return "show table description"; - } - - protected String toFormattedString(TableDesc desc) { - StringBuilder sb = new StringBuilder(); - sb.append("\ntable name: ").append(desc.getName()).append("\n"); - sb.append("table path: ").append(desc.getPath()).append("\n"); - sb.append("store type: ").append(desc.getMeta().getStoreType()).append("\n"); - if (desc.getStats() != null) { - - long row = desc.getStats().getNumRows(); - String rowText = row == QueryClient.UNKNOWN_ROW_NUMBER ? "unknown" : row + ""; - sb.append("number of rows: ").append(rowText).append("\n"); - sb.append("volume: ").append( - FileUtil.humanReadableByteCount(desc.getStats().getNumBytes(), - true)).append("\n"); - } - sb.append("Options: \n"); - for(Map.Entry entry : desc.getMeta().toMap().entrySet()){ - - /* - * Checks whether the character is ASCII 7 bit printable. - * For example, a printable unicode '\u007c' become the character ‘|’. - * - * Control-chars : ctrl-a(\u0001), tab(\u0009) .. - * Printable-chars : '|'(\u007c), ','(\u002c) .. - * */ - - String value = entry.getValue(); - String unescaped = StringEscapeUtils.unescapeJava(value); - if (unescaped.length() == 1 && CharUtils.isAsciiPrintable(unescaped.charAt(0))) { - value = unescaped; - } - sb.append("\t").append("'").append(entry.getKey()).append("'").append("=") - .append("'").append(value).append("'").append("\n"); - } - sb.append("\n"); - sb.append("schema: \n"); - - for(int i = 0; i < desc.getSchema().size(); i++) { - Column col = desc.getSchema().getColumn(i); - sb.append(col.getSimpleName()).append("\t").append(col.getDataType().getType()); - if (col.getDataType().hasLength()) { - sb.append("(").append(col.getDataType().getLength()).append(")"); - } - sb.append("\n"); - } - - sb.append("\n"); - if (desc.getPartitionMethod() != null) { - PartitionMethodDesc partition = desc.getPartitionMethod(); - sb.append("Partitions: \n"); - - sb.append("type:").append(partition.getPartitionType().name()).append("\n"); - - sb.append("columns:").append(":"); - sb.append(TUtil.arrayToString(partition.getExpressionSchema().toArray())); - } - - return sb.toString(); - } -} http://git-wip-us.apache.org/repos/asf/tajo/blob/c59baa3a/tajo-client/src/main/java/org/apache/tajo/cli/ExecExternalShellCommand.java ---------------------------------------------------------------------- diff --git a/tajo-client/src/main/java/org/apache/tajo/cli/ExecExternalShellCommand.java b/tajo-client/src/main/java/org/apache/tajo/cli/ExecExternalShellCommand.java deleted file mode 100644 index 628f8ba..0000000 --- a/tajo-client/src/main/java/org/apache/tajo/cli/ExecExternalShellCommand.java +++ /dev/null @@ -1,122 +0,0 @@ -/** - * 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. - */ - -package org.apache.tajo.cli; - -import java.io.*; -import java.util.concurrent.CountDownLatch; - -public class ExecExternalShellCommand extends TajoShellCommand { - public ExecExternalShellCommand(TajoCli.TajoCliContext context) { - super(context); - } - - @Override - public String getCommand() { - return "\\!"; - } - - @Override - public void invoke(String[] command) throws Exception { - StringBuilder shellCommand = new StringBuilder(); - String prefix = ""; - for(int i = 1; i < command.length; i++) { - shellCommand.append(prefix).append(command[i]); - prefix = " "; - } - - String builtCommand = shellCommand.toString(); - if (command.length < 2) { - throw new IOException("ERROR: '" + builtCommand + "' is an invalid command."); - } - - String[] execCommand = new String[3]; - execCommand[0] = "/bin/bash"; - execCommand[1] = "-c"; - execCommand[2] = builtCommand; - - PrintWriter sout = context.getOutput(); - - CountDownLatch latch = new CountDownLatch(2); - Process process = Runtime.getRuntime().exec(execCommand); - try { - InputStreamConsoleWriter inWriter = new InputStreamConsoleWriter(process.getInputStream(), sout, "", latch); - InputStreamConsoleWriter errWriter = new InputStreamConsoleWriter(process.getErrorStream(), sout, "ERROR: ", latch); - - inWriter.start(); - errWriter.start(); - - int processResult = process.waitFor(); - latch.await(); - if (processResult != 0) { - throw new IOException("ERROR: Failed with exit code = " + processResult); - } - } finally { - org.apache.commons.io.IOUtils.closeQuietly(process.getInputStream()); - org.apache.commons.io.IOUtils.closeQuietly(process.getOutputStream()); - org.apache.commons.io.IOUtils.closeQuietly(process.getErrorStream()); - } - } - - @Override - public String getUsage() { - return " [params]"; - } - - @Override - public String getDescription() { - return "executes external shell command in TAJO shell"; - } - - static class InputStreamConsoleWriter extends Thread { - private InputStream in; - private PrintWriter writer; - private String prefix; - private CountDownLatch latch; - - public InputStreamConsoleWriter(InputStream in, PrintWriter writer, String prefix, CountDownLatch latch) { - this.in = in; - this.writer = writer; - this.prefix = prefix; - this.latch = latch; - } - - @Override - public void run() { - BufferedReader reader = null; - try { - reader = new BufferedReader(new InputStreamReader(in)); - String line; - while ((line = reader.readLine()) != null) { - writer.println(prefix + line); - writer.flush(); - } - } catch (Exception e) { - writer.println("ERROR: " + e.getMessage()); - } finally { - if (reader != null) { - try { - reader.close(); - } catch (IOException e) { - } - } - latch.countDown(); - } - } - } -} http://git-wip-us.apache.org/repos/asf/tajo/blob/c59baa3a/tajo-client/src/main/java/org/apache/tajo/cli/ExitCommand.java ---------------------------------------------------------------------- diff --git a/tajo-client/src/main/java/org/apache/tajo/cli/ExitCommand.java b/tajo-client/src/main/java/org/apache/tajo/cli/ExitCommand.java deleted file mode 100644 index 1a18841..0000000 --- a/tajo-client/src/main/java/org/apache/tajo/cli/ExitCommand.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * 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. - */ - -package org.apache.tajo.cli; - -public class ExitCommand extends TajoShellCommand { - - public ExitCommand(TajoCli.TajoCliContext context) { - super(context); - } - - @Override - public String getCommand() { - return "\\q"; - } - - @Override - public void invoke(String[] cmd) throws Exception { - context.getOutput().println("bye!"); - System.exit(0); - } - - @Override - public String getUsage() { - return ""; - } - - @Override - public String getDescription() { - return "quit"; - } -} http://git-wip-us.apache.org/repos/asf/tajo/blob/c59baa3a/tajo-client/src/main/java/org/apache/tajo/cli/HdfsCommand.java ---------------------------------------------------------------------- diff --git a/tajo-client/src/main/java/org/apache/tajo/cli/HdfsCommand.java b/tajo-client/src/main/java/org/apache/tajo/cli/HdfsCommand.java deleted file mode 100644 index 5b4c12e..0000000 --- a/tajo-client/src/main/java/org/apache/tajo/cli/HdfsCommand.java +++ /dev/null @@ -1,57 +0,0 @@ -/** - * 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. - */ - -package org.apache.tajo.cli; - -import org.apache.hadoop.fs.FsShell; - -public class HdfsCommand extends TajoShellCommand { - private FsShell fsShell; - - public HdfsCommand(TajoCli.TajoCliContext context) { - super(context); - fsShell = new FsShell(context.getConf()); - } - - @Override - public String getCommand() { - return "\\dfs"; - } - - @Override - public void invoke(String[] command) throws Exception { - try { - String[] dfsCommands = new String[command.length - 1]; - System.arraycopy(command, 1, dfsCommands, 0, dfsCommands.length); - - fsShell.run(dfsCommands); - } catch (Exception e) { - context.getOutput().println("ERROR: " + e.getMessage()); - } - } - - @Override - public String getUsage() { - return " [options]"; - } - - @Override - public String getDescription() { - return "executes a dfs command in TAJO shell "; - } -} http://git-wip-us.apache.org/repos/asf/tajo/blob/c59baa3a/tajo-client/src/main/java/org/apache/tajo/cli/HelpCommand.java ---------------------------------------------------------------------- diff --git a/tajo-client/src/main/java/org/apache/tajo/cli/HelpCommand.java b/tajo-client/src/main/java/org/apache/tajo/cli/HelpCommand.java deleted file mode 100644 index d4ade37..0000000 --- a/tajo-client/src/main/java/org/apache/tajo/cli/HelpCommand.java +++ /dev/null @@ -1,132 +0,0 @@ -/** - * 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. - */ - -package org.apache.tajo.cli; - -import java.io.PrintWriter; - -import org.apache.tajo.util.VersionInfo; - -public class HelpCommand extends TajoShellCommand { - private String targetDocVersion = ""; - - public HelpCommand(TajoCli.TajoCliContext context) { - super(context); - } - - @Override - public String getCommand() { - return "\\?"; - } - - @Override - public String [] getAliases() { - return new String [] {"\\help"}; - } - - @Override - public void invoke(String[] cmd) throws Exception { - if(targetDocVersion.equalsIgnoreCase("")) { - targetDocVersion = getDocumentationVersion(); - } - - if (cmd.length == 1) { - PrintWriter sout = context.getOutput(); - sout.println(); - - sout.println("General"); - sout.println(" \\copyright show Apache License 2.0"); - sout.println(" \\version show Tajo version"); - sout.println(" \\? show help"); - sout.println(" \\? [COMMAND] show help of a given command"); - sout.println(" \\help alias of \\?"); - sout.println(" \\q quit tsql"); - sout.println(); - sout.println(); - - sout.println("Informational"); - sout.println(" \\l list databases"); - sout.println(" \\c show current database"); - sout.println(" \\c [DBNAME] connect to new database"); - sout.println(" \\d list tables"); - sout.println(" \\d [TBNAME] describe table"); - sout.println(" \\df list functions"); - sout.println(" \\df NAME describe function"); - sout.println(); - sout.println(); - - sout.println("Tool"); - sout.println(" \\! execute a linux shell command"); - sout.println(" \\dfs execute a dfs command"); - sout.println(" \\admin execute tajo admin command"); - sout.println(); - sout.println(); - - sout.println("Variables"); - sout.println(" \\set [[NAME] [VALUE] set session variable or list session variables"); - sout.println(" \\unset NAME unset session variable"); - sout.println(); - sout.println(); - - sout.println("Documentations"); - sout.println(" tsql guide http://tajo.apache.org/docs/" + targetDocVersion + "/cli.html"); - sout.println(" Query language http://tajo.apache.org/docs/" + targetDocVersion + "/sql_language.html"); - sout.println(" Functions http://tajo.apache.org/docs/" + targetDocVersion + "/functions.html"); - sout.println(" Backup & restore http://tajo.apache.org/docs/" + targetDocVersion + "/backup_and_restore.html"); - sout.println(" Configuration http://tajo.apache.org/docs/" + targetDocVersion + "/configuration.html"); - sout.println(); - } else if (cmd.length == 2) { - String slashCommand = "\\" + cmd[1]; - if (context.getCommands().containsKey(slashCommand)) { - context.getCommands().get(slashCommand).printHelp(); - } else { - context.getOutput().println("Command not found: " + cmd[1]); - } - } - } - - private String getDocumentationVersion() { - String tajoVersion = "", docVersion = "", docDefaultVersion = "current"; - String tajoFullVersion = VersionInfo.getVersion(); - - int delimiterIdx = tajoFullVersion.indexOf("-"); - if (delimiterIdx > -1) { - tajoVersion = tajoFullVersion.substring(0, delimiterIdx); - } else { - tajoVersion = tajoFullVersion; - } - - if(tajoVersion.equalsIgnoreCase("")) { - docVersion = docDefaultVersion; - } else { - docVersion = tajoVersion; - } - - return docVersion; - } - - @Override - public String getUsage() { - return ""; - } - - @Override - public String getDescription() { - return "show command lists and their usages"; - } -} http://git-wip-us.apache.org/repos/asf/tajo/blob/c59baa3a/tajo-client/src/main/java/org/apache/tajo/cli/InvalidStatementException.java ---------------------------------------------------------------------- diff --git a/tajo-client/src/main/java/org/apache/tajo/cli/InvalidStatementException.java b/tajo-client/src/main/java/org/apache/tajo/cli/InvalidStatementException.java deleted file mode 100644 index 9782e84..0000000 --- a/tajo-client/src/main/java/org/apache/tajo/cli/InvalidStatementException.java +++ /dev/null @@ -1,25 +0,0 @@ -/** - * 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. - */ - -package org.apache.tajo.cli; - -public class InvalidStatementException extends Exception { - public InvalidStatementException(String message) { - super(message); - } -} http://git-wip-us.apache.org/repos/asf/tajo/blob/c59baa3a/tajo-client/src/main/java/org/apache/tajo/cli/ListDatabaseCommand.java ---------------------------------------------------------------------- diff --git a/tajo-client/src/main/java/org/apache/tajo/cli/ListDatabaseCommand.java b/tajo-client/src/main/java/org/apache/tajo/cli/ListDatabaseCommand.java deleted file mode 100644 index 199fed2..0000000 --- a/tajo-client/src/main/java/org/apache/tajo/cli/ListDatabaseCommand.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * 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. - */ - -package org.apache.tajo.cli; - -public class ListDatabaseCommand extends TajoShellCommand { - - public ListDatabaseCommand(TajoCli.TajoCliContext context) { - super(context); - } - - @Override - public String getCommand() { - return "\\l"; - } - - @Override - public void invoke(String[] cmd) throws Exception { - for (String databaseName : client.getAllDatabaseNames()) { - context.getOutput().println(databaseName); - } - } - - @Override - public String getUsage() { - return ""; - } - - @Override - public String getDescription() { - return "list all databases"; - } -} http://git-wip-us.apache.org/repos/asf/tajo/blob/c59baa3a/tajo-client/src/main/java/org/apache/tajo/cli/ParsedResult.java ---------------------------------------------------------------------- diff --git a/tajo-client/src/main/java/org/apache/tajo/cli/ParsedResult.java b/tajo-client/src/main/java/org/apache/tajo/cli/ParsedResult.java deleted file mode 100644 index 001aded..0000000 --- a/tajo-client/src/main/java/org/apache/tajo/cli/ParsedResult.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * 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. - */ - -package org.apache.tajo.cli; - - -public class ParsedResult { - public static enum StatementType { - META, - STATEMENT - } - - private final StatementType type; - private final String historyStatement; - private final String statement; - - public ParsedResult(StatementType type, String statement, String historyStatement) { - this.type = type; - this.statement = statement; - this.historyStatement = historyStatement; - } - - public StatementType getType() { - return type; - } - - public String getHistoryStatement() { - return historyStatement.trim(); - } - - public String getStatement() { - return statement.trim(); - } - - public String toString() { - return "(" + type.name() + ") " + historyStatement; - } -} http://git-wip-us.apache.org/repos/asf/tajo/blob/c59baa3a/tajo-client/src/main/java/org/apache/tajo/cli/SetCommand.java ---------------------------------------------------------------------- diff --git a/tajo-client/src/main/java/org/apache/tajo/cli/SetCommand.java b/tajo-client/src/main/java/org/apache/tajo/cli/SetCommand.java deleted file mode 100644 index c957a19..0000000 --- a/tajo-client/src/main/java/org/apache/tajo/cli/SetCommand.java +++ /dev/null @@ -1,126 +0,0 @@ -/** - * 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. - */ - -package org.apache.tajo.cli; - -import com.google.protobuf.ServiceException; -import org.apache.tajo.SessionVars; -import org.apache.tajo.util.StringUtils; - -import java.util.HashMap; -import java.util.Map; - -import static org.apache.tajo.SessionVars.VariableMode; - -public class SetCommand extends TajoShellCommand { - - public SetCommand(TajoCli.TajoCliContext context) { - super(context); - } - - @Override - public String getCommand() { - return "\\set"; - } - - private void showAllSessionVars() throws ServiceException { - for (Map.Entry entry: client.getAllSessionVariables().entrySet()) { - context.getOutput().println(StringUtils.quote(entry.getKey()) + "=" + StringUtils.quote(entry.getValue())); - } - } - - private void updateSessionVariable(String key, String val) throws ServiceException { - Map variables = new HashMap(); - variables.put(key, val); - client.updateSessionVariables(variables); - } - - void set(String key, String val) throws ServiceException { - SessionVars sessionVar = null; - - if (SessionVars.exists(key)) { // if the variable is one of the session variables - sessionVar = SessionVars.get(key); - - // is it cli-side variable? - if (sessionVar.getMode() == VariableMode.CLI_SIDE_VAR) { - context.setCliSideVar(key, val); - } else { - updateSessionVariable(key, val); - } - - if (SessionVars.isDeprecated(key)) { - context.getOutput().println("Warning: deprecated to directly use config key in TajoConf.ConfVars. " + - "Please execute '\\help set'."); - } - } else { - updateSessionVariable(key, val); - } - } - - @Override - public void invoke(String[] cmd) throws Exception { - if (cmd.length == 1) { - showAllSessionVars(); - } else if (cmd.length == 3) { - set(cmd[1], cmd[2]); - } else { - context.getOutput().println("usage: \\set [[NAME] VALUE]"); - } - } - - @Override - public String getUsage() { - return ""; - } - - @Override - public String getDescription() { - return "set session variable or shows all session variables"; - } - - @Override - public void printHelp() { - context.getOutput().println("\nAvailable Session Variables:\n"); - for (SessionVars var : SessionVars.values()) { - - if (var.getMode() == VariableMode.DEFAULT || - var.getMode() == VariableMode.CLI_SIDE_VAR || - var.getMode() == VariableMode.FROM_SHELL_ENV) { - - context.getOutput().println("\\set " + var.keyname() + " " + getDisplayType(var.getVarType()) + " - " + var - .getDescription()); - } - } - } - - public static String getDisplayType(Class clazz) { - if (clazz == String.class) { - return "[text value]"; - } else if (clazz == Integer.class) { - return "[int value]"; - } else if (clazz == Long.class) { - return "[long value]"; - } else if (clazz == Float.class) { - return "[real value]"; - } else if (clazz == Boolean.class) { - return "[true or false]"; - } else { - return clazz.getSimpleName(); - } - } -} http://git-wip-us.apache.org/repos/asf/tajo/blob/c59baa3a/tajo-client/src/main/java/org/apache/tajo/cli/SimpleParser.java ---------------------------------------------------------------------- diff --git a/tajo-client/src/main/java/org/apache/tajo/cli/SimpleParser.java b/tajo-client/src/main/java/org/apache/tajo/cli/SimpleParser.java deleted file mode 100644 index 0beaec8..0000000 --- a/tajo-client/src/main/java/org/apache/tajo/cli/SimpleParser.java +++ /dev/null @@ -1,388 +0,0 @@ -/** - * 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. - */ - -package org.apache.tajo.cli; - -import java.util.ArrayList; -import java.util.List; - -import static org.apache.tajo.cli.ParsedResult.StatementType.META; -import static org.apache.tajo.cli.ParsedResult.StatementType.STATEMENT; - -/** - * This is a parser used in tsql to parse multiple SQL lines into SQL statements. - * It helps tsql recognizes the termination of each SQL statement and quotation mark (') while - * parses multiple separate lines. - */ -public class SimpleParser { - - public static enum ParsingState { - TOK_START, // Start State - META, // Meta Command - STATEMENT, // Statement - WITHIN_QUOTE, // Within Quote - INVALID, // Invalid Statement - STATEMENT_EOS, // End State (End of Statement) - META_EOS // End State (End of Statement) - } - - ParsingState state = START_STATE; - int lineNum; - - /** - * It will be used to store a query statement into Jline history. - * the query statement for history does not include unnecessary white spaces and new line. - */ - private StringBuilder historyAppender = new StringBuilder(); - /** - * It will be used to submit a query statement to the TajoMaster. It just contains a raw query statement string. - */ - private StringBuilder rawAppender = new StringBuilder(); - - public static final ParsingState START_STATE = ParsingState.TOK_START; - - /** - *

State Machine

- * All whitespace are ignored in all cases except for - * - *
-   * (start) TOK_START --> META ---------------------> META_EOS
-   *                    |
-   *                    |
-   *                    |
-   *                    |-----------> STATEMENT ----------> STMT_EOS
-   *                                  \       ^
-   *                                  \      /
-   *                                  \-> WITHIN_QUOTE
-   *                                        \    ^
-   *                                        \---/
-   * 
- */ - - public static List parseScript(String str) throws InvalidStatementException { - SimpleParser parser = new SimpleParser(); - List parsedResults = new ArrayList(); - parsedResults.addAll(parser.parseLines(str)); - parsedResults.addAll(parser.EOF()); - return parsedResults; - } - - public List parseLines(String str) throws InvalidStatementException { - List statements = new ArrayList(); - int lineStartIdx; - int idx = 0; - char [] chars = str.toCharArray(); - - // if parsing continues, it means that the previous line is broken by '\n'. - // So, we should add new line to rawAppender. - if (isStatementContinue()) { - rawAppender.append("\n"); - } - - while(idx < str.length()) { - - // initialization for new statement - if (state == ParsingState.TOK_START) { - lineNum = 0; - - // ignore all whitespace before start - if (Character.isWhitespace(chars[idx])) { - idx++; - continue; - } - } - - //////////////////////////// - // TOK_START --> META - //////////////////////////// - - lineStartIdx = idx; - - if (state == ParsingState.TOK_START && chars[idx] == '\\') { - state = ParsingState.META; - - //////////////////////////// - // META --> TOK_EOS - //////////////////////////// - while (state != ParsingState.META_EOS && idx < chars.length) { - char character = chars[idx++]; - - if (isEndOfMeta(character)) { - state = ParsingState.META_EOS; - } else if (Character.isWhitespace(character)) { - // skip - } - } - - if (state == ParsingState.META_EOS) { - historyAppender.append(str.subSequence(lineStartIdx, idx - 1).toString()); - appendToRawStatement(str.subSequence(lineStartIdx, idx - 1).toString(), true); - } else { - historyAppender.append(str.subSequence(lineStartIdx, idx).toString()); - appendToRawStatement(str.subSequence(lineStartIdx, idx).toString(), true); - } - - } else if (isInlineCommentStart(chars, idx)) { - idx = consumeInlineComment(chars, idx); - appendToRawStatement(str.subSequence(lineStartIdx, idx).toString(), true); - - ///////////////////////////////// - // TOK_START -> STATEMENT - // or TOK_STATEMENT -> STATEMENT - //////////////////////////////// - } else if (isStatementContinue() || isStatementStart(chars[idx])) { - if (!isStatementContinue()) { // TOK_START -> STATEMENT - state = ParsingState.STATEMENT; - rawAppender.append("\n"); - } - - while (!isTerminateState(state) && idx < chars.length) { - char character = chars[idx++]; - - /////////////////////////////////////////////////////// - // in-statement loop BEGIN - /////////////////////////////////////////////////////// - if (isEndOfStatement(character)) { - state = ParsingState.STATEMENT_EOS; - - } else if (state == ParsingState.STATEMENT && character == '\n') { - appendToBothStatements(chars, lineStartIdx, idx, 1); // omit new line chacter '\n' from history statement - lineStartIdx = idx; - - } else if (state == ParsingState.STATEMENT && character == '\'') { // TOK_STATEMENT -> WITHIN_QUOTE - state = ParsingState.WITHIN_QUOTE; - - if (idx < chars.length) { - character = chars[idx++]; - } else { - continue; - } - - - // idx points the characters followed by the current character. So, we should use 'idx - 1' - // in order to point the current character. - } else if (state == ParsingState.STATEMENT && idx < chars.length && isInlineCommentStart(chars, idx - 1)) { - idx++; - 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); - lineStartIdx = idx; - } - /////////////////////////////////////////////////////// - // in-statement loop END - /////////////////////////////////////////////////////// - - if (state == ParsingState.WITHIN_QUOTE) { - while(idx < chars.length) { - /////////////////////////////// - // WITHIN_QUOTE --> STATEMENT - /////////////////////////////// - if (character == '\'') { - state = ParsingState.STATEMENT; - break; - } - character = chars[idx++]; - } - if (state == ParsingState.WITHIN_QUOTE && character == '\'') { - state = ParsingState.STATEMENT; - } - } - } - - // After all characters are consumed - - if (state == ParsingState.STATEMENT_EOS) { // If one query statement is terminated - appendToBothStatements(chars, lineStartIdx, idx - 1); // skip semicolon (;) - } else { - appendToBothStatements(chars, lineStartIdx, idx); - - // if it is not within quote and there is no space between lines, adds a space. - if (state == ParsingState.STATEMENT && (historyAppender.charAt(historyAppender.length() - 1) != ' ')) { - historyAppender.append(" "); - rawAppender.append("\n"); - } - } - } else { // skip unknown character - idx++; - } - - lineNum++; - statements.addAll(doProcessEndOfStatement(state == ParsingState.META)); - } - - return statements; - } - - /** - * Append the range of characters into a given StringBuilder instance. - * - * @param chars Characters - * @param fromIdx start character index - * @param toIdx end character index - */ - private void appendToStatement(StringBuilder builder, char[] chars, int fromIdx, int toIdx) { - builder.append(chars, fromIdx, toIdx - fromIdx); - } - - /** - * Append the range of characters into both history and raw appenders. It omits the number of characters specified by - * omitCharNums. - * - * - * @param chars Characters - * @param fromIdx start character index - * @param toIdx end character index - * @param omitCharNums how many characters will be omitted from history statement - */ - private void appendToBothStatements(char[] chars, int fromIdx, int toIdx, int omitCharNums) { - appendToStatement(historyAppender, chars, fromIdx, toIdx - omitCharNums); - if (historyAppender.charAt(historyAppender.length() - 1) != ' ') { - historyAppender.append(" "); - } - appendToStatement(rawAppender, chars, fromIdx, toIdx); - } - - /** - * Append the range of characters into both history and raw appenders. - * - * - * @param chars Characters - * @param fromIdx start character index - * @param toIdx end character index - */ - private void appendToBothStatements(char[] chars, int fromIdx, int toIdx) { - historyAppender.append(chars, fromIdx, toIdx - fromIdx); - rawAppender.append(chars, fromIdx, toIdx - fromIdx); - } - - private int consumeInlineComment(char [] chars, int currentIdx) { - currentIdx++; - while (currentIdx < chars.length && !isNewLine(chars[currentIdx])) { - currentIdx++; - } - return currentIdx; - } - - 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(str); - } else { - rawAppender.append(str); - } - } - - private static boolean isEndOfMeta(char character) { - return character == ';' || character == '\n'; - } - - private static boolean isEndOfStatement(char character) { - return character == ';'; - } - - /** - * It checks if inline comment '--' begins. - * @param chars - * @param idx - * @return - */ - private boolean isInlineCommentStart(char[] chars, int idx) { - if (idx >= chars.length - 1) { - return false; - } - return (state == ParsingState.STATEMENT || state == ParsingState.TOK_START) && - (chars[idx] == '-' && chars[idx + 1] == '-'); - } - - private boolean isNewLine(char character) { - return character == '\n'; - } - - private boolean isStatementStart(char character) { - return state == ParsingState.TOK_START && (Character.isLetterOrDigit(character)); - } - - private boolean isStatementContinue() { - return state == ParsingState.WITHIN_QUOTE || state == ParsingState.STATEMENT; - } - - /** - * process all parsed statements so far and return a list of parsed results. - * - * @param endOfFile TRUE if the end of file. - * @return the list of parsed results, each of result contains one query statement or meta command. - * @throws InvalidStatementException - */ - private List doProcessEndOfStatement(boolean endOfFile) throws InvalidStatementException { - List parsedResults = new ArrayList(); - String errorMessage = ""; - if (endOfFile) { - if (state == ParsingState.META) { - state = ParsingState.META_EOS; - } else if (state == ParsingState.STATEMENT) { - state = ParsingState.STATEMENT_EOS; - } else if (state == ParsingState.WITHIN_QUOTE) { - state = ParsingState.INVALID; - errorMessage = "unterminated quoted string at LINE " + lineNum; - } - } - - if (isTerminateState(state)) { - String historyStatement = historyAppender.toString(); - String rawStatement = rawAppender.toString(); - if (state == ParsingState.META_EOS) { - parsedResults.add(new ParsedResult(META, rawStatement, historyStatement)); - state = ParsingState.TOK_START; - } else if (state == ParsingState.STATEMENT_EOS) { - parsedResults.add(new ParsedResult(STATEMENT, rawStatement, historyStatement)); - } else { - throw new InvalidStatementException("ERROR: " + errorMessage); - } - - // reset all states - historyAppender.delete(0, historyAppender.length()); - rawAppender.delete(0, rawAppender.length()); - state = START_STATE; - } - - return parsedResults; - } - - /** - * It manually triggers the end of file. - * - * @return the list of parsed results, each of result contains one query statement or meta command. - * @throws InvalidStatementException - */ - public List EOF() throws InvalidStatementException { - return doProcessEndOfStatement(true); - } - - private static boolean isTerminateState(ParsingState state) { - return (state == ParsingState.META_EOS || state == ParsingState.STATEMENT_EOS || state == ParsingState.INVALID); - } - - public ParsingState getState() { - return state; - } - - public String toString() { - return "[" + state.name() + "]: " + historyAppender.toString(); - } -} http://git-wip-us.apache.org/repos/asf/tajo/blob/c59baa3a/tajo-client/src/main/java/org/apache/tajo/cli/TajoAdminCommand.java ---------------------------------------------------------------------- diff --git a/tajo-client/src/main/java/org/apache/tajo/cli/TajoAdminCommand.java b/tajo-client/src/main/java/org/apache/tajo/cli/TajoAdminCommand.java deleted file mode 100644 index 267c7a4..0000000 --- a/tajo-client/src/main/java/org/apache/tajo/cli/TajoAdminCommand.java +++ /dev/null @@ -1,57 +0,0 @@ -/** - * 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. - */ - -package org.apache.tajo.cli; - -import org.apache.tajo.client.TajoAdmin; - -public class TajoAdminCommand extends TajoShellCommand { - private TajoAdmin admin; - - public TajoAdminCommand(TajoCli.TajoCliContext context) { - super(context); - admin = new TajoAdmin(context.getConf(), context.getOutput(), context.getTajoClient()); - } - - @Override - public String getCommand() { - return "\\admin"; - } - - @Override - public void invoke(String[] command) throws Exception { - try { - String[] dfsCommands = new String[command.length - 1]; - System.arraycopy(command, 1, dfsCommands, 0, dfsCommands.length); - - admin.runCommand(dfsCommands); - } catch (Exception e) { - context.getOutput().println("ERROR: " + e.getMessage()); - } - } - - @Override - public String getUsage() { - return " [options]"; - } - - @Override - public String getDescription() { - return "execute a tajo amdin command."; - } -}