All functionality in place Signed-off-by: Aaron McCurry <[email protected]>
Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/cd2c6ff4 Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/cd2c6ff4 Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/cd2c6ff4 Branch: refs/heads/master Commit: cd2c6ff4e342bf7c2f0dd79fdf197bfcf6d9e385 Parents: d17e64e Author: hunterwilliams <[email protected]> Authored: Thu Sep 12 14:51:08 2013 -0400 Committer: Aaron McCurry <[email protected]> Committed: Sun Sep 15 20:56:22 2013 -0400 ---------------------------------------------------------------------- .../org/apache/blur/shell/TermsDataCommand.java | 115 ++++++++++++------- 1 file changed, 71 insertions(+), 44 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/cd2c6ff4/blur-shell/src/main/java/org/apache/blur/shell/TermsDataCommand.java ---------------------------------------------------------------------- diff --git a/blur-shell/src/main/java/org/apache/blur/shell/TermsDataCommand.java b/blur-shell/src/main/java/org/apache/blur/shell/TermsDataCommand.java index 7afe5c3..1ce646b 100644 --- a/blur-shell/src/main/java/org/apache/blur/shell/TermsDataCommand.java +++ b/blur-shell/src/main/java/org/apache/blur/shell/TermsDataCommand.java @@ -22,6 +22,10 @@ import java.io.PrintWriter; import java.io.Writer; import java.util.List; +import jline.Terminal; +import jline.console.ConsoleReader; + +import org.apache.blur.shell.PagingPrintWriter.FinishedException; import org.apache.blur.thirdparty.thrift_0_9_0.TException; import org.apache.blur.thrift.generated.Blur; import org.apache.blur.thrift.generated.BlurException; @@ -37,64 +41,87 @@ import org.apache.commons.cli.PosixParser; public class TermsDataCommand extends Command implements TableFirstArgCommand { @Override - public void doit(PrintWriter out, Blur.Iface client, String[] args) throws CommandException, TException, + public void doit(PrintWriter outPw, Blur.Iface client, String[] args) throws CommandException, TException, BlurException { if (args.length < 3) { throw new CommandException("Invalid args: " + help()); } - CommandLine cmd = parse(args, out); - /* - #then this starts displaying all the row ids in the system - terms testtable rowid - #This command starts displaying all the terms for column "col1" in family "fam0"in the system - terms testtable fam0.col1 - #This command starts displaying all the terms for column "col1" in family "fam0"in the system starting at "value1" - terms testtable fam0.col1 -s value1 - #This command starts displaying all the terms for column "col1" in family "fam0"in the system starting at "value1" fetch 100 then exit - terms testtable fam0.col1 -s value1 -n 100 - */ - String tablename = args[1]; - String namePlusValue = args[2]; - String family = null; - String column = namePlusValue; - String startWith = ""; - short size = 100; - - - if (namePlusValue.contains(".")){ - int index = namePlusValue.indexOf("."); - family = namePlusValue.substring(0, index); - column = namePlusValue.substring(index + 1); + try{ + doitInternal(outPw,client,args); } - - if (cmd.hasOption("n")){ - size = Short.parseShort(cmd.getOptionValue("n")); + catch (FinishedException e) { + if (Main.debug) { + e.printStackTrace(); + } } + } - if (cmd.hasOption("s")){ - startWith = cmd.getOptionValue("s"); - out.println("startWith:"+startWith); - } + private void doitInternal(PrintWriter outPw, Blur.Iface client, String[] args) throws FinishedException, + BlurException, TException{ + PagingPrintWriter out = new PagingPrintWriter(outPw); + CommandLine cmd = parse(args, outPw); + /* + #then this starts displaying all the row ids in the system + terms testtable rowid + #This command starts displaying all the terms for column "col1" in family "fam0"in the system + terms testtable fam0.col1 + #This command starts displaying all the terms for column "col1" in family "fam0"in the system starting at "value1" + terms testtable fam0.col1 -s value1 + #This command starts displaying all the terms for column "col1" in family "fam0"in the system starting at "value1" fetch 100 then exit + terms testtable fam0.col1 -s value1 -n 100 + */ + String tablename = args[1]; + String namePlusValue = args[2]; + String family = null; + String column = namePlusValue; + String startWith = ""; + short size = 100; + + + if (namePlusValue.contains(".")){ + int index = namePlusValue.indexOf("."); + family = namePlusValue.substring(0, index); + column = namePlusValue.substring(index + 1); + } - boolean checkFreq = false; - if (cmd.hasOption("F")){ - checkFreq = true; - } + if (cmd.hasOption("n")){ + size = Short.parseShort(cmd.getOptionValue("n")); + } - //todo print line by line. also break input at certain amount - List<String> terms = client.terms(tablename,family,column,startWith,size); - for (int i=0;i<terms.size(); i++){ - if (checkFreq){ - out.println(terms.get(i)+"\t"+client.recordFrequency(tablename,family,column,terms.get(i))); + if (cmd.hasOption("s")){ + startWith = cmd.getOptionValue("s"); + out.println("startWith:"+startWith); } - else - { - out.println(terms.get(i)); + + boolean checkFreq = false; + if (cmd.hasOption("F")){ + checkFreq = true; + } + + int maxWidth = 100; + ConsoleReader reader = getConsoleReader(); + if (reader != null) { + Terminal terminal = reader.getTerminal(); + maxWidth = terminal.getWidth() - 15; + out.setLineLimit(terminal.getHeight() - 2); + } + + + + //todo print line by line. also break input at certain amount + List<String> terms = client.terms(tablename,family,column,startWith,size); + for (int i=0;i<terms.size(); i++){ + if (checkFreq){ + out.println(terms.get(i)+"\t"+client.recordFrequency(tablename,family,column,terms.get(i))); + } + else + { + out.println(terms.get(i)); + } } } - } @Override public String description() {
