Apache Solr open-source search software
SOLR-11145, SOLR-11146: Added comprehensive unit tests for Analytics Component 2.0 as well as analytics bug fixes.
Houston Putman86d84bff82ff
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/AnalyticsRequestParser.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/AnalyticsRequestParser.javaindex bfa62e2a151..bcb77473cf6 100644--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/AnalyticsRequestParser.java+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/AnalyticsRequestParser.java@@ -73,34 +73,8 @@ public class AnalyticsRequestParser {public static final String analyticsParamName = "analytics";- private static Predicate<String> request = acceptNames("request", "req");- private static Predicate<String> functions = acceptNames("functions", "funcs", "f");- private static Predicate<String> expressions = acceptNames("expressions", "exprs", "e");-- private static Predicate<String> grouping = acceptNames("grouping", "group", "g");-- private static Predicate<String> valueFacet = acceptNames("valuefacet", "vf");-- private static Predicate<String> pivotFacet = acceptNames("pivotfacet", "pf");- private static Predicate<String> pivot = acceptNames("pivot", "p");-- private static Predicate<String> sort = acceptNames("sort", "s");- private static Predicate<String> sortExpression = acceptNames("expression", "expr");- private static Predicate<String> sortFacetValue = acceptNames("facetvalue", "fv");- private static Predicate<String> sortDirection = acceptNames("direction", "dir");private static Predicate<String> sortAscending = acceptNames("ascending", "asc", "a");private static Predicate<String> sortDescending = acceptNames("descending", "desc", "d");- private static Predicate<String> sortLimit = acceptNames("limit", "l");- private static Predicate<String> sortOffset = acceptNames("offset", "o");-- private static Predicate<String> rangeFacet = acceptNames("rangefacet", "rf");- private static Predicate<String> rangeGaps = acceptNames("gaps", "g");- private static Predicate<String> rangeHardEnd = acceptNames("hardend", "he");- private static Predicate<String> rangeInclude = acceptNames("include", "i");- private static Predicate<String> rangeOthers = acceptNames("others", "o");-- private static Predicate<String> queryFacet = acceptNames("queryfacet", "qf");- private static Predicate<String> query = acceptNames("query", "q");private static Predicate<String> acceptNames(String... names) {return Pattern.compile("^(?:" + Arrays.stream(names).reduce((a,b) -> a + "|" + b).orElse("") + ")$", Pattern.CASE_INSENSITIVE).asPredicate();diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/ExpressionFactory.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/ExpressionFactory.javaindex 1d7a793d38b..18020b79d97 100644--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/ExpressionFactory.java+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/ExpressionFactory.java@@ -17,6 +17,7 @@package org.apache.solr.analytics;import java.util.ArrayList;+import java.util.Arrays;import java.util.HashMap;import java.util.HashSet;import java.util.LinkedHashMap;@@ -28,15 +29,14 @@ import java.util.regex.Pattern;import org.apache.solr.analytics.function.MergingReductionCollectionManager;import org.apache.solr.analytics.function.ReductionCollectionManager;import org.apache.solr.analytics.function.mapping.*;-import org.apache.solr.analytics.function.mapping.CompareFunction.EqualFunction;-import org.apache.solr.analytics.function.mapping.CompareFunction.GTEFunction;-import org.apache.solr.analytics.function.mapping.CompareFunction.GTFunction;-import org.apache.solr.analytics.function.mapping.CompareFunction.LTEFunction;-import org.apache.solr.analytics.function.mapping.CompareFunction.LTFunction;-import org.apache.solr.analytics.function.mapping.ConcatFunction.ConcatSeparatedFunction;-import org.apache.solr.analytics.function.mapping.NumericConvertFunction.CeilingFunction;-import org.apache.solr.analytics.function.mapping.NumericConvertFunction.FloorFunction;-import org.apache.solr.analytics.function.mapping.NumericConvertFunction.RoundFunction;+import org.apache.solr.analytics.function.mapping.ComparisonFunction.GTEFunction;+import org.apache.solr.analytics.function.mapping.ComparisonFunction.GTFunction;+import org.apache.solr.analytics.function.mapping.ComparisonFunction.LTEFunction;+import org.apache.solr.analytics.function.mapping.ComparisonFunction.LTFunction;+import org.apache.solr.analytics.function.mapping.ConcatFunction.SeparatedConcatFunction;+import org.apache.solr.analytics.function.mapping.DecimalNumericConversionFunction.CeilingFunction;+import org.apache.solr.analytics.function.mapping.DecimalNumericConversionFunction.FloorFunction;+import org.apache.solr.analytics.function.mapping.DecimalNumericConversionFunction.RoundFunction;import org.apache.solr.analytics.function.mapping.LogicFunction.AndFunction;import org.apache.solr.analytics.function.mapping.LogicFunction.OrFunction;import org.apache.solr.analytics.function.reduction.*;@@ -177,13 +177,17 @@ public class ExpressionFactory {/*** Add a variable function that will be treated like a system function.*- * @param functionSignature the function signature of the variable function (e.g. {@code func(a,b)} )+ * @param functionName the function's name+ * @param functionParams the comma separated and ordered parameters of the function (e.g. {@code "a,b"} )* @param returnSignature the return signature of the variable function (e.g. {@code div(sum(a,b),count(b))} )* @return this factory, to easily chain function adds* @throws SolrException if the name of the function is not unique or the syntax of either signature is incorrect*/- public ExpressionFactory addSystemVariableFunction(final String functionSignature, final String returnSignature) throws SolrException {- return addVariableFunction(functionSignature, returnSignature, systemVariableFunctions);+ public ExpressionFactory addSystemVariableFunction(final String functionName, final String functionParams, final String returnSignature) throws SolrException {+ return addVariableFunction(functionName,+ Arrays.stream(functionParams.split(",")).map(param -> param.trim()).toArray(size -> new String[size]),+ returnSignature,+ systemVariableFunctions);}/**@@ -210,12 +214,29 @@ public class ExpressionFactory {private ExpressionFactory addVariableFunction(final String functionSignature,final String returnSignature,Map<String,VariableFunctionInfo> variableFunctions) throws SolrException {- String functionName = getFunctionName(functionSignature);+ addVariableFunction(getFunctionName(functionSignature), getParams(functionSignature, null, null), returnSignature, variableFunctions);+ return this;+ }++ /**+ * Add a variable function to the given map of variable functions.+ *+ * @param functionName the function's name+ * @param functionParams the parameters of the function (this is ordered)+ * @param returnSignature the return signature of the variable function (e.g. {@code div(sum(a,b),count(b))} )+ * @param variableFunctions the map of variable functions to add the new function to+ * @return this factory, to easily chain function adds+ * @throws SolrException if the name of the function is not unique or the syntax of either signature is incorrect+ */+ private ExpressionFactory addVariableFunction(final String functionName,+ final String[] functionParams,+ final String returnSignature,+ Map<String,VariableFunctionInfo> variableFunctions) throws SolrException {if (expressionCreators.containsKey(functionName)) {throw new SolrException(ErrorCode.BAD_REQUEST,"Users cannot define a variable function with the same name as an existing function: " + functionName);}VariableFunctionInfo varFuncInfo = new VariableFunctionInfo();- varFuncInfo.params = getParams(functionSignature, null, null);+ varFuncInfo.params = functionParams;varFuncInfo.returnSignature = returnSignature;variableFunctions.put(functionName, varFuncInfo);return this;@@ -292,13 +313,9 @@ public class ExpressionFactory {// Not a constant// If the expression has parens, it is an expression otherwise it is a fieldif (!expressionStr.contains("(")) {- try {- // Try to make a field out of it- expression = createField(schema.getField(expressionStr));- isField = true;- } catch (SolrException e2) {- throw new SolrException(ErrorCode.BAD_REQUEST,"The following is not a field, constant or function : " + expressionStr);- }+ // Try to make a field out of it+ expression = createField(schema.getField(expressionStr));+ isField = true;} else {// Must be a functionexpression = createFunction(expressionStr, varFuncParams, varFuncVarParamName, varFuncVarParamValues);@@ -367,6 +384,9 @@ public class ExpressionFactory {final String[] params = getParams(expressionStr, varFuncVarParamName, varFuncVarParamValues);AnalyticsValueStream[] paramStreams = new AnalyticsValueStream[params.length];++ boolean allParamsConstant = true;+for (int i = 0; i < params.length; i++) {// First check if the parameter is a variable function variable otherwise create the expressionif (varFuncParams.containsKey(params[i])) {@@ -374,7 +394,11 @@ public class ExpressionFactory {} else {paramStreams[i] = createExpression(params[i], varFuncParams, varFuncVarParamName, varFuncVarParamValues);}++ // Then update whether all of the params are constant+ allParamsConstant &= paramStreams[i].getExpressionType().equals(ExpressionType.CONST);}+// Check to see if the function name is a variable function name, if so apply the variables to the return signatureif (variableFunctions.containsKey(name)) {if (variableFunctionNameHistory.contains(name)) {@@ -386,6 +410,10 @@ public class ExpressionFactory {boolean varLenEnd = false;+ if (paramStreams.length < newVarFunc.params.length) {+ throw new SolrException(ErrorCode.BAD_REQUEST,"The variable function '" + name + "' requires at least " + newVarFunc.params.length + " parameters."+ + " Only " + paramStreams.length + " arguments given in the following invocation : " + expressionStr);+ }for (int i = 0; i < newVarFunc.params.length; ++i) {String variable = newVarFunc.params[i];if (variable.endsWith(variableLengthParamSuffix)) {@@ -408,16 +436,23 @@ public class ExpressionFactory {}}if (!varLenEnd) {+ if (paramStreams.length > newVarFunc.params.length) {+ throw new SolrException(ErrorCode.BAD_REQUEST,"The variable function '" + name + "' requires " + newVarFunc.params.length + " parameters."+ + " " + paramStreams.length + " arguments given in the following invocation : " + expressionStr);+ }expression = createExpression(newVarFunc.returnSignature, newVarFuncParams, null, null);}variableFunctionNameHistory.remove(name);- return expression;} else if (expressionCreators.containsKey(name)) {// It is a regular system functionexpression = expressionCreators.get(name).apply(paramStreams);} else {throw new SolrException(ErrorCode.BAD_REQUEST,"The following function does not exist: " + name);}++ // If the all params are constant, then try to convert the expression to a constant value.+ expression = expression.convertToConstant();+return expression;}@@ -751,19 +786,18 @@ public class ExpressionFactory {expressionCreators.put(BottomFunction.name, BottomFunction.creatorFunction);expressionCreators.put(CeilingFunction.name, CeilingFunction.creatorFunction);expressionCreators.put(ConcatFunction.name, ConcatFunction.creatorFunction);- expressionCreators.put(ConcatSeparatedFunction.name, ConcatSeparatedFunction.creatorFunction);+ expressionCreators.put(SeparatedConcatFunction.name, SeparatedConcatFunction.creatorFunction);expressionCreators.put(DateMathFunction.name, DateMathFunction.creatorFunction);expressionCreators.put(DateParseFunction.name, DateParseFunction.creatorFunction);expressionCreators.put(DivideFunction.name, DivideFunction.creatorFunction);- expressionCreators.put(DocCountFunction.name, DocCountFunction.creatorFunction);expressionCreators.put(EqualFunction.name,EqualFunction.creatorFunction);+ expressionCreators.put(ExistsFunction.name,ExistsFunction.creatorFunction);expressionCreators.put(FillMissingFunction.name, FillMissingFunction.creatorFunction);expressionCreators.put(FilterFunction.name, FilterFunction.creatorFunction);expressionCreators.put(FloorFunction.name, FloorFunction.creatorFunction);expressionCreators.put(GTFunction.name,GTFunction.creatorFunction);expressionCreators.put(GTEFunction.name,GTEFunction.creatorFunction);expressionCreators.put(IfFunction.name, IfFunction.creatorFunction);- expressionCreators.put(JoinFunction.name, JoinFunction.creatorFunction);expressionCreators.put(LogFunction.name,LogFunction.creatorFunction);expressionCreators.put(LTFunction.name,LTFunction.creatorFunction);expressionCreators.put(LTEFunction.name,LTEFunction.creatorFunction);@@ -780,7 +814,9 @@ public class ExpressionFactory {// Reduction FunctionsexpressionCreators.put(CountFunction.name, CountFunction.creatorFunction);+ expressionCreators.put(DocCountFunction.name, DocCountFunction.creatorFunction);expressionCreators.put(MaxFunction.name, MaxFunction.creatorFunction);+ expressionCreators.put(MeanFunction.name, MeanFunction.creatorFunction);expressionCreators.put(MedianFunction.name, MedianFunction.creatorFunction);expressionCreators.put(MinFunction.name, MinFunction.creatorFunction);expressionCreators.put(MissingFunction.name, MissingFunction.creatorFunction);@@ -790,14 +826,13 @@ public class ExpressionFactory {expressionCreators.put(UniqueFunction.name, UniqueFunction.creatorFunction);// Variables- addSystemVariableFunction("wmean(a,b)","div(mean(prod(a,b)),sum(b))");- addSystemVariableFunction("mean(a)","div(sum(a),count(a))");- addSystemVariableFunction("sumofsquares(a)","sum(pow(a,2))");- addSystemVariableFunction("sqrt(a)","pow(a,0.5)");- addSystemVariableFunction("variance(a)","sub(mean(pow(a,2)),pow(mean(a),2))");- addSystemVariableFunction("stddev(a)","sqrt(variance(a))");- addSystemVariableFunction("csv(a..)","concatsep(',',a)");- addSystemVariableFunction("csv_output(a..)","concatsep(',',a:fillmissing(join(_,';'),''))");+ addSystemVariableFunction(WeightedMeanVariableFunction.name, WeightedMeanVariableFunction.params, WeightedMeanVariableFunction.function);+ addSystemVariableFunction(SumOfSquaresVariableFunction.name, SumOfSquaresVariableFunction.params, SumOfSquaresVariableFunction.function);+ addSystemVariableFunction(SquareRootVariableFunction.name, SquareRootVariableFunction.params, SquareRootVariableFunction.function);+ addSystemVariableFunction(VarianceVariableFunction.name, VarianceVariableFunction.params, VarianceVariableFunction.function);+ addSystemVariableFunction(SandardDeviationVariableFunction.name, SandardDeviationVariableFunction.params, SandardDeviationVariableFunction.function);+ addSystemVariableFunction(CSVVariableFunction.name, CSVVariableFunction.params, CSVVariableFunction.function);+ addSystemVariableFunction(CSVOutputVariableFunction.name, CSVOutputVariableFunction.params, CSVOutputVariableFunction.function);}/**@@ -818,4 +853,39 @@ public class ExpressionFactory {class VariableFunctionInfo {public String[] params;public String returnSignature;+}+class WeightedMeanVariableFunction {+ public static final String name = "wmean";+ public static final String params = "a,b";+ public static final String function = DivideFunction.name+"("+SumFunction.name+"("+MultFunction.name+"(a,b)),"+SumFunction.name+"("+FilterFunction.name+"(b,"+ExistsFunction.name+"(a))))";+}+class SumOfSquaresVariableFunction {+ public static final String name = "sumofsquares";+ public static final String params = "a";+ public static final String function = SumFunction.name+"("+PowerFunction.name+"(a,2))";+}+class SquareRootVariableFunction {+ public static final String name = "sqrt";+ public static final String params = "a";+ public static final String function = PowerFunction.name+"(a,0.5)";+}+class VarianceVariableFunction {+ public static final String name = "variance";+ public static final String params = "a";+ public static final String function = SubtractFunction.name+"("+MeanFunction.name+"("+PowerFunction.name+"(a,2)),"+PowerFunction.name+"("+MeanFunction.name+"(a),2))";+}+class SandardDeviationVariableFunction {+ public static final String name = "stddev";+ public static final String params = "a";+ public static final String function = SquareRootVariableFunction.name+"("+VarianceVariableFunction.name+"(a))";+}+class CSVVariableFunction {+ public static final String name = "csv";+ public static final String params = "a"+ExpressionFactory.variableLengthParamSuffix;+ public static final String function = SeparatedConcatFunction.name+"(',',a)";+}+class CSVOutputVariableFunction {+ public static final String name = "csv_output";+ public static final String params = "a"+ExpressionFactory.variableLengthParamSuffix;+ public static final String function = "concat_sep(',',a"+ExpressionFactory.variableForEachSep+FillMissingFunction.name+"("+SeparatedConcatFunction.name+"(';',"+ExpressionFactory.variableForEachParam+"),''))";}\ No newline at end of filediff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/field/AnalyticsField.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/field/AnalyticsField.javaindex dab03586afe..e0bbb4b2871 100644--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/field/AnalyticsField.java+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/field/AnalyticsField.java@@ -50,6 +50,11 @@ public abstract class AnalyticsField implements AnalyticsValueStream {return ExpressionType.FIELD;}+ @Override+ public AnalyticsValueStream convertToConstant() {+ return this;+ }+/*** Set the segment reader context*diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/BottomFunction.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/BottomFunction.javaindex f896da4d528..10674fddb90 100644--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/BottomFunction.java+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/BottomFunction.java@@ -141,7 +141,7 @@ public class BottomFunction {}if (param instanceof StringValueStream) {if (params.length == 1) {- return LambdaFunction.createStringLambdaFunction(name, (a,b) -> (a.compareTo(b)<=0)? a:b, (StringValueStream)param);+ return LambdaFunction.createStringLambdaFunction(name, (a,b) -> (a.compareTo(b)<0)? a:b, (StringValueStream)param);}StringValue[] castedParams = new StringValue[params.length];boolean tryNextType = false;@@ -154,7 +154,7 @@ public class BottomFunction {}}if (!tryNextType) {- return LambdaFunction.createStringLambdaFunction(name, (a,b) -> (a.compareTo(b)<=0)? a:b, castedParams, false);+ return LambdaFunction.createStringLambdaFunction(name, (a,b) -> (a.compareTo(b)<0)? a:b, castedParams, false);}}throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires a comparable parameter. " +diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/CompareFunction.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/CompareFunction.javadeleted file mode 100644index a06f7b88682..00000000000--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/CompareFunction.java+++ /dev/null@@ -1,614 +0,0 @@-/*- * 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.analytics.function.mapping;--import org.apache.solr.analytics.ExpressionFactory.CreatorFunction;-import org.apache.solr.analytics.util.function.BooleanConsumer;-import org.apache.solr.analytics.value.AnalyticsValue;-import org.apache.solr.analytics.value.AnalyticsValueStream;-import org.apache.solr.analytics.value.BooleanValue;-import org.apache.solr.analytics.value.BooleanValueStream;-import org.apache.solr.analytics.value.DateValue;-import org.apache.solr.analytics.value.DateValueStream;-import org.apache.solr.analytics.value.DoubleValue;-import org.apache.solr.analytics.value.DoubleValueStream;-import org.apache.solr.analytics.value.StringValue;-import org.apache.solr.analytics.value.StringValueStream;-import org.apache.solr.analytics.value.BooleanValue.AbstractBooleanValue;-import org.apache.solr.analytics.value.BooleanValueStream.AbstractBooleanValueStream;-import org.apache.solr.common.SolrException;-import org.apache.solr.common.SolrException.ErrorCode;--/**- * Contains all comparable functions. Comparable functions accept two parameters and return a BooleanValueStream.- * The two parameters must be able to be cast to the same type.- * <p>- * Uses:- * <ul>- * <li>If a two comparable {@link AnalyticsValue}s are passed in, a {@link BooleanValue} representing the comparison of the two values for each document is returned.- * <li>If a comparable {@link AnalyticsValue} and a comparable {@link AnalyticsValueStream} are passed in,- * a {@link BooleanValueStream} representing the comparison of the Value and each of the values of the ValueStream for the document is returned.- * </ul>- */-public class CompareFunction {-- private static BooleanValueStream createCompareFunction(String name, CompResultFunction comp, AnalyticsValueStream... params) {- if (params.length != 2) {- throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires 2 paramaters, " + params.length + " found.");- }- AnalyticsValueStream paramA = params[0];- AnalyticsValueStream paramB = params[1];- if (paramA instanceof DateValueStream && paramB instanceof DateValueStream) {- if (paramA instanceof DateValue) {- if (paramB instanceof DateValue) {- return new CompareDateValueFunction(name,(DateValue)paramA,(DateValue)paramB,comp);- }- return new CompareDateStreamFunction(name,(DateValue)paramA,(DateValueStream)paramB,comp);- }- if (paramB instanceof DateValue) {- return new CompareDateStreamFunction(name,(DateValue)paramB,(DateValueStream)paramA,reverse(comp));- }- } else if (paramA instanceof DoubleValueStream && paramB instanceof DoubleValueStream) {- if (paramA instanceof DoubleValue) {- if (paramB instanceof DoubleValue) {- return new CompareDoubleValueFunction(name,(DoubleValue)paramA,(DoubleValue)paramB,comp);- }- return new CompareDoubleStreamFunction(name,(DoubleValue)paramA,(DoubleValueStream)paramB,comp);- }- if (paramB instanceof DoubleValue) {- return new CompareDoubleStreamFunction(name,(DoubleValue)paramB,(DoubleValueStream)paramA,reverse(comp));- }- } else if (paramA instanceof StringValueStream && paramB instanceof StringValueStream) {- if (paramA instanceof StringValue) {- if (paramB instanceof StringValue) {- return new CompareStringValueFunction(name,(StringValue)paramA,(StringValue)paramB,comp);- }- return new CompareStringStreamFunction(name,(StringValue)paramA,(StringValueStream)paramB,comp);- }- if (paramB instanceof StringValue) {- return new CompareStringStreamFunction(name,(StringValue)paramB,(StringValueStream)paramA,reverse(comp));- }- } else {- throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires comparable parameters.");- }- throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires that at least 1 parameter be single-valued.");- }-- /**- * A comparison function that tests equality.- */- public static class EqualFunction {- public static final String name = "equal";- public static final CreatorFunction creatorFunction = (params -> {- try {- return CompareFunction.createCompareFunction(name, val -> {- return val == 0;- }, params);- } catch (SolrException e) {- if (params.length != 2) {- throw e;- }-- AnalyticsValueStream paramA = params[0];- AnalyticsValueStream paramB = params[1];-- // Booleans aren't really comparable, so just enable the equal function- if (paramA instanceof BooleanValueStream && paramB instanceof BooleanValueStream) {- if (paramA instanceof BooleanValue) {- if (paramB instanceof BooleanValue) {- return new BooleanValueEqualFunction((BooleanValue)paramA,(BooleanValue)paramB);- }- return new BooleanStreamEqualFunction((BooleanValue)paramA,(BooleanValueStream)paramB);- } else if (paramB instanceof BooleanValue) {- return new BooleanStreamEqualFunction((BooleanValue)paramB,(BooleanValueStream)paramA);- }- }-- // This means that the Objects created by the AnalyticsValueStreams are not comparable, so use the .equals() method instead- else if (paramA instanceof AnalyticsValue) {- if (paramB instanceof AnalyticsValue) {- return new ValueEqualFunction((AnalyticsValue)paramA,(AnalyticsValue)paramB);- }- return new StreamEqualFunction((AnalyticsValue)paramA,paramB);- }- if (paramB instanceof AnalyticsValue) {- return new StreamEqualFunction((AnalyticsValue)paramB,paramA);- }- }- throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires that at least 1 parameter be single-valued.");- });- }-- /**- * A comparison function that tests whether the first parameter is greater than the second parameter- */- public static class GTFunction {- public static final String name = "gt";- public static final CreatorFunction creatorFunction = (params -> {- return CompareFunction.createCompareFunction(name, val -> {- return val > 0;- }, params);- });- }-- /**- * A comparison function that tests whether the first parameter is greater than or equal to the second parameter- */- public static class GTEFunction {- public static final String name = "gte";- public static final CreatorFunction creatorFunction = (params -> {- return CompareFunction.createCompareFunction(name, val -> {- return val >= 0;- }, params);- });- }-- /**- * A comparison function that tests whether the first parameter is less than the second parameter- */- public static class LTFunction {- public static final String name = "lt";- public static final CreatorFunction creatorFunction = (params -> {- return CompareFunction.createCompareFunction(name, val -> {- return val < 0;- }, params);- });- }-- /**- * A comparison function that tests whether the first parameter is less than or equal to the second parameter- */- public static class LTEFunction {- public static final String name = "lte";- public static final CreatorFunction creatorFunction = (params -> {- return CompareFunction.createCompareFunction(name, val -> {- return val <= 0;- }, params);- });- }-- private static CompResultFunction reverse(CompResultFunction original) {- return val -> original.apply(val*-1);- }-}-@FunctionalInterface-interface CompResultFunction {- public boolean apply(int compResult);-}-/**- * A comparison function for two {@link DoubleValue}s.- */-class CompareDoubleValueFunction extends AbstractBooleanValue {- private final DoubleValue exprA;- private final DoubleValue exprB;- private final CompResultFunction comp;- private final String name;- private final String funcStr;- private final ExpressionType funcType;-- public CompareDoubleValueFunction(String name, DoubleValue exprA, DoubleValue exprB, CompResultFunction comp) {- this.name = name;- this.exprA = exprA;- this.exprB = exprB;- this.comp = comp;- this.funcStr = AnalyticsValueStream.createExpressionString(name,exprA,exprB);- this.funcType = AnalyticsValueStream.determineMappingPhase(funcStr,exprA,exprB);- }-- private boolean exists = false;- @Override- public boolean getBoolean() {- double valueA = exprA.getDouble();- double valueB = exprB.getDouble();- exists = exprA.exists() && exprB.exists();- return exists ? comp.apply(Double.compare(valueA,valueB)) : false;- }- @Override- public boolean exists() {- return exists;- }-- @Override- public String getName() {- return name;- }- @Override- public String getExpressionStr() {- return funcStr;- }- @Override- public ExpressionType getExpressionType() {- return funcType;- }-}-/**- * A comparison function for a {@link DoubleValue} and a {@link DoubleValueStream}.- */-class CompareDoubleStreamFunction extends AbstractBooleanValueStream {- private final DoubleValue baseExpr;- private final DoubleValueStream compExpr;- private final CompResultFunction comp;- private final String name;- private final String funcStr;- private final ExpressionType funcType;-- public CompareDoubleStreamFunction(String name, DoubleValue baseExpr, DoubleValueStream compExpr, CompResultFunction comp) throws SolrException {- this.name = name;- this.baseExpr = baseExpr;- this.compExpr = compExpr;- this.comp = comp;- this.funcStr = AnalyticsValueStream.createExpressionString(name,baseExpr,compExpr);- this.funcType = AnalyticsValueStream.determineMappingPhase(funcStr,baseExpr,compExpr);- }-- @Override- public void streamBooleans(BooleanConsumer cons) {- double baseValue = baseExpr.getDouble();- if (baseExpr.exists()) {- compExpr.streamDoubles(compValue -> cons.accept(comp.apply(Double.compare(baseValue,compValue))));- }- }-- @Override- public String getName() {- return name;- }- @Override- public String getExpressionStr() {- return funcStr;- }- @Override- public ExpressionType getExpressionType() {- return funcType;- }-}-/**- * A comparison function for two {@link DateValue}s.- */-class CompareDateValueFunction extends AbstractBooleanValue {- private final DateValue exprA;- private final DateValue exprB;- private final CompResultFunction comp;- private final String name;- private final String funcStr;- private final ExpressionType funcType;-- public CompareDateValueFunction(String name, DateValue exprA, DateValue exprB, CompResultFunction comp) {- this.name = name;- this.exprA = exprA;- this.exprB = exprB;- this.comp = comp;- this.funcStr = AnalyticsValueStream.createExpressionString(name,exprA,exprB);- this.funcType = AnalyticsValueStream.determineMappingPhase(funcStr,exprA,exprB);- }-- private boolean exists = false;- @Override- public boolean getBoolean() {- long valueA = exprA.getLong();- long valueB = exprB.getLong();- exists = exprA.exists() && exprB.exists();- return exists ? comp.apply(Long.compare(valueA,valueB)) : false;- }- @Override- public boolean exists() {- return exists;- }-- @Override- public String getName() {- return name;- }- @Override- public String getExpressionStr() {- return funcStr;- }- @Override- public ExpressionType getExpressionType() {- return funcType;- }-}-/**- * A comparison function for a {@link DateValue} and a {@link DateValueStream}.- */-class CompareDateStreamFunction extends AbstractBooleanValueStream {- private final DateValue baseExpr;- private final DateValueStream compExpr;- private final CompResultFunction comp;- private final String name;- private final String funcStr;- private final ExpressionType funcType;-- public CompareDateStreamFunction(String name, DateValue baseExpr, DateValueStream compExpr, CompResultFunction comp) throws SolrException {- this.name = name;- this.baseExpr = baseExpr;- this.compExpr = compExpr;- this.comp = comp;- this.funcStr = AnalyticsValueStream.createExpressionString(name,baseExpr,compExpr);- this.funcType = AnalyticsValueStream.determineMappingPhase(funcStr,baseExpr,compExpr);- }-- @Override- public void streamBooleans(BooleanConsumer cons) {- long baseValue = baseExpr.getLong();- if (baseExpr.exists()) {- compExpr.streamLongs(compValue -> cons.accept(comp.apply(Long.compare(baseValue,compValue))));- }- }-- @Override- public String getName() {- return name;- }- @Override- public String getExpressionStr() {- return funcStr;- }- @Override- public ExpressionType getExpressionType() {- return funcType;- }-}-/**- * A comparison function for two {@link StringValue}s.- */-class CompareStringValueFunction extends AbstractBooleanValue {- private final StringValue exprA;- private final StringValue exprB;- private final CompResultFunction comp;- private final String name;- private final String funcStr;- private final ExpressionType funcType;-- public CompareStringValueFunction(String name, StringValue exprA, StringValue exprB, CompResultFunction comp) {- this.name = name;- this.exprA = exprA;- this.exprB = exprB;- this.comp = comp;- this.funcStr = AnalyticsValueStream.createExpressionString(name,exprA,exprB);- this.funcType = AnalyticsValueStream.determineMappingPhase(funcStr,exprA,exprB);- }-- private boolean exists = false;- @Override- public boolean getBoolean() {- String valueA = exprA.toString();- String valueB = exprB.toString();- exists = exprA.exists() && exprB.exists();- return exists ? comp.apply(valueA.compareTo(valueB)) : false;- }- @Override- public boolean exists() {- return exists;- }-- @Override- public String getName() {- return name;- }- @Override- public String getExpressionStr() {- return funcStr;- }- @Override- public ExpressionType getExpressionType() {- return funcType;- }-}-/**- * A comparison function for a {@link StringValue} and a {@link StringValueStream}.- */-class CompareStringStreamFunction extends AbstractBooleanValueStream {- private final StringValue baseExpr;- private final StringValueStream compExpr;- private final CompResultFunction comp;- private final String name;- private final String funcStr;- private final ExpressionType funcType;-- public CompareStringStreamFunction(String name, StringValue baseExpr, StringValueStream compExpr, CompResultFunction comp) throws SolrException {- this.name = name;- this.baseExpr = baseExpr;- this.compExpr = compExpr;- this.comp = comp;- this.funcStr = AnalyticsValueStream.createExpressionString(name,baseExpr,compExpr);- this.funcType = AnalyticsValueStream.determineMappingPhase(funcStr,baseExpr,compExpr);- }-- @Override- public void streamBooleans(BooleanConsumer cons) {- String baseValue = baseExpr.toString();- if (baseExpr.exists()) {- compExpr.streamStrings(compValue -> cons.accept(comp.apply(baseValue.compareTo(compValue))));- }- }-- @Override- public String getName() {- return name;- }- @Override- public String getExpressionStr() {- return funcStr;- }- @Override- public ExpressionType getExpressionType() {- return funcType;- }-}-/**- * An equal function for two {@link BooleanValue}s.- */-class BooleanValueEqualFunction extends AbstractBooleanValue {- private final BooleanValue exprA;- private final BooleanValue exprB;- public static final String name = CompareFunction.EqualFunction.name;- private final String funcStr;- private final ExpressionType funcType;-- public BooleanValueEqualFunction(BooleanValue exprA, BooleanValue exprB) {- this.exprA = exprA;- this.exprB = exprB;- this.funcStr = AnalyticsValueStream.createExpressionString(name,exprA,exprB);- this.funcType = AnalyticsValueStream.determineMappingPhase(funcStr,exprA,exprB);- }-- private boolean exists = false;- @Override- public boolean getBoolean() {- boolean valueA = exprA.getBoolean();- boolean valueB = exprB.getBoolean();- exists = exprA.exists() && exprB.exists();- return exists ? valueA == valueB : false;- }- @Override- public boolean exists() {- return exists;- }-- @Override- public String getName() {- return name;- }- @Override- public String getExpressionStr() {- return funcStr;- }- @Override- public ExpressionType getExpressionType() {- return funcType;- }-}-/**- * An equal function for a {@link BooleanValue} and a {@link BooleanValueStream}.- */-class BooleanStreamEqualFunction extends AbstractBooleanValueStream {- private final BooleanValue baseExpr;- private final BooleanValueStream compExpr;- public static final String name = CompareFunction.EqualFunction.name;- private final String funcStr;- private final ExpressionType funcType;-- public BooleanStreamEqualFunction(BooleanValue baseExpr, BooleanValueStream compExpr) throws SolrException {- this.baseExpr = baseExpr;- this.compExpr = compExpr;- this.funcStr = AnalyticsValueStream.createExpressionString(name,baseExpr,compExpr);- this.funcType = AnalyticsValueStream.determineMappingPhase(funcStr,baseExpr,compExpr);- }-- @Override- public void streamBooleans(BooleanConsumer cons) {- boolean baseValue = baseExpr.getBoolean();- if (baseExpr.exists()) {- compExpr.streamBooleans(compValue -> cons.accept(baseValue == compValue));- }- }-- @Override- public String getName() {- return name;- }- @Override- public String getExpressionStr() {- return funcStr;- }- @Override- public ExpressionType getExpressionType() {- return funcType;- }-}-/**- * A catch-all equal function for two {@link AnalyticsValue}s.- */-class ValueEqualFunction extends AbstractBooleanValue {- private final AnalyticsValue exprA;- private final AnalyticsValue exprB;- public static final String name = CompareFunction.EqualFunction.name;- private final String funcStr;- private final ExpressionType funcType;-- public ValueEqualFunction(AnalyticsValue exprA, AnalyticsValue exprB) {- this.exprA = exprA;- this.exprB = exprB;- this.funcStr = AnalyticsValueStream.createExpressionString(name,exprA,exprB);- this.funcType = AnalyticsValueStream.determineMappingPhase(funcStr,exprA,exprB);- }-- private boolean exists = false;- @Override- public boolean getBoolean() {- Object valueA = exprA.getObject();- Object valueB = exprB.getObject();- exists = exprA.exists() && exprB.exists();- return exists ? valueA.equals(valueB) : false;- }- @Override- public boolean exists() {- return exists;- }-- @Override- public String getName() {- return name;- }- @Override- public String getExpressionStr() {- return funcStr;- }- @Override- public ExpressionType getExpressionType() {- return funcType;- }-}-/**- * A catch-all equal function for an {@link AnalyticsValue} and an {@link AnalyticsValueStream}.- */-class StreamEqualFunction extends AbstractBooleanValueStream {- private final AnalyticsValue baseExpr;- private final AnalyticsValueStream compExpr;- public static final String name = CompareFunction.EqualFunction.name;- private final String funcStr;- private final ExpressionType funcType;-- public StreamEqualFunction(AnalyticsValue baseExpr, AnalyticsValueStream compExpr) throws SolrException {- this.baseExpr = baseExpr;- this.compExpr = compExpr;- this.funcStr = AnalyticsValueStream.createExpressionString(name,baseExpr,compExpr);- this.funcType = AnalyticsValueStream.determineMappingPhase(funcStr,baseExpr,compExpr);- }-- @Override- public void streamBooleans(BooleanConsumer cons) {- Object baseValue = baseExpr.getObject();- if (baseExpr.exists()) {- compExpr.streamObjects(compValue -> cons.accept(baseValue.equals(compValue)));- }- }-- @Override- public String getName() {- return name;- }- @Override- public String getExpressionStr() {- return funcStr;- }- @Override- public ExpressionType getExpressionType() {- return funcType;- }-}\ No newline at end of filediff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/ComparisonFunction.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/ComparisonFunction.javanew file mode 100644index 00000000000..1bbf9ae86fa--- /dev/null+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/ComparisonFunction.java@@ -0,0 +1,318 @@+/*+ * 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.analytics.function.mapping;++import org.apache.solr.analytics.ExpressionFactory.CreatorFunction;+import org.apache.solr.analytics.function.mapping.ComparisonFunction.CompResultFunction;+import org.apache.solr.analytics.util.function.BooleanConsumer;+import org.apache.solr.analytics.value.AnalyticsValue;+import org.apache.solr.analytics.value.AnalyticsValueStream;+import org.apache.solr.analytics.value.BooleanValue;+import org.apache.solr.analytics.value.BooleanValueStream;+import org.apache.solr.analytics.value.DateValue;+import org.apache.solr.analytics.value.DateValueStream;+import org.apache.solr.analytics.value.DoubleValue;+import org.apache.solr.analytics.value.DoubleValueStream;+import org.apache.solr.analytics.value.BooleanValue.AbstractBooleanValue;+import org.apache.solr.analytics.value.BooleanValueStream.AbstractBooleanValueStream;+import org.apache.solr.common.SolrException;+import org.apache.solr.common.SolrException.ErrorCode;++/**+ * Contains all comparable functions. Comparable functions accept two comparable (numeric and date) parameters and return a BooleanValueStream.+ * The two parameters must be able to be cast to the same type.+ * <p>+ * Uses:+ * <ul>+ * <li>If a two comparable {@link AnalyticsValue}s are passed in, a {@link BooleanValue} representing the comparison of the two values for each document is returned.+ * <li>If a comparable {@link AnalyticsValue} and a comparable {@link AnalyticsValueStream} are passed in,+ * a {@link BooleanValueStream} representing the comparison of the Value and each of the values of the ValueStream for the document is returned.+ * </ul>+ */+public class ComparisonFunction {++ /**+ * Create a comparison mapping function, comparing two analytics value (streams) of the same type.+ *+ * @param name name of the function+ * @param comp function to find the result of a comparison+ * @param params the parameters to compare+ * @return an instance of the requested comparison function using the given parameters+ */+ public static BooleanValueStream createComparisonFunction(String name, CompResultFunction comp, AnalyticsValueStream... params) {+ if (params.length != 2) {+ throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires 2 paramaters, " + params.length + " found.");+ }+ AnalyticsValueStream paramA = params[0];+ AnalyticsValueStream paramB = params[1];+ if (paramA instanceof DoubleValueStream && paramB instanceof DoubleValueStream) {+ if (paramA instanceof DoubleValue) {+ if (paramB instanceof DoubleValue) {+ return new CompareDoubleValueFunction(name,(DoubleValue)paramA,(DoubleValue)paramB,comp);+ }+ return new CompareDoubleStreamFunction(name,(DoubleValue)paramA,(DoubleValueStream)paramB,comp);+ }+ if (paramB instanceof DoubleValue) {+ return new CompareDoubleStreamFunction(name,(DoubleValue)paramB,(DoubleValueStream)paramA,reverse(comp));+ }+ } else if (paramA instanceof DateValueStream && paramB instanceof DateValueStream) {+ if (paramA instanceof DateValue) {+ if (paramB instanceof DateValue) {+ return new CompareDateValueFunction(name,(DateValue)paramA,(DateValue)paramB,comp);+ }+ return new CompareDateStreamFunction(name,(DateValue)paramA,(DateValueStream)paramB,comp);+ }+ if (paramB instanceof DateValue) {+ return new CompareDateStreamFunction(name,(DateValue)paramB,(DateValueStream)paramA,reverse(comp));+ }+ } else {+ throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires comparable (numeric or date) parameters.");+ }+ throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires that at least 1 parameter be single-valued.");+ }++ /**+ * A comparison function that tests whether the first parameter is greater than the second parameter+ */+ public static class GTFunction {+ public static final String name = "gt";+ public static final CreatorFunction creatorFunction = (params -> {+ return ComparisonFunction.createComparisonFunction(name, val -> {+ return val > 0;+ }, params);+ });+ }++ /**+ * A comparison function that tests whether the first parameter is greater than or equal to the second parameter+ */+ public static class GTEFunction {+ public static final String name = "gte";+ public static final CreatorFunction creatorFunction = (params -> {+ return ComparisonFunction.createComparisonFunction(name, val -> {+ return val >= 0;+ }, params);+ });+ }++ /**+ * A comparison function that tests whether the first parameter is less than the second parameter+ */+ public static class LTFunction {+ public static final String name = "lt";+ public static final CreatorFunction creatorFunction = (params -> {+ return ComparisonFunction.createComparisonFunction(name, val -> {+ return val < 0;+ }, params);+ });+ }++ /**+ * A comparison function that tests whether the first parameter is less than or equal to the second parameter+ */+ public static class LTEFunction {+ public static final String name = "lte";+ public static final CreatorFunction creatorFunction = (params -> {+ return ComparisonFunction.createComparisonFunction(name, val -> {+ return val <= 0;+ }, params);+ });+ }++ @FunctionalInterface+ public static interface CompResultFunction {+ public boolean apply(int compResult);+ }++ private static CompResultFunction reverse(CompResultFunction original) {+ return val -> original.apply(val*-1);+ }+}+/**+ * A comparison function for two {@link DoubleValue}s.+ */+class CompareDoubleValueFunction extends AbstractBooleanValue {+ private final DoubleValue exprA;+ private final DoubleValue exprB;+ private final CompResultFunction comp;+ private final String name;+ private final String funcStr;+ private final ExpressionType funcType;++ public CompareDoubleValueFunction(String name, DoubleValue exprA, DoubleValue exprB, CompResultFunction comp) {+ this.name = name;+ this.exprA = exprA;+ this.exprB = exprB;+ this.comp = comp;+ this.funcStr = AnalyticsValueStream.createExpressionString(name,exprA,exprB);+ this.funcType = AnalyticsValueStream.determineMappingPhase(funcStr,exprA,exprB);+ }++ private boolean exists = false;+ @Override+ public boolean getBoolean() {+ double valueA = exprA.getDouble();+ double valueB = exprB.getDouble();+ exists = exprA.exists() && exprB.exists();+ return exists ? comp.apply(Double.compare(valueA,valueB)) : false;+ }+ @Override+ public boolean exists() {+ return exists;+ }++ @Override+ public String getName() {+ return name;+ }+ @Override+ public String getExpressionStr() {+ return funcStr;+ }+ @Override+ public ExpressionType getExpressionType() {+ return funcType;+ }+}+/**+ * A comparison function for a {@link DoubleValue} and a {@link DoubleValueStream}.+ */+class CompareDoubleStreamFunction extends AbstractBooleanValueStream {+ private final DoubleValue baseExpr;+ private final DoubleValueStream compExpr;+ private final CompResultFunction comp;+ private final String name;+ private final String funcStr;+ private final ExpressionType funcType;++ public CompareDoubleStreamFunction(String name, DoubleValue baseExpr, DoubleValueStream compExpr, CompResultFunction comp) throws SolrException {+ this.name = name;+ this.baseExpr = baseExpr;+ this.compExpr = compExpr;+ this.comp = comp;+ this.funcStr = AnalyticsValueStream.createExpressionString(name,baseExpr,compExpr);+ this.funcType = AnalyticsValueStream.determineMappingPhase(funcStr,baseExpr,compExpr);+ }++ @Override+ public void streamBooleans(BooleanConsumer cons) {+ double baseValue = baseExpr.getDouble();+ if (baseExpr.exists()) {+ compExpr.streamDoubles(compValue -> cons.accept(comp.apply(Double.compare(baseValue,compValue))));+ }+ }++ @Override+ public String getName() {+ return name;+ }+ @Override+ public String getExpressionStr() {+ return funcStr;+ }+ @Override+ public ExpressionType getExpressionType() {+ return funcType;+ }+}+/**+ * A comparison function for two {@link DateValue}s.+ */+class CompareDateValueFunction extends AbstractBooleanValue {+ private final DateValue exprA;+ private final DateValue exprB;+ private final CompResultFunction comp;+ private final String name;+ private final String funcStr;+ private final ExpressionType funcType;++ public CompareDateValueFunction(String name, DateValue exprA, DateValue exprB, CompResultFunction comp) {+ this.name = name;+ this.exprA = exprA;+ this.exprB = exprB;+ this.comp = comp;+ this.funcStr = AnalyticsValueStream.createExpressionString(name,exprA,exprB);+ this.funcType = AnalyticsValueStream.determineMappingPhase(funcStr,exprA,exprB);+ }++ private boolean exists = false;+ @Override+ public boolean getBoolean() {+ long valueA = exprA.getLong();+ long valueB = exprB.getLong();+ exists = exprA.exists() && exprB.exists();+ return exists ? comp.apply(Long.compare(valueA,valueB)) : false;+ }+ @Override+ public boolean exists() {+ return exists;+ }++ @Override+ public String getName() {+ return name;+ }+ @Override+ public String getExpressionStr() {+ return funcStr;+ }+ @Override+ public ExpressionType getExpressionType() {+ return funcType;+ }+}+/**+ * A comparison function for a {@link DateValue} and a {@link DateValueStream}.+ */+class CompareDateStreamFunction extends AbstractBooleanValueStream {+ private final DateValue baseExpr;+ private final DateValueStream compExpr;+ private final CompResultFunction comp;+ private final String name;+ private final String funcStr;+ private final ExpressionType funcType;++ public CompareDateStreamFunction(String name, DateValue baseExpr, DateValueStream compExpr, CompResultFunction comp) throws SolrException {+ this.name = name;+ this.baseExpr = baseExpr;+ this.compExpr = compExpr;+ this.comp = comp;+ this.funcStr = AnalyticsValueStream.createExpressionString(name,baseExpr,compExpr);+ this.funcType = AnalyticsValueStream.determineMappingPhase(funcStr,baseExpr,compExpr);+ }++ @Override+ public void streamBooleans(BooleanConsumer cons) {+ long baseValue = baseExpr.getLong();+ if (baseExpr.exists()) {+ compExpr.streamLongs(compValue -> cons.accept(comp.apply(Long.compare(baseValue,compValue))));+ }+ }++ @Override+ public String getName() {+ return name;+ }+ @Override+ public String getExpressionStr() {+ return funcStr;+ }+ @Override+ public ExpressionType getExpressionType() {+ return funcType;+ }+}\ No newline at end of filediff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/ConcatFunction.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/ConcatFunction.javaindex e54e8c53311..9b0809ec728 100644--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/ConcatFunction.java+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/ConcatFunction.java@@ -18,61 +18,90 @@ package org.apache.solr.analytics.function.mapping;import org.apache.solr.common.SolrException;import org.apache.solr.common.SolrException.ErrorCode;++import java.util.Arrays;+import org.apache.solr.analytics.ExpressionFactory.CreatorFunction;+import org.apache.solr.analytics.function.mapping.LambdaFunction.TwoStringInStringOutLambda;+import org.apache.solr.analytics.value.AnalyticsValueStream;import org.apache.solr.analytics.value.StringValue;+import org.apache.solr.analytics.value.StringValueStream;import org.apache.solr.analytics.value.constant.ConstantStringValue;+import org.apache.solr.analytics.value.constant.ConstantValue;/*** A concatenation mapping function, combining the string values of the given parameters. (At least 1 parameter is required)* <p>- * Multiple comparable {@link StringValue}s are passed in and a {@link StringValue} representing the concatenation of all values is returned.+ * Uses:+ * <ul>+ * <li>If a single {@link StringValueStream} is passed in, a {@link StringValue} representing the concatenation of the values for each document is returned.+ * No ordering is guaranteed while concatenating.+ * <li>If a {@link StringValue} and a {@link StringValueStream} are passed in, a {@link StringValueStream} representing the concatenation of+ * the Value and each of the values of the ValueStream for a document is returned.+ * (Or the other way, since the Value and ValueStream can be used in either order)+ * <li>If any number (more than 0) of {@link StringValue}s are passed in, a {@link StringValue} representing the concatenation of all values is returned.+ * If any values don't exist, the overall concatenation value will still exist with an empty string used for any missing values. If none of the parameter+ * values exist, then the overall concatenation value will not exist.+ * </ul>*/public class ConcatFunction {public static final String name = "concat";public static final CreatorFunction creatorFunction = (params -> {- if (params.length == 0) {- throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires parameters.");- }- else if (params.length == 1 && params[0] instanceof StringValue) {- return params[0];- }- StringValue[] castedParams = new StringValue[params.length];- for (int i = 0; i < params.length; i++) {- if (params[i] instanceof StringValue) {- castedParams[i] = (StringValue) params[i];- } else {- throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires that all parameters be single-valued and convertible to string values.");- }- }- return LambdaFunction.createStringLambdaFunction(name, (a,b) -> a+b, castedParams, false);+ return createConcatFunction(name, name, (a,b) -> a + b, params);});/*** A concatenation mapping function, combining the string values of the given parameters with a given separating string.* <br>- * Multiple comparable {@link StringValue}s are passed in and a {@link StringValue} representing the separated concatenation of all values is returned.- * <p>- * The first parameter must be a constant string (e.g. ",").- * The remaining parameters are the {@link StringValue} expressions to concatenate. (At least 1 expression is required)+ * The usage is exactly the same as the {@link ConcatFunction}, however a {@link ConstantStringValue} separator is added as the first argument+ * of every usage. So the acceptable inputs are as follows:+ * <ul>+ * <li>{@value #name} ( {@link ConstantStringValue} , {@link StringValueStream} )+ * <li>{@value #name} ( {@link ConstantStringValue} , {@link StringValueStream} , {@link StringValue} )+ * <li>{@value #name} ( {@link ConstantStringValue} , {@link StringValue} , {@link StringValueStream} )+ * <li>{@value #name} ( {@link ConstantStringValue} , {@link StringValue} ... )+ * </ul>+ * The {@link ConstantStringValue} separator is used to separate every two (or more) string during concatenation. If only one string value exists,+ * then the separator will not be used.*/- public static class ConcatSeparatedFunction {- public static final String name = "concatsep";+ public static class SeparatedConcatFunction {+ public static final String name = "concat_sep";public static final CreatorFunction creatorFunction = (params -> {if (params.length < 2) {throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires at least 2 parameters.");- } else if (!(params[0] instanceof ConstantStringValue)) {+ } else if (!(params[0] instanceof StringValue && params[0] instanceof ConstantValue)) {throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires that the first parameter to be a constant string.");}- final String sep = ((ConstantStringValue)params[0]).getString();- StringValue[] castedParams = new StringValue[params.length - 1];- for (int i = 0; i < castedParams.length; i++) {- if (params[i + 1] instanceof StringValue) {- castedParams[i] = (StringValue) params[i + 1];- } else {- throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires that all non-separator parameters be single-valued and convertible to string values.");- }- }- return LambdaFunction.createStringLambdaFunction(name, (a,b) -> a + sep + b, castedParams, false);+ final String sep = ((StringValue)params[0]).getString();+ String uniqueName = name + "(" + sep + ")";+ return createConcatFunction(name, uniqueName, (a,b) -> a + sep + b, Arrays.copyOfRange(params, 1, params.length));});}++ private static StringValueStream createConcatFunction(String functionName, String uniqueName, TwoStringInStringOutLambda lambda, AnalyticsValueStream[] params) {+ if (params.length == 0) {+ throw new SolrException(ErrorCode.BAD_REQUEST, "The "+functionName+" function requires parameters.");+ } else if (params.length == 1) {+ if (params[0] instanceof StringValueStream) {+ return LambdaFunction.createStringLambdaFunction(uniqueName, lambda, (StringValueStream)params[0]);+ }+ throw new SolrException(ErrorCode.BAD_REQUEST, "The "+functionName+" function requires that all parameters be string-castable.");+ } else if (params.length == 2) {+ // If it is not a pair of a single valued and multi valued string, then it will be taken care of below+ if (params[0] instanceof StringValueStream && params[1] instanceof StringValueStream+ && !(params[0] instanceof StringValue && params[1] instanceof StringValue)) {+ return LambdaFunction.createStringLambdaFunction(uniqueName, lambda, (StringValueStream)params[0], (StringValueStream)params[1]);+ }+ }+ StringValue[] castedParams = new StringValue[params.length];+ for (int i = 0; i < params.length; i++) {+ if (params[i] instanceof StringValue) {+ castedParams[i] = (StringValue) params[i];+ } else {+ throw new SolrException(ErrorCode.BAD_REQUEST, "The "+functionName+" function requires that all parameters be string-castable, and if more than 2 parameters"+ + " are provided then all must be single-valued.");+ }+ }+ return LambdaFunction.createStringLambdaFunction(uniqueName, lambda, castedParams, false);+ }}\ No newline at end of filediff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/DateMathFunction.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/DateMathFunction.javaindex 99016255a6b..c9dab98b0cb 100644--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/DateMathFunction.java+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/DateMathFunction.java@@ -24,9 +24,11 @@ import org.apache.solr.analytics.ExpressionFactory.CreatorFunction;import org.apache.solr.analytics.value.AnalyticsValueStream;import org.apache.solr.analytics.value.DateValue;import org.apache.solr.analytics.value.DateValueStream;+import org.apache.solr.analytics.value.StringValue;import org.apache.solr.analytics.value.DateValue.AbstractDateValue;import org.apache.solr.analytics.value.DateValueStream.AbstractDateValueStream;import org.apache.solr.analytics.value.constant.ConstantStringValue;+import org.apache.solr.analytics.value.constant.ConstantValue;import org.apache.solr.common.SolrException;import org.apache.solr.common.SolrException.ErrorCode;import org.apache.solr.util.DateMathParser;@@ -46,8 +48,8 @@ public class DateMathFunction {}StringBuilder mathParam = new StringBuilder();for (int i = 1; i < params.length; ++i) {- if (params[i] instanceof ConstantStringValue) {- mathParam.append(((ConstantStringValue) params[i]).getString());+ if (params[i] instanceof StringValue && params[i] instanceof ConstantValue) {+ mathParam.append(((StringValue) params[i]).getString());} else {throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires all math parameters to be a constant strings.");}@@ -84,7 +86,7 @@ class DateMathValueFunction extends AbstractDateValue {@Overridepublic long getLong() {Date date = getDate();- return (date == null) ? 0 : date.getTime();+ return (exists) ? date.getTime() : 0;}@Overridepublic Date getDate() {diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/DateParseFunction.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/DateParseFunction.javaindex 5929b884199..226acacc9a6 100644--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/DateParseFunction.java+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/DateParseFunction.java@@ -16,10 +16,8 @@*/package org.apache.solr.analytics.function.mapping;-import java.text.DateFormat;-import java.text.ParseException;-import java.text.SimpleDateFormat;-import java.util.Locale;+import java.time.Instant;+import java.time.format.DateTimeParseException;import java.util.function.LongConsumer;import org.apache.solr.analytics.ExpressionFactory.CreatorFunction;@@ -103,7 +101,6 @@ class LongStreamToDateParseFunction extends AbstractDateValueStream {public static final String name = DateParseFunction.name;private final String exprStr;private final ExpressionType funcType;- public static final DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss.SSS", Locale.ROOT);public LongStreamToDateParseFunction(LongValueStream param) throws SolrException {this.param = param;@@ -134,7 +131,6 @@ class StringToDateParseFunction extends AbstractDateValue {public static final String name = DateParseFunction.name;private final String exprStr;private final ExpressionType funcType;- public static final DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss.SSS", Locale.ROOT);public StringToDateParseFunction(StringValue param) throws SolrException {this.param = param;@@ -147,9 +143,12 @@ class StringToDateParseFunction extends AbstractDateValue {public long getLong() {long value = 0;try {- value = formatter.parse(param.toString()).getTime();+ String paramStr = param.getString();exists = param.exists();- } catch (ParseException e) {+ if (exists) {+ value = Instant.parse(paramStr).toEpochMilli();+ }+ } catch (DateTimeParseException e) {exists = false;}return value;@@ -177,7 +176,6 @@ class StringStreamToDateParseFunction extends AbstractDateValueStream {public static final String name = DateParseFunction.name;private final String exprStr;private final ExpressionType funcType;- public static final DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss.SSS", Locale.ROOT);public StringStreamToDateParseFunction(StringValueStream param) throws SolrException {this.param = param;@@ -189,13 +187,11 @@ class StringStreamToDateParseFunction extends AbstractDateValueStream {public void streamLongs(LongConsumer cons) {param.streamStrings(value -> {try {- cons.accept(formatter.parse(value).getTime());- } catch (ParseException e) {- }+ cons.accept(Instant.parse(value).toEpochMilli());+ } catch (DateTimeParseException e) {}});}- @Overridepublic String getName() {return name;}@@ -207,4 +203,4 @@ class StringStreamToDateParseFunction extends AbstractDateValueStream {public ExpressionType getExpressionType() {return funcType;}-}\ No newline at end of file+}diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/NumericConvertFunction.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/DecimalNumericConversionFunction.javasimilarity index 81%rename from solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/NumericConvertFunction.javarename to solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/DecimalNumericConversionFunction.javaindex 2381f602c84..df91c956245 100644--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/NumericConvertFunction.java+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/DecimalNumericConversionFunction.java@@ -20,6 +20,8 @@ import java.util.function.IntConsumer;import java.util.function.LongConsumer;import org.apache.solr.analytics.ExpressionFactory.CreatorFunction;+import org.apache.solr.analytics.function.mapping.DecimalNumericConversionFunction.ConvertDoubleFunction;+import org.apache.solr.analytics.function.mapping.DecimalNumericConversionFunction.ConvertFloatFunction;import org.apache.solr.analytics.value.AnalyticsValueStream;import org.apache.solr.analytics.value.DoubleValue;import org.apache.solr.analytics.value.DoubleValueStream;@@ -37,17 +39,29 @@ import org.apache.solr.common.SolrException;import org.apache.solr.common.SolrException.ErrorCode;/**- * An abstract numeric converting mapping function. For example "round()" would convert a float to an int and a double to a long.+ * An abstract decimal numeric converting mapping function. For example "round()" would convert a float to an int and a double to a long.* <p>- * Takes a numeric Double or Float ValueStream or Value and returns a Long or Int ValueStream or Value, repectively.+ * Takes a numeric Double or Float ValueStream or Value and returns a Long or Int ValueStream or Value, respectively.*/-public class NumericConvertFunction {+public class DecimalNumericConversionFunction {- private static LongValueStream createConvertFunction(String name, ConvertFloatFunction fconv, ConvertDoubleFunction dconv, AnalyticsValueStream... params) {+ /**+ * Create a numeric conversion mapping function.+ *+ * @param name the name of the function+ * @param fconv the method to convert floats to ints+ * @param dconv the method to convert doubles to longs+ * @param params the parameters of the function+ * @return an instance of the conversion function using the given parameters.+ */+ public static LongValueStream createDecimalConversionFunction(String name, ConvertFloatFunction fconv, ConvertDoubleFunction dconv, AnalyticsValueStream... params) {if (params.length != 1) {throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires 1 paramaters, " + params.length + " found.");}AnalyticsValueStream param = params[0];+ if (param instanceof LongValueStream) {+ return (LongValueStream)param;+ }if (param instanceof FloatValueStream) {if (param instanceof FloatValue) {return new ConvertFloatValueFunction(name, (FloatValue)param, fconv);@@ -69,7 +83,7 @@ public class NumericConvertFunction {public static class FloorFunction {public static final String name = "floor";public static final CreatorFunction creatorFunction = (params -> {- return NumericConvertFunction.createConvertFunction(name, val -> (int)Math.floor(val), val -> (long)Math.floor(val), params);+ return DecimalNumericConversionFunction.createDecimalConversionFunction(name, val -> (int)Math.floor(val), val -> (long)Math.floor(val), params);});}@@ -79,7 +93,7 @@ public class NumericConvertFunction {public static class CeilingFunction {public static final String name = "ceil";public static final CreatorFunction creatorFunction = (params -> {- return NumericConvertFunction.createConvertFunction(name, val -> (int)Math.ceil(val), val -> (long)Math.ceil(val), params);+ return DecimalNumericConversionFunction.createDecimalConversionFunction(name, val -> (int)Math.ceil(val), val -> (long)Math.ceil(val), params);});}@@ -89,18 +103,19 @@ public class NumericConvertFunction {public static class RoundFunction {public static final String name = "round";public static final CreatorFunction creatorFunction = (params -> {- return NumericConvertFunction.createConvertFunction(name, val -> (int)Math.round(val), val -> (long)Math.round(val), params);+ return DecimalNumericConversionFunction.createDecimalConversionFunction(name, val -> (int)Math.round(val), val -> (long)Math.round(val), params);});}-}-@FunctionalInterface-interface ConvertFloatFunction {- public int convert(float value);-}-@FunctionalInterface-interface ConvertDoubleFunction {- public long convert(double value);+ @FunctionalInterface+ public static interface ConvertFloatFunction {+ public int convert(float value);+ }++ @FunctionalInterface+ public static interface ConvertDoubleFunction {+ public long convert(double value);+ }}/*** A function to convert a {@link FloatValue} to a {@link IntValue}.diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/EqualFunction.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/EqualFunction.javanew file mode 100644index 00000000000..6e3c651d01e--- /dev/null+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/EqualFunction.java@@ -0,0 +1,238 @@+/*+ * 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.analytics.function.mapping;++import org.apache.solr.analytics.ExpressionFactory.CreatorFunction;+import org.apache.solr.analytics.util.function.BooleanConsumer;+import org.apache.solr.analytics.value.AnalyticsValue;+import org.apache.solr.analytics.value.AnalyticsValueStream;+import org.apache.solr.analytics.value.BooleanValue;+import org.apache.solr.analytics.value.BooleanValueStream;+import org.apache.solr.analytics.value.BooleanValue.AbstractBooleanValue;+import org.apache.solr.analytics.value.BooleanValueStream.AbstractBooleanValueStream;+import org.apache.solr.analytics.value.DoubleValueStream;+import org.apache.solr.common.SolrException;+import org.apache.solr.common.SolrException.ErrorCode;++/**+ * An equals mapping function, returning whether two values are equal.+ * <p>+ * Uses:+ * <ul>+ * <li>If two Values are passed in, a {@link BooleanValue} representing the equality of the two values for each document is returned.+ * <li>If an {@link AnalyticsValue} and an {@link AnalyticsValueStream} are passed in,+ * a {@link BooleanValueStream} representing the equality of the Value and each of the values of the ValueStream for the document is returned.+ * </ul>+ */+public class EqualFunction {+ public static final String name = "equal";+ public static final CreatorFunction creatorFunction = (params -> {+ if (params.length != 2) {+ throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires 2 paramaters, " + params.length + " found.");+ }++ AnalyticsValueStream paramA = params[0];+ AnalyticsValueStream paramB = params[1];++ // Booleans aren't really comparable, so just enable the equal function+ if (paramA instanceof BooleanValueStream && paramB instanceof BooleanValueStream) {+ if (paramA instanceof BooleanValue) {+ if (paramB instanceof BooleanValue) {+ return new BooleanValueEqualFunction((BooleanValue)paramA,(BooleanValue)paramB);+ }+ return new BooleanStreamEqualFunction((BooleanValue)paramA,(BooleanValueStream)paramB);+ } else if (paramB instanceof BooleanValue) {+ return new BooleanStreamEqualFunction((BooleanValue)paramB,(BooleanValueStream)paramA);+ }+ } else if (paramA instanceof DoubleValueStream && paramB instanceof DoubleValueStream) {+ return ComparisonFunction.createComparisonFunction(name, val -> {+ return val == 0;+ }, params);+ } else if (paramA instanceof AnalyticsValue) {+ // This means that the Objects created by the AnalyticsValueStreams are not comparable, so use the .equals() method instead+ if (paramB instanceof AnalyticsValue) {+ return new ValueEqualFunction((AnalyticsValue)paramA,(AnalyticsValue)paramB);+ }+ return new StreamEqualFunction((AnalyticsValue)paramA,paramB);+ } else if (paramB instanceof AnalyticsValue) {+ return new StreamEqualFunction((AnalyticsValue)paramB,paramA);+ }+ throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires that at least 1 parameter be single-valued.");+ });+}+/**+ * An equal function for two {@link BooleanValue}s.+ */+class BooleanValueEqualFunction extends AbstractBooleanValue {+ private final BooleanValue exprA;+ private final BooleanValue exprB;+ public static final String name = EqualFunction.name;+ private final String funcStr;+ private final ExpressionType funcType;++ public BooleanValueEqualFunction(BooleanValue exprA, BooleanValue exprB) {+ this.exprA = exprA;+ this.exprB = exprB;+ this.funcStr = AnalyticsValueStream.createExpressionString(name,exprA,exprB);+ this.funcType = AnalyticsValueStream.determineMappingPhase(funcStr,exprA,exprB);+ }++ private boolean exists = false;+ @Override+ public boolean getBoolean() {+ boolean valueA = exprA.getBoolean();+ boolean valueB = exprB.getBoolean();+ exists = exprA.exists() && exprB.exists();+ return exists ? valueA == valueB : false;+ }+ @Override+ public boolean exists() {+ return exists;+ }++ @Override+ public String getName() {+ return name;+ }+ @Override+ public String getExpressionStr() {+ return funcStr;+ }+ @Override+ public ExpressionType getExpressionType() {+ return funcType;+ }+}+/**+ * An equal function for a {@link BooleanValue} and a {@link BooleanValueStream}.+ */+class BooleanStreamEqualFunction extends AbstractBooleanValueStream {+ private final BooleanValue baseExpr;+ private final BooleanValueStream compExpr;+ public static final String name = EqualFunction.name;+ private final String funcStr;+ private final ExpressionType funcType;++ public BooleanStreamEqualFunction(BooleanValue baseExpr, BooleanValueStream compExpr) throws SolrException {+ this.baseExpr = baseExpr;+ this.compExpr = compExpr;+ this.funcStr = AnalyticsValueStream.createExpressionString(name,baseExpr,compExpr);+ this.funcType = AnalyticsValueStream.determineMappingPhase(funcStr,baseExpr,compExpr);+ }++ @Override+ public void streamBooleans(BooleanConsumer cons) {+ boolean baseValue = baseExpr.getBoolean();+ if (baseExpr.exists()) {+ compExpr.streamBooleans(compValue -> cons.accept(baseValue == compValue));+ }+ }++ @Override+ public String getName() {+ return name;+ }+ @Override+ public String getExpressionStr() {+ return funcStr;+ }+ @Override+ public ExpressionType getExpressionType() {+ return funcType;+ }+}+/**+ * A catch-all equal function for two {@link AnalyticsValue}s.+ */+class ValueEqualFunction extends AbstractBooleanValue {+ private final AnalyticsValue exprA;+ private final AnalyticsValue exprB;+ public static final String name = EqualFunction.name;+ private final String funcStr;+ private final ExpressionType funcType;++ public ValueEqualFunction(AnalyticsValue exprA, AnalyticsValue exprB) {+ this.exprA = exprA;+ this.exprB = exprB;+ this.funcStr = AnalyticsValueStream.createExpressionString(name,exprA,exprB);+ this.funcType = AnalyticsValueStream.determineMappingPhase(funcStr,exprA,exprB);+ }++ private boolean exists = false;+ @Override+ public boolean getBoolean() {+ Object valueA = exprA.getObject();+ Object valueB = exprB.getObject();+ exists = exprA.exists() && exprB.exists();+ return exists ? valueA.equals(valueB) : false;+ }+ @Override+ public boolean exists() {+ return exists;+ }++ @Override+ public String getName() {+ return name;+ }+ @Override+ public String getExpressionStr() {+ return funcStr;+ }+ @Override+ public ExpressionType getExpressionType() {+ return funcType;+ }+}+/**+ * A catch-all equal function for an {@link AnalyticsValue} and an {@link AnalyticsValueStream}.+ */+class StreamEqualFunction extends AbstractBooleanValueStream {+ private final AnalyticsValue baseExpr;+ private final AnalyticsValueStream compExpr;+ public static final String name = EqualFunction.name;+ private final String funcStr;+ private final ExpressionType funcType;++ public StreamEqualFunction(AnalyticsValue baseExpr, AnalyticsValueStream compExpr) throws SolrException {+ this.baseExpr = baseExpr;+ this.compExpr = compExpr;+ this.funcStr = AnalyticsValueStream.createExpressionString(name,baseExpr,compExpr);+ this.funcType = AnalyticsValueStream.determineMappingPhase(funcStr,baseExpr,compExpr);+ }++ @Override+ public void streamBooleans(BooleanConsumer cons) {+ Object baseValue = baseExpr.getObject();+ if (baseExpr.exists()) {+ compExpr.streamObjects(compValue -> cons.accept(baseValue.equals(compValue)));+ }+ }++ @Override+ public String getName() {+ return name;+ }+ @Override+ public String getExpressionStr() {+ return funcStr;+ }+ @Override+ public ExpressionType getExpressionType() {+ return funcType;+ }+}diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/ExistsFunction.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/ExistsFunction.javanew file mode 100644index 00000000000..dbdca472e1a--- /dev/null+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/ExistsFunction.java@@ -0,0 +1,123 @@+/*+ * 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.analytics.function.mapping;++import org.apache.solr.common.SolrException;+import org.apache.solr.common.SolrException.ErrorCode;++import org.apache.solr.analytics.ExpressionFactory.CreatorFunction;+import org.apache.solr.analytics.value.AnalyticsValue;+import org.apache.solr.analytics.value.AnalyticsValueStream;+import org.apache.solr.analytics.value.BooleanValue;+import org.apache.solr.analytics.value.BooleanValue.AbstractBooleanValue;++/**+ * A mapping function to test if a value.+ * <p>+ * Any {@link AnalyticsValueStream} can be passed in, and a {@link BooleanValue} will be returned representing whether a value exists.+ */+public class ExistsFunction {+ public static final String name = "exists";+ public static final CreatorFunction creatorFunction = (params -> {+ if (params.length != 1) {+ throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires 1 parameter.");+ }+ AnalyticsValueStream param = params[0];+ if (param instanceof AnalyticsValue) {+ return new ValueExistsFunction((AnalyticsValue)param);+ }+ return new ValueStreamExistsFunction(param);+ });+}+/**+ * Exists function that supports {@link AnalyticsValueStream}s.+ */+class ValueStreamExistsFunction extends AbstractBooleanValue {+ private final AnalyticsValueStream param;+ public static final String name = ExistsFunction.name;+ private final String exprStr;+ private final ExpressionType funcType;++ public ValueStreamExistsFunction(AnalyticsValueStream param) throws SolrException {+ this.param = param;+ this.exprStr = AnalyticsValueStream.createExpressionString(name,param);+ this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,param);+ }++ private boolean exists;+ @Override+ public boolean getBoolean() {+ exists = false;+ param.streamObjects(val -> exists = true);+ return exists;+ }+ @Override+ public boolean exists() {+ return true;+ }++ @Override+ public String getName() {+ return name;+ }+ @Override+ public String getExpressionStr() {+ return exprStr;+ }+ @Override+ public ExpressionType getExpressionType() {+ return funcType;+ }+}+/**+ * Exists function that supports {@link AnalyticsValue}s.+ */+class ValueExistsFunction extends AbstractBooleanValue {+ private final AnalyticsValue param;+ public static final String name = ExistsFunction.name;+ private final String exprStr;+ private final ExpressionType funcType;++ public ValueExistsFunction(AnalyticsValue param) throws SolrException {+ this.param = param;+ this.exprStr = AnalyticsValueStream.createExpressionString(name,param);+ this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,param);+ }++ @Override+ public boolean getBoolean() {+ param.getObject();+ return param.exists();+ }+ @Override+ public boolean exists() {+ return true;+ }++ @Override+ public String getName() {+ return name;+ }+ @Override+ public String getExpressionStr() {+ return exprStr;+ }+ @Override+ public ExpressionType getExpressionType() {+ return funcType;+ }+}diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/FillMissingFunction.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/FillMissingFunction.javaindex 188d6986a49..837bbe6af3c 100644--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/FillMissingFunction.java+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/FillMissingFunction.java@@ -41,6 +41,7 @@ import org.apache.solr.analytics.value.LongValueStream;import org.apache.solr.analytics.value.StringValue;import org.apache.solr.analytics.value.StringValueStream;import org.apache.solr.analytics.value.AnalyticsValue.AbstractAnalyticsValue;+import org.apache.solr.analytics.value.AnalyticsValueStream.AbstractAnalyticsValueStream;import org.apache.solr.analytics.value.BooleanValue.AbstractBooleanValue;import org.apache.solr.analytics.value.BooleanValueStream.AbstractBooleanValueStream;import org.apache.solr.analytics.value.DateValue.AbstractDateValue;@@ -71,7 +72,7 @@ import org.apache.solr.common.SolrException.ErrorCode;* (e.g. {@value #name}(double,int) will return a double)*/public class FillMissingFunction {- public static final String name = "fillmissing";+ public static final String name = "fill_missing";public static final CreatorFunction creatorFunction = (params -> {if (params.length != 2) {@@ -128,7 +129,7 @@ public class FillMissingFunction {return new StreamFillMissingFunction(baseExpr,fillExpr);});}-class StreamFillMissingFunction implements AnalyticsValueStream, Consumer<Object> {+class StreamFillMissingFunction extends AbstractAnalyticsValueStream implements Consumer<Object> {private final AnalyticsValueStream baseExpr;private final AnalyticsValueStream fillExpr;public static final String name = FillMissingFunction.name;diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/FilterFunction.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/FilterFunction.javaindex 84a3e30ca13..afd2c2a3ebb 100644--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/FilterFunction.java+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/FilterFunction.java@@ -41,6 +41,7 @@ import org.apache.solr.analytics.value.LongValueStream;import org.apache.solr.analytics.value.StringValue;import org.apache.solr.analytics.value.StringValueStream;import org.apache.solr.analytics.value.AnalyticsValue.AbstractAnalyticsValue;+import org.apache.solr.analytics.value.AnalyticsValueStream.AbstractAnalyticsValueStream;import org.apache.solr.analytics.value.BooleanValue.AbstractBooleanValue;import org.apache.solr.analytics.value.BooleanValueStream.AbstractBooleanValueStream;import org.apache.solr.analytics.value.DateValue.AbstractDateValue;@@ -128,7 +129,7 @@ public class FilterFunction {return new StreamFilterFunction(baseExpr,filterExpr);});}-class StreamFilterFunction implements AnalyticsValueStream {+class StreamFilterFunction extends AbstractAnalyticsValueStream {private final AnalyticsValueStream baseExpr;private final BooleanValue filterExpr;public static final String name = FilterFunction.name;diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/IfFunction.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/IfFunction.javaindex e2fd16364f4..0e4f1b9876a 100644--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/IfFunction.java+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/IfFunction.java@@ -41,6 +41,7 @@ import org.apache.solr.analytics.value.LongValueStream;import org.apache.solr.analytics.value.StringValue;import org.apache.solr.analytics.value.StringValueStream;import org.apache.solr.analytics.value.AnalyticsValue.AbstractAnalyticsValue;+import org.apache.solr.analytics.value.AnalyticsValueStream.AbstractAnalyticsValueStream;import org.apache.solr.analytics.value.BooleanValue.AbstractBooleanValue;import org.apache.solr.analytics.value.BooleanValueStream.AbstractBooleanValueStream;import org.apache.solr.analytics.value.DateValue.AbstractDateValue;@@ -70,7 +71,7 @@ import org.apache.solr.common.SolrException.ErrorCode;* If two {@link AnalyticsValue}s are passed as the if-else parameters, an {@link AnalyticsValue} will be returned.* If either parameter isn't single-valued, a {@link AnalyticsValueStream} will be returned.*/-public class IfFunction implements AnalyticsValueStream {+public class IfFunction extends AbstractAnalyticsValueStream {private final BooleanValue ifExpr;private final AnalyticsValueStream thenExpr;private final AnalyticsValueStream elseExpr;diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/JoinFunction.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/JoinFunction.javadeleted file mode 100644index 528aae25656..00000000000--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/JoinFunction.java+++ /dev/null@@ -1,57 +0,0 @@-/*- * 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.analytics.function.mapping;--import org.apache.solr.common.SolrException;-import org.apache.solr.common.SolrException.ErrorCode;-import org.apache.solr.analytics.ExpressionFactory.CreatorFunction;-import org.apache.solr.analytics.value.AnalyticsValueStream;-import org.apache.solr.analytics.value.StringValue;-import org.apache.solr.analytics.value.StringValueStream;-import org.apache.solr.analytics.value.constant.ConstantStringValue;--/**- * A string join mapping function.- * <p>- * Takes a {@link StringValueStream} as the first parameter and a {@link ConstantStringValue} (e.g. ",") as the second parameter- * and a {@link StringValue} is returned.- * <br>- * The second parameter is used as the separator while joining all values the first parameter has for a document.- * No order is guaranteed while joining the string values- */-public class JoinFunction {- public static final String name = "join";- public static final CreatorFunction creatorFunction = (params -> {- if (params.length != 2) {- throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires 2 parameters.");- }- AnalyticsValueStream param1 = params[0];- AnalyticsValueStream param2 = params[1];- if (!(param2 instanceof ConstantStringValue)) {- throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires the second parameter to be a constant string");- }- String sep = ((StringValue)param2).getString();- if (!(param1 instanceof StringValueStream)) {- throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires the first parameter to be castable to a string");- }- if (param1 instanceof StringValue) {- return param1;- }- String uniqueName = name + "(" + sep + ")";- return LambdaFunction.createStringLambdaFunction(uniqueName, (a,b) -> a + sep + b, (StringValueStream)params[0]);- });-}\ No newline at end of filediff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/LogicFunction.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/LogicFunction.javaindex 806cb0aeece..93dea531d2f 100644--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/LogicFunction.java+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/LogicFunction.java@@ -53,7 +53,7 @@ public class LogicFunction {AnalyticsValueStream param1 = params[0];AnalyticsValueStream param2 = params[1];if (param1 instanceof BooleanValueStream && param2 instanceof BooleanValueStream) {- return LambdaFunction.createBooleanLambdaFunction(name, (a,b) -> a && b, (BooleanValueStream)param1, (BooleanValueStream)param2);+ return LambdaFunction.createBooleanLambdaFunction(name, comp, (BooleanValueStream)param1, (BooleanValueStream)param2);}throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires boolean parameters.");}diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/RemoveFunction.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/RemoveFunction.javaindex 5800a1bc0bb..3ae070b8027 100644--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/RemoveFunction.java+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/RemoveFunction.java@@ -26,6 +26,7 @@ import org.apache.solr.analytics.util.function.BooleanConsumer;import org.apache.solr.analytics.util.function.FloatConsumer;import org.apache.solr.analytics.value.AnalyticsValue;import org.apache.solr.analytics.value.AnalyticsValueStream;+import org.apache.solr.analytics.value.AnalyticsValueStream.AbstractAnalyticsValueStream;import org.apache.solr.analytics.value.BooleanValue;import org.apache.solr.analytics.value.BooleanValueStream;import org.apache.solr.analytics.value.DateValue;@@ -77,7 +78,7 @@ public class RemoveFunction {throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires 2 paramaters, " + params.length + " found.");}if (!(params[1] instanceof AnalyticsValue)) {- throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires the remove paramater to be single-valued.");+ throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires the remove (2nd) paramater to be single-valued.");}AnalyticsValueStream baseExpr = params[0];@@ -131,7 +132,7 @@ public class RemoveFunction {return new StreamRemoveFunction(baseExpr,removeExpr);});}-class StreamRemoveFunction implements AnalyticsValueStream {+class StreamRemoveFunction extends AbstractAnalyticsValueStream {private final AnalyticsValueStream baseExpr;private final AnalyticsValue removeExpr;public static final String name = RemoveFunction.name;@@ -150,7 +151,7 @@ class StreamRemoveFunction implements AnalyticsValueStream {Object removeValue = removeExpr.getObject();if (removeExpr.exists()) {baseExpr.streamObjects(value -> {- if (removeValue.equals(value)) cons.accept(value);+ if (!removeValue.equals(value)) cons.accept(value);});} else {baseExpr.streamObjects(cons);@@ -193,7 +194,7 @@ class ValueRemoveFunction extends AbstractAnalyticsValue {Object value = baseExpr.getObject();exists = false;if (baseExpr.exists()) {- exists = value.equals(removeExpr.toString()) ? removeExpr.exists()? false : true : true;+ exists = value.equals(removeExpr.getObject()) ? (removeExpr.exists() ? false : true) : true;}return value;}@@ -237,7 +238,7 @@ class BooleanStreamRemoveFunction extends AbstractBooleanValueStream {boolean removeValue = removeExpr.getBoolean();if (removeExpr.exists()) {baseExpr.streamBooleans(value -> {- if (removeValue==value) cons.accept(value);+ if (removeValue != value) cons.accept(value);});} else {baseExpr.streamBooleans(cons);@@ -280,7 +281,7 @@ class BooleanRemoveFunction extends AbstractBooleanValue {boolean value = baseExpr.getBoolean();exists = false;if (baseExpr.exists()) {- exists = value==removeExpr.getBoolean() ? removeExpr.exists()? false : true : true;+ exists = value==removeExpr.getBoolean() ? (removeExpr.exists() ? false : true) : true;}return value;}@@ -321,7 +322,7 @@ class IntStreamRemoveFunction extends AbstractIntValueStream {int removeValue = removeExpr.getInt();if (removeExpr.exists()) {baseExpr.streamInts(value -> {- if (removeValue==value) cons.accept(value);+ if (removeValue != value) cons.accept(value);});} else {baseExpr.streamInts(cons);@@ -362,7 +363,7 @@ class IntRemoveFunction extends AbstractIntValue {int value = baseExpr.getInt();exists = false;if (baseExpr.exists()) {- exists = value==removeExpr.getInt() ? removeExpr.exists()? false : true : true;+ exists = value==removeExpr.getInt() ? (removeExpr.exists() ? false : true) : true;}return value;}@@ -403,7 +404,7 @@ class LongStreamRemoveFunction extends AbstractLongValueStream {long removeValue = removeExpr.getLong();if (removeExpr.exists()) {baseExpr.streamLongs(value -> {- if (removeValue==value) cons.accept(value);+ if (removeValue != value) cons.accept(value);});} else {baseExpr.streamLongs(cons);@@ -444,7 +445,7 @@ class LongRemoveFunction extends AbstractLongValue {long value = baseExpr.getLong();exists = false;if (baseExpr.exists()) {- exists = value==removeExpr.getLong() ? removeExpr.exists()? false : true : true;+ exists = value==removeExpr.getLong() ? (removeExpr.exists() ? false : true) : true;}return value;}@@ -485,7 +486,7 @@ class FloatStreamRemoveFunction extends AbstractFloatValueStream {float removeValue = removeExpr.getFloat();if (removeExpr.exists()) {baseExpr.streamFloats(value -> {- if (removeValue==value) cons.accept(value);+ if (removeValue != value) cons.accept(value);});} else {baseExpr.streamFloats(cons);@@ -526,7 +527,7 @@ class FloatRemoveFunction extends AbstractFloatValue {float value = baseExpr.getFloat();exists = false;if (baseExpr.exists()) {- exists = value==removeExpr.getFloat() ? removeExpr.exists()? false : true : true;+ exists = value==removeExpr.getFloat() ? (removeExpr.exists() ? false : true) : true;}return value;}@@ -567,7 +568,7 @@ class DoubleStreamRemoveFunction extends AbstractDoubleValueStream {double removeValue = removeExpr.getDouble();if (removeExpr.exists()) {baseExpr.streamDoubles(value -> {- if (removeValue==value) cons.accept(value);+ if (removeValue != value) cons.accept(value);});} else {baseExpr.streamDoubles(cons);@@ -608,7 +609,7 @@ class DoubleRemoveFunction extends AbstractDoubleValue {double value = baseExpr.getDouble();exists = false;if (baseExpr.exists()) {- exists = value==removeExpr.getDouble() ? removeExpr.exists()? false : true : true;+ exists = value==removeExpr.getDouble() ? (removeExpr.exists() ? false : true) : true;}return value;}@@ -649,7 +650,7 @@ class DateStreamRemoveFunction extends AbstractDateValueStream {long removeValue = removeExpr.getLong();if (removeExpr.exists()) {baseExpr.streamLongs(value -> {- if (removeValue==value) cons.accept(value);+ if (removeValue != value) cons.accept(value);});} else {baseExpr.streamLongs(cons);@@ -690,7 +691,7 @@ class DateRemoveFunction extends AbstractDateValue {long value = baseExpr.getLong();exists = false;if (baseExpr.exists()) {- exists = value==removeExpr.getLong() ? removeExpr.exists() ? false : true : true;+ exists = value==removeExpr.getLong() ? (removeExpr.exists() ? false : true) : true;}return value;}@@ -728,10 +729,10 @@ class StringStreamRemoveFunction extends AbstractStringValueStream {@Overridepublic void streamStrings(Consumer<String> cons) {- String removeValue = removeExpr.toString();+ String removeValue = removeExpr.getString();if (removeExpr.exists()) {baseExpr.streamStrings(value -> {- if (removeValue.equals(value)) cons.accept(value);+ if (!removeValue.equals(value)) cons.accept(value);});} else {baseExpr.streamStrings(cons);@@ -772,7 +773,7 @@ class StringRemoveFunction extends AbstractStringValue {String value = baseExpr.getString();exists = false;if (baseExpr.exists()) {- exists = value.equals(removeExpr.getString()) ? removeExpr.exists()? false : true : true;+ exists = value.equals(removeExpr.getString()) ? (removeExpr.exists() ? false : true) : true;}return value;}diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/ReplaceFunction.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/ReplaceFunction.javaindex 0d9e278b5ea..f878393a81f 100644--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/ReplaceFunction.java+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/ReplaceFunction.java@@ -41,6 +41,7 @@ import org.apache.solr.analytics.value.LongValueStream;import org.apache.solr.analytics.value.StringValue;import org.apache.solr.analytics.value.StringValueStream;import org.apache.solr.analytics.value.AnalyticsValue.AbstractAnalyticsValue;+import org.apache.solr.analytics.value.AnalyticsValueStream.AbstractAnalyticsValueStream;import org.apache.solr.analytics.value.BooleanValue.AbstractBooleanValue;import org.apache.solr.analytics.value.BooleanValueStream.AbstractBooleanValueStream;import org.apache.solr.analytics.value.DateValue.AbstractDateValue;@@ -136,7 +137,7 @@ public class ReplaceFunction {});}-class StreamReplaceFunction implements AnalyticsValueStream {+class StreamReplaceFunction extends AbstractAnalyticsValueStream {private final AnalyticsValueStream baseExpr;private final AnalyticsValue compExpr;private final AnalyticsValue fillExpr;@@ -156,8 +157,8 @@ class StreamReplaceFunction implements AnalyticsValueStream {public void streamObjects(Consumer<Object> cons) {Object compValue = compExpr.getObject();if (compExpr.exists()) {- Object fillValue = fillExpr.getObject();- boolean fillExists = fillExpr.exists();+ final Object fillValue = fillExpr.getObject();+ final boolean fillExists = fillExpr.exists();baseExpr.streamObjects(value -> {if (value.equals(compValue)) {if (fillExists) {@@ -209,7 +210,7 @@ class ValueReplaceFunction extends AbstractAnalyticsValue {Object value = baseExpr.getObject();exists = baseExpr.exists();Object comp = compExpr.getObject();- if (value.equals(comp) && exists==compExpr.exists()) {+ if (exists && compExpr.exists() && value.equals(comp)) {value = fillExpr.getObject();exists = fillExpr.exists();}@@ -253,10 +254,10 @@ class BooleanStreamReplaceFunction extends AbstractBooleanValueStream {public void streamBooleans(BooleanConsumer cons) {boolean compValue = compExpr.getBoolean();if (compExpr.exists()) {- boolean fillValue = fillExpr.getBoolean();- boolean fillExists = fillExpr.exists();+ final boolean fillValue = fillExpr.getBoolean();+ final boolean fillExists = fillExpr.exists();baseExpr.streamBooleans(value -> {- if (value==compValue) {+ if (value == compValue) {if (fillExists) {cons.accept(fillValue);}@@ -306,7 +307,7 @@ class BooleanReplaceFunction extends AbstractBooleanValue {boolean value = baseExpr.getBoolean();exists = baseExpr.exists();boolean comp = compExpr.getBoolean();- if (value==comp && exists==compExpr.exists()) {+ if (exists && compExpr.exists() && value == comp) {value = fillExpr.getBoolean();exists = fillExpr.exists();}@@ -350,10 +351,10 @@ class IntStreamReplaceFunction extends AbstractIntValueStream {public void streamInts(IntConsumer cons) {int compValue = compExpr.getInt();if (compExpr.exists()) {- int fillValue = fillExpr.getInt();- boolean fillExists = fillExpr.exists();+ final int fillValue = fillExpr.getInt();+ final boolean fillExists = fillExpr.exists();baseExpr.streamInts(value -> {- if (value==compValue) {+ if (value == compValue) {if (fillExists) {cons.accept(fillValue);}@@ -403,7 +404,7 @@ class IntReplaceFunction extends AbstractIntValue {int value = baseExpr.getInt();exists = baseExpr.exists();int comp = compExpr.getInt();- if (value==comp && exists==compExpr.exists()) {+ if (exists && compExpr.exists() && value == comp) {value = fillExpr.getInt();exists = fillExpr.exists();}@@ -447,10 +448,10 @@ class LongStreamReplaceFunction extends AbstractLongValueStream {public void streamLongs(LongConsumer cons) {long compValue = compExpr.getLong();if (compExpr.exists()) {- long fillValue = fillExpr.getLong();- boolean fillExists = fillExpr.exists();+ final long fillValue = fillExpr.getLong();+ final boolean fillExists = fillExpr.exists();baseExpr.streamLongs(value -> {- if (value==compValue) {+ if (value == compValue) {if (fillExists) {cons.accept(fillValue);}@@ -500,7 +501,7 @@ class LongReplaceFunction extends AbstractLongValue {long value = baseExpr.getLong();exists = baseExpr.exists();long comp = compExpr.getLong();- if (value==comp && exists==compExpr.exists()) {+ if (exists && compExpr.exists() && value == comp) {value = fillExpr.getLong();exists = fillExpr.exists();}@@ -544,10 +545,10 @@ class FloatStreamReplaceFunction extends AbstractFloatValueStream {public void streamFloats(FloatConsumer cons) {float compValue = compExpr.getFloat();if (compExpr.exists()) {- float fillValue = fillExpr.getFloat();- boolean fillExists = fillExpr.exists();+ final float fillValue = fillExpr.getFloat();+ final boolean fillExists = fillExpr.exists();baseExpr.streamFloats(value -> {- if (value==compValue) {+ if (value == compValue) {if (fillExists) {cons.accept(fillValue);}@@ -597,7 +598,7 @@ class FloatReplaceFunction extends AbstractFloatValue {float value = baseExpr.getFloat();exists = baseExpr.exists();float comp = compExpr.getFloat();- if (value==comp && exists==compExpr.exists()) {+ if (exists && compExpr.exists() && value == comp) {value = fillExpr.getFloat();exists = fillExpr.exists();}@@ -641,10 +642,10 @@ class DoubleStreamReplaceFunction extends AbstractDoubleValueStream {public void streamDoubles(DoubleConsumer cons) {double compValue = compExpr.getDouble();if (compExpr.exists()) {- double fillValue = fillExpr.getDouble();- boolean fillExists = fillExpr.exists();+ final double fillValue = fillExpr.getDouble();+ final boolean fillExists = fillExpr.exists();baseExpr.streamDoubles(value -> {- if (value==compValue) {+ if (value == compValue) {if (fillExists) {cons.accept(fillValue);}@@ -694,7 +695,7 @@ class DoubleReplaceFunction extends AbstractDoubleValue {double value = baseExpr.getDouble();exists = baseExpr.exists();double comp = compExpr.getDouble();- if (value==comp && exists==compExpr.exists()) {+ if (exists && compExpr.exists() && value == comp) {value = fillExpr.getDouble();exists = fillExpr.exists();}@@ -738,10 +739,10 @@ class DateStreamReplaceFunction extends AbstractDateValueStream {public void streamLongs(LongConsumer cons) {long compValue = compExpr.getLong();if (compExpr.exists()) {- long fillValue = fillExpr.getLong();- boolean fillExists = fillExpr.exists();+ final long fillValue = fillExpr.getLong();+ final boolean fillExists = fillExpr.exists();baseExpr.streamLongs(value -> {- if (value==compValue) {+ if (value == compValue) {if (fillExists) {cons.accept(fillValue);}@@ -791,7 +792,7 @@ class DateReplaceFunction extends AbstractDateValue {long value = baseExpr.getLong();exists = baseExpr.exists();long comp = compExpr.getLong();- if (value==comp && exists==compExpr.exists()) {+ if (exists && compExpr.exists() && value == comp) {value = fillExpr.getLong();exists = fillExpr.exists();}@@ -833,10 +834,10 @@ class StringStreamReplaceFunction extends AbstractStringValueStream {@Overridepublic void streamStrings(Consumer<String> cons) {- String compValue = compExpr.toString();+ String compValue = compExpr.getString();if (compExpr.exists()) {- String fillValue = fillExpr.toString();- boolean fillExists = fillExpr.exists();+ final String fillValue = fillExpr.getString();+ final boolean fillExists = fillExpr.exists();baseExpr.streamStrings(value -> {if (value.equals(compValue)) {if (fillExists) {@@ -888,7 +889,7 @@ class StringReplaceFunction extends AbstractStringValue {String value = baseExpr.getString();exists = baseExpr.exists();String comp = compExpr.getString();- if (value.equals(comp) && exists==compExpr.exists()) {+ if (exists && compExpr.exists() && value.equals(comp)) {value = fillExpr.getString();exists = fillExpr.exists();}diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/TopFunction.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/TopFunction.javaindex 801d1ea8378..a0d87547cfd 100644--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/TopFunction.java+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/TopFunction.java@@ -141,7 +141,7 @@ public class TopFunction {}if (param instanceof StringValueStream) {if (params.length == 1) {- return LambdaFunction.createStringLambdaFunction(name, (a,b) -> (a.compareTo(b)>=0)? a:b, (StringValueStream)param);+ return LambdaFunction.createStringLambdaFunction(name, (a,b) -> (a.compareTo(b)>0)? a:b, (StringValueStream)param);}StringValue[] castedParams = new StringValue[params.length];boolean tryNextType = false;@@ -154,7 +154,7 @@ public class TopFunction {}}if (!tryNextType) {- return LambdaFunction.createStringLambdaFunction(name, (a,b) -> (a.compareTo(b)>=0)? a:b, castedParams, false);+ return LambdaFunction.createStringLambdaFunction(name, (a,b) -> (a.compareTo(b)>0)? a:b, castedParams, false);}}throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires a comparable parameter. " +diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/reduction/DocCountFunction.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/reduction/DocCountFunction.javaindex f009b59cf02..d3e4be1120c 100644--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/reduction/DocCountFunction.java+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/reduction/DocCountFunction.java@@ -35,7 +35,7 @@ import org.apache.solr.common.SolrException.ErrorCode;*/public class DocCountFunction extends AbstractLongValue implements ReductionFunction {private CountCollector collector;- public static final String name = "docCount";+ public static final String name = "doc_count";private final String exprStr;public static final CreatorFunction creatorFunction = (params -> {if (params.length == 0) {diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/reduction/MeanFunction.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/reduction/MeanFunction.javanew file mode 100644index 00000000000..322f2f20cca--- /dev/null+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/reduction/MeanFunction.java@@ -0,0 +1,97 @@+/*+ * 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.analytics.function.reduction;++import java.io.Serializable;+import java.util.function.UnaryOperator;++import org.apache.solr.analytics.ExpressionFactory.CreatorFunction;+import org.apache.solr.analytics.function.ReductionFunction;+import org.apache.solr.analytics.function.reduction.data.CountCollector;+import org.apache.solr.analytics.function.reduction.data.CountCollector.ExpressionCountCollector;+import org.apache.solr.analytics.function.reduction.data.ReductionData;+import org.apache.solr.analytics.function.reduction.data.ReductionDataCollector;+import org.apache.solr.analytics.function.reduction.data.SumCollector;+import org.apache.solr.analytics.value.AnalyticsValueStream;+import org.apache.solr.analytics.value.DoubleValueStream;+import org.apache.solr.analytics.value.DoubleValue.AbstractDoubleValue;+import org.apache.solr.common.SolrException;+import org.apache.solr.common.SolrException.ErrorCode;++/**+ * A reduction function which returns the mean of the values of the given expression.+ */+public class MeanFunction extends AbstractDoubleValue implements ReductionFunction {+ private SumCollector sumCollector;+ private CountCollector countCollector;+ public static final String name = "mean";+ private final String exprStr;+ public static final CreatorFunction creatorFunction = (params -> {+ if (params.length != 1) {+ throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires 1 paramater, " + params.length + " found.");+ }+ DoubleValueStream casted;+ try {+ casted = (DoubleValueStream) params[0];+ }+ catch (ClassCastException e) {+ throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires numeric parameter. " ++ "Incorrect parameter: "+params[0].getExpressionStr());+ }+ return new MeanFunction(casted);+ });++ public MeanFunction(DoubleValueStream param) {+ this.sumCollector = new SumCollector(param);+ this.countCollector = new ExpressionCountCollector(param);+ this.exprStr = AnalyticsValueStream.createExpressionString(name,param);+ }++ @Override+ public double getDouble() {+ return (countCollector.count() > 0)? sumCollector.sum() / countCollector.count() : 0;+ }+ @Override+ public boolean exists() {+ return sumCollector.exists() && countCollector.count() > 0;+ }++ @Override+ public void synchronizeDataCollectors(UnaryOperator<ReductionDataCollector<?>> sync) {+ sumCollector = (SumCollector) sync.apply(sumCollector);+ countCollector = (CountCollector) sync.apply(countCollector);+ }++ @Override+ public String getExpressionStr() {+ return exprStr;+ }+ @Override+ public String getName() {+ return name;+ }++ @Override+ public ExpressionType getExpressionType() {+ return ExpressionType.REDUCTION;+ }++ protected static class SumData extends ReductionData implements Serializable {+ private static final long serialVersionUID = 5920718235872898338L;+ double sum;+ }+}\ No newline at end of filediff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/reduction/OrdinalFunction.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/reduction/OrdinalFunction.javaindex 0b86cdf9be9..cd059471140 100644--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/reduction/OrdinalFunction.java+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/reduction/OrdinalFunction.java@@ -41,7 +41,7 @@ import org.apache.solr.analytics.value.FloatValue.AbstractFloatValue;import org.apache.solr.analytics.value.IntValue.AbstractIntValue;import org.apache.solr.analytics.value.LongValue.AbstractLongValue;import org.apache.solr.analytics.value.StringValue.AbstractStringValue;-import org.apache.solr.analytics.value.constant.ConstantIntValue;+import org.apache.solr.analytics.value.constant.ConstantValue;import org.apache.solr.common.SolrException;import org.apache.solr.common.SolrException.ErrorCode;@@ -56,7 +56,7 @@ public class OrdinalFunction {}AnalyticsValueStream percValue = params[0];int ord = 0;- if (params[0] instanceof ConstantIntValue) {+ if (params[0] instanceof IntValue && params[0] instanceof ConstantValue) {ord = ((IntValue)percValue).getInt();if (ord == 0) {throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires the ordinal to be >= 1 or <= -1, 0 is not accepted.");@@ -81,10 +81,10 @@ public class OrdinalFunction {throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires a comparable parameter.");});- protected static String createOrdinalExpressionString(AnalyticsValueStream param, double perc) {+ protected static String createOrdinalExpressionString(AnalyticsValueStream param, double ord) {return String.format(Locale.ROOT, "%s(%s,%s)",name,- (int)(perc*100),+ ord,param.getExpressionStr());}}@@ -108,7 +108,6 @@ class IntOrdinalFunction extends AbstractIntValue implements ReductionFunction {} else {return (ordinal * -1) <= size ? collector.get(size + ordinal) : 0;}-}@Overridepublic boolean exists() {@@ -118,11 +117,7 @@ class IntOrdinalFunction extends AbstractIntValue implements ReductionFunction {@Overridepublic void synchronizeDataCollectors(UnaryOperator<ReductionDataCollector<?>> sync) {collector = (SortedIntListCollector)sync.apply(collector);- if (ordinal > 0) {- collector.calcOrdinal(ordinal);- } else {- collector.calcReverseOrdinal(ordinal*-1);- }+ collector.calcOrdinal(ordinal);}@Override@@ -158,7 +153,6 @@ class LongOrdinalFunction extends AbstractLongValue implements ReductionFunction} else {return (ordinal * -1) <= size ? collector.get(size + ordinal) : 0;}-}@Overridepublic boolean exists() {@@ -168,11 +162,7 @@ class LongOrdinalFunction extends AbstractLongValue implements ReductionFunction@Overridepublic void synchronizeDataCollectors(UnaryOperator<ReductionDataCollector<?>> sync) {collector = (SortedLongListCollector)sync.apply(collector);- if (ordinal > 0) {- collector.calcOrdinal(ordinal);- } else {- collector.calcReverseOrdinal(ordinal*-1);- }+ collector.calcOrdinal(ordinal);}@Override@@ -208,7 +198,6 @@ class FloatOrdinalFunction extends AbstractFloatValue implements ReductionFuncti} else {return (ordinal * -1) <= size ? collector.get(size + ordinal) : 0;}-}@Overridepublic boolean exists() {@@ -218,11 +207,7 @@ class FloatOrdinalFunction extends AbstractFloatValue implements ReductionFuncti@Overridepublic void synchronizeDataCollectors(UnaryOperator<ReductionDataCollector<?>> sync) {collector = (SortedFloatListCollector)sync.apply(collector);- if (ordinal > 0) {- collector.calcOrdinal(ordinal);- } else {- collector.calcReverseOrdinal(ordinal*-1);- }+ collector.calcOrdinal(ordinal);}@Override@@ -258,7 +243,6 @@ class DoubleOrdinalFunction extends AbstractDoubleValue implements ReductionFunc} else {return (ordinal * -1) <= size ? collector.get(size + ordinal) : 0;}-}@Overridepublic boolean exists() {@@ -268,11 +252,7 @@ class DoubleOrdinalFunction extends AbstractDoubleValue implements ReductionFunc@Overridepublic void synchronizeDataCollectors(UnaryOperator<ReductionDataCollector<?>> sync) {collector = (SortedDoubleListCollector)sync.apply(collector);- if (ordinal > 0) {- collector.calcOrdinal(ordinal);- } else {- collector.calcReverseOrdinal(ordinal*-1);- }+ collector.calcOrdinal(ordinal);}@Override@@ -308,7 +288,6 @@ class DateOrdinalFunction extends AbstractDateValue implements ReductionFunction} else {return (ordinal * -1) <= size ? collector.get(size + ordinal) : 0;}-}@Overridepublic boolean exists() {@@ -354,7 +333,6 @@ class StringOrdinalFunction extends AbstractStringValue implements ReductionFunc} else {return (ordinal * -1) <= size ? collector.get(size + ordinal) : null;}-}@Overridepublic boolean exists() {@@ -364,11 +342,7 @@ class StringOrdinalFunction extends AbstractStringValue implements ReductionFunc@Overridepublic void synchronizeDataCollectors(UnaryOperator<ReductionDataCollector<?>> sync) {collector = (SortedStringListCollector)sync.apply(collector);- if (ordinal > 0) {- collector.calcOrdinal(ordinal);- } else {- collector.calcReverseOrdinal(ordinal*-1);- }+ collector.calcOrdinal(ordinal);}@Overridediff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/reduction/PercentileFunction.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/reduction/PercentileFunction.javaindex 4277d90e0f1..a329160c63d 100644--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/reduction/PercentileFunction.java+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/reduction/PercentileFunction.java@@ -29,9 +29,9 @@ import org.apache.solr.analytics.function.reduction.data.SortedListCollector.Sorimport org.apache.solr.analytics.function.reduction.data.SortedListCollector.SortedStringListCollector;import org.apache.solr.analytics.value.AnalyticsValueStream;import org.apache.solr.analytics.value.DateValueStream;+import org.apache.solr.analytics.value.DoubleValue;import org.apache.solr.analytics.value.DoubleValueStream;import org.apache.solr.analytics.value.FloatValueStream;-import org.apache.solr.analytics.value.IntValue;import org.apache.solr.analytics.value.IntValueStream;import org.apache.solr.analytics.value.LongValueStream;import org.apache.solr.analytics.value.StringValueStream;@@ -41,7 +41,7 @@ import org.apache.solr.analytics.value.FloatValue.AbstractFloatValue;import org.apache.solr.analytics.value.IntValue.AbstractIntValue;import org.apache.solr.analytics.value.LongValue.AbstractLongValue;import org.apache.solr.analytics.value.StringValue.AbstractStringValue;-import org.apache.solr.analytics.value.constant.ConstantIntValue;+import org.apache.solr.analytics.value.constant.ConstantValue;import org.apache.solr.common.SolrException;import org.apache.solr.common.SolrException.ErrorCode;@@ -56,14 +56,14 @@ public class PercentileFunction {}AnalyticsValueStream percValue = params[0];double perc = 0;- if (percValue instanceof ConstantIntValue) {- perc = ((IntValue)percValue).getInt();- if (perc < 0 || perc > 99) {- throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires a percentile between 0 and 99, " + ((int)perc) + " found.");+ if (percValue instanceof DoubleValue && percValue instanceof ConstantValue) {+ perc = ((DoubleValue)percValue).getDouble();+ if (perc < 0 || perc >= 100) {+ throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires a percentile between [0, 100), " + perc + " found.");}perc /= 100;} else {- throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires a constant int value (the percentile) as the first argument.");+ throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires a constant double value (the percentile) as the first argument.");}AnalyticsValueStream param = params[1];if (param instanceof DateValueStream) {@@ -85,7 +85,7 @@ public class PercentileFunction {protected static String createPercentileExpressionString(AnalyticsValueStream param, double perc) {return String.format(Locale.ROOT, "%s(%s,%s)",name,- (int)(perc*100),+ perc,param.getExpressionStr());}}diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/reduction/SumFunction.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/reduction/SumFunction.javaindex 7d4e939108b..fec1a38d7c1 100644--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/reduction/SumFunction.java+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/reduction/SumFunction.java@@ -31,7 +31,7 @@ import org.apache.solr.common.SolrException;import org.apache.solr.common.SolrException.ErrorCode;/**- * A reduction function which returns the sum of the sorted values of the given expression.+ * A reduction function which returns the sum of the values of the given expression.*/public class SumFunction extends AbstractDoubleValue implements ReductionFunction {private SumCollector collector;diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/reduction/data/SortedListCollector.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/reduction/data/SortedListCollector.javaindex c0de54bab5f..bc0c4d4049d 100644--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/reduction/data/SortedListCollector.java+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/reduction/data/SortedListCollector.java@@ -68,7 +68,6 @@ public abstract class SortedListCollector<T extends Comparable<T>> extends ReduccalcMedian = false;calcPercs = new HashSet<>();calcOrds = new HashSet<>();- calcRevOrds = new HashSet<>();}private List<T> list;@@ -76,7 +75,6 @@ public abstract class SortedListCollector<T extends Comparable<T>> extends Reducprivate boolean calcMedian;private Set<Double> calcPercs;private Set<Integer> calcOrds;- private Set<Integer> calcRevOrds;public int size() {return list.size();@@ -107,21 +105,11 @@ public abstract class SortedListCollector<T extends Comparable<T>> extends ReduccalcOrds.add(ordinal);}- /**- * Informs the collector that the following reverse ordinal needs to be computed.- * Reverse ordinals are ordinals that start at the end of the list.- *- * @param reverseOrdinal requested reverseOrdinal- */- public void calcReverseOrdinal(int reverseOrdinal) {- calcRevOrds.add(reverseOrdinal);- }-/*** Once the data has been set by either {@link #setData} or {@link #setMergedData},* this returns the value at the given sorted index.*- * Only the indices specified by {@link #calcMedian}, {@link #calcPercentile}, {@link #calcOrdinal}, and {@link #calcReverseOrdinal}+ * Only the indices specified by {@link #calcMedian}, {@link #calcPercentile}, and {@link #calcOrdinal}* will contain valid data. All other indices may return unsorted data.** @param index the index of the sorted data to return@@ -207,11 +195,14 @@ public abstract class SortedListCollector<T extends Comparable<T>> extends Reduc// Ordinals start at 0 and end at size-1Set<Integer> ordinals = new HashSet<>();for (double percentile : calcPercs) {- ordinals.add((int) Math.ceil(percentile * size) - 1);+ ordinals.add((int) Math.round(percentile * size - .5));}- ordinals.addAll(calcOrds);- for (int reverseOrdinal : calcRevOrds) {- ordinals.add(size + reverseOrdinal);+ for (int ordinal : calcOrds) {+ if (ordinal > 0) {+ ordinals.add(ordinal - 1);+ } else if (ordinal < 0){+ ordinals.add(size + ordinal);+ }}if (calcMedian) {int mid = list.size() / 2;diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/plugin/AnalyticsStatisticsCollector.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/plugin/AnalyticsStatisticsCollector.javadeleted file mode 100644index 4c993232388..00000000000--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/plugin/AnalyticsStatisticsCollector.java+++ /dev/null@@ -1,104 +0,0 @@-/*- * 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.analytics.plugin;--import java.util.HashMap;-import java.util.Map;-import java.util.concurrent.atomic.AtomicLong;--import com.codahale.metrics.Timer;-import org.apache.solr.util.stats.MetricUtils;--public class AnalyticsStatisticsCollector {- private final AtomicLong numRequests;- private final AtomicLong numAnalyticsRequests;- private final AtomicLong numStatsRequests;- private final AtomicLong numCollectedStats;- private final AtomicLong numFieldFacets;- private final AtomicLong numRangeFacets;- private final AtomicLong numQueryFacets;- private final AtomicLong numQueries;- private final Timer requestTimes;-- public Timer.Context currentTimer;-- public AnalyticsStatisticsCollector() {- numRequests = new AtomicLong();- numAnalyticsRequests = new AtomicLong();- numStatsRequests = new AtomicLong();- numCollectedStats = new AtomicLong();- numFieldFacets = new AtomicLong();- numRangeFacets = new AtomicLong();- numQueryFacets = new AtomicLong();- numQueries = new AtomicLong();- requestTimes = new Timer();- }-- public void startRequest() {- numRequests.incrementAndGet();- currentTimer = requestTimes.time();- }-- public void addRequests(long num) {- numAnalyticsRequests.addAndGet(num);- }-- public void addStatsRequests(long num) {- numStatsRequests.addAndGet(num);- }-- public void addStatsCollected(long num) {- numCollectedStats.addAndGet(num);- }-- public void addFieldFacets(long num) {- numFieldFacets.addAndGet(num);- }-- public void addRangeFacets(long num) {- numRangeFacets.addAndGet(num);- }-- public void addQueryFacets(long num) {- numQueryFacets.addAndGet(num);- }-- public void addQueries(long num) {- numQueries.addAndGet(num);- }-- public void endRequest() {- currentTimer.stop();- }-- public Map<String, Object> getStatistics() {-- Map<String, Object> map = new HashMap<>();- MetricUtils.convertTimer("", requestTimes, MetricUtils.PropertyFilter.ALL, false, false, ".", (k, v) -> {- map.putAll((Map<String, Object>)v);- });- map.put("requests", numRequests.longValue());- map.put("analyticsRequests", numAnalyticsRequests.longValue());- map.put("statsRequests", numStatsRequests.longValue());- map.put("statsCollected", numCollectedStats.longValue());- map.put("fieldFacets", numFieldFacets.longValue());- map.put("rangeFacets", numRangeFacets.longValue());- map.put("queryFacets", numQueryFacets.longValue());- map.put("queriesInQueryFacets", numQueries.longValue());- return map;- }-}diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/util/OldAnalyticsParams.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/util/OldAnalyticsParams.javaindex 084d997140a..86203fcbdd2 100644--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/util/OldAnalyticsParams.java+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/util/OldAnalyticsParams.java@@ -27,6 +27,7 @@ import org.apache.solr.analytics.AnalyticsRequestParser.AnalyticsExpressionSortRimport org.apache.solr.analytics.AnalyticsRequestParser.AnalyticsRangeFacetRequest;import org.apache.solr.analytics.AnalyticsRequestParser.AnalyticsSortRequest;import org.apache.solr.analytics.AnalyticsRequestParser.AnalyticsValueFacetRequest;+import org.apache.solr.analytics.function.mapping.FillMissingFunction;/*** Specifies the format of the old olap-style analytics requests.@@ -80,7 +81,7 @@ public interface OldAnalyticsParams {} else if (isOffset.test(param)) {getSort(facet).offset = Integer.parseInt(value);} else if (isShowMissing.test(param)) {- facet.expression = "fillmissing(" + facet.expression + ",\"(MISSING)\")";+ facet.expression = FillMissingFunction.name + "(" + facet.expression + ",\"(MISSING)\")";} else if (isSortExpr.test(param)) {AnalyticsSortRequest sort = getSort(facet);AnalyticsExpressionSortRequest criterion;diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/util/OrdinalCalculator.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/util/OrdinalCalculator.javaindex e484e7cacca..23ff70e2a97 100644--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/util/OrdinalCalculator.java+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/util/OrdinalCalculator.java@@ -44,11 +44,8 @@ public class OrdinalCalculator {for (int ord : ordinals) {ords[i++] = ord;}- Arrays.sort(ords);+ ords = Arrays.stream(ords).sorted().filter( ord -> ord >= 0 && ord < size).toArray();- if (ords[0] < 0 || ords[ords.length - 1] > size - 1) {- throw new IllegalArgumentException();- }distributeAndFind(list, ords, 0, ords.length - 1);}diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/AnalyticsValue.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/AnalyticsValue.javaindex 54a3003c8db..5b738dedba4 100644--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/AnalyticsValue.java+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/AnalyticsValue.java@@ -17,7 +17,6 @@package org.apache.solr.analytics.value;import java.util.function.Consumer;-/*** A single-valued analytics value.* <p>@@ -33,6 +32,7 @@ public interface AnalyticsValue extends AnalyticsValueStream {* @return whether the current value exists*/boolean exists();+/*** Get the object representation of the current value.*@@ -51,5 +51,9 @@ public interface AnalyticsValue extends AnalyticsValueStream {cons.accept(value);}}+ @Override+ public AnalyticsValueStream convertToConstant() {+ return this;+ }}}diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/AnalyticsValueStream.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/AnalyticsValueStream.javaindex 0c021158c25..cba88358fd5 100644--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/AnalyticsValueStream.java+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/AnalyticsValueStream.java@@ -21,6 +21,7 @@ import java.util.Locale;import java.util.function.Consumer;import org.apache.solr.analytics.ExpressionFactory;+import org.apache.solr.analytics.value.constant.ConstantValue;import org.apache.solr.common.SolrException;import org.apache.solr.common.SolrException.ErrorCode;@@ -51,6 +52,22 @@ public interface AnalyticsValueStream {*/void streamObjects(Consumer<Object> cons);+ /**+ * Converts this value to a {@link ConstantValue} if it's expression type is {@link ExpressionType#CONST}.+ *+ * If the value is reduced then no conversion will occur and the value itself will be returned.+ *+ * @return a constant representation of this value+ */+ AnalyticsValueStream convertToConstant();++ public static abstract class AbstractAnalyticsValueStream implements AnalyticsValueStream {+ @Override+ public AnalyticsValueStream convertToConstant() {+ return this;+ }+ }+/*** The types of expressions.*/diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/BooleanValue.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/BooleanValue.javaindex 5d58a8b2407..4c742f2a9d1 100644--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/BooleanValue.java+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/BooleanValue.java@@ -20,6 +20,7 @@ import java.util.function.Consumer;import org.apache.solr.analytics.facet.compare.ExpressionComparator;import org.apache.solr.analytics.util.function.BooleanConsumer;+import org.apache.solr.analytics.value.constant.ConstantBooleanValue;/*** A single-valued analytics value that can be represented as a boolean.@@ -78,6 +79,13 @@ public interface BooleanValue extends BooleanValueStream, AnalyticsValue {}}@Override+ public AnalyticsValue convertToConstant() {+ if (getExpressionType().equals(ExpressionType.CONST)) {+ return new ConstantBooleanValue(getBoolean());+ }+ return this;+ }+ @Overridepublic ExpressionComparator<Boolean> getObjectComparator(String expression) {return new ExpressionComparator<>(expression);}diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/BooleanValueStream.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/BooleanValueStream.javaindex 0827aea6426..b2eb19b44ab 100644--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/BooleanValueStream.java+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/BooleanValueStream.java@@ -51,5 +51,9 @@ public interface BooleanValueStream extends AnalyticsValueStream {public void streamObjects(Consumer<Object> cons) {streamBooleans((boolean val) -> cons.accept(val));}+ @Override+ public AnalyticsValueStream convertToConstant() {+ return this;+ }}}diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/DateValue.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/DateValue.javaindex b105d5861b4..8a0f0a9a39c 100644--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/DateValue.java+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/DateValue.java@@ -22,6 +22,7 @@ import java.util.function.Consumer;import java.util.function.LongConsumer;import org.apache.solr.analytics.facet.compare.ExpressionComparator;+import org.apache.solr.analytics.value.constant.ConstantDateValue;/*** A single-valued analytics value that can be represented as a date.@@ -63,8 +64,7 @@ public interface DateValue extends DateValueStream, LongValue {}@Overridepublic Object getObject() {- long val = getLong();- return exists() ? new Date(val) : null;+ return getDate();}@Overridepublic void streamDates(Consumer<Date> cons) {@@ -95,6 +95,13 @@ public interface DateValue extends DateValueStream, LongValue {}}@Override+ public AnalyticsValue convertToConstant() {+ if (getExpressionType().equals(ExpressionType.CONST)) {+ return new ConstantDateValue(getLong());+ }+ return this;+ }+ @Overridepublic ExpressionComparator<Date> getObjectComparator(String expression) {return new ExpressionComparator<>(expression);}diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/DateValueStream.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/DateValueStream.javaindex f709264c1c4..b7ab159f0c3 100644--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/DateValueStream.java+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/DateValueStream.java@@ -56,7 +56,11 @@ public interface DateValueStream extends LongValueStream {}@Overridepublic void streamObjects(Consumer<Object> cons) {- streamLongs((long val) -> cons.accept(new Date(val)));+ streamDates((Date val) -> cons.accept(val));+ }+ @Override+ public AnalyticsValueStream convertToConstant() {+ return this;}}}diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/DoubleValue.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/DoubleValue.javaindex ba527f0ba8f..87a1499ad64 100644--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/DoubleValue.java+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/DoubleValue.java@@ -20,6 +20,7 @@ import java.util.function.Consumer;import java.util.function.DoubleConsumer;import org.apache.solr.analytics.facet.compare.ExpressionComparator;+import org.apache.solr.analytics.value.constant.ConstantDoubleValue;/*** A single-valued analytics value that can be represented as a date.@@ -79,6 +80,13 @@ public interface DoubleValue extends DoubleValueStream, AnalyticsValue {}}@Override+ public AnalyticsValue convertToConstant() {+ if (getExpressionType().equals(ExpressionType.CONST)) {+ return new ConstantDoubleValue(getDouble());+ }+ return this;+ }+ @Overridepublic ExpressionComparator<Double> getObjectComparator(String expression) {return new ExpressionComparator<>(expression);}diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/DoubleValueStream.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/DoubleValueStream.javaindex a50c8347fa9..e0b4b30e023 100644--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/DoubleValueStream.java+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/DoubleValueStream.java@@ -50,5 +50,9 @@ public interface DoubleValueStream extends AnalyticsValueStream {public void streamObjects(Consumer<Object> cons) {streamDoubles((double val) -> cons.accept(val));}+ @Override+ public AnalyticsValueStream convertToConstant() {+ return this;+ }}}diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/FloatValue.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/FloatValue.javaindex 16883d5a787..38893d1fef9 100644--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/FloatValue.java+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/FloatValue.java@@ -21,6 +21,7 @@ import java.util.function.DoubleConsumer;import org.apache.solr.analytics.facet.compare.ExpressionComparator;import org.apache.solr.analytics.util.function.FloatConsumer;+import org.apache.solr.analytics.value.constant.ConstantFloatValue;/*** A single-valued analytics value that can be represented as a float.@@ -90,6 +91,13 @@ public interface FloatValue extends FloatValueStream, AnalyticsValue {}}@Override+ public AnalyticsValue convertToConstant() {+ if (getExpressionType().equals(ExpressionType.CONST)) {+ return new ConstantFloatValue(getFloat());+ }+ return this;+ }+ @Overridepublic ExpressionComparator<Float> getObjectComparator(String expression) {return new ExpressionComparator<>(expression);}diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/FloatValueStream.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/FloatValueStream.javaindex cf15a2154dc..5364540dec6 100644--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/FloatValueStream.java+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/FloatValueStream.java@@ -56,5 +56,9 @@ public interface FloatValueStream extends AnalyticsValueStream {public void streamObjects(Consumer<Object> cons) {streamFloats((float val) -> cons.accept(val));}+ @Override+ public AnalyticsValueStream convertToConstant() {+ return this;+ }}}diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/IntValue.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/IntValue.javaindex 56883571e22..c7353d8c771 100644--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/IntValue.java+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/IntValue.java@@ -23,6 +23,7 @@ import java.util.function.LongConsumer;import org.apache.solr.analytics.facet.compare.ExpressionComparator;import org.apache.solr.analytics.util.function.FloatConsumer;+import org.apache.solr.analytics.value.constant.ConstantIntValue;/*** A single-valued analytics value that can be represented as an int.@@ -114,6 +115,13 @@ public interface IntValue extends IntValueStream, AnalyticsValue {}}@Override+ public AnalyticsValue convertToConstant() {+ if (getExpressionType().equals(ExpressionType.CONST)) {+ return new ConstantIntValue(getInt());+ }+ return this;+ }+ @Overridepublic ExpressionComparator<Integer> getObjectComparator(String expression) {return new ExpressionComparator<>(expression);}diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/IntValueStream.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/IntValueStream.javaindex 9cbe28c5388..e4f1014ba35 100644--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/IntValueStream.java+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/IntValueStream.java@@ -67,5 +67,9 @@ public interface IntValueStream extends AnalyticsValueStream {public void streamObjects(Consumer<Object> cons) {streamInts((int val) -> cons.accept(val));}+ @Override+ public AnalyticsValueStream convertToConstant() {+ return this;+ }}}diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/LongValue.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/LongValue.javaindex 623cd1343d4..2cdf16ccc81 100644--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/LongValue.java+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/LongValue.java@@ -21,6 +21,7 @@ import java.util.function.DoubleConsumer;import java.util.function.LongConsumer;import org.apache.solr.analytics.facet.compare.ExpressionComparator;+import org.apache.solr.analytics.value.constant.ConstantLongValue;/*** A single-valued analytics value that can be represented as a long.@@ -90,6 +91,13 @@ public interface LongValue extends LongValueStream, AnalyticsValue {}}@Override+ public AnalyticsValue convertToConstant() {+ if (getExpressionType().equals(ExpressionType.CONST)) {+ return new ConstantLongValue(getLong());+ }+ return this;+ }+ @Overridepublic ExpressionComparator<Long> getObjectComparator(String expression) {return new ExpressionComparator<>(expression);}diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/LongValueStream.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/LongValueStream.javaindex d18cb03c130..5446b70fec3 100644--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/LongValueStream.java+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/LongValueStream.java@@ -56,5 +56,9 @@ public interface LongValueStream extends AnalyticsValueStream {public void streamObjects(Consumer<Object> cons) {streamLongs((long val) -> cons.accept(val));}+ @Override+ public AnalyticsValueStream convertToConstant() {+ return this;+ }}}diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/StringValue.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/StringValue.javaindex 7baf18e631a..47c0a33dd18 100644--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/StringValue.java+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/StringValue.java@@ -19,6 +19,7 @@ package org.apache.solr.analytics.value;import java.util.function.Consumer;import org.apache.solr.analytics.facet.compare.ExpressionComparator;+import org.apache.solr.analytics.value.constant.ConstantStringValue;/*** A single-valued analytics value that can be represented as a string.@@ -64,6 +65,13 @@ public interface StringValue extends StringValueStream, AnalyticsValue {}}@Override+ public AnalyticsValue convertToConstant() {+ if (getExpressionType().equals(ExpressionType.CONST)) {+ return new ConstantStringValue(getString());+ }+ return this;+ }+ @Overridepublic ExpressionComparator<String> getObjectComparator(String expression) {return new ExpressionComparator<>(expression);}diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/StringValueStream.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/StringValueStream.javaindex 2269ac401f6..536e4751845 100644--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/StringValueStream.java+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/StringValueStream.java@@ -45,5 +45,9 @@ public interface StringValueStream extends AnalyticsValueStream {public void streamObjects(Consumer<Object> cons) {streamStrings((String val) -> cons.accept(val));}+ @Override+ public AnalyticsValueStream convertToConstant() {+ return this;+ }}}diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/constant/ConstantValue.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/constant/ConstantValue.javaindex 2e364b15344..5691f6481cd 100644--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/constant/ConstantValue.java+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/constant/ConstantValue.java@@ -16,7 +16,8 @@*/package org.apache.solr.analytics.value.constant;-import java.text.SimpleDateFormat;+import java.time.Instant;+import java.time.format.DateTimeParseException;import java.util.Locale;import java.util.regex.Matcher;import java.util.regex.Pattern;@@ -34,29 +35,13 @@ import org.apache.solr.common.SolrException.ErrorCode;* <ul>* <li> Constant booleans must match one of the following in any case: true, t, false, f* <li> Constant strings must be surrounded with "s or 's- * <li> Constant numbers do not have to be surrounded with anything- * <li> Constant dates must match one of the following patterns- * <ul>- * <li> yyyy-MM-dd- * <li> yyyy-MM-ddXXX- * <li> yyyy-MM-dd'T'HH:mm:ssZ- * <li> yyyy-MM-dd'T'HH:mm:ssXXX- * <li> yyyy-MM-dd'T'HH:mm:ss.SSSZ- * <li> yyyy-MM-dd'T'HH:mm:ss.SSSXXX- * </ul>- * </li>+ * <li> Constant numbers do not have to be surrounded with anything (floats are currently not supported)+ * <li> Constant dates must be formated in the ISO-8601 instant format* </ul>*/-public abstract class ConstantValue {+public abstract class ConstantValue implements AnalyticsValue {private static final Pattern truePattern = Pattern.compile("^true|t$", Pattern.CASE_INSENSITIVE);private static final Pattern falsePattern = Pattern.compile("^false|f$", Pattern.CASE_INSENSITIVE);- private static final SimpleDateFormat dateParserBase = new SimpleDateFormat("yyyy-MM-dd", Locale.ROOT);- private static final SimpleDateFormat dateParser1 = new SimpleDateFormat("yyyy-MM-ddZ", Locale.ROOT);- private static final SimpleDateFormat dateParser2 = new SimpleDateFormat("yyyy-MM-ddXXX", Locale.ROOT);- private static final SimpleDateFormat dateParser3 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.ROOT);- private static final SimpleDateFormat dateParser4 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX", Locale.ROOT);- private static final SimpleDateFormat dateParser5 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.ROOT);- private static final SimpleDateFormat dateParser6 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX", Locale.ROOT);public static final ConstantFunction creatorFunction = (param -> {param = param.trim();@@ -79,50 +64,36 @@ public abstract class ConstantValue {// Try to create a numbertry {- AnalyticsValue value = new ConstantDoubleValue(Double.parseDouble(param));- try {- value = new ConstantLongValue(Long.parseLong(param));- value = new ConstantIntValue(Integer.parseInt(param));- } catch (NumberFormatException e) {- value = new ConstantFloatValue(Float.parseFloat(param));+ long longTemp = Long.parseLong(param);+ if (longTemp == (int) longTemp) {+ return new ConstantIntValue((int) longTemp);+ } else {+ return new ConstantLongValue(longTemp);}- return value;- } catch (NumberFormatException e) {- // The constant is not a number+ } catch (NumberFormatException e1) {+ try {+ return new ConstantDoubleValue(Double.parseDouble(param));+ } catch (NumberFormatException e2) {}}// Try to create a datetry {- AnalyticsValue value = new ConstantDateValue(dateParserBase.parse(param).getTime());- try {- return new ConstantDateValue(dateParser1.parse(param).getTime());- } catch (Exception e) {}- try {- return new ConstantDateValue(dateParser2.parse(param).getTime());- } catch (Exception e) {}- try {- return new ConstantDateValue(dateParser3.parse(param).getTime());- } catch (Exception e) {}- try {- return new ConstantDateValue(dateParser4.parse(param).getTime());- } catch (Exception e) {}- try {- return new ConstantDateValue(dateParser5.parse(param).getTime());- } catch (Exception e) {}- try {- return new ConstantDateValue(dateParser6.parse(param).getTime());- } catch (Exception e) {}- return value;- } catch (Exception e) {+ return new ConstantDateValue(Instant.parse(param).toEpochMilli());+ } catch (DateTimeParseException e) {throw new SolrException(ErrorCode.BAD_REQUEST,"The parameter "+param+" could not be cast to any constant.");}});+ @Override+ public AnalyticsValue convertToConstant() {+ return this;+ }+static String createExpressionString(AnalyticsValueStream func,Object param) {return String.format(Locale.ROOT,"%s(%s)",func.getName(),param.toString());}-}\ No newline at end of file+}diff --git a/solr/contrib/analytics/src/test-files/solr/analytics/expressions.txt b/solr/contrib/analytics/src/test-files/solr/analytics/legacy/expressions.txtsimilarity index 100%rename from solr/contrib/analytics/src/test-files/solr/analytics/expressions.txtrename to solr/contrib/analytics/src/test-files/solr/analytics/legacy/expressions.txtdiff --git a/solr/contrib/analytics/src/test-files/solr/analytics/facetSorting.txt b/solr/contrib/analytics/src/test-files/solr/analytics/legacy/facetSorting.txtsimilarity index 100%rename from solr/contrib/analytics/src/test-files/solr/analytics/facetSorting.txtrename to solr/contrib/analytics/src/test-files/solr/analytics/legacy/facetSorting.txtdiff --git a/solr/contrib/analytics/src/test-files/solr/analytics/fieldFacetExtras.txt b/solr/contrib/analytics/src/test-files/solr/analytics/legacy/fieldFacetExtras.txtsimilarity index 100%rename from solr/contrib/analytics/src/test-files/solr/analytics/fieldFacetExtras.txtrename to solr/contrib/analytics/src/test-files/solr/analytics/legacy/fieldFacetExtras.txtdiff --git a/solr/contrib/analytics/src/test-files/solr/analytics/fieldFacets.txt b/solr/contrib/analytics/src/test-files/solr/analytics/legacy/fieldFacets.txtsimilarity index 100%rename from solr/contrib/analytics/src/test-files/solr/analytics/fieldFacets.txtrename to solr/contrib/analytics/src/test-files/solr/analytics/legacy/fieldFacets.txtdiff --git a/solr/contrib/analytics/src/test-files/solr/analytics/functions.txt b/solr/contrib/analytics/src/test-files/solr/analytics/legacy/functions.txtsimilarity index 100%rename from solr/contrib/analytics/src/test-files/solr/analytics/functions.txtrename to solr/contrib/analytics/src/test-files/solr/analytics/legacy/functions.txtdiff --git a/solr/contrib/analytics/src/test-files/solr/analytics/noFacets.txt b/solr/contrib/analytics/src/test-files/solr/analytics/legacy/noFacets.txtsimilarity index 100%rename from solr/contrib/analytics/src/test-files/solr/analytics/noFacets.txtrename to solr/contrib/analytics/src/test-files/solr/analytics/legacy/noFacets.txtdiff --git a/solr/contrib/analytics/src/test-files/solr/analytics/queryFacets.txt b/solr/contrib/analytics/src/test-files/solr/analytics/legacy/queryFacets.txtsimilarity index 100%rename from solr/contrib/analytics/src/test-files/solr/analytics/queryFacets.txtrename to solr/contrib/analytics/src/test-files/solr/analytics/legacy/queryFacets.txtdiff --git a/solr/contrib/analytics/src/test-files/solr/analytics/rangeFacets.txt b/solr/contrib/analytics/src/test-files/solr/analytics/legacy/rangeFacets.txtsimilarity index 100%rename from solr/contrib/analytics/src/test-files/solr/analytics/rangeFacets.txtrename to solr/contrib/analytics/src/test-files/solr/analytics/legacy/rangeFacets.txtdiff --git a/solr/contrib/analytics/src/test-files/solr/collection1/conf/schema-analytics.xml b/solr/contrib/analytics/src/test-files/solr/collection1/conf/schema-analytics.xmlindex 527e66a2bce..65704168817 100644--- a/solr/contrib/analytics/src/test-files/solr/collection1/conf/schema-analytics.xml+++ b/solr/contrib/analytics/src/test-files/solr/collection1/conf/schema-analytics.xml@@ -25,7 +25,7 @@-->-<schema name="schema-analytics" version="1.0">+<schema name="schema-analytics" version="1.6"><!-- field type definitions... note that the "name" attribute is@@ -39,50 +39,89 @@These are provided more for backward compatability, allowing oneto create a schema that matches an existing lucene index.-->- <fieldType name="int" class="${solr.tests.IntegerFieldType}" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>- <fieldType name="float" class="${solr.tests.FloatFieldType}" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>- <fieldType name="long" class="${solr.tests.LongFieldType}" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>- <fieldType name="double" class="${solr.tests.DoubleFieldType}" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>+ <fieldType name="int" class="${solr.tests.IntegerFieldType}" docValues="true" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>+ <fieldType name="float" class="${solr.tests.FloatFieldType}" docValues="true" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>+ <fieldType name="long" class="${solr.tests.LongFieldType}" docValues="true" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>+ <fieldType name="double" class="${solr.tests.DoubleFieldType}" docValues="true" precisionStep="0" omitNorms="true" positionIncrementGap="0"/><!-- format for date is 1995-12-31T23:59:59.999Z and only the fractionalseconds part (.999) is optional.-->- <fieldType name="date" class="${solr.tests.DateFieldType}" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>-- <fieldType name="boolean" class="solr.BoolField"/>- <fieldType name="string" class="solr.StrField"/>-- <fieldType name="uuid" class="solr.UUIDField"/>--- <field name="id" type="string" docValues="true" multiValued="false" required="true"/>-- <field name="floatdv" type="float" indexed="false" stored="false" docValues="true" default="1"/>- <field name="intdv" type="int" indexed="false" stored="false" docValues="true" default="2"/>- <field name="doubledv" type="double" indexed="false" stored="false" docValues="true" default="3"/>- <field name="longdv" type="long" indexed="false" stored="false" docValues="true" default="4"/>- <field name="datedv" type="date" indexed="false" stored="false" docValues="true" default="1995-12-31T23:59:59.999Z"/>-- <field name="stringdv" type="string" indexed="false" stored="false" docValues="true" default="solr"/>- <field name="stringdvm" type="string" indexed="false" stored="false" docValues="true" default="solr" multiValued="true"/>-- <dynamicField name="*_i" type="int" indexed="true" stored="true" docValues="false" multiValued="false"/>- <dynamicField name="*_id" type="int" indexed="true" stored="true" docValues="true" multiValued="false"/>- <dynamicField name="*_idm" type="int" indexed="true" stored="true" docValues="true" multiValued="true"/>- <dynamicField name="*_l" type="long" indexed="true" stored="true" docValues="false" multiValued="false"/>- <dynamicField name="*_ld" type="long" indexed="true" stored="true" docValues="true" multiValued="false"/>- <dynamicField name="*_ldm" type="long" indexed="true" stored="true" docValues="true" multiValued="true"/>- <dynamicField name="*_f" type="float" indexed="true" stored="true" docValues="false" multiValued="false"/>- <dynamicField name="*_fd" type="float" indexed="true" stored="true" docValues="true" multiValued="false"/>- <dynamicField name="*_fdm" type="float" indexed="true" stored="true" docValues="true" multiValued="true"/>- <dynamicField name="*_d" type="double" indexed="true" stored="true" docValues="false" multiValued="false"/>- <dynamicField name="*_dd" type="double" indexed="true" stored="true" docValues="true" multiValued="false"/>- <dynamicField name="*_ddm" type="double" indexed="true" stored="true" docValues="true" multiValued="true"/>- <dynamicField name="*_dt" type="date" indexed="true" stored="true" docValues="false" multiValued="false"/>- <dynamicField name="*_dtd" type="date" indexed="true" stored="true" docValues="true" multiValued="false"/>- <dynamicField name="*_dtdm" type="date" indexed="true" stored="true" docValues="true" multiValued="true"/>- <dynamicField name="*_s" type="string" indexed="true" stored="true" docValues="false" multiValued="false"/>- <dynamicField name="*_sd" type="string" indexed="true" stored="true" docValues="true" multiValued="false"/>- <dynamicField name="*_sdm" type="string" indexed="true" stored="true" docValues="true" multiValued="true"/>+ <fieldType name="date" class="${solr.tests.DateFieldType}" docValues="true" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>++ <!-- Numeric Trie Fields -->+ <fieldType name="int_trie" class="solr.TrieIntField" docValues="true" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>+ <fieldType name="float_trie" class="solr.TrieFloatField" docValues="true" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>+ <fieldType name="long_trie" class="solr.TrieLongField" docValues="true" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>+ <fieldType name="double_trie" class="solr.TrieDoubleField" docValues="true" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>+ <fieldType name="date_trie" class="solr.TrieDateField" docValues="true" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>++ <!-- Numeric Trie Fields -->+ <fieldType name="int_pnt" class="solr.IntPointField" docValues="true" />+ <fieldType name="float_pnt" class="solr.FloatPointField" docValues="true" />+ <fieldType name="long_pnt" class="solr.LongPointField" docValues="true" />+ <fieldType name="double_pnt" class="solr.DoublePointField" docValues="true" />+ <fieldType name="date_pnt" class="solr.DatePointField" docValues="true" />++ <fieldType name="boolean" class="solr.BoolField" docValues="true"/>+ <fieldType name="string" class="solr.StrField" docValues="true"/>+++ <field name="id" type="string" multiValued="false" required="true"/>++ <dynamicField name="*_b" type="boolean" indexed="true" stored="true" multiValued="false"/>+ <dynamicField name="*_bm" type="boolean" indexed="true" stored="true" multiValued="true"/>+ <dynamicField name="*_bd" type="boolean" indexed="true" stored="true" multiValued="false"/>+ <dynamicField name="*_bdm" type="boolean" indexed="true" stored="true" multiValued="true"/>++ <dynamicField name="*_i" type="int" indexed="true" stored="true" multiValued="false"/>+ <dynamicField name="*_im" type="int" indexed="true" stored="true" multiValued="true"/>+ <dynamicField name="*_i_t" type="int_trie" indexed="true" stored="true" multiValued="false"/>+ <dynamicField name="*_im_t" type="int_trie" indexed="true" stored="true" multiValued="true"/>+ <dynamicField name="*_i_p" type="int_pnt" indexed="true" stored="true" multiValued="false"/>+ <dynamicField name="*_im_p" type="int_pnt" indexed="true" stored="true" multiValued="true"/>+ <dynamicField name="*_id" type="int" indexed="true" stored="true" multiValued="false"/>+ <dynamicField name="*_idm" type="int" indexed="true" stored="true" multiValued="true"/>++ <dynamicField name="*_l" type="long" indexed="true" stored="true" multiValued="false"/>+ <dynamicField name="*_lm" type="long" indexed="true" stored="true" multiValued="true"/>+ <dynamicField name="*_l_t" type="long_trie" indexed="true" stored="true" multiValued="false"/>+ <dynamicField name="*_lm_t" type="long_trie" indexed="true" stored="true" multiValued="true"/>+ <dynamicField name="*_l_p" type="long_pnt" indexed="true" stored="true" multiValued="false"/>+ <dynamicField name="*_lm_p" type="long_pnt" indexed="true" stored="true" multiValued="true"/>+ <dynamicField name="*_ld" type="long" indexed="true" stored="true" multiValued="false"/>+ <dynamicField name="*_ldm" type="long" indexed="true" stored="true" multiValued="true"/>++ <dynamicField name="*_f" type="float" indexed="true" stored="true" multiValued="false"/>+ <dynamicField name="*_fm" type="float" indexed="true" stored="true" multiValued="true"/>+ <dynamicField name="*_f_t" type="float_trie" indexed="true" stored="true" multiValued="false"/>+ <dynamicField name="*_fm_t" type="float_trie" indexed="true" stored="true" multiValued="true"/>+ <dynamicField name="*_f_p" type="float_pnt" indexed="true" stored="true" multiValued="false"/>+ <dynamicField name="*_fm_p" type="float_pnt" indexed="true" stored="true" multiValued="true"/>+ <dynamicField name="*_fd" type="float" indexed="true" stored="true" multiValued="false"/>+ <dynamicField name="*_fdm" type="float" indexed="true" stored="true" multiValued="true"/>++ <dynamicField name="*_d" type="double" indexed="true" stored="true" multiValued="false"/>+ <dynamicField name="*_dm" type="double" indexed="true" stored="true" multiValued="true"/>+ <dynamicField name="*_d_t" type="double_trie" indexed="true" stored="true" multiValued="false"/>+ <dynamicField name="*_dm_t" type="double_trie" indexed="true" stored="true" multiValued="true"/>+ <dynamicField name="*_d_p" type="double_pnt" indexed="true" stored="true" multiValued="false"/>+ <dynamicField name="*_dm_p" type="double_pnt" indexed="true" stored="true" multiValued="true"/>+ <dynamicField name="*_dd" type="double" indexed="true" stored="true" multiValued="false"/>+ <dynamicField name="*_ddm" type="double" indexed="true" stored="true" multiValued="true"/>++ <dynamicField name="*_dt" type="date" indexed="true" stored="true" multiValued="false"/>+ <dynamicField name="*_dtm" type="date" indexed="true" stored="true" multiValued="true"/>+ <dynamicField name="*_dt_t" type="date_trie" indexed="true" stored="true" multiValued="false"/>+ <dynamicField name="*_dtm_t" type="date_trie" indexed="true" stored="true" multiValued="true"/>+ <dynamicField name="*_dt_p" type="date_pnt" indexed="true" stored="true" multiValued="false"/>+ <dynamicField name="*_dtm_p" type="date_pnt" indexed="true" stored="true" multiValued="true"/>+ <dynamicField name="*_dtd" type="date" indexed="true" stored="true" multiValued="false"/>+ <dynamicField name="*_dtdm" type="date" indexed="true" stored="true" multiValued="true"/>++ <dynamicField name="*_s" type="string" indexed="true" stored="true" multiValued="false"/>+ <dynamicField name="*_sm" type="string" indexed="true" stored="true" multiValued="true"/>+ <dynamicField name="*_sd" type="string" indexed="true" stored="true" multiValued="false"/>+ <dynamicField name="*_sdm" type="string" indexed="true" stored="true" multiValued="true"/><uniqueKey>id</uniqueKey>diff --git a/solr/contrib/analytics/src/test-files/solr/configsets/cloud-analytics/conf/schema.xml b/solr/contrib/analytics/src/test-files/solr/configsets/cloud-analytics/conf/schema.xmlindex 0fac17f6cac..cb9ad1396ee 100644--- a/solr/contrib/analytics/src/test-files/solr/configsets/cloud-analytics/conf/schema.xml+++ b/solr/contrib/analytics/src/test-files/solr/configsets/cloud-analytics/conf/schema.xml@@ -16,18 +16,18 @@limitations under the License.-->-<!-- The Solr schema file for cloud analytics, version 1.0 -->+<!-- The Solr schema file for cloud analytics, version 1.6 -->-<schema name="cloud-analytics" version="1.0">+<schema name="cloud-analytics" version="1.6">- <fieldType name="boolean" class="solr.BoolField" sortMissingLast="true"/>- <fieldType name="string" class="solr.StrField" sortMissingLast="true"/>+ <fieldType name="boolean" class="solr.BoolField" docValues="true" sortMissingLast="true"/>+ <fieldType name="string" class="solr.StrField" docValues="true" sortMissingLast="true"/>- <fieldType name="int" class="${solr.tests.IntegerFieldType}" precisionStep="0" omitNorms="true" positionIncrementGap="0" />- <fieldType name="float" class="${solr.tests.FloatFieldType}" precisionStep="0" omitNorms="true" positionIncrementGap="0" />- <fieldType name="long" class="${solr.tests.LongFieldType}" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>- <fieldType name="double" class="${solr.tests.DoubleFieldType}" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>- <fieldType name="date" class="${solr.tests.DateFieldType}" precisionStep="0" omitNorms="true" positionIncrementGap="0" />+ <fieldType name="int" class="${solr.tests.IntegerFieldType}" docValues="true" precisionStep="0" omitNorms="true" positionIncrementGap="0" />+ <fieldType name="float" class="${solr.tests.FloatFieldType}" docValues="true" precisionStep="0" omitNorms="true" positionIncrementGap="0" />+ <fieldType name="long" class="${solr.tests.LongFieldType}" docValues="true" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>+ <fieldType name="double" class="${solr.tests.DoubleFieldType}" docValues="true" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>+ <fieldType name="date" class="${solr.tests.DateFieldType}" docValues="true" precisionStep="0" omitNorms="true" positionIncrementGap="0" /><field name="id" type="string" indexed="true" stored="true" multiValued="false" required="true"/>@@ -39,20 +39,40 @@<field name="_route_" type="string" indexed="true" stored="true" multiValued="false"/><!-- dynamic fields with doc-values (for analytics) -->- <dynamicField name="*_id" type="int" docValues="true" indexed="true" stored="true"/>- <dynamicField name="*_idm" type="int" docValues="true" indexed="true" stored="true" multiValued="true"/>- <dynamicField name="*_sd" type="string" docValues="true" indexed="true" stored="true" />- <dynamicField name="*_sdm" type="string" docValues="true" indexed="true" stored="true" multiValued="true"/>- <dynamicField name="*_ld" type="long" docValues="true" indexed="true" stored="true"/>- <dynamicField name="*_ldm" type="long" docValues="true" indexed="true" stored="true" multiValued="true"/>- <dynamicField name="*_bd" type="boolean" docValues="true" indexed="true" stored="true"/>- <dynamicField name="*_bdm" type="boolean" docValues="true" indexed="true" stored="true" multiValued="true"/>- <dynamicField name="*_fd" type="float" docValues="true" indexed="true" stored="true"/>- <dynamicField name="*_fdm" type="float" docValues="true" indexed="true" stored="true" multiValued="true"/>- <dynamicField name="*_dd" type="double" docValues="true" indexed="true" stored="true"/>- <dynamicField name="*_ddm" type="double" docValues="true" indexed="true" stored="true" multiValued="true"/>- <dynamicField name="*_dtd" type="date" docValues="true" indexed="true" stored="true"/>- <dynamicField name="*_dtdm" type="date" docValues="true" indexed="true" stored="true" multiValued="true"/>+ <dynamicField name="*_i" type="int" indexed="true" stored="true"/>+ <dynamicField name="*_im" type="int" indexed="true" stored="true" multiValued="true"/>+ <dynamicField name="*_id" type="int" indexed="true" stored="true"/>+ <dynamicField name="*_idm" type="int" indexed="true" stored="true" multiValued="true"/>++ <dynamicField name="*_s" type="string" indexed="true" stored="true" />+ <dynamicField name="*_sm" type="string" indexed="true" stored="true" multiValued="true"/>+ <dynamicField name="*_sd" type="string" indexed="true" stored="true" />+ <dynamicField name="*_sdm" type="string" indexed="true" stored="true" multiValued="true"/>++ <dynamicField name="*_l" type="long" indexed="true" stored="true"/>+ <dynamicField name="*_lm" type="long" indexed="true" stored="true" multiValued="true"/>+ <dynamicField name="*_ld" type="long" indexed="true" stored="true"/>+ <dynamicField name="*_ldm" type="long" indexed="true" stored="true" multiValued="true"/>++ <dynamicField name="*_b" type="boolean" indexed="true" stored="true"/>+ <dynamicField name="*_bm" type="boolean" indexed="true" stored="true" multiValued="true"/>+ <dynamicField name="*_bd" type="boolean" indexed="true" stored="true"/>+ <dynamicField name="*_bdm" type="boolean" indexed="true" stored="true" multiValued="true"/>++ <dynamicField name="*_f" type="float" indexed="true" stored="true"/>+ <dynamicField name="*_fm" type="float" indexed="true" stored="true" multiValued="true"/>+ <dynamicField name="*_fd" type="float" indexed="true" stored="true"/>+ <dynamicField name="*_fdm" type="float" indexed="true" stored="true" multiValued="true"/>++ <dynamicField name="*_d" type="double" indexed="true" stored="true"/>+ <dynamicField name="*_dm" type="double" indexed="true" stored="true" multiValued="true"/>+ <dynamicField name="*_dd" type="double" indexed="true" stored="true"/>+ <dynamicField name="*_ddm" type="double" indexed="true" stored="true" multiValued="true"/>++ <dynamicField name="*_dt" type="date" indexed="true" stored="true"/>+ <dynamicField name="*_dtm" type="date" indexed="true" stored="true" multiValued="true"/>+ <dynamicField name="*_dtd" type="date" indexed="true" stored="true"/>+ <dynamicField name="*_dtdm" type="date" indexed="true" stored="true" multiValued="true"/><uniqueKey>id</uniqueKey></schema>diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/ExpressionFactoryTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/ExpressionFactoryTest.javanew file mode 100644index 00000000000..b4f5b952025--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/ExpressionFactoryTest.java@@ -0,0 +1,249 @@+/*+ * 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.analytics;++import java.util.Arrays;+import java.util.HashSet;+import java.util.Set;++import org.apache.solr.SolrTestCaseJ4;+import org.apache.solr.analytics.function.ReductionCollectionManager;+import org.apache.solr.analytics.value.constant.ConstantValue;+import org.apache.solr.schema.IndexSchema;+import org.junit.BeforeClass;+import org.junit.Test;++public class ExpressionFactoryTest extends SolrTestCaseJ4 {++ private static IndexSchema indexSchema;++ @BeforeClass+ public static void createSchemaAndFields() throws Exception {+ initCore("solrconfig-analytics.xml","schema-analytics.xml");+ assertU(adoc("id", "1",+ "int_i", "1",+ "int_im", "1",+ "long_l", "1",+ "long_lm", "1",+ "float_f", "1",+ "float_fm", "1",+ "double_d", "1",+ "double_dm", "1",+ "date_dt", "1800-12-31T23:59:59Z",+ "date_dtm", "1800-12-31T23:59:59Z",+ "string_s", "1",+ "string_sm", "1",+ "boolean_b", "true",+ "boolean_bm", "false"+ ));+ assertU(commit());++ indexSchema = h.getCore().getLatestSchema();+ }++ private ExpressionFactory getExpressionFactory() {+ ExpressionFactory fact = new ExpressionFactory(indexSchema);+ fact.startRequest();+ return fact;+ }++ @Test+ public void userDefinedVariableFunctionTest() {+ ExpressionFactory fact = getExpressionFactory();++ // Single parameter function+ fact.startRequest();+ fact.addUserDefinedVariableFunction("single_func(a)", "sum(add(a,double_d,float_f))");+ assertEquals("div(sum(add(int_i,double_d,float_f)),count(string_s))", fact.createExpression("div(single_func(int_i),count(string_s))").getExpressionStr());++ // Multi parameter function+ fact.startRequest();+ fact.addUserDefinedVariableFunction("multi_func(a,b,c)", "median(if(boolean_b,add(a,b),c))");+ assertEquals("div(median(if(boolean_b,add(int_i,double_d),float_f)),count(string_s))", fact.createExpression("div(multi_func(int_i,double_d,float_f),count(string_s))").getExpressionStr());++ // Function within function+ fact.startRequest();+ fact.addUserDefinedVariableFunction("inner_func(a,b)", "div(add(a,b),b)");+ fact.addUserDefinedVariableFunction("outer_func(a,b,c)", "pow(inner_func(a,b),c)");+ assertEquals("div(median(pow(div(add(int_i,double_d),double_d),float_f)),count(string_s))", fact.createExpression("div(median(outer_func(int_i,double_d,float_f)),count(string_s))").getExpressionStr());++ // Variable parameter function+ fact.startRequest();+ fact.addUserDefinedVariableFunction("var_func(a,b..)", "div(add(b),a)");+ assertEquals("unique(div(add(double_d,float_f),int_i))", fact.createExpression("unique(var_func(int_i,double_d,float_f))").getExpressionStr());+ assertEquals("unique(div(add(double_d,float_f,long_l),int_i))", fact.createExpression("unique(var_func(int_i,double_d,float_f,long_l))").getExpressionStr());++ // Variable parameter function with for-each+ fact.startRequest();+ fact.addUserDefinedVariableFunction("var_func_fe(a,b..)", "div(add(b:abs(_)),a)");+ assertEquals("unique(div(add(abs(double_d),abs(float_f)),int_i))", fact.createExpression("unique(var_func_fe(int_i,double_d,float_f))").getExpressionStr());+ assertEquals("unique(div(add(abs(double_d),abs(float_f),abs(long_l)),int_i))", fact.createExpression("unique(var_func_fe(int_i,double_d,float_f,long_l))").getExpressionStr());+ }++ @Test+ public void reuseFunctionsTest() {+ ExpressionFactory fact = getExpressionFactory();++ // Two ungrouped exactly the same expression+ fact.startRequest();+ assertTrue("The objects of the two mapping expressions are not the same.",+ fact.createExpression("pow(int_i,double_d)") == fact.createExpression("pow(int_i,double_d)"));+ assertTrue("The objects of the two reduced expressions are not the same.",+ fact.createExpression("unique(add(int_i,double_d))") == fact.createExpression("unique(add(int_i,double_d))"));++ // Two ungrouped different expressions+ fact.startRequest();+ assertFalse("The objects of the two mapping expressions are not the same.",+ fact.createExpression("pow(int_i,double_d)") == fact.createExpression("pow(int_i,float_f)"));+ assertFalse("The objects of the two reduced expressions are not the same.",+ fact.createExpression("unique(add(int_i,double_d))") == fact.createExpression("unique(add(int_i,float_f))"));++ // Grouped and ungrouped mapping expression+ fact.startRequest();+ Object ungrouped = fact.createExpression("pow(int_i,double_d)");+ fact.startGrouping();+ Object grouped = fact.createExpression("pow(int_i,double_d)");+ assertTrue("The objects of the two mapping expressions are not the same.", ungrouped == grouped);++ // Grouped and ungrouped diferent mapping expressions+ fact.startRequest();+ ungrouped = fact.createExpression("pow(int_i,double_d)");+ fact.startGrouping();+ grouped = fact.createExpression("pow(int_i,float_f)");+ assertFalse("The objects of the two mapping expressions are not the same.", ungrouped == grouped);++ // Grouped and ungrouped reduced expression.+ fact.startRequest();+ ungrouped = fact.createExpression("unique(add(int_i,double_d))");+ fact.startGrouping();+ grouped = fact.createExpression("unique(add(int_i,double_d))");+ assertTrue("The objects of the two mapping expressions are not the same.", ungrouped == grouped);++ // Grouped and ungrouped different reduced expressions.+ fact.startRequest();+ ungrouped = fact.createExpression("unique(add(int_i,double_d))");+ fact.startGrouping();+ grouped = fact.createExpression("unique(add(int_i,float_f))");+ assertFalse("The objects of the two mapping expressions are the same.", ungrouped == grouped);+ }++ @Test+ public void constantFunctionConversionTest() {+ ExpressionFactory fact = getExpressionFactory();+ fact.startRequest();++ assertTrue(fact.createExpression("add(1,2)") instanceof ConstantValue);+ assertTrue(fact.createExpression("add(1,2,2,3,4)") instanceof ConstantValue);+ assertTrue(fact.createExpression("add(1)") instanceof ConstantValue);+ assertTrue(fact.createExpression("concat(add(1,2), ' is a number')") instanceof ConstantValue);++ assertFalse(fact.createExpression("sum(add(1,2))") instanceof ConstantValue);+ assertFalse(fact.createExpression("sum(int_i)") instanceof ConstantValue);+ assertFalse(fact.createExpression("sub(1,long_l)") instanceof ConstantValue);+ }++ public void testReductionManager(ReductionCollectionManager manager, boolean hasExpressions, String... fields) {+ Set<String> usedFields = new HashSet<>(Arrays.asList(fields));+ manager.getUsedFields().forEach( field -> {+ assertTrue("Field '" + field.getName() + "' is either not unique or should not exist in the reductionManager.", usedFields.remove(field.getName()));+ });+ assertEquals(hasExpressions, manager.needsCollection());+ }++ @Test+ public void reductionManagerCreationTest() {+ ExpressionFactory fact = getExpressionFactory();++ // No expressions+ fact.startRequest();+ testReductionManager(fact.createReductionManager(false), false);++ // No fields+ fact.startRequest();+ fact.createExpression("sum(add(1,2))");+ testReductionManager(fact.createReductionManager(false), true);++ // Multiple expressions+ fact.startRequest();+ fact.createExpression("unique(add(int_i,float_f))");+ fact.createExpression("sum(add(int_i,double_d))");+ testReductionManager(fact.createReductionManager(false), true, "int_i", "float_f", "double_d");+ }++ @Test+ public void groupingReductionManagerCreationTest() {+ ExpressionFactory fact = getExpressionFactory();++ // No grouped expressions+ fact.startRequest();+ fact.createExpression("unique(add(int_i,float_f))");+ fact.createExpression("sum(add(int_i,double_d))");+ fact.startGrouping();+ testReductionManager(fact.createGroupingReductionManager(false), false);++ // No grouped fields+ fact.startRequest();+ fact.createExpression("unique(add(int_i,float_f))");+ fact.createExpression("sum(add(int_i,double_d))");+ fact.startGrouping();+ fact.createExpression("sum(add(1,2))");+ testReductionManager(fact.createGroupingReductionManager(false), true);++ // Single grouping, no ungrouped+ fact.startRequest();+ fact.startGrouping();+ fact.createExpression("unique(add(int_i,float_f))");+ fact.createExpression("sum(add(int_i,double_d))");+ testReductionManager(fact.createGroupingReductionManager(false), true, "int_i", "float_f", "double_d");++ // Single grouping, with ungrouped+ fact.startRequest();+ fact.createExpression("count(string_s)");+ fact.startGrouping();+ fact.createExpression("unique(add(int_i,float_f))");+ fact.createExpression("sum(add(int_i,double_d))");+ testReductionManager(fact.createGroupingReductionManager(false), true, "int_i", "float_f", "double_d");++ // Multiple groupings, no ungrouped+ fact.startRequest();+ fact.startGrouping();+ fact.createExpression("unique(add(int_i,float_f))");+ fact.createExpression("sum(add(int_i,double_d))");+ testReductionManager(fact.createGroupingReductionManager(false), true, "int_i", "float_f", "double_d");+ fact.startGrouping();+ testReductionManager(fact.createGroupingReductionManager(false), false);+ fact.startGrouping();+ fact.createExpression("unique(add(int_i,float_f))");+ fact.createExpression("ordinal(1,concat(string_s,'-extra'))");+ testReductionManager(fact.createGroupingReductionManager(false), true, "int_i", "float_f", "string_s");++ // Multiple groupings, with grouped+ fact.startRequest();+ fact.createExpression("count(string_s)");+ fact.createExpression("median(date_math(date_dt,'+1DAY'))");+ fact.startGrouping();+ fact.createExpression("unique(add(int_i,float_f))");+ fact.createExpression("sum(add(int_i,double_d))");+ testReductionManager(fact.createGroupingReductionManager(false), true, "int_i", "float_f", "double_d");+ fact.startGrouping();+ testReductionManager(fact.createGroupingReductionManager(false), false);+ fact.startGrouping();+ fact.createExpression("unique(add(int_i,float_f))");+ fact.createExpression("ordinal(1,concat(string_s,'-extra'))");+ testReductionManager(fact.createGroupingReductionManager(false), true, "int_i", "float_f", "string_s");+ }+}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/NoFacetTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/NoFacetTest.javaindex cfd1176c03e..6a5f8c572a4 100644--- a/solr/contrib/analytics/src/test/org/apache/solr/analytics/NoFacetTest.java+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/NoFacetTest.java@@ -17,434 +17,232 @@package org.apache.solr.analytics;import java.util.ArrayList;+import java.util.HashMap;import java.util.List;+import java.util.Map;import org.junit.BeforeClass;import org.junit.Test;-public class NoFacetTest extends AbstractAnalyticsStatsTest {- static String fileName = "noFacets.txt";-- static public final int INT = 71;- static public final int LONG = 36;- static public final int FLOAT = 93;- static public final int DOUBLE = 49;- static public final int DATE = 12;- static public final int STRING = 28;- static public final int NUM_LOOPS = 100;-- //INT- static ArrayList<Integer> intTestStart;- static long intMissing = 0;-- //LONG- static ArrayList<Long> longTestStart;- static long longMissing = 0;-- //FLOAT- static ArrayList<Float> floatTestStart;- static long floatMissing = 0;-- //DOUBLE- static ArrayList<Double> doubleTestStart;- static long doubleMissing = 0;-- //DATE- static ArrayList<String> dateTestStart;- static long dateMissing = 0;-- //STR- static ArrayList<String> stringTestStart;- static long stringMissing = 0;+public class NoFacetTest extends SolrAnalyticsTestCase {@BeforeClass- public static void beforeClass() throws Exception {- initCore("solrconfig-analytics.xml","schema-analytics.xml");- h.update("<delete><query>*:*</query></delete>");- defaults.put("int_id", new Integer(0));- defaults.put("long_ld", new Long(0));- defaults.put("float_fd", new Float(0));- defaults.put("double_dd", new Double(0));- defaults.put("date_dtd", "1800-12-31T23:59:59Z");- defaults.put("string_sd", "str0");-- intTestStart = new ArrayList<>();- longTestStart = new ArrayList<>();- floatTestStart = new ArrayList<>();- doubleTestStart = new ArrayList<>();- dateTestStart = new ArrayList<>();- stringTestStart = new ArrayList<>();-+ public static void populate() throws Exception {for (int j = 0; j < NUM_LOOPS; ++j) {int i = j%INT;long l = j%LONG;float f = j%FLOAT;double d = j%DOUBLE;String dt = (1800+j%DATE) + "-12-31T23:59:59Z";+ String dtm = (1800+j%DATE + 10) + "-12-31T23:59:59Z";String s = "str" + (j%STRING);List<String> fields = new ArrayList<>();fields.add("id"); fields.add("1000"+j);- if( i != 0 ){- fields.add("int_id"); fields.add("" + i);- intTestStart.add(i);- } else intMissing++;-- if( l != 0l ){- fields.add("long_ld"); fields.add("" + l);- longTestStart.add(l);- } else longMissing++;-- if( f != 0.0f ){- fields.add("float_fd"); fields.add("" + f);- floatTestStart.add(f);- } else floatMissing++;-- if( d != 0.0d ){- fields.add("double_dd"); fields.add("" + d);- doubleTestStart.add(d);- } else doubleMissing++;+ if ( i != 0 ) {+ fields.add("int_i"); fields.add("" + i);+ fields.add("int_im"); fields.add("" + i);+ fields.add("int_im"); fields.add("" + (i+10));+ }- if( (j%DATE) != 0 ){- fields.add("date_dtd"); fields.add(dt);- dateTestStart.add(dt);- } else dateMissing++;+ if ( l != 0l ) {+ fields.add("long_l"); fields.add("" + l);+ fields.add("long_lm"); fields.add("" + l);+ fields.add("long_lm"); fields.add("" + (l+10));+ }- if( (j%STRING) != 0 ){- fields.add("string_sd"); fields.add(s);- stringTestStart.add(s);- } else stringMissing++;+ if ( f != 0.0f ) {+ fields.add("float_f"); fields.add("" + f);+ fields.add("float_fm"); fields.add("" + f);+ fields.add("float_fm"); fields.add("" + (f+10));+ }- assertU(adoc(fields.toArray(new String[0])));+ if ( d != 0.0d ) {+ fields.add("double_d"); fields.add("" + d);+ fields.add("double_dm"); fields.add("" + d);+ fields.add("double_dm"); fields.add("" + (d+10));+ }+ if ( (j%DATE) != 0 ) {+ fields.add("date_dt"); fields.add(dt);+ fields.add("date_dtm"); fields.add(dt);+ fields.add("date_dtm"); fields.add(dtm);+ }- if (usually()) {- assertU(commit()); // to have several segments+ if ( (j%STRING) != 0 ) {+ fields.add("string_s"); fields.add(s);+ fields.add("string_sm"); fields.add(s);+ fields.add("string_sm"); fields.add(s + "_second");}++ addDoc(fields);}+ commitDocs();+ }++ static public final int INT = 7;+ static public final int LONG = 2;+ static public final int FLOAT = 6;+ static public final int DOUBLE = 5;+ static public final int DATE = 3;+ static public final int STRING = 4;+ static public final int NUM_LOOPS = 20;++ @Test+ public void countTest() throws Exception {+ Map<String, ETP> expressions = new HashMap<>();+ expressions.put("single", new ETP("count(long_l)", 10L));+ expressions.put("multi", new ETP("count(string_sm)", 30L));- assertU(commit());+ testExpressions(expressions);+ }++ @Test+ public void docCountTest() throws Exception {+ Map<String, ETP> expressions = new HashMap<>();+ expressions.put("single", new ETP("doc_count(date_dt)", 13L));+ expressions.put("multi", new ETP("doc_count(float_fm)", 16L));- //Sort ascending tests- setResponse(h.query(request(fileToStringArr(NoFacetTest.class, fileName))));+ testExpressions(expressions);}@Test- public void sumTest() throws Exception {- //Int- Double intResult = (Double)getStatResult("sr", "int_id", VAL_TYPE.DOUBLE);- Double intTest = (Double)calculateNumberStat(intTestStart, "sum");- assertEquals(getRawResponse(), intResult,intTest);-- //Long- Double longResult = (Double)getStatResult("sr", "long_ld", VAL_TYPE.DOUBLE);- Double longTest = (Double)calculateNumberStat(longTestStart, "sum");- assertEquals(getRawResponse(), longResult,longTest);-- //Float- Double floatResult = (Double)getStatResult("sr", "float_fd", VAL_TYPE.DOUBLE);- Double floatTest = (Double)calculateNumberStat(floatTestStart, "sum");- assertEquals(getRawResponse(), floatResult,floatTest);+ public void missingTest() throws Exception {+ Map<String, ETP> expressions = new HashMap<>();+ expressions.put("single", new ETP("missing(string_s)", 5L));+ expressions.put("multi", new ETP("missing(date_dtm)", 7L));- //Double- Double doubleResult = (Double)getStatResult("sr", "double_dd", VAL_TYPE.DOUBLE);- Double doubleTest = (Double) calculateNumberStat(doubleTestStart, "sum");- assertEquals(getRawResponse(), doubleResult,doubleTest);+ testExpressions(expressions);}@Test- public void meanTest() throws Exception {- //Int- Double intResult = (Double)getStatResult("mr", "int_id", VAL_TYPE.DOUBLE);- Double intTest = (Double)calculateNumberStat(intTestStart, "mean");- assertEquals(getRawResponse(), intResult,intTest);-- //Long- Double longResult = (Double)getStatResult("mr", "long_ld", VAL_TYPE.DOUBLE);- Double longTest = (Double)calculateNumberStat(longTestStart, "mean");- assertEquals(getRawResponse(), longResult,longTest);-- //Float- Double floatResult = (Double)getStatResult("mr", "float_fd", VAL_TYPE.DOUBLE);- Double floatTest = (Double)calculateNumberStat(floatTestStart, "mean");- assertEquals(getRawResponse(), floatResult,floatTest);-- //Double- Double doubleResult = (Double)getStatResult("mr", "double_dd", VAL_TYPE.DOUBLE);- Double doubleTest = (Double)calculateNumberStat(doubleTestStart, "mean");- assertEquals(getRawResponse(), doubleResult,doubleTest);+ public void uniqueTest() throws Exception {+ Map<String, ETP> expressions = new HashMap<>();+ expressions.put("int", new ETP("unique(int_i)", 6L));+ expressions.put("longs", new ETP("unique(long_lm)", 2L));+ expressions.put("float", new ETP("unique(float_f)", 5L));+ expressions.put("doubles", new ETP("unique(double_dm)", 8L));+ expressions.put("dates", new ETP("unique(date_dt)", 2L));+ expressions.put("strings", new ETP("unique(string_sm)", 6L));++ testExpressions(expressions);}@Test- public void stddevTest() throws Exception {- //Int- Double intResult = (Double)getStatResult("str", "int_id", VAL_TYPE.DOUBLE);- Double intTest = (Double)calculateNumberStat(intTestStart, "stddev");- assertEquals(getRawResponse(), intResult, intTest, 0.00000000001);-- //Long- Double longResult = (Double)getStatResult("str", "long_ld", VAL_TYPE.DOUBLE);- Double longTest = (Double)calculateNumberStat(longTestStart, "stddev");- assertEquals(getRawResponse(), longResult, longTest, 0.00000000001);-- //Float- Double floatResult = (Double)getStatResult("str", "float_fd", VAL_TYPE.DOUBLE);- Double floatTest = (Double)calculateNumberStat(floatTestStart, "stddev");- assertEquals(getRawResponse(), floatResult, floatTest, 0.00000000001);--- //Double- Double doubleResult = (Double)getStatResult("str", "double_dd", VAL_TYPE.DOUBLE);- Double doubleTest = (Double)calculateNumberStat(doubleTestStart, "stddev");- assertEquals(getRawResponse(), doubleResult, doubleTest, 0.00000000001);+ public void minTest() throws Exception {+ Map<String, ETP> expressions = new HashMap<>();+ expressions.put("int", new ETP("min(int_i)", 1));+ expressions.put("longs", new ETP("min(long_lm)", 1L));+ expressions.put("float", new ETP("min(float_f)", 1.0F));+ expressions.put("doubles", new ETP("min(double_dm)", 1.0));+ expressions.put("dates", new ETP("min(date_dt)", "1801-12-31T23:59:59Z"));+ expressions.put("strings", new ETP("min(string_sm)", "str1"));++ testExpressions(expressions);}@Test- public void medianTest() throws Exception {- //Int- Double intResult = (Double)getStatResult("medr", "int_id", VAL_TYPE.DOUBLE);- Double intTest = (Double)calculateNumberStat(intTestStart, "median");- assertEquals(getRawResponse(), intResult,intTest);-- //Long- Double longResult = (Double)getStatResult("medr", "long_ld", VAL_TYPE.DOUBLE);- Double longTest = (Double)calculateNumberStat(longTestStart, "median");- assertEquals(getRawResponse(), longResult,longTest);+ public void maxTest() throws Exception {+ Map<String, ETP> expressions = new HashMap<>();+ expressions.put("int", new ETP("max(int_i)", 6));+ expressions.put("longs", new ETP("max(long_lm)", 11L));+ expressions.put("float", new ETP("max(float_f)", 5.0F));+ expressions.put("doubles", new ETP("max(double_dm)", 14.0));+ expressions.put("dates", new ETP("max(date_dt)", "1802-12-31T23:59:59Z"));+ expressions.put("strings", new ETP("max(string_sm)", "str3_second"));++ testExpressions(expressions);+ }++ @Test+ public void sumTest() throws Exception {+ Map<String, ETP> expressions = new HashMap<>();+ expressions.put("single", new ETP("sum(int_i)", 57.0));+ expressions.put("multi", new ETP("sum(long_lm)", 120.0));- //Float- Double floatResult = (Double)getStatResult("medr", "float_fd", VAL_TYPE.DOUBLE);- Double floatTest = (Double)calculateNumberStat(floatTestStart, "median");- assertEquals(getRawResponse(), floatResult,floatTest);+ testExpressions(expressions);+ }++ @Test+ public void meanTest() throws Exception {+ Map<String, ETP> expressions = new HashMap<>();+ expressions.put("single", new ETP("mean(int_i)", 3.3529411764));+ expressions.put("multi", new ETP("mean(long_lm)", 6.0));- //Double- Double doubleResult = (Double)getStatResult("medr", "double_dd", VAL_TYPE.DOUBLE);- Double doubleTest = (Double)calculateNumberStat(doubleTestStart, "median");- assertEquals(getRawResponse(), doubleResult,doubleTest);+ testExpressions(expressions);}@Test- public void perc20Test() throws Exception {- //Int 20- Integer intResult = (Integer)getStatResult("p2r", "int_id", VAL_TYPE.INTEGER);- Integer intTest = (Integer)calculateStat(intTestStart, "perc_20");- assertEquals(getRawResponse(), intResult,intTest);-- //Long 20- Long longResult = (Long)getStatResult("p2r", "long_ld", VAL_TYPE.LONG);- Long longTest = (Long)calculateStat(longTestStart, "perc_20");- assertEquals(getRawResponse(), longResult,longTest);-- //Float 20- Float floatResult = (Float)getStatResult("p2r", "float_fd", VAL_TYPE.FLOAT);- Float floatTest = (Float)calculateStat(floatTestStart, "perc_20");- //assertEquals(getRawResponse(), floatResult,floatTest);-- //Double 20- Double doubleResult = (Double)getStatResult("p2r", "double_dd", VAL_TYPE.DOUBLE);- Double doubleTest = (Double)calculateStat(doubleTestStart, "perc_20");- assertEquals(getRawResponse(), doubleResult,doubleTest);-- //Date 20- String dateResult = (String)getStatResult("p2r", "date_dtd", VAL_TYPE.DATE);- String dateTest = (String)calculateStat(dateTestStart, "perc_20");- assertEquals(getRawResponse(), dateResult,dateTest);-- //String 20- String stringResult = (String)getStatResult("p2r", "string_sd", VAL_TYPE.STRING);- String stringTest = (String)calculateStat(stringTestStart, "perc_20");- assertEquals(getRawResponse(), stringResult,stringTest);+ public void weightedMeanTest() throws Exception {+ Map<String, ETP> expressions = new HashMap<>();+ expressions.put("single", new ETP("wmean(int_i, long_l)", 3.33333333333));+ expressions.put("multi", new ETP("wmean(double_d, float_f)", 2.470588235));++ testExpressions(expressions);}@Test- public void perc60Test() throws Exception {- //Int 60- Integer intResult = (Integer)getStatResult("p6r", "int_id", VAL_TYPE.INTEGER);- Integer intTest = (Integer)calculateStat(intTestStart, "perc_60");- assertEquals(getRawResponse(), intResult,intTest);-- //Long 60- Long longResult = (Long)getStatResult("p6r", "long_ld", VAL_TYPE.LONG);- Long longTest = (Long)calculateStat(longTestStart, "perc_60");- assertEquals(getRawResponse(), longResult,longTest);-- //Float 60- Float floatResult = (Float)getStatResult("p6r", "float_fd", VAL_TYPE.FLOAT);- Float floatTest = (Float)calculateStat(floatTestStart, "perc_60");- assertEquals(getRawResponse(), floatResult,floatTest);-- //Double 60- Double doubleResult = (Double)getStatResult("p6r", "double_dd", VAL_TYPE.DOUBLE);- Double doubleTest = (Double)calculateStat(doubleTestStart, "perc_60");- assertEquals(getRawResponse(), doubleResult,doubleTest);-- //Date 60- String dateResult = (String)getStatResult("p6r", "date_dtd", VAL_TYPE.DATE);- String dateTest = (String)calculateStat(dateTestStart, "perc_60");- assertEquals(getRawResponse(), dateResult,dateTest);-- //String 60- String stringResult = (String)getStatResult("p6r", "string_sd", VAL_TYPE.STRING);- String stringTest = (String)calculateStat(stringTestStart, "perc_60");- assertEquals(getRawResponse(), stringResult,stringTest);+ public void sumOfSquaresTest() throws Exception {+ Map<String, ETP> expressions = new HashMap<>();+ expressions.put("single", new ETP("sumofsquares(int_i)", 237.0));+ expressions.put("multi", new ETP("sumofsquares(long_lm)", 1220.0));++ testExpressions(expressions);}@Test- public void minTest() throws Exception {- //Int- Integer intResult = ((Integer)getStatResult("mir", "int_id", VAL_TYPE.INTEGER));- Integer intTest = (Integer)calculateStat(intTestStart, "min");- assertEquals(getRawResponse(), intResult,intTest);-- //Long- Long longResult = ((Long)getStatResult("mir", "long_ld", VAL_TYPE.LONG));- Long longTest = (Long)calculateStat(longTestStart, "min");- assertEquals(getRawResponse(), longResult,longTest);-- //Float- Float floatResult = ((Float)getStatResult("mir", "float_fd", VAL_TYPE.FLOAT));- Float floatTest = (Float)calculateStat(floatTestStart, "min");- assertEquals(getRawResponse(), floatResult,floatTest);-- //Double- Double doubleResult = (Double)getStatResult("mir", "double_dd", VAL_TYPE.DOUBLE);- Double doubleTest = (Double)calculateStat(doubleTestStart, "min");- assertEquals(getRawResponse(), doubleResult,doubleTest);-- //Date- String dateResult = (String)getStatResult("mir", "date_dtd", VAL_TYPE.DATE);- String dateTest = (String)calculateStat(dateTestStart, "min");- assertEquals(getRawResponse(), dateResult,dateTest);-- //String- String stringResult = (String)getStatResult("mir", "string_sd", VAL_TYPE.STRING);- String stringTest = (String)calculateStat(stringTestStart, "min");- assertEquals(getRawResponse(), stringResult,stringTest);+ public void varianceTest() throws Exception {+ Map<String, ETP> expressions = new HashMap<>();+ expressions.put("single", new ETP("variance(int_i)", 2.6989619377162));+ expressions.put("multi", new ETP("variance(long_lm)", 25.0));++ testExpressions(expressions);}@Test- public void maxTest() throws Exception {- //Int- Integer intResult = ((Integer)getStatResult("mar", "int_id", VAL_TYPE.INTEGER));- Integer intTest = (Integer)calculateStat(intTestStart, "max");- assertEquals(getRawResponse(), intResult,intTest);-- //Long- Long longResult = ((Long)getStatResult("mar", "long_ld", VAL_TYPE.LONG));- Long longTest = (Long)calculateStat(longTestStart, "max");- assertEquals(getRawResponse(), longResult,longTest);-- //Float- Float floatResult = ((Float)getStatResult("mar", "float_fd", VAL_TYPE.FLOAT));- Float floatTest = (Float)calculateStat(floatTestStart, "max");- assertEquals(getRawResponse(), floatResult,floatTest);-- //Double- Double doubleResult = (Double)getStatResult("mar", "double_dd", VAL_TYPE.DOUBLE);- Double doubleTest = (Double)calculateStat(doubleTestStart, "max");- assertEquals(getRawResponse(), doubleResult,doubleTest);-- //Date- String dateResult = (String)getStatResult("mar", "date_dtd", VAL_TYPE.DATE);- String dateTest = (String)calculateStat(dateTestStart, "max");- assertEquals(getRawResponse(), dateResult,dateTest);-- //String- String stringResult = (String)getStatResult("mar", "string_sd", VAL_TYPE.STRING);- String stringTest = (String)calculateStat(stringTestStart, "max");- assertEquals(getRawResponse(), stringResult,stringTest);+ public void standardDeviationTest() throws Exception {+ Map<String, ETP> expressions = new HashMap<>();+ expressions.put("single", new ETP("stddev(int_i)", 1.6428517698551));+ expressions.put("multi", new ETP("stddev(long_lm)", 5.0));++ testExpressions(expressions);}@Test- public void uniqueTest() throws Exception {- //Int- Long intResult = (Long)getStatResult("ur", "int_id", VAL_TYPE.LONG);- Long intTest = (Long)calculateStat(intTestStart, "unique");- assertEquals(getRawResponse(), intResult,intTest);-- //Long- Long longResult = (Long)getStatResult("ur", "long_ld", VAL_TYPE.LONG);- Long longTest = (Long)calculateStat(longTestStart, "unique");- assertEquals(getRawResponse(), longResult,longTest);-- //Float- Long floatResult = (Long)getStatResult("ur", "float_fd", VAL_TYPE.LONG);- Long floatTest = (Long)calculateStat(floatTestStart, "unique");- assertEquals(getRawResponse(), floatResult,floatTest);-- //Double- Long doubleResult = (Long)getStatResult("ur", "double_dd", VAL_TYPE.LONG);- Long doubleTest = (Long)calculateStat(doubleTestStart, "unique");- assertEquals(getRawResponse(), doubleResult,doubleTest);-- //Date- Long dateResult = (Long)getStatResult("ur", "date_dtd", VAL_TYPE.LONG);- Long dateTest = (Long)calculateStat(dateTestStart, "unique");- assertEquals(getRawResponse(), dateResult,dateTest);-- //String- Long stringResult = (Long)getStatResult("ur", "string_sd", VAL_TYPE.LONG);- Long stringTest = (Long)calculateStat(stringTestStart, "unique");- assertEquals(getRawResponse(), stringResult,stringTest);+ public void medianTest() throws Exception {+ Map<String, ETP> expressions = new HashMap<>();+ expressions.put("int", new ETP("median(int_i)", 3.0));+ expressions.put("longs", new ETP("median(long_lm)", 6.0));+ expressions.put("float", new ETP("median(float_f)", 3.0));+ expressions.put("doubles", new ETP("median(double_dm)", 7.5));+ expressions.put("dates", new ETP("median(date_dt)", "1801-12-31T23:59:59Z"));++ testExpressions(expressions);}@Test- public void countTest() throws Exception {- //Int- Long intResult = (Long)getStatResult("cr", "int_id", VAL_TYPE.LONG);- Long intTest = (Long)calculateStat(intTestStart, "count");- assertEquals(getRawResponse(), intResult,intTest);-- //Long- Long longResult = (Long)getStatResult("cr", "long_ld", VAL_TYPE.LONG);- Long longTest = (Long)calculateStat(longTestStart, "count");- assertEquals(getRawResponse(), longResult,longTest);-- //Float- Long floatResult = (Long)getStatResult("cr", "float_fd", VAL_TYPE.LONG);- Long floatTest = (Long)calculateStat(floatTestStart, "count");- assertEquals(getRawResponse(), floatResult,floatTest);-- //Double- Long doubleResult = (Long)getStatResult("cr", "double_dd", VAL_TYPE.LONG);- Long doubleTest = (Long)calculateStat(doubleTestStart, "count");- assertEquals(getRawResponse(), doubleResult,doubleTest);-- //Date- Long dateResult = (Long)getStatResult("cr", "date_dtd", VAL_TYPE.LONG);- Long dateTest = (Long)calculateStat(dateTestStart, "count");- assertEquals(getRawResponse(), dateResult,dateTest);-- //String- Long stringResult = (Long)getStatResult("cr", "string_sd", VAL_TYPE.LONG);- Long stringTest = (Long)calculateStat(stringTestStart, "count");- assertEquals(getRawResponse(), stringResult,stringTest);- }-+ public void percentileTest() throws Exception {+ Map<String, ETP> expressions = new HashMap<>();+ expressions.put("int", new ETP("percentile(20,int_i)", 2));+ expressions.put("longs", new ETP("percentile(80,long_lm)", 11L));+ expressions.put("float", new ETP("percentile(40,float_f)", 2.0F));+ expressions.put("doubles", new ETP("percentile(50,double_dm)", 11.0));+ expressions.put("dates", new ETP("percentile(0,date_dt)", "1801-12-31T23:59:59Z"));+ expressions.put("strings", new ETP("percentile(99.99,string_sm)", "str3_second"));++ testExpressions(expressions);+ }+@Test- public void missingDefaultTest() throws Exception {- //Int- long intResult = (Long)getStatResult("misr", "int_id", VAL_TYPE.LONG);- assertEquals(getRawResponse(), intMissing,intResult);-- //Long- long longResult = (Long)getStatResult("misr", "long_ld", VAL_TYPE.LONG);- assertEquals(getRawResponse(), longMissing,longResult);-- //Float- long floatResult = (Long)getStatResult("misr", "float_fd", VAL_TYPE.LONG);- assertEquals(getRawResponse(), floatMissing,floatResult);-- //Double- long doubleResult = (Long)getStatResult("misr", "double_dd", VAL_TYPE.LONG);- assertEquals(getRawResponse(), doubleMissing,doubleResult);-- //Date- long dateResult = (Long)getStatResult("misr", "date_dtd", VAL_TYPE.LONG);- assertEquals(getRawResponse(), dateMissing,dateResult);-- //String- long stringResult = (Long)getStatResult("misr", "string_sd", VAL_TYPE.LONG);- assertEquals(getRawResponse(), stringMissing, stringResult);+ public void ordinalTest() throws Exception {+ Map<String, ETP> expressions = new HashMap<>();+ expressions.put("int", new ETP("ordinal(15,int_i)", 5));+ expressions.put("longs", new ETP("ordinal(11,long_lm)", 11L));+ expressions.put("float", new ETP("ordinal(-5,float_f)", 4.0F));+ expressions.put("doubles", new ETP("ordinal(1,double_dm)", 1.0));+ expressions.put("dates", new ETP("ordinal(-1,date_dt)", "1802-12-31T23:59:59Z"));+ expressions.put("strings", new ETP("ordinal(6,string_sm)", "str1_second"));++ testExpressions(expressions);}-}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/OverallAnalyticsTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/OverallAnalyticsTest.javanew file mode 100644index 00000000000..de6d6d26f2c--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/OverallAnalyticsTest.java@@ -0,0 +1,320 @@+/*+ * 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.analytics;++import java.util.ArrayList;+import java.util.List;++import org.apache.solr.analytics.facet.SolrAnalyticsFacetTestCase;+import org.junit.BeforeClass;+import org.junit.Test;++public class OverallAnalyticsTest extends SolrAnalyticsFacetTestCase {++ @BeforeClass+ public static void populate() throws Exception {+ for (int j = 0; j < NUM_LOOPS; ++j) {+ int i = j%INT;+ long l = j%LONG;+ float f = j%FLOAT;+ double d = j%DOUBLE;+ String dt = (1800+j%DATE) + "-12-31T23:59:59Z";+ String dtm = (1800+j%DATE + 10) + "-12-31T23:59:59Z";+ String s = "str" + (j%STRING);+ List<String> fields = new ArrayList<>();+ fields.add("id"); fields.add("1000"+j);++ if ( i != 0 ) {+ fields.add("int_i"); fields.add("" + i);+ fields.add("int_im"); fields.add("" + i);+ fields.add("int_im"); fields.add("" + (i+10));+ }++ if ( l != 0l ) {+ fields.add("long_l"); fields.add("" + l);+ fields.add("long_lm"); fields.add("" + l);+ fields.add("long_lm"); fields.add("" + (l+10));+ }++ if ( f != 0.0f ) {+ fields.add("float_f"); fields.add("" + f);+ fields.add("float_fm"); fields.add("" + f);+ fields.add("float_fm"); fields.add("" + (f+10));+ }++ if ( d != 0.0d ) {+ fields.add("double_d"); fields.add("" + d);+ fields.add("double_dm"); fields.add("" + d);+ fields.add("double_dm"); fields.add("" + (d+10));+ }++ if ( (j%DATE) != 0 ) {+ fields.add("date_dt"); fields.add(dt);+ fields.add("date_dtm"); fields.add(dt);+ fields.add("date_dtm"); fields.add(dtm);+ }++ if ( (j%STRING) != 0 ) {+ fields.add("string_s"); fields.add(s);+ fields.add("string_sm"); fields.add(s);+ fields.add("string_sm"); fields.add(s + "_second");+ }++ addDoc(fields);+ }+ commitDocs();+ }++ static public final int INT = 7;+ static public final int LONG = 2;+ static public final int FLOAT = 6;+ static public final int DOUBLE = 5;+ static public final int DATE = 3;+ static public final int STRING = 4;+ static public final int NUM_LOOPS = 20;++ @Test+ public void pivotFacetTest() throws Exception {+ String analyticsRequest = "{"+ + "\n 'expressions' : { "+ + "\n 'floor_mean_add' : 'floor(mean(add(int_i,long_lm)))', "+ + "\n 'consts' : 'max(mod(\\'_\\', string_s, 1800-01-01T11:59:59Z))' "+ + "\n }, "+ + "\n 'functions' : { "+ + "\n 'mod(a,b..)' : 'concat_sep(a, b:concat(_,\\'-con\\'))', "+ + "\n 'rep_0(num)' : 'fill_missing(num,0)' "+ + "\n }, "+ + "\n 'groupings': { "+ + "\n 'grouping0' : { "+ + "\n 'expressions' : { "+ + "\n 'mean' : 'mean(float_f)', "+ + "\n 'count2' : 'count(string_sm)' "+ + "\n }, "+ + "\n 'facets' : { "+ + "\n 'ranges' : { "+ + "\n 'type' : 'range', "+ + "\n 'field': 'int_im', "+ + "\n 'start': '2', "+ + "\n 'end' : '13', "+ + "\n 'gaps' : ['2', '5', '3'], "+ + "\n 'hardend' : false "+ + "\n } "+ + "\n } "+ + "\n }, "+ + "\n 'grouping1' : { "+ + "\n 'expressions' : { "+ + "\n 'mean' : 'mean(rep_0(int_i))', "+ + "\n 'count' : 'count(long_lm)' "+ + "\n }, "+ + "\n 'facets' : { "+ + "\n 'queries' : { "+ + "\n 'type' : 'query', "+ + "\n 'queries' : { "+ + "\n 'float < 3' : 'float_f:[* TO 3]', "+ + "\n 'string = 1, date = 2' : 'string_s:\"str1\" AND date_dt:\"1802-12-31T23:59:59Z\"' "+ + "\n } "+ + "\n }, "+ + "\n 'pivoting' : { "+ + "\n 'type' : 'pivot', "+ + "\n 'pivots' : [ "+ + "\n { "+ + "\n 'name' : 'strings', "+ + "\n 'expression' : 'string_sm', "+ + "\n 'sort' : { "+ + "\n 'criteria' : [ "+ + "\n { "+ + "\n 'type' : 'expression', "+ + "\n 'expression' : 'mean', "+ + "\n 'direction' : 'ascending' "+ + "\n }, "+ + "\n { "+ + "\n 'type' : 'facetvalue', "+ + "\n 'direction' : 'descending' "+ + "\n } "+ + "\n ], "+ + "\n 'limit' : 3, "+ + "\n 'offset' : 1 "+ + "\n } "+ + "\n }, "+ + "\n { "+ + "\n 'name' : 'date', "+ + "\n 'expression' : 'fill_missing(date_dt, \\'No Date\\')', "+ + "\n 'sort' : { "+ + "\n 'criteria' : [ "+ + "\n { "+ + "\n 'type' : 'expression', "+ + "\n 'expression' : 'count', "+ + "\n 'direction' : 'ascending' "+ + "\n }, "+ + "\n { "+ + "\n 'type' : 'expression', "+ + "\n 'expression' : 'mean', "+ + "\n 'direction' : 'ascending' "+ + "\n } "+ + "\n ], "+ + "\n 'limit' : 2 "+ + "\n } "+ + "\n } "+ + "\n ] "+ + "\n } "+ + "\n } "+ + "\n } "+ + "\n } "+ + "\n} ";++ String test = "== {"+ + "\n 'results' : { "+ + "\n 'floor_mean_add' : 9, "+ + "\n 'consts' : 'str3-con_1800-01-01T11:59:59Z-con' "+ + "\n }, "+ + "\n 'groupings' : { "+ + "\n 'grouping0' : { "+ + "\n 'ranges' : [ "+ + "\n { "+ + "\n 'value' : '[2 TO 4)', "+ + "\n 'results' : { "+ + "\n 'mean' : 3.5, "+ + "\n 'count2' : 10 "+ + "\n } "+ + "\n }, "+ + "\n { "+ + "\n 'value' : '[4 TO 9)', "+ + "\n 'results' : { "+ + "\n 'mean' : 3.2, "+ + "\n 'count2' : 12 "+ + "\n } "+ + "\n }, "+ + "\n { "+ + "\n 'value' : '[9 TO 12)', "+ + "\n 'results' : { "+ + "\n 'mean' : 2.0, "+ + "\n 'count2' : 4 "+ + "\n } "+ + "\n }, "+ + "\n { "+ + "\n 'value' : '[12 TO 15)', "+ + "\n 'results' : { "+ + "\n 'mean' : 3.75, "+ + "\n 'count2' : 14 "+ + "\n } "+ + "\n } "+ + "\n ] "+ + "\n }, "+ + "\n 'grouping1': { "+ + "\n 'queries' : [ "+ + "\n { "+ + "\n 'value' : 'float < 3', "+ + "\n 'results' : { "+ + "\n 'mean' : 2.1, "+ + "\n 'count' : 14 "+ + "\n } "+ + "\n }, "+ + "\n { "+ + "\n 'value' : 'string = 1, date = 2', "+ + "\n 'results' : { "+ + "\n 'mean' : 4.0, "+ + "\n 'count' : 4 "+ + "\n } "+ + "\n } "+ + "\n ], "+ + "\n 'pivoting':["+ + "\n { "+ + "\n 'pivot' : 'strings', "+ + "\n 'value' : 'str3', "+ + "\n 'results' : { "+ + "\n 'mean' : 2.6, "+ + "\n 'count' : 10 "+ + "\n }, "+ + "\n 'children' : [ "+ + "\n { "+ + "\n 'pivot' : 'date', "+ + "\n 'value' : '1802-12-31T23:59:59Z', "+ + "\n 'results' : { "+ + "\n 'mean' : 4.0, "+ + "\n 'count' : 2 "+ + "\n } "+ + "\n }, "+ + "\n { "+ + "\n 'pivot' : 'date', "+ + "\n 'value' : 'No Date', "+ + "\n 'results' : { "+ + "\n 'mean' : 2.0, "+ + "\n 'count' : 4 "+ + "\n } "+ + "\n } "+ + "\n ]"+ + "\n }, "+ + "\n { "+ + "\n 'pivot' : 'strings', "+ + "\n 'value' : 'str2_second', "+ + "\n 'results' : { "+ + "\n 'mean' : 3.0, "+ + "\n 'count' : 0 "+ + "\n }, "+ + "\n 'children' : [ "+ + "\n { "+ + "\n 'pivot' : 'date', "+ + "\n 'value' : '1802-12-31T23:59:59Z', "+ + "\n 'results' : { "+ + "\n 'mean' : 1.0, "+ + "\n 'count' : 0 "+ + "\n } "+ + "\n }, "+ + "\n { "+ + "\n 'pivot' : 'date', "+ + "\n 'value' : '1801-12-31T23:59:59Z', "+ + "\n 'results' : { "+ + "\n 'mean' : 3.0, "+ + "\n 'count' : 0 "+ + "\n } "+ + "\n } "+ + "\n ]"+ + "\n }, "+ + "\n { "+ + "\n 'pivot' : 'strings', "+ + "\n 'value' : 'str2', "+ + "\n 'results' : { "+ + "\n 'mean' : 3.0, "+ + "\n 'count' : 0 "+ + "\n }, "+ + "\n 'children' : [ "+ + "\n { "+ + "\n 'pivot' : 'date', "+ + "\n 'value' : '1802-12-31T23:59:59Z', "+ + "\n 'results' : { "+ + "\n 'mean' : 1.0, "+ + "\n 'count' : 0 "+ + "\n } "+ + "\n }, "+ + "\n { "+ + "\n 'pivot' : 'date', "+ + "\n 'value' : '1801-12-31T23:59:59Z', "+ + "\n 'results' : { "+ + "\n 'mean' : 3.0, "+ + "\n 'count' : 0 "+ + "\n } "+ + "\n } "+ + "\n ]"+ + "\n } "+ + "\n ]"+ + "\n }"+ + "\n }"+ + "\n}";++ testAnalytics(analyticsRequest, test);+ }+}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/SolrAnalyticsTestCase.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/SolrAnalyticsTestCase.javanew file mode 100644index 00000000000..993c1d3b036--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/SolrAnalyticsTestCase.java@@ -0,0 +1,349 @@+/*+ * 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.analytics;++import java.io.IOException;+import java.time.Instant;+import java.util.ArrayList;+import java.util.Arrays;+import java.util.Comparator;+import java.util.Date;+import java.util.List;+import java.util.Map;+import java.util.stream.Collectors;++import org.apache.solr.JSONTestUtil;+import org.apache.solr.client.solrj.SolrServerException;+import org.apache.solr.client.solrj.request.CollectionAdminRequest;+import org.apache.solr.client.solrj.request.QueryRequest;+import org.apache.solr.client.solrj.request.UpdateRequest;+import org.apache.solr.client.solrj.response.QueryResponse;+import org.apache.solr.cloud.AbstractDistribZkTestBase;+import org.apache.solr.cloud.SolrCloudTestCase;+import org.apache.solr.common.params.ModifiableSolrParams;+import org.apache.solr.common.params.SolrParams;+import org.apache.solr.common.util.Utils;+import org.junit.BeforeClass;++public class SolrAnalyticsTestCase extends SolrCloudTestCase {+ private static final double DEFAULT_DELTA = .0000001;++ protected static final String COLLECTIONORALIAS = "collection1";+ protected static final int TIMEOUT = DEFAULT_TIMEOUT;+ protected static final String id = "id";++ private static UpdateRequest cloudReq;++ @BeforeClass+ public static void setupCollection() throws Exception {+ // Single-sharded core+ initCore("solrconfig-analytics.xml", "schema-analytics.xml");+ h.update("<delete><query>*:*</query></delete>");++ // Solr Cloud+ configureCluster(4)+ .addConfig("conf", configset("cloud-analytics"))+ .configure();++ CollectionAdminRequest.createCollection(COLLECTIONORALIAS, "conf", 2, 1).process(cluster.getSolrClient());+ AbstractDistribZkTestBase.waitForRecoveriesToFinish(COLLECTIONORALIAS, cluster.getSolrClient().getZkStateReader(),+ false, true, TIMEOUT);++ new UpdateRequest()+ .deleteByQuery("*:*")+ .commit(cluster.getSolrClient(), COLLECTIONORALIAS);++ cloudReq = new UpdateRequest();+ }++ protected static void cleanIndex() throws Exception {+ h.update("<delete><query>*:*</query></delete>");++ new UpdateRequest()+ .deleteByQuery("*:*")+ .commit(cluster.getSolrClient(), COLLECTIONORALIAS);+ }++ protected static void addDoc(List<String> fieldsAndValues) {+ assertU(adoc(fieldsAndValues.toArray(new String[0])));+ cloudReq.add(fieldsAndValues.toArray(new String[0]));+ }++ protected static void commitDocs() {+ assertU(commit());+ try {+ cloudReq.commit(cluster.getSolrClient(), COLLECTIONORALIAS);+ } catch (Exception e) {+ throw new RuntimeException(e);+ }+ cloudReq = new UpdateRequest();+ }++ private void testResults(SolrParams params, String analyticsRequest, String... tests) {+ String coreJson = queryCoreJson(params);+ Object cloudObj = queryCloudObject(params);++ for (String test : tests) {+ if (test == null || test.length()==0) continue;+ // Single-Sharded+ String err = null;+ try {+ err = JSONTestUtil.match(coreJson, test, DEFAULT_DELTA);+ } catch (Exception e) {+ err = e.getMessage();+ } finally {+ assertNull("query failed JSON validation. test= Single-Sharded Collection" ++ "\n error=" + err ++ "\n expected =" + test ++ "\n response = " + coreJson ++ "\n analyticsRequest = " + analyticsRequest, err);+ }++ // Cloud+ err = null;+ try {+ err = JSONTestUtil.matchObj(cloudObj, test, DEFAULT_DELTA);+ } catch (Exception e) {+ err = e.getMessage();+ } finally {+ assertNull("query failed JSON validation. test= Solr Cloud Collection" ++ "\n error=" + err ++ "\n expected =" + test ++ "\n response = " + Utils.toJSONString(cloudObj) ++ "\n analyticsRequest = " + analyticsRequest, err);+ }+ }+ }++ private String queryCoreJson(SolrParams params) {+ try {+ return JQ(req(params));+ } catch (Exception e) {+ throw new RuntimeException(e);+ }+ }++ private Object queryCloudObject(SolrParams params) {+ QueryResponse resp;+ try {+ cluster.waitForAllNodes(10000);+ QueryRequest qreq = new QueryRequest(params);+ resp = qreq.process(cluster.getSolrClient(), COLLECTIONORALIAS);+ } catch (Exception e) {+ throw new RuntimeException(e);+ }+ return convertDatesToStrings(resp.getResponse().asShallowMap());+ }++ protected void testAnalytics(String analyticsRequest, String... tests) throws IOException, InterruptedException, SolrServerException {+ ModifiableSolrParams params = new ModifiableSolrParams();+ params.set("q", "*:*");+ params.set("indent", "true");+ params.set("rows", "0");+ params.set("wt", "json");++ params.set("analytics", analyticsRequest);++ String[] revisedTests = Arrays.stream(tests).map( test -> "analytics_response/" + test).toArray( size -> new String[size]);+ testResults(params, analyticsRequest, revisedTests);+ }++ protected void testExpressions(Map<String, ETP> expressions) throws Exception {+ StringBuilder analyticsRequest = new StringBuilder("{ \"expressions\": {");+ String expressionsStr = expressions.entrySet()+ .stream()+ .map( entry -> '"' + entry.getKey() + "\":\"" + entry.getValue().expression + '"')+ .reduce((a,b) -> a + ',' + b)+ .orElseGet(() -> "");+ analyticsRequest.append(expressionsStr);+ analyticsRequest.append("}}");++ String results = expressions.entrySet()+ .stream()+ .map( entry -> '"' + entry.getKey() + "\":" + entry.getValue().expectedResultStr())+ .reduce((a,b) -> a + ',' + b)+ .orElseGet(() -> "");++ testAnalytics(analyticsRequest.toString(), "results=={"+results+", \"_UNORDERED_\":true}");+ }++ protected void testGrouping(String grouping,+ Map<String, String> expressions,+ Map<String, String> facets,+ Map<String, List<FVP>> results,+ boolean sortAscending) throws Exception {+ testGroupingSorted(grouping,+ expressions,+ facets,+ results,+ ", 'sort': { 'criteria' : [{'type': 'facetvalue', 'direction': '" + (sortAscending ? "ascending" : "descending") + "'}]}",+ (fvp1, fvp2) -> fvp1.facetValue.compareTo(fvp2.facetValue),+ sortAscending);+ }++ @SuppressWarnings("unchecked")+ protected void testGrouping(String grouping,+ Map<String, String> expressions,+ Map<String, String> facets,+ Map<String, List<FVP>> results,+ String sortExpression,+ boolean sortAscending) throws Exception {+ testGroupingSorted(grouping,+ expressions,+ facets,+ results,+ ", 'sort': { 'criteria' : [{'type': 'expression', 'expression': '" + sortExpression + "', 'direction': '" + (sortAscending ? "ascending" : "descending") + "'}]}",+ (fvp1, fvp2) -> fvp1.expectedResults.get(sortExpression).compareTo(fvp2.expectedResults.get(sortExpression)),+ sortAscending);+ }++ protected void testGrouping(String grouping,+ Map<String, String> expressions,+ Map<String, String> facets,+ Map<String, List<FVP>> results) throws Exception {+ testGroupingSorted(grouping,+ expressions,+ facets,+ results,+ "",+ (fvp1, fvp2) -> fvp1.compareTo(fvp2),+ true);+ }++ private void testGroupingSorted(String grouping,+ Map<String, String> expressions,+ Map<String, String> facets,+ Map<String, List<FVP>> results,+ String sort,+ Comparator<FVP> comparator,+ boolean sortAscending) throws Exception {+ StringBuilder analyticsRequest = new StringBuilder("{ \"groupings\": { \"" + grouping + "\" : { \"expressions\" : {");+ String expressionsStr = expressions.entrySet()+ .stream()+ .map( entry -> '"' + entry.getKey() + "\":\"" + entry.getValue() + '"')+ .collect(Collectors.joining(" , "));+ analyticsRequest.append(expressionsStr);+ analyticsRequest.append("}, \"facets\": {");+ String facetsStr = facets.entrySet()+ .stream()+ .map( entry -> '"' + entry.getKey() + "\":" + entry.getValue().replaceFirst("}\\s*$", sort) + "}")+ .collect(Collectors.joining(" , "));+ analyticsRequest.append(facetsStr);+ analyticsRequest.append("}}}}");++ String groupingResults = results.entrySet()+ .stream()+ .map( facet -> {+ String resultList = facet.getValue()+ .stream()+ .sorted(sortAscending ? comparator : comparator.reversed())+ .map( fvp -> fvp.toJsonResults() )+ .collect(Collectors.joining(" , "));+ return '"' + facet.getKey() + "\" : [ " + resultList + " ]";+ })+ .collect(Collectors.joining(" , "));++ testAnalytics(analyticsRequest.toString(), "groupings/" + grouping + "=={"+groupingResults+", \"_UNORDERED_\":true}");+ }++ private static String resultToJson(Object result) {+ if (result instanceof String) {+ return '"' + result.toString() + '"';+ }+ return result.toString();+ }++ /*+ * Expression Test Pair, contains the expression and the expected result+ */+ protected static class ETP {+ final String expression;+ final Object expectedResult;++ public ETP(String expression, Object expectedResult) {+ this.expression = expression;+ this.expectedResult = expectedResult;+ }++ public String expectedResultStr() {+ if (expectedResult instanceof String) {+ return '"' + expectedResult.toString() + '"';+ }+ return expectedResult.toString();+ }+ }++ /*+ * FacetValuePair, contains the expression and the expected result+ */+ @SuppressWarnings("rawtypes")+ protected static class FVP implements Comparable<FVP> {+ final private int order;+ final public String facetValue;+ final public Map<String, Comparable> expectedResults;++ public FVP(int order, String facetValue, Map<String, Comparable> expectedResults) {+ this.order = order;+ this.facetValue = facetValue;+ this.expectedResults = expectedResults;+ }++ public String toJsonResults() {+ String valueResults = expectedResults.entrySet()+ .stream()+ .map( result -> '"' + result.getKey() + "\":" + resultToJson(result.getValue()))+ .collect(Collectors.joining(" , "));+ return "{ \"value\" : \"" + facetValue + "\", \"results\": { " + valueResults + ", \"_UNORDERED_\":true } }";+ }++ @Override+ public int compareTo(FVP other) {+ return Integer.compare(order, other.order);+ }+ }++ /*+ * FacetValuePair, contains the expression and the expected result+ */+ @SuppressWarnings("rawtypes")+ protected static class PivotFVP extends FVP {+ final public String pivot;+ final public List<FVP> children;++ public PivotFVP(int order, String pivot, String facetValue, Map<String, Comparable> expectedResults) {+ super(order, facetValue, expectedResults);+ this.pivot = pivot;+ children = new ArrayList<>();+ }++ public void addChild(FVP child) {+ children.add(child);+ }+ }++ @SuppressWarnings("unchecked")+ protected static Object convertDatesToStrings(Object value) {+ if (value instanceof Date) {+ return Instant.ofEpochMilli(((Date)value).getTime()).toString();+ } else if (value instanceof Map) {+ ((Map<String,Object>)value).replaceAll( (key, obj) -> convertDatesToStrings(obj));+ } else if (value instanceof List) {+ ((List<Object>)value).replaceAll( obj -> convertDatesToStrings(obj));+ }+ return value;+ }+}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/PivotFacetTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/PivotFacetTest.javanew file mode 100644index 00000000000..be0e853254b--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/PivotFacetTest.java@@ -0,0 +1,230 @@+/*+ * 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.analytics.facet;++import java.util.ArrayList;+import java.util.List;++import org.junit.BeforeClass;+import org.junit.Test;++public class PivotFacetTest extends SolrAnalyticsFacetTestCase {++ @BeforeClass+ public static void populate() throws Exception {+ for (int j = 0; j < NUM_LOOPS; ++j) {+ int i = j%INT;+ long l = j%LONG;+ float f = j%FLOAT;+ double d = j%DOUBLE;+ String dt = (1800+j%DATE) + "-12-31T23:59:59Z";+ String dtm = (1800+j%DATE + 10) + "-12-31T23:59:59Z";+ String s = "str" + (j%STRING);+ List<String> fields = new ArrayList<>();+ fields.add("id"); fields.add("1000"+j);++ if ( i != 0 ) {+ fields.add("int_i"); fields.add("" + i);+ fields.add("int_im"); fields.add("" + i);+ fields.add("int_im"); fields.add("" + (i+10));+ }++ if ( l != 0l ) {+ fields.add("long_l"); fields.add("" + l);+ fields.add("long_lm"); fields.add("" + l);+ fields.add("long_lm"); fields.add("" + (l+10));+ }++ if ( f != 0.0f ) {+ fields.add("float_f"); fields.add("" + f);+ fields.add("float_fm"); fields.add("" + f);+ fields.add("float_fm"); fields.add("" + (f+10));+ }++ if ( d != 0.0d ) {+ fields.add("double_d"); fields.add("" + d);+ fields.add("double_dm"); fields.add("" + d);+ fields.add("double_dm"); fields.add("" + (d+10));+ }++ if ( (j%DATE) != 0 ) {+ fields.add("date_dt"); fields.add(dt);+ fields.add("date_dtm"); fields.add(dt);+ fields.add("date_dtm"); fields.add(dtm);+ }++ if ( (j%STRING) != 0 ) {+ fields.add("string_s"); fields.add(s);+ fields.add("string_sm"); fields.add(s);+ fields.add("string_sm"); fields.add(s + "_second");+ }++ addDoc(fields);+ }+ commitDocs();+ }++ static public final int INT = 7;+ static public final int LONG = 2;+ static public final int FLOAT = 6;+ static public final int DOUBLE = 5;+ static public final int DATE = 3;+ static public final int STRING = 4;+ static public final int NUM_LOOPS = 20;++ @Test+ public void pivotFacetTest() throws Exception {+ String analyticsRequest = "{"+ + "\n 'groupings': { "+ + "\n 'grouping' : { "+ + "\n 'expressions' : { "+ + "\n 'mean' : 'mean(fill_missing(int_i,0))', "+ + "\n 'count' : 'count(long_lm)' "+ + "\n }, "+ + "\n 'facets' : { "+ + "\n 'pivoting' : { "+ + "\n 'type' : 'pivot', "+ + "\n 'pivots' : [ "+ + "\n { "+ + "\n 'name' : 'strings', "+ + "\n 'expression' : 'string_sm', "+ + "\n 'sort' : { "+ + "\n 'criteria' : [ "+ + "\n { "+ + "\n 'type' : 'expression', "+ + "\n 'expression' : 'mean', "+ + "\n 'direction' : 'ascending' "+ + "\n }, "+ + "\n { "+ + "\n 'type' : 'facetvalue', "+ + "\n 'direction' : 'descending' "+ + "\n } "+ + "\n ], "+ + "\n 'limit' : 3, "+ + "\n 'offset' : 1 "+ + "\n } "+ + "\n }, "+ + "\n { "+ + "\n 'name' : 'date', "+ + "\n 'expression' : 'fill_missing(date_dt, \\'No Date\\')', "+ + "\n 'sort' : { "+ + "\n 'criteria' : [ "+ + "\n { "+ + "\n 'type' : 'expression', "+ + "\n 'expression' : 'count', "+ + "\n 'direction' : 'ascending' "+ + "\n }, "+ + "\n { "+ + "\n 'type' : 'expression', "+ + "\n 'expression' : 'mean', "+ + "\n 'direction' : 'ascending' "+ + "\n } "+ + "\n ], "+ + "\n 'limit' : 2 "+ + "\n } "+ + "\n } "+ + "\n ] "+ + "\n } "+ + "\n } "+ + "\n } "+ + "\n } "+ + "\n} ";++ String test = "groupings=={'grouping':{'pivoting':["+ + "\n { "+ + "\n 'pivot' : 'strings', "+ + "\n 'value' : 'str3', "+ + "\n 'results' : { "+ + "\n 'mean' : 2.6, "+ + "\n 'count' : 10 "+ + "\n }, "+ + "\n 'children' : [ "+ + "\n { "+ + "\n 'pivot' : 'date', "+ + "\n 'value' : '1802-12-31T23:59:59Z', "+ + "\n 'results' : { "+ + "\n 'mean' : 4.0, "+ + "\n 'count' : 2 "+ + "\n } "+ + "\n }, "+ + "\n { "+ + "\n 'pivot' : 'date', "+ + "\n 'value' : 'No Date', "+ + "\n 'results' : { "+ + "\n 'mean' : 2.0, "+ + "\n 'count' : 4 "+ + "\n } "+ + "\n } "+ + "\n ]"+ + "\n }, "+ + "\n { "+ + "\n 'pivot' : 'strings', "+ + "\n 'value' : 'str2_second', "+ + "\n 'results' : { "+ + "\n 'mean' : 3.0, "+ + "\n 'count' : 0 "+ + "\n }, "+ + "\n 'children' : [ "+ + "\n { "+ + "\n 'pivot' : 'date', "+ + "\n 'value' : '1802-12-31T23:59:59Z', "+ + "\n 'results' : { "+ + "\n 'mean' : 1.0, "+ + "\n 'count' : 0 "+ + "\n } "+ + "\n }, "+ + "\n { "+ + "\n 'pivot' : 'date', "+ + "\n 'value' : '1801-12-31T23:59:59Z', "+ + "\n 'results' : { "+ + "\n 'mean' : 3.0, "+ + "\n 'count' : 0 "+ + "\n } "+ + "\n } "+ + "\n ]"+ + "\n }, "+ + "\n { "+ + "\n 'pivot' : 'strings', "+ + "\n 'value' : 'str2', "+ + "\n 'results' : { "+ + "\n 'mean' : 3.0, "+ + "\n 'count' : 0 "+ + "\n }, "+ + "\n 'children' : [ "+ + "\n { "+ + "\n 'pivot' : 'date', "+ + "\n 'value' : '1802-12-31T23:59:59Z', "+ + "\n 'results' : { "+ + "\n 'mean' : 1.0, "+ + "\n 'count' : 0 "+ + "\n } "+ + "\n }, "+ + "\n { "+ + "\n 'pivot' : 'date', "+ + "\n 'value' : '1801-12-31T23:59:59Z', "+ + "\n 'results' : { "+ + "\n 'mean' : 3.0, "+ + "\n 'count' : 0 "+ + "\n } "+ + "\n } "+ + "\n ]"+ + "\n } "+ + "\n]}}";++ testAnalytics(analyticsRequest, test);+ }+}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/QueryFacetTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/QueryFacetTest.javaindex e892dc9c6b4..63a62c8b4cc 100644--- a/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/QueryFacetTest.java+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/QueryFacetTest.java@@ -16,109 +16,95 @@*/package org.apache.solr.analytics.facet;-import java.util.ArrayList;+import java.util.HashMap;+import java.util.List;+import java.util.Map;import org.junit.BeforeClass;import org.junit.Test;-public class QueryFacetTest extends AbstractAnalyticsFacetTest {- static String fileName = "queryFacets.txt";-- public final int INT = 71;- public final int LONG = 36;- public final int FLOAT = 93;- public final int DOUBLE = 49;- public final int DATE = 12;- public final int STRING = 28;- public final int NUM_LOOPS = 100;-+public class QueryFacetTest extends SolrAnalyticsFacetTestCase {+@BeforeClass- public static void beforeClass() throws Exception {- initCore("solrconfig-analytics.xml","schema-analytics.xml");- }-- @SuppressWarnings("unchecked")- @Test- public void queryTest() throws Exception {- h.update("<delete><query>*:*</query></delete>");- //INT- ArrayList<ArrayList<Integer>> int1TestStart = new ArrayList<>();- int1TestStart.add(new ArrayList<Integer>());- ArrayList<ArrayList<Integer>> int2TestStart = new ArrayList<>();- int2TestStart.add(new ArrayList<Integer>());-- //LONG- ArrayList<ArrayList<Long>> longTestStart = new ArrayList<>();- longTestStart.add(new ArrayList<Long>());- longTestStart.add(new ArrayList<Long>());-- //FLOAT- ArrayList<ArrayList<Float>> floatTestStart = new ArrayList<>();- floatTestStart.add(new ArrayList<Float>());- floatTestStart.add(new ArrayList<Float>());- floatTestStart.add(new ArrayList<Float>());-+ public static void populate() throws Exception {for (int j = 0; j < NUM_LOOPS; ++j) {int i = j%INT;long l = j%LONG;float f = j%FLOAT;double d = j%DOUBLE;- int dt = j%DATE;- int s = j%STRING;- assertU(adoc("id", "1000" + j, "int_id", "" + i, "long_ld", "" + l, "float_fd", "" + f,- "double_dd", "" + d, "date_dtd", (1800+dt) + "-12-31T23:59:59.999Z", "string_sd", "abc" + new Integer(s).toString().charAt(0)));-- if (f<=50) {- int1TestStart.get(0).add(i);- }- if (f<=30) {- int2TestStart.get(0).add(i);- }- if (new Integer(s).toString().charAt(0)=='1') {- longTestStart.get(0).add(l);+ String dt = (1800+j%DATE) + "-12-31T23:59:59Z";+ String dtm = (1800+j%DATE + 10) + "-12-31T23:59:59Z";+ String s = "str" + (j%STRING);+ List<String> fields = new ArrayList<>();+ fields.add("id"); fields.add("1000"+j);++ if ( i != 0 ) {+ fields.add("int_i"); fields.add("" + i);+ fields.add("int_im"); fields.add("" + i);+ fields.add("int_im"); fields.add("" + (i+10));}- if (new Integer(s).toString().charAt(0)=='2') {- longTestStart.get(1).add(l);++ if ( l != 0l ) {+ fields.add("long_l"); fields.add("" + l);+ fields.add("long_lm"); fields.add("" + l);+ fields.add("long_lm"); fields.add("" + (l+10));}- if (l>=30) {- floatTestStart.get(0).add(f);++ if ( f != 0.0f ) {+ fields.add("float_f"); fields.add("" + f);+ fields.add("float_fm"); fields.add("" + f);+ fields.add("float_fm"); fields.add("" + (f+10));}- if (d<=50) {- floatTestStart.get(1).add(f);++ if ( d != 0.0d ) {+ fields.add("double_d"); fields.add("" + d);+ fields.add("double_dm"); fields.add("" + d);+ fields.add("double_dm"); fields.add("" + (d+10));}- if (l>=20) {- floatTestStart.get(2).add(f);++ if ( (j%DATE) != 0 ) {+ fields.add("date_dt"); fields.add(dt);+ fields.add("date_dtm"); fields.add(dt);+ fields.add("date_dtm"); fields.add(dtm);}- if (usually()) {- assertU(commit()); // to have several segments+ if ( (j%STRING) != 0 ) {+ fields.add("string_s"); fields.add(s);+ fields.add("string_sm"); fields.add(s);+ fields.add("string_sm"); fields.add(s + "_second");}++ addDoc(fields);}+ commitDocs();+ }++ static public final int INT = 7;+ static public final int LONG = 2;+ static public final int FLOAT = 6;+ static public final int DOUBLE = 5;+ static public final int DATE = 3;+ static public final int STRING = 4;+ static public final int NUM_LOOPS = 20;++ @Test+ public void queryFacetTest() throws Exception {+ Map<String, String> expressions = new HashMap<>();+ expressions.put("mean", "mean(int_i)");+ expressions.put("count", "count(string_sm)");- assertU(commit());+ // Value Facet "with_missing"+ addFacet("with_missing", "{ 'type':'query', 'queries':{'q1':'long_l:1 AND float_f:1.0','q2':'double_dm:[3 TO 11] OR double_dm:1'}}");++ addFacetValue("q1");+ addFacetResult("mean", 4.0);+ addFacetResult("count", 8L);- //Query ascending tests- setResponse(h.query(request(fileToStringArr(QueryFacetTest.class, fileName))));+ addFacetValue("q2");+ addFacetResult("mean", 38.0/11.0);+ addFacetResult("count", 18L);- //Int One- ArrayList<Double> int1 = getDoubleList("ir", "queryFacets", "float1", "double", "sum");- ArrayList<Double> int1Test = calculateNumberStat(int1TestStart, "sum");- assertEquals(getRawResponse(), int1, int1Test);- //Int Two- ArrayList<Integer> int2 = getIntegerList("ir", "queryFacets", "float2", "int", "percentile_8");- ArrayList<Integer> int2Test = (ArrayList<Integer>)calculateStat(int2TestStart, "perc_8");- assertEquals(getRawResponse(), int2, int2Test);-- //Long- ArrayList<Double> long1 = getDoubleList("lr", "queryFacets", "string", "double", "median");- ArrayList<Double> long1Test = calculateNumberStat(longTestStart, "median");- assertEquals(getRawResponse(),long1,long1Test);-- //Float- ArrayList<Double> float1 = getDoubleList("fr", "queryFacets", "lad", "double", "mean");- ArrayList<Double> float1Test = calculateNumberStat(floatTestStart, "mean");- assertEquals(getRawResponse(), float1, float1Test);+ testGrouping(expressions);}-}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/RangeFacetTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/RangeFacetTest.javaindex 24a7ea2c116..9f482bc5af5 100644--- a/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/RangeFacetTest.java+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/RangeFacetTest.java@@ -16,402 +16,298 @@*/package org.apache.solr.analytics.facet;-import java.util.ArrayList;+import java.util.HashMap;+import java.util.List;+import java.util.Map;import org.junit.BeforeClass;import org.junit.Test;--public class RangeFacetTest extends AbstractAnalyticsFacetTest {- static String fileName = "rangeFacets.txt";-- public static final int INT = 71;- public static final int LONG = 36;- public static final int FLOAT = 93;- public static final int DOUBLE = 48;- public static final int DATE = 52;- public static final int STRING = 28;- public static final int NUM_LOOPS = 100;-- //INT- static ArrayList<ArrayList<Integer>> intLongTestStart;- static ArrayList<ArrayList<Integer>> intDoubleTestStart;- static ArrayList<ArrayList<Integer>> intDateTestStart;-- //FLOAT- static ArrayList<ArrayList<Float>> floatLongTestStart;- static ArrayList<ArrayList<Float>> floatDoubleTestStart;- static ArrayList<ArrayList<Float>> floatDateTestStart;+public class RangeFacetTest extends SolrAnalyticsFacetTestCase {@BeforeClass- public static void beforeClass() throws Exception {- initCore("solrconfig-analytics.xml","schema-analytics.xml");- h.update("<delete><query>*:*</query></delete>");-- //INT- intLongTestStart = new ArrayList<>();- intDoubleTestStart = new ArrayList<>();- intDateTestStart = new ArrayList<>();-- //FLOAT- floatLongTestStart = new ArrayList<>();- floatDoubleTestStart = new ArrayList<>();- floatDateTestStart = new ArrayList<>();-+ public static void populate() throws Exception {for (int j = 0; j < NUM_LOOPS; ++j) {int i = j%INT;long l = j%LONG;float f = j%FLOAT;double d = j%DOUBLE;- int dt = j%DATE;- int s = j%STRING;- assertU(adoc("id", "1000" + j, "int_id", "" + i, "long_ld", "" + l, "float_fd", "" + f,- "double_dd", "" + d, "date_dtd", (1000+dt) + "-01-01T23:59:59Z", "string_sd", "abc" + s));- //Longs- if (j-LONG<0) {- ArrayList<Integer> list1 = new ArrayList<>();- list1.add(i);- intLongTestStart.add(list1);- ArrayList<Float> list2 = new ArrayList<>();- list2.add(f);- floatLongTestStart.add(list2);- } else {- intLongTestStart.get((int)l).add(i);- floatLongTestStart.get((int)l).add(f);+ String dt = (1800+j%DATE) + "-12-31T23:59:59Z";+ String dtm = (1800+j%DATE + 10) + "-12-31T23:59:59Z";+ String s = "str" + (j%STRING);+ List<String> fields = new ArrayList<>();+ fields.add("id"); fields.add("1000"+j);++ if ( i != 0 ) {+ fields.add("int_i"); fields.add("" + i);+ fields.add("int_im"); fields.add("" + i);+ fields.add("int_im"); fields.add("" + (i+10));+ }++ if ( l != 0l ) {+ fields.add("long_l"); fields.add("" + l);+ fields.add("long_lm"); fields.add("" + l);+ fields.add("long_lm"); fields.add("" + (l+10));}- //Doubles- if (j-DOUBLE<0) {- ArrayList<Integer> list1 = new ArrayList<>();- list1.add(i);- intDoubleTestStart.add(list1);- ArrayList<Float> list2 = new ArrayList<>();- list2.add(f);- floatDoubleTestStart.add(list2);- } else {- intDoubleTestStart.get((int)d).add(i);- floatDoubleTestStart.get((int)d).add(f);++ if ( f != 0.0f ) {+ fields.add("float_f"); fields.add("" + f);+ fields.add("float_fm"); fields.add("" + f);+ fields.add("float_fm"); fields.add("" + (f+10));}- //Dates- if (j-DATE<0) {- ArrayList<Integer> list1 = new ArrayList<>();- list1.add(i);- intDateTestStart.add(list1);- ArrayList<Float> list2 = new ArrayList<>();- list2.add(f);- floatDateTestStart.add(list2);- } else {- intDateTestStart.get(dt).add(i);- floatDateTestStart.get(dt).add(f);++ if ( d != 0.0d ) {+ fields.add("double_d"); fields.add("" + d);+ fields.add("double_dm"); fields.add("" + d);+ fields.add("double_dm"); fields.add("" + (d+10));}- if (usually()) {- assertU(commit()); // to have several segments+ if ( (j%DATE) != 0 ) {+ fields.add("date_dt"); fields.add(dt);+ fields.add("date_dtm"); fields.add(dt);+ fields.add("date_dtm"); fields.add(dtm);}++ if ( (j%STRING) != 0 ) {+ fields.add("string_s"); fields.add(s);+ fields.add("string_sm"); fields.add(s);+ fields.add("string_sm"); fields.add(s + "_second");+ }++ addDoc(fields);}+ commitDocs();+ }++ static public final int INT = 7;+ static public final int LONG = 2;+ static public final int FLOAT = 6;+ static public final int DOUBLE = 5;+ static public final int DATE = 3;+ static public final int STRING = 4;+ static public final int NUM_LOOPS = 20;++ @Test+ public void intRangeHardEndTest() throws Exception {+ Map<String, String> expressions = new HashMap<>();+ expressions.put("mean", "mean(float_f)");+ expressions.put("count", "count(string_sm)");- assertU(commit());+ // Hard end on+ addFacet("hard_end_on", "{ 'type':'range', "+ + " 'field': 'int_im', "+ + " 'start': '2', "+ + " 'end' : '13', "+ + " 'gaps' : ['2', '5', '3'], "+ + " 'hardend' : true }");++ addFacetValue("[2 TO 4)");+ addFacetResult("mean", 3.5);+ addFacetResult("count", 10L);- setResponse(h.query(request(fileToStringArr(RangeFacetTest.class, fileName))));- }+ addFacetValue("[4 TO 9)");+ addFacetResult("mean", 16.0/5.0);+ addFacetResult("count", 12L);++ addFacetValue("[9 TO 12)");+ addFacetResult("mean", 2.0);+ addFacetResult("count", 4L);++ addFacetValue("[12 TO 13)");+ addFacetResult("mean", 3.0);+ addFacetResult("count", 4L);++ // Hard end off+ addFacet("hard_end_off", "{ 'type':'range', "+ + " 'field': 'int_im', "+ + " 'start': '2', "+ + " 'end' : '13', "+ + " 'gaps' : ['2', '5', '3'], "+ + " 'hardend' : false }");- @SuppressWarnings("unchecked")- @Test- public void rangeTest() throws Exception {-- //Int Long- ArrayList<Long> intLong = getLongList("ri", "rangeFacets", "long_ld", "long", "count");- ArrayList<Long> intLongTest = calculateStat(transformLists(intLongTestStart, 5, 30, 5- , false, true, false, false, false), "count");- assertEquals(getRawResponse(), intLong,intLongTest);- //Int Double- ArrayList<Double> intDouble = getDoubleList("ri", "rangeFacets", "double_dd", "double", "mean");- ArrayList<Double> intDoubleTest = calculateNumberStat(transformLists(intDoubleTestStart, 3, 39, 7- , false, false, true, false, true), "mean");- assertEquals(getRawResponse(), intDouble,intDoubleTest);- //Int Date- ArrayList<Long> intDate = getLongList("ri", "rangeFacets", "date_dtd", "long", "count");- ArrayList<Long> intDateTest = (ArrayList<Long>)calculateStat(transformLists(intDateTestStart, 7, 44, 7- , false, true, false, true, true), "count");- assertEquals(getRawResponse(), intDate,intDateTest);-- //Float Long- ArrayList<Double> floatLong = getDoubleList("rf", "rangeFacets", "long_ld", "double", "median");- ArrayList<Double> floatLongTest = calculateNumberStat(transformLists(floatLongTestStart, 0, 29, 4- , false, true, true, true, true), "median");- assertEquals(getRawResponse(), floatLong,floatLongTest);- //Float Double- ArrayList<Long> floatDouble = getLongList("rf", "rangeFacets", "double_dd", "long", "count");- ArrayList<Long> floatDoubleTest = (ArrayList<Long>)calculateStat(transformLists(floatDoubleTestStart, 4, 47, 11- , false, false, false, true, false), "count");- assertEquals(getRawResponse(), floatDouble,floatDoubleTest);+ addFacetValue("[2 TO 4)");+ addFacetResult("mean", 3.5);+ addFacetResult("count", 10L);++ addFacetValue("[4 TO 9)");+ addFacetResult("mean", 16.0/5.0);+ addFacetResult("count", 12L);++ addFacetValue("[9 TO 12)");+ addFacetResult("mean", 2.0);+ addFacetResult("count", 4L);++ addFacetValue("[12 TO 15)");+ addFacetResult("mean", 30.0/8.0);+ addFacetResult("count", 14L);++ testGrouping(expressions);}-- @SuppressWarnings("unchecked")@Test- public void hardendRangeTest() throws Exception {- //Int Long- ArrayList<Double> intLong = getDoubleList("hi", "rangeFacets", "long_ld", "double", "sum");- ArrayList<Double> intLongTest = calculateNumberStat(transformLists(intLongTestStart, 5, 30, 5- , true, true, false, false, false), "sum");- assertEquals(getRawResponse(), intLong,intLongTest);- //Int Double- ArrayList<Double> intDouble = getDoubleList("hi", "rangeFacets", "double_dd", "double", "mean");- ArrayList<Double> intDoubleTest = calculateNumberStat(transformLists(intDoubleTestStart, 3, 39, 7- , true, false, true, false, true), "mean");- assertEquals(getRawResponse(), intDouble,intDoubleTest);- //Int Date- ArrayList<Long> intDate = getLongList("hi", "rangeFacets", "date_dtd", "long", "count");- ArrayList<Long> intDateTest = (ArrayList<Long>)calculateStat(transformLists(intDateTestStart, 7, 44, 7- , true, true, false, true, true), "count");- assertEquals(getRawResponse(), intDate,intDateTest);-- //Float Long- ArrayList<Double> floatLong = getDoubleList("hf", "rangeFacets", "long_ld", "double", "median");- ArrayList<Double> floatLongTest = calculateNumberStat(transformLists(floatLongTestStart, 0, 29, 4- , true, true, true, true, true), "median");- assertEquals(getRawResponse(), floatLong,floatLongTest);- //Float Double- ArrayList<Long> floatDouble = getLongList("hf", "rangeFacets", "double_dd", "long", "count");- ArrayList<Long> floatDoubleTest = (ArrayList<Long>)calculateStat(transformLists(floatDoubleTestStart, 4, 47, 11- , true, false, false, true, false), "count");- assertEquals(getRawResponse(), floatDouble,floatDoubleTest);+ public void doubleOthersTest() throws Exception {+ Map<String, String> expressions = new HashMap<>();+ expressions.put("mean", "mean(float_f)");+ expressions.put("count", "count(string_sm)");++ addFacet("before_between", "{ 'type':'range', "+ + " 'field': 'double_d', "+ + " 'start': '2', "+ + " 'end' : '4', "+ + " 'gaps' : ['1'], "+ + " 'others' : ['before', 'between'] }");++ addFacetValue("[2.0 TO 3.0)");+ addFacetResult("mean", 8.0/3.0);+ addFacetResult("count", 6L);++ addFacetValue("[3.0 TO 4.0)");+ addFacetResult("mean", 2.0);+ addFacetResult("count", 6L);++ addFacetValue("(* TO 2.0)");+ addFacetResult("mean", 10.0/3.0);+ addFacetResult("count", 6L);++ addFacetValue("[2.0 TO 4.0)");+ addFacetResult("mean", 14.0/6.0);+ addFacetResult("count", 12L);++ addFacet("after", "{ 'type':'range', "+ + " 'field': 'double_d', "+ + " 'start': '2', "+ + " 'end' : '4', "+ + " 'gaps' : ['1'], "+ + " 'others' : ['after'] }");++ addFacetValue("[2.0 TO 3.0)");+ addFacetResult("mean", 8.0/3.0);+ addFacetResult("count", 6L);++ addFacetValue("[3.0 TO 4.0)");+ addFacetResult("mean", 2.0);+ addFacetResult("count", 6L);++ addFacetValue("[4.0 TO *)");+ addFacetResult("mean", 2.5);+ addFacetResult("count", 6L);++ testGrouping(expressions);}- @SuppressWarnings("unchecked")@Test- public void multiGapTest() throws Exception {- //Int Long- ArrayList<Double> intLong = getDoubleList("mi", "rangeFacets", "long_ld", "double", "sum");- ArrayList<Double> intLongTest = calculateNumberStat(transformLists(intLongTestStart, 5, 30, "4,2,6,3"- , false, true, false, false, false), "sum");- assertEquals(getRawResponse(), intLong,intLongTest);- //Int Double- ArrayList<Double> intDouble = getDoubleList("mi", "rangeFacets", "double_dd", "double", "mean");- ArrayList<Double> intDoubleTest = calculateNumberStat(transformLists(intDoubleTestStart, 3, 39, "3,1,7"- , false, false, true, false, true), "mean");- assertEquals(getRawResponse(), intDouble,intDoubleTest);- //Int Date- ArrayList<Long> intDate = getLongList("mi", "rangeFacets", "date_dtd", "long", "count");- ArrayList<Long> intDateTest = (ArrayList<Long>)calculateStat(transformLists(intDateTestStart, 7, 44, "2,7"- , false, true, false, true, true), "count");- assertEquals(getRawResponse(), intDate,intDateTest);-- //Float Long- ArrayList<Double> floatLong = getDoubleList("mf", "rangeFacets", "long_ld", "double", "median");- ArrayList<Double> floatLongTest = calculateNumberStat(transformLists(floatLongTestStart, 0, 29, "1,4"- , false, true, true, true, true), "median");;- assertEquals(getRawResponse(), floatLong,floatLongTest);- //Float Double- ArrayList<Long> floatDouble = getLongList("mf", "rangeFacets", "double_dd", "long", "count");- ArrayList<Long> floatDoubleTest = (ArrayList<Long>)calculateStat(transformLists(floatDoubleTestStart, 4, 47, "2,3,11"- , false, false, false, true, false), "count");- assertEquals(getRawResponse(), floatDouble,floatDoubleTest);+ public void dateIncludeTest() throws Exception {+ Map<String, String> expressions = new HashMap<>();+ expressions.put("mean", "mean(float_f)");+ expressions.put("count", "count(string_sm)");++ addFacet("lower_upper", "{ 'type':'range', "+ + " 'field': 'date_dt', "+ + " 'start': '1801-12-31T23:59:59Z', "+ + " 'end' : '1803-12-31T23:59:59Z', "+ + " 'gaps' : ['+1YEAR'], "+ + " 'include' : ['lower', 'upper'] }");++ addFacetValue("[1801-12-31T23:59:59Z TO 1802-12-31T23:59:59Z]");+ addFacetResult("mean", 37.0/13.0);+ addFacetResult("count", 20L);++ addFacetValue("[1802-12-31T23:59:59Z TO 1803-12-31T23:59:59Z]");+ addFacetResult("mean", 3.5);+ addFacetResult("count", 10L);++ testGrouping(expressions);++ addFacet("lower_upper", "{ 'type':'range', "+ + " 'field': 'date_dt', "+ + " 'start': '1801-12-31T23:59:59Z', "+ + " 'end' : '1803-12-31T23:59:59Z', "+ + " 'gaps' : ['+1YEAR'], "+ + " 'include' : ['lower','edge'] }");++ addFacetValue("[1801-12-31T23:59:59Z TO 1802-12-31T23:59:59Z)");+ addFacetResult("mean", 16.0/7.0);+ addFacetResult("count", 10L);++ addFacetValue("[1802-12-31T23:59:59Z TO 1803-12-31T23:59:59Z]");+ addFacetResult("mean", 3.5);+ addFacetResult("count", 10L);++ testGrouping(expressions);}- private <T> ArrayList<ArrayList<T>> transformLists(ArrayList<ArrayList<T>> listsStart, int start, int end, int gap- , boolean hardend, boolean incLow, boolean incUp, boolean incEdge, boolean incOut) {- int off = (end-start)%gap;- if (!hardend && off>0) {- end+=gap-off;- }+ @Test+ public void floatIncludeOuterTest() throws Exception {+ Map<String, String> expressions = new HashMap<>();+ expressions.put("mean", "mean(int_i)");+ expressions.put("count", "count(string_sm)");++ addFacet("include_outer", "{ 'type':'range', "+ + " 'field': 'float_f', "+ + " 'start': '1', "+ + " 'end' : '5', "+ + " 'gaps' : ['2'], "+ + " 'include' : ['outer'], "+ + " 'others' : ['all'] }");- ArrayList<ArrayList<T>> lists = new ArrayList<>();- ArrayList<T> between = new ArrayList<>();- if (incLow && incUp) {- for (int i = start; i<end && i<listsStart.size(); i+=gap) {- ArrayList<T> list = new ArrayList<>();- for (int j = i; j<=i+gap && j<=end && j<listsStart.size(); j++) {- list.addAll(listsStart.get(j));- }- lists.add(list);- }- for (int i = start; i<listsStart.size() && i<=end; i++) {- between.addAll(listsStart.get(i));- }- } else if (incLow && !incUp) {- for (int i = start; i<end && i<listsStart.size(); i+=gap) {- ArrayList<T> list = new ArrayList<>();- for (int j = i; j<i+gap && j<end && j<listsStart.size(); j++) {- list.addAll(listsStart.get(j));- }- lists.add(list);- }- for (int i = start; i<listsStart.size() && i<end; i++) {- between.addAll(listsStart.get(i));- }- } else if (!incLow && incUp) {- for (int i = start; i<end && i<listsStart.size(); i+=gap) {- ArrayList<T> list = new ArrayList<>();- for (int j = i+1; j<=i+gap && j<=end && j<listsStart.size(); j++) {- list.addAll(listsStart.get(j));- }- lists.add(list);- }- for (int i = start+1; i<listsStart.size() && i<=end; i++) {- between.addAll(listsStart.get(i));- }- } else {- for (int i = start; i<end && i<listsStart.size(); i+=gap) {- ArrayList<T> list = new ArrayList<>();- for (int j = i+1; j<i+gap && j<end && j<listsStart.size(); j++) {- list.addAll(listsStart.get(j));- }- lists.add(list);- }- for (int i = start+1; i<listsStart.size() && i<end; i++) {- between.addAll(listsStart.get(i));- }- }+ addFacetValue("(1.0 TO 3.0)");+ addFacetResult("mean", 1.5);+ addFacetResult("count", 4L);++ addFacetValue("(3.0 TO 5.0)");+ addFacetResult("mean", 3.0);+ addFacetResult("count", 2L);- if (incEdge && !incLow && start>=0) {- lists.get(0).addAll(listsStart.get(start));- between.addAll(listsStart.get(start));- }- if (incEdge && !incUp && end<listsStart.size()) {- lists.get(lists.size()-1).addAll(listsStart.get(end));- between.addAll(listsStart.get(end));- }- ArrayList<T> before = new ArrayList<>();- ArrayList<T> after = new ArrayList<>();- if (incOut || !(incLow||incEdge)) {- for (int i = 0; i<=start; i++) {- before.addAll(listsStart.get(i));- }- } else {- for (int i = 0; i<start; i++) {- before.addAll(listsStart.get(i));- }- }- if (incOut || !(incUp||incEdge)) {- for (int i = end; i<listsStart.size(); i++) {- after.addAll(listsStart.get(i));- }- }- else {- for (int i = end+1; i<listsStart.size(); i++) {- after.addAll(listsStart.get(i));- }- }- lists.add(before);- lists.add(after);- lists.add(between);- return lists;+ addFacetValue("(* TO 1.0]");+ addFacetResult("mean", 4.0);+ addFacetResult("count", 8L);++ addFacetValue("[5.0 TO *)");+ addFacetResult("mean", 4.0);+ addFacetResult("count", 6L);++ addFacetValue("(1.0 TO 5.0)");+ addFacetResult("mean", 18.0/8.0);+ addFacetResult("count", 12L);++ testGrouping(expressions);}- private <T> ArrayList<ArrayList<T>> transformLists(ArrayList<ArrayList<T>> listsStart, int start, int end, String gapString- , boolean hardend, boolean incLow, boolean incUp, boolean incEdge, boolean incOut) {- String[] stringGaps = gapString.split(",");- int[] gaps = new int[stringGaps.length];- for (int i = 0; i<gaps.length; i++) {- gaps[i] = Integer.parseInt(stringGaps[i]);- }- int bigGap = 0;- int last = gaps[gaps.length-1];- for (int i = 0; i<gaps.length-1; i++) {- bigGap += gaps[i];- }- int off = (end-start-bigGap)%last;- if (!hardend && off>0) {- end+=last-off;- }+ @Test+ public void floatIncludeAllTest() throws Exception {+ Map<String, String> expressions = new HashMap<>();+ expressions.put("mean", "mean(int_i)");+ expressions.put("count", "count(string_sm)");- ArrayList<ArrayList<T>> lists = new ArrayList<>();- ArrayList<T> between = new ArrayList<>();- int gap = 0;- int gapCounter = 0;- if (incLow && incUp) {- for (int i = start; i<end && i<listsStart.size(); i+=gap) {- if (gapCounter<gaps.length) {- gap = gaps[gapCounter++];- }- ArrayList<T> list = new ArrayList<>();- for (int j = i; j<=i+gap && j<=end && j<listsStart.size(); j++) {- list.addAll(listsStart.get(j));- }- lists.add(list);- }- for (int i = start; i<listsStart.size() && i<=end; i++) {- between.addAll(listsStart.get(i));- }- } else if (incLow && !incUp) {- for (int i = start; i<end && i<listsStart.size(); i+=gap) {- if (gapCounter<gaps.length) {- gap = gaps[gapCounter++];- }- ArrayList<T> list = new ArrayList<>();- for (int j = i; j<i+gap && j<end && j<listsStart.size(); j++) {- list.addAll(listsStart.get(j));- }- lists.add(list);- }- for (int i = start; i<listsStart.size() && i<end; i++) {- between.addAll(listsStart.get(i));- }- } else if (!incLow && incUp) {- for (int i = start; i<end && i<listsStart.size(); i+=gap) {- if (gapCounter<gaps.length) {- gap = gaps[gapCounter++];- }- ArrayList<T> list = new ArrayList<>();- for (int j = i+1; j<=i+gap && j<=end && j<listsStart.size(); j++) {- list.addAll(listsStart.get(j));- }- lists.add(list);- }- for (int i = start+1; i<listsStart.size() && i<=end; i++) {- between.addAll(listsStart.get(i));- }- } else {- for (int i = start; i<end && i<listsStart.size(); i+=gap) {- if (gapCounter<gaps.length) {- gap = gaps[gapCounter++];- }- ArrayList<T> list = new ArrayList<>();- for (int j = i+1; j<i+gap && j<end && j<listsStart.size(); j++) {- list.addAll(listsStart.get(j));- }- lists.add(list);- }- for (int i = start+1; i<listsStart.size() && i<end; i++) {- between.addAll(listsStart.get(i));- }- }+ addFacet("include_all", "{ 'type':'range', "+ + " 'field': 'float_f', "+ + " 'start': '1', "+ + " 'end' : '5', "+ + " 'gaps' : ['2'], "+ + " 'include' : ['all'], "+ + " 'others' : ['all'] }");++ addFacetValue("[1.0 TO 3.0]");+ addFacetResult("mean", 21.0/8.0);+ addFacetResult("count", 18L);++ addFacetValue("[3.0 TO 5.0]");+ addFacetResult("mean", 3.0);+ addFacetResult("count", 14L);- if (incEdge && !incLow && start>=0) {- lists.get(0).addAll(listsStart.get(start));- between.addAll(listsStart.get(start));- }- if (incEdge && !incUp && end<listsStart.size()) {- lists.get(lists.size()-1).addAll(listsStart.get(end));- between.addAll(listsStart.get(end));- }- ArrayList<T> before = new ArrayList<>();- ArrayList<T> after = new ArrayList<>();- if (incOut || !(incLow||incEdge)) {- for (int i = 0; i<=start; i++) {- before.addAll(listsStart.get(i));- }- } else {- for (int i = 0; i<start; i++) {- before.addAll(listsStart.get(i));- }- }- if (incOut || !(incUp||incEdge)) {- for (int i = end; i<listsStart.size(); i++) {- after.addAll(listsStart.get(i));- }- }- else {- for (int i = end+1; i<listsStart.size(); i++) {- after.addAll(listsStart.get(i));- }- }- lists.add(before);- lists.add(after);- lists.add(between);- return lists;+ addFacetValue("(* TO 1.0]");+ addFacetResult("mean", 4.0);+ addFacetResult("count", 8L);++ addFacetValue("[5.0 TO *)");+ addFacetResult("mean", 4.0);+ addFacetResult("count", 6L);++ addFacetValue("[1.0 TO 5.0]");+ addFacetResult("mean", 3.0);+ addFacetResult("count", 26L);++ testGrouping(expressions);}-}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/SolrAnalyticsFacetTestCase.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/SolrAnalyticsFacetTestCase.javanew file mode 100644index 00000000000..22decd7de4f--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/SolrAnalyticsFacetTestCase.java@@ -0,0 +1,80 @@+/*+ * 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.analytics.facet;++import java.util.ArrayList;+import java.util.HashMap;+import java.util.List;+import java.util.Map;++import org.apache.solr.analytics.SolrAnalyticsTestCase;+import org.junit.Before;++public class SolrAnalyticsFacetTestCase extends SolrAnalyticsTestCase {++ private List<FVP> facetResults;+ private Map<String, List<FVP>> results = new HashMap<>();+ private Map<String, String> facets = new HashMap<>();+ private FVP fvp;+ private int fvp_num;++ @Before+ protected void initData() {+ results = new HashMap<>();+ facets = new HashMap<>();+ }++ protected void addFacet(String name, String json) {+ facets.put(name, json);+ facetResults = new ArrayList<>();+ results.put(name, facetResults);+ fvp_num = 0;+ }++ protected void addFacetValue(String value) {+ fvp = new FVP(fvp_num++, value, new HashMap<>());+ facetResults.add(fvp);+ }++ protected void addFacetResult(String expr, Comparable<?> result) {+ fvp.expectedResults.put(expr, result);+ }++ protected void testGrouping(Map<String,String> expressions) {+ try {+ testGrouping("grouping", expressions, facets, results);+ } catch (Exception e) {+ throw new RuntimeException(e);+ }+ }++ protected void testGrouping(Map<String,String> expressions, boolean sortAscending) {+ try {+ testGrouping("grouping", expressions, facets, results, sortAscending);+ } catch (Exception e) {+ throw new RuntimeException(e);+ }+ }++ protected void testGrouping(Map<String,String> expressions, String sortExpression, boolean sortAscending) {+ try {+ testGrouping("grouping", expressions, facets, results, sortExpression, sortAscending);+ } catch (Exception e) {+ throw new RuntimeException(e);+ }+ }+}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/ValueFacetTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/ValueFacetTest.javanew file mode 100644index 00000000000..da117de38a3--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/ValueFacetTest.java@@ -0,0 +1,433 @@+/*+ * 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.analytics.facet;++import java.util.ArrayList;+import java.util.HashMap;+import java.util.List;+import java.util.Map;++import org.junit.BeforeClass;+import org.junit.Test;++public class ValueFacetTest extends SolrAnalyticsFacetTestCase {++ @BeforeClass+ public static void populate() throws Exception {+ for (int j = 0; j < NUM_LOOPS; ++j) {+ int i = j%INT;+ long l = j%LONG;+ float f = j%FLOAT;+ double d = j%DOUBLE;+ String dt = (1800+j%DATE) + "-12-31T23:59:59Z";+ String dtm = (1800+j%DATE + 10) + "-12-31T23:59:59Z";+ String s = "str" + (j%STRING);+ List<String> fields = new ArrayList<>();+ fields.add("id"); fields.add("1000"+j);++ if ( i != 0 ) {+ fields.add("int_i"); fields.add("" + i);+ fields.add("int_im"); fields.add("" + i);+ fields.add("int_im"); fields.add("" + (i+10));+ }++ if ( l != 0l ) {+ fields.add("long_l"); fields.add("" + l);+ fields.add("long_lm"); fields.add("" + l);+ fields.add("long_lm"); fields.add("" + (l+10));+ }++ if ( f != 0.0f ) {+ fields.add("float_f"); fields.add("" + f);+ fields.add("float_fm"); fields.add("" + f);+ fields.add("float_fm"); fields.add("" + (f+10));+ }++ if ( d != 0.0d ) {+ fields.add("double_d"); fields.add("" + d);+ fields.add("double_dm"); fields.add("" + d);+ fields.add("double_dm"); fields.add("" + (d+10));+ }++ if ( (j%DATE) != 0 ) {+ fields.add("date_dt"); fields.add(dt);+ fields.add("date_dtm"); fields.add(dt);+ fields.add("date_dtm"); fields.add(dtm);+ }++ if ( (j%STRING) != 0 ) {+ fields.add("string_s"); fields.add(s);+ fields.add("string_sm"); fields.add(s);+ fields.add("string_sm"); fields.add(s + "_second");+ }++ addDoc(fields);+ }+ commitDocs();+ }++ static public final int INT = 7;+ static public final int LONG = 2;+ static public final int FLOAT = 6;+ static public final int DOUBLE = 5;+ static public final int DATE = 3;+ static public final int STRING = 4;+ static public final int NUM_LOOPS = 20;++ @Test+ public void countTest() throws Exception {+ Map<String, String> expressions = new HashMap<>();+ expressions.put("single", "count(float_f)");+ expressions.put("multi", "count(string_sm)");++ // Value Facet "with_missing"+ addFacet("with_missing", "{ 'type':'value', 'expression':'fill_missing(long_l,\\'No Long\\')' }");++ addFacetValue("1");+ addFacetResult("single", 10L);+ addFacetResult("multi", 20L);++ addFacetValue("No Long");+ addFacetResult("single", 6L);+ addFacetResult("multi", 10L);++ testGrouping(expressions, "single", true);+ }++ @Test+ public void docCountTest() throws Exception {+ Map<String, String> expressions = new HashMap<>();+ expressions.put("single", "doc_count(date_dt)");+ expressions.put("multi", "doc_count(float_fm)");++ // Value Facet "with_missing"+ addFacet("with_missing", "{ 'type':'value', 'expression':'fill_missing(string_sm,\\'No Values\\')' }");++ addFacetValue("str1");+ addFacetResult("single", 4L);+ addFacetResult("multi", 5L);++ addFacetValue("str1_second");+ addFacetResult("single", 4L);+ addFacetResult("multi", 5L);++ addFacetValue("str2");+ addFacetResult("single", 3L);+ addFacetResult("multi", 3L);++ addFacetValue("str2_second");+ addFacetResult("single", 3L);+ addFacetResult("multi", 3L);++ addFacetValue("str3");+ addFacetResult("single", 3L);+ addFacetResult("multi", 5L);++ addFacetValue("str3_second");+ addFacetResult("single", 3L);+ addFacetResult("multi", 5L);++ addFacetValue("No Values");+ addFacetResult("single", 3L);+ addFacetResult("multi", 3L);++ // Value Facet "no_missing"+ addFacet("no_missing", "{ 'type':'value', 'expression':'long_l' }");++ addFacetValue("1");+ addFacetResult("single", 7L);+ addFacetResult("multi", 10L);++ testGrouping(expressions, false);+ }++ @Test+ public void missingTest() throws Exception {+ Map<String, String> expressions = new HashMap<>();+ expressions.put("single", "missing(date_dt)");+ expressions.put("multi", "missing(float_fm)");++ // Value Facet "with_missing"+ addFacet("with_missing", "{ 'type':'value', 'expression':'fill_missing(string_sm,\\'No Values\\')' }");++ addFacetValue("str1");+ addFacetResult("single", 1L);+ addFacetResult("multi", 0L);++ addFacetValue("str1_second");+ addFacetResult("single", 1L);+ addFacetResult("multi", 0L);++ addFacetValue("str2");+ addFacetResult("single", 2L);+ addFacetResult("multi", 2L);++ addFacetValue("str2_second");+ addFacetResult("single", 2L);+ addFacetResult("multi", 2L);++ addFacetValue("str3");+ addFacetResult("single", 2L);+ addFacetResult("multi", 0L);++ addFacetValue("str3_second");+ addFacetResult("single", 2L);+ addFacetResult("multi", 0L);++ addFacetValue("No Values");+ addFacetResult("single", 2L);+ addFacetResult("multi", 2L);++ // Value Facet "no_missing"+ addFacet("no_missing", "{ 'type':'value', 'expression':'long_l' }");++ addFacetValue("1");+ addFacetResult("single", 3L);+ addFacetResult("multi", 0L);++ testGrouping(expressions, false);+ }++ @Test+ public void uniqueTest() throws Exception {+ Map<String, String> expressions = new HashMap<>();+ expressions.put("int", "unique(int_i)");+ expressions.put("longs", "unique(long_lm)");+ expressions.put("float", "unique(float_f)");+ expressions.put("doubles", "unique(double_dm)");+ expressions.put("dates", "unique(date_dtm)");+ expressions.put("string", "unique(string_s)");++ // Value Facet "without_missing"+ addFacet("without_missing", "{ 'type':'value', 'expression':'date_dt' }");++ addFacetValue("1801-12-31T23:59:59Z");+ addFacetResult("int", 6L);+ addFacetResult("longs", 2L);+ addFacetResult("float", 2L);+ addFacetResult("doubles", 8L);+ addFacetResult("dates", 2L);+ addFacetResult("string", 3L);++ addFacetValue("1802-12-31T23:59:59Z");+ addFacetResult("int", 5L);+ addFacetResult("longs", 2L);+ addFacetResult("float", 2L);+ addFacetResult("doubles", 8L);+ addFacetResult("dates", 2L);+ addFacetResult("string", 3L);++ testGrouping(expressions, false);+ }++ @Test+ public void minTest() throws Exception {+ Map<String, String> expressions = new HashMap<>();+ expressions.put("int", "min(int_i)");+ expressions.put("longs", "min(long_lm)");+ expressions.put("float", "min(float_f)");+ expressions.put("doubles", "min(double_dm)");+ expressions.put("dates", "min(date_dtm)");+ expressions.put("string", "min(string_s)");++ // Value Facet "without_missing"+ addFacet("without_missing", "{ 'type':'value', 'expression':'date_dt' }");++ addFacetValue("1801-12-31T23:59:59Z");+ addFacetResult("int", 1);+ addFacetResult("longs", 1L);+ addFacetResult("float", 1.0F);+ addFacetResult("doubles", 1.0);+ addFacetResult("dates", "1801-12-31T23:59:59Z");+ addFacetResult("string", "str1");++ addFacetValue("1802-12-31T23:59:59Z");+ addFacetResult("int", 1);+ addFacetResult("longs", 1L);+ addFacetResult("float", 2.0F);+ addFacetResult("doubles", 1.0);+ addFacetResult("dates", "1802-12-31T23:59:59Z");+ addFacetResult("string", "str1");++ testGrouping(expressions, false);+ }++ @Test+ public void maxTest() throws Exception {+ Map<String, String> expressions = new HashMap<>();+ expressions.put("int", "max(int_i)");+ expressions.put("longs", "max(long_lm)");+ expressions.put("float", "max(float_f)");+ expressions.put("doubles", "max(double_dm)");+ expressions.put("dates", "max(date_dtm)");+ expressions.put("string", "max(string_s)");++ // Value Facet "without_missing"+ addFacet("without_missing", "{ 'type':'value', 'expression':'date_dt' }");++ addFacetValue("1801-12-31T23:59:59Z");+ addFacetResult("int", 6);+ addFacetResult("longs", 11L);+ addFacetResult("float", 4.0F);+ addFacetResult("doubles", 14.0);+ addFacetResult("dates", "1811-12-31T23:59:59Z");+ addFacetResult("string", "str3");++ addFacetValue("1802-12-31T23:59:59Z");+ addFacetResult("int", 5);+ addFacetResult("longs", 11L);+ addFacetResult("float", 5.0F);+ addFacetResult("doubles", 14.0);+ addFacetResult("dates", "1812-12-31T23:59:59Z");+ addFacetResult("string", "str3");++ testGrouping(expressions, false);+ }++ @Test+ public void sumTest() throws Exception {+ Map<String, String> expressions = new HashMap<>();+ expressions.put("single", "sum(float_f)");+ expressions.put("multi", "sum(double_dm)");++ // Value Facet "without_missing"+ addFacet("without_missing", "{ 'type':'value', 'expression':'date_dt' }");++ addFacetValue("1801-12-31T23:59:59Z");+ addFacetResult("single", 16.0);+ addFacetResult("multi", 90.0);++ addFacetValue("1802-12-31T23:59:59Z");+ addFacetResult("single", 21.0);+ addFacetResult("multi", 74.0);++ testGrouping(expressions, false);+ }++ @Test+ public void meanTest() throws Exception {+ Map<String, String> expressions = new HashMap<>();+ expressions.put("single", "mean(float_f)");+ expressions.put("multi", "mean(double_dm)");++ // Value Facet "without_missing"+ addFacet("without_missing", "{ 'type':'value', 'expression':'date_dt' }");++ addFacetValue("1801-12-31T23:59:59Z");+ addFacetResult("single", 16.0/7.0);+ addFacetResult("multi", 90.0/12.0);++ addFacetValue("1802-12-31T23:59:59Z");+ addFacetResult("single", 21.0/6.0);+ addFacetResult("multi", 74.0/10.0);++ testGrouping(expressions, "multi", true);+ }++ @Test+ public void medianTest() throws Exception {+ Map<String, String> expressions = new HashMap<>();+ expressions.put("int", "median(int_i)");+ expressions.put("longs", "median(long_lm)");+ expressions.put("float", "median(float_f)");+ expressions.put("doubles", "median(double_dm)");+ expressions.put("dates", "median(date_dtm)");++ // Value Facet "without_missing"+ addFacet("without_missing", "{ 'type':'value', 'expression':'date_dt' }");++ addFacetValue("1801-12-31T23:59:59Z");+ addFacetResult("int", 3.5);+ addFacetResult("longs", 6.0);+ addFacetResult("float", 1.0);+ addFacetResult("doubles", 7.5);+ addFacetResult("dates", "1806-12-31T23:59:59Z");++ addFacetValue("1802-12-31T23:59:59Z");+ addFacetResult("int", 3.0);+ addFacetResult("longs", 6.0);+ addFacetResult("float", 3.5);+ addFacetResult("doubles", 7.50);+ addFacetResult("dates", "1808-01-01T11:59:59Z");++ testGrouping(expressions, false);+ }++ @Test+ public void percentileTest() throws Exception {+ Map<String, String> expressions = new HashMap<>();+ expressions.put("int", "percentile(20,int_i)");+ expressions.put("longs", "percentile(80,long_lm)");+ expressions.put("float", "percentile(40,float_f)");+ expressions.put("doubles", "percentile(50,double_dm)");+ expressions.put("dates", "percentile(0,date_dtm)");+ expressions.put("string", "percentile(99.99,string_s)");++ // Value Facet "without_missing"+ addFacet("without_missing", "{ 'type':'value', 'expression':'date_dt' }");++ addFacetValue("1801-12-31T23:59:59Z");+ addFacetResult("int", 2);+ addFacetResult("longs", 11L);+ addFacetResult("float", 1.0F);+ addFacetResult("doubles", 11.0);+ addFacetResult("dates", "1801-12-31T23:59:59Z");+ addFacetResult("string", "str3");++ addFacetValue("1802-12-31T23:59:59Z");+ addFacetResult("int", 2);+ addFacetResult("longs", 11L);+ addFacetResult("float", 2.0F);+ addFacetResult("doubles", 11.0);+ addFacetResult("dates", "1802-12-31T23:59:59Z");+ addFacetResult("string", "str3");++ testGrouping(expressions, "dates", false);+ }++ @Test+ public void ordinalTest() throws Exception {+ Map<String, String> expressions = new HashMap<>();+ expressions.put("int", "ordinal(3,int_i)");+ expressions.put("longs", "ordinal(-2,long_lm)");+ expressions.put("float", "ordinal(-3,float_f)");+ expressions.put("doubles", "ordinal(1,double_dm)");+ expressions.put("dates", "ordinal(-1,date_dtm)");+ expressions.put("string", "ordinal(4,string_s)");++ // Value Facet "without_missing"+ addFacet("without_missing", "{ 'type':'value', 'expression':'date_dt' }");++ addFacetValue("1801-12-31T23:59:59Z");+ addFacetResult("int", 3);+ addFacetResult("longs", 11L);+ addFacetResult("float", 4.0F);+ addFacetResult("doubles", 1.0);+ addFacetResult("dates", "1811-12-31T23:59:59Z");+ addFacetResult("string", "str3");++ addFacetValue("1802-12-31T23:59:59Z");+ addFacetResult("int", 3);+ addFacetResult("longs", 11L);+ addFacetResult("float", 5.0F);+ addFacetResult("doubles", 1.0);+ addFacetResult("dates", "1812-12-31T23:59:59Z");+ addFacetResult("string", "str2");++ testGrouping(expressions, "string", false);+ }+}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/AbstractAnalyticsFieldTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/AbstractAnalyticsFieldTest.javanew file mode 100644index 00000000000..4361dea2715--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/AbstractAnalyticsFieldTest.java@@ -0,0 +1,299 @@+/*+ * 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.analytics.function.field;++import java.io.IOException;+import java.time.Instant;+import java.util.ArrayList;+import java.util.HashMap;+import java.util.HashSet;+import java.util.List;+import java.util.Map;+import java.util.Set;+import java.util.function.Predicate;++import org.apache.lucene.index.LeafReaderContext;+import org.apache.lucene.search.DocIdSet;+import org.apache.lucene.search.DocIdSetIterator;+import org.apache.lucene.search.MatchAllDocsQuery;+import org.apache.solr.SolrTestCaseJ4;+import org.apache.solr.analytics.ExpressionFactory;+import org.apache.solr.schema.IndexSchema;+import org.apache.solr.search.Filter;+import org.apache.solr.search.QueryWrapperFilter;+import org.apache.solr.search.SolrIndexSearcher;+import org.apache.solr.util.RefCounted;+import org.junit.AfterClass;+import org.junit.BeforeClass;++public class AbstractAnalyticsFieldTest extends SolrTestCaseJ4 {++ private static IndexSchema indexSchema;+ private static SolrIndexSearcher searcher;+ private static RefCounted<SolrIndexSearcher> ref;++ protected static Map<String,Integer> singleInts;+ protected static Map<String,Map<Integer,Integer>> multiInts;+ protected static Map<String,Long> singleLongs;+ protected static Map<String,Map<Long,Integer>> multiLongs;+ protected static Map<String,Float> singleFloats;+ protected static Map<String,Map<Float,Integer>> multiFloats;+ protected static Map<String,Double> singleDoubles;+ protected static Map<String,Map<Double,Integer>> multiDoubles;+ protected static Map<String,Long> singleDates;+ protected static Map<String,Map<Long,Integer>> multiDates;+ protected static Map<String,String> singleStrings;+ protected static Map<String,Map<String,Integer>> multiStrings;+ protected static Map<String,Boolean> singleBooleans;+ protected static Map<String,Map<Boolean,Integer>> multiBooleans;++ private static List<String> missingDocuments;++ @BeforeClass+ public static void createSchemaAndFields() throws Exception {+ initCore("solrconfig-analytics.xml","schema-analytics.xml");++ singleInts = new HashMap<>();+ multiInts = new HashMap<>();+ singleLongs = new HashMap<>();+ multiLongs = new HashMap<>();+ singleFloats = new HashMap<>();+ multiFloats = new HashMap<>();+ singleDoubles = new HashMap<>();+ multiDoubles = new HashMap<>();+ singleDates = new HashMap<>();+ multiDates = new HashMap<>();+ singleStrings = new HashMap<>();+ multiStrings = new HashMap<>();+ singleBooleans = new HashMap<>();+ multiBooleans = new HashMap<>();++ missingDocuments = new ArrayList<>();++ assertU(adoc("id", "-1"));+ missingDocuments.add("-1");+ assertU(adoc("id", "5"));+ missingDocuments.add("5");+ for (int i = 0; i < 5; ++i) {+ assertU(adoc(+ "id", "" + i,++ "int_i_t", "" + i,+ "int_im_t", "" + i,+ "int_im_t", "" + (i + 10),+ "int_im_t", "" + (i + 10),+ "int_im_t", "" + (i + 20),++ "int_i_p", "" + i,+ "int_im_p", "" + i,+ "int_im_p", "" + (i + 10),+ "int_im_p", "" + (i + 10),+ "int_im_p", "" + (i + 20),++ "long_l_t", "" + i,+ "long_lm_t", "" + i,+ "long_lm_t", "" + (i + 10),+ "long_lm_t", "" + (i + 10),+ "long_lm_t", "" + (i + 20),++ "long_l_p", "" + i,+ "long_lm_p", "" + i,+ "long_lm_p", "" + (i + 10),+ "long_lm_p", "" + (i + 10),+ "long_lm_p", "" + (i + 20),++ "float_f_t", "" + (i + .75F),+ "float_fm_t", "" + (i + .75F),+ "float_fm_t", "" + (i + 10.75F),+ "float_fm_t", "" + (i + 10.75F),+ "float_fm_t", "" + (i + 20.75F),++ "float_f_p", "" + (i + .75F),+ "float_fm_p", "" + (i + .75F),+ "float_fm_p", "" + (i + 10.75F),+ "float_fm_p", "" + (i + 10.75F),+ "float_fm_p", "" + (i + 20.75F),++ "double_d_t", "" + (i + .5),+ "double_dm_t", "" + (i + .5),+ "double_dm_t", "" + (i + 10.5),+ "double_dm_t", "" + (i + 10.5),+ "double_dm_t", "" + (i + 20.5),++ "double_d_p", "" + (i + .5),+ "double_dm_p", "" + (i + .5),+ "double_dm_p", "" + (i + 10.5),+ "double_dm_p", "" + (i + 10.5),+ "double_dm_p", "" + (i + 20.5),++ "date_dt_t", "180" + i + "-12-31T23:59:59Z",+ "date_dtm_t", "180" + i + "-12-31T23:59:59Z",+ "date_dtm_t", "18" + (i + 10) + "-12-31T23:59:59Z",+ "date_dtm_t", "18" + (i + 10) + "-12-31T23:59:59Z",+ "date_dtm_t", "18" + (i + 20) + "-12-31T23:59:59Z",++ "date_dt_p", "180" + i + "-12-31T23:59:59Z",+ "date_dtm_p", "180" + i + "-12-31T23:59:59Z",+ "date_dtm_p", "18" + (i + 10) + "-12-31T23:59:59Z",+ "date_dtm_p", "18" + (i + 10) + "-12-31T23:59:59Z",+ "date_dtm_p", "18" + (i + 20) + "-12-31T23:59:59Z",++ "string_s", "abc" + i,+ "string_sm", "abc" + i,+ "string_sm", "def" + i,+ "string_sm", "def" + i,+ "string_sm", "ghi" + i,++ "boolean_b", Boolean.toString(i % 3 == 0),+ "boolean_bm", "false",+ "boolean_bm", "true",+ "boolean_bm", "false"+ ));++ singleInts.put(""+i, i);+ Map<Integer, Integer> ints = new HashMap<>();+ ints.put(i, 1);+ ints.put(i + 10, 2);+ ints.put(i + 20, 1);+ multiInts.put(""+i, ints);++ singleLongs.put(""+i, (long) i);+ Map<Long, Integer> longs = new HashMap<>();+ longs.put((long) i, 1);+ longs.put(i + 10L, 2);+ longs.put(i + 20L, 1);+ multiLongs.put(""+i, longs);++ singleFloats.put(""+i, i + .75F);+ Map<Float, Integer> floats = new HashMap<>();+ floats.put(i + .75F, 1);+ floats.put(i + 10.75F, 2);+ floats.put(i + 20.75F, 1);+ multiFloats.put(""+i, floats);++ singleDoubles.put(""+i, i + .5);+ Map<Double, Integer> doubles = new HashMap<>();+ doubles.put(i + .5, 1);+ doubles.put(i + 10.5, 2);+ doubles.put(i + 20.5, 1);+ multiDoubles.put(""+i, doubles);++ singleDates.put(""+i, Instant.parse("180" + i + "-12-31T23:59:59Z").toEpochMilli());+ Map<Long, Integer> dates = new HashMap<>();+ dates.put(Instant.parse("180" + i + "-12-31T23:59:59Z").toEpochMilli(), 1);+ dates.put(Instant.parse("18" + ( i + 10 ) + "-12-31T23:59:59Z").toEpochMilli(), 2);+ dates.put(Instant.parse("18" + ( i + 20 ) + "-12-31T23:59:59Z").toEpochMilli(), 1);+ multiDates.put(""+i, dates);++ singleStrings.put(""+i, "abc" + i);+ Map<String, Integer> strings = new HashMap<>();+ strings.put("abc" + i, 1);+ strings.put("def" + i, 2);+ strings.put("ghi" + i, 1);+ multiStrings.put(""+i, strings);++ singleBooleans.put(""+i, i % 3 == 0);+ Map<Boolean, Integer> booleans = new HashMap<>();+ booleans.put(true, 1);+ booleans.put(false, 2);+ multiBooleans.put(""+i, booleans);+ }+ assertU(commit());++ ref = h.getCore().getSearcher();+ searcher = ref.get();++ indexSchema = h.getCore().getLatestSchema();+ }++ protected ExpressionFactory getExpressionFactory() {+ ExpressionFactory fact = new ExpressionFactory(indexSchema);+ fact.startRequest();+ return fact;+ }++ @AfterClass+ public static void closeSearcher() throws IOException {+ ref.decref();+ }++ protected <T> void checkSingleFieldValues(Map<String,T> expected, Map<String,T> found, Set<String> missing) {+ expected.forEach( (id, value) -> {+ assertTrue("Field does not contain value for id '" + id + "'.", found.containsKey(id));+ assertEquals(value, found.get(id));+ });+ assertEquals(expected.size(), found.size());++ missingDocuments.forEach( id -> assertTrue("Field does not have correct information for missing id '" + id + "'.", missing.contains(id)));+ assertEquals(missingDocuments.size(), missing.size());+ }++ protected <T> void checkMultiFieldValues(Map<String,Map<T,Integer>> expected, Map<String,Map<T,Integer>> found, Set<String> missing, boolean deduplicated) {+ expected.forEach( (id, expectedValues) -> {+ assertTrue("Field does not contain values for id '" + id + "'.", found.containsKey(id));+ Map<T,Integer> foundValues = found.get(id);+ expectedValues.forEach( (value, count) -> {+ assertTrue("Value '" + value + "' not found for document with id '" + id + "'.", foundValues.containsKey(value));+ if (deduplicated) {+ assertEquals(1, foundValues.get(value).intValue());+ } else {+ assertEquals(count, foundValues.get(value));+ }+ });+ assertEquals(expectedValues.size(), foundValues.size());+ });+ assertEquals(expected.size(), found.size());++ missingDocuments.forEach( id -> assertTrue("Field does not have correct information for missing id '" + id + "'.", missing.contains(id)));+ assertEquals(missingDocuments.size(), missing.size());+ }++ protected boolean emptyValueFound;++ protected Set<String> collectFieldValues(AnalyticsField testField, Predicate<String> valuesFiller) throws IOException {+ StringField idField = new StringField("id");+ Filter filter = new QueryWrapperFilter(new MatchAllDocsQuery());+ Set<String> missing = new HashSet<>();++ List<LeafReaderContext> contexts = searcher.getTopReaderContext().leaves();+ for (int leafNum = 0; leafNum < contexts.size(); leafNum++) {+ LeafReaderContext context = contexts.get(leafNum);+ DocIdSet dis = filter.getDocIdSet(context, null); // solr docsets already exclude any deleted docs+ if (dis == null) {+ continue;+ }+ DocIdSetIterator disi = dis.iterator();+ if (disi != null) {+ testField.doSetNextReader(context);+ idField.doSetNextReader(context);+ int doc = disi.nextDoc();+ while( doc != DocIdSetIterator.NO_MORE_DOCS){+ // Add a document to the statistics being generated+ testField.collect(doc);+ idField.collect(doc);++ String id = idField.getString();+ if (!valuesFiller.test(id)) {+ missing.add(id);+ }+ doc = disi.nextDoc();+ }+ }+ }+ return missing;+ }+}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/BooleanFieldsTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/BooleanFieldsTest.javanew file mode 100644index 00000000000..4c3b79fa692--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/BooleanFieldsTest.java@@ -0,0 +1,71 @@+/*+ * 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.analytics.function.field;++import java.io.IOException;+import java.util.HashMap;+import java.util.Map;+import java.util.Set;++import org.apache.solr.analytics.ExpressionFactory;+import org.junit.Test;++public class BooleanFieldsTest extends AbstractAnalyticsFieldTest {++ @Test+ public void expressionFactoryCreationTest() {+ ExpressionFactory fact = getExpressionFactory();++ assertTrue(fact.createExpression("boolean_b") instanceof BooleanField);+ assertTrue(fact.createExpression("boolean_bm") instanceof BooleanMultiField);+ }++ @Test+ public void singleValuedBooleanTest() throws IOException {+ BooleanField valueField = new BooleanField("boolean_b");+ Map<String,Boolean> values = new HashMap<>();++ Set<String> missing = collectFieldValues(valueField, id -> {+ boolean value = valueField.getBoolean();+ if (valueField.exists()) {+ values.put(id, value);+ }+ return valueField.exists();+ });++ checkSingleFieldValues(singleBooleans, values, missing);+ }++ @Test+ public void multiValuedBooleanTest() throws IOException {+ BooleanMultiField valueField = new BooleanMultiField("boolean_bm");+ Map<String,Map<Boolean,Integer>> values = new HashMap<>();++ Set<String> missing = collectFieldValues(valueField, id -> {+ Map<Boolean, Integer> doc = new HashMap<>();+ valueField.streamBooleans( value -> {+ doc.put(value, doc.getOrDefault(value, 0) + 1);+ });+ if (doc.size() > 0) {+ values.put(id, doc);+ }+ return doc.size() > 0;+ });++ checkMultiFieldValues(multiBooleans, values, missing, true);+ }+}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/DateFieldsTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/DateFieldsTest.javanew file mode 100644index 00000000000..88356dc61ae--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/DateFieldsTest.java@@ -0,0 +1,108 @@+/*+ * 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.analytics.function.field;++import java.io.IOException;+import java.util.HashMap;+import java.util.Map;+import java.util.Set;++import org.apache.solr.analytics.ExpressionFactory;+import org.junit.Test;++public class DateFieldsTest extends AbstractAnalyticsFieldTest {++ @Test+ public void expressionFactoryCreationTest() {+ ExpressionFactory fact = getExpressionFactory();++ assertTrue(fact.createExpression("date_dt_t") instanceof DateField);+ assertTrue(fact.createExpression("date_dt_p") instanceof DateField);+ assertTrue(fact.createExpression("date_dtm_t") instanceof DateMultiTrieField);+ assertTrue(fact.createExpression("date_dtm_p") instanceof DateMultiPointField);+ }++ @Test+ public void singleValuedTrieDateTest() throws IOException {+ DateField valueField = new DateField("date_dt_t");+ Map<String,Long> values = new HashMap<>();++ Set<String> missing = collectFieldValues(valueField, id -> {+ long value = valueField.getLong();+ if (valueField.exists()) {+ values.put(id, value);+ }+ return valueField.exists();+ });++ checkSingleFieldValues(singleDates, values, missing);+ }++ @Test+ public void singleValuedPointDateTest() throws IOException {+ DateField valueField = new DateField("date_dt_p");+ Map<String,Long> values = new HashMap<>();++ Set<String> missing = collectFieldValues(valueField, id -> {+ long value = valueField.getLong();+ if (valueField.exists()) {+ values.put(id, value);+ }+ return valueField.exists();+ });++ checkSingleFieldValues(singleDates, values, missing);+ }++ @Test+ public void multiValuedTrieDateTest() throws IOException {+ DateMultiTrieField valueField = new DateMultiTrieField("date_dtm_t");+ Map<String,Map<Long,Integer>> values = new HashMap<>();++ Set<String> missing = collectFieldValues(valueField, id -> {+ Map<Long, Integer> doc = new HashMap<>();+ valueField.streamLongs( value -> {+ doc.put(value, doc.getOrDefault(value, 0) + 1);+ });+ if (doc.size() > 0) {+ values.put(id, doc);+ }+ return doc.size() > 0;+ });++ checkMultiFieldValues(multiDates, values, missing, true);+ }++ @Test+ public void multiValuedPointDateTest() throws IOException {+ DateMultiPointField valueField = new DateMultiPointField("date_dtm_p");+ Map<String,Map<Long,Integer>> values = new HashMap<>();++ Set<String> missing = collectFieldValues(valueField, id -> {+ Map<Long, Integer> doc = new HashMap<>();+ valueField.streamLongs( value -> {+ doc.put(value, doc.getOrDefault(value, 0) + 1);+ });+ if (doc.size() > 0) {+ values.put(id, doc);+ }+ return doc.size() > 0;+ });++ checkMultiFieldValues(multiDates, values, missing, false);+ }+}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/DoubleFieldsTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/DoubleFieldsTest.javanew file mode 100644index 00000000000..c668b0da104--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/DoubleFieldsTest.java@@ -0,0 +1,108 @@+/*+ * 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.analytics.function.field;++import java.io.IOException;+import java.util.HashMap;+import java.util.Map;+import java.util.Set;++import org.apache.solr.analytics.ExpressionFactory;+import org.junit.Test;++public class DoubleFieldsTest extends AbstractAnalyticsFieldTest {++ @Test+ public void expressionFactoryCreationTest() {+ ExpressionFactory fact = getExpressionFactory();++ assertTrue(fact.createExpression("double_d_t") instanceof DoubleField);+ assertTrue(fact.createExpression("double_d_p") instanceof DoubleField);+ assertTrue(fact.createExpression("double_dm_t") instanceof DoubleMultiTrieField);+ assertTrue(fact.createExpression("double_dm_p") instanceof DoubleMultiPointField);+ }++ @Test+ public void singleValuedTrieDoubleTest() throws IOException {+ DoubleField valueField = new DoubleField("double_d_t");+ Map<String,Double> values = new HashMap<>();++ Set<String> missing = collectFieldValues(valueField, id -> {+ double value = valueField.getDouble();+ if (valueField.exists()) {+ values.put(id, value);+ }+ return valueField.exists();+ });++ checkSingleFieldValues(singleDoubles, values, missing);+ }++ @Test+ public void singleValuedPointDoubleTest() throws IOException {+ DoubleField valueField = new DoubleField("double_d_p");+ Map<String,Double> values = new HashMap<>();++ Set<String> missing = collectFieldValues(valueField, id -> {+ double value = valueField.getDouble();+ if (valueField.exists()) {+ values.put(id, value);+ }+ return valueField.exists();+ });++ checkSingleFieldValues(singleDoubles, values, missing);+ }++ @Test+ public void multiValuedTrieDoubleTest() throws IOException {+ DoubleMultiTrieField valueField = new DoubleMultiTrieField("double_dm_t");+ Map<String,Map<Double,Integer>> values = new HashMap<>();++ Set<String> missing = collectFieldValues(valueField, id -> {+ Map<Double, Integer> doc = new HashMap<>();+ valueField.streamDoubles( value -> {+ doc.put(value, doc.getOrDefault(value, 0) + 1);+ });+ if (doc.size() > 0) {+ values.put(id, doc);+ }+ return doc.size() > 0;+ });++ checkMultiFieldValues(multiDoubles, values, missing, true);+ }++ @Test+ public void multiValuedPointDoubleTest() throws IOException {+ DoubleMultiPointField valueField = new DoubleMultiPointField("double_dm_p");+ Map<String,Map<Double,Integer>> values = new HashMap<>();++ Set<String> missing = collectFieldValues(valueField, id -> {+ Map<Double, Integer> doc = new HashMap<>();+ valueField.streamDoubles( value -> {+ doc.put(value, doc.getOrDefault(value, 0) + 1);+ });+ if (doc.size() > 0) {+ values.put(id, doc);+ }+ return doc.size() > 0;+ });++ checkMultiFieldValues(multiDoubles, values, missing, false);+ }+}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/FloatFieldsTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/FloatFieldsTest.javanew file mode 100644index 00000000000..b1aead68f71--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/FloatFieldsTest.java@@ -0,0 +1,108 @@+/*+ * 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.analytics.function.field;++import java.io.IOException;+import java.util.HashMap;+import java.util.Map;+import java.util.Set;++import org.apache.solr.analytics.ExpressionFactory;+import org.junit.Test;++public class FloatFieldsTest extends AbstractAnalyticsFieldTest {++ @Test+ public void expressionFactoryCreationTest() {+ ExpressionFactory fact = getExpressionFactory();++ assertTrue(fact.createExpression("float_f_t") instanceof FloatField);+ assertTrue(fact.createExpression("float_f_p") instanceof FloatField);+ assertTrue(fact.createExpression("float_fm_t") instanceof FloatMultiTrieField);+ assertTrue(fact.createExpression("float_fm_p") instanceof FloatMultiPointField);+ }++ @Test+ public void singleValuedTrieFloatTest() throws IOException {+ FloatField valueField = new FloatField("float_f_t");+ Map<String,Float> values = new HashMap<>();++ Set<String> missing = collectFieldValues(valueField, id -> {+ float value = valueField.getFloat();+ if (valueField.exists()) {+ values.put(id, value);+ }+ return valueField.exists();+ });++ checkSingleFieldValues(singleFloats, values, missing);+ }++ @Test+ public void singleValuedPointFloatTest() throws IOException {+ FloatField valueField = new FloatField("float_f_p");+ Map<String,Float> values = new HashMap<>();++ Set<String> missing = collectFieldValues(valueField, id -> {+ float value = valueField.getFloat();+ if (valueField.exists()) {+ values.put(id, value);+ }+ return valueField.exists();+ });++ checkSingleFieldValues(singleFloats, values, missing);+ }++ @Test+ public void multiValuedTrieFloatTest() throws IOException {+ FloatMultiTrieField valueField = new FloatMultiTrieField("float_fm_t");+ Map<String,Map<Float,Integer>> values = new HashMap<>();++ Set<String> missing = collectFieldValues(valueField, id -> {+ Map<Float, Integer> doc = new HashMap<>();+ valueField.streamFloats( value -> {+ doc.put(value, doc.getOrDefault(value, 0) + 1);+ });+ if (doc.size() > 0) {+ values.put(id, doc);+ }+ return doc.size() > 0;+ });++ checkMultiFieldValues(multiFloats, values, missing, true);+ }++ @Test+ public void multiValuedPointFloatTest() throws IOException {+ FloatMultiPointField valueField = new FloatMultiPointField("float_fm_p");+ Map<String,Map<Float,Integer>> values = new HashMap<>();++ Set<String> missing = collectFieldValues(valueField, id -> {+ Map<Float, Integer> doc = new HashMap<>();+ valueField.streamFloats( value -> {+ doc.put(value, doc.getOrDefault(value, 0) + 1);+ });+ if (doc.size() > 0) {+ values.put(id, doc);+ }+ return doc.size() > 0;+ });++ checkMultiFieldValues(multiFloats, values, missing, false);+ }+}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/IntFieldsTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/IntFieldsTest.javanew file mode 100644index 00000000000..014d9d18c6d--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/IntFieldsTest.java@@ -0,0 +1,108 @@+/*+ * 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.analytics.function.field;++import java.io.IOException;+import java.util.HashMap;+import java.util.Map;+import java.util.Set;++import org.apache.solr.analytics.ExpressionFactory;+import org.junit.Test;++public class IntFieldsTest extends AbstractAnalyticsFieldTest {++ @Test+ public void expressionFactoryCreationTest() {+ ExpressionFactory fact = getExpressionFactory();++ assertTrue(fact.createExpression("int_i_t") instanceof IntField);+ assertTrue(fact.createExpression("int_i_p") instanceof IntField);+ assertTrue(fact.createExpression("int_im_t") instanceof IntMultiTrieField);+ assertTrue(fact.createExpression("int_im_p") instanceof IntMultiPointField);+ }++ @Test+ public void singleValuedTrieIntTest() throws IOException {+ IntField valueField = new IntField("int_i_t");+ Map<String,Integer> values = new HashMap<>();++ Set<String> missing = collectFieldValues(valueField, id -> {+ int value = valueField.getInt();+ if (valueField.exists()) {+ values.put(id, value);+ }+ return valueField.exists();+ });++ checkSingleFieldValues(singleInts, values, missing);+ }++ @Test+ public void singleValuedPointIntTest() throws IOException {+ IntField valueField = new IntField("int_i_p");+ Map<String,Integer> values = new HashMap<>();++ Set<String> missing = collectFieldValues(valueField, id -> {+ int value = valueField.getInt();+ if (valueField.exists()) {+ values.put(id, value);+ }+ return valueField.exists();+ });++ checkSingleFieldValues(singleInts, values, missing);+ }++ @Test+ public void multiValuedTrieIntTest() throws IOException {+ IntMultiTrieField valueField = new IntMultiTrieField("int_im_t");+ Map<String,Map<Integer,Integer>> values = new HashMap<>();++ Set<String> missing = collectFieldValues(valueField, id -> {+ Map<Integer, Integer> doc = new HashMap<>();+ valueField.streamInts( value -> {+ doc.put(value, doc.getOrDefault(value, 0) + 1);+ });+ if (doc.size() > 0) {+ values.put(id, doc);+ }+ return doc.size() > 0;+ });++ checkMultiFieldValues(multiInts, values, missing, true);+ }++ @Test+ public void multiValuedPointIntTest() throws IOException {+ IntMultiPointField valueField = new IntMultiPointField("int_im_p");+ Map<String,Map<Integer,Integer>> values = new HashMap<>();++ Set<String> missing = collectFieldValues(valueField, id -> {+ Map<Integer, Integer> doc = new HashMap<>();+ valueField.streamInts( value -> {+ doc.put(value, doc.getOrDefault(value, 0) + 1);+ });+ if (doc.size() > 0) {+ values.put(id, doc);+ }+ return doc.size() > 0;+ });++ checkMultiFieldValues(multiInts, values, missing, false);+ }+}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/LongFieldsTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/LongFieldsTest.javanew file mode 100644index 00000000000..d1fc6b8e9ae--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/LongFieldsTest.java@@ -0,0 +1,108 @@+/*+ * 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.analytics.function.field;++import java.io.IOException;+import java.util.HashMap;+import java.util.Map;+import java.util.Set;++import org.apache.solr.analytics.ExpressionFactory;+import org.junit.Test;++public class LongFieldsTest extends AbstractAnalyticsFieldTest {++ @Test+ public void expressionFactoryCreationTest() {+ ExpressionFactory fact = getExpressionFactory();++ assertTrue(fact.createExpression("long_l_t") instanceof LongField);+ assertTrue(fact.createExpression("long_l_p") instanceof LongField);+ assertTrue(fact.createExpression("long_lm_t") instanceof LongMultiTrieField);+ assertTrue(fact.createExpression("long_lm_p") instanceof LongMultiPointField);+ }++ @Test+ public void singleValuedTrieLongTest() throws IOException {+ LongField valueField = new LongField("long_l_t");+ Map<String,Long> values = new HashMap<>();++ Set<String> missing = collectFieldValues(valueField, id -> {+ long value = valueField.getLong();+ if (valueField.exists()) {+ values.put(id, value);+ }+ return valueField.exists();+ });++ checkSingleFieldValues(singleLongs, values, missing);+ }++ @Test+ public void singleValuedPointLongTest() throws IOException {+ LongField valueField = new LongField("long_l_p");+ Map<String,Long> values = new HashMap<>();++ Set<String> missing = collectFieldValues(valueField, id -> {+ long value = valueField.getLong();+ if (valueField.exists()) {+ values.put(id, value);+ }+ return valueField.exists();+ });++ checkSingleFieldValues(singleLongs, values, missing);+ }++ @Test+ public void multiValuedTrieLongTest() throws IOException {+ LongMultiTrieField valueField = new LongMultiTrieField("long_lm_t");+ Map<String,Map<Long,Integer>> values = new HashMap<>();++ Set<String> missing = collectFieldValues(valueField, id -> {+ Map<Long, Integer> doc = new HashMap<>();+ valueField.streamLongs( value -> {+ doc.put(value, doc.getOrDefault(value, 0) + 1);+ });+ if (doc.size() > 0) {+ values.put(id, doc);+ }+ return doc.size() > 0;+ });++ checkMultiFieldValues(multiLongs, values, missing, true);+ }++ @Test+ public void multiValuedPointLongTest() throws IOException {+ LongMultiPointField valueField = new LongMultiPointField("long_lm_p");+ Map<String,Map<Long,Integer>> values = new HashMap<>();++ Set<String> missing = collectFieldValues(valueField, id -> {+ Map<Long, Integer> doc = new HashMap<>();+ valueField.streamLongs( value -> {+ doc.put(value, doc.getOrDefault(value, 0) + 1);+ });+ if (doc.size() > 0) {+ values.put(id, doc);+ }+ return doc.size() > 0;+ });++ checkMultiFieldValues(multiLongs, values, missing, false);+ }+}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/StringFieldsTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/StringFieldsTest.javanew file mode 100644index 00000000000..152a0092fd9--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/StringFieldsTest.java@@ -0,0 +1,71 @@+/*+ * 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.analytics.function.field;++import java.io.IOException;+import java.util.HashMap;+import java.util.Map;+import java.util.Set;++import org.apache.solr.analytics.ExpressionFactory;+import org.junit.Test;++public class StringFieldsTest extends AbstractAnalyticsFieldTest {++ @Test+ public void expressionFactoryCreationTest() {+ ExpressionFactory fact = getExpressionFactory();++ assertTrue(fact.createExpression("string_s") instanceof StringField);+ assertTrue(fact.createExpression("string_sm") instanceof StringMultiField);+ }++ @Test+ public void singleValuedStringTest() throws IOException {+ StringField valueField = new StringField("string_s");+ Map<String,String> values = new HashMap<>();++ Set<String> missing = collectFieldValues(valueField, id -> {+ String value = valueField.getString();+ if (valueField.exists()) {+ values.put(id, value);+ }+ return valueField.exists();+ });++ checkSingleFieldValues(singleStrings, values, missing);+ }++ @Test+ public void multiValuedStringTest() throws IOException {+ StringMultiField valueField = new StringMultiField("string_sm");+ Map<String,Map<String,Integer>> values = new HashMap<>();++ Set<String> missing = collectFieldValues(valueField, id -> {+ Map<String, Integer> doc = new HashMap<>();+ valueField.streamStrings( value -> {+ doc.put(value, doc.getOrDefault(value, 0) + 1);+ });+ if (doc.size() > 0) {+ values.put(id, doc);+ }+ return doc.size() > 0;+ });++ checkMultiFieldValues(multiStrings, values, missing, true);+ }+}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/AbsoluteValueFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/AbsoluteValueFunctionTest.javanew file mode 100644index 00000000000..9996c28b25b--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/AbsoluteValueFunctionTest.java@@ -0,0 +1,267 @@+/*+ * 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.analytics.function.mapping;++import java.util.Arrays;+import java.util.Iterator;++import org.apache.solr.SolrTestCaseJ4;+import org.apache.solr.analytics.value.AnalyticsValueStream;+import org.apache.solr.analytics.value.DoubleValue;+import org.apache.solr.analytics.value.DoubleValueStream;+import org.apache.solr.analytics.value.FloatValue;+import org.apache.solr.analytics.value.FloatValueStream;+import org.apache.solr.analytics.value.IntValue;+import org.apache.solr.analytics.value.IntValueStream;+import org.apache.solr.analytics.value.LongValue;+import org.apache.solr.analytics.value.LongValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValue;+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValue;+import org.apache.solr.analytics.value.FillableTestValue.TestIntValue;+import org.apache.solr.analytics.value.FillableTestValue.TestLongValue;+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestIntValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestLongValueStream;+import org.junit.Test;++public class AbsoluteValueFunctionTest extends SolrTestCaseJ4 {++ @Test+ public void singleValueIntTest() {+ TestIntValue val = new TestIntValue();++ AnalyticsValueStream uncasted = AbsoluteValueFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});+ assertTrue(uncasted instanceof IntValue);+ IntValue func = (IntValue) uncasted;++ // Value doesn't exist+ val.setExists(false);+ func.getInt();+ assertFalse(func.exists());++ // Value exists+ val.setValue(21).setExists(true);+ assertEquals(21, func.getInt());+ assertTrue(func.exists());++ val.setValue(-100).setExists(true);+ assertEquals(100, func.getInt());+ assertTrue(func.exists());+ }++ @Test+ public void singleValueLongTest() {+ TestLongValue val = new TestLongValue();++ AnalyticsValueStream uncasted = AbsoluteValueFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});+ assertTrue(uncasted instanceof LongValue);+ LongValue func = (LongValue) uncasted;++ // Value doesn't exist+ val.setExists(false);+ func.getLong();+ assertFalse(func.exists());++ // Value exists+ val.setValue(21L).setExists(true);+ assertEquals(21L, func.getLong());+ assertTrue(func.exists());++ val.setValue(-100L).setExists(true);+ assertEquals(100L, func.getLong());+ assertTrue(func.exists());+ }++ @Test+ public void singleValueFloatTest() {+ TestFloatValue val = new TestFloatValue();++ AnalyticsValueStream uncasted = AbsoluteValueFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});+ assertTrue(uncasted instanceof FloatValue);+ FloatValue func = (FloatValue) uncasted;++ // Value doesn't exist+ val.setExists(false);+ func.getFloat();+ assertFalse(func.exists());++ // Value exists+ val.setValue(21.56F).setExists(true);+ assertEquals(21.56F, func.getFloat(), 0.00001);+ assertTrue(func.exists());++ val.setValue(-100F).setExists(true);+ assertEquals(100F, func.getFloat(), 0.00001);+ assertTrue(func.exists());+ }++ @Test+ public void singleValueDoubleTest() {+ TestDoubleValue val = new TestDoubleValue();++ AnalyticsValueStream uncasted = AbsoluteValueFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});+ assertTrue(uncasted instanceof DoubleValue);+ DoubleValue func = (DoubleValue) uncasted;++ // Value doesn't exist+ val.setExists(false);+ func.getDouble();+ assertFalse(func.exists());++ // Value exists+ val.setValue(21.56).setExists(true);+ assertEquals(21.56, func.getDouble(), 0.00001);+ assertTrue(func.exists());++ val.setValue(-100.1).setExists(true);+ assertEquals(100.1, func.getDouble(), 0.00001);+ assertTrue(func.exists());+ }++ @Test+ public void multiValueIntTest() {+ TestIntValueStream val = new TestIntValueStream();++ AnalyticsValueStream uncasted = AbsoluteValueFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});+ assertTrue(uncasted instanceof IntValueStream);+ IntValueStream func = (IntValueStream) uncasted;++ // No values+ val.setValues();+ func.streamInts( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // One value+ val.setValues(-4);+ Iterator<Integer> values1 = Arrays.asList(4).iterator();+ func.streamInts( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next().intValue(), value);+ });+ assertFalse(values1.hasNext());++ // Multiple values+ val.setValues(4, -10, 50, -74);+ Iterator<Integer> values2 = Arrays.asList(4, 10, 50, 74).iterator();+ func.streamInts( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next().intValue(), value);+ });+ assertFalse(values2.hasNext());+ }++ @Test+ public void multiValueLongTest() {+ TestLongValueStream val = new TestLongValueStream();++ AnalyticsValueStream uncasted = AbsoluteValueFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});+ assertTrue(uncasted instanceof LongValueStream);+ LongValueStream func = (LongValueStream) uncasted;++ // No values+ val.setValues();+ func.streamLongs( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // One value+ val.setValues(-4L);+ Iterator<Long> values1 = Arrays.asList(4L).iterator();+ func.streamLongs( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next().longValue(), value);+ });+ assertFalse(values1.hasNext());++ // Multiple values+ val.setValues(4L, -10L, 50L, -74L);+ Iterator<Long> values2 = Arrays.asList(4L, 10L, 50L, 74L).iterator();+ func.streamLongs( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next().longValue(), value);+ });+ assertFalse(values2.hasNext());+ }++ @Test+ public void multiValueFloatTest() {+ TestFloatValueStream val = new TestFloatValueStream();++ AnalyticsValueStream uncasted = AbsoluteValueFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});+ assertTrue(uncasted instanceof FloatValueStream);+ FloatValueStream func = (FloatValueStream) uncasted;++ // No values+ val.setValues();+ func.streamFloats( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // One value+ val.setValues(-4.3F);+ Iterator<Float> values1 = Arrays.asList(4.3F).iterator();+ func.streamFloats( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value, .000001);+ });+ assertFalse(values1.hasNext());++ // Multiple values+ val.setValues(4.3F, -10F, 50.75F, -74.4446F);+ Iterator<Float> values2 = Arrays.asList(4.3F, 10F, 50.75F, 74.4446F).iterator();+ func.streamFloats( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value, .000001);+ });+ assertFalse(values2.hasNext());+ }++ @Test+ public void multiValueDoubleTest() {+ TestDoubleValueStream val = new TestDoubleValueStream();++ AnalyticsValueStream uncasted = AbsoluteValueFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});+ assertTrue(uncasted instanceof DoubleValueStream);+ DoubleValueStream func = (DoubleValueStream) uncasted;++ // No values+ val.setValues();+ func.streamDoubles( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // One value+ val.setValues(-4.3);+ Iterator<Double> values1 = Arrays.asList(4.3).iterator();+ func.streamDoubles( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value, .000001);+ });+ assertFalse(values1.hasNext());++ // Multiple values+ val.setValues(4.3, -10, 50.75, -74.4446);+ Iterator<Double> values2 = Arrays.asList(4.3, 10.0, 50.75, 74.4446).iterator();+ func.streamDoubles( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value, .000001);+ });+ assertFalse(values2.hasNext());+ }+}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/AddFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/AddFunctionTest.javanew file mode 100644index 00000000000..87b80cbabfc--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/AddFunctionTest.java@@ -0,0 +1,156 @@+/*+ * 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.analytics.function.mapping;++import java.util.Arrays;+import java.util.Iterator;++import org.apache.solr.SolrTestCaseJ4;+import org.apache.solr.analytics.value.AnalyticsValueStream;+import org.apache.solr.analytics.value.DoubleValue;+import org.apache.solr.analytics.value.DoubleValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValue;+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValue;+import org.apache.solr.analytics.value.FillableTestValue.TestIntValue;+import org.apache.solr.analytics.value.FillableTestValue.TestLongValue;+import org.apache.solr.analytics.value.FillableTestValue.TestLongValueStream;+import org.junit.Test;++public class AddFunctionTest extends SolrTestCaseJ4 {++ @Test+ public void twoSingleValueParametersTest() {+ TestIntValue val1 = new TestIntValue();+ TestFloatValue val2 = new TestFloatValue();++ AnalyticsValueStream uncasted = AddFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2});+ assertTrue(uncasted instanceof DoubleValue);+ DoubleValue func = (DoubleValue) uncasted;++ // Neither exists+ val1.setExists(false);+ val2.setExists(false);+ func.getDouble();+ assertFalse(func.exists());++ // One exists+ val1.setValue(30).setExists(true);+ val2.setExists(false);+ func.getDouble();+ assertFalse(func.exists());++ // Both exist+ val1.setValue(30).setExists(true);+ val2.setValue(21.56F).setExists(true);+ assertEquals(51.56, func.getDouble(), 0.000001);+ assertTrue(func.exists());+ }++ @Test+ public void oneMultiValueParameterTest() {+ TestLongValueStream val = new TestLongValueStream();++ AnalyticsValueStream uncasted = AddFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});+ assertTrue(uncasted instanceof DoubleValue);+ DoubleValue func = (DoubleValue) uncasted;++ // No values+ val.setValues();+ func.getDouble();+ assertFalse(func.exists());++ // One value+ val.setValues(30L);+ assertEquals(30, func.getDouble(), 0.000001);+ assertTrue(func.exists());++ // Multiple values+ val.setValues(30L, 20L, 55L, 61L);+ assertEquals(166, func.getDouble(), 0.000001);+ assertTrue(func.exists());+ }++ @Test+ public void oneMultiOneSingleValueParameterTest() {+ TestLongValueStream val1 = new TestLongValueStream();+ TestDoubleValue val2 = new TestDoubleValue();++ AnalyticsValueStream uncasted = AddFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2});+ assertTrue(uncasted instanceof DoubleValueStream);+ DoubleValueStream func = (DoubleValueStream) uncasted;++ // No values, One value+ val1.setValues();+ val2.setValue(21.56F).setExists(true);+ func.streamDoubles( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple values, no value+ val1.setValues(4L, 10023L);+ val2.setExists(false);+ func.streamDoubles( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple values, one value+ val1.setValues(4L, 10023L, 48L);+ val2.setValue(21.56F).setExists(true);+ Iterator<Double> values = Arrays.asList(25.56, 10044.56, 69.56).iterator();+ func.streamDoubles( value -> {+ assertTrue(values.hasNext());+ assertEquals(values.next(), value, 0.000001);+ });+ assertFalse(values.hasNext());+ }++ @Test+ public void multipleSingleValueParameterTest() {+ TestLongValue val1 = new TestLongValue();+ TestDoubleValue val2 = new TestDoubleValue();+ TestFloatValue val3 = new TestFloatValue();+ TestIntValue val4 = new TestIntValue();++ AnalyticsValueStream uncasted = AddFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2, val3, val4});+ assertTrue(uncasted instanceof DoubleValue);+ DoubleValue func = (DoubleValue) uncasted;++ // None exist+ val1.setExists(false);+ val2.setExists(false);+ val3.setExists(false);+ val4.setExists(false);+ func.getDouble();+ assertFalse(func.exists());++ // Some exist+ val1.setExists(false);+ val2.setValue(30.56).setExists(true);+ val3.setExists(false);+ val4.setValue(12).setExists(true);+ func.getDouble();+ assertFalse(func.exists());++ // All exist values, one value+ val1.setValue(45L).setExists(true);+ val2.setValue(30.56).setExists(true);+ val3.setValue(2.5F).setExists(true);+ val4.setValue(12).setExists(true);+ assertEquals(90.06, func.getDouble(), 0.000001);+ assertTrue(func.exists());+ }+}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/AndFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/AndFunctionTest.javanew file mode 100644index 00000000000..d2e9a1bcae8--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/AndFunctionTest.java@@ -0,0 +1,192 @@+/*+ * 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.analytics.function.mapping;++import java.util.Arrays;+import java.util.Iterator;++import org.apache.solr.SolrTestCaseJ4;+import org.apache.solr.analytics.function.mapping.LogicFunction.AndFunction;+import org.apache.solr.analytics.value.AnalyticsValueStream;+import org.apache.solr.analytics.value.BooleanValue;+import org.apache.solr.analytics.value.BooleanValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestBooleanValue;+import org.apache.solr.analytics.value.FillableTestValue.TestBooleanValueStream;+import org.junit.Test;++public class AndFunctionTest extends SolrTestCaseJ4 {+ @Test+ public void twoSingleValueParametersTest() {+ TestBooleanValue val1 = new TestBooleanValue();+ TestBooleanValue val2 = new TestBooleanValue();++ AnalyticsValueStream uncasted = AndFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2});+ assertTrue(uncasted instanceof BooleanValue);+ BooleanValue func = (BooleanValue) uncasted;++ // Neither exists+ val1.setExists(false);+ val2.setExists(false);+ func.getBoolean();+ assertFalse(func.exists());++ // One exists+ val1.setValue(true).setExists(true);+ val2.setExists(false);+ func.getBoolean();+ assertFalse(func.exists());++ // Both exist+ val1.setValue(false).setExists(true);+ val2.setValue(false).setExists(true);+ assertEquals(false, func.getBoolean());+ assertTrue(func.exists());++ val1.setValue(true).setExists(true);+ val2.setValue(false).setExists(true);+ assertEquals(false, func.getBoolean());+ assertTrue(func.exists());++ val1.setValue(false).setExists(true);+ val2.setValue(true).setExists(true);+ assertEquals(false, func.getBoolean());+ assertTrue(func.exists());++ val1.setValue(true).setExists(true);+ val2.setValue(true).setExists(true);+ assertEquals(true, func.getBoolean());+ assertTrue(func.exists());+ }++ @Test+ public void oneMultiValueParameterTest() {+ TestBooleanValueStream val = new TestBooleanValueStream();++ AnalyticsValueStream uncasted = AndFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});+ assertTrue(uncasted instanceof BooleanValue);+ BooleanValue func = (BooleanValue) uncasted;++ // No values+ val.setValues();+ func.getBoolean();+ assertFalse(func.exists());++ // One value+ val.setValues(true);+ assertEquals(true, func.getBoolean());+ assertTrue(func.exists());++ val.setValues(false);+ assertEquals(false, func.getBoolean());+ assertTrue(func.exists());++ // Multiple values+ val.setValues(true, true, false, true);+ assertEquals(false, func.getBoolean());+ assertTrue(func.exists());++ val.setValues(true, true, true);+ assertEquals(true, func.getBoolean());+ assertTrue(func.exists());+ }++ @Test+ public void oneMultiOneSingleValueParameterTest() {+ TestBooleanValue val1 = new TestBooleanValue();+ TestBooleanValueStream val2 = new TestBooleanValueStream();++ AnalyticsValueStream uncasted = AndFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2});+ assertTrue(uncasted instanceof BooleanValueStream);+ BooleanValueStream func = (BooleanValueStream) uncasted;++ // No values, One value+ val1.setValue(false).setExists(true);+ val2.setValues();+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple values, no value+ val1.setExists(false);+ val2.setValues(true, false);+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple values, one value+ val1.setValue(false).setExists(true);+ val2.setValues(true, false, true);+ Iterator<Boolean> values1 = Arrays.asList(false, false, false).iterator();+ func.streamBooleans( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value);+ });+ assertFalse(values1.hasNext());++ val1.setValue(true).setExists(true);+ val2.setValues(true, false, true);+ Iterator<Boolean> values2 = Arrays.asList(true, false, true).iterator();+ func.streamBooleans( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value);+ });+ assertFalse(values2.hasNext());+ }++ @Test+ public void multipleSingleValueParameterTest() {+ TestBooleanValue val1 = new TestBooleanValue();+ TestBooleanValue val2 = new TestBooleanValue();+ TestBooleanValue val3 = new TestBooleanValue();+ TestBooleanValue val4 = new TestBooleanValue();++ AnalyticsValueStream uncasted = AndFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2, val3, val4});+ assertTrue(uncasted instanceof BooleanValue);+ BooleanValue func = (BooleanValue) uncasted;++ // None exist+ val1.setExists(false);+ val2.setExists(false);+ val3.setExists(false);+ val4.setExists(false);+ func.getBoolean();+ assertFalse(func.exists());++ // Some exist+ val1.setExists(false);+ val2.setValue(true).setExists(true);+ val3.setExists(false);+ val4.setValue(false).setExists(true);+ func.getBoolean();+ assertFalse(func.exists());++ // All exist values, one value+ val1.setValue(true).setExists(true);+ val2.setValue(false).setExists(true);+ val3.setValue(true).setExists(true);+ val4.setValue(true).setExists(true);+ assertEquals(false, func.getBoolean());+ assertTrue(func.exists());++ val1.setValue(true).setExists(true);+ val2.setValue(true).setExists(true);+ val3.setValue(true).setExists(true);+ val4.setValue(true).setExists(true);+ assertEquals(true, func.getBoolean());+ assertTrue(func.exists());+ }+}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/BottomFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/BottomFunctionTest.javanew file mode 100644index 00000000000..feb43d845b2--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/BottomFunctionTest.java@@ -0,0 +1,406 @@+/*+ * 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.analytics.function.mapping;++import java.time.Instant;+import java.time.format.DateTimeParseException;+import java.util.Date;++import org.apache.solr.SolrTestCaseJ4;+import org.apache.solr.analytics.value.AnalyticsValueStream;+import org.apache.solr.analytics.value.DateValue;+import org.apache.solr.analytics.value.DoubleValue;+import org.apache.solr.analytics.value.FillableTestValue.TestDateValue;+import org.apache.solr.analytics.value.FillableTestValue.TestDateValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValue;+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValue;+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestIntValue;+import org.apache.solr.analytics.value.FillableTestValue.TestIntValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestLongValue;+import org.apache.solr.analytics.value.FillableTestValue.TestLongValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestStringValue;+import org.apache.solr.analytics.value.FillableTestValue.TestStringValueStream;+import org.apache.solr.analytics.value.FloatValue;+import org.apache.solr.analytics.value.IntValue;+import org.apache.solr.analytics.value.LongValue;+import org.apache.solr.analytics.value.StringValue;+import org.junit.Test;++public class BottomFunctionTest extends SolrTestCaseJ4 {++ @Test+ public void multiValueIntTest() {+ TestIntValueStream val = new TestIntValueStream();++ AnalyticsValueStream uncasted = BottomFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});+ assertTrue(uncasted instanceof IntValue);+ IntValue func = (IntValue) uncasted;++ // Neither exists+ val.setValues();+ func.getInt();+ assertFalse(func.exists());++ // One exists+ val.setValues(30);+ assertEquals(30, func.getInt());+ assertTrue(func.exists());++ // Both exist+ val.setValues(30, 20, -10, 59);+ assertEquals(-10, func.getInt());+ assertTrue(func.exists());+ }++ @Test+ public void multiValueLongTest() {+ TestLongValueStream val = new TestLongValueStream();++ AnalyticsValueStream uncasted = BottomFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});+ assertTrue(uncasted instanceof LongValue);+ LongValue func = (LongValue) uncasted;++ // Neither exists+ val.setValues();+ func.getLong();+ assertFalse(func.exists());++ // One exists+ val.setValues(30L);+ assertEquals(30L, func.getLong());+ assertTrue(func.exists());++ // Both exist+ val.setValues(30L, 20L, -10L, 59L);+ assertEquals(-10L, func.getLong());+ assertTrue(func.exists());+ }++ @Test+ public void multiValueFloatTest() {+ TestFloatValueStream val = new TestFloatValueStream();++ AnalyticsValueStream uncasted = BottomFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});+ assertTrue(uncasted instanceof FloatValue);+ FloatValue func = (FloatValue) uncasted;++ // Neither exists+ val.setValues();+ func.getFloat();+ assertFalse(func.exists());++ // One exists+ val.setValues(30.0F);+ assertEquals(30.0F, func.getFloat(), .000001);+ assertTrue(func.exists());++ // Both exist+ val.setValues(30.5F, 20.01F, -10.49F, -10.48F);+ assertEquals(-10.49F, func.getFloat(), .000001);+ assertTrue(func.exists());+ }++ @Test+ public void multiValueDoubleTest() {+ TestDoubleValueStream val = new TestDoubleValueStream();++ AnalyticsValueStream uncasted = BottomFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});+ assertTrue(uncasted instanceof DoubleValue);+ DoubleValue func = (DoubleValue) uncasted;++ // Neither exists+ val.setValues();+ func.getDouble();+ assertFalse(func.exists());++ // One exists+ val.setValues(30.0);+ assertEquals(30.0, func.getDouble(), .000001);+ assertTrue(func.exists());++ // Both exist+ val.setValues(30.5, 20.01, -10.49, -10.48);+ assertEquals(-10.49, func.getDouble(), .000001);+ assertTrue(func.exists());+ }++ @Test+ public void multiValueDateTest() throws DateTimeParseException {+ TestDateValueStream val = new TestDateValueStream();++ AnalyticsValueStream uncasted = BottomFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});+ assertTrue(uncasted instanceof DateValue);+ DateValue func = (DateValue) uncasted;++ // Neither exists+ val.setValues();+ func.getDate();+ assertFalse(func.exists());++ // One exists+ val.setValues("1950-05-03T10:30:50Z");+ assertEquals(Date.from(Instant.parse("1950-05-03T10:30:50Z")), func.getDate());+ assertTrue(func.exists());++ // Both exist+ val.setValues("1950-05-03T10:30:50Z", "2200-01-01T10:00:50Z", "1800-12-31T11:30:50Z", "1930-05-020T10:45:50Z");+ assertEquals(Date.from(Instant.parse("1800-12-31T11:30:50Z")), func.getDate());+ assertTrue(func.exists());+ }++ @Test+ public void multiValueStringTest() {+ TestStringValueStream val = new TestStringValueStream();++ AnalyticsValueStream uncasted = BottomFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});+ assertTrue(uncasted instanceof StringValue);+ StringValue func = (StringValue) uncasted;++ // Neither exists+ val.setValues();+ func.getString();+ assertFalse(func.exists());++ // One exists+ val.setValues("abc");+ assertEquals("abc", func.getString());+ assertTrue(func.exists());++ // Both exist+ val.setValues("1abcdef", "abc", "def", "1abc");+ assertEquals("1abc", func.getString());+ assertTrue(func.exists());+ }++ @Test+ public void multipleSingleValueIntTest() {+ TestIntValue val1 = new TestIntValue();+ TestIntValue val2 = new TestIntValue();+ TestIntValue val3 = new TestIntValue();+ TestIntValue val4 = new TestIntValue();++ AnalyticsValueStream uncasted = BottomFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2, val3, val4});+ assertTrue(uncasted instanceof IntValue);+ IntValue func = (IntValue) uncasted;++ // None exist+ val1.setExists(false);+ val2.setExists(false);+ val3.setExists(false);+ val4.setExists(false);+ func.getInt();+ assertFalse(func.exists());++ // Some exist+ val1.setValue(1000).setExists(false);+ val2.setValue(30).setExists(true);+ val3.setValue(-1000).setExists(false);+ val4.setValue(12).setExists(true);+ assertEquals(12, func.getInt());+ assertTrue(func.exists());++ // All exist values, one value+ val1.setValue(45).setExists(true);+ val2.setValue(30).setExists(true);+ val3.setValue(-2).setExists(true);+ val4.setValue(12).setExists(true);+ assertEquals(-2, func.getInt());+ assertTrue(func.exists());+ }++ @Test+ public void multipleSingleValueLongTest() {+ TestLongValue val1 = new TestLongValue();+ TestLongValue val2 = new TestLongValue();+ TestLongValue val3 = new TestLongValue();+ TestLongValue val4 = new TestLongValue();++ AnalyticsValueStream uncasted = BottomFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2, val3, val4});+ assertTrue(uncasted instanceof LongValue);+ LongValue func = (LongValue) uncasted;++ // None exist+ val1.setExists(false);+ val2.setExists(false);+ val3.setExists(false);+ val4.setExists(false);+ func.getLong();+ assertFalse(func.exists());++ // Some exist+ val1.setValue(1000L).setExists(false);+ val2.setValue(30L).setExists(true);+ val3.setValue(-1000L).setExists(false);+ val4.setValue(12L).setExists(true);+ assertEquals(12L, func.getLong());+ assertTrue(func.exists());++ // All exist values, one value+ val1.setValue(45L).setExists(true);+ val2.setValue(30L).setExists(true);+ val3.setValue(-2L).setExists(true);+ val4.setValue(12L).setExists(true);+ assertEquals(-2L, func.getLong());+ assertTrue(func.exists());+ }++ @Test+ public void multipleSingleValueFloatTest() {+ TestFloatValue val1 = new TestFloatValue();+ TestFloatValue val2 = new TestFloatValue();+ TestFloatValue val3 = new TestFloatValue();+ TestFloatValue val4 = new TestFloatValue();++ AnalyticsValueStream uncasted = BottomFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2, val3, val4});+ assertTrue(uncasted instanceof FloatValue);+ FloatValue func = (FloatValue) uncasted;++ // None exist+ val1.setExists(false);+ val2.setExists(false);+ val3.setExists(false);+ val4.setExists(false);+ func.getFloat();+ assertFalse(func.exists());++ // Some exist+ val1.setValue(1000.1233F).setExists(false);+ val2.setValue(30.34F).setExists(true);+ val3.setValue(-1000.3241F).setExists(false);+ val4.setValue(12.123F).setExists(true);+ assertEquals(12.123F, func.getFloat(), .000001);+ assertTrue(func.exists());++ // All exist values, one value+ val1.setValue(45.43F).setExists(true);+ val2.setValue(30.231F).setExists(true);+ val3.setValue(-2.33F).setExists(true);+ val4.setValue(12.5F).setExists(true);+ assertEquals(-2.33F, func.getFloat(), .000001);+ assertTrue(func.exists());+ }++ @Test+ public void multipleSingleValueDoubleTest() {+ TestDoubleValue val1 = new TestDoubleValue();+ TestDoubleValue val2 = new TestDoubleValue();+ TestDoubleValue val3 = new TestDoubleValue();+ TestDoubleValue val4 = new TestDoubleValue();++ AnalyticsValueStream uncasted = BottomFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2, val3, val4});+ assertTrue(uncasted instanceof DoubleValue);+ DoubleValue func = (DoubleValue) uncasted;++ // None exist+ val1.setExists(false);+ val2.setExists(false);+ val3.setExists(false);+ val4.setExists(false);+ func.getDouble();+ assertFalse(func.exists());++ // Some exist+ val1.setValue(1000.1233).setExists(false);+ val2.setValue(30.34).setExists(true);+ val3.setValue(-1000.3241).setExists(false);+ val4.setValue(12.123).setExists(true);+ assertEquals(12.123, func.getDouble(), .000001);+ assertTrue(func.exists());++ // All exist values, one value+ val1.setValue(45.43).setExists(true);+ val2.setValue(30.231).setExists(true);+ val3.setValue(-2.33).setExists(true);+ val4.setValue(12.5).setExists(true);+ assertEquals(-2.33, func.getDouble(), .000001);+ assertTrue(func.exists());+ }++ @Test+ public void multipleSingleValueDateTest() throws DateTimeParseException {+ TestDateValue val1 = new TestDateValue();+ TestDateValue val2 = new TestDateValue();+ TestDateValue val3 = new TestDateValue();+ TestDateValue val4 = new TestDateValue();++ AnalyticsValueStream uncasted = BottomFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2, val3, val4});+ assertTrue(uncasted instanceof DateValue);+ DateValue func = (DateValue) uncasted;++ // None exist+ val1.setExists(false);+ val2.setExists(false);+ val3.setExists(false);+ val4.setExists(false);+ func.getDate();+ assertFalse(func.exists());++ // Some exist+ val1.setValue("9999-05-03T10:30:50Z").setExists(false);+ val2.setValue("1950-05-03T10:30:50Z").setExists(true);+ val3.setValue("0000-05-03T10:30:50Z").setExists(false);+ val4.setValue("1850-05-03T10:30:50Z").setExists(true);+ assertEquals(Date.from(Instant.parse("1850-05-03T10:30:50Z")), func.getDate());+ assertTrue(func.exists());++ // All exist values, one value+ val1.setValue("2200-05-03T10:30:50Z").setExists(true);+ val2.setValue("1950-05-03T10:30:50Z").setExists(true);+ val3.setValue("1700-05-03T10:30:50Z").setExists(true);+ val4.setValue("1850-05-03T10:30:50Z").setExists(true);+ assertEquals(Date.from(Instant.parse("1700-05-03T10:30:50Z")), func.getDate());+ assertTrue(func.exists());+ }++ @Test+ public void multipleStringValueDateTest() {+ TestStringValue val1 = new TestStringValue();+ TestStringValue val2 = new TestStringValue();+ TestStringValue val3 = new TestStringValue();+ TestStringValue val4 = new TestStringValue();++ AnalyticsValueStream uncasted = BottomFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2, val3, val4});+ assertTrue(uncasted instanceof StringValue);+ StringValue func = (StringValue) uncasted;++ // None exist+ val1.setExists(false);+ val2.setExists(false);+ val3.setExists(false);+ val4.setExists(false);+ func.getString();+ assertFalse(func.exists());++ // Some exist+ val1.setValue("abc").setExists(true);+ val2.setValue("1111").setExists(false);+ val3.setValue("asdfads").setExists(true);+ val4.setValue("zzzzzzzz").setExists(false);+ assertEquals("abc", func.getString());+ assertTrue(func.exists());++ // All exist values, one value+ val1.setValue("abc").setExists(true);+ val2.setValue("abc1234").setExists(true);+ val3.setValue("asdfads").setExists(true);+ val4.setValue("fdgsfg").setExists(true);+ assertEquals("abc", func.getString());+ assertTrue(func.exists());+ }+}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/CeilingFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/CeilingFunctionTest.javanew file mode 100644index 00000000000..c527df83604--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/CeilingFunctionTest.java@@ -0,0 +1,180 @@+/*+ * 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.analytics.function.mapping;++import java.util.Arrays;+import java.util.Iterator;++import org.apache.solr.SolrTestCaseJ4;+import org.apache.solr.analytics.function.mapping.DecimalNumericConversionFunction.CeilingFunction;+import org.apache.solr.analytics.value.AnalyticsValueStream;+import org.apache.solr.analytics.value.IntValue;+import org.apache.solr.analytics.value.IntValueStream;+import org.apache.solr.analytics.value.LongValue;+import org.apache.solr.analytics.value.LongValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValue;+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValue;+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestIntValue;+import org.apache.solr.analytics.value.FillableTestValue.TestIntValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestLongValue;+import org.apache.solr.analytics.value.FillableTestValue.TestLongValueStream;+import org.junit.Test;++public class CeilingFunctionTest extends SolrTestCaseJ4 {++ @Test+ public void singleValueFloatParameterTest() {+ TestFloatValue val = new TestFloatValue();++ AnalyticsValueStream uncasted = CeilingFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});+ assertTrue(uncasted instanceof IntValue);+ IntValue func = (IntValue) uncasted;++ // Value doesn't exist+ val.setExists(false);+ func.getInt();+ assertFalse(func.exists());++ // Value exists+ val.setValue(21.56F).setExists(true);+ assertEquals(22, func.getInt());+ assertTrue(func.exists());++ val.setValue(-100.3F).setExists(true);+ assertEquals(-100, func.getInt());+ assertTrue(func.exists());+ }++ @Test+ public void singleValueDoubleParameterTest() {+ TestDoubleValue val = new TestDoubleValue();++ AnalyticsValueStream uncasted = CeilingFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});+ assertTrue(uncasted instanceof LongValue);+ LongValue func = (LongValue) uncasted;++ // Value doesn't exist+ val.setExists(false);+ func.getLong();+ assertFalse(func.exists());++ // Value exists+ val.setValue(21.56).setExists(true);+ assertEquals(22L, func.getLong());+ assertTrue(func.exists());++ val.setValue(-100.3).setExists(true);+ assertEquals(-100L, func.getLong());+ assertTrue(func.exists());+ }++ @Test+ public void multiValueFloatParameterTest() {+ TestFloatValueStream val = new TestFloatValueStream();++ AnalyticsValueStream uncasted = CeilingFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});+ assertTrue(uncasted instanceof IntValueStream);+ IntValueStream func = (IntValueStream) uncasted;++ // No values+ val.setValues();+ func.streamInts( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // One value+ val.setValues(-4F);+ Iterator<Integer> values1 = Arrays.asList(-4).iterator();+ func.streamInts( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next().intValue(), value);+ });+ assertFalse(values1.hasNext());++ // Multiple values+ val.setValues(4F, -10.9999F, 50.00001F, 74.99999F);+ Iterator<Integer> values2 = Arrays.asList(4, -10, 51, 75).iterator();+ func.streamInts( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next().intValue(), value);+ });+ assertFalse(values2.hasNext());+ }++ @Test+ public void multiValueDoubleParameterTest() {+ TestDoubleValueStream val = new TestDoubleValueStream();++ AnalyticsValueStream uncasted = CeilingFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});+ assertTrue(uncasted instanceof LongValueStream);+ LongValueStream func = (LongValueStream) uncasted;++ // No values+ val.setValues();+ func.streamLongs( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // One value+ val.setValues(-4);+ Iterator<Long> values1 = Arrays.asList(-4L).iterator();+ func.streamLongs( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next().longValue(), value);+ });+ assertFalse(values1.hasNext());++ // Multiple values+ val.setValues(4, -10.9999, 50.000001, 74.99999);+ Iterator<Long> values2 = Arrays.asList(4L, -10L, 51L, 75L).iterator();+ func.streamLongs( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next().longValue(), value);+ });+ assertFalse(values2.hasNext());+ }++ @Test+ public void nonDecimalParameterTest() {+ AnalyticsValueStream result;+ AnalyticsValueStream param;++ param = new TestIntValue();+ result = CeilingFunction.creatorFunction.apply(new AnalyticsValueStream[] {param});+ assertTrue(result instanceof IntValue);+ assertEquals(param, result);++ param = new TestIntValueStream();+ result = CeilingFunction.creatorFunction.apply(new AnalyticsValueStream[] {param});+ assertTrue(result instanceof IntValueStream);+ assertEquals(param, result);++ param = new TestLongValue();+ result = CeilingFunction.creatorFunction.apply(new AnalyticsValueStream[] {param});+ assertTrue(result instanceof LongValue);+ assertEquals(param, result);++ param = new TestLongValueStream();+ result = CeilingFunction.creatorFunction.apply(new AnalyticsValueStream[] {param});+ assertTrue(result instanceof LongValueStream);+ assertEquals(param, result);+ }+++}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/ConcatFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/ConcatFunctionTest.javanew file mode 100644index 00000000000..db5b36e77d6--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/ConcatFunctionTest.java@@ -0,0 +1,317 @@+/*+ * 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.analytics.function.mapping;++import java.util.Arrays;+import java.util.Iterator;++import org.apache.solr.SolrTestCaseJ4;+import org.apache.solr.analytics.function.mapping.ConcatFunction.SeparatedConcatFunction;+import org.apache.solr.analytics.value.AnalyticsValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestStringValue;+import org.apache.solr.analytics.value.FillableTestValue.TestStringValueStream;+import org.apache.solr.analytics.value.StringValue;+import org.apache.solr.analytics.value.StringValueStream;+import org.apache.solr.analytics.value.constant.ConstantStringValue;+import org.junit.Test;++public class ConcatFunctionTest extends SolrTestCaseJ4 {++ @Test+ public void oneMultiValueParameterUnseparatedTest() {+ TestStringValueStream val = new TestStringValueStream();++ AnalyticsValueStream uncasted = ConcatFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});+ assertTrue(uncasted instanceof StringValue);+ StringValue func = (StringValue) uncasted;++ // No values+ val.setValues();+ func.getString();+ assertFalse(func.exists());++ // One value+ val.setValues("abc");+ assertEquals("abc", func.getString());+ assertTrue(func.exists());++ // Multiple values+ val.setValues("abc", "def", "ghi");+ assertEquals("abcdefghi", func.getString());+ assertTrue(func.exists());+ }++ @Test+ public void oneMultiValueParameterSeparatedTest() {+ TestStringValueStream val = new TestStringValueStream();+ ConstantStringValue sep = new ConstantStringValue("===:---");++ AnalyticsValueStream uncasted = SeparatedConcatFunction.creatorFunction.apply(new AnalyticsValueStream[] {sep, val});+ assertTrue(uncasted instanceof StringValue);+ StringValue func = (StringValue) uncasted;++ // No values+ val.setValues();+ func.getString();+ assertFalse(func.exists());++ // One value+ val.setValues("abc");+ assertEquals("abc", func.getString());+ assertTrue(func.exists());++ // Multiple values+ val.setValues("abc", "def", "ghi");+ assertEquals("abc===:---def===:---ghi", func.getString());+ assertTrue(func.exists());+ }++ @Test+ public void oneSingleOneMultiValueParameterUnseperatedTest() {+ TestStringValue val1 = new TestStringValue();+ TestStringValueStream val2 = new TestStringValueStream();++ AnalyticsValueStream uncasted = ConcatFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2});+ assertTrue(uncasted instanceof StringValueStream);+ StringValueStream func = (StringValueStream) uncasted;++ // None exist+ val1.setExists(false);+ val2.setValues();+ func.streamStrings( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // One exists+ val1.setExists(false);+ val2.setValues("def");+ func.streamStrings( value -> {+ assertTrue("There should be no values to stream", false);+ });++ val1.setValue("abc").setExists(true);+ val2.setValues();+ func.streamStrings( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Both exist+ val1.setValue("abc").setExists(true);+ val2.setValues("def", "ghi", "jkl");+ Iterator<String> values2 = Arrays.asList("abcdef", "abcghi", "abcjkl").iterator();+ func.streamStrings( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value);+ });+ assertFalse(values2.hasNext());+ }++ @Test+ public void oneSingleOneMultiValueParameterSeperatedTest() {+ TestStringValue val1 = new TestStringValue();+ TestStringValueStream val2 = new TestStringValueStream();+ ConstantStringValue sep = new ConstantStringValue("+-;");++ AnalyticsValueStream uncasted = SeparatedConcatFunction.creatorFunction.apply(new AnalyticsValueStream[] {sep, val1, val2});+ assertTrue(uncasted instanceof StringValueStream);+ StringValueStream func = (StringValueStream) uncasted;++ // None exist+ val1.setExists(false);+ val2.setValues();+ func.streamStrings( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // One exists+ val1.setExists(false);+ val2.setValues("def");+ func.streamStrings( value -> {+ assertTrue("There should be no values to stream", false);+ });++ val1.setValue("abc").setExists(true);+ val2.setValues();+ func.streamStrings( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Both exist+ val1.setValue("abc").setExists(true);+ val2.setValues("def", "ghi", "jkl");+ Iterator<String> values2 = Arrays.asList("abc+-;def", "abc+-;ghi", "abc+-;jkl").iterator();+ func.streamStrings( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value);+ });+ assertFalse(values2.hasNext());+ }++ @Test+ public void oneMultiOneSingleValueParameterUnseperatedTest() {+ TestStringValueStream val1 = new TestStringValueStream();+ TestStringValue val2 = new TestStringValue();++ AnalyticsValueStream uncasted = ConcatFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2});+ assertTrue(uncasted instanceof StringValueStream);+ StringValueStream func = (StringValueStream) uncasted;++ // None exist+ val1.setValues();+ val2.setExists(false);+ func.streamStrings( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // One exists+ val1.setValues("def");+ val2.setExists(false);+ func.streamStrings( value -> {+ assertTrue("There should be no values to stream", false);+ });++ val1.setValues();+ val2.setValue("abc").setExists(true);+ func.streamStrings( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Both exist+ val1.setValues("def", "ghi", "jkl");+ val2.setValue("abc").setExists(true);+ Iterator<String> values2 = Arrays.asList("defabc", "ghiabc", "jklabc").iterator();+ func.streamStrings( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value);+ });+ assertFalse(values2.hasNext());+ }++ @Test+ public void oneMultiOneSingleValueParameterSeperatedTest() {+ TestStringValueStream val1 = new TestStringValueStream();+ TestStringValue val2 = new TestStringValue();+ ConstantStringValue sep = new ConstantStringValue("<");++ AnalyticsValueStream uncasted = SeparatedConcatFunction.creatorFunction.apply(new AnalyticsValueStream[] {sep, val1, val2});+ assertTrue(uncasted instanceof StringValueStream);+ StringValueStream func = (StringValueStream) uncasted;++ // None exist+ val1.setValues();+ val2.setExists(false);+ func.streamStrings( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // One exists+ val1.setValues("def");+ val2.setExists(false);+ func.streamStrings( value -> {+ assertTrue("There should be no values to stream", false);+ });++ val1.setValues();+ val2.setValue("abc").setExists(true);+ func.streamStrings( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Both exist+ val1.setValues("def", "ghi", "jkl");+ val2.setValue("abc").setExists(true);+ Iterator<String> values2 = Arrays.asList("def<abc", "ghi<abc", "jkl<abc").iterator();+ func.streamStrings( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value);+ });+ assertFalse(values2.hasNext());+ }++ @Test+ public void multipleSingleValueParameterUnseperatedTest() {+ TestStringValue val1 = new TestStringValue();+ TestStringValue val2 = new TestStringValue();+ TestStringValue val3 = new TestStringValue();+ TestStringValue val4 = new TestStringValue();++ AnalyticsValueStream uncasted = ConcatFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2, val3, val4});+ assertTrue(uncasted instanceof StringValue);+ StringValue func = (StringValue) uncasted;++ // None exist+ val1.setExists(false);+ val2.setExists(false);+ val3.setExists(false);+ val4.setExists(false);+ func.getString();+ assertFalse(func.exists());++ // Some exist+ val1.setExists(false);+ val2.setValue("def").setExists(true);+ val3.setExists(false);+ val4.setValue("jkl").setExists(true);+ assertEquals("defjkl", func.getString());+ assertTrue(func.exists());++ // All exist values, one value+ val1.setValue("abc").setExists(true);+ val2.setValue("def").setExists(true);+ val3.setValue("ghi").setExists(true);+ val4.setValue("jkl").setExists(true);+ assertEquals("abcdefghijkl", func.getString());+ assertTrue(func.exists());+ }++ @Test+ public void multipleSingleValueParameterSeperatedTest() {+ TestStringValue val1 = new TestStringValue();+ TestStringValue val2 = new TestStringValue();+ TestStringValue val3 = new TestStringValue();+ TestStringValue val4 = new TestStringValue();+ ConstantStringValue sep = new ConstantStringValue("+:-");++ AnalyticsValueStream uncasted = SeparatedConcatFunction.creatorFunction.apply(new AnalyticsValueStream[] {sep, val1, val2, val3, val4});+ assertTrue(uncasted instanceof StringValue);+ StringValue func = (StringValue) uncasted;++ // None exist+ val1.setExists(false);+ val2.setExists(false);+ val3.setExists(false);+ val4.setExists(false);+ func.getString();+ assertFalse(func.exists());++ // Some exist+ val1.setExists(false);+ val2.setValue("def").setExists(true);+ val3.setExists(false);+ val4.setValue("jkl").setExists(true);+ assertEquals("def+:-jkl", func.getString());+ assertTrue(func.exists());++ // All exist values, one value+ val1.setValue("abc").setExists(true);+ val2.setValue("def").setExists(true);+ val3.setValue("ghi").setExists(true);+ val4.setValue("jkl").setExists(true);+ assertEquals("abc+:-def+:-ghi+:-jkl", func.getString());+ assertTrue(func.exists());+ }+}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/DateMathFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/DateMathFunctionTest.javanew file mode 100644index 00000000000..f3802afd933--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/DateMathFunctionTest.java@@ -0,0 +1,127 @@+/*+ * 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.analytics.function.mapping;++import java.time.Instant;+import java.time.format.DateTimeParseException;+import java.util.Arrays;+import java.util.Date;+import java.util.Iterator;++import org.apache.solr.SolrTestCaseJ4;+import org.apache.solr.analytics.value.AnalyticsValueStream;+import org.apache.solr.analytics.value.DateValue;+import org.apache.solr.analytics.value.DateValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestDateValue;+import org.apache.solr.analytics.value.FillableTestValue.TestDateValueStream;+import org.apache.solr.analytics.value.constant.ConstantStringValue;+import org.junit.Test;++public class DateMathFunctionTest extends SolrTestCaseJ4 {++ @Test+ public void singleValueParameterTest() throws DateTimeParseException {+ Date date1 = Date.from(Instant.parse("1810-12-02T10:30:15Z"));+ Date date2 = Date.from(Instant.parse("1931-03-16T18:15:45Z"));++ TestDateValue val = new TestDateValue();++ ConstantStringValue math1 = new ConstantStringValue("+1DAY");+ ConstantStringValue math2 = new ConstantStringValue("-1MONTH");+ ConstantStringValue math3 = new ConstantStringValue("+11YEARS");++ AnalyticsValueStream uncasted = DateMathFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, math1, math2, math3});+ assertTrue(uncasted instanceof DateValue);+ DateValue func = (DateValue) uncasted;++ // Value doesn't exist+ val.setExists(false);+ func.getDate();+ assertFalse(func.exists());+ func.getLong();+ assertFalse(func.exists());++ // Value exists+ val.setValue("1800-01-01T10:30:15Z").setExists(true);+ assertEquals(date1, func.getDate());+ assertTrue(func.exists());+ assertEquals(date1.getTime(), func.getLong());+ assertTrue(func.exists());++ val.setValue("1920-04-15T18:15:45Z").setExists(true);+ assertEquals(date2, func.getDate());+ assertTrue(func.exists());+ assertEquals(date2.getTime(), func.getLong());+ assertTrue(func.exists());+ }++ @Test+ public void multiValueParamaterTest() throws DateTimeParseException {+ Date date1 = Date.from(Instant.parse("1810-12-02T10:30:15Z"));+ Date date2 = Date.from(Instant.parse("1931-03-16T18:15:45Z"));+ Date date3 = Date.from(Instant.parse("2023-11-01T20:30:15Z"));++ TestDateValueStream val = new TestDateValueStream();++ ConstantStringValue math1 = new ConstantStringValue("+1DAY");+ ConstantStringValue math2 = new ConstantStringValue("-1MONTH");+ ConstantStringValue math3 = new ConstantStringValue("+11YEARS");++ AnalyticsValueStream uncasted = DateMathFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, math1, math2, math3});+ assertTrue(uncasted instanceof DateValueStream);+ DateValueStream func = (DateValueStream) uncasted;++ // No values+ val.setValues();+ func.streamDates( value -> {+ assertTrue("There should be no values to stream", false);+ });+ func.streamLongs( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // One value+ val.setValues("1800-01-01T10:30:15Z");+ Iterator<Date> values1 = Arrays.asList(date1).iterator();+ func.streamDates( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value);+ });+ assertFalse(values1.hasNext());+ Iterator<Long> times1 = Arrays.asList(date1.getTime()).iterator();+ func.streamLongs( value -> {+ assertTrue(times1.hasNext());+ assertEquals(times1.next().longValue(), value);+ });+ assertFalse(times1.hasNext());++ // Multiple values+ val.setValues("1800-01-01T10:30:15Z", "1920-04-15T18:15:45Z", "2012-11-30T20:30:15Z");+ Iterator<Date> values2 = Arrays.asList(date1, date2, date3).iterator();+ func.streamDates( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value);+ });+ assertFalse(values2.hasNext());+ Iterator<Long> times2 = Arrays.asList(date1.getTime(), date2.getTime(), date3.getTime()).iterator();+ func.streamLongs( value -> {+ assertTrue(times2.hasNext());+ assertEquals(times2.next().longValue(), value);+ });+ assertFalse(times2.hasNext());+ }+}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/DateParseFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/DateParseFunctionTest.javanew file mode 100644index 00000000000..2f348339b32--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/DateParseFunctionTest.java@@ -0,0 +1,245 @@+/*+ * 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.analytics.function.mapping;++import java.time.Instant;+import java.time.format.DateTimeParseException;+import java.util.Arrays;+import java.util.Date;+import java.util.Iterator;++import org.apache.solr.SolrTestCaseJ4;+import org.apache.solr.analytics.value.AnalyticsValueStream;+import org.apache.solr.analytics.value.DateValue;+import org.apache.solr.analytics.value.DateValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestLongValue;+import org.apache.solr.analytics.value.FillableTestValue.TestLongValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestStringValue;+import org.apache.solr.analytics.value.FillableTestValue.TestStringValueStream;+import org.junit.Test;++public class DateParseFunctionTest extends SolrTestCaseJ4 {++ @Test+ public void singleValueLongTest() throws DateTimeParseException {+ Date date1 = Date.from(Instant.parse("1800-01-01T10:30:15Z"));+ Date date2 = Date.from(Instant.parse("1920-04-15T18:15:45Z"));+ TestLongValue val = new TestLongValue();++ AnalyticsValueStream uncasted = DateParseFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});+ assertTrue(uncasted instanceof DateValue);+ DateValue func = (DateValue) uncasted;++ // Value doesn't exist+ val.setExists(false);+ func.getDate();+ assertFalse(func.exists());+ func.getLong();+ assertFalse(func.exists());++ // Value exists+ val.setValue(date1.getTime()).setExists(true);+ assertEquals(date1, func.getDate());+ assertTrue(func.exists());+ assertEquals(date1.getTime(), func.getLong());+ assertTrue(func.exists());++ val.setValue(date2.getTime()).setExists(true);+ assertEquals(date2, func.getDate());+ assertTrue(func.exists());+ assertEquals(date2.getTime(), func.getLong());+ assertTrue(func.exists());+ }++ @Test+ public void singleValueStringTest() throws DateTimeParseException {+ Date date1 = Date.from(Instant.parse("1800-01-01T10:30:15Z"));+ Date date2 = Date.from(Instant.parse("1920-04-15T18:15:45Z"));+ TestStringValue val = new TestStringValue();++ AnalyticsValueStream uncasted = DateParseFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});+ assertTrue(uncasted instanceof DateValue);+ DateValue func = (DateValue) uncasted;++ // Value doesn't exist+ val.setExists(false);+ func.getDate();+ assertFalse(func.exists());+ func.getLong();+ assertFalse(func.exists());++ // Incorrect Value+ val.setValue("1800-01T10:30:15Z").setExists(true);+ func.getDate();+ assertFalse(func.exists());+ func.getLong();+ assertFalse(func.exists());++ val.setValue("1800-01-T::Z").setExists(true);+ func.getDate();+ assertFalse(func.exists());+ func.getLong();+ assertFalse(func.exists());++ val.setValue("1800--01T30:30:15Z").setExists(true);+ func.getDate();+ assertFalse(func.exists());+ func.getLong();+ assertFalse(func.exists());+++ // Value exists+ val.setValue("1800-01-01T10:30:15Z").setExists(true);+ assertEquals(date1, func.getDate());+ assertTrue(func.exists());+ assertEquals(date1.getTime(), func.getLong());+ assertTrue(func.exists());++ val.setValue("1920-04-15T18:15:45Z").setExists(true);+ assertEquals(date2, func.getDate());+ assertTrue(func.exists());+ assertEquals(date2.getTime(), func.getLong());+ assertTrue(func.exists());+ }++ @Test+ public void multiValueLongTest() throws DateTimeParseException {+ Date date1 = Date.from(Instant.parse("1800-01-01T10:30:15Z"));+ Date date2 = Date.from(Instant.parse("1920-04-15T18:15:45Z"));+ Date date3 = Date.from(Instant.parse("2012-11-30T20:30:15Z"));+ TestLongValueStream val = new TestLongValueStream();++ AnalyticsValueStream uncasted = DateParseFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});+ assertTrue(uncasted instanceof DateValueStream);+ DateValueStream func = (DateValueStream) uncasted;++ // No values+ val.setValues();+ func.streamDates( value -> {+ assertTrue("There should be no values to stream", false);+ });+ func.streamLongs( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // One value+ val.setValues(date1.getTime());+ Iterator<Date> values1 = Arrays.asList(date1).iterator();+ func.streamDates( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value);+ });+ assertFalse(values1.hasNext());+ Iterator<Long> times1 = Arrays.asList(date1.getTime()).iterator();+ func.streamLongs( value -> {+ assertTrue(times1.hasNext());+ assertEquals(times1.next().longValue(), value);+ });+ assertFalse(times1.hasNext());++ // Multiple values+ val.setValues(date1.getTime(), date2.getTime(), date3.getTime());+ Iterator<Date> values2 = Arrays.asList(date1, date2, date3).iterator();+ func.streamDates( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value);+ });+ assertFalse(values2.hasNext());+ Iterator<Long> times2 = Arrays.asList(date1.getTime(), date2.getTime(), date3.getTime()).iterator();+ func.streamLongs( value -> {+ assertTrue(times2.hasNext());+ assertEquals(times2.next().longValue(), value);+ });+ assertFalse(times2.hasNext());+ }++ @Test+ public void multiValueStringTest() throws DateTimeParseException {+ Date date1 = Date.from(Instant.parse("1800-01-01T10:30:15Z"));+ Date date2 = Date.from(Instant.parse("1920-04-15T18:15:45Z"));+ Date date3 = Date.from(Instant.parse("2012-11-30T20:30:15Z"));+ TestStringValueStream val = new TestStringValueStream();++ AnalyticsValueStream uncasted = DateParseFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});+ assertTrue(uncasted instanceof DateValueStream);+ DateValueStream func = (DateValueStream) uncasted;++ // No values+ val.setValues();+ func.streamDates( value -> {+ assertTrue("There should be no values to stream", false);+ });+ func.streamLongs( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Incorrect value+ val.setValues("10:30:15Z");+ func.streamDates( value -> {+ assertTrue("There should be no values to stream", false);+ });+ func.streamLongs( value -> {+ assertTrue("There should be no values to stream", false);+ });++ val.setValues("01-33T10:30:15Z");+ func.streamDates( value -> {+ assertTrue("There should be no values to stream", false);+ });+ func.streamLongs( value -> {+ assertTrue("There should be no values to stream", false);+ });++ val.setValues("1800-01T30:30:15Z");+ func.streamDates( value -> {+ assertTrue("There should be no values to stream", false);+ });+ func.streamLongs( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // One value+ val.setValues("1800-01-01T10:30:15Z");+ Iterator<Date> values1 = Arrays.asList(date1).iterator();+ func.streamDates( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value);+ });+ assertFalse(values1.hasNext());+ Iterator<Long> times1 = Arrays.asList(date1.getTime()).iterator();+ func.streamLongs( value -> {+ assertTrue(times1.hasNext());+ assertEquals(times1.next().longValue(), value);+ });+ assertFalse(times1.hasNext());++ // Multiple values+ val.setValues("1800-01-01T10:30:15Z", "1920-04-15T18:15:45Z", "2012-11-30T20:30:15Z");+ Iterator<Date> values2 = Arrays.asList(date1, date2, date3).iterator();+ func.streamDates( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value);+ });+ assertFalse(values2.hasNext());+ Iterator<Long> times2 = Arrays.asList(date1.getTime(), date2.getTime(), date3.getTime()).iterator();+ func.streamLongs( value -> {+ assertTrue(times2.hasNext());+ assertEquals(times2.next().longValue(), value);+ });+ assertFalse(times2.hasNext());+ }+}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/DivideFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/DivideFunctionTest.javanew file mode 100644index 00000000000..5ca324d9867--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/DivideFunctionTest.java@@ -0,0 +1,128 @@+/*+ * 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.analytics.function.mapping;++import java.util.Arrays;+import java.util.Iterator;++import org.apache.solr.SolrTestCaseJ4;+import org.apache.solr.analytics.value.AnalyticsValueStream;+import org.apache.solr.analytics.value.DoubleValue;+import org.apache.solr.analytics.value.DoubleValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValue;+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValue;+import org.apache.solr.analytics.value.FillableTestValue.TestIntValue;+import org.apache.solr.analytics.value.FillableTestValue.TestLongValueStream;+import org.junit.Test;++public class DivideFunctionTest extends SolrTestCaseJ4 {+ @Test+ public void twoSingleValueParametersTest() {+ TestIntValue dividend = new TestIntValue();+ TestFloatValue divisor = new TestFloatValue();++ AnalyticsValueStream uncasted = DivideFunction.creatorFunction.apply(new AnalyticsValueStream[] {dividend, divisor});+ assertTrue(uncasted instanceof DoubleValue);+ DoubleValue func = (DoubleValue) uncasted;++ // Neither exists+ dividend.setExists(false);+ divisor.setExists(false);+ func.getDouble();+ assertFalse(func.exists());++ // One exists+ dividend.setValue(30).setExists(true);+ divisor.setExists(false);+ func.getDouble();+ assertFalse(func.exists());++ // Both exist+ dividend.setValue(60).setExists(true);+ divisor.setValue(23.56F).setExists(true);+ assertEquals(2.546689, func.getDouble(), 0.00001);+ assertTrue(func.exists());+ }++ @Test+ public void oneMultiOneSingleValueParameterTest() {+ TestLongValueStream dividend = new TestLongValueStream();+ TestDoubleValue divisor = new TestDoubleValue();++ AnalyticsValueStream uncasted = DivideFunction.creatorFunction.apply(new AnalyticsValueStream[] {dividend, divisor});+ assertTrue(uncasted instanceof DoubleValueStream);+ DoubleValueStream func = (DoubleValueStream) uncasted;++ // No values, One value+ dividend.setValues();+ divisor.setValue(21.56F).setExists(true);+ func.streamDoubles( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple values, no value+ dividend.setValues(4L, 10023L);+ divisor.setExists(false);+ func.streamDoubles( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple values, one value+ dividend.setValues(20L, 5L, -234L);+ divisor.setValue(44.56F).setExists(true);+ Iterator<Double> values = Arrays.asList(0.448833, 0.112208, -5.251346).iterator();+ func.streamDoubles( value -> {+ assertTrue(values.hasNext());+ assertEquals(values.next(), value, 0.00001);+ });+ assertFalse(values.hasNext());+ }++ @Test+ public void oneSingleOneMultiValueParameterTest() {+ TestDoubleValue dividend = new TestDoubleValue();+ TestLongValueStream divisor = new TestLongValueStream();++ AnalyticsValueStream uncasted = DivideFunction.creatorFunction.apply(new AnalyticsValueStream[] {dividend, divisor});+ assertTrue(uncasted instanceof DoubleValueStream);+ DoubleValueStream func = (DoubleValueStream) uncasted;++ // No values, One value+ dividend.setValue(21.56F).setExists(true);+ divisor.setValues();+ func.streamDoubles( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple values, no value+ dividend.setExists(false);+ divisor.setValues(4L, 10023L);+ func.streamDoubles( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple values, one value+ dividend.setValue(44.56F).setExists(true);+ divisor.setValues(20L, 5L, -234L);+ Iterator<Double> values = Arrays.asList(2.228, 8.912, -0.190427).iterator();+ func.streamDoubles( value -> {+ assertTrue(values.hasNext());+ assertEquals(values.next(), value, 0.00001);+ });+ assertFalse(values.hasNext());+ }+}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/EqualFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/EqualFunctionTest.javanew file mode 100644index 00000000000..6495f961c8f--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/EqualFunctionTest.java@@ -0,0 +1,530 @@+/*+ * 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.analytics.function.mapping;++import java.util.Arrays;+import java.util.Iterator;++import org.apache.solr.SolrTestCaseJ4;+import org.apache.solr.analytics.function.mapping.EqualFunction;+import org.apache.solr.analytics.value.AnalyticsValueStream;+import org.apache.solr.analytics.value.BooleanValue;+import org.apache.solr.analytics.value.BooleanValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestBooleanValue;+import org.apache.solr.analytics.value.FillableTestValue.TestBooleanValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestDateValue;+import org.apache.solr.analytics.value.FillableTestValue.TestDateValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValue;+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestStringValue;+import org.apache.solr.analytics.value.FillableTestValue.TestStringValueStream;+import org.junit.Test;++public class EqualFunctionTest extends SolrTestCaseJ4 {++ @Test+ public void singleValueBooleanParameterTest() {+ TestBooleanValue val1 = new TestBooleanValue();+ TestBooleanValue val2 = new TestBooleanValue();++ AnalyticsValueStream uncasted = EqualFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2});+ assertTrue(uncasted instanceof BooleanValue);+ BooleanValue func = (BooleanValue) uncasted;++ // Value doesn't exist+ val1.setExists(false);+ val2.setExists(false);+ func.getBoolean();+ assertFalse(func.exists());++ val1.setExists(false);+ val2.setValue(false).setExists(true);+ func.getBoolean();+ assertFalse(func.exists());++ val1.setValue(true).setExists(true);+ val2.setExists(false);+ func.getBoolean();+ assertFalse(func.exists());++ // Value exists+ val1.setValue(false).setExists(true);+ val2.setValue(false).setExists(true);+ assertEquals(true, func.getBoolean());+ assertTrue(func.exists());++ val1.setValue(false).setExists(true);+ val2.setValue(true).setExists(true);+ assertEquals(false, func.getBoolean());+ assertTrue(func.exists());+ }++ @Test+ public void singleValueNumericParameterTest() {+ TestDoubleValue val1 = new TestDoubleValue();+ TestDoubleValue val2 = new TestDoubleValue();++ AnalyticsValueStream uncasted = EqualFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2});+ assertTrue(uncasted instanceof BooleanValue);+ BooleanValue func = (BooleanValue) uncasted;++ // Value doesn't exist+ val1.setExists(false);+ val2.setExists(false);+ func.getBoolean();+ assertFalse(func.exists());++ val1.setExists(false);+ val2.setValue(3.3).setExists(true);+ func.getBoolean();+ assertFalse(func.exists());++ val1.setValue(3.3).setExists(true);+ val2.setExists(false);+ func.getBoolean();+ assertFalse(func.exists());++ // Value exists+ val1.setValue(21.56).setExists(true);+ val2.setValue(21.56).setExists(true);+ assertEquals(true, func.getBoolean());+ assertTrue(func.exists());++ val1.setValue(21.56).setExists(true);+ val2.setValue(21.57).setExists(true);+ assertEquals(false, func.getBoolean());+ assertTrue(func.exists());+ }++ @Test+ public void singleValueDateParameterTest() {+ TestDateValue val1 = new TestDateValue();+ TestDateValue val2 = new TestDateValue();++ AnalyticsValueStream uncasted = EqualFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2});+ assertTrue(uncasted instanceof BooleanValue);+ BooleanValue func = (BooleanValue) uncasted;++ // Value doesn't exist+ val1.setExists(false);+ val2.setExists(false);+ func.getBoolean();+ assertFalse(func.exists());++ val1.setExists(false);+ val2.setValue("1800-01-02T10:20:30Z").setExists(true);+ func.getBoolean();+ assertFalse(func.exists());++ val1.setValue("1800-01-02T10:20:30Z").setExists(true);+ val2.setExists(false);+ func.getBoolean();+ assertFalse(func.exists());++ // Value exists+ val1.setValue("1800-01-02T10:20:30Z").setExists(true);+ val2.setValue("1800-01-02T10:20:30Z").setExists(true);+ assertEquals(true, func.getBoolean());+ assertTrue(func.exists());++ val1.setValue("1800-01-02T10:20:30Z").setExists(true);+ val2.setValue("1800-01-02T10:20:31Z").setExists(true);+ assertEquals(false, func.getBoolean());+ assertTrue(func.exists());+ }++ @Test+ public void singleValueStringParameterTest() {+ TestStringValue val1 = new TestStringValue();+ TestStringValue val2 = new TestStringValue();++ AnalyticsValueStream uncasted = EqualFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2});+ assertTrue(uncasted instanceof BooleanValue);+ BooleanValue func = (BooleanValue) uncasted;++ // Value doesn't exist+ val1.setExists(false);+ val2.setExists(false);+ func.getBoolean();+ assertFalse(func.exists());++ val1.setExists(false);+ val2.setValue("abcdefghi").setExists(true);+ func.getBoolean();+ assertFalse(func.exists());++ val1.setValue("abcdefghi").setExists(true);+ val2.setExists(false);+ func.getBoolean();+ assertFalse(func.exists());++ // Value exists+ val1.setValue("abcdefghi").setExists(true);+ val2.setValue("abcdefghi").setExists(true);+ assertEquals(true, func.getBoolean());+ assertTrue(func.exists());++ val1.setValue("abcdefghi1").setExists(true);+ val2.setValue("abcdefghi2").setExists(true);+ assertEquals(false, func.getBoolean());+ assertTrue(func.exists());+ }++ @Test+ public void oneSingleOneMultiValueBooleanParameterTest() {+ TestBooleanValueStream val1 = new TestBooleanValueStream();+ TestBooleanValue val2 = new TestBooleanValue();++ AnalyticsValueStream uncasted = EqualFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2});+ assertTrue(uncasted instanceof BooleanValueStream);+ BooleanValueStream func = (BooleanValueStream) uncasted;++ // No values+ val1.setValues();+ val2.setValue(false).setExists(true);+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ val1.setValues(true);+ val2.setExists(false);+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // One value+ val1.setValues(false);+ val2.setValue(false).setExists(true);+ Iterator<Boolean> values1 = Arrays.asList(true).iterator();+ func.streamBooleans( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value);+ });+ assertFalse(values1.hasNext());++ // Multiple values+ val1.setValues(false, true, true, false, false);+ val2.setValue(false).setExists(true);+ Iterator<Boolean> values2 = Arrays.asList(true, false, false, true, true).iterator();+ func.streamBooleans( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value);+ });+ assertFalse(values2.hasNext());+ }++ @Test+ public void oneMultiOneSingleValueBooleanParameterTest() {+ TestBooleanValueStream val1 = new TestBooleanValueStream();+ TestBooleanValue val2 = new TestBooleanValue();++ AnalyticsValueStream uncasted = EqualFunction.creatorFunction.apply(new AnalyticsValueStream[] {val2, val1});+ assertTrue(uncasted instanceof BooleanValueStream);+ BooleanValueStream func = (BooleanValueStream) uncasted;++ // No values+ val1.setValues();+ val2.setValue(false).setExists(true);+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ val1.setValues(true);+ val2.setExists(false);+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // One value+ val1.setValues(false);+ val2.setValue(false).setExists(true);+ Iterator<Boolean> values1 = Arrays.asList(true).iterator();+ func.streamBooleans( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value);+ });+ assertFalse(values1.hasNext());++ // Multiple values+ val1.setValues(false, true, true, false, false);+ val2.setValue(false).setExists(true);+ Iterator<Boolean> values2 = Arrays.asList(true, false, false, true, true).iterator();+ func.streamBooleans( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value);+ });+ assertFalse(values2.hasNext());+ }++ @Test+ public void oneSingleOneMultiValueNumericParameterTest() {+ TestDoubleValueStream val1 = new TestDoubleValueStream();+ TestDoubleValue val2 = new TestDoubleValue();++ AnalyticsValueStream uncasted = EqualFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2});+ assertTrue(uncasted instanceof BooleanValueStream);+ BooleanValueStream func = (BooleanValueStream) uncasted;++ // No values+ val1.setValues();+ val2.setValue(-4.2).setExists(true);+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ val1.setValues(-4.2);+ val2.setExists(false);+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // One value+ val1.setValues(-4.2);+ val2.setValue(-4.2).setExists(true);+ Iterator<Boolean> values1 = Arrays.asList(true).iterator();+ func.streamBooleans( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value);+ });+ assertFalse(values1.hasNext());++ // Multiple values+ val1.setValues(4, -10, 4, -74, 4.0001);+ val2.setValue(4).setExists(true);+ Iterator<Boolean> values2 = Arrays.asList(true, false, true, false, false).iterator();+ func.streamBooleans( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value);+ });+ assertFalse(values2.hasNext());+ }++ @Test+ public void oneMultiOneSingleValueNumericParameterTest() {+ TestDoubleValueStream val1 = new TestDoubleValueStream();+ TestDoubleValue val2 = new TestDoubleValue();++ AnalyticsValueStream uncasted = EqualFunction.creatorFunction.apply(new AnalyticsValueStream[] {val2, val1});+ assertTrue(uncasted instanceof BooleanValueStream);+ BooleanValueStream func = (BooleanValueStream) uncasted;++ // No values+ val1.setValues();+ val2.setValue(-4.2).setExists(true);+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ val1.setValues(-4.2);+ val2.setExists(false);+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // One value+ val1.setValues(-4.2);+ val2.setValue(-4.2).setExists(true);+ Iterator<Boolean> values1 = Arrays.asList(true).iterator();+ func.streamBooleans( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value);+ });+ assertFalse(values1.hasNext());++ // Multiple values+ val1.setValues(4, -10, 4, -74, 4.0001);+ val2.setValue(4).setExists(true);+ Iterator<Boolean> values2 = Arrays.asList(true, false, true, false, false).iterator();+ func.streamBooleans( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value);+ });+ assertFalse(values2.hasNext());+ }++ @Test+ public void oneSingleOneMultiValueDateParameterTest() {+ TestDateValueStream val1 = new TestDateValueStream();+ TestDateValue val2 = new TestDateValue();++ AnalyticsValueStream uncasted = EqualFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2});+ assertTrue(uncasted instanceof BooleanValueStream);+ BooleanValueStream func = (BooleanValueStream) uncasted;++ // No values+ val1.setValues();+ val2.setValue("1800-01-02T10:20:30Z").setExists(true);+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ val1.setValues("1800-01-02T10:20:30Z");+ val2.setExists(false);+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // One value+ val1.setValues("1800-01-02T10:20:30Z");+ val2.setValue("1800-01-02T10:20:30Z").setExists(true);+ Iterator<Boolean> values1 = Arrays.asList(true).iterator();+ func.streamBooleans( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value);+ });+ assertFalse(values1.hasNext());++ // Multiple values+ val1.setValues("1800-01-02T10:20:30Z", "1800-01-02T10:20:31Z", "1800-01-02T10:20:30Z", "1801-01-02T10:20:30Z");+ val2.setValue("1800-01-02T10:20:30Z").setExists(true);+ Iterator<Boolean> values2 = Arrays.asList(true, false, true, false).iterator();+ func.streamBooleans( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value);+ });+ assertFalse(values2.hasNext());+ }++ @Test+ public void oneMultiOneSingleValueDateParameterTest() {+ TestDateValueStream val1 = new TestDateValueStream();+ TestDateValue val2 = new TestDateValue();++ AnalyticsValueStream uncasted = EqualFunction.creatorFunction.apply(new AnalyticsValueStream[] {val2, val1});+ assertTrue(uncasted instanceof BooleanValueStream);+ BooleanValueStream func = (BooleanValueStream) uncasted;++ // No values+ val1.setValues();+ val2.setValue("1800-01-02T10:20:30Z").setExists(true);+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ val1.setValues("1800-01-02T10:20:30Z");+ val2.setExists(false);+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // One value+ val1.setValues("1800-01-02T10:20:30Z");+ val2.setValue("1800-01-02T10:20:30Z").setExists(true);+ Iterator<Boolean> values1 = Arrays.asList(true).iterator();+ func.streamBooleans( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value);+ });+ assertFalse(values1.hasNext());++ // Multiple values+ val1.setValues("1800-01-02T10:20:30Z", "1800-01-02T10:20:31Z", "1800-01-02T10:20:30Z", "9999-01-02T10:20:30Z");+ val2.setValue("1800-01-02T10:20:30Z").setExists(true);+ Iterator<Boolean> values2 = Arrays.asList(true, false, true, false).iterator();+ func.streamBooleans( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value);+ });+ assertFalse(values2.hasNext());+ }++ @Test+ public void oneSingleOneMultiValueStringParameterTest() {+ TestStringValueStream val1 = new TestStringValueStream();+ TestStringValue val2 = new TestStringValue();++ AnalyticsValueStream uncasted = EqualFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2});+ assertTrue(uncasted instanceof BooleanValueStream);+ BooleanValueStream func = (BooleanValueStream) uncasted;++ // No values+ val1.setValues();+ val2.setValue("abcdefghi").setExists(true);+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ val1.setValues("abcdefghi");+ val2.setExists(false);+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // One value+ val1.setValues("abcdefghi");+ val2.setValue("abcdefghi").setExists(true);+ Iterator<Boolean> values1 = Arrays.asList(true).iterator();+ func.streamBooleans( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value);+ });+ assertFalse(values1.hasNext());++ // Multiple values+ val1.setValues("abcdefghi", "abcdefghi1", "sbcdefghi", "abcdefghi");+ val2.setValue("abcdefghi").setExists(true);+ Iterator<Boolean> values2 = Arrays.asList(true, false, false, true).iterator();+ func.streamBooleans( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value);+ });+ assertFalse(values2.hasNext());+ }++ @Test+ public void oneMultiOneSingleValueStringParameterTest() {+ TestStringValueStream val1 = new TestStringValueStream();+ TestStringValue val2 = new TestStringValue();++ AnalyticsValueStream uncasted = EqualFunction.creatorFunction.apply(new AnalyticsValueStream[] {val2, val1});+ assertTrue(uncasted instanceof BooleanValueStream);+ BooleanValueStream func = (BooleanValueStream) uncasted;++ // No values+ val1.setValues();+ val2.setValue("abcdefghi").setExists(true);+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ val1.setValues("abcdefghi");+ val2.setExists(false);+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // One value+ val1.setValues("abcdefghi");+ val2.setValue("abcdefghi").setExists(true);+ Iterator<Boolean> values1 = Arrays.asList(true).iterator();+ func.streamBooleans( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value);+ });+ assertFalse(values1.hasNext());++ // Multiple values+ val1.setValues("abcdefghi", "abcdefghi1", "sbcdefghi", "abcdefghi");+ val2.setValue("abcdefghi").setExists(true);+ Iterator<Boolean> values2 = Arrays.asList(true, false, false, true).iterator();+ func.streamBooleans( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value);+ });+ assertFalse(values2.hasNext());+ }+}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/ExistsFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/ExistsFunctionTest.javanew file mode 100644index 00000000000..89fcf426d92--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/ExistsFunctionTest.java@@ -0,0 +1,74 @@+/*+ * 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.analytics.function.mapping;++import org.apache.solr.SolrTestCaseJ4;+import org.apache.solr.analytics.function.mapping.ExistsFunction;+import org.apache.solr.analytics.value.AnalyticsValueStream;+import org.apache.solr.analytics.value.BooleanValue;+import org.apache.solr.analytics.value.FillableTestValue.TestBooleanValue;+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValueStream;+import org.junit.Test;++public class ExistsFunctionTest extends SolrTestCaseJ4 {++ @Test+ public void singleValueParameterTest() {+ TestBooleanValue val = new TestBooleanValue();++ AnalyticsValueStream uncasted = ExistsFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});+ assertTrue(uncasted instanceof BooleanValue);+ BooleanValue func = (BooleanValue) uncasted;++ val.setExists(false);+ assertFalse(func.getBoolean());+ assertTrue(func.exists());++ val.setValue(true).setExists(true);+ assertTrue(func.getBoolean());+ assertTrue(func.exists());++ val.setValue(false).setExists(true);+ assertTrue(func.getBoolean());+ assertTrue(func.exists());+ }++ @Test+ public void multiValueParameterTest() {+ TestDoubleValueStream val = new TestDoubleValueStream();++ AnalyticsValueStream uncasted = ExistsFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});+ assertTrue(uncasted instanceof BooleanValue);+ BooleanValue func = (BooleanValue) uncasted;++ val.setValues(2, 30.0);+ assertTrue(func.getBoolean());+ assertTrue(func.exists());++ val.setValues();+ assertFalse(func.getBoolean());+ assertTrue(func.exists());++ val.setValues(21234.65);+ assertTrue(func.getBoolean());+ assertTrue(func.exists());++ val.setValues();+ assertFalse(func.getBoolean());+ assertTrue(func.exists());+ }+}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/FillMissingFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/FillMissingFunctionTest.javanew file mode 100644index 00000000000..ea82193e1b0--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/FillMissingFunctionTest.java@@ -0,0 +1,717 @@+/*+ * 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.analytics.function.mapping;++import java.time.Instant;+import java.time.format.DateTimeParseException;+import java.util.Arrays;+import java.util.Date;+import java.util.Iterator;++import org.apache.solr.SolrTestCaseJ4;+import org.apache.solr.analytics.value.AnalyticsValue;+import org.apache.solr.analytics.value.AnalyticsValueStream;+import org.apache.solr.analytics.value.BooleanValue;+import org.apache.solr.analytics.value.BooleanValueStream;+import org.apache.solr.analytics.value.DateValue;+import org.apache.solr.analytics.value.DateValueStream;+import org.apache.solr.analytics.value.DoubleValue;+import org.apache.solr.analytics.value.DoubleValueStream;+import org.apache.solr.analytics.value.FloatValue;+import org.apache.solr.analytics.value.FloatValueStream;+import org.apache.solr.analytics.value.IntValue;+import org.apache.solr.analytics.value.IntValueStream;+import org.apache.solr.analytics.value.LongValue;+import org.apache.solr.analytics.value.LongValueStream;+import org.apache.solr.analytics.value.StringValue;+import org.apache.solr.analytics.value.StringValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestAnalyticsValue;+import org.apache.solr.analytics.value.FillableTestValue.TestAnalyticsValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestBooleanValue;+import org.apache.solr.analytics.value.FillableTestValue.TestBooleanValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestDateValue;+import org.apache.solr.analytics.value.FillableTestValue.TestDateValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValue;+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValue;+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestIntValue;+import org.apache.solr.analytics.value.FillableTestValue.TestIntValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestLongValue;+import org.apache.solr.analytics.value.FillableTestValue.TestLongValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestStringValue;+import org.apache.solr.analytics.value.FillableTestValue.TestStringValueStream;+import org.junit.Test;++public class FillMissingFunctionTest extends SolrTestCaseJ4 {++ @Test+ public void castingTest() {+ assertTrue(FillMissingFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestBooleanValue(), new TestStringValue()}) instanceof StringValue);++ assertFalse(FillMissingFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestIntValue(), new TestFloatValue()}) instanceof IntValue);++ assertFalse(FillMissingFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestBooleanValue(), new TestStringValueStream()}) instanceof AnalyticsValue);++ assertFalse(FillMissingFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestLongValue(), new TestAnalyticsValue()}) instanceof LongValue);++ assertTrue(FillMissingFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestIntValue(), new TestLongValue()}) instanceof DoubleValue);++ assertFalse(FillMissingFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestDateValue(), new TestStringValue()}) instanceof DateValue);++ assertFalse(FillMissingFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestBooleanValueStream(), new TestStringValue()}) instanceof AnalyticsValue);++ assertTrue(FillMissingFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestDoubleValue(), new TestIntValueStream()}) instanceof DoubleValueStream);+ }++ @Test+ public void singleValueBooleanTest() {+ TestBooleanValue val = new TestBooleanValue();+ TestBooleanValue filler = new TestBooleanValue();++ AnalyticsValueStream uncasted = FillMissingFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filler});+ assertTrue(uncasted instanceof BooleanValue);+ BooleanValue func = (BooleanValue) uncasted;++ // Value doesn't exist+ val.setExists(false);+ filler.setExists(false);+ func.getBoolean();+ assertFalse(func.exists());++ // Value exists+ val.setValue(true).setExists(true);+ filler.setValue(false).setExists(true);+ assertEquals(true, func.getBoolean());+ assertTrue(func.exists());++ val.setValue(false).setExists(true);+ filler.setValue(false).setExists(true);+ assertEquals(false, func.getBoolean());+ assertTrue(func.exists());++ val.setValue(true).setExists(true);+ filler.setExists(false);+ assertEquals(true, func.getBoolean());+ assertTrue(func.exists());++ val.setValue(false).setExists(true);+ filler.setExists(false);+ assertEquals(false, func.getBoolean());+ assertTrue(func.exists());++ val.setExists(false);+ filler.setValue(false).setExists(true);+ assertEquals(false, func.getBoolean());+ assertTrue(func.exists());++ val.setExists(false);+ filler.setValue(true).setExists(true);+ assertEquals(true, func.getBoolean());+ assertTrue(func.exists());+ }++ @Test+ public void singleValueIntTest() {+ TestIntValue val = new TestIntValue();+ TestIntValue filler = new TestIntValue();++ AnalyticsValueStream uncasted = FillMissingFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filler});+ assertTrue(uncasted instanceof IntValue);+ IntValue func = (IntValue) uncasted;++ // Value doesn't exist+ val.setExists(false);+ filler.setExists(false);+ func.getInt();+ assertFalse(func.exists());++ // Value exists+ val.setValue(21).setExists(true);+ filler.setValue(234).setExists(true);+ assertEquals(21, func.getInt());+ assertTrue(func.exists());++ val.setExists(false);+ filler.setValue(-234).setExists(true);+ assertEquals(-234, func.getInt());+ assertTrue(func.exists());++ val.setValue(52334).setExists(true);+ filler.setExists(false);+ assertEquals(52334, func.getInt());+ assertTrue(func.exists());+ }++ @Test+ public void singleValueLongTest() {+ TestLongValue val = new TestLongValue();+ TestLongValue filler = new TestLongValue();++ AnalyticsValueStream uncasted = FillMissingFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filler});+ assertTrue(uncasted instanceof LongValue);+ LongValue func = (LongValue) uncasted;++ // Value doesn't exist+ val.setExists(false);+ filler.setExists(false);+ func.getLong();+ assertFalse(func.exists());++ // Value exists+ val.setValue(21L).setExists(true);+ filler.setValue(234L).setExists(true);+ assertEquals(21L, func.getLong());+ assertTrue(func.exists());++ val.setExists(false);+ filler.setValue(234L).setExists(true);+ assertEquals(234L, func.getLong());+ assertTrue(func.exists());++ val.setValue(-52334L).setExists(true);+ filler.setExists(false);+ assertEquals(-52334L, func.getLong());+ assertTrue(func.exists());+ }++ @Test+ public void singleValueFloatTest() {+ TestFloatValue val = new TestFloatValue();+ TestFloatValue filler = new TestFloatValue();++ AnalyticsValueStream uncasted = FillMissingFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filler});+ assertTrue(uncasted instanceof FloatValue);+ FloatValue func = (FloatValue) uncasted;++ // Value doesn't exist+ val.setExists(false);+ filler.setExists(false);+ func.getFloat();+ assertFalse(func.exists());++ // Value exists+ val.setValue(-21.324F).setExists(true);+ filler.setValue(23423.423342F).setExists(true);+ assertEquals(-21.324F, func.getFloat(), .00000001);+ assertTrue(func.exists());++ val.setExists(false);+ filler.setValue(3124123.32F).setExists(true);+ assertEquals(3124123.32F, func.getFloat(), .00000001);+ assertTrue(func.exists());++ val.setValue(2345.345543F).setExists(true);+ filler.setExists(false);+ assertEquals(2345.345543F, func.getFloat(), .00000001);+ assertTrue(func.exists());+ }++ @Test+ public void singleValueDoubleTest() {+ TestDoubleValue val = new TestDoubleValue();+ TestDoubleValue filler = new TestDoubleValue();++ AnalyticsValueStream uncasted = FillMissingFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filler});+ assertTrue(uncasted instanceof DoubleValue);+ DoubleValue func = (DoubleValue) uncasted;++ // Value doesn't exist+ val.setExists(false);+ filler.setExists(false);+ func.getDouble();+ assertFalse(func.exists());++ // Value exists+ val.setValue(-21.324).setExists(true);+ filler.setValue(23423.423342).setExists(true);+ assertEquals(-21.324, func.getDouble(), .00000001);+ assertTrue(func.exists());++ val.setExists(false);+ filler.setValue(3124123.32).setExists(true);+ assertEquals(3124123.32, func.getDouble(), .00000001);+ assertTrue(func.exists());++ val.setValue(2345.345543).setExists(true);+ filler.setExists(false);+ assertEquals(2345.345543, func.getDouble(), .00000001);+ assertTrue(func.exists());+ }++ @Test+ public void singleValueDateTest() throws DateTimeParseException {+ Date date1 = Date.from(Instant.parse("1810-12-02T10:30:15Z"));+ Date date2 = Date.from(Instant.parse("1950-02-23T14:54:34Z"));+ Date date3 = Date.from(Instant.parse("2023-11-01T20:30:15Z"));++ TestDateValue val = new TestDateValue();+ TestDateValue filler = new TestDateValue();++ AnalyticsValueStream uncasted = FillMissingFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filler});+ assertTrue(uncasted instanceof DateValue);+ DateValue func = (DateValue) uncasted;++ // Value doesn't exist+ val.setExists(false);+ filler.setExists(false);+ func.getLong();+ assertFalse(func.exists());++ // Value exists+ val.setValue("1810-12-02T10:30:15Z").setExists(true);+ filler.setValue("2023-11-01T20:30:15Z").setExists(true);+ assertEquals(date1.getTime(), func.getLong());+ assertTrue(func.exists());++ val.setExists(false);+ filler.setValue("1950-02-23T14:54:34Z").setExists(true);+ assertEquals(date2.getTime(), func.getLong());+ assertTrue(func.exists());++ val.setValue("2023-11-01T20:30:15Z").setExists(true);+ filler.setExists(false);+ assertEquals(date3.getTime(), func.getLong());+ assertTrue(func.exists());+ }++ @Test+ public void singleValueStringTest() {+ TestStringValue val = new TestStringValue();+ TestStringValue filler = new TestStringValue();++ AnalyticsValueStream uncasted = FillMissingFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filler});+ assertTrue(uncasted instanceof StringValue);+ StringValue func = (StringValue) uncasted;++ // Value doesn't exist+ val.setExists(false);+ filler.setExists(false);+ func.getString();+ assertFalse(func.exists());++ // Value exists+ val.setValue("abc123").setExists(true);+ filler.setValue("def456").setExists(true);+ assertEquals("abc123", func.getString());+ assertTrue(func.exists());++ val.setExists(false);+ filler.setValue("abc456").setExists(true);+ assertEquals("abc456", func.getString());+ assertTrue(func.exists());++ val.setValue("def123").setExists(true);+ filler.setExists(false);+ assertEquals("def123", func.getString());+ assertTrue(func.exists());+ }++ @Test+ public void singleValueObjectTest() {+ TestAnalyticsValue val = new TestAnalyticsValue();+ TestAnalyticsValue filler = new TestAnalyticsValue();++ AnalyticsValueStream uncasted = FillMissingFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filler});+ assertTrue(uncasted instanceof AnalyticsValue);+ AnalyticsValue func = (AnalyticsValue) uncasted;++ // Value doesn't exist+ val.setExists(false);+ filler.setExists(false);+ func.getObject();+ assertFalse(func.exists());++ // Value exists+ val.setValue("abc123").setExists(true);+ filler.setValue(new Date(123)).setExists(true);+ assertEquals("abc123", func.getObject());+ assertTrue(func.exists());++ val.setExists(false);+ filler.setValue(new Boolean(true)).setExists(true);+ assertEquals(new Boolean(true), func.getObject());+ assertTrue(func.exists());++ val.setValue(new Long(234)).setExists(true);+ filler.setExists(false);+ assertEquals(new Long(234), func.getObject());+ assertTrue(func.exists());+ }++ @Test+ public void multiValueBooleanTest() {+ TestBooleanValueStream val = new TestBooleanValueStream();+ TestBooleanValueStream filler = new TestBooleanValueStream();++ AnalyticsValueStream uncasted = FillMissingFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filler});+ assertTrue(uncasted instanceof BooleanValueStream);+ BooleanValueStream func = (BooleanValueStream) uncasted;++ // No values+ val.setValues();+ filler.setValues();+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Values exist+ val.setValues(true);+ filler.setValues(true, false);+ Iterator<Boolean> values1 = Arrays.asList(true).iterator();+ func.streamBooleans( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value);+ });+ assertFalse(values1.hasNext());++ val.setValues();+ filler.setValues(true, false);+ Iterator<Boolean> values2 = Arrays.asList(true, false).iterator();+ func.streamBooleans( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value);+ });+ assertFalse(values2.hasNext());++ val.setValues(true, false, true);+ filler.setValues();+ Iterator<Boolean> values3 = Arrays.asList(true, false, true).iterator();+ func.streamBooleans( value -> {+ assertTrue(values3.hasNext());+ assertEquals(values3.next(), value);+ });+ assertFalse(values3.hasNext());+ }++ @Test+ public void multiValueIntTest() {+ TestIntValueStream val = new TestIntValueStream();+ TestIntValueStream filler = new TestIntValueStream();++ AnalyticsValueStream uncasted = FillMissingFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filler});+ assertTrue(uncasted instanceof IntValueStream);+ IntValueStream func = (IntValueStream) uncasted;++ // No values+ val.setValues();+ filler.setValues();+ func.streamInts( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Values exist+ val.setValues(323, -9423);+ filler.setValues(-1234, 5433, -73843, 1245144);+ Iterator<Integer> values1 = Arrays.asList(323, -9423).iterator();+ func.streamInts( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next().intValue(), value);+ });+ assertFalse(values1.hasNext());++ val.setValues();+ filler.setValues(312423, -12343, -23, 2);+ Iterator<Integer> values2 = Arrays.asList(312423, -12343, -23, 2).iterator();+ func.streamInts( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next().intValue(), value);+ });+ assertFalse(values2.hasNext());++ val.setValues(1423, -413543);+ filler.setValues();+ Iterator<Integer> values3 = Arrays.asList(1423, -413543).iterator();+ func.streamInts( value -> {+ assertTrue(values3.hasNext());+ assertEquals(values3.next().intValue(), value);+ });+ assertFalse(values3.hasNext());+ }++ @Test+ public void multiValueLongTest() {+ TestLongValueStream val = new TestLongValueStream();+ TestLongValueStream filler = new TestLongValueStream();++ AnalyticsValueStream uncasted = FillMissingFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filler});+ assertTrue(uncasted instanceof LongValueStream);+ LongValueStream func = (LongValueStream) uncasted;++ // No values+ val.setValues();+ filler.setValues();+ func.streamLongs( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Values exist+ val.setValues(323L, -9423L);+ filler.setValues(-1234L, -5433L, -73843L, 1245144L);+ Iterator<Long> values1 = Arrays.asList(323L, -9423L).iterator();+ func.streamLongs( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next().longValue(), value);+ });+ assertFalse(values1.hasNext());++ val.setValues();+ filler.setValues(-312423L, 12343L, 23L, 2L);+ Iterator<Long> values2 = Arrays.asList(-312423L, 12343L, 23L, 2L).iterator();+ func.streamLongs( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next().longValue(), value);+ });+ assertFalse(values2.hasNext());++ val.setValues(1423L, -413543L);+ filler.setValues();+ Iterator<Long> values3 = Arrays.asList(1423L, -413543L).iterator();+ func.streamLongs( value -> {+ assertTrue(values3.hasNext());+ assertEquals(values3.next().longValue(), value);+ });+ assertFalse(values3.hasNext());+ }++ @Test+ public void multiValueFloatTest() {+ TestFloatValueStream val = new TestFloatValueStream();+ TestFloatValueStream filler = new TestFloatValueStream();++ AnalyticsValueStream uncasted = FillMissingFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filler});+ assertTrue(uncasted instanceof FloatValueStream);+ FloatValueStream func = (FloatValueStream) uncasted;++ // No values+ val.setValues();+ filler.setValues();+ func.streamFloats( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Values exist+ val.setValues(323.213F, -9423.5F);+ filler.setValues(-1234.9478F, -5433.234F, -73843F, 1245144.2342F);+ Iterator<Float> values1 = Arrays.asList(323.213F, -9423.5F).iterator();+ func.streamFloats( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value, .00000001);+ });+ assertFalse(values1.hasNext());++ val.setValues();+ filler.setValues(-312423.2F, 12343.234823F, 23.582F, 2.23F);+ Iterator<Float> values2 = Arrays.asList(-312423.2F, 12343.234823F, 23.582F, 2.23F).iterator();+ func.streamFloats( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value, .00000001);+ });+ assertFalse(values2.hasNext());++ val.setValues(1423.23039F, -413543F);+ filler.setValues();+ Iterator<Float> values3 = Arrays.asList(1423.23039F, -413543F).iterator();+ func.streamFloats( value -> {+ assertTrue(values3.hasNext());+ assertEquals(values3.next(), value, .00000001);+ });+ assertFalse(values3.hasNext());+ }++ @Test+ public void multiValueDoubleTest() {+ TestDoubleValueStream val = new TestDoubleValueStream();+ TestDoubleValueStream filler = new TestDoubleValueStream();++ AnalyticsValueStream uncasted = FillMissingFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filler});+ assertTrue(uncasted instanceof DoubleValueStream);+ DoubleValueStream func = (DoubleValueStream) uncasted;++ // No values+ val.setValues();+ filler.setValues();+ func.streamDoubles( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Values exist+ val.setValues(323.213, -9423.5);+ filler.setValues(-1234.9478, -5433.234, -73843.0, 1245144.2342);+ Iterator<Double> values1 = Arrays.asList(323.213, -9423.5).iterator();+ func.streamDoubles( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value, .00000001);+ });+ assertFalse(values1.hasNext());++ val.setValues();+ filler.setValues(-312423.2, 12343.234823, 23.582, 2.23);+ Iterator<Double> values2 = Arrays.asList(-312423.2, 12343.234823, 23.582, 2.23).iterator();+ func.streamDoubles( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value, .00000001);+ });+ assertFalse(values2.hasNext());++ val.setValues(1423.23039, -413543.0);+ filler.setValues();+ Iterator<Double> values3 = Arrays.asList(1423.23039, -413543.0).iterator();+ func.streamDoubles( value -> {+ assertTrue(values3.hasNext());+ assertEquals(values3.next(), value, .00000001);+ });+ assertFalse(values3.hasNext());+ }++ @Test+ public void multiValueDateTest() throws DateTimeParseException {+ Date date1 = Date.from(Instant.parse("1810-12-02T10:30:15Z"));+ Date date2 = Date.from(Instant.parse("1931-03-16T18:15:45Z"));+ Date date3 = Date.from(Instant.parse("2023-11-01T20:30:15Z"));++ TestDateValueStream val = new TestDateValueStream();+ TestDateValueStream filler = new TestDateValueStream();++ AnalyticsValueStream uncasted = FillMissingFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filler});+ assertTrue(uncasted instanceof DateValueStream);+ DateValueStream func = (DateValueStream) uncasted;++ // No values+ val.setValues();+ filler.setValues();+ func.streamLongs( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Values exist+ val.setValues("1810-12-02T10:30:15Z");+ filler.setValues("1931-03-16T18:15:45Z", "2023-11-01T20:30:15Z");+ Iterator<Long> values1 = Arrays.asList(date1.getTime()).iterator();+ func.streamLongs( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next().longValue(), value);+ });+ assertFalse(values1.hasNext());++ val.setValues();+ filler.setValues("1931-03-16T18:15:45Z", "1810-12-02T10:30:15Z");+ Iterator<Long> values2 = Arrays.asList(date2.getTime(), date1.getTime()).iterator();+ func.streamLongs( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next().longValue(), value);+ });+ assertFalse(values2.hasNext());++ val.setValues("2023-11-01T20:30:15Z", "1931-03-16T18:15:45Z");+ filler.setValues();+ Iterator<Long> values3 = Arrays.asList(date3.getTime(), date2.getTime()).iterator();+ func.streamLongs( value -> {+ assertTrue(values3.hasNext());+ assertEquals(values3.next().longValue(), value);+ });+ assertFalse(values3.hasNext());+ }++ @Test+ public void multiValueStringTest() {+ TestStringValueStream val = new TestStringValueStream();+ TestStringValueStream filler = new TestStringValueStream();++ AnalyticsValueStream uncasted = FillMissingFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filler});+ assertTrue(uncasted instanceof StringValueStream);+ StringValueStream func = (StringValueStream) uncasted;++ // No values+ val.setValues();+ filler.setValues();+ func.streamStrings( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Values exist+ val.setValues("abc");+ filler.setValues("123", "def");+ Iterator<String> values1 = Arrays.asList("abc").iterator();+ func.streamStrings( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value);+ });+ assertFalse(values1.hasNext());++ val.setValues();+ filler.setValues("def", "12341");+ Iterator<String> values2 = Arrays.asList("def", "12341").iterator();+ func.streamStrings( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value);+ });+ assertFalse(values2.hasNext());++ val.setValues("string1", "another string", "the final and last string");+ filler.setValues();+ Iterator<String> values3 = Arrays.asList("string1", "another string", "the final and last string").iterator();+ func.streamStrings( value -> {+ assertTrue(values3.hasNext());+ assertEquals(values3.next(), value);+ });+ assertFalse(values3.hasNext());+ }++ @Test+ public void multiValueObjectTest() {+ TestAnalyticsValueStream val = new TestAnalyticsValueStream();+ TestAnalyticsValueStream filler = new TestAnalyticsValueStream();++ AnalyticsValueStream func = FillMissingFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filler});++ // No values+ val.setValues();+ filler.setValues();+ func.streamObjects( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Values exist+ val.setValues("asdfs");+ filler.setValues(new Date(12312), new Long(213123L));+ Iterator<Object> values1 = Arrays.<Object>asList("asdfs").iterator();+ func.streamObjects( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value);+ });+ assertFalse(values1.hasNext());++ val.setValues();+ filler.setValues(new Double(3234.42), "replacement");+ Iterator<Object> values2 = Arrays.<Object>asList(new Double(3234.42), "replacement").iterator();+ func.streamObjects( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value);+ });+ assertFalse(values2.hasNext());++ val.setValues(new Date(3), "3", new Float(3F));+ filler.setValues();+ Iterator<Object> values3 = Arrays.<Object>asList(new Date(3), "3", new Float(3F)).iterator();+ func.streamObjects( value -> {+ assertTrue(values3.hasNext());+ assertEquals(values3.next(), value);+ });+ assertFalse(values3.hasNext());+ }+}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/FilterFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/FilterFunctionTest.javanew file mode 100644index 00000000000..e2bcc7350f5--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/FilterFunctionTest.java@@ -0,0 +1,1035 @@+/*+ * 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.analytics.function.mapping;++import java.time.Instant;+import java.time.format.DateTimeParseException;+import java.util.Arrays;+import java.util.Date;+import java.util.Iterator;++import org.apache.solr.SolrTestCaseJ4;+import org.apache.solr.analytics.value.AnalyticsValue;+import org.apache.solr.analytics.value.AnalyticsValueStream;+import org.apache.solr.analytics.value.BooleanValue;+import org.apache.solr.analytics.value.BooleanValueStream;+import org.apache.solr.analytics.value.DateValue;+import org.apache.solr.analytics.value.DateValueStream;+import org.apache.solr.analytics.value.DoubleValue;+import org.apache.solr.analytics.value.DoubleValueStream;+import org.apache.solr.analytics.value.FloatValue;+import org.apache.solr.analytics.value.FloatValueStream;+import org.apache.solr.analytics.value.IntValue;+import org.apache.solr.analytics.value.IntValueStream;+import org.apache.solr.analytics.value.LongValue;+import org.apache.solr.analytics.value.LongValueStream;+import org.apache.solr.analytics.value.StringValue;+import org.apache.solr.analytics.value.StringValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestAnalyticsValue;+import org.apache.solr.analytics.value.FillableTestValue.TestAnalyticsValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestBooleanValue;+import org.apache.solr.analytics.value.FillableTestValue.TestBooleanValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestDateValue;+import org.apache.solr.analytics.value.FillableTestValue.TestDateValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValue;+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValue;+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestIntValue;+import org.apache.solr.analytics.value.FillableTestValue.TestIntValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestLongValue;+import org.apache.solr.analytics.value.FillableTestValue.TestLongValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestStringValue;+import org.apache.solr.analytics.value.FillableTestValue.TestStringValueStream;+import org.junit.Test;++public class FilterFunctionTest extends SolrTestCaseJ4 {++ @Test+ public void singleValueBooleanTest() {+ TestBooleanValue val = new TestBooleanValue();+ TestBooleanValue filter = new TestBooleanValue();++ AnalyticsValueStream uncasted = FilterFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filter});+ assertTrue(uncasted instanceof BooleanValue);+ BooleanValue func = (BooleanValue) uncasted;++ // Value doesn't exist+ val.setExists(false);+ filter.setExists(false);+ func.getBoolean();+ assertFalse(func.exists());++ val.setValue(true).setExists(true);+ filter.setExists(false);+ func.getBoolean();+ assertFalse(func.exists());++ val.setExists(false);+ filter.setValue(true).setExists(true);+ func.getBoolean();+ assertFalse(func.exists());++ // Value exists+ val.setValue(true).setExists(true);+ filter.setValue(true).setExists(true);+ assertEquals(true, func.getBoolean());+ assertTrue(func.exists());++ val.setValue(true).setExists(true);+ filter.setValue(false).setExists(true);+ func.getBoolean();+ assertFalse(func.exists());++ val.setValue(false).setExists(true);+ filter.setValue(true).setExists(true);+ assertEquals(false, func.getBoolean());+ assertTrue(func.exists());++ val.setValue(false).setExists(true);+ filter.setValue(false).setExists(true);+ func.getBoolean();+ assertFalse(func.exists());+ }++ @Test+ public void singleValueIntTest() {+ TestIntValue val = new TestIntValue();+ TestBooleanValue filter = new TestBooleanValue();++ AnalyticsValueStream uncasted = FilterFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filter});+ assertTrue(uncasted instanceof IntValue);+ IntValue func = (IntValue) uncasted;++ // Value doesn't exist+ val.setExists(false);+ filter.setExists(false);+ func.getInt();+ assertFalse(func.exists());++ val.setValue(32).setExists(true);+ filter.setExists(false);+ func.getInt();+ assertFalse(func.exists());++ val.setExists(false);+ filter.setValue(true).setExists(true);+ func.getInt();+ assertFalse(func.exists());++ // Value exists+ val.setValue(21).setExists(true);+ filter.setValue(true).setExists(true);+ assertEquals(21, func.getInt());+ assertTrue(func.exists());++ val.setValue(-100).setExists(true);+ filter.setValue(false).setExists(true);+ func.getInt();+ assertFalse(func.exists());++ val.setValue(50).setExists(true);+ filter.setValue(true).setExists(true);+ assertEquals(50, func.getInt());+ assertTrue(func.exists());++ val.setValue(5432).setExists(true);+ filter.setValue(false).setExists(true);+ func.getInt();+ assertFalse(func.exists());+ }++ @Test+ public void singleValueLongTest() {+ TestLongValue val = new TestLongValue();+ TestBooleanValue filter = new TestBooleanValue();++ AnalyticsValueStream uncasted = FilterFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filter});+ assertTrue(uncasted instanceof LongValue);+ LongValue func = (LongValue) uncasted;++ // Value doesn't exist+ val.setExists(false);+ filter.setExists(false);+ func.getLong();+ assertFalse(func.exists());++ val.setValue(32L).setExists(true);+ filter.setExists(false);+ func.getLong();+ assertFalse(func.exists());++ val.setExists(false);+ filter.setValue(true).setExists(true);+ func.getLong();+ assertFalse(func.exists());++ // Value exists+ val.setValue(21L).setExists(true);+ filter.setValue(true).setExists(true);+ assertEquals(21L, func.getLong());+ assertTrue(func.exists());++ val.setValue(-100L).setExists(true);+ filter.setValue(false).setExists(true);+ func.getLong();+ assertFalse(func.exists());++ val.setValue(50L).setExists(true);+ filter.setValue(true).setExists(true);+ assertEquals(50L, func.getLong());+ assertTrue(func.exists());++ val.setValue(3245L).setExists(true);+ filter.setValue(false).setExists(true);+ func.getLong();+ assertFalse(func.exists());+ }++ @Test+ public void singleValueFloatTest() {+ TestFloatValue val = new TestFloatValue();+ TestBooleanValue filter = new TestBooleanValue();++ AnalyticsValueStream uncasted = FilterFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filter});+ assertTrue(uncasted instanceof FloatValue);+ FloatValue func = (FloatValue) uncasted;++ // Value doesn't exist+ val.setExists(false);+ filter.setExists(false);+ func.getFloat();+ assertFalse(func.exists());++ val.setValue(32.123F).setExists(true);+ filter.setExists(false);+ func.getFloat();+ assertFalse(func.exists());++ val.setExists(false);+ filter.setValue(true).setExists(true);+ func.getFloat();+ assertFalse(func.exists());++ // Value exists+ val.setValue(21.453F).setExists(true);+ filter.setValue(true).setExists(true);+ assertEquals(21.453F, func.getFloat(), .000001);+ assertTrue(func.exists());++ val.setValue(-100.123F).setExists(true);+ filter.setValue(false).setExists(true);+ func.getFloat();+ assertFalse(func.exists());++ val.setValue(50.5F).setExists(true);+ filter.setValue(true).setExists(true);+ assertEquals(50.5F, func.getFloat(), .000001);+ assertTrue(func.exists());++ val.setValue(25643.23F).setExists(true);+ filter.setValue(false).setExists(true);+ func.getFloat();+ assertFalse(func.exists());+ }++ @Test+ public void singleValueDoubleTest() {+ TestDoubleValue val = new TestDoubleValue();+ TestBooleanValue filter = new TestBooleanValue();++ AnalyticsValueStream uncasted = FilterFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filter});+ assertTrue(uncasted instanceof DoubleValue);+ DoubleValue func = (DoubleValue) uncasted;++ // Value doesn't exist+ val.setExists(false);+ filter.setExists(false);+ func.getDouble();+ assertFalse(func.exists());++ val.setValue(32.123).setExists(true);+ filter.setExists(false);+ func.getDouble();+ assertFalse(func.exists());++ val.setExists(false);+ filter.setValue(true).setExists(true);+ func.getDouble();+ assertFalse(func.exists());++ // Value exists+ val.setValue(21.453).setExists(true);+ filter.setValue(true).setExists(true);+ assertEquals(21.453, func.getDouble(), .000001);+ assertTrue(func.exists());++ val.setValue(-100.123).setExists(true);+ filter.setValue(false).setExists(true);+ func.getDouble();+ assertFalse(func.exists());++ val.setValue(50.5).setExists(true);+ filter.setValue(true).setExists(true);+ assertEquals(50.5, func.getDouble(), .000001);+ assertTrue(func.exists());++ val.setValue(25643.23).setExists(true);+ filter.setValue(false).setExists(true);+ func.getDouble();+ assertFalse(func.exists());+ }++ @Test+ public void singleValueDateTest() throws DateTimeParseException {+ Date date1 = Date.from(Instant.parse("1810-12-02T10:30:15Z"));+ Date date3 = Date.from(Instant.parse("2023-11-01T20:30:15Z"));++ TestDateValue val = new TestDateValue();+ TestBooleanValue filter = new TestBooleanValue();++ AnalyticsValueStream uncasted = FilterFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filter});+ assertTrue(uncasted instanceof DateValue);+ DateValue func = (DateValue) uncasted;++ // Value doesn't exist+ val.setExists(false);+ filter.setExists(false);+ func.getLong();+ assertFalse(func.exists());++ val.setValue("1810-12-02T10:30:15Z").setExists(true);+ filter.setExists(false);+ func.getLong();+ assertFalse(func.exists());++ val.setExists(false);+ filter.setValue(true).setExists(true);+ func.getLong();+ assertFalse(func.exists());++ // Value exists+ val.setValue("1810-12-02T10:30:15Z").setExists(true);+ filter.setValue(true).setExists(true);+ assertEquals(date1.getTime(), func.getLong());+ assertTrue(func.exists());++ val.setValue("1931-03-16T18:15:45Z").setExists(true);+ filter.setValue(false).setExists(true);+ func.getLong();+ assertFalse(func.exists());++ val.setValue("2023-11-01T20:30:15Z").setExists(true);+ filter.setValue(true).setExists(true);+ assertEquals(date3.getTime(), func.getLong());+ assertTrue(func.exists());++ val.setValue("1810-12-02T10:30:15Z").setExists(true);+ filter.setValue(false).setExists(true);+ func.getLong();+ assertFalse(func.exists());+ }++ @Test+ public void singleValueStringTest() {+ TestStringValue val = new TestStringValue();+ TestBooleanValue filter = new TestBooleanValue();++ AnalyticsValueStream uncasted = FilterFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filter});+ assertTrue(uncasted instanceof StringValue);+ StringValue func = (StringValue) uncasted;++ // Value doesn't exist+ val.setExists(false);+ filter.setExists(false);+ func.getString();+ assertFalse(func.exists());++ val.setValue("abc123").setExists(true);+ filter.setExists(false);+ func.getString();+ assertFalse(func.exists());++ val.setExists(false);+ filter.setValue(true).setExists(true);+ func.getString();+ assertFalse(func.exists());++ // Value exists+ val.setValue("abc").setExists(true);+ filter.setValue(true).setExists(true);+ assertEquals("abc", func.getString());+ assertTrue(func.exists());++ val.setValue("def").setExists(true);+ filter.setValue(false).setExists(true);+ func.getString();+ assertFalse(func.exists());++ val.setValue("123").setExists(true);+ filter.setValue(true).setExists(true);+ assertEquals("123", func.getString());+ assertTrue(func.exists());++ val.setValue("456").setExists(true);+ filter.setValue(false).setExists(true);+ func.getString();+ assertFalse(func.exists());+ }++ @Test+ public void singleValueObjectTest() {+ TestAnalyticsValue val = new TestAnalyticsValue();+ TestBooleanValue filter = new TestBooleanValue();++ AnalyticsValueStream uncasted = FilterFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filter});+ assertTrue(uncasted instanceof AnalyticsValue);+ AnalyticsValue func = (AnalyticsValue) uncasted;++ // Value doesn't exist+ val.setExists(false);+ filter.setExists(false);+ func.getObject();+ assertFalse(func.exists());++ val.setValue("1810-12-02T10:30:15Z").setExists(true);+ filter.setExists(false);+ func.getObject();+ assertFalse(func.exists());++ val.setExists(false);+ filter.setValue(true).setExists(true);+ func.getObject();+ assertFalse(func.exists());++ // Value exists+ val.setValue(new Long(3)).setExists(true);+ filter.setValue(true).setExists(true);+ assertEquals(new Long(3), func.getObject());+ assertTrue(func.exists());++ val.setValue(new Date(2)).setExists(true);+ filter.setValue(false).setExists(true);+ func.getObject();+ assertFalse(func.exists());++ val.setValue("3").setExists(true);+ filter.setValue(true).setExists(true);+ assertEquals("3", func.getObject());+ assertTrue(func.exists());++ val.setValue(new TestAnalyticsValue()).setExists(true);+ filter.setValue(false).setExists(true);+ func.getObject();+ assertFalse(func.exists());+ }++ @Test+ public void multiValueBooleanTest() {+ TestBooleanValueStream val = new TestBooleanValueStream();+ TestBooleanValue filter = new TestBooleanValue();++ AnalyticsValueStream uncasted = FilterFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filter});+ assertTrue(uncasted instanceof BooleanValueStream);+ BooleanValueStream func = (BooleanValueStream) uncasted;++ // No values+ val.setValues();+ filter.setExists(false);+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ val.setValues(false, true, false);+ filter.setExists(false);+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ val.setValues();+ filter.setValue(true).setExists(true);+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // One value+ val.setValues(true);++ filter.setValue(true).setExists(true);+ Iterator<Boolean> values1 = Arrays.asList(true).iterator();+ func.streamBooleans( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value);+ });+ assertFalse(values1.hasNext());++ filter.setValue(false).setExists(true);+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ filter.setValue(true).setExists(true);+ Iterator<Boolean> values2 = Arrays.asList(true).iterator();+ func.streamBooleans( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value);+ });+ assertFalse(values2.hasNext());++ // Multiple values+ val.setValues(false, false, true, true);++ filter.setValue(false).setExists(true);+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ filter.setValue(true).setExists(true);+ Iterator<Boolean> values3 = Arrays.asList(false, false, true, true).iterator();+ func.streamBooleans( value -> {+ assertTrue(values3.hasNext());+ assertEquals(values3.next(), value);+ });+ assertFalse(values3.hasNext());++ filter.setValue(false).setExists(true);+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });+ }++ @Test+ public void multiValueIntTest() {+ TestIntValueStream val = new TestIntValueStream();+ TestBooleanValue filter = new TestBooleanValue();++ AnalyticsValueStream uncasted = FilterFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filter});+ assertTrue(uncasted instanceof IntValueStream);+ IntValueStream func = (IntValueStream) uncasted;++ // No values+ val.setValues();+ filter.setExists(false);+ func.streamInts( value -> {+ assertTrue("There should be no values to stream", false);+ });++ val.setValues(1, 3, 5);+ filter.setExists(false);+ func.streamInts( value -> {+ assertTrue("There should be no values to stream", false);+ });++ val.setValues();+ filter.setValue(true).setExists(true);+ func.streamInts( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // One value+ val.setValues(-4);++ filter.setValue(true).setExists(true);+ Iterator<Integer> values1 = Arrays.asList(-4).iterator();+ func.streamInts( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next().intValue(), value);+ });+ assertFalse(values1.hasNext());++ filter.setValue(false).setExists(true);+ func.streamInts( value -> {+ assertTrue("There should be no values to stream", false);+ });++ filter.setValue(true).setExists(true);+ Iterator<Integer> values2 = Arrays.asList(-4).iterator();+ func.streamInts( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next().intValue(), value);+ });+ assertFalse(values2.hasNext());++ // Multiple values+ val.setValues(4, -10, 50, -74);++ filter.setValue(false).setExists(true);+ func.streamInts( value -> {+ assertTrue("There should be no values to stream", false);+ });++ filter.setValue(true).setExists(true);+ Iterator<Integer> values3 = Arrays.asList(4, -10, 50, -74).iterator();+ func.streamInts( value -> {+ assertTrue(values3.hasNext());+ assertEquals(values3.next().intValue(), value);+ });+ assertFalse(values3.hasNext());++ filter.setValue(false).setExists(true);+ func.streamInts( value -> {+ assertTrue("There should be no values to stream", false);+ });+ }++ @Test+ public void multiValueLongTest() {+ TestLongValueStream val = new TestLongValueStream();+ TestBooleanValue filter = new TestBooleanValue();++ AnalyticsValueStream uncasted = FilterFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filter});+ assertTrue(uncasted instanceof LongValueStream);+ LongValueStream func = (LongValueStream) uncasted;++ // No values+ val.setValues();+ filter.setExists(false);+ func.streamLongs( value -> {+ assertTrue("There should be no values to stream", false);+ });++ val.setValues(1L, 3L, 5L);+ filter.setExists(false);+ func.streamLongs( value -> {+ assertTrue("There should be no values to stream", false);+ });++ val.setValues();+ filter.setValue(true).setExists(true);+ func.streamLongs( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // One value+ val.setValues(-4L);++ filter.setValue(true).setExists(true);+ Iterator<Long> values1 = Arrays.asList(-4L).iterator();+ func.streamLongs( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next().longValue(), value);+ });+ assertFalse(values1.hasNext());++ filter.setValue(false).setExists(true);+ func.streamLongs( value -> {+ assertTrue("There should be no values to stream", false);+ });++ filter.setValue(true).setExists(true);+ Iterator<Long> values2 = Arrays.asList(-4L).iterator();+ func.streamLongs( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next().longValue(), value);+ });+ assertFalse(values2.hasNext());++ // Multiple values+ val.setValues(4L, -10L, 50L, -74L);++ filter.setValue(false).setExists(true);+ func.streamLongs( value -> {+ assertTrue("There should be no values to stream", false);+ });++ filter.setValue(true).setExists(true);+ Iterator<Long> values3 = Arrays.asList(4L, -10L, 50L, -74L).iterator();+ func.streamLongs( value -> {+ assertTrue(values3.hasNext());+ assertEquals(values3.next().longValue(), value);+ });+ assertFalse(values3.hasNext());++ filter.setValue(false).setExists(true);+ func.streamLongs( value -> {+ assertTrue("There should be no values to stream", false);+ });+ }++ @Test+ public void multiValueFloatTest() {+ TestFloatValueStream val = new TestFloatValueStream();+ TestBooleanValue filter = new TestBooleanValue();++ AnalyticsValueStream uncasted = FilterFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filter});+ assertTrue(uncasted instanceof FloatValueStream);+ FloatValueStream func = (FloatValueStream) uncasted;++ // No values+ val.setValues();+ filter.setExists(false);+ func.streamFloats( value -> {+ assertTrue("There should be no values to stream", false);+ });++ val.setValues(50.343F, -74.9874F, 2342332342.32F);+ filter.setExists(false);+ func.streamFloats( value -> {+ assertTrue("There should be no values to stream", false);+ });++ val.setValues();+ filter.setValue(true).setExists(true);+ func.streamFloats( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // One value+ val.setValues(-4.23423F);++ filter.setValue(true).setExists(true);+ Iterator<Float> values1 = Arrays.asList(-4.23423F).iterator();+ func.streamFloats( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value, .0000001);+ });+ assertFalse(values1.hasNext());++ filter.setValue(false).setExists(true);+ func.streamFloats( value -> {+ assertTrue("There should be no values to stream", false);+ });++ filter.setValue(true).setExists(true);+ Iterator<Float> values2 = Arrays.asList(-4.23423F).iterator();+ func.streamFloats( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value, .0000001);+ });+ assertFalse(values2.hasNext());++ // Multiple values+ val.setValues(4.3F, -10.134F, 50.343F, -74.9874F);++ filter.setValue(false).setExists(true);+ func.streamFloats( value -> {+ assertTrue("There should be no values to stream", false);+ });++ filter.setValue(true).setExists(true);+ Iterator<Float> values3 = Arrays.asList(4.3F, -10.134F, 50.343F, -74.9874F).iterator();+ func.streamFloats( value -> {+ assertTrue(values3.hasNext());+ assertEquals(values3.next(), value, .0000001);+ });+ assertFalse(values3.hasNext());++ filter.setValue(false).setExists(true);+ func.streamFloats( value -> {+ assertTrue("There should be no values to stream", false);+ });+ }++ @Test+ public void multiValueDoubleTest() {+ TestDoubleValueStream val = new TestDoubleValueStream();+ TestBooleanValue filter = new TestBooleanValue();++ AnalyticsValueStream uncasted = FilterFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filter});+ assertTrue(uncasted instanceof DoubleValueStream);+ DoubleValueStream func = (DoubleValueStream) uncasted;++ // No values+ val.setValues();+ filter.setExists(false);+ func.streamDoubles( value -> {+ assertTrue("There should be no values to stream", false);+ });++ val.setValues(50.343, -74.9874, 2342332342.32);+ filter.setExists(false);+ func.streamDoubles( value -> {+ assertTrue("There should be no values to stream", false);+ });++ val.setValues();+ filter.setValue(true).setExists(true);+ func.streamDoubles( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // One value+ val.setValues(-4.23423);++ filter.setValue(true).setExists(true);+ Iterator<Double> values1 = Arrays.asList(-4.23423).iterator();+ func.streamDoubles( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value, .0000001);+ });+ assertFalse(values1.hasNext());++ filter.setValue(false).setExists(true);+ func.streamDoubles( value -> {+ assertTrue("There should be no values to stream", false);+ });++ filter.setValue(true).setExists(true);+ Iterator<Double> values2 = Arrays.asList(-4.23423).iterator();+ func.streamDoubles( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value, .0000001);+ });+ assertFalse(values2.hasNext());++ // Multiple values+ val.setValues(4.3, -10.134, 50.343, -74.9874);++ filter.setValue(false).setExists(true);+ func.streamDoubles( value -> {+ assertTrue("There should be no values to stream", false);+ });++ filter.setValue(true).setExists(true);+ Iterator<Double> values3 = Arrays.asList(4.3, -10.134, 50.343, -74.9874).iterator();+ func.streamDoubles( value -> {+ assertTrue(values3.hasNext());+ assertEquals(values3.next(), value, .0000001);+ });+ assertFalse(values3.hasNext());++ filter.setValue(false).setExists(true);+ func.streamDoubles( value -> {+ assertTrue("There should be no values to stream", false);+ });+ }++ @Test+ public void multiValueDateTest() throws DateTimeParseException {+ Date date1 = Date.from(Instant.parse("1810-12-02T10:30:15Z"));+ Date date2 = Date.from(Instant.parse("1931-03-16T18:15:45Z"));+ Date date3 = Date.from(Instant.parse("2023-11-01T20:30:15Z"));++ TestDateValueStream val = new TestDateValueStream();+ TestBooleanValue filter = new TestBooleanValue();++ AnalyticsValueStream uncasted = FilterFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filter});+ assertTrue(uncasted instanceof DateValueStream);+ DateValueStream func = (DateValueStream) uncasted;++ // No values+ val.setValues();+ filter.setExists(false);+ func.streamLongs( value -> {+ assertTrue("There should be no values to stream", false);+ });++ val.setValues("1810-12-02T10:30:15Z", "1850-12-02T20:30:15Z");+ filter.setExists(false);+ func.streamLongs( value -> {+ assertTrue("There should be no values to stream", false);+ });++ val.setValues();+ filter.setValue(true).setExists(true);+ func.streamLongs( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // One value+ val.setValues("1810-12-02T10:30:15Z");++ filter.setValue(true).setExists(true);+ Iterator<Long> values1 = Arrays.asList(date1.getTime()).iterator();+ func.streamLongs( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next().longValue(), value);+ });+ assertFalse(values1.hasNext());++ filter.setValue(false).setExists(true);+ func.streamLongs( value -> {+ assertTrue("There should be no values to stream", false);+ });++ filter.setValue(true).setExists(true);+ Iterator<Long> values2 = Arrays.asList(date1.getTime()).iterator();+ func.streamLongs( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next().longValue(), value);+ });+ assertFalse(values2.hasNext());++ // Multiple values+ val.setValues("1810-12-02T10:30:15Z", "1931-03-16T18:15:45Z", "2023-11-01T20:30:15Z");++ filter.setValue(false).setExists(true);+ func.streamLongs( value -> {+ assertTrue("There should be no values to stream", false);+ });++ filter.setValue(true).setExists(true);+ Iterator<Long> values3 = Arrays.asList(date1.getTime(), date2.getTime(), date3.getTime()).iterator();+ func.streamLongs( value -> {+ assertTrue(values3.hasNext());+ assertEquals(values3.next().longValue(), value);+ });+ assertFalse(values3.hasNext());++ filter.setValue(false).setExists(true);+ func.streamLongs( value -> {+ assertTrue("There should be no values to stream", false);+ });+ }++ @Test+ public void multiValueStringTest() {+ TestStringValueStream val = new TestStringValueStream();+ TestBooleanValue filter = new TestBooleanValue();++ AnalyticsValueStream uncasted = FilterFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filter});+ assertTrue(uncasted instanceof StringValueStream);+ StringValueStream func = (StringValueStream) uncasted;++ // No values+ val.setValues();+ filter.setExists(false);+ func.streamStrings( value -> {+ assertTrue("There should be no values to stream", false);+ });++ val.setValues("abc", "123", "def", "456");+ filter.setExists(false);+ func.streamStrings( value -> {+ assertTrue("There should be no values to stream", false);+ });++ val.setValues();+ filter.setValue(true).setExists(true);+ func.streamStrings( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // One value+ val.setValues("abcdef");++ filter.setValue(true).setExists(true);+ Iterator<String> values1 = Arrays.asList("abcdef").iterator();+ func.streamStrings( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value);+ });+ assertFalse(values1.hasNext());++ filter.setValue(false).setExists(true);+ func.streamStrings( value -> {+ assertTrue("There should be no values to stream", false);+ });++ filter.setValue(true).setExists(true);+ Iterator<String> values2 = Arrays.asList("abcdef").iterator();+ func.streamStrings( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value);+ });+ assertFalse(values2.hasNext());++ // Multiple values+ val.setValues("abc", "123", "def", "456");++ filter.setValue(false).setExists(true);+ func.streamStrings( value -> {+ assertTrue("There should be no values to stream", false);+ });++ filter.setValue(true).setExists(true);+ Iterator<String> values3 = Arrays.asList("abc", "123", "def", "456").iterator();+ func.streamStrings( value -> {+ assertTrue(values3.hasNext());+ assertEquals(values3.next(), value);+ });+ assertFalse(values3.hasNext());++ filter.setValue(false).setExists(true);+ func.streamStrings( value -> {+ assertTrue("There should be no values to stream", false);+ });+ }++ @Test+ public void multiValueObjectTest() {+ TestAnalyticsValueStream val = new TestAnalyticsValueStream();+ TestBooleanValue filter = new TestBooleanValue();++ AnalyticsValueStream func = FilterFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filter});++ // No values+ val.setValues();+ filter.setExists(false);+ func.streamObjects( value -> {+ assertTrue("There should be no values to stream", false);+ });++ val.setValues(new Integer(3), "3", new Date(3));+ filter.setExists(false);+ func.streamObjects( value -> {+ assertTrue("There should be no values to stream", false);+ });++ val.setValues();+ filter.setValue(true).setExists(true);+ func.streamObjects( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // One value+ Object obj = new TestAnalyticsValueStream();+ val.setValues(obj);++ filter.setValue(true).setExists(true);+ Iterator<Object> values1 = Arrays.<Object>asList(obj).iterator();+ func.streamObjects( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value);+ });+ assertFalse(values1.hasNext());++ filter.setValue(false).setExists(true);+ func.streamObjects( value -> {+ assertTrue("There should be no values to stream", false);+ });++ filter.setValue(true).setExists(true);+ Iterator<Object> values2 = Arrays.<Object>asList(obj).iterator();+ func.streamObjects( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value);+ });+ assertFalse(values2.hasNext());++ // Multiple values+ val.setValues(new Integer(3), "3", new Date(3));++ filter.setValue(false).setExists(true);+ func.streamObjects( value -> {+ assertTrue("There should be no values to stream", false);+ });++ filter.setValue(true).setExists(true);+ Iterator<Object> values3 = Arrays.<Object>asList(new Integer(3), "3", new Date(3)).iterator();+ func.streamObjects( value -> {+ assertTrue(values3.hasNext());+ assertEquals(values3.next(), value);+ });+ assertFalse(values3.hasNext());++ filter.setValue(false).setExists(true);+ func.streamObjects( value -> {+ assertTrue("There should be no values to stream", false);+ });+ }+}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/FloorFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/FloorFunctionTest.javanew file mode 100644index 00000000000..ba94fb6a074--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/FloorFunctionTest.java@@ -0,0 +1,180 @@+/*+ * 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.analytics.function.mapping;++import java.util.Arrays;+import java.util.Iterator;++import org.apache.solr.SolrTestCaseJ4;+import org.apache.solr.analytics.function.mapping.DecimalNumericConversionFunction.FloorFunction;+import org.apache.solr.analytics.value.AnalyticsValueStream;+import org.apache.solr.analytics.value.IntValue;+import org.apache.solr.analytics.value.IntValueStream;+import org.apache.solr.analytics.value.LongValue;+import org.apache.solr.analytics.value.LongValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValue;+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValue;+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestIntValue;+import org.apache.solr.analytics.value.FillableTestValue.TestIntValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestLongValue;+import org.apache.solr.analytics.value.FillableTestValue.TestLongValueStream;+import org.junit.Test;++public class FloorFunctionTest extends SolrTestCaseJ4 {++ @Test+ public void singleValueFloatParameterTest() {+ TestFloatValue val = new TestFloatValue();++ AnalyticsValueStream uncasted = FloorFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});+ assertTrue(uncasted instanceof IntValue);+ IntValue func = (IntValue) uncasted;++ // Value doesn't exist+ val.setExists(false);+ func.getInt();+ assertFalse(func.exists());++ // Value exists+ val.setValue(21.56F).setExists(true);+ assertEquals(21, func.getInt());+ assertTrue(func.exists());++ val.setValue(-100.3F).setExists(true);+ assertEquals(-101, func.getInt());+ assertTrue(func.exists());+ }++ @Test+ public void singleValueDoubleParameterTest() {+ TestDoubleValue val = new TestDoubleValue();++ AnalyticsValueStream uncasted = FloorFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});+ assertTrue(uncasted instanceof LongValue);+ LongValue func = (LongValue) uncasted;++ // Value doesn't exist+ val.setExists(false);+ func.getLong();+ assertFalse(func.exists());++ // Value exists+ val.setValue(21.56).setExists(true);+ assertEquals(21L, func.getLong());+ assertTrue(func.exists());++ val.setValue(-100.3).setExists(true);+ assertEquals(-101L, func.getLong());+ assertTrue(func.exists());+ }++ @Test+ public void multiValueFloatParameterTest() {+ TestFloatValueStream val = new TestFloatValueStream();++ AnalyticsValueStream uncasted = FloorFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});+ assertTrue(uncasted instanceof IntValueStream);+ IntValueStream func = (IntValueStream) uncasted;++ // No values+ val.setValues();+ func.streamInts( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // One value+ val.setValues(-4F);+ Iterator<Integer> values1 = Arrays.asList(-4).iterator();+ func.streamInts( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next().intValue(), value);+ });+ assertFalse(values1.hasNext());++ // Multiple values+ val.setValues(4F, -10.9999F, 50.00001F, 74.99999F);+ Iterator<Integer> values2 = Arrays.asList(4, -11, 50, 74).iterator();+ func.streamInts( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next().intValue(), value);+ });+ assertFalse(values2.hasNext());+ }++ @Test+ public void multiValueDoubleParameterTest() {+ TestDoubleValueStream val = new TestDoubleValueStream();++ AnalyticsValueStream uncasted = FloorFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});+ assertTrue(uncasted instanceof LongValueStream);+ LongValueStream func = (LongValueStream) uncasted;++ // No values+ val.setValues();+ func.streamLongs( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // One value+ val.setValues(-4);+ Iterator<Long> values1 = Arrays.asList(-4L).iterator();+ func.streamLongs( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next().longValue(), value);+ });+ assertFalse(values1.hasNext());++ // Multiple values+ val.setValues(4, -10.9999, 50.000001, 74.99999);+ Iterator<Long> values2 = Arrays.asList(4L, -11L, 50L, 74L).iterator();+ func.streamLongs( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next().longValue(), value);+ });+ assertFalse(values2.hasNext());+ }++ @Test+ public void nonDecimalParameterTest() {+ AnalyticsValueStream result;+ AnalyticsValueStream param;++ param = new TestIntValue();+ result = FloorFunction.creatorFunction.apply(new AnalyticsValueStream[] {param});+ assertTrue(result instanceof IntValue);+ assertEquals(param, result);++ param = new TestIntValueStream();+ result = FloorFunction.creatorFunction.apply(new AnalyticsValueStream[] {param});+ assertTrue(result instanceof IntValueStream);+ assertEquals(param, result);++ param = new TestLongValue();+ result = FloorFunction.creatorFunction.apply(new AnalyticsValueStream[] {param});+ assertTrue(result instanceof LongValue);+ assertEquals(param, result);++ param = new TestLongValueStream();+ result = FloorFunction.creatorFunction.apply(new AnalyticsValueStream[] {param});+ assertTrue(result instanceof LongValueStream);+ assertEquals(param, result);+ }+++}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/GTEFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/GTEFunctionTest.javanew file mode 100644index 00000000000..b6883c55ae7--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/GTEFunctionTest.java@@ -0,0 +1,290 @@+/*+ * 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.analytics.function.mapping;++import java.util.Arrays;+import java.util.Iterator;++import org.apache.solr.SolrTestCaseJ4;+import org.apache.solr.analytics.function.mapping.ComparisonFunction.GTEFunction;+import org.apache.solr.analytics.value.AnalyticsValueStream;+import org.apache.solr.analytics.value.BooleanValue;+import org.apache.solr.analytics.value.BooleanValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestDateValue;+import org.apache.solr.analytics.value.FillableTestValue.TestDateValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValue;+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValueStream;+import org.junit.Test;++public class GTEFunctionTest extends SolrTestCaseJ4 {++ @Test+ public void singleValueNumericParameterTest() {+ TestDoubleValue base = new TestDoubleValue();+ TestDoubleValue comp = new TestDoubleValue();++ AnalyticsValueStream uncasted = GTEFunction.creatorFunction.apply(new AnalyticsValueStream[] {base, comp});+ assertTrue(uncasted instanceof BooleanValue);+ BooleanValue func = (BooleanValue) uncasted;++ // Value doesn't exist+ base.setExists(false);+ comp.setExists(false);+ func.getBoolean();+ assertFalse(func.exists());++ base.setExists(false);+ comp.setValue(3.3).setExists(true);+ func.getBoolean();+ assertFalse(func.exists());++ base.setValue(3.3).setExists(true);+ comp.setExists(false);+ func.getBoolean();+ assertFalse(func.exists());++ // Value exists+ base.setValue(21.56).setExists(true);+ comp.setValue(21.56).setExists(true);+ assertEquals(true, func.getBoolean());+ assertTrue(func.exists());++ base.setValue(21.56).setExists(true);+ comp.setValue(21.57).setExists(true);+ assertEquals(false, func.getBoolean());+ assertTrue(func.exists());++ base.setValue(21.56).setExists(true);+ comp.setValue(-21.57).setExists(true);+ assertEquals(true, func.getBoolean());+ assertTrue(func.exists());+ }++ @Test+ public void singleValueDateParameterTest() {+ TestDateValue base = new TestDateValue();+ TestDateValue comp = new TestDateValue();++ AnalyticsValueStream uncasted = GTEFunction.creatorFunction.apply(new AnalyticsValueStream[] {base, comp});+ assertTrue(uncasted instanceof BooleanValue);+ BooleanValue func = (BooleanValue) uncasted;++ // Value doesn't exist+ base.setExists(false);+ comp.setExists(false);+ func.getBoolean();+ assertFalse(func.exists());++ base.setExists(false);+ comp.setValue("1800-01-02T10:20:30Z").setExists(true);+ func.getBoolean();+ assertFalse(func.exists());++ base.setValue("1800-01-02T10:20:30Z").setExists(true);+ comp.setExists(false);+ func.getBoolean();+ assertFalse(func.exists());++ // Value exists+ base.setValue("1800-01-02T10:20:30Z").setExists(true);+ comp.setValue("1800-01-02T10:20:30Z").setExists(true);+ assertEquals(true, func.getBoolean());+ assertTrue(func.exists());++ base.setValue("1800-01-02T10:20:30Z").setExists(true);+ comp.setValue("1800-01-02T10:20:31Z").setExists(true);+ assertEquals(false, func.getBoolean());+ assertTrue(func.exists());++ base.setValue("1800-01-02T10:20:30Z").setExists(true);+ comp.setValue("1000-01-02T10:20:31Z").setExists(true);+ assertEquals(true, func.getBoolean());+ assertTrue(func.exists());+ }++ @Test+ public void oneSingleOneMultiValueNumericParameterTest() {+ TestDoubleValue base = new TestDoubleValue();+ TestDoubleValueStream comp = new TestDoubleValueStream();++ AnalyticsValueStream uncasted = GTEFunction.creatorFunction.apply(new AnalyticsValueStream[] {base, comp});+ assertTrue(uncasted instanceof BooleanValueStream);+ BooleanValueStream func = (BooleanValueStream) uncasted;++ // No values+ base.setValue(-4.2).setExists(true);+ comp.setValues();+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ base.setExists(false);+ comp.setValues(-4.2);+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // One value+ base.setValue(-4.2).setExists(true);+ comp.setValues(-4);+ Iterator<Boolean> values1 = Arrays.asList(false).iterator();+ func.streamBooleans( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value);+ });+ assertFalse(values1.hasNext());++ // Multiple values+ base.setValue(4).setExists(true);+ comp.setValues(4, -10, 2345, -74, 4.0001);+ Iterator<Boolean> values2 = Arrays.asList(true, true, false, true, false).iterator();+ func.streamBooleans( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value);+ });+ assertFalse(values2.hasNext());+ }++ @Test+ public void oneMultiOneSingleValueNumericParameterTest() {+ TestDoubleValueStream base = new TestDoubleValueStream();+ TestDoubleValue comp = new TestDoubleValue();++ AnalyticsValueStream uncasted = GTEFunction.creatorFunction.apply(new AnalyticsValueStream[] {base, comp});+ assertTrue(uncasted instanceof BooleanValueStream);+ BooleanValueStream func = (BooleanValueStream) uncasted;++ // No values+ base.setValues();+ comp.setValue(-4.2).setExists(true);+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ base.setValues(-4.2);+ comp.setExists(false);+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // One value+ base.setValues(-4.2);+ comp.setValue(-4).setExists(true);+ Iterator<Boolean> values1 = Arrays.asList(false).iterator();+ func.streamBooleans( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value);+ });+ assertFalse(values1.hasNext());++ // Multiple values+ base.setValues(4, -10, 2345, -74, 4.0001);+ comp.setValue(4).setExists(true);+ Iterator<Boolean> values2 = Arrays.asList(true, false, true, false, true).iterator();+ func.streamBooleans( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value);+ });+ assertFalse(values2.hasNext());+ }++ @Test+ public void oneSingleOneMultiValueDateParameterTest() {+ TestDateValue base = new TestDateValue();+ TestDateValueStream comp = new TestDateValueStream();++ AnalyticsValueStream uncasted = GTEFunction.creatorFunction.apply(new AnalyticsValueStream[] {base, comp});+ assertTrue(uncasted instanceof BooleanValueStream);+ BooleanValueStream func = (BooleanValueStream) uncasted;++ // No values+ base.setValue("1800-01-02T10:20:30Z").setExists(true);+ comp.setValues();+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ base.setExists(false);+ comp.setValues("1800-01-02T10:20:30Z");+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // One value+ base.setValue("1803-01-02T10:20:30Z").setExists(true);+ comp.setValues("1800-01-02T10:20:30Z");+ Iterator<Boolean> values1 = Arrays.asList(true).iterator();+ func.streamBooleans( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value);+ });+ assertFalse(values1.hasNext());++ // Multiple values+ base.setValue("1800-01-02T10:20:30Z").setExists(true);+ comp.setValues("1800-03-02T10:20:30Z", "1799-01-01T10:20:29Z", "1800-01-02T10:20:31Z", "1800-01-02T10:20:30Z", "1800-01-02T10:20:29Z");+ Iterator<Boolean> values2 = Arrays.asList(false, true, false, true, true).iterator();+ func.streamBooleans( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value);+ });+ assertFalse(values2.hasNext());+ }++ @Test+ public void oneMultiOneSingleValueDateParameterTest() {+ TestDateValueStream base = new TestDateValueStream();+ TestDateValue comp = new TestDateValue();++ AnalyticsValueStream uncasted = GTEFunction.creatorFunction.apply(new AnalyticsValueStream[] {base, comp});+ assertTrue(uncasted instanceof BooleanValueStream);+ BooleanValueStream func = (BooleanValueStream) uncasted;++ // No values+ base.setValues();+ comp.setValue("1800-01-02T10:20:30Z").setExists(true);+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ base.setValues("1800-01-02T10:20:30Z");+ comp.setExists(false);+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // One value+ base.setValues("1800-01-02T10:20:30Z");+ comp.setValue("1803-01-02T10:20:30Z").setExists(true);+ Iterator<Boolean> values1 = Arrays.asList(false).iterator();+ func.streamBooleans( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value);+ });+ assertFalse(values1.hasNext());++ // Multiple values+ base.setValues("1800-03-02T10:20:30Z", "1799-01-01T10:20:29Z", "1800-01-02T10:20:31Z", "1800-01-02T10:20:30Z", "1800-01-02T10:20:29Z");+ comp.setValue("1800-01-02T10:20:30Z").setExists(true);+ Iterator<Boolean> values2 = Arrays.asList(true, false, true, true, false).iterator();+ func.streamBooleans( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value);+ });+ assertFalse(values2.hasNext());+ }+}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/GTFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/GTFunctionTest.javanew file mode 100644index 00000000000..03c34e55674--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/GTFunctionTest.java@@ -0,0 +1,290 @@+/*+ * 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.analytics.function.mapping;++import java.util.Arrays;+import java.util.Iterator;++import org.apache.solr.SolrTestCaseJ4;+import org.apache.solr.analytics.function.mapping.ComparisonFunction.GTFunction;+import org.apache.solr.analytics.value.AnalyticsValueStream;+import org.apache.solr.analytics.value.BooleanValue;+import org.apache.solr.analytics.value.BooleanValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestDateValue;+import org.apache.solr.analytics.value.FillableTestValue.TestDateValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValue;+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValueStream;+import org.junit.Test;++public class GTFunctionTest extends SolrTestCaseJ4 {++ @Test+ public void singleValueNumericParameterTest() {+ TestDoubleValue base = new TestDoubleValue();+ TestDoubleValue comp = new TestDoubleValue();++ AnalyticsValueStream uncasted = GTFunction.creatorFunction.apply(new AnalyticsValueStream[] {base, comp});+ assertTrue(uncasted instanceof BooleanValue);+ BooleanValue func = (BooleanValue) uncasted;++ // Value doesn't exist+ base.setExists(false);+ comp.setExists(false);+ func.getBoolean();+ assertFalse(func.exists());++ base.setExists(false);+ comp.setValue(3.3).setExists(true);+ func.getBoolean();+ assertFalse(func.exists());++ base.setValue(3.3).setExists(true);+ comp.setExists(false);+ func.getBoolean();+ assertFalse(func.exists());++ // Value exists+ base.setValue(21.56).setExists(true);+ comp.setValue(21.56).setExists(true);+ assertEquals(false, func.getBoolean());+ assertTrue(func.exists());++ base.setValue(21.56).setExists(true);+ comp.setValue(21.57).setExists(true);+ assertEquals(false, func.getBoolean());+ assertTrue(func.exists());++ base.setValue(21.56).setExists(true);+ comp.setValue(-21.57).setExists(true);+ assertEquals(true, func.getBoolean());+ assertTrue(func.exists());+ }++ @Test+ public void singleValueDateParameterTest() {+ TestDateValue base = new TestDateValue();+ TestDateValue comp = new TestDateValue();++ AnalyticsValueStream uncasted = GTFunction.creatorFunction.apply(new AnalyticsValueStream[] {base, comp});+ assertTrue(uncasted instanceof BooleanValue);+ BooleanValue func = (BooleanValue) uncasted;++ // Value doesn't exist+ base.setExists(false);+ comp.setExists(false);+ func.getBoolean();+ assertFalse(func.exists());++ base.setExists(false);+ comp.setValue("1800-01-02T10:20:30Z").setExists(true);+ func.getBoolean();+ assertFalse(func.exists());++ base.setValue("1800-01-02T10:20:30Z").setExists(true);+ comp.setExists(false);+ func.getBoolean();+ assertFalse(func.exists());++ // Value exists+ base.setValue("1800-01-02T10:20:30Z").setExists(true);+ comp.setValue("1800-01-02T10:20:30Z").setExists(true);+ assertEquals(false, func.getBoolean());+ assertTrue(func.exists());++ base.setValue("1800-01-02T10:20:30Z").setExists(true);+ comp.setValue("1800-01-02T10:20:31Z").setExists(true);+ assertEquals(false, func.getBoolean());+ assertTrue(func.exists());++ base.setValue("1800-01-02T10:20:30Z").setExists(true);+ comp.setValue("1000-01-02T10:20:31Z").setExists(true);+ assertEquals(true, func.getBoolean());+ assertTrue(func.exists());+ }++ @Test+ public void oneSingleOneMultiValueNumericParameterTest() {+ TestDoubleValue base = new TestDoubleValue();+ TestDoubleValueStream comp = new TestDoubleValueStream();++ AnalyticsValueStream uncasted = GTFunction.creatorFunction.apply(new AnalyticsValueStream[] {base, comp});+ assertTrue(uncasted instanceof BooleanValueStream);+ BooleanValueStream func = (BooleanValueStream) uncasted;++ // No values+ base.setValue(-4.2).setExists(true);+ comp.setValues();+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ base.setExists(false);+ comp.setValues(-4.2);+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // One value+ base.setValue(-4.2).setExists(true);+ comp.setValues(-4);+ Iterator<Boolean> values1 = Arrays.asList(false).iterator();+ func.streamBooleans( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value);+ });+ assertFalse(values1.hasNext());++ // Multiple values+ base.setValue(4).setExists(true);+ comp.setValues(4, -10, 2345, -74, 4.0001);+ Iterator<Boolean> values2 = Arrays.asList(false, true, false, true, false).iterator();+ func.streamBooleans( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value);+ });+ assertFalse(values2.hasNext());+ }++ @Test+ public void oneMultiOneSingleValueNumericParameterTest() {+ TestDoubleValueStream base = new TestDoubleValueStream();+ TestDoubleValue comp = new TestDoubleValue();++ AnalyticsValueStream uncasted = GTFunction.creatorFunction.apply(new AnalyticsValueStream[] {base, comp});+ assertTrue(uncasted instanceof BooleanValueStream);+ BooleanValueStream func = (BooleanValueStream) uncasted;++ // No values+ base.setValues();+ comp.setValue(-4.2).setExists(true);+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ base.setValues(-4.2);+ comp.setExists(false);+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // One value+ base.setValues(-4.2);+ comp.setValue(-4).setExists(true);+ Iterator<Boolean> values1 = Arrays.asList(false).iterator();+ func.streamBooleans( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value);+ });+ assertFalse(values1.hasNext());++ // Multiple values+ base.setValues(4, -10, 2345, -74, 4.0001);+ comp.setValue(4).setExists(true);+ Iterator<Boolean> values2 = Arrays.asList(false, false, true, false, true).iterator();+ func.streamBooleans( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value);+ });+ assertFalse(values2.hasNext());+ }++ @Test+ public void oneSingleOneMultiValueDateParameterTest() {+ TestDateValue base = new TestDateValue();+ TestDateValueStream comp = new TestDateValueStream();++ AnalyticsValueStream uncasted = GTFunction.creatorFunction.apply(new AnalyticsValueStream[] {base, comp});+ assertTrue(uncasted instanceof BooleanValueStream);+ BooleanValueStream func = (BooleanValueStream) uncasted;++ // No values+ base.setValue("1800-01-02T10:20:30Z").setExists(true);+ comp.setValues();+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ base.setExists(false);+ comp.setValues("1800-01-02T10:20:30Z");+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // One value+ base.setValue("1803-01-02T10:20:30Z").setExists(true);+ comp.setValues("1800-01-02T10:20:30Z");+ Iterator<Boolean> values1 = Arrays.asList(true).iterator();+ func.streamBooleans( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value);+ });+ assertFalse(values1.hasNext());++ // Multiple values+ base.setValue("1800-01-02T10:20:30Z").setExists(true);+ comp.setValues("1800-03-02T10:20:30Z", "1799-01-01T10:20:29Z", "1800-01-02T10:20:31Z", "1800-01-02T10:20:30Z", "1800-01-02T10:20:29Z");+ Iterator<Boolean> values2 = Arrays.asList(false, true, false, false, true).iterator();+ func.streamBooleans( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value);+ });+ assertFalse(values2.hasNext());+ }++ @Test+ public void oneMultiOneSingleValueDateParameterTest() {+ TestDateValueStream base = new TestDateValueStream();+ TestDateValue comp = new TestDateValue();++ AnalyticsValueStream uncasted = GTFunction.creatorFunction.apply(new AnalyticsValueStream[] {base, comp});+ assertTrue(uncasted instanceof BooleanValueStream);+ BooleanValueStream func = (BooleanValueStream) uncasted;++ // No values+ base.setValues();+ comp.setValue("1800-01-02T10:20:30Z").setExists(true);+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ base.setValues("1800-01-02T10:20:30Z");+ comp.setExists(false);+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // One value+ base.setValues("1800-01-02T10:20:30Z");+ comp.setValue("1803-01-02T10:20:30Z").setExists(true);+ Iterator<Boolean> values1 = Arrays.asList(false).iterator();+ func.streamBooleans( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value);+ });+ assertFalse(values1.hasNext());++ // Multiple values+ base.setValues("1800-03-02T10:20:30Z", "1799-01-01T10:20:29Z", "1800-01-02T10:20:31Z", "1800-01-02T10:20:30Z", "1800-01-02T10:20:29Z");+ comp.setValue("1800-01-02T10:20:30Z").setExists(true);+ Iterator<Boolean> values2 = Arrays.asList(true, false, true, false, false).iterator();+ func.streamBooleans( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value);+ });+ assertFalse(values2.hasNext());+ }+}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/IfFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/IfFunctionTest.javanew file mode 100644index 00000000000..0a48ac90341--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/IfFunctionTest.java@@ -0,0 +1,994 @@+/*+ * 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.analytics.function.mapping;++import java.time.Instant;+import java.time.format.DateTimeParseException;+import java.util.Arrays;+import java.util.Date;+import java.util.Iterator;++import org.apache.solr.SolrTestCaseJ4;+import org.apache.solr.analytics.value.AnalyticsValue;+import org.apache.solr.analytics.value.AnalyticsValueStream;+import org.apache.solr.analytics.value.BooleanValue;+import org.apache.solr.analytics.value.BooleanValueStream;+import org.apache.solr.analytics.value.DateValue;+import org.apache.solr.analytics.value.DateValueStream;+import org.apache.solr.analytics.value.DoubleValue;+import org.apache.solr.analytics.value.DoubleValueStream;+import org.apache.solr.analytics.value.FloatValue;+import org.apache.solr.analytics.value.FloatValueStream;+import org.apache.solr.analytics.value.IntValue;+import org.apache.solr.analytics.value.IntValueStream;+import org.apache.solr.analytics.value.LongValue;+import org.apache.solr.analytics.value.LongValueStream;+import org.apache.solr.analytics.value.StringValue;+import org.apache.solr.analytics.value.StringValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestAnalyticsValue;+import org.apache.solr.analytics.value.FillableTestValue.TestAnalyticsValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestBooleanValue;+import org.apache.solr.analytics.value.FillableTestValue.TestBooleanValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestDateValue;+import org.apache.solr.analytics.value.FillableTestValue.TestDateValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValue;+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValue;+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestIntValue;+import org.apache.solr.analytics.value.FillableTestValue.TestIntValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestLongValue;+import org.apache.solr.analytics.value.FillableTestValue.TestLongValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestStringValue;+import org.apache.solr.analytics.value.FillableTestValue.TestStringValueStream;+import org.junit.Test;++public class IfFunctionTest extends SolrTestCaseJ4 {++ @Test+ public void castingTest() {+ assertTrue(IfFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestBooleanValue(), new TestStringValue(), new TestStringValue()}) instanceof StringValue);++ assertFalse(IfFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestBooleanValue(), new TestFloatValue(), new TestDoubleValue()}) instanceof FloatValueStream);++ assertFalse(IfFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestBooleanValue(), new TestDateValue(), new TestLongValue()}) instanceof DateValueStream);++ assertFalse(IfFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestBooleanValue(), new TestAnalyticsValue(), new TestStringValue()}) instanceof StringValue);++ assertTrue(IfFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestBooleanValue(), new TestLongValue(), new TestFloatValue()}) instanceof DoubleValue);++ assertFalse(IfFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestBooleanValue(), new TestStringValue(), new TestLongValue()}) instanceof DateValue);++ assertFalse(IfFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestBooleanValue(), new TestStringValue(), new TestStringValue()}) instanceof BooleanValueStream);++ assertFalse(IfFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestBooleanValue(), new TestIntValueStream(), new TestLongValue()}) instanceof LongValue);+ }++ @Test+ public void singleValueBooleanTest() {+ TestBooleanValue cond = new TestBooleanValue();+ TestBooleanValue then = new TestBooleanValue();+ TestBooleanValue els = new TestBooleanValue();++ AnalyticsValueStream uncasted = IfFunction.creatorFunction.apply(new AnalyticsValueStream[] {cond, then, els});+ assertTrue(uncasted instanceof BooleanValue);+ BooleanValue func = (BooleanValue) uncasted;++ // Condition doesn't exist+ then.setExists(false);+ then.setExists(false);+ els.setExists(false);+ func.getBoolean();+ assertFalse(func.exists());++ cond.setExists(false);+ then.setValue(false).setExists(true);+ els.setValue(true).setExists(true);+ func.getBoolean();+ assertFalse(func.exists());++ // Result doesn't exist+ cond.setValue(true).setExists(true);+ then.setExists(false);+ els.setValue(false).setExists(true);+ func.getBoolean();+ assertFalse(func.exists());++ cond.setValue(false).setExists(true);+ then.setValue(true).setExists(true);+ els.setExists(false);+ func.getBoolean();+ assertFalse(func.exists());++ // Value exists+ cond.setValue(true).setExists(true);+ then.setValue(false).setExists(true);+ els.setValue(true).setExists(true);+ assertEquals(false, func.getBoolean());+ assertTrue(func.exists());++ cond.setValue(true).setExists(true);+ then.setValue(true).setExists(true);+ els.setValue(false).setExists(true);+ assertEquals(true, func.getBoolean());+ assertTrue(func.exists());++ cond.setValue(false).setExists(true);+ then.setValue(false).setExists(true);+ els.setValue(true).setExists(true);+ assertEquals(true, func.getBoolean());+ assertTrue(func.exists());++ cond.setValue(false).setExists(true);+ then.setValue(true).setExists(true);+ els.setValue(false).setExists(true);+ assertEquals(false, func.getBoolean());+ assertTrue(func.exists());+ }++ @Test+ public void singleValueIntTest() {+ TestBooleanValue cond = new TestBooleanValue();+ TestIntValue then = new TestIntValue();+ TestIntValue els = new TestIntValue();++ AnalyticsValueStream uncasted = IfFunction.creatorFunction.apply(new AnalyticsValueStream[] {cond, then, els});+ assertTrue(uncasted instanceof IntValue);+ IntValue func = (IntValue) uncasted;++ // Condition doesn't exist+ cond.setExists(false);+ then.setExists(false);+ els.setExists(false);+ func.getInt();+ assertFalse(func.exists());++ cond.setExists(false);+ then.setValue(-234).setExists(true);+ els.setValue(765).setExists(true);+ func.getInt();+ assertFalse(func.exists());++ // Result doesn't exist+ cond.setValue(true).setExists(true);+ then.setExists(false);+ els.setValue(23423).setExists(true);+ func.getInt();+ assertFalse(func.exists());++ cond.setValue(false).setExists(true);+ then.setValue(745).setExists(true);+ els.setExists(false);+ func.getInt();+ assertFalse(func.exists());++ // Value exists+ cond.setValue(true).setExists(true);+ then.setValue(234).setExists(true);+ els.setValue(-23423).setExists(true);+ assertEquals(234, func.getInt());+ assertTrue(func.exists());++ cond.setValue(false).setExists(true);+ then.setValue(234).setExists(true);+ els.setValue(-23423).setExists(true);+ assertEquals(-23423, func.getInt());+ assertTrue(func.exists());+ }++ @Test+ public void singleValueLongTest() {+ TestBooleanValue cond = new TestBooleanValue();+ TestLongValue then = new TestLongValue();+ TestLongValue els = new TestLongValue();++ AnalyticsValueStream uncasted = IfFunction.creatorFunction.apply(new AnalyticsValueStream[] {cond, then, els});+ assertTrue(uncasted instanceof LongValue);+ LongValue func = (LongValue) uncasted;++ // Condition doesn't exist+ cond.setExists(false);+ then.setExists(false);+ els.setExists(false);+ func.getLong();+ assertFalse(func.exists());++ cond.setExists(false);+ then.setValue(-234L).setExists(true);+ els.setValue(765L).setExists(true);+ func.getLong();+ assertFalse(func.exists());++ // Result doesn't exist+ cond.setValue(true).setExists(true);+ then.setExists(false);+ els.setValue(23423L).setExists(true);+ func.getLong();+ assertFalse(func.exists());++ cond.setValue(false).setExists(true);+ then.setValue(745L).setExists(true);+ els.setExists(false);+ func.getLong();+ assertFalse(func.exists());++ // Value exists+ cond.setValue(true).setExists(true);+ then.setValue(234L).setExists(true);+ els.setValue(-23423L).setExists(true);+ assertEquals(234L, func.getLong());+ assertTrue(func.exists());++ cond.setValue(false).setExists(true);+ then.setValue(234l).setExists(true);+ els.setValue(-23423L).setExists(true);+ assertEquals(-23423L, func.getLong());+ assertTrue(func.exists());+ }++ @Test+ public void singleValueFloatTest() {+ TestBooleanValue cond = new TestBooleanValue();+ TestFloatValue then = new TestFloatValue();+ TestFloatValue els = new TestFloatValue();++ AnalyticsValueStream uncasted = IfFunction.creatorFunction.apply(new AnalyticsValueStream[] {cond, then, els});+ assertTrue(uncasted instanceof FloatValue);+ FloatValue func = (FloatValue) uncasted;++ // Condition doesn't exist+ cond.setExists(false);+ then.setExists(false);+ els.setExists(false);+ func.getFloat();+ assertFalse(func.exists());++ cond.setExists(false);+ then.setValue(234.7565F).setExists(true);+ els.setValue(-234.7565F).setExists(true);+ func.getFloat();+ assertFalse(func.exists());++ // Result doesn't exist+ cond.setValue(true).setExists(true);+ then.setExists(false);+ els.setValue(234.7565F).setExists(true);+ func.getFloat();+ assertFalse(func.exists());++ cond.setValue(false).setExists(true);+ then.setValue(-23423.234F).setExists(true);+ els.setExists(false);+ func.getFloat();+ assertFalse(func.exists());++ // Value exists+ cond.setValue(true).setExists(true);+ then.setValue(234.7565F).setExists(true);+ els.setValue(-23423.234F).setExists(true);+ assertEquals(234.7565F, func.getFloat(), .0000001);+ assertTrue(func.exists());++ cond.setValue(false).setExists(true);+ then.setValue(234.7565F).setExists(true);+ els.setValue(-23423.234F).setExists(true);+ assertEquals(-23423.234F, func.getFloat(), .0000001);+ assertTrue(func.exists());+ }++ @Test+ public void singleValueDoubleTest() {+ TestBooleanValue cond = new TestBooleanValue();+ TestDoubleValue then = new TestDoubleValue();+ TestDoubleValue els = new TestDoubleValue();++ AnalyticsValueStream uncasted = IfFunction.creatorFunction.apply(new AnalyticsValueStream[] {cond, then, els});+ assertTrue(uncasted instanceof DoubleValue);+ DoubleValue func = (DoubleValue) uncasted;++ // Condition doesn't exist+ cond.setExists(false);+ then.setExists(false);+ els.setExists(false);+ func.getDouble();+ assertFalse(func.exists());++ cond.setExists(false);+ then.setValue(234.7565).setExists(true);+ els.setValue(-234.7565).setExists(true);+ func.getDouble();+ assertFalse(func.exists());++ // Result doesn't exist+ cond.setValue(true).setExists(true);+ then.setExists(false);+ els.setValue(234.7565).setExists(true);+ func.getDouble();+ assertFalse(func.exists());++ cond.setValue(false).setExists(true);+ then.setValue(-23423.234).setExists(true);+ els.setExists(false);+ func.getDouble();+ assertFalse(func.exists());++ // Value exists+ cond.setValue(true).setExists(true);+ then.setValue(234.7565).setExists(true);+ els.setValue(-23423.234).setExists(true);+ assertEquals(234.7565, func.getDouble(), .0000001);+ assertTrue(func.exists());++ cond.setValue(false).setExists(true);+ then.setValue(234.7565).setExists(true);+ els.setValue(-23423.234).setExists(true);+ assertEquals(-23423.234, func.getDouble(), .0000001);+ assertTrue(func.exists());+ }++ @Test+ public void singleValueDateTest() throws DateTimeParseException {+ Date date1 = Date.from(Instant.parse("1810-12-02T10:30:15Z"));+ Date date2 = Date.from(Instant.parse("1950-02-23T14:54:34Z"));+ Date date3 = Date.from(Instant.parse("2023-11-01T20:30:15Z"));++ TestBooleanValue cond = new TestBooleanValue();+ TestDateValue then = new TestDateValue();+ TestDateValue els = new TestDateValue();++ AnalyticsValueStream uncasted = IfFunction.creatorFunction.apply(new AnalyticsValueStream[] {cond, then, els});+ assertTrue(uncasted instanceof DateValue);+ DateValue func = (DateValue) uncasted;++ // Condition doesn't exist+ cond.setExists(false);+ then.setExists(false);+ els.setExists(false);+ func.getLong();+ assertFalse(func.exists());++ cond.setExists(false);+ then.setValue("6723-08-01T23:30:15Z").setExists(true);+ els.setValue("2207-11-01T20:30:15Z").setExists(true);+ func.getLong();+ assertFalse(func.exists());++ // Result doesn't exist+ cond.setValue(true).setExists(true);+ then.setExists(false);+ els.setValue("1810-12-02T10:30:15Z").setExists(true);+ func.getLong();+ assertFalse(func.exists());++ cond.setValue(false).setExists(true);+ then.setValue("2023-11-01T20:30:15Z").setExists(true);+ els.setExists(false);+ func.getLong();+ assertFalse(func.exists());++ // Value exists+ cond.setValue(true).setExists(true);+ then.setValue("1810-12-02T10:30:15Z").setExists(true);+ els.setValue("2023-11-01T20:30:15Z").setExists(true);+ assertEquals(date1.getTime(), func.getLong());+ assertTrue(func.exists());++ cond.setValue(false).setExists(true);+ then.setValue("1810-12-02T10:30:15Z").setExists(true);+ els.setValue("2023-11-01T20:30:15Z").setExists(true);+ assertEquals(date3.getTime(), func.getLong());+ assertTrue(func.exists());+ }++ @Test+ public void singleValueStringTest() {+ TestBooleanValue cond = new TestBooleanValue();+ TestStringValue then = new TestStringValue();+ TestStringValue els = new TestStringValue();++ AnalyticsValueStream uncasted = IfFunction.creatorFunction.apply(new AnalyticsValueStream[] {cond, then, els});+ assertTrue(uncasted instanceof StringValue);+ StringValue func = (StringValue) uncasted;++ // Condition doesn't exist+ cond.setExists(false);+ then.setExists(false);+ els.setExists(false);+ func.getString();+ assertFalse(func.exists());++ cond.setExists(false);+ then.setValue("if the value is true").setExists(true);+ els.setValue("when the value is false").setExists(true);+ func.getString();+ assertFalse(func.exists());++ // Result doesn't exist+ cond.setValue(true).setExists(true);+ then.setExists(false);+ els.setValue("not picked").setExists(true);+ func.getString();+ assertFalse(func.exists());++ cond.setValue(false).setExists(true);+ then.setValue("also not picked").setExists(true);+ els.setExists(false);+ func.getString();+ assertFalse(func.exists());++ // Value exists+ cond.setValue(true).setExists(true);+ then.setValue("abc123").setExists(true);+ els.setValue("def456").setExists(true);+ assertEquals("abc123", func.getString());+ assertTrue(func.exists());++ cond.setValue(false).setExists(true);+ then.setValue("abc123").setExists(true);+ els.setValue("def456").setExists(true);+ assertEquals("def456", func.getString());+ assertTrue(func.exists());+ }++ @Test+ public void singleValueObjectTest() {+ TestBooleanValue cond = new TestBooleanValue();+ TestAnalyticsValue then = new TestAnalyticsValue();+ TestAnalyticsValue els = new TestAnalyticsValue();++ AnalyticsValueStream uncasted = IfFunction.creatorFunction.apply(new AnalyticsValueStream[] {cond, then, els});+ assertTrue(uncasted instanceof AnalyticsValue);+ AnalyticsValue func = (AnalyticsValue) uncasted;++ // Condition doesn't exist+ cond.setExists(false);+ then.setExists(false);+ els.setExists(false);+ func.getObject();+ assertFalse(func.exists());++ cond.setExists(false);+ then.setValue("if the value is true").setExists(true);+ els.setValue(new Boolean(false)).setExists(true);+ func.getObject();+ assertFalse(func.exists());++ // Result doesn't exist+ cond.setValue(true).setExists(true);+ then.setExists(false);+ els.setValue(new Long(123421324L)).setExists(true);+ func.getObject();+ assertFalse(func.exists());++ cond.setValue(false).setExists(true);+ then.setValue(new Float(1234324.454F)).setExists(true);+ els.setExists(false);+ func.getObject();+ assertFalse(func.exists());++ // Value exists+ cond.setValue(true).setExists(true);+ then.setValue("abc123").setExists(true);+ els.setValue(new Date(3214)).setExists(true);+ assertEquals("abc123", func.getObject());+ assertTrue(func.exists());++ cond.setValue(false).setExists(true);+ then.setValue("abc123").setExists(true);+ els.setValue(new Date(3214)).setExists(true);+ assertEquals(new Date(3214), func.getObject());+ assertTrue(func.exists());+ }++ @Test+ public void multiValueBooleanTest() {+ TestBooleanValue cond = new TestBooleanValue();+ TestBooleanValueStream then = new TestBooleanValueStream();+ TestBooleanValueStream els = new TestBooleanValueStream();++ AnalyticsValueStream uncasted = IfFunction.creatorFunction.apply(new AnalyticsValueStream[] {cond, then, els});+ assertTrue(uncasted instanceof BooleanValueStream);+ BooleanValueStream func = (BooleanValueStream) uncasted;++ // No values+ cond.setExists(false);+ then.setValues();+ els.setValues();+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ cond.setExists(false);+ then.setValues(false, true, false);+ els.setValues(true, true, true, false);+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Result doesn't exist+ cond.setValue(true).setExists(true);+ then.setValues();+ els.setValues(true, true, true, false);+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ cond.setValue(false).setExists(true);+ then.setValues(true, true, true, false);+ els.setValues();+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Values exist+ cond.setValue(true).setExists(true);+ then.setValues(true, true, true, false);+ els.setValues(false, false, true, false, true);+ Iterator<Boolean> values1 = Arrays.asList(true, true, true, false).iterator();+ func.streamBooleans( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value);+ });+ assertFalse(values1.hasNext());++ cond.setValue(false).setExists(true);+ then.setValues(true, true, true, false);+ els.setValues(false, false, true, false, true);+ Iterator<Boolean> values2 = Arrays.asList(false, false, true, false, true).iterator();+ func.streamBooleans( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value);+ });+ assertFalse(values2.hasNext());+ }++ @Test+ public void multiValueIntTest() {+ TestBooleanValue cond = new TestBooleanValue();+ TestIntValueStream then = new TestIntValueStream();+ TestIntValueStream els = new TestIntValueStream();++ AnalyticsValueStream uncasted = IfFunction.creatorFunction.apply(new AnalyticsValueStream[] {cond, then, els});+ assertTrue(uncasted instanceof IntValueStream);+ IntValueStream func = (IntValueStream) uncasted;++ // No values+ cond.setExists(false);+ then.setValues();+ els.setValues();+ func.streamInts( value -> {+ assertTrue("There should be no values to stream", false);+ });++ cond.setExists(false);+ then.setValues(-132, 41543, 563);+ els.setValues(0, 1, -2, 3);+ func.streamInts( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Result doesn't exist+ cond.setValue(true).setExists(true);+ then.setValues();+ els.setValues(0, 1, -2, 3);+ func.streamInts( value -> {+ assertTrue("There should be no values to stream", false);+ });++ cond.setValue(false).setExists(true);+ then.setValues(-132, 41543, 563);+ els.setValues();+ func.streamInts( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Values exist+ cond.setValue(true).setExists(true);+ then.setValues(-132, 41543, 563);+ els.setValues(0, 1, -2, 3);+ Iterator<Integer> values1 = Arrays.asList(-132, 41543, 563).iterator();+ func.streamInts( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next().intValue(), value);+ });+ assertFalse(values1.hasNext());++ cond.setValue(false).setExists(true);+ then.setValues(-132, 41543, 563);+ els.setValues(0, 1, -2, 3);+ Iterator<Integer> values2 = Arrays.asList(0, 1, -2, 3).iterator();+ func.streamInts( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next().intValue(), value);+ });+ assertFalse(values2.hasNext());+ }++ @Test+ public void multiValueLongTest() {+ TestBooleanValue cond = new TestBooleanValue();+ TestLongValueStream then = new TestLongValueStream();+ TestLongValueStream els = new TestLongValueStream();++ AnalyticsValueStream uncasted = IfFunction.creatorFunction.apply(new AnalyticsValueStream[] {cond, then, els});+ assertTrue(uncasted instanceof LongValueStream);+ LongValueStream func = (LongValueStream) uncasted;++ // No values+ cond.setExists(false);+ then.setValues();+ els.setValues();+ func.streamLongs( value -> {+ assertTrue("There should be no values to stream", false);+ });++ cond.setExists(false);+ then.setValues(-132L, 41543L, 563L);+ els.setValues(0L, 1L, -2L, 3L);+ func.streamLongs( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Result doesn't exist+ cond.setValue(true).setExists(true);+ then.setValues();+ els.setValues(0L, 1L, -2L, 3L);+ func.streamLongs( value -> {+ assertTrue("There should be no values to stream", false);+ });++ cond.setValue(false).setExists(true);+ then.setValues(-132L, 41543L, 563L);+ els.setValues();+ func.streamLongs( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Values exist+ cond.setValue(true).setExists(true);+ then.setValues(-132L, 41543L, 563L);+ els.setValues(0L, 1L, -2L, 3L);+ Iterator<Long> values1 = Arrays.asList(-132L, 41543L, 563L).iterator();+ func.streamLongs( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next().longValue(), value);+ });+ assertFalse(values1.hasNext());++ cond.setValue(false).setExists(true);+ then.setValues(-132L, 41543L, 563L);+ els.setValues(0L, 1L, -2L, 3L);+ Iterator<Long> values2 = Arrays.asList(0L, 1L, -2L, 3L).iterator();+ func.streamLongs( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next().longValue(), value);+ });+ assertFalse(values2.hasNext());+ }++ @Test+ public void multiValueFloatTest() {+ TestBooleanValue cond = new TestBooleanValue();+ TestFloatValueStream then = new TestFloatValueStream();+ TestFloatValueStream els = new TestFloatValueStream();++ AnalyticsValueStream uncasted = IfFunction.creatorFunction.apply(new AnalyticsValueStream[] {cond, then, els});+ assertTrue(uncasted instanceof FloatValueStream);+ FloatValueStream func = (FloatValueStream) uncasted;++ // No values+ cond.setExists(false);+ then.setValues();+ els.setValues();+ func.streamFloats( value -> {+ assertTrue("There should be no values to stream", false);+ });++ cond.setExists(false);+ then.setValues(2134.2345F, -234.23F, 20000.0F);+ els.setValues(.1111F , -.22222F, .333F);+ func.streamFloats( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Result doesn't exist+ cond.setValue(true).setExists(true);+ then.setValues();+ els.setValues(.1111F , -.22222F, .333F);+ func.streamFloats( value -> {+ assertTrue("There should be no values to stream", false);+ });++ cond.setValue(false).setExists(true);+ then.setValues(2134.2345F, -234.23F, 20000.0F);+ els.setValues();+ func.streamFloats( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Values exist+ cond.setValue(true).setExists(true);+ then.setValues(2134.2345F, -234.23F, 20000.0F);+ els.setValues(.1111F , -.22222F, .333F);+ Iterator<Float> values1 = Arrays.asList(2134.2345F, -234.23F, 20000.0F).iterator();+ func.streamFloats( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value, .000001);+ });+ assertFalse(values1.hasNext());++ cond.setValue(false).setExists(true);+ then.setValues(2134.2345F, -234.23F, 20000.0F);+ els.setValues(.1111F , -.22222F, .333F);+ Iterator<Float> values2 = Arrays.asList(.1111F , -.22222F, .333F).iterator();+ func.streamFloats( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value, .000001);+ });+ assertFalse(values2.hasNext());+ }++ @Test+ public void multiValueDoubleTest() {+ TestBooleanValue cond = new TestBooleanValue();+ TestDoubleValueStream then = new TestDoubleValueStream();+ TestDoubleValueStream els = new TestDoubleValueStream();++ AnalyticsValueStream uncasted = IfFunction.creatorFunction.apply(new AnalyticsValueStream[] {cond, then, els});+ assertTrue(uncasted instanceof DoubleValueStream);+ DoubleValueStream func = (DoubleValueStream) uncasted;++ // No values+ cond.setExists(false);+ then.setValues();+ els.setValues();+ func.streamDoubles( value -> {+ assertTrue("There should be no values to stream", false);+ });++ cond.setExists(false);+ then.setValues(2134.2345, -234.23, 20000.0);+ els.setValues(.1111 , -.22222, .333);+ func.streamDoubles( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Result doesn't exist+ cond.setValue(true).setExists(true);+ then.setValues();+ els.setValues(.1111 , -.22222, .333);+ func.streamDoubles( value -> {+ assertTrue("There should be no values to stream", false);+ });++ cond.setValue(false).setExists(true);+ then.setValues(2134.2345, -234.23, 20000.0);+ els.setValues();+ func.streamDoubles( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Values exist+ cond.setValue(true).setExists(true);+ then.setValues(2134.2345, -234.23, 20000.0);+ els.setValues(.1111 , -.22222, .333);+ Iterator<Double> values1 = Arrays.asList(2134.2345, -234.23, 20000.0).iterator();+ func.streamDoubles( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value, .000001);+ });+ assertFalse(values1.hasNext());++ cond.setValue(false).setExists(true);+ then.setValues(2134.2345, -234.23, 20000.0);+ els.setValues(.1111 , -.22222, .333);+ Iterator<Double> values2 = Arrays.asList(.1111 , -.22222, .333).iterator();+ func.streamDoubles( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value, .000001);+ });+ assertFalse(values2.hasNext());+ }++ @Test+ public void multiValueDateTest() throws DateTimeParseException {+ Date date1 = Date.from(Instant.parse("1810-12-02T10:30:15Z"));+ Date date2 = Date.from(Instant.parse("1931-03-16T18:15:45Z"));+ Date date3 = Date.from(Instant.parse("2023-11-01T20:30:15Z"));++ TestBooleanValue cond = new TestBooleanValue();+ TestDateValueStream then = new TestDateValueStream();+ TestDateValueStream els = new TestDateValueStream();++ AnalyticsValueStream uncasted = IfFunction.creatorFunction.apply(new AnalyticsValueStream[] {cond, then, els});+ assertTrue(uncasted instanceof DateValueStream);+ DateValueStream func = (DateValueStream) uncasted;++ // No values+ cond.setExists(false);+ then.setValues();+ els.setValues();+ func.streamLongs( value -> {+ assertTrue("There should be no values to stream", false);+ });++ cond.setExists(false);+ then.setValues("1810-12-02T10:30:15Z", "2023-11-01T20:30:15Z", "1810-12-02T10:30:15Z");+ els.setValues("2023-11-01T20:30:15Z", "1931-03-16T18:15:45Z");+ func.streamLongs( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Result doesn't exist+ cond.setValue(true).setExists(true);+ then.setValues();+ els.setValues("2023-11-01T20:30:15Z", "1931-03-16T18:15:45Z");+ func.streamLongs( value -> {+ assertTrue("There should be no values to stream", false);+ });++ cond.setValue(false).setExists(true);+ then.setValues("1810-12-02T10:30:15Z", "2023-11-01T20:30:15Z", "1810-12-02T10:30:15Z");+ els.setValues();+ func.streamLongs( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Values exist+ cond.setValue(true).setExists(true);+ then.setValues("1810-12-02T10:30:15Z", "2023-11-01T20:30:15Z", "1810-12-02T10:30:15Z");+ els.setValues("2023-11-01T20:30:15Z", "1931-03-16T18:15:45Z");+ Iterator<Long> values1 = Arrays.asList(date1.getTime(), date3.getTime(), date1.getTime()).iterator();+ func.streamLongs( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next().longValue(), value);+ });+ assertFalse(values1.hasNext());++ cond.setValue(false).setExists(true);+ then.setValues("1810-12-02T10:30:15Z", "2023-11-01T20:30:15Z", "1810-12-02T10:30:15Z");+ els.setValues("2023-11-01T20:30:15Z", "1931-03-16T18:15:45Z");+ Iterator<Long> values2 = Arrays.asList(date3.getTime(), date2.getTime()).iterator();+ func.streamLongs( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next().longValue(), value);+ });+ assertFalse(values2.hasNext());+ }++ @Test+ public void multiValueStringTest() {+ TestBooleanValue cond = new TestBooleanValue();+ TestStringValueStream then = new TestStringValueStream();+ TestStringValueStream els = new TestStringValueStream();++ AnalyticsValueStream uncasted = IfFunction.creatorFunction.apply(new AnalyticsValueStream[] {cond, then, els});+ assertTrue(uncasted instanceof StringValueStream);+ StringValueStream func = (StringValueStream) uncasted;++ // No values+ cond.setExists(false);+ then.setValues();+ els.setValues();+ func.streamStrings( value -> {+ assertTrue("There should be no values to stream", false);+ });++ cond.setExists(false);+ then.setValues("abc123", "abcsdafasd", "third");+ els.setValues("this", "is", "a", "sentence");+ func.streamStrings( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Result doesn't exist+ cond.setValue(true).setExists(true);+ then.setValues();+ els.setValues("this", "is", "a", "sentence");+ func.streamStrings( value -> {+ assertTrue("There should be no values to stream", false);+ });++ cond.setValue(false).setExists(true);+ then.setValues("abc123", "abcsdafasd", "third");+ els.setValues();+ func.streamStrings( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Values exist+ cond.setValue(true).setExists(true);+ then.setValues("abc123", "abcsdafasd", "third");+ els.setValues("this", "is", "a", "sentence");+ Iterator<String> values1 = Arrays.asList("abc123", "abcsdafasd", "third").iterator();+ func.streamStrings( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value);+ });+ assertFalse(values1.hasNext());++ cond.setValue(false).setExists(true);+ then.setValues("abc123", "abcsdafasd", "third");+ els.setValues("this", "is", "a", "sentence");+ Iterator<String> values2 = Arrays.asList("this", "is", "a", "sentence").iterator();+ func.streamStrings( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value);+ });+ assertFalse(values2.hasNext());+ }++ @Test+ public void multiValueObjectTest() {+ TestBooleanValue cond = new TestBooleanValue();+ TestAnalyticsValueStream then = new TestAnalyticsValueStream();+ TestAnalyticsValueStream els = new TestAnalyticsValueStream();++ AnalyticsValueStream func = IfFunction.creatorFunction.apply(new AnalyticsValueStream[] {cond, then, els});++ // No values+ cond.setExists(false);+ then.setValues();+ els.setValues();+ func.streamObjects( value -> {+ assertTrue("There should be no values to stream", false);+ });++ cond.setExists(false);+ then.setValues(new Date(142341), "abcsdafasd", new Double(1234.1324123));+ els.setValues(new Float(324923.0234F), new Integer(123), new Boolean(true), "if statement");+ func.streamObjects( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Result doesn't exist+ cond.setValue(true).setExists(true);+ then.setValues();+ els.setValues(new Float(324923.0234F), new Integer(123), new Boolean(true), "if statement");+ func.streamObjects( value -> {+ assertTrue("There should be no values to stream", false);+ });++ cond.setValue(false).setExists(true);+ then.setValues(new Date(142341), "abcsdafasd", new Double(1234.1324123));+ els.setValues();+ func.streamObjects( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Values exist+ cond.setValue(true).setExists(true);+ then.setValues(new Date(142341), "abcsdafasd", new Double(1234.1324123));+ els.setValues(new Float(324923.0234F), new Integer(123), new Boolean(true), "if statement");+ Iterator<Object> values1 = Arrays.<Object>asList(new Date(142341), "abcsdafasd", new Double(1234.1324123)).iterator();+ func.streamObjects( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value);+ });+ assertFalse(values1.hasNext());++ cond.setValue(false).setExists(true);+ then.setValues(new Date(142341), "abcsdafasd", new Double(1234.1324123));+ els.setValues(new Float(324923.0234F), new Integer(123), new Boolean(true), "if statement");+ Iterator<Object> values2 = Arrays.<Object>asList(new Float(324923.0234F), new Integer(123), new Boolean(true), "if statement").iterator();+ func.streamObjects( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value);+ });+ assertFalse(values2.hasNext());+ }+}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/LTEFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/LTEFunctionTest.javanew file mode 100644index 00000000000..6e1590e6c1d--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/LTEFunctionTest.java@@ -0,0 +1,290 @@+/*+ * 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.analytics.function.mapping;++import java.util.Arrays;+import java.util.Iterator;++import org.apache.solr.SolrTestCaseJ4;+import org.apache.solr.analytics.function.mapping.ComparisonFunction.LTEFunction;+import org.apache.solr.analytics.value.AnalyticsValueStream;+import org.apache.solr.analytics.value.BooleanValue;+import org.apache.solr.analytics.value.BooleanValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestDateValue;+import org.apache.solr.analytics.value.FillableTestValue.TestDateValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValue;+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValueStream;+import org.junit.Test;++public class LTEFunctionTest extends SolrTestCaseJ4 {++ @Test+ public void singleValueNumericParameterTest() {+ TestDoubleValue base = new TestDoubleValue();+ TestDoubleValue comp = new TestDoubleValue();++ AnalyticsValueStream uncasted = LTEFunction.creatorFunction.apply(new AnalyticsValueStream[] {base, comp});+ assertTrue(uncasted instanceof BooleanValue);+ BooleanValue func = (BooleanValue) uncasted;++ // Value doesn't exist+ base.setExists(false);+ comp.setExists(false);+ func.getBoolean();+ assertFalse(func.exists());++ base.setExists(false);+ comp.setValue(3.3).setExists(true);+ func.getBoolean();+ assertFalse(func.exists());++ base.setValue(3.3).setExists(true);+ comp.setExists(false);+ func.getBoolean();+ assertFalse(func.exists());++ // Value exists+ base.setValue(21.56).setExists(true);+ comp.setValue(21.56).setExists(true);+ assertEquals(true, func.getBoolean());+ assertTrue(func.exists());++ base.setValue(21.56).setExists(true);+ comp.setValue(21.57).setExists(true);+ assertEquals(true, func.getBoolean());+ assertTrue(func.exists());++ base.setValue(21.56).setExists(true);+ comp.setValue(-21.57).setExists(true);+ assertEquals(false, func.getBoolean());+ assertTrue(func.exists());+ }++ @Test+ public void singleValueDateParameterTest() {+ TestDateValue base = new TestDateValue();+ TestDateValue comp = new TestDateValue();++ AnalyticsValueStream uncasted = LTEFunction.creatorFunction.apply(new AnalyticsValueStream[] {base, comp});+ assertTrue(uncasted instanceof BooleanValue);+ BooleanValue func = (BooleanValue) uncasted;++ // Value doesn't exist+ base.setExists(false);+ comp.setExists(false);+ func.getBoolean();+ assertFalse(func.exists());++ base.setExists(false);+ comp.setValue("1800-01-02T10:20:30Z").setExists(true);+ func.getBoolean();+ assertFalse(func.exists());++ base.setValue("1800-01-02T10:20:30Z").setExists(true);+ comp.setExists(false);+ func.getBoolean();+ assertFalse(func.exists());++ // Value exists+ base.setValue("1800-01-02T10:20:30Z").setExists(true);+ comp.setValue("1800-01-02T10:20:30Z").setExists(true);+ assertEquals(true, func.getBoolean());+ assertTrue(func.exists());++ base.setValue("1800-01-02T10:20:30Z").setExists(true);+ comp.setValue("1800-01-02T10:20:31Z").setExists(true);+ assertEquals(true, func.getBoolean());+ assertTrue(func.exists());++ base.setValue("1800-01-02T10:20:30Z").setExists(true);+ comp.setValue("1000-01-02T10:20:31Z").setExists(true);+ assertEquals(false, func.getBoolean());+ assertTrue(func.exists());+ }++ @Test+ public void oneSingleOneMultiValueNumericParameterTest() {+ TestDoubleValue base = new TestDoubleValue();+ TestDoubleValueStream comp = new TestDoubleValueStream();++ AnalyticsValueStream uncasted = LTEFunction.creatorFunction.apply(new AnalyticsValueStream[] {base, comp});+ assertTrue(uncasted instanceof BooleanValueStream);+ BooleanValueStream func = (BooleanValueStream) uncasted;++ // No values+ base.setValue(-4.2).setExists(true);+ comp.setValues();+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ base.setExists(false);+ comp.setValues(-4.2);+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // One value+ base.setValue(-4.2).setExists(true);+ comp.setValues(-4);+ Iterator<Boolean> values1 = Arrays.asList(true).iterator();+ func.streamBooleans( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value);+ });+ assertFalse(values1.hasNext());++ // Multiple values+ base.setValue(4).setExists(true);+ comp.setValues(4, -10, 2345, -74, 4.0001);+ Iterator<Boolean> values2 = Arrays.asList(true, false, true, false, true).iterator();+ func.streamBooleans( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value);+ });+ assertFalse(values2.hasNext());+ }++ @Test+ public void oneMultiOneSingleValueNumericParameterTest() {+ TestDoubleValueStream base = new TestDoubleValueStream();+ TestDoubleValue comp = new TestDoubleValue();++ AnalyticsValueStream uncasted = LTEFunction.creatorFunction.apply(new AnalyticsValueStream[] {base, comp});+ assertTrue(uncasted instanceof BooleanValueStream);+ BooleanValueStream func = (BooleanValueStream) uncasted;++ // No values+ base.setValues();+ comp.setValue(-4.2).setExists(true);+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ base.setValues(-4.2);+ comp.setExists(false);+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // One value+ base.setValues(-4.2);+ comp.setValue(-4).setExists(true);+ Iterator<Boolean> values1 = Arrays.asList(true).iterator();+ func.streamBooleans( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value);+ });+ assertFalse(values1.hasNext());++ // Multiple values+ base.setValues(4, -10, 2345, -74, 4.0001);+ comp.setValue(4).setExists(true);+ Iterator<Boolean> values2 = Arrays.asList(true, true, false, true, false).iterator();+ func.streamBooleans( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value);+ });+ assertFalse(values2.hasNext());+ }++ @Test+ public void oneSingleOneMultiValueDateParameterTest() {+ TestDateValue base = new TestDateValue();+ TestDateValueStream comp = new TestDateValueStream();++ AnalyticsValueStream uncasted = LTEFunction.creatorFunction.apply(new AnalyticsValueStream[] {base, comp});+ assertTrue(uncasted instanceof BooleanValueStream);+ BooleanValueStream func = (BooleanValueStream) uncasted;++ // No values+ base.setValue("1800-01-02T10:20:30Z").setExists(true);+ comp.setValues();+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ base.setExists(false);+ comp.setValues("1800-01-02T10:20:30Z");+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // One value+ base.setValue("1803-01-02T10:20:30Z").setExists(true);+ comp.setValues("1800-01-02T10:20:30Z");+ Iterator<Boolean> values1 = Arrays.asList(false).iterator();+ func.streamBooleans( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value);+ });+ assertFalse(values1.hasNext());++ // Multiple values+ base.setValue("1800-01-02T10:20:30Z").setExists(true);+ comp.setValues("1800-03-02T10:20:30Z", "1799-01-01T10:20:29Z", "1800-01-02T10:20:31Z", "1800-01-02T10:20:30Z", "1800-01-02T10:20:29Z");+ Iterator<Boolean> values2 = Arrays.asList(true, false, true, true, false).iterator();+ func.streamBooleans( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value);+ });+ assertFalse(values2.hasNext());+ }++ @Test+ public void oneMultiOneSingleValueDateParameterTest() {+ TestDateValueStream base = new TestDateValueStream();+ TestDateValue comp = new TestDateValue();++ AnalyticsValueStream uncasted = LTEFunction.creatorFunction.apply(new AnalyticsValueStream[] {base, comp});+ assertTrue(uncasted instanceof BooleanValueStream);+ BooleanValueStream func = (BooleanValueStream) uncasted;++ // No values+ base.setValues();+ comp.setValue("1800-01-02T10:20:30Z").setExists(true);+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ base.setValues("1800-01-02T10:20:30Z");+ comp.setExists(false);+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // One value+ base.setValues("1800-01-02T10:20:30Z");+ comp.setValue("1803-01-02T10:20:30Z").setExists(true);+ Iterator<Boolean> values1 = Arrays.asList(true).iterator();+ func.streamBooleans( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value);+ });+ assertFalse(values1.hasNext());++ // Multiple values+ base.setValues("1800-03-02T10:20:30Z", "1799-01-01T10:20:29Z", "1800-01-02T10:20:31Z", "1800-01-02T10:20:30Z", "1800-01-02T10:20:29Z");+ comp.setValue("1800-01-02T10:20:30Z").setExists(true);+ Iterator<Boolean> values2 = Arrays.asList(false, true, false, true, true).iterator();+ func.streamBooleans( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value);+ });+ assertFalse(values2.hasNext());+ }+}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/LTFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/LTFunctionTest.javanew file mode 100644index 00000000000..f7d5e8ef935--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/LTFunctionTest.java@@ -0,0 +1,290 @@+/*+ * 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.analytics.function.mapping;++import java.util.Arrays;+import java.util.Iterator;++import org.apache.solr.SolrTestCaseJ4;+import org.apache.solr.analytics.function.mapping.ComparisonFunction.LTFunction;+import org.apache.solr.analytics.value.AnalyticsValueStream;+import org.apache.solr.analytics.value.BooleanValue;+import org.apache.solr.analytics.value.BooleanValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestDateValue;+import org.apache.solr.analytics.value.FillableTestValue.TestDateValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValue;+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValueStream;+import org.junit.Test;++public class LTFunctionTest extends SolrTestCaseJ4 {++ @Test+ public void singleValueNumericParameterTest() {+ TestDoubleValue base = new TestDoubleValue();+ TestDoubleValue comp = new TestDoubleValue();++ AnalyticsValueStream uncasted = LTFunction.creatorFunction.apply(new AnalyticsValueStream[] {base, comp});+ assertTrue(uncasted instanceof BooleanValue);+ BooleanValue func = (BooleanValue) uncasted;++ // Value doesn't exist+ base.setExists(false);+ comp.setExists(false);+ func.getBoolean();+ assertFalse(func.exists());++ base.setExists(false);+ comp.setValue(3.3).setExists(true);+ func.getBoolean();+ assertFalse(func.exists());++ base.setValue(3.3).setExists(true);+ comp.setExists(false);+ func.getBoolean();+ assertFalse(func.exists());++ // Value exists+ base.setValue(21.56).setExists(true);+ comp.setValue(21.56).setExists(true);+ assertEquals(false, func.getBoolean());+ assertTrue(func.exists());++ base.setValue(21.56).setExists(true);+ comp.setValue(21.57).setExists(true);+ assertEquals(true, func.getBoolean());+ assertTrue(func.exists());++ base.setValue(21.56).setExists(true);+ comp.setValue(-21.57).setExists(true);+ assertEquals(false, func.getBoolean());+ assertTrue(func.exists());+ }++ @Test+ public void singleValueDateParameterTest() {+ TestDateValue base = new TestDateValue();+ TestDateValue comp = new TestDateValue();++ AnalyticsValueStream uncasted = LTFunction.creatorFunction.apply(new AnalyticsValueStream[] {base, comp});+ assertTrue(uncasted instanceof BooleanValue);+ BooleanValue func = (BooleanValue) uncasted;++ // Value doesn't exist+ base.setExists(false);+ comp.setExists(false);+ func.getBoolean();+ assertFalse(func.exists());++ base.setExists(false);+ comp.setValue("1800-01-02T10:20:30Z").setExists(true);+ func.getBoolean();+ assertFalse(func.exists());++ base.setValue("1800-01-02T10:20:30Z").setExists(true);+ comp.setExists(false);+ func.getBoolean();+ assertFalse(func.exists());++ // Value exists+ base.setValue("1800-01-02T10:20:30Z").setExists(true);+ comp.setValue("1800-01-02T10:20:30Z").setExists(true);+ assertEquals(false, func.getBoolean());+ assertTrue(func.exists());++ base.setValue("1800-01-02T10:20:30Z").setExists(true);+ comp.setValue("1800-01-02T10:20:31Z").setExists(true);+ assertEquals(true, func.getBoolean());+ assertTrue(func.exists());++ base.setValue("1800-01-02T10:20:30Z").setExists(true);+ comp.setValue("1000-01-02T10:20:31Z").setExists(true);+ assertEquals(false, func.getBoolean());+ assertTrue(func.exists());+ }++ @Test+ public void oneSingleOneMultiValueNumericParameterTest() {+ TestDoubleValue base = new TestDoubleValue();+ TestDoubleValueStream comp = new TestDoubleValueStream();++ AnalyticsValueStream uncasted = LTFunction.creatorFunction.apply(new AnalyticsValueStream[] {base, comp});+ assertTrue(uncasted instanceof BooleanValueStream);+ BooleanValueStream func = (BooleanValueStream) uncasted;++ // No values+ base.setValue(-4.2).setExists(true);+ comp.setValues();+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ base.setExists(false);+ comp.setValues(-4.2);+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // One value+ base.setValue(-4.2).setExists(true);+ comp.setValues(-4);+ Iterator<Boolean> values1 = Arrays.asList(true).iterator();+ func.streamBooleans( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value);+ });+ assertFalse(values1.hasNext());++ // Multiple values+ base.setValue(4).setExists(true);+ comp.setValues(4, -10, 2345, -74, 4.0001);+ Iterator<Boolean> values2 = Arrays.asList(false, false, true, false, true).iterator();+ func.streamBooleans( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value);+ });+ assertFalse(values2.hasNext());+ }++ @Test+ public void oneMultiOneSingleValueNumericParameterTest() {+ TestDoubleValueStream base = new TestDoubleValueStream();+ TestDoubleValue comp = new TestDoubleValue();++ AnalyticsValueStream uncasted = LTFunction.creatorFunction.apply(new AnalyticsValueStream[] {base, comp});+ assertTrue(uncasted instanceof BooleanValueStream);+ BooleanValueStream func = (BooleanValueStream) uncasted;++ // No values+ base.setValues();+ comp.setValue(-4.2).setExists(true);+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ base.setValues(-4.2);+ comp.setExists(false);+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // One value+ base.setValues(-4.2);+ comp.setValue(-4).setExists(true);+ Iterator<Boolean> values1 = Arrays.asList(true).iterator();+ func.streamBooleans( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value);+ });+ assertFalse(values1.hasNext());++ // Multiple values+ base.setValues(4, -10, 2345, -74, 4.0001);+ comp.setValue(4).setExists(true);+ Iterator<Boolean> values2 = Arrays.asList(false, true, false, true, false).iterator();+ func.streamBooleans( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value);+ });+ assertFalse(values2.hasNext());+ }++ @Test+ public void oneSingleOneMultiValueDateParameterTest() {+ TestDateValue base = new TestDateValue();+ TestDateValueStream comp = new TestDateValueStream();++ AnalyticsValueStream uncasted = LTFunction.creatorFunction.apply(new AnalyticsValueStream[] {base, comp});+ assertTrue(uncasted instanceof BooleanValueStream);+ BooleanValueStream func = (BooleanValueStream) uncasted;++ // No values+ base.setValue("1800-01-02T10:20:30Z").setExists(true);+ comp.setValues();+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ base.setExists(false);+ comp.setValues("1800-01-02T10:20:30Z");+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // One value+ base.setValue("1803-01-02T10:20:30Z").setExists(true);+ comp.setValues("1800-01-02T10:20:30Z");+ Iterator<Boolean> values1 = Arrays.asList(false).iterator();+ func.streamBooleans( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value);+ });+ assertFalse(values1.hasNext());++ // Multiple values+ base.setValue("1800-01-02T10:20:30Z").setExists(true);+ comp.setValues("1800-03-02T10:20:30Z", "1799-01-01T10:20:29Z", "1800-01-02T10:20:31Z", "1800-01-02T10:20:30Z", "1800-01-02T10:20:29Z");+ Iterator<Boolean> values2 = Arrays.asList(true, false, true, false, false).iterator();+ func.streamBooleans( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value);+ });+ assertFalse(values2.hasNext());+ }++ @Test+ public void oneMultiOneSingleValueDateParameterTest() {+ TestDateValueStream base = new TestDateValueStream();+ TestDateValue comp = new TestDateValue();++ AnalyticsValueStream uncasted = LTFunction.creatorFunction.apply(new AnalyticsValueStream[] {base, comp});+ assertTrue(uncasted instanceof BooleanValueStream);+ BooleanValueStream func = (BooleanValueStream) uncasted;++ // No values+ base.setValues();+ comp.setValue("1800-01-02T10:20:30Z").setExists(true);+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ base.setValues("1800-01-02T10:20:30Z");+ comp.setExists(false);+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // One value+ base.setValues("1800-01-02T10:20:30Z");+ comp.setValue("1803-01-02T10:20:30Z").setExists(true);+ Iterator<Boolean> values1 = Arrays.asList(true).iterator();+ func.streamBooleans( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value);+ });+ assertFalse(values1.hasNext());++ // Multiple values+ base.setValues("1800-03-02T10:20:30Z", "1799-01-01T10:20:29Z", "1800-01-02T10:20:31Z", "1800-01-02T10:20:30Z", "1800-01-02T10:20:29Z");+ comp.setValue("1800-01-02T10:20:30Z").setExists(true);+ Iterator<Boolean> values2 = Arrays.asList(false, true, false, false, true).iterator();+ func.streamBooleans( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value);+ });+ assertFalse(values2.hasNext());+ }+}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/LogFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/LogFunctionTest.javanew file mode 100644index 00000000000..1cffb5aecab--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/LogFunctionTest.java@@ -0,0 +1,186 @@+/*+ * 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.analytics.function.mapping;++import java.util.Arrays;+import java.util.Iterator;++import org.apache.solr.SolrTestCaseJ4;+import org.apache.solr.analytics.value.AnalyticsValueStream;+import org.apache.solr.analytics.value.DoubleValue;+import org.apache.solr.analytics.value.DoubleValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValue;+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValue;+import org.apache.solr.analytics.value.FillableTestValue.TestIntValue;+import org.apache.solr.analytics.value.FillableTestValue.TestIntValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestLongValueStream;+import org.junit.Test;++public class LogFunctionTest extends SolrTestCaseJ4 {++ @Test+ public void singleValueParameterTest() {+ TestFloatValue val = new TestFloatValue();++ AnalyticsValueStream uncasted = LogFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});+ assertTrue(uncasted instanceof DoubleValue);+ DoubleValue func = (DoubleValue) uncasted;++ // Value doesn't exist+ val.setExists(false);+ func.getDouble();+ assertFalse(func.exists());++ // Value exists+ val.setValue(21.56F).setExists(true);+ assertEquals(Math.log(21.56F), func.getDouble(), 0.00001);+ assertTrue(func.exists());++ val.setValue(-100F).setExists(true);+ assertEquals(Math.log(-100F), func.getDouble(), 0.00001);+ assertTrue(func.exists());+ }++ @Test+ public void multiValueParameterTest() {+ TestIntValueStream val = new TestIntValueStream();++ AnalyticsValueStream uncasted = LogFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});+ assertTrue(uncasted instanceof DoubleValueStream);+ DoubleValueStream func = (DoubleValueStream) uncasted;++ // No values+ val.setValues();+ func.streamDoubles( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // One value+ val.setValues(4);+ Iterator<Double> values1 = Arrays.asList(Math.log(4)).iterator();+ func.streamDoubles( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value, .00001);+ });+ assertFalse(values1.hasNext());++ // Multiple values+ val.setValues(2, 103, 502, 743);+ Iterator<Double> values2 = Arrays.asList(Math.log(2), Math.log(103), Math.log(502), Math.log(743)).iterator();+ func.streamDoubles( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value, .00001);+ });+ assertFalse(values2.hasNext());+ }++ @Test+ public void twoSingleValueParametersTest() {+ TestIntValue base = new TestIntValue();+ TestFloatValue val = new TestFloatValue();++ AnalyticsValueStream uncasted = LogFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, base});+ assertTrue(uncasted instanceof DoubleValue);+ DoubleValue func = (DoubleValue) uncasted;++ // Neither exists+ base.setExists(false);+ val.setExists(false);+ func.getDouble();+ assertFalse(func.exists());++ // One exists+ base.setValue(30).setExists(true);+ val.setExists(false);+ func.getDouble();+ assertFalse(func.exists());++ // Both exist+ base.setValue(6).setExists(true);+ val.setValue(2.56F).setExists(true);+ assertEquals(Math.log(2.56F)/Math.log(6), func.getDouble(), 0.0001);+ assertTrue(func.exists());+ }++ @Test+ public void oneMultiOneSingleValueParameterTest() {+ TestLongValueStream base = new TestLongValueStream();+ TestDoubleValue val = new TestDoubleValue();++ AnalyticsValueStream uncasted = LogFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, base});+ assertTrue(uncasted instanceof DoubleValueStream);+ DoubleValueStream func = (DoubleValueStream) uncasted;++ // No values, One value+ base.setValues();+ val.setValue(21.56F).setExists(true);+ func.streamDoubles( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple values, no value+ base.setValues(4L, 10023L);+ val.setExists(false);+ func.streamDoubles( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple values, one value+ base.setValues(4L, 123L, 2L);+ val.setValue(4.56F).setExists(true);+ Iterator<Double> values = Arrays.asList(Math.log(4.56F)/Math.log(4L), Math.log(4.56F)/Math.log(123L), Math.log(4.56F)/Math.log(2L)).iterator();+ func.streamDoubles( value -> {+ assertTrue(values.hasNext());+ assertEquals(values.next(), value, 0.0001);+ });+ assertFalse(values.hasNext());+ }++ @Test+ public void oneSingleOneMultiValueParameterTest() {+ TestDoubleValue base = new TestDoubleValue();+ TestLongValueStream val = new TestLongValueStream();++ AnalyticsValueStream uncasted = LogFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, base});+ assertTrue(uncasted instanceof DoubleValueStream);+ DoubleValueStream func = (DoubleValueStream) uncasted;++ // No values, One value+ base.setValue(21.56F).setExists(true);+ val.setValues();+ func.streamDoubles( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple values, no value+ base.setExists(false);+ val.setValues(4L, 10023L);+ func.streamDoubles( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple values, one value+ base.setValue(4.56F).setExists(true);+ val.setValues(2L, 50L, 3L);+ Iterator<Double> values = Arrays.asList(Math.log(2L)/Math.log(4.56F), Math.log(50L)/Math.log(4.56F), Math.log(3L)/Math.log(4.56F)).iterator();+ func.streamDoubles( value -> {+ assertTrue(values.hasNext());+ assertEquals(values.next(), value, 0.0001);+ });+ assertFalse(values.hasNext());+ }+}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/MultFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/MultFunctionTest.javanew file mode 100644index 00000000000..c2f5d32e311--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/MultFunctionTest.java@@ -0,0 +1,155 @@+/*+ * 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.analytics.function.mapping;++import java.util.Arrays;+import java.util.Iterator;++import org.apache.solr.SolrTestCaseJ4;+import org.apache.solr.analytics.value.AnalyticsValueStream;+import org.apache.solr.analytics.value.DoubleValue;+import org.apache.solr.analytics.value.DoubleValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValue;+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValue;+import org.apache.solr.analytics.value.FillableTestValue.TestIntValue;+import org.apache.solr.analytics.value.FillableTestValue.TestLongValue;+import org.apache.solr.analytics.value.FillableTestValue.TestLongValueStream;+import org.junit.Test;++public class MultFunctionTest extends SolrTestCaseJ4 {+ @Test+ public void twoSingleValueParametersTest() {+ TestIntValue val1 = new TestIntValue();+ TestFloatValue val2 = new TestFloatValue();++ AnalyticsValueStream uncasted = MultFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2});+ assertTrue(uncasted instanceof DoubleValue);+ DoubleValue func = (DoubleValue) uncasted;++ // Neither exists+ val1.setExists(false);+ val2.setExists(false);+ func.getDouble();+ assertFalse(func.exists());++ // One exists+ val1.setValue(30).setExists(true);+ val2.setExists(false);+ func.getDouble();+ assertFalse(func.exists());++ // Both exist+ val1.setValue(30).setExists(true);+ val2.setValue(21.56F).setExists(true);+ assertEquals(646.8, func.getDouble(), 0.0001);+ assertTrue(func.exists());+ }++ @Test+ public void oneMultiValueParameterTest() {+ TestLongValueStream val = new TestLongValueStream();++ AnalyticsValueStream uncasted = MultFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});+ assertTrue(uncasted instanceof DoubleValue);+ DoubleValue func = (DoubleValue) uncasted;++ // No values+ val.setValues();+ func.getDouble();+ assertFalse(func.exists());++ // One value+ val.setValues(30L);+ assertEquals(30, func.getDouble(), 0.00001);+ assertTrue(func.exists());++ // Multiple values+ val.setValues(30L, 20L, 55L, 61L);+ assertEquals(2013000, func.getDouble(), 0.00001);+ assertTrue(func.exists());+ }++ @Test+ public void oneMultiOneSingleValueParameterTest() {+ TestLongValueStream val1 = new TestLongValueStream();+ TestDoubleValue val2 = new TestDoubleValue();++ AnalyticsValueStream uncasted = MultFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2});+ assertTrue(uncasted instanceof DoubleValueStream);+ DoubleValueStream func = (DoubleValueStream) uncasted;++ // No values, One value+ val1.setValues();+ val2.setValue(21.56F).setExists(true);+ func.streamDoubles( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple values, no value+ val1.setValues(4L, 10023L);+ val2.setExists(false);+ func.streamDoubles( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple values, one value+ val1.setValues(4L, 10023L, 48L);+ val2.setValue(21.56F).setExists(true);+ Iterator<Double> values = Arrays.asList(86.24, 216095.88, 1034.88).iterator();+ func.streamDoubles( value -> {+ assertTrue(values.hasNext());+ assertEquals(values.next(), value, 0.01);+ });+ assertFalse(values.hasNext());+ }++ @Test+ public void multipleSingleValueParameterTest() {+ TestLongValue val1 = new TestLongValue();+ TestDoubleValue val2 = new TestDoubleValue();+ TestFloatValue val3 = new TestFloatValue();+ TestIntValue val4 = new TestIntValue();++ AnalyticsValueStream uncasted = MultFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2, val3, val4});+ assertTrue(uncasted instanceof DoubleValue);+ DoubleValue func = (DoubleValue) uncasted;++ // None exist+ val1.setExists(false);+ val2.setExists(false);+ val3.setExists(false);+ val4.setExists(false);+ func.getDouble();+ assertFalse(func.exists());++ // Some exist+ val1.setExists(false);+ val2.setValue(30.56).setExists(true);+ val3.setExists(false);+ val4.setValue(12).setExists(true);+ func.getDouble();+ assertFalse(func.exists());++ // All exist values, one value+ val1.setValue(45L).setExists(true);+ val2.setValue(30.56).setExists(true);+ val3.setValue(2.5F).setExists(true);+ val4.setValue(12).setExists(true);+ assertEquals(41256, func.getDouble(), 0.00001);+ assertTrue(func.exists());+ }+}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/NegateFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/NegateFunctionTest.javanew file mode 100644index 00000000000..7b0aa13984b--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/NegateFunctionTest.java@@ -0,0 +1,327 @@+/*+ * 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.analytics.function.mapping;++import java.util.Arrays;+import java.util.Iterator;++import org.apache.solr.SolrTestCaseJ4;+import org.apache.solr.analytics.value.AnalyticsValueStream;+import org.apache.solr.analytics.value.BooleanValue;+import org.apache.solr.analytics.value.BooleanValueStream;+import org.apache.solr.analytics.value.DoubleValue;+import org.apache.solr.analytics.value.DoubleValueStream;+import org.apache.solr.analytics.value.FloatValue;+import org.apache.solr.analytics.value.FloatValueStream;+import org.apache.solr.analytics.value.IntValue;+import org.apache.solr.analytics.value.IntValueStream;+import org.apache.solr.analytics.value.LongValue;+import org.apache.solr.analytics.value.LongValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestBooleanValue;+import org.apache.solr.analytics.value.FillableTestValue.TestBooleanValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValue;+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValue;+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestIntValue;+import org.apache.solr.analytics.value.FillableTestValue.TestIntValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestLongValue;+import org.apache.solr.analytics.value.FillableTestValue.TestLongValueStream;+import org.junit.Test;++public class NegateFunctionTest extends SolrTestCaseJ4 {++ @Test+ public void singleValueBooleanTest() {+ TestBooleanValue val = new TestBooleanValue();++ AnalyticsValueStream uncasted = NegateFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});+ assertTrue(uncasted instanceof BooleanValue);+ BooleanValue func = (BooleanValue) uncasted;++ // Value doesn't exist+ val.setExists(false);+ func.getBoolean();+ assertFalse(func.exists());++ // Value exists+ val.setValue(true).setExists(true);+ assertEquals(false, func.getBoolean());+ assertTrue(func.exists());++ val.setValue(false).setExists(true);+ assertEquals(true, func.getBoolean());+ assertTrue(func.exists());+ }++ @Test+ public void singleValueIntTest() {+ TestIntValue val = new TestIntValue();++ AnalyticsValueStream uncasted = NegateFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});+ assertTrue(uncasted instanceof IntValue);+ IntValue func = (IntValue) uncasted;++ // Value doesn't exist+ val.setExists(false);+ func.getInt();+ assertFalse(func.exists());++ // Value exists+ val.setValue(21).setExists(true);+ assertEquals(-21, func.getInt());+ assertTrue(func.exists());++ val.setValue(-100).setExists(true);+ assertEquals(100, func.getInt());+ assertTrue(func.exists());+ }++ @Test+ public void singleValueLongTest() {+ TestLongValue val = new TestLongValue();++ AnalyticsValueStream uncasted = NegateFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});+ assertTrue(uncasted instanceof LongValue);+ LongValue func = (LongValue) uncasted;++ // Value doesn't exist+ val.setExists(false);+ func.getLong();+ assertFalse(func.exists());++ // Value exists+ val.setValue(21L).setExists(true);+ assertEquals(-21, func.getLong());+ assertTrue(func.exists());++ val.setValue(-100L).setExists(true);+ assertEquals(100L, func.getLong());+ assertTrue(func.exists());+ }++ @Test+ public void singleValueFloatTest() {+ TestFloatValue val = new TestFloatValue();++ AnalyticsValueStream uncasted = NegateFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});+ assertTrue(uncasted instanceof FloatValue);+ FloatValue func = (FloatValue) uncasted;++ // Value doesn't exist+ val.setExists(false);+ func.getFloat();+ assertFalse(func.exists());++ // Value exists+ val.setValue(21.56F).setExists(true);+ assertEquals(-21.56F, func.getFloat(), 0.00001);+ assertTrue(func.exists());++ val.setValue(-100F).setExists(true);+ assertEquals(100F, func.getFloat(), 0.00001);+ assertTrue(func.exists());+ }++ @Test+ public void singleValueDoubleTest() {+ TestDoubleValue val = new TestDoubleValue();++ AnalyticsValueStream uncasted = NegateFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});+ assertTrue(uncasted instanceof DoubleValue);+ DoubleValue func = (DoubleValue) uncasted;++ // Value doesn't exist+ val.setExists(false);+ func.getDouble();+ assertFalse(func.exists());++ // Value exists+ val.setValue(21.56).setExists(true);+ assertEquals(-21.56, func.getDouble(), 0.00001);+ assertTrue(func.exists());++ val.setValue(-100.1).setExists(true);+ assertEquals(100.1, func.getDouble(), 0.00001);+ assertTrue(func.exists());+ }++ @Test+ public void multiValueBooleanTest() {+ TestBooleanValueStream val = new TestBooleanValueStream();++ AnalyticsValueStream uncasted = NegateFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});+ assertTrue(uncasted instanceof BooleanValueStream);+ BooleanValueStream func = (BooleanValueStream) uncasted;++ // No values+ val.setValues();+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // One value+ val.setValues(true);+ Iterator<Boolean> values1 = Arrays.asList(false).iterator();+ func.streamBooleans( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value);+ });+ assertFalse(values1.hasNext());++ // Multiple values+ val.setValues(true, false, true, false);+ Iterator<Boolean> values2 = Arrays.asList(false, true, false, true).iterator();+ func.streamBooleans( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value);+ });+ assertFalse(values2.hasNext());+ }++ @Test+ public void multiValueIntTest() {+ TestIntValueStream val = new TestIntValueStream();++ AnalyticsValueStream uncasted = NegateFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});+ assertTrue(uncasted instanceof IntValueStream);+ IntValueStream func = (IntValueStream) uncasted;++ // No values+ val.setValues();+ func.streamInts( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // One value+ val.setValues(-4);+ Iterator<Integer> values1 = Arrays.asList(4).iterator();+ func.streamInts( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next().intValue(), value);+ });+ assertFalse(values1.hasNext());++ // Multiple values+ val.setValues(4, -10, 50, -74);+ Iterator<Integer> values2 = Arrays.asList(-4, 10, -50, 74).iterator();+ func.streamInts( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next().intValue(), value);+ });+ assertFalse(values2.hasNext());+ }++ @Test+ public void multiValueLongTest() {+ TestLongValueStream val = new TestLongValueStream();++ AnalyticsValueStream uncasted = NegateFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});+ assertTrue(uncasted instanceof LongValueStream);+ LongValueStream func = (LongValueStream) uncasted;++ // No values+ val.setValues();+ func.streamLongs( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // One value+ val.setValues(-4L);+ Iterator<Long> values1 = Arrays.asList(4L).iterator();+ func.streamLongs( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next().longValue(), value);+ });+ assertFalse(values1.hasNext());++ // Multiple values+ val.setValues(4L, -10L, 50L, -74L);+ Iterator<Long> values2 = Arrays.asList(-4L, 10L, -50L, 74L).iterator();+ func.streamLongs( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next().longValue(), value);+ });+ assertFalse(values2.hasNext());+ }++ @Test+ public void multiValueFloatTest() {+ TestFloatValueStream val = new TestFloatValueStream();++ AnalyticsValueStream uncasted = NegateFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});+ assertTrue(uncasted instanceof FloatValueStream);+ FloatValueStream func = (FloatValueStream) uncasted;++ // No values+ val.setValues();+ func.streamFloats( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // One value+ val.setValues(-4.3F);+ Iterator<Float> values1 = Arrays.asList(4.3F).iterator();+ func.streamFloats( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value, .000001);+ });+ assertFalse(values1.hasNext());++ // Multiple values+ val.setValues(4.3F, -10F, 50.75F, -74.4446F);+ Iterator<Float> values2 = Arrays.asList(-4.3F, 10F, -50.75F, 74.4446F).iterator();+ func.streamFloats( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value, .000001);+ });+ assertFalse(values2.hasNext());+ }++ @Test+ public void multiValueDoubleTest() {+ TestDoubleValueStream val = new TestDoubleValueStream();++ AnalyticsValueStream uncasted = NegateFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});+ assertTrue(uncasted instanceof DoubleValueStream);+ DoubleValueStream func = (DoubleValueStream) uncasted;++ // No values+ val.setValues();+ func.streamDoubles( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // One value+ val.setValues(-4.3);+ Iterator<Double> values1 = Arrays.asList(4.3).iterator();+ func.streamDoubles( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value, .000001);+ });+ assertFalse(values1.hasNext());++ // Multiple values+ val.setValues(4.3, -10, 50.75, -74.4446);+ Iterator<Double> values2 = Arrays.asList(-4.3, 10.0, -50.75, 74.4446).iterator();+ func.streamDoubles( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value, .000001);+ });+ assertFalse(values2.hasNext());+ }+}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/OrFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/OrFunctionTest.javanew file mode 100644index 00000000000..bf8f77b9c96--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/OrFunctionTest.java@@ -0,0 +1,192 @@+/*+ * 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.analytics.function.mapping;++import java.util.Arrays;+import java.util.Iterator;++import org.apache.solr.SolrTestCaseJ4;+import org.apache.solr.analytics.function.mapping.LogicFunction.OrFunction;+import org.apache.solr.analytics.value.AnalyticsValueStream;+import org.apache.solr.analytics.value.BooleanValue;+import org.apache.solr.analytics.value.BooleanValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestBooleanValue;+import org.apache.solr.analytics.value.FillableTestValue.TestBooleanValueStream;+import org.junit.Test;++public class OrFunctionTest extends SolrTestCaseJ4 {+ @Test+ public void twoSingleValueParametersTest() {+ TestBooleanValue val1 = new TestBooleanValue();+ TestBooleanValue val2 = new TestBooleanValue();++ AnalyticsValueStream uncasted = OrFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2});+ assertTrue(uncasted instanceof BooleanValue);+ BooleanValue func = (BooleanValue) uncasted;++ // Neither exists+ val1.setExists(false);+ val2.setExists(false);+ func.getBoolean();+ assertFalse(func.exists());++ // One exists+ val1.setValue(true).setExists(true);+ val2.setExists(false);+ func.getBoolean();+ assertFalse(func.exists());++ // Both exist+ val1.setValue(false).setExists(true);+ val2.setValue(false).setExists(true);+ assertEquals(false, func.getBoolean());+ assertTrue(func.exists());++ val1.setValue(true).setExists(true);+ val2.setValue(false).setExists(true);+ assertEquals(true, func.getBoolean());+ assertTrue(func.exists());++ val1.setValue(false).setExists(true);+ val2.setValue(true).setExists(true);+ assertEquals(true, func.getBoolean());+ assertTrue(func.exists());++ val1.setValue(true).setExists(true);+ val2.setValue(true).setExists(true);+ assertEquals(true, func.getBoolean());+ assertTrue(func.exists());+ }++ @Test+ public void oneMultiValueParameterTest() {+ TestBooleanValueStream val = new TestBooleanValueStream();++ AnalyticsValueStream uncasted = OrFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});+ assertTrue(uncasted instanceof BooleanValue);+ BooleanValue func = (BooleanValue) uncasted;++ // No values+ val.setValues();+ func.getBoolean();+ assertFalse(func.exists());++ // One value+ val.setValues(true);+ assertEquals(true, func.getBoolean());+ assertTrue(func.exists());++ val.setValues(false);+ assertEquals(false, func.getBoolean());+ assertTrue(func.exists());++ // Multiple values+ val.setValues(false, false, true, false);+ assertEquals(true, func.getBoolean());+ assertTrue(func.exists());++ val.setValues(false, false, false);+ assertEquals(false, func.getBoolean());+ assertTrue(func.exists());+ }++ @Test+ public void oneMultiOneSingleValueParameterTest() {+ TestBooleanValue val1 = new TestBooleanValue();+ TestBooleanValueStream val2 = new TestBooleanValueStream();++ AnalyticsValueStream uncasted = OrFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2});+ assertTrue(uncasted instanceof BooleanValueStream);+ BooleanValueStream func = (BooleanValueStream) uncasted;++ // No values, One value+ val1.setValue(false).setExists(true);+ val2.setValues();+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple values, no value+ val1.setExists(false);+ val2.setValues(true, false);+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple values, one value+ val1.setValue(false).setExists(true);+ val2.setValues(true, false, true);+ Iterator<Boolean> values1 = Arrays.asList(true, false, true).iterator();+ func.streamBooleans( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value);+ });+ assertFalse(values1.hasNext());++ val1.setValue(true).setExists(true);+ val2.setValues(true, false, true);+ Iterator<Boolean> values2 = Arrays.asList(true, true, true).iterator();+ func.streamBooleans( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value);+ });+ assertFalse(values2.hasNext());+ }++ @Test+ public void multipleSingleValueParameterTest() {+ TestBooleanValue val1 = new TestBooleanValue();+ TestBooleanValue val2 = new TestBooleanValue();+ TestBooleanValue val3 = new TestBooleanValue();+ TestBooleanValue val4 = new TestBooleanValue();++ AnalyticsValueStream uncasted = OrFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2, val3, val4});+ assertTrue(uncasted instanceof BooleanValue);+ BooleanValue func = (BooleanValue) uncasted;++ // None exist+ val1.setExists(false);+ val2.setExists(false);+ val3.setExists(false);+ val4.setExists(false);+ func.getBoolean();+ assertFalse(func.exists());++ // Some exist+ val1.setExists(false);+ val2.setValue(true).setExists(true);+ val3.setExists(false);+ val4.setValue(false).setExists(true);+ func.getBoolean();+ assertFalse(func.exists());++ // All exist values, one value+ val1.setValue(false).setExists(true);+ val2.setValue(true).setExists(true);+ val3.setValue(false).setExists(true);+ val4.setValue(false).setExists(true);+ assertEquals(true, func.getBoolean());+ assertTrue(func.exists());++ val1.setValue(false).setExists(true);+ val2.setValue(false).setExists(true);+ val3.setValue(false).setExists(true);+ val4.setValue(false).setExists(true);+ assertEquals(false, func.getBoolean());+ assertTrue(func.exists());+ }+}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/PowerFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/PowerFunctionTest.javanew file mode 100644index 00000000000..a7db7d7b337--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/PowerFunctionTest.java@@ -0,0 +1,128 @@+/*+ * 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.analytics.function.mapping;++import java.util.Arrays;+import java.util.Iterator;++import org.apache.solr.SolrTestCaseJ4;+import org.apache.solr.analytics.value.AnalyticsValueStream;+import org.apache.solr.analytics.value.DoubleValue;+import org.apache.solr.analytics.value.DoubleValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValue;+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValue;+import org.apache.solr.analytics.value.FillableTestValue.TestIntValue;+import org.apache.solr.analytics.value.FillableTestValue.TestLongValueStream;+import org.junit.Test;++public class PowerFunctionTest extends SolrTestCaseJ4 {+ @Test+ public void twoSingleValueParametersTest() {+ TestIntValue base = new TestIntValue();+ TestFloatValue pow = new TestFloatValue();++ AnalyticsValueStream uncasted = PowerFunction.creatorFunction.apply(new AnalyticsValueStream[] {base, pow});+ assertTrue(uncasted instanceof DoubleValue);+ DoubleValue func = (DoubleValue) uncasted;++ // Neither exists+ base.setExists(false);+ pow.setExists(false);+ func.getDouble();+ assertFalse(func.exists());++ // One exists+ base.setValue(30).setExists(true);+ pow.setExists(false);+ func.getDouble();+ assertFalse(func.exists());++ // Both exist+ base.setValue(6).setExists(true);+ pow.setValue(2.56F).setExists(true);+ assertEquals(98.1899, func.getDouble(), 0.0001);+ assertTrue(func.exists());+ }++ @Test+ public void oneMultiOneSingleValueParameterTest() {+ TestLongValueStream base = new TestLongValueStream();+ TestDoubleValue pow = new TestDoubleValue();++ AnalyticsValueStream uncasted = PowerFunction.creatorFunction.apply(new AnalyticsValueStream[] {base, pow});+ assertTrue(uncasted instanceof DoubleValueStream);+ DoubleValueStream func = (DoubleValueStream) uncasted;++ // No values, One value+ base.setValues();+ pow.setValue(21.56F).setExists(true);+ func.streamDoubles( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple values, no value+ base.setValues(4L, 10023L);+ pow.setExists(false);+ func.streamDoubles( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple values, one value+ base.setValues(4L, 123L, 10L);+ pow.setValue(2.5F).setExists(true);+ Iterator<Double> values = Arrays.asList(32.0, 167788.7268, 316.2277).iterator();+ func.streamDoubles( value -> {+ assertTrue(values.hasNext());+ assertEquals(values.next(), value, 0.001);+ });+ assertFalse(values.hasNext());+ }++ @Test+ public void oneSingleOneMultiValueParameterTest() {+ TestDoubleValue base = new TestDoubleValue();+ TestLongValueStream pow = new TestLongValueStream();++ AnalyticsValueStream uncasted = PowerFunction.creatorFunction.apply(new AnalyticsValueStream[] {base, pow});+ assertTrue(uncasted instanceof DoubleValueStream);+ DoubleValueStream func = (DoubleValueStream) uncasted;++ // No values, One value+ base.setValue(21.56F).setExists(true);+ pow.setValues();+ func.streamDoubles( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple values, no value+ base.setExists(false);+ pow.setValues(4L, 10023L);+ func.streamDoubles( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple values, one value+ base.setValue(4.56F).setExists(true);+ pow.setValues(2L, 5L, 3L);+ Iterator<Double> values = Arrays.asList(20.7936, 1971.6245, 94.8188).iterator();+ func.streamDoubles( value -> {+ assertTrue(values.hasNext());+ assertEquals(values.next(), value, 0.0001);+ });+ assertFalse(values.hasNext());+ }+}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/RemoveFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/RemoveFunctionTest.javanew file mode 100644index 00000000000..05226f9cc44--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/RemoveFunctionTest.java@@ -0,0 +1,849 @@+/*+ * 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.analytics.function.mapping;++import java.time.Instant;+import java.time.format.DateTimeParseException;+import java.util.Arrays;+import java.util.Date;+import java.util.Iterator;++import org.apache.solr.SolrTestCaseJ4;+import org.apache.solr.analytics.value.AnalyticsValue;+import org.apache.solr.analytics.value.AnalyticsValueStream;+import org.apache.solr.analytics.value.BooleanValue;+import org.apache.solr.analytics.value.BooleanValueStream;+import org.apache.solr.analytics.value.DateValue;+import org.apache.solr.analytics.value.DateValueStream;+import org.apache.solr.analytics.value.DoubleValue;+import org.apache.solr.analytics.value.DoubleValueStream;+import org.apache.solr.analytics.value.FloatValue;+import org.apache.solr.analytics.value.FloatValueStream;+import org.apache.solr.analytics.value.IntValue;+import org.apache.solr.analytics.value.IntValueStream;+import org.apache.solr.analytics.value.LongValue;+import org.apache.solr.analytics.value.LongValueStream;+import org.apache.solr.analytics.value.StringValue;+import org.apache.solr.analytics.value.StringValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestAnalyticsValue;+import org.apache.solr.analytics.value.FillableTestValue.TestAnalyticsValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestBooleanValue;+import org.apache.solr.analytics.value.FillableTestValue.TestBooleanValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestDateValue;+import org.apache.solr.analytics.value.FillableTestValue.TestDateValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValue;+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValue;+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestIntValue;+import org.apache.solr.analytics.value.FillableTestValue.TestIntValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestLongValue;+import org.apache.solr.analytics.value.FillableTestValue.TestLongValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestStringValue;+import org.apache.solr.analytics.value.FillableTestValue.TestStringValueStream;+import org.junit.Test;++public class RemoveFunctionTest extends SolrTestCaseJ4 {++ @Test+ public void castingTest() {+ assertTrue(RemoveFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestBooleanValue(), new TestStringValue()}) instanceof StringValue);++ assertFalse(RemoveFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestIntValueStream(), new TestFloatValue()}) instanceof FloatValue);++ assertFalse(RemoveFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestLongValueStream(), new TestDateValue()}) instanceof AnalyticsValue);++ assertFalse(RemoveFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestLongValue(), new TestAnalyticsValue()}) instanceof StringValue);++ assertTrue(RemoveFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestIntValue(), new TestLongValue()}) instanceof DoubleValue);++ assertFalse(RemoveFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestDateValue(), new TestStringValue()}) instanceof DateValue);++ assertFalse(RemoveFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestBooleanValueStream(), new TestStringValue()}) instanceof BooleanValueStream);++ assertFalse(RemoveFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestDoubleValue(), new TestIntValue()}) instanceof LongValue);+ }++ @Test+ public void singleValueBooleanTest() {+ TestBooleanValue val = new TestBooleanValue();+ TestBooleanValue remover = new TestBooleanValue();++ AnalyticsValueStream uncasted = RemoveFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, remover});+ assertTrue(uncasted instanceof BooleanValue);+ BooleanValue func = (BooleanValue) uncasted;++ // Value doesn't exist+ val.setExists(false);+ remover.setExists(false);+ func.getBoolean();+ assertFalse(func.exists());++ val.setExists(false);+ remover.setValue(false).setExists(true);+ func.getBoolean();+ assertFalse(func.exists());++ // Value exists+ val.setValue(true).setExists(true);+ remover.setValue(false).setExists(true);+ assertEquals(true, func.getBoolean());+ assertTrue(func.exists());++ val.setValue(true).setExists(true);+ remover.setValue(true).setExists(true);+ func.getBoolean();+ assertFalse(func.exists());++ val.setValue(false).setExists(true);+ remover.setValue(true).setExists(true);+ assertEquals(false, func.getBoolean());+ assertTrue(func.exists());++ val.setValue(false).setExists(true);+ remover.setValue(false).setExists(true);+ func.getBoolean();+ assertFalse(func.exists());++ val.setValue(false).setExists(true);+ remover.setExists(false);+ assertEquals(false, func.getBoolean());+ assertTrue(func.exists());+ }++ @Test+ public void singleValueIntTest() {+ TestIntValue val = new TestIntValue();+ TestIntValue remover = new TestIntValue();++ AnalyticsValueStream uncasted = RemoveFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, remover});+ assertTrue(uncasted instanceof IntValue);+ IntValue func = (IntValue) uncasted;++ // Value doesn't exist+ val.setExists(false);+ remover.setExists(false);+ func.getInt();+ assertFalse(func.exists());++ val.setExists(false);+ remover.setValue(-234).setExists(true);+ func.getInt();+ assertFalse(func.exists());++ // Value exists+ val.setValue(21).setExists(true);+ remover.setValue(234).setExists(true);+ assertEquals(21, func.getInt());+ assertTrue(func.exists());++ val.setValue(-154).setExists(true);+ remover.setValue(-154).setExists(true);+ func.getInt();+ assertFalse(func.exists());++ val.setValue(52334).setExists(true);+ remover.setExists(false);+ assertEquals(52334, func.getInt());+ assertTrue(func.exists());+ }++ @Test+ public void singleValueLongTest() {+ TestLongValue val = new TestLongValue();+ TestLongValue remover = new TestLongValue();++ AnalyticsValueStream uncasted = RemoveFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, remover});+ assertTrue(uncasted instanceof LongValue);+ LongValue func = (LongValue) uncasted;++ // Value doesn't exist+ val.setExists(false);+ remover.setExists(false);+ func.getLong();+ assertFalse(func.exists());++ val.setExists(false);+ remover.setValue(234L).setExists(true);+ func.getLong();+ assertFalse(func.exists());++ // Value exists+ val.setValue(21L).setExists(true);+ remover.setValue(234L).setExists(true);+ assertEquals(21L, func.getLong());+ assertTrue(func.exists());++ val.setValue(3421L).setExists(true);+ remover.setValue(3421L).setExists(true);+ func.getLong();+ assertFalse(func.exists());++ val.setValue(-52334L).setExists(true);+ remover.setExists(false);+ assertEquals(-52334L, func.getLong());+ assertTrue(func.exists());+ }++ @Test+ public void singleValueFloatTest() {+ TestFloatValue val = new TestFloatValue();+ TestFloatValue remover = new TestFloatValue();++ AnalyticsValueStream uncasted = RemoveFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, remover});+ assertTrue(uncasted instanceof FloatValue);+ FloatValue func = (FloatValue) uncasted;++ // Value doesn't exist+ val.setExists(false);+ remover.setExists(false);+ func.getFloat();+ assertFalse(func.exists());++ val.setExists(false);+ remover.setValue(3124123.32F).setExists(true);+ func.getFloat();+ assertFalse(func.exists());++ // Value exists+ val.setValue(-21.324F).setExists(true);+ remover.setValue(23423.423342F).setExists(true);+ assertEquals(-21.324F, func.getFloat(), .00000001);+ assertTrue(func.exists());++ val.setValue(84353.452F).setExists(true);+ remover.setValue(84353.452F).setExists(true);+ func.getFloat();+ assertFalse(func.exists());++ val.setValue(2345.345543F).setExists(true);+ remover.setExists(false);+ assertEquals(2345.345543F, func.getFloat(), .00000001);+ assertTrue(func.exists());+ }++ @Test+ public void singleValueDoubleTest() {+ TestDoubleValue val = new TestDoubleValue();+ TestDoubleValue remover = new TestDoubleValue();++ AnalyticsValueStream uncasted = RemoveFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, remover});+ assertTrue(uncasted instanceof DoubleValue);+ DoubleValue func = (DoubleValue) uncasted;++ // Value doesn't exist+ val.setExists(false);+ remover.setExists(false);+ func.getDouble();+ assertFalse(func.exists());++ val.setExists(false);+ remover.setValue(3124123.32).setExists(true);+ func.getDouble();+ assertFalse(func.exists());++ // Value exists+ val.setValue(-21.324).setExists(true);+ remover.setValue(23423.423342).setExists(true);+ assertEquals(-21.324, func.getDouble(), .00000001);+ assertTrue(func.exists());++ val.setValue(84353.452).setExists(true);+ remover.setValue(84353.452).setExists(true);+ func.getDouble();+ assertFalse(func.exists());++ val.setValue(2345.345543).setExists(true);+ remover.setExists(false);+ assertEquals(2345.345543, func.getDouble(), .00000001);+ assertTrue(func.exists());+ }++ @Test+ public void singleValueDateTest() throws DateTimeParseException {+ Date date1 = Date.from(Instant.parse("1810-12-02T10:30:15Z"));+ Date date2 = Date.from(Instant.parse("1950-02-23T14:54:34Z"));+ Date date3 = Date.from(Instant.parse("2023-11-01T20:30:15Z"));++ TestDateValue val = new TestDateValue();+ TestDateValue remover = new TestDateValue();++ AnalyticsValueStream uncasted = RemoveFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, remover});+ assertTrue(uncasted instanceof DateValue);+ DateValue func = (DateValue) uncasted;++ // Value doesn't exist+ val.setExists(false);+ remover.setExists(false);+ func.getLong();+ assertFalse(func.exists());++ val.setExists(false);+ remover.setValue("1950-02-23T14:54:34Z").setExists(true);+ func.getLong();+ assertFalse(func.exists());++ // Value exists+ val.setValue("1810-12-02T10:30:15Z").setExists(true);+ remover.setValue("2023-11-01T20:30:15Z").setExists(true);+ assertEquals(date1.getTime(), func.getLong());+ assertTrue(func.exists());++ val.setValue("1950-02-23T14:54:34Z").setExists(true);+ remover.setValue("1950-02-23T14:54:34Z").setExists(true);+ func.getLong();+ assertFalse(func.exists());++ val.setValue("2023-11-01T20:30:15Z").setExists(true);+ remover.setExists(false);+ assertEquals(date3.getTime(), func.getLong());+ assertTrue(func.exists());+ }++ @Test+ public void singleValueStringTest() {+ TestStringValue val = new TestStringValue();+ TestStringValue remover = new TestStringValue();++ AnalyticsValueStream uncasted = RemoveFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, remover});+ assertTrue(uncasted instanceof StringValue);+ StringValue func = (StringValue) uncasted;++ // Value doesn't exist+ val.setExists(false);+ remover.setExists(false);+ func.getString();+ assertFalse(func.exists());++ val.setExists(false);+ remover.setValue("abc456").setExists(true);+ func.getString();+ assertFalse(func.exists());++ // Value exists+ val.setValue("abc123").setExists(true);+ remover.setValue("def456").setExists(true);+ assertEquals("abc123", func.getString());+ assertTrue(func.exists());++ val.setValue("this will be removed").setExists(true);+ remover.setValue("this will be removed").setExists(true);+ func.getString();+ assertFalse(func.exists());++ val.setValue("def123").setExists(true);+ remover.setExists(false);+ assertEquals("def123", func.getString());+ assertTrue(func.exists());+ }++ @Test+ public void singleValueObjectTest() {+ TestAnalyticsValue val = new TestAnalyticsValue();+ TestAnalyticsValue remover = new TestAnalyticsValue();++ AnalyticsValueStream uncasted = RemoveFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, remover});+ assertTrue(uncasted instanceof AnalyticsValue);+ AnalyticsValue func = (AnalyticsValue) uncasted;++ // Value doesn't exist+ val.setExists(false);+ remover.setExists(false);+ func.getObject();+ assertFalse(func.exists());++ val.setExists(false);+ remover.setValue(new Boolean(true)).setExists(true);+ func.getObject();+ assertFalse(func.exists());++ // Value exists+ val.setValue("abc123").setExists(true);+ remover.setValue(new Date(123)).setExists(true);+ assertEquals("abc123", func.getObject());+ assertTrue(func.exists());++ val.setValue(new Double(23423.0)).setExists(true);+ remover.setValue(new Double(23423.0)).setExists(true);+ func.getObject();+ assertFalse(func.exists());++ val.setValue(new Long(234)).setExists(true);+ remover.setExists(false);+ assertEquals(new Long(234), func.getObject());+ assertTrue(func.exists());+ }++ @Test+ public void multiValueBooleanTest() {+ TestBooleanValueStream val = new TestBooleanValueStream();+ TestBooleanValue remover = new TestBooleanValue();++ AnalyticsValueStream uncasted = RemoveFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, remover});+ assertTrue(uncasted instanceof BooleanValueStream);+ BooleanValueStream func = (BooleanValueStream) uncasted;++ // No values+ val.setValues();+ remover.setExists(false);+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ val.setValues();+ remover.setValue(true).setExists(true);+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Values exist+ val.setValues(false, true, false, true, true);+ remover.setValue(true).setExists(true);+ Iterator<Boolean> values1 = Arrays.asList(false, false).iterator();+ func.streamBooleans( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value);+ });+ assertFalse(values1.hasNext());++ val.setValues(false, true, false, true, true);+ remover.setExists(false);+ Iterator<Boolean> values2 = Arrays.asList(false, true, false, true, true).iterator();+ func.streamBooleans( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value);+ });+ assertFalse(values2.hasNext());++ val.setValues(false, true, false, true, true);+ remover.setValue(false).setExists(true);+ Iterator<Boolean> values3 = Arrays.asList(true, true, true).iterator();+ func.streamBooleans( value -> {+ assertTrue(values3.hasNext());+ assertEquals(values3.next(), value);+ });+ assertFalse(values3.hasNext());++ val.setValues(false, false, false);+ remover.setValue(false).setExists(true);+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });+ }++ @Test+ public void multiValueIntTest() {+ TestIntValueStream val = new TestIntValueStream();+ TestIntValue remover = new TestIntValue();++ AnalyticsValueStream uncasted = RemoveFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, remover});+ assertTrue(uncasted instanceof IntValueStream);+ IntValueStream func = (IntValueStream) uncasted;++ // No values+ val.setValues();+ remover.setExists(false);+ func.streamInts( value -> {+ assertTrue("There should be no values to stream", false);+ });++ val.setValues();+ remover.setValue(324).setExists(true);+ func.streamInts( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Values exist+ val.setValues(1, 234, -234, 4439, -234, -3245);+ remover.setValue(-234).setExists(true);+ Iterator<Integer> values1 = Arrays.asList(1, 234, 4439, -3245).iterator();+ func.streamInts( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next().intValue(), value);+ });+ assertFalse(values1.hasNext());++ val.setValues(1, 234, -234, 4439, -234, -3245);+ remover.setExists(false);+ Iterator<Integer> values2 = Arrays.asList(1, 234, -234, 4439, -234, -3245).iterator();+ func.streamInts( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next().intValue(), value);+ });+ assertFalse(values2.hasNext());++ val.setValues(1, 234, -234, 4439, -234, -3245);+ remover.setValue(100).setExists(true);+ Iterator<Integer> values3 = Arrays.asList(1, 234, -234, 4439, -234, -3245).iterator();+ func.streamInts( value -> {+ assertTrue(values3.hasNext());+ assertEquals(values3.next().intValue(), value);+ });+ assertFalse(values3.hasNext());++ val.setValues(1, 1);+ remover.setValue(1).setExists(true);+ func.streamInts( value -> {+ assertTrue("There should be no values to stream", false);+ });+ }++ @Test+ public void multiValueLongTest() {+ TestLongValueStream val = new TestLongValueStream();+ TestLongValue remover = new TestLongValue();++ AnalyticsValueStream uncasted = RemoveFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, remover});+ assertTrue(uncasted instanceof LongValueStream);+ LongValueStream func = (LongValueStream) uncasted;++ // No values+ val.setValues();+ remover.setExists(false);+ func.streamLongs( value -> {+ assertTrue("There should be no values to stream", false);+ });++ val.setValues();+ remover.setValue(2323L).setExists(true);+ func.streamLongs( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Values exist+ val.setValues(323L, -9423L, -1234L, 23423L, -1234L, -1234L);+ remover.setValue(-1234L).setExists(true);+ Iterator<Long> values1 = Arrays.asList(323L, -9423L, 23423L).iterator();+ func.streamLongs( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next().longValue(), value);+ });+ assertFalse(values1.hasNext());++ val.setValues(323L, -9423L, -1234L, 23423L, -1234L, -1234L);+ remover.setExists(false);+ Iterator<Long> values2 = Arrays.asList(323L, -9423L, -1234L, 23423L, -1234L, -1234L).iterator();+ func.streamLongs( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next().longValue(), value);+ });+ assertFalse(values2.hasNext());++ val.setValues(323L, -9423L, -1234L, 23423L, -1234L, -1234L);+ remover.setValue(100L).setExists(true);+ Iterator<Long> values3 = Arrays.asList(323L, -9423L, -1234L, 23423L, -1234L, -1234L).iterator();+ func.streamLongs( value -> {+ assertTrue(values3.hasNext());+ assertEquals(values3.next().longValue(), value);+ });+ assertFalse(values3.hasNext());++ val.setValues(10L);+ remover.setValue(10L).setExists(true);+ func.streamLongs( value -> {+ assertTrue("There should be no values to stream", false);+ });+ }++ @Test+ public void multiValueFloatTest() {+ TestFloatValueStream val = new TestFloatValueStream();+ TestFloatValue remover = new TestFloatValue();++ AnalyticsValueStream uncasted = RemoveFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, remover});+ assertTrue(uncasted instanceof FloatValueStream);+ FloatValueStream func = (FloatValueStream) uncasted;++ // No values+ val.setValues();+ remover.setExists(false);+ func.streamFloats( value -> {+ assertTrue("There should be no values to stream", false);+ });++ val.setValues();+ remover.setValue(230.32F).setExists(true);+ func.streamFloats( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Values exist+ val.setValues(-1234.9478F, -9423.5F, -1234.9478F, 23423.324F, 942.0F);+ remover.setValue(-1234.9478F).setExists(true);+ Iterator<Float> values1 = Arrays.asList(-9423.5F, 23423.324F, 942.0F).iterator();+ func.streamFloats( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value, .00000001);+ });+ assertFalse(values1.hasNext());++ val.setValues(-1234.9478F, -9423.5F, -1234.9478F, 23423.324F, 942.0F);+ remover.setExists(false);+ Iterator<Float> values2 = Arrays.asList(-1234.9478F, -9423.5F, -1234.9478F, 23423.324F, 942.0F).iterator();+ func.streamFloats( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value, .00000001);+ });+ assertFalse(values2.hasNext());++ val.setValues(-1234.9478F, -9423.5F, -1234.9478F, 23423.324F, 942.0F);+ remover.setValue(23423.5845F).setExists(true);+ Iterator<Float> values3= Arrays.asList(-1234.9478F, -9423.5F, -1234.9478F, 23423.324F, 942.0F).iterator();+ func.streamFloats( value -> {+ assertTrue(values3.hasNext());+ assertEquals(values3.next(), value, .00000001);+ });+ assertFalse(values3.hasNext());++ val.setValues(23.56F, 23.56F, 23.56F);+ remover.setValue(23.56F).setExists(true);+ func.streamFloats( value -> {+ assertTrue("There should be no values to stream", false);+ });+ }++ @Test+ public void multiValueDoubleTest() {+ TestDoubleValueStream val = new TestDoubleValueStream();+ TestDoubleValue remover = new TestDoubleValue();++ AnalyticsValueStream uncasted = RemoveFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, remover});+ assertTrue(uncasted instanceof DoubleValueStream);+ DoubleValueStream func = (DoubleValueStream) uncasted;++ // No values+ val.setValues();+ remover.setExists(false);+ func.streamDoubles( value -> {+ assertTrue("There should be no values to stream", false);+ });++ val.setValues();+ remover.setValue(234237.67).setExists(true);+ func.streamDoubles( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Values exist+ val.setValues(323.213, -9423.5, 124544.42);+ remover.setValue(124544.42).setExists(true);+ Iterator<Double> values1 = Arrays.asList(323.213, -9423.5).iterator();+ func.streamDoubles( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value, .00000001);+ });+ assertFalse(values1.hasNext());++ val.setValues(323.213, -9423.5, 124544.42);+ remover.setExists(false);+ Iterator<Double> values2 = Arrays.asList(323.213, -9423.5, 124544.42).iterator();+ func.streamDoubles( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value, .00000001);+ });+ assertFalse(values2.hasNext());+++ val.setValues(323.213, -9423.5, 124544.42);+ remover.setValue(345.34).setExists(true);+ Iterator<Double> values3 = Arrays.asList(323.213, -9423.5, 124544.42).iterator();+ func.streamDoubles( value -> {+ assertTrue(values3.hasNext());+ assertEquals(values3.next(), value, .00000001);+ });+ assertFalse(values1.hasNext());++ val.setValues(3124.96, 3124.96);+ remover.setValue(3124.96).setExists(true);+ func.streamDoubles( value -> {+ assertTrue("There should be no values to stream", false);+ });+ }++ @Test+ public void multiValueDateTest() throws DateTimeParseException {+ Date date1 = Date.from(Instant.parse("1810-12-02T10:30:15Z"));+ Date date2 = Date.from(Instant.parse("1931-03-16T18:15:45Z"));+ Date date3 = Date.from(Instant.parse("2023-11-01T20:30:15Z"));++ TestDateValueStream val = new TestDateValueStream();+ TestDateValue remover = new TestDateValue();++ AnalyticsValueStream uncasted = RemoveFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, remover});+ assertTrue(uncasted instanceof DateValueStream);+ DateValueStream func = (DateValueStream) uncasted;++ // No values+ val.setValues();+ remover.setExists(false);+ func.streamLongs( value -> {+ assertTrue("There should be no values to stream", false);+ });++ val.setValues();+ remover.setValue("1700-12-14").setExists(true);+ func.streamLongs( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Values exist+ val.setValues("1810-12-02T10:30:15Z", "1931-03-16T18:15:45Z", "2023-11-01T20:30:15Z", "1931-03-16T18:15:45Z");+ remover.setValue("1931-03-16T18:15:45Z").setExists(true);+ Iterator<Long> values1 = Arrays.asList(date1.getTime(), date3.getTime()).iterator();+ func.streamLongs( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next().longValue(), value);+ });+ assertFalse(values1.hasNext());++ val.setValues("1810-12-02T10:30:15Z", "1931-03-16T18:15:45Z", "2023-11-01T20:30:15Z", "1931-03-16T18:15:45Z");+ remover.setExists(false);+ Iterator<Long> values2 = Arrays.asList(date1.getTime(), date2.getTime(), date3.getTime(), date2.getTime()).iterator();+ func.streamLongs( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next().longValue(), value);+ });+ assertFalse(values2.hasNext());++ val.setValues("1810-12-02T10:30:15Z", "1931-03-16T18:15:45Z", "2023-11-01T20:30:15Z", "1931-03-16T18:15:45Z");+ remover.setValue("1810-12-02T10:30:16Z").setExists(true);+ Iterator<Long> values3 = Arrays.asList(date1.getTime(), date2.getTime(), date3.getTime(), date2.getTime()).iterator();+ func.streamLongs( value -> {+ assertTrue(values3.hasNext());+ assertEquals(values3.next().longValue(), value);+ });+ assertFalse(values3.hasNext());++ val.setValues("1810-12-02T10:30:15Z");+ remover.setValue("1810-12-02T10:30:15Z").setExists(true);+ func.streamLongs( value -> {+ assertTrue("There should be no values to stream", false);+ });+ }++ @Test+ public void multiValueStringTest() {+ TestStringValueStream val = new TestStringValueStream();+ TestStringValue remover = new TestStringValue();++ AnalyticsValueStream uncasted = RemoveFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, remover});+ assertTrue(uncasted instanceof StringValueStream);+ StringValueStream func = (StringValueStream) uncasted;++ // No values+ val.setValues();+ remover.setExists(false);+ func.streamStrings( value -> {+ assertTrue("There should be no values to stream", false);+ });++ val.setValues();+ remover.setValue("ads").setExists(true);+ func.streamStrings( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Values exist+ val.setValues("abc", "123", "456", "abc");+ remover.setValue("abc").setExists(true);+ Iterator<String> values1 = Arrays.asList("123", "456").iterator();+ func.streamStrings( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value);+ });+ assertFalse(values1.hasNext());++ val.setValues("abc", "123", "456", "abc");+ remover.setExists(false);+ Iterator<String> values2 = Arrays.asList("abc", "123", "456", "abc").iterator();+ func.streamStrings( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value);+ });+ assertFalse(values2.hasNext());++ val.setValues("string1", "another string", "the final and last string");+ remover.setValue("not in values").setExists(true);+ Iterator<String> values3 = Arrays.asList("string1", "another string", "the final and last string").iterator();+ func.streamStrings( value -> {+ assertTrue(values3.hasNext());+ assertEquals(values3.next(), value);+ });+ assertFalse(values3.hasNext());++ val.setValues("abc123", "abc123", "abc123", "abc123");+ remover.setValue("abc123").setExists(true);+ func.streamStrings( value -> {+ assertTrue("There should be no values to stream", false);+ });+ }++ @Test+ public void multiValueObjectTest() {+ TestAnalyticsValueStream val = new TestAnalyticsValueStream();+ TestAnalyticsValue remover = new TestAnalyticsValue();++ AnalyticsValueStream func = RemoveFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, remover});++ // No values+ val.setValues();+ remover.setExists(false);+ func.streamObjects( value -> {+ assertTrue("There should be no values to stream", false);+ });++ val.setValues();+ remover.setValue("doesn't matter").setExists(true);+ func.streamObjects( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Values exist+ val.setValues("asdfs", new Date(12312), new Long(213123L), new Date(12312));+ remover.setValue(new Date(12312)).setExists(true);+ Iterator<Object> values1 = Arrays.<Object>asList("asdfs", new Long(213123L)).iterator();+ func.streamObjects( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value);+ });+ assertFalse(values1.hasNext());++ val.setValues("asdfs", new Date(12312), new Long(213123L), new Date(12312));+ remover.setExists(false);+ Iterator<Object> values2 = Arrays.<Object>asList("asdfs", new Date(12312), new Long(213123L), new Date(12312)).iterator();+ func.streamObjects( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value);+ });+ assertFalse(values2.hasNext());++ val.setValues(new Date(3), "3", new Float(3F));+ remover.setValue(new Date(4)).setExists(true);+ Iterator<Object> values3 = Arrays.<Object>asList(new Date(3), "3", new Float(3F)).iterator();+ func.streamObjects( value -> {+ assertTrue(values3.hasNext());+ assertEquals(values3.next(), value);+ });+ assertFalse(values3.hasNext());++ val.setValues(new Date(4));+ remover.setValue(new Date(4)).setExists(true);+ func.streamObjects( value -> {+ assertTrue("There should be no values to stream", false);+ });+ }+}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/ReplaceFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/ReplaceFunctionTest.javanew file mode 100644index 00000000000..c62546d9ec3--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/ReplaceFunctionTest.java@@ -0,0 +1,990 @@+/*+ * 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.analytics.function.mapping;++import java.time.Instant;+import java.time.format.DateTimeParseException;+import java.util.Arrays;+import java.util.Date;+import java.util.Iterator;++import org.apache.solr.SolrTestCaseJ4;+import org.apache.solr.analytics.value.AnalyticsValue;+import org.apache.solr.analytics.value.AnalyticsValueStream;+import org.apache.solr.analytics.value.BooleanValue;+import org.apache.solr.analytics.value.BooleanValueStream;+import org.apache.solr.analytics.value.DateValue;+import org.apache.solr.analytics.value.DateValueStream;+import org.apache.solr.analytics.value.DoubleValue;+import org.apache.solr.analytics.value.DoubleValueStream;+import org.apache.solr.analytics.value.FloatValue;+import org.apache.solr.analytics.value.FloatValueStream;+import org.apache.solr.analytics.value.IntValue;+import org.apache.solr.analytics.value.IntValueStream;+import org.apache.solr.analytics.value.LongValue;+import org.apache.solr.analytics.value.LongValueStream;+import org.apache.solr.analytics.value.StringValue;+import org.apache.solr.analytics.value.StringValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestAnalyticsValue;+import org.apache.solr.analytics.value.FillableTestValue.TestAnalyticsValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestBooleanValue;+import org.apache.solr.analytics.value.FillableTestValue.TestBooleanValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestDateValue;+import org.apache.solr.analytics.value.FillableTestValue.TestDateValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValue;+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValue;+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestIntValue;+import org.apache.solr.analytics.value.FillableTestValue.TestIntValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestLongValue;+import org.apache.solr.analytics.value.FillableTestValue.TestLongValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestStringValue;+import org.apache.solr.analytics.value.FillableTestValue.TestStringValueStream;+import org.junit.Test;++public class ReplaceFunctionTest extends SolrTestCaseJ4 {++ @Test+ public void castingTest() {+ assertTrue(ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestBooleanValue(), new TestStringValue(), new TestStringValue()}) instanceof StringValue);++ assertFalse(ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestIntValueStream(), new TestFloatValue(), new TestDoubleValue()}) instanceof FloatValueStream);++ assertFalse(ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestLongValueStream(), new TestDateValue(), new TestLongValue()}) instanceof DateValueStream);++ assertFalse(ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestLongValue(), new TestAnalyticsValue(), new TestStringValue()}) instanceof StringValue);++ assertTrue(ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestIntValue(), new TestLongValue(), new TestFloatValue()}) instanceof DoubleValue);++ assertFalse(ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestDateValue(), new TestStringValue(), new TestLongValue()}) instanceof DateValue);++ assertFalse(ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestBooleanValueStream(), new TestStringValue(), new TestStringValue()}) instanceof BooleanValueStream);++ assertFalse(ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestDoubleValue(), new TestIntValue(), new TestLongValue()}) instanceof LongValue);+ }++ @Test+ public void singleValueBooleanTest() {+ TestBooleanValue val = new TestBooleanValue();+ TestBooleanValue comp = new TestBooleanValue();+ TestBooleanValue fill = new TestBooleanValue();++ AnalyticsValueStream uncasted = ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, comp, fill});+ assertTrue(uncasted instanceof BooleanValue);+ BooleanValue func = (BooleanValue) uncasted;++ // Value doesn't exist+ val.setExists(false);+ comp.setExists(false);+ fill.setExists(false);+ func.getBoolean();+ assertFalse(func.exists());++ val.setExists(false);+ comp.setValue(false).setExists(true);+ fill.setValue(true).setExists(true);+ func.getBoolean();+ assertFalse(func.exists());++ // Comp doesn't exist+ val.setValue(true).setExists(true);+ comp.setExists(false);+ fill.setValue(false).setExists(true);+ assertEquals(true, func.getBoolean());+ assertTrue(func.exists());++ // Value exists+ val.setValue(true).setExists(true);+ comp.setValue(false).setExists(true);+ fill.setValue(false).setExists(true);+ assertEquals(true, func.getBoolean());+ assertTrue(func.exists());++ val.setValue(true).setExists(true);+ comp.setValue(true).setExists(true);+ fill.setValue(false).setExists(true);+ assertEquals(false, func.getBoolean());+ assertTrue(func.exists());++ val.setValue(false).setExists(true);+ comp.setValue(false).setExists(true);+ fill.setExists(false);+ func.getBoolean();+ assertFalse(func.exists());+ }++ @Test+ public void singleValueIntTest() {+ TestIntValue val = new TestIntValue();+ TestIntValue comp = new TestIntValue();+ TestIntValue fill = new TestIntValue();++ AnalyticsValueStream uncasted = ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, comp, fill});+ assertTrue(uncasted instanceof IntValue);+ IntValue func = (IntValue) uncasted;++ // Value doesn't exist+ val.setExists(false);+ comp.setExists(false);+ func.getInt();+ assertFalse(func.exists());++ val.setExists(false);+ comp.setValue(-234).setExists(true);+ fill.setValue(765).setExists(true);+ func.getInt();+ assertFalse(func.exists());++ // Comp doesn't exist+ val.setValue(745).setExists(true);+ comp.setExists(false);+ fill.setValue(23423).setExists(true);+ assertEquals(745, func.getInt());+ assertTrue(func.exists());++ // Value exists+ // Comp != Val+ val.setValue(21).setExists(true);+ comp.setValue(234).setExists(true);++ fill.setValue(23423).setExists(true);+ assertEquals(21, func.getInt());+ assertTrue(func.exists());++ fill.setExists(false);+ assertEquals(21, func.getInt());+ assertTrue(func.exists());++ // Comp == Val+ val.setValue(-154).setExists(true);+ comp.setValue(-154).setExists(true);++ fill.setExists(false);+ func.getInt();+ assertFalse(func.exists());++ fill.setValue(23423).setExists(true);+ assertEquals(23423, func.getInt());+ assertTrue(func.exists());+ }++ @Test+ public void singleValueLongTest() {+ TestLongValue val = new TestLongValue();+ TestLongValue comp = new TestLongValue();+ TestLongValue fill = new TestLongValue();++ AnalyticsValueStream uncasted = ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, comp, fill});+ assertTrue(uncasted instanceof LongValue);+ LongValue func = (LongValue) uncasted;++ // Value doesn't exist+ val.setExists(false);+ comp.setExists(false);+ fill.setExists(false);+ func.getLong();+ assertFalse(func.exists());++ val.setExists(false);+ comp.setValue(234L).setExists(true);+ fill.setValue(232584L).setExists(true);+ func.getLong();+ assertFalse(func.exists());++ // Comp doesn't exist+ val.setValue(745L).setExists(true);+ comp.setExists(false);+ fill.setValue(23423L).setExists(true);+ assertEquals(745L, func.getLong());+ assertTrue(func.exists());++ // Value exists+ // Comp != Val+ val.setValue(21L).setExists(true);+ comp.setValue(234L).setExists(true);++ fill.setValue(23423L).setExists(true);+ assertEquals(21L, func.getLong());+ assertTrue(func.exists());++ fill.setExists(false);+ assertEquals(21L, func.getLong());+ assertTrue(func.exists());++ // Comp == Val+ val.setValue(-154L).setExists(true);+ comp.setValue(-154L).setExists(true);++ fill.setExists(false);+ func.getLong();+ assertFalse(func.exists());++ fill.setValue(23423L).setExists(true);+ assertEquals(23423L, func.getLong());+ assertTrue(func.exists());+ }++ @Test+ public void singleValueFloatTest() {+ TestFloatValue val = new TestFloatValue();+ TestFloatValue comp = new TestFloatValue();+ TestFloatValue fill = new TestFloatValue();++ AnalyticsValueStream uncasted = ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, comp, fill});+ assertTrue(uncasted instanceof FloatValue);+ FloatValue func = (FloatValue) uncasted;++ // Value doesn't exist+ val.setExists(false);+ comp.setExists(false);+ fill.setExists(false);+ func.getFloat();+ assertFalse(func.exists());++ val.setExists(false);+ comp.setValue(3124123.32F).setExists(true);+ fill.setValue(-32473.336F).setExists(true);+ func.getFloat();+ assertFalse(func.exists());++ // Comp doesn't exist+ val.setValue(-745.234F).setExists(true);+ comp.setExists(false);+ fill.setValue(23423.324F).setExists(true);+ assertEquals(-745.234F, func.getFloat(), .0000001);+ assertTrue(func.exists());++ // Value exists+ // Comp != Val+ val.setValue(3423.304F).setExists(true);+ comp.setValue(3423.303F).setExists(true);++ fill.setValue(-23.764F).setExists(true);+ assertEquals(3423.304F, func.getFloat(), .0000001);+ assertTrue(func.exists());++ fill.setExists(false);+ assertEquals(3423.304F, func.getFloat(), .0000001);+ assertTrue(func.exists());++ // Comp == Val+ val.setValue(-154.45F).setExists(true);+ comp.setValue(-154.45F).setExists(true);++ fill.setExists(false);+ func.getFloat();+ assertFalse(func.exists());++ fill.setValue(4353434.234F).setExists(true);+ assertEquals(4353434.234F, func.getFloat(), .0000001);+ assertTrue(func.exists());+ }++ @Test+ public void singleValueDoubleTest() {+ TestDoubleValue val = new TestDoubleValue();+ TestDoubleValue comp = new TestDoubleValue();+ TestDoubleValue fill = new TestDoubleValue();++ AnalyticsValueStream uncasted = ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, comp, fill});+ assertTrue(uncasted instanceof DoubleValue);+ DoubleValue func = (DoubleValue) uncasted;++ // Value doesn't exist+ val.setExists(false);+ comp.setExists(false);+ fill.setExists(false);+ func.getDouble();+ assertFalse(func.exists());++ val.setExists(false);+ comp.setValue(3124123.32).setExists(true);+ fill.setValue(-13242.34).setExists(true);+ func.getDouble();+ assertFalse(func.exists());++ // Comp doesn't exist+ val.setValue(-745.234).setExists(true);+ comp.setExists(false);+ fill.setValue(23423.324).setExists(true);+ assertEquals(-745.234, func.getDouble(), .0000001);+ assertTrue(func.exists());++ // Value exists+ // Comp != Val+ val.setValue(34923.304).setExists(true);+ comp.setValue(34923.303).setExists(true);++ fill.setValue(-23.764).setExists(true);+ assertEquals(34923.304, func.getDouble(), .0000001);+ assertTrue(func.exists());++ fill.setExists(false);+ assertEquals(34923.304, func.getDouble(), .0000001);+ assertTrue(func.exists());++ // Comp == Val+ val.setValue(-154.45).setExists(true);+ comp.setValue(-154.45).setExists(true);++ fill.setExists(false);+ func.getDouble();+ assertFalse(func.exists());++ fill.setValue(4353434.234).setExists(true);+ assertEquals(4353434.234, func.getDouble(), .0000001);+ assertTrue(func.exists());+ }++ @Test+ public void singleValueDateTest() throws DateTimeParseException {+ Date date1 = Date.from(Instant.parse("1810-12-02T10:30:15Z"));+ Date date2 = Date.from(Instant.parse("1950-02-23T14:54:34Z"));++ TestDateValue val = new TestDateValue();+ TestDateValue comp = new TestDateValue();+ TestDateValue fill = new TestDateValue();++ AnalyticsValueStream uncasted = ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, comp, fill});+ assertTrue(uncasted instanceof DateValue);+ DateValue func = (DateValue) uncasted;++ // Value doesn't exist+ val.setExists(false);+ comp.setExists(false);+ fill.setExists(false);+ func.getLong();+ assertFalse(func.exists());++ val.setExists(false);+ comp.setValue("1950-02-23T14:54:34Z").setExists(true);+ fill.setValue("1350-02-26T14:34:34Z").setExists(true);+ func.getLong();+ assertFalse(func.exists());++ // Comp doesn't exist+ val.setValue("1950-02-23T14:54:34Z").setExists(true);+ comp.setExists(false);+ fill.setValue("1350-02-26T14:34:34Z").setExists(true);+ assertEquals(date2.getTime(), func.getLong());+ assertTrue(func.exists());++ // Value exists+ // Comp != Val+ val.setValue("1950-02-23T14:54:34Z").setExists(true);+ comp.setValue("1350-02-26T14:34:34Z").setExists(true);++ fill.setValue("2023-11-01T20:30:15Z").setExists(true);+ assertEquals(date2.getTime(), func.getLong());+ assertTrue(func.exists());++ fill.setExists(false);+ assertEquals(date2.getTime(), func.getLong());+ assertTrue(func.exists());++ // Comp == Val+ val.setValue("2023-11-01T20:30:15Z").setExists(true);+ comp.setValue("2023-11-01T20:30:15Z").setExists(true);++ fill.setExists(false);+ func.getLong();+ assertFalse(func.exists());++ fill.setValue("1810-12-02T10:30:15Z").setExists(true);+ assertEquals(date1.getTime(), func.getLong());+ assertTrue(func.exists());+ }++ @Test+ public void singleValueStringTest() {+ TestStringValue val = new TestStringValue();+ TestStringValue comp = new TestStringValue();+ TestStringValue fill = new TestStringValue();++ AnalyticsValueStream uncasted = ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, comp, fill});+ assertTrue(uncasted instanceof StringValue);+ StringValue func = (StringValue) uncasted;++ // Value doesn't exist+ val.setExists(false);+ comp.setExists(false);+ fill.setExists(false);+ func.getString();+ assertFalse(func.exists());++ val.setExists(false);+ comp.setValue("abc456").setExists(true);+ fill.setValue("not touched").setExists(true);+ func.getString();+ assertFalse(func.exists());++ // Comp doesn't exist+ val.setValue("abcd").setExists(true);+ comp.setExists(false);+ fill.setValue("12234").setExists(true);+ assertEquals("abcd", func.getString());+ assertTrue(func.exists());++ // Value exists+ // Comp != Val+ val.setValue("original").setExists(true);+ comp.setValue("different").setExists(true);++ fill.setValue("anything").setExists(true);+ assertEquals("original", func.getString());+ assertTrue(func.exists());++ fill.setExists(false);+ assertEquals("original", func.getString());+ assertTrue(func.exists());++ // Comp == Val+ val.setValue("the same").setExists(true);+ comp.setValue("the same").setExists(true);++ fill.setExists(false);+ func.getString();+ assertFalse(func.exists());++ fill.setValue("replacement").setExists(true);+ assertEquals("replacement", func.getString());+ assertTrue(func.exists());+ }++ @Test+ public void singleValueObjectTest() {+ TestAnalyticsValue val = new TestAnalyticsValue();+ TestAnalyticsValue comp = new TestAnalyticsValue();+ TestAnalyticsValue fill = new TestAnalyticsValue();++ AnalyticsValueStream uncasted = ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, comp, fill});+ assertTrue(uncasted instanceof AnalyticsValue);+ AnalyticsValue func = (AnalyticsValue) uncasted;++ // Value doesn't exist+ val.setExists(false);+ comp.setExists(false);+ fill.setExists(false);+ func.getObject();+ assertFalse(func.exists());++ val.setExists(false);+ comp.setValue(new Boolean(true)).setExists(true);+ fill.setValue("abc").setExists(true);+ func.getObject();+ assertFalse(func.exists());++ // Comp doesn't exist+ val.setValue("abcd").setExists(true);+ comp.setExists(false);+ fill.setValue(new Date(123321)).setExists(true);+ assertEquals("abcd", func.getObject());+ assertTrue(func.exists());++ // Value exists+ // Comp != Val+ val.setValue(new Date(1234)).setExists(true);+ comp.setValue(new Integer(1234)).setExists(true);++ fill.setValue("not used").setExists(true);+ assertEquals(new Date(1234), func.getObject());+ assertTrue(func.exists());++ fill.setExists(false);+ assertEquals(new Date(1234), func.getObject());+ assertTrue(func.exists());++ // Comp == Val+ val.setValue(new Float(2342.324F)).setExists(true);+ comp.setValue(new Float(2342.324F)).setExists(true);++ fill.setExists(false);+ func.getObject();+ assertFalse(func.exists());++ fill.setValue("replacement").setExists(true);+ assertEquals("replacement", func.getObject());+ assertTrue(func.exists());+ }++ @Test+ public void multiValueBooleanTest() {+ TestBooleanValueStream val = new TestBooleanValueStream();+ TestBooleanValue comp = new TestBooleanValue();+ TestBooleanValue fill = new TestBooleanValue();++ AnalyticsValueStream uncasted = ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, comp, fill});+ assertTrue(uncasted instanceof BooleanValueStream);+ BooleanValueStream func = (BooleanValueStream) uncasted;++ // No values+ val.setValues();+ comp.setExists(false);+ fill.setExists(false);+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ val.setValues();+ comp.setValue(true).setExists(true);+ fill.setValue(false).setExists(true);+ func.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Comp doesn't exist+ val.setValues(false, true, false, true, true);+ comp.setExists(false);+ fill.setValue(true).setExists(true);+ Iterator<Boolean> values1 = Arrays.asList(false, true, false, true, true).iterator();+ func.streamBooleans( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value);+ });+ assertFalse(values1.hasNext());++ // Values exist+ val.setValues(false, true, false, true, true);+ comp.setValue(true).setExists(true);+ fill.setValue(false).setExists(true);+ Iterator<Boolean> values2 = Arrays.asList(false, false, false, false, false).iterator();+ func.streamBooleans( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value);+ });+ assertFalse(values2.hasNext());++ val.setValues(false, true, false, true, true);+ comp.setValue(false).setExists(true);+ fill.setExists(false);+ Iterator<Boolean> values3 = Arrays.asList(true, true, true).iterator();+ func.streamBooleans( value -> {+ assertTrue(values3.hasNext());+ assertEquals(values3.next(), value);+ });+ assertFalse(values3.hasNext());+ }++ @Test+ public void multiValueIntTest() {+ TestIntValueStream val = new TestIntValueStream();+ TestIntValue comp = new TestIntValue();+ TestIntValue fill = new TestIntValue();++ AnalyticsValueStream uncasted = ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, comp, fill});+ assertTrue(uncasted instanceof IntValueStream);+ IntValueStream func = (IntValueStream) uncasted;++ // No values+ val.setValues();+ comp.setExists(false);+ fill.setExists(false);+ func.streamInts( value -> {+ assertTrue("There should be no values to stream", false);+ });++ val.setValues();+ comp.setValue(324).setExists(true);+ fill.setValue(52341).setExists(true);+ func.streamInts( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Comp doesn't exist+ val.setValues(1, 234, -234, 4439, -234, -3245);+ comp.setExists(false);+ fill.setValue(52135).setExists(true);+ Iterator<Integer> values1 = Arrays.asList(1, 234, -234, 4439, -234, -3245).iterator();+ func.streamInts( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next().intValue(), value);+ });+ assertFalse(values1.hasNext());++ // Values exist+ val.setValues(1, 234, -234, 4439, -234, -3245);+ comp.setValue(-234).setExists(true);+ fill.setExists(false);+ Iterator<Integer> values2 = Arrays.asList(1, 234, 4439, -3245).iterator();+ func.streamInts( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next().intValue(), value);+ });+ assertFalse(values2.hasNext());++ val.setValues(1, 234, -234, 4439, -234, -3245);+ comp.setValue(4439).setExists(true);+ fill.setValue(-1000).setExists(true);+ Iterator<Integer> values3 = Arrays.asList(1, 234, -234, -1000, -234, -3245).iterator();+ func.streamInts( value -> {+ assertTrue(values3.hasNext());+ assertEquals(values3.next().intValue(), value);+ });+ assertFalse(values3.hasNext());+ }++ @Test+ public void multiValueLongTest() {+ TestLongValueStream val = new TestLongValueStream();+ TestLongValue comp = new TestLongValue();+ TestLongValue fill = new TestLongValue();++ AnalyticsValueStream uncasted = ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, comp, fill});+ assertTrue(uncasted instanceof LongValueStream);+ LongValueStream func = (LongValueStream) uncasted;++ // No values+ val.setValues();+ comp.setExists(false);+ fill.setExists(false);+ func.streamLongs( value -> {+ assertTrue("There should be no values to stream", false);+ });++ val.setValues();+ comp.setValue(2323L).setExists(true);+ fill.setValue(-5943L).setExists(true);+ func.streamLongs( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Comp doesn't exist+ val.setValues(1L, 234L, -234L, 4439L, -234L, -3245L);+ comp.setExists(false);+ fill.setValue(52135L).setExists(true);+ Iterator<Long> values1 = Arrays.asList(1L, 234L, -234L, 4439L, -234L, -3245L).iterator();+ func.streamLongs( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next().longValue(), value);+ });+ assertFalse(values1.hasNext());++ // Values exist+ val.setValues(1L, 234L, -234L, 4439L, -234L, -3245L);+ comp.setValue(-234L).setExists(true);+ fill.setExists(false);+ Iterator<Long> values2 = Arrays.asList(1L, 234L, 4439L, -3245L).iterator();+ func.streamLongs( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next().longValue(), value);+ });+ assertFalse(values2.hasNext());++ val.setValues(1L, 234L, -234L, 4439L, -234L, -3245L);+ comp.setValue(4439L).setExists(true);+ fill.setValue(-1000L).setExists(true);+ Iterator<Long> values3 = Arrays.asList(1L, 234L, -234L, -1000L, -234L, -3245L).iterator();+ func.streamLongs( value -> {+ assertTrue(values3.hasNext());+ assertEquals(values3.next().longValue(), value);+ });+ assertFalse(values3.hasNext());+ }++ @Test+ public void multiValueFloatTest() {+ TestFloatValueStream val = new TestFloatValueStream();+ TestFloatValue comp = new TestFloatValue();+ TestFloatValue fill = new TestFloatValue();++ AnalyticsValueStream uncasted = ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, comp, fill});+ assertTrue(uncasted instanceof FloatValueStream);+ FloatValueStream func = (FloatValueStream) uncasted;++ // No values+ val.setValues();+ comp.setExists(false);+ fill.setExists(false);+ func.streamFloats( value -> {+ assertTrue("There should be no values to stream", false);+ });++ val.setValues();+ comp.setValue(-230.32F).setExists(true);+ fill.setValue(9459.3458F).setExists(true);+ func.streamFloats( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Comp doesn't exist+ val.setValues(1423.3F, 423.4323F, -2349.2F, -343.43934F, 423.4323F);+ comp.setExists(false);+ fill.setValue(234.234F).setExists(true);+ Iterator<Float> values1 = Arrays.asList(1423.3F, 423.4323F, -2349.2F, -343.43934F, 423.4323F).iterator();+ func.streamFloats( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value, .000001);+ });+ assertFalse(values1.hasNext());++ // Values exist+ val.setValues(1423.3F, 423.4323F, -2349.2F, -343.43934F, 423.4323F);+ comp.setValue(423.4323F).setExists(true);+ fill.setExists(false);+ Iterator<Float> values2 = Arrays.asList(1423.3F, -2349.2F, -343.43934F).iterator();+ func.streamFloats( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value, .000001);+ });+ assertFalse(values2.hasNext());++ val.setValues(1423.3F, 423.4323F, -2349.2F, -343.43934F, 423.4323F);+ comp.setValue(423.4323F).setExists(true);+ fill.setValue(-1000F).setExists(true);+ Iterator<Float> values3 = Arrays.asList(1423.3F, -1000F, -2349.2F, -343.43934F, -1000F).iterator();+ func.streamFloats( value -> {+ assertTrue(values3.hasNext());+ assertEquals(values3.next(), value, .000001);+ });+ assertFalse(values3.hasNext());+ }++ @Test+ public void multiValueDoubleTest() {+ TestDoubleValueStream val = new TestDoubleValueStream();+ TestDoubleValue comp = new TestDoubleValue();+ TestDoubleValue fill = new TestDoubleValue();++ AnalyticsValueStream uncasted = ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, comp, fill});+ assertTrue(uncasted instanceof DoubleValueStream);+ DoubleValueStream func = (DoubleValueStream) uncasted;++ // No values+ val.setValues();+ comp.setExists(false);+ fill.setExists(false);+ func.streamDoubles( value -> {+ assertTrue("There should be no values to stream", false);+ });++ val.setValues();+ comp.setValue(234237.67).setExists(true);+ fill.setValue(-234.312).setExists(true);+ func.streamDoubles( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Comp doesn't exist+ val.setValues(1423.3, 423.4323, -2349.2, -343.43934, 423.4323);+ comp.setExists(false);+ fill.setValue(234.234).setExists(true);+ Iterator<Double> values1 = Arrays.asList(1423.3, 423.4323, -2349.2, -343.43934, 423.4323).iterator();+ func.streamDoubles( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value, .000001);+ });+ assertFalse(values1.hasNext());++ // Values exist+ val.setValues(1423.3, 423.4323, -2349.2, -343.43934, 423.4323);+ comp.setValue(423.4323).setExists(true);+ fill.setExists(false);+ Iterator<Double> values2 = Arrays.asList(1423.3, -2349.2, -343.43934).iterator();+ func.streamDoubles( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value, .000001);+ });+ assertFalse(values2.hasNext());++ val.setValues(1423.3, 423.4323, -2349.2, -343.43934, 423.4323);+ comp.setValue(423.4323).setExists(true);+ fill.setValue(-1000.0).setExists(true);+ Iterator<Double> values3 = Arrays.asList(1423.3, -1000.0, -2349.2, -343.43934, -1000.0).iterator();+ func.streamDoubles( value -> {+ assertTrue(values3.hasNext());+ assertEquals(values3.next(), value, .000001);+ });+ assertFalse(values3.hasNext());+ }++ @Test+ public void multiValueDateTest() throws DateTimeParseException {+ Date date1 = Date.from(Instant.parse("1810-12-02T10:30:15Z"));+ Date date2 = Date.from(Instant.parse("1931-03-16T18:15:45Z"));+ Date date3 = Date.from(Instant.parse("2023-11-01T20:30:15Z"));++ TestDateValueStream val = new TestDateValueStream();+ TestDateValue comp = new TestDateValue();+ TestDateValue fill = new TestDateValue();++ AnalyticsValueStream uncasted = ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, comp, fill});+ assertTrue(uncasted instanceof DateValueStream);+ DateValueStream func = (DateValueStream) uncasted;++ // No values+ val.setValues();+ comp.setExists(false);+ fill.setExists(false);+ func.streamLongs( value -> {+ assertTrue("There should be no values to stream", false);+ });++ val.setValues();+ comp.setValue("1700-12-14").setExists(true);+ fill.setValue("3450-04-23").setExists(true);+ func.streamLongs( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Comp doesn't exist+ val.setValues("1810-12-02T10:30:15Z", "1931-03-16T18:15:45Z", "2023-11-01T20:30:15Z", "1931-03-16T18:15:45Z");+ comp.setExists(false);+ fill.setValue("1810-12-02T10:30:15Z").setExists(true);+ Iterator<Long> values1 = Arrays.asList(date1.getTime(), date2.getTime(), date3.getTime(), date2.getTime()).iterator();+ func.streamLongs( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next().longValue(), value);+ });+ assertFalse(values1.hasNext());++ // Values exist+ val.setValues("1810-12-02T10:30:15Z", "1931-03-16T18:15:45Z", "2023-11-01T20:30:15Z", "1931-03-16T18:15:45Z");+ comp.setValue("1931-03-16T18:15:45Z").setExists(true);+ fill.setExists(false);+ Iterator<Long> values2 = Arrays.asList(date1.getTime(), date3.getTime()).iterator();+ func.streamLongs( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next().longValue(), value);+ });+ assertFalse(values2.hasNext());++ val.setValues("1810-12-02T10:30:15Z", "1931-03-16T18:15:45Z", "2023-11-01T20:30:15Z", "1931-03-16T18:15:45Z");+ comp.setValue("1931-03-16T18:15:45Z").setExists(true);+ fill.setValue("1810-12-02T10:30:15Z").setExists(true);+ Iterator<Long> values3 = Arrays.asList(date1.getTime(), date1.getTime(), date3.getTime(), date1.getTime()).iterator();+ func.streamLongs( value -> {+ assertTrue(values3.hasNext());+ assertEquals(values3.next().longValue(), value);+ });+ assertFalse(values3.hasNext());+ }++ @Test+ public void multiValueStringTest() {+ TestStringValueStream val = new TestStringValueStream();+ TestStringValue comp = new TestStringValue();+ TestStringValue fill = new TestStringValue();++ AnalyticsValueStream uncasted = ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, comp, fill});+ assertTrue(uncasted instanceof StringValueStream);+ StringValueStream func = (StringValueStream) uncasted;++ // No values+ val.setValues();+ comp.setExists(false);+ fill.setExists(false);+ func.streamStrings( value -> {+ assertTrue("There should be no values to stream", false);+ });++ val.setValues();+ comp.setValue("ads").setExists(true);+ fill.setValue("empty").setExists(true);+ func.streamStrings( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Comp doesn't exist+ val.setValues("abc", "123", "456", "def", "123");+ comp.setExists(false);+ fill.setValue("won't show up").setExists(true);+ Iterator<String> values1 = Arrays.asList("abc", "123", "456", "def", "123").iterator();+ func.streamStrings( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value);+ });+ assertFalse(values1.hasNext());++ // Values exist+ val.setValues("abc", "123", "456", "def", "123");+ comp.setValue("123").setExists(true);+ fill.setExists(false);+ Iterator<String> values2 = Arrays.asList("abc", "456", "def").iterator();+ func.streamStrings( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value);+ });+ assertFalse(values2.hasNext());++ val.setValues("abc", "123", "456", "def", "123");+ comp.setValue("456").setExists(true);+ fill.setValue("changed").setExists(true);+ Iterator<String> values3 = Arrays.asList("abc", "123", "changed", "def", "123").iterator();+ func.streamStrings( value -> {+ assertTrue(values3.hasNext());+ assertEquals(values3.next(), value);+ });+ assertFalse(values3.hasNext());+ }++ @Test+ public void multiValueObjectTest() {+ TestAnalyticsValueStream val = new TestAnalyticsValueStream();+ TestAnalyticsValue comp = new TestAnalyticsValue();+ TestAnalyticsValue fill = new TestAnalyticsValue();++ AnalyticsValueStream func = ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, comp, fill});++ // No values+ val.setValues();+ comp.setExists(false);+ fill.setExists(false);+ func.streamObjects( value -> {+ assertTrue("There should be no values to stream", false);+ });++ val.setValues();+ comp.setValue("doesn't matter").setExists(true);+ fill.setValue("won't show up").setExists(true);+ func.streamObjects( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Comp doesn't exist+ val.setValues("asdfs", new Date(12312), new Long(213123L), new Date(12312));+ comp.setExists(false);+ fill.setValue("won't show up").setExists(true);+ Iterator<Object> values1 = Arrays.<Object>asList("asdfs", new Date(12312), new Long(213123L), new Date(12312)).iterator();+ func.streamObjects( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value);+ });+ assertFalse(values1.hasNext());++ // Values exist+ val.setValues("asdfs", new Date(12312), new Long(213123L), new Date(12312));+ comp.setValue("asdfs").setExists(true);+ fill.setExists(false);+ Iterator<Object> values2 = Arrays.<Object>asList(new Date(12312), new Long(213123L), new Date(12312)).iterator();+ func.streamObjects( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value);+ });+ assertFalse(values2.hasNext());++ val.setValues("asdfs", new Date(12312), new Long(213123L), new Date(12312));+ comp.setValue(new Date(12312)).setExists(true);+ fill.setValue(new Boolean(false)).setExists(true);+ Iterator<Object> values3 = Arrays.<Object>asList("asdfs", new Boolean(false), new Long(213123L), new Boolean(false)).iterator();+ func.streamObjects( value -> {+ assertTrue(values3.hasNext());+ assertEquals(values3.next(), value);+ });+ assertFalse(values3.hasNext());+ }+}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/RoundFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/RoundFunctionTest.javanew file mode 100644index 00000000000..2da48f5b22f--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/RoundFunctionTest.java@@ -0,0 +1,180 @@+/*+ * 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.analytics.function.mapping;++import java.util.Arrays;+import java.util.Iterator;++import org.apache.solr.SolrTestCaseJ4;+import org.apache.solr.analytics.function.mapping.DecimalNumericConversionFunction.RoundFunction;+import org.apache.solr.analytics.value.AnalyticsValueStream;+import org.apache.solr.analytics.value.IntValue;+import org.apache.solr.analytics.value.IntValueStream;+import org.apache.solr.analytics.value.LongValue;+import org.apache.solr.analytics.value.LongValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValue;+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValue;+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestIntValue;+import org.apache.solr.analytics.value.FillableTestValue.TestIntValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestLongValue;+import org.apache.solr.analytics.value.FillableTestValue.TestLongValueStream;+import org.junit.Test;++public class RoundFunctionTest extends SolrTestCaseJ4 {++ @Test+ public void singleValueFloatParameterTest() {+ TestFloatValue val = new TestFloatValue();++ AnalyticsValueStream uncasted = RoundFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});+ assertTrue(uncasted instanceof IntValue);+ IntValue func = (IntValue) uncasted;++ // Value doesn't exist+ val.setExists(false);+ func.getInt();+ assertFalse(func.exists());++ // Value exists+ val.setValue(21.56F).setExists(true);+ assertEquals(22, func.getInt());+ assertTrue(func.exists());++ val.setValue(-100.3F).setExists(true);+ assertEquals(-100, func.getInt());+ assertTrue(func.exists());+ }++ @Test+ public void singleValueDoubleParameterTest() {+ TestDoubleValue val = new TestDoubleValue();++ AnalyticsValueStream uncasted = RoundFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});+ assertTrue(uncasted instanceof LongValue);+ LongValue func = (LongValue) uncasted;++ // Value doesn't exist+ val.setExists(false);+ func.getLong();+ assertFalse(func.exists());++ // Value exists+ val.setValue(21.56).setExists(true);+ assertEquals(22L, func.getLong());+ assertTrue(func.exists());++ val.setValue(-100.3).setExists(true);+ assertEquals(-100L, func.getLong());+ assertTrue(func.exists());+ }++ @Test+ public void multiValueFloatParameterTest() {+ TestFloatValueStream val = new TestFloatValueStream();++ AnalyticsValueStream uncasted = RoundFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});+ assertTrue(uncasted instanceof IntValueStream);+ IntValueStream func = (IntValueStream) uncasted;++ // No values+ val.setValues();+ func.streamInts( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // One value+ val.setValues(-4F);+ Iterator<Integer> values1 = Arrays.asList(-4).iterator();+ func.streamInts( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next().intValue(), value);+ });+ assertFalse(values1.hasNext());++ // Multiple values+ val.setValues(4F, -10.9999F, 50.00001F, 74.99999F, 101.4999F, 105.5F);+ Iterator<Integer> values2 = Arrays.asList(4, -11, 50, 75, 101, 106).iterator();+ func.streamInts( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next().intValue(), value);+ });+ assertFalse(values2.hasNext());+ }++ @Test+ public void multiValueDoubleParameterTest() {+ TestDoubleValueStream val = new TestDoubleValueStream();++ AnalyticsValueStream uncasted = RoundFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});+ assertTrue(uncasted instanceof LongValueStream);+ LongValueStream func = (LongValueStream) uncasted;++ // No values+ val.setValues();+ func.streamLongs( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // One value+ val.setValues(-4);+ Iterator<Long> values1 = Arrays.asList(-4L).iterator();+ func.streamLongs( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next().longValue(), value);+ });+ assertFalse(values1.hasNext());++ // Multiple values+ val.setValues(4, -10.9999, 50.000001, 74.99999, 101.4999, 105.5);+ Iterator<Long> values2 = Arrays.asList(4L, -11L, 50L, 75L, 101L, 106L).iterator();+ func.streamLongs( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next().longValue(), value);+ });+ assertFalse(values2.hasNext());+ }++ @Test+ public void nonDecimalParameterTest() {+ AnalyticsValueStream result;+ AnalyticsValueStream param;++ param = new TestIntValue();+ result = RoundFunction.creatorFunction.apply(new AnalyticsValueStream[] {param});+ assertTrue(result instanceof IntValue);+ assertEquals(param, result);++ param = new TestIntValueStream();+ result = RoundFunction.creatorFunction.apply(new AnalyticsValueStream[] {param});+ assertTrue(result instanceof IntValueStream);+ assertEquals(param, result);++ param = new TestLongValue();+ result = RoundFunction.creatorFunction.apply(new AnalyticsValueStream[] {param});+ assertTrue(result instanceof LongValue);+ assertEquals(param, result);++ param = new TestLongValueStream();+ result = RoundFunction.creatorFunction.apply(new AnalyticsValueStream[] {param});+ assertTrue(result instanceof LongValueStream);+ assertEquals(param, result);+ }+++}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/StringCastFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/StringCastFunctionTest.javanew file mode 100644index 00000000000..79ef86aa74b--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/StringCastFunctionTest.java@@ -0,0 +1,87 @@+/*+ * 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.analytics.function.mapping;++import java.util.Arrays;+import java.util.Iterator;++import org.apache.solr.SolrTestCaseJ4;+import org.apache.solr.analytics.value.AnalyticsValueStream;+import org.apache.solr.analytics.value.StringValue;+import org.apache.solr.analytics.value.StringValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestBooleanValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestIntValue;+import org.junit.Test;++public class StringCastFunctionTest extends SolrTestCaseJ4 {++ @Test+ public void singleValueParameterTest() {+ TestIntValue val = new TestIntValue();++ AnalyticsValueStream uncasted = StringCastFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});+ assertTrue(uncasted instanceof StringValue);+ StringValue func = (StringValue) uncasted;++ // Value doesn't exist+ val.setExists(false);+ func.getObject();+ assertFalse(func.exists());++ // Value exists+ val.setValue(21).setExists(true);+ assertEquals("21", func.getObject());+ assertTrue(func.exists());++ val.setValue(-100).setExists(true);+ assertEquals("-100", func.getObject());+ assertTrue(func.exists());+ }++ @Test+ public void multiValueParameterTest() {+ TestBooleanValueStream val = new TestBooleanValueStream();++ AnalyticsValueStream uncasted = StringCastFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});+ assertTrue(uncasted instanceof StringValueStream);+ StringValueStream func = (StringValueStream) uncasted;++ // No values+ val.setValues();+ func.streamStrings( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // One value+ val.setValues(true);+ Iterator<String> values1 = Arrays.asList("true").iterator();+ func.streamObjects( value -> {+ assertTrue(values1.hasNext());+ assertEquals(values1.next(), value);+ });+ assertFalse(values1.hasNext());++ // Multiple values+ val.setValues(true, true, false, false);+ Iterator<String> values2 = Arrays.asList("true", "true", "false", "false").iterator();+ func.streamObjects( value -> {+ assertTrue(values2.hasNext());+ assertEquals(values2.next(), value);+ });+ assertFalse(values2.hasNext());+ }+}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/SubtractFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/SubtractFunctionTest.javanew file mode 100644index 00000000000..1095bba3701--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/SubtractFunctionTest.java@@ -0,0 +1,128 @@+/*+ * 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.analytics.function.mapping;++import java.util.Arrays;+import java.util.Iterator;++import org.apache.solr.SolrTestCaseJ4;+import org.apache.solr.analytics.value.AnalyticsValueStream;+import org.apache.solr.analytics.value.DoubleValue;+import org.apache.solr.analytics.value.DoubleValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValue;+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValue;+import org.apache.solr.analytics.value.FillableTestValue.TestIntValue;+import org.apache.solr.analytics.value.FillableTestValue.TestLongValueStream;+import org.junit.Test;++public class SubtractFunctionTest extends SolrTestCaseJ4 {+ @Test+ public void twoSingleValueParametersTest() {+ TestIntValue minuend = new TestIntValue();+ TestFloatValue subtrahend = new TestFloatValue();++ AnalyticsValueStream uncasted = SubtractFunction.creatorFunction.apply(new AnalyticsValueStream[] {minuend, subtrahend});+ assertTrue(uncasted instanceof DoubleValue);+ DoubleValue func = (DoubleValue) uncasted;++ // Neither exists+ minuend.setExists(false);+ subtrahend.setExists(false);+ func.getDouble();+ assertFalse(func.exists());++ // One exists+ minuend.setValue(30).setExists(true);+ subtrahend.setExists(false);+ func.getDouble();+ assertFalse(func.exists());++ // Both exist+ minuend.setValue(60).setExists(true);+ subtrahend.setValue(23.56F).setExists(true);+ assertEquals(36.44, func.getDouble(), 0.00001);+ assertTrue(func.exists());+ }++ @Test+ public void oneMultiOneSingleValueParameterTest() {+ TestLongValueStream minuend = new TestLongValueStream();+ TestDoubleValue subtrahend = new TestDoubleValue();++ AnalyticsValueStream uncasted = SubtractFunction.creatorFunction.apply(new AnalyticsValueStream[] {minuend, subtrahend});+ assertTrue(uncasted instanceof DoubleValueStream);+ DoubleValueStream func = (DoubleValueStream) uncasted;++ // No values, One value+ minuend.setValues();+ subtrahend.setValue(21.56F).setExists(true);+ func.streamDoubles( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple values, no value+ minuend.setValues(4L, 10023L);+ subtrahend.setExists(false);+ func.streamDoubles( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple values, one value+ minuend.setValues(20L, 5L, 234L);+ subtrahend.setValue(44.56F).setExists(true);+ Iterator<Double> values = Arrays.asList(-24.56, -39.56, 189.44).iterator();+ func.streamDoubles( value -> {+ assertTrue(values.hasNext());+ assertEquals(values.next(), value, 0.00001);+ });+ assertFalse(values.hasNext());+ }++ @Test+ public void oneSingleOneMultiValueParameterTest() {+ TestDoubleValue minuend = new TestDoubleValue();+ TestLongValueStream subtrahend = new TestLongValueStream();++ AnalyticsValueStream uncasted = SubtractFunction.creatorFunction.apply(new AnalyticsValueStream[] {minuend, subtrahend});+ assertTrue(uncasted instanceof DoubleValueStream);+ DoubleValueStream func = (DoubleValueStream) uncasted;++ // No values, One value+ minuend.setValue(21.56F).setExists(true);+ subtrahend.setValues();+ func.streamDoubles( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple values, no value+ minuend.setExists(false);+ subtrahend.setValues(4L, 10023L);+ func.streamDoubles( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple values, one value+ minuend.setValue(44.56F).setExists(true);+ subtrahend.setValues(20L, 5L, 234L);+ Iterator<Double> values = Arrays.asList(24.56, 39.56, -189.44).iterator();+ func.streamDoubles( value -> {+ assertTrue(values.hasNext());+ assertEquals(values.next(), value, 0.00001);+ });+ assertFalse(values.hasNext());+ }+}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/TopFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/TopFunctionTest.javanew file mode 100644index 00000000000..419f883445c--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/TopFunctionTest.java@@ -0,0 +1,406 @@+/*+ * 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.analytics.function.mapping;++import java.time.Instant;+import java.time.format.DateTimeParseException;+import java.util.Date;++import org.apache.solr.SolrTestCaseJ4;+import org.apache.solr.analytics.value.AnalyticsValueStream;+import org.apache.solr.analytics.value.DateValue;+import org.apache.solr.analytics.value.DoubleValue;+import org.apache.solr.analytics.value.FillableTestValue.TestDateValue;+import org.apache.solr.analytics.value.FillableTestValue.TestDateValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValue;+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValue;+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestIntValue;+import org.apache.solr.analytics.value.FillableTestValue.TestIntValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestLongValue;+import org.apache.solr.analytics.value.FillableTestValue.TestLongValueStream;+import org.apache.solr.analytics.value.FillableTestValue.TestStringValue;+import org.apache.solr.analytics.value.FillableTestValue.TestStringValueStream;+import org.apache.solr.analytics.value.FloatValue;+import org.apache.solr.analytics.value.IntValue;+import org.apache.solr.analytics.value.LongValue;+import org.apache.solr.analytics.value.StringValue;+import org.junit.Test;++public class TopFunctionTest extends SolrTestCaseJ4 {++ @Test+ public void multiValueIntTest() {+ TestIntValueStream val = new TestIntValueStream();++ AnalyticsValueStream uncasted = TopFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});+ assertTrue(uncasted instanceof IntValue);+ IntValue func = (IntValue) uncasted;++ // Neither exists+ val.setValues();+ func.getInt();+ assertFalse(func.exists());++ // One exists+ val.setValues(30);+ assertEquals(30, func.getInt());+ assertTrue(func.exists());++ // Both exist+ val.setValues(30, 20, -10, 59);+ assertEquals(59, func.getInt());+ assertTrue(func.exists());+ }++ @Test+ public void multiValueLongTest() {+ TestLongValueStream val = new TestLongValueStream();++ AnalyticsValueStream uncasted = TopFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});+ assertTrue(uncasted instanceof LongValue);+ LongValue func = (LongValue) uncasted;++ // Neither exists+ val.setValues();+ func.getLong();+ assertFalse(func.exists());++ // One exists+ val.setValues(30L);+ assertEquals(30L, func.getLong());+ assertTrue(func.exists());++ // Both exist+ val.setValues(30L, 20L, -10L, 59L);+ assertEquals(59L, func.getLong());+ assertTrue(func.exists());+ }++ @Test+ public void multiValueFloatTest() {+ TestFloatValueStream val = new TestFloatValueStream();++ AnalyticsValueStream uncasted = TopFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});+ assertTrue(uncasted instanceof FloatValue);+ FloatValue func = (FloatValue) uncasted;++ // Neither exists+ val.setValues();+ func.getFloat();+ assertFalse(func.exists());++ // One exists+ val.setValues(30.0F);+ assertEquals(30.0F, func.getFloat(), .000001);+ assertTrue(func.exists());++ // Both exist+ val.setValues(30.5F, 20.01F, -10.49F, -10.48F);+ assertEquals(30.5F, func.getFloat(), .000001);+ assertTrue(func.exists());+ }++ @Test+ public void multiValueDoubleTest() {+ TestDoubleValueStream val = new TestDoubleValueStream();++ AnalyticsValueStream uncasted = TopFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});+ assertTrue(uncasted instanceof DoubleValue);+ DoubleValue func = (DoubleValue) uncasted;++ // Neither exists+ val.setValues();+ func.getDouble();+ assertFalse(func.exists());++ // One exists+ val.setValues(30.0);+ assertEquals(30.0, func.getDouble(), .000001);+ assertTrue(func.exists());++ // Both exist+ val.setValues(30.5, 20.01, -10.49, -10.48);+ assertEquals(30.5, func.getDouble(), .000001);+ assertTrue(func.exists());+ }++ @Test+ public void multiValueDateTest() throws DateTimeParseException {+ TestDateValueStream val = new TestDateValueStream();++ AnalyticsValueStream uncasted = TopFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});+ assertTrue(uncasted instanceof DateValue);+ DateValue func = (DateValue) uncasted;++ // Neither exists+ val.setValues();+ func.getDate();+ assertFalse(func.exists());++ // One exists+ val.setValues("1950-05-03T10:30:50Z");+ assertEquals(Date.from(Instant.parse("1950-05-03T10:30:50Z")), func.getDate());+ assertTrue(func.exists());++ // Both exist+ val.setValues("1950-05-03T10:30:50Z", "2200-01-01T10:00:50Z", "1800-12-31T11:30:50Z", "1930-05-020T10:45:50Z");+ assertEquals(Date.from(Instant.parse("2200-01-01T10:00:50Z")), func.getDate());+ assertTrue(func.exists());+ }++ @Test+ public void multiValueStringTest() {+ TestStringValueStream val = new TestStringValueStream();++ AnalyticsValueStream uncasted = TopFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});+ assertTrue(uncasted instanceof StringValue);+ StringValue func = (StringValue) uncasted;++ // Neither exists+ val.setValues();+ func.getString();+ assertFalse(func.exists());++ // One exists+ val.setValues("abc");+ assertEquals("abc", func.getString());+ assertTrue(func.exists());++ // Both exist+ val.setValues("1abcdef", "abc", "def", "def1", "1abc");+ assertEquals("def1", func.getString());+ assertTrue(func.exists());+ }++ @Test+ public void multipleSingleValueIntTest() {+ TestIntValue val1 = new TestIntValue();+ TestIntValue val2 = new TestIntValue();+ TestIntValue val3 = new TestIntValue();+ TestIntValue val4 = new TestIntValue();++ AnalyticsValueStream uncasted = TopFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2, val3, val4});+ assertTrue(uncasted instanceof IntValue);+ IntValue func = (IntValue) uncasted;++ // None exist+ val1.setExists(false);+ val2.setExists(false);+ val3.setExists(false);+ val4.setExists(false);+ func.getInt();+ assertFalse(func.exists());++ // Some exist+ val1.setValue(1000).setExists(false);+ val2.setValue(30).setExists(true);+ val3.setValue(-1000).setExists(false);+ val4.setValue(12).setExists(true);+ assertEquals(30, func.getInt());+ assertTrue(func.exists());++ // All exist values, one value+ val1.setValue(45).setExists(true);+ val2.setValue(30).setExists(true);+ val3.setValue(-2).setExists(true);+ val4.setValue(12).setExists(true);+ assertEquals(45, func.getInt());+ assertTrue(func.exists());+ }++ @Test+ public void multipleSingleValueLongTest() {+ TestLongValue val1 = new TestLongValue();+ TestLongValue val2 = new TestLongValue();+ TestLongValue val3 = new TestLongValue();+ TestLongValue val4 = new TestLongValue();++ AnalyticsValueStream uncasted = TopFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2, val3, val4});+ assertTrue(uncasted instanceof LongValue);+ LongValue func = (LongValue) uncasted;++ // None exist+ val1.setExists(false);+ val2.setExists(false);+ val3.setExists(false);+ val4.setExists(false);+ func.getLong();+ assertFalse(func.exists());++ // Some exist+ val1.setValue(1000L).setExists(false);+ val2.setValue(30L).setExists(true);+ val3.setValue(-1000L).setExists(false);+ val4.setValue(12L).setExists(true);+ assertEquals(30L, func.getLong());+ assertTrue(func.exists());++ // All exist values, one value+ val1.setValue(45L).setExists(true);+ val2.setValue(30L).setExists(true);+ val3.setValue(-2L).setExists(true);+ val4.setValue(12L).setExists(true);+ assertEquals(45L, func.getLong());+ assertTrue(func.exists());+ }++ @Test+ public void multipleSingleValueFloatTest() {+ TestFloatValue val1 = new TestFloatValue();+ TestFloatValue val2 = new TestFloatValue();+ TestFloatValue val3 = new TestFloatValue();+ TestFloatValue val4 = new TestFloatValue();++ AnalyticsValueStream uncasted = TopFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2, val3, val4});+ assertTrue(uncasted instanceof FloatValue);+ FloatValue func = (FloatValue) uncasted;++ // None exist+ val1.setExists(false);+ val2.setExists(false);+ val3.setExists(false);+ val4.setExists(false);+ func.getFloat();+ assertFalse(func.exists());++ // Some exist+ val1.setValue(1000.1233F).setExists(false);+ val2.setValue(30.34F).setExists(true);+ val3.setValue(-1000.3241F).setExists(false);+ val4.setValue(12.123F).setExists(true);+ assertEquals(30.34F, func.getFloat(), .000001);+ assertTrue(func.exists());++ // All exist values, one value+ val1.setValue(45.43F).setExists(true);+ val2.setValue(30.231F).setExists(true);+ val3.setValue(-2.33F).setExists(true);+ val4.setValue(12.5F).setExists(true);+ assertEquals(45.43F, func.getFloat(), .000001);+ assertTrue(func.exists());+ }++ @Test+ public void multipleSingleValueDoubleTest() {+ TestDoubleValue val1 = new TestDoubleValue();+ TestDoubleValue val2 = new TestDoubleValue();+ TestDoubleValue val3 = new TestDoubleValue();+ TestDoubleValue val4 = new TestDoubleValue();++ AnalyticsValueStream uncasted = TopFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2, val3, val4});+ assertTrue(uncasted instanceof DoubleValue);+ DoubleValue func = (DoubleValue) uncasted;++ // None exist+ val1.setExists(false);+ val2.setExists(false);+ val3.setExists(false);+ val4.setExists(false);+ func.getDouble();+ assertFalse(func.exists());++ // Some exist+ val1.setValue(1000.1233).setExists(false);+ val2.setValue(30.34).setExists(true);+ val3.setValue(-1000.3241).setExists(false);+ val4.setValue(12.123).setExists(true);+ assertEquals(30.34, func.getDouble(), .000001);+ assertTrue(func.exists());++ // All exist values, one value+ val1.setValue(45.43).setExists(true);+ val2.setValue(30.231).setExists(true);+ val3.setValue(-2.33).setExists(true);+ val4.setValue(12.5).setExists(true);+ assertEquals(45.43, func.getDouble(), .000001);+ assertTrue(func.exists());+ }++ @Test+ public void multipleSingleValueDateTest() throws DateTimeParseException {+ TestDateValue val1 = new TestDateValue();+ TestDateValue val2 = new TestDateValue();+ TestDateValue val3 = new TestDateValue();+ TestDateValue val4 = new TestDateValue();++ AnalyticsValueStream uncasted = TopFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2, val3, val4});+ assertTrue(uncasted instanceof DateValue);+ DateValue func = (DateValue) uncasted;++ // None exist+ val1.setExists(false);+ val2.setExists(false);+ val3.setExists(false);+ val4.setExists(false);+ func.getDate();+ assertFalse(func.exists());++ // Some exist+ val1.setValue("9999-05-03T10:30:50Z").setExists(false);+ val2.setValue("1950-05-03T10:30:50Z").setExists(true);+ val3.setValue("0000-05-03T10:30:50Z").setExists(false);+ val4.setValue("1850-05-03T10:30:50Z").setExists(true);+ assertEquals(Date.from(Instant.parse("1950-05-03T10:30:50Z")), func.getDate());+ assertTrue(func.exists());++ // All exist values, one value+ val1.setValue("2200-05-03T10:30:50Z").setExists(true);+ val2.setValue("1950-05-03T10:30:50Z").setExists(true);+ val3.setValue("1700-05-03T10:30:50Z").setExists(true);+ val4.setValue("1850-05-03T10:30:50Z").setExists(true);+ assertEquals(Date.from(Instant.parse("2200-05-03T10:30:50Z")), func.getDate());+ assertTrue(func.exists());+ }++ @Test+ public void multipleStringValueDateTest() {+ TestStringValue val1 = new TestStringValue();+ TestStringValue val2 = new TestStringValue();+ TestStringValue val3 = new TestStringValue();+ TestStringValue val4 = new TestStringValue();++ AnalyticsValueStream uncasted = TopFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2, val3, val4});+ assertTrue(uncasted instanceof StringValue);+ StringValue func = (StringValue) uncasted;++ // None exist+ val1.setExists(false);+ val2.setExists(false);+ val3.setExists(false);+ val4.setExists(false);+ func.getString();+ assertFalse(func.exists());++ // Some exist+ val1.setValue("abc").setExists(true);+ val2.setValue("1111").setExists(false);+ val3.setValue("asdfads").setExists(true);+ val4.setValue("zzzzzzzz").setExists(false);+ assertEquals("asdfads", func.getString());+ assertTrue(func.exists());++ // All exist values, one value+ val1.setValue("abc").setExists(true);+ val2.setValue("abc1234").setExists(true);+ val3.setValue("fdgsfg1").setExists(true);+ val4.setValue("fdgsfg").setExists(true);+ assertEquals("fdgsfg1", func.getString());+ assertTrue(func.exists());+ }+}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/AbstractAnalyticsStatsCloudTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/LegacyAbstractAnalyticsCloudTest.javasimilarity index 86%rename from solr/contrib/analytics/src/test/org/apache/solr/analytics/AbstractAnalyticsStatsCloudTest.javarename to solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/LegacyAbstractAnalyticsCloudTest.javaindex 59ebbcb3c55..f34c6674700 100644--- a/solr/contrib/analytics/src/test/org/apache/solr/analytics/AbstractAnalyticsStatsCloudTest.java+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/LegacyAbstractAnalyticsCloudTest.java@@ -14,12 +14,11 @@* See the License for the specific language governing permissions and* limitations under the License.*/-package org.apache.solr.analytics;+package org.apache.solr.analytics.legacy;import java.io.IOException;import java.util.ArrayList;import java.util.Collections;-import java.util.HashMap;import java.util.HashSet;import org.apache.solr.analytics.util.AnalyticsResponseHeadings;@@ -34,40 +33,16 @@ import org.apache.solr.cloud.AbstractDistribZkTestBase;import org.apache.solr.cloud.SolrCloudTestCase;import org.apache.solr.common.params.ModifiableSolrParams;import org.apache.solr.common.util.NamedList;-import org.junit.AfterClass;+import org.junit.BeforeClass;-public class AbstractAnalyticsStatsCloudTest extends SolrCloudTestCase {+public class LegacyAbstractAnalyticsCloudTest extends SolrCloudTestCase {- protected static final String[] BASEPARMS = new String[]{ "q", "*:*", "indent", "true", "olap", "true", "rows", "0" };- protected static final HashMap<String,Object> defaults = new HashMap<>();-- public static enum VAL_TYPE {- INTEGER("int"),- LONG("long"),- FLOAT("float"),- DOUBLE("double"),- STRING("str"),- DATE("date");-- private VAL_TYPE (final String text) {- this.text = text;- }-- private final String text;-- @Override- public String toString() {- return text;- }- }---protected static final String COLLECTIONORALIAS = "collection1";protected static final int TIMEOUT = DEFAULT_TIMEOUT;protected static final String id = "id";- public static void setupCluster() throws Exception {+ @BeforeClass+ public static void setupCollection() throws Exception {configureCluster(4).addConfig("conf", configset("cloud-analytics")).configure();@@ -84,19 +59,36 @@ public class AbstractAnalyticsStatsCloudTest extends SolrCloudTestCase {.commit(cluster.getSolrClient(), COLLECTIONORALIAS);}- @AfterClass- public static void afterClassAbstractAnalysis() {- defaults.clear();+ protected static final String[] BASEPARMS = new String[]{ "q", "*:*", "indent", "true", "olap", "true", "rows", "0" };++ public static enum VAL_TYPE {+ INTEGER("int"),+ LONG("long"),+ FLOAT("float"),+ DOUBLE("double"),+ STRING("str"),+ DATE("date");++ private VAL_TYPE (final String text) {+ this.text = text;+ }++ private final String text;++ @Override+ public String toString() {+ return text;+ }}- protected NamedList<Object> queryCloudAnalytics(String[] testParams) throws SolrServerException, IOException, InterruptedException {+ protected NamedList<Object> queryLegacyCloudAnalytics(String[] testParams) throws SolrServerException, IOException, InterruptedException {ModifiableSolrParams params = new ModifiableSolrParams();params.set("q", "*:*");params.set("indent", "true");params.set("olap", "true");params.set("rows", "0");for (int i = 0; i + 1 < testParams.length;) {- params.set(testParams[i++], testParams[i++]);+ params.add(testParams[i++], testParams[i++]);}cluster.waitForAllNodes(10000);QueryRequest qreq = new QueryRequest(params);@@ -172,16 +164,4 @@ public class AbstractAnalyticsStatsCloudTest extends SolrCloudTestCase {}return result;}-- @SuppressWarnings("unchecked")- public <T extends Comparable<T>> Long calculateMissing(ArrayList<T> list, String type) {- T def = (T)defaults.get(type);- long miss = 0;- for (T element : list) {- if (element.compareTo(def)==0) {- miss++;- }- }- return Long.valueOf(miss);- }}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/AbstractAnalyticsStatsTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/LegacyAbstractAnalyticsTest.javasimilarity index 97%rename from solr/contrib/analytics/src/test/org/apache/solr/analytics/AbstractAnalyticsStatsTest.javarename to solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/LegacyAbstractAnalyticsTest.javaindex 18f51a9c821..3488f63db7d 100644--- a/solr/contrib/analytics/src/test/org/apache/solr/analytics/AbstractAnalyticsStatsTest.java+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/LegacyAbstractAnalyticsTest.java@@ -14,7 +14,7 @@* See the License for the specific language governing permissions and* limitations under the License.*/-package org.apache.solr.analytics;+package org.apache.solr.analytics.legacy;import java.io.ByteArrayInputStream;import java.io.FileNotFoundException;@@ -49,8 +49,7 @@ import org.xml.sax.SAXException;import com.google.common.collect.ObjectArrays;[email protected](bugUrl="https://issues.apache.org/jira/browse/SOLR-10949")-public class AbstractAnalyticsStatsTest extends SolrTestCaseJ4 {+public class LegacyAbstractAnalyticsTest extends SolrTestCaseJ4 {protected static final String[] BASEPARMS = new String[]{ "q", "*:*", "indent", "true", "olap", "true", "rows", "0" };protected static final HashMap<String,Object> defaults = new HashMap<>();@@ -211,7 +210,7 @@ public class AbstractAnalyticsStatsTest extends SolrTestCaseJ4 {}public static String[] fileToStringArr(Class<?> clazz, String fileName) throws FileNotFoundException {- InputStream in = clazz.getResourceAsStream("/solr/analytics/" + fileName);+ InputStream in = clazz.getResourceAsStream("/solr/analytics/legacy/" + fileName);if (in == null) throw new FileNotFoundException("Resource not found: " + fileName);Scanner file = new Scanner(in, "UTF-8");try {diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/NoFacetCloudTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/LegacyNoFacetCloudTest.javasimilarity index 94%rename from solr/contrib/analytics/src/test/org/apache/solr/analytics/NoFacetCloudTest.javarename to solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/LegacyNoFacetCloudTest.javaindex 71503affbbd..7489f3f977b 100644--- a/solr/contrib/analytics/src/test/org/apache/solr/analytics/NoFacetCloudTest.java+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/LegacyNoFacetCloudTest.java@@ -14,7 +14,7 @@* See the License for the specific language governing permissions and* limitations under the License.*/-package org.apache.solr.analytics;+package org.apache.solr.analytics.legacy;import java.util.ArrayList;import java.util.List;@@ -24,7 +24,7 @@ import org.apache.solr.common.util.NamedList;import org.junit.BeforeClass;import org.junit.Test;-public class NoFacetCloudTest extends AbstractAnalyticsStatsCloudTest {+public class LegacyNoFacetCloudTest extends LegacyAbstractAnalyticsCloudTest {static public final int INT = 71;static public final int LONG = 36;static public final int FLOAT = 93;@@ -59,13 +59,7 @@ public class NoFacetCloudTest extends AbstractAnalyticsStatsCloudTest {@BeforeClasspublic static void populate() throws Exception {- setupCluster();- defaults.put("int_id", new Integer(0));- defaults.put("long_ld", new Long(0));- defaults.put("float_fd", new Float(0));- defaults.put("double_dd", new Double(0));- defaults.put("date_dtd", "1800-12-31T23:59:59Z");- defaults.put("string_sd", "str0");+ cleanIndex();intTestStart = new ArrayList<>();longTestStart = new ArrayList<>();@@ -128,7 +122,7 @@ public class NoFacetCloudTest extends AbstractAnalyticsStatsCloudTest {"o.sr.s.float_fd", "sum(float_fd)","o.sr.s.double_dd", "sum(double_dd)"};- NamedList<Object> response = queryCloudAnalytics(params);+ NamedList<Object> response = queryLegacyCloudAnalytics(params);String responseStr = response.toString();//Int@@ -160,7 +154,7 @@ public class NoFacetCloudTest extends AbstractAnalyticsStatsCloudTest {"o.mr.s.float_fd", "mean(float_fd)","o.mr.s.double_dd", "mean(double_dd)"};- NamedList<Object> response = queryCloudAnalytics(params);+ NamedList<Object> response = queryLegacyCloudAnalytics(params);String responseStr = response.toString();//Int@@ -192,7 +186,7 @@ public class NoFacetCloudTest extends AbstractAnalyticsStatsCloudTest {"o.str.s.float_fd", "stddev(float_fd)","o.str.s.double_dd", "stddev(double_dd)"};- NamedList<Object> response = queryCloudAnalytics(params);+ NamedList<Object> response = queryLegacyCloudAnalytics(params);String responseStr = response.toString();//Int@@ -226,7 +220,7 @@ public class NoFacetCloudTest extends AbstractAnalyticsStatsCloudTest {"o.medr.s.double_dd", "median(double_dd)","o.medr.s.date_dtd", "median(date_dtd)"};- NamedList<Object> response = queryCloudAnalytics(params);+ NamedList<Object> response = queryLegacyCloudAnalytics(params);String responseStr = response.toString();//Int@@ -262,7 +256,7 @@ public class NoFacetCloudTest extends AbstractAnalyticsStatsCloudTest {"o.p2r.s.date_dtd", "string(percentile(20,date_dtd))","o.p2r.s.string_sd", "percentile(20,string_sd)"};- NamedList<Object> response = queryCloudAnalytics(params);+ NamedList<Object> response = queryLegacyCloudAnalytics(params);String responseStr = response.toString();//Int 20@@ -306,7 +300,7 @@ public class NoFacetCloudTest extends AbstractAnalyticsStatsCloudTest {"o.p6r.s.date_dtd", "string(percentile(60,date_dtd))","o.p6r.s.string_sd", "percentile(60,string_sd)"};- NamedList<Object> response = queryCloudAnalytics(params);+ NamedList<Object> response = queryLegacyCloudAnalytics(params);String responseStr = response.toString();//Int 60@@ -350,7 +344,7 @@ public class NoFacetCloudTest extends AbstractAnalyticsStatsCloudTest {"o.mir.s.date_dtd", "string(min(date_dtd))","o.mir.s.string_sd", "min(string_sd)"};- NamedList<Object> response = queryCloudAnalytics(params);+ NamedList<Object> response = queryLegacyCloudAnalytics(params);String responseStr = response.toString();//Int@@ -394,7 +388,7 @@ public class NoFacetCloudTest extends AbstractAnalyticsStatsCloudTest {"o.mar.s.date_dtd", "string(max(date_dtd))","o.mar.s.string_sd", "max(string_sd)"};- NamedList<Object> response = queryCloudAnalytics(params);+ NamedList<Object> response = queryLegacyCloudAnalytics(params);String responseStr = response.toString();//Int@@ -438,7 +432,7 @@ public class NoFacetCloudTest extends AbstractAnalyticsStatsCloudTest {"o.ur.s.date_dtd", "unique(date_dtd)","o.ur.s.string_sd", "unique(string_sd)"};- NamedList<Object> response = queryCloudAnalytics(params);+ NamedList<Object> response = queryLegacyCloudAnalytics(params);String responseStr = response.toString();//Int@@ -482,7 +476,7 @@ public class NoFacetCloudTest extends AbstractAnalyticsStatsCloudTest {"o.cr.s.date_dtd", "count(date_dtd)","o.cr.s.string_sd", "count(string_sd)"};- NamedList<Object> response = queryCloudAnalytics(params);+ NamedList<Object> response = queryLegacyCloudAnalytics(params);String responseStr = response.toString();//Int@@ -526,7 +520,7 @@ public class NoFacetCloudTest extends AbstractAnalyticsStatsCloudTest {"o.misr.s.date_dtd", "missing(date_dtd)","o.misr.s.string_sd", "missing(string_sd)"};- NamedList<Object> response = queryCloudAnalytics(params);+ NamedList<Object> response = queryLegacyCloudAnalytics(params);String responseStr = response.toString();//Intdiff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/LegacyNoFacetTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/LegacyNoFacetTest.javanew file mode 100644index 00000000000..4fb573da551--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/LegacyNoFacetTest.java@@ -0,0 +1,450 @@+/*+ * 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.analytics.legacy;++import java.util.ArrayList;+import java.util.List;++import org.junit.BeforeClass;+import org.junit.Test;++public class LegacyNoFacetTest extends LegacyAbstractAnalyticsTest {+ static String fileName = "noFacets.txt";++ static public final int INT = 71;+ static public final int LONG = 36;+ static public final int FLOAT = 93;+ static public final int DOUBLE = 49;+ static public final int DATE = 12;+ static public final int STRING = 28;+ static public final int NUM_LOOPS = 100;++ //INT+ static ArrayList<Integer> intTestStart;+ static long intMissing = 0;++ //LONG+ static ArrayList<Long> longTestStart;+ static long longMissing = 0;++ //FLOAT+ static ArrayList<Float> floatTestStart;+ static long floatMissing = 0;++ //DOUBLE+ static ArrayList<Double> doubleTestStart;+ static long doubleMissing = 0;++ //DATE+ static ArrayList<String> dateTestStart;+ static long dateMissing = 0;++ //STR+ static ArrayList<String> stringTestStart;+ static long stringMissing = 0;++ @BeforeClass+ public static void beforeClass() throws Exception {+ initCore("solrconfig-analytics.xml","schema-analytics.xml");+ h.update("<delete><query>*:*</query></delete>");+ defaults.put("int_id", new Integer(0));+ defaults.put("long_ld", new Long(0));+ defaults.put("float_fd", new Float(0));+ defaults.put("double_dd", new Double(0));+ defaults.put("date_dtd", "1800-12-31T23:59:59Z");+ defaults.put("string_sd", "str0");++ intTestStart = new ArrayList<>();+ longTestStart = new ArrayList<>();+ floatTestStart = new ArrayList<>();+ doubleTestStart = new ArrayList<>();+ dateTestStart = new ArrayList<>();+ stringTestStart = new ArrayList<>();++ for (int j = 0; j < NUM_LOOPS; ++j) {+ int i = j%INT;+ long l = j%LONG;+ float f = j%FLOAT;+ double d = j%DOUBLE;+ String dt = (1800+j%DATE) + "-12-31T23:59:59Z";+ String s = "str" + (j%STRING);+ List<String> fields = new ArrayList<>();+ fields.add("id"); fields.add("1000"+j);++ if( i != 0 ){+ fields.add("int_id"); fields.add("" + i);+ intTestStart.add(i);+ } else intMissing++;++ if( l != 0l ){+ fields.add("long_ld"); fields.add("" + l);+ longTestStart.add(l);+ } else longMissing++;++ if( f != 0.0f ){+ fields.add("float_fd"); fields.add("" + f);+ floatTestStart.add(f);+ } else floatMissing++;++ if( d != 0.0d ){+ fields.add("double_dd"); fields.add("" + d);+ doubleTestStart.add(d);+ } else doubleMissing++;++ if( (j%DATE) != 0 ){+ fields.add("date_dtd"); fields.add(dt);+ dateTestStart.add(dt);+ } else dateMissing++;++ if( (j%STRING) != 0 ){+ fields.add("string_sd"); fields.add(s);+ stringTestStart.add(s);+ } else stringMissing++;++ assertU(adoc(fields.toArray(new String[0])));+++ if (usually()) {+ assertU(commit()); // to have several segments+ }+ }++ assertU(commit());++ //Sort ascending tests+ setResponse(h.query(request(fileToStringArr(LegacyNoFacetTest.class, fileName))));+ }++ @Test+ public void sumTest() throws Exception {+ //Int+ Double intResult = (Double)getStatResult("sr", "int_id", VAL_TYPE.DOUBLE);+ Double intTest = (Double)calculateNumberStat(intTestStart, "sum");+ assertEquals(getRawResponse(), intResult,intTest);++ //Long+ Double longResult = (Double)getStatResult("sr", "long_ld", VAL_TYPE.DOUBLE);+ Double longTest = (Double)calculateNumberStat(longTestStart, "sum");+ assertEquals(getRawResponse(), longResult,longTest);++ //Float+ Double floatResult = (Double)getStatResult("sr", "float_fd", VAL_TYPE.DOUBLE);+ Double floatTest = (Double)calculateNumberStat(floatTestStart, "sum");+ assertEquals(getRawResponse(), floatResult,floatTest);++ //Double+ Double doubleResult = (Double)getStatResult("sr", "double_dd", VAL_TYPE.DOUBLE);+ Double doubleTest = (Double) calculateNumberStat(doubleTestStart, "sum");+ assertEquals(getRawResponse(), doubleResult,doubleTest);+ }++ @Test+ public void meanTest() throws Exception {+ //Int+ Double intResult = (Double)getStatResult("mr", "int_id", VAL_TYPE.DOUBLE);+ Double intTest = (Double)calculateNumberStat(intTestStart, "mean");+ assertEquals(getRawResponse(), intResult,intTest);++ //Long+ Double longResult = (Double)getStatResult("mr", "long_ld", VAL_TYPE.DOUBLE);+ Double longTest = (Double)calculateNumberStat(longTestStart, "mean");+ assertEquals(getRawResponse(), longResult,longTest);++ //Float+ Double floatResult = (Double)getStatResult("mr", "float_fd", VAL_TYPE.DOUBLE);+ Double floatTest = (Double)calculateNumberStat(floatTestStart, "mean");+ assertEquals(getRawResponse(), floatResult,floatTest);++ //Double+ Double doubleResult = (Double)getStatResult("mr", "double_dd", VAL_TYPE.DOUBLE);+ Double doubleTest = (Double)calculateNumberStat(doubleTestStart, "mean");+ assertEquals(getRawResponse(), doubleResult,doubleTest);+ }++ @Test+ public void stddevTest() throws Exception {+ //Int+ Double intResult = (Double)getStatResult("str", "int_id", VAL_TYPE.DOUBLE);+ Double intTest = (Double)calculateNumberStat(intTestStart, "stddev");+ assertEquals(getRawResponse(), intResult, intTest, 0.00000000001);++ //Long+ Double longResult = (Double)getStatResult("str", "long_ld", VAL_TYPE.DOUBLE);+ Double longTest = (Double)calculateNumberStat(longTestStart, "stddev");+ assertEquals(getRawResponse(), longResult, longTest, 0.00000000001);++ //Float+ Double floatResult = (Double)getStatResult("str", "float_fd", VAL_TYPE.DOUBLE);+ Double floatTest = (Double)calculateNumberStat(floatTestStart, "stddev");+ assertEquals(getRawResponse(), floatResult, floatTest, 0.00000000001);+++ //Double+ Double doubleResult = (Double)getStatResult("str", "double_dd", VAL_TYPE.DOUBLE);+ Double doubleTest = (Double)calculateNumberStat(doubleTestStart, "stddev");+ assertEquals(getRawResponse(), doubleResult, doubleTest, 0.00000000001);+ }++ @Test+ public void medianTest() throws Exception {+ //Int+ Double intResult = (Double)getStatResult("medr", "int_id", VAL_TYPE.DOUBLE);+ Double intTest = (Double)calculateNumberStat(intTestStart, "median");+ assertEquals(getRawResponse(), intResult,intTest);++ //Long+ Double longResult = (Double)getStatResult("medr", "long_ld", VAL_TYPE.DOUBLE);+ Double longTest = (Double)calculateNumberStat(longTestStart, "median");+ assertEquals(getRawResponse(), longResult,longTest);++ //Float+ Double floatResult = (Double)getStatResult("medr", "float_fd", VAL_TYPE.DOUBLE);+ Double floatTest = (Double)calculateNumberStat(floatTestStart, "median");+ assertEquals(getRawResponse(), floatResult,floatTest);++ //Double+ Double doubleResult = (Double)getStatResult("medr", "double_dd", VAL_TYPE.DOUBLE);+ Double doubleTest = (Double)calculateNumberStat(doubleTestStart, "median");+ assertEquals(getRawResponse(), doubleResult,doubleTest);+ }++ @Test+ public void perc20Test() throws Exception {+ //Int 20+ Integer intResult = (Integer)getStatResult("p2r", "int_id", VAL_TYPE.INTEGER);+ Integer intTest = (Integer)calculateStat(intTestStart, "perc_20");+ assertEquals(getRawResponse(), intResult,intTest);++ //Long 20+ Long longResult = (Long)getStatResult("p2r", "long_ld", VAL_TYPE.LONG);+ Long longTest = (Long)calculateStat(longTestStart, "perc_20");+ assertEquals(getRawResponse(), longResult,longTest);++ //Float 20+ Float floatResult = (Float)getStatResult("p2r", "float_fd", VAL_TYPE.FLOAT);+ Float floatTest = (Float)calculateStat(floatTestStart, "perc_20");+ //assertEquals(getRawResponse(), floatResult,floatTest);++ //Double 20+ Double doubleResult = (Double)getStatResult("p2r", "double_dd", VAL_TYPE.DOUBLE);+ Double doubleTest = (Double)calculateStat(doubleTestStart, "perc_20");+ assertEquals(getRawResponse(), doubleResult,doubleTest);++ //Date 20+ String dateResult = (String)getStatResult("p2r", "date_dtd", VAL_TYPE.DATE);+ String dateTest = (String)calculateStat(dateTestStart, "perc_20");+ assertEquals(getRawResponse(), dateResult,dateTest);++ //String 20+ String stringResult = (String)getStatResult("p2r", "string_sd", VAL_TYPE.STRING);+ String stringTest = (String)calculateStat(stringTestStart, "perc_20");+ assertEquals(getRawResponse(), stringResult,stringTest);+ }++ @Test+ public void perc60Test() throws Exception {+ //Int 60+ Integer intResult = (Integer)getStatResult("p6r", "int_id", VAL_TYPE.INTEGER);+ Integer intTest = (Integer)calculateStat(intTestStart, "perc_60");+ assertEquals(getRawResponse(), intResult,intTest);++ //Long 60+ Long longResult = (Long)getStatResult("p6r", "long_ld", VAL_TYPE.LONG);+ Long longTest = (Long)calculateStat(longTestStart, "perc_60");+ assertEquals(getRawResponse(), longResult,longTest);++ //Float 60+ Float floatResult = (Float)getStatResult("p6r", "float_fd", VAL_TYPE.FLOAT);+ Float floatTest = (Float)calculateStat(floatTestStart, "perc_60");+ assertEquals(getRawResponse(), floatResult,floatTest);++ //Double 60+ Double doubleResult = (Double)getStatResult("p6r", "double_dd", VAL_TYPE.DOUBLE);+ Double doubleTest = (Double)calculateStat(doubleTestStart, "perc_60");+ assertEquals(getRawResponse(), doubleResult,doubleTest);++ //Date 60+ String dateResult = (String)getStatResult("p6r", "date_dtd", VAL_TYPE.DATE);+ String dateTest = (String)calculateStat(dateTestStart, "perc_60");+ assertEquals(getRawResponse(), dateResult,dateTest);++ //String 60+ String stringResult = (String)getStatResult("p6r", "string_sd", VAL_TYPE.STRING);+ String stringTest = (String)calculateStat(stringTestStart, "perc_60");+ assertEquals(getRawResponse(), stringResult,stringTest);+ }++ @Test+ public void minTest() throws Exception {+ //Int+ Integer intResult = ((Integer)getStatResult("mir", "int_id", VAL_TYPE.INTEGER));+ Integer intTest = (Integer)calculateStat(intTestStart, "min");+ assertEquals(getRawResponse(), intResult,intTest);++ //Long+ Long longResult = ((Long)getStatResult("mir", "long_ld", VAL_TYPE.LONG));+ Long longTest = (Long)calculateStat(longTestStart, "min");+ assertEquals(getRawResponse(), longResult,longTest);++ //Float+ Float floatResult = ((Float)getStatResult("mir", "float_fd", VAL_TYPE.FLOAT));+ Float floatTest = (Float)calculateStat(floatTestStart, "min");+ assertEquals(getRawResponse(), floatResult,floatTest);++ //Double+ Double doubleResult = (Double)getStatResult("mir", "double_dd", VAL_TYPE.DOUBLE);+ Double doubleTest = (Double)calculateStat(doubleTestStart, "min");+ assertEquals(getRawResponse(), doubleResult,doubleTest);++ //Date+ String dateResult = (String)getStatResult("mir", "date_dtd", VAL_TYPE.DATE);+ String dateTest = (String)calculateStat(dateTestStart, "min");+ assertEquals(getRawResponse(), dateResult,dateTest);++ //String+ String stringResult = (String)getStatResult("mir", "string_sd", VAL_TYPE.STRING);+ String stringTest = (String)calculateStat(stringTestStart, "min");+ assertEquals(getRawResponse(), stringResult,stringTest);+ }++ @Test+ public void maxTest() throws Exception {+ //Int+ Integer intResult = ((Integer)getStatResult("mar", "int_id", VAL_TYPE.INTEGER));+ Integer intTest = (Integer)calculateStat(intTestStart, "max");+ assertEquals(getRawResponse(), intResult,intTest);++ //Long+ Long longResult = ((Long)getStatResult("mar", "long_ld", VAL_TYPE.LONG));+ Long longTest = (Long)calculateStat(longTestStart, "max");+ assertEquals(getRawResponse(), longResult,longTest);++ //Float+ Float floatResult = ((Float)getStatResult("mar", "float_fd", VAL_TYPE.FLOAT));+ Float floatTest = (Float)calculateStat(floatTestStart, "max");+ assertEquals(getRawResponse(), floatResult,floatTest);++ //Double+ Double doubleResult = (Double)getStatResult("mar", "double_dd", VAL_TYPE.DOUBLE);+ Double doubleTest = (Double)calculateStat(doubleTestStart, "max");+ assertEquals(getRawResponse(), doubleResult,doubleTest);++ //Date+ String dateResult = (String)getStatResult("mar", "date_dtd", VAL_TYPE.DATE);+ String dateTest = (String)calculateStat(dateTestStart, "max");+ assertEquals(getRawResponse(), dateResult,dateTest);++ //String+ String stringResult = (String)getStatResult("mar", "string_sd", VAL_TYPE.STRING);+ String stringTest = (String)calculateStat(stringTestStart, "max");+ assertEquals(getRawResponse(), stringResult,stringTest);+ }++ @Test+ public void uniqueTest() throws Exception {+ //Int+ Long intResult = (Long)getStatResult("ur", "int_id", VAL_TYPE.LONG);+ Long intTest = (Long)calculateStat(intTestStart, "unique");+ assertEquals(getRawResponse(), intResult,intTest);++ //Long+ Long longResult = (Long)getStatResult("ur", "long_ld", VAL_TYPE.LONG);+ Long longTest = (Long)calculateStat(longTestStart, "unique");+ assertEquals(getRawResponse(), longResult,longTest);++ //Float+ Long floatResult = (Long)getStatResult("ur", "float_fd", VAL_TYPE.LONG);+ Long floatTest = (Long)calculateStat(floatTestStart, "unique");+ assertEquals(getRawResponse(), floatResult,floatTest);++ //Double+ Long doubleResult = (Long)getStatResult("ur", "double_dd", VAL_TYPE.LONG);+ Long doubleTest = (Long)calculateStat(doubleTestStart, "unique");+ assertEquals(getRawResponse(), doubleResult,doubleTest);++ //Date+ Long dateResult = (Long)getStatResult("ur", "date_dtd", VAL_TYPE.LONG);+ Long dateTest = (Long)calculateStat(dateTestStart, "unique");+ assertEquals(getRawResponse(), dateResult,dateTest);++ //String+ Long stringResult = (Long)getStatResult("ur", "string_sd", VAL_TYPE.LONG);+ Long stringTest = (Long)calculateStat(stringTestStart, "unique");+ assertEquals(getRawResponse(), stringResult,stringTest);+ }++ @Test+ public void countTest() throws Exception {+ //Int+ Long intResult = (Long)getStatResult("cr", "int_id", VAL_TYPE.LONG);+ Long intTest = (Long)calculateStat(intTestStart, "count");+ assertEquals(getRawResponse(), intResult,intTest);++ //Long+ Long longResult = (Long)getStatResult("cr", "long_ld", VAL_TYPE.LONG);+ Long longTest = (Long)calculateStat(longTestStart, "count");+ assertEquals(getRawResponse(), longResult,longTest);++ //Float+ Long floatResult = (Long)getStatResult("cr", "float_fd", VAL_TYPE.LONG);+ Long floatTest = (Long)calculateStat(floatTestStart, "count");+ assertEquals(getRawResponse(), floatResult,floatTest);++ //Double+ Long doubleResult = (Long)getStatResult("cr", "double_dd", VAL_TYPE.LONG);+ Long doubleTest = (Long)calculateStat(doubleTestStart, "count");+ assertEquals(getRawResponse(), doubleResult,doubleTest);++ //Date+ Long dateResult = (Long)getStatResult("cr", "date_dtd", VAL_TYPE.LONG);+ Long dateTest = (Long)calculateStat(dateTestStart, "count");+ assertEquals(getRawResponse(), dateResult,dateTest);++ //String+ Long stringResult = (Long)getStatResult("cr", "string_sd", VAL_TYPE.LONG);+ Long stringTest = (Long)calculateStat(stringTestStart, "count");+ assertEquals(getRawResponse(), stringResult,stringTest);+ }++ @Test+ public void missingDefaultTest() throws Exception {+ //Int+ long intResult = (Long)getStatResult("misr", "int_id", VAL_TYPE.LONG);+ assertEquals(getRawResponse(), intMissing,intResult);++ //Long+ long longResult = (Long)getStatResult("misr", "long_ld", VAL_TYPE.LONG);+ assertEquals(getRawResponse(), longMissing,longResult);++ //Float+ long floatResult = (Long)getStatResult("misr", "float_fd", VAL_TYPE.LONG);+ assertEquals(getRawResponse(), floatMissing,floatResult);++ //Double+ long doubleResult = (Long)getStatResult("misr", "double_dd", VAL_TYPE.LONG);+ assertEquals(getRawResponse(), doubleMissing,doubleResult);++ //Date+ long dateResult = (Long)getStatResult("misr", "date_dtd", VAL_TYPE.LONG);+ assertEquals(getRawResponse(), dateMissing,dateResult);++ //String+ long stringResult = (Long)getStatResult("misr", "string_sd", VAL_TYPE.LONG);+ assertEquals(getRawResponse(), stringMissing, stringResult);+ }++}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/expression/ExpressionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/expression/LegacyExpressionTest.javasimilarity index 95%rename from solr/contrib/analytics/src/test/org/apache/solr/analytics/expression/ExpressionTest.javarename to solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/expression/LegacyExpressionTest.javaindex eeecbe6b3ea..89fe2c79499 100644--- a/solr/contrib/analytics/src/test/org/apache/solr/analytics/expression/ExpressionTest.java+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/expression/LegacyExpressionTest.java@@ -14,17 +14,17 @@* See the License for the specific language governing permissions and* limitations under the License.*/-package org.apache.solr.analytics.expression;+package org.apache.solr.analytics.legacy.expression;import java.time.Instant;import java.util.Date;-import org.apache.solr.analytics.AbstractAnalyticsStatsTest;+import org.apache.solr.analytics.legacy.LegacyAbstractAnalyticsTest;import org.apache.solr.util.DateMathParser;import org.junit.BeforeClass;import org.junit.Test;-public class ExpressionTest extends AbstractAnalyticsStatsTest {+public class LegacyExpressionTest extends LegacyAbstractAnalyticsTest {private static final String fileName = "expressions.txt";private static final int INT = 71;@@ -58,7 +58,7 @@ public class ExpressionTest extends AbstractAnalyticsStatsTest {assertU(commit());- setResponse(h.query(request(fileToStringArr(ExpressionTest.class, fileName))));+ setResponse(h.query(request(fileToStringArr(LegacyExpressionTest.class, fileName))));}@Test@@ -142,8 +142,8 @@ public class ExpressionTest extends AbstractAnalyticsStatsTest {int result = (Integer) getStatResult("cnr", "c8", VAL_TYPE.INTEGER);assertEquals(getRawResponse(), 8, result, 0.0);- float dresult = (Float) getStatResult("cnr", "c10", VAL_TYPE.FLOAT);- assertEquals(getRawResponse(), 10.0f, dresult, 0.0);+ double dresult = (Double) getStatResult("cnr", "c10", VAL_TYPE.DOUBLE);+ assertEquals(getRawResponse(), 10.0, dresult, 0.0);}@Testdiff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/expression/FunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/expression/LegacyFunctionTest.javasimilarity index 94%rename from solr/contrib/analytics/src/test/org/apache/solr/analytics/expression/FunctionTest.javarename to solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/expression/LegacyFunctionTest.javaindex dac79216fda..85c1333084e 100644--- a/solr/contrib/analytics/src/test/org/apache/solr/analytics/expression/FunctionTest.java+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/expression/LegacyFunctionTest.java@@ -14,15 +14,15 @@* See the License for the specific language governing permissions and* limitations under the License.*/-package org.apache.solr.analytics.expression;+package org.apache.solr.analytics.legacy.expression;-import org.apache.solr.analytics.AbstractAnalyticsStatsTest;-import org.apache.solr.analytics.facet.AbstractAnalyticsFacetTest;+import org.apache.solr.analytics.legacy.LegacyAbstractAnalyticsTest;+import org.apache.solr.analytics.legacy.facet.LegacyAbstractAnalyticsFacetTest;import org.junit.BeforeClass;import org.junit.Test;-public class FunctionTest extends AbstractAnalyticsStatsTest {+public class LegacyFunctionTest extends LegacyAbstractAnalyticsTest {static String fileName = "functions.txt";static public final int INT = 71;@@ -62,7 +62,7 @@ public class FunctionTest extends AbstractAnalyticsStatsTest {String concat_first = "this is the first"+s;String concat_second = "this is the second"+s;- assertU(adoc(AbstractAnalyticsFacetTest.filter("id", "1000" + j, "int_id", "" + i, "long_ld", "" + l, "float_fd", "" + f,+ assertU(adoc(LegacyAbstractAnalyticsFacetTest.filter("id", "1000" + j, "int_id", "" + i, "long_ld", "" + l, "float_fd", "" + f,"double_dd", "" + d, "date_dtd", dt, "string_sd", s,"add_if_dd", ""+add_if, "add_ldf_dd", ""+add_ldf, "mult_if_dd", ""+mult_if, "mult_ldf_dd", ""+mult_ldf,"div_if_dd", ""+div_if, "div_ld_dd", ""+div_ld, "pow_if_dd", ""+pow_if, "pow_ld_dd", ""+pow_ld,@@ -78,7 +78,7 @@ public class FunctionTest extends AbstractAnalyticsStatsTest {assertU(commit());- setResponse(h.query(request(fileToStringArr(FunctionTest.class, fileName))));+ setResponse(h.query(request(fileToStringArr(LegacyFunctionTest.class, fileName))));}@Testdiff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/AbstractAnalyticsFacetCloudTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyAbstractAnalyticsFacetCloudTest.javasimilarity index 62%rename from solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/AbstractAnalyticsFacetCloudTest.javarename to solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyAbstractAnalyticsFacetCloudTest.javaindex 99e5103570d..783177d7804 100644--- a/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/AbstractAnalyticsFacetCloudTest.java+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyAbstractAnalyticsFacetCloudTest.java@@ -14,81 +14,31 @@* See the License for the specific language governing permissions and* limitations under the License.*/-package org.apache.solr.analytics.facet;+package org.apache.solr.analytics.legacy.facet;-import java.io.FileNotFoundException;-import java.io.IOException;-import java.io.InputStream;import java.util.ArrayList;import java.util.Collection;import java.util.Collections;import java.util.HashMap;import java.util.HashSet;import java.util.List;-import java.util.Scanner;-import org.apache.commons.lang.StringUtils;-import org.apache.lucene.util.IOUtils;+import org.apache.solr.analytics.legacy.LegacyAbstractAnalyticsCloudTest;import org.apache.solr.analytics.util.AnalyticsResponseHeadings;import org.apache.solr.analytics.util.MedianCalculator;import org.apache.solr.analytics.util.OrdinalCalculator;-import org.apache.solr.client.solrj.SolrServerException;-import org.apache.solr.client.solrj.request.CollectionAdminRequest;-import org.apache.solr.client.solrj.request.QueryRequest;-import org.apache.solr.client.solrj.request.UpdateRequest;-import org.apache.solr.client.solrj.response.QueryResponse;-import org.apache.solr.cloud.AbstractDistribZkTestBase;-import org.apache.solr.cloud.SolrCloudTestCase;-import org.apache.solr.common.params.ModifiableSolrParams;import org.apache.solr.common.util.NamedList;import org.junit.AfterClass;-public class AbstractAnalyticsFacetCloudTest extends SolrCloudTestCase {+public class LegacyAbstractAnalyticsFacetCloudTest extends LegacyAbstractAnalyticsCloudTest {protected static final HashMap<String,Object> defaults = new HashMap<>();- protected static final String COLLECTIONORALIAS = "collection1";- protected static final int TIMEOUT = DEFAULT_TIMEOUT;- protected static final String id = "id";-- public static void setupCluster() throws Exception {- configureCluster(2)- .addConfig("conf", configset("cloud-analytics"))- .configure();-- CollectionAdminRequest.createCollection(COLLECTIONORALIAS, "conf", 2, 1).process(cluster.getSolrClient());- AbstractDistribZkTestBase.waitForRecoveriesToFinish(COLLECTIONORALIAS, cluster.getSolrClient().getZkStateReader(),- false, true, TIMEOUT);-- cleanIndex();- }-- public static void cleanIndex() throws Exception {- new UpdateRequest()- .deleteByQuery("*:*")- .commit(cluster.getSolrClient(), COLLECTIONORALIAS);- }-protected String latestType = "";@AfterClasspublic static void afterClassAbstractAnalysis() {defaults.clear();}-- protected NamedList<Object> queryCloudAnalytics(String[] testParams) throws SolrServerException, IOException, InterruptedException {- ModifiableSolrParams params = new ModifiableSolrParams();- params.set("q", "*:*");- params.set("indent", "true");- params.set("olap", "true");- params.set("rows", "0");- for (int i = 0; i + 1 < testParams.length;) {- params.add(testParams[i++], testParams[i++]);- }- cluster.waitForAllNodes(10000);- QueryRequest qreq = new QueryRequest(params);- QueryResponse resp = qreq.process(cluster.getSolrClient(), COLLECTIONORALIAS);- return resp.getResponse();- }@SuppressWarnings("unchecked")protected <T> ArrayList<T> getValueList(NamedList<Object> response, String infoName, String facetType, String facetName, String exprName, boolean includeMissing) {@@ -123,27 +73,12 @@ public class AbstractAnalyticsFacetCloudTest extends SolrCloudTestCase {list.add(idx, i+1);}- public static String[] filter(String...args){- List<String> l = new ArrayList<>();- for( int i=0; i <args.length; i+=2){- if( args[i+1].equals("0") || args[i+1].equals("0.0") ||- args[i+1].equals("1800-12-31T23:59:59Z") || args[i+1].equals("str0") ||- args[i+1].equals("this is the firststr0") ||- args[i+1].equals("this is the secondstr0") ){- continue;- }- l.add(args[i]);- l.add(args[i+1]);- }- return l.toArray(new String[0]);- }-protected void setLatestType(String latestType) {this.latestType = latestType;}@SuppressWarnings({ "unchecked", "rawtypes" })- public <T extends Number & Comparable<T>> ArrayList calculateNumberStat(ArrayList<ArrayList<T>> lists, String stat) {+ public <T extends Number & Comparable<T>> ArrayList calculateFacetedNumberStat(ArrayList<ArrayList<T>> lists, String stat) {ArrayList result;if (stat.equals("median")) {result = new ArrayList<Double>();@@ -196,7 +131,7 @@ public class AbstractAnalyticsFacetCloudTest extends SolrCloudTestCase {}@SuppressWarnings({ "unchecked", "rawtypes" })- public <T extends Comparable<T>> ArrayList calculateStat(ArrayList<ArrayList<T>> lists, String stat) {+ public <T extends Comparable<T>> ArrayList calculateFacetedStat(ArrayList<ArrayList<T>> lists, String stat) {ArrayList result;if (stat.contains("perc_")) {result = new ArrayList<T>();@@ -256,29 +191,4 @@ public class AbstractAnalyticsFacetCloudTest extends SolrCloudTestCase {}return Long.valueOf(miss);}-- public static ModifiableSolrParams fileToParams(Class<?> clazz, String fileName) throws FileNotFoundException {- InputStream in = clazz.getResourceAsStream(fileName);- if (in == null) throw new FileNotFoundException("Resource not found: " + fileName);- Scanner file = new Scanner(in, "UTF-8");- try {- ModifiableSolrParams params = new ModifiableSolrParams();- params.set("q", "*:*");- params.set("indent", "true");- params.set("olap", "true");- params.set("rows", "0");- while (file.hasNextLine()) {- String line = file.nextLine();- line = line.trim();- if( StringUtils.isBlank(line) || line.startsWith("#")){- continue;- }- String[] param = line.split("=");- params.set(param[0], param[1]);- }- return params;- } finally {- IOUtils.closeWhileHandlingException(file, in);- }- }}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/AbstractAnalyticsFacetTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyAbstractAnalyticsFacetTest.javasimilarity index 98%rename from solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/AbstractAnalyticsFacetTest.javarename to solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyAbstractAnalyticsFacetTest.javaindex ff0e7dace5b..68c98268a64 100644--- a/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/AbstractAnalyticsFacetTest.java+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyAbstractAnalyticsFacetTest.java@@ -14,7 +14,7 @@* See the License for the specific language governing permissions and* limitations under the License.*/-package org.apache.solr.analytics.facet;+package org.apache.solr.analytics.legacy.facet;import java.io.ByteArrayInputStream;import java.io.FileNotFoundException;@@ -53,8 +53,7 @@ import javax.xml.xpath.XPathConstants;import javax.xml.xpath.XPathExpressionException;import javax.xml.xpath.XPathFactory;[email protected](bugUrl="https://issues.apache.org/jira/browse/SOLR-10949")-public class AbstractAnalyticsFacetTest extends SolrTestCaseJ4 {+public class LegacyAbstractAnalyticsFacetTest extends SolrTestCaseJ4 {protected static final HashMap<String,Object> defaults = new HashMap<>();protected String latestType = "";@@ -299,7 +298,7 @@ public class AbstractAnalyticsFacetTest extends SolrTestCaseJ4 {public static String[] fileToStringArr(Class<?> clazz, String fileName) throws FileNotFoundException {- InputStream in = clazz.getResourceAsStream("/solr/analytics/" + fileName);+ InputStream in = clazz.getResourceAsStream("/solr/analytics/legacy/" + fileName);if (in == null) throw new FileNotFoundException("Resource not found: " + fileName);Scanner file = new Scanner(in, "UTF-8");try {diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/FacetSortingTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyFacetSortingTest.javasimilarity index 85%rename from solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/FacetSortingTest.javarename to solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyFacetSortingTest.javaindex ef090144a2b..d89c7132661 100644--- a/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/FacetSortingTest.java+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyFacetSortingTest.java@@ -14,14 +14,14 @@* See the License for the specific language governing permissions and* limitations under the License.*/-package org.apache.solr.analytics.facet;+package org.apache.solr.analytics.legacy.facet;-import org.apache.solr.analytics.AbstractAnalyticsStatsTest;-import org.apache.solr.analytics.expression.ExpressionTest;+import org.apache.solr.analytics.legacy.LegacyAbstractAnalyticsTest;+import org.apache.solr.analytics.legacy.expression.LegacyExpressionTest;import org.junit.BeforeClass;import org.junit.Test;-public class FacetSortingTest extends AbstractAnalyticsStatsTest {+public class LegacyFacetSortingTest extends LegacyAbstractAnalyticsTest {private static String fileName = "facetSorting.txt";@BeforeClass@@ -39,7 +39,7 @@ public class FacetSortingTest extends AbstractAnalyticsStatsTest {assertU(adoc("id", "1005", "string_sd", "C", "double_dd", "" + 17));assertU(commit());- String response = h.query(request(fileToStringArr(ExpressionTest.class, fileName)));+ String response = h.query(request(fileToStringArr(LegacyExpressionTest.class, fileName)));setResponse(response);}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/FieldFacetCloudTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyFieldFacetCloudTest.javasimilarity index 83%rename from solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/FieldFacetCloudTest.javarename to solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyFieldFacetCloudTest.javaindex d4ffb4085af..11241407053 100644--- a/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/FieldFacetCloudTest.java+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyFieldFacetCloudTest.java@@ -14,7 +14,7 @@* See the License for the specific language governing permissions and* limitations under the License.*/-package org.apache.solr.analytics.facet;+package org.apache.solr.analytics.legacy.facet;import java.util.ArrayList;import java.util.Collection;@@ -28,7 +28,7 @@ import org.junit.BeforeClass;import org.junit.Test;-public class FieldFacetCloudTest extends AbstractAnalyticsFacetCloudTest {+public class LegacyFieldFacetCloudTest extends LegacyAbstractAnalyticsFacetCloudTest {public static final int INT = 71;public static final int LONG = 36;public static final int LONGM = 50;@@ -87,7 +87,7 @@ public class FieldFacetCloudTest extends AbstractAnalyticsFacetCloudTest {@BeforeClasspublic static void beforeClass() throws Exception {- setupCluster();+ cleanIndex();//INTintDateTestStart = new ArrayList<>();@@ -411,43 +411,43 @@ public class FieldFacetCloudTest extends AbstractAnalyticsFacetCloudTest {"o.sum.ff", "string_sd","o.sum.ff", "date_dtd"};- NamedList<Object> response = queryCloudAnalytics(params);+ NamedList<Object> response = queryLegacyCloudAnalytics(params);String responseStr = response.toString();//Int DateCollection<Double> intDate = getValueList(response, "sum", "fieldFacets", "date_dtd", "int", false);- ArrayList<Double> intDateTest = calculateNumberStat(intDateTestStart, "sum");+ ArrayList<Double> intDateTest = calculateFacetedNumberStat(intDateTestStart, "sum");assertEquals(responseStr.toString(),intDate,intDateTest);//Int StringCollection<Double> intString = getValueList(response, "sum", "fieldFacets", "string_sd", "int", false);- ArrayList<Double> intStringTest = calculateNumberStat(intStringTestStart, "sum");+ ArrayList<Double> intStringTest = calculateFacetedNumberStat(intStringTestStart, "sum");assertEquals(responseStr,intString,intStringTest);//Long DateCollection<Double> longDate = getValueList(response, "sum", "fieldFacets", "date_dtd", "long", false);- ArrayList<Double> longDateTest = calculateNumberStat(longDateTestStart, "sum");+ ArrayList<Double> longDateTest = calculateFacetedNumberStat(longDateTestStart, "sum");assertEquals(responseStr,longDate,longDateTest);//Long StringCollection<Double> longString = getValueList(response, "sum", "fieldFacets", "string_sd", "long", false);- ArrayList<Double> longStringTest = calculateNumberStat(longStringTestStart, "sum");+ ArrayList<Double> longStringTest = calculateFacetedNumberStat(longStringTestStart, "sum");assertEquals(responseStr,longString,longStringTest);//Float DateCollection<Double> floatDate = getValueList(response, "sum", "fieldFacets", "date_dtd", "float", false);- ArrayList<Double> floatDateTest = calculateNumberStat(floatDateTestStart, "sum");+ ArrayList<Double> floatDateTest = calculateFacetedNumberStat(floatDateTestStart, "sum");assertEquals(responseStr,floatDate,floatDateTest);//Float StringCollection<Double> floatString = getValueList(response, "sum", "fieldFacets", "string_sd", "float", false);- ArrayList<Double> floatStringTest = calculateNumberStat(floatStringTestStart, "sum");+ ArrayList<Double> floatStringTest = calculateFacetedNumberStat(floatStringTestStart, "sum");assertEquals(responseStr,floatString,floatStringTest);//Double DateCollection<Double> doubleDate = getValueList(response, "sum", "fieldFacets", "date_dtd", "double", false);- ArrayList<Double> doubleDateTest = calculateNumberStat(doubleDateTestStart, "sum");+ ArrayList<Double> doubleDateTest = calculateFacetedNumberStat(doubleDateTestStart, "sum");assertEquals(responseStr,doubleDate,doubleDateTest);//Double StringCollection<Double> doubleString = getValueList(response, "sum", "fieldFacets", "string_sd", "double", false);- ArrayList<Double> doubleStringTest = calculateNumberStat(doubleStringTestStart, "sum");+ ArrayList<Double> doubleStringTest = calculateFacetedNumberStat(doubleStringTestStart, "sum");assertEquals(responseStr,doubleString,doubleStringTest);}@@ -462,43 +462,43 @@ public class FieldFacetCloudTest extends AbstractAnalyticsFacetCloudTest {"o.mean.ff", "string_sd","o.mean.ff", "date_dtd"};- NamedList<Object> response = queryCloudAnalytics(params);+ NamedList<Object> response = queryLegacyCloudAnalytics(params);String responseStr = response.toString();//Int DateCollection<Double> intDate = getValueList(response, "mean", "fieldFacets", "date_dtd", "int", false);- ArrayList<Double> intDateTest = calculateNumberStat(intDateTestStart, "mean");+ ArrayList<Double> intDateTest = calculateFacetedNumberStat(intDateTestStart, "mean");assertEquals(responseStr,intDate,intDateTest);//Int StringCollection<Double> intString = getValueList(response, "mean", "fieldFacets", "string_sd", "int", false);- ArrayList<Double> intStringTest = calculateNumberStat(intStringTestStart, "mean");+ ArrayList<Double> intStringTest = calculateFacetedNumberStat(intStringTestStart, "mean");assertEquals(responseStr,intString,intStringTest);//Long DateCollection<Double> longDate = getValueList(response, "mean", "fieldFacets", "date_dtd", "long", false);- ArrayList<Double> longDateTest = calculateNumberStat(longDateTestStart, "mean");+ ArrayList<Double> longDateTest = calculateFacetedNumberStat(longDateTestStart, "mean");assertEquals(responseStr,longDate,longDateTest);//Long StringCollection<Double> longString = getValueList(response, "mean", "fieldFacets", "string_sd", "long", false);- ArrayList<Double> longStringTest = calculateNumberStat(longStringTestStart, "mean");+ ArrayList<Double> longStringTest = calculateFacetedNumberStat(longStringTestStart, "mean");assertEquals(responseStr,longString,longStringTest);//Float DateCollection<Double> floatDate = getValueList(response, "mean", "fieldFacets", "date_dtd", "float", false);- ArrayList<Double> floatDateTest = calculateNumberStat(floatDateTestStart, "mean");+ ArrayList<Double> floatDateTest = calculateFacetedNumberStat(floatDateTestStart, "mean");assertEquals(responseStr,floatDate,floatDateTest);//Float StringCollection<Double> floatString = getValueList(response, "mean", "fieldFacets", "string_sd", "float", false);- ArrayList<Double> floatStringTest = calculateNumberStat(floatStringTestStart, "mean");+ ArrayList<Double> floatStringTest = calculateFacetedNumberStat(floatStringTestStart, "mean");assertEquals(responseStr,floatString,floatStringTest);//Double DateCollection<Double> doubleDate = getValueList(response, "mean", "fieldFacets", "date_dtd", "double", false);- ArrayList<Double> doubleDateTest = calculateNumberStat(doubleDateTestStart, "mean");+ ArrayList<Double> doubleDateTest = calculateFacetedNumberStat(doubleDateTestStart, "mean");assertEquals(responseStr,doubleDate,doubleDateTest);//Double StringCollection<Double> doubleString = getValueList(response, "mean", "fieldFacets", "string_sd", "double", false);- ArrayList<Double> doubleStringTest = calculateNumberStat(doubleStringTestStart, "mean");+ ArrayList<Double> doubleStringTest = calculateFacetedNumberStat(doubleStringTestStart, "mean");assertEquals(responseStr,doubleString,doubleStringTest);}@@ -513,42 +513,42 @@ public class FieldFacetCloudTest extends AbstractAnalyticsFacetCloudTest {"o.stddev.ff", "string_sd","o.stddev.ff", "date_dtd"};- NamedList<Object> response = queryCloudAnalytics(params);+ NamedList<Object> response = queryLegacyCloudAnalytics(params);//Int DateArrayList<Double> intDate = getValueList(response, "stddev", "fieldFacets", "date_dtd", "int", false);- ArrayList<Double> intDateTest = calculateNumberStat(intDateTestStart, "stddev");+ ArrayList<Double> intDateTest = calculateFacetedNumberStat(intDateTestStart, "stddev");checkStddevs(response, intDate, intDateTest);//Int StringArrayList<Double> intString = getValueList(response, "stddev", "fieldFacets", "string_sd", "int", false);- ArrayList<Double> intStringTest = calculateNumberStat(intStringTestStart, "stddev");+ ArrayList<Double> intStringTest = calculateFacetedNumberStat(intStringTestStart, "stddev");checkStddevs(response, intString, intStringTest);//Long DateArrayList<Double> longDate = getValueList(response, "stddev", "fieldFacets", "date_dtd", "long", false);- ArrayList<Double> longDateTest = calculateNumberStat(longDateTestStart, "stddev");+ ArrayList<Double> longDateTest = calculateFacetedNumberStat(longDateTestStart, "stddev");checkStddevs(response, longDate, longDateTest);//Long StringArrayList<Double> longString = getValueList(response, "stddev", "fieldFacets", "string_sd", "long", false);- ArrayList<Double> longStringTest = calculateNumberStat(longStringTestStart, "stddev");+ ArrayList<Double> longStringTest = calculateFacetedNumberStat(longStringTestStart, "stddev");checkStddevs(response, longString, longStringTest);//Float DateArrayList<Double> floatDate = getValueList(response, "stddev", "fieldFacets", "date_dtd", "float", false);- ArrayList<Double> floatDateTest = calculateNumberStat(floatDateTestStart, "stddev");+ ArrayList<Double> floatDateTest = calculateFacetedNumberStat(floatDateTestStart, "stddev");checkStddevs(response, floatDate, floatDateTest);//Float StringArrayList<Double> floatString = getValueList(response, "stddev", "fieldFacets", "string_sd", "float", false);- ArrayList<Double> floatStringTest = calculateNumberStat(floatStringTestStart, "stddev");+ ArrayList<Double> floatStringTest = calculateFacetedNumberStat(floatStringTestStart, "stddev");checkStddevs(response, floatString, floatStringTest);//Double DateArrayList<Double> doubleDate = getValueList(response, "stddev", "fieldFacets", "date_dtd", "double", false);- ArrayList<Double> doubleDateTest = calculateNumberStat(doubleDateTestStart, "stddev");+ ArrayList<Double> doubleDateTest = calculateFacetedNumberStat(doubleDateTestStart, "stddev");checkStddevs(response, doubleDate, doubleDateTest);//Double StringArrayList<Double> doubleString = getValueList(response, "stddev", "fieldFacets", "string_sd", "double", false);- ArrayList<Double> doubleStringTest = calculateNumberStat(doubleStringTestStart, "stddev");+ ArrayList<Double> doubleStringTest = calculateFacetedNumberStat(doubleStringTestStart, "stddev");checkStddevs(response, doubleString, doubleStringTest);}@@ -563,43 +563,43 @@ public class FieldFacetCloudTest extends AbstractAnalyticsFacetCloudTest {"o.median.ff", "string_sd","o.median.ff", "date_dtd"};- NamedList<Object> response = queryCloudAnalytics(params);+ NamedList<Object> response = queryLegacyCloudAnalytics(params);String responseStr = response.toString();//Int DateCollection<Double> intDate = getValueList(response, "median","fieldFacets", "date_dtd", "int", false);- ArrayList<Double> intDateTest = calculateNumberStat(intDateTestStart, "median");+ ArrayList<Double> intDateTest = calculateFacetedNumberStat(intDateTestStart, "median");assertEquals(responseStr,intDate,intDateTest);//Int StringCollection<Double> intString = getValueList(response, "median", "fieldFacets", "string_sd", "int", false);- ArrayList<Double> intStringTest = calculateNumberStat(intStringTestStart, "median");+ ArrayList<Double> intStringTest = calculateFacetedNumberStat(intStringTestStart, "median");assertEquals(responseStr,intString,intStringTest);//Long DateCollection<Double> longDate = getValueList(response, "median", "fieldFacets", "date_dtd", "long", false);- ArrayList<Double> longDateTest = calculateNumberStat(longDateTestStart, "median");+ ArrayList<Double> longDateTest = calculateFacetedNumberStat(longDateTestStart, "median");assertEquals(responseStr,longDate,longDateTest);//Long StringCollection<Double> longString = getValueList(response, "median", "fieldFacets", "string_sd", "long", false);- ArrayList<Double> longStringTest = calculateNumberStat(longStringTestStart, "median");+ ArrayList<Double> longStringTest = calculateFacetedNumberStat(longStringTestStart, "median");assertEquals(responseStr,longString,longStringTest);//Float DateCollection<Double> floatDate = getValueList(response, "median", "fieldFacets", "date_dtd", "float", false);- ArrayList<Double> floatDateTest = calculateNumberStat(floatDateTestStart, "median");+ ArrayList<Double> floatDateTest = calculateFacetedNumberStat(floatDateTestStart, "median");assertEquals(responseStr,floatDate,floatDateTest);//Float StringCollection<Double> floatString = getValueList(response, "median", "fieldFacets", "string_sd", "float", false);- ArrayList<Double> floatStringTest = calculateNumberStat(floatStringTestStart, "median");+ ArrayList<Double> floatStringTest = calculateFacetedNumberStat(floatStringTestStart, "median");assertEquals(responseStr,floatString,floatStringTest);//Double DateCollection<Double> doubleDate = getValueList(response, "median", "fieldFacets", "date_dtd", "double", false);- ArrayList<Double> doubleDateTest = calculateNumberStat(doubleDateTestStart, "median");+ ArrayList<Double> doubleDateTest = calculateFacetedNumberStat(doubleDateTestStart, "median");assertEquals(responseStr,doubleDate,doubleDateTest);//Double StringCollection<Double> doubleString = getValueList(response, "median", "fieldFacets", "string_sd", "double", false);- ArrayList<Double> doubleStringTest = calculateNumberStat(doubleStringTestStart, "median");+ ArrayList<Double> doubleStringTest = calculateFacetedNumberStat(doubleStringTestStart, "median");assertEquals(responseStr,doubleString,doubleStringTest);}@@ -619,61 +619,61 @@ public class FieldFacetCloudTest extends AbstractAnalyticsFacetCloudTest {"o.percentile_20.ff", "int_id","o.percentile_20.ff", "long_ld"};- NamedList<Object> response = queryCloudAnalytics(params);+ NamedList<Object> response = queryLegacyCloudAnalytics(params);String responseStr = response.toString();//Int DateCollection<Integer> intDate = getValueList(response, "percentile_20n", "fieldFacets", "date_dtd", "int", false);- ArrayList<Integer> intDateTest = (ArrayList<Integer>)calculateStat(intDateTestStart, "perc_20");+ ArrayList<Integer> intDateTest = (ArrayList<Integer>)calculateFacetedStat(intDateTestStart, "perc_20");assertEquals(responseStr,intDate,intDateTest);//Int StringCollection<Integer> intString = getValueList(response, "percentile_20n", "fieldFacets", "string_sd", "int", false);- ArrayList<Integer> intStringTest = (ArrayList<Integer>)calculateStat(intStringTestStart, "perc_20");+ ArrayList<Integer> intStringTest = (ArrayList<Integer>)calculateFacetedStat(intStringTestStart, "perc_20");assertEquals(responseStr,intString,intStringTest);//Long DateCollection<Long> longDate = getValueList(response, "percentile_20n", "fieldFacets", "date_dtd", "long", false);- ArrayList<Long> longDateTest = (ArrayList<Long>)calculateStat(longDateTestStart, "perc_20");+ ArrayList<Long> longDateTest = (ArrayList<Long>)calculateFacetedStat(longDateTestStart, "perc_20");assertEquals(responseStr,longDate,longDateTest);//Long StringCollection<Long> longString = getValueList(response, "percentile_20n", "fieldFacets", "string_sd", "long", false);- ArrayList<Long> longStringTest = (ArrayList<Long>)calculateStat(longStringTestStart, "perc_20");+ ArrayList<Long> longStringTest = (ArrayList<Long>)calculateFacetedStat(longStringTestStart, "perc_20");assertEquals(responseStr,longString,longStringTest);//Float DateCollection<Float> floatDate = getValueList(response, "percentile_20n", "fieldFacets", "date_dtd", "float", false);- ArrayList<Float> floatDateTest = (ArrayList<Float>)calculateStat(floatDateTestStart, "perc_20");+ ArrayList<Float> floatDateTest = (ArrayList<Float>)calculateFacetedStat(floatDateTestStart, "perc_20");assertEquals(responseStr,floatDate,floatDateTest);//Float StringCollection<Float> floatString = getValueList(response, "percentile_20n", "fieldFacets", "string_sd", "float", false);- ArrayList<Float> floatStringTest = (ArrayList<Float>)calculateStat(floatStringTestStart, "perc_20");+ ArrayList<Float> floatStringTest = (ArrayList<Float>)calculateFacetedStat(floatStringTestStart, "perc_20");assertEquals(responseStr,floatString,floatStringTest);//Double DateCollection<Double> doubleDate = getValueList(response, "percentile_20n", "fieldFacets", "date_dtd", "double", false);- ArrayList<Double> doubleDateTest = (ArrayList<Double>)calculateStat(doubleDateTestStart, "perc_20");+ ArrayList<Double> doubleDateTest = (ArrayList<Double>)calculateFacetedStat(doubleDateTestStart, "perc_20");assertEquals(responseStr,doubleDate,doubleDateTest);//Double StringCollection<Double> doubleString = getValueList(response, "percentile_20n", "fieldFacets", "string_sd", "double", false);- ArrayList<Double> doubleStringTest = (ArrayList<Double>)calculateStat(doubleStringTestStart, "perc_20");+ ArrayList<Double> doubleStringTest = (ArrayList<Double>)calculateFacetedStat(doubleStringTestStart, "perc_20");assertEquals(responseStr,doubleString,doubleStringTest);//Date IntCollection<String> dateInt = getValueList(response, "percentile_20", "fieldFacets", "int_id", "date", false);- ArrayList<String> dateIntTest = (ArrayList<String>)calculateStat(dateIntTestStart, "perc_20");+ ArrayList<String> dateIntTest = (ArrayList<String>)calculateFacetedStat(dateIntTestStart, "perc_20");assertEquals(responseStr,dateInt,dateIntTest);//Date LongCollection<String> dateString = getValueList(response, "percentile_20", "fieldFacets", "long_ld", "date", false);- ArrayList<String> dateLongTest = (ArrayList<String>)calculateStat(dateLongTestStart, "perc_20");+ ArrayList<String> dateLongTest = (ArrayList<String>)calculateFacetedStat(dateLongTestStart, "perc_20");assertEquals(responseStr,dateString,dateLongTest);//String IntCollection<String> stringInt = getValueList(response, "percentile_20", "fieldFacets", "int_id", "str", false);- ArrayList<String> stringIntTest = (ArrayList<String>)calculateStat(stringIntTestStart, "perc_20");+ ArrayList<String> stringIntTest = (ArrayList<String>)calculateFacetedStat(stringIntTestStart, "perc_20");assertEquals(responseStr,stringInt,stringIntTest);//String LongCollection<String> stringLong = getValueList(response, "percentile_20", "fieldFacets", "long_ld", "str", false);- ArrayList<String> stringLongTest = (ArrayList<String>)calculateStat(stringLongTestStart, "perc_20");+ ArrayList<String> stringLongTest = (ArrayList<String>)calculateFacetedStat(stringLongTestStart, "perc_20");assertEquals(responseStr,stringLong,stringLongTest);}@@ -693,61 +693,61 @@ public class FieldFacetCloudTest extends AbstractAnalyticsFacetCloudTest {"o.percentile_60.ff", "int_id","o.percentile_60.ff", "long_ld"};- NamedList<Object> response = queryCloudAnalytics(params);+ NamedList<Object> response = queryLegacyCloudAnalytics(params);String responseStr = response.toString();//Int DateCollection<Integer> intDate = getValueList(response, "percentile_60n", "fieldFacets", "date_dtd", "int", false);- ArrayList<Integer> intDateTest = (ArrayList<Integer>)calculateStat(intDateTestStart, "perc_60");+ ArrayList<Integer> intDateTest = (ArrayList<Integer>)calculateFacetedStat(intDateTestStart, "perc_60");assertEquals(responseStr,intDate,intDateTest);//Int StringCollection<Integer> intString = getValueList(response, "percentile_60n", "fieldFacets", "string_sd", "int", false);- ArrayList<Integer> intStringTest = (ArrayList<Integer>)calculateStat(intStringTestStart, "perc_60");+ ArrayList<Integer> intStringTest = (ArrayList<Integer>)calculateFacetedStat(intStringTestStart, "perc_60");assertEquals(responseStr,intString,intStringTest);//Long DateCollection<Long> longDate = getValueList(response, "percentile_60n", "fieldFacets", "date_dtd", "long", false);- ArrayList<Long> longDateTest = (ArrayList<Long>)calculateStat(longDateTestStart, "perc_60");+ ArrayList<Long> longDateTest = (ArrayList<Long>)calculateFacetedStat(longDateTestStart, "perc_60");assertEquals(responseStr,longDate,longDateTest);//Long StringCollection<Long> longString = getValueList(response, "percentile_60n", "fieldFacets", "string_sd", "long", false);- ArrayList<Long> longStringTest = (ArrayList<Long>)calculateStat(longStringTestStart, "perc_60");+ ArrayList<Long> longStringTest = (ArrayList<Long>)calculateFacetedStat(longStringTestStart, "perc_60");assertEquals(responseStr,longString,longStringTest);//Float DateCollection<Float> floatDate = getValueList(response, "percentile_60n", "fieldFacets", "date_dtd", "float", false);- ArrayList<Float> floatDateTest = (ArrayList<Float>)calculateStat(floatDateTestStart, "perc_60");+ ArrayList<Float> floatDateTest = (ArrayList<Float>)calculateFacetedStat(floatDateTestStart, "perc_60");assertEquals(responseStr,floatDate,floatDateTest);//Float StringCollection<Float> floatString = getValueList(response, "percentile_60n", "fieldFacets", "string_sd", "float", false);- ArrayList<Float> floatStringTest = (ArrayList<Float>)calculateStat(floatStringTestStart, "perc_60");+ ArrayList<Float> floatStringTest = (ArrayList<Float>)calculateFacetedStat(floatStringTestStart, "perc_60");assertEquals(responseStr,floatString,floatStringTest);//Double DateCollection<Double> doubleDate = getValueList(response, "percentile_60n", "fieldFacets", "date_dtd", "double", false);- ArrayList<Double> doubleDateTest = (ArrayList<Double>)calculateStat(doubleDateTestStart, "perc_60");+ ArrayList<Double> doubleDateTest = (ArrayList<Double>)calculateFacetedStat(doubleDateTestStart, "perc_60");assertEquals(responseStr,doubleDate,doubleDateTest);//Double StringCollection<Double> doubleString = getValueList(response, "percentile_60n", "fieldFacets", "string_sd", "double", false);- ArrayList<Double> doubleStringTest = (ArrayList<Double>)calculateStat(doubleStringTestStart, "perc_60");+ ArrayList<Double> doubleStringTest = (ArrayList<Double>)calculateFacetedStat(doubleStringTestStart, "perc_60");assertEquals(responseStr,doubleString,doubleStringTest);//Date IntCollection<String> dateInt = getValueList(response, "percentile_60", "fieldFacets", "int_id", "date", false);- ArrayList<String> dateIntTest = (ArrayList<String>)calculateStat(dateIntTestStart, "perc_60");+ ArrayList<String> dateIntTest = (ArrayList<String>)calculateFacetedStat(dateIntTestStart, "perc_60");assertEquals(responseStr,dateInt,dateIntTest);//Date LongCollection<String> dateString = getValueList(response, "percentile_60", "fieldFacets", "long_ld", "date", false);- ArrayList<String> dateLongTest = (ArrayList<String>)calculateStat(dateLongTestStart, "perc_60");+ ArrayList<String> dateLongTest = (ArrayList<String>)calculateFacetedStat(dateLongTestStart, "perc_60");assertEquals(responseStr,dateString,dateLongTest);//String IntCollection<String> stringInt = getValueList(response, "percentile_60", "fieldFacets", "int_id", "str", false);- ArrayList<String> stringIntTest = (ArrayList<String>)calculateStat(stringIntTestStart, "perc_60");+ ArrayList<String> stringIntTest = (ArrayList<String>)calculateFacetedStat(stringIntTestStart, "perc_60");assertEquals(responseStr,stringInt,stringIntTest);//String LongCollection<String> stringLong = getValueList(response, "percentile_60", "fieldFacets", "long_ld", "str", false);- ArrayList<String> stringLongTest = (ArrayList<String>)calculateStat(stringLongTestStart, "perc_60");+ ArrayList<String> stringLongTest = (ArrayList<String>)calculateFacetedStat(stringLongTestStart, "perc_60");assertEquals(responseStr,stringLong,stringLongTest);}@@ -767,61 +767,61 @@ public class FieldFacetCloudTest extends AbstractAnalyticsFacetCloudTest {"o.min.ff", "int_id","o.min.ff", "long_ld"};- NamedList<Object> response = queryCloudAnalytics(params);+ NamedList<Object> response = queryLegacyCloudAnalytics(params);String responseStr = response.toString();//Int DateCollection<Integer> intDate = getValueList(response, "minn", "fieldFacets", "date_dtd", "int", false);- ArrayList<Integer> intDateTest = (ArrayList<Integer>)calculateStat(intDateTestStart, "min");+ ArrayList<Integer> intDateTest = (ArrayList<Integer>)calculateFacetedStat(intDateTestStart, "min");assertEquals(responseStr,intDate,intDateTest);//Int StringCollection<Integer> intString = getValueList(response, "minn", "fieldFacets", "string_sd", "int", false);- ArrayList<Integer> intStringTest = (ArrayList<Integer>)calculateStat(intStringTestStart, "min");+ ArrayList<Integer> intStringTest = (ArrayList<Integer>)calculateFacetedStat(intStringTestStart, "min");assertEquals(responseStr,intString,intStringTest);//Long DateCollection<Long> longDate = getValueList(response, "minn", "fieldFacets", "date_dtd", "long", false);- ArrayList<Long> longDateTest = (ArrayList<Long>)calculateStat(longDateTestStart, "min");+ ArrayList<Long> longDateTest = (ArrayList<Long>)calculateFacetedStat(longDateTestStart, "min");assertEquals(responseStr,longDate,longDateTest);//Long StringCollection<Long> longString = getValueList(response, "minn", "fieldFacets", "string_sd", "long", false);- ArrayList<Long> longStringTest = (ArrayList<Long>)calculateStat(longStringTestStart, "min");+ ArrayList<Long> longStringTest = (ArrayList<Long>)calculateFacetedStat(longStringTestStart, "min");assertEquals(responseStr,longString,longStringTest);//Float DateCollection<Float> floatDate = getValueList(response, "minn", "fieldFacets", "date_dtd", "float", false);- ArrayList<Float> floatDateTest = (ArrayList<Float>)calculateStat(floatDateTestStart, "min");+ ArrayList<Float> floatDateTest = (ArrayList<Float>)calculateFacetedStat(floatDateTestStart, "min");assertEquals(responseStr,floatDate,floatDateTest);//Float StringCollection<Float> floatString = getValueList(response, "minn", "fieldFacets", "string_sd", "float", false);- ArrayList<Float> floatStringTest = (ArrayList<Float>)calculateStat(floatStringTestStart, "min");+ ArrayList<Float> floatStringTest = (ArrayList<Float>)calculateFacetedStat(floatStringTestStart, "min");assertEquals(responseStr,floatString,floatStringTest);//Double DateCollection<Double> doubleDate = getValueList(response, "minn", "fieldFacets", "date_dtd", "double", false);- ArrayList<Double> doubleDateTest = (ArrayList<Double>)calculateStat(doubleDateTestStart, "min");+ ArrayList<Double> doubleDateTest = (ArrayList<Double>)calculateFacetedStat(doubleDateTestStart, "min");assertEquals(responseStr,doubleDate,doubleDateTest);//Double StringCollection<Double> doubleString = getValueList(response, "minn", "fieldFacets", "string_sd", "double", false);- ArrayList<Double> doubleStringTest = (ArrayList<Double>)calculateStat(doubleStringTestStart, "min");+ ArrayList<Double> doubleStringTest = (ArrayList<Double>)calculateFacetedStat(doubleStringTestStart, "min");assertEquals(responseStr,doubleString,doubleStringTest);//Date IntCollection<String> dateInt = getValueList(response, "min", "fieldFacets", "int_id", "date", false);- ArrayList<String> dateIntTest = (ArrayList<String>)calculateStat(dateIntTestStart, "min");+ ArrayList<String> dateIntTest = (ArrayList<String>)calculateFacetedStat(dateIntTestStart, "min");assertEquals(responseStr,dateInt,dateIntTest);//Date LongCollection<String> dateString = getValueList(response, "min", "fieldFacets", "long_ld", "date", false);- ArrayList<String> dateLongTest = (ArrayList<String>)calculateStat(dateLongTestStart, "min");+ ArrayList<String> dateLongTest = (ArrayList<String>)calculateFacetedStat(dateLongTestStart, "min");assertEquals(responseStr,dateString,dateLongTest);//String IntCollection<String> stringInt = getValueList(response, "min", "fieldFacets", "int_id", "str", false);- ArrayList<String> stringIntTest = (ArrayList<String>)calculateStat(stringIntTestStart, "min");+ ArrayList<String> stringIntTest = (ArrayList<String>)calculateFacetedStat(stringIntTestStart, "min");assertEquals(responseStr,stringInt,stringIntTest);//String LongCollection<String> stringLong = getValueList(response, "min", "fieldFacets", "long_ld", "str", false);- ArrayList<String> stringLongTest = (ArrayList<String>)calculateStat(stringLongTestStart, "min");+ ArrayList<String> stringLongTest = (ArrayList<String>)calculateFacetedStat(stringLongTestStart, "min");assertEquals(responseStr,stringLong,stringLongTest);}@@ -841,67 +841,67 @@ public class FieldFacetCloudTest extends AbstractAnalyticsFacetCloudTest {"o.max.ff", "int_id","o.max.ff", "long_ld"};- NamedList<Object> response = queryCloudAnalytics(params);+ NamedList<Object> response = queryLegacyCloudAnalytics(params);String responseStr = response.toString();//Int DateCollection<Integer> intDate = getValueList(response, "maxn", "fieldFacets", "date_dtd", "int", false);- ArrayList<Integer> intDateTest = (ArrayList<Integer>)calculateStat(intDateTestStart, "max");+ ArrayList<Integer> intDateTest = (ArrayList<Integer>)calculateFacetedStat(intDateTestStart, "max");assertEquals(responseStr,intDate,intDateTest);//Int StringCollection<Integer> intString = getValueList(response, "maxn", "fieldFacets", "string_sd", "int", false);- ArrayList<Integer> intStringTest = (ArrayList<Integer>)calculateStat(intStringTestStart, "max");+ ArrayList<Integer> intStringTest = (ArrayList<Integer>)calculateFacetedStat(intStringTestStart, "max");assertEquals(responseStr,intString,intStringTest);//Long DateCollection<Long> longDate = getValueList(response, "maxn", "fieldFacets", "date_dtd", "long", false);- ArrayList<Long> longDateTest = (ArrayList<Long>)calculateStat(longDateTestStart, "max");+ ArrayList<Long> longDateTest = (ArrayList<Long>)calculateFacetedStat(longDateTestStart, "max");assertEquals(responseStr,longDate,longDateTest);//Long StringCollection<Long> longString = getValueList(response, "maxn", "fieldFacets", "string_sd", "long", false);- ArrayList<Long> longStringTest = (ArrayList<Long>)calculateStat(longStringTestStart, "max");+ ArrayList<Long> longStringTest = (ArrayList<Long>)calculateFacetedStat(longStringTestStart, "max");assertEquals(responseStr,longString,longStringTest);//Float DateCollection<Float> floatDate = getValueList(response, "maxn", "fieldFacets", "date_dtd", "float", false);- ArrayList<Float> floatDateTest = (ArrayList<Float>)calculateStat(floatDateTestStart, "max");+ ArrayList<Float> floatDateTest = (ArrayList<Float>)calculateFacetedStat(floatDateTestStart, "max");assertEquals(responseStr,floatDate,floatDateTest);//Float StringCollection<Float> floatString = getValueList(response, "maxn", "fieldFacets", "string_sd", "float", false);- ArrayList<Float> floatStringTest = (ArrayList<Float>)calculateStat(floatStringTestStart, "max");+ ArrayList<Float> floatStringTest = (ArrayList<Float>)calculateFacetedStat(floatStringTestStart, "max");assertEquals(responseStr,floatString,floatStringTest);//Double DateCollection<Double> doubleDate = getValueList(response, "maxn", "fieldFacets", "date_dtd", "double", false);- ArrayList<Double> doubleDateTest = (ArrayList<Double>)calculateStat(doubleDateTestStart, "max");+ ArrayList<Double> doubleDateTest = (ArrayList<Double>)calculateFacetedStat(doubleDateTestStart, "max");assertEquals(responseStr,doubleDate,doubleDateTest);//Double StringCollection<Double> doubleString = getValueList(response, "maxn", "fieldFacets", "string_sd", "double", false);- ArrayList<Double> doubleStringTest = (ArrayList<Double>)calculateStat(doubleStringTestStart, "max");+ ArrayList<Double> doubleStringTest = (ArrayList<Double>)calculateFacetedStat(doubleStringTestStart, "max");assertEquals(responseStr,doubleString,doubleStringTest);//String IntCollection<String> stringInt = getValueList(response, "max", "fieldFacets", "int_id", "str", false);- ArrayList<String> stringIntTest = (ArrayList<String>)calculateStat(stringIntTestStart, "max");+ ArrayList<String> stringIntTest = (ArrayList<String>)calculateFacetedStat(stringIntTestStart, "max");assertEquals(responseStr,stringInt,stringIntTest);//String LongCollection<String> stringLong = getValueList(response, "max", "fieldFacets", "long_ld", "str", false);- ArrayList<String> stringLongTest = (ArrayList<String>)calculateStat(stringLongTestStart, "max");+ ArrayList<String> stringLongTest = (ArrayList<String>)calculateFacetedStat(stringLongTestStart, "max");assertEquals(responseStr,stringLong,stringLongTest);//Date IntCollection<String> dateInt = getValueList(response, "max", "fieldFacets", "int_id", "date", false);- ArrayList<String> dateIntTest = (ArrayList<String>)calculateStat(dateIntTestStart, "max");+ ArrayList<String> dateIntTest = (ArrayList<String>)calculateFacetedStat(dateIntTestStart, "max");assertEquals(responseStr,dateInt,dateIntTest);//Date LongCollection<String> dateString = getValueList(response, "max", "fieldFacets", "long_ld", "date", false);- ArrayList<String> dateLongTest = (ArrayList<String>)calculateStat(dateLongTestStart, "max");+ ArrayList<String> dateLongTest = (ArrayList<String>)calculateFacetedStat(dateLongTestStart, "max");assertEquals(responseStr,dateString,dateLongTest);}@@ -922,61 +922,61 @@ public class FieldFacetCloudTest extends AbstractAnalyticsFacetCloudTest {"o.unique.ff", "int_id","o.unique.ff", "long_ld"};- NamedList<Object> response = queryCloudAnalytics(params);+ NamedList<Object> response = queryLegacyCloudAnalytics(params);String responseStr = response.toString();//Int DateCollection<Long> intDate = getValueList(response, "uniquen", "fieldFacets", "date_dtd", "int", false);- ArrayList<Long> intDateTest = (ArrayList<Long>)calculateStat(intDateTestStart, "unique");+ ArrayList<Long> intDateTest = (ArrayList<Long>)calculateFacetedStat(intDateTestStart, "unique");assertEquals(responseStr,intDate,intDateTest);//Int StringCollection<Long> intString = getValueList(response, "uniquen", "fieldFacets", "string_sd", "int", false);- ArrayList<Long> intStringTest = (ArrayList<Long>)calculateStat(intStringTestStart, "unique");+ ArrayList<Long> intStringTest = (ArrayList<Long>)calculateFacetedStat(intStringTestStart, "unique");assertEquals(responseStr,intString,intStringTest);//Long DateCollection<Long> longDate = getValueList(response, "uniquen", "fieldFacets", "date_dtd", "long", false);- ArrayList<Long> longDateTest = (ArrayList<Long>)calculateStat(longDateTestStart, "unique");+ ArrayList<Long> longDateTest = (ArrayList<Long>)calculateFacetedStat(longDateTestStart, "unique");assertEquals(responseStr,longDate,longDateTest);//Long StringCollection<Long> longString = getValueList(response, "uniquen", "fieldFacets", "string_sd", "long", false);- ArrayList<Long> longStringTest = (ArrayList<Long>)calculateStat(longStringTestStart, "unique");+ ArrayList<Long> longStringTest = (ArrayList<Long>)calculateFacetedStat(longStringTestStart, "unique");assertEquals(responseStr,longString,longStringTest);//Float DateCollection<Long> floatDate = getValueList(response, "uniquen", "fieldFacets", "date_dtd", "float", false);- ArrayList<Long> floatDateTest = (ArrayList<Long>)calculateStat(floatDateTestStart, "unique");+ ArrayList<Long> floatDateTest = (ArrayList<Long>)calculateFacetedStat(floatDateTestStart, "unique");assertEquals(responseStr,floatDate,floatDateTest);//Float StringCollection<Long> floatString = getValueList(response, "uniquen", "fieldFacets", "string_sd", "float", false);- ArrayList<Long> floatStringTest = (ArrayList<Long>)calculateStat(floatStringTestStart, "unique");+ ArrayList<Long> floatStringTest = (ArrayList<Long>)calculateFacetedStat(floatStringTestStart, "unique");assertEquals(responseStr,floatString,floatStringTest);//Double DateCollection<Long> doubleDate = getValueList(response, "uniquen", "fieldFacets", "date_dtd", "double", false);- ArrayList<Long> doubleDateTest = (ArrayList<Long>)calculateStat(doubleDateTestStart, "unique");+ ArrayList<Long> doubleDateTest = (ArrayList<Long>)calculateFacetedStat(doubleDateTestStart, "unique");assertEquals(responseStr,doubleDate,doubleDateTest);//Double StringCollection<Long> doubleString = getValueList(response, "uniquen", "fieldFacets", "string_sd", "double", false);- ArrayList<Long> doubleStringTest = (ArrayList<Long>)calculateStat(doubleStringTestStart, "unique");+ ArrayList<Long> doubleStringTest = (ArrayList<Long>)calculateFacetedStat(doubleStringTestStart, "unique");assertEquals(responseStr,doubleString,doubleStringTest);//Date IntCollection<Long> dateInt = getValueList(response, "unique", "fieldFacets", "int_id", "date", false);- ArrayList<Long> dateIntTest = (ArrayList<Long>)calculateStat(dateIntTestStart, "unique");+ ArrayList<Long> dateIntTest = (ArrayList<Long>)calculateFacetedStat(dateIntTestStart, "unique");assertEquals(responseStr,dateInt,dateIntTest);//Date LongCollection<Long> dateString = getValueList(response, "unique", "fieldFacets", "long_ld", "date", false);- ArrayList<Long> dateLongTest = (ArrayList<Long>)calculateStat(dateLongTestStart, "unique");+ ArrayList<Long> dateLongTest = (ArrayList<Long>)calculateFacetedStat(dateLongTestStart, "unique");assertEquals(responseStr,dateString,dateLongTest);//String IntCollection<Long> stringInt = getValueList(response, "unique", "fieldFacets", "int_id", "str", false);- ArrayList<Long> stringIntTest = (ArrayList<Long>)calculateStat(stringIntTestStart, "unique");+ ArrayList<Long> stringIntTest = (ArrayList<Long>)calculateFacetedStat(stringIntTestStart, "unique");assertEquals(responseStr,stringInt,stringIntTest);//String LongCollection<Long> stringLong = getValueList(response, "unique", "fieldFacets", "long_ld", "str", false);- ArrayList<Long> stringLongTest = (ArrayList<Long>)calculateStat(stringLongTestStart, "unique");+ ArrayList<Long> stringLongTest = (ArrayList<Long>)calculateFacetedStat(stringLongTestStart, "unique");assertEquals(responseStr,stringLong,stringLongTest);}@@ -996,67 +996,67 @@ public class FieldFacetCloudTest extends AbstractAnalyticsFacetCloudTest {"o.count.ff", "int_id","o.count.ff", "long_ld"};- NamedList<Object> response = queryCloudAnalytics(params);+ NamedList<Object> response = queryLegacyCloudAnalytics(params);String responseStr = response.toString();//Int DateCollection<Long> intDate = getValueList(response, "countn", "fieldFacets", "date_dtd", "int", false);- ArrayList<Long> intDateTest = (ArrayList<Long>)calculateStat(intDateTestStart, "count");+ ArrayList<Long> intDateTest = (ArrayList<Long>)calculateFacetedStat(intDateTestStart, "count");assertEquals(responseStr,intDate,intDateTest);//Int StringCollection<Long> intString = getValueList(response, "countn", "fieldFacets", "string_sd", "int", false);- ArrayList<Long> intStringTest = (ArrayList<Long>)calculateStat(intStringTestStart, "count");+ ArrayList<Long> intStringTest = (ArrayList<Long>)calculateFacetedStat(intStringTestStart, "count");assertEquals(responseStr,intString,intStringTest);//Long DateCollection<Long> longDate = getValueList(response, "countn", "fieldFacets", "date_dtd", "long", false);- ArrayList<Long> longDateTest = (ArrayList<Long>)calculateStat(longDateTestStart, "count");+ ArrayList<Long> longDateTest = (ArrayList<Long>)calculateFacetedStat(longDateTestStart, "count");assertEquals(responseStr,longDate,longDateTest);//Long StringCollection<Long> longString = getValueList(response, "countn", "fieldFacets", "string_sd", "long", false);- ArrayList<Long> longStringTest = (ArrayList<Long>)calculateStat(longStringTestStart, "count");+ ArrayList<Long> longStringTest = (ArrayList<Long>)calculateFacetedStat(longStringTestStart, "count");assertEquals(responseStr,longString,longStringTest);//Float DateCollection<Long> floatDate = getValueList(response, "countn", "fieldFacets", "date_dtd", "float", false);- ArrayList<Long> floatDateTest = (ArrayList<Long>)calculateStat(floatDateTestStart, "count");+ ArrayList<Long> floatDateTest = (ArrayList<Long>)calculateFacetedStat(floatDateTestStart, "count");assertEquals(responseStr,floatDate,floatDateTest);//Float StringCollection<Long> floatString = getValueList(response, "countn", "fieldFacets", "string_sd", "float", false);- ArrayList<Long> floatStringTest = (ArrayList<Long>)calculateStat(floatStringTestStart, "count");+ ArrayList<Long> floatStringTest = (ArrayList<Long>)calculateFacetedStat(floatStringTestStart, "count");assertEquals(responseStr,floatString,floatStringTest);//Double DateCollection<Long> doubleDate = getValueList(response, "countn", "fieldFacets", "date_dtd", "double", false);- ArrayList<Long> doubleDateTest = (ArrayList<Long>)calculateStat(doubleDateTestStart, "count");+ ArrayList<Long> doubleDateTest = (ArrayList<Long>)calculateFacetedStat(doubleDateTestStart, "count");assertEquals(responseStr,doubleDate,doubleDateTest);//Double StringCollection<Long> doubleString = getValueList(response, "countn", "fieldFacets", "string_sd", "double", false);- ArrayList<Long> doubleStringTest = (ArrayList<Long>)calculateStat(doubleStringTestStart, "count");+ ArrayList<Long> doubleStringTest = (ArrayList<Long>)calculateFacetedStat(doubleStringTestStart, "count");assertEquals(responseStr,doubleString,doubleStringTest);//Date IntCollection<Long> dateInt = getValueList(response, "count", "fieldFacets", "int_id", "date", false);- ArrayList<Long> dateIntTest = (ArrayList<Long>)calculateStat(dateIntTestStart, "count");+ ArrayList<Long> dateIntTest = (ArrayList<Long>)calculateFacetedStat(dateIntTestStart, "count");assertEquals(responseStr,dateIntTest,dateInt);//Date LongCollection<Long> dateLong = getValueList(response, "count", "fieldFacets", "long_ld", "date", false);- ArrayList<Long> dateLongTest = (ArrayList<Long>)calculateStat(dateLongTestStart, "count");+ ArrayList<Long> dateLongTest = (ArrayList<Long>)calculateFacetedStat(dateLongTestStart, "count");assertEquals(responseStr,dateLong,dateLongTest);//String IntCollection<Long> stringInt = getValueList(response, "count", "fieldFacets", "int_id", "str", false);- ArrayList<Long> stringIntTest = (ArrayList<Long>)calculateStat(stringIntTestStart, "count");+ ArrayList<Long> stringIntTest = (ArrayList<Long>)calculateFacetedStat(stringIntTestStart, "count");assertEquals(responseStr,stringInt,stringIntTest);//String LongCollection<Long> stringLong = getValueList(response, "count", "fieldFacets", "long_ld", "str", false);- ArrayList<Long> stringLongTest = (ArrayList<Long>)calculateStat(stringLongTestStart, "count");+ ArrayList<Long> stringLongTest = (ArrayList<Long>)calculateFacetedStat(stringLongTestStart, "count");assertEquals(responseStr,stringLong,stringLongTest);}@@ -1075,7 +1075,7 @@ public class FieldFacetCloudTest extends AbstractAnalyticsFacetCloudTest {"o.missing.ff", "int_id","o.missing.ff", "long_ld"};- NamedList<Object> response = queryCloudAnalytics(params);+ NamedList<Object> response = queryLegacyCloudAnalytics(params);String responseStr = response.toString();//Int Date@@ -1142,20 +1142,20 @@ public class FieldFacetCloudTest extends AbstractAnalyticsFacetCloudTest {"o.multivalued.ff", "string_sdm","o.multivalued.ff", "date_dtdm"};- NamedList<Object> response = queryCloudAnalytics(params);+ NamedList<Object> response = queryLegacyCloudAnalytics(params);String responseStr = response.toString();//LongCollection<Double> lon = getValueList(response, "multivalued", "fieldFacets", "long_ldm", "mean", false);- ArrayList<Double> longTest = calculateNumberStat(multiLongTestStart, "mean");+ ArrayList<Double> longTest = calculateFacetedNumberStat(multiLongTestStart, "mean");assertEquals(responseStr,lon,longTest);//DateCollection<Double> date = getValueList(response, "multivalued", "fieldFacets", "date_dtdm", "mean", false);- ArrayList<Double> dateTest = calculateNumberStat(multiDateTestStart, "mean");+ ArrayList<Double> dateTest = calculateFacetedNumberStat(multiDateTestStart, "mean");assertEquals(responseStr,date,dateTest);//StringCollection<Double> string = getValueList(response, "multivalued", "fieldFacets", "string_sdm", "mean", false);- ArrayList<Double> stringTest = calculateNumberStat(multiStringTestStart, "mean");+ ArrayList<Double> stringTest = calculateFacetedNumberStat(multiStringTestStart, "mean");assertEquals(responseStr,string,stringTest);}@@ -1170,26 +1170,26 @@ public class FieldFacetCloudTest extends AbstractAnalyticsFacetCloudTest {"o.missingf.ff", "date_dtdm","o.missingf.ff.date_dtdm.sm", "true"};- NamedList<Object> response = queryCloudAnalytics(params);+ NamedList<Object> response = queryLegacyCloudAnalytics(params);String responseStr = response.toString();//int MultiDateassertTrue(responseStr, responseContainsFacetValue(response, "missingf", "fieldFacets", "date_dtdm", "(MISSING)"));ArrayList<Double> string = getValueList(response, "missingf", "fieldFacets", "date_dtdm", "mean", false);- ArrayList<Double> stringTest = calculateNumberStat(multiDateTestStart, "mean");+ ArrayList<Double> stringTest = calculateFacetedNumberStat(multiDateTestStart, "mean");assertEquals(responseStr, string,stringTest);//Int StringassertTrue(responseStr, responseContainsFacetValue(response, "missingf", "fieldFacets", "string_sd", "(MISSING)"));assertTrue(responseStr, !responseContainsFacetValue(response, "missingf", "fieldFacets", "string_sd", "str0"));List<Double> intString = getValueList(response, "missingf", "fieldFacets", "string_sd", "mean", false);- ArrayList<Double> intStringTest = calculateNumberStat(intStringTestStart, "mean");+ ArrayList<Double> intStringTest = calculateFacetedNumberStat(intStringTestStart, "mean");assertEquals(responseStr, intString,intStringTest);//Int DateCollection<Double> intDate = getValueList(response, "missingf", "fieldFacets", "date_dtd", "mean", false);ArrayList<ArrayList<Double>> intDateMissingTestStart = (ArrayList<ArrayList<Double>>) intDateTestStart.clone();- ArrayList<Double> intDateTest = calculateNumberStat(intDateMissingTestStart, "mean");+ ArrayList<Double> intDateTest = calculateFacetedNumberStat(intDateMissingTestStart, "mean");assertEquals(responseStr,intDate,intDateTest);}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/FieldFacetExtrasCloudTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyFieldFacetExtrasCloudTest.javasimilarity index 92%rename from solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/FieldFacetExtrasCloudTest.javarename to solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyFieldFacetExtrasCloudTest.javaindex 427b50da98b..808269a3864 100644--- a/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/FieldFacetExtrasCloudTest.java+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyFieldFacetExtrasCloudTest.java@@ -14,7 +14,7 @@* See the License for the specific language governing permissions and* limitations under the License.*/-package org.apache.solr.analytics.facet;+package org.apache.solr.analytics.legacy.facet;import java.util.ArrayList;@@ -27,7 +27,7 @@ import org.apache.solr.common.util.NamedList;import org.junit.BeforeClass;import org.junit.Test;-public class FieldFacetExtrasCloudTest extends AbstractAnalyticsFacetCloudTest {+public class LegacyFieldFacetExtrasCloudTest extends LegacyAbstractAnalyticsFacetCloudTest {public static final int INT = 21;public static final int LONG = 22;public static final int FLOAT = 23;@@ -44,7 +44,7 @@ public class FieldFacetExtrasCloudTest extends AbstractAnalyticsFacetCloudTest {@BeforeClasspublic static void beforeClass() throws Exception {- setupCluster();+ cleanIndex();//INTintLongTestStart = new ArrayList<>();@@ -134,7 +134,7 @@ public class FieldFacetExtrasCloudTest extends AbstractAnalyticsFacetCloudTest {"o.lr.ff.string_sd.limit", "1"};- NamedList<Object> response = queryCloudAnalytics(params);+ NamedList<Object> response = queryLegacyCloudAnalytics(params);String responseStr = response.toString();Collection<Double> lon = getValueList(response, "lr", "fieldFacets", "long_ld", "mean", false);@@ -178,7 +178,7 @@ public class FieldFacetExtrasCloudTest extends AbstractAnalyticsFacetCloudTest {"o.off2.ff.long_ld.offset", "4"};- NamedList<Object> response = queryCloudAnalytics(params);+ NamedList<Object> response = queryLegacyCloudAnalytics(params);String responseStr = response.toString();Collection<Double> lon;@@ -226,26 +226,26 @@ public class FieldFacetExtrasCloudTest extends AbstractAnalyticsFacetCloudTest {"o.sr.ff.string_sd.sd", "desc"};- NamedList<Object> response = queryCloudAnalytics(params);+ NamedList<Object> response = queryLegacyCloudAnalytics(params);String responseStr = response.toString();Collection<Double> lon = getValueList(response, "sr", "fieldFacets", "long_ld", "mean", false);- ArrayList<Double> longTest = calculateNumberStat(intLongTestStart, "mean");+ ArrayList<Double> longTest = calculateFacetedNumberStat(intLongTestStart, "mean");Collections.sort(longTest);assertEquals(responseStr, longTest,lon);Collection<Double> flo = getValueList(response, "sr", "fieldFacets", "float_fd", "median", false);- ArrayList<Double> floatTest = calculateNumberStat(intFloatTestStart, "median");+ ArrayList<Double> floatTest = calculateFacetedNumberStat(intFloatTestStart, "median");Collections.sort(floatTest,Collections.reverseOrder());assertEquals(responseStr, floatTest,flo);Collection<Long> doub = getValueList(response, "sr", "fieldFacets", "double_dd", "count", false);- ArrayList<Long> doubleTest = (ArrayList<Long>)calculateStat(intDoubleTestStart, "count");+ ArrayList<Long> doubleTest = (ArrayList<Long>)calculateFacetedStat(intDoubleTestStart, "count");Collections.sort(doubleTest);assertEquals(responseStr, doubleTest,doub);Collection<Integer> string = getValueList(response, "sr", "fieldFacets", "string_sd", "percentile_20", false);- ArrayList<Integer> stringTest = (ArrayList<Integer>)calculateStat(intStringTestStart, "perc_20");+ ArrayList<Integer> stringTest = (ArrayList<Integer>)calculateFacetedStat(intStringTestStart, "perc_20");Collections.sort(stringTest,Collections.reverseOrder());assertEquals(responseStr, stringTest,string);}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/FieldFacetExtrasTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyFieldFacetExtrasTest.javasimilarity index 96%rename from solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/FieldFacetExtrasTest.javarename to solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyFieldFacetExtrasTest.javaindex a7e0012e61e..ac3046c55e1 100644--- a/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/FieldFacetExtrasTest.java+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyFieldFacetExtrasTest.java@@ -14,7 +14,7 @@* See the License for the specific language governing permissions and* limitations under the License.*/-package org.apache.solr.analytics.facet;+package org.apache.solr.analytics.legacy.facet;import java.util.ArrayList;@@ -25,7 +25,7 @@ import java.util.List;import org.junit.BeforeClass;import org.junit.Test;-public class FieldFacetExtrasTest extends AbstractAnalyticsFacetTest {+public class LegacyFieldFacetExtrasTest extends LegacyAbstractAnalyticsFacetTest {static String fileName = "fieldFacetExtras.txt";public static final int INT = 21;@@ -101,7 +101,7 @@ public class FieldFacetExtrasTest extends AbstractAnalyticsFacetTest {}assertU(commit());- setResponse(h.query(request(fileToStringArr(FieldFacetExtrasTest.class, fileName))));+ setResponse(h.query(request(fileToStringArr(LegacyFieldFacetExtrasTest.class, fileName))));}@Testdiff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/FieldFacetTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyFieldFacetTest.javasimilarity index 99%rename from solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/FieldFacetTest.javarename to solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyFieldFacetTest.javaindex d30413ef390..92eb7ed5eab 100644--- a/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/FieldFacetTest.java+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyFieldFacetTest.java@@ -14,7 +14,7 @@* See the License for the specific language governing permissions and* limitations under the License.*/-package org.apache.solr.analytics.facet;+package org.apache.solr.analytics.legacy.facet;import java.util.ArrayList;import java.util.Collection;@@ -27,7 +27,7 @@ import org.junit.Test;import org.w3c.dom.Node;-public class FieldFacetTest extends AbstractAnalyticsFacetTest{+public class LegacyFieldFacetTest extends LegacyAbstractAnalyticsFacetTest{static String fileName = "fieldFacets.txt";public static final int INT = 71;@@ -409,7 +409,7 @@ public class FieldFacetTest extends AbstractAnalyticsFacetTest{}assertU(commit());- String[] reqFacetParamas = fileToStringArr(FieldFacetTest.class, fileName);+ String[] reqFacetParamas = fileToStringArr(LegacyFieldFacetTest.class, fileName);String[] reqParamas = new String[reqFacetParamas.length + 2];System.arraycopy(reqFacetParamas, 0, reqParamas, 0, reqFacetParamas.length);reqParamas[reqFacetParamas.length] = "solr";diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/QueryFacetCloudTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyQueryFacetCloudTest.javasimilarity index 89%rename from solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/QueryFacetCloudTest.javarename to solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyQueryFacetCloudTest.javaindex 42b5abe6cc0..4c78a43cfd8 100644--- a/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/QueryFacetCloudTest.java+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyQueryFacetCloudTest.java@@ -14,7 +14,7 @@* See the License for the specific language governing permissions and* limitations under the License.*/-package org.apache.solr.analytics.facet;+package org.apache.solr.analytics.legacy.facet;import java.util.ArrayList;@@ -25,7 +25,7 @@ import org.apache.solr.common.util.NamedList;import org.junit.BeforeClass;import org.junit.Test;-public class QueryFacetCloudTest extends AbstractAnalyticsFacetCloudTest {+public class LegacyQueryFacetCloudTest extends LegacyAbstractAnalyticsFacetCloudTest {private static final int INT = 71;private static final int LONG = 36;private static final int FLOAT = 93;@@ -41,7 +41,7 @@ public class QueryFacetCloudTest extends AbstractAnalyticsFacetCloudTest {@BeforeClasspublic static void beforeClass() throws Exception {- setupCluster();+ cleanIndex();//INTint1TestStart.add(new ArrayList<Integer>());@@ -133,26 +133,26 @@ public class QueryFacetCloudTest extends AbstractAnalyticsFacetCloudTest {"o.fr.qf.lad.q", "double_dd:[* TO 50]"};- NamedList<Object> response = queryCloudAnalytics(params);+ NamedList<Object> response = queryLegacyCloudAnalytics(params);String responseStr = response.toString();//Int OneArrayList<Double> int1 = getValueList(response, "ir", "queryFacets", "float1", "sum", false);- ArrayList<Double> int1Test = calculateNumberStat(int1TestStart, "sum");+ ArrayList<Double> int1Test = calculateFacetedNumberStat(int1TestStart, "sum");assertEquals(responseStr, int1, int1Test);//Int TwoArrayList<Integer> int2 = getValueList(response, "ir", "queryFacets", "float2", "percentile_8", false);- ArrayList<Integer> int2Test = (ArrayList<Integer>)calculateStat(int2TestStart, "perc_8");+ ArrayList<Integer> int2Test = (ArrayList<Integer>)calculateFacetedStat(int2TestStart, "perc_8");assertEquals(responseStr, int2, int2Test);//LongArrayList<Double> long1 = getValueList(response, "lr", "queryFacets", "string", "median", false);- ArrayList<Double> long1Test = calculateNumberStat(longTestStart, "median");+ ArrayList<Double> long1Test = calculateFacetedNumberStat(longTestStart, "median");assertEquals(responseStr,long1,long1Test);//FloatArrayList<Double> float1 = getValueList(response, "fr", "queryFacets", "lad", "mean", false);- ArrayList<Double> float1Test = calculateNumberStat(floatTestStart, "mean");+ ArrayList<Double> float1Test = calculateFacetedNumberStat(floatTestStart, "mean");assertEquals(responseStr, float1, float1Test);}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyQueryFacetTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyQueryFacetTest.javanew file mode 100644index 00000000000..62ebc3bb9b0--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyQueryFacetTest.java@@ -0,0 +1,124 @@+/*+ * 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.analytics.legacy.facet;+++import java.util.ArrayList;++import org.junit.BeforeClass;+import org.junit.Test;++public class LegacyQueryFacetTest extends LegacyAbstractAnalyticsFacetTest {+ static String fileName = "queryFacets.txt";++ public final int INT = 71;+ public final int LONG = 36;+ public final int FLOAT = 93;+ public final int DOUBLE = 49;+ public final int DATE = 12;+ public final int STRING = 28;+ public final int NUM_LOOPS = 100;++ @BeforeClass+ public static void beforeClass() throws Exception {+ initCore("solrconfig-analytics.xml","schema-analytics.xml");+ }++ @SuppressWarnings("unchecked")+ @Test+ public void queryTest() throws Exception {+ h.update("<delete><query>*:*</query></delete>");+ //INT+ ArrayList<ArrayList<Integer>> int1TestStart = new ArrayList<>();+ int1TestStart.add(new ArrayList<Integer>());+ ArrayList<ArrayList<Integer>> int2TestStart = new ArrayList<>();+ int2TestStart.add(new ArrayList<Integer>());++ //LONG+ ArrayList<ArrayList<Long>> longTestStart = new ArrayList<>();+ longTestStart.add(new ArrayList<Long>());+ longTestStart.add(new ArrayList<Long>());++ //FLOAT+ ArrayList<ArrayList<Float>> floatTestStart = new ArrayList<>();+ floatTestStart.add(new ArrayList<Float>());+ floatTestStart.add(new ArrayList<Float>());+ floatTestStart.add(new ArrayList<Float>());++ for (int j = 0; j < NUM_LOOPS; ++j) {+ int i = j%INT;+ long l = j%LONG;+ float f = j%FLOAT;+ double d = j%DOUBLE;+ int dt = j%DATE;+ int s = j%STRING;+ assertU(adoc("id", "1000" + j, "int_id", "" + i, "long_ld", "" + l, "float_fd", "" + f,+ "double_dd", "" + d, "date_dtd", (1800+dt) + "-12-31T23:59:59.999Z", "string_sd", "abc" + new Integer(s).toString().charAt(0)));++ if (f<=50) {+ int1TestStart.get(0).add(i);+ }+ if (f<=30) {+ int2TestStart.get(0).add(i);+ }+ if (new Integer(s).toString().charAt(0)=='1') {+ longTestStart.get(0).add(l);+ }+ if (new Integer(s).toString().charAt(0)=='2') {+ longTestStart.get(1).add(l);+ }+ if (l>=30) {+ floatTestStart.get(0).add(f);+ }+ if (d<=50) {+ floatTestStart.get(1).add(f);+ }+ if (l>=20) {+ floatTestStart.get(2).add(f);+ }++ if (usually()) {+ assertU(commit()); // to have several segments+ }+ }++ assertU(commit());++ //Query ascending tests+ setResponse(h.query(request(fileToStringArr(LegacyQueryFacetTest.class, fileName))));++ //Int One+ ArrayList<Double> int1 = getDoubleList("ir", "queryFacets", "float1", "double", "sum");+ ArrayList<Double> int1Test = calculateNumberStat(int1TestStart, "sum");+ assertEquals(getRawResponse(), int1, int1Test);+ //Int Two+ ArrayList<Integer> int2 = getIntegerList("ir", "queryFacets", "float2", "int", "percentile_8");+ ArrayList<Integer> int2Test = (ArrayList<Integer>)calculateStat(int2TestStart, "perc_8");+ assertEquals(getRawResponse(), int2, int2Test);++ //Long+ ArrayList<Double> long1 = getDoubleList("lr", "queryFacets", "string", "double", "median");+ ArrayList<Double> long1Test = calculateNumberStat(longTestStart, "median");+ assertEquals(getRawResponse(),long1,long1Test);++ //Float+ ArrayList<Double> float1 = getDoubleList("fr", "queryFacets", "lad", "double", "mean");+ ArrayList<Double> float1Test = calculateNumberStat(floatTestStart, "mean");+ assertEquals(getRawResponse(), float1, float1Test);+ }++}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/RangeFacetCloudTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyRangeFacetCloudTest.javasimilarity index 92%rename from solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/RangeFacetCloudTest.javarename to solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyRangeFacetCloudTest.javaindex 880324d2bf7..95585c42380 100644--- a/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/RangeFacetCloudTest.java+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyRangeFacetCloudTest.java@@ -14,7 +14,7 @@* See the License for the specific language governing permissions and* limitations under the License.*/-package org.apache.solr.analytics.facet;+package org.apache.solr.analytics.legacy.facet;import java.util.ArrayList;import java.util.List;@@ -25,7 +25,7 @@ import org.junit.BeforeClass;import org.junit.Test;-public class RangeFacetCloudTest extends AbstractAnalyticsFacetCloudTest{+public class LegacyRangeFacetCloudTest extends LegacyAbstractAnalyticsFacetCloudTest{public static final int INT = 71;public static final int LONG = 36;public static final int FLOAT = 93;@@ -46,7 +46,7 @@ public class RangeFacetCloudTest extends AbstractAnalyticsFacetCloudTest{@BeforeClasspublic static void beforeClass() throws Exception {- setupCluster();+ cleanIndex();//INTintLongTestStart = new ArrayList<>();@@ -174,33 +174,33 @@ public class RangeFacetCloudTest extends AbstractAnalyticsFacetCloudTest{"o.rf.rf.date_dtd.or", "all"};- NamedList<Object> response = queryCloudAnalytics(params);+ NamedList<Object> response = queryLegacyCloudAnalytics(params);String responseStr = response.toString();//Int LongArrayList<Long> intLong = getValueList(response, "ri", "rangeFacets", "long_ld", "count", false);- ArrayList<Long> intLongTest = calculateStat(transformLists(intLongTestStart, 5, 30, 5+ ArrayList<Long> intLongTest = calculateFacetedStat(transformLists(intLongTestStart, 5, 30, 5, false, true, false, false, false), "count");assertEquals(responseStr, intLong,intLongTest);//Int DoubleArrayList<Double> intDouble = getValueList(response, "ri", "rangeFacets", "double_dd", "mean", false);- ArrayList<Double> intDoubleTest = calculateNumberStat(transformLists(intDoubleTestStart, 3, 39, 7+ ArrayList<Double> intDoubleTest = calculateFacetedNumberStat(transformLists(intDoubleTestStart, 3, 39, 7, false, false, true, false, true), "mean");assertEquals(responseStr, intDouble,intDoubleTest);//Int DateArrayList<Long> intDate = getValueList(response, "ri", "rangeFacets", "date_dtd", "count", false);- ArrayList<Long> intDateTest = (ArrayList<Long>)calculateStat(transformLists(intDateTestStart, 7, 44, 7+ ArrayList<Long> intDateTest = (ArrayList<Long>)calculateFacetedStat(transformLists(intDateTestStart, 7, 44, 7, false, true, false, true, true), "count");assertEquals(responseStr, intDate,intDateTest);//Float LongArrayList<Double> floatLong = getValueList(response, "rf", "rangeFacets", "long_ld", "median", false);- ArrayList<Double> floatLongTest = calculateNumberStat(transformLists(floatLongTestStart, 0, 29, 4+ ArrayList<Double> floatLongTest = calculateFacetedNumberStat(transformLists(floatLongTestStart, 0, 29, 4, false, true, true, true, true), "median");assertEquals(responseStr, floatLong,floatLongTest);//Float DoubleArrayList<Long> floatDouble = getValueList(response, "rf", "rangeFacets", "double_dd", "count", false);- ArrayList<Long> floatDoubleTest = (ArrayList<Long>)calculateStat(transformLists(floatDoubleTestStart, 4, 47, 11+ ArrayList<Long> floatDoubleTest = (ArrayList<Long>)calculateFacetedStat(transformLists(floatDoubleTestStart, 4, 47, 11, false, false, false, true, false), "count");assertEquals(responseStr, floatDouble,floatDoubleTest);}@@ -266,33 +266,33 @@ public class RangeFacetCloudTest extends AbstractAnalyticsFacetCloudTest{"o.hf.rf.date_dtd.ib", "edge","o.hf.rf.date_dtd.or", "all"};- NamedList<Object> response = queryCloudAnalytics(params);+ NamedList<Object> response = queryLegacyCloudAnalytics(params);String responseStr = response.toString();//Int LongArrayList<Double> intLong = getValueList(response, "hi", "rangeFacets", "long_ld", "sum", false);- ArrayList<Double> intLongTest = calculateNumberStat(transformLists(intLongTestStart, 5, 30, 5+ ArrayList<Double> intLongTest = calculateFacetedNumberStat(transformLists(intLongTestStart, 5, 30, 5, true, true, false, false, false), "sum");assertEquals(responseStr, intLong,intLongTest);//Int DoubleArrayList<Double> intDouble = getValueList(response, "hi", "rangeFacets", "double_dd", "mean", false);- ArrayList<Double> intDoubleTest = calculateNumberStat(transformLists(intDoubleTestStart, 3, 39, 7+ ArrayList<Double> intDoubleTest = calculateFacetedNumberStat(transformLists(intDoubleTestStart, 3, 39, 7, true, false, true, false, true), "mean");assertEquals(responseStr, intDouble,intDoubleTest);//Int DateArrayList<Long> intDate = getValueList(response, "hi", "rangeFacets", "date_dtd", "count", false);- ArrayList<Long> intDateTest = (ArrayList<Long>)calculateStat(transformLists(intDateTestStart, 7, 44, 7+ ArrayList<Long> intDateTest = (ArrayList<Long>)calculateFacetedStat(transformLists(intDateTestStart, 7, 44, 7, true, true, false, true, true), "count");assertEquals(responseStr, intDate,intDateTest);//Float LongArrayList<Double> floatLong = getValueList(response, "hf", "rangeFacets", "long_ld", "median", false);- ArrayList<Double> floatLongTest = calculateNumberStat(transformLists(floatLongTestStart, 0, 29, 4+ ArrayList<Double> floatLongTest = calculateFacetedNumberStat(transformLists(floatLongTestStart, 0, 29, 4, true, true, true, true, true), "median");assertEquals(responseStr, floatLong,floatLongTest);//Float DoubleArrayList<Long> floatDouble = getValueList(response, "hf", "rangeFacets", "double_dd", "count", false);- ArrayList<Long> floatDoubleTest = (ArrayList<Long>)calculateStat(transformLists(floatDoubleTestStart, 4, 47, 11+ ArrayList<Long> floatDoubleTest = (ArrayList<Long>)calculateFacetedStat(transformLists(floatDoubleTestStart, 4, 47, 11, true, false, false, true, false), "count");assertEquals(responseStr, floatDouble,floatDoubleTest);}@@ -351,33 +351,33 @@ public class RangeFacetCloudTest extends AbstractAnalyticsFacetCloudTest{"o.mf.rf.date_dtd.ib", "edge","o.mf.rf.date_dtd.or", "all"};- NamedList<Object> response = queryCloudAnalytics(params);+ NamedList<Object> response = queryLegacyCloudAnalytics(params);String responseStr = response.toString();//Int LongArrayList<Double> intLong = getValueList(response, "mi", "rangeFacets", "long_ld", "sum", false);- ArrayList<Double> intLongTest = calculateNumberStat(transformLists(intLongTestStart, 5, 30, "4,2,6,3"+ ArrayList<Double> intLongTest = calculateFacetedNumberStat(transformLists(intLongTestStart, 5, 30, "4,2,6,3", false, true, false, false, false), "sum");assertEquals(responseStr, intLong,intLongTest);//Int DoubleArrayList<Double> intDouble = getValueList(response, "mi", "rangeFacets", "double_dd", "mean", false);- ArrayList<Double> intDoubleTest = calculateNumberStat(transformLists(intDoubleTestStart, 3, 39, "3,1,7"+ ArrayList<Double> intDoubleTest = calculateFacetedNumberStat(transformLists(intDoubleTestStart, 3, 39, "3,1,7", false, false, true, false, true), "mean");assertEquals(responseStr, intDouble,intDoubleTest);//Int DateArrayList<Long> intDate = getValueList(response, "mi", "rangeFacets", "date_dtd", "count", false);- ArrayList<Long> intDateTest = (ArrayList<Long>)calculateStat(transformLists(intDateTestStart, 7, 44, "2,7"+ ArrayList<Long> intDateTest = (ArrayList<Long>)calculateFacetedStat(transformLists(intDateTestStart, 7, 44, "2,7", false, true, false, true, true), "count");assertEquals(responseStr, intDate,intDateTest);//Float LongArrayList<Double> floatLong = getValueList(response, "mf", "rangeFacets", "long_ld", "median", false);- ArrayList<Double> floatLongTest = calculateNumberStat(transformLists(floatLongTestStart, 0, 29, "1,4"+ ArrayList<Double> floatLongTest = calculateFacetedNumberStat(transformLists(floatLongTestStart, 0, 29, "1,4", false, true, true, true, true), "median");;assertEquals(responseStr, floatLong,floatLongTest);//Float DoubleArrayList<Long> floatDouble = getValueList(response, "mf", "rangeFacets", "double_dd", "count", false);- ArrayList<Long> floatDoubleTest = (ArrayList<Long>)calculateStat(transformLists(floatDoubleTestStart, 4, 47, "2,3,11"+ ArrayList<Long> floatDoubleTest = (ArrayList<Long>)calculateFacetedStat(transformLists(floatDoubleTestStart, 4, 47, "2,3,11", false, false, false, true, false), "count");assertEquals(responseStr, floatDouble,floatDoubleTest);}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyRangeFacetTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyRangeFacetTest.javanew file mode 100644index 00000000000..329645e5e3c--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyRangeFacetTest.java@@ -0,0 +1,417 @@+/*+ * 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.analytics.legacy.facet;+++import java.util.ArrayList;++import org.junit.BeforeClass;+import org.junit.Test;+++public class LegacyRangeFacetTest extends LegacyAbstractAnalyticsFacetTest {+ static String fileName = "rangeFacets.txt";++ public static final int INT = 71;+ public static final int LONG = 36;+ public static final int FLOAT = 93;+ public static final int DOUBLE = 48;+ public static final int DATE = 52;+ public static final int STRING = 28;+ public static final int NUM_LOOPS = 100;++ //INT+ static ArrayList<ArrayList<Integer>> intLongTestStart;+ static ArrayList<ArrayList<Integer>> intDoubleTestStart;+ static ArrayList<ArrayList<Integer>> intDateTestStart;++ //FLOAT+ static ArrayList<ArrayList<Float>> floatLongTestStart;+ static ArrayList<ArrayList<Float>> floatDoubleTestStart;+ static ArrayList<ArrayList<Float>> floatDateTestStart;++ @BeforeClass+ public static void beforeClass() throws Exception {+ initCore("solrconfig-analytics.xml","schema-analytics.xml");+ h.update("<delete><query>*:*</query></delete>");++ //INT+ intLongTestStart = new ArrayList<>();+ intDoubleTestStart = new ArrayList<>();+ intDateTestStart = new ArrayList<>();++ //FLOAT+ floatLongTestStart = new ArrayList<>();+ floatDoubleTestStart = new ArrayList<>();+ floatDateTestStart = new ArrayList<>();++ for (int j = 0; j < NUM_LOOPS; ++j) {+ int i = j%INT;+ long l = j%LONG;+ float f = j%FLOAT;+ double d = j%DOUBLE;+ int dt = j%DATE;+ int s = j%STRING;+ assertU(adoc("id", "1000" + j, "int_id", "" + i, "long_ld", "" + l, "float_fd", "" + f,+ "double_dd", "" + d, "date_dtd", (1000+dt) + "-01-01T23:59:59Z", "string_sd", "abc" + s));+ //Longs+ if (j-LONG<0) {+ ArrayList<Integer> list1 = new ArrayList<>();+ list1.add(i);+ intLongTestStart.add(list1);+ ArrayList<Float> list2 = new ArrayList<>();+ list2.add(f);+ floatLongTestStart.add(list2);+ } else {+ intLongTestStart.get((int)l).add(i);+ floatLongTestStart.get((int)l).add(f);+ }+ //Doubles+ if (j-DOUBLE<0) {+ ArrayList<Integer> list1 = new ArrayList<>();+ list1.add(i);+ intDoubleTestStart.add(list1);+ ArrayList<Float> list2 = new ArrayList<>();+ list2.add(f);+ floatDoubleTestStart.add(list2);+ } else {+ intDoubleTestStart.get((int)d).add(i);+ floatDoubleTestStart.get((int)d).add(f);+ }+ //Dates+ if (j-DATE<0) {+ ArrayList<Integer> list1 = new ArrayList<>();+ list1.add(i);+ intDateTestStart.add(list1);+ ArrayList<Float> list2 = new ArrayList<>();+ list2.add(f);+ floatDateTestStart.add(list2);+ } else {+ intDateTestStart.get(dt).add(i);+ floatDateTestStart.get(dt).add(f);+ }++ if (usually()) {+ assertU(commit()); // to have several segments+ }+ }++ assertU(commit());++ setResponse(h.query(request(fileToStringArr(LegacyRangeFacetTest.class, fileName))));+ }++ @SuppressWarnings("unchecked")+ @Test+ public void rangeTest() throws Exception {++ //Int Long+ ArrayList<Long> intLong = getLongList("ri", "rangeFacets", "long_ld", "long", "count");+ ArrayList<Long> intLongTest = calculateStat(transformLists(intLongTestStart, 5, 30, 5+ , false, true, false, false, false), "count");+ assertEquals(getRawResponse(), intLong,intLongTest);+ //Int Double+ ArrayList<Double> intDouble = getDoubleList("ri", "rangeFacets", "double_dd", "double", "mean");+ ArrayList<Double> intDoubleTest = calculateNumberStat(transformLists(intDoubleTestStart, 3, 39, 7+ , false, false, true, false, true), "mean");+ assertEquals(getRawResponse(), intDouble,intDoubleTest);+ //Int Date+ ArrayList<Long> intDate = getLongList("ri", "rangeFacets", "date_dtd", "long", "count");+ ArrayList<Long> intDateTest = (ArrayList<Long>)calculateStat(transformLists(intDateTestStart, 7, 44, 7+ , false, true, false, true, true), "count");+ assertEquals(getRawResponse(), intDate,intDateTest);++ //Float Long+ ArrayList<Double> floatLong = getDoubleList("rf", "rangeFacets", "long_ld", "double", "median");+ ArrayList<Double> floatLongTest = calculateNumberStat(transformLists(floatLongTestStart, 0, 29, 4+ , false, true, true, true, true), "median");+ assertEquals(getRawResponse(), floatLong,floatLongTest);+ //Float Double+ ArrayList<Long> floatDouble = getLongList("rf", "rangeFacets", "double_dd", "long", "count");+ ArrayList<Long> floatDoubleTest = (ArrayList<Long>)calculateStat(transformLists(floatDoubleTestStart, 4, 47, 11+ , false, false, false, true, false), "count");+ assertEquals(getRawResponse(), floatDouble,floatDoubleTest);+ }+++ @SuppressWarnings("unchecked")+ @Test+ public void hardendRangeTest() throws Exception {+ //Int Long+ ArrayList<Double> intLong = getDoubleList("hi", "rangeFacets", "long_ld", "double", "sum");+ ArrayList<Double> intLongTest = calculateNumberStat(transformLists(intLongTestStart, 5, 30, 5+ , true, true, false, false, false), "sum");+ assertEquals(getRawResponse(), intLong,intLongTest);+ //Int Double+ ArrayList<Double> intDouble = getDoubleList("hi", "rangeFacets", "double_dd", "double", "mean");+ ArrayList<Double> intDoubleTest = calculateNumberStat(transformLists(intDoubleTestStart, 3, 39, 7+ , true, false, true, false, true), "mean");+ assertEquals(getRawResponse(), intDouble,intDoubleTest);+ //Int Date+ ArrayList<Long> intDate = getLongList("hi", "rangeFacets", "date_dtd", "long", "count");+ ArrayList<Long> intDateTest = (ArrayList<Long>)calculateStat(transformLists(intDateTestStart, 7, 44, 7+ , true, true, false, true, true), "count");+ assertEquals(getRawResponse(), intDate,intDateTest);++ //Float Long+ ArrayList<Double> floatLong = getDoubleList("hf", "rangeFacets", "long_ld", "double", "median");+ ArrayList<Double> floatLongTest = calculateNumberStat(transformLists(floatLongTestStart, 0, 29, 4+ , true, true, true, true, true), "median");+ assertEquals(getRawResponse(), floatLong,floatLongTest);+ //Float Double+ ArrayList<Long> floatDouble = getLongList("hf", "rangeFacets", "double_dd", "long", "count");+ ArrayList<Long> floatDoubleTest = (ArrayList<Long>)calculateStat(transformLists(floatDoubleTestStart, 4, 47, 11+ , true, false, false, true, false), "count");+ assertEquals(getRawResponse(), floatDouble,floatDoubleTest);+ }++ @SuppressWarnings("unchecked")+ @Test+ public void multiGapTest() throws Exception {+ //Int Long+ ArrayList<Double> intLong = getDoubleList("mi", "rangeFacets", "long_ld", "double", "sum");+ ArrayList<Double> intLongTest = calculateNumberStat(transformLists(intLongTestStart, 5, 30, "4,2,6,3"+ , false, true, false, false, false), "sum");+ assertEquals(getRawResponse(), intLong,intLongTest);+ //Int Double+ ArrayList<Double> intDouble = getDoubleList("mi", "rangeFacets", "double_dd", "double", "mean");+ ArrayList<Double> intDoubleTest = calculateNumberStat(transformLists(intDoubleTestStart, 3, 39, "3,1,7"+ , false, false, true, false, true), "mean");+ assertEquals(getRawResponse(), intDouble,intDoubleTest);+ //Int Date+ ArrayList<Long> intDate = getLongList("mi", "rangeFacets", "date_dtd", "long", "count");+ ArrayList<Long> intDateTest = (ArrayList<Long>)calculateStat(transformLists(intDateTestStart, 7, 44, "2,7"+ , false, true, false, true, true), "count");+ assertEquals(getRawResponse(), intDate,intDateTest);++ //Float Long+ ArrayList<Double> floatLong = getDoubleList("mf", "rangeFacets", "long_ld", "double", "median");+ ArrayList<Double> floatLongTest = calculateNumberStat(transformLists(floatLongTestStart, 0, 29, "1,4"+ , false, true, true, true, true), "median");;+ assertEquals(getRawResponse(), floatLong,floatLongTest);+ //Float Double+ ArrayList<Long> floatDouble = getLongList("mf", "rangeFacets", "double_dd", "long", "count");+ ArrayList<Long> floatDoubleTest = (ArrayList<Long>)calculateStat(transformLists(floatDoubleTestStart, 4, 47, "2,3,11"+ , false, false, false, true, false), "count");+ assertEquals(getRawResponse(), floatDouble,floatDoubleTest);+ }++ private <T> ArrayList<ArrayList<T>> transformLists(ArrayList<ArrayList<T>> listsStart, int start, int end, int gap+ , boolean hardend, boolean incLow, boolean incUp, boolean incEdge, boolean incOut) {+ int off = (end-start)%gap;+ if (!hardend && off>0) {+ end+=gap-off;+ }++ ArrayList<ArrayList<T>> lists = new ArrayList<>();+ ArrayList<T> between = new ArrayList<>();+ if (incLow && incUp) {+ for (int i = start; i<end && i<listsStart.size(); i+=gap) {+ ArrayList<T> list = new ArrayList<>();+ for (int j = i; j<=i+gap && j<=end && j<listsStart.size(); j++) {+ list.addAll(listsStart.get(j));+ }+ lists.add(list);+ }+ for (int i = start; i<listsStart.size() && i<=end; i++) {+ between.addAll(listsStart.get(i));+ }+ } else if (incLow && !incUp) {+ for (int i = start; i<end && i<listsStart.size(); i+=gap) {+ ArrayList<T> list = new ArrayList<>();+ for (int j = i; j<i+gap && j<end && j<listsStart.size(); j++) {+ list.addAll(listsStart.get(j));+ }+ lists.add(list);+ }+ for (int i = start; i<listsStart.size() && i<end; i++) {+ between.addAll(listsStart.get(i));+ }+ } else if (!incLow && incUp) {+ for (int i = start; i<end && i<listsStart.size(); i+=gap) {+ ArrayList<T> list = new ArrayList<>();+ for (int j = i+1; j<=i+gap && j<=end && j<listsStart.size(); j++) {+ list.addAll(listsStart.get(j));+ }+ lists.add(list);+ }+ for (int i = start+1; i<listsStart.size() && i<=end; i++) {+ between.addAll(listsStart.get(i));+ }+ } else {+ for (int i = start; i<end && i<listsStart.size(); i+=gap) {+ ArrayList<T> list = new ArrayList<>();+ for (int j = i+1; j<i+gap && j<end && j<listsStart.size(); j++) {+ list.addAll(listsStart.get(j));+ }+ lists.add(list);+ }+ for (int i = start+1; i<listsStart.size() && i<end; i++) {+ between.addAll(listsStart.get(i));+ }+ }++ if (incEdge && !incLow && start>=0) {+ lists.get(0).addAll(listsStart.get(start));+ between.addAll(listsStart.get(start));+ }+ if (incEdge && !incUp && end<listsStart.size()) {+ lists.get(lists.size()-1).addAll(listsStart.get(end));+ between.addAll(listsStart.get(end));+ }+ ArrayList<T> before = new ArrayList<>();+ ArrayList<T> after = new ArrayList<>();+ if (incOut || !(incLow||incEdge)) {+ for (int i = 0; i<=start; i++) {+ before.addAll(listsStart.get(i));+ }+ } else {+ for (int i = 0; i<start; i++) {+ before.addAll(listsStart.get(i));+ }+ }+ if (incOut || !(incUp||incEdge)) {+ for (int i = end; i<listsStart.size(); i++) {+ after.addAll(listsStart.get(i));+ }+ }+ else {+ for (int i = end+1; i<listsStart.size(); i++) {+ after.addAll(listsStart.get(i));+ }+ }+ lists.add(before);+ lists.add(after);+ lists.add(between);+ return lists;+ }++ private <T> ArrayList<ArrayList<T>> transformLists(ArrayList<ArrayList<T>> listsStart, int start, int end, String gapString+ , boolean hardend, boolean incLow, boolean incUp, boolean incEdge, boolean incOut) {+ String[] stringGaps = gapString.split(",");+ int[] gaps = new int[stringGaps.length];+ for (int i = 0; i<gaps.length; i++) {+ gaps[i] = Integer.parseInt(stringGaps[i]);+ }+ int bigGap = 0;+ int last = gaps[gaps.length-1];+ for (int i = 0; i<gaps.length-1; i++) {+ bigGap += gaps[i];+ }+ int off = (end-start-bigGap)%last;+ if (!hardend && off>0) {+ end+=last-off;+ }++ ArrayList<ArrayList<T>> lists = new ArrayList<>();+ ArrayList<T> between = new ArrayList<>();+ int gap = 0;+ int gapCounter = 0;+ if (incLow && incUp) {+ for (int i = start; i<end && i<listsStart.size(); i+=gap) {+ if (gapCounter<gaps.length) {+ gap = gaps[gapCounter++];+ }+ ArrayList<T> list = new ArrayList<>();+ for (int j = i; j<=i+gap && j<=end && j<listsStart.size(); j++) {+ list.addAll(listsStart.get(j));+ }+ lists.add(list);+ }+ for (int i = start; i<listsStart.size() && i<=end; i++) {+ between.addAll(listsStart.get(i));+ }+ } else if (incLow && !incUp) {+ for (int i = start; i<end && i<listsStart.size(); i+=gap) {+ if (gapCounter<gaps.length) {+ gap = gaps[gapCounter++];+ }+ ArrayList<T> list = new ArrayList<>();+ for (int j = i; j<i+gap && j<end && j<listsStart.size(); j++) {+ list.addAll(listsStart.get(j));+ }+ lists.add(list);+ }+ for (int i = start; i<listsStart.size() && i<end; i++) {+ between.addAll(listsStart.get(i));+ }+ } else if (!incLow && incUp) {+ for (int i = start; i<end && i<listsStart.size(); i+=gap) {+ if (gapCounter<gaps.length) {+ gap = gaps[gapCounter++];+ }+ ArrayList<T> list = new ArrayList<>();+ for (int j = i+1; j<=i+gap && j<=end && j<listsStart.size(); j++) {+ list.addAll(listsStart.get(j));+ }+ lists.add(list);+ }+ for (int i = start+1; i<listsStart.size() && i<=end; i++) {+ between.addAll(listsStart.get(i));+ }+ } else {+ for (int i = start; i<end && i<listsStart.size(); i+=gap) {+ if (gapCounter<gaps.length) {+ gap = gaps[gapCounter++];+ }+ ArrayList<T> list = new ArrayList<>();+ for (int j = i+1; j<i+gap && j<end && j<listsStart.size(); j++) {+ list.addAll(listsStart.get(j));+ }+ lists.add(list);+ }+ for (int i = start+1; i<listsStart.size() && i<end; i++) {+ between.addAll(listsStart.get(i));+ }+ }++ if (incEdge && !incLow && start>=0) {+ lists.get(0).addAll(listsStart.get(start));+ between.addAll(listsStart.get(start));+ }+ if (incEdge && !incUp && end<listsStart.size()) {+ lists.get(lists.size()-1).addAll(listsStart.get(end));+ between.addAll(listsStart.get(end));+ }+ ArrayList<T> before = new ArrayList<>();+ ArrayList<T> after = new ArrayList<>();+ if (incOut || !(incLow||incEdge)) {+ for (int i = 0; i<=start; i++) {+ before.addAll(listsStart.get(i));+ }+ } else {+ for (int i = 0; i<start; i++) {+ before.addAll(listsStart.get(i));+ }+ }+ if (incOut || !(incUp||incEdge)) {+ for (int i = end; i<listsStart.size(); i++) {+ after.addAll(listsStart.get(i));+ }+ }+ else {+ for (int i = end+1; i<listsStart.size(); i++) {+ after.addAll(listsStart.get(i));+ }+ }+ lists.add(before);+ lists.add(after);+ lists.add(between);+ return lists;+ }++}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingAnalyticsValueTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingAnalyticsValueTest.javanew file mode 100644index 00000000000..3eb1e572caf--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingAnalyticsValueTest.java@@ -0,0 +1,56 @@+/*+ * 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.analytics.value;++import java.util.Arrays;+import java.util.Iterator;++import org.apache.solr.SolrTestCaseJ4;+import org.apache.solr.analytics.value.FillableTestValue.TestAnalyticsValue;+import org.junit.Test;++public class CastingAnalyticsValueTest extends SolrTestCaseJ4 {++ @Test+ public void objectStreamCastingTest() {+ TestAnalyticsValue val = new TestAnalyticsValue();++ assertTrue(val instanceof AnalyticsValueStream);+ AnalyticsValueStream casted = (AnalyticsValueStream)val;++ // No values+ val.setExists(false);+ casted.streamObjects( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple Values+ val.setValue("Object").setExists(true);+ Iterator<Object> values = Arrays.<Object>asList("Object").iterator();+ casted.streamObjects( value -> {+ assertTrue(values.hasNext());+ assertEquals(values.next(), value);+ });+ assertFalse(values.hasNext());+ }++ @Test+ public void constantConversionTest() {+ AnalyticsValueStream val = new TestAnalyticsValue();+ assertSame(val, val.convertToConstant());+ }+}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingBooleanValueStreamTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingBooleanValueStreamTest.javanew file mode 100644index 00000000000..630e6fa45f1--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingBooleanValueStreamTest.java@@ -0,0 +1,79 @@+/*+ * 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.analytics.value;++import java.util.Arrays;+import java.util.Iterator;++import org.apache.solr.SolrTestCaseJ4;+import org.apache.solr.analytics.value.FillableTestValue.TestBooleanValueStream;+import org.junit.Test;++public class CastingBooleanValueStreamTest extends SolrTestCaseJ4 {++ @Test+ public void stringStreamCastingTest() {+ TestBooleanValueStream val = new TestBooleanValueStream();++ assertTrue(val instanceof StringValueStream);+ StringValueStream casted = (StringValueStream)val;++ // No values+ val.setValues();+ casted.streamStrings( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple Values+ val.setValues(false, true, false);+ Iterator<String> values = Arrays.asList("false", "true", "false").iterator();+ casted.streamStrings( value -> {+ assertTrue(values.hasNext());+ assertEquals(values.next(), value);+ });+ assertFalse(values.hasNext());+ }++ @Test+ public void objectStreamCastingTest() {+ TestBooleanValueStream val = new TestBooleanValueStream();++ assertTrue(val instanceof AnalyticsValueStream);+ AnalyticsValueStream casted = (AnalyticsValueStream)val;++ // No values+ val.setValues();+ casted.streamObjects( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple Values+ val.setValues(false, true, false);+ Iterator<Object> values = Arrays.<Object>asList(new Boolean(false), new Boolean(true), new Boolean(false)).iterator();+ casted.streamObjects( value -> {+ assertTrue(values.hasNext());+ assertEquals(values.next(), value);+ });+ assertFalse(values.hasNext());+ }++ @Test+ public void constantConversionTest() {+ AnalyticsValueStream val = new TestBooleanValueStream();+ assertSame(val, val.convertToConstant());+ }+}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingBooleanValueTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingBooleanValueTest.javanew file mode 100644index 00000000000..1ebfe85adf0--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingBooleanValueTest.java@@ -0,0 +1,159 @@+/*+ * 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.analytics.value;++import java.util.Arrays;+import java.util.Iterator;++import org.apache.solr.SolrTestCaseJ4;+import org.apache.solr.analytics.value.AnalyticsValueStream.ExpressionType;+import org.apache.solr.analytics.value.FillableTestValue.TestBooleanValue;+import org.apache.solr.analytics.value.constant.ConstantBooleanValue;+import org.junit.Test;++public class CastingBooleanValueTest extends SolrTestCaseJ4 {++ @Test+ public void stringCastingTest() {+ TestBooleanValue val = new TestBooleanValue();++ assertTrue(val instanceof StringValue);+ StringValue casted = (StringValue)val;++ val.setValue(false).setExists(true);+ assertEquals("false", casted.getString());+ assertTrue(casted.exists());++ val.setValue(true).setExists(true);+ assertEquals("true", casted.getString());+ assertTrue(casted.exists());+ }++ @Test+ public void objectCastingTest() {+ TestBooleanValue val = new TestBooleanValue();++ assertTrue(val instanceof AnalyticsValue);+ AnalyticsValue casted = (AnalyticsValue)val;++ val.setValue(false).setExists(true);+ assertEquals(new Boolean(false), casted.getObject());+ assertTrue(casted.exists());++ val.setValue(true).setExists(true);+ assertEquals(new Boolean(true), casted.getObject());+ assertTrue(casted.exists());+ }++ @Test+ public void booleanStreamCastingTest() {+ TestBooleanValue val = new TestBooleanValue();++ assertTrue(val instanceof BooleanValueStream);+ BooleanValueStream casted = (BooleanValueStream)val;++ // No values+ val.setExists(false);+ casted.streamBooleans( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple Values+ val.setValue(false).setExists(true);+ Iterator<Boolean> values = Arrays.asList(false).iterator();+ casted.streamBooleans( value -> {+ assertTrue(values.hasNext());+ assertEquals(values.next(), value);+ });+ assertFalse(values.hasNext());+ }++ @Test+ public void stringStreamCastingTest() {+ TestBooleanValue val = new TestBooleanValue();++ assertTrue(val instanceof StringValueStream);+ StringValueStream casted = (StringValueStream)val;++ // No values+ val.setExists(false);+ casted.streamStrings( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple Values+ val.setValue(false).setExists(true);+ Iterator<String> values = Arrays.asList("false").iterator();+ casted.streamStrings( value -> {+ assertTrue(values.hasNext());+ assertEquals(values.next(), value);+ });+ assertFalse(values.hasNext());+ }++ @Test+ public void objectStreamCastingTest() {+ TestBooleanValue val = new TestBooleanValue();++ assertTrue(val instanceof AnalyticsValueStream);+ AnalyticsValueStream casted = (AnalyticsValueStream)val;++ // No values+ val.setExists(false);+ casted.streamObjects( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple Values+ val.setValue(false).setExists(true);+ Iterator<Object> values = Arrays.<Object>asList(new Boolean(false)).iterator();+ casted.streamObjects( value -> {+ assertTrue(values.hasNext());+ assertEquals(values.next(), value);+ });+ assertFalse(values.hasNext());+ }++ @Test+ public void constantConversionTest() {+ TestBooleanValue val = new TestBooleanValue(ExpressionType.CONST);+ val.setValue(true).setExists(true);+ AnalyticsValueStream conv = val.convertToConstant();+ assertTrue(conv instanceof ConstantBooleanValue);+ assertEquals(true, ((ConstantBooleanValue)conv).getBoolean());++ val = new TestBooleanValue(ExpressionType.FIELD);+ val.setValue(true).setExists(true);+ conv = val.convertToConstant();+ assertSame(val, conv);++ val = new TestBooleanValue(ExpressionType.UNREDUCED_MAPPING);+ val.setValue(true).setExists(true);+ conv = val.convertToConstant();+ assertSame(val, conv);++ val = new TestBooleanValue(ExpressionType.REDUCTION);+ val.setValue(true).setExists(true);+ conv = val.convertToConstant();+ assertSame(val, conv);++ val = new TestBooleanValue(ExpressionType.REDUCED_MAPPING);+ val.setValue(true).setExists(true);+ conv = val.convertToConstant();+ assertSame(val, conv);+ }+}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingDateValueStreamTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingDateValueStreamTest.javanew file mode 100644index 00000000000..e6659ea8c12--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingDateValueStreamTest.java@@ -0,0 +1,111 @@+/*+ * 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.analytics.value;++import java.time.Instant;+import java.time.format.DateTimeParseException;+import java.util.Arrays;+import java.util.Date;+import java.util.Iterator;++import org.apache.solr.SolrTestCaseJ4;+import org.apache.solr.analytics.value.FillableTestValue.TestDateValueStream;+import org.junit.Test;++public class CastingDateValueStreamTest extends SolrTestCaseJ4 {++ @Test+ public void dateStreamCastingTest() throws DateTimeParseException {+ Date date1 = Date.from(Instant.parse("1800-01-01T10:30:15Z"));+ Date date2 = Date.from(Instant.parse("1920-04-15T18:15:45Z"));+ Date date3 = Date.from(Instant.parse("2012-11-30T20:30:15Z"));+ TestDateValueStream val = new TestDateValueStream();++ assertTrue(val instanceof DateValueStream);+ DateValueStream casted = (DateValueStream)val;++ // No values+ val.setValues();+ casted.streamDates( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple Values+ val.setValues("1800-01-01T10:30:15Z", "1920-04-15T18:15:45Z", "2012-11-30T20:30:15Z");+ Iterator<Date> values = Arrays.asList(date1, date2, date3).iterator();+ casted.streamDates( value -> {+ assertTrue(values.hasNext());+ assertEquals(values.next(), value);+ });+ assertFalse(values.hasNext());+ }++ @Test+ public void stringStreamCastingTest() {+ TestDateValueStream val = new TestDateValueStream();++ assertTrue(val instanceof StringValueStream);+ StringValueStream casted = (StringValueStream)val;++ // No values+ val.setValues();+ casted.streamStrings( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple Values+ val.setValues("1800-01-01T10:30:15Z", "1920-04-15T18:15:45Z", "2012-11-30T20:30:15Z");+ Iterator<String> values = Arrays.asList("1800-01-01T10:30:15Z", "1920-04-15T18:15:45Z", "2012-11-30T20:30:15Z").iterator();+ casted.streamStrings( value -> {+ assertTrue(values.hasNext());+ assertEquals(values.next(), value);+ });+ assertFalse(values.hasNext());+ }++ @Test+ public void objectStreamCastingTest() throws DateTimeParseException {+ Date date1 = Date.from(Instant.parse("1800-01-01T10:30:15Z"));+ Date date2 = Date.from(Instant.parse("1920-04-15T18:15:45Z"));+ Date date3 = Date.from(Instant.parse("2012-11-30T20:30:15Z"));+ TestDateValueStream val = new TestDateValueStream();++ assertTrue(val instanceof AnalyticsValueStream);+ AnalyticsValueStream casted = (AnalyticsValueStream)val;++ // No values+ val.setValues();+ casted.streamObjects( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple Values+ val.setValues("1800-01-01T10:30:15Z", "1920-04-15T18:15:45Z", "2012-11-30T20:30:15Z");+ Iterator<Object> values = Arrays.<Object>asList(date1, date2, date3).iterator();+ casted.streamObjects( value -> {+ assertTrue(values.hasNext());+ assertEquals(values.next(), value);+ });+ assertFalse(values.hasNext());+ }++ @Test+ public void constantConversionTest() {+ AnalyticsValueStream val = new TestDateValueStream();+ assertSame(val, val.convertToConstant());+ }+}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingDateValueTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingDateValueTest.javanew file mode 100644index 00000000000..e0fd9511691--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingDateValueTest.java@@ -0,0 +1,172 @@+/*+ * 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.analytics.value;++import java.time.Instant;+import java.time.format.DateTimeParseException;+import java.util.Arrays;+import java.util.Date;+import java.util.Iterator;++import org.apache.solr.SolrTestCaseJ4;+import org.apache.solr.analytics.value.AnalyticsValueStream.ExpressionType;+import org.apache.solr.analytics.value.FillableTestValue.TestDateValue;+import org.apache.solr.analytics.value.constant.ConstantDateValue;+import org.junit.Test;++public class CastingDateValueTest extends SolrTestCaseJ4 {++ @Test+ public void dateCastingTest() throws DateTimeParseException {+ Date date = Date.from(Instant.parse("1800-01-01T10:30:15Z"));+ TestDateValue val = new TestDateValue();++ assertTrue(val instanceof DateValue);+ DateValue casted = (DateValue)val;++ val.setValue("1800-01-01T10:30:15Z").setExists(true);+ assertEquals(date, casted.getDate());+ assertTrue(casted.exists());+ }++ @Test+ public void stringCastingTest() {+ TestDateValue val = new TestDateValue();++ assertTrue(val instanceof StringValue);+ StringValue casted = (StringValue)val;++ val.setValue("1800-01-01T10:30:15Z").setExists(true);+ assertEquals("1800-01-01T10:30:15Z", casted.getString());+ assertTrue(casted.exists());+ }++ @Test+ public void objectCastingTest() throws DateTimeParseException {+ Date date = Date.from(Instant.parse("1800-01-01T10:30:15Z"));+ TestDateValue val = new TestDateValue();++ assertTrue(val instanceof AnalyticsValue);+ AnalyticsValue casted = (AnalyticsValue)val;++ val.setValue("1800-01-01T10:30:15Z").setExists(true);+ assertEquals(date, casted.getObject());+ assertTrue(casted.exists());+ }++ @Test+ public void dateStreamCastingTest() throws DateTimeParseException {+ Date date = Date.from(Instant.parse("1800-01-01T10:30:15Z"));+ TestDateValue val = new TestDateValue();++ assertTrue(val instanceof DateValueStream);+ DateValueStream casted = (DateValueStream)val;++ // No values+ val.setExists(false);+ casted.streamDates( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple Values+ val.setValue("1800-01-01T10:30:15Z").setExists(true);+ Iterator<Date> values = Arrays.asList(date).iterator();+ casted.streamDates( value -> {+ assertTrue(values.hasNext());+ assertEquals(values.next(), value);+ });+ assertFalse(values.hasNext());+ }++ @Test+ public void stringStreamCastingTest() {+ TestDateValue val = new TestDateValue();++ assertTrue(val instanceof StringValueStream);+ StringValueStream casted = (StringValueStream)val;++ // No values+ val.setExists(false);+ casted.streamStrings( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple Values+ val.setValue("1800-01-01T10:30:15Z").setExists(true);+ Iterator<String> values = Arrays.asList("1800-01-01T10:30:15Z").iterator();+ casted.streamStrings( value -> {+ assertTrue(values.hasNext());+ assertEquals(values.next(), value);+ });+ assertFalse(values.hasNext());+ }++ @Test+ public void objectStreamCastingTest() throws DateTimeParseException {+ Date date = Date.from(Instant.parse("1800-01-01T10:30:15Z"));+ TestDateValue val = new TestDateValue();++ assertTrue(val instanceof AnalyticsValueStream);+ AnalyticsValueStream casted = (AnalyticsValueStream)val;++ // No values+ val.setExists(false);+ casted.streamObjects( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple Values+ val.setValue("1800-01-01T10:30:15Z").setExists(true);+ Iterator<Object> values = Arrays.<Object>asList(date).iterator();+ casted.streamObjects( value -> {+ assertTrue(values.hasNext());+ assertEquals(values.next(), value);+ });+ assertFalse(values.hasNext());+ }++ @Test+ public void constantConversionTest() throws DateTimeParseException {+ Date date = Date.from(Instant.parse("1800-01-01T10:30:15Z"));++ TestDateValue val = new TestDateValue(ExpressionType.CONST);+ val.setValue("1800-01-01T10:30:15Z").setExists(true);+ AnalyticsValueStream conv = val.convertToConstant();+ assertTrue(conv instanceof ConstantDateValue);+ assertEquals(date, ((ConstantDateValue)conv).getDate());++ val = new TestDateValue(ExpressionType.FIELD);+ val.setValue("1800-01-01T10:30:15Z").setExists(true);+ conv = val.convertToConstant();+ assertSame(val, conv);++ val = new TestDateValue(ExpressionType.UNREDUCED_MAPPING);+ val.setValue("1800-01-01T10:30:15Z").setExists(true);+ conv = val.convertToConstant();+ assertSame(val, conv);++ val = new TestDateValue(ExpressionType.REDUCTION);+ val.setValue("1800-01-01T10:30:15Z").setExists(true);+ conv = val.convertToConstant();+ assertSame(val, conv);++ val = new TestDateValue(ExpressionType.REDUCED_MAPPING);+ val.setValue("1800-01-01T10:30:15Z").setExists(true);+ conv = val.convertToConstant();+ assertSame(val, conv);+ }+}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingDoubleValueStreamTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingDoubleValueStreamTest.javanew file mode 100644index 00000000000..7f2ddc67b31--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingDoubleValueStreamTest.java@@ -0,0 +1,79 @@+/*+ * 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.analytics.value;++import java.util.Arrays;+import java.util.Iterator;++import org.apache.solr.SolrTestCaseJ4;+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValueStream;+import org.junit.Test;++public class CastingDoubleValueStreamTest extends SolrTestCaseJ4 {++ @Test+ public void stringStreamCastingTest() {+ TestDoubleValueStream val = new TestDoubleValueStream();++ assertTrue(val instanceof StringValueStream);+ StringValueStream casted = (StringValueStream)val;++ // No values+ val.setValues();+ casted.streamStrings( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple Values+ val.setValues(20.0, -3.32, 42.5);+ Iterator<String> values = Arrays.asList("20.0", "-3.32", "42.5").iterator();+ casted.streamStrings( value -> {+ assertTrue(values.hasNext());+ assertEquals(values.next(), value);+ });+ assertFalse(values.hasNext());+ }++ @Test+ public void objectStreamCastingTest() {+ TestDoubleValueStream val = new TestDoubleValueStream();++ assertTrue(val instanceof AnalyticsValueStream);+ AnalyticsValueStream casted = (AnalyticsValueStream)val;++ // No values+ val.setValues();+ casted.streamObjects( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple Values+ val.setValues(20.0, -3.32, 42.5);+ Iterator<Object> values = Arrays.<Object>asList(new Double(20.0), new Double(-3.32), new Double(42.5)).iterator();+ casted.streamObjects( value -> {+ assertTrue(values.hasNext());+ assertEquals(values.next(), value);+ });+ assertFalse(values.hasNext());+ }++ @Test+ public void constantConversionTest() {+ AnalyticsValueStream val = new TestDoubleValueStream();+ assertSame(val, val.convertToConstant());+ }+}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingDoubleValueTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingDoubleValueTest.javanew file mode 100644index 00000000000..a4558b0dbfd--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingDoubleValueTest.java@@ -0,0 +1,159 @@+/*+ * 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.analytics.value;++import java.util.Arrays;+import java.util.Iterator;++import org.apache.solr.SolrTestCaseJ4;+import org.apache.solr.analytics.value.AnalyticsValueStream.ExpressionType;+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValue;+import org.apache.solr.analytics.value.constant.ConstantDoubleValue;+import org.junit.Test;++public class CastingDoubleValueTest extends SolrTestCaseJ4 {++ @Test+ public void stringCastingTest() {+ TestDoubleValue val = new TestDoubleValue();++ assertTrue(val instanceof StringValue);+ StringValue casted = (StringValue)val;++ val.setValue(20.0).setExists(true);+ assertEquals("20.0", casted.getString());+ assertTrue(casted.exists());++ val.setValue(1234.0).setExists(true);+ assertEquals("1234.0", casted.getString());+ assertTrue(casted.exists());+ }++ @Test+ public void objectCastingTest() {+ TestDoubleValue val = new TestDoubleValue();++ assertTrue(val instanceof AnalyticsValue);+ AnalyticsValue casted = (AnalyticsValue)val;++ val.setValue(20.0).setExists(true);+ assertEquals(new Double(20.0), casted.getObject());+ assertTrue(casted.exists());++ val.setValue(1234.0).setExists(true);+ assertEquals(new Double(1234.0), casted.getObject());+ assertTrue(casted.exists());+ }++ @Test+ public void doubleStreamCastingTest() {+ TestDoubleValue val = new TestDoubleValue();++ assertTrue(val instanceof DoubleValueStream);+ DoubleValueStream casted = (DoubleValueStream)val;++ // No values+ val.setExists(false);+ casted.streamDoubles( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple Values+ val.setValue(20.0).setExists(true);+ Iterator<Double> values = Arrays.asList(20.0).iterator();+ casted.streamDoubles( value -> {+ assertTrue(values.hasNext());+ assertEquals(values.next(), value, .00001);+ });+ assertFalse(values.hasNext());+ }++ @Test+ public void stringStreamCastingTest() {+ TestDoubleValue val = new TestDoubleValue();++ assertTrue(val instanceof StringValueStream);+ StringValueStream casted = (StringValueStream)val;++ // No values+ val.setExists(false);+ casted.streamStrings( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple Values+ val.setValue(20.0).setExists(true);+ Iterator<String> values = Arrays.asList("20.0").iterator();+ casted.streamStrings( value -> {+ assertTrue(values.hasNext());+ assertEquals(values.next(), value);+ });+ assertFalse(values.hasNext());+ }++ @Test+ public void objectStreamCastingTest() {+ TestDoubleValue val = new TestDoubleValue();++ assertTrue(val instanceof AnalyticsValueStream);+ AnalyticsValueStream casted = (AnalyticsValueStream)val;++ // No values+ val.setExists(false);+ casted.streamObjects( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple Values+ val.setValue(20.0).setExists(true);+ Iterator<Object> values = Arrays.<Object>asList(new Double(20.0)).iterator();+ casted.streamObjects( value -> {+ assertTrue(values.hasNext());+ assertEquals(values.next(), value);+ });+ assertFalse(values.hasNext());+ }++ @Test+ public void constantConversionTest() {+ TestDoubleValue val = new TestDoubleValue(ExpressionType.CONST);+ val.setValue(12354.234).setExists(true);+ AnalyticsValueStream conv = val.convertToConstant();+ assertTrue(conv instanceof ConstantDoubleValue);+ assertEquals(12354.234, ((ConstantDoubleValue)conv).getDouble(), .0000001);++ val = new TestDoubleValue(ExpressionType.FIELD);+ val.setValue(12354.234).setExists(true);+ conv = val.convertToConstant();+ assertSame(val, conv);++ val = new TestDoubleValue(ExpressionType.UNREDUCED_MAPPING);+ val.setValue(12354.234).setExists(true);+ conv = val.convertToConstant();+ assertSame(val, conv);++ val = new TestDoubleValue(ExpressionType.REDUCTION);+ val.setValue(12354.234).setExists(true);+ conv = val.convertToConstant();+ assertSame(val, conv);++ val = new TestDoubleValue(ExpressionType.REDUCED_MAPPING);+ val.setValue(12354.234).setExists(true);+ conv = val.convertToConstant();+ assertSame(val, conv);+ }+}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingFloatValueStreamTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingFloatValueStreamTest.javanew file mode 100644index 00000000000..2c7753e0284--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingFloatValueStreamTest.java@@ -0,0 +1,102 @@+/*+ * 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.analytics.value;++import java.util.Arrays;+import java.util.Iterator;++import org.apache.solr.SolrTestCaseJ4;+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValueStream;+import org.junit.Test;++public class CastingFloatValueStreamTest extends SolrTestCaseJ4 {++ @Test+ public void doubleStreamCastingTest() {+ TestFloatValueStream val = new TestFloatValueStream();++ assertTrue(val instanceof DoubleValueStream);+ DoubleValueStream casted = (DoubleValueStream)val;++ // No values+ val.setValues();+ casted.streamDoubles( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple Values+ val.setValues(20F, -3.32F, 42.5F);+ Iterator<Double> values = Arrays.asList(20.0, -3.32, 42.5).iterator();+ casted.streamDoubles( value -> {+ assertTrue(values.hasNext());+ assertEquals(values.next(), value, .00001);+ });+ assertFalse(values.hasNext());+ }++ @Test+ public void stringStreamCastingTest() {+ TestFloatValueStream val = new TestFloatValueStream();++ assertTrue(val instanceof StringValueStream);+ StringValueStream casted = (StringValueStream)val;++ // No values+ val.setValues();+ casted.streamStrings( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple Values+ val.setValues(20F, -3.32F, 42.5F);+ Iterator<String> values = Arrays.asList("20.0", "-3.32", "42.5").iterator();+ casted.streamStrings( value -> {+ assertTrue(values.hasNext());+ assertEquals(values.next(), value);+ });+ assertFalse(values.hasNext());+ }++ @Test+ public void objectStreamCastingTest() {+ TestFloatValueStream val = new TestFloatValueStream();++ assertTrue(val instanceof AnalyticsValueStream);+ AnalyticsValueStream casted = (AnalyticsValueStream)val;++ // No values+ val.setValues();+ casted.streamObjects( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple Values+ val.setValues(20F, -3.32F, 42.5F);+ Iterator<Object> values = Arrays.<Object>asList(new Float(20F), new Float(-3.32F), new Float(42.5F)).iterator();+ casted.streamObjects( value -> {+ assertTrue(values.hasNext());+ assertEquals(values.next(), value);+ });+ assertFalse(values.hasNext());+ }++ @Test+ public void constantConversionTest() {+ AnalyticsValueStream val = new TestFloatValueStream();+ assertSame(val, val.convertToConstant());+ }+}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingFloatValueTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingFloatValueTest.javanew file mode 100644index 00000000000..0f044b201e3--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingFloatValueTest.java@@ -0,0 +1,198 @@+/*+ * 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.analytics.value;++import java.util.Arrays;+import java.util.Iterator;++import org.apache.solr.SolrTestCaseJ4;+import org.apache.solr.analytics.value.AnalyticsValueStream.ExpressionType;+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValue;+import org.apache.solr.analytics.value.constant.ConstantFloatValue;+import org.junit.Test;++public class CastingFloatValueTest extends SolrTestCaseJ4 {++ @Test+ public void doubleCastingTest() {+ TestFloatValue val = new TestFloatValue();++ assertTrue(val instanceof DoubleValue);+ DoubleValue casted = (DoubleValue)val;++ val.setValue(20F).setExists(true);+ assertEquals(20.0, casted.getDouble(), .00001);+ assertTrue(casted.exists());++ val.setValue(1234F).setExists(true);+ assertEquals(1234.0, casted.getDouble(), .00001);+ assertTrue(casted.exists());+ }++ @Test+ public void stringCastingTest() {+ TestFloatValue val = new TestFloatValue();++ assertTrue(val instanceof StringValue);+ StringValue casted = (StringValue)val;++ val.setValue(20F).setExists(true);+ assertEquals("20.0", casted.getString());+ assertTrue(casted.exists());++ val.setValue(1234F).setExists(true);+ assertEquals("1234.0", casted.getString());+ assertTrue(casted.exists());+ }++ @Test+ public void objectCastingTest() {+ TestFloatValue val = new TestFloatValue();++ assertTrue(val instanceof AnalyticsValue);+ AnalyticsValue casted = (AnalyticsValue)val;++ val.setValue(20F).setExists(true);+ assertEquals(new Float(20F), casted.getObject());+ assertTrue(casted.exists());++ val.setValue(1234F).setExists(true);+ assertEquals(new Float(1234F), casted.getObject());+ assertTrue(casted.exists());+ }++ @Test+ public void floatStreamCastingTest() {+ TestFloatValue val = new TestFloatValue();++ assertTrue(val instanceof FloatValueStream);+ FloatValueStream casted = (FloatValueStream)val;++ // No values+ val.setExists(false);+ casted.streamFloats( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple Values+ val.setValue(20F).setExists(true);+ Iterator<Float> values = Arrays.asList(20F).iterator();+ casted.streamFloats( value -> {+ assertTrue(values.hasNext());+ assertEquals(values.next(), value, .00001);+ });+ assertFalse(values.hasNext());+ }++ @Test+ public void doubleStreamCastingTest() {+ TestFloatValue val = new TestFloatValue();++ assertTrue(val instanceof DoubleValueStream);+ DoubleValueStream casted = (DoubleValueStream)val;++ // No values+ val.setExists(false);+ casted.streamDoubles( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple Values+ val.setValue(20F).setExists(true);+ Iterator<Double> values = Arrays.asList(20.0).iterator();+ casted.streamDoubles( value -> {+ assertTrue(values.hasNext());+ assertEquals(values.next(), value, .00001);+ });+ assertFalse(values.hasNext());+ }++ @Test+ public void stringStreamCastingTest() {+ TestFloatValue val = new TestFloatValue();++ assertTrue(val instanceof StringValueStream);+ StringValueStream casted = (StringValueStream)val;++ // No values+ val.setExists(false);+ casted.streamStrings( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple Values+ val.setValue(20F).setExists(true);+ Iterator<String> values = Arrays.asList("20.0").iterator();+ casted.streamStrings( value -> {+ assertTrue(values.hasNext());+ assertEquals(values.next(), value);+ });+ assertFalse(values.hasNext());+ }++ @Test+ public void objectStreamCastingTest() {+ TestFloatValue val = new TestFloatValue();++ assertTrue(val instanceof AnalyticsValueStream);+ AnalyticsValueStream casted = (AnalyticsValueStream)val;++ // No values+ val.setExists(false);+ casted.streamObjects( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple Values+ val.setValue(20F).setExists(true);+ Iterator<Object> values = Arrays.<Object>asList(new Float(20F)).iterator();+ casted.streamObjects( value -> {+ assertTrue(values.hasNext());+ assertEquals(values.next(), value);+ });+ assertFalse(values.hasNext());+ }++ @Test+ public void constantConversionTest() {+ TestFloatValue val = new TestFloatValue(ExpressionType.CONST);+ val.setValue(12354.234F).setExists(true);+ AnalyticsValueStream conv = val.convertToConstant();+ assertTrue(conv instanceof ConstantFloatValue);+ assertEquals(12354.234F, ((ConstantFloatValue)conv).getFloat(), .0000001);++ val = new TestFloatValue(ExpressionType.FIELD);+ val.setValue(12354.234F).setExists(true);+ conv = val.convertToConstant();+ assertSame(val, conv);++ val = new TestFloatValue(ExpressionType.UNREDUCED_MAPPING);+ val.setValue(12354.234F).setExists(true);+ conv = val.convertToConstant();+ assertSame(val, conv);++ val = new TestFloatValue(ExpressionType.REDUCTION);+ val.setValue(12354.234F).setExists(true);+ conv = val.convertToConstant();+ assertSame(val, conv);++ val = new TestFloatValue(ExpressionType.REDUCED_MAPPING);+ val.setValue(12354.234F).setExists(true);+ conv = val.convertToConstant();+ assertSame(val, conv);+ }+}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingIntValueStreamTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingIntValueStreamTest.javanew file mode 100644index 00000000000..f099b6e8baf--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingIntValueStreamTest.java@@ -0,0 +1,148 @@+/*+ * 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.analytics.value;++import java.util.Arrays;+import java.util.Iterator;++import org.apache.solr.SolrTestCaseJ4;+import org.apache.solr.analytics.value.FillableTestValue.TestIntValueStream;+import org.junit.Test;++public class CastingIntValueStreamTest extends SolrTestCaseJ4 {++ @Test+ public void longStreamCastingTest() {+ TestIntValueStream val = new TestIntValueStream();++ assertTrue(val instanceof LongValueStream);+ LongValueStream casted = (LongValueStream)val;++ // No values+ val.setValues();+ casted.streamLongs( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple Values+ val.setValues(20, -3, 42);+ Iterator<Long> values = Arrays.asList(20L, -3L, 42L).iterator();+ casted.streamLongs( value -> {+ assertTrue(values.hasNext());+ assertEquals(values.next().longValue(), value);+ });+ assertFalse(values.hasNext());+ }++ @Test+ public void floatStreamCastingTest() {+ TestIntValueStream val = new TestIntValueStream();++ assertTrue(val instanceof FloatValueStream);+ FloatValueStream casted = (FloatValueStream)val;++ // No values+ val.setValues();+ casted.streamFloats( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple Values+ val.setValues(20, -3, 42);+ Iterator<Float> values = Arrays.asList(20F, -3F, 42F).iterator();+ casted.streamFloats( value -> {+ assertTrue(values.hasNext());+ assertEquals(values.next(), value, .00001);+ });+ assertFalse(values.hasNext());+ }++ @Test+ public void doubleStreamCastingTest() {+ TestIntValueStream val = new TestIntValueStream();++ assertTrue(val instanceof DoubleValueStream);+ DoubleValueStream casted = (DoubleValueStream)val;++ // No values+ val.setValues();+ casted.streamDoubles( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple Values+ val.setValues(20, -3, 42);+ Iterator<Double> values = Arrays.asList(20.0, -3.0, 42.0).iterator();+ casted.streamDoubles( value -> {+ assertTrue(values.hasNext());+ assertEquals(values.next(), value, .00001);+ });+ assertFalse(values.hasNext());+ }++ @Test+ public void stringStreamCastingTest() {+ TestIntValueStream val = new TestIntValueStream();++ assertTrue(val instanceof StringValueStream);+ StringValueStream casted = (StringValueStream)val;++ // No values+ val.setValues();+ casted.streamStrings( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple Values+ val.setValues(20, -3, 42);+ Iterator<String> values = Arrays.asList("20", "-3", "42").iterator();+ casted.streamStrings( value -> {+ assertTrue(values.hasNext());+ assertEquals(values.next(), value);+ });+ assertFalse(values.hasNext());+ }++ @Test+ public void objectStreamCastingTest() {+ TestIntValueStream val = new TestIntValueStream();++ assertTrue(val instanceof AnalyticsValueStream);+ AnalyticsValueStream casted = (AnalyticsValueStream)val;++ // No values+ val.setValues();+ casted.streamObjects( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple Values+ val.setValues(20, -3, 42);+ Iterator<Object> values = Arrays.<Object>asList(new Integer(20), new Integer(-3), new Integer(42)).iterator();+ casted.streamObjects( value -> {+ assertTrue(values.hasNext());+ assertEquals(values.next(), value);+ });+ assertFalse(values.hasNext());+ }++ @Test+ public void constantConversionTest() {+ AnalyticsValueStream val = new TestIntValueStream();+ assertSame(val, val.convertToConstant());+ }+}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingIntValueTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingIntValueTest.javanew file mode 100644index 00000000000..65a3a7e17ab--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingIntValueTest.java@@ -0,0 +1,276 @@+/*+ * 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.analytics.value;++import java.util.Arrays;+import java.util.Iterator;++import org.apache.solr.SolrTestCaseJ4;+import org.apache.solr.analytics.value.AnalyticsValueStream.ExpressionType;+import org.apache.solr.analytics.value.FillableTestValue.TestIntValue;+import org.apache.solr.analytics.value.constant.ConstantIntValue;+import org.junit.Test;++public class CastingIntValueTest extends SolrTestCaseJ4 {++ @Test+ public void longCastingTest() {+ TestIntValue val = new TestIntValue();++ assertTrue(val instanceof LongValue);+ LongValue casted = (LongValue)val;++ val.setValue(20).setExists(true);+ assertEquals(20L, casted.getLong());+ assertTrue(casted.exists());++ val.setValue(1234).setExists(true);+ assertEquals(1234L, casted.getLong());+ assertTrue(casted.exists());+ }++ @Test+ public void floatCastingTest() {+ TestIntValue val = new TestIntValue();++ assertTrue(val instanceof FloatValue);+ FloatValue casted = (FloatValue)val;++ val.setValue(20).setExists(true);+ assertEquals(20F, casted.getFloat(), .00001);+ assertTrue(casted.exists());++ val.setValue(1234).setExists(true);+ assertEquals(1234F, casted.getFloat(), .00001);+ assertTrue(casted.exists());+ }++ @Test+ public void doubleCastingTest() {+ TestIntValue val = new TestIntValue();++ assertTrue(val instanceof DoubleValue);+ DoubleValue casted = (DoubleValue)val;++ val.setValue(20).setExists(true);+ assertEquals(20.0, casted.getDouble(), .00001);+ assertTrue(casted.exists());++ val.setValue(1234).setExists(true);+ assertEquals(1234.0, casted.getDouble(), .00001);+ assertTrue(casted.exists());+ }++ @Test+ public void stringCastingTest() {+ TestIntValue val = new TestIntValue();++ assertTrue(val instanceof StringValue);+ StringValue casted = (StringValue)val;++ val.setValue(20).setExists(true);+ assertEquals("20", casted.getString());+ assertTrue(casted.exists());++ val.setValue(1234).setExists(true);+ assertEquals("1234", casted.getString());+ assertTrue(casted.exists());+ }++ @Test+ public void objectCastingTest() {+ TestIntValue val = new TestIntValue();++ assertTrue(val instanceof AnalyticsValue);+ AnalyticsValue casted = (AnalyticsValue)val;++ val.setValue(20).setExists(true);+ assertEquals(new Integer(20), casted.getObject());+ assertTrue(casted.exists());++ val.setValue(1234).setExists(true);+ assertEquals(new Integer(1234), casted.getObject());+ assertTrue(casted.exists());+ }++ @Test+ public void intStreamCastingTest() {+ TestIntValue val = new TestIntValue();++ assertTrue(val instanceof IntValueStream);+ IntValueStream casted = (IntValueStream)val;++ // No values+ val.setExists(false);+ casted.streamInts( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple Values+ val.setValue(20).setExists(true);+ Iterator<Integer> values = Arrays.asList(20).iterator();+ casted.streamInts( value -> {+ assertTrue(values.hasNext());+ assertEquals(values.next().intValue(), value);+ });+ assertFalse(values.hasNext());+ }++ @Test+ public void longStreamCastingTest() {+ TestIntValue val = new TestIntValue();++ assertTrue(val instanceof LongValueStream);+ LongValueStream casted = (LongValueStream)val;++ // No values+ val.setExists(false);+ casted.streamLongs( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple Values+ val.setValue(20).setExists(true);+ Iterator<Long> values = Arrays.asList(20L).iterator();+ casted.streamLongs( value -> {+ assertTrue(values.hasNext());+ assertEquals(values.next().longValue(), value);+ });+ assertFalse(values.hasNext());+ }++ @Test+ public void floatStreamCastingTest() {+ TestIntValue val = new TestIntValue();++ assertTrue(val instanceof FloatValueStream);+ FloatValueStream casted = (FloatValueStream)val;++ // No values+ val.setExists(false);+ casted.streamFloats( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple Values+ val.setValue(20).setExists(true);+ Iterator<Float> values = Arrays.asList(20F).iterator();+ casted.streamFloats( value -> {+ assertTrue(values.hasNext());+ assertEquals(values.next(), value, .00001);+ });+ assertFalse(values.hasNext());+ }++ @Test+ public void doubleStreamCastingTest() {+ TestIntValue val = new TestIntValue();++ assertTrue(val instanceof DoubleValueStream);+ DoubleValueStream casted = (DoubleValueStream)val;++ // No values+ val.setExists(false);+ casted.streamDoubles( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple Values+ val.setValue(20).setExists(true);+ Iterator<Double> values = Arrays.asList(20.0).iterator();+ casted.streamDoubles( value -> {+ assertTrue(values.hasNext());+ assertEquals(values.next(), value, .00001);+ });+ assertFalse(values.hasNext());+ }++ @Test+ public void stringStreamCastingTest() {+ TestIntValue val = new TestIntValue();++ assertTrue(val instanceof StringValueStream);+ StringValueStream casted = (StringValueStream)val;++ // No values+ val.setExists(false);+ casted.streamStrings( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple Values+ val.setValue(20).setExists(true);+ Iterator<String> values = Arrays.asList("20").iterator();+ casted.streamStrings( value -> {+ assertTrue(values.hasNext());+ assertEquals(values.next(), value);+ });+ assertFalse(values.hasNext());+ }++ @Test+ public void objectStreamCastingTest() {+ TestIntValue val = new TestIntValue();++ assertTrue(val instanceof AnalyticsValueStream);+ AnalyticsValueStream casted = (AnalyticsValueStream)val;++ // No values+ val.setExists(false);+ casted.streamObjects( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple Values+ val.setValue(20).setExists(true);+ Iterator<Object> values = Arrays.<Object>asList(new Integer(20)).iterator();+ casted.streamObjects( value -> {+ assertTrue(values.hasNext());+ assertEquals(values.next(), value);+ });+ assertFalse(values.hasNext());+ }++ @Test+ public void constantConversionTest() {+ TestIntValue val = new TestIntValue(ExpressionType.CONST);+ val.setValue(1234).setExists(true);+ AnalyticsValueStream conv = val.convertToConstant();+ assertTrue(conv instanceof ConstantIntValue);+ assertEquals(1234, ((ConstantIntValue)conv).getInt());++ val = new TestIntValue(ExpressionType.FIELD);+ val.setValue(1234).setExists(true);+ conv = val.convertToConstant();+ assertSame(val, conv);++ val = new TestIntValue(ExpressionType.UNREDUCED_MAPPING);+ val.setValue(1234).setExists(true);+ conv = val.convertToConstant();+ assertSame(val, conv);++ val = new TestIntValue(ExpressionType.REDUCTION);+ val.setValue(1234).setExists(true);+ conv = val.convertToConstant();+ assertSame(val, conv);++ val = new TestIntValue(ExpressionType.REDUCED_MAPPING);+ val.setValue(1234).setExists(true);+ conv = val.convertToConstant();+ assertSame(val, conv);+ }+}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingLongValueStreamTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingLongValueStreamTest.javanew file mode 100644index 00000000000..163cbc7aad9--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingLongValueStreamTest.java@@ -0,0 +1,102 @@+/*+ * 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.analytics.value;++import java.util.Arrays;+import java.util.Iterator;++import org.apache.solr.SolrTestCaseJ4;+import org.apache.solr.analytics.value.FillableTestValue.TestLongValueStream;+import org.junit.Test;++public class CastingLongValueStreamTest extends SolrTestCaseJ4 {++ @Test+ public void doubleStreamCastingTest() {+ TestLongValueStream val = new TestLongValueStream();++ assertTrue(val instanceof DoubleValueStream);+ DoubleValueStream casted = (DoubleValueStream)val;++ // No values+ val.setValues();+ casted.streamDoubles( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple Values+ val.setValues(20L, -3L, 42L);+ Iterator<Double> values = Arrays.asList(20.0, -3.0, 42.0).iterator();+ casted.streamDoubles( value -> {+ assertTrue(values.hasNext());+ assertEquals(values.next(), value, .00001);+ });+ assertFalse(values.hasNext());+ }++ @Test+ public void stringStreamCastingTest() {+ TestLongValueStream val = new TestLongValueStream();++ assertTrue(val instanceof StringValueStream);+ StringValueStream casted = (StringValueStream)val;++ // No values+ val.setValues();+ casted.streamStrings( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple Values+ val.setValues(20L, -3L, 42L);+ Iterator<String> values = Arrays.asList("20", "-3", "42").iterator();+ casted.streamStrings( value -> {+ assertTrue(values.hasNext());+ assertEquals(values.next(), value);+ });+ assertFalse(values.hasNext());+ }++ @Test+ public void objectStreamCastingTest() {+ TestLongValueStream val = new TestLongValueStream();++ assertTrue(val instanceof AnalyticsValueStream);+ AnalyticsValueStream casted = (AnalyticsValueStream)val;++ // No values+ val.setValues();+ casted.streamObjects( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple Values+ val.setValues(20L, -3L, 42L);+ Iterator<Object> values = Arrays.<Object>asList(new Long(20L), new Long(-3L), new Long(42L)).iterator();+ casted.streamObjects( value -> {+ assertTrue(values.hasNext());+ assertEquals(values.next(), value);+ });+ assertFalse(values.hasNext());+ }++ @Test+ public void constantConversionTest() {+ AnalyticsValueStream val = new TestLongValueStream();+ assertSame(val, val.convertToConstant());+ }+}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingLongValueTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingLongValueTest.javanew file mode 100644index 00000000000..b3df7ed574d--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingLongValueTest.java@@ -0,0 +1,198 @@+/*+ * 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.analytics.value;++import java.util.Arrays;+import java.util.Iterator;++import org.apache.solr.SolrTestCaseJ4;+import org.apache.solr.analytics.value.AnalyticsValueStream.ExpressionType;+import org.apache.solr.analytics.value.FillableTestValue.TestLongValue;+import org.apache.solr.analytics.value.constant.ConstantLongValue;+import org.junit.Test;++public class CastingLongValueTest extends SolrTestCaseJ4 {++ @Test+ public void doubleCastingTest() {+ TestLongValue val = new TestLongValue();++ assertTrue(val instanceof DoubleValue);+ DoubleValue casted = (DoubleValue)val;++ val.setValue(20L).setExists(true);+ assertEquals(20.0, casted.getDouble(), .00001);+ assertTrue(casted.exists());++ val.setValue(1234L).setExists(true);+ assertEquals(1234.0, casted.getDouble(), .00001);+ assertTrue(casted.exists());+ }++ @Test+ public void stringCastingTest() {+ TestLongValue val = new TestLongValue();++ assertTrue(val instanceof StringValue);+ StringValue casted = (StringValue)val;++ val.setValue(20L).setExists(true);+ assertEquals("20", casted.getString());+ assertTrue(casted.exists());++ val.setValue(1234L).setExists(true);+ assertEquals("1234", casted.getString());+ assertTrue(casted.exists());+ }++ @Test+ public void objectCastingTest() {+ TestLongValue val = new TestLongValue();++ assertTrue(val instanceof AnalyticsValue);+ AnalyticsValue casted = (AnalyticsValue)val;++ val.setValue(20L).setExists(true);+ assertEquals(new Long(20), casted.getObject());+ assertTrue(casted.exists());++ val.setValue(1234L).setExists(true);+ assertEquals(new Long(1234), casted.getObject());+ assertTrue(casted.exists());+ }++ @Test+ public void longStreamCastingTest() {+ TestLongValue val = new TestLongValue();++ assertTrue(val instanceof LongValueStream);+ LongValueStream casted = (LongValueStream)val;++ // No values+ val.setExists(false);+ casted.streamLongs( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple Values+ val.setValue(20L).setExists(true);+ Iterator<Long> values = Arrays.asList(20L).iterator();+ casted.streamLongs( value -> {+ assertTrue(values.hasNext());+ assertEquals(values.next().longValue(), value);+ });+ assertFalse(values.hasNext());+ }++ @Test+ public void doubleStreamCastingTest() {+ TestLongValue val = new TestLongValue();++ assertTrue(val instanceof DoubleValueStream);+ DoubleValueStream casted = (DoubleValueStream)val;++ // No values+ val.setExists(false);+ casted.streamDoubles( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple Values+ val.setValue(20L).setExists(true);+ Iterator<Double> values = Arrays.asList(20.0).iterator();+ casted.streamDoubles( value -> {+ assertTrue(values.hasNext());+ assertEquals(values.next(), value, .00001);+ });+ assertFalse(values.hasNext());+ }++ @Test+ public void stringStreamCastingTest() {+ TestLongValue val = new TestLongValue();++ assertTrue(val instanceof StringValueStream);+ StringValueStream casted = (StringValueStream)val;++ // No values+ val.setExists(false);+ casted.streamStrings( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple Values+ val.setValue(20L).setExists(true);+ Iterator<String> values = Arrays.asList("20").iterator();+ casted.streamStrings( value -> {+ assertTrue(values.hasNext());+ assertEquals(values.next(), value);+ });+ assertFalse(values.hasNext());+ }++ @Test+ public void objectStreamCastingTest() {+ TestLongValue val = new TestLongValue();++ assertTrue(val instanceof AnalyticsValueStream);+ AnalyticsValueStream casted = (AnalyticsValueStream)val;++ // No values+ val.setExists(false);+ casted.streamObjects( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple Values+ val.setValue(20L).setExists(true);+ Iterator<Object> values = Arrays.<Object>asList(new Long(20L)).iterator();+ casted.streamObjects( value -> {+ assertTrue(values.hasNext());+ assertEquals(values.next(), value);+ });+ assertFalse(values.hasNext());+ }++ @Test+ public void constantConversionTest() {+ TestLongValue val = new TestLongValue(ExpressionType.CONST);+ val.setValue(12341L).setExists(true);+ AnalyticsValueStream conv = val.convertToConstant();+ assertTrue(conv instanceof ConstantLongValue);+ assertEquals(12341L, ((ConstantLongValue)conv).getLong());++ val = new TestLongValue(ExpressionType.FIELD);+ val.setValue(12341L).setExists(true);+ conv = val.convertToConstant();+ assertSame(val, conv);++ val = new TestLongValue(ExpressionType.UNREDUCED_MAPPING);+ val.setValue(12341L).setExists(true);+ conv = val.convertToConstant();+ assertSame(val, conv);++ val = new TestLongValue(ExpressionType.REDUCTION);+ val.setValue(12341L).setExists(true);+ conv = val.convertToConstant();+ assertSame(val, conv);++ val = new TestLongValue(ExpressionType.REDUCED_MAPPING);+ val.setValue(12341L).setExists(true);+ conv = val.convertToConstant();+ assertSame(val, conv);+ }+}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingStringValueStreamTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingStringValueStreamTest.javanew file mode 100644index 00000000000..8b1a2297c37--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingStringValueStreamTest.java@@ -0,0 +1,56 @@+/*+ * 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.analytics.value;++import java.util.Arrays;+import java.util.Iterator;++import org.apache.solr.SolrTestCaseJ4;+import org.apache.solr.analytics.value.FillableTestValue.TestStringValueStream;+import org.junit.Test;++public class CastingStringValueStreamTest extends SolrTestCaseJ4 {++ @Test+ public void objectStreamCastingTest() {+ TestStringValueStream val = new TestStringValueStream();++ assertTrue(val instanceof AnalyticsValueStream);+ AnalyticsValueStream casted = (AnalyticsValueStream)val;++ // No values+ val.setValues();+ casted.streamObjects( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple Values+ val.setValues("abc", "def", "ghi");+ Iterator<Object> values = Arrays.<Object>asList("abc", "def", "ghi").iterator();+ casted.streamObjects( value -> {+ assertTrue(values.hasNext());+ assertEquals(values.next(), value);+ });+ assertFalse(values.hasNext());+ }++ @Test+ public void constantConversionTest() {+ AnalyticsValueStream val = new TestStringValueStream();+ assertSame(val, val.convertToConstant());+ }+}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingStringValueTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingStringValueTest.javanew file mode 100644index 00000000000..3286a15ed94--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingStringValueTest.java@@ -0,0 +1,120 @@+/*+ * 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.analytics.value;++import java.util.Arrays;+import java.util.Iterator;++import org.apache.solr.SolrTestCaseJ4;+import org.apache.solr.analytics.value.AnalyticsValueStream.ExpressionType;+import org.apache.solr.analytics.value.FillableTestValue.TestStringValue;+import org.apache.solr.analytics.value.constant.ConstantStringValue;+import org.junit.Test;++public class CastingStringValueTest extends SolrTestCaseJ4 {++ @Test+ public void objectCastingTest() {+ TestStringValue val = new TestStringValue();++ assertTrue(val instanceof AnalyticsValue);+ AnalyticsValue casted = (AnalyticsValue)val;++ val.setValue("string 1").setExists(true);+ assertEquals("string 1", casted.getObject());+ assertTrue(casted.exists());++ val.setValue("abc").setExists(true);+ assertEquals("abc", casted.getObject());+ assertTrue(casted.exists());+ }++ @Test+ public void stringStreamCastingTest() {+ TestStringValue val = new TestStringValue();++ assertTrue(val instanceof StringValueStream);+ StringValueStream casted = (StringValueStream)val;++ // No values+ val.setExists(false);+ casted.streamStrings( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple Values+ val.setValue("abcd").setExists(true);+ Iterator<String> values = Arrays.asList("abcd").iterator();+ casted.streamStrings( value -> {+ assertTrue(values.hasNext());+ assertEquals(values.next(), value);+ });+ assertFalse(values.hasNext());+ }++ @Test+ public void objectStreamCastingTest() {+ TestStringValue val = new TestStringValue();++ assertTrue(val instanceof AnalyticsValueStream);+ AnalyticsValueStream casted = (AnalyticsValueStream)val;++ // No values+ val.setExists(false);+ casted.streamObjects( value -> {+ assertTrue("There should be no values to stream", false);+ });++ // Multiple Values+ val.setValue("abcd").setExists(true);+ Iterator<Object> values = Arrays.<Object>asList("abcd").iterator();+ casted.streamObjects( value -> {+ assertTrue(values.hasNext());+ assertEquals(values.next(), value);+ });+ assertFalse(values.hasNext());+ }++ @Test+ public void constantConversionTest() {+ TestStringValue val = new TestStringValue(ExpressionType.CONST);+ val.setValue("asd23n23").setExists(true);+ AnalyticsValueStream conv = val.convertToConstant();+ assertTrue(conv instanceof ConstantStringValue);+ assertEquals("asd23n23", ((ConstantStringValue)conv).getString());++ val = new TestStringValue(ExpressionType.FIELD);+ val.setValue("asd23n23").setExists(true);+ conv = val.convertToConstant();+ assertSame(val, conv);++ val = new TestStringValue(ExpressionType.UNREDUCED_MAPPING);+ val.setValue("asd23n23").setExists(true);+ conv = val.convertToConstant();+ assertSame(val, conv);++ val = new TestStringValue(ExpressionType.REDUCTION);+ val.setValue("asd23n23").setExists(true);+ conv = val.convertToConstant();+ assertSame(val, conv);++ val = new TestStringValue(ExpressionType.REDUCED_MAPPING);+ val.setValue("asd23n23").setExists(true);+ conv = val.convertToConstant();+ assertSame(val, conv);+ }+}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/ConstantValueTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/ConstantValueTest.javanew file mode 100644index 00000000000..bcdf7da5029--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/ConstantValueTest.java@@ -0,0 +1,368 @@+/*+ * 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.analytics.value;++import java.time.Instant;+import java.time.format.DateTimeParseException;+import java.util.Date;++import org.apache.solr.SolrTestCaseJ4;+import org.apache.solr.analytics.value.FillableTestValue.TestIntValue;+import org.apache.solr.analytics.value.constant.ConstantBooleanValue;+import org.apache.solr.analytics.value.constant.ConstantDateValue;+import org.apache.solr.analytics.value.constant.ConstantDoubleValue;+import org.apache.solr.analytics.value.constant.ConstantFloatValue;+import org.apache.solr.analytics.value.constant.ConstantIntValue;+import org.apache.solr.analytics.value.constant.ConstantLongValue;+import org.apache.solr.analytics.value.constant.ConstantStringValue;+import org.apache.solr.analytics.value.constant.ConstantValue;+import org.junit.Test;++public class ConstantValueTest extends SolrTestCaseJ4 {+++ @Test+ public void constantParsingTest() throws DateTimeParseException {+ // Int+ AnalyticsValueStream uncasted = ConstantValue.creatorFunction.apply("1234");+ assertTrue(uncasted instanceof ConstantIntValue);+ assertEquals(1234, ((ConstantIntValue)uncasted).getInt());++ // Long+ uncasted = ConstantValue.creatorFunction.apply("1234123412341234");+ assertTrue(uncasted instanceof ConstantLongValue);+ assertEquals(1234123412341234L, ((ConstantLongValue)uncasted).getLong());++ // Floats cannot currently be implicitly created++ // Double+ uncasted = ConstantValue.creatorFunction.apply("12341234.12341234");+ assertTrue(uncasted instanceof ConstantDoubleValue);+ assertEquals(12341234.12341234, ((ConstantDoubleValue)uncasted).getDouble(), .000000001);++ // String+ uncasted = ConstantValue.creatorFunction.apply("'abcdef'");+ assertTrue(uncasted instanceof ConstantStringValue);+ assertEquals("abcdef", ((ConstantStringValue)uncasted).getString());++ uncasted = ConstantValue.creatorFunction.apply("\"abcdef\"");+ assertTrue(uncasted instanceof ConstantStringValue);+ assertEquals("abcdef", ((ConstantStringValue)uncasted).getString());++ // Date+ uncasted = ConstantValue.creatorFunction.apply("1800-01-01T10:30:15.33Z");+ assertTrue(uncasted instanceof ConstantDateValue);+ assertEquals(Date.from(Instant.parse("1800-01-01T10:30:15.33Z")), ((ConstantDateValue)uncasted).getDate());+ }++ @Test+ public void constantConversionTest() {+ AnalyticsValueStream val = new ConstantBooleanValue(true);+ assertSame(val, val.convertToConstant());++ val = new ConstantIntValue(123);+ assertSame(val, val.convertToConstant());++ val = new ConstantLongValue(123L);+ assertSame(val, val.convertToConstant());++ val = new ConstantFloatValue(123F);+ assertSame(val, val.convertToConstant());++ val = new ConstantDoubleValue(123.0);+ assertSame(val, val.convertToConstant());++ val = new ConstantDateValue(123L);+ assertSame(val, val.convertToConstant());++ val = new ConstantStringValue("123");+ assertSame(val, val.convertToConstant());+ }++ @Test+ public void constantBooleanTest() {+ ConstantBooleanValue val = new ConstantBooleanValue(true);++ assertTrue(val.exists());+ assertEquals(true, val.getBoolean());+ assertEquals("true", val.getString());+ assertEquals(new Boolean(true), val.getObject());++ TestIntValue counter = new TestIntValue();+ counter.setValue(0);+ val.streamBooleans( value -> {+ assertEquals(true, value);+ assertEquals(0, counter.getInt());+ counter.setValue(1);+ });+ counter.setValue(0);+ val.streamStrings( value -> {+ assertEquals("true", value);+ assertEquals(0, counter.getInt());+ counter.setValue(1);+ });+ counter.setValue(0);+ val.streamObjects( value -> {+ assertEquals(new Boolean(true), value);+ assertEquals(0, counter.getInt());+ counter.setValue(1);+ });+++ val = new ConstantBooleanValue(false);++ assertTrue(val.exists());+ assertEquals(false, val.getBoolean());+ assertEquals("false", val.getString());+ assertEquals(new Boolean(false), val.getObject());++ counter.setValue(0);+ val.streamBooleans( value -> {+ assertEquals(false, value);+ assertEquals(0, counter.getInt());+ counter.setValue(1);+ });+ counter.setValue(0);+ val.streamStrings( value -> {+ assertEquals("false", value);+ assertEquals(0, counter.getInt());+ counter.setValue(1);+ });+ counter.setValue(0);+ val.streamObjects( value -> {+ assertEquals(new Boolean(false), value);+ assertEquals(0, counter.getInt());+ counter.setValue(1);+ });+ }++ @Test+ public void constantIntTest() {+ ConstantIntValue val = new ConstantIntValue(24);++ assertTrue(val.exists());+ assertEquals(24, val.getInt());+ assertEquals(24L, val.getLong());+ assertEquals(24F, val.getFloat(), .00001);+ assertEquals(24.0, val.getDouble(), .00001);+ assertEquals("24", val.getString());+ assertEquals(new Integer(24), val.getObject());++ TestIntValue counter = new TestIntValue();+ counter.setValue(0);+ val.streamInts( value -> {+ assertEquals(24, value);+ assertEquals(0, counter.getInt());+ counter.setValue(1);+ });+ counter.setValue(0);+ val.streamLongs( value -> {+ assertEquals(24L, value);+ assertEquals(0, counter.getInt());+ counter.setValue(1);+ });+ counter.setValue(0);+ val.streamFloats( value -> {+ assertEquals(24F, value, .00001);+ assertEquals(0, counter.getInt());+ counter.setValue(1);+ });+ counter.setValue(0);+ val.streamDoubles( value -> {+ assertEquals(24.0, value, .00001);+ assertEquals(0, counter.getInt());+ counter.setValue(1);+ });+ counter.setValue(0);+ val.streamStrings( value -> {+ assertEquals("24", value);+ assertEquals(0, counter.getInt());+ counter.setValue(1);+ });+ counter.setValue(0);+ val.streamObjects( value -> {+ assertEquals(new Integer(24), value);+ assertEquals(0, counter.getInt());+ counter.setValue(1);+ });+ }++ @Test+ public void constantLongTest() {+ ConstantLongValue val = new ConstantLongValue(24L);++ assertTrue(val.exists());+ assertEquals(24L, val.getLong());+ assertEquals(24.0, val.getDouble(), .00001);+ assertEquals("24", val.getString());+ assertEquals(new Long(24L), val.getObject());++ TestIntValue counter = new TestIntValue();+ counter.setValue(0);+ val.streamLongs( value -> {+ assertEquals(24L, value);+ assertEquals(0, counter.getInt());+ counter.setValue(1);+ });+ counter.setValue(0);+ val.streamDoubles( value -> {+ assertEquals(24.0, value, .00001);+ assertEquals(0, counter.getInt());+ counter.setValue(1);+ });+ counter.setValue(0);+ val.streamStrings( value -> {+ assertEquals("24", value);+ assertEquals(0, counter.getInt());+ counter.setValue(1);+ });+ counter.setValue(0);+ val.streamObjects( value -> {+ assertEquals(new Long(24L), value);+ assertEquals(0, counter.getInt());+ counter.setValue(1);+ });+ }++ @Test+ public void constantFloatTest() {+ ConstantFloatValue val = new ConstantFloatValue(24F);++ assertTrue(val.exists());+ assertEquals(24F, val.getFloat(), .00001);+ assertEquals(24.0, val.getDouble(), .00001);+ assertEquals("24.0", val.getString());+ assertEquals(new Float(24F), val.getObject());++ TestIntValue counter = new TestIntValue();+ counter.setValue(0);+ val.streamFloats( value -> {+ assertEquals(24F, value, .00001);+ assertEquals(0, counter.getInt());+ counter.setValue(1);+ });+ counter.setValue(0);+ val.streamDoubles( value -> {+ assertEquals(24.0, value, .00001);+ assertEquals(0, counter.getInt());+ counter.setValue(1);+ });+ counter.setValue(0);+ val.streamStrings( value -> {+ assertEquals("24.0", value);+ assertEquals(0, counter.getInt());+ counter.setValue(1);+ });+ counter.setValue(0);+ val.streamObjects( value -> {+ assertEquals(new Float(24F), value);+ assertEquals(0, counter.getInt());+ counter.setValue(1);+ });+ }++ @Test+ public void constantDoubleTest() {+ ConstantDoubleValue val = new ConstantDoubleValue(24.0);++ assertTrue(val.exists());+ assertEquals(24.0, val.getDouble(), .00001);+ assertEquals("24.0", val.getString());+ assertEquals(new Double(24.0), val.getObject());++ TestIntValue counter = new TestIntValue();+ counter.setValue(0);+ val.streamDoubles( value -> {+ assertEquals(24.0, value, .00001);+ assertEquals(0, counter.getInt());+ counter.setValue(1);+ });+ counter.setValue(0);+ val.streamStrings( value -> {+ assertEquals("24.0", value);+ assertEquals(0, counter.getInt());+ counter.setValue(1);+ });+ counter.setValue(0);+ val.streamObjects( value -> {+ assertEquals(new Double(24.0), value);+ assertEquals(0, counter.getInt());+ counter.setValue(1);+ });+ }++ @Test+ public void constantDateTest() throws DateTimeParseException {+ Date date = Date.from(Instant.parse("1800-01-01T10:30:15Z"));+ ConstantDateValue val = new ConstantDateValue(date.getTime());++ assertTrue(val.exists());+ assertEquals(date.getTime(), val.getLong());+ assertEquals(date, val.getDate());+ assertEquals("1800-01-01T10:30:15Z", val.getString());+ assertEquals(date, val.getObject());++ TestIntValue counter = new TestIntValue();+ counter.setValue(0);+ val.streamLongs( value -> {+ assertEquals(date.getTime(), value);+ assertEquals(0, counter.getInt());+ counter.setValue(1);+ });+ counter.setValue(0);+ val.streamDates( value -> {+ assertEquals(date, value);+ assertEquals(0, counter.getInt());+ counter.setValue(1);+ });+ counter.setValue(0);+ val.streamStrings( value -> {+ assertEquals("1800-01-01T10:30:15Z", value);+ assertEquals(0, counter.getInt());+ counter.setValue(1);+ });+ counter.setValue(0);+ val.streamObjects( value -> {+ assertEquals(date, value);+ assertEquals(0, counter.getInt());+ counter.setValue(1);+ });+ }++ @Test+ public void constantStringTest() {+ ConstantStringValue val = new ConstantStringValue("abcdef");++ assertTrue(val.exists());+ assertEquals("abcdef", val.getString());+ assertEquals("abcdef", val.getObject());++ TestIntValue counter = new TestIntValue();+ counter.setValue(0);+ val.streamStrings( value -> {+ assertEquals("abcdef", value);+ assertEquals(0, counter.getInt());+ counter.setValue(1);+ });+ counter.setValue(0);+ val.streamObjects( value -> {+ assertEquals("abcdef", value);+ assertEquals(0, counter.getInt());+ counter.setValue(1);+ });+ }+}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/FillableTestValue.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/FillableTestValue.javanew file mode 100644index 00000000000..7facef94d1b--- /dev/null+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/FillableTestValue.java@@ -0,0 +1,641 @@+/*+ * 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.analytics.value;++import java.time.Instant;+import java.time.format.DateTimeParseException;+import java.util.function.Consumer;+import java.util.function.DoubleConsumer;+import java.util.function.IntConsumer;+import java.util.function.LongConsumer;++import org.apache.solr.analytics.util.function.BooleanConsumer;+import org.apache.solr.analytics.util.function.FloatConsumer;+import org.apache.solr.analytics.value.AnalyticsValue.AbstractAnalyticsValue;+import org.apache.solr.analytics.value.AnalyticsValueStream.AbstractAnalyticsValueStream;+import org.apache.solr.analytics.value.BooleanValue.AbstractBooleanValue;+import org.apache.solr.analytics.value.BooleanValueStream.AbstractBooleanValueStream;+import org.apache.solr.analytics.value.DateValue.AbstractDateValue;+import org.apache.solr.analytics.value.DateValueStream.AbstractDateValueStream;+import org.apache.solr.analytics.value.DoubleValue.AbstractDoubleValue;+import org.apache.solr.analytics.value.DoubleValueStream.AbstractDoubleValueStream;+import org.apache.solr.analytics.value.FloatValue.AbstractFloatValue;+import org.apache.solr.analytics.value.FloatValueStream.AbstractFloatValueStream;+import org.apache.solr.analytics.value.IntValue.AbstractIntValue;+import org.apache.solr.analytics.value.IntValueStream.AbstractIntValueStream;+import org.apache.solr.analytics.value.LongValue.AbstractLongValue;+import org.apache.solr.analytics.value.LongValueStream.AbstractLongValueStream;+import org.apache.solr.analytics.value.StringValue.AbstractStringValue;+import org.apache.solr.analytics.value.StringValueStream.AbstractStringValueStream;++public class FillableTestValue {+ public static class TestAnalyticsValue extends AbstractAnalyticsValue {+ private final ExpressionType expressionType;++ private Object value;+ private boolean exists;++ public TestAnalyticsValue() {+ this(ExpressionType.CONST);+ }++ public TestAnalyticsValue(ExpressionType expressionType) {+ this.expressionType = expressionType;+ }++ public TestAnalyticsValue setValue(Object value) {+ this.value = value;+ return this;+ }++ public TestAnalyticsValue setExists(boolean exists) {+ this.exists = exists;+ return this;+ }++ @Override+ public Object getObject() {+ return value;+ }++ @Override+ public boolean exists() {+ return exists;+ }++ @Override+ public String getName() { return "test_analytics_value"; }++ @Override+ public String getExpressionStr() { return "test_analytics_value"; }++ @Override+ public ExpressionType getExpressionType() { return expressionType; }+ }++ public static class TestAnalyticsValueStream extends AbstractAnalyticsValueStream {+ private final ExpressionType expressionType;++ private Object[] values;++ public TestAnalyticsValueStream() {+ this(ExpressionType.CONST);+ }++ public TestAnalyticsValueStream(ExpressionType expressionType) {+ this.expressionType = expressionType;+ }++ public TestAnalyticsValueStream setValues(Object... values) {+ this.values = values;+ return this;+ }++ @Override+ public void streamObjects(Consumer<Object> cons) {+ for (int i = 0; i < values.length; ++i) {+ cons.accept(values[i]);+ }+ }++ @Override+ public String getName() { return "test_analytics_value_stream"; }++ @Override+ public String getExpressionStr() { return "test_analytics_value_stream"; }++ @Override+ public ExpressionType getExpressionType() { return expressionType; }+ }++ public static class TestIntValue extends AbstractIntValue {+ private final ExpressionType expressionType;++ private int value;+ private boolean exists;++ public TestIntValue() {+ this(ExpressionType.CONST);+ }++ public TestIntValue(ExpressionType expressionType) {+ this.expressionType = expressionType;+ }++ public TestIntValue setValue(int value) {+ this.value = value;+ return this;+ }++ public TestIntValue setExists(boolean exists) {+ this.exists = exists;+ return this;+ }++ @Override+ public int getInt() {+ return value;+ }++ @Override+ public boolean exists() {+ return exists;+ }++ @Override+ public String getName() { return "test_int_value"; }++ @Override+ public String getExpressionStr() { return "test_int_value"; }++ @Override+ public ExpressionType getExpressionType() { return expressionType; }+ }++ public static class TestIntValueStream extends AbstractIntValueStream {+ private int[] values;++ public TestIntValueStream() {+ this.values = new int[0];+ }++ public TestIntValueStream setValues(int... values) {+ this.values = values;+ return this;+ }++ @Override+ public void streamInts(IntConsumer cons) {+ for (int i = 0; i < values.length; ++i) {+ cons.accept(values[i]);+ }+ }++ @Override+ public String getName() { return "test_int_value_stream"; }++ @Override+ public String getExpressionStr() { return "test_int_value_stream"; }++ @Override+ public ExpressionType getExpressionType() { return ExpressionType.UNREDUCED_MAPPING; }+ }++ public static class TestLongValue extends AbstractLongValue {+ private final ExpressionType expressionType;++ private long value;+ private boolean exists;++ public TestLongValue() {+ this(ExpressionType.CONST);+ }++ public TestLongValue(ExpressionType expressionType) {+ this.expressionType = expressionType;+ }++ public TestLongValue setValue(long value) {+ this.value = value;+ return this;+ }++ public TestLongValue setExists(boolean exists) {+ this.exists = exists;+ return this;+ }++ @Override+ public long getLong() {+ return value;+ }++ @Override+ public boolean exists() {+ return exists;+ }++ @Override+ public String getName() { return "test_long_value"; }++ @Override+ public String getExpressionStr() { return "test_long_value"; }++ @Override+ public ExpressionType getExpressionType() { return expressionType; }+ }++ public static class TestLongValueStream extends AbstractLongValueStream {+ private long[] values;++ public TestLongValueStream() {+ this.values = new long[0];+ }++ public TestLongValueStream setValues(long... values) {+ this.values = values;+ return this;+ }++ @Override+ public void streamLongs(LongConsumer cons) {+ for (int i = 0; i < values.length; ++i) {+ cons.accept(values[i]);+ }+ }++ @Override+ public String getName() { return "test_long_value_stream"; }++ @Override+ public String getExpressionStr() { return "test_long_value_stream"; }++ @Override+ public ExpressionType getExpressionType() { return ExpressionType.UNREDUCED_MAPPING; }+ }++ public static class TestFloatValue extends AbstractFloatValue {+ private final ExpressionType expressionType;++ private float value;+ private boolean exists;++ public TestFloatValue() {+ this(ExpressionType.CONST);+ }++ public TestFloatValue(ExpressionType expressionType) {+ this.expressionType = expressionType;+ }++ public TestFloatValue setValue(float value) {+ this.value = value;+ return this;+ }++ public TestFloatValue setExists(boolean exists) {+ this.exists = exists;+ return this;+ }++ @Override+ public float getFloat() {+ return value;+ }++ @Override+ public boolean exists() {+ return exists;+ }++ @Override+ public String getName() { return "test_float_value"; }++ @Override+ public String getExpressionStr() { return "test_float_value"; }++ @Override+ public ExpressionType getExpressionType() { return expressionType; }+ }++ public static class TestFloatValueStream extends AbstractFloatValueStream {+ private float[] values;++ public TestFloatValueStream() {+ this.values = new float[0];+ }++ public TestFloatValueStream setValues(float... values) {+ this.values = values;+ return this;+ }++ @Override+ public void streamFloats(FloatConsumer cons) {+ for (int i = 0; i < values.length; ++i) {+ cons.accept(values[i]);+ }+ }++ @Override+ public String getName() { return "test_float_value_stream"; }++ @Override+ public String getExpressionStr() { return "test_float_value_stream"; }++ @Override+ public ExpressionType getExpressionType() { return ExpressionType.UNREDUCED_MAPPING; }+ }++ public static class TestDoubleValue extends AbstractDoubleValue {+ private final ExpressionType expressionType;++ private double value;+ private boolean exists;++ public TestDoubleValue() {+ this(ExpressionType.CONST);+ }++ public TestDoubleValue(ExpressionType expressionType) {+ this.expressionType = expressionType;+ }++ public TestDoubleValue setValue(double value) {+ this.value = value;+ return this;+ }++ public TestDoubleValue setExists(boolean exists) {+ this.exists = exists;+ return this;+ }++ @Override+ public double getDouble() {+ return value;+ }++ @Override+ public boolean exists() {+ return exists;+ }++ @Override+ public String getName() { return "test_double_value"; }++ @Override+ public String getExpressionStr() { return "test_double_value"; }++ @Override+ public ExpressionType getExpressionType() { return expressionType; }+ }++ public static class TestDoubleValueStream extends AbstractDoubleValueStream {+ private double[] values;++ public TestDoubleValueStream() {+ this.values = new double[0];+ }++ public TestDoubleValueStream setValues(double... values) {+ this.values = values;+ return this;+ }++ @Override+ public void streamDoubles(DoubleConsumer cons) {+ for (int i = 0; i < values.length; ++i) {+ cons.accept(values[i]);+ }+ }++ @Override+ public String getName() { return "test_double_value_stream"; }++ @Override+ public String getExpressionStr() { return "test_double_value_stream"; }++ @Override+ public ExpressionType getExpressionType() { return ExpressionType.UNREDUCED_MAPPING; }+ }++ public static class TestBooleanValue extends AbstractBooleanValue {+ private final ExpressionType expressionType;++ private boolean value;+ private boolean exists;++ public TestBooleanValue() {+ this(ExpressionType.CONST);+ }++ public TestBooleanValue(ExpressionType expressionType) {+ this.expressionType = expressionType;+ }++ public TestBooleanValue setValue(boolean value) {+ this.value = value;+ return this;+ }++ public TestBooleanValue setExists(boolean exists) {+ this.exists = exists;+ return this;+ }++ @Override+ public boolean getBoolean() {+ return value;+ }++ @Override+ public boolean exists() {+ return exists;+ }++ @Override+ public String getName() { return "test_boolean_value"; }++ @Override+ public String getExpressionStr() { return "test_boolean_value"; }++ @Override+ public ExpressionType getExpressionType() { return expressionType; }+ }++ public static class TestBooleanValueStream extends AbstractBooleanValueStream {+ private boolean[] values;++ public TestBooleanValueStream() {+ this.values = new boolean[0];+ }++ public TestBooleanValueStream setValues(boolean... values) {+ this.values = values;+ return this;+ }++ @Override+ public void streamBooleans(BooleanConsumer cons) {+ for (int i = 0; i < values.length; ++i) {+ cons.accept(values[i]);+ }+ }++ @Override+ public String getName() { return "test_boolean_value_stream"; }++ @Override+ public String getExpressionStr() { return "test_boolean_value_stream"; }++ @Override+ public ExpressionType getExpressionType() { return ExpressionType.UNREDUCED_MAPPING; }+ }++ public static class TestDateValue extends AbstractDateValue {+ private final ExpressionType expressionType;++ private long value;+ private boolean exists;++ public TestDateValue() {+ this(ExpressionType.CONST);+ }++ public TestDateValue(ExpressionType expressionType) {+ this.expressionType = expressionType;+ }++ public TestDateValue setValue(String value) {+ try {+ this.value = Instant.parse(value).toEpochMilli();+ } catch (DateTimeParseException e) {+ this.value = 0;+ }+ return this;+ }++ public TestDateValue setExists(boolean exists) {+ this.exists = exists;+ return this;+ }++ @Override+ public long getLong() {+ return value;+ }++ @Override+ public boolean exists() {+ return exists;+ }++ @Override+ public String getName() { return "test_date_value"; }++ @Override+ public String getExpressionStr() { return "test_date_value"; }++ @Override+ public ExpressionType getExpressionType() { return expressionType; }+ }++ public static class TestDateValueStream extends AbstractDateValueStream {+ private String[] values;++ public TestDateValueStream() {+ this.values = new String[0];+ }++ public TestDateValueStream setValues(String... values) {+ this.values = values;+ return this;+ }++ @Override+ public void streamLongs(LongConsumer cons) {+ for (int i = 0; i < values.length; ++i) {+ try {+ cons.accept(Instant.parse(values[i]).toEpochMilli());+ } catch (DateTimeParseException e) { }+ }+ }++ @Override+ public String getName() { return "test_date_value_stream"; }++ @Override+ public String getExpressionStr() { return "test_date_value_stream"; }++ @Override+ public ExpressionType getExpressionType() { return ExpressionType.UNREDUCED_MAPPING; }+ }++ public static class TestStringValue extends AbstractStringValue {+ private final ExpressionType expressionType;++ private String value;+ private boolean exists;++ public TestStringValue() {+ this(ExpressionType.CONST);+ }++ public TestStringValue(ExpressionType expressionType) {+ this.expressionType = expressionType;+ }++ public TestStringValue setValue(String value) {+ this.value = value;+ return this;+ }++ public TestStringValue setExists(boolean exists) {+ this.exists = exists;+ return this;+ }++ @Override+ public String getString() {+ return value;+ }++ @Override+ public boolean exists() {+ return exists;+ }++ @Override+ public String getName() { return "test_string_value"; }++ @Override+ public String getExpressionStr() { return "test_string_value"; }++ @Override+ public ExpressionType getExpressionType() { return expressionType; }+ }++ public static class TestStringValueStream extends AbstractStringValueStream {+ private String[] values;++ public TestStringValueStream() {+ this.values = new String[0];+ }++ public TestStringValueStream setValues(String... values) {+ this.values = values;+ return this;+ }++ @Override+ public void streamStrings(Consumer<String> cons) {+ for (int i = 0; i < values.length; ++i) {+ cons.accept(values[i]);+ }+ }++ @Override+ public String getName() { return "test_string_value_stream"; }++ @Override+ public String getExpressionStr() { return "test_string_value_stream"; }++ @Override+ public ExpressionType getExpressionType() { return ExpressionType.UNREDUCED_MAPPING; }+ }+}