Repository: incubator-blur Updated Branches: refs/heads/master a587dc158 -> f07b1a6be
Working on BLUR-401 Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/f07b1a6b Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/f07b1a6b Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/f07b1a6b Branch: refs/heads/master Commit: f07b1a6be1e6c2cc4ac92a33e5a349927aabc24a Parents: a587dc1 Author: Aaron McCurry <[email protected]> Authored: Tue Jan 13 10:26:50 2015 -0500 Committer: Aaron McCurry <[email protected]> Committed: Tue Jan 13 10:26:50 2015 -0500 ---------------------------------------------------------------------- blur-shell/pom.xml | 101 +++++++++---------- .../org/apache/blur/shell/QueryCommand.java | 68 ++++++++++++- 2 files changed, 110 insertions(+), 59 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/f07b1a6b/blur-shell/pom.xml ---------------------------------------------------------------------- diff --git a/blur-shell/pom.xml b/blur-shell/pom.xml index 54c53c4..c856767 100644 --- a/blur-shell/pom.xml +++ b/blur-shell/pom.xml @@ -1,22 +1,14 @@ <?xml version="1.0" encoding="UTF-8"?> -<!-- -Licensed to the Apache Software Foundation (ASF) under one -or more contributor license agreements. See the NOTICE file -distributed with this work for additional information -regarding copyright ownership. The ASF licenses this file -to you under the Apache License, Version 2.0 (the -"License"); you may not use this file except in compliance -with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, -software distributed under the License is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -KIND, either express or implied. See the License for the -specific language governing permissions and limitations -under the License. ---> +<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor + license agreements. See the NOTICE file distributed with this work for additional + information regarding copyright ownership. The ASF licenses this file to + you under the Apache License, Version 2.0 (the "License"); you may not use + this file except in compliance with the License. You may obtain a copy of + the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required + by applicable law or agreed to in writing, software distributed under the + License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS + OF ANY KIND, either express or implied. See the License for the specific + language governing permissions and limitations under the License. --> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> @@ -24,7 +16,7 @@ under the License. <groupId>org.apache.blur</groupId> <artifactId>blur</artifactId> <version>0.2.4-incubating-SNAPSHOT</version> - <relativePath>../pom.xml</relativePath> + <relativePath>../pom.xml</relativePath> </parent> <groupId>org.apache.blur</groupId> <artifactId>blur-shell</artifactId> @@ -34,33 +26,34 @@ under the License. <description>The Blur shell module contains a shell for interacting with Blur. All shell commands can be called as a CLI program as well.</description> - <dependencies> - <dependency> - <groupId>org.apache.blur</groupId> - <artifactId>blur-core</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.blur</groupId> - <artifactId>blur-thrift</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>jline</groupId> - <artifactId>jline</artifactId> - <version>${jline.version}</version> - </dependency> - <dependency> - <groupId>com.google.guava</groupId> - <artifactId>guava</artifactId> - <version>${guava.version}</version> - </dependency> - </dependencies> + <dependencies> + <dependency> + <groupId>jline</groupId> + <artifactId>jline</artifactId> + <version>${jline.version}</version> + </dependency> + <dependency> + <groupId>org.apache.blur</groupId> + <artifactId>blur-core</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.blur</groupId> + <artifactId>blur-thrift</artifactId> + <version>${project.version}</version> + </dependency> - <build> - <finalName>blur-shell-${project.version}</finalName> + <dependency> + <groupId>com.google.guava</groupId> + <artifactId>guava</artifactId> + <version>${guava.version}</version> + </dependency> + </dependencies> - <plugins> + <build> + <finalName>blur-shell-${project.version}</finalName> + + <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> @@ -74,16 +67,16 @@ under the License. </systemPropertyVariables> </configuration> </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - <configuration> - <source>1.6</source> - <target>1.6</target> - </configuration> - </plugin> - </plugins> - </build> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <source>1.6</source> + <target>1.6</target> + </configuration> + </plugin> + </plugins> + </build> <profiles> <profile> http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/f07b1a6b/blur-shell/src/main/java/org/apache/blur/shell/QueryCommand.java ---------------------------------------------------------------------- diff --git a/blur-shell/src/main/java/org/apache/blur/shell/QueryCommand.java b/blur-shell/src/main/java/org/apache/blur/shell/QueryCommand.java index fd4aa64..a7fc985 100644 --- a/blur-shell/src/main/java/org/apache/blur/shell/QueryCommand.java +++ b/blur-shell/src/main/java/org/apache/blur/shell/QueryCommand.java @@ -43,7 +43,6 @@ import org.apache.blur.thrift.generated.BlurQuery; import org.apache.blur.thrift.generated.BlurResult; import org.apache.blur.thrift.generated.BlurResults; import org.apache.blur.thrift.generated.Column; -import org.apache.blur.thrift.generated.ErrorType; import org.apache.blur.thrift.generated.FetchRecordResult; import org.apache.blur.thrift.generated.FetchResult; import org.apache.blur.thrift.generated.FetchRowResult; @@ -91,10 +90,6 @@ public class QueryCommand extends Command implements TableFirstArgCommand { if (commandLine.hasOption(QueryCommandHelper.WIDTH)) { _width = Integer.parseInt(commandLine.getOptionValue(QueryCommandHelper.WIDTH)); } - ConsoleReader reader = getConsoleReader(); - if (reader == null) { - throw new BlurException("This command can only be run with a proper jline environment.", null, ErrorType.UNKNOWN); - } long s = System.nanoTime(); BlurResults blurResults = client.query(tablename, blurQuery); @@ -105,6 +100,18 @@ public class QueryCommand extends Command implements TableFirstArgCommand { return; } + ConsoleReader reader = getConsoleReader(); + if (reader == null) { + String description = blurResults.getTotalResults() + " results found in [" + timeInNanos / 1000000.0 + " ms]. " + + getFetchMetaData(blurResults); + out.println(description); + List<BlurResult> results = blurResults.getResults(); + for (BlurResult result : results) { + print(out, result); + } + return; + } + String prompt = reader.getPrompt(); reader.setPrompt(""); final TableDisplay tableDisplay = new TableDisplay(reader); @@ -176,6 +183,57 @@ public class QueryCommand extends Command implements TableFirstArgCommand { } } + private void print(PrintWriter out, BlurResult result) { + FetchResult fetchResult = result.getFetchResult(); + FetchRowResult rowResult = fetchResult.getRowResult(); + if (rowResult != null) { + print(out, rowResult); + } else { + FetchRecordResult recordResult = fetchResult.getRecordResult(); + print(out, recordResult); + } + } + + private void print(PrintWriter out, FetchRowResult rowResult) { + Row row = rowResult.getRow(); + int totalRecords = rowResult.getTotalRecords(); + String id = row.getId(); + List<Record> records = row.getRecords(); + int index = 0; + for (Record record : records) { + print(out, id, index + 1, totalRecords, record); + index++; + } + } + + private void print(PrintWriter out, String rowId, int index, int totalRecords, Record record) { + String recordId = record.getRecordId(); + String family = record.getFamily(); + out.print(rowId + "\t" + index + " of " + totalRecords + "\t" + recordId + "\t" + family); + print(out, record.getColumns()); + out.println(); + } + + private void print(PrintWriter out, List<Column> columns) { + Collections.sort(columns, new Comparator<Column>() { + @Override + public int compare(Column o1, Column o2) { + String name1 = o1.getName(); + String name2 = o2.getName(); + return name1.compareTo(name2); + } + }); + for (Column column : columns) { + out.print("\t" + column.getName() + ":" + column.getValue()); + } + } + + private void print(PrintWriter out, FetchRecordResult recordResult) { + String rowid = recordResult.getRowid(); + Record record = recordResult.getRecord(); + print(out, rowid, 0, 1, record); + } + private String getFetchMetaData(BlurResults blurResults) { AtomicInteger rowCount = new AtomicInteger(); AtomicInteger recordCount = new AtomicInteger();
