mirror of https://github.com/apache/lucene.git
SOLR-10393: Adds UUID Streaming Evaluator
This commit is contained in:
parent
017a4b796f
commit
14e412d64a
|
@ -69,6 +69,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.
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue