Apache Solr open-source search software
SOLR-10393: Adds UUID Streaming Evaluator
Dennis Goveef821834d151
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 1c3aaf725d4..e30824f962e 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -63,6 +63,8 @@ New Features* SOLR-10356: Adds basic math Streaming Evaluators (Dennis Gove)+* SOLR-10393: Adds UUID Streaming Evaluator (Dennis Gove)+Bug Fixes----------------------* SOLR-9262: Connection and read timeouts are being ignored by UpdateShardHandler after SOLR-4509.diff --git a/solr/core/src/java/org/apache/solr/handler/StreamHandler.java b/solr/core/src/java/org/apache/solr/handler/StreamHandler.javaindex b508754b20a..599924ed358 100644--- a/solr/core/src/java/org/apache/solr/handler/StreamHandler.java+++ b/solr/core/src/java/org/apache/solr/handler/StreamHandler.java@@ -67,6 +67,7 @@ import org.apache.solr.client.solrj.io.eval.SineEvaluator;import org.apache.solr.client.solrj.io.eval.SquareRootEvaluator;import org.apache.solr.client.solrj.io.eval.SubtractEvaluator;import org.apache.solr.client.solrj.io.eval.TangentEvaluator;+import org.apache.solr.client.solrj.io.eval.UuidEvaluator;import org.apache.solr.client.solrj.io.graph.GatherNodesStream;import org.apache.solr.client.solrj.io.graph.ShortestPathStream;import org.apache.solr.client.solrj.io.ops.ConcatOperation;@@ -277,6 +278,7 @@ public class StreamHandler extends RequestHandlerBase implements SolrCoreAware,.withFunctionName("sqrt", SquareRootEvaluator.class).withFunctionName("cbrt", CubedRootEvaluator.class).withFunctionName("coalesce", CoalesceEvaluator.class)+ .withFunctionName("uuid", UuidEvaluator.class)// Conditional Stream Evaluators.withFunctionName("if", IfThenElseEvaluator.class)diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/UuidEvaluator.java b/solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/UuidEvaluator.javanew file mode 100644index 00000000000..88acee45f37--- /dev/null+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/UuidEvaluator.java@@ -0,0 +1,57 @@+/*+ * 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.UUID;++import org.apache.solr.client.solrj.io.Tuple;+import org.apache.solr.client.solrj.io.stream.expr.Explanation;+import org.apache.solr.client.solrj.io.stream.expr.Explanation.ExpressionType;+import org.apache.solr.client.solrj.io.stream.expr.StreamExpression;+import org.apache.solr.client.solrj.io.stream.expr.StreamExpressionParameter;+import org.apache.solr.client.solrj.io.stream.expr.StreamFactory;++public class UuidEvaluator extends SimpleEvaluator {+ protected static final long serialVersionUID = 1L;++ public UuidEvaluator(StreamExpression expression, StreamFactory factory) throws IOException{+ // no parameters are used+ }++ @Override+ public UUID evaluate(Tuple tuple) throws IOException {+ return UUID.randomUUID();+ }++ @Override+ public StreamExpressionParameter toExpression(StreamFactory factory) throws IOException {+ return new StreamExpression(factory.getFunctionName(getClass()));+ }++ @Override+ public Explanation toExplanation(StreamFactory factory) throws IOException {+ return new Explanation(nodeId.toString())+ .withExpressionType(ExpressionType.EVALUATOR)+ .withImplementingClass(getClass().getName())+ .withExpression(toExpression(factory).toString());+ }++}diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/eval/UuidEvaluatorTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/eval/UuidEvaluatorTest.javanew file mode 100644index 00000000000..682b600493c--- /dev/null+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/eval/UuidEvaluatorTest.java@@ -0,0 +1,52 @@+/*+ * 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.stream.eval;++import java.util.HashMap;+import java.util.Map;+import java.util.UUID;++import org.apache.lucene.util.LuceneTestCase;+import org.apache.solr.client.solrj.io.Tuple;+import org.apache.solr.client.solrj.io.eval.StreamEvaluator;+import org.apache.solr.client.solrj.io.eval.UuidEvaluator;+import org.apache.solr.client.solrj.io.stream.expr.StreamFactory;+import org.junit.Test;++import junit.framework.Assert;++public class UuidEvaluatorTest extends LuceneTestCase {++ StreamFactory factory;+ Map<String, Object> values;++ public UuidEvaluatorTest() {+ super();++ factory = new StreamFactory()+ .withFunctionName("uuid", UuidEvaluator.class);+ values = new HashMap<String,Object>();+ }++ @Test+ public void isUuidType() throws Exception{+ StreamEvaluator evaluator = factory.constructEvaluator("uuid()");++ Assert.assertTrue(evaluator.evaluate(null) instanceof UUID);+ Assert.assertTrue(evaluator.evaluate(new Tuple(values)) instanceof UUID);+ }+}