get started on terms combine
Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/2a61bb5d Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/2a61bb5d Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/2a61bb5d Branch: refs/heads/master Commit: 2a61bb5d6fc5fad3b85c95409bd5cda0989d2d84 Parents: af68cd3 Author: twilliams <[email protected]> Authored: Mon Sep 22 22:55:57 2014 -0400 Committer: twilliams <[email protected]> Committed: Mon Sep 22 22:55:57 2014 -0400 ---------------------------------------------------------------------- .../org/apache/blur/command/TermsCommand.java | 13 ++- .../blur/command/CoreTestClusterContext.java | 85 ++++++++++++++++++++ .../apache/blur/command/TermsCommandTest.java | 32 +++++++- .../org/apache/blur/command/ClusterContext.java | 2 - .../blur/command/ControllerClusterContext.java | 5 -- 5 files changed, 126 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/2a61bb5d/blur-command/src/main/java/org/apache/blur/command/TermsCommand.java ---------------------------------------------------------------------- diff --git a/blur-command/src/main/java/org/apache/blur/command/TermsCommand.java b/blur-command/src/main/java/org/apache/blur/command/TermsCommand.java index be0d5f5..477db7f 100644 --- a/blur-command/src/main/java/org/apache/blur/command/TermsCommand.java +++ b/blur-command/src/main/java/org/apache/blur/command/TermsCommand.java @@ -4,6 +4,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.TreeSet; import org.apache.blur.utils.BlurUtil; import org.apache.lucene.index.AtomicReader; @@ -17,6 +18,9 @@ import org.apache.lucene.search.TermQuery; import org.apache.lucene.search.TopDocs; import org.apache.lucene.util.BytesRef; +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; + /** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with this @@ -55,7 +59,13 @@ public class TermsCommand extends Command implements ClusterCommand<List<String> @Override public List<String> combine(Map<Shard, List<String>> results) throws IOException { - return null; + TreeSet<String> terms = Sets.newTreeSet(); + + for(List<String> t: results.values()) { + terms.addAll(t); + } + //TODO: Use default until we figure out the requested size from the context. + return Lists.newArrayList(terms).subList(0, Math.min(DEFAULT_SIZE, terms.size())); } @Override @@ -104,7 +114,6 @@ public class TermsCommand extends Command implements ClusterCommand<List<String> } return new Term(fieldName, value); - } } http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/2a61bb5d/blur-command/src/test/java/org/apache/blur/command/CoreTestClusterContext.java ---------------------------------------------------------------------- diff --git a/blur-command/src/test/java/org/apache/blur/command/CoreTestClusterContext.java b/blur-command/src/test/java/org/apache/blur/command/CoreTestClusterContext.java new file mode 100644 index 0000000..e1efa9f --- /dev/null +++ b/blur-command/src/test/java/org/apache/blur/command/CoreTestClusterContext.java @@ -0,0 +1,85 @@ +package org.apache.blur.command; + +import java.io.IOException; +import java.util.Map; +import java.util.concurrent.Future; + +import org.apache.blur.BlurConfiguration; +import org.apache.blur.server.TableContext; + +/** + * 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. + */ +public class CoreTestClusterContext extends ClusterContext { + + @Override + public Args getArgs() { + // TODO Auto-generated method stub + return null; + } + + @Override + public TableContext getTableContext(String table) throws IOException { + // TODO Auto-generated method stub + return null; + } + + @Override + public BlurConfiguration getBlurConfiguration(String table) throws IOException { + // TODO Auto-generated method stub + return null; + } + + @Override + public <T> Map<Shard, T> readIndexes(Args args, Class<? extends IndexReadCommand<T>> clazz) throws IOException { + // TODO Auto-generated method stub + return null; + } + + @Override + public <T> Map<Shard, Future<T>> readIndexesAsync(Args args, Class<? extends IndexReadCommand<T>> clazz) + throws IOException { + // TODO Auto-generated method stub + return null; + } + + @Override + public <T> T readIndex(Args args, Class<? extends IndexReadCommand<T>> clazz) throws IOException { + // TODO Auto-generated method stub + return null; + } + + @Override + public <T> Future<T> readIndexAsync(Args args, Class<? extends IndexReadCommand<T>> clazz) throws IOException { + // TODO Auto-generated method stub + return null; + } + + @Override + public <T> Map<Server, T> readServers(Args args, Class<? extends IndexReadCombiningCommand<?, T>> clazz) + throws IOException { + // TODO Auto-generated method stub + return null; + } + + @Override + public <T> Map<Server, Future<T>> readServersAsync(Args args, Class<? extends IndexReadCombiningCommand<?, T>> clazz) + throws IOException { + // TODO Auto-generated method stub + return null; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/2a61bb5d/blur-command/src/test/java/org/apache/blur/command/TermsCommandTest.java ---------------------------------------------------------------------- diff --git a/blur-command/src/test/java/org/apache/blur/command/TermsCommandTest.java b/blur-command/src/test/java/org/apache/blur/command/TermsCommandTest.java index 227acee..7787217 100644 --- a/blur-command/src/test/java/org/apache/blur/command/TermsCommandTest.java +++ b/blur-command/src/test/java/org/apache/blur/command/TermsCommandTest.java @@ -1,14 +1,16 @@ package org.apache.blur.command; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; import java.io.IOException; import java.util.List; +import java.util.Map; import org.junit.BeforeClass; import org.junit.Test; import com.google.common.collect.Lists; +import com.google.common.collect.Maps; /** * Licensed to the Apache Software Foundation (ASF) under one or more @@ -58,11 +60,37 @@ public class TermsCommandTest { assertEquals(expected, returned); } + @Test + public void combineShouldBeCorrect() throws IOException { + Map<Shard, List<String>> execResults = Maps.newHashMap(); + execResults.put(new Shard("t1", "s1"), Lists.newArrayList("aa", "cc")); + execResults.put(new Shard("t1", "s2"), Lists.newArrayList("bb", "dd")); + + List<String> expected = Lists.newArrayList("aa", "bb", "cc", "dd"); + + TermsCommand cmd = new TermsCommand(); + List<String> returned = cmd.combine(execResults); + + assertEquals(expected, returned); + } + + @Test + public void combineEmptyShouldGiveNiceEmptyList() throws IOException { + Map<Shard, List<String>> execResults = Maps.newHashMap(); + List<String> expected = Lists.newArrayList(); + + TermsCommand cmd = new TermsCommand(); + List<String> returned = cmd.combine(execResults); + + assertEquals(expected, returned); + } + + private List<String> getExecuteResult(IndexContext context) throws IOException { TermsCommand cmd = new TermsCommand(); return cmd.execute(context); } - + private IndexContext newContext(String field, Short size, String startsWith) { Args args = new Args(); http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/2a61bb5d/blur-core/src/main/java/org/apache/blur/command/ClusterContext.java ---------------------------------------------------------------------- diff --git a/blur-core/src/main/java/org/apache/blur/command/ClusterContext.java b/blur-core/src/main/java/org/apache/blur/command/ClusterContext.java index b199cb5..5b7040f 100644 --- a/blur-core/src/main/java/org/apache/blur/command/ClusterContext.java +++ b/blur-core/src/main/java/org/apache/blur/command/ClusterContext.java @@ -33,8 +33,6 @@ public abstract class ClusterContext { public abstract BlurConfiguration getBlurConfiguration(String table) throws IOException; - public abstract Configuration getConfiguration(String table) throws IOException; - public abstract <T> Map<Shard, T> readIndexes(Args args, Class<? extends IndexReadCommand<T>> clazz) throws IOException; http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/2a61bb5d/blur-core/src/main/java/org/apache/blur/command/ControllerClusterContext.java ---------------------------------------------------------------------- diff --git a/blur-core/src/main/java/org/apache/blur/command/ControllerClusterContext.java b/blur-core/src/main/java/org/apache/blur/command/ControllerClusterContext.java index dfb030b..ea7dbc7 100644 --- a/blur-core/src/main/java/org/apache/blur/command/ControllerClusterContext.java +++ b/blur-core/src/main/java/org/apache/blur/command/ControllerClusterContext.java @@ -261,11 +261,6 @@ public class ControllerClusterContext extends ClusterContext implements Closeabl } @Override - public Configuration getConfiguration(String table) throws IOException { - return _tableContextFactory.getTableContext(table).getConfiguration(); - } - - @Override public <T> T readIndex(Args args, Class<? extends IndexReadCommand<T>> clazz) throws IOException { Future<T> future = readIndexAsync(args, clazz); try {
