This commit is contained in:
Karl Wright 2018-04-28 09:14:05 -04:00
commit 400449f2c7
6 changed files with 159 additions and 14 deletions

View File

@ -14,13 +14,16 @@
# See the License for the specific language governing permissions and
# limitations under the License.
ASSERT_SUCCEEDED=1
ASSERT_FAILURE=0
ASSERT_SUCCESS=0
ASSERT_FAILURE=1
TEST_SUCCESS=0
TEST_FAILURE=1
function assert_cmd_succeeded() {
retval=$?
if [[ $? -ne 0 ]]; then
if [[ $retval -ne 0 ]]; then
echo "Expected command $1 to succeed, but exited with $retval"
return $ASSERT_FAILURE
fi
@ -31,7 +34,7 @@ function assert_cmd_succeeded() {
function assert_cmd_failed() {
retval=$?
if [[ $? -eq 0 ]]; then
if [[ $retval -eq 0 ]]; then
echo "Expected command $1 to fail, but exited with $retval"
return $ASSERT_FAILURE
fi
@ -67,9 +70,9 @@ function assert_collection_exists() {
local coll_name=$1
local coll_list=$(bin/solr zk ls /collections -z localhost:9983)
for coll in "$coll_list";
for coll in $coll_list;
do
if [[ $(echo $coll | tr -d " ") -eq $coll_name ]]; then
if [[ $(echo $coll | tr -d " ") == $coll_name ]]; then
return $ASSERT_SUCCESS
fi
done
@ -81,9 +84,10 @@ function assert_collection_exists() {
function assert_collection_doesnt_exist() {
local coll_name=$1
local coll_list=$(bin/solr zk ls /collections -z localhost:9983)
for coll in "$coll_list";
for coll in $coll_list;
do
if [[ $(echo $coll | tr -d " ") -eq $coll_name ]]; then
echo "Comparing $coll to $coll_name"
if [[ $(echo $coll | tr -d " ") == "$coll_name" ]]; then
echo "Expected not to find collection [$coll_name], but it exists"
return $ASSERT_FAILURE
fi
@ -96,9 +100,9 @@ function assert_config_exists() {
local config_name=$1
local config_list=$(bin/solr zk ls /configs -z localhost:9983)
for config in "$config_list";
for config in $config_list;
do
if [[ $(echo $config | tr -d " ") -eq $config_name ]]; then
if [[ $(echo $config | tr -d " ") == $config_name ]]; then
return $ASSERT_SUCCESS
fi
done
@ -111,9 +115,9 @@ function assert_config_doesnt_exist() {
local config_name=$1
local config_list=$(bin/solr zk ls /configs -z localhost:9983)
for config in "$config_list";
for config in $config_list;
do
if [[ $(echo $config | tr -d " ") -eq $config_name ]]; then
if [[ $(echo $config | tr -d " ") == $config_name ]]; then
echo "Expected not to find config [$config_name], but it exists"
return $ASSERT_FAILURE
fi

View File

@ -242,8 +242,10 @@ public class Lang {
.withFunctionName("earthMovers", EarthMoversEvaluator.class)
.withFunctionName("euclidean", EuclideanEvaluator.class)
.withFunctionName("chebyshev", ChebyshevEvaluator.class)
.withFunctionName("ones", OnesEvaluator.class)
.withFunctionName("zeros", ZerosEvaluator.class)
// Boolean Stream Evaluators
// Boolean Stream Evaluators
.withFunctionName("and", AndEvaluator.class)
.withFunctionName("eor", ExclusiveOrEvaluator.class)

View File

@ -0,0 +1,47 @@
/*
* 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.solr.client.solrj.io.eval;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import org.apache.solr.client.solrj.io.stream.expr.StreamExpression;
import org.apache.solr.client.solrj.io.stream.expr.StreamFactory;
public class OnesEvaluator extends RecursiveNumericEvaluator implements OneValueWorker {
protected static final long serialVersionUID = 1L;
public OnesEvaluator(StreamExpression expression, StreamFactory factory) throws IOException{
super(expression, factory);
if(1 != containedEvaluators.size()){
throw new IOException(String.format(Locale.ROOT,"Invalid expression %s - expecting exactly 1 value but found %d",expression,containedEvaluators.size()));
}
}
@Override
public Object doWork(Object value){
int size = ((Number)value).intValue();
List<Number> ones = new ArrayList();
for(int i=0; i<size; i++) {
ones.add(1);
}
return ones;
}
}

View File

@ -0,0 +1,47 @@
/*
* 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.solr.client.solrj.io.eval;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import org.apache.solr.client.solrj.io.stream.expr.StreamExpression;
import org.apache.solr.client.solrj.io.stream.expr.StreamFactory;
public class ZerosEvaluator extends RecursiveNumericEvaluator implements OneValueWorker {
protected static final long serialVersionUID = 1L;
public ZerosEvaluator(StreamExpression expression, StreamFactory factory) throws IOException{
super(expression, factory);
if(1 != containedEvaluators.size()){
throw new IOException(String.format(Locale.ROOT,"Invalid expression %s - expecting exactly 1 value but found %d",expression,containedEvaluators.size()));
}
}
@Override
public Object doWork(Object value){
int size = ((Number)value).intValue();
List<Number> ones = new ArrayList();
for(int i=0; i<size; i++) {
ones.add(0);
}
return ones;
}
}

View File

@ -69,7 +69,7 @@ public class TestLang extends LuceneTestCase {
TemporalEvaluatorDayOfQuarter.FUNCTION_NAME, "abs", "add", "div", "mult", "sub", "log", "pow",
"mod", "ceil", "floor", "sin", "asin", "sinh", "cos", "acos", "cosh", "tan", "atan", "tanh", "round", "sqrt",
"cbrt", "coalesce", "uuid", "if", "convert", "valueAt", "memset", "fft", "ifft", "euclidean","manhattan",
"earthMovers", "canberra", "chebyshev"};
"earthMovers", "canberra", "chebyshev", "ones", "zeros"};
@Test
public void testLang() {

View File

@ -995,6 +995,51 @@ public class MathExpressionTest extends SolrCloudTestCase {
assertTrue(out.get(5).doubleValue() == 500.23D);
}
@Test
public void testOnes() throws Exception {
String cexpr = "ones(6)";
ModifiableSolrParams paramsLoc = new ModifiableSolrParams();
paramsLoc.set("expr", cexpr);
paramsLoc.set("qt", "/stream");
String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;
TupleStream solrStream = new SolrStream(url, paramsLoc);
StreamContext context = new StreamContext();
solrStream.setStreamContext(context);
List<Tuple> tuples = getTuples(solrStream);
assertTrue(tuples.size() == 1);
List<Number> out = (List<Number>)tuples.get(0).get("return-value");
assertEquals(out.size(), 6);
assertEquals(out.get(0).intValue(), 1);
assertEquals(out.get(1).intValue(), 1);
assertEquals(out.get(2).intValue(), 1);
assertEquals(out.get(3).intValue(), 1);
assertEquals(out.get(4).intValue(), 1);
assertEquals(out.get(5).intValue(), 1);
}
@Test
public void testZeros() throws Exception {
String cexpr = "zeros(6)";
ModifiableSolrParams paramsLoc = new ModifiableSolrParams();
paramsLoc.set("expr", cexpr);
paramsLoc.set("qt", "/stream");
String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;
TupleStream solrStream = new SolrStream(url, paramsLoc);
StreamContext context = new StreamContext();
solrStream.setStreamContext(context);
List<Tuple> tuples = getTuples(solrStream);
assertTrue(tuples.size() == 1);
List<Number> out = (List<Number>)tuples.get(0).get("return-value");
assertEquals(out.size(), 6);
assertEquals(out.get(0).intValue(), 0);
assertEquals(out.get(1).intValue(), 0);
assertEquals(out.get(2).intValue(), 0);
assertEquals(out.get(3).intValue(), 0);
assertEquals(out.get(4).intValue(), 0);
assertEquals(out.get(5).intValue(), 0);
}
@Test
public void testMatrix() throws Exception {
String cexpr = "let(echo=true," +