Index: src/contrib/hbase/src/test/org/apache/hadoop/hbase/shell/TestHBaseShell.java =================================================================== --- src/contrib/hbase/src/test/org/apache/hadoop/hbase/shell/TestHBaseShell.java (revision 611544) +++ src/contrib/hbase/src/test/org/apache/hadoop/hbase/shell/TestHBaseShell.java (working copy) @@ -1,176 +0,0 @@ -/** - * Copyright 2007 The Apache Software Foundation - * - * 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.hadoop.hbase.shell; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.OutputStreamWriter; -import java.io.PrintStream; -import java.io.UnsupportedEncodingException; -import java.io.Writer; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.hadoop.hbase.HBaseAdmin; -import org.apache.hadoop.hbase.HBaseClusterTestCase; -import org.apache.hadoop.hbase.HConstants; -import org.apache.hadoop.hbase.HTableDescriptor; -import org.apache.hadoop.hbase.shell.generated.ParseException; -import org.apache.hadoop.hbase.shell.generated.Parser; -import org.apache.hadoop.io.Text; - -/** - * Tests for Hbase shell - */ -public class TestHBaseShell extends HBaseClusterTestCase { - - protected final Log LOG = LogFactory.getLog(this.getClass().getName()); - private ByteArrayOutputStream baos; - private HBaseAdmin admin; - - /** constructor */ - public TestHBaseShell() { - super(1 /*One region server only*/); - } - - /** {@inheritDoc} */ - @Override - public void setUp() throws Exception { - super.setUp(); - // Capture System.out so we can grep for stuff in it. Have to do it once - // only because ConsoleTable sets up STDOUT in a static initialization - this.baos = new ByteArrayOutputStream(); - System.setOut(new PrintStream(this.baos)); - this.admin = new HBaseAdmin(this.conf); - } - - /** - * Create and then drop a table. - * Tests also that I can use single or double quotes around table and - * column family names. - * @throws Exception - */ - public void testCreateDeleteTable() throws Exception { - final String tableName = getName(); - final String columnFamily = tableName; - // Create table - createTable("create table " + tableName + " (" + columnFamily + ");", - tableName, columnFamily); - // Try describe - runCommand("describe " + tableName + ";"); - // Try describe with single quotes - runCommand("describe '" + tableName + "';"); - // Try describe with double-quotes - runCommand("describe \"" + tableName + "\";"); - // Try dropping the table. - dropTable("drop table " + tableName + ";", tableName); - // Use double-quotes creating table. - final String dblQuoteSuffix = "DblQuote"; - final String dblQuotedTableName = tableName + dblQuoteSuffix; - createTable("create table \"" + dblQuotedTableName + "\" (" + - columnFamily + ");", dblQuotedTableName, columnFamily); - // Use single-quotes creating table. - final String sglQuoteSuffix = "SglQuote"; - final String snglQuotedTableName = tableName + sglQuoteSuffix; - createTable("create table '" + snglQuotedTableName + "' (" + - columnFamily + ");", snglQuotedTableName, columnFamily); - // Use double-quotes around columnfamily name. - final String dblQuotedColumnFamily = columnFamily + dblQuoteSuffix; - String tmpTableName = tableName + dblQuotedColumnFamily; - createTable("create table " + tmpTableName + " (\"" + - dblQuotedColumnFamily + "\");", tmpTableName, - dblQuotedColumnFamily); - // Use single-quotes around columnfamily name. - final String sglQuotedColumnFamily = columnFamily + sglQuoteSuffix; - tmpTableName = tableName + sglQuotedColumnFamily; - createTable("create table " + tmpTableName + " ('" + - sglQuotedColumnFamily + "');", tmpTableName, sglQuotedColumnFamily); - } - - /** - * @throws Exception - */ - public void testInsertSelectDelete() throws Exception { - final String tableName = getName(); - final String columnFamily = tableName; - createTable("create table " + tableName + " (" + columnFamily + ");", - tableName, columnFamily); - // TODO: Add asserts that inserts, selects and deletes worked. - runCommand("insert into " + tableName + " (" + columnFamily + - ") values ('" + columnFamily + "') where row='" + columnFamily + "';"); - // Insert with double-quotes on row. - runCommand("insert into " + tableName + " (" + columnFamily + - ") values ('" + columnFamily + "') where row=\"" + columnFamily + "\";"); - // Insert with double-quotes on row and value. - runCommand("insert into " + tableName + " (" + columnFamily + - ") values (\"" + columnFamily + "\") where row=\"" + columnFamily + - "\";"); - runCommand("select \"" + columnFamily + "\" from \"" + tableName + - "\" where row=\"" + columnFamily + "\";"); - runCommand("delete \"" + columnFamily + ":\" from \"" + tableName + - "\" where row=\"" + columnFamily + "\";"); - } - - private void createTable(final String cmdStr, final String tableName, - final String columnFamily) - throws ParseException, IOException { - // Run create command. - runCommand(cmdStr); - // Assert table was created. - assertTrue(this.admin.tableExists(new Text(tableName))); - HTableDescriptor [] tables = this.admin.listTables(); - HTableDescriptor td = null; - for (int i = 0; i < tables.length; i++) { - if (tableName.equals(tables[i].getName().toString())) { - td = tables[i]; - } - } - assertNotNull(td); - assertTrue(td.hasFamily(new Text(columnFamily + ":"))); - } - - private void dropTable(final String cmdStr, final String tableName) - throws ParseException, IOException { - runCommand(cmdStr); - // Assert its gone - HTableDescriptor [] tables = this.admin.listTables(); - for (int i = 0; i < tables.length; i++) { - assertNotSame(tableName, tables[i].getName().toString()); - } - } - - private ReturnMsg runCommand(final String cmdStr) - throws ParseException, UnsupportedEncodingException { - LOG.info("Running command: " + cmdStr); - Writer out = new OutputStreamWriter(System.out, "UTF-8"); - TableFormatterFactory tff = new TableFormatterFactory(out, this.conf); - Parser parser = new Parser(cmdStr, out, tff.get()); - Command cmd = parser.terminatedCommand(); - ReturnMsg rm = cmd.execute(this.conf); - dumpStdout(); - return rm; - } - - private void dumpStdout() throws UnsupportedEncodingException { - LOG.info("STDOUT: " + - new String(this.baos.toByteArray(), HConstants.UTF8_ENCODING)); - this.baos.reset(); - } -} \ No newline at end of file Index: src/contrib/hbase/src/test/org/apache/hadoop/hbase/hql/TestHQL.java =================================================================== --- src/contrib/hbase/src/test/org/apache/hadoop/hbase/hql/TestHQL.java (revision 0) +++ src/contrib/hbase/src/test/org/apache/hadoop/hbase/hql/TestHQL.java (revision 0) @@ -0,0 +1,176 @@ +/** + * Copyright 2007 The Apache Software Foundation + * + * 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.hadoop.hbase.hql; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.io.PrintStream; +import java.io.UnsupportedEncodingException; +import java.io.Writer; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.hadoop.hbase.HBaseAdmin; +import org.apache.hadoop.hbase.HBaseClusterTestCase; +import org.apache.hadoop.hbase.HConstants; +import org.apache.hadoop.hbase.HTableDescriptor; +import org.apache.hadoop.hbase.hql.generated.ParseException; +import org.apache.hadoop.hbase.hql.generated.HQLParser; +import org.apache.hadoop.io.Text; + +/** + * Tests for HQL + */ +public class TestHQL extends HBaseClusterTestCase { + + protected final Log LOG = LogFactory.getLog(this.getClass().getName()); + private ByteArrayOutputStream baos; + private HBaseAdmin admin; + + /** constructor */ + public TestHQL() { + super(1 /*One region server only*/); + } + + /** {@inheritDoc} */ + @Override + public void setUp() throws Exception { + super.setUp(); + // Capture System.out so we can grep for stuff in it. Have to do it once + // only because ConsoleTable sets up STDOUT in a static initialization + this.baos = new ByteArrayOutputStream(); + System.setOut(new PrintStream(this.baos)); + this.admin = new HBaseAdmin(this.conf); + } + + /** + * Create and then drop a table. + * Tests also that I can use single or double quotes around table and + * column family names. + * @throws Exception + */ + public void testCreateDeleteTable() throws Exception { + final String tableName = getName(); + final String columnFamily = tableName; + // Create table + createTable("create table " + tableName + " (" + columnFamily + ");", + tableName, columnFamily); + // Try describe + runCommand("describe " + tableName + ";"); + // Try describe with single quotes + runCommand("describe '" + tableName + "';"); + // Try describe with double-quotes + runCommand("describe \"" + tableName + "\";"); + // Try dropping the table. + dropTable("drop table " + tableName + ";", tableName); + // Use double-quotes creating table. + final String dblQuoteSuffix = "DblQuote"; + final String dblQuotedTableName = tableName + dblQuoteSuffix; + createTable("create table \"" + dblQuotedTableName + "\" (" + + columnFamily + ");", dblQuotedTableName, columnFamily); + // Use single-quotes creating table. + final String sglQuoteSuffix = "SglQuote"; + final String snglQuotedTableName = tableName + sglQuoteSuffix; + createTable("create table '" + snglQuotedTableName + "' (" + + columnFamily + ");", snglQuotedTableName, columnFamily); + // Use double-quotes around columnfamily name. + final String dblQuotedColumnFamily = columnFamily + dblQuoteSuffix; + String tmpTableName = tableName + dblQuotedColumnFamily; + createTable("create table " + tmpTableName + " (\"" + + dblQuotedColumnFamily + "\");", tmpTableName, + dblQuotedColumnFamily); + // Use single-quotes around columnfamily name. + final String sglQuotedColumnFamily = columnFamily + sglQuoteSuffix; + tmpTableName = tableName + sglQuotedColumnFamily; + createTable("create table " + tmpTableName + " ('" + + sglQuotedColumnFamily + "');", tmpTableName, sglQuotedColumnFamily); + } + + /** + * @throws Exception + */ + public void testInsertSelectDelete() throws Exception { + final String tableName = getName(); + final String columnFamily = tableName; + createTable("create table " + tableName + " (" + columnFamily + ");", + tableName, columnFamily); + // TODO: Add asserts that inserts, selects and deletes worked. + runCommand("insert into " + tableName + " (" + columnFamily + + ") values ('" + columnFamily + "') where row='" + columnFamily + "';"); + // Insert with double-quotes on row. + runCommand("insert into " + tableName + " (" + columnFamily + + ") values ('" + columnFamily + "') where row=\"" + columnFamily + "\";"); + // Insert with double-quotes on row and value. + runCommand("insert into " + tableName + " (" + columnFamily + + ") values (\"" + columnFamily + "\") where row=\"" + columnFamily + + "\";"); + runCommand("select \"" + columnFamily + "\" from \"" + tableName + + "\" where row=\"" + columnFamily + "\";"); + runCommand("delete \"" + columnFamily + ":\" from \"" + tableName + + "\" where row=\"" + columnFamily + "\";"); + } + + private void createTable(final String cmdStr, final String tableName, + final String columnFamily) + throws ParseException, IOException { + // Run create command. + runCommand(cmdStr); + // Assert table was created. + assertTrue(this.admin.tableExists(new Text(tableName))); + HTableDescriptor [] tables = this.admin.listTables(); + HTableDescriptor td = null; + for (int i = 0; i < tables.length; i++) { + if (tableName.equals(tables[i].getName().toString())) { + td = tables[i]; + } + } + assertNotNull(td); + assertTrue(td.hasFamily(new Text(columnFamily + ":"))); + } + + private void dropTable(final String cmdStr, final String tableName) + throws ParseException, IOException { + runCommand(cmdStr); + // Assert its gone + HTableDescriptor [] tables = this.admin.listTables(); + for (int i = 0; i < tables.length; i++) { + assertNotSame(tableName, tables[i].getName().toString()); + } + } + + private ReturnMsg runCommand(final String cmdStr) + throws ParseException, UnsupportedEncodingException { + LOG.info("Running command: " + cmdStr); + Writer out = new OutputStreamWriter(System.out, "UTF-8"); + TableFormatterFactory tff = new TableFormatterFactory(out, this.conf); + HQLParser parser = new HQLParser(cmdStr, out, tff.get()); + Command cmd = parser.terminatedCommand(); + ReturnMsg rm = cmd.execute(this.conf); + dumpStdout(); + return rm; + } + + private void dumpStdout() throws UnsupportedEncodingException { + LOG.info("STDOUT: " + + new String(this.baos.toByteArray(), HConstants.UTF8_ENCODING)); + this.baos.reset(); + } +} \ No newline at end of file Index: src/contrib/hbase/src/java/org/apache/hadoop/hbase/Shell.java =================================================================== --- src/contrib/hbase/src/java/org/apache/hadoop/hbase/Shell.java (revision 611544) +++ src/contrib/hbase/src/java/org/apache/hadoop/hbase/Shell.java (working copy) @@ -25,16 +25,13 @@ import jline.ConsoleReader; -import org.apache.hadoop.hbase.shell.Command; -import org.apache.hadoop.hbase.shell.HelpCommand; -import org.apache.hadoop.hbase.shell.ReturnMsg; -import org.apache.hadoop.hbase.shell.ShellSecurityManager; -import org.apache.hadoop.hbase.shell.TableFormatter; -import org.apache.hadoop.hbase.shell.TableFormatterFactory; -import org.apache.hadoop.hbase.shell.formatter.HtmlTableFormatter; -import org.apache.hadoop.hbase.shell.generated.ParseException; -import org.apache.hadoop.hbase.shell.generated.Parser; -import org.apache.hadoop.hbase.shell.generated.TokenMgrError; +import org.apache.hadoop.hbase.hql.HQLClient; +import org.apache.hadoop.hbase.hql.HelpCommand; +import org.apache.hadoop.hbase.hql.ReturnMsg; +import org.apache.hadoop.hbase.hql.HQLSecurityManager; +import org.apache.hadoop.hbase.hql.TableFormatter; +import org.apache.hadoop.hbase.hql.TableFormatterFactory; +import org.apache.hadoop.hbase.hql.formatter.HtmlTableFormatter; /** * An hbase shell. @@ -90,7 +87,7 @@ HBaseConfiguration conf = new HBaseConfiguration(); ConsoleReader reader = new ConsoleReader(); - System.setSecurityManager(new ShellSecurityManager()); + System.setSecurityManager(new HQLSecurityManager()); reader.setBellEnabled(conf.getBoolean("hbaseshell.jline.bell.enabled", DEFAULT_BELL_ENABLED)); Writer out = new OutputStreamWriter(System.out, "UTF-8"); @@ -112,23 +109,10 @@ if (isEndOfCommand(extendedLine)) { queryStr.append(" " + extendedLine); long start = System.currentTimeMillis(); - Parser parser = new Parser(queryStr.toString(), out, tableFormater); - ReturnMsg rs = null; - try { - Command cmd = parser.terminatedCommand(); - if (cmd != null) { - rs = cmd.execute(conf); - } - } catch (ParseException pe) { - String[] msg = pe.getMessage().split("[\n]"); - System.out.println("Syntax error : Type 'help;' for usage.\nMessage : " - + msg[0]); - } catch (TokenMgrError te) { - String[] msg = te.getMessage().split("[\n]"); - System.out.println("Lexical error : Type 'help;' for usage.\nMessage : " - + msg[0]); - } + HQLClient hql = new HQLClient(conf, MASTER_ADDRESS, out, tableFormater); + ReturnMsg rs = hql.executeQuery(queryStr.toString()); + long end = System.currentTimeMillis(); if (rs != null && rs.getType() > -1) System.out.println(rs.getMsg() Index: src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/DeleteCommand.java =================================================================== --- src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/DeleteCommand.java (revision 611544) +++ src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/DeleteCommand.java (working copy) @@ -1,131 +0,0 @@ -/** - * Copyright 2007 The Apache Software Foundation - * - * 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.hadoop.hbase.shell; - -import java.io.IOException; -import java.io.Writer; -import java.util.ArrayList; -import java.util.List; - -import org.apache.hadoop.hbase.HBaseAdmin; -import org.apache.hadoop.hbase.HBaseConfiguration; -import org.apache.hadoop.hbase.HConnection; -import org.apache.hadoop.hbase.HConnectionManager; -import org.apache.hadoop.hbase.HTable; -import org.apache.hadoop.io.Text; - -/** - * Deletes values from tables. - */ -public class DeleteCommand extends BasicCommand { - public DeleteCommand(Writer o) { - super(o); - } - - private Text tableName; - private Text rowKey; - private List columnList; - - public ReturnMsg execute(HBaseConfiguration conf) { - if (columnList == null) { - throw new IllegalArgumentException("Column list is null"); - } - try { - HConnection conn = HConnectionManager.getConnection(conf); - if (!conn.tableExists(tableName)) { - return new ReturnMsg(0, "'" + tableName + "'" + TABLE_NOT_FOUND); - } - - HBaseAdmin admin = new HBaseAdmin(conf); - HTable hTable = new HTable(conf, tableName); - - if (rowKey != null) { - long lockID = hTable.startUpdate(rowKey); - for (Text column : getColumnList(admin, hTable)) { - hTable.delete(lockID, new Text(column)); - } - hTable.commit(lockID); - } else { - admin.disableTable(tableName); - for (Text column : getColumnList(admin, hTable)) { - admin.deleteColumn(tableName, new Text(column)); - } - admin.enableTable(tableName); - } - - return new ReturnMsg(1, "Column(s) deleted successfully."); - } catch (IOException e) { - String[] msg = e.getMessage().split("[\n]"); - return new ReturnMsg(0, msg[0]); - } - } - - public void setTable(String tableName) { - this.tableName = new Text(tableName); - } - - public void setRow(String row) { - this.rowKey = new Text(row); - } - - /** - * Sets the column list. - * - * @param columnList - */ - public void setColumnList(List columnList) { - this.columnList = columnList; - } - - /** - * @param admin - * @param hTable - * @return return the column list. - */ - public Text[] getColumnList(HBaseAdmin admin, HTable hTable) { - Text[] columns = null; - try { - if (columnList.contains("*")) { - columns = hTable.getRow(new Text(this.rowKey)).keySet().toArray( - new Text[] {}); - } else { - List tmpList = new ArrayList(); - for (int i = 0; i < columnList.size(); i++) { - Text column = null; - if (columnList.get(i).contains(":")) - column = new Text(columnList.get(i)); - else - column = new Text(columnList.get(i) + ":"); - - tmpList.add(column); - } - columns = tmpList.toArray(new Text[] {}); - } - } catch (IOException e) { - e.printStackTrace(); - } - return columns; - } - - @Override - public CommandType getCommandType() { - return CommandType.DELETE; - } -} Index: src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/CreateCommand.java =================================================================== --- src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/CreateCommand.java (revision 611544) +++ src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/CreateCommand.java (working copy) @@ -1,93 +0,0 @@ -/** - * Copyright 2007 The Apache Software Foundation - * - * 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.hadoop.hbase.shell; - -import java.io.Writer; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - -import org.apache.hadoop.hbase.HBaseAdmin; -import org.apache.hadoop.hbase.HBaseConfiguration; -import org.apache.hadoop.hbase.HColumnDescriptor; -import org.apache.hadoop.hbase.HConnection; -import org.apache.hadoop.hbase.HConnectionManager; -import org.apache.hadoop.hbase.HTableDescriptor; -import org.apache.hadoop.io.Text; - -/** - * Creates tables. - */ -public class CreateCommand extends SchemaModificationCommand { - private Text tableName; - private Map> columnSpecMap = new HashMap>(); - - public CreateCommand(Writer o) { - super(o); - } - - public ReturnMsg execute(HBaseConfiguration conf) { - try { - HConnection conn = HConnectionManager.getConnection(conf); - if (conn.tableExists(tableName)) { - return new ReturnMsg(0, "'" + tableName + "' table already exist."); - } - - HBaseAdmin admin = new HBaseAdmin(conf); - HTableDescriptor tableDesc = new HTableDescriptor(tableName.toString()); - HColumnDescriptor columnDesc = null; - Set columns = columnSpecMap.keySet(); - for (String column : columns) { - columnDesc = getColumnDescriptor(column, columnSpecMap.get(column)); - tableDesc.addFamily(columnDesc); - } - - println("Creating table... Please wait."); - - admin.createTable(tableDesc); - return new ReturnMsg(0, "Table created successfully."); - } catch (Exception e) { - return new ReturnMsg(0, extractErrMsg(e)); - } - } - - /** - * Sets the table to be created. - * - * @param tableName Table to be created - */ - public void setTable(String tableName) { - this.tableName = new Text(tableName); - } - - /** - * Adds a column specification. - * - * @param columnSpec Column specification - */ - public void addColumnSpec(String column, Map columnSpec) { - columnSpecMap.put(column, columnSpec); - } - - @Override - public CommandType getCommandType() { - return CommandType.DDL; - } -} Index: src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/DisableCommand.java =================================================================== --- src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/DisableCommand.java (revision 611544) +++ src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/DisableCommand.java (working copy) @@ -1,68 +0,0 @@ -/** - * Copyright 2007 The Apache Software Foundation - * - * 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.hadoop.hbase.shell; - -import java.io.IOException; -import java.io.Writer; - -import org.apache.hadoop.hbase.HBaseAdmin; -import org.apache.hadoop.hbase.HBaseConfiguration; -import org.apache.hadoop.hbase.HConnection; -import org.apache.hadoop.hbase.HConnectionManager; -import org.apache.hadoop.io.Text; - -/** - * Disables tables. - */ -public class DisableCommand extends BasicCommand { - private String tableName; - - public DisableCommand(Writer o) { - super(o); - } - - public ReturnMsg execute(HBaseConfiguration conf) { - assert tableName != null; - - try { - HConnection conn = HConnectionManager.getConnection(conf); - if (!conn.tableExists(new Text(tableName))) { - return new ReturnMsg(0, "'" + tableName + "'" + TABLE_NOT_FOUND); - } - - HBaseAdmin admin = new HBaseAdmin(conf); - admin.disableTable(new Text(tableName)); - - return new ReturnMsg(1, "Table disabled successfully."); - } catch (IOException e) { - String[] msg = e.getMessage().split("[\n]"); - return new ReturnMsg(0, msg[0]); - } - } - - public void setTable(String table) { - this.tableName = table; - } - - @Override - public CommandType getCommandType() { - return CommandType.DDL; - } -} Index: src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/TableFormatterFactory.java =================================================================== --- src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/TableFormatterFactory.java (revision 611544) +++ src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/TableFormatterFactory.java (working copy) @@ -1,83 +0,0 @@ -/** - * Copyright 2007 The Apache Software Foundation - * - * 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.hadoop.hbase.shell; - -import java.io.Writer; -import java.lang.reflect.Constructor; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.shell.formatter.AsciiTableFormatter; - -/** - * Table formatter. Specify formatter by setting "hbaseshell.formatter" property - * in hbase-site.xml or by setting system property - * hbaseshell.formatter. System property setting prevails over - * all other configurations. Outputs UTF-8 encoded Strings even if original data - * is binary. On static initialization, changes System.out to be a UTF-8 output - * stream. . - *

- * TODO: Mysql has --skip-column-names and --silent which inserts a tab as - * separator. Also has --html and --xml. - *

- * To use the html formatter, currently set HBASE_OPTS as in: - * $ HBASE_OPTS="-Dhbaseshell.formatter=org.apache.hadoop.hbase.shell.formatter.HtmlTableFormatter" ./bin/hbase shell - *

- */ -public class TableFormatterFactory { - private static final Log LOG = LogFactory.getLog(TableFormatterFactory.class - .getName()); - private static final String FORMATTER_KEY = "hbaseshell.formatter"; - private final TableFormatter formatter; - - /** - * Not instantiable - */ - @SuppressWarnings( { "unchecked", "unused" }) - private TableFormatterFactory() { - this(null, null); - } - - @SuppressWarnings("unchecked") - public TableFormatterFactory(final Writer out, final Configuration c) { - String className = System.getProperty(FORMATTER_KEY); - if (className == null) { - className = c.get(FORMATTER_KEY, AsciiTableFormatter.class.getName()); - } - LOG.debug("Table formatter class: " + className); - try { - Class clazz = (Class) Class - .forName(className); - Constructor constructor = clazz.getConstructor(Writer.class); - this.formatter = (TableFormatter) constructor.newInstance(out); - } catch (Exception e) { - throw new RuntimeException("Failed instantiation of " + className, e); - } - } - - /** - * @return The table formatter instance - */ - @SuppressWarnings("unchecked") - public TableFormatter get() { - return this.formatter; - } -} Index: src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/InsertCommand.java =================================================================== --- src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/InsertCommand.java (revision 611544) +++ src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/InsertCommand.java (working copy) @@ -1,120 +0,0 @@ -/** - * Copyright 2007 The Apache Software Foundation - * - * 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.hadoop.hbase.shell; - -import java.io.IOException; -import java.io.Writer; -import java.util.List; - -import org.apache.hadoop.hbase.HBaseConfiguration; -import org.apache.hadoop.hbase.HConnection; -import org.apache.hadoop.hbase.HConnectionManager; -import org.apache.hadoop.hbase.HTable; -import org.apache.hadoop.io.Text; - -/** - * Inserts values into tables. - */ -public class InsertCommand extends BasicCommand { - private Text tableName; - private List columnfamilies; - private List values; - private String rowKey; - private String timestamp = null; - - public InsertCommand(Writer o) { - super(o); - } - - public ReturnMsg execute(HBaseConfiguration conf) { - if (tableName == null || values == null || rowKey == null) - return new ReturnMsg(0, "Syntax error : Please check 'Insert' syntax."); - - HConnection conn = HConnectionManager.getConnection(conf); - if (!conn.tableExists(tableName)) { - return new ReturnMsg(0, "'" + tableName + "'" + TABLE_NOT_FOUND); - } - - if (columnfamilies.size() != values.size()) - return new ReturnMsg(0, - "Mismatch between values list and columnfamilies list."); - - try { - HTable table = new HTable(conf, tableName); - long lockId = table.startUpdate(getRow()); - - for (int i = 0; i < values.size(); i++) { - Text column = null; - if (getColumn(i).toString().contains(":")) - column = getColumn(i); - else - column = new Text(getColumn(i) + ":"); - table.put(lockId, column, getValue(i)); - } - - if(timestamp != null) - table.commit(lockId, Long.parseLong(timestamp)); - else - table.commit(lockId); - - return new ReturnMsg(1, "1 row inserted successfully."); - } catch (IOException e) { - String[] msg = e.getMessage().split("[\n]"); - return new ReturnMsg(0, msg[0]); - } - } - - public void setTable(String table) { - this.tableName = new Text(table); - } - - public void setColumnfamilies(List columnfamilies) { - this.columnfamilies = columnfamilies; - } - - public void setValues(List values) { - this.values = values; - } - - public void setRow(String row) { - this.rowKey = row; - } - - public Text getRow() { - return new Text(this.rowKey); - } - - public Text getColumn(int i) { - return new Text(this.columnfamilies.get(i)); - } - - public byte[] getValue(int i) { - return this.values.get(i).getBytes(); - } - - public void setTimestamp(String timestamp) { - this.timestamp = timestamp; - } - - @Override - public CommandType getCommandType() { - return CommandType.INSERT; - } -} Index: src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/DropCommand.java =================================================================== --- src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/DropCommand.java (revision 611544) +++ src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/DropCommand.java (working copy) @@ -1,80 +0,0 @@ -/** - * Copyright 2007 The Apache Software Foundation - * - * 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.hadoop.hbase.shell; - -import java.io.IOException; -import java.io.Writer; -import java.util.List; - -import org.apache.hadoop.hbase.HBaseAdmin; -import org.apache.hadoop.hbase.HBaseConfiguration; -import org.apache.hadoop.hbase.HConnection; -import org.apache.hadoop.hbase.HConnectionManager; -import org.apache.hadoop.io.Text; - -/** - * Drops tables. - */ -public class DropCommand extends BasicCommand { - private List tableList; - - public DropCommand(Writer o) { - super(o); - } - - public ReturnMsg execute(HBaseConfiguration conf) { - if (tableList == null) { - throw new IllegalArgumentException("List of tables is null."); - } - - try { - HBaseAdmin admin = new HBaseAdmin(conf); - HConnection conn = HConnectionManager.getConnection(conf); - - int count = 0; - for (String table : tableList) { - if (!conn.tableExists(new Text(table))) { - println("'" + table + "' table not found."); - } else { - println("Dropping " + table + "... Please wait."); - admin.deleteTable(new Text(table)); - count++; - } - } - - if (count > 0) { - return new ReturnMsg(1, count + " table(s) dropped successfully."); - } else { - return new ReturnMsg(0, count + " table(s) dropped."); - } - } catch (IOException e) { - return new ReturnMsg(0, extractErrMsg(e)); - } - } - - public void setTableList(List tableList) { - this.tableList = tableList; - } - - @Override - public CommandType getCommandType() { - return CommandType.DDL; - } -} Index: src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/AlterCommand.java =================================================================== --- src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/AlterCommand.java (revision 611544) +++ src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/AlterCommand.java (working copy) @@ -1,248 +0,0 @@ -/** - * Copyright 2007 The Apache Software Foundation - * - * 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.hadoop.hbase.shell; - -import java.io.IOException; -import java.io.Writer; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - -import org.apache.hadoop.hbase.HBaseAdmin; -import org.apache.hadoop.hbase.HBaseConfiguration; -import org.apache.hadoop.hbase.HColumnDescriptor; -import org.apache.hadoop.hbase.HTableDescriptor; -import org.apache.hadoop.hbase.HConnection; -import org.apache.hadoop.hbase.HConnectionManager; -import org.apache.hadoop.io.Text; - -import org.apache.hadoop.hbase.BloomFilterDescriptor; -import org.apache.hadoop.hbase.BloomFilterDescriptor.BloomFilterType; - -/** - * Alters tables. - */ -public class AlterCommand extends SchemaModificationCommand { - public enum OperationType { - ADD, DROP, CHANGE, NOOP - } - - private OperationType operationType = OperationType.NOOP; - private Map> columnSpecMap = new HashMap>(); - private String tableName; - private String column; // column to be dropped - - public AlterCommand(Writer o) { - super(o); - } - - @SuppressWarnings("unchecked") - public ReturnMsg execute(HBaseConfiguration conf) { - try { - HConnection conn = HConnectionManager.getConnection(conf); - if (!conn.tableExists(new Text(this.tableName))) { - return new ReturnMsg(0, "'" + this.tableName + "'" + TABLE_NOT_FOUND); - } - - HBaseAdmin admin = new HBaseAdmin(conf); - Set columns = null; - HColumnDescriptor columnDesc = null; - switch (operationType) { - case ADD: - disableTable(admin, tableName); - columns = columnSpecMap.keySet(); - for (String c : columns) { - columnDesc = getColumnDescriptor(c, columnSpecMap.get(c)); - println("Adding " + c + " to " + tableName + "... Please wait."); - admin.addColumn(new Text(tableName), columnDesc); - } - enableTable(admin, tableName); - break; - case DROP: - disableTable(admin, tableName); - println("Dropping " + column + " from " + tableName + "... Please wait."); - column = appendDelimiter(column); - admin.deleteColumn(new Text(tableName), new Text(column)); - enableTable(admin, tableName); - break; - case CHANGE: - disableTable(admin, tableName); - - Map.Entry> columnEntry = (Map.Entry>) columnSpecMap - .entrySet().toArray()[0]; - - // add the : if there isn't one - Text columnName = new Text( - columnEntry.getKey().endsWith(":") ? columnEntry.getKey() - : columnEntry.getKey() + ":"); - - // get the table descriptor so we can get the old column descriptor - HTableDescriptor tDesc = getTableDescByName(admin, tableName); - HColumnDescriptor oldColumnDesc = tDesc.families().get(columnName); - - // combine the options specified in the shell with the options - // from the exiting descriptor to produce the new descriptor - columnDesc = getColumnDescriptor(columnName.toString(), columnEntry - .getValue(), oldColumnDesc); - - // send the changes out to the master - admin.modifyColumn(new Text(tableName), columnName, columnDesc); - - enableTable(admin, tableName); - break; - case NOOP: - return new ReturnMsg(0, "Invalid operation type."); - } - return new ReturnMsg(0, "Table altered successfully."); - } catch (Exception e) { - return new ReturnMsg(0, extractErrMsg(e)); - } - } - - private void disableTable(HBaseAdmin admin, String t) throws IOException { - println("Disabling " + t + "... Please wait."); - admin.disableTable(new Text(t)); - } - - private void enableTable(HBaseAdmin admin, String t) throws IOException { - println("Enabling " + t + "... Please wait."); - admin.enableTable(new Text(t)); - } - - /** - * Sets the table to be altered. - * - * @param t Table to be altered. - */ - public void setTable(String t) { - this.tableName = t; - } - - /** - * Adds a column specification. - * - * @param columnSpec Column specification - */ - public void addColumnSpec(String c, Map columnSpec) { - columnSpecMap.put(c, columnSpec); - } - - /** - * Sets the column to be dropped. Only applicable to the DROP operation. - * - * @param c Column to be dropped. - */ - public void setColumn(String c) { - this.column = c; - } - - /** - * Sets the operation type of this alteration. - * - * @param operationType Operation type - * @see OperationType - */ - public void setOperationType(OperationType operationType) { - this.operationType = operationType; - } - - @Override - public CommandType getCommandType() { - return CommandType.DDL; - } - - private HTableDescriptor getTableDescByName(HBaseAdmin admin, String tableName) - throws IOException { - HTableDescriptor[] tables = admin.listTables(); - for (HTableDescriptor tDesc : tables) { - if (tDesc.getName().toString().equals(tableName)) { - return tDesc; - } - } - return null; - } - - /** - * Given a column name, column spec, and original descriptor, returns an - * instance of HColumnDescriptor representing the column spec, with empty - * values drawn from the original as defaults - */ - protected HColumnDescriptor getColumnDescriptor(String column, - Map columnSpec, HColumnDescriptor original) - throws IllegalArgumentException { - initOptions(original); - - Set specs = columnSpec.keySet(); - for (String spec : specs) { - spec = spec.toUpperCase(); - - if (spec.equals("MAX_VERSIONS")) { - maxVersions = (Integer) columnSpec.get(spec); - } else if (spec.equals("MAX_LENGTH")) { - maxLength = (Integer) columnSpec.get(spec); - } else if (spec.equals("COMPRESSION")) { - compression = HColumnDescriptor.CompressionType.valueOf(((String) columnSpec - .get(spec)).toUpperCase()); - } else if (spec.equals("IN_MEMORY")) { - inMemory = (Boolean) columnSpec.get(spec); - } else if (spec.equals("BLOOMFILTER")) { - bloomFilterType = BloomFilterType.valueOf(((String) columnSpec.get(spec)) - .toUpperCase()); - } else if (spec.equals("VECTOR_SIZE")) { - vectorSize = (Integer) columnSpec.get(spec); - } else if (spec.equals("NUM_HASH")) { - numHash = (Integer) columnSpec.get(spec); - } else if (spec.equals("NUM_ENTRIES")) { - numEntries = (Integer) columnSpec.get(spec); - } else { - throw new IllegalArgumentException("Invalid option: " + spec); - } - } - - // Now we gather all the specified options for this column. - if (bloomFilterType != null) { - if (specs.contains("NUM_ENTRIES")) { - bloomFilterDesc = new BloomFilterDescriptor(bloomFilterType, numEntries); - } else { - bloomFilterDesc = new BloomFilterDescriptor(bloomFilterType, vectorSize, - numHash); - } - } - - column = appendDelimiter(column); - - HColumnDescriptor columnDesc = new HColumnDescriptor(new Text(column), - maxVersions, compression, inMemory, maxLength, bloomFilterDesc); - - return columnDesc; - } - - private void initOptions(HColumnDescriptor original) { - if (original == null) { - initOptions(); - return; - } - maxVersions = original.getMaxVersions(); - maxLength = original.getMaxValueLength(); - compression = original.getCompression(); - inMemory = original.isInMemory(); - bloomFilterDesc = original.getBloomFilter(); - } -} Index: src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/CommandFactory.java =================================================================== --- src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/CommandFactory.java (revision 611544) +++ src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/CommandFactory.java (working copy) @@ -1,27 +0,0 @@ -/** - * Copyright 2007 The Apache Software Foundation - * - * 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.hadoop.hbase.shell; - -/** - * Parser uses command factories to create command. - */ -public interface CommandFactory { - Command getCommand(); -} \ No newline at end of file Index: src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/FsCommand.java =================================================================== --- src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/FsCommand.java (revision 611544) +++ src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/FsCommand.java (working copy) @@ -1,64 +0,0 @@ -/** - * Copyright 2007 The Apache Software Foundation - * - * 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.hadoop.hbase.shell; - -import java.io.Writer; -import java.util.List; - -import org.apache.hadoop.fs.FsShell; -import org.apache.hadoop.hbase.HBaseConfiguration; -import org.apache.hadoop.util.ToolRunner; - -/** - * Run hadoop filesystem commands. - */ -public class FsCommand extends BasicCommand { - private List query; - - public FsCommand(Writer o) { - super(o); - } - - public ReturnMsg execute(@SuppressWarnings("unused") - HBaseConfiguration conf) { - // This commmand will write the - FsShell shell = new FsShell(); - try { - ToolRunner.run(shell, getQuery()); - shell.close(); - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } - - public void setQuery(List query) { - this.query = query; - } - - private String[] getQuery() { - return query.toArray(new String[] {}); - } - - @Override - public CommandType getCommandType() { - return CommandType.SHELL; - } -} Index: src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/ExitCommand.java =================================================================== --- src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/ExitCommand.java (revision 611544) +++ src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/ExitCommand.java (working copy) @@ -1,44 +0,0 @@ -/** - * Copyright 2007 The Apache Software Foundation - * - * 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.hadoop.hbase.shell; - -import java.io.Writer; - -import org.apache.hadoop.hbase.HBaseConfiguration; -import org.apache.hadoop.hbase.Shell; - -public class ExitCommand extends BasicCommand { - public ExitCommand(Writer o) { - super(o); - } - - public ReturnMsg execute(@SuppressWarnings("unused") - HBaseConfiguration conf) { - // TOD: Is this the best way to exit? Would be a problem if shell is run - // inside another program -- St.Ack 09/11/2007 - System.exit(Shell.EXIT_FLAG); - return null; - } - - @Override - public CommandType getCommandType() { - return CommandType.SHELL; - } -} Index: src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/TableFormatter.java =================================================================== --- src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/TableFormatter.java (revision 611544) +++ src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/TableFormatter.java (working copy) @@ -1,63 +0,0 @@ -/** - * Copyright 2007 The Apache Software Foundation - * - * 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.hadoop.hbase.shell; - -import java.io.IOException; -import java.io.Writer; - -import org.apache.hadoop.hbase.shell.formatter.AsciiTableFormatter; - -/** - * Interface implemented by table formatters outputting select results. - * Implementations must have a constructor that takes a Writer. - * - * @see AsciiTableFormatter - */ -public interface TableFormatter { - /** - * Output header. - * - * @param titles Titles to emit. - * @throws IOException - */ - public void header(final String[] titles) throws IOException; - - /** - * Output footer. - * - * @throws IOException - */ - public void footer() throws IOException; - - /** - * Output a row. - * - * @param cells - * @throws IOException - */ - public void row(final String[] cells) throws IOException; - - /** - * @return Output stream being used (This is in interface to enforce fact that - * formatters use Writers -- that they operate on character streams - * rather than on byte streams). - */ - public Writer getOut(); -} Index: src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/JarCommand.java =================================================================== --- src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/JarCommand.java (revision 611544) +++ src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/JarCommand.java (working copy) @@ -1,156 +0,0 @@ -/** - * Copyright 2007 The Apache Software Foundation - * - * 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.hadoop.hbase.shell; - -import java.io.File; -import java.io.IOException; -import java.io.Writer; -import java.lang.reflect.Array; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.jar.JarFile; -import java.util.jar.Manifest; - -import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.fs.FileUtil; -import org.apache.hadoop.hbase.HBaseConfiguration; -import org.apache.hadoop.util.RunJar; - -/** - * Run hadoop jar commands. - */ -public class JarCommand extends BasicCommand { - private List query; - - public JarCommand(Writer o) { - super(o); - } - - @SuppressWarnings("deprecation") - public ReturnMsg execute(@SuppressWarnings("unused") - HBaseConfiguration conf) { - - try { - String[] args = getQuery(); - String usage = "JAR jarFile [mainClass] args...;\n"; - - if (args.length < 1) { - return new ReturnMsg(0, usage); - } - - int firstArg = 0; - String fileName = args[firstArg++]; - File file = new File(fileName); - String mainClassName = null; - - JarFile jarFile; - try { - jarFile = new JarFile(fileName); - } catch (IOException io) { - throw new IOException("Error opening job jar: " + fileName + "\n") - .initCause(io); - } - - Manifest manifest = jarFile.getManifest(); - if (manifest != null) { - mainClassName = manifest.getMainAttributes().getValue("Main-Class"); - } - jarFile.close(); - - if (mainClassName == null) { - if (args.length < 2) { - return new ReturnMsg(0, usage); - } - mainClassName = args[firstArg++]; - } - mainClassName = mainClassName.replaceAll("/", "."); - - File tmpDir = new File(new Configuration().get("hadoop.tmp.dir")); - tmpDir.mkdirs(); - if (!tmpDir.isDirectory()) { - return new ReturnMsg(0, "Mkdirs failed to create " + tmpDir + "\n"); - } - final File workDir = File.createTempFile("hadoop-unjar", "", tmpDir); - workDir.delete(); - workDir.mkdirs(); - if (!workDir.isDirectory()) { - return new ReturnMsg(0, "Mkdirs failed to create " + workDir + "\n"); - } - - Runtime.getRuntime().addShutdownHook(new Thread() { - public void run() { - try { - FileUtil.fullyDelete(workDir); - } catch (IOException e) { - e.printStackTrace(); - } - } - }); - - RunJar.unJar(file, workDir); - - ArrayList classPath = new ArrayList(); - classPath.add(new File(workDir + "/").toURL()); - classPath.add(file.toURL()); - classPath.add(new File(workDir, "classes/").toURL()); - File[] libs = new File(workDir, "lib").listFiles(); - if (libs != null) { - for (int i = 0; i < libs.length; i++) { - classPath.add(libs[i].toURL()); - } - } - ClassLoader loader = new URLClassLoader(classPath.toArray(new URL[0])); - - Thread.currentThread().setContextClassLoader(loader); - Class mainClass = Class.forName(mainClassName, true, loader); - Method main = mainClass.getMethod("main", new Class[] { Array.newInstance( - String.class, 0).getClass() }); - String[] newArgs = Arrays.asList(args).subList(firstArg, args.length) - .toArray(new String[0]); - try { - main.invoke(null, new Object[] { newArgs }); - } catch (InvocationTargetException e) { - throw e.getTargetException(); - } - } catch (Throwable e) { - e.printStackTrace(); - } - - return null; - } - - public void setQuery(List query) { - this.query = query; - } - - private String[] getQuery() { - return query.toArray(new String[] {}); - } - - @Override - public CommandType getCommandType() { - return CommandType.SHELL; - } -} Index: src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/DescCommand.java =================================================================== --- src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/DescCommand.java (revision 611544) +++ src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/DescCommand.java (working copy) @@ -1,90 +0,0 @@ -/** - * Copyright 2007 The Apache Software Foundation - * - * 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.hadoop.hbase.shell; - -import java.io.IOException; -import java.io.Writer; - -import org.apache.hadoop.hbase.HBaseConfiguration; -import org.apache.hadoop.hbase.HColumnDescriptor; -import org.apache.hadoop.hbase.HConnection; -import org.apache.hadoop.hbase.HConnectionManager; -import org.apache.hadoop.hbase.HTableDescriptor; -import org.apache.hadoop.io.Text; - -/** - * Prints information about tables. - */ -public class DescCommand extends BasicCommand { - private static final String[] HEADER = new String[] { "Column Family Descriptor" }; - private Text tableName; - private final TableFormatter formatter; - - // Not instantiable - @SuppressWarnings("unused") - private DescCommand() { - this(null, null); - } - - public DescCommand(final Writer o, final TableFormatter f) { - super(o); - this.formatter = f; - } - - public ReturnMsg execute(final HBaseConfiguration conf) { - if (tableName == null) - return new ReturnMsg(0, "Syntax error : Please check 'Describe' syntax."); - try { - HConnection conn = HConnectionManager.getConnection(conf); - if (!conn.tableExists(tableName)) { - return new ReturnMsg(0, "Table not found."); - } - HTableDescriptor[] tables = conn.listTables(); - HColumnDescriptor[] columns = null; - for (int i = 0; i < tables.length; i++) { - if (tables[i].getName().equals(tableName)) { - columns = tables[i].getFamilies().values().toArray( - new HColumnDescriptor[] {}); - break; - } - } - formatter.header(HEADER); - // Do a toString on the HColumnDescriptors - String[] columnStrs = new String[columns.length]; - for (int i = 0; i < columns.length; i++) { - String tmp = columns[i].toString(); - // Strip the curly-brackets if present. - if (tmp.length() > 2 && tmp.startsWith("{") && tmp.endsWith("}")) { - tmp = tmp.substring(1, tmp.length() - 1); - } - columnStrs[i] = tmp; - formatter.row(new String[] { columnStrs[i] }); - } - formatter.footer(); - return new ReturnMsg(1, columns.length + " columnfamily(s) in set."); - } catch (IOException e) { - return new ReturnMsg(0, "error msg : " + e.toString()); - } - } - - public void setArgument(String table) { - this.tableName = new Text(table); - } -} Index: src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/generated/Token.java =================================================================== --- src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/generated/Token.java (revision 611544) +++ src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/generated/Token.java (working copy) @@ -1,100 +0,0 @@ -/* Generated By:JavaCC: Do not edit this line. Token.java Version 3.0 */ -/** - * Copyright 2007 The Apache Software Foundation - * - * 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.hadoop.hbase.shell.generated; - -/** - * Describes the input token stream. - */ - -public class Token { - - /** - * An integer that describes the kind of this token. This numbering - * system is determined by JavaCCParser, and a table of these numbers is - * stored in the file ...Constants.java. - */ - public int kind; - - /** - * beginLine and beginColumn describe the position of the first character - * of this token; endLine and endColumn describe the position of the - * last character of this token. - */ - public int beginLine, beginColumn, endLine, endColumn; - - /** - * The string image of the token. - */ - public String image; - - /** - * A reference to the next regular (non-special) token from the input - * stream. If this is the last token from the input stream, or if the - * token manager has not read tokens beyond this one, this field is - * set to null. This is true only if this token is also a regular - * token. Otherwise, see below for a description of the contents of - * this field. - */ - public Token next; - - /** - * This field is used to access special tokens that occur prior to this - * token, but after the immediately preceding regular (non-special) token. - * If there are no such special tokens, this field is set to null. - * When there are more than one such special token, this field refers - * to the last of these special tokens, which in turn refers to the next - * previous special token through its specialToken field, and so on - * until the first special token (whose specialToken field is null). - * The next fields of special tokens refer to other special tokens that - * immediately follow it (without an intervening regular token). If there - * is no such token, this field is null. - */ - public Token specialToken; - - /** - * Returns the image. - */ - public String toString() - { - return image; - } - - /** - * Returns a new Token object, by default. However, if you want, you - * can create and return subclass objects based on the value of ofKind. - * Simply add the cases to the switch for all those special cases. - * For example, if you have a subclass of Token called IDToken that - * you want to create if ofKind is ID, simlpy add something like : - * - * case MyParserConstants.ID : return new IDToken(); - * - * to the following switch statement. Then you can cast matchedToken - * variable to the appropriate type and use it in your lexical actions. - */ - public static final Token newToken(int ofKind) - { - switch(ofKind) - { - default : return new Token(); - } - } - -} Index: src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/generated/TokenMgrError.java =================================================================== --- src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/generated/TokenMgrError.java (revision 611544) +++ src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/generated/TokenMgrError.java (working copy) @@ -1,152 +0,0 @@ -/* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 3.0 */ -/** - * Copyright 2007 The Apache Software Foundation - * - * 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.hadoop.hbase.shell.generated; - -public class TokenMgrError extends Error -{ - /* - * Ordinals for various reasons why an Error of this type can be thrown. - */ - - /** - * Lexical error occured. - */ - static final int LEXICAL_ERROR = 0; - - /** - * An attempt wass made to create a second instance of a static token manager. - */ - static final int STATIC_LEXER_ERROR = 1; - - /** - * Tried to change to an invalid lexical state. - */ - static final int INVALID_LEXICAL_STATE = 2; - - /** - * Detected (and bailed out of) an infinite loop in the token manager. - */ - static final int LOOP_DETECTED = 3; - - /** - * Indicates the reason why the exception is thrown. It will have - * one of the above 4 values. - */ - int errorCode; - - /** - * Replaces unprintable characters by their espaced (or unicode escaped) - * equivalents in the given string - */ - protected static final String addEscapes(String str) { - StringBuffer retval = new StringBuffer(); - char ch; - for (int i = 0; i < str.length(); i++) { - switch (str.charAt(i)) - { - case 0 : - continue; - case '\b': - retval.append("\\b"); - continue; - case '\t': - retval.append("\\t"); - continue; - case '\n': - retval.append("\\n"); - continue; - case '\f': - retval.append("\\f"); - continue; - case '\r': - retval.append("\\r"); - continue; - case '\"': - retval.append("\\\""); - continue; - case '\'': - retval.append("\\\'"); - continue; - case '\\': - retval.append("\\\\"); - continue; - default: - if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { - String s = "0000" + Integer.toString(ch, 16); - retval.append("\\u" + s.substring(s.length() - 4, s.length())); - } else { - retval.append(ch); - } - continue; - } - } - return retval.toString(); - } - - /** - * Returns a detailed message for the Error when it is thrown by the - * token manager to indicate a lexical error. - * Parameters : - * EOFSeen : indicates if EOF caused the lexicl error - * curLexState : lexical state in which this error occured - * errorLine : line number when the error occured - * errorColumn : column number when the error occured - * errorAfter : prefix that was seen before this error occured - * curchar : the offending character - * Note: You can customize the lexical error message by modifying this method. - */ - protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) { - return("Lexical error at line " + - errorLine + ", column " + - errorColumn + ". Encountered: " + - (EOFSeen ? " " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") + - "after : \"" + addEscapes(errorAfter) + "\""); - } - - /** - * You can also modify the body of this method to customize your error messages. - * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not - * of end-users concern, so you can return something like : - * - * "Internal Error : Please file a bug report .... " - * - * from this method for such cases in the release version of your parser. - */ - public String getMessage() { - return super.getMessage(); - } - - /* - * Constructors of various flavors follow. - */ - - public TokenMgrError() { - } - - public TokenMgrError(String message, int reason) { - super(message); - errorCode = reason; - } - - public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) { - this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); - } -} Index: src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/generated/SimpleCharStream.java =================================================================== --- src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/generated/SimpleCharStream.java (revision 611544) +++ src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/generated/SimpleCharStream.java (working copy) @@ -1,458 +0,0 @@ -/* Generated By:JavaCC: Do not edit this line. SimpleCharStream.java Version 4.0 */ -/** - * Copyright 2007 The Apache Software Foundation - * - * 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.hadoop.hbase.shell.generated; - -/** - * An implementation of interface CharStream, where the stream is assumed to - * contain only ASCII characters (without unicode processing). - */ - -public class SimpleCharStream -{ - public static final boolean staticFlag = false; - int bufsize; - int available; - int tokenBegin; - public int bufpos = -1; - protected int bufline[]; - protected int bufcolumn[]; - - protected int column = 0; - protected int line = 1; - - protected boolean prevCharIsCR = false; - protected boolean prevCharIsLF = false; - - protected java.io.Reader inputStream; - - protected char[] buffer; - protected int maxNextCharInd = 0; - protected int inBuf = 0; - protected int tabSize = 8; - - protected void setTabSize(int i) { tabSize = i; } - protected int getTabSize(int i) { return tabSize; } - - - protected void ExpandBuff(boolean wrapAround) - { - char[] newbuffer = new char[bufsize + 2048]; - int newbufline[] = new int[bufsize + 2048]; - int newbufcolumn[] = new int[bufsize + 2048]; - - try - { - if (wrapAround) - { - System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin); - System.arraycopy(buffer, 0, newbuffer, - bufsize - tokenBegin, bufpos); - buffer = newbuffer; - - System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin); - System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos); - bufline = newbufline; - - System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin); - System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos); - bufcolumn = newbufcolumn; - - maxNextCharInd = (bufpos += (bufsize - tokenBegin)); - } - else - { - System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin); - buffer = newbuffer; - - System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin); - bufline = newbufline; - - System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin); - bufcolumn = newbufcolumn; - - maxNextCharInd = (bufpos -= tokenBegin); - } - } - catch (Throwable t) - { - throw new Error(t.getMessage()); - } - - - bufsize += 2048; - available = bufsize; - tokenBegin = 0; - } - - protected void FillBuff() throws java.io.IOException - { - if (maxNextCharInd == available) - { - if (available == bufsize) - { - if (tokenBegin > 2048) - { - bufpos = maxNextCharInd = 0; - available = tokenBegin; - } - else if (tokenBegin < 0) - bufpos = maxNextCharInd = 0; - else - ExpandBuff(false); - } - else if (available > tokenBegin) - available = bufsize; - else if ((tokenBegin - available) < 2048) - ExpandBuff(true); - else - available = tokenBegin; - } - - int i; - try { - if ((i = inputStream.read(buffer, maxNextCharInd, - available - maxNextCharInd)) == -1) - { - inputStream.close(); - throw new java.io.IOException(); - } - else - maxNextCharInd += i; - return; - } - catch(java.io.IOException e) { - --bufpos; - backup(0); - if (tokenBegin == -1) - tokenBegin = bufpos; - throw e; - } - } - - public char BeginToken() throws java.io.IOException - { - tokenBegin = -1; - char c = readChar(); - tokenBegin = bufpos; - - return c; - } - - protected void UpdateLineColumn(char c) - { - column++; - - if (prevCharIsLF) - { - prevCharIsLF = false; - line += (column = 1); - } - else if (prevCharIsCR) - { - prevCharIsCR = false; - if (c == '\n') - { - prevCharIsLF = true; - } - else - line += (column = 1); - } - - switch (c) - { - case '\r' : - prevCharIsCR = true; - break; - case '\n' : - prevCharIsLF = true; - break; - case '\t' : - column--; - column += (tabSize - (column % tabSize)); - break; - default : - break; - } - - bufline[bufpos] = line; - bufcolumn[bufpos] = column; - } - - public char readChar() throws java.io.IOException - { - if (inBuf > 0) - { - --inBuf; - - if (++bufpos == bufsize) - bufpos = 0; - - return buffer[bufpos]; - } - - if (++bufpos >= maxNextCharInd) - FillBuff(); - - char c = buffer[bufpos]; - - UpdateLineColumn(c); - return (c); - } - - /** - * @deprecated - * @see #getEndColumn - */ - - public int getColumn() { - return bufcolumn[bufpos]; - } - - /** - * @deprecated - * @see #getEndLine - */ - - public int getLine() { - return bufline[bufpos]; - } - - public int getEndColumn() { - return bufcolumn[bufpos]; - } - - public int getEndLine() { - return bufline[bufpos]; - } - - public int getBeginColumn() { - return bufcolumn[tokenBegin]; - } - - public int getBeginLine() { - return bufline[tokenBegin]; - } - - public void backup(int amount) { - - inBuf += amount; - if ((bufpos -= amount) < 0) - bufpos += bufsize; - } - - public SimpleCharStream(java.io.Reader dstream, int startline, - int startcolumn, int buffersize) - { - inputStream = dstream; - line = startline; - column = startcolumn - 1; - - available = bufsize = buffersize; - buffer = new char[buffersize]; - bufline = new int[buffersize]; - bufcolumn = new int[buffersize]; - } - - public SimpleCharStream(java.io.Reader dstream, int startline, - int startcolumn) - { - this(dstream, startline, startcolumn, 4096); - } - - public SimpleCharStream(java.io.Reader dstream) - { - this(dstream, 1, 1, 4096); - } - public void ReInit(java.io.Reader dstream, int startline, - int startcolumn, int buffersize) - { - inputStream = dstream; - line = startline; - column = startcolumn - 1; - - if (buffer == null || buffersize != buffer.length) - { - available = bufsize = buffersize; - buffer = new char[buffersize]; - bufline = new int[buffersize]; - bufcolumn = new int[buffersize]; - } - prevCharIsLF = prevCharIsCR = false; - tokenBegin = inBuf = maxNextCharInd = 0; - bufpos = -1; - } - - public void ReInit(java.io.Reader dstream, int startline, - int startcolumn) - { - ReInit(dstream, startline, startcolumn, 4096); - } - - public void ReInit(java.io.Reader dstream) - { - ReInit(dstream, 1, 1, 4096); - } - public SimpleCharStream(java.io.InputStream dstream, String encoding, int startline, - int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException - { - this(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); - } - - public SimpleCharStream(java.io.InputStream dstream, int startline, - int startcolumn, int buffersize) - { - this(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize); - } - - public SimpleCharStream(java.io.InputStream dstream, String encoding, int startline, - int startcolumn) throws java.io.UnsupportedEncodingException - { - this(dstream, encoding, startline, startcolumn, 4096); - } - - public SimpleCharStream(java.io.InputStream dstream, int startline, - int startcolumn) - { - this(dstream, startline, startcolumn, 4096); - } - - public SimpleCharStream(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException - { - this(dstream, encoding, 1, 1, 4096); - } - - public SimpleCharStream(java.io.InputStream dstream) - { - this(dstream, 1, 1, 4096); - } - - public void ReInit(java.io.InputStream dstream, String encoding, int startline, - int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException - { - ReInit(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); - } - - public void ReInit(java.io.InputStream dstream, int startline, - int startcolumn, int buffersize) - { - ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize); - } - - public void ReInit(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException - { - ReInit(dstream, encoding, 1, 1, 4096); - } - - public void ReInit(java.io.InputStream dstream) - { - ReInit(dstream, 1, 1, 4096); - } - public void ReInit(java.io.InputStream dstream, String encoding, int startline, - int startcolumn) throws java.io.UnsupportedEncodingException - { - ReInit(dstream, encoding, startline, startcolumn, 4096); - } - public void ReInit(java.io.InputStream dstream, int startline, - int startcolumn) - { - ReInit(dstream, startline, startcolumn, 4096); - } - public String GetImage() - { - if (bufpos >= tokenBegin) - return new String(buffer, tokenBegin, bufpos - tokenBegin + 1); - else - return new String(buffer, tokenBegin, bufsize - tokenBegin) + - new String(buffer, 0, bufpos + 1); - } - - public char[] GetSuffix(int len) - { - char[] ret = new char[len]; - - if ((bufpos + 1) >= len) - System.arraycopy(buffer, bufpos - len + 1, ret, 0, len); - else - { - System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0, - len - bufpos - 1); - System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1); - } - - return ret; - } - - public void Done() - { - buffer = null; - bufline = null; - bufcolumn = null; - } - - /** - * Method to adjust line and column numbers for the start of a token. - */ - public void adjustBeginLineColumn(int newLine, int newCol) - { - int start = tokenBegin; - int len; - - if (bufpos >= tokenBegin) - { - len = bufpos - tokenBegin + inBuf + 1; - } - else - { - len = bufsize - tokenBegin + bufpos + 1 + inBuf; - } - - int i = 0, j = 0, k = 0; - int nextColDiff = 0, columnDiff = 0; - - while (i < len && - bufline[j = start % bufsize] == bufline[k = ++start % bufsize]) - { - bufline[j] = newLine; - nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j]; - bufcolumn[j] = newCol + columnDiff; - columnDiff = nextColDiff; - i++; - } - - if (i < len) - { - bufline[j] = newLine++; - bufcolumn[j] = newCol + columnDiff; - - while (i++ < len) - { - if (bufline[j = start % bufsize] != bufline[++start % bufsize]) - bufline[j] = newLine++; - else - bufline[j] = newLine; - } - } - - line = bufline[j]; - column = bufcolumn[j]; - } - -} Index: src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/generated/ParserTokenManager.java =================================================================== --- src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/generated/ParserTokenManager.java (revision 611544) +++ src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/generated/ParserTokenManager.java (working copy) @@ -1,1605 +0,0 @@ -/* Generated By:JavaCC: Do not edit this line. ParserTokenManager.java */ -package org.apache.hadoop.hbase.shell.generated; -/** - * Copyright 2007 The Apache Software Foundation - * - * 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. - */ - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.HashMap; -import java.io.StringReader; -import java.io.Reader; -import java.io.Writer; -import java.net.URLEncoder; -import java.io.UnsupportedEncodingException; -import org.apache.hadoop.hbase.shell.*; - -public class ParserTokenManager implements ParserConstants -{ - public java.io.PrintStream debugStream = System.out; - public void setDebugStream(java.io.PrintStream ds) { debugStream = ds; } -private final int jjStopStringLiteralDfa_0(int pos, long active0, long active1) -{ - switch (pos) - { - case 0: - if ((active0 & 0x3fffcc0fffffffe0L) != 0L) - { - jjmatchedKind = 62; - return 1; - } - return -1; - case 1: - if ((active0 & 0x3fefc407fff9bfe0L) != 0L) - { - if (jjmatchedPos != 1) - { - jjmatchedKind = 62; - jjmatchedPos = 1; - } - return 1; - } - if ((active0 & 0x10080800064000L) != 0L) - return 1; - return -1; - case 2: - if ((active0 & 0x37ffc003efff3fe0L) != 0L) - { - jjmatchedKind = 62; - jjmatchedPos = 2; - return 1; - } - if ((active0 & 0x800040410008000L) != 0L) - return 1; - return -1; - case 3: - if ((active0 & 0x37fdc003ebfa28c0L) != 0L) - { - if (jjmatchedPos != 3) - { - jjmatchedKind = 62; - jjmatchedPos = 3; - } - return 1; - } - if ((active0 & 0x2000004051720L) != 0L) - return 1; - return -1; - case 4: - if ((active0 & 0x17b9c001e1f22a00L) != 0L) - { - if (jjmatchedPos != 4) - { - jjmatchedKind = 62; - jjmatchedPos = 4; - } - return 1; - } - if ((active0 & 0x204400020a0800c0L) != 0L) - return 1; - return -1; - case 5: - if ((active0 & 0x1008000020720800L) != 0L) - return 1; - if ((active0 & 0x7f1c001c1802200L) != 0L) - { - jjmatchedKind = 62; - jjmatchedPos = 5; - return 1; - } - return -1; - case 6: - if ((active0 & 0x800000L) != 0L) - return 1; - if ((active0 & 0x7f1c001c1002200L) != 0L) - { - jjmatchedKind = 62; - jjmatchedPos = 6; - return 1; - } - return -1; - case 7: - if ((active0 & 0x200000001002200L) != 0L) - return 1; - if ((active0 & 0x5f1c001c0000000L) != 0L) - { - jjmatchedKind = 62; - jjmatchedPos = 7; - return 1; - } - return -1; - case 8: - if ((active0 & 0x10000080000000L) != 0L) - return 1; - if ((active0 & 0x5e1c00140000000L) != 0L) - { - jjmatchedKind = 62; - jjmatchedPos = 8; - return 1; - } - return -1; - case 9: - if ((active0 & 0x800000000000L) != 0L) - return 1; - if ((active0 & 0x5e1400140000000L) != 0L) - { - jjmatchedKind = 62; - jjmatchedPos = 9; - return 1; - } - return -1; - case 10: - if ((active0 & 0x521000000000000L) != 0L) - return 1; - if ((active0 & 0xc0400140000000L) != 0L) - { - jjmatchedKind = 62; - jjmatchedPos = 10; - return 1; - } - return -1; - case 11: - if ((active0 & 0x400100000000L) != 0L) - return 1; - if ((active0 & 0xc0000040000000L) != 0L) - { - jjmatchedKind = 62; - jjmatchedPos = 11; - return 1; - } - return -1; - case 12: - if ((active0 & 0xc0000040000000L) != 0L) - { - jjmatchedKind = 62; - jjmatchedPos = 12; - return 1; - } - return -1; - case 13: - if ((active0 & 0x40000000L) != 0L) - return 1; - if ((active0 & 0xc0000000000000L) != 0L) - { - jjmatchedKind = 62; - jjmatchedPos = 13; - return 1; - } - return -1; - case 14: - if ((active0 & 0xc0000000000000L) != 0L) - { - jjmatchedKind = 62; - jjmatchedPos = 14; - return 1; - } - return -1; - case 15: - if ((active0 & 0xc0000000000000L) != 0L) - { - jjmatchedKind = 62; - jjmatchedPos = 15; - return 1; - } - return -1; - case 16: - if ((active0 & 0xc0000000000000L) != 0L) - { - jjmatchedKind = 62; - jjmatchedPos = 16; - return 1; - } - return -1; - case 17: - if ((active0 & 0xc0000000000000L) != 0L) - { - jjmatchedKind = 62; - jjmatchedPos = 17; - return 1; - } - return -1; - case 18: - if ((active0 & 0xc0000000000000L) != 0L) - { - jjmatchedKind = 62; - jjmatchedPos = 18; - return 1; - } - return -1; - case 19: - if ((active0 & 0x80000000000000L) != 0L) - { - jjmatchedKind = 62; - jjmatchedPos = 19; - return 1; - } - if ((active0 & 0x40000000000000L) != 0L) - return 1; - return -1; - default : - return -1; - } -} -private final int jjStartNfa_0(int pos, long active0, long active1) -{ - return jjMoveNfa_0(jjStopStringLiteralDfa_0(pos, active0, active1), pos + 1); -} -private final int jjStopAtPos(int pos, int kind) -{ - jjmatchedKind = kind; - jjmatchedPos = pos; - return pos + 1; -} -private final int jjStartNfaWithStates_0(int pos, int kind, int state) -{ - jjmatchedKind = kind; - jjmatchedPos = pos; - try { curChar = input_stream.readChar(); } - catch(java.io.IOException e) { return pos + 1; } - return jjMoveNfa_0(state, pos + 1); -} -private final int jjMoveStringLiteralDfa0_0() -{ - switch(curChar) - { - case 33: - return jjMoveStringLiteralDfa1_0(0x100000000000L); - case 40: - return jjStopAtPos(0, 37); - case 41: - return jjStopAtPos(0, 38); - case 42: - return jjStopAtPos(0, 45); - case 44: - return jjStopAtPos(0, 36); - case 59: - return jjStopAtPos(0, 68); - case 60: - return jjStopAtPos(0, 41); - case 61: - return jjStopAtPos(0, 39); - case 62: - return jjStopAtPos(0, 40); - case 65: - case 97: - return jjMoveStringLiteralDfa1_0(0x800000400000040L); - case 66: - case 98: - return jjMoveStringLiteralDfa1_0(0x24000000000000L); - case 67: - case 99: - return jjMoveStringLiteralDfa1_0(0x3041000040000880L); - case 68: - case 100: - return jjMoveStringLiteralDfa1_0(0x901600L); - case 69: - case 101: - return jjMoveStringLiteralDfa1_0(0x410000L); - case 70: - case 102: - return jjMoveStringLiteralDfa1_0(0x4004000L); - case 72: - case 104: - return jjMoveStringLiteralDfa1_0(0x20L); - case 73: - case 105: - return jjMoveStringLiteralDfa1_0(0x10080000060000L); - case 74: - case 106: - return jjMoveStringLiteralDfa1_0(0x8000L); - case 76: - case 108: - return jjMoveStringLiteralDfa1_0(0x200000000L); - case 77: - case 109: - return jjMoveStringLiteralDfa1_0(0xc00000000000L); - case 78: - case 110: - return jjMoveStringLiteralDfa1_0(0x602040100000000L); - case 79: - case 111: - return jjMoveStringLiteralDfa1_0(0x800000000L); - case 82: - case 114: - return jjMoveStringLiteralDfa1_0(0x88000010000000L); - case 83: - case 115: - return jjMoveStringLiteralDfa1_0(0x1200100L); - case 84: - case 116: - return jjMoveStringLiteralDfa1_0(0x80082000L); - case 85: - case 117: - return jjMoveStringLiteralDfa1_0(0x8000000L); - case 86: - case 118: - return jjMoveStringLiteralDfa1_0(0x100000020000000L); - case 87: - case 119: - return jjMoveStringLiteralDfa1_0(0x2000000L); - default : - return jjMoveNfa_0(0, 0); - } -} -private final int jjMoveStringLiteralDfa1_0(long active0) -{ - try { curChar = input_stream.readChar(); } - catch(java.io.IOException e) { - jjStopStringLiteralDfa_0(0, active0, 0L); - return 1; - } - switch(curChar) - { - case 61: - if ((active0 & 0x100000000000L) != 0L) - return jjStopAtPos(1, 44); - break; - case 65: - case 97: - return jjMoveStringLiteralDfa2_0(active0, 0xc00020088000L); - case 68: - case 100: - return jjMoveStringLiteralDfa2_0(active0, 0x800000000000000L); - case 69: - case 101: - return jjMoveStringLiteralDfa2_0(active0, 0x188000000300620L); - case 72: - case 104: - return jjMoveStringLiteralDfa2_0(active0, 0x1000000002000100L); - case 73: - case 105: - return jjMoveStringLiteralDfa2_0(active0, 0x280800000L); - case 76: - case 108: - return jjMoveStringLiteralDfa2_0(active0, 0x240000000000c0L); - case 78: - case 110: - if ((active0 & 0x80000000000L) != 0L) - { - jjmatchedKind = 43; - jjmatchedPos = 1; - } - return jjMoveStringLiteralDfa2_0(active0, 0x10000408460000L); - case 79: - case 111: - return jjMoveStringLiteralDfa2_0(active0, 0x2043040050000000L); - case 82: - case 114: - if ((active0 & 0x800000000L) != 0L) - return jjStartNfaWithStates_0(1, 35, 1); - return jjMoveStringLiteralDfa2_0(active0, 0x4003800L); - case 83: - case 115: - if ((active0 & 0x4000L) != 0L) - return jjStartNfaWithStates_0(1, 14, 1); - break; - case 84: - case 116: - return jjMoveStringLiteralDfa2_0(active0, 0x1000000L); - case 85: - case 117: - return jjMoveStringLiteralDfa2_0(active0, 0x600000100000000L); - case 88: - case 120: - return jjMoveStringLiteralDfa2_0(active0, 0x10000L); - default : - break; - } - return jjStartNfa_0(0, active0, 0L); -} -private final int jjMoveStringLiteralDfa2_0(long old0, long active0) -{ - if (((active0 &= old0)) == 0L) - return jjStartNfa_0(0, old0, 0L); - try { curChar = input_stream.readChar(); } - catch(java.io.IOException e) { - jjStopStringLiteralDfa_0(1, active0, 0L); - return 2; - } - switch(curChar) - { - case 95: - return jjMoveStringLiteralDfa3_0(active0, 0x10000000000000L); - case 65: - case 97: - return jjMoveStringLiteralDfa3_0(active0, 0x1000000001400000L); - case 66: - case 98: - return jjMoveStringLiteralDfa3_0(active0, 0x80000L); - case 67: - case 99: - return jjMoveStringLiteralDfa3_0(active0, 0x108000000000000L); - case 68: - case 100: - if ((active0 & 0x400000000L) != 0L) - return jjStartNfaWithStates_0(2, 34, 1); - else if ((active0 & 0x800000000000000L) != 0L) - return jjStartNfaWithStates_0(2, 59, 1); - break; - case 69: - case 101: - return jjMoveStringLiteralDfa3_0(active0, 0x2000880L); - case 73: - case 105: - return jjMoveStringLiteralDfa3_0(active0, 0x10000L); - case 76: - case 108: - return jjMoveStringLiteralDfa3_0(active0, 0x60300020L); - case 77: - case 109: - return jjMoveStringLiteralDfa3_0(active0, 0x601000380000000L); - case 78: - case 110: - return jjMoveStringLiteralDfa3_0(active0, 0x2000000000000L); - case 79: - case 111: - return jjMoveStringLiteralDfa3_0(active0, 0x24000004001100L); - case 82: - case 114: - if ((active0 & 0x8000L) != 0L) - return jjStartNfaWithStates_0(2, 15, 1); - break; - case 83: - case 115: - return jjMoveStringLiteralDfa3_0(active0, 0x820600L); - case 84: - case 116: - if ((active0 & 0x40000000000L) != 0L) - return jjStartNfaWithStates_0(2, 42, 1); - return jjMoveStringLiteralDfa3_0(active0, 0x80000008040040L); - case 85: - case 117: - return jjMoveStringLiteralDfa3_0(active0, 0x2040000000002000L); - case 87: - case 119: - if ((active0 & 0x10000000L) != 0L) - return jjStartNfaWithStates_0(2, 28, 1); - break; - case 88: - case 120: - return jjMoveStringLiteralDfa3_0(active0, 0xc00000000000L); - default : - break; - } - return jjStartNfa_0(1, active0, 0L); -} -private final int jjMoveStringLiteralDfa3_0(long old0, long active0) -{ - if (((active0 &= old0)) == 0L) - return jjStartNfa_0(1, old0, 0L); - try { curChar = input_stream.readChar(); } - catch(java.io.IOException e) { - jjStopStringLiteralDfa_0(2, active0, 0L); - return 3; - } - switch(curChar) - { - case 95: - return jjMoveStringLiteralDfa4_0(active0, 0x600c00100000000L); - case 65: - case 97: - return jjMoveStringLiteralDfa4_0(active0, 0x800880L); - case 66: - case 98: - return jjMoveStringLiteralDfa4_0(active0, 0x400000L); - case 67: - case 99: - if ((active0 & 0x400L) != 0L) - { - jjmatchedKind = 10; - jjmatchedPos = 3; - } - return jjMoveStringLiteralDfa4_0(active0, 0x4000000000200L); - case 69: - case 101: - if ((active0 & 0x2000000000000L) != 0L) - return jjStartNfaWithStates_0(3, 49, 1); - return jjMoveStringLiteralDfa4_0(active0, 0x80320040L); - case 73: - case 105: - return jjMoveStringLiteralDfa4_0(active0, 0x208000000L); - case 76: - case 108: - return jjMoveStringLiteralDfa4_0(active0, 0x80000L); - case 77: - case 109: - if ((active0 & 0x4000000L) != 0L) - return jjStartNfaWithStates_0(3, 26, 1); - return jjMoveStringLiteralDfa4_0(active0, 0x10000000000000L); - case 78: - case 110: - return jjMoveStringLiteralDfa4_0(active0, 0x3040000000002000L); - case 79: - case 111: - if ((active0 & 0x40000L) != 0L) - return jjStartNfaWithStates_0(3, 18, 1); - return jjMoveStringLiteralDfa4_0(active0, 0xa8000000000000L); - case 80: - case 112: - if ((active0 & 0x20L) != 0L) - return jjStartNfaWithStates_0(3, 5, 1); - else if ((active0 & 0x1000L) != 0L) - return jjStartNfaWithStates_0(3, 12, 1); - return jjMoveStringLiteralDfa4_0(active0, 0x1000000000000L); - case 82: - case 114: - return jjMoveStringLiteralDfa4_0(active0, 0x3000000L); - case 84: - case 116: - if ((active0 & 0x10000L) != 0L) - return jjStartNfaWithStates_0(3, 16, 1); - return jjMoveStringLiteralDfa4_0(active0, 0x100000000000000L); - case 85: - case 117: - return jjMoveStringLiteralDfa4_0(active0, 0x60000000L); - case 87: - case 119: - if ((active0 & 0x100L) != 0L) - return jjStartNfaWithStates_0(3, 8, 1); - break; - default : - break; - } - return jjStartNfa_0(2, active0, 0L); -} -private final int jjMoveStringLiteralDfa4_0(long old0, long active0) -{ - if (((active0 &= old0)) == 0L) - return jjStartNfa_0(2, old0, 0L); - try { curChar = input_stream.readChar(); } - catch(java.io.IOException e) { - jjStopStringLiteralDfa_0(3, active0, 0L); - return 4; - } - switch(curChar) - { - case 66: - case 98: - return jjMoveStringLiteralDfa5_0(active0, 0x800000L); - case 67: - case 99: - return jjMoveStringLiteralDfa5_0(active0, 0x202000L); - case 69: - case 101: - if ((active0 & 0x80000L) != 0L) - return jjStartNfaWithStates_0(4, 19, 1); - else if ((active0 & 0x2000000L) != 0L) - return jjStartNfaWithStates_0(4, 25, 1); - return jjMoveStringLiteralDfa5_0(active0, 0x410000020000000L); - case 71: - case 103: - return jjMoveStringLiteralDfa5_0(active0, 0x1000000000000000L); - case 72: - case 104: - return jjMoveStringLiteralDfa5_0(active0, 0x200000000000000L); - case 75: - case 107: - if ((active0 & 0x4000000000000L) != 0L) - return jjStartNfaWithStates_0(4, 50, 1); - break; - case 76: - case 108: - if ((active0 & 0x8000000L) != 0L) - return jjStartNfaWithStates_0(4, 27, 1); - return jjMoveStringLiteralDfa5_0(active0, 0x800000400000L); - case 77: - case 109: - return jjMoveStringLiteralDfa5_0(active0, 0x20000040000000L); - case 79: - case 111: - return jjMoveStringLiteralDfa5_0(active0, 0x100000000000000L); - case 82: - case 114: - if ((active0 & 0x40L) != 0L) - return jjStartNfaWithStates_0(4, 6, 1); - else if ((active0 & 0x80L) != 0L) - return jjStartNfaWithStates_0(4, 7, 1); - return jjMoveStringLiteralDfa5_0(active0, 0x9000000020200L); - case 83: - case 115: - return jjMoveStringLiteralDfa5_0(active0, 0x80000000L); - case 84: - case 116: - if ((active0 & 0x200000000L) != 0L) - return jjStartNfaWithStates_0(4, 33, 1); - else if ((active0 & 0x2000000000000000L) != 0L) - { - jjmatchedKind = 61; - jjmatchedPos = 4; - } - return jjMoveStringLiteralDfa5_0(active0, 0x40000001100800L); - case 85: - case 117: - return jjMoveStringLiteralDfa5_0(active0, 0x80000000000000L); - case 86: - case 118: - return jjMoveStringLiteralDfa5_0(active0, 0x400100000000L); - default : - break; - } - return jjStartNfa_0(3, active0, 0L); -} -private final int jjMoveStringLiteralDfa5_0(long old0, long active0) -{ - if (((active0 &= old0)) == 0L) - return jjStartNfa_0(3, old0, 0L); - try { curChar = input_stream.readChar(); } - catch(java.io.IOException e) { - jjStopStringLiteralDfa_0(4, active0, 0L); - return 5; - } - switch(curChar) - { - case 65: - case 97: - return jjMoveStringLiteralDfa6_0(active0, 0x200000000002000L); - case 67: - case 99: - return jjMoveStringLiteralDfa6_0(active0, 0x80000000000000L); - case 68: - case 100: - if ((active0 & 0x8000000000000L) != 0L) - return jjStartNfaWithStates_0(5, 51, 1); - break; - case 69: - case 101: - if ((active0 & 0x800L) != 0L) - return jjStartNfaWithStates_0(5, 11, 1); - else if ((active0 & 0x100000L) != 0L) - return jjStartNfaWithStates_0(5, 20, 1); - else if ((active0 & 0x400000L) != 0L) - return jjStartNfaWithStates_0(5, 22, 1); - else if ((active0 & 0x1000000000000000L) != 0L) - return jjStartNfaWithStates_0(5, 60, 1); - return jjMoveStringLiteralDfa6_0(active0, 0x1c00100000000L); - case 70: - case 102: - return jjMoveStringLiteralDfa6_0(active0, 0x20000000000000L); - case 73: - case 105: - return jjMoveStringLiteralDfa6_0(active0, 0x40000001000200L); - case 76: - case 108: - return jjMoveStringLiteralDfa6_0(active0, 0x800000L); - case 77: - case 109: - return jjMoveStringLiteralDfa6_0(active0, 0x10000000000000L); - case 78: - case 110: - return jjMoveStringLiteralDfa6_0(active0, 0x400000040000000L); - case 82: - case 114: - return jjMoveStringLiteralDfa6_0(active0, 0x100000000000000L); - case 83: - case 115: - if ((active0 & 0x20000000L) != 0L) - return jjStartNfaWithStates_0(5, 29, 1); - break; - case 84: - case 116: - if ((active0 & 0x20000L) != 0L) - return jjStartNfaWithStates_0(5, 17, 1); - else if ((active0 & 0x200000L) != 0L) - return jjStartNfaWithStates_0(5, 21, 1); - return jjMoveStringLiteralDfa6_0(active0, 0x80000000L); - default : - break; - } - return jjStartNfa_0(4, active0, 0L); -} -private final int jjMoveStringLiteralDfa6_0(long old0, long active0) -{ - if (((active0 &= old0)) == 0L) - return jjStartNfa_0(4, old0, 0L); - try { curChar = input_stream.readChar(); } - catch(java.io.IOException e) { - jjStopStringLiteralDfa_0(5, active0, 0L); - return 6; - } - switch(curChar) - { - case 95: - return jjMoveStringLiteralDfa7_0(active0, 0x100000000000000L); - case 65: - case 97: - return jjMoveStringLiteralDfa7_0(active0, 0x80000000L); - case 66: - case 98: - return jjMoveStringLiteralDfa7_0(active0, 0x200L); - case 69: - case 101: - if ((active0 & 0x800000L) != 0L) - return jjStartNfaWithStates_0(6, 23, 1); - break; - case 70: - case 102: - return jjMoveStringLiteralDfa7_0(active0, 0x40000000L); - case 72: - case 104: - return jjMoveStringLiteralDfa7_0(active0, 0x80000000000000L); - case 73: - case 105: - return jjMoveStringLiteralDfa7_0(active0, 0x20000000000000L); - case 78: - case 110: - return jjMoveStringLiteralDfa7_0(active0, 0x40800001000000L); - case 79: - case 111: - return jjMoveStringLiteralDfa7_0(active0, 0x10000000000000L); - case 82: - case 114: - return jjMoveStringLiteralDfa7_0(active0, 0x400100000000L); - case 83: - case 115: - return jjMoveStringLiteralDfa7_0(active0, 0x201000000000000L); - case 84: - case 116: - return jjMoveStringLiteralDfa7_0(active0, 0x400000000002000L); - default : - break; - } - return jjStartNfa_0(5, active0, 0L); -} -private final int jjMoveStringLiteralDfa7_0(long old0, long active0) -{ - if (((active0 &= old0)) == 0L) - return jjStartNfa_0(5, old0, 0L); - try { curChar = input_stream.readChar(); } - catch(java.io.IOException e) { - jjStopStringLiteralDfa_0(6, active0, 0L); - return 7; - } - switch(curChar) - { - case 65: - case 97: - return jjMoveStringLiteralDfa8_0(active0, 0x40000000L); - case 69: - case 101: - if ((active0 & 0x200L) != 0L) - return jjStartNfaWithStates_0(7, 9, 1); - else if ((active0 & 0x2000L) != 0L) - return jjStartNfaWithStates_0(7, 13, 1); - return jjMoveStringLiteralDfa8_0(active0, 0x80000000000000L); - case 71: - case 103: - if ((active0 & 0x1000000L) != 0L) - return jjStartNfaWithStates_0(7, 24, 1); - return jjMoveStringLiteralDfa8_0(active0, 0x40800000000000L); - case 72: - case 104: - if ((active0 & 0x200000000000000L) != 0L) - return jjStartNfaWithStates_0(7, 57, 1); - break; - case 76: - case 108: - return jjMoveStringLiteralDfa8_0(active0, 0x20000000000000L); - case 77: - case 109: - return jjMoveStringLiteralDfa8_0(active0, 0x80000000L); - case 82: - case 114: - return jjMoveStringLiteralDfa8_0(active0, 0x410000000000000L); - case 83: - case 115: - return jjMoveStringLiteralDfa8_0(active0, 0x101400100000000L); - default : - break; - } - return jjStartNfa_0(6, active0, 0L); -} -private final int jjMoveStringLiteralDfa8_0(long old0, long active0) -{ - if (((active0 &= old0)) == 0L) - return jjStartNfa_0(6, old0, 0L); - try { curChar = input_stream.readChar(); } - catch(java.io.IOException e) { - jjStopStringLiteralDfa_0(7, active0, 0L); - return 8; - } - switch(curChar) - { - case 95: - return jjMoveStringLiteralDfa9_0(active0, 0x40000000000000L); - case 68: - case 100: - return jjMoveStringLiteralDfa9_0(active0, 0x80000000000000L); - case 73: - case 105: - return jjMoveStringLiteralDfa9_0(active0, 0x501400100000000L); - case 77: - case 109: - return jjMoveStringLiteralDfa9_0(active0, 0x40000000L); - case 80: - case 112: - if ((active0 & 0x80000000L) != 0L) - return jjStartNfaWithStates_0(8, 31, 1); - break; - case 84: - case 116: - return jjMoveStringLiteralDfa9_0(active0, 0x20800000000000L); - case 89: - case 121: - if ((active0 & 0x10000000000000L) != 0L) - return jjStartNfaWithStates_0(8, 52, 1); - break; - default : - break; - } - return jjStartNfa_0(7, active0, 0L); -} -private final int jjMoveStringLiteralDfa9_0(long old0, long active0) -{ - if (((active0 &= old0)) == 0L) - return jjStartNfa_0(7, old0, 0L); - try { curChar = input_stream.readChar(); } - catch(java.io.IOException e) { - jjStopStringLiteralDfa_0(8, active0, 0L); - return 9; - } - switch(curChar) - { - case 95: - return jjMoveStringLiteralDfa10_0(active0, 0x80000000000000L); - case 66: - case 98: - return jjMoveStringLiteralDfa10_0(active0, 0x40000000000000L); - case 69: - case 101: - return jjMoveStringLiteralDfa10_0(active0, 0x420000000000000L); - case 72: - case 104: - if ((active0 & 0x800000000000L) != 0L) - return jjStartNfaWithStates_0(9, 47, 1); - break; - case 73: - case 105: - return jjMoveStringLiteralDfa10_0(active0, 0x40000000L); - case 79: - case 111: - return jjMoveStringLiteralDfa10_0(active0, 0x1400100000000L); - case 90: - case 122: - return jjMoveStringLiteralDfa10_0(active0, 0x100000000000000L); - default : - break; - } - return jjStartNfa_0(8, active0, 0L); -} -private final int jjMoveStringLiteralDfa10_0(long old0, long active0) -{ - if (((active0 &= old0)) == 0L) - return jjStartNfa_0(8, old0, 0L); - try { curChar = input_stream.readChar(); } - catch(java.io.IOException e) { - jjStopStringLiteralDfa_0(9, active0, 0L); - return 10; - } - switch(curChar) - { - case 66: - case 98: - return jjMoveStringLiteralDfa11_0(active0, 0x80000000000000L); - case 69: - case 101: - if ((active0 & 0x100000000000000L) != 0L) - return jjStartNfaWithStates_0(10, 56, 1); - break; - case 76: - case 108: - return jjMoveStringLiteralDfa11_0(active0, 0x40000040000000L); - case 78: - case 110: - if ((active0 & 0x1000000000000L) != 0L) - return jjStartNfaWithStates_0(10, 48, 1); - return jjMoveStringLiteralDfa11_0(active0, 0x400100000000L); - case 82: - case 114: - if ((active0 & 0x20000000000000L) != 0L) - return jjStartNfaWithStates_0(10, 53, 1); - break; - case 83: - case 115: - if ((active0 & 0x400000000000000L) != 0L) - return jjStartNfaWithStates_0(10, 58, 1); - break; - default : - break; - } - return jjStartNfa_0(9, active0, 0L); -} -private final int jjMoveStringLiteralDfa11_0(long old0, long active0) -{ - if (((active0 &= old0)) == 0L) - return jjStartNfa_0(9, old0, 0L); - try { curChar = input_stream.readChar(); } - catch(java.io.IOException e) { - jjStopStringLiteralDfa_0(10, active0, 0L); - return 11; - } - switch(curChar) - { - case 73: - case 105: - return jjMoveStringLiteralDfa12_0(active0, 0x40000000L); - case 76: - case 108: - return jjMoveStringLiteralDfa12_0(active0, 0x80000000000000L); - case 79: - case 111: - return jjMoveStringLiteralDfa12_0(active0, 0x40000000000000L); - case 83: - case 115: - if ((active0 & 0x100000000L) != 0L) - return jjStartNfaWithStates_0(11, 32, 1); - else if ((active0 & 0x400000000000L) != 0L) - return jjStartNfaWithStates_0(11, 46, 1); - break; - default : - break; - } - return jjStartNfa_0(10, active0, 0L); -} -private final int jjMoveStringLiteralDfa12_0(long old0, long active0) -{ - if (((active0 &= old0)) == 0L) - return jjStartNfa_0(10, old0, 0L); - try { curChar = input_stream.readChar(); } - catch(java.io.IOException e) { - jjStopStringLiteralDfa_0(11, active0, 0L); - return 12; - } - switch(curChar) - { - case 69: - case 101: - return jjMoveStringLiteralDfa13_0(active0, 0x40000000L); - case 79: - case 111: - return jjMoveStringLiteralDfa13_0(active0, 0xc0000000000000L); - default : - break; - } - return jjStartNfa_0(11, active0, 0L); -} -private final int jjMoveStringLiteralDfa13_0(long old0, long active0) -{ - if (((active0 &= old0)) == 0L) - return jjStartNfa_0(11, old0, 0L); - try { curChar = input_stream.readChar(); } - catch(java.io.IOException e) { - jjStopStringLiteralDfa_0(12, active0, 0L); - return 13; - } - switch(curChar) - { - case 77: - case 109: - return jjMoveStringLiteralDfa14_0(active0, 0x40000000000000L); - case 79: - case 111: - return jjMoveStringLiteralDfa14_0(active0, 0x80000000000000L); - case 83: - case 115: - if ((active0 & 0x40000000L) != 0L) - return jjStartNfaWithStates_0(13, 30, 1); - break; - default : - break; - } - return jjStartNfa_0(12, active0, 0L); -} -private final int jjMoveStringLiteralDfa14_0(long old0, long active0) -{ - if (((active0 &= old0)) == 0L) - return jjStartNfa_0(12, old0, 0L); - try { curChar = input_stream.readChar(); } - catch(java.io.IOException e) { - jjStopStringLiteralDfa_0(13, active0, 0L); - return 14; - } - switch(curChar) - { - case 70: - case 102: - return jjMoveStringLiteralDfa15_0(active0, 0x40000000000000L); - case 77: - case 109: - return jjMoveStringLiteralDfa15_0(active0, 0x80000000000000L); - default : - break; - } - return jjStartNfa_0(13, active0, 0L); -} -private final int jjMoveStringLiteralDfa15_0(long old0, long active0) -{ - if (((active0 &= old0)) == 0L) - return jjStartNfa_0(13, old0, 0L); - try { curChar = input_stream.readChar(); } - catch(java.io.IOException e) { - jjStopStringLiteralDfa_0(14, active0, 0L); - return 15; - } - switch(curChar) - { - case 70: - case 102: - return jjMoveStringLiteralDfa16_0(active0, 0x80000000000000L); - case 73: - case 105: - return jjMoveStringLiteralDfa16_0(active0, 0x40000000000000L); - default : - break; - } - return jjStartNfa_0(14, active0, 0L); -} -private final int jjMoveStringLiteralDfa16_0(long old0, long active0) -{ - if (((active0 &= old0)) == 0L) - return jjStartNfa_0(14, old0, 0L); - try { curChar = input_stream.readChar(); } - catch(java.io.IOException e) { - jjStopStringLiteralDfa_0(15, active0, 0L); - return 16; - } - switch(curChar) - { - case 73: - case 105: - return jjMoveStringLiteralDfa17_0(active0, 0x80000000000000L); - case 76: - case 108: - return jjMoveStringLiteralDfa17_0(active0, 0x40000000000000L); - default : - break; - } - return jjStartNfa_0(15, active0, 0L); -} -private final int jjMoveStringLiteralDfa17_0(long old0, long active0) -{ - if (((active0 &= old0)) == 0L) - return jjStartNfa_0(15, old0, 0L); - try { curChar = input_stream.readChar(); } - catch(java.io.IOException e) { - jjStopStringLiteralDfa_0(16, active0, 0L); - return 17; - } - switch(curChar) - { - case 76: - case 108: - return jjMoveStringLiteralDfa18_0(active0, 0x80000000000000L); - case 84: - case 116: - return jjMoveStringLiteralDfa18_0(active0, 0x40000000000000L); - default : - break; - } - return jjStartNfa_0(16, active0, 0L); -} -private final int jjMoveStringLiteralDfa18_0(long old0, long active0) -{ - if (((active0 &= old0)) == 0L) - return jjStartNfa_0(16, old0, 0L); - try { curChar = input_stream.readChar(); } - catch(java.io.IOException e) { - jjStopStringLiteralDfa_0(17, active0, 0L); - return 18; - } - switch(curChar) - { - case 69: - case 101: - return jjMoveStringLiteralDfa19_0(active0, 0x40000000000000L); - case 84: - case 116: - return jjMoveStringLiteralDfa19_0(active0, 0x80000000000000L); - default : - break; - } - return jjStartNfa_0(17, active0, 0L); -} -private final int jjMoveStringLiteralDfa19_0(long old0, long active0) -{ - if (((active0 &= old0)) == 0L) - return jjStartNfa_0(17, old0, 0L); - try { curChar = input_stream.readChar(); } - catch(java.io.IOException e) { - jjStopStringLiteralDfa_0(18, active0, 0L); - return 19; - } - switch(curChar) - { - case 69: - case 101: - return jjMoveStringLiteralDfa20_0(active0, 0x80000000000000L); - case 82: - case 114: - if ((active0 & 0x40000000000000L) != 0L) - return jjStartNfaWithStates_0(19, 54, 1); - break; - default : - break; - } - return jjStartNfa_0(18, active0, 0L); -} -private final int jjMoveStringLiteralDfa20_0(long old0, long active0) -{ - if (((active0 &= old0)) == 0L) - return jjStartNfa_0(18, old0, 0L); - try { curChar = input_stream.readChar(); } - catch(java.io.IOException e) { - jjStopStringLiteralDfa_0(19, active0, 0L); - return 20; - } - switch(curChar) - { - case 82: - case 114: - if ((active0 & 0x80000000000000L) != 0L) - return jjStartNfaWithStates_0(20, 55, 1); - break; - default : - break; - } - return jjStartNfa_0(19, active0, 0L); -} -private final void jjCheckNAdd(int state) -{ - if (jjrounds[state] != jjround) - { - jjstateSet[jjnewStateCnt++] = state; - jjrounds[state] = jjround; - } -} -private final void jjAddStates(int start, int end) -{ - do { - jjstateSet[jjnewStateCnt++] = jjnextStates[start]; - } while (start++ != end); -} -private final void jjCheckNAddTwoStates(int state1, int state2) -{ - jjCheckNAdd(state1); - jjCheckNAdd(state2); -} -private final void jjCheckNAddStates(int start, int end) -{ - do { - jjCheckNAdd(jjnextStates[start]); - } while (start++ != end); -} -private final void jjCheckNAddStates(int start) -{ - jjCheckNAdd(jjnextStates[start]); - jjCheckNAdd(jjnextStates[start + 1]); -} -static final long[] jjbitVec0 = { - 0x0L, 0x0L, 0xffffffffffffffffL, 0xffffffffffffffffL -}; -private final int jjMoveNfa_0(int startState, int curPos) -{ - int[] nextStates; - int startsAt = 0; - jjnewStateCnt = 32; - int i = 1; - jjstateSet[0] = startState; - int j, kind = 0x7fffffff; - for (;;) - { - if (++jjround == 0x7fffffff) - ReInitRounds(); - if (curChar < 64) - { - long l = 1L << curChar; - MatchLoop: do - { - switch(jjstateSet[--i]) - { - case 0: - if ((0x3ff000000000000L & l) != 0L) - { - if (kind > 63) - kind = 63; - jjCheckNAddStates(0, 6); - } - else if ((0x400e00000000000L & l) != 0L) - { - if (kind > 62) - kind = 62; - jjCheckNAdd(1); - } - else if (curChar == 39) - jjCheckNAddStates(7, 9); - else if (curChar == 34) - jjCheckNAdd(8); - if (curChar == 46) - jjCheckNAdd(3); - break; - case 1: - if ((0x7ffe00000000000L & l) == 0L) - break; - if (kind > 62) - kind = 62; - jjCheckNAdd(1); - break; - case 2: - if (curChar == 46) - jjCheckNAdd(3); - break; - case 3: - if ((0x3ff000000000000L & l) == 0L) - break; - if (kind > 64) - kind = 64; - jjCheckNAddTwoStates(3, 4); - break; - case 5: - if ((0x280000000000L & l) != 0L) - jjCheckNAdd(6); - break; - case 6: - if ((0x3ff000000000000L & l) == 0L) - break; - if (kind > 64) - kind = 64; - jjCheckNAdd(6); - break; - case 7: - if (curChar == 34) - jjCheckNAdd(8); - break; - case 8: - if ((0xfffffffbffffffffL & l) != 0L) - jjCheckNAddTwoStates(8, 9); - break; - case 9: - if (curChar == 34 && kind > 66) - kind = 66; - break; - case 10: - if (curChar == 39) - jjCheckNAddStates(7, 9); - break; - case 11: - if ((0xffffff7fffffffffL & l) != 0L) - jjCheckNAddStates(7, 9); - break; - case 12: - if (curChar == 39) - jjCheckNAddStates(10, 12); - break; - case 13: - if (curChar == 39) - jjstateSet[jjnewStateCnt++] = 12; - break; - case 14: - if ((0xffffff7fffffffffL & l) != 0L) - jjCheckNAddStates(10, 12); - break; - case 15: - if (curChar == 39 && kind > 67) - kind = 67; - break; - case 16: - if ((0x3ff000000000000L & l) == 0L) - break; - if (kind > 63) - kind = 63; - jjCheckNAddStates(0, 6); - break; - case 17: - if ((0x3ff000000000000L & l) == 0L) - break; - if (kind > 63) - kind = 63; - jjCheckNAdd(17); - break; - case 18: - if ((0x3ff000000000000L & l) != 0L) - jjCheckNAddTwoStates(18, 19); - break; - case 19: - if (curChar == 46) - jjCheckNAdd(20); - break; - case 20: - if ((0x3ff000000000000L & l) == 0L) - break; - if (kind > 64) - kind = 64; - jjCheckNAddTwoStates(20, 21); - break; - case 22: - if ((0x280000000000L & l) != 0L) - jjCheckNAdd(23); - break; - case 23: - if ((0x3ff000000000000L & l) == 0L) - break; - if (kind > 64) - kind = 64; - jjCheckNAdd(23); - break; - case 24: - if ((0x3ff000000000000L & l) != 0L) - jjCheckNAddTwoStates(24, 25); - break; - case 26: - if ((0x280000000000L & l) != 0L) - jjCheckNAdd(27); - break; - case 27: - if ((0x3ff000000000000L & l) == 0L) - break; - if (kind > 64) - kind = 64; - jjCheckNAdd(27); - break; - case 28: - if ((0x3ff000000000000L & l) == 0L) - break; - if (kind > 64) - kind = 64; - jjCheckNAddTwoStates(28, 29); - break; - case 30: - if ((0x280000000000L & l) != 0L) - jjCheckNAdd(31); - break; - case 31: - if ((0x3ff000000000000L & l) == 0L) - break; - if (kind > 64) - kind = 64; - jjCheckNAdd(31); - break; - default : break; - } - } while(i != startsAt); - } - else if (curChar < 128) - { - long l = 1L << (curChar & 077); - MatchLoop: do - { - switch(jjstateSet[--i]) - { - case 0: - case 1: - if ((0x47fffffe87fffffeL & l) == 0L) - break; - if (kind > 62) - kind = 62; - jjCheckNAdd(1); - break; - case 4: - if ((0x2000000020L & l) != 0L) - jjAddStates(13, 14); - break; - case 8: - jjAddStates(15, 16); - break; - case 11: - jjCheckNAddStates(7, 9); - break; - case 14: - jjCheckNAddStates(10, 12); - break; - case 21: - if ((0x2000000020L & l) != 0L) - jjAddStates(17, 18); - break; - case 25: - if ((0x2000000020L & l) != 0L) - jjAddStates(19, 20); - break; - case 29: - if ((0x2000000020L & l) != 0L) - jjAddStates(21, 22); - break; - default : break; - } - } while(i != startsAt); - } - else - { - int i2 = (curChar & 0xff) >> 6; - long l2 = 1L << (curChar & 077); - MatchLoop: do - { - switch(jjstateSet[--i]) - { - case 8: - if ((jjbitVec0[i2] & l2) != 0L) - jjAddStates(15, 16); - break; - case 11: - if ((jjbitVec0[i2] & l2) != 0L) - jjCheckNAddStates(7, 9); - break; - case 14: - if ((jjbitVec0[i2] & l2) != 0L) - jjCheckNAddStates(10, 12); - break; - default : break; - } - } while(i != startsAt); - } - if (kind != 0x7fffffff) - { - jjmatchedKind = kind; - jjmatchedPos = curPos; - kind = 0x7fffffff; - } - ++curPos; - if ((i = jjnewStateCnt) == (startsAt = 32 - (jjnewStateCnt = startsAt))) - return curPos; - try { curChar = input_stream.readChar(); } - catch(java.io.IOException e) { return curPos; } - } -} -static final int[] jjnextStates = { - 17, 18, 19, 24, 25, 28, 29, 11, 13, 15, 13, 14, 15, 5, 6, 8, - 9, 22, 23, 26, 27, 30, 31, -}; -public static final String[] jjstrLiteralImages = { -"", null, null, null, null, null, null, null, null, null, null, null, null, -null, null, null, null, null, null, null, null, null, null, null, null, null, null, -null, null, null, null, null, null, null, null, null, "\54", "\50", "\51", "\75", -"\76", "\74", null, null, "\41\75", "\52", null, null, null, null, null, null, null, -null, null, null, null, null, null, null, null, null, null, null, null, null, null, -null, "\73", }; -public static final String[] lexStateNames = { - "DEFAULT", -}; -static final long[] jjtoToken = { - 0xffffffffffffffe1L, 0x1dL, -}; -static final long[] jjtoSkip = { - 0x1eL, 0x0L, -}; -protected SimpleCharStream input_stream; -private final int[] jjrounds = new int[32]; -private final int[] jjstateSet = new int[64]; -protected char curChar; -public ParserTokenManager(SimpleCharStream stream){ - if (SimpleCharStream.staticFlag) - throw new Error("ERROR: Cannot use a static CharStream class with a non-static lexical analyzer."); - input_stream = stream; -} -public ParserTokenManager(SimpleCharStream stream, int lexState){ - this(stream); - SwitchTo(lexState); -} -public void ReInit(SimpleCharStream stream) -{ - jjmatchedPos = jjnewStateCnt = 0; - curLexState = defaultLexState; - input_stream = stream; - ReInitRounds(); -} -private final void ReInitRounds() -{ - int i; - jjround = 0x80000001; - for (i = 32; i-- > 0;) - jjrounds[i] = 0x80000000; -} -public void ReInit(SimpleCharStream stream, int lexState) -{ - ReInit(stream); - SwitchTo(lexState); -} -public void SwitchTo(int lexState) -{ - if (lexState >= 1 || lexState < 0) - throw new TokenMgrError("Error: Ignoring invalid lexical state : " + lexState + ". State unchanged.", TokenMgrError.INVALID_LEXICAL_STATE); - else - curLexState = lexState; -} - -protected Token jjFillToken() -{ - Token t = Token.newToken(jjmatchedKind); - t.kind = jjmatchedKind; - String im = jjstrLiteralImages[jjmatchedKind]; - t.image = (im == null) ? input_stream.GetImage() : im; - t.beginLine = input_stream.getBeginLine(); - t.beginColumn = input_stream.getBeginColumn(); - t.endLine = input_stream.getEndLine(); - t.endColumn = input_stream.getEndColumn(); - return t; -} - -int curLexState = 0; -int defaultLexState = 0; -int jjnewStateCnt; -int jjround; -int jjmatchedPos; -int jjmatchedKind; - -public Token getNextToken() -{ - int kind; - Token specialToken = null; - Token matchedToken; - int curPos = 0; - - EOFLoop : - for (;;) - { - try - { - curChar = input_stream.BeginToken(); - } - catch(java.io.IOException e) - { - jjmatchedKind = 0; - matchedToken = jjFillToken(); - return matchedToken; - } - - try { input_stream.backup(0); - while (curChar <= 32 && (0x100002600L & (1L << curChar)) != 0L) - curChar = input_stream.BeginToken(); - } - catch (java.io.IOException e1) { continue EOFLoop; } - jjmatchedKind = 0x7fffffff; - jjmatchedPos = 0; - curPos = jjMoveStringLiteralDfa0_0(); - if (jjmatchedKind != 0x7fffffff) - { - if (jjmatchedPos + 1 < curPos) - input_stream.backup(curPos - jjmatchedPos - 1); - if ((jjtoToken[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L) - { - matchedToken = jjFillToken(); - return matchedToken; - } - else - { - continue EOFLoop; - } - } - int error_line = input_stream.getEndLine(); - int error_column = input_stream.getEndColumn(); - String error_after = null; - boolean EOFSeen = false; - try { input_stream.readChar(); input_stream.backup(1); } - catch (java.io.IOException e1) { - EOFSeen = true; - error_after = curPos <= 1 ? "" : input_stream.GetImage(); - if (curChar == '\n' || curChar == '\r') { - error_line++; - error_column = 0; - } - else - error_column++; - } - if (!EOFSeen) { - input_stream.backup(1); - error_after = curPos <= 1 ? "" : input_stream.GetImage(); - } - throw new TokenMgrError(EOFSeen, curLexState, error_line, error_column, error_after, curChar, TokenMgrError.LEXICAL_ERROR); - } -} - -} Index: src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/generated/ParseException.java =================================================================== --- src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/generated/ParseException.java (revision 611544) +++ src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/generated/ParseException.java (working copy) @@ -1,211 +0,0 @@ -/* Generated By:JavaCC: Do not edit this line. ParseException.java Version 3.0 */ -/** - * Copyright 2007 The Apache Software Foundation - * - * 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.hadoop.hbase.shell.generated; - -/** - * This exception is thrown when parse errors are encountered. - * You can explicitly create objects of this exception type by - * calling the method generateParseException in the generated - * parser. - * - * You can modify this class to customize your error reporting - * mechanisms so long as you retain the public fields. - */ -public class ParseException extends Exception { - - /** - * This constructor is used by the method "generateParseException" - * in the generated parser. Calling this constructor generates - * a new object of this type with the fields "currentToken", - * "expectedTokenSequences", and "tokenImage" set. The boolean - * flag "specialConstructor" is also set to true to indicate that - * this constructor was used to create this object. - * This constructor calls its super class with the empty string - * to force the "toString" method of parent class "Throwable" to - * print the error message in the form: - * ParseException: - */ - public ParseException(Token currentTokenVal, - int[][] expectedTokenSequencesVal, - String[] tokenImageVal - ) - { - super(""); - specialConstructor = true; - currentToken = currentTokenVal; - expectedTokenSequences = expectedTokenSequencesVal; - tokenImage = tokenImageVal; - } - - /** - * The following constructors are for use by you for whatever - * purpose you can think of. Constructing the exception in this - * manner makes the exception behave in the normal way - i.e., as - * documented in the class "Throwable". The fields "errorToken", - * "expectedTokenSequences", and "tokenImage" do not contain - * relevant information. The JavaCC generated code does not use - * these constructors. - */ - - public ParseException() { - super(); - specialConstructor = false; - } - - public ParseException(String message) { - super(message); - specialConstructor = false; - } - - /** - * This variable determines which constructor was used to create - * this object and thereby affects the semantics of the - * "getMessage" method (see below). - */ - protected boolean specialConstructor; - - /** - * This is the last token that has been consumed successfully. If - * this object has been created due to a parse error, the token - * followng this token will (therefore) be the first error token. - */ - public Token currentToken; - - /** - * Each entry in this array is an array of integers. Each array - * of integers represents a sequence of tokens (by their ordinal - * values) that is expected at this point of the parse. - */ - public int[][] expectedTokenSequences; - - /** - * This is a reference to the "tokenImage" array of the generated - * parser within which the parse error occurred. This array is - * defined in the generated ...Constants interface. - */ - public String[] tokenImage; - - /** - * This method has the standard behavior when this object has been - * created using the standard constructors. Otherwise, it uses - * "currentToken" and "expectedTokenSequences" to generate a parse - * error message and returns it. If this object has been created - * due to a parse error, and you do not catch it (it gets thrown - * from the parser), then this method is called during the printing - * of the final stack trace, and hence the correct error message - * gets displayed. - */ - public String getMessage() { - if (!specialConstructor) { - return super.getMessage(); - } - StringBuffer expected = new StringBuffer(); - int maxSize = 0; - for (int i = 0; i < expectedTokenSequences.length; i++) { - if (maxSize < expectedTokenSequences[i].length) { - maxSize = expectedTokenSequences[i].length; - } - for (int j = 0; j < expectedTokenSequences[i].length; j++) { - expected.append(tokenImage[expectedTokenSequences[i][j]]).append(" "); - } - if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) { - expected.append("..."); - } - expected.append(eol).append(" "); - } - String retval = "Encountered \""; - Token tok = currentToken.next; - for (int i = 0; i < maxSize; i++) { - if (i != 0) retval += " "; - if (tok.kind == 0) { - retval += tokenImage[0]; - break; - } - retval += add_escapes(tok.image); - tok = tok.next; - } - retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn; - retval += "." + eol; - if (expectedTokenSequences.length == 1) { - retval += "Was expecting:" + eol + " "; - } else { - retval += "Was expecting one of:" + eol + " "; - } - retval += expected.toString(); - return retval; - } - - /** - * The end of line string for this machine. - */ - protected String eol = System.getProperty("line.separator", "\n"); - - /** - * Used to convert raw characters to their escaped version - * when these raw version cannot be used as part of an ASCII - * string literal. - */ - protected String add_escapes(String str) { - StringBuffer retval = new StringBuffer(); - char ch; - for (int i = 0; i < str.length(); i++) { - switch (str.charAt(i)) - { - case 0 : - continue; - case '\b': - retval.append("\\b"); - continue; - case '\t': - retval.append("\\t"); - continue; - case '\n': - retval.append("\\n"); - continue; - case '\f': - retval.append("\\f"); - continue; - case '\r': - retval.append("\\r"); - continue; - case '\"': - retval.append("\\\""); - continue; - case '\'': - retval.append("\\\'"); - continue; - case '\\': - retval.append("\\\\"); - continue; - default: - if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { - String s = "0000" + Integer.toString(ch, 16); - retval.append("\\u" + s.substring(s.length() - 4, s.length())); - } else { - retval.append(ch); - } - continue; - } - } - return retval.toString(); - } - -} Index: src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/generated/ParserConstants.java =================================================================== --- src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/generated/ParserConstants.java (revision 611544) +++ src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/generated/ParserConstants.java (working copy) @@ -1,145 +0,0 @@ -/* Generated By:JavaCC: Do not edit this line. ParserConstants.java */ -package org.apache.hadoop.hbase.shell.generated; - -public interface ParserConstants { - - int EOF = 0; - int HELP = 5; - int ALTER = 6; - int CLEAR = 7; - int SHOW = 8; - int DESCRIBE = 9; - int DESC = 10; - int CREATE = 11; - int DROP = 12; - int TRUNCATE = 13; - int FS = 14; - int JAR = 15; - int EXIT = 16; - int INSERT = 17; - int INTO = 18; - int TABLE = 19; - int DELETE = 20; - int SELECT = 21; - int ENABLE = 22; - int DISABLE = 23; - int STARTING = 24; - int WHERE = 25; - int FROM = 26; - int UNTIL = 27; - int ROW = 28; - int VALUES = 29; - int COLUMNFAMILIES = 30; - int TIMESTAMP = 31; - int NUM_VERSIONS = 32; - int LIMIT = 33; - int AND = 34; - int OR = 35; - int COMMA = 36; - int LPAREN = 37; - int RPAREN = 38; - int EQUALS = 39; - int LCOMP = 40; - int RCOMP = 41; - int NOT = 42; - int IN = 43; - int NOTEQUAL = 44; - int ASTERISK = 45; - int MAX_VERSIONS = 46; - int MAX_LENGTH = 47; - int COMPRESSION = 48; - int NONE = 49; - int BLOCK = 50; - int RECORD = 51; - int IN_MEMORY = 52; - int BLOOMFILTER = 53; - int COUNTING_BLOOMFILTER = 54; - int RETOUCHED_BLOOMFILTER = 55; - int VECTOR_SIZE = 56; - int NUM_HASH = 57; - int NUM_ENTRIES = 58; - int ADD = 59; - int CHANGE = 60; - int COUNT = 61; - int ID = 62; - int INTEGER_LITERAL = 63; - int FLOATING_POINT_LITERAL = 64; - int EXPONENT = 65; - int QUOTED_IDENTIFIER = 66; - int STRING_LITERAL = 67; - - int DEFAULT = 0; - - String[] tokenImage = { - "", - "\" \"", - "\"\\t\"", - "\"\\r\"", - "\"\\n\"", - "\"help\"", - "\"alter\"", - "\"clear\"", - "\"show\"", - "\"describe\"", - "\"desc\"", - "\"create\"", - "\"drop\"", - "\"truncate\"", - "\"fs\"", - "\"jar\"", - "\"exit\"", - "\"insert\"", - "\"into\"", - "\"table\"", - "\"delete\"", - "\"select\"", - "\"enable\"", - "\"disable\"", - "\"starting\"", - "\"where\"", - "\"from\"", - "\"until\"", - "\"row\"", - "\"values\"", - "\"columnfamilies\"", - "\"timestamp\"", - "\"num_versions\"", - "\"limit\"", - "\"and\"", - "\"or\"", - "\",\"", - "\"(\"", - "\")\"", - "\"=\"", - "\">\"", - "\"<\"", - "\"not\"", - "\"in\"", - "\"!=\"", - "\"*\"", - "\"max_versions\"", - "\"max_length\"", - "\"compression\"", - "\"none\"", - "\"block\"", - "\"record\"", - "\"in_memory\"", - "\"bloomfilter\"", - "\"counting_bloomfilter\"", - "\"retouched_bloomfilter\"", - "\"vector_size\"", - "\"num_hash\"", - "\"num_entries\"", - "\"add\"", - "\"change\"", - "\"count\"", - "", - "", - "", - "", - "", - "", - "\";\"", - }; - -} Index: src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/generated/Parser.java =================================================================== --- src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/generated/Parser.java (revision 611544) +++ src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/generated/Parser.java (working copy) @@ -1,1398 +0,0 @@ -/* Generated By:JavaCC: Do not edit this line. Parser.java */ -package org.apache.hadoop.hbase.shell.generated; - -/** - * Copyright 2007 The Apache Software Foundation - * - * 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. - */ - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.HashMap; -import java.io.StringReader; -import java.io.Reader; -import java.io.Writer; -import java.net.URLEncoder; -import java.io.UnsupportedEncodingException; - -import org.apache.hadoop.hbase.shell.*; - -/** - * Parsing command line. - */ -public class Parser implements ParserConstants { - private String QueryString; - private TableFormatter formatter; - private Writer out; - private String secondR; - - public Parser(final String query, final Writer o, final TableFormatter f) { - this((Reader)(new StringReader(query))); - this.QueryString = query; - this.formatter = f; - this.out = o; - } - - public String getQueryStr() { - return this.QueryString; - } - -/** - * Parses the given array of command line arguments. - */ - final public Command terminatedCommand() throws ParseException { - Command statement = null; - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case HELP: - case ALTER: - case CLEAR: - case SHOW: - case DESCRIBE: - case DESC: - case CREATE: - case DROP: - case TRUNCATE: - case FS: - case JAR: - case EXIT: - case INSERT: - case DELETE: - case SELECT: - case ENABLE: - case DISABLE: - case 68: - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case HELP: - case ALTER: - case CLEAR: - case SHOW: - case DESCRIBE: - case DESC: - case CREATE: - case DROP: - case TRUNCATE: - case FS: - case JAR: - case EXIT: - case INSERT: - case DELETE: - case SELECT: - case ENABLE: - case DISABLE: - statement = cmdStatement(); - break; - default: - jj_la1[0] = jj_gen; - ; - } - jj_consume_token(68); - break; - case 0: - jj_consume_token(0); - break; - default: - jj_la1[1] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - {if (true) return statement;} - throw new Error("Missing return statement in function"); - } - - final public Command cmdStatement() throws ParseException { - Command cmd = null; - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case EXIT: - cmd = exitCommand(); - break; - case HELP: - cmd = helpCommand(); - break; - case SHOW: - cmd = showCommand(); - break; - case DESCRIBE: - case DESC: - cmd = descCommand(); - break; - case CREATE: - cmd = createCommand(); - break; - case DROP: - cmd = dropCommand(); - break; - case TRUNCATE: - cmd = truncateCommand(); - break; - case ALTER: - cmd = alterCommand(); - break; - case INSERT: - cmd = insertCommand(); - break; - case DELETE: - cmd = deleteCommand(); - break; - case SELECT: - cmd = selectCommand(); - break; - case ENABLE: - cmd = enableCommand(); - break; - case DISABLE: - cmd = disableCommand(); - break; - case CLEAR: - cmd = clearCommand(); - break; - case FS: - cmd = fsCommand(); - break; - case JAR: - cmd = jarCommand(); - break; - default: - jj_la1[2] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - {if (true) return cmd;} - throw new Error("Missing return statement in function"); - } - - final public ExitCommand exitCommand() throws ParseException { - ExitCommand exit = new ExitCommand(this.out); - jj_consume_token(EXIT); - {if (true) return exit;} - throw new Error("Missing return statement in function"); - } - - final public FsCommand fsCommand() throws ParseException { - Token t = null; - FsCommand fs = new FsCommand(this.out); - List query = new ArrayList(); - jj_consume_token(FS); - label_1: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case ID: - ; - break; - default: - jj_la1[3] = jj_gen; - break label_1; - } - t = jj_consume_token(ID); - query.add(t.image.toString()); - } - fs.setQuery(query); - {if (true) return fs;} - throw new Error("Missing return statement in function"); - } - - final public JarCommand jarCommand() throws ParseException { - Token t = null; - JarCommand jar = new JarCommand(this.out); - List query = new ArrayList(); - jj_consume_token(JAR); - label_2: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case ID: - case INTEGER_LITERAL: - case FLOATING_POINT_LITERAL: - ; - break; - default: - jj_la1[4] = jj_gen; - break label_2; - } - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case ID: - t = jj_consume_token(ID); - break; - case INTEGER_LITERAL: - t = jj_consume_token(INTEGER_LITERAL); - break; - case FLOATING_POINT_LITERAL: - t = jj_consume_token(FLOATING_POINT_LITERAL); - break; - default: - jj_la1[5] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - query.add(t.image.toString()); - } - jar.setQuery(query); - {if (true) return jar;} - throw new Error("Missing return statement in function"); - } - - final public TruncateCommand truncateCommand() throws ParseException { - TruncateCommand truncate = new TruncateCommand(this.out); - String tableName = null; - jj_consume_token(TRUNCATE); - jj_consume_token(TABLE); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case ID: - case QUOTED_IDENTIFIER: - case STRING_LITERAL: - tableName = identifier(); - break; - default: - jj_la1[6] = jj_gen; - ; - } - truncate.setTableName(tableName); - {if (true) return truncate;} - throw new Error("Missing return statement in function"); - } - - final public HelpCommand helpCommand() throws ParseException { - Token t = null; - HelpCommand help = new HelpCommand(this.out, this.formatter); - String argument = ""; - jj_consume_token(HELP); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case ALTER: - case CLEAR: - case SHOW: - case DESCRIBE: - case CREATE: - case DROP: - case FS: - case JAR: - case EXIT: - case INSERT: - case DELETE: - case SELECT: - case ID: - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case SHOW: - t = jj_consume_token(SHOW); - break; - case DESCRIBE: - t = jj_consume_token(DESCRIBE); - break; - case CREATE: - t = jj_consume_token(CREATE); - break; - case DROP: - t = jj_consume_token(DROP); - break; - case EXIT: - t = jj_consume_token(EXIT); - break; - case INSERT: - t = jj_consume_token(INSERT); - break; - case DELETE: - t = jj_consume_token(DELETE); - break; - case SELECT: - t = jj_consume_token(SELECT); - break; - case ALTER: - t = jj_consume_token(ALTER); - break; - case CLEAR: - t = jj_consume_token(CLEAR); - break; - case FS: - t = jj_consume_token(FS); - break; - case JAR: - t = jj_consume_token(JAR); - break; - case ID: - t = jj_consume_token(ID); - break; - default: - jj_la1[7] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - argument = t.image.toString(); - break; - default: - jj_la1[8] = jj_gen; - ; - } - help.setArgument(argument); - {if (true) return help;} - throw new Error("Missing return statement in function"); - } - - final public ShowCommand showCommand() throws ParseException { - ShowCommand show = new ShowCommand(this.out, this.formatter); - String argument = null; - jj_consume_token(SHOW); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case ID: - case QUOTED_IDENTIFIER: - case STRING_LITERAL: - argument = identifier(); - break; - default: - jj_la1[9] = jj_gen; - ; - } - show.setArgument(argument); - {if (true) return show;} - throw new Error("Missing return statement in function"); - } - - final public DescCommand descCommand() throws ParseException { - DescCommand desc = new DescCommand(this.out, this.formatter); - String argument = null; - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case DESCRIBE: - jj_consume_token(DESCRIBE); - break; - case DESC: - jj_consume_token(DESC); - break; - default: - jj_la1[10] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - argument = identifier(); - desc.setArgument(argument); - {if (true) return desc;} - throw new Error("Missing return statement in function"); - } - - final public Map ColumnSpec() throws ParseException { - Map columnSpec = new HashMap(); - int n = -1; - Token t = null; - label_3: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case MAX_VERSIONS: - case MAX_LENGTH: - case COMPRESSION: - case IN_MEMORY: - case BLOOMFILTER: - case VECTOR_SIZE: - case NUM_HASH: - case NUM_ENTRIES: - ; - break; - default: - jj_la1[11] = jj_gen; - break label_3; - } - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case MAX_VERSIONS: - jj_consume_token(MAX_VERSIONS); - jj_consume_token(EQUALS); - n = number(); - if(n < 0) { - n = Integer.MAX_VALUE; - } - columnSpec.put("MAX_VERSIONS", n); - break; - case MAX_LENGTH: - jj_consume_token(MAX_LENGTH); - jj_consume_token(EQUALS); - n = number(); - columnSpec.put("MAX_LENGTH", n); - break; - case COMPRESSION: - jj_consume_token(COMPRESSION); - jj_consume_token(EQUALS); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case NONE: - t = jj_consume_token(NONE); - break; - case BLOCK: - t = jj_consume_token(BLOCK); - break; - case RECORD: - t = jj_consume_token(RECORD); - break; - default: - jj_la1[12] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - columnSpec.put("COMPRESSION", t.image.toString()); - break; - case IN_MEMORY: - jj_consume_token(IN_MEMORY); - columnSpec.put("IN_MEMORY", true); - break; - case BLOOMFILTER: - jj_consume_token(BLOOMFILTER); - jj_consume_token(EQUALS); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case BLOOMFILTER: - t = jj_consume_token(BLOOMFILTER); - break; - case COUNTING_BLOOMFILTER: - t = jj_consume_token(COUNTING_BLOOMFILTER); - break; - case RETOUCHED_BLOOMFILTER: - t = jj_consume_token(RETOUCHED_BLOOMFILTER); - break; - default: - jj_la1[13] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - columnSpec.put("BLOOMFILTER", t.image.toString()); - break; - case VECTOR_SIZE: - jj_consume_token(VECTOR_SIZE); - jj_consume_token(EQUALS); - n = number(); - columnSpec.put("VECTOR_SIZE", n); - break; - case NUM_HASH: - jj_consume_token(NUM_HASH); - jj_consume_token(EQUALS); - n = number(); - columnSpec.put("NUM_HASH", n); - break; - case NUM_ENTRIES: - jj_consume_token(NUM_ENTRIES); - jj_consume_token(EQUALS); - n = number(); - columnSpec.put("NUM_ENTRIES", n); - break; - default: - jj_la1[14] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - } - {if (true) return columnSpec;} - throw new Error("Missing return statement in function"); - } - - final public CreateCommand createCommand() throws ParseException { - CreateCommand createCommand = new CreateCommand(this.out); - String table = null; - Map columnSpec = null; - String column = null; - jj_consume_token(CREATE); - jj_consume_token(TABLE); - table = identifier(); - createCommand.setTable(table); - jj_consume_token(LPAREN); - column = identifier(); - columnSpec = ColumnSpec(); - createCommand.addColumnSpec(column, columnSpec); - label_4: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case COMMA: - ; - break; - default: - jj_la1[15] = jj_gen; - break label_4; - } - jj_consume_token(COMMA); - column = identifier(); - columnSpec = ColumnSpec(); - createCommand.addColumnSpec(column, columnSpec); - } - jj_consume_token(RPAREN); - {if (true) return createCommand;} - throw new Error("Missing return statement in function"); - } - - final public AlterCommand alterCommand() throws ParseException { - AlterCommand alterCommand = new AlterCommand(this.out); - String table = null; - String column = null; - Map columnSpec = null; - jj_consume_token(ALTER); - jj_consume_token(TABLE); - table = identifier(); - alterCommand.setTable(table); - if (jj_2_1(2)) { - jj_consume_token(ADD); - column = identifier(); - columnSpec = ColumnSpec(); - alterCommand.setOperationType(AlterCommand.OperationType.ADD); - alterCommand.addColumnSpec(column, columnSpec); - } else { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case ADD: - jj_consume_token(ADD); - jj_consume_token(LPAREN); - alterCommand.setOperationType(AlterCommand.OperationType.ADD); - column = identifier(); - columnSpec = ColumnSpec(); - alterCommand.addColumnSpec(column, columnSpec); - label_5: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case COMMA: - ; - break; - default: - jj_la1[16] = jj_gen; - break label_5; - } - jj_consume_token(COMMA); - column = identifier(); - columnSpec = ColumnSpec(); - alterCommand.addColumnSpec(column, columnSpec); - } - jj_consume_token(RPAREN); - break; - case DROP: - jj_consume_token(DROP); - column = identifier(); - alterCommand.setOperationType(AlterCommand.OperationType.DROP); - alterCommand.setColumn(column); - break; - case CHANGE: - jj_consume_token(CHANGE); - column = identifier(); - columnSpec = ColumnSpec(); - alterCommand.setOperationType(AlterCommand.OperationType.CHANGE); - alterCommand.addColumnSpec(column, columnSpec); - break; - default: - jj_la1[17] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - } - {if (true) return alterCommand;} - throw new Error("Missing return statement in function"); - } - - final public DropCommand dropCommand() throws ParseException { - DropCommand drop = new DropCommand(this.out); - List tableList = null; - jj_consume_token(DROP); - jj_consume_token(TABLE); - tableList = tableList(); - drop.setTableList(tableList); - {if (true) return drop;} - throw new Error("Missing return statement in function"); - } - - final public InsertCommand insertCommand() throws ParseException { - InsertCommand in = new InsertCommand(this.out); - List columnfamilies = null; - List values = null; - String table = null; - String timestamp = null; - Token t = null; - jj_consume_token(INSERT); - jj_consume_token(INTO); - table = identifier(); - in.setTable(table); - columnfamilies = getColumns(); - in.setColumnfamilies(columnfamilies); - jj_consume_token(VALUES); - values = getLiteralValues(); - in.setValues(values); - jj_consume_token(WHERE); - jj_consume_token(ROW); - jj_consume_token(EQUALS); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case STRING_LITERAL: - t = jj_consume_token(STRING_LITERAL); - break; - case QUOTED_IDENTIFIER: - t = jj_consume_token(QUOTED_IDENTIFIER); - break; - default: - jj_la1[18] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - in.setRow(t.image.substring(1, t.image.length()-1)); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case TIMESTAMP: - jj_consume_token(TIMESTAMP); - timestamp = getStringLiteral(); - in.setTimestamp(timestamp); - break; - default: - jj_la1[19] = jj_gen; - ; - } - {if (true) return in;} - throw new Error("Missing return statement in function"); - } - - final public DeleteCommand deleteCommand() throws ParseException { - DeleteCommand deleteCommand = new DeleteCommand(this.out); - List columnList = null; - Token t = null; - String table = null; - jj_consume_token(DELETE); - columnList = columnList(); - deleteCommand.setColumnList(columnList); - jj_consume_token(FROM); - table = identifier(); - deleteCommand.setTable(table); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case WHERE: - jj_consume_token(WHERE); - jj_consume_token(ROW); - jj_consume_token(EQUALS); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case STRING_LITERAL: - t = jj_consume_token(STRING_LITERAL); - break; - case QUOTED_IDENTIFIER: - t = jj_consume_token(QUOTED_IDENTIFIER); - break; - default: - jj_la1[20] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - deleteCommand.setRow(t.image.substring(1, t.image.length()-1)); - break; - default: - jj_la1[21] = jj_gen; - ; - } - {if (true) return deleteCommand;} - throw new Error("Missing return statement in function"); - } - - final public SelectCommand selectCommand() throws ParseException { - SelectCommand select = new SelectCommand(this.out, this.formatter); - List columns = null; - String rowKey = ""; - String stopRow = ""; - String timestamp = null; - int numVersion = 0; - String tableName = null; - int limit; - jj_consume_token(SELECT); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case COUNT: - jj_consume_token(COUNT); - columns = getLiteralValues(); - select.setCountFunction(true); - break; - case ASTERISK: - case ID: - case INTEGER_LITERAL: - case QUOTED_IDENTIFIER: - case STRING_LITERAL: - columns = columnList(); - break; - default: - jj_la1[22] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - jj_consume_token(FROM); - tableName = identifier(); - select.setColumns(columns); - select.setTable(tableName); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case STARTING: - case WHERE: - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case WHERE: - jj_consume_token(WHERE); - jj_consume_token(ROW); - jj_consume_token(EQUALS); - select.setWhere(true); - break; - case STARTING: - jj_consume_token(STARTING); - jj_consume_token(FROM); - break; - default: - jj_la1[23] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - rowKey = getStringLiteral(); - select.setRowKey(rowKey); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case UNTIL: - jj_consume_token(UNTIL); - stopRow = getStringLiteral(); - select.setStopRow(stopRow); - break; - default: - jj_la1[24] = jj_gen; - ; - } - break; - default: - jj_la1[25] = jj_gen; - ; - } - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case TIMESTAMP: - jj_consume_token(TIMESTAMP); - timestamp = getStringLiteral(); - select.setTimestamp(timestamp); - break; - default: - jj_la1[26] = jj_gen; - ; - } - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case NUM_VERSIONS: - jj_consume_token(NUM_VERSIONS); - jj_consume_token(EQUALS); - numVersion = number(); - select.setVersion(numVersion); - break; - default: - jj_la1[27] = jj_gen; - ; - } - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case LIMIT: - jj_consume_token(LIMIT); - jj_consume_token(EQUALS); - limit = number(); - try{ - select.setLimit(limit); - }catch(ClassCastException ce) { - {if (true) throw generateParseException();} - } - break; - default: - jj_la1[28] = jj_gen; - ; - } - {if (true) return select;} - throw new Error("Missing return statement in function"); - } - - final public EnableCommand enableCommand() throws ParseException { - EnableCommand enableCommand = new EnableCommand(this.out); - String table = null; - jj_consume_token(ENABLE); - table = identifier(); - enableCommand.setTable(table); - {if (true) return enableCommand;} - throw new Error("Missing return statement in function"); - } - - final public DisableCommand disableCommand() throws ParseException { - DisableCommand disableCommand = new DisableCommand(this.out); - String table = null; - jj_consume_token(DISABLE); - table = identifier(); - disableCommand.setTable(table); - {if (true) return disableCommand;} - throw new Error("Missing return statement in function"); - } - - final public ClearCommand clearCommand() throws ParseException { - ClearCommand clear = new ClearCommand(this.out); - jj_consume_token(CLEAR); - {if (true) return clear;} - throw new Error("Missing return statement in function"); - } - - final public List getLiteralValues() throws ParseException { - List values = new ArrayList(); - String literal = null; - jj_consume_token(LPAREN); - literal = getStringLiteral(); - if(literal != null) values.add(literal); - label_6: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case COMMA: - ; - break; - default: - jj_la1[29] = jj_gen; - break label_6; - } - jj_consume_token(COMMA); - literal = getStringLiteral(); - if(literal != null) values.add(literal); - } - jj_consume_token(RPAREN); - {if (true) return values;} - throw new Error("Missing return statement in function"); - } - - final public String getStringLiteral() throws ParseException { - Token s; - String value = null; - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case QUOTED_IDENTIFIER: - case STRING_LITERAL: - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case STRING_LITERAL: - s = jj_consume_token(STRING_LITERAL); - break; - case QUOTED_IDENTIFIER: - s = jj_consume_token(QUOTED_IDENTIFIER); - break; - default: - jj_la1[30] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - value = s.image.toString(); - {if (true) return value.substring(1,value.length() - 1);} - break; - case ASTERISK: - case ID: - case INTEGER_LITERAL: - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case ID: - s = jj_consume_token(ID); - break; - case INTEGER_LITERAL: - s = jj_consume_token(INTEGER_LITERAL); - break; - case ASTERISK: - s = jj_consume_token(ASTERISK); - break; - default: - jj_la1[31] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - value = s.image.toString(); - {if (true) return value;} - break; - default: - jj_la1[32] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - throw new Error("Missing return statement in function"); - } - - final public String getColumn() throws ParseException { - Token col; - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case ASTERISK: - case ID: - case INTEGER_LITERAL: - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case ID: - col = jj_consume_token(ID); - break; - case INTEGER_LITERAL: - col = jj_consume_token(INTEGER_LITERAL); - break; - case ASTERISK: - col = jj_consume_token(ASTERISK); - break; - default: - jj_la1[33] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - {if (true) return col.image.toString();} - break; - case QUOTED_IDENTIFIER: - case STRING_LITERAL: - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case QUOTED_IDENTIFIER: - col = jj_consume_token(QUOTED_IDENTIFIER); - break; - case STRING_LITERAL: - col = jj_consume_token(STRING_LITERAL); - break; - default: - jj_la1[34] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - {if (true) return col.image.substring(1,col.image.toString().length() - 1);} - break; - default: - jj_la1[35] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - throw new Error("Missing return statement in function"); - } - - final public List getColumns() throws ParseException { - List values = new ArrayList(); - String literal = null; - jj_consume_token(LPAREN); - literal = getColumn(); - if(literal != null) values.add(literal); - label_7: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case COMMA: - ; - break; - default: - jj_la1[36] = jj_gen; - break label_7; - } - jj_consume_token(COMMA); - literal = getColumn(); - if(literal != null) values.add(literal); - } - jj_consume_token(RPAREN); - {if (true) return values;} - throw new Error("Missing return statement in function"); - } - - final public List tableList() throws ParseException { - List tableList = new ArrayList(); - String table = null; - table = identifier(); - tableList.add(table); - label_8: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case COMMA: - ; - break; - default: - jj_la1[37] = jj_gen; - break label_8; - } - jj_consume_token(COMMA); - table = identifier(); - tableList.add(table); - } - {if (true) return tableList;} - throw new Error("Missing return statement in function"); - } - - final public List columnList() throws ParseException { - List columnList = new ArrayList(); - String column = null; - column = getColumn(); - if(column != null) { - columnList.add(column); - } else { - {if (true) return columnList;} - } - label_9: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case COMMA: - ; - break; - default: - jj_la1[38] = jj_gen; - break label_9; - } - jj_consume_token(COMMA); - column = getColumn(); - columnList.add(column); - } - {if (true) return columnList;} - throw new Error("Missing return statement in function"); - } - - final public int number() throws ParseException { - Token t = null; - Token minusSignedInt = null; - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case ID: - minusSignedInt = jj_consume_token(ID); - break; - case INTEGER_LITERAL: - t = jj_consume_token(INTEGER_LITERAL); - break; - default: - jj_la1[39] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - if(minusSignedInt != null) { - {if (true) return Integer.parseInt(minusSignedInt.image.toString());} - } else { - {if (true) return Integer.parseInt(t.image.toString());} - } - throw new Error("Missing return statement in function"); - } - - final public String identifier() throws ParseException { - Token t = null; - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case ID: - t = jj_consume_token(ID); - {if (true) return t.image.toString();} - break; - case QUOTED_IDENTIFIER: - case STRING_LITERAL: - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case QUOTED_IDENTIFIER: - t = jj_consume_token(QUOTED_IDENTIFIER); - break; - case STRING_LITERAL: - t = jj_consume_token(STRING_LITERAL); - break; - default: - jj_la1[40] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - {if (true) return t.image.substring(1,t.image.toString().length() - 1);} - break; - default: - jj_la1[41] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - throw new Error("Missing return statement in function"); - } - - final public String appendIndicator(String columnName) throws ParseException { - String column = columnName; - {if (true) return (!column.endsWith(":") && column.indexOf(":") == -1) - ? column + ":" : column;} - throw new Error("Missing return statement in function"); - } - - final private boolean jj_2_1(int xla) { - jj_la = xla; jj_lastpos = jj_scanpos = token; - try { return !jj_3_1(); } - catch(LookaheadSuccess ls) { return true; } - finally { jj_save(0, xla); } - } - - final private boolean jj_3R_10() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_11()) { - jj_scanpos = xsp; - if (jj_3R_12()) return true; - } - return false; - } - - final private boolean jj_3_1() { - if (jj_scan_token(ADD)) return true; - if (jj_3R_10()) return true; - return false; - } - - final private boolean jj_3R_12() { - Token xsp; - xsp = jj_scanpos; - if (jj_scan_token(66)) { - jj_scanpos = xsp; - if (jj_scan_token(67)) return true; - } - return false; - } - - final private boolean jj_3R_11() { - if (jj_scan_token(ID)) return true; - return false; - } - - public ParserTokenManager token_source; - SimpleCharStream jj_input_stream; - public Token token, jj_nt; - private int jj_ntk; - private Token jj_scanpos, jj_lastpos; - private int jj_la; - public boolean lookingAhead = false; - private boolean jj_semLA; - private int jj_gen; - final private int[] jj_la1 = new int[42]; - static private int[] jj_la1_0; - static private int[] jj_la1_1; - static private int[] jj_la1_2; - static { - jj_la1_0(); - jj_la1_1(); - jj_la1_2(); - } - private static void jj_la1_0() { - jj_la1_0 = new int[] {0xf3ffe0,0xf3ffe1,0xf3ffe0,0x0,0x0,0x0,0x0,0x33dbc0,0x33dbc0,0x0,0x600,0x0,0x0,0x0,0x0,0x0,0x0,0x1000,0x0,0x80000000,0x0,0x2000000,0x0,0x3000000,0x8000000,0x3000000,0x80000000,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,}; - } - private static void jj_la1_1() { - jj_la1_1 = new int[] {0x0,0x0,0x0,0x40000000,0xc0000000,0xc0000000,0x40000000,0x40000000,0x40000000,0x40000000,0x0,0x731c000,0xe0000,0xe00000,0x731c000,0x10,0x10,0x18000000,0x0,0x0,0x0,0x0,0xe0002000,0x0,0x0,0x0,0x0,0x1,0x2,0x10,0x0,0xc0002000,0xc0002000,0xc0002000,0x0,0xc0002000,0x10,0x10,0x10,0xc0000000,0x0,0x40000000,}; - } - private static void jj_la1_2() { - jj_la1_2 = new int[] {0x0,0x10,0x0,0x0,0x1,0x1,0xc,0x0,0x0,0xc,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xc,0x0,0xc,0x0,0xc,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xc,0x0,0xc,0x0,0xc,0xc,0x0,0x0,0x0,0x0,0xc,0xc,}; - } - final private JJCalls[] jj_2_rtns = new JJCalls[1]; - private boolean jj_rescan = false; - private int jj_gc = 0; - - public Parser(java.io.InputStream stream) { - this(stream, null); - } - public Parser(java.io.InputStream stream, String encoding) { - try { jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); } - token_source = new ParserTokenManager(jj_input_stream); - token = new Token(); - jj_ntk = -1; - jj_gen = 0; - for (int i = 0; i < 42; i++) jj_la1[i] = -1; - for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); - } - - public void ReInit(java.io.InputStream stream) { - ReInit(stream, null); - } - public void ReInit(java.io.InputStream stream, String encoding) { - try { jj_input_stream.ReInit(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); } - token_source.ReInit(jj_input_stream); - token = new Token(); - jj_ntk = -1; - jj_gen = 0; - for (int i = 0; i < 42; i++) jj_la1[i] = -1; - for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); - } - - public Parser(java.io.Reader stream) { - jj_input_stream = new SimpleCharStream(stream, 1, 1); - token_source = new ParserTokenManager(jj_input_stream); - token = new Token(); - jj_ntk = -1; - jj_gen = 0; - for (int i = 0; i < 42; i++) jj_la1[i] = -1; - for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); - } - - public void ReInit(java.io.Reader stream) { - jj_input_stream.ReInit(stream, 1, 1); - token_source.ReInit(jj_input_stream); - token = new Token(); - jj_ntk = -1; - jj_gen = 0; - for (int i = 0; i < 42; i++) jj_la1[i] = -1; - for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); - } - - public Parser(ParserTokenManager tm) { - token_source = tm; - token = new Token(); - jj_ntk = -1; - jj_gen = 0; - for (int i = 0; i < 42; i++) jj_la1[i] = -1; - for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); - } - - public void ReInit(ParserTokenManager tm) { - token_source = tm; - token = new Token(); - jj_ntk = -1; - jj_gen = 0; - for (int i = 0; i < 42; i++) jj_la1[i] = -1; - for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); - } - - final private Token jj_consume_token(int kind) throws ParseException { - Token oldToken; - if ((oldToken = token).next != null) token = token.next; - else token = token.next = token_source.getNextToken(); - jj_ntk = -1; - if (token.kind == kind) { - jj_gen++; - if (++jj_gc > 100) { - jj_gc = 0; - for (int i = 0; i < jj_2_rtns.length; i++) { - JJCalls c = jj_2_rtns[i]; - while (c != null) { - if (c.gen < jj_gen) c.first = null; - c = c.next; - } - } - } - return token; - } - token = oldToken; - jj_kind = kind; - throw generateParseException(); - } - - static private final class LookaheadSuccess extends java.lang.Error { } - final private LookaheadSuccess jj_ls = new LookaheadSuccess(); - final private boolean jj_scan_token(int kind) { - if (jj_scanpos == jj_lastpos) { - jj_la--; - if (jj_scanpos.next == null) { - jj_lastpos = jj_scanpos = jj_scanpos.next = token_source.getNextToken(); - } else { - jj_lastpos = jj_scanpos = jj_scanpos.next; - } - } else { - jj_scanpos = jj_scanpos.next; - } - if (jj_rescan) { - int i = 0; Token tok = token; - while (tok != null && tok != jj_scanpos) { i++; tok = tok.next; } - if (tok != null) jj_add_error_token(kind, i); - } - if (jj_scanpos.kind != kind) return true; - if (jj_la == 0 && jj_scanpos == jj_lastpos) throw jj_ls; - return false; - } - - final public Token getNextToken() { - if (token.next != null) token = token.next; - else token = token.next = token_source.getNextToken(); - jj_ntk = -1; - jj_gen++; - return token; - } - - final public Token getToken(int index) { - Token t = lookingAhead ? jj_scanpos : token; - for (int i = 0; i < index; i++) { - if (t.next != null) t = t.next; - else t = t.next = token_source.getNextToken(); - } - return t; - } - - final private int jj_ntk() { - if ((jj_nt=token.next) == null) - return (jj_ntk = (token.next=token_source.getNextToken()).kind); - else - return (jj_ntk = jj_nt.kind); - } - - private java.util.Vector jj_expentries = new java.util.Vector(); - private int[] jj_expentry; - private int jj_kind = -1; - private int[] jj_lasttokens = new int[100]; - private int jj_endpos; - - private void jj_add_error_token(int kind, int pos) { - if (pos >= 100) return; - if (pos == jj_endpos + 1) { - jj_lasttokens[jj_endpos++] = kind; - } else if (jj_endpos != 0) { - jj_expentry = new int[jj_endpos]; - for (int i = 0; i < jj_endpos; i++) { - jj_expentry[i] = jj_lasttokens[i]; - } - boolean exists = false; - for (java.util.Enumeration e = jj_expentries.elements(); e.hasMoreElements();) { - int[] oldentry = (int[])(e.nextElement()); - if (oldentry.length == jj_expentry.length) { - exists = true; - for (int i = 0; i < jj_expentry.length; i++) { - if (oldentry[i] != jj_expentry[i]) { - exists = false; - break; - } - } - if (exists) break; - } - } - if (!exists) jj_expentries.addElement(jj_expentry); - if (pos != 0) jj_lasttokens[(jj_endpos = pos) - 1] = kind; - } - } - - public ParseException generateParseException() { - jj_expentries.removeAllElements(); - boolean[] la1tokens = new boolean[69]; - for (int i = 0; i < 69; i++) { - la1tokens[i] = false; - } - if (jj_kind >= 0) { - la1tokens[jj_kind] = true; - jj_kind = -1; - } - for (int i = 0; i < 42; i++) { - if (jj_la1[i] == jj_gen) { - for (int j = 0; j < 32; j++) { - if ((jj_la1_0[i] & (1< jj_gen) { - jj_la = p.arg; jj_lastpos = jj_scanpos = p.first; - switch (i) { - case 0: jj_3_1(); break; - } - } - p = p.next; - } while (p != null); - } catch(LookaheadSuccess ls) { } - } - jj_rescan = false; - } - - final private void jj_save(int index, int xla) { - JJCalls p = jj_2_rtns[index]; - while (p.gen > jj_gen) { - if (p.next == null) { p = p.next = new JJCalls(); break; } - p = p.next; - } - p.gen = jj_gen + xla - jj_la; p.first = token; p.arg = xla; - } - - static final class JJCalls { - int gen; - Token first; - int arg; - JJCalls next; - } - -} Index: src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/Command.java =================================================================== --- src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/Command.java (revision 611544) +++ src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/Command.java (working copy) @@ -1,45 +0,0 @@ -/** - * Copyright 2007 The Apache Software Foundation - * - * 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.hadoop.hbase.shell; - -import org.apache.hadoop.hbase.HBaseConfiguration; - -public interface Command { - /** family indicator */ - public static final String FAMILY_INDICATOR = ":"; - - public enum CommandType { - DDL, UPDATE, SELECT, INSERT, DELETE, SHELL - } - - /** - * Execute a command - * - * @param conf Configuration - * @return Result of command execution - */ - public ReturnMsg execute(final HBaseConfiguration conf); - - /** - * @return Type of this command whether DDL, SELECT, INSERT, UPDATE, DELETE, - * or SHELL. - */ - public CommandType getCommandType(); -} Index: src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/SelectCommand.java =================================================================== --- src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/SelectCommand.java (revision 611544) +++ src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/SelectCommand.java (working copy) @@ -1,385 +0,0 @@ -/** - * Copyright 2007 The Apache Software Foundation - * - * 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.hadoop.hbase.shell; - -import java.io.IOException; -import java.io.OutputStreamWriter; -import java.io.Writer; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.TreeMap; - -import org.apache.hadoop.hbase.HBaseAdmin; -import org.apache.hadoop.hbase.HBaseConfiguration; -import org.apache.hadoop.hbase.HConnection; -import org.apache.hadoop.hbase.HConnectionManager; -import org.apache.hadoop.hbase.HConstants; -import org.apache.hadoop.hbase.HScannerInterface; -import org.apache.hadoop.hbase.HStoreKey; -import org.apache.hadoop.hbase.HTable; -import org.apache.hadoop.hbase.HTableDescriptor; -import org.apache.hadoop.hbase.Shell; -import org.apache.hadoop.hbase.filter.RowFilterInterface; -import org.apache.hadoop.hbase.filter.StopRowFilter; -import org.apache.hadoop.hbase.filter.WhileMatchRowFilter; -import org.apache.hadoop.hbase.shell.generated.Parser; -import org.apache.hadoop.hbase.util.Writables; -import org.apache.hadoop.io.Text; - -/** - * Selects values from tables. - */ -public class SelectCommand extends BasicCommand { - private Text tableName; - private Text rowKey = new Text(""); - private Text stopRow = new Text(""); - private List columns; - private long timestamp; - private int limit; - // Count of versions to return. - private int version; - private boolean countFunction = false; - private boolean whereClause = false; - private static final String[] HEADER_ROW_CELL = new String[] { "Row", "Cell" }; - private static final String[] HEADER_COLUMN_CELL = new String[] { "Column", "Cell" }; - private static final String[] HEADER = new String[] { "Row", "Column", "Cell" }; - private static final String ASTERISK = "*"; - - private final TableFormatter formatter; - - // Not instantiable - @SuppressWarnings("unused") - private SelectCommand() { - this(null, null); - } - - public SelectCommand(final Writer o, final TableFormatter f) { - super(o); - this.formatter = f; - } - - public ReturnMsg execute(final HBaseConfiguration conf) { - if (tableName.equals("") || rowKey == null || columns.size() == 0) { - return new ReturnMsg(0, "Syntax error : Please check 'Select' syntax."); - } - try { - HConnection conn = HConnectionManager.getConnection(conf); - if (!conn.tableExists(tableName) && !isMetaTable()) { - return new ReturnMsg(0, "'" + tableName + "'" + TABLE_NOT_FOUND); - } - - HTable table = new HTable(conf, tableName); - HBaseAdmin admin = new HBaseAdmin(conf); - int count = 0; - if (whereClause) { - if (countFunction) { - count = 1; - } else { - count = compoundWherePrint(table, admin); - } - } else { - count = scanPrint(table, admin); - } - return new ReturnMsg(1, Integer.toString(count) + " row(s) in set."); - } catch (IOException e) { - String[] msg = e.getMessage().split("[,]"); - return new ReturnMsg(0, msg[0]); - } - } - - private boolean isMetaTable() { - return (tableName.equals(HConstants.ROOT_TABLE_NAME) || tableName - .equals(HConstants.META_TABLE_NAME)) ? true : false; - } - - private int compoundWherePrint(HTable table, HBaseAdmin admin) { - int count = 0; - try { - if (version != 0) { - // A number of versions has been specified. - byte[][] result = null; - ParsedColumns parsedColumns = getColumns(admin, false); - boolean multiple = parsedColumns.isMultiple() || version > 1; - for (Text column : parsedColumns.getColumns()) { - if (count == 0) { - formatter.header(multiple ? HEADER_COLUMN_CELL : null); - } - if (timestamp != 0) { - result = table.get(rowKey, column, timestamp, version); - } else { - result = table.get(rowKey, column, version); - } - for (int ii = 0; result != null && ii < result.length; ii++) { - if (multiple) { - formatter.row(new String[] { column.toString(), - toString(column, result[ii]) }); - } else { - formatter.row(new String[] { toString(column, result[ii]) }); - } - count++; - } - } - } else { - for (Map.Entry e : table.getRow(rowKey).entrySet()) { - if (count == 0) { - formatter.header(isMultiple() ? HEADER_COLUMN_CELL : null); - } - Text key = e.getKey(); - String keyStr = key.toString(); - if (!columns.contains(ASTERISK) && !columns.contains(keyStr)) { - continue; - } - String cellData = toString(key, e.getValue()); - if (isMultiple()) { - formatter.row(new String[] { key.toString(), cellData }); - } else { - formatter.row(new String[] { cellData }); - } - count++; - } - } - - if (count == 0 && Shell.HTML_OPTION != null) { - formatter.header(isMultiple() ? HEADER_COLUMN_CELL : null); - } - formatter.footer(); - } catch (IOException e) { - e.printStackTrace(); - } - return 1; - } - - private String toString(final Text columnName, final byte[] cell) - throws IOException { - String result = null; - if (columnName.equals(HConstants.COL_REGIONINFO) - || columnName.equals(HConstants.COL_SPLITA) - || columnName.equals(HConstants.COL_SPLITA)) { - result = Writables.getHRegionInfoOrNull(cell).toString(); - } else if (columnName.equals(HConstants.COL_STARTCODE)) { - result = Long.toString(Writables.bytesToLong(cell)); - } else { - result = Writables.bytesToString(cell); - } - return result; - } - - /** - * Data structure with columns to use scanning and whether or not the scan - * could return more than one column. - */ - class ParsedColumns { - private final List cols; - private final boolean isMultiple; - - ParsedColumns(final List columns) { - this(columns, true); - } - - ParsedColumns(final List columns, final boolean isMultiple) { - this.cols = columns; - this.isMultiple = isMultiple; - } - - public List getColumns() { - return this.cols; - } - - public boolean isMultiple() { - return this.isMultiple; - } - } - - private int scanPrint(HTable table, HBaseAdmin admin) { - int count = 0; - HScannerInterface scan = null; - try { - ParsedColumns parsedColumns = getColumns(admin, true); - Text[] cols = parsedColumns.getColumns().toArray(new Text[] {}); - if (timestamp == 0) { - scan = table.obtainScanner(cols, rowKey); - } else { - scan = table.obtainScanner(cols, rowKey, timestamp); - } - - if (this.stopRow.toString().length() > 0) { - RowFilterInterface filter = new WhileMatchRowFilter(new StopRowFilter( - stopRow)); - scan = table.obtainScanner(cols, rowKey, filter); - } - - HStoreKey key = new HStoreKey(); - TreeMap results = new TreeMap(); - // If only one column in query, then don't print out the column. - while (scan.next(key, results) && checkLimit(count)) { - if (count == 0 && !countFunction) { - formatter.header((parsedColumns.isMultiple()) ? HEADER : HEADER_ROW_CELL); - } - - Text r = key.getRow(); - - if (!countFunction) { - for (Text columnKey : results.keySet()) { - String cellData = toString(columnKey, results.get(columnKey)); - if (parsedColumns.isMultiple()) { - formatter.row(new String[] { r.toString(), columnKey.toString(), - cellData }); - } else { - // Don't print out the column since only one specified in query. - formatter.row(new String[] { r.toString(), cellData }); - } - if (limit > 0 && count >= limit) { - break; - } - } - } - - count++; - // Clear results else subsequent results polluted w/ previous finds. - results.clear(); - } - - if (count == 0 && Shell.HTML_OPTION != null && !countFunction) { - formatter.header((parsedColumns.isMultiple()) ? HEADER : HEADER_ROW_CELL); - } - - formatter.footer(); - scan.close(); - } catch (IOException e) { - e.printStackTrace(); - } - return count; - } - - /** - * Make sense of the supplied list of columns. - * - * @param admin Admin to use. - * @return Interpretation of supplied list of columns. - */ - public ParsedColumns getColumns(final HBaseAdmin admin, final boolean scanning) { - ParsedColumns result = null; - try { - if (columns.contains(ASTERISK)) { - if (tableName.equals(HConstants.ROOT_TABLE_NAME) - || tableName.equals(HConstants.META_TABLE_NAME)) { - result = new ParsedColumns(Arrays.asList(HConstants.COLUMN_FAMILY_ARRAY)); - } else { - HTableDescriptor[] tables = admin.listTables(); - for (int i = 0; i < tables.length; i++) { - if (tables[i].getName().equals(tableName)) { - result = new ParsedColumns(new ArrayList(tables[i].families() - .keySet())); - break; - } - } - } - } else { - List tmpList = new ArrayList(); - for (int i = 0; i < columns.size(); i++) { - Text column = null; - // Add '$' to column name if we are scanning. Scanners support - // regex column names. Adding '$', the column becomes a - // regex that does an explicit match on the supplied column name. - // Otherwise, if the specified column is a column family, then - // default behavior is to fetch all columns that have a matching - // column family. - column = (columns.get(i).contains(":")) ? new Text(columns.get(i) - + (scanning ? "$" : "")) : new Text(columns.get(i) + ":" - + (scanning ? "$" : "")); - tmpList.add(column); - } - result = new ParsedColumns(tmpList, tmpList.size() > 1); - } - } catch (IOException e) { - e.printStackTrace(); - } - return result; - } - - /* - * @return True if query contains multiple columns. - */ - private boolean isMultiple() { - return this.columns.size() > 1 || this.columns.contains(ASTERISK); - } - - private boolean checkLimit(int count) { - return (this.limit == 0) ? true : (this.limit > count) ? true : false; - } - - public void setTable(String table) { - this.tableName = new Text(table); - } - - public void setLimit(int limit) { - this.limit = limit; - } - - public void setWhere(boolean isWhereClause) { - if (isWhereClause) - this.whereClause = true; - } - - public void setTimestamp(String timestamp) { - this.timestamp = Long.parseLong(timestamp); - } - - public void setColumns(List columns) { - this.columns = columns; - } - - public void setRowKey(String rowKey) { - if (rowKey == null) - this.rowKey = null; - else - this.rowKey = new Text(rowKey); - } - - public void setCountFunction(boolean countFunction) { - this.countFunction = countFunction; - } - - public void setStopRow(String stopRow) { - this.stopRow = new Text(stopRow); - } - - /** - * @param version Set maximum versions for this selection - */ - public void setVersion(int version) { - this.version = version; - } - - public static void main(String[] args) throws Exception { - Writer out = new OutputStreamWriter(System.out, "UTF-8"); - HBaseConfiguration c = new HBaseConfiguration(); - // For debugging - TableFormatterFactory tff = new TableFormatterFactory(out, c); - Parser parser = new Parser("select * from 'x' where row='x';", out, tff.get()); - Command cmd = parser.terminatedCommand(); - - ReturnMsg rm = cmd.execute(c); - out.write(rm == null ? "" : rm.toString()); - out.flush(); - } -} Index: src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/ShowCommand.java =================================================================== --- src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/ShowCommand.java (revision 611544) +++ src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/ShowCommand.java (working copy) @@ -1,81 +0,0 @@ -/** - * Copyright 2007 The Apache Software Foundation - * - * 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.hadoop.hbase.shell; - -import java.io.IOException; -import java.io.Writer; - -import org.apache.hadoop.hbase.HBaseAdmin; -import org.apache.hadoop.hbase.HBaseConfiguration; -import org.apache.hadoop.hbase.HTableDescriptor; - -/** - * Shows all available tables. - */ -public class ShowCommand extends BasicCommand { - private static final String[] HEADER = new String[] { "Name", "Descriptor" }; - private String command; - private final TableFormatter formatter; - - // Not instantiable - @SuppressWarnings("unused") - private ShowCommand() { - this(null, null); - } - - public ShowCommand(final Writer o, final TableFormatter f) { - this(o, f, null); - } - - public ShowCommand(final Writer o, final TableFormatter f, - final String argument) { - super(o); - this.formatter = f; - this.command = argument; - } - - public ReturnMsg execute(final HBaseConfiguration conf) { - if (command == null) { - return new ReturnMsg(0, "Syntax error : Please check 'Show' syntax."); - } - try { - HBaseAdmin admin = new HBaseAdmin(conf); - int tableLength = 0; - HTableDescriptor[] tables = admin.listTables(); - tableLength = tables.length; - if (tableLength == 0) { - return new ReturnMsg(0, "No tables found."); - } - formatter.header(HEADER); - for (int i = 0; i < tableLength; i++) { - String tableName = tables[i].getName().toString(); - formatter.row(new String[] { tableName, tables[i].toString() }); - } - formatter.footer(); - return new ReturnMsg(1, tableLength + " table(s) in set."); - } catch (IOException e) { - return new ReturnMsg(0, "error msg : " + e.toString()); - } - } - - public void setArgument(String argument) { - this.command = argument; - } -} Index: src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/BasicCommand.java =================================================================== --- src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/BasicCommand.java (revision 611544) +++ src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/BasicCommand.java (working copy) @@ -1,100 +0,0 @@ -/** - * Copyright 2007 The Apache Software Foundation - * - * 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.hadoop.hbase.shell; - -import java.io.IOException; -import java.io.Writer; - -/** - * Takes the lowest-common-denominator {@link Writer} doing its own printlns, - * etc. - * - * @see HBaseShell - */ -public abstract class BasicCommand implements Command, CommandFactory { - private final Writer out; - public final String LINE_SEPARATOR = System.getProperty("line.separator"); - public final String TABLE_NOT_FOUND = " is non-existant table."; - - // Shutdown constructor. - @SuppressWarnings("unused") - private BasicCommand() { - this(null); - } - - /** - * Constructor - * - * @param o A Writer. - */ - public BasicCommand(final Writer o) { - this.out = o; - } - - public BasicCommand getBasicCommand() { - return this; - } - - /** basic commands are their own factories. */ - public Command getCommand() { - return this; - } - - protected String extractErrMsg(String msg) { - int index = msg.indexOf(":"); - int eofIndex = msg.indexOf("\n"); - return msg.substring(index + 1, eofIndex); - } - - protected String extractErrMsg(Exception e) { - return extractErrMsg(e.getMessage()); - } - - /** - * Appends, if it does not exist, a delimiter (colon) at the end of the column - * name. - */ - protected String appendDelimiter(String column) { - return (!column.endsWith(FAMILY_INDICATOR) && column - .indexOf(FAMILY_INDICATOR) == -1) ? column + FAMILY_INDICATOR : column; - } - - /** - * @return Writer to use outputting. - */ - public Writer getOut() { - return this.out; - } - - public void print(final String msg) throws IOException { - this.out.write(msg); - } - - public void println(final String msg) throws IOException { - print(msg); - print(LINE_SEPARATOR); - this.out.flush(); - } - - public CommandType getCommandType() { - return CommandType.SELECT; - } -} Index: src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/formatter/HtmlTableFormatter.java =================================================================== --- src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/formatter/HtmlTableFormatter.java (revision 611544) +++ src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/formatter/HtmlTableFormatter.java (working copy) @@ -1,183 +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.hadoop.hbase.shell.formatter; - -import java.io.IOException; -import java.io.OutputStreamWriter; -import java.io.UnsupportedEncodingException; -import java.io.Writer; - -import org.apache.hadoop.hbase.shell.TableFormatter; -import org.znerd.xmlenc.LineBreak; -import org.znerd.xmlenc.XMLOutputter; -import org.znerd.xmlenc.XMLEncoder; -import org.znerd.xmlenc.InvalidXMLException; - -/** - * Formatter that outputs data inside an HTML table. If only a single cell - * result, then no formatting is done. Presumption is that client manages - * serial access outputting tables. Does not close passed {@link Writer}. - * Since hbase columns have no typing, the formatter presumes a type of - * UTF-8 String. If cells contain images, etc., this formatter will mangle - * their display. - *

TODO: Uses xmlenc. Hopefully it flushes every so often (Claims its a - * stream-based outputter). Verify. - */ -public class HtmlTableFormatter implements TableFormatter { - private final XMLOutputter outputter; - private boolean noFormatting = false; - private final Writer out; - - // Uninstantiable - @SuppressWarnings("unused") - private HtmlTableFormatter() { - this(null); - } - - /* - * An encoder that replaces illegal XML characters with the '@' sign. - */ - private static class HbaseXMLEncoder extends XMLEncoder { - @SuppressWarnings("deprecation") - public HbaseXMLEncoder() - throws IllegalArgumentException, UnsupportedEncodingException { - super("UTF-8"); - } - - @Override - public void text(Writer w, char c, boolean escape) - throws InvalidXMLException, IOException { - super.text(w, legalize(c), escape); - } - - @Override - public void text(Writer w, char[] cs, int start, int length, boolean b) - throws NullPointerException, IndexOutOfBoundsException, - InvalidXMLException, IOException { - for (int i = start; i < start + length; i++) { - cs[i] = legalize(cs[i]); - } - super.text(w, cs, start, length, b); - } - - /** - * If character is in range A, C, or E, then replace with '@' - *

-     * A   0-8     Control characters   -- Not allowed in XML 1.0 --
-     * B   9-10    Normal characters    Never needed
-     * C   11-12   Control characters   -- Not allowed in XML 1.0 --
-     * D   13      Normal character     Never needed
-     * E   14-31   Control characters   -- Not allowed in XML 1.0 --
-     * 
- * @param c Character to look at. - * @return - */ - private char legalize(final char c) { - return (c <= 8 || c == 11 || c == 12 || (c >= 14 && c <= 31))? '@': c; - } - } - - public HtmlTableFormatter(final Writer o) { - this.out = o; - try { - // Looking at the xmlenc source, there should be no issue w/ wrapping - // the stream -- i.e. no hanging resources. - this.outputter = new XMLOutputter(this.out, new HbaseXMLEncoder()); - String os = System.getProperty("os.name").toLowerCase(); - // Shell likes the DOS output. - this.outputter.setLineBreak(os.contains("windows")? - LineBreak.DOS: LineBreak.UNIX); - this.outputter.setIndentation(" "); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - - /** - * @param titles List of titles. Pass null if no formatting (i.e. - * no header, no footer, etc. - * @throws IOException - */ - public void header(String[] titles) throws IOException { - if (titles == null) { - // print nothing. - setNoFormatting(true); - return; - } - // Can't add a 'border=1' attribute because its included on the end in - - this.outputter.startTag("table"); - this.outputter.startTag("tr"); - for (int i = 0; i < titles.length; i++) { - this.outputter.startTag("th"); - this.outputter.pcdata(titles[i]); - this.outputter.endTag(); - } - this.outputter.endTag(); - } - - public void row(String [] cells) throws IOException{ - if (isNoFormatting()) { - getOut().write(cells[0]); - return; - } - this.outputter.startTag("tr"); - for (int i = 0; i < cells.length; i++) { - this.outputter.startTag("td"); - this.outputter.pcdata(cells[i]); - this.outputter.endTag(); - } - this.outputter.endTag(); - } - - public void footer() throws IOException { - if (!isNoFormatting()) { - // To close the table - this.outputter.endTag(); - this.outputter.endDocument(); - } - // We're done. Clear flag. - this.setNoFormatting(false); - // If no formatting, output a newline to delimit cell and the - // result summary output at end of every command. If html, also emit a - // newline to delimit html and summary line. - getOut().write(System.getProperty("line.separator")); - getOut().flush(); - } - - public Writer getOut() { - return this.out; - } - - public boolean isNoFormatting() { - return this.noFormatting; - } - - public void setNoFormatting(boolean noFormatting) { - this.noFormatting = noFormatting; - } - - public static void main(String[] args) throws IOException { - HtmlTableFormatter f = - new HtmlTableFormatter(new OutputStreamWriter(System.out, "UTF-8")); - f.header(new String [] {"a", "b"}); - f.row(new String [] {"a", "b"}); - f.footer(); - } -} \ No newline at end of file Index: src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/formatter/AsciiTableFormatter.java =================================================================== --- src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/formatter/AsciiTableFormatter.java (revision 611544) +++ src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/formatter/AsciiTableFormatter.java (working copy) @@ -1,168 +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.hadoop.hbase.shell.formatter; - -import java.io.IOException; -import java.io.Writer; - -import org.apache.hadoop.hbase.shell.TableFormatter; - - -/** - * Formatter that outputs data inside an ASCII table. - * If only a single cell result, then no formatting is done. Presumption is - * that client manages serial access outputting tables. Does not close passed - * {@link Writer}. - */ -public class AsciiTableFormatter implements TableFormatter { - private static final String COLUMN_DELIMITER = "| "; - private static final String COLUMN_CLOSER = "|"; - private static final int DEFAULT_COLUMN_WIDTH = 26; - // Width is a line of content + delimiter - private int columnWidth = DEFAULT_COLUMN_WIDTH; - // Amount of width to use for a line of content. - private int columnContentWidth = - DEFAULT_COLUMN_WIDTH - COLUMN_DELIMITER.length(); - // COLUMN_LINE is put at head and foot of a column and per column, is drawn - // as row delimiter - private String columnHorizLine; - private final String COLUMN_HORIZ_LINE_CLOSER = "+"; - // Used padding content to fill column - private final String PADDING_CHAR = " "; - // True if we are to output no formatting. - private boolean noFormatting = false; - private final Writer out; - private final String LINE_SEPARATOR = System.getProperty("line.separator"); - - // Not instantiable - @SuppressWarnings("unused") - private AsciiTableFormatter() { - this(null); - } - - public AsciiTableFormatter(final Writer o) { - this.out = o; - } - - public Writer getOut() { - return this.out; - } - - /** - * @param titles List of titles. Pass null if no formatting (i.e. - * no header, no footer, etc. - * @throws IOException - */ - public void header(String[] titles) throws IOException { - if (titles == null) { - // print nothing. - setNoFormatting(true); - return; - } - // Calculate width of columns. - this.columnWidth = titles.length == 1? 3 * DEFAULT_COLUMN_WIDTH: - titles.length == 2? 39: DEFAULT_COLUMN_WIDTH; - this.columnContentWidth = this.columnWidth - COLUMN_DELIMITER.length(); - // Create the horizontal line to draw across the top of each column. - this.columnHorizLine = calculateColumnHorizLine(this.columnWidth); - // Print out a column topper per column. - printRowDelimiter(titles.length); - row(titles); - } - - public void row(String [] cells) throws IOException { - if (isNoFormatting()) { - getOut().write(cells[0]); - getOut().flush(); - return; - } - // Ok. Output cells a line at a time w/ delimiters between cells. - int [] indexes = new int[cells.length]; - for (int i = 0; i < indexes.length; i++) { - indexes[i] = 0; - } - int allFinished = 0; - while (allFinished < indexes.length) { - StringBuffer sb = new StringBuffer(); - for (int i = 0; i < cells.length; i++) { - sb.append(COLUMN_DELIMITER); - int offset = indexes[i]; - if (offset + this.columnContentWidth >= cells[i].length()) { - String substr = cells[i].substring(offset); - if (substr.length() > 0) { - // This column is finished - allFinished++; - sb.append(substr); - } - for (int j = 0; j < this.columnContentWidth - substr.length(); j++) { - sb.append(PADDING_CHAR); - } - indexes[i] = cells[i].length(); - } else { - String substr = cells[i].substring(indexes[i], - indexes[i] + this.columnContentWidth); - indexes[i] += this.columnContentWidth; - sb.append(substr); - } - } - sb.append(COLUMN_CLOSER); - getOut().write(sb.toString()); - getOut().write(LINE_SEPARATOR); - getOut().flush(); - } - printRowDelimiter(cells.length); - } - - public void footer() throws IOException { - if (isNoFormatting()) { - // If no formatting, output a newline to delimit cell and the - // result summary output at end of every command. - getOut().write(LINE_SEPARATOR); - getOut().flush(); - } - // We're done. Clear flag. - setNoFormatting(false); - } - - private void printRowDelimiter(final int columnCount) throws IOException { - for (int i = 0; i < columnCount; i++) { - getOut().write(this.columnHorizLine); - - } - getOut().write(COLUMN_HORIZ_LINE_CLOSER); - getOut().write(LINE_SEPARATOR); - getOut().flush(); - } - - private String calculateColumnHorizLine(final int width) { - StringBuffer sb = new StringBuffer(); - sb.append("+"); - for (int i = 1; i < width; i++) { - sb.append("-"); - } - return sb.toString(); - } - - public boolean isNoFormatting() { - return this.noFormatting; - } - - public void setNoFormatting(boolean noFormatting) { - this.noFormatting = noFormatting; - } -} \ No newline at end of file Index: src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/TruncateCommand.java =================================================================== --- src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/TruncateCommand.java (revision 611544) +++ src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/TruncateCommand.java (working copy) @@ -1,86 +0,0 @@ -/** - * Copyright 2007 The Apache Software Foundation - * - * 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.hadoop.hbase.shell; - -import java.io.IOException; -import java.io.Writer; - -import org.apache.hadoop.hbase.HBaseAdmin; -import org.apache.hadoop.hbase.HBaseConfiguration; -import org.apache.hadoop.hbase.HColumnDescriptor; -import org.apache.hadoop.hbase.HConnection; -import org.apache.hadoop.hbase.HConnectionManager; -import org.apache.hadoop.hbase.HTableDescriptor; -import org.apache.hadoop.io.Text; - -/** - * Truncate table is used to clean all data from a table. - */ -public class TruncateCommand extends BasicCommand { - private Text tableName; - - public TruncateCommand(Writer o) { - super(o); - } - - public ReturnMsg execute(final HBaseConfiguration conf) { - if (this.tableName == null) - return new ReturnMsg(0, "Syntax error : Please check 'Truncate' syntax."); - - try { - HConnection conn = HConnectionManager.getConnection(conf); - HBaseAdmin admin = new HBaseAdmin(conf); - - if (!conn.tableExists(tableName)) { - return new ReturnMsg(0, "Table not found."); - } - - HTableDescriptor[] tables = conn.listTables(); - HColumnDescriptor[] columns = null; - for (int i = 0; i < tables.length; i++) { - if (tables[i].getName().equals(tableName)) { - columns = tables[i].getFamilies().values().toArray( - new HColumnDescriptor[] {}); - break; - } - } - println("Truncating a '" + tableName + "' table ... Please wait."); - - admin.deleteTable(tableName); // delete the table - HTableDescriptor tableDesc = new HTableDescriptor(tableName.toString()); - for (int i = 0; i < columns.length; i++) { - tableDesc.addFamily(columns[i]); - } - admin.createTable(tableDesc); // re-create the table - } catch (IOException e) { - return new ReturnMsg(0, "error msg : " + e.toString()); - } - return new ReturnMsg(0, "'" + tableName + "' is successfully truncated."); - } - - public void setTableName(String tableName) { - this.tableName = new Text(tableName); - } - - @Override - public CommandType getCommandType() { - return CommandType.DDL; - } -} Index: src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/EnableCommand.java =================================================================== --- src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/EnableCommand.java (revision 611544) +++ src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/EnableCommand.java (working copy) @@ -1,66 +0,0 @@ -/** - * Copyright 2007 The Apache Software Foundation - * - * 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.hadoop.hbase.shell; - -import java.io.IOException; -import java.io.Writer; - -import org.apache.hadoop.hbase.HBaseAdmin; -import org.apache.hadoop.hbase.HBaseConfiguration; -import org.apache.hadoop.hbase.HConnection; -import org.apache.hadoop.hbase.HConnectionManager; -import org.apache.hadoop.io.Text; - -/** - * Enables tables. - */ -public class EnableCommand extends BasicCommand { - private String tableName; - - public EnableCommand(Writer o) { - super(o); - } - - public ReturnMsg execute(HBaseConfiguration conf) { - assert tableName != null; - try { - HConnection conn = HConnectionManager.getConnection(conf); - if (!conn.tableExists(new Text(tableName))) { - return new ReturnMsg(0, "'" + tableName + "'" + TABLE_NOT_FOUND); - } - - HBaseAdmin admin = new HBaseAdmin(conf); - admin.enableTable(new Text(tableName)); - return new ReturnMsg(1, "Table enabled successfully."); - } catch (IOException e) { - String[] msg = e.getMessage().split("[\n]"); - return new ReturnMsg(0, msg[0]); - } - } - - public void setTable(String table) { - this.tableName = table; - } - - @Override - public CommandType getCommandType() { - return CommandType.DDL; - } -} Index: src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/ClearCommand.java =================================================================== --- src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/ClearCommand.java (revision 611544) +++ src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/ClearCommand.java (working copy) @@ -1,66 +0,0 @@ -/** - * Copyright 2007 The Apache Software Foundation - * - * 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.hadoop.hbase.shell; - -import java.io.IOException; -import java.io.Writer; - -import org.apache.hadoop.hbase.HBaseConfiguration; - -/** - * Clears the console screen. - */ -public class ClearCommand extends BasicCommand { - public ClearCommand(Writer o) { - super(o); - } - - public ReturnMsg execute(@SuppressWarnings("unused") - HBaseConfiguration conf) { - clear(); - return null; - } - - private void clear() { - String osName = System.getProperty("os.name"); - if (osName.length() > 7 && osName.subSequence(0, 7).equals("Windows")) { - try { - Runtime.getRuntime().exec("cmd /C cls"); - } catch (IOException e) { - try { - println("Can't clear." + e.toString()); - } catch (IOException e1) { - e1.printStackTrace(); - } - } - } else { - try { - print("\033c"); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - - @Override - public CommandType getCommandType() { - return CommandType.SHELL; - } -} Index: src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/SchemaModificationCommand.java =================================================================== --- src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/SchemaModificationCommand.java (revision 611544) +++ src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/SchemaModificationCommand.java (working copy) @@ -1,110 +0,0 @@ -/** - * Copyright 2007 The Apache Software Foundation - * - * 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.hadoop.hbase.shell; - -import java.io.Writer; -import java.util.Map; -import java.util.Set; - -import org.apache.hadoop.hbase.BloomFilterDescriptor; -import org.apache.hadoop.hbase.BloomFilterDescriptor.BloomFilterType; -import org.apache.hadoop.hbase.HColumnDescriptor; -import org.apache.hadoop.io.Text; - -/** - * The base class of schema modification commands, CreateCommand and Alter - * Command. Provides utility methods for alteration operations. - */ -public abstract class SchemaModificationCommand extends BasicCommand { - protected int maxVersions; - protected int maxLength; - protected HColumnDescriptor.CompressionType compression; - protected boolean inMemory; - protected BloomFilterDescriptor bloomFilterDesc; - protected BloomFilterType bloomFilterType; - protected int vectorSize; - protected int numHash; - protected int numEntries; - - public SchemaModificationCommand(Writer o) { - super(o); - } - - protected void initOptions() { - maxVersions = HColumnDescriptor.DEFAULT_N_VERSIONS; - maxLength = HColumnDescriptor.DEFAULT_MAX_VALUE_LENGTH; - compression = HColumnDescriptor.DEFAULT_COMPRESSION_TYPE; - inMemory = HColumnDescriptor.DEFAULT_IN_MEMORY; - bloomFilterDesc = HColumnDescriptor.DEFAULT_BLOOM_FILTER_DESCRIPTOR; - } - - /** - * Given a column name and column spec, returns an instance of - * HColumnDescriptor representing the column spec. - */ - protected HColumnDescriptor getColumnDescriptor(String column, - Map columnSpec) throws IllegalArgumentException { - initOptions(); - - Set specs = columnSpec.keySet(); - for (String spec : specs) { - spec = spec.toUpperCase(); - - if (spec.equals("MAX_VERSIONS")) { - maxVersions = (Integer) columnSpec.get(spec); - } else if (spec.equals("MAX_LENGTH")) { - maxLength = (Integer) columnSpec.get(spec); - } else if (spec.equals("COMPRESSION")) { - compression = HColumnDescriptor.CompressionType - .valueOf(((String) columnSpec.get(spec)).toUpperCase()); - } else if (spec.equals("IN_MEMORY")) { - inMemory = (Boolean) columnSpec.get(spec); - } else if (spec.equals("BLOOMFILTER")) { - bloomFilterType = BloomFilterType.valueOf(((String) columnSpec.get(spec)) - .toUpperCase()); - } else if (spec.equals("VECTOR_SIZE")) { - vectorSize = (Integer) columnSpec.get(spec); - } else if (spec.equals("NUM_HASH")) { - numHash = (Integer) columnSpec.get(spec); - } else if (spec.equals("NUM_ENTRIES")) { - numEntries = (Integer) columnSpec.get(spec); - } else { - throw new IllegalArgumentException("Invalid option: " + spec); - } - } - - // Now we gather all the specified options for this column. - if (bloomFilterType != null) { - if (specs.contains("NUM_ENTRIES")) { - bloomFilterDesc = new BloomFilterDescriptor(bloomFilterType, numEntries); - } else { - bloomFilterDesc = new BloomFilterDescriptor(bloomFilterType, vectorSize, - numHash); - } - } - - column = appendDelimiter(column); - - HColumnDescriptor columnDesc = new HColumnDescriptor(new Text(column), - maxVersions, compression, inMemory, maxLength, bloomFilterDesc); - - return columnDesc; - } -} Index: src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/ReturnMsg.java =================================================================== --- src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/ReturnMsg.java (revision 611544) +++ src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/ReturnMsg.java (working copy) @@ -1,54 +0,0 @@ -/** - * Copyright 2007 The Apache Software Foundation - * - * 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.hadoop.hbase.shell; - -import org.apache.hadoop.hbase.HBaseConfiguration; - -/** - * Message returned when a {@link Command} is - * {@link Command#execute(HBaseConfiguration)}'ed. - */ -public class ReturnMsg { - private final String msg; - private final int type; - - public ReturnMsg(int i, String string) { - this.type = i; - this.msg = string; - } - - public ReturnMsg(int i) { - this.type = i; - this.msg = ""; - } - - public String getMsg() { - return this.msg; - } - - public int getType() { - return this.type; - } - - @Override - public String toString() { - return this.msg; - } -} Index: src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/HelpCommand.java =================================================================== --- src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/HelpCommand.java (revision 611544) +++ src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/HelpCommand.java (working copy) @@ -1,183 +0,0 @@ -/** - * Copyright 2007 The Apache Software Foundation - * - * 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.hadoop.hbase.shell; - -import java.io.IOException; -import java.io.OutputStreamWriter; -import java.io.UnsupportedEncodingException; -import java.io.Writer; -import java.util.HashMap; -import java.util.Map; - -import org.apache.hadoop.hbase.HBaseConfiguration; - -public class HelpCommand extends BasicCommand { - private String argument; - private static final String[] HEADER = new String[] { "Command", - "Description", "Example" }; - - /** application name */ - public static final String APP_NAME = "Hbase Shell"; - - /** version of the code */ - public static final String APP_VERSION = "0.0.2"; - - /** help contents map */ - public final Map help = new HashMap(); - - private final TableFormatter formatter; - - public HelpCommand(final Writer o, final TableFormatter f) { - super(o); - this.help.putAll(load()); - this.formatter = f; - } - - public ReturnMsg execute(@SuppressWarnings("unused") - HBaseConfiguration conf) { - try { - printHelp(this.argument); - } catch (IOException e) { - e.printStackTrace(); - } - return null; - } - - public void setArgument(String argument) { - this.argument = argument; - } - - /** - * add help contents - */ - private Map load() { - Map load = new HashMap(); - load.put("SHOW", new String[] { "Show information about selected title", - "SHOW TABLES [or substitution variable name];" }); - - load.put("FS", new String[] { - "Hadoop FsShell; entering a lone 'FS;' " + "will emit usage", - "FS [-option] arguments..;" }); - - load.put("JAR", new String[] { "Hadoop RunJar util", - "JAR jarFile [mainClass] arguments...;" }); - load.put("CLEAR", new String[] { "Clear the screen", "CLEAR;" }); - - load.put("DESCRIBE", new String[] { "Print table information", - "[DESCRIBE|DESC] table_name;" }); - - load - .put( - "CREATE", - new String[] { - "Create tables", - "CREATE TABLE table_name (column_family_name [MAX_VERSIONS=n] " - + "[MAX_LENGTH=n] [COMPRESSION=NONE|RECORD|BLOCK] [IN_MEMORY] " - + "[BLOOMFILTER=NONE|BLOOMFILTER|COUNTING_BLOOMFILTER|RETOUCHED_BLOOMFILTER " - + "VECTOR_SIZE=n NUM_HASH=n], " + "...)" }); - load.put("DROP", new String[] { "Drop tables", - "DROP TABLE table_name [, table_name] ...;" }); - - load.put("INSERT", new String[] { - "Insert values into table", - "INSERT INTO table_name (column_name, ...) " - + "VALUES ('value', ...) WHERE row='row_key'" + - " [TIMESTAMP 'timestamp'];" }); - - load.put("DELETE", new String[] { - "Delete table data", - "DELETE {column_name, [, column_name] ... | *} FROM table_name " - + "WHERE row='row-key';" }); - - load.put("SELECT", new String[] { - "Select values from table", - "SELECT {column_name, [, column_name] ... | expr[alias] | * } FROM table_name " - + "[WHERE row='row_key' | STARTING FROM 'row-key' [UNTIL 'stop-key']] " - + "[NUM_VERSIONS = version_count] " + "[TIMESTAMP 'timestamp'] " - + "[LIMIT = row_count] " + "[INTO FILE 'file_name'];" }); - - load.put("ALTER", new String[] { - "Alter structure of table", - "ALTER TABLE table_name ADD column_spec | " - + "ADD (column_spec, column_spec, ...) | " - + "CHANGE column_family column_spec | " - + "DROP column_family_name | " + "CHANGE column_spec;" }); - - load.put("TRUNCATE", new String[] { - "Truncate table is used to clean all data from a table", - "TRUNCATE TABLE table_name;" }); - - load.put("EXIT", new String[] { "Exit shell", "EXIT;" }); - - return load; - } - - /** - * Print out the program version. - * - * @throws IOException - */ - public void printVersion() throws IOException { - println(APP_NAME + ", " + APP_VERSION + " version.\n" - + "Copyright (c) 2007 by udanax, " - + "licensed to Apache Software Foundation.\n" - + "Type 'help;' for usage.\n"); - } - - public void printHelp(final String cmd) throws IOException { - if (cmd.equals("")) { - println("Type 'help COMMAND;' to see command-specific usage."); - printHelp(this.help); - } else { - if (this.help.containsKey(cmd.toUpperCase())) { - final Map m = new HashMap(); - m.put(cmd.toUpperCase(), this.help.get(cmd.toUpperCase())); - printHelp(m); - } else { - println("Unknown Command : Type 'help;' for usage."); - } - } - } - - private void printHelp(final Map m) throws IOException { - this.formatter.header(HEADER); - for (Map.Entry e : m.entrySet()) { - String[] value = e.getValue(); - if (value.length == 2) { - this.formatter.row(new String[] { e.getKey().toUpperCase(), value[0], - value[1] }); - } else { - throw new IOException("Value has too many elements:" + value); - } - } - this.formatter.footer(); - } - - public static void main(String[] args) throws UnsupportedEncodingException { - HBaseConfiguration conf = new HBaseConfiguration(); - Writer out = new OutputStreamWriter(System.out, "UTF-8"); - TableFormatterFactory tff = new TableFormatterFactory(out, conf); - HelpCommand cmd = new HelpCommand(out, tff.get()); - cmd.setArgument(""); - cmd.execute(conf); - cmd.setArgument("select"); - cmd.execute(conf); - } -} Index: src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/ExitException.java =================================================================== --- src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/ExitException.java (revision 611544) +++ src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/ExitException.java (working copy) @@ -1,44 +0,0 @@ -/** - * Copyright 2007 The Apache Software Foundation - * - * 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.hadoop.hbase.shell; - -public class ExitException extends SecurityException { - private static final long serialVersionUID = -8085525076856622991L; - /** Status code */ - private int status; - - /** - * Constructs an exit exception. - * - * @param status the status code returned via System.exit() - */ - public ExitException(int status) { - this.status = status; - } - - /** - * The status code returned by System.exit() - * - * @return the status code returned by System.exit() - */ - public int getStatus() { - return status; - } -} Index: src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/ShellSecurityManager.java =================================================================== --- src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/ShellSecurityManager.java (revision 611544) +++ src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/ShellSecurityManager.java (working copy) @@ -1,75 +0,0 @@ -/** - * Copyright 2007 The Apache Software Foundation - * - * 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.hadoop.hbase.shell; - -import java.io.IOException; -import java.security.Permission; -import java.util.ArrayList; -import java.util.List; - -import org.apache.hadoop.hbase.Shell; - -/** - * This is intended as a replacement for the default system manager. The goal is - * to intercept System.exit calls and make it throw an exception instead so that - * a System.exit in a jar command program does not fully terminate Shell. - * - * @see ExitException - */ -public class ShellSecurityManager extends SecurityManager { - - /** - * Override SecurityManager#checkExit. This throws an ExitException(status) - * exception. - * - * @param status the exit status - */ - @SuppressWarnings("static-access") - public void checkExit(int status) { - if (status != Shell.EXIT_FLAG) { - // throw new ExitException(status); - - // I didn't figure out How can catch the ExitException in shell main. - // So, I just Re-launching the shell. - Shell shell = new Shell(); - - List argList = new ArrayList(); - argList.add(String.valueOf(Shell.RELAUNCH_FLAG)); - if(Shell.HTML_OPTION != null) - argList.add(Shell.HTML_OPTION); - if(Shell.MASTER_ADDRESS != null) - argList.add(Shell.MASTER_ADDRESS); - - try { - shell.main(argList.toArray(new String[] {})); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - - /** - * Override SecurityManager#checkPermission. This does nothing. - * - * @param perm the requested permission. - */ - public void checkPermission(Permission perm) { - } -} Index: src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/HBaseShell.jj =================================================================== --- src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/HBaseShell.jj (revision 611544) +++ src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/HBaseShell.jj (working copy) @@ -1,824 +0,0 @@ -options { - STATIC = false; - IGNORE_CASE = true; -} - -PARSER_BEGIN(Parser) -package org.apache.hadoop.hbase.shell.generated; - -/** - * Copyright 2007 The Apache Software Foundation - * - * 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. - */ - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.HashMap; -import java.io.StringReader; -import java.io.Reader; -import java.io.Writer; -import java.net.URLEncoder; -import java.io.UnsupportedEncodingException; - -import org.apache.hadoop.hbase.shell.*; - -/** - * Parsing command line. - */ -public class Parser { - private String QueryString; - private TableFormatter formatter; - private Writer out; - private String secondR; - - public Parser(final String query, final Writer o, final TableFormatter f) { - this((Reader)(new StringReader(query))); - this.QueryString = query; - this.formatter = f; - this.out = o; - } - - public String getQueryStr() { - return this.QueryString; - } -} - -PARSER_END(Parser) - -SKIP : -{ - " " - | "\t" - | "\r" - | "\n" -} - -TOKEN: /** for HQL statements */ -{ - - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | "> - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | -} - -TOKEN : /** Functions */ -{ - -} - -TOKEN : /** Literals */ -{ - - | - | )? - | "." (["0"-"9"])+ ()? - | (["0"-"9"])+ - | (["0"-"9"])+ ()? - > - | <#EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ > - | - | -} - -/** - * Parses the given array of command line arguments. - */ -Command terminatedCommand() : -{ - Command statement = null; -} -{ - ( - [statement = cmdStatement()] ";" | - ) - - { - return statement; - } -} - -Command cmdStatement() : -{ - Command cmd = null; -} -{ - ( - cmd = exitCommand() - | cmd = helpCommand() - | cmd = showCommand() - | cmd = descCommand() - | cmd = createCommand() - | cmd = dropCommand() - | cmd = truncateCommand() - | cmd = alterCommand() - | cmd = insertCommand() - | cmd = deleteCommand() - | cmd = selectCommand() - | cmd = enableCommand() - | cmd = disableCommand() - | cmd = clearCommand() - | cmd = fsCommand() - | cmd = jarCommand() - ) - { - return cmd; - } -} - -ExitCommand exitCommand() : -{ - ExitCommand exit = new ExitCommand(this.out); -} -{ - { return exit; } -} - -FsCommand fsCommand() : -{ - Token t = null; - FsCommand fs = new FsCommand(this.out); - List query = new ArrayList(); -} -{ - - ( - t = - { query.add(t.image.toString()); } - )* - - { - fs.setQuery(query); - return fs; - } -} - -JarCommand jarCommand() : -{ - Token t = null; - JarCommand jar = new JarCommand(this.out); - List query = new ArrayList(); -} -{ - - ( - ( t= | t= | t= ) - { query.add(t.image.toString()); } - )* - - { - jar.setQuery(query); - return jar; - } -} - -TruncateCommand truncateCommand() : -{ - TruncateCommand truncate = new TruncateCommand(this.out); - String tableName = null; -} -{ - - [ - tableName = identifier() - ] - { - truncate.setTableName(tableName); - return truncate; - } -} - -HelpCommand helpCommand() : -{ - Token t = null; - HelpCommand help = new HelpCommand(this.out, this.formatter); - String argument = ""; -} -{ - - [ - ( - t= - | t= - | t= - | t= - | t= - | t= - | t= - | t=
- table = identifier() - { - createCommand.setTable(table); - } - - - - column = identifier() - columnSpec = ColumnSpec() - { - createCommand.addColumnSpec(column, columnSpec); - } - - ( - - column = identifier() - columnSpec = ColumnSpec() - { - createCommand.addColumnSpec(column, columnSpec); - } - )* - - - { return createCommand; } -} - -AlterCommand alterCommand() : -{ - AlterCommand alterCommand = new AlterCommand(this.out); - String table = null; - String column = null; - Map columnSpec = null; -} -{ - -
table = identifier() - { alterCommand.setTable(table); } - - ( - LOOKAHEAD(2) - column = identifier() columnSpec = ColumnSpec() - { - alterCommand.setOperationType(AlterCommand.OperationType.ADD); - alterCommand.addColumnSpec(column, columnSpec); - } - | - - - { - alterCommand.setOperationType(AlterCommand.OperationType.ADD); - } - - column = identifier() columnSpec = ColumnSpec() - { - alterCommand.addColumnSpec(column, columnSpec); - } - - ( - - column = identifier() - columnSpec = ColumnSpec() - { - alterCommand.addColumnSpec(column, columnSpec); - } - )* - - | - column = identifier() - { - alterCommand.setOperationType(AlterCommand.OperationType.DROP); - alterCommand.setColumn(column); - } - | - column = identifier() columnSpec = ColumnSpec() - { - alterCommand.setOperationType(AlterCommand.OperationType.CHANGE); - alterCommand.addColumnSpec(column, columnSpec); - } - ) - { return alterCommand; } -} - -DropCommand dropCommand() : -{ - DropCommand drop = new DropCommand(this.out); - List tableList = null; -} -{ - -
- tableList = tableList() - { - drop.setTableList(tableList); - return drop; - } -} - -InsertCommand insertCommand() : -{ - InsertCommand in = new InsertCommand(this.out); - List columnfamilies = null; - List values = null; - String table = null; - String timestamp = null; - Token t = null; -} -{ - - - table = identifier() - { - in.setTable(table); - } - columnfamilies = getColumns() - { - in.setColumnfamilies(columnfamilies); - } - - values = getLiteralValues() - { - in.setValues(values); - } - - - ( t= | t= ) - { - in.setRow(t.image.substring(1, t.image.length()-1)); - } - - [ - timestamp = getStringLiteral() - { - in.setTimestamp(timestamp); - } - ] - - { - return in; - } -} - -DeleteCommand deleteCommand() : -{ - DeleteCommand deleteCommand = new DeleteCommand(this.out); - List columnList = null; - Token t = null; - String table = null; -} -{ - - columnList = columnList() - { - deleteCommand.setColumnList(columnList); - } - - - table = identifier() - { - deleteCommand.setTable(table); - } - - [ - - ( t= | t= ) - { - deleteCommand.setRow(t.image.substring(1, t.image.length()-1)); - } - ] - { return deleteCommand; } -} - -SelectCommand selectCommand() : -{ - SelectCommand select = new SelectCommand(this.out, this.formatter); - List columns = null; - String rowKey = ""; - String stopRow = ""; - String timestamp = null; - int numVersion = 0; - String tableName = null; - int limit; -} -{ -
+ [ + tableName = identifier() + ] + { + truncate.setTableName(tableName); + return truncate; + } +} + +HelpCommand helpCommand() : +{ + Token t = null; + HelpCommand help = new HelpCommand(this.out, this.formatter); + String argument = ""; +} +{ + + [ + ( + t= + | t= + | t= + | t= + | t= + | t= + | t= + | t=
+ table = identifier() + { + createCommand.setTable(table); + } + + + + column = identifier() + columnSpec = ColumnSpec() + { + createCommand.addColumnSpec(column, columnSpec); + } + + ( + + column = identifier() + columnSpec = ColumnSpec() + { + createCommand.addColumnSpec(column, columnSpec); + } + )* + + + { return createCommand; } +} + +AlterCommand alterCommand() : +{ + AlterCommand alterCommand = new AlterCommand(this.out); + String table = null; + String column = null; + Map columnSpec = null; +} +{ + +
table = identifier() + { alterCommand.setTable(table); } + + ( + LOOKAHEAD(2) + column = identifier() columnSpec = ColumnSpec() + { + alterCommand.setOperationType(AlterCommand.OperationType.ADD); + alterCommand.addColumnSpec(column, columnSpec); + } + | + + + { + alterCommand.setOperationType(AlterCommand.OperationType.ADD); + } + + column = identifier() columnSpec = ColumnSpec() + { + alterCommand.addColumnSpec(column, columnSpec); + } + + ( + + column = identifier() + columnSpec = ColumnSpec() + { + alterCommand.addColumnSpec(column, columnSpec); + } + )* + + | + column = identifier() + { + alterCommand.setOperationType(AlterCommand.OperationType.DROP); + alterCommand.setColumn(column); + } + | + column = identifier() columnSpec = ColumnSpec() + { + alterCommand.setOperationType(AlterCommand.OperationType.CHANGE); + alterCommand.addColumnSpec(column, columnSpec); + } + ) + { return alterCommand; } +} + +DropCommand dropCommand() : +{ + DropCommand drop = new DropCommand(this.out); + List tableList = null; +} +{ + +
+ tableList = tableList() + { + drop.setTableList(tableList); + return drop; + } +} + +InsertCommand insertCommand() : +{ + InsertCommand in = new InsertCommand(this.out); + List columnfamilies = null; + List values = null; + String table = null; + String timestamp = null; + Token t = null; +} +{ + + + table = identifier() + { + in.setTable(table); + } + columnfamilies = getColumns() + { + in.setColumnfamilies(columnfamilies); + } + + values = getLiteralValues() + { + in.setValues(values); + } + + + ( t= | t= ) + { + in.setRow(t.image.substring(1, t.image.length()-1)); + } + + [ + timestamp = getStringLiteral() + { + in.setTimestamp(timestamp); + } + ] + + { + return in; + } +} + +DeleteCommand deleteCommand() : +{ + DeleteCommand deleteCommand = new DeleteCommand(this.out); + List columnList = null; + Token t = null; + String table = null; +} +{ + + columnList = columnList() + { + deleteCommand.setColumnList(columnList); + } + + + table = identifier() + { + deleteCommand.setTable(table); + } + + [ + + ( t= | t= ) + { + deleteCommand.setRow(t.image.substring(1, t.image.length()-1)); + } + ] + { return deleteCommand; } +} + +SelectCommand selectCommand() : +{ + SelectCommand select = new SelectCommand(this.out, this.formatter); + List columns = null; + String rowKey = ""; + String stopRow = ""; + String timestamp = null; + int numVersion = 0; + String tableName = null; + int limit; +} +{ +