Repository: incubator-blur Updated Branches: refs/heads/master 959fa9cb9 -> 4abcff366
Add initial command archetype Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/4abcff36 Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/4abcff36 Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/4abcff36 Branch: refs/heads/master Commit: 4abcff36658133c70cc3697f2e6e359126d195ef Parents: 959fa9c Author: twilliams <[email protected]> Authored: Tue Nov 18 18:56:02 2014 -0500 Committer: twilliams <[email protected]> Committed: Tue Nov 18 18:56:02 2014 -0500 ---------------------------------------------------------------------- .../main/resources/META-INF/maven/archetype.xml | 32 +++++ .../main/resources/archetype-resources/pom.xml | 119 +++++++++++++++++++ .../src/main/java/MyCommand.java | 86 ++++++++++++++ .../src/test/java/MyCommandIntegrationTest.java | 49 ++++++++ .../src/test/java/MyCommandTest.java | 56 +++++++++ 5 files changed, 342 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/4abcff36/blur-command/src/main/resources/META-INF/maven/archetype.xml ---------------------------------------------------------------------- diff --git a/blur-command/src/main/resources/META-INF/maven/archetype.xml b/blur-command/src/main/resources/META-INF/maven/archetype.xml new file mode 100644 index 0000000..df326f8 --- /dev/null +++ b/blur-command/src/main/resources/META-INF/maven/archetype.xml @@ -0,0 +1,32 @@ +<?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. +--> +<archetype xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype/1.0.0 http://maven.apache.org/xsd/archetype-1.0.0.xsd"> + <id>blur-command</id> + + <allowPartial>true</allowPartial> + <sources> + <source>src/main/java/MyCommand.java</source> + </sources> + <testSources> + <source>src/test/java/MyCommandTest.java</source> + <source>src/test/java/MyCommandIntegrationTest.java</source> + </testSources> +</archetype> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/4abcff36/blur-command/src/main/resources/archetype-resources/pom.xml ---------------------------------------------------------------------- diff --git a/blur-command/src/main/resources/archetype-resources/pom.xml b/blur-command/src/main/resources/archetype-resources/pom.xml new file mode 100644 index 0000000..0dc9df6 --- /dev/null +++ b/blur-command/src/main/resources/archetype-resources/pom.xml @@ -0,0 +1,119 @@ +<?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. --> +<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> + <groupId>${groupId}</groupId> + <artifactId>${artifactId}</artifactId> + <version>${version}</version> + <packaging>jar</packaging> + <name>My Blur Command</name> + <description>MyBlurCommand contains Commands that do...</description> + + <dependencies> + <dependency> + <groupId>org.apache.blur</groupId> + <artifactId>blur-core</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </dependency> + <dependency> + <groupId>org.apache.blur</groupId> + <artifactId>blur-core</artifactId> + <version>${project.version}</version> + <type>test-jar</type> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + <version>${slf4j.version}</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>${slf4j.version}</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>com.google.guava</groupId> + <artifactId>guava</artifactId> + <version>${guava.version}</version> + </dependency> + </dependencies> + + <build> + <pluginManagement> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <argLine>-XX:+UseConcMarkSweepGC -Xmx1g -Xms1g</argLine> + <forkCount>2</forkCount> + <forkMode>always</forkMode> + <reuseForks>false</reuseForks> + <systemPropertyVariables> + <blur.tmp.dir>${project.build.directory}/target/tmp</blur.tmp.dir> + </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> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jar-plugin</artifactId> + <executions> + <execution> + <goals> + <goal>test-jar</goal> + </goals> + </execution> + </executions> + </plugin> + <plugin> + <artifactId>maven-assembly-plugin</artifactId> + <configuration> + <descriptorRefs> + <descriptorRef>jar-with-dependencies</descriptorRef> + </descriptorRefs> + </configuration> + + <executions> + <execution> + <id>make-assembly</id> + <phase>package</phase> + <goals> + <goal>attached</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </pluginManagement> + </build> +</project> http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/4abcff36/blur-command/src/main/resources/archetype-resources/src/main/java/MyCommand.java ---------------------------------------------------------------------- diff --git a/blur-command/src/main/resources/archetype-resources/src/main/java/MyCommand.java b/blur-command/src/main/resources/archetype-resources/src/main/java/MyCommand.java new file mode 100644 index 0000000..c9c3207 --- /dev/null +++ b/blur-command/src/main/resources/archetype-resources/src/main/java/MyCommand.java @@ -0,0 +1,86 @@ +package ${groupId}.${artifactId}; + +import java.io.IOException; +import java.util.Map; + +import org.apache.blur.command.annotation.Description; +import org.apache.blur.command.annotation.RequiredArgument; +import org.apache.blur.command.commandtype.ClusterServerReadCommandSingleTable; +import org.apache.lucene.index.Term; + +/** + * 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. + */ + +@Description("Returns the total number of occurrences of term across all documents (the sum of the freq() for each doc that has this term).") +public class MyCommand extends ClusterServerReadCommandSingleTable<Long> { + private static final String NAME = "myCommand"; + + @RequiredArgument + private String fieldName; + + @RequiredArgument + private String term; + + public TotalTermFreqCommand() { + super(); + } + + public TotalTermFreqCommand(String fieldName, String term) { + super(); + this.fieldName = fieldName; + this.term = term; + } + + @Override + public Long execute(IndexContext context) throws IOException { + return new Long(context.getIndexReader().totalTermFreq(new Term(fieldName, term))); + } + + @Override + public Long combine(CombiningContext context, Map<? extends Location<?>, Long> results) throws IOException, + InterruptedException { + + Long total = 0l; + + for (Long shardTotal : results.values()) { + total += shardTotal; + } + + return total; + } + + @Override + public String getName() { + return NAME; + } + + public String getFieldName() { + return fieldName; + } + + public void setFieldName(String fieldName) { + this.fieldName = fieldName; + } + + public String getTerm() { + return term; + } + + public void setValue(String term) { + this.term = term; + } +} http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/4abcff36/blur-command/src/main/resources/archetype-resources/src/test/java/MyCommandIntegrationTest.java ---------------------------------------------------------------------- diff --git a/blur-command/src/main/resources/archetype-resources/src/test/java/MyCommandIntegrationTest.java b/blur-command/src/main/resources/archetype-resources/src/test/java/MyCommandIntegrationTest.java new file mode 100644 index 0000000..9165570 --- /dev/null +++ b/blur-command/src/main/resources/archetype-resources/src/test/java/MyCommandIntegrationTest.java @@ -0,0 +1,49 @@ +package ${groupId}.${artifactId}; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.util.List; + +import org.apache.blur.thirdparty.thrift_0_9_0.TException; +import org.apache.blur.thrift.BaseClusterTest; +import org.apache.blur.thrift.TableGen; +import org.apache.blur.thrift.generated.BlurException; +import org.junit.Test; + +import com.google.common.collect.Lists; + +/** + * 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 MyCommandIntegrationTests extends BaseClusterTest { + + @Test + public void testTotalTermFreq() throws BlurException, TException, IOException, InterruptedException { + final String tableName = "testTotalTermFreq"; + TableGen.define(tableName).cols("test", "col1").addRows(100, 20, "r1", "rec-###", "value").build(getClient()); + + TermsCommand command = new TermsCommand(); + command.setTable(tableName); + command.setFieldName("test.col1"); + + List<String> terms = command.run(getClient()); + List<String> list = Lists.newArrayList("value"); + assertEquals(list, terms); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/4abcff36/blur-command/src/main/resources/archetype-resources/src/test/java/MyCommandTest.java ---------------------------------------------------------------------- diff --git a/blur-command/src/main/resources/archetype-resources/src/test/java/MyCommandTest.java b/blur-command/src/main/resources/archetype-resources/src/test/java/MyCommandTest.java new file mode 100644 index 0000000..72ebbdd --- /dev/null +++ b/blur-command/src/main/resources/archetype-resources/src/test/java/MyCommandTest.java @@ -0,0 +1,56 @@ +package ${groupId}.${artifactId}; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +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 + * 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 MyCommandTest { + private static IndexContext ctx; + + @BeforeClass + public static void init() { + ctx = CoreTestContext.newSimpleAlpaNumContext(); + } + + @Test + public void termInAllDocsShouldBeCorrect() throws IOException { + Long returned = new MyCommand("val", "val").execute(ctx); + Long expected = 26l; + + assertEquals(expected, returned); + } + + @Test + public void singleDocFreq() throws IOException { + Long returned = new MyCommand("dupVal", "dupVal").execute(ctx); + Long expected = 52l; + + assertEquals(expected, returned); + } + + + +}
