You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by ja...@apache.org on 2023/05/12 21:43:56 UTC
[solr] branch main updated: SOLR-16661 Remove deprecated Analytics Component in 10.0 (#1622)
This is an automated email from the ASF dual-hosted git repository.
janhoy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/main by this push:
new 67afcc228de SOLR-16661 Remove deprecated Analytics Component in 10.0 (#1622)
67afcc228de is described below
commit 67afcc228de5efe27f8a60ece5d5d2862eeeeb24
Author: Jan Høydahl <ja...@users.noreply.github.com>
AuthorDate: Fri May 12 23:43:49 2023 +0200
SOLR-16661 Remove deprecated Analytics Component in 10.0 (#1622)
---
gradle/documentation/render-javadoc.gradle | 11 -
settings.gradle | 1 -
solr/CHANGES.txt | 2 +
.../solr/handler/component/ResponseBuilder.java | 27 -
.../handler/component/ResponseBuilderTest.java | 26 -
solr/modules/analytics/build.gradle | 36 -
.../org/apache/solr/analytics/AnalyticsDriver.java | 85 -
.../apache/solr/analytics/AnalyticsExpression.java | 64 -
.../solr/analytics/AnalyticsGroupingManager.java | 245 --
.../solr/analytics/AnalyticsRequestManager.java | 292 --
.../solr/analytics/AnalyticsRequestParser.java | 656 ----
.../apache/solr/analytics/ExpressionFactory.java | 1109 ------
.../solr/analytics/TimeExceededStubException.java | 35 -
.../analytics/facet/AbstractSolrQueryFacet.java | 110 -
.../solr/analytics/facet/AnalyticsFacet.java | 167 -
.../apache/solr/analytics/facet/PivotFacet.java | 115 -
.../org/apache/solr/analytics/facet/PivotNode.java | 265 --
.../apache/solr/analytics/facet/QueryFacet.java | 63 -
.../apache/solr/analytics/facet/RangeFacet.java | 117 -
.../apache/solr/analytics/facet/SortableFacet.java | 170 -
.../solr/analytics/facet/StreamingFacet.java | 31 -
.../apache/solr/analytics/facet/ValueFacet.java | 59 -
.../facet/compare/ConstantComparator.java | 28 -
.../facet/compare/DelegatingComparator.java | 65 -
.../facet/compare/ExpressionComparator.java | 45 -
.../facet/compare/FacetResultsComparator.java | 48 -
.../facet/compare/FacetValueComparator.java | 36 -
.../solr/analytics/facet/compare/package-info.java | 19 -
.../apache/solr/analytics/facet/package-info.java | 19 -
.../analytics/function/ExpressionCalculator.java | 70 -
.../MergingReductionCollectionManager.java | 48 -
.../function/ReductionCollectionManager.java | 328 --
.../solr/analytics/function/ReductionFunction.java | 34 -
.../analytics/function/field/AnalyticsField.java | 72 -
.../analytics/function/field/BooleanField.java | 113 -
.../function/field/BooleanMultiField.java | 100 -
.../solr/analytics/function/field/DateField.java | 115 -
.../function/field/DateMultiPointField.java | 46 -
.../function/field/DateMultiTrieField.java | 51 -
.../solr/analytics/function/field/DoubleField.java | 101 -
.../function/field/DoubleMultiPointField.java | 81 -
.../function/field/DoubleMultiTrieField.java | 92 -
.../solr/analytics/function/field/FloatField.java | 114 -
.../function/field/FloatMultiPointField.java | 87 -
.../function/field/FloatMultiTrieField.java | 98 -
.../solr/analytics/function/field/IntField.java | 140 -
.../function/field/IntMultiPointField.java | 98 -
.../function/field/IntMultiTrieField.java | 107 -
.../solr/analytics/function/field/LongField.java | 114 -
.../function/field/LongMultiPointField.java | 86 -
.../function/field/LongMultiTrieField.java | 95 -
.../solr/analytics/function/field/StringField.java | 115 -
.../analytics/function/field/StringMultiField.java | 63 -
.../analytics/function/field/package-info.java | 19 -
.../function/mapping/AbsoluteValueFunction.java | 68 -
.../analytics/function/mapping/AddFunction.java | 84 -
.../analytics/function/mapping/BottomFunction.java | 185 -
.../function/mapping/ComparisonFunction.java | 368 --
.../analytics/function/mapping/ConcatFunction.java | 142 -
.../function/mapping/DateMathFunction.java | 177 -
.../function/mapping/DateParseFunction.java | 228 --
.../mapping/DecimalNumericConversionFunction.java | 285 --
.../analytics/function/mapping/DivideFunction.java | 60 -
.../analytics/function/mapping/EqualFunction.java | 264 --
.../analytics/function/mapping/ExistsFunction.java | 130 -
.../function/mapping/FillMissingFunction.java | 938 -----
.../analytics/function/mapping/FilterFunction.java | 796 ----
.../analytics/function/mapping/IfFunction.java | 988 -----
.../analytics/function/mapping/LambdaFunction.java | 3834 --------------------
.../analytics/function/mapping/LogFunction.java | 67 -
.../analytics/function/mapping/LogicFunction.java | 104 -
.../analytics/function/mapping/MultFunction.java | 84 -
.../analytics/function/mapping/NegateFunction.java | 72 -
.../analytics/function/mapping/PowerFunction.java | 62 -
.../analytics/function/mapping/RemoveFunction.java | 874 -----
.../function/mapping/ReplaceFunction.java | 1073 ------
.../function/mapping/StringCastFunction.java | 47 -
.../function/mapping/SubtractFunction.java | 59 -
.../analytics/function/mapping/TopFunction.java | 185 -
.../analytics/function/mapping/package-info.java | 19 -
.../solr/analytics/function/package-info.java | 19 -
.../function/reduction/CountFunction.java | 91 -
.../function/reduction/DocCountFunction.java | 91 -
.../analytics/function/reduction/MaxFunction.java | 327 --
.../analytics/function/reduction/MeanFunction.java | 96 -
.../function/reduction/MedianFunction.java | 213 --
.../analytics/function/reduction/MinFunction.java | 327 --
.../function/reduction/MissingFunction.java | 81 -
.../function/reduction/OrdinalFunction.java | 393 --
.../function/reduction/PercentileFunction.java | 373 --
.../analytics/function/reduction/SumFunction.java | 91 -
.../function/reduction/UniqueFunction.java | 104 -
.../function/reduction/data/CountCollector.java | 181 -
.../function/reduction/data/MaxCollector.java | 487 ---
.../function/reduction/data/MinCollector.java | 487 ---
.../function/reduction/data/ReductionData.java | 22 -
.../reduction/data/ReductionDataCollector.java | 179 -
.../reduction/data/SortedListCollector.java | 354 --
.../function/reduction/data/SumCollector.java | 123 -
.../function/reduction/data/UniqueCollector.java | 230 --
.../function/reduction/data/package-info.java | 22 -
.../analytics/function/reduction/package-info.java | 19 -
.../org/apache/solr/analytics/package-info.java | 19 -
.../apache/solr/analytics/plugin/package-info.java | 19 -
.../stream/AnalyticsShardRequestManager.java | 245 --
.../stream/AnalyticsShardResponseParser.java | 94 -
.../apache/solr/analytics/stream/package-info.java | 19 -
.../reservation/BooleanArrayReservation.java | 48 -
.../reservation/BooleanCheckedReservation.java | 43 -
.../stream/reservation/BooleanReservation.java | 41 -
.../stream/reservation/DoubleArrayReservation.java | 48 -
.../reservation/DoubleCheckedReservation.java | 44 -
.../stream/reservation/DoubleReservation.java | 41 -
.../stream/reservation/FloatArrayReservation.java | 48 -
.../reservation/FloatCheckedReservation.java | 44 -
.../stream/reservation/FloatReservation.java | 41 -
.../stream/reservation/IntArrayReservation.java | 45 -
.../stream/reservation/IntCheckedReservation.java | 43 -
.../stream/reservation/IntReservation.java | 41 -
.../stream/reservation/LongArrayReservation.java | 48 -
.../stream/reservation/LongCheckedReservation.java | 44 -
.../stream/reservation/LongReservation.java | 41 -
.../ReductionCheckedDataReservation.java | 34 -
.../reservation/ReductionDataArrayReservation.java | 37 -
.../reservation/ReductionDataReservation.java | 54 -
.../stream/reservation/StringArrayReservation.java | 48 -
.../reservation/StringCheckedReservation.java | 44 -
.../stream/reservation/StringReservation.java | 42 -
.../analytics/stream/reservation/package-info.java | 22 -
.../reservation/read/BooleanCheckedDataReader.java | 33 -
.../reservation/read/BooleanDataArrayReader.java | 37 -
.../stream/reservation/read/BooleanDataReader.java | 33 -
.../reservation/read/DoubleCheckedDataReader.java | 33 -
.../reservation/read/DoubleDataArrayReader.java | 36 -
.../stream/reservation/read/DoubleDataReader.java | 33 -
.../reservation/read/FloatCheckedDataReader.java | 33 -
.../reservation/read/FloatDataArrayReader.java | 36 -
.../stream/reservation/read/FloatDataReader.java | 33 -
.../reservation/read/IntCheckedDataReader.java | 33 -
.../reservation/read/IntDataArrayReader.java | 35 -
.../stream/reservation/read/IntDataReader.java | 33 -
.../reservation/read/LongCheckedDataReader.java | 33 -
.../reservation/read/LongDataArrayReader.java | 36 -
.../stream/reservation/read/LongDataReader.java | 33 -
.../read/ReductionCheckedDataReader.java | 52 -
.../reservation/read/ReductionDataArrayReader.java | 56 -
.../reservation/read/ReductionDataReader.java | 38 -
.../reservation/read/StringCheckedDataReader.java | 33 -
.../reservation/read/StringDataArrayReader.java | 37 -
.../stream/reservation/read/StringDataReader.java | 35 -
.../stream/reservation/read/package-info.java | 22 -
.../write/BooleanCheckedDataWriter.java | 34 -
.../reservation/write/BooleanDataArrayWriter.java | 37 -
.../reservation/write/BooleanDataWriter.java | 33 -
.../reservation/write/DoubleCheckedDataWriter.java | 35 -
.../reservation/write/DoubleDataArrayWriter.java | 37 -
.../stream/reservation/write/DoubleDataWriter.java | 33 -
.../reservation/write/FloatCheckedDataWriter.java | 35 -
.../reservation/write/FloatDataArrayWriter.java | 37 -
.../stream/reservation/write/FloatDataWriter.java | 33 -
.../reservation/write/IntCheckedDataWriter.java | 35 -
.../reservation/write/IntDataArrayWriter.java | 35 -
.../stream/reservation/write/IntDataWriter.java | 33 -
.../reservation/write/LongCheckedDataWriter.java | 35 -
.../reservation/write/LongDataArrayWriter.java | 36 -
.../stream/reservation/write/LongDataWriter.java | 33 -
.../write/ReductionCheckedDataWriter.java | 60 -
.../write/ReductionDataArrayWriter.java | 54 -
.../reservation/write/ReductionDataWriter.java | 41 -
.../reservation/write/StringCheckedDataWriter.java | 35 -
.../reservation/write/StringDataArrayWriter.java | 37 -
.../stream/reservation/write/StringDataWriter.java | 37 -
.../stream/reservation/write/package-info.java | 22 -
.../analytics/util/AnalyticsResponseHeadings.java | 34 -
.../solr/analytics/util/FacetRangeGenerator.java | 405 ---
.../solr/analytics/util/MedianCalculator.java | 133 -
.../solr/analytics/util/OldAnalyticsParams.java | 164 -
.../util/OldAnalyticsRequestConverter.java | 220 --
.../solr/analytics/util/OrdinalCalculator.java | 174 -
.../analytics/util/function/BooleanConsumer.java | 60 -
.../analytics/util/function/FloatConsumer.java | 60 -
.../analytics/util/function/FloatSupplier.java | 41 -
.../solr/analytics/util/function/package-info.java | 19 -
.../apache/solr/analytics/util/package-info.java | 19 -
.../solr/analytics/value/AnalyticsValue.java | 59 -
.../solr/analytics/value/AnalyticsValueStream.java | 154 -
.../apache/solr/analytics/value/BooleanValue.java | 100 -
.../solr/analytics/value/BooleanValueStream.java | 62 -
.../solr/analytics/value/ComparableValue.java | 30 -
.../org/apache/solr/analytics/value/DateValue.java | 119 -
.../solr/analytics/value/DateValueStream.java | 72 -
.../apache/solr/analytics/value/DoubleValue.java | 100 -
.../solr/analytics/value/DoubleValueStream.java | 62 -
.../apache/solr/analytics/value/FloatValue.java | 115 -
.../solr/analytics/value/FloatValueStream.java | 69 -
.../org/apache/solr/analytics/value/IntValue.java | 141 -
.../solr/analytics/value/IntValueStream.java | 85 -
.../org/apache/solr/analytics/value/LongValue.java | 115 -
.../solr/analytics/value/LongValueStream.java | 69 -
.../apache/solr/analytics/value/StringValue.java | 84 -
.../solr/analytics/value/StringValueStream.java | 56 -
.../value/constant/ConstantBooleanValue.java | 96 -
.../value/constant/ConstantDateValue.java | 109 -
.../value/constant/ConstantDoubleValue.java | 95 -
.../value/constant/ConstantFloatValue.java | 106 -
.../analytics/value/constant/ConstantIntValue.java | 128 -
.../value/constant/ConstantLongValue.java | 106 -
.../value/constant/ConstantStringValue.java | 82 -
.../analytics/value/constant/ConstantValue.java | 101 -
.../analytics/value/constant/package-info.java | 19 -
.../apache/solr/analytics/value/package-info.java | 19 -
.../org/apache/solr/handler/AnalyticsHandler.java | 146 -
.../solr/handler/component/AnalyticsComponent.java | 178 -
.../org/apache/solr/handler/component/package.html | 28 -
.../src/java/org/apache/solr/handler/package.html | 28 -
.../response/AnalyticsShardResponseWriter.java | 90 -
.../src/java/org/apache/solr/response/package.html | 28 -
solr/modules/analytics/src/java/overview.html | 21 -
solr/modules/analytics/src/test-files/log4j2.xml | 42 -
.../solr/analytics/legacy/expressions.txt | 65 -
.../solr/analytics/legacy/facetSorting.txt | 4 -
.../analytics/legacy/facetWithDottedFields.txt | 16 -
.../solr/analytics/legacy/fieldFacetExtras.txt | 66 -
.../solr/analytics/legacy/fieldFacets.txt | 132 -
.../test-files/solr/analytics/legacy/functions.txt | 57 -
.../test-files/solr/analytics/legacy/noFacets.txt | 74 -
.../solr/analytics/legacy/queryFacets.txt | 27 -
.../solr/analytics/legacy/rangeFacets.txt | 161 -
.../solr/collection1/conf/schema-analytics.xml | 131 -
.../solr/collection1/conf/solrconfig-analytics.xml | 42 -
.../conf/solrconfig.snippet.randomindexconfig.xml | 46 -
.../configsets/cloud-analytics/conf/schema.xml | 78 -
.../configsets/cloud-analytics/conf/solrconfig.xml | 59 -
.../solr/analytics/ExpressionFactoryTest.java | 311 --
.../org/apache/solr/analytics/NoFacetTest.java | 188 -
.../solr/analytics/OverallAnalyticsTest.java | 262 --
.../solr/analytics/SolrAnalyticsTestCase.java | 448 ---
.../solr/analytics/facet/PivotFacetTest.java | 175 -
.../solr/analytics/facet/QueryFacetTest.java | 53 -
.../solr/analytics/facet/RangeFacetTest.java | 270 --
.../facet/SolrAnalyticsFacetTestCase.java | 80 -
.../solr/analytics/facet/ValueFacetTest.java | 379 --
.../function/field/AbstractAnalyticsFieldTest.java | 300 --
.../function/field/BooleanFieldsTest.java | 77 -
.../analytics/function/field/DateFieldsTest.java | 121 -
.../analytics/function/field/DoubleFieldsTest.java | 121 -
.../analytics/function/field/FloatFieldsTest.java | 121 -
.../analytics/function/field/IntFieldsTest.java | 121 -
.../analytics/function/field/LongFieldsTest.java | 121 -
.../analytics/function/field/StringFieldsTest.java | 77 -
.../mapping/AbsoluteValueFunctionTest.java | 286 --
.../function/mapping/AddFunctionTest.java | 162 -
.../function/mapping/AndFunctionTest.java | 199 -
.../function/mapping/BottomFunctionTest.java | 425 ---
.../function/mapping/CeilingFunctionTest.java | 187 -
.../function/mapping/ConcatFunctionTest.java | 341 --
.../function/mapping/DateMathFunctionTest.java | 136 -
.../function/mapping/DateParseFunctionTest.java | 265 --
.../function/mapping/DivideFunctionTest.java | 136 -
.../function/mapping/EqualFunctionTest.java | 580 ---
.../function/mapping/ExistsFunctionTest.java | 75 -
.../function/mapping/FillMissingFunctionTest.java | 789 ----
.../function/mapping/FilterFunctionTest.java | 1123 ------
.../function/mapping/FloorFunctionTest.java | 187 -
.../function/mapping/GTEFunctionTest.java | 321 --
.../analytics/function/mapping/GTFunctionTest.java | 321 --
.../analytics/function/mapping/IfFunctionTest.java | 1100 ------
.../function/mapping/LTEFunctionTest.java | 321 --
.../analytics/function/mapping/LTFunctionTest.java | 321 --
.../function/mapping/LogFunctionTest.java | 210 --
.../function/mapping/MultFunctionTest.java | 161 -
.../function/mapping/NegateFunctionTest.java | 351 --
.../analytics/function/mapping/OrFunctionTest.java | 199 -
.../function/mapping/PowerFunctionTest.java | 136 -
.../function/mapping/RemoveFunctionTest.java | 955 -----
.../function/mapping/ReplaceFunctionTest.java | 1108 ------
.../function/mapping/RoundFunctionTest.java | 187 -
.../function/mapping/StringCastFunctionTest.java | 91 -
.../function/mapping/SubtractFunctionTest.java | 136 -
.../function/mapping/TopFunctionTest.java | 425 ---
.../legacy/LegacyAbstractAnalyticsCloudTest.java | 192 -
.../legacy/LegacyAbstractAnalyticsTest.java | 263 --
.../analytics/legacy/LegacyNoFacetCloudTest.java | 570 ---
.../solr/analytics/legacy/LegacyNoFacetTest.java | 459 ---
.../legacy/expression/LegacyExpressionTest.java | 223 --
.../legacy/expression/LegacyFunctionTest.java | 270 --
.../LegacyAbstractAnalyticsFacetCloudTest.java | 208 --
.../facet/LegacyAbstractAnalyticsFacetTest.java | 357 --
.../legacy/facet/LegacyFacetSortingTest.java | 54 -
.../legacy/facet/LegacyFieldFacetCloudTest.java | 1444 --------
.../facet/LegacyFieldFacetExtrasCloudTest.java | 260 --
.../legacy/facet/LegacyFieldFacetExtrasTest.java | 182 -
.../legacy/facet/LegacyFieldFacetTest.java | 1234 -------
.../legacy/facet/LegacyQueryFacetCloudTest.java | 173 -
.../legacy/facet/LegacyQueryFacetTest.java | 135 -
.../legacy/facet/LegacyRangeFacetCloudTest.java | 653 ----
.../legacy/facet/LegacyRangeFacetTest.java | 471 ---
.../util/OldAnalyticsRequestConverterUnitTest.java | 73 -
.../analytics/value/CastingAnalyticsValueTest.java | 56 -
.../value/CastingBooleanValueStreamTest.java | 81 -
.../analytics/value/CastingBooleanValueTest.java | 155 -
.../value/CastingDateValueStreamTest.java | 115 -
.../solr/analytics/value/CastingDateValueTest.java | 165 -
.../value/CastingDoubleValueStreamTest.java | 80 -
.../analytics/value/CastingDoubleValueTest.java | 155 -
.../value/CastingFloatValueStreamTest.java | 104 -
.../analytics/value/CastingFloatValueTest.java | 192 -
.../analytics/value/CastingIntValueStreamTest.java | 152 -
.../solr/analytics/value/CastingIntValueTest.java | 266 --
.../value/CastingLongValueStreamTest.java | 104 -
.../solr/analytics/value/CastingLongValueTest.java | 192 -
.../value/CastingStringValueStreamTest.java | 56 -
.../analytics/value/CastingStringValueTest.java | 118 -
.../solr/analytics/value/ConstantValueTest.java | 396 --
.../solr/analytics/value/FillableTestValue.java | 737 ----
.../pages/configuring-solr-xml.adoc | 1 +
.../pages/requesthandlers-searchcomponents.adoc | 1 -
.../deployment-guide/pages/metrics-reporting.adoc | 1 +
.../pages/analytics-expression-sources.adoc | 95 -
.../pages/analytics-mapping-functions.adoc | 363 --
.../pages/analytics-reduction-functions.adoc | 128 -
.../modules/query-guide/pages/analytics.adoc | 967 -----
.../query-guide/pages/common-query-parameters.adoc | 2 +-
.../modules/query-guide/querying-nav.adoc | 4 -
.../pages/major-changes-in-solr-10.adoc | 1 +
.../pages/major-changes-in-solr-7.adoc | 2 +-
.../pages/major-changes-in-solr-9.adoc | 2 +-
.../src/java/org/apache/solr/SolrTestCase.java | 3 -
328 files changed, 8 insertions(+), 56330 deletions(-)
diff --git a/gradle/documentation/render-javadoc.gradle b/gradle/documentation/render-javadoc.gradle
index 99275293657..29e43f913ce 100644
--- a/gradle/documentation/render-javadoc.gradle
+++ b/gradle/documentation/render-javadoc.gradle
@@ -116,17 +116,6 @@ configure(project(":solr:modules:analysis-extras")) {
}
}
-configure(project(":solr:modules:analytics")) {
- project.tasks.withType(RenderJavadocTask) {
- // TODO: clean up split packages SOLR-15604
- javadocMissingIgnore = [
- "org.apache.solr.handler",
- "org.apache.solr.handler.component",
- "org.apache.solr.response"
- ]
- }
-}
-
configure(project(":solr:modules:langid")) {
project.tasks.withType(RenderJavadocTask) {
// TODO: clean up split packages SOLR-15604
diff --git a/settings.gradle b/settings.gradle
index 3e9b0c4e065..65235015950 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -32,7 +32,6 @@ include "solr:solrj-streaming"
include "solr:core"
include "solr:server"
include "solr:modules:analysis-extras"
-include "solr:modules:analytics"
include "solr:modules:clustering"
include "solr:modules:opentelemetry"
include "solr:modules:extraction"
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index d3a39aefe04..f5f70eb1174 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -31,6 +31,8 @@ Deprecation Removals
* SOLR-15703: Removed deprecated SolrException#log methods (Kevin Risden)
+* SOLR-16661: Removed deprecated 'analytics' component (janhoy)
+
Dependency Upgrades
---------------------
(No changes)
diff --git a/solr/core/src/java/org/apache/solr/handler/component/ResponseBuilder.java b/solr/core/src/java/org/apache/solr/handler/component/ResponseBuilder.java
index bb06eac78e1..ea90503ef5c 100644
--- a/solr/core/src/java/org/apache/solr/handler/component/ResponseBuilder.java
+++ b/solr/core/src/java/org/apache/solr/handler/component/ResponseBuilder.java
@@ -60,7 +60,6 @@ public class ResponseBuilder {
public boolean doExpand;
public boolean doStats;
public boolean doTerms;
- public boolean doAnalytics;
public MergeStrategy mergeFieldHandler;
public String queryID;
@@ -181,8 +180,6 @@ public class ResponseBuilder {
StatsInfo _statsInfo;
TermsComponent.TermsHelper _termsHelper;
SimpleOrderedMap<List<NamedList<Object>>> _pivots;
- Object _analyticsRequestManager;
- boolean _isOlapAnalytics;
// Context fields for grouping
public final Map<String, Collection<SearchGroup<BytesRef>>> mergedSearchGroups = new HashMap<>();
@@ -492,30 +489,6 @@ public class ResponseBuilder {
this.nextCursorMark = nextCursorMark;
}
- public void setAnalytics(boolean doAnalytics) {
- this.doAnalytics = doAnalytics;
- }
-
- public boolean isAnalytics() {
- return this.doAnalytics;
- }
-
- public void setAnalyticsRequestManager(Object analyticsRequestManager) {
- this._analyticsRequestManager = analyticsRequestManager;
- }
-
- public Object getAnalyticsRequestManager() {
- return this._analyticsRequestManager;
- }
-
- public void setOlapAnalytics(boolean isOlapAnalytics) {
- this._isOlapAnalytics = isOlapAnalytics;
- }
-
- public boolean isOlapAnalytics() {
- return this._isOlapAnalytics;
- }
-
public void setCancellation(boolean isCancellation) {
this.isCancellation = isCancellation;
}
diff --git a/solr/core/src/test/org/apache/solr/handler/component/ResponseBuilderTest.java b/solr/core/src/test/org/apache/solr/handler/component/ResponseBuilderTest.java
index 7adfed4f68e..183ccb8e08c 100644
--- a/solr/core/src/test/org/apache/solr/handler/component/ResponseBuilderTest.java
+++ b/solr/core/src/test/org/apache/solr/handler/component/ResponseBuilderTest.java
@@ -38,30 +38,4 @@ public class ResponseBuilderTest extends SolrTestCaseJ4 {
ResponseBuilder responseBuilder = new ResponseBuilder(req, rsp, new ArrayList<>(0));
assertFalse(responseBuilder.isDistributed());
}
-
- public void testDoAnalyticsAccessors() {
- ResponseBuilder rb = new ResponseBuilder(req, rsp, new ArrayList<>(0));
- assertFalse(rb.isAnalytics());
- rb.setAnalytics(true);
- assertTrue(rb.isAnalytics());
- rb.setAnalytics(false);
- assertFalse(rb.isAnalytics());
- }
-
- public void testIsOlapAnalyticsAccessors() {
- ResponseBuilder rb = new ResponseBuilder(req, rsp, new ArrayList<>(0));
- assertFalse(rb.isOlapAnalytics());
- rb.setOlapAnalytics(true);
- assertTrue(rb.isOlapAnalytics());
- rb.setOlapAnalytics(false);
- assertFalse(rb.isOlapAnalytics());
- }
-
- public void testAnalyticsRequestManagerAccessors() {
- ResponseBuilder rb = new ResponseBuilder(req, rsp, new ArrayList<>(0));
- assertNull(rb.getAnalyticsRequestManager());
- rb.setAnalyticsRequestManager(this);
- assertNotNull(rb.getAnalyticsRequestManager());
- assertEquals(rb.getAnalyticsRequestManager(), this);
- }
}
diff --git a/solr/modules/analytics/build.gradle b/solr/modules/analytics/build.gradle
deleted file mode 100644
index 8e5b0d403c3..00000000000
--- a/solr/modules/analytics/build.gradle
+++ /dev/null
@@ -1,36 +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.
- */
-
-apply plugin: 'java-library'
-
-description = 'Analytics Package'
-
-dependencies {
- implementation project(':solr:core')
- implementation project(':solr:solrj')
-
- implementation 'org.apache.lucene:lucene-core'
-
- implementation 'com.fasterxml.jackson.core:jackson-annotations'
- implementation 'com.fasterxml.jackson.core:jackson-core'
- implementation 'com.fasterxml.jackson.core:jackson-databind'
-
- testImplementation project(':solr:test-framework')
- testImplementation 'com.carrotsearch.randomizedtesting:randomizedtesting-runner'
- testImplementation 'junit:junit'
- testImplementation 'org.slf4j:slf4j-api'
-}
diff --git a/solr/modules/analytics/src/java/org/apache/solr/analytics/AnalyticsDriver.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/AnalyticsDriver.java
deleted file mode 100644
index 9903f63d3b1..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/AnalyticsDriver.java
+++ /dev/null
@@ -1,85 +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;
-
-import java.io.IOException;
-import java.util.List;
-import org.apache.lucene.index.LeafReaderContext;
-import org.apache.lucene.search.DocIdSetIterator;
-import org.apache.lucene.search.Query;
-import org.apache.solr.analytics.AnalyticsRequestManager.StreamingInfo;
-import org.apache.solr.analytics.facet.AbstractSolrQueryFacet.FacetValueQueryExecuter;
-import org.apache.solr.analytics.facet.StreamingFacet;
-import org.apache.solr.analytics.function.ReductionCollectionManager;
-import org.apache.solr.request.SolrQueryRequest;
-import org.apache.solr.search.DocSet;
-import org.apache.solr.search.SolrIndexSearcher;
-
-public class AnalyticsDriver {
-
- /**
- * Drive the collection of reduction data. This includes overall data as well as faceted data.
- *
- * @param manager of the request to drive
- * @param searcher the results of the query
- * @param filter that represents the overall query
- * @param queryRequest used for the search request
- * @throws IOException if an error occurs while reading from Solr
- */
- public static void drive(
- AnalyticsRequestManager manager,
- SolrIndexSearcher searcher,
- DocSet filter,
- SolrQueryRequest queryRequest)
- throws IOException {
- StreamingInfo streamingInfo = manager.getStreamingFacetInfo();
- Iterable<StreamingFacet> streamingFacets = streamingInfo.streamingFacets;
- ReductionCollectionManager collectionManager = streamingInfo.streamingCollectionManager;
-
- Query fq =
- filter.makeQuery(); // TODO: passing this along as a DocSet would affect a lot of APIs
- Iterable<FacetValueQueryExecuter> facetExecuters = manager.getFacetExecuters(fq, queryRequest);
-
- // Streaming phase (Overall results & Value/Pivot Facets)
- // Loop through all documents and collect reduction data for streaming facets and overall
- // results
- if (collectionManager.needsCollection()) {
- List<LeafReaderContext> contexts = searcher.getTopReaderContext().leaves();
- for (int leafNum = 0; leafNum < contexts.size(); leafNum++) {
- LeafReaderContext context = contexts.get(leafNum);
- DocIdSetIterator disi = filter.iterator(context);
- if (disi != null) {
- collectionManager.doSetNextReader(context);
- int doc = disi.nextDoc();
- while (doc != DocIdSetIterator.NO_MORE_DOCS) {
- // Add a document to the statistics being generated
- collectionManager.collect(doc);
- streamingFacets.forEach(facet -> facet.addFacetValueCollectionTargets());
- collectionManager.apply();
- doc = disi.nextDoc();
- }
- }
- }
- }
-
- // Executing phase (Query/Range Facets)
- // Send additional Solr Queries to compute facet values
- for (FacetValueQueryExecuter executer : facetExecuters) {
- executer.execute(searcher);
- }
- }
-}
diff --git a/solr/modules/analytics/src/java/org/apache/solr/analytics/AnalyticsExpression.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/AnalyticsExpression.java
deleted file mode 100644
index 0dfe046f2d9..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/AnalyticsExpression.java
+++ /dev/null
@@ -1,64 +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;
-
-import org.apache.solr.analytics.function.ReductionCollectionManager;
-import org.apache.solr.analytics.function.ReductionCollectionManager.ReductionDataCollection;
-import org.apache.solr.analytics.value.AnalyticsValue;
-
-/**
- * A wrapper for a top-level analytics expression. The expression must have a name and be single
- * valued.
- */
-public class AnalyticsExpression {
- private final AnalyticsValue expression;
- private final String name;
-
- public AnalyticsExpression(String name, AnalyticsValue expression) {
- this.name = name;
- this.expression = expression;
- }
-
- public String getName() {
- return name;
- }
-
- public AnalyticsValue getExpression() {
- return expression;
- }
-
- /**
- * Get the current value of the expression. This method can, and will, be called multiple times to
- * return different values. The value returned is based on the {@link ReductionDataCollection}
- * given to the {@link ReductionCollectionManager#setData} method.
- *
- * @return the current value of the expression
- */
- public Object toObject() {
- return expression.getObject();
- }
-
- /**
- * NOTE: Must be called after {@link #toObject()} is called, otherwise the value is not guaranteed
- * to be correct.
- *
- * @return whether the current value of the expression exists.
- */
- public boolean exists() {
- return expression.exists();
- }
-}
diff --git a/solr/modules/analytics/src/java/org/apache/solr/analytics/AnalyticsGroupingManager.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/AnalyticsGroupingManager.java
deleted file mode 100644
index 99b67b677ca..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/AnalyticsGroupingManager.java
+++ /dev/null
@@ -1,245 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file inputtributed 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
- * inputtributed under the License is inputtributed 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.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.function.Consumer;
-import org.apache.lucene.search.Query;
-import org.apache.solr.analytics.facet.AbstractSolrQueryFacet;
-import org.apache.solr.analytics.facet.AbstractSolrQueryFacet.FacetValueQueryExecuter;
-import org.apache.solr.analytics.facet.AnalyticsFacet;
-import org.apache.solr.analytics.facet.PivotFacet;
-import org.apache.solr.analytics.facet.QueryFacet;
-import org.apache.solr.analytics.facet.RangeFacet;
-import org.apache.solr.analytics.facet.StreamingFacet;
-import org.apache.solr.analytics.facet.ValueFacet;
-import org.apache.solr.analytics.function.ExpressionCalculator;
-import org.apache.solr.analytics.function.ReductionCollectionManager;
-import org.apache.solr.analytics.util.AnalyticsResponseHeadings;
-import org.apache.solr.common.util.NamedList;
-import org.apache.solr.request.SolrQueryRequest;
-
-/**
- * The manager for faceted analytics. This class manages one grouping of facets and expressions to
- * compute over those facets.
- *
- * <p>This class will only manage generating faceted results, not overall results.
- */
-public class AnalyticsGroupingManager {
- private final String name;
- private final ReductionCollectionManager reductionCollectionManager;
-
- private final Collection<AnalyticsExpression> topLevelExpressions;
- private final ExpressionCalculator expressionCalculator;
-
- private final Map<String, AnalyticsFacet> facets;
-
- public AnalyticsGroupingManager(
- String name,
- ReductionCollectionManager reductionCollectionManager,
- Collection<AnalyticsExpression> topLevelExpressions) {
- this.name = name;
- this.reductionCollectionManager = reductionCollectionManager;
-
- this.topLevelExpressions = topLevelExpressions;
- this.expressionCalculator = new ExpressionCalculator(topLevelExpressions);
-
- this.facets = new HashMap<>();
- }
-
- // This is outside of the method, since it is used in the lambda and cannot be a local non-final
- // variable
- private boolean hasStreamingFacets;
-
- /**
- * Get the {@link StreamingFacet}s (e.g. {@link ValueFacet} and {@link PivotFacet}) contained
- * within this grouping, returning them through the given consumer.
- *
- * @param cons where the streaming facets are passed to
- * @return whether the grouping contains streaming facets
- */
- public boolean getStreamingFacets(Consumer<StreamingFacet> cons) {
- hasStreamingFacets = false;
- facets.forEach(
- (name, facet) -> {
- if (facet instanceof StreamingFacet) {
- cons.accept((StreamingFacet) facet);
- hasStreamingFacets = true;
- }
- });
- return hasStreamingFacets;
- }
-
- /**
- * Create the {@link FacetValueQueryExecuter}s for all {@link AbstractSolrQueryFacet}s (e.g.
- * {@link QueryFacet} and {@link RangeFacet}) contained within this grouping. The executers are
- * returned through the given consumer.
- *
- * <p>One {@link FacetValueQueryExecuter} is created for each facet value to be returned for a
- * facet. Since every {@link AbstractSolrQueryFacet} has discrete and user-defined facet values,
- * unlike {@link StreamingFacet}s, a discrete number of {@link FacetValueQueryExecuter}s are
- * created and returned.
- *
- * @param filter representing the overall Solr Query of the request, will be combined with the
- * facet value queries
- * @param queryRequest from the overall search request
- * @param cons where the executers are passed to
- */
- public void getFacetExecuters(
- Query filter, SolrQueryRequest queryRequest, Consumer<FacetValueQueryExecuter> cons) {
- facets.forEach(
- (name, facet) -> {
- if (facet instanceof AbstractSolrQueryFacet) {
- ((AbstractSolrQueryFacet) facet).createFacetValueExecuters(filter, queryRequest, cons);
- }
- });
- }
-
- /**
- * Add a facet to the grouping. All expressions in this grouping will be computed over the facet.
- *
- * @param facet to compute expressions over
- */
- public void addFacet(AnalyticsFacet facet) {
- facet.setExpressionCalculator(expressionCalculator);
- facet.setReductionCollectionManager(reductionCollectionManager);
- facets.put(facet.getName(), facet);
- }
-
- /**
- * Import the shard data for this grouping from a bit-stream, exported by the {@link
- * #exportShardData} method in the each of the collection's shards.
- *
- * @param input The bit-stream to import the grouping data from
- * @throws IOException if an exception occurs while reading from the {@link DataInput}
- */
- public void importShardData(DataInput input) throws IOException {
- // This allows mergeData() to import from the same input everytime it is called
- // while the facets are importing.
- reductionCollectionManager.setShardInput(input);
-
- int sz = input.readInt();
- for (int i = 0; i < sz; ++i) {
- facets.get(input.readUTF()).importShardData(input);
- }
- }
-
- /**
- * Export the shard data for this grouping through a bit-stream, to be imported by the {@link
- * #importShardData} method in the originating shard.
- *
- * @param output The bit-stream to output the grouping data through
- * @throws IOException if an exception occurs while writing to the {@link DataOutput}
- */
- public void exportShardData(DataOutput output) throws IOException {
- // This allows exportData() to export to the same output everytime it is called
- // while the facets are exporting.
- reductionCollectionManager.setShardOutput(output);
-
- output.writeInt(facets.size());
- for (Entry<String, AnalyticsFacet> facet : facets.entrySet()) {
- output.writeUTF(facet.getKey());
- facet.getValue().exportShardData(output);
- }
- }
-
- /**
- * Get the {@link ReductionCollectionManager} that manages the collection of reduction data for
- * the expressions contained within this grouping.
- *
- * @return the grouping's reduction manager
- */
- public ReductionCollectionManager getReductionManager() {
- return reductionCollectionManager;
- }
-
- /**
- * Create the response for this grouping, a mapping from each of it's facets' names to the facet's
- * response.
- *
- * @return the named list representation of the response
- */
- public Map<String, Object> createResponse() {
- Map<String, Object> response = new HashMap<>();
-
- // Add the value facet buckets to the output
- facets.forEach((name, facet) -> response.put(name, facet.createResponse()));
-
- return response;
- }
-
- /**
- * Create the response for this grouping, but in the old style of response. This response has a
- * bucket for the following if they are contained in the grouping: FieldFacets, RangeFacets and
- * QueryFacets. Each facet's name and response are put into the bucket corresponding to its type.
- *
- * <p>Since groupings in the old notation must also return overall results, the overall results
- * are passed in and the values are used to populate the grouping response.
- *
- * @param overallResults of the expressions to add to the grouping response
- * @return the named list representation of the response
- */
- public NamedList<Object> createOldResponse(Map<String, Object> overallResults) {
- NamedList<Object> response = new NamedList<>();
-
- topLevelExpressions.forEach(
- expression ->
- response.add(expression.getName(), overallResults.get(name + expression.getName())));
-
- NamedList<Object> fieldFacetResults = new NamedList<>();
- NamedList<Object> rangeFacetResults = new NamedList<>();
- NamedList<Object> queryFacetResults = new NamedList<>();
- // Add the field facet buckets to the output
- facets.forEach(
- (name, facet) -> {
- // The old style of request only accepts field facets
- // So we can assume that all value facets are field facets
- if (facet instanceof ValueFacet) {
- fieldFacetResults.add(name, facet.createOldResponse());
- } else if (facet instanceof RangeFacet) {
- rangeFacetResults.add(name, facet.createOldResponse());
- } else if (facet instanceof QueryFacet) {
- queryFacetResults.add(name, facet.createOldResponse());
- }
- });
- if (fieldFacetResults.size() > 0) {
- response.add(AnalyticsResponseHeadings.FIELD_FACETS, fieldFacetResults);
- }
- if (rangeFacetResults.size() > 0) {
- response.add(AnalyticsResponseHeadings.RANGE_FACETS, rangeFacetResults);
- }
- if (queryFacetResults.size() > 0) {
- response.add(AnalyticsResponseHeadings.QUERY_FACETS, queryFacetResults);
- }
- return response;
- }
-
- /**
- * Get the name of the grouping.
- *
- * @return the grouping name
- */
- public String getName() {
- return name;
- }
-}
diff --git a/solr/modules/analytics/src/java/org/apache/solr/analytics/AnalyticsRequestManager.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/AnalyticsRequestManager.java
deleted file mode 100644
index 93315855cc5..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/AnalyticsRequestManager.java
+++ /dev/null
@@ -1,292 +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;
-
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-import org.apache.lucene.search.Query;
-import org.apache.solr.analytics.facet.AbstractSolrQueryFacet;
-import org.apache.solr.analytics.facet.AbstractSolrQueryFacet.FacetValueQueryExecuter;
-import org.apache.solr.analytics.facet.StreamingFacet;
-import org.apache.solr.analytics.function.ExpressionCalculator;
-import org.apache.solr.analytics.function.ReductionCollectionManager;
-import org.apache.solr.analytics.function.ReductionCollectionManager.ReductionDataCollection;
-import org.apache.solr.analytics.stream.AnalyticsShardRequestManager;
-import org.apache.solr.analytics.util.AnalyticsResponseHeadings;
-import org.apache.solr.common.util.NamedList;
-import org.apache.solr.request.SolrQueryRequest;
-
-/** The manager of an entire analytics request. */
-public class AnalyticsRequestManager {
- private final ReductionCollectionManager ungroupedReductionManager;
- private ReductionDataCollection ungroupedData;
-
- private final Map<String, AnalyticsGroupingManager> groupingManagers;
-
- private final Collection<AnalyticsExpression> ungroupedExpressions;
- private final ExpressionCalculator ungroupedExpressionCalculator;
-
- /** If the request is distributed, the manager for shard requests. */
- public String analyticsRequest;
-
- public AnalyticsShardRequestManager shardStream;
- public boolean sendShards;
- private boolean partialResults = false;
-
- /**
- * Create an manager with the given ungrouped expressions. This is straightforward in the new
- * style of request, however in the old olap-style requests all groupings' expressions are
- * expected to be ungrouped as well.
- *
- * @param ungroupedReductionManager to manage the reduction collection for all ungrouped
- * expressions
- * @param ungroupedExpressions to compute overall results for
- */
- public AnalyticsRequestManager(
- ReductionCollectionManager ungroupedReductionManager,
- Collection<AnalyticsExpression> ungroupedExpressions) {
- this.ungroupedReductionManager = ungroupedReductionManager;
- this.ungroupedData = ungroupedReductionManager.newDataCollection();
- this.ungroupedReductionManager.addLastingCollectTarget(ungroupedData);
-
- this.ungroupedExpressions = ungroupedExpressions;
- this.ungroupedExpressionCalculator = new ExpressionCalculator(ungroupedExpressions);
- this.groupingManagers = new HashMap<>();
- }
-
- /**
- * Get the collection manager for ungrouped expressions, including grouped expressions if the old
- * request notation is used.
- *
- * @return the collection manager for the ungrouped expressions
- */
- public ReductionCollectionManager getUngroupedCollectionManager() {
- return ungroupedReductionManager;
- }
-
- /**
- * Get the collection manager for all ungrouped expressions, including grouped expressions if the
- * old request notation is used.
- *
- * @return the collection manager for the ungrouped expressions
- */
- public ReductionDataCollection getUngroupedData() {
- return ungroupedData;
- }
-
- /**
- * Return all ungrouped expressions, including grouped expressions if the old request notation is
- * used.
- *
- * @return an {@link Iterable} of the ungrouped expressions
- */
- public Iterable<AnalyticsExpression> getUngroupedExpressions() {
- return ungroupedExpressions;
- }
-
- /**
- * Generate the results of all ungrouped expressions, including grouped expressions if the old
- * request notation is used.
- *
- * @param response the response to add the ungrouped results to.
- */
- public void addUngroupedResults(Map<String, Object> response) {
- ungroupedReductionManager.setData(ungroupedData);
- ungroupedExpressionCalculator.addResults(response);
- }
-
- /**
- * Generate the results of all ungrouped expressions, including grouped expressions if the old
- * request notation is used.
- *
- * @return the map containing the ungrouped results
- */
- public Map<String, Object> getUngroupedResults() {
- ungroupedReductionManager.setData(ungroupedData);
- return ungroupedExpressionCalculator.getResults();
- }
-
- /**
- * Add a grouping to the request.
- *
- * @param groupingManager that manages the grouping
- */
- public void addGrouping(AnalyticsGroupingManager groupingManager) {
- groupingManagers.put(groupingManager.getName(), groupingManager);
- }
-
- /**
- * Import the shard data for this request from a bit-stream, exported by the {@link
- * #exportShardData} method in the each of the collection's shards.
- *
- * <p>First the overall data is imported, then the grouping data is imported.
- *
- * @param input The bit-stream to import the shard data from
- * @throws IOException if an exception occurs while reading from the {@link DataInput}
- */
- public synchronized void importShardData(DataInput input) throws IOException {
- ungroupedReductionManager.setShardInput(input);
-
- // The ungroupedData will not exist for the first shard imported
- if (ungroupedData == null) {
- ungroupedData = ungroupedReductionManager.newDataCollectionIO();
- } else {
- ungroupedReductionManager.prepareReductionDataIO(ungroupedData);
- }
- ungroupedReductionManager.mergeData();
-
- int size = input.readInt();
- while (--size >= 0) {
- String groupingName = input.readUTF();
- groupingManagers.get(groupingName).importShardData(input);
- }
- }
-
- /**
- * Export the shard data for this request through a bit-stream, to be imported by the {@link
- * #importShardData} method in the originating shard.
- *
- * <p>First the overall data is exported, then the grouping data is exported.
- *
- * @param output The bit-stream to output the shard data through
- * @throws IOException if an exception occurs while writing to the {@link DataOutput}
- */
- public void exportShardData(DataOutput output) throws IOException {
- ungroupedReductionManager.setShardOutput(output);
-
- ungroupedReductionManager.prepareReductionDataIO(ungroupedData);
- ungroupedReductionManager.exportData();
-
- output.writeInt(groupingManagers.size());
- for (Map.Entry<String, AnalyticsGroupingManager> entry : groupingManagers.entrySet()) {
- output.writeUTF(entry.getKey());
- entry.getValue().exportShardData(output);
- }
- }
-
- /**
- * Consolidate the information of all {@link StreamingFacet}s contained within the request, since
- * they need to be collected along with the overall results during the streaming phase of the
- * {@link AnalyticsDriver}.
- *
- * @return the info for all {@link StreamingFacet}s
- */
- public StreamingInfo getStreamingFacetInfo() {
- StreamingInfo streamingInfo = new StreamingInfo();
- ArrayList<ReductionCollectionManager> groupingCollectors = new ArrayList<>();
- groupingManagers
- .values()
- .forEach(
- grouping -> {
- // If a grouping has streaming facets, then that groupings expressions
- // must be collected during the streaming phase.
- if (grouping.getStreamingFacets(facet -> streamingInfo.streamingFacets.add(facet))) {
- groupingCollectors.add(grouping.getReductionManager());
- }
- });
-
- // Create an streaming collection manager to manage the collection of all ungrouped expressions
- // and
- // grouped expressions that are calculated over streaming facets.
- streamingInfo.streamingCollectionManager = ungroupedReductionManager.merge(groupingCollectors);
- return streamingInfo;
- }
-
- /** Class to encapsulate all necessary data for collecting {@link StreamingFacet}s. */
- public static class StreamingInfo {
- Collection<StreamingFacet> streamingFacets = new ArrayList<>();
- /** Manages the collection of all expressions needed for streaming facets */
- ReductionCollectionManager streamingCollectionManager;
- }
-
- /**
- * Create the {@link FacetValueQueryExecuter}s for all {@link AbstractSolrQueryFacet}s contained
- * in the request.
- *
- * @param filter representing the overall search query
- * @param queryRequest of the overall search query
- * @return an {@link Iterable} of executers
- */
- public Iterable<FacetValueQueryExecuter> getFacetExecuters(
- Query filter, SolrQueryRequest queryRequest) {
- ArrayList<FacetValueQueryExecuter> facetExecutors = new ArrayList<>();
- groupingManagers
- .values()
- .forEach(
- grouping -> {
- grouping.getFacetExecuters(
- filter, queryRequest, executor -> facetExecutors.add(executor));
- });
- return facetExecutors;
- }
-
- /**
- * Create the response for a request given in the old olap-style format. The old response returned
- * overall expressions within groupings.
- *
- * @return a {@link NamedList} representation of the response
- */
- public NamedList<Object> createOldResponse() {
- NamedList<Object> analyticsResponse = new NamedList<>();
- Map<String, Object> ungroupedResults = getUngroupedResults();
- groupingManagers.forEach(
- (name, groupingManager) -> {
- analyticsResponse.add(name, groupingManager.createOldResponse(ungroupedResults));
- });
-
- return analyticsResponse;
- }
-
- /**
- * Create the response for a request.
- *
- * <p>NOTE: Analytics requests specified in the old olap-style format have their responses
- * generated by {@link #createOldResponse()}.
- *
- * @return a {@link Map} representation of the response
- */
- public Map<String, Object> createResponse() {
- Map<String, Object> analyticsResponse = new HashMap<>();
- if (ungroupedExpressions.size() > 0) {
- addUngroupedResults(analyticsResponse);
- }
-
- Map<String, Object> groupingsResponse = new HashMap<>();
- groupingManagers.forEach(
- (name, groupingManager) -> {
- groupingsResponse.put(name, groupingManager.createResponse());
- });
-
- if (groupingsResponse.size() > 0) {
- analyticsResponse.put(AnalyticsResponseHeadings.GROUPINGS, groupingsResponse);
- }
- return analyticsResponse;
- }
-
- public void setPartialResults(boolean b) {
- this.partialResults = b;
- }
-
- public boolean isPartialResults() {
- return partialResults;
- }
-}
diff --git a/solr/modules/analytics/src/java/org/apache/solr/analytics/AnalyticsRequestParser.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/AnalyticsRequestParser.java
deleted file mode 100644
index 43b9e9d109c..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/AnalyticsRequestParser.java
+++ /dev/null
@@ -1,656 +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;
-
-import com.fasterxml.jackson.annotation.JsonInclude;
-import com.fasterxml.jackson.annotation.JsonInclude.Include;
-import com.fasterxml.jackson.annotation.JsonSubTypes;
-import com.fasterxml.jackson.annotation.JsonSubTypes.Type;
-import com.fasterxml.jackson.annotation.JsonTypeInfo;
-import com.fasterxml.jackson.annotation.JsonTypeName;
-import com.fasterxml.jackson.core.JsonFactory;
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.DeserializationFeature;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.EnumSet;
-import java.util.HashMap;
-import java.util.List;
-import java.util.ListIterator;
-import java.util.Map;
-import java.util.function.Predicate;
-import java.util.regex.Pattern;
-import org.apache.solr.analytics.facet.PivotFacet;
-import org.apache.solr.analytics.facet.PivotNode;
-import org.apache.solr.analytics.facet.QueryFacet;
-import org.apache.solr.analytics.facet.RangeFacet;
-import org.apache.solr.analytics.facet.SortableFacet.FacetSortSpecification;
-import org.apache.solr.analytics.facet.ValueFacet;
-import org.apache.solr.analytics.facet.compare.DelegatingComparator;
-import org.apache.solr.analytics.facet.compare.FacetResultsComparator;
-import org.apache.solr.analytics.facet.compare.FacetValueComparator;
-import org.apache.solr.analytics.value.AnalyticsValue;
-import org.apache.solr.analytics.value.AnalyticsValueStream;
-import org.apache.solr.analytics.value.ComparableValue;
-import org.apache.solr.analytics.value.StringValueStream;
-import org.apache.solr.common.SolrException;
-import org.apache.solr.common.SolrException.ErrorCode;
-import org.apache.solr.common.params.FacetParams.FacetRangeInclude;
-import org.apache.solr.common.params.FacetParams.FacetRangeOther;
-import org.apache.solr.schema.IndexSchema;
-import org.apache.solr.schema.SchemaField;
-
-/** Class to manage the parsing of new-style analytics requests. */
-public class AnalyticsRequestParser {
-
- private static ObjectMapper mapper = new ObjectMapper();
-
- public static void init() {
- mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
- mapper.configure(DeserializationFeature.FAIL_ON_INVALID_SUBTYPE, true);
- }
-
- public static final String analyticsParamName = "analytics";
-
- private static Predicate<String> sortAscending = acceptNames("ascending", "asc", "a");
- private static Predicate<String> sortDescending = acceptNames("descending", "desc", "d");
-
- private static Predicate<String> acceptNames(String... names) {
- return Pattern.compile(
- "^(?:" + Arrays.stream(names).reduce((a, b) -> a + "|" + b).orElse("") + ")$",
- Pattern.CASE_INSENSITIVE)
- .asPredicate();
- }
-
- // Defaults
- public static final String DEFAULT_SORT_DIRECTION = "ascending";
- public static final int DEFAULT_OFFSET = 0;
- public static final int DEFAULT_LIMIT = -1;
- public static final boolean DEFAULT_HARDEND = false;
-
- @JsonInclude(Include.NON_EMPTY)
- public static class AnalyticsRequest {
- public Map<String, String> functions;
- public Map<String, String> expressions;
-
- public Map<String, AnalyticsGroupingRequest> groupings;
- }
-
- public static class AnalyticsGroupingRequest {
- public Map<String, String> expressions;
-
- public Map<String, AnalyticsFacetRequest> facets;
- }
-
- @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type")
- @JsonSubTypes({
- @Type(value = AnalyticsValueFacetRequest.class, name = "value"),
- @Type(value = AnalyticsPivotFacetRequest.class, name = "pivot"),
- @Type(value = AnalyticsRangeFacetRequest.class, name = "range"),
- @Type(value = AnalyticsQueryFacetRequest.class, name = "query")
- })
- @JsonInclude(Include.NON_EMPTY)
- public static interface AnalyticsFacetRequest {}
-
- @JsonTypeName("value")
- public static class AnalyticsValueFacetRequest implements AnalyticsFacetRequest {
- public String expression;
- public AnalyticsSortRequest sort;
- }
-
- @JsonTypeName("pivot")
- public static class AnalyticsPivotFacetRequest implements AnalyticsFacetRequest {
- public List<AnalyticsPivotRequest> pivots;
- }
-
- public static class AnalyticsPivotRequest {
- public String name;
- public String expression;
- public AnalyticsSortRequest sort;
- }
-
- @JsonInclude(Include.NON_EMPTY)
- public static class AnalyticsSortRequest {
- public List<AnalyticsSortCriteriaRequest> criteria;
- public int limit = DEFAULT_LIMIT;
- public int offset = DEFAULT_OFFSET;
- }
-
- @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type")
- @JsonSubTypes({
- @Type(value = AnalyticsExpressionSortRequest.class, name = "expression"),
- @Type(value = AnalyticsFacetValueSortRequest.class, name = "facetvalue")
- })
- @JsonInclude(Include.NON_EMPTY)
- public abstract static class AnalyticsSortCriteriaRequest {
- public String direction;
- }
-
- @JsonTypeName("expression")
- public static class AnalyticsExpressionSortRequest extends AnalyticsSortCriteriaRequest {
- public String expression;
- }
-
- @JsonTypeName("facetvalue")
- public static class AnalyticsFacetValueSortRequest extends AnalyticsSortCriteriaRequest {}
-
- @JsonTypeName("range")
- public static class AnalyticsRangeFacetRequest implements AnalyticsFacetRequest {
- public String field;
- public String start;
- public String end;
- public List<String> gaps;
- public boolean hardend = DEFAULT_HARDEND;
- public List<String> include;
- public List<String> others;
- }
-
- @JsonTypeName("query")
- public static class AnalyticsQueryFacetRequest implements AnalyticsFacetRequest {
- public Map<String, String> queries;
- }
-
- /* ***************
- * Request & Groupings
- * ***************/
-
- public static AnalyticsRequestManager parse(
- AnalyticsRequest request, ExpressionFactory expressionFactory, boolean isDistribRequest)
- throws SolrException {
- AnalyticsRequestManager manager =
- constructRequest(request, expressionFactory, isDistribRequest);
- if (isDistribRequest) {
- try {
- manager.analyticsRequest = mapper.writeValueAsString(request);
- } catch (JsonProcessingException e) {
- throw new RuntimeException(e);
- }
- }
- return manager;
- }
-
- public static AnalyticsRequestManager parse(
- String rawRequest, ExpressionFactory expressionFactory, boolean isDistribRequest)
- throws SolrException {
- JsonParser parser;
- try {
- parser =
- new JsonFactory()
- .createParser(rawRequest)
- .configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true)
- .configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
- } catch (IOException e1) {
- throw new RuntimeException(e1);
- }
- AnalyticsRequest request;
- try {
- request = mapper.readValue(parser, AnalyticsRequest.class);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
-
- AnalyticsRequestManager manager =
- constructRequest(request, expressionFactory, isDistribRequest);
- if (isDistribRequest) {
- manager.analyticsRequest = rawRequest;
- }
- return manager;
- }
-
- private static AnalyticsRequestManager constructRequest(
- AnalyticsRequest request, ExpressionFactory expressionFactory, boolean isDistribRequest)
- throws SolrException {
- expressionFactory.startRequest();
-
- // Functions
- if (request.functions != null) {
- request.functions.forEach(
- (funcSig, retSig) -> expressionFactory.addUserDefinedVariableFunction(funcSig, retSig));
- }
-
- // Expressions
- Map<String, AnalyticsExpression> topLevelExpressions;
- if (request.expressions != null) {
- topLevelExpressions = constructExpressions(request.expressions, expressionFactory);
- } else {
- topLevelExpressions = new HashMap<>();
- }
- AnalyticsRequestManager manager =
- new AnalyticsRequestManager(
- expressionFactory.createReductionManager(isDistribRequest),
- topLevelExpressions.values());
-
- // Groupings
- if (request.groupings != null) {
- request.groupings.forEach(
- (name, grouping) -> {
- manager.addGrouping(
- constructGrouping(name, grouping, expressionFactory, isDistribRequest));
- });
- }
- return manager;
- }
-
- private static AnalyticsGroupingManager constructGrouping(
- String name,
- AnalyticsGroupingRequest grouping,
- ExpressionFactory expressionFactory,
- boolean isDistribRequest)
- throws SolrException {
- expressionFactory.startGrouping();
-
- // Expressions
- if (grouping.expressions == null || grouping.expressions.size() == 0) {
- throw new SolrException(
- ErrorCode.BAD_REQUEST,
- "Groupings must contain at least one expression, '" + name + "' has none.");
- }
-
- Map<String, AnalyticsExpression> expressions =
- constructExpressions(grouping.expressions, expressionFactory);
- AnalyticsGroupingManager manager =
- new AnalyticsGroupingManager(
- name,
- expressionFactory.createGroupingReductionManager(isDistribRequest),
- expressions.values());
-
- if (grouping.facets == null) {
- throw new SolrException(
- ErrorCode.BAD_REQUEST,
- "Groupings must contain at least one facet, '" + name + "' has none.");
- }
- // Parse the facets
- grouping.facets.forEach(
- (facetName, facet) -> {
- if (facet instanceof AnalyticsValueFacetRequest) {
- manager.addFacet(
- constructValueFacet(
- facetName, (AnalyticsValueFacetRequest) facet, expressionFactory, expressions));
- } else if (facet instanceof AnalyticsPivotFacetRequest) {
- manager.addFacet(
- constructPivotFacet(
- facetName, (AnalyticsPivotFacetRequest) facet, expressionFactory, expressions));
- } else if (facet instanceof AnalyticsRangeFacetRequest) {
- manager.addFacet(
- constructRangeFacet(
- facetName, (AnalyticsRangeFacetRequest) facet, expressionFactory.getSchema()));
- } else if (facet instanceof AnalyticsQueryFacetRequest) {
- manager.addFacet(constructQueryFacet(facetName, (AnalyticsQueryFacetRequest) facet));
- } else {
- throw new SolrException(
- ErrorCode.BAD_REQUEST,
- "The facet type, '"
- + facet.getClass().toString()
- + "' in "
- + "grouping '"
- + name
- + "' is not a valid type of facet");
- }
- });
-
- return manager;
- }
-
- /* ***************
- * Expression & Functions
- * ***************/
-
- private static Map<String, AnalyticsExpression> constructExpressions(
- Map<String, String> rawExpressions, ExpressionFactory expressionFactory)
- throws SolrException {
- Map<String, AnalyticsExpression> expressions = new HashMap<>();
- rawExpressions.forEach(
- (name, expression) -> {
- AnalyticsValueStream exprVal = expressionFactory.createExpression(expression);
- if (exprVal instanceof AnalyticsValue) {
- if (exprVal.getExpressionType().isReduced()) {
- expressions.put(name, (new AnalyticsExpression(name, (AnalyticsValue) exprVal)));
- } else {
- throw new SolrException(
- ErrorCode.BAD_REQUEST,
- "Top-level expressions must be reduced, the '" + name + "' expression is not.");
- }
- } else {
- throw new SolrException(
- ErrorCode.BAD_REQUEST,
- "Top-level expressions must be single-valued, the '"
- + name
- + "' expression is not.");
- }
- });
- return expressions;
- }
-
- /* ***************
- * FACETS
- * ***************/
-
- /*
- * Value Facets
- */
-
- private static ValueFacet constructValueFacet(
- String name,
- AnalyticsValueFacetRequest facetRequest,
- ExpressionFactory expressionFactory,
- Map<String, AnalyticsExpression> expressions)
- throws SolrException {
- if (facetRequest.expression == null) {
- throw new SolrException(
- ErrorCode.BAD_REQUEST,
- "Value Facets must contain a mapping expression to facet over, '" + name + "' has none.");
- }
-
- // The second parameter must be a mapping expression
- AnalyticsValueStream expr = expressionFactory.createExpression(facetRequest.expression);
- if (!expr.getExpressionType().isUnreduced()) {
- throw new SolrException(
- ErrorCode.BAD_REQUEST,
- "Value Facet expressions must be mapping expressions, "
- + "the following expression in value facet '"
- + name
- + "' contains a reduction: "
- + facetRequest.expression);
- }
- if (!(expr instanceof StringValueStream)) {
- throw new SolrException(
- ErrorCode.BAD_REQUEST,
- "Value Facet expressions must be castable to string expressions, "
- + "the following expression in value facet '"
- + name
- + "' is not: "
- + facetRequest.expression);
- }
-
- ValueFacet facet = new ValueFacet(name, (StringValueStream) expr);
-
- // Check if the value facet is sorted
- if (facetRequest.sort != null) {
- facet.setSort(constructSort(facetRequest.sort, expressions));
- }
- return facet;
- }
-
- /*
- * Pivot Facets
- */
-
- private static PivotFacet constructPivotFacet(
- String name,
- AnalyticsPivotFacetRequest facetRequest,
- ExpressionFactory expressionFactory,
- Map<String, AnalyticsExpression> expressions)
- throws SolrException {
- PivotNode<?> topPivot = null;
-
- // Pivots
- if (facetRequest.pivots == null || facetRequest.pivots.size() == 0) {
- throw new SolrException(
- ErrorCode.BAD_REQUEST,
- "Pivot Facets must contain at least one pivot to facet over, '" + name + "' has none.");
- }
-
- ListIterator<AnalyticsPivotRequest> iter =
- facetRequest.pivots.listIterator(facetRequest.pivots.size());
- while (iter.hasPrevious()) {
- topPivot = constructPivot(iter.previous(), topPivot, expressionFactory, expressions);
- }
-
- return new PivotFacet(name, topPivot);
- }
-
- private static PivotNode<?> constructPivot(
- AnalyticsPivotRequest pivotRequest,
- PivotNode<?> childPivot,
- ExpressionFactory expressionFactory,
- Map<String, AnalyticsExpression> expressions)
- throws SolrException {
- if (pivotRequest.name == null || pivotRequest.name.length() == 0) {
- throw new SolrException(ErrorCode.BAD_REQUEST, "Pivots must have a name.");
- }
- if (pivotRequest.expression == null) {
- throw new SolrException(
- ErrorCode.BAD_REQUEST,
- "Pivots must have an expression to facet over, '" + pivotRequest.name + "' does not.");
- }
-
- // The second parameter must be a mapping expression
- AnalyticsValueStream expr = expressionFactory.createExpression(pivotRequest.expression);
- if (!expr.getExpressionType().isUnreduced()) {
- throw new SolrException(
- ErrorCode.BAD_REQUEST,
- "Pivot expressions must be mapping expressions, "
- + "the following expression in pivot '"
- + pivotRequest.name
- + "' contains a reduction: "
- + pivotRequest.expression);
- }
- if (!(expr instanceof StringValueStream)) {
- throw new SolrException(
- ErrorCode.BAD_REQUEST,
- "Pivot expressions must be castable to string expressions, "
- + "the following expression in pivot '"
- + pivotRequest.name
- + "' is not: '"
- + pivotRequest.expression);
- }
-
- PivotNode<?> pivot;
- if (childPivot == null) {
- pivot = new PivotNode.PivotLeaf(pivotRequest.name, (StringValueStream) expr);
- } else {
- pivot = new PivotNode.PivotBranch<>(pivotRequest.name, (StringValueStream) expr, childPivot);
- }
-
- // Check if the pivot is sorted
- if (pivotRequest.sort != null) {
- pivot.setSort(constructSort(pivotRequest.sort, expressions));
- }
- return pivot;
- }
-
- /*
- * Range Facets
- */
-
- private static RangeFacet constructRangeFacet(
- String name, AnalyticsRangeFacetRequest facetRequest, IndexSchema schema)
- throws SolrException {
- if (facetRequest.field == null || facetRequest.field.length() == 0) {
- throw new SolrException(
- ErrorCode.BAD_REQUEST,
- "Range Facets must specify a field to facet over, '" + name + "' does not.");
- }
- SchemaField field = schema.getFieldOrNull(facetRequest.field);
- if (field == null) {
- throw new SolrException(
- ErrorCode.BAD_REQUEST,
- "Range Facets must have a valid field as the second parameter. The '"
- + name
- + "' facet "
- + "tries to facet over the non-existent field: "
- + facetRequest.field);
- }
-
- if (facetRequest.start == null || facetRequest.start.length() == 0) {
- throw new SolrException(
- ErrorCode.BAD_REQUEST,
- "Range Facets must specify a start value, '" + name + "' does not.");
- }
- if (facetRequest.end == null || facetRequest.end.length() == 0) {
- throw new SolrException(
- ErrorCode.BAD_REQUEST, "Range Facets must specify a end value, '" + name + "' does not.");
- }
- if (facetRequest.gaps == null || facetRequest.gaps.size() == 0) {
- throw new SolrException(
- ErrorCode.BAD_REQUEST,
- "Range Facets must specify a gap or list of gaps to determine facet buckets, '"
- + name
- + "' does not.");
- }
- RangeFacet facet =
- new RangeFacet(name, field, facetRequest.start, facetRequest.end, facetRequest.gaps);
-
- facet.setHardEnd(facetRequest.hardend);
-
- if (facetRequest.include != null && facetRequest.include.size() > 0) {
- facet.setInclude(constructInclude(facetRequest.include));
- }
- if (facetRequest.others != null && facetRequest.others.size() > 0) {
- facet.setOthers(constructOthers(facetRequest.others, name));
- }
- return facet;
- }
-
- private static EnumSet<FacetRangeInclude> constructInclude(List<String> includes)
- throws SolrException {
- return FacetRangeInclude.parseParam(includes.toArray(new String[includes.size()]));
- }
-
- private static EnumSet<FacetRangeOther> constructOthers(
- List<String> othersRequest, String facetName) throws SolrException {
- EnumSet<FacetRangeOther> others = EnumSet.noneOf(FacetRangeOther.class);
- for (String rawOther : othersRequest) {
- if (!others.add(FacetRangeOther.get(rawOther))) {
- throw new SolrException(
- ErrorCode.BAD_REQUEST,
- "Duplicate include value '" + rawOther + "' found in range facet '" + facetName + "'");
- }
- }
- if (others.contains(FacetRangeOther.NONE)) {
- if (others.size() > 1) {
- throw new SolrException(
- ErrorCode.BAD_REQUEST,
- "Include value 'NONE' is used with other includes in a range facet '"
- + facetName
- + "'. "
- + "If 'NONE' is used, it must be the only include.");
- }
- return EnumSet.noneOf(FacetRangeOther.class);
- }
- if (others.contains(FacetRangeOther.ALL)) {
- if (others.size() > 1) {
- throw new SolrException(
- ErrorCode.BAD_REQUEST,
- "Include value 'ALL' is used with other includes in a range facet '"
- + facetName
- + "'. "
- + "If 'ALL' is used, it must be the only include.");
- }
- return EnumSet.of(FacetRangeOther.BEFORE, FacetRangeOther.BETWEEN, FacetRangeOther.AFTER);
- }
- return others;
- }
-
- /*
- * Query Facets
- */
-
- private static QueryFacet constructQueryFacet(
- String name, AnalyticsQueryFacetRequest facetRequest) throws SolrException {
- if (facetRequest.queries == null || facetRequest.queries.size() == 0) {
- throw new SolrException(
- ErrorCode.BAD_REQUEST,
- "Query Facets must be contain at least 1 query to facet over, '" + name + "' does not.");
- }
-
- // The first param must be the facet name
- return new QueryFacet(name, facetRequest.queries);
- }
-
- /*
- * Facet Sorting
- */
-
- private static FacetSortSpecification constructSort(
- AnalyticsSortRequest sortRequest, Map<String, AnalyticsExpression> expressions)
- throws SolrException {
- if (sortRequest.criteria == null || sortRequest.criteria.size() == 0) {
- throw new SolrException(ErrorCode.BAD_REQUEST, "Sorts must be given at least 1 criteria.");
- }
-
- return new FacetSortSpecification(
- constructSortCriteria(sortRequest.criteria, expressions),
- sortRequest.limit,
- sortRequest.offset);
- }
-
- private static FacetResultsComparator constructSortCriteria(
- List<AnalyticsSortCriteriaRequest> criteria, Map<String, AnalyticsExpression> expressions) {
- ArrayList<FacetResultsComparator> comparators = new ArrayList<>();
- for (AnalyticsSortCriteriaRequest criterion : criteria) {
- FacetResultsComparator comparator;
- if (criterion instanceof AnalyticsExpressionSortRequest) {
- comparator =
- constructExpressionSortCriteria(
- (AnalyticsExpressionSortRequest) criterion, expressions);
- } else if (criterion instanceof AnalyticsFacetValueSortRequest) {
- comparator = constructFacetValueSortCriteria((AnalyticsFacetValueSortRequest) criterion);
- } else {
- // Shouldn't happen
- throw new SolrException(
- ErrorCode.BAD_REQUEST,
- "Sort Criteria must either be expressions or facetValues, '"
- + criterion.getClass().getName()
- + "' given.");
- }
- if (criterion.direction != null && criterion.direction.length() > 0) {
- if (sortAscending.test(criterion.direction)) {
- comparator.setDirection(true);
- } else if (sortDescending.test(criterion.direction)) {
- comparator.setDirection(false);
- } else {
- throw new SolrException(
- ErrorCode.BAD_REQUEST,
- "Sort direction '" + criterion.direction + " is not a recognized direction.");
- }
- }
- comparators.add(comparator);
- }
- return DelegatingComparator.joinComparators(comparators);
- }
-
- private static FacetResultsComparator constructExpressionSortCriteria(
- AnalyticsExpressionSortRequest criterion, Map<String, AnalyticsExpression> expressions) {
- if (criterion.expression == null || criterion.expression.length() == 0) {
- throw new SolrException(
- ErrorCode.BAD_REQUEST,
- "Expression Sorts must contain an expression parameter, none given.");
- }
-
- AnalyticsExpression expression = expressions.get(criterion.expression);
- if (expression == null) {
- throw new SolrException(
- ErrorCode.BAD_REQUEST,
- "Sort Expression not defined within the grouping: " + criterion.expression);
- }
- if (!(expression.getExpression() instanceof ComparableValue)) {
- throw new SolrException(
- ErrorCode.BAD_REQUEST,
- "Expression Sorts must be comparable, the following is not: " + criterion.expression);
- }
- return ((ComparableValue) expression.getExpression()).getObjectComparator(expression.getName());
- }
-
- private static FacetResultsComparator constructFacetValueSortCriteria(
- AnalyticsFacetValueSortRequest criterion) {
- return new FacetValueComparator();
- }
-}
diff --git a/solr/modules/analytics/src/java/org/apache/solr/analytics/ExpressionFactory.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/ExpressionFactory.java
deleted file mode 100644
index d72126792f6..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/ExpressionFactory.java
+++ /dev/null
@@ -1,1109 +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;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedHashMap;
-import java.util.Locale;
-import java.util.Map;
-import java.util.regex.Matcher;
-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.ReductionFunction;
-import org.apache.solr.analytics.function.field.AnalyticsField;
-import org.apache.solr.analytics.function.field.BooleanField;
-import org.apache.solr.analytics.function.field.BooleanMultiField;
-import org.apache.solr.analytics.function.field.DateField;
-import org.apache.solr.analytics.function.field.DateMultiPointField;
-import org.apache.solr.analytics.function.field.DateMultiTrieField;
-import org.apache.solr.analytics.function.field.DoubleField;
-import org.apache.solr.analytics.function.field.DoubleMultiPointField;
-import org.apache.solr.analytics.function.field.DoubleMultiTrieField;
-import org.apache.solr.analytics.function.field.FloatField;
-import org.apache.solr.analytics.function.field.FloatMultiPointField;
-import org.apache.solr.analytics.function.field.FloatMultiTrieField;
-import org.apache.solr.analytics.function.field.IntField;
-import org.apache.solr.analytics.function.field.IntMultiPointField;
-import org.apache.solr.analytics.function.field.IntMultiTrieField;
-import org.apache.solr.analytics.function.field.LongField;
-import org.apache.solr.analytics.function.field.LongMultiPointField;
-import org.apache.solr.analytics.function.field.LongMultiTrieField;
-import org.apache.solr.analytics.function.field.StringField;
-import org.apache.solr.analytics.function.field.StringMultiField;
-import org.apache.solr.analytics.function.mapping.AbsoluteValueFunction;
-import org.apache.solr.analytics.function.mapping.AddFunction;
-import org.apache.solr.analytics.function.mapping.BottomFunction;
-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;
-import org.apache.solr.analytics.function.mapping.ConcatFunction.SeparatedConcatFunction;
-import org.apache.solr.analytics.function.mapping.DateMathFunction;
-import org.apache.solr.analytics.function.mapping.DateParseFunction;
-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.DivideFunction;
-import org.apache.solr.analytics.function.mapping.EqualFunction;
-import org.apache.solr.analytics.function.mapping.ExistsFunction;
-import org.apache.solr.analytics.function.mapping.FillMissingFunction;
-import org.apache.solr.analytics.function.mapping.FilterFunction;
-import org.apache.solr.analytics.function.mapping.IfFunction;
-import org.apache.solr.analytics.function.mapping.LogFunction;
-import org.apache.solr.analytics.function.mapping.LogicFunction.AndFunction;
-import org.apache.solr.analytics.function.mapping.LogicFunction.OrFunction;
-import org.apache.solr.analytics.function.mapping.MultFunction;
-import org.apache.solr.analytics.function.mapping.NegateFunction;
-import org.apache.solr.analytics.function.mapping.PowerFunction;
-import org.apache.solr.analytics.function.mapping.RemoveFunction;
-import org.apache.solr.analytics.function.mapping.ReplaceFunction;
-import org.apache.solr.analytics.function.mapping.StringCastFunction;
-import org.apache.solr.analytics.function.mapping.SubtractFunction;
-import org.apache.solr.analytics.function.mapping.TopFunction;
-import org.apache.solr.analytics.function.reduction.CountFunction;
-import org.apache.solr.analytics.function.reduction.DocCountFunction;
-import org.apache.solr.analytics.function.reduction.MaxFunction;
-import org.apache.solr.analytics.function.reduction.MeanFunction;
-import org.apache.solr.analytics.function.reduction.MedianFunction;
-import org.apache.solr.analytics.function.reduction.MinFunction;
-import org.apache.solr.analytics.function.reduction.MissingFunction;
-import org.apache.solr.analytics.function.reduction.OrdinalFunction;
-import org.apache.solr.analytics.function.reduction.PercentileFunction;
-import org.apache.solr.analytics.function.reduction.SumFunction;
-import org.apache.solr.analytics.function.reduction.UniqueFunction;
-import org.apache.solr.analytics.function.reduction.data.ReductionDataCollector;
-import org.apache.solr.analytics.value.AnalyticsValueStream;
-import org.apache.solr.analytics.value.AnalyticsValueStream.ExpressionType;
-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.schema.BoolField;
-import org.apache.solr.schema.DatePointField;
-import org.apache.solr.schema.DoublePointField;
-import org.apache.solr.schema.FieldType;
-import org.apache.solr.schema.FloatPointField;
-import org.apache.solr.schema.IndexSchema;
-import org.apache.solr.schema.IntPointField;
-import org.apache.solr.schema.LongPointField;
-import org.apache.solr.schema.SchemaField;
-import org.apache.solr.schema.StrField;
-import org.apache.solr.schema.TrieDateField;
-import org.apache.solr.schema.TrieDoubleField;
-import org.apache.solr.schema.TrieFloatField;
-import org.apache.solr.schema.TrieIntField;
-import org.apache.solr.schema.TrieLongField;
-
-/**
- * A factory to parse and create expressions, and capture information about those expressions along
- * the way.
- *
- * <p>In order to use, first call {@link #startRequest()} and create all ungrouped expressions, then
- * call {@link #createReductionManager} to get the ungrouped reduction manager. <br>
- * Then for each grouping call {@link #startGrouping()} first then create all expressions within
- * that grouping, finally calling {@link #createGroupingReductionManager} to get the reduction
- * manager for that grouping.
- */
-public class ExpressionFactory {
- private static final Pattern functionNamePattern =
- Pattern.compile("^\\s*([^().\\s]+)\\s*(?:\\(.*\\)\\s*)?$", Pattern.CASE_INSENSITIVE);
- private static final Pattern functionParamsPattern =
- Pattern.compile("^\\s*(?:[^(.)]+)\\s*\\(\\s*(.+)\\s*\\)\\s*$", Pattern.CASE_INSENSITIVE);
- private static final String funtionVarParamUniqueName = ".%s_(%d)";
-
- /** Used to denote a variable length parameter. */
- public static final String variableLengthParamSuffix = "..";
- /** The character used to denote the start of a for each lambda expression */
- public static final char variableForEachSep = ':';
- /** The character used to denote the looped parameter in the for each lambda expression */
- public static final char variableForEachParam = '_';
-
- private HashMap<String, VariableFunctionInfo> systemVariableFunctions;
- private HashMap<String, VariableFunctionInfo> variableFunctions;
- private HashSet<String> variableFunctionNameHistory;
-
- private HashMap<String, CreatorFunction> expressionCreators;
- private final ConstantFunction constantCreator;
-
- private LinkedHashMap<String, ReductionFunction> reductionFunctions;
- private LinkedHashMap<String, ReductionDataCollector<?>> collectors;
- private LinkedHashMap<String, AnalyticsField> fields;
- private HashMap<String, AnalyticsValueStream> expressions;
-
- private IndexSchema schema;
-
- private Map<String, ReductionDataCollector<?>> groupedCollectors;
- private Map<String, AnalyticsField> groupedFields;
- private boolean isGrouped;
-
- public ExpressionFactory(IndexSchema schema) {
- this.schema = schema;
-
- expressionCreators = new HashMap<>();
- systemVariableFunctions = new HashMap<>();
-
- constantCreator = ConstantValue.creatorFunction;
- addSystemFunctions();
- }
-
- /**
- * Get the index schema used by this factory.
- *
- * @return the index schema
- */
- public IndexSchema getSchema() {
- return schema;
- }
-
- /** Prepare the factory to start building the request. */
- public void startRequest() {
- reductionFunctions = new LinkedHashMap<>();
- collectors = new LinkedHashMap<>();
- fields = new LinkedHashMap<>();
- expressions = new HashMap<>();
-
- variableFunctions = new HashMap<>();
- variableFunctions.putAll(systemVariableFunctions);
- variableFunctionNameHistory = new HashSet<>();
-
- isGrouped = false;
- }
-
- /**
- * Prepare the factory to start building the next grouping. <br>
- * NOTE: MUST be called before each new grouping.
- */
- public void startGrouping() {
- groupedCollectors = new HashMap<>();
- groupedFields = new HashMap<>();
-
- isGrouped = true;
- }
-
- /**
- * Add a system function to the expression factory. This will be treated as a native function and
- * not a variable function.
- *
- * @param functionName the unique name for the function
- * @param functionCreator the creator function to generate an expression
- * @return this factory, to easily chain function adds
- * @throws SolrException if the functionName is not unique
- */
- public ExpressionFactory addSystemFunction(
- final String functionName, final CreatorFunction functionCreator) throws SolrException {
- if (expressionCreators.containsKey(functionName)) {
- throw new SolrException(
- ErrorCode.BAD_REQUEST, "System function " + functionName + " defined twice.");
- }
- expressionCreators.put(CountFunction.name, CountFunction.creatorFunction);
- return this;
- }
-
- /**
- * Add a variable function that will be treated like a system function.
- *
- * @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 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);
- }
-
- /**
- * Add a variable function that was defined in an analytics request.
- *
- * @param functionSignature the function signature of the variable function (e.g. {@code
- * func(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 addUserDefinedVariableFunction(
- final String functionSignature, final String returnSignature) throws SolrException {
- return addVariableFunction(functionSignature, returnSignature, variableFunctions);
- }
-
- /**
- * Add a variable function to the given map of variable functions.
- *
- * @param functionSignature the function signature of the variable function (e.g. {@code
- * func(a,b)} )
- * @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 functionSignature,
- final String returnSignature,
- Map<String, VariableFunctionInfo> variableFunctions)
- throws SolrException {
- 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 = functionParams;
- varFuncInfo.returnSignature = returnSignature;
- variableFunctions.put(functionName, varFuncInfo);
- return this;
- }
-
- /**
- * Create a reduction manager to manage the collection of all expressions that have been created
- * since {@link #startRequest()} was called.
- *
- * @param isCloudCollection whether the request is a distributed request
- * @return a reduction manager
- */
- public ReductionCollectionManager createReductionManager(boolean isCloudCollection) {
- ReductionDataCollector<?>[] collectorsArr = new ReductionDataCollector<?>[collectors.size()];
- collectors.values().toArray(collectorsArr);
- if (isCloudCollection) {
- return new MergingReductionCollectionManager(collectorsArr, fields.values());
- } else {
- return new ReductionCollectionManager(collectorsArr, fields.values());
- }
- }
-
- /**
- * Create a reduction manager to manage the collection of all expressions that have been created
- * since {@link #startGrouping()} was called.
- *
- * @param isCloudCollection whether the request is a distributed request
- * @return a reduction manager
- */
- public ReductionCollectionManager createGroupingReductionManager(boolean isCloudCollection) {
- ReductionDataCollector<?>[] collectorsArr =
- new ReductionDataCollector<?>[groupedCollectors.size()];
- groupedCollectors.values().toArray(collectorsArr);
- if (isCloudCollection) {
- return new MergingReductionCollectionManager(collectorsArr, groupedFields.values());
- } else {
- return new ReductionCollectionManager(collectorsArr, groupedFields.values());
- }
- }
-
- /**
- * Parse and build an expression from the given expression string.
- *
- * @param expressionStr string that represents the desired expression
- * @return the object representation of the expression
- * @throws SolrException if an error occurs while constructing the expression
- */
- public AnalyticsValueStream createExpression(String expressionStr) throws SolrException {
- return createExpression(expressionStr, new HashMap<>(), null, null);
- }
-
- /**
- * Create an expression from the given expression string, with the given variable function
- * information.
- *
- * @param expressionStr string that represents the desired expression
- * @param varFuncParams the current set of variable function parameters and their values. If this
- * expression is not a variable function return signature, the map should be empty.
- * @param varFuncVarParamName if the current expression is a variable function return signature,
- * this must be the name of the variable length parameter if it is included in the function
- * signature.
- * @param varFuncVarParamValues if the current expression is a variable function return signature,
- * this must be the array values of the variable length parameter if they are included when
- * calling the function.
- * @return the object representation of the expression
- * @throws SolrException if an error occurs while constructing the expression
- */
- private AnalyticsValueStream createExpression(
- String expressionStr,
- Map<String, AnalyticsValueStream> varFuncParams,
- String varFuncVarParamName,
- String[] varFuncVarParamValues)
- throws SolrException {
- AnalyticsValueStream expression;
- expressionStr = expressionStr.trim();
-
- boolean isField = false;
- try {
- // Try to make a constant value
- expression = constantCreator.apply(expressionStr);
- } catch (SolrException e1) {
- // Not a constant
- // If the expression has parens, it is an expression otherwise it is a field
- if (!expressionStr.contains("(")) {
- // Try to make a field out of it
- expression = createField(schema.getField(expressionStr));
- isField = true;
- } else {
- // Must be a function
- expression =
- createFunction(
- expressionStr, varFuncParams, varFuncVarParamName, varFuncVarParamValues);
- }
- }
-
- // Try to use an already made expression instead of the new one.
- // This will decrease the amount of collection needed to be done.
- if (expressions.containsKey(expression.getExpressionStr())) {
- expression = expressions.get(expression.getExpressionStr());
- // If this is a grouped expression, make sure that the reduction info for the expression is
- // included in the grouped reduction manager.
- if (expression.getExpressionType() == ExpressionType.REDUCTION && isGrouped) {
- ((ReductionFunction) expression)
- .synchronizeDataCollectors(
- collector -> {
- groupedCollectors.put(collector.getExpressionStr(), collector);
- return collector;
- });
- }
- } else {
- expressions.put(expression.getExpressionStr(), expression);
- // Make sure that the reduction info for the expression is included in the reduction manager
- // and grouped reduction manager if necessary.
- if (expression.getExpressionType() == ExpressionType.REDUCTION) {
- reductionFunctions.put(expression.getExpressionStr(), (ReductionFunction) expression);
- ((ReductionFunction) expression)
- .synchronizeDataCollectors(
- collector -> {
- String collectorStr = collector.getExpressionStr();
- ReductionDataCollector<?> usedCollector = collectors.get(collectorStr);
- if (usedCollector == null) {
- usedCollector = collector;
- collectors.put(collectorStr, collector);
- }
- if (isGrouped) {
- groupedCollectors.put(collectorStr, usedCollector);
- }
- return usedCollector;
- });
- }
- // Add the field info to the reduction manager
- if (isField) {
- fields.put(expression.getExpressionStr(), (AnalyticsField) expression);
- }
- }
- // If this is a grouped expression, make sure that the field info is included in the grouped
- // reduction manager.
- if (isField && isGrouped) {
- groupedFields.put(expression.getExpressionStr(), (AnalyticsField) expression);
- }
- return expression;
- }
-
- /**
- * Create a function expression from the given expression string, with the given variable function
- * information.
- *
- * @param expressionStr string that represents the desired expression
- * @param varFuncParams the current set of variable function parameters and their values. If this
- * expression is not a variable function return signature, the map should be empty.
- * @param varFuncVarParamName if the current expression is a variable function return signature,
- * this must be the name of the variable length parameter if it is included in the function
- * signature.
- * @param varFuncVarParamValues if the current expression is a variable function return signature,
- * this must be the array values of the variable length parameter if they are included when
- * calling the function.
- * @return the object representation of the expression
- * @throws SolrException if an error occurs while constructing the expression
- */
- private AnalyticsValueStream createFunction(
- String expressionStr,
- Map<String, AnalyticsValueStream> varFuncParams,
- String varFuncVarParamName,
- String[] varFuncVarParamValues)
- throws SolrException {
- AnalyticsValueStream expression = null;
- String name = getFunctionName(expressionStr);
-
- 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
- // expression
- if (varFuncParams.containsKey(params[i])) {
- paramStreams[i] = varFuncParams.get(params[i]);
- } 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 signature
- if (variableFunctions.containsKey(name)) {
- if (variableFunctionNameHistory.contains(name)) {
- throw new SolrException(
- ErrorCode.BAD_REQUEST, "The following variable function is self referencing : " + name);
- }
- variableFunctionNameHistory.add(name);
- VariableFunctionInfo newVarFunc = variableFunctions.get(name);
- Map<String, AnalyticsValueStream> newVarFuncParams = new HashMap<>();
-
- 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)) {
- if (i != newVarFunc.params.length - 1) {
- throw new SolrException(
- ErrorCode.BAD_REQUEST,
- "The following invocation of a variable function has the incorrect number of arguments : "
- + expressionStr);
- }
- variable =
- variable.substring(0, variable.length() - variableLengthParamSuffix.length()).trim();
- int numVars = paramStreams.length - i;
- String[] newVarFuncVarParamValues = new String[numVars];
- for (int j = 0; j < numVars; ++j) {
- // Create a new name for each variable length parameter value
- String paramName = String.format(Locale.ROOT, funtionVarParamUniqueName, variable, j);
- newVarFuncVarParamValues[j] = paramName;
- newVarFuncParams.put(paramName, paramStreams[i + j]);
- }
- expression =
- createFunction(
- newVarFunc.returnSignature, newVarFuncParams, variable, newVarFuncVarParamValues);
- varLenEnd = true;
- } else {
- newVarFuncParams.put(variable, paramStreams[i]);
- }
- }
- 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);
- } else if (expressionCreators.containsKey(name)) {
- // It is a regular system function
- expression = 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;
- }
-
- /**
- * Create an {@link AnalyticsField} out of the given {@link SchemaField}.
- *
- * <p>Currently only fields with doc-values enabled are supported.
- *
- * @param field the field to convert for analytics
- * @return an analytics representation of the field
- * @throws SolrException if the field is not supported by the analytics framework
- */
- private AnalyticsField createField(SchemaField field) throws SolrException {
- String fieldName = field.getName();
- if (fields.containsKey(fieldName)) {
- return fields.get(fieldName);
- }
- if (!field.hasDocValues()) {
- throw new SolrException(
- ErrorCode.BAD_REQUEST, "The field " + fieldName + " does not have docValues enabled.");
- }
- boolean multivalued = field.multiValued();
- FieldType fieldType = field.getType();
- AnalyticsField aField;
- if (fieldType instanceof BoolField) {
- if (multivalued) {
- aField = new BooleanMultiField(fieldName);
- } else {
- aField = new BooleanField(fieldName);
- }
- } else if (fieldType instanceof TrieIntField) {
- if (multivalued) {
- aField = new IntMultiTrieField(fieldName);
- } else {
- aField = new IntField(fieldName);
- }
- } else if (fieldType instanceof IntPointField) {
- if (multivalued) {
- aField = new IntMultiPointField(fieldName);
- } else {
- aField = new IntField(fieldName);
- }
- } else if (fieldType instanceof TrieLongField) {
- if (multivalued) {
- aField = new LongMultiTrieField(fieldName);
- } else {
- aField = new LongField(fieldName);
- }
- } else if (fieldType instanceof LongPointField) {
- if (multivalued) {
- aField = new LongMultiPointField(fieldName);
- } else {
- aField = new LongField(fieldName);
- }
- } else if (fieldType instanceof TrieFloatField) {
- if (multivalued) {
- aField = new FloatMultiTrieField(fieldName);
- } else {
- aField = new FloatField(fieldName);
- }
- } else if (fieldType instanceof FloatPointField) {
- if (multivalued) {
- aField = new FloatMultiPointField(fieldName);
- } else {
- aField = new FloatField(fieldName);
- }
- } else if (fieldType instanceof TrieDoubleField) {
- if (multivalued) {
- aField = new DoubleMultiTrieField(fieldName);
- } else {
- aField = new DoubleField(fieldName);
- }
- } else if (fieldType instanceof DoublePointField) {
- if (multivalued) {
- aField = new DoubleMultiPointField(fieldName);
- } else {
- aField = new DoubleField(fieldName);
- }
- } else if (fieldType instanceof TrieDateField) {
- if (multivalued) {
- aField = new DateMultiTrieField(fieldName);
- } else {
- aField = new DateField(fieldName);
- }
- } else if (fieldType instanceof DatePointField) {
- if (multivalued) {
- aField = new DateMultiPointField(fieldName);
- } else {
- aField = new DateField(fieldName);
- }
- } else if (fieldType instanceof StrField) {
- if (multivalued) {
- aField = new StringMultiField(fieldName);
- } else {
- aField = new StringField(fieldName);
- }
- } else {
- throw new SolrException(
- ErrorCode.BAD_REQUEST,
- "FieldType of the following field not supported by analytics: " + fieldName);
- }
- return aField;
- }
-
- /**
- * Get the name of the top function used in the given expression.
- *
- * @param expression the expression to find the function name of
- * @return the name of the function
- * @throws SolrException if the expression has incorrect syntax
- */
- private static String getFunctionName(String expression) throws SolrException {
- Matcher m = functionNamePattern.matcher(expression);
- if (!m.matches()) {
- throw new SolrException(
- ErrorCode.BAD_REQUEST, "The following function has no name: " + expression);
- }
- String name = m.group(1);
- return name;
- }
-
- /**
- * Get the params of a function.
- *
- * @param function the function to parse
- * @return an array of param strings
- * @throws SolrException if the function has incorrect syntax
- */
- private static String[] getFunctionParams(String function) throws SolrException {
- return getParams(function, null, null);
- }
-
- /**
- * Parse a function expression string and break up the parameters of the function into separate
- * strings.
- *
- * <p>The parsing replaces the variable length parameter, and lambda for-each's using the variable
- * length parameter, with the parameter values in the returned parameter string.
- *
- * <p>Parsing breaks up parameters by commas (',') and ignores ',' inside of extra parens and
- * quotes (both ' and "), since these commas are either splitting up the parameters of nested
- * functions or are apart of strings. <br>
- * The only escaping that needs to be done is " within a double quote string and ' within a single
- * quote string and \ within any string. For example\:
- *
- * <ul>
- * <li>{@code func("This is \" the \\ escaping ' example")} will be treated as {@code func(This
- * is " the \ escaping ' example)}
- * <li>{@code func('This is " the \\ escaping \' example')} will be treated as {@code func(This
- * is " the \ escaping ' example)}
- * </ul>
- *
- * In string constants the \ character is used to escape quotes, so it can never be used alone. in
- * order to write a \ you must write \\
- *
- * @param expression the function expression to parse
- * @param varLengthParamName the name of the variable length parameter that is used in the
- * expression, pass null if none is used.
- * @param varLengthParamValues the values of the variable length parameter that are used in the
- * expression, pass null if none are used.
- * @return the parsed and split arguments to the function
- * @throws SolrException if the expression has incorrect syntax.
- */
- private static String[] getParams(
- String expression, String varLengthParamName, String[] varLengthParamValues)
- throws SolrException {
- Matcher m = functionParamsPattern.matcher(expression);
- if (!m.matches()) {
- return new String[0];
- }
- String paramsStr = m.group(1);
-
- ArrayList<String> paramsList = new ArrayList<String>();
- StringBuilder param = new StringBuilder();
-
- // Variables to help while filling out the values of for-each lambda functions.
- boolean inForEach = false;
- int forEachStart = -1;
- int forEachIter = -1;
- int forEachLevel = -1;
-
- // The current level of nested parenthesis, 0 means the iteration is in no nested parentheses
- int parenCount = 0;
- // If the iteration is currently in a single-quote string constant
- boolean singleQuoteOn = false;
- // If the iteration is currently in a double-quote string constant
- boolean doubleQuoteOn = false;
- // If the iteration is currently in any kind of string constant
- boolean quoteOn = false;
- // Is the next character escaped.
- boolean escaped = false;
-
- char[] chars = paramsStr.toCharArray();
-
- // Iterate through every character, building the params one at a time
- for (int i = 0; i < chars.length; ++i) {
- char c = chars[i];
-
- if (c == ' ' && !quoteOn) {
- // Ignore white space that is not in string constants
- continue;
- } else if (c == ',' && parenCount == 0 && !quoteOn) {
- // This signifies the end of one parameter and the start of another, since we are not in a
- // nested parenthesis or a string constant
- String paramStr = param.toString();
- if (paramStr.length() == 0) {
- throw new SolrException(
- ErrorCode.BAD_REQUEST, "Empty parameter in expression: " + expression);
- }
- // check to see if the parameter is a variable length parameter
- if (paramStr.equals(varLengthParamName)) {
- // Add every variable length parameter value, since there are a variable amount
- for (String paramName : varLengthParamValues) {
- paramsList.add(paramName);
- }
- } else {
- paramsList.add(paramStr);
- }
-
- param.setLength(0);
- continue;
- } else if (c == ',' && !quoteOn && inForEach) {
- // separate the for each parameters, so they can be replaced with the result of the for each
- if (param.charAt(param.length() - 1) == variableForEachParam
- && (param.charAt(param.length() - 2) == '('
- || param.charAt(param.length() - 2) == ',')) {
- param.setLength(param.length() - 1);
- param.append(varLengthParamValues[forEachIter++]);
- }
- } else if (c == '"' && !singleQuoteOn) {
- // Deal with escaping, or ending string constants
- if (doubleQuoteOn && !escaped) {
- doubleQuoteOn = false;
- quoteOn = false;
- } else if (!quoteOn) {
- doubleQuoteOn = true;
- quoteOn = true;
- } else {
- // only happens if escaped is true
- escaped = false;
- }
- } else if (c == '\'' && !doubleQuoteOn) {
- // Deal with escaping, or ending string constants
- if (singleQuoteOn && !escaped) {
- singleQuoteOn = false;
- quoteOn = false;
- } else if (!singleQuoteOn) {
- singleQuoteOn = true;
- quoteOn = true;
- } else {
- // only happens if escaped is true
- escaped = false;
- }
- } else if (c == '(' && !quoteOn) {
- // Reached a further level of nested parentheses
- parenCount++;
- } else if (c == ')' && !quoteOn) {
- // Returned from a level of nested parentheses
- parenCount--;
- if (parenCount < 0) {
- throw new SolrException(
- ErrorCode.BAD_REQUEST,
- "The following expression has extra end parens: " + param.toString());
- }
- if (inForEach) {
- if (param.charAt(param.length() - 1) == variableForEachParam
- && (param.charAt(param.length() - 2) == '('
- || param.charAt(param.length() - 2) == ',')) {
- param.setLength(param.length() - 1);
- param.append(varLengthParamValues[forEachIter++]);
- }
- if (forEachLevel == parenCount) {
- // at the end of the for-each start the parsing of the for-each again, with the next
- // value of the variable length parameter
- if (forEachIter == 0) {
- throw new SolrException(
- ErrorCode.BAD_REQUEST,
- "For each statement for variable '"
- + varLengthParamName
- + "' has no use of lambda variable "
- + variableForEachParam);
- } else if (forEachIter < varLengthParamValues.length) {
- if (parenCount == 0) {
- param.append(')');
- paramsList.add(param.toString());
- param.setLength(0);
- } else {
- param.append(')');
- param.append(',');
- }
- i = forEachStart;
- continue;
- } else {
- inForEach = false;
- }
- }
- }
- }
- if (c == '\\') {
- // Escaping or escaped backslash
- if (!quoteOn) {
- throw new SolrException(
- ErrorCode.BAD_REQUEST,
- "The following expression has escaped characters outside of quotation marks: "
- + expression.toString());
- }
- if (escaped) {
- escaped = false;
- } else {
- escaped = true;
- if (parenCount == 0) {
- continue;
- }
- }
- } else if (escaped) {
- throw new SolrException(
- ErrorCode.BAD_REQUEST,
- "Invalid escape character '"
- + c
- + "' used in the following expression: "
- + expression.toString());
- }
- if (c == variableForEachSep && !quoteOn && varLengthParamName != null) {
- int varStart = param.length() - varLengthParamName.length();
- if (varLengthParamName.contentEquals(param.subSequence(varStart, param.length()))) {
- inForEach = true;
- forEachStart = i;
- forEachIter = 0;
- forEachLevel = parenCount;
- param.setLength(varStart);
- continue;
- }
- throw new SolrException(
- ErrorCode.BAD_REQUEST,
- "For-each called on invalid parameter '" + param.toString().trim());
- }
- param.append(c);
- }
- String paramStr = param.toString().trim();
- if (paramStr.length() == 0) {
- throw new SolrException(
- ErrorCode.BAD_REQUEST, "Empty parameter in expression: " + expression);
- }
- if (parenCount > 0) {
- throw new SolrException(
- ErrorCode.BAD_REQUEST,
- "The following expression needs more end parens: " + param.toString());
- }
- if (quoteOn) {
- throw new SolrException(
- ErrorCode.BAD_REQUEST, "Misplaced quotation marks in expression: " + expression);
- }
- if (paramStr.equals(varLengthParamName)) {
- for (String paramName : varLengthParamValues) {
- paramsList.add(paramName);
- }
- } else {
- paramsList.add(paramStr);
- }
- return paramsList.toArray(new String[paramsList.size()]);
- }
-
- /** Add the natively supported functionality. */
- public void addSystemFunctions() {
- // Mapping Functions
- expressionCreators.put(AbsoluteValueFunction.name, AbsoluteValueFunction.creatorFunction);
- expressionCreators.put(AndFunction.name, AndFunction.creatorFunction);
- expressionCreators.put(AddFunction.name, AddFunction.creatorFunction);
- expressionCreators.put(BottomFunction.name, BottomFunction.creatorFunction);
- expressionCreators.put(CeilingFunction.name, CeilingFunction.creatorFunction);
- expressionCreators.put(ConcatFunction.name, ConcatFunction.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(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(LogFunction.name, LogFunction.creatorFunction);
- expressionCreators.put(LTFunction.name, LTFunction.creatorFunction);
- expressionCreators.put(LTEFunction.name, LTEFunction.creatorFunction);
- expressionCreators.put(MultFunction.name, MultFunction.creatorFunction);
- expressionCreators.put(NegateFunction.name, NegateFunction.creatorFunction);
- expressionCreators.put(OrFunction.name, OrFunction.creatorFunction);
- expressionCreators.put(PowerFunction.name, PowerFunction.creatorFunction);
- expressionCreators.put(ReplaceFunction.name, ReplaceFunction.creatorFunction);
- expressionCreators.put(RemoveFunction.name, RemoveFunction.creatorFunction);
- expressionCreators.put(RoundFunction.name, RoundFunction.creatorFunction);
- expressionCreators.put(StringCastFunction.name, StringCastFunction.creatorFunction);
- expressionCreators.put(SubtractFunction.name, SubtractFunction.creatorFunction);
- expressionCreators.put(TopFunction.name, TopFunction.creatorFunction);
-
- // Reduction Functions
- expressionCreators.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);
- expressionCreators.put(OrdinalFunction.name, OrdinalFunction.creatorFunction);
- expressionCreators.put(PercentileFunction.name, PercentileFunction.creatorFunction);
- expressionCreators.put(SumFunction.name, SumFunction.creatorFunction);
- expressionCreators.put(UniqueFunction.name, UniqueFunction.creatorFunction);
-
- // Variables
- 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);
- }
-
- /**
- * Used for system analytics functions for initialization. Should take in a list of expression
- * parameters and return an expression.
- */
- @FunctionalInterface
- public static interface CreatorFunction {
- AnalyticsValueStream apply(AnalyticsValueStream[] t) throws SolrException;
- }
- /** Used to initialize analytics constants. */
- @FunctionalInterface
- public static interface ConstantFunction {
- AnalyticsValueStream apply(String t) throws SolrException;
- }
-
- static class VariableFunctionInfo {
- public String[] params;
- public String returnSignature;
- }
-
- static 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))))";
- }
-
- static 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))";
- }
-
- static class SquareRootVariableFunction {
- public static final String name = "sqrt";
- public static final String params = "a";
- public static final String function = PowerFunction.name + "(a,0.5)";
- }
-
- static 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))";
- }
-
- static class SandardDeviationVariableFunction {
- public static final String name = "stddev";
- public static final String params = "a";
- public static final String function =
- SquareRootVariableFunction.name + "(" + VarianceVariableFunction.name + "(a))";
- }
-
- static class CSVVariableFunction {
- public static final String name = "csv";
- public static final String params = "a" + ExpressionFactory.variableLengthParamSuffix;
- public static final String function = SeparatedConcatFunction.name + "(',',a)";
- }
-
- static 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
- + "),''))";
- }
-}
diff --git a/solr/modules/analytics/src/java/org/apache/solr/analytics/TimeExceededStubException.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/TimeExceededStubException.java
deleted file mode 100644
index 200350f2591..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/TimeExceededStubException.java
+++ /dev/null
@@ -1,35 +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;
-
-import org.apache.solr.common.SolrException;
-import org.apache.solr.common.params.CommonParams;
-import org.apache.solr.response.SolrQueryResponse;
-
-public final class TimeExceededStubException extends SolrException {
- private static final int HTTP_CODE = 524;
-
- public TimeExceededStubException(Throwable th) {
- super(HTTP_CODE, SolrQueryResponse.RESPONSE_HEADER_PARTIAL_RESULTS_KEY, th);
- setMetadata("cause", CommonParams.TIME_ALLOWED + " is exceeded");
- }
-
- public static boolean isIt(SolrException e) {
- return e.code() == HTTP_CODE
- && SolrQueryResponse.RESPONSE_HEADER_PARTIAL_RESULTS_KEY.equals(e.getMessage());
- }
-}
diff --git a/solr/modules/analytics/src/java/org/apache/solr/analytics/facet/AbstractSolrQueryFacet.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/facet/AbstractSolrQueryFacet.java
deleted file mode 100644
index 512acd8f1ba..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/facet/AbstractSolrQueryFacet.java
+++ /dev/null
@@ -1,110 +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.facet;
-
-import java.io.IOException;
-import java.util.function.Consumer;
-import org.apache.lucene.index.LeafReaderContext;
-import org.apache.lucene.search.Query;
-import org.apache.lucene.search.ScoreMode;
-import org.apache.lucene.search.SimpleCollector;
-import org.apache.solr.analytics.AnalyticsDriver;
-import org.apache.solr.analytics.function.ReductionCollectionManager.ReductionDataCollection;
-import org.apache.solr.request.SolrQueryRequest;
-import org.apache.solr.search.SolrIndexSearcher;
-
-/**
- * Solr Query Facets are AnalyticsFacets that are calculated after the document streaming phase has
- * occurred in the {@link AnalyticsDriver} (during which StreamingFacets and overall expressions are
- * calculated). {@link AbstractSolrQueryFacet}s should not be confused with {@link QueryFacet}s,
- * which are a specific sub-type.
- *
- * <p>The filtering for these facets is done through issuing additional Solr queries, and collecting
- * on the resulting documents. Unlike streaming facets, which have an unspecified amount of facet
- * values (facet buckets), the amount of facet values is determined by the user and a Solr query is
- * issued for each requested facet value.
- */
-public abstract class AbstractSolrQueryFacet extends AnalyticsFacet {
-
- protected AbstractSolrQueryFacet(String name) {
- super(name);
- }
-
- /**
- * Returns the set of {@link FacetValueQueryExecuter}s, one for each facet value, through the
- * given consumer.
- *
- * <p>Each of these executors will be executed after the streaming phase in the {@link
- * AnalyticsDriver}.
- *
- * @param filter the overall query representing the documents being used for the analytics request
- * @param queryRequest the queryRequest
- * @param consumer the consumer of each facet value's executer
- */
- public abstract void createFacetValueExecuters(
- final Query filter,
- SolrQueryRequest queryRequest,
- Consumer<FacetValueQueryExecuter> consumer);
-
- /**
- * This executer is in charge of issuing the Solr query for a facet value and collecting results
- * as the query is processed.
- */
- public class FacetValueQueryExecuter extends SimpleCollector {
- private final ReductionDataCollection collection;
- private final Query query;
-
- /**
- * Create an executer to collect the given reduction data from the given Solr query.
- *
- * @param collection The reduction data to collect while querying
- * @param query The query used to filter for the facet value
- */
- public FacetValueQueryExecuter(ReductionDataCollection collection, Query query) {
- this.collection = collection;
- this.query = query;
- }
-
- @Override
- public ScoreMode scoreMode() {
- return ScoreMode.COMPLETE_NO_SCORES;
- }
-
- @Override
- public void doSetNextReader(LeafReaderContext context) throws IOException {
- collectionManager.doSetNextReader(context);
- }
-
- @Override
- public void collect(int doc) throws IOException {
- collectionManager.collect(doc);
- collectionManager.apply();
- }
-
- /**
- * Start the collection for this facet value.
- *
- * @param searcher the solr searcher
- * @throws IOException if an exception occurs during the querying
- */
- public void execute(SolrIndexSearcher searcher) throws IOException {
- collectionManager.clearLastingCollectTargets();
- collectionManager.addLastingCollectTarget(collection);
- searcher.search(query, this);
- }
- }
-}
diff --git a/solr/modules/analytics/src/java/org/apache/solr/analytics/facet/AnalyticsFacet.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/facet/AnalyticsFacet.java
deleted file mode 100644
index 17a96f1d421..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/facet/AnalyticsFacet.java
+++ /dev/null
@@ -1,167 +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.facet;
-
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import org.apache.solr.analytics.function.ExpressionCalculator;
-import org.apache.solr.analytics.function.ReductionCollectionManager;
-import org.apache.solr.analytics.function.ReductionCollectionManager.ReductionDataCollection;
-import org.apache.solr.analytics.function.reduction.data.ReductionData;
-import org.apache.solr.analytics.util.AnalyticsResponseHeadings;
-import org.apache.solr.common.util.NamedList;
-
-/** An abstract Facet to break up Analytics data over. */
-public abstract class AnalyticsFacet {
- protected final Map<String, ReductionDataCollection> reductionData;
- protected ReductionCollectionManager collectionManager;
- protected ExpressionCalculator expressionCalculator;
-
- protected final String name;
-
- public AnalyticsFacet(String name) {
- this.reductionData = new LinkedHashMap<>();
- this.name = name;
- }
-
- /**
- * Set the {@link ReductionCollectionManager} that manages the collection of the expressions
- * calculated with this facet.
- *
- * @param collectionManager The manager for relevant expressions
- */
- public void setReductionCollectionManager(ReductionCollectionManager collectionManager) {
- this.collectionManager = collectionManager;
- }
-
- /**
- * Set the {@link ExpressionCalculator} that calculates the collection of the expressions
- * requested for this facet.
- *
- * @param expressionCalculator The calculator for relevant expressions
- */
- public void setExpressionCalculator(ExpressionCalculator expressionCalculator) {
- this.expressionCalculator = expressionCalculator;
- }
-
- /**
- * Import the shard data from a bit-stream, exported by the {@link #exportShardData} method in the
- * each of the collection's shards.
- *
- * @param input The bit-stream to import the data from
- * @throws IOException if an exception occurs while reading from the {@link DataInput}
- */
- public void importShardData(DataInput input) throws IOException {
- int size = input.readInt();
- for (int i = 0; i < size; ++i) {
- importFacetValue(input, input.readUTF());
- }
- }
- /**
- * Import the next facet value's set of {@link ReductionData}.
- *
- * @param input the bit-stream to import the reduction data from
- * @param facetValue the next facet value
- * @throws IOException if an exception occurs while reading from the input
- */
- protected void importFacetValue(DataInput input, String facetValue) throws IOException {
- ReductionDataCollection dataCollection = reductionData.get(facetValue);
- if (dataCollection == null) {
- reductionData.put(facetValue, collectionManager.newDataCollectionIO());
- } else {
- collectionManager.prepareReductionDataIO(dataCollection);
- }
-
- collectionManager.mergeData();
- }
-
- /**
- * Export the shard data through a bit-stream, to be imported by the {@link #importShardData}
- * method in the originating shard.
- *
- * @param output The bit-stream to output the data through
- * @throws IOException if an exception occurs while writing to the {@link DataOutput}
- */
- public void exportShardData(DataOutput output) throws IOException {
- output.writeInt(reductionData.size());
- for (String facetValue : reductionData.keySet()) {
- exportFacetValue(output, facetValue);
- }
- }
- /**
- * Export the next facet value's set of {@link ReductionData}.
- *
- * @param output the bit-stream to output the reduction data to
- * @param facetValue the next facet value
- * @throws IOException if an exception occurs while reading from the input
- */
- protected void exportFacetValue(DataOutput output, String facetValue) throws IOException {
- output.writeUTF(facetValue);
-
- collectionManager.prepareReductionDataIO(reductionData.get(facetValue));
- collectionManager.exportData();
- }
-
- /**
- * Create the old olap-style response of the facet to be returned in the overall analytics
- * response.
- *
- * @return the response of the facet
- */
- public NamedList<Object> createOldResponse() {
- NamedList<Object> nl = new NamedList<>();
- reductionData.forEach(
- (facetVal, dataCol) -> {
- collectionManager.setData(dataCol);
- nl.add(facetVal, new NamedList<>(expressionCalculator.getResults()));
- });
- return nl;
- }
-
- /**
- * Create the response of the facet to be returned in the overall analytics response.
- *
- * @return the response of the facet
- */
- public Iterable<Map<String, Object>> createResponse() {
- List<Map<String, Object>> list = new ArrayList<>();
- reductionData.forEach(
- (facetVal, dataCol) -> {
- Map<String, Object> bucket = new HashMap<>();
- bucket.put(AnalyticsResponseHeadings.FACET_VALUE, facetVal);
- collectionManager.setData(dataCol);
- expressionCalculator.addResults(bucket);
- list.add(bucket);
- });
- return list;
- }
-
- /**
- * Get the name of the Facet. This is unique for the grouping.
- *
- * @return The name of the Facet
- */
- public String getName() {
- return name;
- }
-}
diff --git a/solr/modules/analytics/src/java/org/apache/solr/analytics/facet/PivotFacet.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/facet/PivotFacet.java
deleted file mode 100644
index 87cf0eeea7f..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/facet/PivotFacet.java
+++ /dev/null
@@ -1,115 +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.facet;
-
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-import org.apache.solr.analytics.function.ExpressionCalculator;
-import org.apache.solr.analytics.function.ReductionCollectionManager;
-import org.apache.solr.common.util.NamedList;
-
-/**
- * A facet that takes in multiple ValueFacet expressions and does analytics calculations over each
- * dimension given.
- */
-public class PivotFacet extends AnalyticsFacet implements StreamingFacet {
- private final PivotHead<?> pivotHead;
-
- public PivotFacet(String name, PivotNode<?> topPivot) {
- super(name);
- this.pivotHead = new PivotHead<>(topPivot);
- }
-
- @Override
- public void setReductionCollectionManager(ReductionCollectionManager collectionManager) {
- pivotHead.setReductionCollectionManager(collectionManager);
- }
-
- @Override
- public void setExpressionCalculator(ExpressionCalculator expressionCalculator) {
- pivotHead.setExpressionCalculator(expressionCalculator);
- }
-
- @Override
- public void addFacetValueCollectionTargets() {
- pivotHead.addFacetValueCollectionTargets();
- }
-
- @Override
- public void importShardData(DataInput input) throws IOException {
- pivotHead.importShardData(input);
- }
-
- @Override
- public void exportShardData(DataOutput output) throws IOException {
- pivotHead.exportShardData(output);
- }
-
- @Override
- public NamedList<Object> createOldResponse() {
- return new NamedList<>();
- }
-
- @Override
- public Iterable<Map<String, Object>> createResponse() {
- return pivotHead.createResponse();
- }
-
- /**
- * Typed Pivot class that stores the overall Pivot data and head of the Pivot node chain.
- *
- * <p>This class exists so that the {@link PivotFacet} class doesn't have to be typed ( {@code
- * <T>} ).
- */
- private static class PivotHead<T> implements StreamingFacet {
- private final PivotNode<T> topPivot;
- private final Map<String, T> pivotValues;
-
- public PivotHead(PivotNode<T> topPivot) {
- this.topPivot = topPivot;
- this.pivotValues = new HashMap<>();
- }
-
- public void setReductionCollectionManager(ReductionCollectionManager collectionManager) {
- topPivot.setReductionCollectionManager(collectionManager);
- }
-
- public void setExpressionCalculator(ExpressionCalculator expressionCalculator) {
- topPivot.setExpressionCalculator(expressionCalculator);
- }
-
- @Override
- public void addFacetValueCollectionTargets() {
- topPivot.addFacetValueCollectionTargets(pivotValues);
- }
-
- public void importShardData(DataInput input) throws IOException {
- topPivot.importPivot(input, pivotValues);
- }
-
- public void exportShardData(DataOutput output) throws IOException {
- topPivot.exportPivot(output, pivotValues);
- }
-
- public Iterable<Map<String, Object>> createResponse() {
- return topPivot.getPivotedResponse(pivotValues);
- }
- }
-}
diff --git a/solr/modules/analytics/src/java/org/apache/solr/analytics/facet/PivotNode.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/facet/PivotNode.java
deleted file mode 100644
index 430ac0ff55f..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/facet/PivotNode.java
+++ /dev/null
@@ -1,265 +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.facet;
-
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.function.Consumer;
-import org.apache.solr.analytics.AnalyticsDriver;
-import org.apache.solr.analytics.function.ExpressionCalculator;
-import org.apache.solr.analytics.function.ReductionCollectionManager;
-import org.apache.solr.analytics.function.ReductionCollectionManager.ReductionDataCollection;
-import org.apache.solr.analytics.function.reduction.data.ReductionData;
-import org.apache.solr.analytics.util.AnalyticsResponseHeadings;
-import org.apache.solr.analytics.value.StringValueStream;
-
-/**
- * Representation of one layer of a Pivot Facet. A PivotFacet node is individually sortable, and is
- * collected during the streaming phase of the {@link AnalyticsDriver}.
- */
-public abstract class PivotNode<T> extends SortableFacet implements Consumer<String> {
- private StringValueStream expression;
- protected Map<String, T> currentPivot;
-
- public PivotNode(String name, StringValueStream expression) {
- super(name);
- this.expression = expression;
- }
-
- /**
- * Determine which facet values match the current document. Add the {@link
- * ReductionDataCollection}s of the relevant facet values to the targets of the streaming {@link
- * ReductionCollectionManager} so that they are updated with the current document's data.
- */
- public void addFacetValueCollectionTargets(Map<String, T> pivot) {
- currentPivot = pivot;
- expression.streamStrings(this);
- }
-
- /**
- * Import the shard data from a bit-stream for the given pivot, exported by the {@link
- * #exportPivot} method in the each of the collection's shards.
- *
- * @param input The bit-stream to import the data from
- * @param pivot the values for this pivot node and the pivot children (if they exist)
- * @throws IOException if an exception occurs while reading from the {@link DataInput}
- */
- public void importPivot(DataInput input, Map<String, T> pivot) throws IOException {
- int size = input.readInt();
- currentPivot = pivot;
- for (int i = 0; i < size; ++i) {
- importPivotValue(input, input.readUTF());
- }
- }
- /**
- * Import the next pivot value's set of {@link ReductionData} and children's {@link ReductionData}
- * if they exist.
- *
- * @param input the bit-stream to import the reduction data from
- * @param pivotValue the next pivot value
- * @throws IOException if an exception occurs while reading from the input
- */
- protected abstract void importPivotValue(DataInput input, String pivotValue) throws IOException;
-
- /**
- * Export the shard data through a bit-stream for the given pivot, to be imported by the {@link
- * #importPivot} method in the originating shard.
- *
- * @param output The bit-stream to output the data through
- * @param pivot the values for this pivot node and the pivot children (if they exist)
- * @throws IOException if an exception occurs while writing to the {@link DataOutput}
- */
- public void exportPivot(DataOutput output, Map<String, T> pivot) throws IOException {
- output.writeInt(pivot.size());
- for (Map.Entry<String, T> entry : pivot.entrySet()) {
- output.writeUTF(entry.getKey());
- exportPivotValue(output, entry.getValue());
- }
- }
- /**
- * Export the given pivot data, containing {@link ReductionData} and pivot children if they exist.
- *
- * @param output the bit-stream to output the reduction data to
- * @param pivotData the next pivot value data
- * @throws IOException if an exception occurs while reading from the input
- */
- protected abstract void exportPivotValue(DataOutput output, T pivotData) throws IOException;
-
- /**
- * Create the response of the facet to be returned in the overall analytics response.
- *
- * @param pivot the pivot to create a response for
- * @return the response of the facet
- */
- public abstract Iterable<Map<String, Object>> getPivotedResponse(Map<String, T> pivot);
-
- /** A pivot node that has no pivot children. */
- public static class PivotLeaf extends PivotNode<ReductionDataCollection> {
-
- public PivotLeaf(String name, StringValueStream expression) {
- super(name, expression);
- }
-
- @Override
- public void accept(String pivotValue) {
- ReductionDataCollection collection = currentPivot.get(pivotValue);
- if (collection == null) {
- collection = collectionManager.newDataCollectionTarget();
- currentPivot.put(pivotValue, collection);
- } else {
- collectionManager.addCollectTarget(collection);
- }
- }
-
- @Override
- protected void importPivotValue(DataInput input, String pivotValue) throws IOException {
- ReductionDataCollection dataCollection = currentPivot.get(pivotValue);
- if (dataCollection == null) {
- currentPivot.put(pivotValue, collectionManager.newDataCollectionIO());
- } else {
- collectionManager.prepareReductionDataIO(dataCollection);
- }
- collectionManager.mergeData();
- }
-
- @Override
- protected void exportPivotValue(DataOutput output, ReductionDataCollection pivotData)
- throws IOException {
- collectionManager.prepareReductionDataIO(pivotData);
- collectionManager.exportData();
- }
-
- @Override
- public Iterable<Map<String, Object>> getPivotedResponse(
- Map<String, ReductionDataCollection> pivot) {
- final List<FacetBucket> facetResults = new ArrayList<>();
- pivot.forEach(
- (facetVal, dataCol) -> {
- collectionManager.setData(dataCol);
- facetResults.add(new FacetBucket(facetVal, expressionCalculator.getResults()));
- });
-
- Iterable<FacetBucket> facetResultsIter = applyOptions(facetResults);
- final List<Map<String, Object>> results = new ArrayList<>();
- // Export each expression in the bucket.
- for (FacetBucket bucket : facetResultsIter) {
- Map<String, Object> bucketMap = new HashMap<>();
- bucketMap.put(AnalyticsResponseHeadings.PIVOT_NAME, name);
- bucketMap.put(AnalyticsResponseHeadings.FACET_VALUE, bucket.getFacetValue());
- bucketMap.put(AnalyticsResponseHeadings.RESULTS, bucket.getResults());
- results.add(bucketMap);
- }
- return results;
- }
- }
-
- /** A pivot node that has pivot children. */
- public static class PivotBranch<T> extends PivotNode<PivotBranch.PivotDataPair<T>> {
- private final PivotNode<T> childPivot;
-
- public PivotBranch(String name, StringValueStream expression, PivotNode<T> childPivot) {
- super(name, expression);
- this.childPivot = childPivot;
- }
-
- @Override
- public void setReductionCollectionManager(ReductionCollectionManager collectionManager) {
- super.setReductionCollectionManager(collectionManager);
- childPivot.setReductionCollectionManager(collectionManager);
- }
-
- @Override
- public void setExpressionCalculator(ExpressionCalculator expressionCalculator) {
- super.setExpressionCalculator(expressionCalculator);
- childPivot.setExpressionCalculator(expressionCalculator);
- }
-
- @Override
- public void accept(String pivotValue) {
- PivotDataPair<T> pivotData = currentPivot.get(pivotValue);
- if (pivotData == null) {
- pivotData = new PivotDataPair<>();
- pivotData.childPivots = new HashMap<>();
- pivotData.pivotReduction = collectionManager.newDataCollectionTarget();
- currentPivot.put(pivotValue, pivotData);
- } else {
- collectionManager.addCollectTarget(pivotData.pivotReduction);
- }
- childPivot.addFacetValueCollectionTargets(pivotData.childPivots);
- }
-
- @Override
- protected void importPivotValue(DataInput input, String pivotValue) throws IOException {
- PivotDataPair<T> pivotData = currentPivot.get(pivotValue);
- if (pivotData == null) {
- pivotData = new PivotDataPair<>();
- pivotData.childPivots = new HashMap<>();
- pivotData.pivotReduction = collectionManager.newDataCollectionIO();
- currentPivot.put(pivotValue, pivotData);
- } else {
- collectionManager.prepareReductionDataIO(pivotData.pivotReduction);
- }
- collectionManager.mergeData();
- childPivot.importPivot(input, pivotData.childPivots);
- }
-
- @Override
- protected void exportPivotValue(DataOutput output, PivotDataPair<T> pivotData)
- throws IOException {
- collectionManager.prepareReductionDataIO(pivotData.pivotReduction);
- collectionManager.exportData();
-
- childPivot.exportPivot(output, pivotData.childPivots);
- }
-
- @Override
- public Iterable<Map<String, Object>> getPivotedResponse(Map<String, PivotDataPair<T>> pivot) {
- final List<FacetBucket> facetResults = new ArrayList<>();
- pivot.forEach(
- (facetVal, dataPair) -> {
- collectionManager.setData(dataPair.pivotReduction);
- facetResults.add(new FacetBucket(facetVal, expressionCalculator.getResults()));
- });
-
- Iterable<FacetBucket> facetResultsIter = applyOptions(facetResults);
- final List<Map<String, Object>> results = new ArrayList<>();
- // Export each expression in the bucket.
- for (FacetBucket bucket : facetResultsIter) {
- Map<String, Object> bucketMap = new HashMap<>();
- bucketMap.put(AnalyticsResponseHeadings.PIVOT_NAME, name);
- bucketMap.put(AnalyticsResponseHeadings.FACET_VALUE, bucket.getFacetValue());
- bucketMap.put(AnalyticsResponseHeadings.RESULTS, bucket.getResults());
- bucketMap.put(
- AnalyticsResponseHeadings.PIVOT_CHILDREN,
- childPivot.getPivotedResponse(pivot.get(bucket.getFacetValue()).childPivots));
- results.add(bucketMap);
- }
- return results;
- }
-
- /** Contains pivot data for {@link PivotNode.PivotBranch} classes. */
- protected static class PivotDataPair<T> {
- ReductionDataCollection pivotReduction;
- Map<String, T> childPivots;
- }
- }
-}
diff --git a/solr/modules/analytics/src/java/org/apache/solr/analytics/facet/QueryFacet.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/facet/QueryFacet.java
deleted file mode 100644
index 47350a88a6b..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/facet/QueryFacet.java
+++ /dev/null
@@ -1,63 +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.facet;
-
-import java.util.Map;
-import java.util.function.Consumer;
-import org.apache.lucene.search.Query;
-import org.apache.solr.analytics.function.ReductionCollectionManager.ReductionDataCollection;
-import org.apache.solr.common.SolrException;
-import org.apache.solr.common.SolrException.ErrorCode;
-import org.apache.solr.request.SolrQueryRequest;
-import org.apache.solr.search.QParser;
-import org.apache.solr.search.QueryUtils;
-
-/** A facet that breaks down the data by additional Solr Queries. */
-public class QueryFacet extends AbstractSolrQueryFacet {
- private final Map<String, String> queries;
-
- public QueryFacet(String name, Map<String, String> queries) {
- super(name);
- this.queries = queries;
- }
-
- @Override
- public void createFacetValueExecuters(
- final Query filter,
- SolrQueryRequest queryRequest,
- Consumer<FacetValueQueryExecuter> consumer) {
- queries.forEach(
- (queryName, query) -> {
- final Query q;
- try {
- q = QParser.getParser(query, queryRequest).getQuery();
- } catch (Exception e) {
- throw new SolrException(
- ErrorCode.BAD_REQUEST,
- "Invalid query '" + query + "' in query facet '" + getName() + "'",
- e);
- }
- // The searcher sends docIds to the QueryFacetAccumulator which forwards
- // them to <code>collectQuery()</code> in this class for collection.
- Query queryQuery = QueryUtils.combineQueryAndFilter(q, filter);
-
- ReductionDataCollection dataCol = collectionManager.newDataCollection();
- reductionData.put(queryName, dataCol);
- consumer.accept(new FacetValueQueryExecuter(dataCol, queryQuery));
- });
- }
-}
diff --git a/solr/modules/analytics/src/java/org/apache/solr/analytics/facet/RangeFacet.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/facet/RangeFacet.java
deleted file mode 100644
index 3d41e0831ed..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/facet/RangeFacet.java
+++ /dev/null
@@ -1,117 +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.facet;
-
-import java.util.EnumSet;
-import java.util.List;
-import java.util.function.Consumer;
-import org.apache.lucene.search.Query;
-import org.apache.solr.analytics.function.ReductionCollectionManager.ReductionDataCollection;
-import org.apache.solr.analytics.util.FacetRangeGenerator;
-import org.apache.solr.analytics.util.FacetRangeGenerator.FacetRange;
-import org.apache.solr.common.params.FacetParams.FacetRangeInclude;
-import org.apache.solr.common.params.FacetParams.FacetRangeOther;
-import org.apache.solr.request.SolrQueryRequest;
-import org.apache.solr.schema.SchemaField;
-import org.apache.solr.search.QueryUtils;
-
-/** A facet that groups data by a discrete set of ranges. */
-public class RangeFacet extends AbstractSolrQueryFacet {
- protected final SchemaField field;
- protected final String start;
- protected final String end;
- protected final List<String> gaps;
- protected boolean hardEnd = false;
- protected EnumSet<FacetRangeInclude> include;
- protected EnumSet<FacetRangeOther> others;
-
- public RangeFacet(String name, SchemaField field, String start, String end, List<String> gaps) {
- super(name);
- this.field = field;
- this.start = start;
- this.end = end;
- this.gaps = gaps;
- include = EnumSet.of(FacetRangeInclude.LOWER);
- others = EnumSet.of(FacetRangeOther.NONE);
- }
-
- @Override
- public void createFacetValueExecuters(
- final Query filter,
- SolrQueryRequest queryRequest,
- Consumer<FacetValueQueryExecuter> consumer) {
- // Computes the end points of the ranges in the rangeFacet
- final FacetRangeGenerator<? extends Comparable<?>> rec = FacetRangeGenerator.create(this);
- final SchemaField sf = field;
-
- // Create a rangeFacetAccumulator for each range and
- // collect the documents for that range.
- for (FacetRange range : rec.getRanges()) {
- Query q =
- sf.getType()
- .getRangeQuery(
- null, sf, range.lower, range.upper, range.includeLower, range.includeUpper);
- // The searcher sends docIds to the RangeFacetAccumulator which forwards
- // them to <code>collectRange()</code> in this class for collection.
- Query rangeQuery = QueryUtils.combineQueryAndFilter(q, filter);
-
- ReductionDataCollection dataCol = collectionManager.newDataCollection();
- reductionData.put(range.toString(), dataCol);
- consumer.accept(new FacetValueQueryExecuter(dataCol, rangeQuery));
- }
- }
-
- public String getStart() {
- return start;
- }
-
- public String getEnd() {
- return end;
- }
-
- public EnumSet<FacetRangeInclude> getInclude() {
- return include;
- }
-
- public void setInclude(EnumSet<FacetRangeInclude> include) {
- this.include = include;
- }
-
- public List<String> getGaps() {
- return gaps;
- }
-
- public boolean isHardEnd() {
- return hardEnd;
- }
-
- public void setHardEnd(boolean hardEnd) {
- this.hardEnd = hardEnd;
- }
-
- public EnumSet<FacetRangeOther> getOthers() {
- return others;
- }
-
- public void setOthers(EnumSet<FacetRangeOther> others) {
- this.others = others;
- }
-
- public SchemaField getField() {
- return field;
- }
-}
diff --git a/solr/modules/analytics/src/java/org/apache/solr/analytics/facet/SortableFacet.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/facet/SortableFacet.java
deleted file mode 100644
index 7ef790b60cf..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/facet/SortableFacet.java
+++ /dev/null
@@ -1,170 +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.facet;
-
-import java.util.ArrayList;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-import org.apache.solr.analytics.facet.compare.FacetResultsComparator;
-import org.apache.solr.analytics.util.AnalyticsResponseHeadings;
-import org.apache.solr.common.util.NamedList;
-
-/** A facet that can be sorted by either the facet value or an expression value. */
-public abstract class SortableFacet extends AnalyticsFacet {
- protected FacetSortSpecification sort = null;
-
- protected SortableFacet(String name) {
- super(name);
- }
-
- @Override
- public NamedList<Object> createOldResponse() {
- final NamedList<Object> results = new NamedList<>();
- // Export each expression in the bucket.
- for (FacetBucket bucket : getBuckets()) {
- results.add(bucket.getFacetValue(), new NamedList<>(bucket.getResults()));
- }
- return results;
- }
-
- @Override
- public Iterable<Map<String, Object>> createResponse() {
- final List<Map<String, Object>> results = new ArrayList<>();
- // Export each expression in the bucket.
- for (FacetBucket bucket : getBuckets()) {
- Map<String, Object> bucketMap = new HashMap<>();
- bucketMap.put(AnalyticsResponseHeadings.FACET_VALUE, bucket.getFacetValue());
- bucketMap.put(AnalyticsResponseHeadings.RESULTS, bucket.getResults());
- results.add(bucketMap);
- }
- return results;
- }
-
- private Iterable<FacetBucket> getBuckets() {
- final List<FacetBucket> facetResults = new ArrayList<>();
- reductionData.forEach(
- (facetVal, dataCol) -> {
- collectionManager.setData(dataCol);
- facetResults.add(new FacetBucket(facetVal, expressionCalculator.getResults()));
- });
-
- return applyOptions(facetResults);
- }
-
- /**
- * Apply the sorting options to the given facet results.
- *
- * @param facetResults to apply sorting options to
- * @return the sorted results
- */
- protected Iterable<FacetBucket> applyOptions(List<FacetBucket> facetResults) {
- // Sorting the buckets if a sort specification is provided
- if (sort == null || facetResults.isEmpty()) {
- return facetResults;
- }
- Comparator<FacetBucket> comp = sort.getComparator();
- facetResults.sort(comp);
- // apply the limit
- if (sort.getLimit() > 0) {
- if (sort.getOffset() > 0) {
- facetResults =
- facetResults.stream().skip(sort.getOffset()).collect(Collectors.toUnmodifiableList());
- }
- facetResults =
- facetResults.stream().limit(sort.getLimit()).collect(Collectors.toUnmodifiableList());
- } else if (sort.getLimit() == 0) {
- return new ArrayList<>();
- }
- return facetResults;
- }
-
- /** Specifies how to sort the buckets of a sortable facet. */
- public static class FacetSortSpecification {
- private FacetResultsComparator comparator;
- protected int limit;
- protected int offset;
-
- public FacetSortSpecification(FacetResultsComparator comparator, int limit, int offset) {
- this.comparator = comparator;
- this.limit = limit;
- this.offset = offset;
- }
-
- public FacetResultsComparator getComparator() {
- return comparator;
- }
-
- /**
- * Get the maximum number of buckets to be returned.
- *
- * @return the limit
- */
- public int getLimit() {
- return limit;
- }
- /**
- * Set the maximum number of buckets to be returned.
- *
- * @param limit the maximum number of buckets
- */
- public void setLimit(int limit) {
- this.limit = limit;
- }
-
- /**
- * Get the first bucket to return, has to be used with the {@code limit} option.
- *
- * @return the bucket offset
- */
- public int getOffset() {
- return offset;
- }
- }
-
- public SortableFacet.FacetSortSpecification getSort() {
- return sort;
- }
-
- public void setSort(SortableFacet.FacetSortSpecification sort) {
- this.sort = sort;
- }
-
- public static class FacetBucket {
- private final String facetValue;
- private final Map<String, Object> expressionResults;
-
- public FacetBucket(String facetValue, Map<String, Object> expressionResults) {
- this.facetValue = facetValue;
- this.expressionResults = expressionResults;
- }
-
- public Object getResult(String expression) {
- return expressionResults.get(expression);
- }
-
- public Map<String, Object> getResults() {
- return expressionResults;
- }
-
- public String getFacetValue() {
- return facetValue;
- }
- }
-}
diff --git a/solr/modules/analytics/src/java/org/apache/solr/analytics/facet/StreamingFacet.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/facet/StreamingFacet.java
deleted file mode 100644
index 2c1ea69e05f..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/facet/StreamingFacet.java
+++ /dev/null
@@ -1,31 +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.facet;
-
-import org.apache.solr.analytics.AnalyticsDriver;
-import org.apache.solr.analytics.function.ReductionCollectionManager;
-import org.apache.solr.analytics.function.ReductionCollectionManager.ReductionDataCollection;
-
-/** A facet that is collected during the streaming phase of the {@link AnalyticsDriver}. */
-public interface StreamingFacet {
- /**
- * Determine which facet values match the current document. Add the {@link
- * ReductionDataCollection}s of the relevant facet values to the targets of the streaming {@link
- * ReductionCollectionManager} so that they are updated with the current document's data.
- */
- void addFacetValueCollectionTargets();
-}
diff --git a/solr/modules/analytics/src/java/org/apache/solr/analytics/facet/ValueFacet.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/facet/ValueFacet.java
deleted file mode 100644
index 2b27a6ac85d..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/facet/ValueFacet.java
+++ /dev/null
@@ -1,59 +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.facet;
-
-import java.util.function.Consumer;
-import org.apache.solr.analytics.function.ReductionCollectionManager.ReductionDataCollection;
-import org.apache.solr.analytics.value.StringValueStream;
-
-/**
- * A facet that breaks up data by the values of a mapping expression or field. The mapping
- * expression must be castable to a {@link StringValueStream}.
- */
-public class ValueFacet extends SortableFacet implements StreamingFacet, Consumer<String> {
- private StringValueStream expression;
-
- public ValueFacet(String name, StringValueStream expression) {
- super(name);
- this.expression = expression;
- }
-
- @Override
- public void addFacetValueCollectionTargets() {
- expression.streamStrings(this);
- }
-
- @Override
- public void accept(String t) {
- ReductionDataCollection collection = reductionData.get(t);
- if (collection == null) {
- collection = collectionManager.newDataCollectionTarget();
- reductionData.put(t, collection);
- } else {
- collectionManager.addCollectTarget(collection);
- }
- }
-
- /**
- * Get the expression used to create the facet values.
- *
- * @return a string mapping expression
- */
- public StringValueStream getExpression() {
- return expression;
- }
-}
diff --git a/solr/modules/analytics/src/java/org/apache/solr/analytics/facet/compare/ConstantComparator.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/facet/compare/ConstantComparator.java
deleted file mode 100644
index ad21e76c009..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/facet/compare/ConstantComparator.java
+++ /dev/null
@@ -1,28 +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.facet.compare;
-
-import org.apache.solr.analytics.facet.SortableFacet.FacetBucket;
-
-/** A results comparator that compares constants. */
-public class ConstantComparator extends FacetResultsComparator {
-
- @Override
- public int compare(FacetBucket b1, FacetBucket b2) {
- return 0;
- }
-}
diff --git a/solr/modules/analytics/src/java/org/apache/solr/analytics/facet/compare/DelegatingComparator.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/facet/compare/DelegatingComparator.java
deleted file mode 100644
index be87f36c678..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/facet/compare/DelegatingComparator.java
+++ /dev/null
@@ -1,65 +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.facet.compare;
-
-import java.util.Collection;
-import org.apache.solr.analytics.facet.SortableFacet.FacetBucket;
-import org.apache.solr.common.SolrException;
-import org.apache.solr.common.SolrException.ErrorCode;
-
-/**
- * A comparator used to sort the facet-value buckets of facet, using the delegate comparator if two
- * values are equal.
- */
-public class DelegatingComparator extends FacetResultsComparator {
- private final Iterable<FacetResultsComparator> comparators;
-
- /**
- * Create a delegating results comparator. This comparator will in succession use the given
- * comparators, continuing if the values are equal. Two buckets are considered equal if and only
- * if all comparators find them equal
- *
- * @param comparators the comparators to use in succession
- */
- private DelegatingComparator(Iterable<FacetResultsComparator> comparators) {
- this.comparators = comparators;
- }
-
- public static FacetResultsComparator joinComparators(
- Collection<FacetResultsComparator> comparators) throws SolrException {
- if (comparators.size() == 0) {
- throw new SolrException(
- ErrorCode.BAD_REQUEST, "A sort must have at least 1 comparator criteria.");
- } else if (comparators.size() == 1) {
- return comparators.iterator().next();
- } else {
- return new DelegatingComparator(comparators);
- }
- }
-
- @Override
- public int compare(FacetBucket b1, FacetBucket b2) {
- int val = 0;
- for (FacetResultsComparator comparator : comparators) {
- val = comparator.compare(b1, b2);
- if (val != 0) {
- break;
- }
- }
- return val;
- }
-}
diff --git a/solr/modules/analytics/src/java/org/apache/solr/analytics/facet/compare/ExpressionComparator.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/facet/compare/ExpressionComparator.java
deleted file mode 100644
index 5b981062455..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/facet/compare/ExpressionComparator.java
+++ /dev/null
@@ -1,45 +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.facet.compare;
-
-import org.apache.solr.analytics.facet.SortableFacet.FacetBucket;
-
-/** A comparator used to sort the facet-value buckets of facet. */
-public class ExpressionComparator<T extends Comparable<T>> extends FacetResultsComparator {
- private final String expression;
-
- /**
- * Create an entry comparator comparing the given expression.
- *
- * @param expression the name of the expression results to compare
- */
- public ExpressionComparator(String expression) {
- this.expression = expression;
- }
-
- @Override
- @SuppressWarnings("unchecked")
- public int compare(FacetBucket b1, FacetBucket b2) {
- T t1 = (T) b1.getResult(expression);
- T t2 = (T) b2.getResult(expression);
- if (t1 == null || t2 == null) {
- return Boolean.compare(t2 == null, t1 == null) * resultMult;
- } else {
- return t1.compareTo(t2) * resultMult;
- }
- }
-}
diff --git a/solr/modules/analytics/src/java/org/apache/solr/analytics/facet/compare/FacetResultsComparator.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/facet/compare/FacetResultsComparator.java
deleted file mode 100644
index a8abc2001c3..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/facet/compare/FacetResultsComparator.java
+++ /dev/null
@@ -1,48 +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.facet.compare;
-
-import java.util.Comparator;
-import org.apache.solr.analytics.facet.SortableFacet.FacetBucket;
-
-/** A comparator used to sort the buckets of facet. */
-public abstract class FacetResultsComparator implements Comparator<FacetBucket> {
- protected int resultMult;
-
- /** Create a results comparator assuming an ascending ordering. */
- public FacetResultsComparator() {
- setDirection(true);
- }
-
- /**
- * Set the order direction for comparison.
- *
- * @param ascending whether to compare using an ascending ordering
- */
- public void setDirection(boolean ascending) {
- this.resultMult = ascending ? 1 : -1;
- }
-
- /**
- * Compare one facet bucket to another.
- *
- * @param b1 the first bucket to compare
- * @param b2 the second bucket to compare
- */
- @Override
- public abstract int compare(FacetBucket b1, FacetBucket b2);
-}
diff --git a/solr/modules/analytics/src/java/org/apache/solr/analytics/facet/compare/FacetValueComparator.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/facet/compare/FacetValueComparator.java
deleted file mode 100644
index 3ec723f8f87..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/facet/compare/FacetValueComparator.java
+++ /dev/null
@@ -1,36 +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.facet.compare;
-
-import org.apache.solr.analytics.facet.SortableFacet.FacetBucket;
-
-/**
- * A results comparator that compares the name of facet value buckets, which is the string value of
- * the facet value.
- */
-public class FacetValueComparator extends FacetResultsComparator {
-
- /** Create a facet value comparator. */
- public FacetValueComparator() {
- super();
- }
-
- @Override
- public int compare(FacetBucket b1, FacetBucket b2) {
- return b1.getFacetValue().compareTo(b2.getFacetValue()) * resultMult;
- }
-}
diff --git a/solr/modules/analytics/src/java/org/apache/solr/analytics/facet/compare/package-info.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/facet/compare/package-info.java
deleted file mode 100644
index 6f1ee63e2cd..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/facet/compare/package-info.java
+++ /dev/null
@@ -1,19 +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.
- */
-
-/** Comparators used to sort the buckets of an analytics facet. */
-package org.apache.solr.analytics.facet.compare;
diff --git a/solr/modules/analytics/src/java/org/apache/solr/analytics/facet/package-info.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/facet/package-info.java
deleted file mode 100644
index 3621dd674eb..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/facet/package-info.java
+++ /dev/null
@@ -1,19 +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.
- */
-
-/** Facets supported by the analytics component. */
-package org.apache.solr.analytics.facet;
diff --git a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/ExpressionCalculator.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/function/ExpressionCalculator.java
deleted file mode 100644
index e94b947aad3..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/ExpressionCalculator.java
+++ /dev/null
@@ -1,70 +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;
-
-import java.util.HashMap;
-import java.util.Map;
-import org.apache.solr.analytics.AnalyticsExpression;
-import org.apache.solr.analytics.function.ReductionCollectionManager.ReductionDataCollection;
-import org.apache.solr.analytics.util.AnalyticsResponseHeadings;
-import org.apache.solr.common.util.NamedList;
-
-/** A class used to generate results for a list of {@link AnalyticsExpression}s. */
-public class ExpressionCalculator {
- private final Iterable<AnalyticsExpression> expressions;
-
- public ExpressionCalculator(Iterable<AnalyticsExpression> expressions) {
- this.expressions = expressions;
- }
-
- /**
- * Calculate results for the list of {@link AnalyticsExpression}s.
- *
- * <p>NOTE: This method can, and is, called multiple times to generate different responses. <br>
- * The results are determined by which {@link ReductionDataCollection} is passed to the {@link
- * ReductionCollectionManager#setData} method of the {@link ReductionCollectionManager} managing
- * the reduction for the list of {@link AnalyticsExpression}s.
- *
- * @return a {@link NamedList} containing the results
- */
- public Map<String, Object> getResults() {
- Map<String, Object> exprVals = new HashMap<>();
- expressions.forEach(
- expr -> {
- Object obj = expr.toObject();
- if (expr.exists()) {
- exprVals.put(expr.getName(), obj);
- }
- });
- return exprVals;
- }
-
- /**
- * Calculate results for the list of {@link AnalyticsExpression}s and add them to the given
- * response.
- *
- * <p>NOTE: This method can, and is, called multiple times to generate different responses. <br>
- * The results are determined by which {@link ReductionDataCollection} is passed to the {@link
- * ReductionCollectionManager#setData} method of the {@link ReductionCollectionManager} managing
- * the reduction for the list of {@link AnalyticsExpression}s.
- *
- * @param response the response to add the results map to.
- */
- public void addResults(Map<String, Object> response) {
- response.put(AnalyticsResponseHeadings.RESULTS, getResults());
- }
-}
diff --git a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/MergingReductionCollectionManager.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/function/MergingReductionCollectionManager.java
deleted file mode 100644
index bb5585aae56..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/MergingReductionCollectionManager.java
+++ /dev/null
@@ -1,48 +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;
-
-import org.apache.solr.analytics.function.field.AnalyticsField;
-import org.apache.solr.analytics.function.reduction.data.ReductionDataCollector;
-
-/** The {@link ReductionCollectionManager} used for distributed requests. */
-public class MergingReductionCollectionManager extends ReductionCollectionManager {
-
- public MergingReductionCollectionManager() {
- super();
- }
-
- public MergingReductionCollectionManager(
- final ReductionDataCollector<?>[] reductionDataCollectors,
- final Iterable<AnalyticsField> fields) {
- super(reductionDataCollectors, fields);
- }
-
- @Override
- protected ReductionCollectionManager createNewManager(
- final ReductionDataCollector<?>[] reductionDataCollectors,
- final Iterable<AnalyticsField> fields) {
- return new MergingReductionCollectionManager(reductionDataCollectors, fields);
- }
-
- @Override
- public void setData(ReductionDataCollection dataCollection) {
- for (int i = 0; i < reductionDataCollectors.length; i++) {
- reductionDataCollectors[i].setMergedData(dataCollection.dataArr[i]);
- }
- }
-}
diff --git a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/ReductionCollectionManager.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/function/ReductionCollectionManager.java
deleted file mode 100644
index 37d86a286fb..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/ReductionCollectionManager.java
+++ /dev/null
@@ -1,328 +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;
-
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import org.apache.lucene.index.LeafReaderContext;
-import org.apache.solr.analytics.function.field.AnalyticsField;
-import org.apache.solr.analytics.function.reduction.data.ReductionData;
-import org.apache.solr.analytics.function.reduction.data.ReductionDataCollector;
-import org.apache.solr.analytics.stream.reservation.ReductionDataReservation;
-import org.apache.solr.analytics.stream.reservation.read.ReductionDataReader;
-import org.apache.solr.analytics.stream.reservation.write.ReductionDataWriter;
-import org.apache.solr.analytics.value.AnalyticsValue;
-
-/**
- * The manager of reduction collection. Contains a group of {@link ReductionDataCollector}s which
- * will be updated together.
- *
- * <p>The manager assumes a non-distributed request. {@link MergingReductionCollectionManager} is
- * used for distributed requests.
- */
-public class ReductionCollectionManager {
- protected final ReductionDataCollector<?>[] reductionDataCollectors;
- private final List<ReductionDataReservation<?, ?>> reservations;
-
- private final List<ReductionDataReader<?>> readers;
- private final List<ReductionDataWriter<?>> writers;
-
- private final Iterable<AnalyticsField> fields;
-
- public ReductionCollectionManager() {
- this(new ReductionDataCollector<?>[0], new ArrayList<>(0));
- }
-
- /**
- * Create a Manager to oversee the given {@link ReductionDataCollector}s.
- *
- * @param reductionDataCollectors array of collectors that are collecting over the same set of
- * data
- * @param fields all fields used by the given collectors
- */
- public ReductionCollectionManager(
- final ReductionDataCollector<?>[] reductionDataCollectors,
- final Iterable<AnalyticsField> fields) {
- this.reductionDataCollectors = reductionDataCollectors;
- Arrays.sort(
- reductionDataCollectors, (a, b) -> a.getExpressionStr().compareTo(b.getExpressionStr()));
-
- reservations = new ArrayList<>();
- for (int i = 0; i < reductionDataCollectors.length; i++) {
- reductionDataCollectors[i].submitReservations(reservation -> reservations.add(reservation));
- }
-
- this.fields = fields;
-
- this.readers = new ArrayList<>();
- this.writers = new ArrayList<>();
- }
-
- /**
- * Return whether or not the manager needs collection done, which is false if no collectors are
- * being managed and true if at least one is.
- *
- * @return true if at least one collector is being managed
- */
- public boolean needsCollection() {
- return reductionDataCollectors.length > 0;
- }
-
- /**
- * Merge this collection manager with others.
- *
- * @param reductionManagers the collection managers to merge with
- * @return a collection manager that manages the union of data collectors from this class and the
- * given managers
- */
- public ReductionCollectionManager merge(Iterable<ReductionCollectionManager> reductionManagers) {
- HashMap<String, ReductionDataCollector<?>> mergedCollectors = new HashMap<>();
- HashMap<String, AnalyticsField> mergedFields = new HashMap<>();
-
- for (ReductionDataCollector<?> collector : reductionDataCollectors) {
- mergedCollectors.put(collector.getExpressionStr(), collector);
- }
- fields.forEach(field -> mergedFields.put(field.getExpressionStr(), field));
-
- reductionManagers.forEach(
- manager -> {
- for (ReductionDataCollector<?> collector : manager.reductionDataCollectors) {
- mergedCollectors.put(collector.getExpressionStr(), collector);
- }
- manager.fields.forEach(field -> mergedFields.put(field.getExpressionStr(), field));
- });
- ReductionDataCollector<?>[] collectors = new ReductionDataCollector<?>[mergedCollectors.size()];
- mergedCollectors.values().toArray(collectors);
- return createNewManager(collectors, mergedFields.values());
- }
-
- /**
- * Create an {@link ReductionCollectionManager} to manage the given collectors and fields.
- *
- * @param reductionDataCollectors Reduction collectors
- * @param fields fields used by the reductions
- * @return a collection manager
- */
- protected ReductionCollectionManager createNewManager(
- final ReductionDataCollector<?>[] reductionDataCollectors,
- final Iterable<AnalyticsField> fields) {
- return new ReductionCollectionManager(reductionDataCollectors, fields);
- }
-
- /**
- * Get the {@link AnalyticsField}s used in the managed expressions.
- *
- * @return the fields used
- */
- public Iterable<AnalyticsField> getUsedFields() {
- return fields;
- }
-
- /**
- * Set the context of the readers of the used {@link AnalyticsField}s.
- *
- * @param context the reader context
- * @throws IOException if an error occurs while setting the fields' context
- */
- public void doSetNextReader(LeafReaderContext context) throws IOException {
- for (AnalyticsField field : fields) {
- field.doSetNextReader(context);
- }
- }
-
- /**
- * Collect the values from the used {@link AnalyticsField}s.
- *
- * @param doc the document to collect values for
- * @throws IOException if an error occurs during field collection
- */
- public void collect(int doc) throws IOException {
- for (AnalyticsField field : fields) {
- field.collect(doc);
- }
- }
-
- /**
- * Add a {@link ReductionDataCollection} to target while collecting documents. This target is
- * valid until the lasting targets are cleared.
- *
- * @param target data collection to add document data too
- */
- public void addLastingCollectTarget(ReductionDataCollection target) {
- for (int i = 0; i < reductionDataCollectors.length; i++) {
- reductionDataCollectors[i].addLastingCollectTarget(target.dataArr[i]);
- }
- }
- /** Clear lasting collection targets. */
- public void clearLastingCollectTargets() {
- for (int i = 0; i < reductionDataCollectors.length; i++) {
- reductionDataCollectors[i].clearLastingCollectTargets();
- }
- }
-
- /**
- * Add a new {@link ReductionDataCollection} to target while collecting the next document. This
- * target is only valid for the next {@link #apply()} call.
- *
- * @return the new data collection being targeted
- */
- public ReductionDataCollection newDataCollectionTarget() {
- ReductionDataCollection newCol = new ReductionDataCollection();
- newCol.dataArr = new ReductionData[reductionDataCollectors.length];
- for (int i = 0; i < reductionDataCollectors.length; i++) {
- newCol.dataArr[i] = reductionDataCollectors[i].newDataTarget();
- }
- return newCol;
- }
- /**
- * Add a {@link ReductionDataCollection} to target while collecting the next document. This target
- * is only valid for the next {@link #apply()} call.
- *
- * @param target data collection to add document data too
- */
- public void addCollectTarget(ReductionDataCollection target) {
- for (int i = 0; i < reductionDataCollectors.length; i++) {
- reductionDataCollectors[i].addCollectTarget(target.dataArr[i]);
- }
- }
-
- /**
- * Apply the values of the collected fields through the expressions' logic to the managed data
- * collectors. This is called after {@link #collect(int)} has been called and the collection
- * targets have been added.
- */
- public void apply() {
- for (int i = 0; i < reductionDataCollectors.length; i++) {
- reductionDataCollectors[i].collectAndApply();
- ;
- }
- }
-
- /**
- * Finalize the reductions with the collected data stored in the parameter. Once the data is
- * finalized, the {@link ReductionFunction}s that use these {@link ReductionDataCollector}s act
- * like regular {@link AnalyticsValue} classes that can be accessed through their {@code
- * get<value-type>} methods.
- *
- * @param dataCollection the collection of reduction data to compute results for
- */
- public void setData(ReductionDataCollection dataCollection) {
- for (int i = 0; i < reductionDataCollectors.length; i++) {
- reductionDataCollectors[i].setData(dataCollection.dataArr[i]);
- }
- }
-
- /**
- * Construct a new data collection holding data for all managed data collectors.
- *
- * @return a new data collection
- */
- public ReductionDataCollection newDataCollection() {
- ReductionDataCollection newCol = new ReductionDataCollection();
- newCol.dataArr = new ReductionData[reductionDataCollectors.length];
- for (int i = 0; i < reductionDataCollectors.length; i++) {
- newCol.dataArr[i] = reductionDataCollectors[i].newData();
- }
- return newCol;
- }
-
- /**
- * Sets the stream of shard data to merge with.
- *
- * @param input the stream of shard data
- */
- public void setShardInput(DataInput input) {
- readers.clear();
- reservations.forEach(resv -> readers.add(resv.createReadStream(input)));
- }
- /**
- * Merge the data from the given shard input stream into the set IO data collectors. Should always
- * be called after {@link #setShardInput(DataInput)} and either {@link
- * #prepareReductionDataIO(ReductionDataCollection)} or {@link #newDataCollectionIO()} have been
- * called.
- *
- * @throws IOException if an error occurs while reading the shard data
- */
- public void mergeData() throws IOException {
- for (ReductionDataReader<?> reader : readers) {
- reader.read();
- }
- }
-
- /**
- * Sets the stream to export shard data to.
- *
- * @param output the stream of shard data
- */
- public void setShardOutput(DataOutput output) {
- writers.clear();
- reservations.forEach(resv -> writers.add(resv.createWriteStream(output)));
- }
- /**
- * Export the data from the set IO data collectors to the given shard output stream. Should always
- * be called after {@link #setShardOutput(DataOutput)} and {@link
- * #prepareReductionDataIO(ReductionDataCollection)}.
- *
- * @throws IOException if an error occurs while writing the shard data
- */
- public void exportData() throws IOException {
- for (ReductionDataWriter<?> writer : writers) {
- writer.write();
- }
- }
-
- /**
- * Set the given data collection to be used for either merging or exporting
- *
- * @param col collection to export from or merge to
- */
- public void prepareReductionDataIO(ReductionDataCollection col) {
- for (int i = 0; i < reductionDataCollectors.length; i++) {
- reductionDataCollectors[i].dataIO(col.dataArr[i]);
- }
- }
-
- /**
- * Create a new {@link ReductionDataCollection} to merge to or export from. Mainly used for
- * creating facet value collectors when merging shard data.
- *
- * @return the new data collection created
- */
- public ReductionDataCollection newDataCollectionIO() {
- ReductionDataCollection newCol = new ReductionDataCollection();
- newCol.dataArr = new ReductionData[reductionDataCollectors.length];
- for (int i = 0; i < reductionDataCollectors.length; i++) {
- newCol.dataArr[i] = reductionDataCollectors[i].newDataIO();
- }
- return newCol;
- }
-
- /**
- * Holds the collection of {@link ReductionData} that will be updated together.
- *
- * <p>For example each grouping will have a separate {@link ReductionDataCollection}, and
- * ungrouped expressions will have their own as well.
- */
- public static class ReductionDataCollection {
- public ReductionData[] dataArr;
- }
-}
diff --git a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/ReductionFunction.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/function/ReductionFunction.java
deleted file mode 100644
index 2d50f2f1867..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/ReductionFunction.java
+++ /dev/null
@@ -1,34 +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;
-
-import java.util.function.UnaryOperator;
-import org.apache.solr.analytics.function.reduction.data.ReductionDataCollector;
-import org.apache.solr.analytics.value.AnalyticsValue;
-
-/** A function that reduces the values of a mapping expression, field or constant. */
-public interface ReductionFunction extends AnalyticsValue {
-
- /**
- * Syncs the data collectors with shared versions across the entire Analytics Request so that as
- * little data as possible is sent across shards.
- *
- * @param sync a function that takes in a {@link ReductionDataCollector} and returns a shared
- * version
- */
- void synchronizeDataCollectors(UnaryOperator<ReductionDataCollector<?>> sync);
-}
diff --git a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/AnalyticsField.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/AnalyticsField.java
deleted file mode 100644
index d101c302f5f..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/AnalyticsField.java
+++ /dev/null
@@ -1,72 +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.field;
-
-import java.io.IOException;
-import org.apache.lucene.index.LeafReaderContext;
-import org.apache.solr.analytics.value.AnalyticsValueStream;
-
-/**
- * An analytics wrapper for Solr Fields.
- *
- * <p>Currently only fields with Doc Values enabled can be used in Analytics queries.
- */
-public abstract class AnalyticsField implements AnalyticsValueStream {
- protected static final int initialArrayLength = 20;
-
- protected final String fieldName;
-
- protected AnalyticsField(String fieldName) {
- this.fieldName = fieldName;
- }
-
- @Override
- public String getExpressionStr() {
- return fieldName;
- }
-
- @Override
- public String getName() {
- return fieldName;
- }
-
- @Override
- public ExpressionType getExpressionType() {
- return ExpressionType.FIELD;
- }
-
- @Override
- public AnalyticsValueStream convertToConstant() {
- return this;
- }
-
- /**
- * Set the segment reader context
- *
- * @param context segment context
- * @throws IOException if an error occurs while loading the leaf reader
- */
- public abstract void doSetNextReader(LeafReaderContext context) throws IOException;
-
- /**
- * Collect the value(s) of the wrapped field for the given document, and store the value.
- *
- * @param doc ID of the document to collect
- * @throws IOException if an error occurs while reading the document.
- */
- public abstract void collect(int doc) throws IOException;
-}
diff --git a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/BooleanField.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/BooleanField.java
deleted file mode 100644
index 9b343da5458..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/BooleanField.java
+++ /dev/null
@@ -1,113 +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.field;
-
-import java.io.IOException;
-import java.util.function.Consumer;
-import org.apache.lucene.index.DocValues;
-import org.apache.lucene.index.LeafReaderContext;
-import org.apache.lucene.index.SortedDocValues;
-import org.apache.lucene.util.BytesRef;
-import org.apache.solr.analytics.facet.compare.ExpressionComparator;
-import org.apache.solr.analytics.util.function.BooleanConsumer;
-import org.apache.solr.analytics.value.BooleanValue.CastingBooleanValue;
-import org.apache.solr.schema.BoolField;
-
-/** An analytics wrapper for a single-valued {@link BoolField} with DocValues enabled. */
-public class BooleanField extends AnalyticsField implements CastingBooleanValue {
- private SortedDocValues docValues;
- boolean value;
- boolean exists;
- int trueOrd;
-
- public BooleanField(String fieldName) {
- super(fieldName);
- }
-
- @Override
- public void doSetNextReader(LeafReaderContext context) throws IOException {
- docValues = DocValues.getSorted(context.reader(), fieldName);
-
- // figure out what ord maps to true
- int numOrds = docValues.getValueCount();
- // if no values in the segment, default trueOrd to something other then -1 (missing)
- int trueOrd = -2;
- for (int i = 0; i < numOrds; i++) {
- final BytesRef br = docValues.lookupOrd(i);
- if (br.length == 1 && br.bytes[br.offset] == 'T') {
- trueOrd = i;
- break;
- }
- }
-
- this.trueOrd = trueOrd;
- }
-
- @Override
- public void collect(int doc) throws IOException {
- exists = docValues.advanceExact(doc);
- if (exists) {
- value = trueOrd == docValues.ordValue();
- }
- }
-
- @Override
- public boolean getBoolean() {
- return value;
- }
-
- @Override
- public String getString() {
- return exists ? Boolean.toString(value) : null;
- }
-
- @Override
- public Object getObject() {
- return exists ? value : null;
- }
-
- @Override
- public boolean exists() {
- return exists;
- }
-
- @Override
- public void streamBooleans(BooleanConsumer cons) {
- if (exists) {
- cons.accept(value);
- }
- }
-
- @Override
- public void streamStrings(Consumer<String> cons) {
- if (exists) {
- cons.accept(Boolean.toString(value));
- }
- }
-
- @Override
- public void streamObjects(Consumer<Object> cons) {
- if (exists) {
- cons.accept(value);
- }
- }
-
- @Override
- public ExpressionComparator<Boolean> getObjectComparator(String expression) {
- return new ExpressionComparator<>(expression);
- }
-}
diff --git a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/BooleanMultiField.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/BooleanMultiField.java
deleted file mode 100644
index 81b260acb97..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/BooleanMultiField.java
+++ /dev/null
@@ -1,100 +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.field;
-
-import java.io.IOException;
-import java.util.function.Consumer;
-import org.apache.lucene.index.DocValues;
-import org.apache.lucene.index.LeafReaderContext;
-import org.apache.lucene.index.SortedSetDocValues;
-import org.apache.lucene.util.BytesRef;
-import org.apache.solr.analytics.util.function.BooleanConsumer;
-import org.apache.solr.analytics.value.BooleanValueStream.CastingBooleanValueStream;
-import org.apache.solr.schema.BoolField;
-
-/** An analytics wrapper for a multi-valued {@link BoolField} with DocValues enabled. */
-public class BooleanMultiField extends AnalyticsField implements CastingBooleanValueStream {
- private SortedSetDocValues docValues;
- private int count;
- private boolean[] values;
-
- private int trueOrd;
-
- public BooleanMultiField(String fieldName) {
- super(fieldName);
- count = 0;
- values = new boolean[initialArrayLength];
- }
-
- @Override
- public void doSetNextReader(LeafReaderContext context) throws IOException {
- docValues = DocValues.getSortedSet(context.reader(), fieldName);
-
- // figure out what ord maps to true
- long numOrds = docValues.getValueCount();
- // if no values in the segment, default trueOrd to something other then -1 (missing)
- int trueOrd = -2;
- for (int i = 0; i < numOrds; i++) {
- final BytesRef br = docValues.lookupOrd(i);
- if (br.length == 1 && br.bytes[br.offset] == 'T') {
- trueOrd = i;
- break;
- }
- }
-
- this.trueOrd = trueOrd;
- }
-
- @Override
- public void collect(int doc) throws IOException {
- count = 0;
- if (docValues.advanceExact(doc)) {
- int term;
- while ((term = (int) docValues.nextOrd()) != SortedSetDocValues.NO_MORE_ORDS) {
- if (count == values.length) {
- resizeValues();
- }
- values[count++] = term == trueOrd;
- }
- }
- }
-
- private void resizeValues() {
- boolean[] newValues = new boolean[values.length * 2];
- for (int i = 0; i < count; ++i) {
- newValues[i] = values[i];
- }
- values = newValues;
- }
-
- @Override
- public void streamBooleans(BooleanConsumer cons) {
- for (int i = 0; i < count; ++i) {
- cons.accept(values[i]);
- }
- }
-
- @Override
- public void streamStrings(Consumer<String> cons) {
- streamBooleans(value -> cons.accept(Boolean.toString(value)));
- }
-
- @Override
- public void streamObjects(Consumer<Object> cons) {
- streamBooleans(value -> cons.accept(value));
- }
-}
diff --git a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/DateField.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/DateField.java
deleted file mode 100644
index da99807456f..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/DateField.java
+++ /dev/null
@@ -1,115 +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.field;
-
-import java.io.IOException;
-import java.time.Instant;
-import java.util.Date;
-import java.util.function.Consumer;
-import java.util.function.LongConsumer;
-import org.apache.lucene.index.DocValues;
-import org.apache.lucene.index.LeafReaderContext;
-import org.apache.lucene.index.NumericDocValues;
-import org.apache.solr.analytics.facet.compare.ExpressionComparator;
-import org.apache.solr.analytics.value.DateValue.CastingDateValue;
-import org.apache.solr.schema.DatePointField;
-import org.apache.solr.schema.TrieDateField;
-
-/**
- * An analytics wrapper for a single-valued {@link TrieDateField} or {@link DatePointField} with
- * DocValues enabled.
- */
-public class DateField extends AnalyticsField implements CastingDateValue {
- private NumericDocValues docValues;
- private long value;
- private boolean exists;
-
- public DateField(String fieldName) {
- super(fieldName);
- }
-
- @Override
- public void doSetNextReader(LeafReaderContext context) throws IOException {
- docValues = DocValues.getNumeric(context.reader(), fieldName);
- }
-
- @Override
- public void collect(int doc) throws IOException {
- exists = docValues.advanceExact(doc);
- if (exists) {
- value = docValues.longValue();
- }
- }
-
- @Override
- public long getLong() {
- return value;
- }
-
- @Override
- public Date getDate() {
- return exists ? new Date(value) : null;
- }
-
- @Override
- public String getString() {
- return exists ? Instant.ofEpochMilli(value).toString() : null;
- }
-
- @Override
- public Object getObject() {
- return exists ? value : null;
- }
-
- @Override
- public boolean exists() {
- return exists;
- }
-
- @Override
- public void streamLongs(LongConsumer cons) {
- if (exists) {
- cons.accept(value);
- }
- }
-
- @Override
- public void streamDates(Consumer<Date> cons) {
- if (exists) {
- cons.accept(new Date(value));
- }
- }
-
- @Override
- public void streamStrings(Consumer<String> cons) {
- if (exists) {
- cons.accept(Instant.ofEpochMilli(value).toString());
- }
- }
-
- @Override
- public void streamObjects(Consumer<Object> cons) {
- if (exists) {
- cons.accept(new Date(value));
- }
- }
-
- @Override
- public ExpressionComparator<Date> getObjectComparator(String expression) {
- return new ExpressionComparator<>(expression);
- }
-}
diff --git a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/DateMultiPointField.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/DateMultiPointField.java
deleted file mode 100644
index 438bd259e07..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/DateMultiPointField.java
+++ /dev/null
@@ -1,46 +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.field;
-
-import java.time.Instant;
-import java.util.Date;
-import java.util.function.Consumer;
-import org.apache.solr.analytics.value.DateValueStream.CastingDateValueStream;
-import org.apache.solr.schema.DatePointField;
-
-/** An analytics wrapper for a multi-valued {@link DatePointField} with DocValues enabled. */
-public class DateMultiPointField extends LongMultiPointField implements CastingDateValueStream {
-
- public DateMultiPointField(String fieldName) {
- super(fieldName);
- }
-
- @Override
- public void streamDates(Consumer<Date> cons) {
- streamLongs(value -> cons.accept(new Date(value)));
- }
-
- @Override
- public void streamStrings(Consumer<String> cons) {
- streamLongs(value -> cons.accept(Instant.ofEpochMilli(value).toString()));
- }
-
- @Override
- public void streamObjects(Consumer<Object> cons) {
- streamLongs(value -> cons.accept(new Date(value)));
- }
-}
diff --git a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/DateMultiTrieField.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/DateMultiTrieField.java
deleted file mode 100644
index fb2d5f8819c..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/DateMultiTrieField.java
+++ /dev/null
@@ -1,51 +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.field;
-
-import java.time.Instant;
-import java.util.Date;
-import java.util.function.Consumer;
-import org.apache.solr.analytics.value.DateValueStream.CastingDateValueStream;
-import org.apache.solr.schema.TrieDateField;
-
-/**
- * An analytics wrapper for a multi-valued {@link TrieDateField} with DocValues enabled.
- *
- * @deprecated Trie fields are deprecated as of Solr 7.0
- */
-@Deprecated
-public class DateMultiTrieField extends LongMultiTrieField implements CastingDateValueStream {
-
- public DateMultiTrieField(String fieldName) {
- super(fieldName);
- }
-
- @Override
- public void streamDates(Consumer<Date> cons) {
- streamLongs(value -> cons.accept(new Date(value)));
- }
-
- @Override
- public void streamStrings(Consumer<String> cons) {
- streamLongs(value -> cons.accept(Instant.ofEpochMilli(value).toString()));
- }
-
- @Override
- public void streamObjects(Consumer<Object> cons) {
- streamLongs(value -> cons.accept(new Date(value)));
- }
-}
diff --git a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/DoubleField.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/DoubleField.java
deleted file mode 100644
index 43e6d8fe83f..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/DoubleField.java
+++ /dev/null
@@ -1,101 +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.field;
-
-import java.io.IOException;
-import java.util.function.Consumer;
-import java.util.function.DoubleConsumer;
-import org.apache.lucene.index.DocValues;
-import org.apache.lucene.index.LeafReaderContext;
-import org.apache.lucene.index.NumericDocValues;
-import org.apache.solr.analytics.facet.compare.ExpressionComparator;
-import org.apache.solr.analytics.value.DoubleValue.CastingDoubleValue;
-import org.apache.solr.schema.DoublePointField;
-import org.apache.solr.schema.TrieDoubleField;
-
-/**
- * An analytics wrapper for a single-valued {@link TrieDoubleField} or {@link DoublePointField} with
- * DocValues enabled.
- */
-public class DoubleField extends AnalyticsField implements CastingDoubleValue {
- private NumericDocValues docValues;
- private double value;
- private boolean exists;
-
- public DoubleField(String fieldName) {
- super(fieldName);
- }
-
- @Override
- public void doSetNextReader(LeafReaderContext context) throws IOException {
- docValues = DocValues.getNumeric(context.reader(), fieldName);
- }
-
- @Override
- public void collect(int doc) throws IOException {
- exists = docValues.advanceExact(doc);
- if (exists) {
- value = Double.longBitsToDouble(docValues.longValue());
- }
- }
-
- @Override
- public double getDouble() {
- return value;
- }
-
- @Override
- public String getString() {
- return exists ? Double.toString(value) : null;
- }
-
- @Override
- public Object getObject() {
- return exists ? value : null;
- }
-
- @Override
- public boolean exists() {
- return exists;
- }
-
- @Override
- public void streamDoubles(DoubleConsumer cons) {
- if (exists) {
- cons.accept(value);
- }
- }
-
- @Override
- public void streamStrings(Consumer<String> cons) {
- if (exists) {
- cons.accept(Double.toString(value));
- }
- }
-
- @Override
- public void streamObjects(Consumer<Object> cons) {
- if (exists) {
- cons.accept(value);
- }
- }
-
- @Override
- public ExpressionComparator<Double> getObjectComparator(String expression) {
- return new ExpressionComparator<>(expression);
- }
-}
diff --git a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/DoubleMultiPointField.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/DoubleMultiPointField.java
deleted file mode 100644
index 76af41e501d..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/DoubleMultiPointField.java
+++ /dev/null
@@ -1,81 +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.field;
-
-import java.io.IOException;
-import java.util.function.Consumer;
-import java.util.function.DoubleConsumer;
-import org.apache.lucene.index.DocValues;
-import org.apache.lucene.index.LeafReaderContext;
-import org.apache.lucene.index.SortedNumericDocValues;
-import org.apache.lucene.util.NumericUtils;
-import org.apache.solr.analytics.value.DoubleValueStream.CastingDoubleValueStream;
-import org.apache.solr.schema.DoublePointField;
-
-/** An analytics wrapper for a multi-valued {@link DoublePointField} with DocValues enabled. */
-public class DoubleMultiPointField extends AnalyticsField implements CastingDoubleValueStream {
- private SortedNumericDocValues docValues;
- private int count;
- private double[] values;
-
- public DoubleMultiPointField(String fieldName) {
- super(fieldName);
- count = 0;
- values = new double[initialArrayLength];
- }
-
- @Override
- public void doSetNextReader(LeafReaderContext context) throws IOException {
- docValues = DocValues.getSortedNumeric(context.reader(), fieldName);
- }
-
- @Override
- public void collect(int doc) throws IOException {
- if (docValues.advanceExact(doc)) {
- count = docValues.docValueCount();
- resizeEmptyValues(count);
- for (int i = 0; i < count; ++i) {
- values[i] = NumericUtils.sortableLongToDouble(docValues.nextValue());
- }
- } else {
- count = 0;
- }
- }
-
- private void resizeEmptyValues(int count) {
- if (count > values.length) {
- values = new double[count];
- }
- }
-
- @Override
- public void streamDoubles(DoubleConsumer cons) {
- for (int i = 0; i < count; ++i) {
- cons.accept(values[i]);
- }
- }
-
- @Override
- public void streamStrings(Consumer<String> cons) {
- streamDoubles(value -> cons.accept(Double.toString(value)));
- }
-
- @Override
- public void streamObjects(Consumer<Object> cons) {
- streamDoubles(value -> cons.accept(value));
- }
-}
diff --git a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/DoubleMultiTrieField.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/DoubleMultiTrieField.java
deleted file mode 100644
index cecde00d0a1..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/DoubleMultiTrieField.java
+++ /dev/null
@@ -1,92 +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.field;
-
-import java.io.IOException;
-import java.util.function.Consumer;
-import java.util.function.DoubleConsumer;
-import org.apache.lucene.index.DocValues;
-import org.apache.lucene.index.LeafReaderContext;
-import org.apache.lucene.index.SortedSetDocValues;
-import org.apache.lucene.util.NumericUtils;
-import org.apache.solr.analytics.value.DoubleValueStream.CastingDoubleValueStream;
-import org.apache.solr.legacy.LegacyNumericUtils;
-import org.apache.solr.schema.TrieDoubleField;
-
-/**
- * An analytics wrapper for a multi-valued {@link TrieDoubleField} with DocValues enabled.
- *
- * @deprecated Trie fields are deprecated as of Solr 7.0
- */
-@Deprecated
-public class DoubleMultiTrieField extends AnalyticsField implements CastingDoubleValueStream {
- private SortedSetDocValues docValues;
- private int count;
- private double[] values;
-
- public DoubleMultiTrieField(String fieldName) {
- super(fieldName);
- count = 0;
- values = new double[initialArrayLength];
- }
-
- @Override
- public void doSetNextReader(LeafReaderContext context) throws IOException {
- docValues = DocValues.getSortedSet(context.reader(), fieldName);
- }
-
- @Override
- public void collect(int doc) throws IOException {
- count = 0;
- if (docValues.advanceExact(doc)) {
- int term;
- while ((term = (int) docValues.nextOrd()) != SortedSetDocValues.NO_MORE_ORDS) {
- if (count == values.length) {
- resizeValues();
- }
- values[count++] =
- NumericUtils.sortableLongToDouble(
- LegacyNumericUtils.prefixCodedToLong(docValues.lookupOrd(term)));
- }
- }
- }
-
- private void resizeValues() {
- double[] newValues = new double[values.length * 2];
- for (int i = 0; i < count; ++i) {
- newValues[i] = values[i];
- }
- values = newValues;
- }
-
- @Override
- public void streamDoubles(DoubleConsumer cons) {
- for (int i = 0; i < count; ++i) {
- cons.accept(values[i]);
- }
- }
-
- @Override
- public void streamStrings(Consumer<String> cons) {
- streamDoubles(value -> cons.accept(Double.toString(value)));
- }
-
- @Override
- public void streamObjects(Consumer<Object> cons) {
- streamDoubles(value -> cons.accept(value));
- }
-}
diff --git a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/FloatField.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/FloatField.java
deleted file mode 100644
index fe506f6431f..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/FloatField.java
+++ /dev/null
@@ -1,114 +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.field;
-
-import java.io.IOException;
-import java.util.function.Consumer;
-import java.util.function.DoubleConsumer;
-import org.apache.lucene.index.DocValues;
-import org.apache.lucene.index.LeafReaderContext;
-import org.apache.lucene.index.NumericDocValues;
-import org.apache.solr.analytics.facet.compare.ExpressionComparator;
-import org.apache.solr.analytics.util.function.FloatConsumer;
-import org.apache.solr.analytics.value.FloatValue.CastingFloatValue;
-import org.apache.solr.schema.FloatPointField;
-import org.apache.solr.schema.TrieFloatField;
-
-/**
- * An analytics wrapper for a single-valued {@link TrieFloatField} or {@link FloatPointField} with
- * DocValues enabled.
- */
-public class FloatField extends AnalyticsField implements CastingFloatValue {
- private NumericDocValues docValues;
- private float value;
- private boolean exists;
-
- public FloatField(String fieldName) {
- super(fieldName);
- }
-
- @Override
- public void doSetNextReader(LeafReaderContext context) throws IOException {
- docValues = DocValues.getNumeric(context.reader(), fieldName);
- }
-
- @Override
- public void collect(int doc) throws IOException {
- exists = docValues.advanceExact(doc);
- if (exists) {
- value = Float.intBitsToFloat((int) docValues.longValue());
- }
- }
-
- @Override
- public float getFloat() {
- return value;
- }
-
- @Override
- public double getDouble() {
- return (double) value;
- }
-
- @Override
- public String getString() {
- return exists ? Float.toString(value) : null;
- }
-
- @Override
- public Object getObject() {
- return exists ? value : null;
- }
-
- @Override
- public boolean exists() {
- return exists;
- }
-
- @Override
- public void streamFloats(FloatConsumer cons) {
- if (exists) {
- cons.accept(value);
- }
- }
-
- @Override
- public void streamDoubles(DoubleConsumer cons) {
- if (exists) {
- cons.accept((double) value);
- }
- }
-
- @Override
- public void streamStrings(Consumer<String> cons) {
- if (exists) {
- cons.accept(Float.toString(value));
- }
- }
-
- @Override
- public void streamObjects(Consumer<Object> cons) {
- if (exists) {
- cons.accept(value);
- }
- }
-
- @Override
- public ExpressionComparator<Float> getObjectComparator(String expression) {
- return new ExpressionComparator<>(expression);
- }
-}
diff --git a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/FloatMultiPointField.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/FloatMultiPointField.java
deleted file mode 100644
index d1f9417a37d..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/FloatMultiPointField.java
+++ /dev/null
@@ -1,87 +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.field;
-
-import java.io.IOException;
-import java.util.function.Consumer;
-import java.util.function.DoubleConsumer;
-import org.apache.lucene.index.DocValues;
-import org.apache.lucene.index.LeafReaderContext;
-import org.apache.lucene.index.SortedNumericDocValues;
-import org.apache.lucene.util.NumericUtils;
-import org.apache.solr.analytics.util.function.FloatConsumer;
-import org.apache.solr.analytics.value.FloatValueStream.CastingFloatValueStream;
-import org.apache.solr.schema.FloatPointField;
-
-/** An analytics wrapper for a multi-valued {@link FloatPointField} with DocValues enabled. */
-public class FloatMultiPointField extends AnalyticsField implements CastingFloatValueStream {
- private SortedNumericDocValues docValues;
- private int count;
- private float[] values;
-
- public FloatMultiPointField(String fieldName) {
- super(fieldName);
- count = 0;
- values = new float[initialArrayLength];
- }
-
- @Override
- public void doSetNextReader(LeafReaderContext context) throws IOException {
- docValues = DocValues.getSortedNumeric(context.reader(), fieldName);
- }
-
- @Override
- public void collect(int doc) throws IOException {
- if (docValues.advanceExact(doc)) {
- count = docValues.docValueCount();
- resizeEmptyValues(count);
- for (int i = 0; i < count; ++i) {
- values[i] = NumericUtils.sortableIntToFloat((int) docValues.nextValue());
- }
- } else {
- count = 0;
- }
- }
-
- private void resizeEmptyValues(int count) {
- if (count > values.length) {
- values = new float[count];
- }
- }
-
- @Override
- public void streamFloats(FloatConsumer cons) {
- for (int i = 0; i < count; ++i) {
- cons.accept(values[i]);
- }
- }
-
- @Override
- public void streamDoubles(DoubleConsumer cons) {
- streamFloats(value -> cons.accept((double) value));
- }
-
- @Override
- public void streamStrings(Consumer<String> cons) {
- streamFloats(value -> cons.accept(Float.toString(value)));
- }
-
- @Override
- public void streamObjects(Consumer<Object> cons) {
- streamFloats(value -> cons.accept(value));
- }
-}
diff --git a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/FloatMultiTrieField.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/FloatMultiTrieField.java
deleted file mode 100644
index 1fa9e0fb38a..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/FloatMultiTrieField.java
+++ /dev/null
@@ -1,98 +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.field;
-
-import java.io.IOException;
-import java.util.function.Consumer;
-import java.util.function.DoubleConsumer;
-import org.apache.lucene.index.DocValues;
-import org.apache.lucene.index.LeafReaderContext;
-import org.apache.lucene.index.SortedSetDocValues;
-import org.apache.lucene.util.NumericUtils;
-import org.apache.solr.analytics.util.function.FloatConsumer;
-import org.apache.solr.analytics.value.FloatValueStream.CastingFloatValueStream;
-import org.apache.solr.legacy.LegacyNumericUtils;
-import org.apache.solr.schema.TrieFloatField;
-
-/**
- * An analytics wrapper for a multi-valued {@link TrieFloatField} with DocValues enabled.
- *
- * @deprecated Trie fields are deprecated as of Solr 7.0
- */
-@Deprecated
-public class FloatMultiTrieField extends AnalyticsField implements CastingFloatValueStream {
- private SortedSetDocValues docValues;
- private int count;
- private float[] values;
-
- public FloatMultiTrieField(String fieldName) {
- super(fieldName);
- count = 0;
- values = new float[initialArrayLength];
- }
-
- @Override
- public void doSetNextReader(LeafReaderContext context) throws IOException {
- docValues = DocValues.getSortedSet(context.reader(), fieldName);
- }
-
- @Override
- public void collect(int doc) throws IOException {
- count = 0;
- if (docValues.advanceExact(doc)) {
- int term;
- while ((term = (int) docValues.nextOrd()) != SortedSetDocValues.NO_MORE_ORDS) {
- if (count == values.length) {
- resizeValues();
- }
- values[count++] =
- NumericUtils.sortableIntToFloat(
- LegacyNumericUtils.prefixCodedToInt(docValues.lookupOrd(term)));
- }
- }
- }
-
- private void resizeValues() {
- float[] newValues = new float[values.length * 2];
- for (int i = 0; i < count; ++i) {
- newValues[i] = values[i];
- }
- values = newValues;
- }
-
- @Override
- public void streamFloats(FloatConsumer cons) {
- for (int i = 0; i < count; ++i) {
- cons.accept(values[i]);
- }
- }
-
- @Override
- public void streamDoubles(DoubleConsumer cons) {
- streamFloats(value -> cons.accept((double) value));
- }
-
- @Override
- public void streamStrings(Consumer<String> cons) {
- streamFloats(value -> cons.accept(Float.toString(value)));
- }
-
- @Override
- public void streamObjects(Consumer<Object> cons) {
- streamFloats(value -> cons.accept(value));
- }
-}
diff --git a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/IntField.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/IntField.java
deleted file mode 100644
index b13356f2b18..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/IntField.java
+++ /dev/null
@@ -1,140 +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.field;
-
-import java.io.IOException;
-import java.util.function.Consumer;
-import java.util.function.DoubleConsumer;
-import java.util.function.IntConsumer;
-import java.util.function.LongConsumer;
-import org.apache.lucene.index.DocValues;
-import org.apache.lucene.index.LeafReaderContext;
-import org.apache.lucene.index.NumericDocValues;
-import org.apache.solr.analytics.facet.compare.ExpressionComparator;
-import org.apache.solr.analytics.util.function.FloatConsumer;
-import org.apache.solr.analytics.value.IntValue.CastingIntValue;
-import org.apache.solr.schema.IntPointField;
-import org.apache.solr.schema.TrieIntField;
-
-/**
- * An analytics wrapper for a single-valued {@link TrieIntField} or {@link IntPointField} with
- * DocValues enabled.
- */
-public class IntField extends AnalyticsField implements CastingIntValue {
- private NumericDocValues docValues;
- private int value;
- private boolean exists;
-
- public IntField(String fieldName) {
- super(fieldName);
- }
-
- @Override
- public void doSetNextReader(LeafReaderContext context) throws IOException {
- docValues = DocValues.getNumeric(context.reader(), fieldName);
- }
-
- @Override
- public void collect(int doc) throws IOException {
- exists = docValues.advanceExact(doc);
- if (exists) {
- value = (int) docValues.longValue();
- }
- }
-
- @Override
- public int getInt() {
- return value;
- }
-
- @Override
- public long getLong() {
- return (long) value;
- }
-
- @Override
- public float getFloat() {
- return (float) value;
- }
-
- @Override
- public double getDouble() {
- return (double) value;
- }
-
- @Override
- public String getString() {
- return exists ? Integer.toString(value) : null;
- }
-
- @Override
- public Object getObject() {
- return exists ? value : null;
- }
-
- @Override
- public boolean exists() {
- return exists;
- }
-
- @Override
- public void streamInts(IntConsumer cons) {
- if (exists) {
- cons.accept(value);
- }
- }
-
- @Override
- public void streamLongs(LongConsumer cons) {
- if (exists) {
- cons.accept((long) value);
- }
- }
-
- @Override
- public void streamFloats(FloatConsumer cons) {
- if (exists) {
- cons.accept((float) value);
- }
- }
-
- @Override
- public void streamDoubles(DoubleConsumer cons) {
- if (exists) {
- cons.accept((double) value);
- }
- }
-
- @Override
- public void streamStrings(Consumer<String> cons) {
- if (exists) {
- cons.accept(Integer.toString(value));
- }
- }
-
- @Override
- public void streamObjects(Consumer<Object> cons) {
- if (exists) {
- cons.accept(value);
- }
- }
-
- @Override
- public ExpressionComparator<Integer> getObjectComparator(String expression) {
- return new ExpressionComparator<>(expression);
- }
-}
diff --git a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/IntMultiPointField.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/IntMultiPointField.java
deleted file mode 100644
index 8a401c8bd14..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/IntMultiPointField.java
+++ /dev/null
@@ -1,98 +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.field;
-
-import java.io.IOException;
-import java.util.function.Consumer;
-import java.util.function.DoubleConsumer;
-import java.util.function.IntConsumer;
-import java.util.function.LongConsumer;
-import org.apache.lucene.index.DocValues;
-import org.apache.lucene.index.LeafReaderContext;
-import org.apache.lucene.index.SortedNumericDocValues;
-import org.apache.solr.analytics.util.function.FloatConsumer;
-import org.apache.solr.analytics.value.IntValueStream.CastingIntValueStream;
-import org.apache.solr.schema.IntPointField;
-
-/** An analytics wrapper for a multi-valued {@link IntPointField} with DocValues enabled. */
-public class IntMultiPointField extends AnalyticsField implements CastingIntValueStream {
- private SortedNumericDocValues docValues;
- private int count;
- private int[] values;
-
- public IntMultiPointField(String fieldName) {
- super(fieldName);
- count = 0;
- values = new int[initialArrayLength];
- }
-
- @Override
- public void doSetNextReader(LeafReaderContext context) throws IOException {
- docValues = DocValues.getSortedNumeric(context.reader(), fieldName);
- }
-
- @Override
- public void collect(int doc) throws IOException {
- if (docValues.advanceExact(doc)) {
- count = docValues.docValueCount();
- resizeEmptyValues(count);
- for (int i = 0; i < count; ++i) {
- values[i] = (int) docValues.nextValue();
- }
- } else {
- count = 0;
- }
- }
-
- private void resizeEmptyValues(int count) {
- if (count > values.length) {
- values = new int[count];
- }
- }
-
- @Override
- public void streamInts(IntConsumer cons) {
- for (int i = 0; i < count; ++i) {
- cons.accept(values[i]);
- }
- }
-
- @Override
- public void streamLongs(LongConsumer cons) {
- streamInts(value -> cons.accept((long) value));
- }
-
- @Override
- public void streamFloats(FloatConsumer cons) {
- streamInts(value -> cons.accept((float) value));
- }
-
- @Override
- public void streamDoubles(DoubleConsumer cons) {
- streamInts(value -> cons.accept((double) value));
- }
-
- @Override
- public void streamStrings(Consumer<String> cons) {
- streamInts(value -> cons.accept(Integer.toString(value)));
- }
-
- @Override
- public void streamObjects(Consumer<Object> cons) {
- streamInts(value -> cons.accept(value));
- }
-}
diff --git a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/IntMultiTrieField.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/IntMultiTrieField.java
deleted file mode 100644
index f8b44e97892..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/IntMultiTrieField.java
+++ /dev/null
@@ -1,107 +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.field;
-
-import java.io.IOException;
-import java.util.function.Consumer;
-import java.util.function.DoubleConsumer;
-import java.util.function.IntConsumer;
-import java.util.function.LongConsumer;
-import org.apache.lucene.index.DocValues;
-import org.apache.lucene.index.LeafReaderContext;
-import org.apache.lucene.index.SortedSetDocValues;
-import org.apache.solr.analytics.util.function.FloatConsumer;
-import org.apache.solr.analytics.value.IntValueStream.CastingIntValueStream;
-import org.apache.solr.legacy.LegacyNumericUtils;
-import org.apache.solr.schema.TrieIntField;
-
-/**
- * An analytics wrapper for a multi-valued {@link TrieIntField} with DocValues enabled.
- *
- * @deprecated Trie fields are deprecated as of Solr 7.0
- */
-@Deprecated
-public class IntMultiTrieField extends AnalyticsField implements CastingIntValueStream {
- private SortedSetDocValues docValues;
- private int count;
- private int[] values;
-
- public IntMultiTrieField(String fieldName) {
- super(fieldName);
- count = 0;
- values = new int[initialArrayLength];
- }
-
- @Override
- public void doSetNextReader(LeafReaderContext context) throws IOException {
- docValues = DocValues.getSortedSet(context.reader(), fieldName);
- }
-
- @Override
- public void collect(int doc) throws IOException {
- count = 0;
- if (docValues.advanceExact(doc)) {
- int term;
- while ((term = (int) docValues.nextOrd()) != SortedSetDocValues.NO_MORE_ORDS) {
- if (count == values.length) {
- resizeValues();
- }
- values[count++] = LegacyNumericUtils.prefixCodedToInt(docValues.lookupOrd(term));
- }
- }
- }
-
- private void resizeValues() {
- int[] newValues = new int[values.length * 2];
- for (int i = 0; i < count; ++i) {
- newValues[i] = values[i];
- }
- values = newValues;
- }
-
- @Override
- public void streamInts(IntConsumer cons) {
- for (int i = 0; i < count; ++i) {
- cons.accept(values[i]);
- }
- }
-
- @Override
- public void streamLongs(LongConsumer cons) {
- streamInts(value -> cons.accept((long) value));
- }
-
- @Override
- public void streamFloats(FloatConsumer cons) {
- streamInts(value -> cons.accept((float) value));
- }
-
- @Override
- public void streamDoubles(DoubleConsumer cons) {
- streamInts(value -> cons.accept((double) value));
- }
-
- @Override
- public void streamStrings(Consumer<String> cons) {
- streamInts(value -> cons.accept(Integer.toString(value)));
- }
-
- @Override
- public void streamObjects(Consumer<Object> cons) {
- streamInts(value -> cons.accept(value));
- }
-}
diff --git a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/LongField.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/LongField.java
deleted file mode 100644
index 4feadd62ba5..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/LongField.java
+++ /dev/null
@@ -1,114 +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.field;
-
-import java.io.IOException;
-import java.util.function.Consumer;
-import java.util.function.DoubleConsumer;
-import java.util.function.LongConsumer;
-import org.apache.lucene.index.DocValues;
-import org.apache.lucene.index.LeafReaderContext;
-import org.apache.lucene.index.NumericDocValues;
-import org.apache.solr.analytics.facet.compare.ExpressionComparator;
-import org.apache.solr.analytics.value.LongValue.CastingLongValue;
-import org.apache.solr.schema.LongPointField;
-import org.apache.solr.schema.TrieLongField;
-
-/**
- * An analytics wrapper for a single-valued {@link TrieLongField} or {@link LongPointField} with
- * DocValues enabled.
- */
-public class LongField extends AnalyticsField implements CastingLongValue {
- private NumericDocValues docValues;
- private long value;
- private boolean exists;
-
- public LongField(String fieldName) {
- super(fieldName);
- }
-
- @Override
- public void doSetNextReader(LeafReaderContext context) throws IOException {
- docValues = DocValues.getNumeric(context.reader(), fieldName);
- }
-
- @Override
- public void collect(int doc) throws IOException {
- exists = docValues.advanceExact(doc);
- if (exists) {
- value = docValues.longValue();
- }
- }
-
- @Override
- public long getLong() {
- return value;
- }
-
- @Override
- public double getDouble() {
- return (double) value;
- }
-
- @Override
- public String getString() {
- return exists ? Long.toString(value) : null;
- }
-
- @Override
- public Object getObject() {
- return exists ? value : null;
- }
-
- @Override
- public boolean exists() {
- return exists;
- }
-
- @Override
- public void streamLongs(LongConsumer cons) {
- if (exists) {
- cons.accept(value);
- }
- }
-
- @Override
- public void streamDoubles(DoubleConsumer cons) {
- if (exists) {
- cons.accept((double) value);
- }
- }
-
- @Override
- public void streamStrings(Consumer<String> cons) {
- if (exists) {
- cons.accept(Long.toString(value));
- }
- }
-
- @Override
- public void streamObjects(Consumer<Object> cons) {
- if (exists) {
- cons.accept(value);
- }
- }
-
- @Override
- public ExpressionComparator<Long> getObjectComparator(String expression) {
- return new ExpressionComparator<>(expression);
- }
-}
diff --git a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/LongMultiPointField.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/LongMultiPointField.java
deleted file mode 100644
index ddba2d85f06..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/LongMultiPointField.java
+++ /dev/null
@@ -1,86 +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.field;
-
-import java.io.IOException;
-import java.util.function.Consumer;
-import java.util.function.DoubleConsumer;
-import java.util.function.LongConsumer;
-import org.apache.lucene.index.DocValues;
-import org.apache.lucene.index.LeafReaderContext;
-import org.apache.lucene.index.SortedNumericDocValues;
-import org.apache.solr.analytics.value.LongValueStream.CastingLongValueStream;
-import org.apache.solr.schema.LongPointField;
-
-/** An analytics wrapper for a multi-valued {@link LongPointField} with DocValues enabled. */
-public class LongMultiPointField extends AnalyticsField implements CastingLongValueStream {
- private SortedNumericDocValues docValues;
- private int count;
- private long[] values;
-
- public LongMultiPointField(String fieldName) {
- super(fieldName);
- count = 0;
- values = new long[initialArrayLength];
- }
-
- @Override
- public void doSetNextReader(LeafReaderContext context) throws IOException {
- docValues = DocValues.getSortedNumeric(context.reader(), fieldName);
- }
-
- @Override
- public void collect(int doc) throws IOException {
- if (docValues.advanceExact(doc)) {
- count = docValues.docValueCount();
- resizeEmptyValues(count);
- for (int i = 0; i < count; ++i) {
- values[i] = docValues.nextValue();
- }
- } else {
- count = 0;
- }
- }
-
- private void resizeEmptyValues(int count) {
- if (count > values.length) {
- values = new long[count];
- }
- }
-
- @Override
- public void streamLongs(LongConsumer cons) {
- for (int i = 0; i < count; ++i) {
- cons.accept(values[i]);
- }
- }
-
- @Override
- public void streamDoubles(DoubleConsumer cons) {
- streamLongs(value -> cons.accept((double) value));
- }
-
- @Override
- public void streamStrings(Consumer<String> cons) {
- streamLongs(value -> cons.accept(Long.toString(value)));
- }
-
- @Override
- public void streamObjects(Consumer<Object> cons) {
- streamLongs(value -> cons.accept(value));
- }
-}
diff --git a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/LongMultiTrieField.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/LongMultiTrieField.java
deleted file mode 100644
index 1402e11f3af..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/LongMultiTrieField.java
+++ /dev/null
@@ -1,95 +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.field;
-
-import java.io.IOException;
-import java.util.function.Consumer;
-import java.util.function.DoubleConsumer;
-import java.util.function.LongConsumer;
-import org.apache.lucene.index.DocValues;
-import org.apache.lucene.index.LeafReaderContext;
-import org.apache.lucene.index.SortedSetDocValues;
-import org.apache.solr.analytics.value.LongValueStream.CastingLongValueStream;
-import org.apache.solr.legacy.LegacyNumericUtils;
-import org.apache.solr.schema.TrieLongField;
-
-/**
- * An analytics wrapper for a multi-valued {@link TrieLongField} with DocValues enabled.
- *
- * @deprecated Trie fields are deprecated as of Solr 7.0
- */
-@Deprecated
-public class LongMultiTrieField extends AnalyticsField implements CastingLongValueStream {
- private SortedSetDocValues docValues;
- private int count;
- private long[] values;
-
- public LongMultiTrieField(String fieldName) {
- super(fieldName);
- count = 0;
- values = new long[initialArrayLength];
- }
-
- @Override
- public void doSetNextReader(LeafReaderContext context) throws IOException {
- docValues = DocValues.getSortedSet(context.reader(), fieldName);
- }
-
- @Override
- public void collect(int doc) throws IOException {
- count = 0;
- if (docValues.advanceExact(doc)) {
- int term;
- while ((term = (int) docValues.nextOrd()) != SortedSetDocValues.NO_MORE_ORDS) {
- if (count == values.length) {
- resizeValues();
- }
- values[count++] = LegacyNumericUtils.prefixCodedToLong(docValues.lookupOrd(term));
- }
- }
- }
-
- private void resizeValues() {
- long[] newValues = new long[values.length * 2];
- for (int i = 0; i < count; ++i) {
- newValues[i] = values[i];
- }
- values = newValues;
- }
-
- @Override
- public void streamLongs(LongConsumer cons) {
- for (int i = 0; i < count; ++i) {
- cons.accept(values[i]);
- }
- }
-
- @Override
- public void streamDoubles(DoubleConsumer cons) {
- streamLongs(value -> cons.accept((double) value));
- }
-
- @Override
- public void streamStrings(Consumer<String> cons) {
- streamLongs(value -> cons.accept(Long.toString(value)));
- }
-
- @Override
- public void streamObjects(Consumer<Object> cons) {
- streamLongs(value -> cons.accept(value));
- }
-}
diff --git a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/StringField.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/StringField.java
deleted file mode 100644
index 71fc7020a4b..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/StringField.java
+++ /dev/null
@@ -1,115 +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.field;
-
-import java.io.IOException;
-import java.util.function.Consumer;
-import org.apache.lucene.index.BinaryDocValues;
-import org.apache.lucene.index.DocValues;
-import org.apache.lucene.index.FieldInfo;
-import org.apache.lucene.index.LeafReaderContext;
-import org.apache.lucene.index.SortedDocValues;
-import org.apache.solr.analytics.facet.compare.ExpressionComparator;
-import org.apache.solr.analytics.value.StringValue.CastingStringValue;
-import org.apache.solr.common.SolrException;
-import org.apache.solr.schema.StrField;
-
-/** An analytics wrapper for a single-valued {@link StrField} with DocValues enabled. */
-public class StringField extends AnalyticsField implements CastingStringValue {
- private BinaryDocValues binaryDocValues;
- private SortedDocValues sortedDocValues;
- String value;
- boolean exists;
-
- public StringField(String fieldName) {
- super(fieldName);
- exists = false;
- }
-
- @Override
- public void doSetNextReader(LeafReaderContext context) throws IOException {
- FieldInfo fieldInfo = context.reader().getFieldInfos().fieldInfo(fieldName);
- if (fieldInfo == null) {
- binaryDocValues = DocValues.emptyBinary();
- sortedDocValues = null;
- } else {
- switch (fieldInfo.getDocValuesType()) {
- case BINARY:
- binaryDocValues = DocValues.getBinary(context.reader(), fieldName);
- sortedDocValues = null;
- break;
- case SORTED:
- binaryDocValues = null;
- sortedDocValues = DocValues.getSorted(context.reader(), fieldName);
- break;
- default:
- throw new SolrException(
- SolrException.ErrorCode.SERVER_ERROR,
- "Invalid doc values type " + fieldInfo.getDocValuesType());
- }
- }
- }
-
- @Override
- public void collect(int doc) throws IOException {
- if (binaryDocValues == null) {
- exists = sortedDocValues.advanceExact(doc);
- if (exists) {
- value = sortedDocValues.lookupOrd(sortedDocValues.ordValue()).utf8ToString();
- }
- } else {
- exists = binaryDocValues.advanceExact(doc);
- if (exists) {
- value = binaryDocValues.binaryValue().utf8ToString();
- }
- }
- }
-
- @Override
- public String getString() {
- return exists ? value : null;
- }
-
- @Override
- public Object getObject() {
- return exists ? value : null;
- }
-
- @Override
- public boolean exists() {
- return exists;
- }
-
- @Override
- public void streamStrings(Consumer<String> cons) {
- if (exists) {
- cons.accept(value);
- }
- }
-
- @Override
- public void streamObjects(Consumer<Object> cons) {
- if (exists) {
- cons.accept(value);
- }
- }
-
- @Override
- public ExpressionComparator<String> getObjectComparator(String expression) {
- return new ExpressionComparator<>(expression);
- }
-}
diff --git a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/StringMultiField.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/StringMultiField.java
deleted file mode 100644
index 8d609340b2c..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/StringMultiField.java
+++ /dev/null
@@ -1,63 +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.field;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.function.Consumer;
-import org.apache.lucene.index.DocValues;
-import org.apache.lucene.index.LeafReaderContext;
-import org.apache.lucene.index.SortedSetDocValues;
-import org.apache.solr.analytics.value.StringValueStream.CastingStringValueStream;
-import org.apache.solr.schema.StrField;
-
-/** An analytics wrapper for a multi-valued {@link StrField} with DocValues enabled. */
-public class StringMultiField extends AnalyticsField implements CastingStringValueStream {
- private SortedSetDocValues docValues;
- private ArrayList<String> values;
-
- public StringMultiField(String fieldName) {
- super(fieldName);
- values = new ArrayList<>(initialArrayLength);
- }
-
- @Override
- public void doSetNextReader(LeafReaderContext context) throws IOException {
- docValues = DocValues.getSortedSet(context.reader(), fieldName);
- }
-
- @Override
- public void collect(int doc) throws IOException {
- values.clear();
- if (docValues.advanceExact(doc)) {
- int term;
- while ((term = (int) docValues.nextOrd()) != SortedSetDocValues.NO_MORE_ORDS) {
- values.add(docValues.lookupOrd(term).utf8ToString());
- }
- }
- }
-
- @Override
- public void streamStrings(Consumer<String> cons) {
- values.forEach(value -> cons.accept(value));
- }
-
- @Override
- public void streamObjects(Consumer<Object> cons) {
- values.forEach(value -> cons.accept(value));
- }
-}
diff --git a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/package-info.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/package-info.java
deleted file mode 100644
index 9a80bafa33d..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/field/package-info.java
+++ /dev/null
@@ -1,19 +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.
- */
-
-/** Fields to use for analytics expressions. */
-package org.apache.solr.analytics.function.field;
diff --git a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/mapping/AbsoluteValueFunction.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/function/mapping/AbsoluteValueFunction.java
deleted file mode 100644
index bbeb3bf4603..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/mapping/AbsoluteValueFunction.java
+++ /dev/null
@@ -1,68 +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.value.AnalyticsValueStream;
-import org.apache.solr.analytics.value.DoubleValueStream;
-import org.apache.solr.analytics.value.FloatValueStream;
-import org.apache.solr.analytics.value.IntValueStream;
-import org.apache.solr.analytics.value.LongValueStream;
-import org.apache.solr.common.SolrException;
-import org.apache.solr.common.SolrException.ErrorCode;
-
-/**
- * An absolute value mapping function.
- *
- * <p>Takes a numeric ValueStream or Value and returns a ValueStream or Value of the same numeric
- * type.
- */
-public class AbsoluteValueFunction {
- public static final String name = "abs";
- public static final CreatorFunction creatorFunction =
- (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 IntValueStream) {
- return LambdaFunction.createIntLambdaFunction(
- name, x -> (x < 0) ? x * -1 : x, (IntValueStream) param);
- }
- if (param instanceof LongValueStream) {
- return LambdaFunction.createLongLambdaFunction(
- name, x -> (x < 0) ? x * -1 : x, (LongValueStream) param);
- }
- if (param instanceof FloatValueStream) {
- return LambdaFunction.createFloatLambdaFunction(
- name, x -> (x < 0) ? x * -1 : x, (FloatValueStream) param);
- }
- if (param instanceof DoubleValueStream) {
- return LambdaFunction.createDoubleLambdaFunction(
- name, x -> (x < 0) ? x * -1 : x, (DoubleValueStream) param);
- }
- throw new SolrException(
- ErrorCode.BAD_REQUEST,
- "The "
- + name
- + " function requires a numeric parameter, "
- + param.getExpressionStr()
- + " found.");
- });
-}
diff --git a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/mapping/AddFunction.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/function/mapping/AddFunction.java
deleted file mode 100644
index 70802ca62a8..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/mapping/AddFunction.java
+++ /dev/null
@@ -1,84 +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.value.AnalyticsValueStream;
-import org.apache.solr.analytics.value.DoubleValue;
-import org.apache.solr.analytics.value.DoubleValueStream;
-import org.apache.solr.common.SolrException;
-import org.apache.solr.common.SolrException.ErrorCode;
-
-/**
- * An addition mapping function.
- *
- * <p>Uses:
- *
- * <ul>
- * <li>If a single numeric ValueStream is passed in, a {@link DoubleValue} representing the sum of
- * the values for each document is returned.
- * <li>If a numeric ValueStream and a numeric Value are passed in, a {@link DoubleValueStream}
- * representing the sum 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 multiple numeric Values are passed in, a {@link DoubleValue} representing the sum of all
- * values is returned.
- * </ul>
- */
-public class AddFunction {
- public static final String name = "add";
- 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) {
- if (params[0] instanceof DoubleValueStream) {
- return LambdaFunction.createDoubleLambdaFunction(
- name, (a, b) -> a + b, (DoubleValueStream) params[0]);
- }
- throw new SolrException(
- ErrorCode.BAD_REQUEST,
- "The "
- + name
- + " function requires numeric parameters. Incorrect param: "
- + params[0].getExpressionStr());
- } else if (params.length == 2) {
- AnalyticsValueStream param1 = params[0];
- AnalyticsValueStream param2 = params[1];
- if (param1 instanceof DoubleValueStream && param2 instanceof DoubleValueStream) {
- return LambdaFunction.createDoubleLambdaFunction(
- name, (a, b) -> a + b, (DoubleValueStream) param1, (DoubleValueStream) param2);
- }
- throw new SolrException(
- ErrorCode.BAD_REQUEST, "The " + name + " function requires numeric parameters.");
- }
- DoubleValue[] castedParams = new DoubleValue[params.length];
- for (int i = 0; i < params.length; i++) {
- if (params[i] instanceof DoubleValue) {
- castedParams[i] = (DoubleValue) params[i];
- } else {
- throw new SolrException(
- ErrorCode.BAD_REQUEST,
- "The "
- + name
- + " function requires that all parameters be single-valued if more than 2 are given.");
- }
- }
- return LambdaFunction.createDoubleLambdaFunction(name, (a, b) -> a + b, castedParams);
- });
-}
diff --git a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/mapping/BottomFunction.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/function/mapping/BottomFunction.java
deleted file mode 100644
index 6a38a0e8098..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/mapping/BottomFunction.java
+++ /dev/null
@@ -1,185 +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.value.AnalyticsValueStream;
-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.common.SolrException;
-import org.apache.solr.common.SolrException.ErrorCode;
-
-/**
- * A bottom mapping function, returning the lowest value found.
- *
- * <p>Uses:
- *
- * <ul>
- * <li>If a single comparable ValueStream is passed in, a Value (of the same type) representing
- * the minimum of the values for each document is returned.
- * <li>If multiple comparable Values are passed in, a Value (of the same type) representing the
- * minimum of all values is returned.
- * </ul>
- */
-public class BottomFunction {
- public static final String name = "bottom";
- public static final CreatorFunction creatorFunction =
- (params -> {
- if (params.length == 0) {
- throw new SolrException(
- ErrorCode.BAD_REQUEST, "The " + name + " function requires paramaters.");
- }
- AnalyticsValueStream param = params[0];
- if (param instanceof DateValueStream) {
- if (params.length == 1) {
- return LambdaFunction.createDateLambdaFunction(
- name, (a, b) -> (a < b) ? a : b, (DateValueStream) param);
- }
- DateValue[] castedParams = new DateValue[params.length];
- boolean tryNextType = false;
- for (int i = 0; i < params.length; i++) {
- if (params[i] instanceof DateValue) {
- castedParams[i] = (DateValue) params[i];
- } else {
- tryNextType = true;
- break;
- }
- }
- if (!tryNextType) {
- return LambdaFunction.createDateLambdaFunction(
- name, (a, b) -> (a < b) ? a : b, castedParams, false);
- }
- }
- if (param instanceof IntValueStream) {
- if (params.length == 1) {
- return LambdaFunction.createIntLambdaFunction(
- name, (a, b) -> (a < b) ? a : b, (IntValueStream) param);
- }
- IntValue[] castedParams = new IntValue[params.length];
- boolean tryNextType = false;
- for (int i = 0; i < params.length; i++) {
- if (params[i] instanceof IntValue) {
- castedParams[i] = (IntValue) params[i];
- } else {
- tryNextType = true;
- break;
- }
- }
- if (!tryNextType) {
- return LambdaFunction.createIntLambdaFunction(
- name, (a, b) -> (a < b) ? a : b, castedParams, false);
- }
- }
- if (param instanceof LongValueStream) {
- if (params.length == 1) {
- return LambdaFunction.createLongLambdaFunction(
- name, (a, b) -> (a < b) ? a : b, (LongValueStream) param);
- }
- LongValue[] castedParams = new LongValue[params.length];
- boolean tryNextType = false;
- for (int i = 0; i < params.length; i++) {
- if (params[i] instanceof LongValue) {
- castedParams[i] = (LongValue) params[i];
- } else {
- tryNextType = true;
- break;
- }
- }
- if (!tryNextType) {
- return LambdaFunction.createLongLambdaFunction(
- name, (a, b) -> (a < b) ? a : b, castedParams, false);
- }
- }
- if (param instanceof FloatValueStream) {
- if (params.length == 1) {
- return LambdaFunction.createFloatLambdaFunction(
- name, (a, b) -> (a < b) ? a : b, (FloatValueStream) param);
- }
- FloatValue[] castedParams = new FloatValue[params.length];
- boolean tryNextType = false;
- for (int i = 0; i < params.length; i++) {
- if (params[i] instanceof FloatValue) {
- castedParams[i] = (FloatValue) params[i];
- } else {
- tryNextType = true;
- break;
- }
- }
- if (!tryNextType) {
- return LambdaFunction.createFloatLambdaFunction(
- name, (a, b) -> (a < b) ? a : b, castedParams, false);
- }
- }
- if (param instanceof DoubleValueStream) {
- if (params.length == 1) {
- return LambdaFunction.createDoubleLambdaFunction(
- name, (a, b) -> (a < b) ? a : b, (DoubleValueStream) param);
- }
- DoubleValue[] castedParams = new DoubleValue[params.length];
- boolean tryNextType = false;
- for (int i = 0; i < params.length; i++) {
- if (params[i] instanceof DoubleValue) {
- castedParams[i] = (DoubleValue) params[i];
- } else {
- tryNextType = true;
- break;
- }
- }
- if (!tryNextType) {
- return LambdaFunction.createDoubleLambdaFunction(
- name, (a, b) -> (a < b) ? a : b, castedParams, false);
- }
- }
- if (param instanceof StringValueStream) {
- if (params.length == 1) {
- return LambdaFunction.createStringLambdaFunction(
- name, (a, b) -> (a.compareTo(b) < 0) ? a : b, (StringValueStream) param);
- }
- StringValue[] castedParams = new StringValue[params.length];
- boolean tryNextType = false;
- for (int i = 0; i < params.length; i++) {
- if (params[i] instanceof StringValue) {
- castedParams[i] = (StringValue) params[i];
- } else {
- tryNextType = true;
- break;
- }
- }
- if (!tryNextType) {
- 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. "
- + "Incorrect parameter: "
- + params[0].getExpressionStr());
- });
-}
diff --git a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/mapping/ComparisonFunction.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/function/mapping/ComparisonFunction.java
deleted file mode 100644
index 4f445f7db42..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/mapping/ComparisonFunction.java
+++ /dev/null
@@ -1,368 +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.BooleanValue.AbstractBooleanValue;
-import org.apache.solr.analytics.value.BooleanValueStream;
-import org.apache.solr.analytics.value.BooleanValueStream.AbstractBooleanValueStream;
-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.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. */
- static 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}. */
- static 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. */
- static 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}. */
- static 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;
- }
- }
-}
diff --git a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/mapping/ConcatFunction.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/function/mapping/ConcatFunction.java
deleted file mode 100644
index a2f396a3e28..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/mapping/ConcatFunction.java
+++ /dev/null
@@ -1,142 +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 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;
-import org.apache.solr.common.SolrException;
-import org.apache.solr.common.SolrException.ErrorCode;
-
-/**
- * A concatenation mapping function, combining the string values of the given parameters. (At least
- * 1 parameter is required)
- *
- * <p>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 -> {
- 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>
- * 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 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 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 = ((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);
- }
-}
diff --git a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/mapping/DateMathFunction.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/function/mapping/DateMathFunction.java
deleted file mode 100644
index 867d6df4872..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/mapping/DateMathFunction.java
+++ /dev/null
@@ -1,177 +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 java.util.Date;
-import java.util.function.Consumer;
-import java.util.function.LongConsumer;
-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.DateValue.AbstractDateValue;
-import org.apache.solr.analytics.value.DateValueStream;
-import org.apache.solr.analytics.value.DateValueStream.AbstractDateValueStream;
-import org.apache.solr.analytics.value.StringValue;
-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;
-
-/**
- * A mapping function that computes date math.
- *
- * <p>The first parameter is the {@link DateValue} or {@link DateValueStream} to compute date math
- * on. (Required) <br>
- * The trailing parameters must be constant date math strings (e.g. "+1DAY"). (At least 1 required)
- */
-public class DateMathFunction {
- public static final String name = "date_math";
- public static final CreatorFunction creatorFunction =
- (params -> {
- if (params.length < 2) {
- throw new SolrException(
- ErrorCode.BAD_REQUEST,
- "The "
- + name
- + " function requires at least 2 paramaters, "
- + params.length
- + " found.");
- }
- StringBuilder mathParam = new StringBuilder();
- for (int i = 1; i < params.length; ++i) {
- 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.");
- }
- }
- if (params[0] instanceof DateValue) {
- return new DateMathValueFunction(
- (DateValue) params[0], new ConstantStringValue(mathParam.toString()));
- } else if (params[0] instanceof DateValueStream) {
- return new DateMathStreamFunction(
- (DateValueStream) params[0], new ConstantStringValue(mathParam.toString()));
- } else {
- throw new SolrException(
- ErrorCode.BAD_REQUEST,
- "The " + name + " function requires a date as the first parameter.");
- }
- });
-
- /** DateMath function that supports {@link DateValue}s. */
- static class DateMathValueFunction extends AbstractDateValue {
- private final DateValue dateParam;
- private final String mathParam;
- DateMathParser parser = new DateMathParser();
- public static final String name = DateMathFunction.name;
- private final String exprStr;
- private final ExpressionType funcType;
-
- public DateMathValueFunction(DateValue dateParam, ConstantStringValue mathParam)
- throws SolrException {
- this.dateParam = dateParam;
- this.mathParam = "NOW" + mathParam.getString();
- this.exprStr = AnalyticsValueStream.createExpressionString(name, dateParam, mathParam);
- this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr, dateParam);
- }
-
- private boolean exists = false;
-
- @Override
- public long getLong() {
- Date date = getDate();
- return (exists) ? date.getTime() : 0;
- }
-
- @Override
- public Date getDate() {
- Date date = dateParam.getDate();
- if (dateParam.exists()) {
- exists = true;
- return DateMathParser.parseMath(date, mathParam);
- } else {
- exists = false;
- return null;
- }
- }
-
- @Override
- public boolean exists() {
- return exists;
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public String getExpressionStr() {
- return exprStr;
- }
-
- @Override
- public ExpressionType getExpressionType() {
- return funcType;
- }
- }
-
- /** DateMath function that supports {@link DateValueStream}s. */
- static class DateMathStreamFunction extends AbstractDateValueStream {
- private final DateValueStream dateParam;
- private final String mathParam;
- public static final String name = DateMathFunction.name;
- private final String exprStr;
- private final ExpressionType funcType;
-
- public DateMathStreamFunction(DateValueStream dateParam, ConstantStringValue mathParam)
- throws SolrException {
- this.dateParam = dateParam;
- this.mathParam = "NOW" + mathParam.getString();
- this.exprStr = AnalyticsValueStream.createExpressionString(name, dateParam, mathParam);
- this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr, dateParam);
- }
-
- @Override
- public void streamLongs(LongConsumer cons) {
- streamDates(value -> cons.accept(value.getTime()));
- }
-
- @Override
- public void streamDates(Consumer<Date> cons) {
- dateParam.streamDates(value -> cons.accept(DateMathParser.parseMath(value, mathParam)));
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public String getExpressionStr() {
- return exprStr;
- }
-
- @Override
- public ExpressionType getExpressionType() {
- return funcType;
- }
- }
-}
diff --git a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/mapping/DateParseFunction.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/function/mapping/DateParseFunction.java
deleted file mode 100644
index c97a3f4e6e5..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/mapping/DateParseFunction.java
+++ /dev/null
@@ -1,228 +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 java.time.Instant;
-import java.time.format.DateTimeParseException;
-import java.util.function.LongConsumer;
-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.DateValue.AbstractDateValue;
-import org.apache.solr.analytics.value.DateValueStream;
-import org.apache.solr.analytics.value.DateValueStream.AbstractDateValueStream;
-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.common.SolrException;
-import org.apache.solr.common.SolrException.ErrorCode;
-
-/**
- * A mapping function that converts long or string representations of dates to actual date objects.
- *
- * <p>The only parameter is the {@link LongValue}, {@link LongValueStream}, {@link DateValue}, or
- * {@link DateValueStream} to convert. (Required)
- */
-public class DateParseFunction {
- public static final String name = "date";
- 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.");
- }
- if (params[0] instanceof LongValue) {
- return new LongToDateParseFunction((LongValue) params[0]);
- } else if (params[0] instanceof LongValueStream) {
- return new LongStreamToDateParseFunction((LongValueStream) params[0]);
- } else if (params[0] instanceof StringValue) {
- return new StringToDateParseFunction((StringValue) params[0]);
- } else if (params[0] instanceof StringValueStream) {
- return new StringStreamToDateParseFunction((StringValueStream) params[0]);
- } else {
- throw new SolrException(
- ErrorCode.BAD_REQUEST,
- "The "
- + name
- + " function requires a string or long parameter. "
- + "Incorrect parameter: "
- + params[0].getExpressionStr());
- }
- });
-
- static class LongToDateParseFunction extends AbstractDateValue {
- private final LongValue param;
- public static final String name = DateParseFunction.name;
- private final String exprStr;
- private final ExpressionType funcType;
-
- public LongToDateParseFunction(LongValue param) throws SolrException {
- this.param = param;
- this.exprStr = AnalyticsValueStream.createExpressionString(name, param);
- this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr, param);
- }
-
- @Override
- public long getLong() {
- return param.getLong();
- }
-
- @Override
- public boolean exists() {
- return param.exists();
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public String getExpressionStr() {
- return exprStr;
- }
-
- @Override
- public ExpressionType getExpressionType() {
- return funcType;
- }
- }
-
- static class LongStreamToDateParseFunction extends AbstractDateValueStream {
- private final LongValueStream param;
- public static final String name = DateParseFunction.name;
- private final String exprStr;
- private final ExpressionType funcType;
-
- public LongStreamToDateParseFunction(LongValueStream param) throws SolrException {
- this.param = param;
- this.exprStr = AnalyticsValueStream.createExpressionString(name, param);
- this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr, param);
- }
-
- @Override
- public void streamLongs(LongConsumer cons) {
- param.streamLongs(cons);
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public String getExpressionStr() {
- return exprStr;
- }
-
- @Override
- public ExpressionType getExpressionType() {
- return funcType;
- }
- }
-
- static class StringToDateParseFunction extends AbstractDateValue {
- private final StringValue param;
- public static final String name = DateParseFunction.name;
- private final String exprStr;
- private final ExpressionType funcType;
-
- public StringToDateParseFunction(StringValue param) throws SolrException {
- this.param = param;
- this.exprStr = AnalyticsValueStream.createExpressionString(name, param);
- this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr, param);
- }
-
- private boolean exists = false;
-
- @Override
- public long getLong() {
- long value = 0;
- try {
- String paramStr = param.getString();
- exists = param.exists();
- if (exists) {
- value = Instant.parse(paramStr).toEpochMilli();
- }
- } catch (DateTimeParseException e) {
- exists = false;
- }
- return value;
- }
-
- @Override
- public boolean exists() {
- return exists;
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public String getExpressionStr() {
- return exprStr;
- }
-
- @Override
- public ExpressionType getExpressionType() {
- return funcType;
- }
- }
-
- static class StringStreamToDateParseFunction extends AbstractDateValueStream {
- private final StringValueStream param;
- public static final String name = DateParseFunction.name;
- private final String exprStr;
- private final ExpressionType funcType;
-
- public StringStreamToDateParseFunction(StringValueStream param) throws SolrException {
- this.param = param;
- this.exprStr = AnalyticsValueStream.createExpressionString(name, param);
- this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr, param);
- }
-
- @Override
- public void streamLongs(LongConsumer cons) {
- param.streamStrings(
- value -> {
- try {
- cons.accept(Instant.parse(value).toEpochMilli());
- } catch (DateTimeParseException e) {
- }
- });
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public String getExpressionStr() {
- return exprStr;
- }
-
- @Override
- public ExpressionType getExpressionType() {
- return funcType;
- }
- }
-}
diff --git a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/mapping/DecimalNumericConversionFunction.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/function/mapping/DecimalNumericConversionFunction.java
deleted file mode 100644
index 86cc27218ea..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/mapping/DecimalNumericConversionFunction.java
+++ /dev/null
@@ -1,285 +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 java.util.function.IntConsumer;
-import java.util.function.LongConsumer;
-import org.apache.solr.analytics.ExpressionFactory.CreatorFunction;
-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.IntValue.AbstractIntValue;
-import org.apache.solr.analytics.value.IntValueStream;
-import org.apache.solr.analytics.value.IntValueStream.AbstractIntValueStream;
-import org.apache.solr.analytics.value.LongValue;
-import org.apache.solr.analytics.value.LongValue.AbstractLongValue;
-import org.apache.solr.analytics.value.LongValueStream;
-import org.apache.solr.analytics.value.LongValueStream.AbstractLongValueStream;
-import org.apache.solr.common.SolrException;
-import org.apache.solr.common.SolrException.ErrorCode;
-
-/**
- * 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, respectively.
- */
-public class DecimalNumericConversionFunction {
-
- /**
- * 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);
- }
- return new ConvertFloatStreamFunction(name, (FloatValueStream) param, fconv);
- } else if (param instanceof DoubleValueStream) {
- if (param instanceof DoubleValue) {
- return new ConvertDoubleValueFunction(name, (DoubleValue) param, dconv);
- }
- return new ConvertDoubleStreamFunction(name, (DoubleValueStream) param, dconv);
- } else {
- throw new SolrException(
- ErrorCode.BAD_REQUEST, "The " + name + " function requires a numeric parameter.");
- }
- }
-
- /** A numeric mapping function that returns the floor of the input. */
- public static class FloorFunction {
- public static final String name = "floor";
- public static final CreatorFunction creatorFunction =
- (params -> {
- return DecimalNumericConversionFunction.createDecimalConversionFunction(
- name, val -> (int) Math.floor(val), val -> (long) Math.floor(val), params);
- });
- }
-
- /** A numeric mapping function that returns the ceiling of the input. */
- public static class CeilingFunction {
- public static final String name = "ceil";
- public static final CreatorFunction creatorFunction =
- (params -> {
- return DecimalNumericConversionFunction.createDecimalConversionFunction(
- name, val -> (int) Math.ceil(val), val -> (long) Math.ceil(val), params);
- });
- }
-
- /** A numeric mapping function that returns the rounded input. */
- public static class RoundFunction {
- public static final String name = "round";
- public static final CreatorFunction creatorFunction =
- (params -> {
- return DecimalNumericConversionFunction.createDecimalConversionFunction(
- name, val -> Math.round(val), val -> Math.round(val), params);
- });
- }
-
- @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}. */
- static class ConvertFloatValueFunction extends AbstractIntValue {
- private final String name;
- private final FloatValue param;
- private final ConvertFloatFunction conv;
- private final String funcStr;
- private final ExpressionType funcType;
-
- public ConvertFloatValueFunction(String name, FloatValue param, ConvertFloatFunction conv) {
- this.name = name;
- this.param = param;
- this.conv = conv;
- this.funcStr = AnalyticsValueStream.createExpressionString(name, param);
- this.funcType = AnalyticsValueStream.determineMappingPhase(funcStr, param);
- }
-
- @Override
- public int getInt() {
- return conv.convert(param.getFloat());
- }
-
- @Override
- public boolean exists() {
- return param.exists();
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public String getExpressionStr() {
- return funcStr;
- }
-
- @Override
- public ExpressionType getExpressionType() {
- return funcType;
- }
- }
-
- /** A function to convert a {@link FloatValueStream} to a {@link IntValueStream}. */
- static class ConvertFloatStreamFunction extends AbstractIntValueStream {
- private final String name;
- private final FloatValueStream param;
- private final ConvertFloatFunction conv;
- private final String funcStr;
- private final ExpressionType funcType;
-
- public ConvertFloatStreamFunction(
- String name, FloatValueStream param, ConvertFloatFunction conv) {
- this.name = name;
- this.param = param;
- this.conv = conv;
- this.funcStr = AnalyticsValueStream.createExpressionString(name, param);
- this.funcType = AnalyticsValueStream.determineMappingPhase(funcStr, param);
- }
-
- @Override
- public void streamInts(IntConsumer cons) {
- param.streamFloats(value -> cons.accept(conv.convert(value)));
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public String getExpressionStr() {
- return funcStr;
- }
-
- @Override
- public ExpressionType getExpressionType() {
- return funcType;
- }
- }
-
- /** A function to convert a {@link DoubleValue} to a {@link LongValue}. */
- static class ConvertDoubleValueFunction extends AbstractLongValue {
- private final String name;
- private final DoubleValue param;
- private final ConvertDoubleFunction conv;
- private final String funcStr;
- private final ExpressionType funcType;
-
- public ConvertDoubleValueFunction(String name, DoubleValue param, ConvertDoubleFunction conv) {
- this.name = name;
- this.param = param;
- this.conv = conv;
- this.funcStr = AnalyticsValueStream.createExpressionString(name, param);
- this.funcType = AnalyticsValueStream.determineMappingPhase(funcStr, param);
- }
-
- @Override
- public long getLong() {
- return conv.convert(param.getDouble());
- }
-
- @Override
- public boolean exists() {
- return param.exists();
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public String getExpressionStr() {
- return funcStr;
- }
-
- @Override
- public ExpressionType getExpressionType() {
- return funcType;
- }
- }
-
- /** A function to convert a {@link DoubleValueStream} to a {@link LongValueStream}. */
- static class ConvertDoubleStreamFunction extends AbstractLongValueStream {
- private final String name;
- private final DoubleValueStream param;
- private final ConvertDoubleFunction conv;
- private final String funcStr;
- private final ExpressionType funcType;
-
- public ConvertDoubleStreamFunction(
- String name, DoubleValueStream param, ConvertDoubleFunction conv) {
- this.name = name;
- this.param = param;
- this.conv = conv;
- this.funcStr = AnalyticsValueStream.createExpressionString(name, param);
- this.funcType = AnalyticsValueStream.determineMappingPhase(funcStr, param);
- }
-
- @Override
- public void streamLongs(LongConsumer cons) {
- param.streamDoubles(value -> cons.accept(conv.convert(value)));
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public String getExpressionStr() {
- return funcStr;
- }
-
- @Override
- public ExpressionType getExpressionType() {
- return funcType;
- }
- }
-}
diff --git a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/mapping/DivideFunction.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/function/mapping/DivideFunction.java
deleted file mode 100644
index 99d665738d9..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/mapping/DivideFunction.java
+++ /dev/null
@@ -1,60 +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.value.AnalyticsValueStream;
-import org.apache.solr.analytics.value.DoubleValue;
-import org.apache.solr.analytics.value.DoubleValueStream;
-import org.apache.solr.common.SolrException;
-import org.apache.solr.common.SolrException.ErrorCode;
-
-/**
- * A division mapping function. No checking on divisor value is done. An error will occur if a zero
- * divisor is used.
- *
- * <p>Uses:
- *
- * <ul>
- * <li>If two numeric Values are passed in, a {@link DoubleValue} representing the divison of the
- * two values is returned.
- * <li>If a numeric ValueStream and a numeric Value are passed in, a {@link DoubleValueStream}
- * representing the division 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)
- * </ul>
- */
-public class DivideFunction {
- public static final String name = "div";
- 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 param1 = params[0];
- AnalyticsValueStream param2 = params[1];
- if (param1 instanceof DoubleValueStream && param2 instanceof DoubleValueStream) {
- return LambdaFunction.createDoubleLambdaFunction(
- name, (a, b) -> a / b, (DoubleValueStream) param1, (DoubleValueStream) param2);
- } else {
- throw new SolrException(
- ErrorCode.BAD_REQUEST, "The " + name + " function requires numeric parameters.");
- }
- });
-}
diff --git a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/mapping/EqualFunction.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/function/mapping/EqualFunction.java
deleted file mode 100644
index ccd5a61f116..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/mapping/EqualFunction.java
+++ /dev/null
@@ -1,264 +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.BooleanValue.AbstractBooleanValue;
-import org.apache.solr.analytics.value.BooleanValueStream;
-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. */
- static 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}. */
- static 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. */
- static 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}.
- */
- static 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/modules/analytics/src/java/org/apache/solr/analytics/function/mapping/ExistsFunction.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/function/mapping/ExistsFunction.java
deleted file mode 100644
index 1cd19e55c81..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/mapping/ExistsFunction.java
+++ /dev/null
@@ -1,130 +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.value.AnalyticsValue;
-import org.apache.solr.analytics.value.AnalyticsValueStream;
-import org.apache.solr.analytics.value.BooleanValue;
-import org.apache.solr.analytics.value.BooleanValue.AbstractBooleanValue;
-import org.apache.solr.common.SolrException;
-import org.apache.solr.common.SolrException.ErrorCode;
-
-/**
- * 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. */
- static 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. */
- static 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/modules/analytics/src/java/org/apache/solr/analytics/function/mapping/FillMissingFunction.java b/solr/modules/analytics/src/java/org/apache/solr/analytics/function/mapping/FillMissingFunction.java
deleted file mode 100644
index bb356ce0ef4..00000000000
--- a/solr/modules/analytics/src/java/org/apache/solr/analytics/function/mapping/FillMissingFunction.java
+++ /dev/null
@@ -1,938 +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 java.util.function.Consumer;
-import java.util.function.DoubleConsumer;
-import java.util.function.IntConsumer;
-import java.util.function.LongConsumer;
-import org.apache.solr.analytics.ExpressionFactory.CreatorFunction;
-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.AnalyticsValue.AbstractAnalyticsValue;
-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.BooleanValue.AbstractBooleanValue;
-import org.apache.solr.analytics.value.BooleanValueStream;
-import org.apache.solr.analytics.value.BooleanValueStream.AbstractBooleanValueStream;
-import org.apache.solr.analytics.value.DateValue;
-import org.apache.solr.analytics.value.DateValue.AbstractDateValue;
-import org.apache.solr.analytics.value.DateValueStream;
-import org.apache.solr.analytics.value.DateValueStream.AbstractDateValueStream;
-import org.apache.solr.analytics.value.DoubleValue;
-import org.apache.solr.analytics.value.DoubleValue.AbstractDoubleValue;
-import org.apache.solr.analytics.value.DoubleValueStream;
-import org.apache.solr.analytics.value.DoubleValueStream.AbstractDoubleValueStream;
-import org.apache.solr.analytics.value.FloatValue;
-import org.apache.solr.analytics.value.FloatValue.AbstractFloatValue;
-import org.apache.solr.analytics.value.FloatValueStream;
-import org.apache.solr.analytics.value.FloatValueStream.AbstractFloatValueStream;
-import org.apache.solr.analytics.value.IntValue;
-import org.apache.solr.analytics.value.IntValue.AbstractIntValue;
-import org.apache.solr.analytics.value.IntValueStream;
-import org.apache.solr.analytics.value.IntValueStream.AbstractIntValueStream;
-import org.apache.solr.analytics.value.LongValue;
-import org.apache.solr.analytics.value.LongValue.AbstractLongValue;
-import org.apache.solr.analytics.value.LongValueStream;
-import org.apache.solr.analytics.value.LongValueStream.AbstractLongValueStream;
-import org.apache.solr.analytics.value.StringValue;
-import org.apache.solr.analytics.value.StringValue.AbstractStringValue;
-import org.apache.solr.analytics.value.StringValueStream;
-import org.apache.solr.analytics.value.StringValueStream.AbstractStringValueStream;
-import org.apache.solr.common.SolrException;
-import org.apache.solr.common.SolrException.ErrorCode;
-
-/**
- * A mapping function to fill all non-existing values with a given value.
- *
- * <p>Uses:
- *
- * <ul>
- * <li>If two Values are passed in, a Value mimicking the first parameter with the second
- * parameter used as filler will be returned.
- * <li>If two ValueStreams are passed in, a ValueStream mimicking the first parameter with the
- * second parameter used as filler will be returned.
- * </ul>
- *
- * <p>The resulting Value or ValueStream will be typed with the closest super-type of the two
- * parameters. (e.g. {@value #name}(double,int) will return a double)
- */
-public class FillMissingFunction {
- public static final String name = "fill_missing";
-
- 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 baseExpr = params[0];
- AnalyticsValueStream fillExpr = params[1];
- if (baseExpr instanceof DateValue && fillExpr instanceof DateValue) {
- return new DateFillMissingFunction((DateValue) baseExpr, (DateValue) fillExpr);
- }
- if (baseExpr instanceof DateValueStream && fillExpr instanceof DateValueStream) {
- return new DateStreamFillMissingFunction(
- (DateValueStream) baseExpr, (DateValueStream) fillExpr);
- }
- if (baseExpr instanceof BooleanValue && fillExpr instanceof BooleanValue) {
- return new BooleanFillMissingFunction((BooleanValue) baseExpr, (BooleanValue) fillExpr);
- }
- if (baseExpr instanceof BooleanValueStream && fillExpr instanceof BooleanValueStream) {
- return new BooleanStreamFillMissingFunction(
- (BooleanValueStream) baseExpr, (BooleanValueStream) fillExpr);
- }
- if (baseExpr instanceof IntValue && fillExpr instanceof IntValue) {
- return new IntFillMissingFunction((IntValue) baseExpr, (IntValue) fillExpr);
- }
- if (baseExpr instanceof IntValueStream && fillExpr instanceof IntValueStream) {
- return new IntStreamFillMissingFunction(
- (IntValueStream) baseExpr, (IntValueStream) fillExpr);
- }
- if (baseExpr instanceof LongValue && fillExpr instanceof LongValue) {
- return new LongFillMissingFunction((LongValue) baseExpr, (LongValue) fillExpr);
- }
- if (baseExpr instanceof LongValueStream && fillExpr instanceof LongValueStream) {
- return new LongStreamFillMissingFunction(
- (LongValueStream) baseExpr, (LongValueStream) fillExpr);
- }
- if (baseExpr instanceof FloatValue && fillExpr instanceof FloatValue) {
- return new FloatFillMissingFunction((FloatValue) baseExpr, (FloatValue) fillExpr);
- }
- if (baseExpr instanceof FloatValueStream && fillExpr instanceof FloatValueStream) {
- return new FloatStreamFillMissingFunction(
- (FloatValueStream) baseExpr, (FloatValueStream) fillExpr);
- }
- if (baseExpr instanceof DoubleValue && fillExpr instanceof DoubleValue) {
- return new DoubleFillMissingFunction((DoubleValue) baseExpr, (DoubleValue) fillExpr);
- }
- if (baseExpr instanceof DoubleValueStream && fillExpr instanceof DoubleValueStream) {
- return new DoubleStreamFillMissingFunction(
- (DoubleValueStream) baseExpr, (DoubleValueStream) fillExpr);
- }
- if (baseExpr instanceof StringValue && fillExpr instanceof StringValue) {
- return new StringFillMissingFunction((StringValue) baseExpr, (StringValue) fillExpr);
- }
- if (baseExpr instanceof StringValueStream && fillExpr instanceof StringValueStream) {
- return new StringStreamFillMissingFunction(
- (StringValueStream) baseExpr, (StringValueStream) fillExpr);
- }
- if (baseExpr instanceof AnalyticsValue && fillExpr instanceof AnalyticsValue) {
- return new ValueFillMissingFunction((AnalyticsValue) baseExpr, (AnalyticsValue) fillExpr);
- }
- return new StreamFillMissingFunction(baseExpr, fillExpr);
- });
-
- static class StreamFillMissingFunction extends AbstractAnalyticsValueStream
- implements Consumer<Object> {
- private final AnalyticsValueStream baseExpr;
- private final AnalyticsValueStream fillExpr;
- public static final String name = FillMissingFunction.name;
- private final String exprStr;
- private final ExpressionType funcType;
-
- public StreamFillMissingFunction(AnalyticsValueStream baseExpr, AnalyticsValueStream fillExpr)
- throws SolrException {
- this.baseExpr = baseExpr;
- this.fillExpr = fillExpr;
- this.exprStr = AnalyticsValueStream.createExpressionString(name, baseExpr, fillExpr);
- this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr, baseExpr, fillExpr);
- }
-
- boolean exists = false;
- Consumer<Object> cons;
-
- @Override
- public void streamObjects(Consumer<Object> cons) {
- exists = false;
- this.cons = cons;
- baseExpr.streamObjects(this);
- if (!exists) {
- fillExpr.streamObjects(cons);
- }
- }
-
- @Override
- public void accept(Object value) {
- exists = true;
- cons.accept(value);
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public String getExpressionStr() {
- return exprStr;
- }
-
- @Override
- public ExpressionType getExpressionType() {
- return funcType;
- }
- }
-
- static class ValueFillMissingFunction extends AbstractAnalyticsValue {
- private final AnalyticsValue baseExpr;
- private final AnalyticsValue fillExpr;
- public static final String name = FillMissingFunction.name;
- private final String exprStr;
- private final ExpressionType funcType;
-
- public ValueFillMissingFunction(AnalyticsValue baseExpr, AnalyticsValue fillExpr)
- throws SolrException {
- this.baseExpr = baseExpr;
- this.fillExpr = fillExpr;
- this.exprStr = AnalyticsValueStream.createExpressionString(name, baseExpr, fillExpr);
- this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr, baseExpr, fillExpr);
- }
-
- boolean exists = false;
-
- @Override
- public Object getObject() {
- Object value = baseExpr.getObject();
- exists = true;
- if (!baseExpr.exists()) {
- value = fillExpr.getObject();
- exists = fillExpr.exists();
- }
- return value;
- }
-
- @Override
- public boolean exists() {
- return exists;
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public String getExpressionStr() {
- return exprStr;
- }
-
- @Override
- public ExpressionType getExpressionType() {
- return funcType;
- }
- }
-
- static class BooleanStreamFillMissingFunction extends AbstractBooleanValueStream
- implements BooleanConsumer {
- private final BooleanValueStream baseExpr;
- private final BooleanValueStream fillExpr;
- public static final String name = FillMissingFunction.name;
- private final String exprStr;
- private final ExpressionType funcType;
-
- public BooleanStreamFillMissingFunction(
- BooleanValueStream baseExpr, BooleanValueStream fillExpr) throws SolrException {
- this.baseExpr = baseExpr;
- this.fillExpr = fillExpr;
- this.exprStr = AnalyticsValueStream.createExpressionString(name, baseExpr, fillExpr);
- this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr, baseExpr, fillExpr);
- }
-
- boolean exists = false;
- BooleanConsumer cons;
-
- @Override
- public void streamBooleans(BooleanConsumer cons) {
- exists = false;
- this.cons = cons;
- baseExpr.streamBooleans(this);
- if (!exists) {
- fillExpr.streamBooleans(cons);
- }
- }
-
- @Override
- public void accept(boolean value) {
- exists = true;
- cons.accept(value);
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public String getExpressionStr() {
- return exprStr;
- }
-
- @Override
- public ExpressionType getExpressionType() {
- return funcType;
- }
- }
-
- static class BooleanFillMissingFunction extends AbstractBooleanValue {
- private final BooleanValue baseExpr;
- private final BooleanValue fillExpr;
- public static final String name = FillMissingFunction.name;
- private final String exprStr;
- private final ExpressionType funcType;
-
- public BooleanFillMissingFunction(BooleanValue baseExpr, BooleanValue fillExpr)
- throws SolrException {
- this.baseExpr = baseExpr;
- this.fillExpr = fillExpr;
- this.exprStr = AnalyticsValueStream.createExpressionString(name, baseExpr, fillExpr);
- this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr, baseExpr, fillExpr);
- }
-
- boolean exists = false;
-
- @Override
- public boolean getBoolean() {
- boolean value = baseExpr.getBoolean();
- exists = true;
- if (!baseExpr.exists()) {
- value = fillExpr.getBoolean();
- exists = fillExpr.exists();
- }
- return value;
- }
-
- @Override
- public boolean exists() {
- return exists;
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public String getExpressionStr() {
- return exprStr;
- }
-
- @Override
- public ExpressionType getExpressionType() {
- return funcType;
- }
- }
-
- static class IntStreamFillMissingFunction extends AbstractIntValueStream implements IntConsumer {
- private final IntValueStream baseExpr;
- private final IntValueStream fillExpr;
- public static final String name = FillMissingFunction.name;
- private final String exprStr;
- private final ExpressionType funcType;
-
- public IntStreamFillMissingFunction(IntValueStream baseExpr, IntValueStream fillExpr)
- throws SolrException {
- this.baseExpr = baseExpr;
- this.fillExpr = fillExpr;
- this.exprStr = AnalyticsValueStream.createExpressionString(name, baseExpr, fillExpr);
- this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr, baseExpr, fillExpr);
- }
-
- boolean exists = false;
- IntConsumer cons;
-
- @Override
- public void streamInts(IntConsumer cons) {
- exists = false;
- this.cons = cons;
- baseExpr.streamInts(this);
- if (!exists) {
- fillExpr.streamInts(cons);
- }
- }
-
- @Override
- public void accept(int value) {
- exists = true;
- cons.accept(value);
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public String getExpressionStr() {
- return exprStr;
- }
-
- @Override
- public ExpressionType getExpressionType() {
- return funcType;
- }
- }
-
- static class IntFillMissingFunction extends AbstractIntValue {
- private final IntValue baseExpr;
- private final IntValue fillExpr;
- public static final String name = FillMissingFunction.name;
- private final String exprStr;
- private final ExpressionType funcType;
-
- public IntFillMissingFunction(IntValue baseExpr, IntValue fillExpr) throws SolrException {
- this.baseExpr = baseExpr;
- this.fillExpr = fillExpr;
- this.exprStr = AnalyticsValueStream.createExpressionString(name, baseExpr, fillExpr);
- this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr, baseExpr, fillExpr);
- }
-
- boolean exists = false;
-
- @Override
- public int getInt() {
- int value = baseExpr.getInt();
- exists = true;
- if (!baseExpr.exists()) {
- value = fillExpr.getInt();
- exists = fillExpr.exists();
- }
- return value;
- }
-
- @Override
- public boolean exists() {
- return exists;
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public String getExpressionStr() {
- return exprStr;
- }
-
- @Override
- public ExpressionType getExpressionType() {
- return funcType;
- }
- }
-
- static class LongStreamFillMissingFunction extends AbstractLongValueStream
- implements LongConsumer {
- private final LongValueStream baseExpr;
- private final LongValueStream fillExpr;
- public static final String name = FillMissingFunction.name;
- private final String exprStr;
- private final ExpressionType funcType;
-
- public LongStreamFillMissingFunction(LongValueStream baseExpr, LongValueStream fillExpr)
- throws SolrException {
- this.baseExpr = baseExpr;
- this.fillExpr = fillExpr;
- this.exprStr = AnalyticsValueStream.createExpressionString(name, baseExpr, fillExpr);
- this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr, baseExpr, fillExpr);
- }
-
- boolean exists = false;
- LongConsumer cons;
-
- @Override
- public void streamLongs(LongConsumer cons) {
- exists = false;
- this.cons = cons;
- baseExpr.streamLongs(this);
- if (!exists) {
- fillExpr.streamLongs(cons);
- }
- }
-
- @Override
- public void accept(long value) {
- exists = true;
- cons.accept(value);
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public String getExpressionStr() {
- return exprStr;
- }
-
- @Override
- public ExpressionType getExpressionType() {
- return funcType;
- }
- }
-
- static class LongFillMissingFunction extends AbstractLongValue {
- private final LongValue baseExpr;
- private final LongValue fillExpr;
- public static final String name = FillMissingFunction.name;
- private final String exprStr;
- private final ExpressionType funcType;
-
- public LongFillMissingFunction(LongValue baseExpr, LongValue fillExpr) throws SolrException {
- this.baseExpr = baseExpr;
- this.fillExpr = fillExpr;
- this.exprStr = AnalyticsValueStream.createExpressionString(name, baseExpr, fillExpr);
- this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr, baseExpr, fillExpr);
- }
-
- boolean exists = false;
-
- @Override
- public long getLong() {
- long value = baseExpr.getLong();
- exists = true;
- if (!baseExpr.exists()) {
- value = fillExpr.getLong();
- exists = fillExpr.exists();
- }
- return value;
- }
-
- @Override
- public boolean exists() {
- return exists;
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public String getExpressionStr() {
- return exprStr;
- }
-
- @Override
- public ExpressionType getExpressionType() {
- return funcType;
- }
- }
-
- static class FloatStreamFillMissingFunction extends AbstractFloatValueStream
- implements FloatConsumer {
- private final FloatValueStream baseExpr;
- private final FloatValueStream fillExpr;
- public static final String name = FillMissingFunction.name;
- private final String exprStr;
- private final ExpressionType funcType;
-
- public FloatStreamFillMissingFunction(FloatValueStream baseExpr, FloatValueStream fillExpr)
- throws SolrException {
- this.baseExpr = baseExpr;
- this.fillExpr = fillExpr;
- this.exprStr = AnalyticsValueStream.createExpressionString(name, baseExpr, fillExpr);
- this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr, baseExpr, fillExpr);
- }
-
- boolean exists = false;
- FloatConsumer cons;
-
- @Override
- public void streamFloats(FloatConsumer cons) {
- exists = false;
- this.cons = cons;
- baseExpr.streamFloats(this);
- if (!exists) {
- fillExpr.streamFloats(cons);
- }
- }
-
- @Override
- public void accept(float value) {
- exists = true;
- cons.accept(value);
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public String getExpressionStr() {
- return exprStr;
- }
-
- @Override
- public ExpressionType getExpressionType() {
- return funcType;
- }
- }
-
- static class FloatFillMissingFunction extends AbstractFloatValue {
- private final FloatValue baseExpr;
- private final FloatValue fillExpr;
- public static final String name = FillMissingFunction.name;
- private final String exprStr;
- private final ExpressionType funcType;
-
- public FloatFillMissingFunction(FloatValue baseExpr, FloatValue fillExpr) throws SolrException {
- this.baseExpr = baseExpr;
- this.fillExpr = fillExpr;
- this.exprStr = AnalyticsValueStream.createExpressionString(name, baseExpr, fillExpr);
- this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr, baseExpr, fillExpr);
- }
-
- boolean exists = false;
-
- @Override
- public float getFloat() {
- float value = baseExpr.getFloat();
- exists = true;
- if (!baseExpr.exists()) {
- value = fillExpr.getFloat();
- exists = fillExpr.exists();
- }
- return value;
- }
-
- @Override
- public boolean exists() {
- return exists;
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public String getExpressionStr() {
- return exprStr;
- }
-
- @Override
- public ExpressionType getExpressionType() {
- return funcType;
- }
- }
-
- static class DoubleStreamFillMissingFunction extends AbstractDoubleValueStream
- implements DoubleConsumer {
- private final DoubleValueStream baseExpr;
- private final DoubleValueStream fillExpr;
- public static final String name = FillMissingFunction.name;
- private final String exprStr;
- private final ExpressionType funcType;
-
- public DoubleStreamFillMissingFunction(DoubleValueStream baseExpr, DoubleValueStream fillExpr)
- throws SolrException {
- this.baseExpr = baseExpr;
- this.fillExpr = fillExpr;
- this.exprStr = AnalyticsValueStream.createExpressionString(name, baseExpr, fillExpr);
- this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr, baseExpr, fillExpr);
- }
-
- boolean exists = false;
- DoubleConsumer cons;
-
- @Override
- public void streamDoubles(DoubleConsumer cons) {
- exists = false;
- this.cons = cons;
- baseExpr.streamDoubles(this);
- if (!exists) {
- fillExpr.streamDoubles(cons);
- }
- }
-
- @Override
- public void accept(double value) {
- exists = true;
- cons.accept(value);
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public String getExpressionStr() {
- return exprStr;
- }
-
- @Override
- public ExpressionType getExpressionType() {
- return funcType;
- }
- }
-
- static class DoubleFillMissingFunction extends AbstractDoubleValue {
- private final DoubleValue baseExpr;
- private final DoubleValue fillExpr;
- public static final String name = FillMissingFunction.name;
- private final String exprStr;
- private final ExpressionType funcType;
-
- public DoubleFillMissingFunction(DoubleValue baseExpr, DoubleValue fillExpr)
- throws SolrException {
- this.baseExpr = baseExpr;
- this.fillExpr = fillExpr;
- this.exprStr = AnalyticsValueStream.createExpressionString(name, baseExpr, fillExpr);
- this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr, baseExpr, fillExpr);
- }
-
- boolean exists = false;
-
- @Override
- public double getDouble() {
- double value = baseExpr.getDouble();
- exists = true;
- if (!baseExpr.exists()) {
- value = fillExpr.getDouble();
- exists = fillExpr.exists();
- }
- return value;
- }
-
- @Override
- public boolean exists() {
- return exists;
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public String getExpressionStr() {
- return exprStr;
- }
-
- @Override
- public ExpressionType getExpressionType() {
- return funcType;
- }
- }
-
- static class DateStreamFillMissingFunction extends AbstractDateValueStream
- implements LongConsumer {
- private final DateValueStream baseExpr;
- private final DateValueStream fillExpr;
- public static final String name = FillMissingFunction.name;
- private final String exprStr;
- private final ExpressionType funcType;
-
- public DateStreamFillMissingFunction(DateValueStream baseExpr, DateValueStream fillExpr)
- throws SolrException {
- this.baseExpr = baseExpr;
- this.fillExpr = fillExpr;
- this.exprStr = AnalyticsValueStream.createExpressionString(name, baseExpr, fillExpr);
- this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr, baseExpr, fillExpr);
- }
-
- boolean exists = false;
- LongConsumer cons;
-
- @Override
- public void streamLongs(LongConsumer cons) {
- exists = false;
- this.cons = cons;
- baseExpr.streamLongs(this);
- if (!exists) {
- fillExpr.streamLongs(cons);
- }
- }
-
- @Override
- public void accept(long value) {
- exists = true;
- cons.accept(value);
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public String getExpressionStr() {
- return exprStr;
- }
-
- @Override
- public ExpressionType getExpressionType() {
- return funcType;
- }
- }
-
- static class DateFillMissingFunction extends AbstractDateValue {
- private final DateValue baseExpr;
- private final DateValue fillExpr;
- public static final String name = FillMissingFunction.name;
- private final String exprStr;
- private final ExpressionType funcType;
-
- public DateFillMissingFunction(DateValue baseExpr, DateValue fillExpr) throws SolrException {
- this.baseExpr = baseExpr;
- this.fillExpr = fillExpr;
- this.exprStr = AnalyticsValueStream.createExpressionString(name, baseExpr, fillExpr);
- this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr, baseExpr, fillExpr);
- }
-
- boolean exists = false;
-
- @Override
- public long getLong() {
- long value = baseExpr.getLong();
- exists = true;
- if (!baseExpr.exists()) {
- value = fillExpr.getLong();
- exists = fillExpr.exists();
- }
- return value;
- }
-
- @Override
- public boolean exists() {
- return exists;
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public String getExpressionStr() {
- return exprStr;
- }
-
- @Override
- public ExpressionType getExpressionType() {
- return funcType;
- }
- }
-
- static class StringStreamFillMissingFunction extends AbstractStringValueStream
- implements Consumer<String> {
- private final StringValueStream baseExpr;
- private final StringValueStream fillExpr;
- public static final String name = FillMissingFunction.name;
- private final String exprStr;
- private final ExpressionType funcType;
-
- public StringStreamFillMissingFunction(StringValueStream baseExpr, StringValueStream fillExpr)
- throws SolrException {
- this.baseExpr = baseExpr;
- this.fillExpr = fillExpr;
- this.exprStr = AnalyticsValueStream.createExpressionString(name, baseExpr, fillExpr);
- this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr, baseExpr, fillExpr);
- }
-
- boolean exists = false;
- Consumer<String> cons;
-
- @Override
- public void streamStrings(Consumer<String> cons) {
- exists = false;
- this.cons = cons;
- baseExpr.streamStrings(this);
- if (!exists) {
- fillExpr.streamStrings(cons);
- }
- }
-
- @Override
- public void accept(String value) {
- exists = true;
- cons.accept(value);
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public String getExpressionStr() {
- return exprStr;
- }
-
- @Override
- public ExpressionType getExpressionType() {
- return funcType;
- }
- }
-
- static class StringFillMissingFunction extends AbstractStringValue {
- private final StringValue baseExpr;
- private final StringValue fillExpr;
- public static final String name = FillMissingFunction.name;
- private final String exprStr;
- private final ExpressionType funcType;
-
- public StringFillMissingFunction(StringValue baseExpr, StringValue fillExpr)
- throws SolrException {
- this.baseExpr = baseExpr;
- this.fillExpr = fillExpr;
- this.exprStr = AnalyticsValueStream.createExpressionString(name, baseExpr, fillExpr);
- this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr, baseExpr, fillExpr);
- }
... 48725 lines suppressed ...