http://git-wip-us.apache.org/repos/asf/tajo/blob/42d79cf5/tajo-client/src/main/java/org/apache/tajo/cli/tsql/TajoCliOutputFormatter.java ---------------------------------------------------------------------- diff --git a/tajo-client/src/main/java/org/apache/tajo/cli/tsql/TajoCliOutputFormatter.java b/tajo-client/src/main/java/org/apache/tajo/cli/tsql/TajoCliOutputFormatter.java deleted file mode 100644 index a90baf3..0000000 --- a/tajo-client/src/main/java/org/apache/tajo/cli/tsql/TajoCliOutputFormatter.java +++ /dev/null @@ -1,98 +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.tsql; - -import org.apache.tajo.QueryId; -import org.apache.tajo.catalog.TableDesc; -import org.apache.tajo.cli.tsql.TajoCli; -import org.apache.tajo.client.QueryStatus; - -import java.io.InputStream; -import java.io.PrintWriter; -import java.sql.ResultSet; - -public interface TajoCliOutputFormatter { - /** - * Initialize formatter - * @param context - */ - public void init(TajoCli.TajoCliContext context); - - /** - * print query result to console - * @param sout - * @param sin - * @param tableDesc - * @param responseTime - * @param res - * @throws Exception - */ - public void printResult(PrintWriter sout, InputStream sin, TableDesc tableDesc, - float responseTime, ResultSet res) throws Exception; - - /** - * print no result message - * @param sout - */ - public void printNoResult(PrintWriter sout); - - /** - * print simple message - * @param sout - * @param message - */ - public void printMessage(PrintWriter sout, String message); - - /** - * print query progress message - * @param sout - * @param status - */ - public void printProgress(PrintWriter sout, QueryStatus status); - - /** - * print error message - * @param sout - * @param t - */ - public void printErrorMessage(PrintWriter sout, Throwable t); - - /** - * print error message - * @param sout - * @param message - */ - public void printErrorMessage(PrintWriter sout, String message); - - /** - * print error message - * @param sout - * @param queryId - */ - public void printKilledMessage(PrintWriter sout, QueryId queryId); - - /** - * print query status error message - * @param sout - * @param status - */ - void printErrorMessage(PrintWriter sout, QueryStatus status); - - void setScriptMode(); -}
http://git-wip-us.apache.org/repos/asf/tajo/blob/42d79cf5/tajo-client/src/main/java/org/apache/tajo/cli/tsql/TajoFileHistory.java ---------------------------------------------------------------------- diff --git a/tajo-client/src/main/java/org/apache/tajo/cli/tsql/TajoFileHistory.java b/tajo-client/src/main/java/org/apache/tajo/cli/tsql/TajoFileHistory.java deleted file mode 100644 index c780a77..0000000 --- a/tajo-client/src/main/java/org/apache/tajo/cli/tsql/TajoFileHistory.java +++ /dev/null @@ -1,41 +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.tsql; - -import jline.console.history.FileHistory; -import org.apache.tajo.cli.tsql.commands.ExitCommand; - -import java.io.File; -import java.io.IOException; - -public class TajoFileHistory extends FileHistory { - - public TajoFileHistory(File file) throws IOException { - super(file); - } - - @Override - public void add(CharSequence item) { - // Don't store an exit command. Most users wouldn't want it. - if (item.equals(ExitCommand.COMMAND_STRING)) { - return; - } - super.add(item); - } -} http://git-wip-us.apache.org/repos/asf/tajo/blob/42d79cf5/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/ConnectDatabaseCommand.java ---------------------------------------------------------------------- diff --git a/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/ConnectDatabaseCommand.java b/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/ConnectDatabaseCommand.java deleted file mode 100644 index ae644bd..0000000 --- a/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/ConnectDatabaseCommand.java +++ /dev/null @@ -1,72 +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.tsql.commands; - -import com.google.protobuf.ServiceException; -import org.apache.tajo.cli.tsql.TajoCli; - -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/42d79cf5/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/CopyrightCommand.java ---------------------------------------------------------------------- diff --git a/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/CopyrightCommand.java b/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/CopyrightCommand.java deleted file mode 100644 index 24276a2..0000000 --- a/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/CopyrightCommand.java +++ /dev/null @@ -1,65 +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.tsql.commands; - -import org.apache.tajo.cli.tsql.TajoCli; - -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/42d79cf5/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/DescFunctionCommand.java ---------------------------------------------------------------------- diff --git a/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/DescFunctionCommand.java b/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/DescFunctionCommand.java deleted file mode 100644 index 0a7f79b..0000000 --- a/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/DescFunctionCommand.java +++ /dev/null @@ -1,136 +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.tsql.commands; - -import org.apache.tajo.catalog.proto.CatalogProtos; -import org.apache.tajo.cli.tsql.TajoCli; -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<CatalogProtos.FunctionDescProto> functions = - new ArrayList<CatalogProtos.FunctionDescProto>(client.getFunctions(functionName)); - - Collections.sort(functions, new Comparator<CatalogProtos.FunctionDescProto>() { - @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<String, CatalogProtos.FunctionDescProto> functionMap = - new HashMap<String, CatalogProtos.FunctionDescProto>(); - - 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/42d79cf5/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/DescTableCommand.java ---------------------------------------------------------------------- diff --git a/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/DescTableCommand.java b/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/DescTableCommand.java deleted file mode 100644 index b7d9334..0000000 --- a/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/DescTableCommand.java +++ /dev/null @@ -1,137 +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.tsql.commands; - -import org.apache.commons.lang.CharUtils; -import org.apache.commons.lang.StringEscapeUtils; -import org.apache.tajo.TajoConstants; -import org.apache.tajo.catalog.CatalogUtil; -import org.apache.tajo.catalog.Column; -import org.apache.tajo.catalog.TableDesc; -import org.apache.tajo.catalog.partition.PartitionMethodDesc; -import org.apache.tajo.cli.tsql.TajoCli; -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<String> 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(CatalogUtil.getStoreTypeString(desc.getMeta().getStoreType())).append("\n"); - if (desc.getStats() != null) { - - long row = desc.getStats().getNumRows(); - String rowText = row == TajoConstants.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<String, String> 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/42d79cf5/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/ExecExternalShellCommand.java ---------------------------------------------------------------------- diff --git a/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/ExecExternalShellCommand.java b/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/ExecExternalShellCommand.java deleted file mode 100644 index ac97959..0000000 --- a/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/ExecExternalShellCommand.java +++ /dev/null @@ -1,124 +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.tsql.commands; - -import org.apache.tajo.cli.tsql.TajoCli; - -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 "<command> [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/42d79cf5/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/ExitCommand.java ---------------------------------------------------------------------- diff --git a/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/ExitCommand.java b/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/ExitCommand.java deleted file mode 100644 index d882b2f..0000000 --- a/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/ExitCommand.java +++ /dev/null @@ -1,52 +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.tsql.commands; - -import org.apache.tajo.cli.tsql.TajoCli; - -public class ExitCommand extends TajoShellCommand { - - // Sharing the exit command string publicly to filter it out from the command history. - public static final String COMMAND_STRING = "\\q"; - - public ExitCommand(TajoCli.TajoCliContext context) { - super(context); - } - - @Override - public String getCommand() { - return COMMAND_STRING; - } - - @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/42d79cf5/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/HdfsCommand.java ---------------------------------------------------------------------- diff --git a/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/HdfsCommand.java b/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/HdfsCommand.java deleted file mode 100644 index 8f57b74..0000000 --- a/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/HdfsCommand.java +++ /dev/null @@ -1,58 +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.tsql.commands; - -import org.apache.hadoop.fs.FsShell; -import org.apache.tajo.cli.tsql.TajoCli; - -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 "<hdfs command> [options]"; - } - - @Override - public String getDescription() { - return "executes a dfs command in TAJO shell "; - } -} http://git-wip-us.apache.org/repos/asf/tajo/blob/42d79cf5/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/HelpCommand.java ---------------------------------------------------------------------- diff --git a/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/HelpCommand.java b/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/HelpCommand.java deleted file mode 100644 index ce56d12..0000000 --- a/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/HelpCommand.java +++ /dev/null @@ -1,133 +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.tsql.commands; - -import org.apache.tajo.cli.tsql.TajoCli; -import org.apache.tajo.util.VersionInfo; - -import java.io.PrintWriter; - -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 + "/tsql.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/42d79cf5/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/ListDatabaseCommand.java ---------------------------------------------------------------------- diff --git a/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/ListDatabaseCommand.java b/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/ListDatabaseCommand.java deleted file mode 100644 index 534bece..0000000 --- a/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/ListDatabaseCommand.java +++ /dev/null @@ -1,50 +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.tsql.commands; - -import org.apache.tajo.cli.tsql.TajoCli; - -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/42d79cf5/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/SetCommand.java ---------------------------------------------------------------------- diff --git a/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/SetCommand.java b/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/SetCommand.java deleted file mode 100644 index 21c4be5..0000000 --- a/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/SetCommand.java +++ /dev/null @@ -1,127 +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.tsql.commands; - -import com.google.protobuf.ServiceException; -import org.apache.tajo.SessionVars; -import org.apache.tajo.cli.tsql.TajoCli; -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<String, String> 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<String, String> variables = new HashMap<String, String>(); - variables.put(key, val); - client.updateSessionVariables(variables); - } - - public 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/42d79cf5/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/TajoAdminCommand.java ---------------------------------------------------------------------- diff --git a/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/TajoAdminCommand.java b/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/TajoAdminCommand.java deleted file mode 100644 index 53f66b0..0000000 --- a/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/TajoAdminCommand.java +++ /dev/null @@ -1,58 +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.tsql.commands; - -import org.apache.tajo.cli.tools.TajoAdmin; -import org.apache.tajo.cli.tsql.TajoCli; - -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 "<command> [options]"; - } - - @Override - public String getDescription() { - return "execute a tajo amdin command."; - } -} http://git-wip-us.apache.org/repos/asf/tajo/blob/42d79cf5/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/TajoGetConfCommand.java ---------------------------------------------------------------------- diff --git a/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/TajoGetConfCommand.java b/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/TajoGetConfCommand.java deleted file mode 100644 index 5c7dd0e..0000000 --- a/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/TajoGetConfCommand.java +++ /dev/null @@ -1,58 +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.tsql.commands; - -import org.apache.tajo.cli.tsql.TajoCli; -import org.apache.tajo.cli.tools.TajoGetConf; - -public class TajoGetConfCommand extends TajoShellCommand { - private TajoGetConf getconf; - - public TajoGetConfCommand(TajoCli.TajoCliContext context) { - super(context); - getconf = new TajoGetConf(context.getConf(), context.getOutput(), context.getTajoClient()); - } - - @Override - public String getCommand() { - return "\\getconf"; - } - - @Override - public void invoke(String[] command) throws Exception { - try { - String[] getConfCommands = new String[command.length - 1]; - System.arraycopy(command, 1, getConfCommands, 0, getConfCommands.length); - - getconf.runCommand(getConfCommands); - } catch (Exception e) { - context.getOutput().println("ERROR: " + e.getMessage()); - } - } - - @Override - public String getUsage() { - return "<command> [options]"; - } - - @Override - public String getDescription() { - return "execute a tajo getconf command."; - } -} http://git-wip-us.apache.org/repos/asf/tajo/blob/42d79cf5/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/TajoHAAdminCommand.java ---------------------------------------------------------------------- diff --git a/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/TajoHAAdminCommand.java b/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/TajoHAAdminCommand.java deleted file mode 100644 index 9010ccb..0000000 --- a/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/TajoHAAdminCommand.java +++ /dev/null @@ -1,58 +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.tsql.commands; - -import org.apache.tajo.cli.tsql.TajoCli; -import org.apache.tajo.cli.tools.TajoHAAdmin; - -public class TajoHAAdminCommand extends TajoShellCommand { - private TajoHAAdmin haAdmin; - - public TajoHAAdminCommand(TajoCli.TajoCliContext context) { - super(context); - haAdmin = new TajoHAAdmin(context.getConf(), context.getOutput(), context.getTajoClient()); - } - - @Override - public String getCommand() { - return "\\haadmin"; - } - - @Override - public void invoke(String[] command) throws Exception { - try { - String[] haAdminCommands = new String[command.length - 1]; - System.arraycopy(command, 1, haAdminCommands, 0, haAdminCommands.length); - - haAdmin.runCommand(haAdminCommands); - } catch (Exception e) { - context.getOutput().println("ERROR: " + e.getMessage()); - } - } - - @Override - public String getUsage() { - return "<command> [options]"; - } - - @Override - public String getDescription() { - return "execute a tajo haAdminF command."; - } -} http://git-wip-us.apache.org/repos/asf/tajo/blob/42d79cf5/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/TajoShellCommand.java ---------------------------------------------------------------------- diff --git a/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/TajoShellCommand.java b/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/TajoShellCommand.java deleted file mode 100644 index 361f04d..0000000 --- a/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/TajoShellCommand.java +++ /dev/null @@ -1,129 +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.tsql.commands; - -import org.apache.tajo.cli.tsql.TajoCli; -import org.apache.tajo.client.TajoClient; -import org.apache.tajo.conf.TajoConf; - -public abstract class TajoShellCommand { - public abstract String getCommand(); - public String [] getAliases() { - return new String[] {}; - } - public abstract void invoke(String [] command) throws Exception; - public abstract String getUsage(); - public abstract String getDescription(); - public void printHelp() { - context.getOutput().print(getCommand()); - context.getOutput().print(" - "); - context.getOutput().println(getDescription()); - } - - protected TajoCli.TajoCliContext context; - protected TajoClient client; - protected int maxColumn; - - public TajoShellCommand(TajoCli.TajoCliContext context) { - maxColumn = context.getConf().getIntVar(TajoConf.ConfVars.$CLI_MAX_COLUMN); - this.context = context; - client = context.getTajoClient(); - } - - protected void println() { - context.getOutput().println(); - } - - protected void printLeft(String message, int columnWidth) { - int messageLength = message.length(); - - if(messageLength >= columnWidth) { - context.getOutput().print(message.substring(0, columnWidth - 1)); - } else { - context.getOutput().print(message); - print(' ', columnWidth - messageLength - 1); - } - } - - protected void printCenter(String message, int columnWidth, boolean warp) { - int messageLength = message.length(); - - if(messageLength > columnWidth) { - context.getOutput().print(message.substring(0, columnWidth - 1)); - } else { - int numPadding = (columnWidth - messageLength)/2; - - print(' ', numPadding); - context.getOutput().print(message); - print(' ', numPadding); - } - if(warp) { - println(); - } - } - - protected void printCenter(String message) { - printCenter(message, maxColumn, true); - } - - protected void print(char c, int count) { - for(int i = 0; i < count; i++) { - context.getOutput().print(c); - } - } - - protected int[] printHeader(String[] headers, float[] columnWidthRates) { - int[] columnWidths = new int[columnWidthRates.length]; - - int columnWidthSum = 0; - for(int i = 0; i < columnWidths.length; i++) { - columnWidths[i] = (int)(maxColumn * columnWidthRates[i]); - if(i > 0) { - columnWidthSum += columnWidths[i - 1]; - } - } - - columnWidths[columnWidths.length - 1] = maxColumn - columnWidthSum; - - String prefix = ""; - for(int i = 0; i < headers.length; i++) { - context.getOutput().print(prefix); - printLeft(" " + headers[i], columnWidths[i]); - prefix = "|"; - } - println(); - - int index = 0; - int printPos = columnWidths[index] - 1; - for(int i = 0; i < maxColumn; i++) { - if(i == printPos) { - if(index < columnWidths.length - 1) { - print('+', 1); - index++; - printPos += columnWidths[index]; - } - } else { - print('-', 1); - } - } - - println(); - return columnWidths; - } -} http://git-wip-us.apache.org/repos/asf/tajo/blob/42d79cf5/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/UnsetCommand.java ---------------------------------------------------------------------- diff --git a/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/UnsetCommand.java b/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/UnsetCommand.java deleted file mode 100644 index b540ca1..0000000 --- a/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/UnsetCommand.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.tsql.commands; - -import com.google.common.collect.Lists; -import org.apache.tajo.cli.tsql.TajoCli; - -public class UnsetCommand extends TajoShellCommand { - - public UnsetCommand(TajoCli.TajoCliContext context) { - super(context); - } - - @Override - public String getCommand() { - return "\\unset"; - } - - @Override - public void invoke(String[] cmd) throws Exception { - if (cmd.length == 2) { - client.unsetSessionVariables(Lists.newArrayList(cmd[1])); - } else { - context.getOutput().println("usage: \\unset NAME"); - } - } - - @Override - public String getUsage() { - return ""; - } - - @Override - public String getDescription() { - return "unset a session variable"; - } -} http://git-wip-us.apache.org/repos/asf/tajo/blob/42d79cf5/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/VersionCommand.java ---------------------------------------------------------------------- diff --git a/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/VersionCommand.java b/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/VersionCommand.java deleted file mode 100644 index 9c4aa25..0000000 --- a/tajo-client/src/main/java/org/apache/tajo/cli/tsql/commands/VersionCommand.java +++ /dev/null @@ -1,49 +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.tsql.commands; - -import org.apache.tajo.cli.tsql.TajoCli; -import org.apache.tajo.util.VersionInfo; - -public class VersionCommand extends TajoShellCommand { - - public VersionCommand(TajoCli.TajoCliContext context) { - super(context); - } - - @Override - public String getCommand() { - return "\\version"; - } - - @Override - public void invoke(String[] cmd) throws Exception { - context.getOutput().println(VersionInfo.getDisplayVersion()); - } - - @Override - public String getUsage() { - return ""; - } - - @Override - public String getDescription() { - return "show Tajo version"; - } -} http://git-wip-us.apache.org/repos/asf/tajo/blob/42d79cf5/tajo-client/src/main/java/org/apache/tajo/client/TajoHAClientUtil.java ---------------------------------------------------------------------- diff --git a/tajo-client/src/main/java/org/apache/tajo/client/TajoHAClientUtil.java b/tajo-client/src/main/java/org/apache/tajo/client/TajoHAClientUtil.java deleted file mode 100644 index 7267b10..0000000 --- a/tajo-client/src/main/java/org/apache/tajo/client/TajoHAClientUtil.java +++ /dev/null @@ -1,87 +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. - */ - -/** - * 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.client; - -import com.google.protobuf.ServiceException; -import org.apache.tajo.cli.tsql.TajoCli.TajoCliContext; -import org.apache.tajo.conf.TajoConf; -import org.apache.tajo.ha.HAServiceUtil; - -import java.io.IOException; - -public class TajoHAClientUtil { - /** - * In TajoMaster HA mode, if TajoCli can't connect existing active master, - * this should try to connect new active master. - * - * @param conf - * @param client - * @return - * @throws IOException - * @throws ServiceException - */ - public static TajoClient getTajoClient(TajoConf conf, TajoClient client) - throws IOException, ServiceException { - return getTajoClient(conf, client, null); - } - - public static TajoClient getTajoClient(TajoConf conf, TajoClient client, - TajoCliContext context) throws IOException, ServiceException { - - if (conf.getBoolVar(TajoConf.ConfVars.TAJO_MASTER_HA_ENABLE)) { - - if (!HAServiceUtil.isMasterAlive(conf.getVar( - TajoConf.ConfVars.TAJO_MASTER_CLIENT_RPC_ADDRESS), conf)) { - TajoClient tajoClient = null; - String baseDatabase = client.getBaseDatabase(); - conf.setVar(TajoConf.ConfVars.TAJO_MASTER_CLIENT_RPC_ADDRESS, - HAServiceUtil.getMasterClientName(conf)); - client.close(); - tajoClient = new TajoClientImpl(conf, baseDatabase); - - if (context != null && context.getCurrentDatabase() != null) { - tajoClient.selectDatabase(context.getCurrentDatabase()); - } - return tajoClient; - } else { - return client; - } - } else { - return client; - } - } -} http://git-wip-us.apache.org/repos/asf/tajo/blob/42d79cf5/tajo-core/pom.xml ---------------------------------------------------------------------- diff --git a/tajo-core/pom.xml b/tajo-core/pom.xml index c713e09..ce9db73 100644 --- a/tajo-core/pom.xml +++ b/tajo-core/pom.xml @@ -269,6 +269,10 @@ </dependency> <dependency> <groupId>org.apache.tajo</groupId> + <artifactId>tajo-cli</artifactId> + </dependency> + <dependency> + <groupId>org.apache.tajo</groupId> <artifactId>tajo-jdbc</artifactId> </dependency> <dependency> http://git-wip-us.apache.org/repos/asf/tajo/blob/42d79cf5/tajo-core/src/main/java/org/apache/tajo/webapp/QueryExecutorServlet.java ---------------------------------------------------------------------- diff --git a/tajo-core/src/main/java/org/apache/tajo/webapp/QueryExecutorServlet.java b/tajo-core/src/main/java/org/apache/tajo/webapp/QueryExecutorServlet.java index da25fe6..3603b79 100644 --- a/tajo-core/src/main/java/org/apache/tajo/webapp/QueryExecutorServlet.java +++ b/tajo-core/src/main/java/org/apache/tajo/webapp/QueryExecutorServlet.java @@ -293,8 +293,6 @@ public class QueryExecutorServlet extends HttpServlet { public void run() { startTime = System.currentTimeMillis(); try { - tajoClient = TajoHAClientUtil.getTajoClient(tajoConf, tajoClient); - if (!tajoClient.getCurrentDatabase().equals(database)) tajoClient.selectDatabase(database); http://git-wip-us.apache.org/repos/asf/tajo/blob/42d79cf5/tajo-dist/pom.xml ---------------------------------------------------------------------- diff --git a/tajo-dist/pom.xml b/tajo-dist/pom.xml index 3df2681..2ddc517 100644 --- a/tajo-dist/pom.xml +++ b/tajo-dist/pom.xml @@ -133,6 +133,7 @@ run cp -r $ROOT/tajo-algebra/target/tajo-algebra-${project.version}/* . run cp -r $ROOT/tajo-plan/target/tajo-plan-${project.version}/* . run cp -r $ROOT/tajo-client/target/tajo-client-${project.version}/* . + run cp -r $ROOT/tajo-cli/target/tajo-cli-${project.version}/* . run cp -r $ROOT/tajo-catalog/target/tajo-catalog-${project.version}/* . run cp -r $ROOT/tajo-storage/target/tajo-storage-${project.version}/* . run cp -r $ROOT/tajo-pullserver/target/tajo-pullserver-${project.version}.jar . http://git-wip-us.apache.org/repos/asf/tajo/blob/42d79cf5/tajo-project/pom.xml ---------------------------------------------------------------------- diff --git a/tajo-project/pom.xml b/tajo-project/pom.xml index ad62bba..30f864c 100644 --- a/tajo-project/pom.xml +++ b/tajo-project/pom.xml @@ -773,6 +773,11 @@ </dependency> <dependency> <groupId>org.apache.tajo</groupId> + <artifactId>tajo-cli</artifactId> + <version>${tajo.version}</version> + </dependency> + <dependency> + <groupId>org.apache.tajo</groupId> <artifactId>tajo-jdbc</artifactId> <version>${tajo.version}</version> </dependency>
