You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by dp...@apache.org on 2017/10/17 17:53:52 UTC
[01/20] lucene-solr:master: SOLR-11145,
SOLR-11146: Added comprehensive unit tests for Analytics Component
2.0 as well as analytics bug fixes.
Repository: lucene-solr
Updated Branches:
refs/heads/master 54469791b -> 6fefcfa18
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingStringValueTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingStringValueTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingStringValueTest.java
new file mode 100644
index 0000000..3286a15
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingStringValueTest.java
@@ -0,0 +1,120 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.value;
+
+import java.util.Arrays;
+import java.util.Iterator;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.analytics.value.AnalyticsValueStream.ExpressionType;
+import org.apache.solr.analytics.value.FillableTestValue.TestStringValue;
+import org.apache.solr.analytics.value.constant.ConstantStringValue;
+import org.junit.Test;
+
+public class CastingStringValueTest extends SolrTestCaseJ4 {
+
+ @Test
+ public void objectCastingTest() {
+ TestStringValue val = new TestStringValue();
+
+ assertTrue(val instanceof AnalyticsValue);
+ AnalyticsValue casted = (AnalyticsValue)val;
+
+ val.setValue("string 1").setExists(true);
+ assertEquals("string 1", casted.getObject());
+ assertTrue(casted.exists());
+
+ val.setValue("abc").setExists(true);
+ assertEquals("abc", casted.getObject());
+ assertTrue(casted.exists());
+ }
+
+ @Test
+ public void stringStreamCastingTest() {
+ TestStringValue val = new TestStringValue();
+
+ assertTrue(val instanceof StringValueStream);
+ StringValueStream casted = (StringValueStream)val;
+
+ // No values
+ val.setExists(false);
+ casted.streamStrings( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple Values
+ val.setValue("abcd").setExists(true);
+ Iterator<String> values = Arrays.asList("abcd").iterator();
+ casted.streamStrings( value -> {
+ assertTrue(values.hasNext());
+ assertEquals(values.next(), value);
+ });
+ assertFalse(values.hasNext());
+ }
+
+ @Test
+ public void objectStreamCastingTest() {
+ TestStringValue val = new TestStringValue();
+
+ assertTrue(val instanceof AnalyticsValueStream);
+ AnalyticsValueStream casted = (AnalyticsValueStream)val;
+
+ // No values
+ val.setExists(false);
+ casted.streamObjects( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple Values
+ val.setValue("abcd").setExists(true);
+ Iterator<Object> values = Arrays.<Object>asList("abcd").iterator();
+ casted.streamObjects( value -> {
+ assertTrue(values.hasNext());
+ assertEquals(values.next(), value);
+ });
+ assertFalse(values.hasNext());
+ }
+
+ @Test
+ public void constantConversionTest() {
+ TestStringValue val = new TestStringValue(ExpressionType.CONST);
+ val.setValue("asd23n23").setExists(true);
+ AnalyticsValueStream conv = val.convertToConstant();
+ assertTrue(conv instanceof ConstantStringValue);
+ assertEquals("asd23n23", ((ConstantStringValue)conv).getString());
+
+ val = new TestStringValue(ExpressionType.FIELD);
+ val.setValue("asd23n23").setExists(true);
+ conv = val.convertToConstant();
+ assertSame(val, conv);
+
+ val = new TestStringValue(ExpressionType.UNREDUCED_MAPPING);
+ val.setValue("asd23n23").setExists(true);
+ conv = val.convertToConstant();
+ assertSame(val, conv);
+
+ val = new TestStringValue(ExpressionType.REDUCTION);
+ val.setValue("asd23n23").setExists(true);
+ conv = val.convertToConstant();
+ assertSame(val, conv);
+
+ val = new TestStringValue(ExpressionType.REDUCED_MAPPING);
+ val.setValue("asd23n23").setExists(true);
+ conv = val.convertToConstant();
+ assertSame(val, conv);
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/ConstantValueTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/ConstantValueTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/ConstantValueTest.java
new file mode 100644
index 0000000..bcdf7da
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/ConstantValueTest.java
@@ -0,0 +1,368 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.value;
+
+import java.time.Instant;
+import java.time.format.DateTimeParseException;
+import java.util.Date;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.analytics.value.FillableTestValue.TestIntValue;
+import org.apache.solr.analytics.value.constant.ConstantBooleanValue;
+import org.apache.solr.analytics.value.constant.ConstantDateValue;
+import org.apache.solr.analytics.value.constant.ConstantDoubleValue;
+import org.apache.solr.analytics.value.constant.ConstantFloatValue;
+import org.apache.solr.analytics.value.constant.ConstantIntValue;
+import org.apache.solr.analytics.value.constant.ConstantLongValue;
+import org.apache.solr.analytics.value.constant.ConstantStringValue;
+import org.apache.solr.analytics.value.constant.ConstantValue;
+import org.junit.Test;
+
+public class ConstantValueTest extends SolrTestCaseJ4 {
+
+
+ @Test
+ public void constantParsingTest() throws DateTimeParseException {
+ // Int
+ AnalyticsValueStream uncasted = ConstantValue.creatorFunction.apply("1234");
+ assertTrue(uncasted instanceof ConstantIntValue);
+ assertEquals(1234, ((ConstantIntValue)uncasted).getInt());
+
+ // Long
+ uncasted = ConstantValue.creatorFunction.apply("1234123412341234");
+ assertTrue(uncasted instanceof ConstantLongValue);
+ assertEquals(1234123412341234L, ((ConstantLongValue)uncasted).getLong());
+
+ // Floats cannot currently be implicitly created
+
+ // Double
+ uncasted = ConstantValue.creatorFunction.apply("12341234.12341234");
+ assertTrue(uncasted instanceof ConstantDoubleValue);
+ assertEquals(12341234.12341234, ((ConstantDoubleValue)uncasted).getDouble(), .000000001);
+
+ // String
+ uncasted = ConstantValue.creatorFunction.apply("'abcdef'");
+ assertTrue(uncasted instanceof ConstantStringValue);
+ assertEquals("abcdef", ((ConstantStringValue)uncasted).getString());
+
+ uncasted = ConstantValue.creatorFunction.apply("\"abcdef\"");
+ assertTrue(uncasted instanceof ConstantStringValue);
+ assertEquals("abcdef", ((ConstantStringValue)uncasted).getString());
+
+ // Date
+ uncasted = ConstantValue.creatorFunction.apply("1800-01-01T10:30:15.33Z");
+ assertTrue(uncasted instanceof ConstantDateValue);
+ assertEquals(Date.from(Instant.parse("1800-01-01T10:30:15.33Z")), ((ConstantDateValue)uncasted).getDate());
+ }
+
+ @Test
+ public void constantConversionTest() {
+ AnalyticsValueStream val = new ConstantBooleanValue(true);
+ assertSame(val, val.convertToConstant());
+
+ val = new ConstantIntValue(123);
+ assertSame(val, val.convertToConstant());
+
+ val = new ConstantLongValue(123L);
+ assertSame(val, val.convertToConstant());
+
+ val = new ConstantFloatValue(123F);
+ assertSame(val, val.convertToConstant());
+
+ val = new ConstantDoubleValue(123.0);
+ assertSame(val, val.convertToConstant());
+
+ val = new ConstantDateValue(123L);
+ assertSame(val, val.convertToConstant());
+
+ val = new ConstantStringValue("123");
+ assertSame(val, val.convertToConstant());
+ }
+
+ @Test
+ public void constantBooleanTest() {
+ ConstantBooleanValue val = new ConstantBooleanValue(true);
+
+ assertTrue(val.exists());
+ assertEquals(true, val.getBoolean());
+ assertEquals("true", val.getString());
+ assertEquals(new Boolean(true), val.getObject());
+
+ TestIntValue counter = new TestIntValue();
+ counter.setValue(0);
+ val.streamBooleans( value -> {
+ assertEquals(true, value);
+ assertEquals(0, counter.getInt());
+ counter.setValue(1);
+ });
+ counter.setValue(0);
+ val.streamStrings( value -> {
+ assertEquals("true", value);
+ assertEquals(0, counter.getInt());
+ counter.setValue(1);
+ });
+ counter.setValue(0);
+ val.streamObjects( value -> {
+ assertEquals(new Boolean(true), value);
+ assertEquals(0, counter.getInt());
+ counter.setValue(1);
+ });
+
+
+ val = new ConstantBooleanValue(false);
+
+ assertTrue(val.exists());
+ assertEquals(false, val.getBoolean());
+ assertEquals("false", val.getString());
+ assertEquals(new Boolean(false), val.getObject());
+
+ counter.setValue(0);
+ val.streamBooleans( value -> {
+ assertEquals(false, value);
+ assertEquals(0, counter.getInt());
+ counter.setValue(1);
+ });
+ counter.setValue(0);
+ val.streamStrings( value -> {
+ assertEquals("false", value);
+ assertEquals(0, counter.getInt());
+ counter.setValue(1);
+ });
+ counter.setValue(0);
+ val.streamObjects( value -> {
+ assertEquals(new Boolean(false), value);
+ assertEquals(0, counter.getInt());
+ counter.setValue(1);
+ });
+ }
+
+ @Test
+ public void constantIntTest() {
+ ConstantIntValue val = new ConstantIntValue(24);
+
+ assertTrue(val.exists());
+ assertEquals(24, val.getInt());
+ assertEquals(24L, val.getLong());
+ assertEquals(24F, val.getFloat(), .00001);
+ assertEquals(24.0, val.getDouble(), .00001);
+ assertEquals("24", val.getString());
+ assertEquals(new Integer(24), val.getObject());
+
+ TestIntValue counter = new TestIntValue();
+ counter.setValue(0);
+ val.streamInts( value -> {
+ assertEquals(24, value);
+ assertEquals(0, counter.getInt());
+ counter.setValue(1);
+ });
+ counter.setValue(0);
+ val.streamLongs( value -> {
+ assertEquals(24L, value);
+ assertEquals(0, counter.getInt());
+ counter.setValue(1);
+ });
+ counter.setValue(0);
+ val.streamFloats( value -> {
+ assertEquals(24F, value, .00001);
+ assertEquals(0, counter.getInt());
+ counter.setValue(1);
+ });
+ counter.setValue(0);
+ val.streamDoubles( value -> {
+ assertEquals(24.0, value, .00001);
+ assertEquals(0, counter.getInt());
+ counter.setValue(1);
+ });
+ counter.setValue(0);
+ val.streamStrings( value -> {
+ assertEquals("24", value);
+ assertEquals(0, counter.getInt());
+ counter.setValue(1);
+ });
+ counter.setValue(0);
+ val.streamObjects( value -> {
+ assertEquals(new Integer(24), value);
+ assertEquals(0, counter.getInt());
+ counter.setValue(1);
+ });
+ }
+
+ @Test
+ public void constantLongTest() {
+ ConstantLongValue val = new ConstantLongValue(24L);
+
+ assertTrue(val.exists());
+ assertEquals(24L, val.getLong());
+ assertEquals(24.0, val.getDouble(), .00001);
+ assertEquals("24", val.getString());
+ assertEquals(new Long(24L), val.getObject());
+
+ TestIntValue counter = new TestIntValue();
+ counter.setValue(0);
+ val.streamLongs( value -> {
+ assertEquals(24L, value);
+ assertEquals(0, counter.getInt());
+ counter.setValue(1);
+ });
+ counter.setValue(0);
+ val.streamDoubles( value -> {
+ assertEquals(24.0, value, .00001);
+ assertEquals(0, counter.getInt());
+ counter.setValue(1);
+ });
+ counter.setValue(0);
+ val.streamStrings( value -> {
+ assertEquals("24", value);
+ assertEquals(0, counter.getInt());
+ counter.setValue(1);
+ });
+ counter.setValue(0);
+ val.streamObjects( value -> {
+ assertEquals(new Long(24L), value);
+ assertEquals(0, counter.getInt());
+ counter.setValue(1);
+ });
+ }
+
+ @Test
+ public void constantFloatTest() {
+ ConstantFloatValue val = new ConstantFloatValue(24F);
+
+ assertTrue(val.exists());
+ assertEquals(24F, val.getFloat(), .00001);
+ assertEquals(24.0, val.getDouble(), .00001);
+ assertEquals("24.0", val.getString());
+ assertEquals(new Float(24F), val.getObject());
+
+ TestIntValue counter = new TestIntValue();
+ counter.setValue(0);
+ val.streamFloats( value -> {
+ assertEquals(24F, value, .00001);
+ assertEquals(0, counter.getInt());
+ counter.setValue(1);
+ });
+ counter.setValue(0);
+ val.streamDoubles( value -> {
+ assertEquals(24.0, value, .00001);
+ assertEquals(0, counter.getInt());
+ counter.setValue(1);
+ });
+ counter.setValue(0);
+ val.streamStrings( value -> {
+ assertEquals("24.0", value);
+ assertEquals(0, counter.getInt());
+ counter.setValue(1);
+ });
+ counter.setValue(0);
+ val.streamObjects( value -> {
+ assertEquals(new Float(24F), value);
+ assertEquals(0, counter.getInt());
+ counter.setValue(1);
+ });
+ }
+
+ @Test
+ public void constantDoubleTest() {
+ ConstantDoubleValue val = new ConstantDoubleValue(24.0);
+
+ assertTrue(val.exists());
+ assertEquals(24.0, val.getDouble(), .00001);
+ assertEquals("24.0", val.getString());
+ assertEquals(new Double(24.0), val.getObject());
+
+ TestIntValue counter = new TestIntValue();
+ counter.setValue(0);
+ val.streamDoubles( value -> {
+ assertEquals(24.0, value, .00001);
+ assertEquals(0, counter.getInt());
+ counter.setValue(1);
+ });
+ counter.setValue(0);
+ val.streamStrings( value -> {
+ assertEquals("24.0", value);
+ assertEquals(0, counter.getInt());
+ counter.setValue(1);
+ });
+ counter.setValue(0);
+ val.streamObjects( value -> {
+ assertEquals(new Double(24.0), value);
+ assertEquals(0, counter.getInt());
+ counter.setValue(1);
+ });
+ }
+
+ @Test
+ public void constantDateTest() throws DateTimeParseException {
+ Date date = Date.from(Instant.parse("1800-01-01T10:30:15Z"));
+ ConstantDateValue val = new ConstantDateValue(date.getTime());
+
+ assertTrue(val.exists());
+ assertEquals(date.getTime(), val.getLong());
+ assertEquals(date, val.getDate());
+ assertEquals("1800-01-01T10:30:15Z", val.getString());
+ assertEquals(date, val.getObject());
+
+ TestIntValue counter = new TestIntValue();
+ counter.setValue(0);
+ val.streamLongs( value -> {
+ assertEquals(date.getTime(), value);
+ assertEquals(0, counter.getInt());
+ counter.setValue(1);
+ });
+ counter.setValue(0);
+ val.streamDates( value -> {
+ assertEquals(date, value);
+ assertEquals(0, counter.getInt());
+ counter.setValue(1);
+ });
+ counter.setValue(0);
+ val.streamStrings( value -> {
+ assertEquals("1800-01-01T10:30:15Z", value);
+ assertEquals(0, counter.getInt());
+ counter.setValue(1);
+ });
+ counter.setValue(0);
+ val.streamObjects( value -> {
+ assertEquals(date, value);
+ assertEquals(0, counter.getInt());
+ counter.setValue(1);
+ });
+ }
+
+ @Test
+ public void constantStringTest() {
+ ConstantStringValue val = new ConstantStringValue("abcdef");
+
+ assertTrue(val.exists());
+ assertEquals("abcdef", val.getString());
+ assertEquals("abcdef", val.getObject());
+
+ TestIntValue counter = new TestIntValue();
+ counter.setValue(0);
+ val.streamStrings( value -> {
+ assertEquals("abcdef", value);
+ assertEquals(0, counter.getInt());
+ counter.setValue(1);
+ });
+ counter.setValue(0);
+ val.streamObjects( value -> {
+ assertEquals("abcdef", value);
+ assertEquals(0, counter.getInt());
+ counter.setValue(1);
+ });
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/FillableTestValue.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/FillableTestValue.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/FillableTestValue.java
new file mode 100644
index 0000000..7facef9
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/FillableTestValue.java
@@ -0,0 +1,641 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.value;
+
+import java.time.Instant;
+import java.time.format.DateTimeParseException;
+import java.util.function.Consumer;
+import java.util.function.DoubleConsumer;
+import java.util.function.IntConsumer;
+import java.util.function.LongConsumer;
+
+import org.apache.solr.analytics.util.function.BooleanConsumer;
+import org.apache.solr.analytics.util.function.FloatConsumer;
+import org.apache.solr.analytics.value.AnalyticsValue.AbstractAnalyticsValue;
+import org.apache.solr.analytics.value.AnalyticsValueStream.AbstractAnalyticsValueStream;
+import org.apache.solr.analytics.value.BooleanValue.AbstractBooleanValue;
+import org.apache.solr.analytics.value.BooleanValueStream.AbstractBooleanValueStream;
+import org.apache.solr.analytics.value.DateValue.AbstractDateValue;
+import org.apache.solr.analytics.value.DateValueStream.AbstractDateValueStream;
+import org.apache.solr.analytics.value.DoubleValue.AbstractDoubleValue;
+import org.apache.solr.analytics.value.DoubleValueStream.AbstractDoubleValueStream;
+import org.apache.solr.analytics.value.FloatValue.AbstractFloatValue;
+import org.apache.solr.analytics.value.FloatValueStream.AbstractFloatValueStream;
+import org.apache.solr.analytics.value.IntValue.AbstractIntValue;
+import org.apache.solr.analytics.value.IntValueStream.AbstractIntValueStream;
+import org.apache.solr.analytics.value.LongValue.AbstractLongValue;
+import org.apache.solr.analytics.value.LongValueStream.AbstractLongValueStream;
+import org.apache.solr.analytics.value.StringValue.AbstractStringValue;
+import org.apache.solr.analytics.value.StringValueStream.AbstractStringValueStream;
+
+public class FillableTestValue {
+ public static class TestAnalyticsValue extends AbstractAnalyticsValue {
+ private final ExpressionType expressionType;
+
+ private Object value;
+ private boolean exists;
+
+ public TestAnalyticsValue() {
+ this(ExpressionType.CONST);
+ }
+
+ public TestAnalyticsValue(ExpressionType expressionType) {
+ this.expressionType = expressionType;
+ }
+
+ public TestAnalyticsValue setValue(Object value) {
+ this.value = value;
+ return this;
+ }
+
+ public TestAnalyticsValue setExists(boolean exists) {
+ this.exists = exists;
+ return this;
+ }
+
+ @Override
+ public Object getObject() {
+ return value;
+ }
+
+ @Override
+ public boolean exists() {
+ return exists;
+ }
+
+ @Override
+ public String getName() { return "test_analytics_value"; }
+
+ @Override
+ public String getExpressionStr() { return "test_analytics_value"; }
+
+ @Override
+ public ExpressionType getExpressionType() { return expressionType; }
+ }
+
+ public static class TestAnalyticsValueStream extends AbstractAnalyticsValueStream {
+ private final ExpressionType expressionType;
+
+ private Object[] values;
+
+ public TestAnalyticsValueStream() {
+ this(ExpressionType.CONST);
+ }
+
+ public TestAnalyticsValueStream(ExpressionType expressionType) {
+ this.expressionType = expressionType;
+ }
+
+ public TestAnalyticsValueStream setValues(Object... values) {
+ this.values = values;
+ return this;
+ }
+
+ @Override
+ public void streamObjects(Consumer<Object> cons) {
+ for (int i = 0; i < values.length; ++i) {
+ cons.accept(values[i]);
+ }
+ }
+
+ @Override
+ public String getName() { return "test_analytics_value_stream"; }
+
+ @Override
+ public String getExpressionStr() { return "test_analytics_value_stream"; }
+
+ @Override
+ public ExpressionType getExpressionType() { return expressionType; }
+ }
+
+ public static class TestIntValue extends AbstractIntValue {
+ private final ExpressionType expressionType;
+
+ private int value;
+ private boolean exists;
+
+ public TestIntValue() {
+ this(ExpressionType.CONST);
+ }
+
+ public TestIntValue(ExpressionType expressionType) {
+ this.expressionType = expressionType;
+ }
+
+ public TestIntValue setValue(int value) {
+ this.value = value;
+ return this;
+ }
+
+ public TestIntValue setExists(boolean exists) {
+ this.exists = exists;
+ return this;
+ }
+
+ @Override
+ public int getInt() {
+ return value;
+ }
+
+ @Override
+ public boolean exists() {
+ return exists;
+ }
+
+ @Override
+ public String getName() { return "test_int_value"; }
+
+ @Override
+ public String getExpressionStr() { return "test_int_value"; }
+
+ @Override
+ public ExpressionType getExpressionType() { return expressionType; }
+ }
+
+ public static class TestIntValueStream extends AbstractIntValueStream {
+ private int[] values;
+
+ public TestIntValueStream() {
+ this.values = new int[0];
+ }
+
+ public TestIntValueStream setValues(int... values) {
+ this.values = values;
+ return this;
+ }
+
+ @Override
+ public void streamInts(IntConsumer cons) {
+ for (int i = 0; i < values.length; ++i) {
+ cons.accept(values[i]);
+ }
+ }
+
+ @Override
+ public String getName() { return "test_int_value_stream"; }
+
+ @Override
+ public String getExpressionStr() { return "test_int_value_stream"; }
+
+ @Override
+ public ExpressionType getExpressionType() { return ExpressionType.UNREDUCED_MAPPING; }
+ }
+
+ public static class TestLongValue extends AbstractLongValue {
+ private final ExpressionType expressionType;
+
+ private long value;
+ private boolean exists;
+
+ public TestLongValue() {
+ this(ExpressionType.CONST);
+ }
+
+ public TestLongValue(ExpressionType expressionType) {
+ this.expressionType = expressionType;
+ }
+
+ public TestLongValue setValue(long value) {
+ this.value = value;
+ return this;
+ }
+
+ public TestLongValue setExists(boolean exists) {
+ this.exists = exists;
+ return this;
+ }
+
+ @Override
+ public long getLong() {
+ return value;
+ }
+
+ @Override
+ public boolean exists() {
+ return exists;
+ }
+
+ @Override
+ public String getName() { return "test_long_value"; }
+
+ @Override
+ public String getExpressionStr() { return "test_long_value"; }
+
+ @Override
+ public ExpressionType getExpressionType() { return expressionType; }
+ }
+
+ public static class TestLongValueStream extends AbstractLongValueStream {
+ private long[] values;
+
+ public TestLongValueStream() {
+ this.values = new long[0];
+ }
+
+ public TestLongValueStream setValues(long... values) {
+ this.values = values;
+ return this;
+ }
+
+ @Override
+ public void streamLongs(LongConsumer cons) {
+ for (int i = 0; i < values.length; ++i) {
+ cons.accept(values[i]);
+ }
+ }
+
+ @Override
+ public String getName() { return "test_long_value_stream"; }
+
+ @Override
+ public String getExpressionStr() { return "test_long_value_stream"; }
+
+ @Override
+ public ExpressionType getExpressionType() { return ExpressionType.UNREDUCED_MAPPING; }
+ }
+
+ public static class TestFloatValue extends AbstractFloatValue {
+ private final ExpressionType expressionType;
+
+ private float value;
+ private boolean exists;
+
+ public TestFloatValue() {
+ this(ExpressionType.CONST);
+ }
+
+ public TestFloatValue(ExpressionType expressionType) {
+ this.expressionType = expressionType;
+ }
+
+ public TestFloatValue setValue(float value) {
+ this.value = value;
+ return this;
+ }
+
+ public TestFloatValue setExists(boolean exists) {
+ this.exists = exists;
+ return this;
+ }
+
+ @Override
+ public float getFloat() {
+ return value;
+ }
+
+ @Override
+ public boolean exists() {
+ return exists;
+ }
+
+ @Override
+ public String getName() { return "test_float_value"; }
+
+ @Override
+ public String getExpressionStr() { return "test_float_value"; }
+
+ @Override
+ public ExpressionType getExpressionType() { return expressionType; }
+ }
+
+ public static class TestFloatValueStream extends AbstractFloatValueStream {
+ private float[] values;
+
+ public TestFloatValueStream() {
+ this.values = new float[0];
+ }
+
+ public TestFloatValueStream setValues(float... values) {
+ this.values = values;
+ return this;
+ }
+
+ @Override
+ public void streamFloats(FloatConsumer cons) {
+ for (int i = 0; i < values.length; ++i) {
+ cons.accept(values[i]);
+ }
+ }
+
+ @Override
+ public String getName() { return "test_float_value_stream"; }
+
+ @Override
+ public String getExpressionStr() { return "test_float_value_stream"; }
+
+ @Override
+ public ExpressionType getExpressionType() { return ExpressionType.UNREDUCED_MAPPING; }
+ }
+
+ public static class TestDoubleValue extends AbstractDoubleValue {
+ private final ExpressionType expressionType;
+
+ private double value;
+ private boolean exists;
+
+ public TestDoubleValue() {
+ this(ExpressionType.CONST);
+ }
+
+ public TestDoubleValue(ExpressionType expressionType) {
+ this.expressionType = expressionType;
+ }
+
+ public TestDoubleValue setValue(double value) {
+ this.value = value;
+ return this;
+ }
+
+ public TestDoubleValue setExists(boolean exists) {
+ this.exists = exists;
+ return this;
+ }
+
+ @Override
+ public double getDouble() {
+ return value;
+ }
+
+ @Override
+ public boolean exists() {
+ return exists;
+ }
+
+ @Override
+ public String getName() { return "test_double_value"; }
+
+ @Override
+ public String getExpressionStr() { return "test_double_value"; }
+
+ @Override
+ public ExpressionType getExpressionType() { return expressionType; }
+ }
+
+ public static class TestDoubleValueStream extends AbstractDoubleValueStream {
+ private double[] values;
+
+ public TestDoubleValueStream() {
+ this.values = new double[0];
+ }
+
+ public TestDoubleValueStream setValues(double... values) {
+ this.values = values;
+ return this;
+ }
+
+ @Override
+ public void streamDoubles(DoubleConsumer cons) {
+ for (int i = 0; i < values.length; ++i) {
+ cons.accept(values[i]);
+ }
+ }
+
+ @Override
+ public String getName() { return "test_double_value_stream"; }
+
+ @Override
+ public String getExpressionStr() { return "test_double_value_stream"; }
+
+ @Override
+ public ExpressionType getExpressionType() { return ExpressionType.UNREDUCED_MAPPING; }
+ }
+
+ public static class TestBooleanValue extends AbstractBooleanValue {
+ private final ExpressionType expressionType;
+
+ private boolean value;
+ private boolean exists;
+
+ public TestBooleanValue() {
+ this(ExpressionType.CONST);
+ }
+
+ public TestBooleanValue(ExpressionType expressionType) {
+ this.expressionType = expressionType;
+ }
+
+ public TestBooleanValue setValue(boolean value) {
+ this.value = value;
+ return this;
+ }
+
+ public TestBooleanValue setExists(boolean exists) {
+ this.exists = exists;
+ return this;
+ }
+
+ @Override
+ public boolean getBoolean() {
+ return value;
+ }
+
+ @Override
+ public boolean exists() {
+ return exists;
+ }
+
+ @Override
+ public String getName() { return "test_boolean_value"; }
+
+ @Override
+ public String getExpressionStr() { return "test_boolean_value"; }
+
+ @Override
+ public ExpressionType getExpressionType() { return expressionType; }
+ }
+
+ public static class TestBooleanValueStream extends AbstractBooleanValueStream {
+ private boolean[] values;
+
+ public TestBooleanValueStream() {
+ this.values = new boolean[0];
+ }
+
+ public TestBooleanValueStream setValues(boolean... values) {
+ this.values = values;
+ return this;
+ }
+
+ @Override
+ public void streamBooleans(BooleanConsumer cons) {
+ for (int i = 0; i < values.length; ++i) {
+ cons.accept(values[i]);
+ }
+ }
+
+ @Override
+ public String getName() { return "test_boolean_value_stream"; }
+
+ @Override
+ public String getExpressionStr() { return "test_boolean_value_stream"; }
+
+ @Override
+ public ExpressionType getExpressionType() { return ExpressionType.UNREDUCED_MAPPING; }
+ }
+
+ public static class TestDateValue extends AbstractDateValue {
+ private final ExpressionType expressionType;
+
+ private long value;
+ private boolean exists;
+
+ public TestDateValue() {
+ this(ExpressionType.CONST);
+ }
+
+ public TestDateValue(ExpressionType expressionType) {
+ this.expressionType = expressionType;
+ }
+
+ public TestDateValue setValue(String value) {
+ try {
+ this.value = Instant.parse(value).toEpochMilli();
+ } catch (DateTimeParseException e) {
+ this.value = 0;
+ }
+ return this;
+ }
+
+ public TestDateValue setExists(boolean exists) {
+ this.exists = exists;
+ return this;
+ }
+
+ @Override
+ public long getLong() {
+ return value;
+ }
+
+ @Override
+ public boolean exists() {
+ return exists;
+ }
+
+ @Override
+ public String getName() { return "test_date_value"; }
+
+ @Override
+ public String getExpressionStr() { return "test_date_value"; }
+
+ @Override
+ public ExpressionType getExpressionType() { return expressionType; }
+ }
+
+ public static class TestDateValueStream extends AbstractDateValueStream {
+ private String[] values;
+
+ public TestDateValueStream() {
+ this.values = new String[0];
+ }
+
+ public TestDateValueStream setValues(String... values) {
+ this.values = values;
+ return this;
+ }
+
+ @Override
+ public void streamLongs(LongConsumer cons) {
+ for (int i = 0; i < values.length; ++i) {
+ try {
+ cons.accept(Instant.parse(values[i]).toEpochMilli());
+ } catch (DateTimeParseException e) { }
+ }
+ }
+
+ @Override
+ public String getName() { return "test_date_value_stream"; }
+
+ @Override
+ public String getExpressionStr() { return "test_date_value_stream"; }
+
+ @Override
+ public ExpressionType getExpressionType() { return ExpressionType.UNREDUCED_MAPPING; }
+ }
+
+ public static class TestStringValue extends AbstractStringValue {
+ private final ExpressionType expressionType;
+
+ private String value;
+ private boolean exists;
+
+ public TestStringValue() {
+ this(ExpressionType.CONST);
+ }
+
+ public TestStringValue(ExpressionType expressionType) {
+ this.expressionType = expressionType;
+ }
+
+ public TestStringValue setValue(String value) {
+ this.value = value;
+ return this;
+ }
+
+ public TestStringValue setExists(boolean exists) {
+ this.exists = exists;
+ return this;
+ }
+
+ @Override
+ public String getString() {
+ return value;
+ }
+
+ @Override
+ public boolean exists() {
+ return exists;
+ }
+
+ @Override
+ public String getName() { return "test_string_value"; }
+
+ @Override
+ public String getExpressionStr() { return "test_string_value"; }
+
+ @Override
+ public ExpressionType getExpressionType() { return expressionType; }
+ }
+
+ public static class TestStringValueStream extends AbstractStringValueStream {
+ private String[] values;
+
+ public TestStringValueStream() {
+ this.values = new String[0];
+ }
+
+ public TestStringValueStream setValues(String... values) {
+ this.values = values;
+ return this;
+ }
+
+ @Override
+ public void streamStrings(Consumer<String> cons) {
+ for (int i = 0; i < values.length; ++i) {
+ cons.accept(values[i]);
+ }
+ }
+
+ @Override
+ public String getName() { return "test_string_value_stream"; }
+
+ @Override
+ public String getExpressionStr() { return "test_string_value_stream"; }
+
+ @Override
+ public ExpressionType getExpressionType() { return ExpressionType.UNREDUCED_MAPPING; }
+ }
+}
[12/20] lucene-solr:master: SOLR-11145,
SOLR-11146: Added comprehensive unit tests for Analytics Component
2.0 as well as analytics bug fixes.
Posted by dp...@apache.org.
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/RangeFacetCloudTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/RangeFacetCloudTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/RangeFacetCloudTest.java
deleted file mode 100644
index 880324d..0000000
--- a/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/RangeFacetCloudTest.java
+++ /dev/null
@@ -1,588 +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.List;
-
-import org.apache.solr.client.solrj.request.UpdateRequest;
-import org.apache.solr.common.util.NamedList;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-
-public class RangeFacetCloudTest extends AbstractAnalyticsFacetCloudTest{
- public static final int INT = 71;
- public static final int LONG = 36;
- public static final int FLOAT = 93;
- public static final int DOUBLE = 48;
- public static final int DATE = 52;
- public static final int STRING = 28;
- public static final int NUM_LOOPS = 100;
-
- //INT
- static ArrayList<ArrayList<Integer>> intLongTestStart;
- static ArrayList<ArrayList<Integer>> intDoubleTestStart;
- static ArrayList<ArrayList<Integer>> intDateTestStart;
-
- //FLOAT
- static ArrayList<ArrayList<Float>> floatLongTestStart;
- static ArrayList<ArrayList<Float>> floatDoubleTestStart;
- static ArrayList<ArrayList<Float>> floatDateTestStart;
-
- @BeforeClass
- public static void beforeClass() throws Exception {
- setupCluster();
-
- //INT
- intLongTestStart = new ArrayList<>();
- intDoubleTestStart = new ArrayList<>();
- intDateTestStart = new ArrayList<>();
-
- //FLOAT
- floatLongTestStart = new ArrayList<>();
- floatDoubleTestStart = new ArrayList<>();
- floatDateTestStart = new ArrayList<>();
-
- UpdateRequest req = new UpdateRequest();
-
- for (int j = 0; j < NUM_LOOPS; ++j) {
- int i = j%INT;
- long l = j%LONG;
- float f = j%FLOAT;
- double d = j%DOUBLE;
- int dt = j%DATE;
- int s = j%STRING;
-
- List<String> fields = new ArrayList<>();
- fields.add("id"); fields.add("1000"+j);
- fields.add("int_id"); fields.add("" + i);
- fields.add("long_ld"); fields.add("" + l);
- fields.add("float_fd"); fields.add("" + f);
- fields.add("double_dd"); fields.add("" + d);
- fields.add("date_dtd"); fields.add((1000+dt) + "-01-01T23:59:59Z");
- fields.add("string_sd"); fields.add("abc" + s);
- req.add(fields.toArray(new String[0]));
-
- //Longs
- if (j-LONG<0) {
- ArrayList<Integer> list1 = new ArrayList<>();
- list1.add(i);
- intLongTestStart.add(list1);
- ArrayList<Float> list2 = new ArrayList<>();
- list2.add(f);
- floatLongTestStart.add(list2);
- } else {
- intLongTestStart.get((int)l).add(i);
- floatLongTestStart.get((int)l).add(f);
- }
- //Doubles
- if (j-DOUBLE<0) {
- ArrayList<Integer> list1 = new ArrayList<>();
- list1.add(i);
- intDoubleTestStart.add(list1);
- ArrayList<Float> list2 = new ArrayList<>();
- list2.add(f);
- floatDoubleTestStart.add(list2);
- } else {
- intDoubleTestStart.get((int)d).add(i);
- floatDoubleTestStart.get((int)d).add(f);
- }
- //Dates
- if (j-DATE<0) {
- ArrayList<Integer> list1 = new ArrayList<>();
- list1.add(i);
- intDateTestStart.add(list1);
- ArrayList<Float> list2 = new ArrayList<>();
- list2.add(f);
- floatDateTestStart.add(list2);
- } else {
- intDateTestStart.get(dt).add(i);
- floatDateTestStart.get(dt).add(f);
- }
- }
-
- req.commit(cluster.getSolrClient(), COLLECTIONORALIAS);
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void rangeTest() throws Exception {
- String[] params = new String[] {
- "o.ri.s.sum", "sum(int_id)",
- "o.ri.s.mean", "mean(int_id)",
- "o.ri.s.median", "median(int_id)",
- "o.ri.s.count", "count(int_id)",
- "o.ri.rf", "long_ld",
- "o.ri.rf.long_ld.st", "5",
- "o.ri.rf.long_ld.e", "30",
- "o.ri.rf.long_ld.g", "5",
- "o.ri.rf.long_ld.ib", "lower",
- "o.ri.rf.long_ld.or", "all",
- "o.ri.rf", "double_dd",
- "o.ri.rf.double_dd.st", "3",
- "o.ri.rf.double_dd.e", "39",
- "o.ri.rf.double_dd.g", "7",
- "o.ri.rf.double_dd.ib", "upper",
- "o.ri.rf.double_dd.ib", "outer",
- "o.ri.rf.double_dd.or", "all",
- "o.ri.rf", "date_dtd",
- "o.ri.rf.date_dtd.st", "1007-01-01T23:59:59Z",
- "o.ri.rf.date_dtd.e", "1044-01-01T23:59:59Z",
- "o.ri.rf.date_dtd.g", "+7YEARS",
- "o.ri.rf.date_dtd.ib", "lower",
- "o.ri.rf.date_dtd.ib", "edge",
- "o.ri.rf.date_dtd.ib", "outer",
- "o.ri.rf.date_dtd.or", "all",
-
- "o.rf.s.sum", "sum(float_fd)",
- "o.rf.s.mean", "mean(float_fd)",
- "o.rf.s.median", "median(float_fd)",
- "o.rf.s.count", "count(float_fd)",
- "o.rf.rf", "long_ld",
- "o.rf.rf.long_ld.st", "0",
- "o.rf.rf.long_ld.e", "29",
- "o.rf.rf.long_ld.g", "4",
- "o.rf.rf.long_ld.ib", "all",
- "o.rf.rf.long_ld.or", "all",
- "o.rf.rf", "double_dd",
- "o.rf.rf.double_dd.st", "4",
- "o.rf.rf.double_dd.e", "47",
- "o.rf.rf.double_dd.g", "11",
- "o.rf.rf.double_dd.ib", "edge",
- "o.rf.rf.double_dd.or", "all",
- "o.rf.rf", "date_dtd",
- "o.rf.rf.date_dtd.st", "1004-01-01T23:59:59Z",
- "o.rf.rf.date_dtd.e", "1046-01-01T23:59:59Z",
- "o.rf.rf.date_dtd.g", "+5YEARS",
- "o.rf.rf.date_dtd.ib", "upper",
- "o.rf.rf.date_dtd.ib", "edge",
- "o.rf.rf.date_dtd.or", "all"
- };
-
- NamedList<Object> response = queryCloudAnalytics(params);
- String responseStr = response.toString();
-
- //Int Long
- ArrayList<Long> intLong = getValueList(response, "ri", "rangeFacets", "long_ld", "count", false);
- ArrayList<Long> intLongTest = calculateStat(transformLists(intLongTestStart, 5, 30, 5
- , false, true, false, false, false), "count");
- assertEquals(responseStr, intLong,intLongTest);
- //Int Double
- ArrayList<Double> intDouble = getValueList(response, "ri", "rangeFacets", "double_dd", "mean", false);
- ArrayList<Double> intDoubleTest = calculateNumberStat(transformLists(intDoubleTestStart, 3, 39, 7
- , false, false, true, false, true), "mean");
- assertEquals(responseStr, intDouble,intDoubleTest);
- //Int Date
- ArrayList<Long> intDate = getValueList(response, "ri", "rangeFacets", "date_dtd", "count", false);
- ArrayList<Long> intDateTest = (ArrayList<Long>)calculateStat(transformLists(intDateTestStart, 7, 44, 7
- , false, true, false, true, true), "count");
- assertEquals(responseStr, intDate,intDateTest);
-
- //Float Long
- ArrayList<Double> floatLong = getValueList(response, "rf", "rangeFacets", "long_ld", "median", false);
- ArrayList<Double> floatLongTest = calculateNumberStat(transformLists(floatLongTestStart, 0, 29, 4
- , false, true, true, true, true), "median");
- assertEquals(responseStr, floatLong,floatLongTest);
- //Float Double
- ArrayList<Long> floatDouble = getValueList(response, "rf", "rangeFacets", "double_dd", "count", false);
- ArrayList<Long> floatDoubleTest = (ArrayList<Long>)calculateStat(transformLists(floatDoubleTestStart, 4, 47, 11
- , false, false, false, true, false), "count");
- assertEquals(responseStr, floatDouble,floatDoubleTest);
- }
-
-
- @SuppressWarnings("unchecked")
- @Test
- public void hardendRangeTest() throws Exception {
- String[] params = new String[] {
- "o.hi.s.sum", "sum(int_id)",
- "o.hi.s.mean", "mean(int_id)",
- "o.hi.s.median", "median(int_id)",
- "o.hi.s.count", "count(int_id)",
- "o.hi.rf", "long_ld",
- "o.hi.rf.long_ld.st", "5",
- "o.hi.rf.long_ld.e", "30",
- "o.hi.rf.long_ld.g", "5",
- "o.hi.rf.long_ld.he", "true",
- "o.hi.rf.long_ld.ib", "lower",
- "o.hi.rf.long_ld.or", "all",
- "o.hi.rf", "double_dd",
- "o.hi.rf.double_dd.st", "3",
- "o.hi.rf.double_dd.e", "39",
- "o.hi.rf.double_dd.g", "7",
- "o.hi.rf.double_dd.he", "true",
- "o.hi.rf.double_dd.ib", "upper",
- "o.hi.rf.double_dd.ib", "outer",
- "o.hi.rf.double_dd.or", "all",
- "o.hi.rf", "date_dtd",
- "o.hi.rf.date_dtd.st", "1007-01-01T23:59:59Z",
- "o.hi.rf.date_dtd.e", "1044-01-01T23:59:59Z",
- "o.hi.rf.date_dtd.g", "+7YEARS",
- "o.hi.rf.date_dtd.he", "true",
- "o.hi.rf.date_dtd.ib", "lower",
- "o.hi.rf.date_dtd.ib", "edge",
- "o.hi.rf.date_dtd.ib", "outer",
- "o.hi.rf.date_dtd.or", "all",
-
- "o.hf.s.sum", "sum(float_fd)",
- "o.hf.s.mean", "mean(float_fd)",
- "o.hf.s.median", "median(float_fd)",
- "o.hf.s.count", "count(float_fd)",
- "o.hf.rf", "long_ld",
- "o.hf.rf.long_ld.st", "0",
- "o.hf.rf.long_ld.e", "29",
- "o.hf.rf.long_ld.g", "4",
- "o.hf.rf.long_ld.he", "true",
- "o.hf.rf.long_ld.ib", "all",
- "o.hf.rf.long_ld.or", "all",
- "o.hf.rf", "double_dd",
- "o.hf.rf.double_dd.st", "4",
- "o.hf.rf.double_dd.e", "47",
- "o.hf.rf.double_dd.g", "11",
- "o.hf.rf.double_dd.he", "true",
- "o.hf.rf.double_dd.ib", "edge",
- "o.hf.rf.double_dd.or", "all",
- "o.hf.rf", "date_dtd",
- "o.hf.rf.date_dtd.st", "1004-01-01T23:59:59Z",
- "o.hf.rf.date_dtd.e", "1046-01-01T23:59:59Z",
- "o.hf.rf.date_dtd.g", "+5YEARS",
- "o.hf.rf.date_dtd.he", "true",
- "o.hf.rf.date_dtd.ib", "upper",
- "o.hf.rf.date_dtd.ib", "edge",
- "o.hf.rf.date_dtd.or", "all"
- };
- NamedList<Object> response = queryCloudAnalytics(params);
- String responseStr = response.toString();
-
- //Int Long
- ArrayList<Double> intLong = getValueList(response, "hi", "rangeFacets", "long_ld", "sum", false);
- ArrayList<Double> intLongTest = calculateNumberStat(transformLists(intLongTestStart, 5, 30, 5
- , true, true, false, false, false), "sum");
- assertEquals(responseStr, intLong,intLongTest);
- //Int Double
- ArrayList<Double> intDouble = getValueList(response, "hi", "rangeFacets", "double_dd", "mean", false);
- ArrayList<Double> intDoubleTest = calculateNumberStat(transformLists(intDoubleTestStart, 3, 39, 7
- , true, false, true, false, true), "mean");
- assertEquals(responseStr, intDouble,intDoubleTest);
- //Int Date
- ArrayList<Long> intDate = getValueList(response, "hi", "rangeFacets", "date_dtd", "count", false);
- ArrayList<Long> intDateTest = (ArrayList<Long>)calculateStat(transformLists(intDateTestStart, 7, 44, 7
- , true, true, false, true, true), "count");
- assertEquals(responseStr, intDate,intDateTest);
-
- //Float Long
- ArrayList<Double> floatLong = getValueList(response, "hf", "rangeFacets", "long_ld", "median", false);
- ArrayList<Double> floatLongTest = calculateNumberStat(transformLists(floatLongTestStart, 0, 29, 4
- , true, true, true, true, true), "median");
- assertEquals(responseStr, floatLong,floatLongTest);
- //Float Double
- ArrayList<Long> floatDouble = getValueList(response, "hf", "rangeFacets", "double_dd", "count", false);
- ArrayList<Long> floatDoubleTest = (ArrayList<Long>)calculateStat(transformLists(floatDoubleTestStart, 4, 47, 11
- , true, false, false, true, false), "count");
- assertEquals(responseStr, floatDouble,floatDoubleTest);
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void multiGapTest() throws Exception {
- String[] params = new String[] {
- "o.mi.s.sum", "sum(int_id)",
- "o.mi.s.mean", "mean(int_id)",
- "o.mi.s.median", "median(int_id)",
- "o.mi.s.count", "count(int_id)",
- "o.mi.rf", "long_ld",
- "o.mi.rf.long_ld.st", "5",
- "o.mi.rf.long_ld.e", "30",
- "o.mi.rf.long_ld.g", "4,2,6,3",
- "o.mi.rf.long_ld.ib", "lower",
- "o.mi.rf.long_ld.or", "all",
- "o.mi.rf", "double_dd",
- "o.mi.rf.double_dd.st", "3",
- "o.mi.rf.double_dd.e", "39",
- "o.mi.rf.double_dd.g", "3,1,7",
- "o.mi.rf.double_dd.ib", "upper",
- "o.mi.rf.double_dd.ib", "outer",
- "o.mi.rf.double_dd.or", "all",
- "o.mi.rf", "date_dtd",
- "o.mi.rf.date_dtd.st", "1007-01-01T23:59:59Z",
- "o.mi.rf.date_dtd.e", "1044-01-01T23:59:59Z",
- "o.mi.rf.date_dtd.g", "+2YEARS,+7YEARS",
- "o.mi.rf.date_dtd.ib", "lower",
- "o.mi.rf.date_dtd.ib", "edge",
- "o.mi.rf.date_dtd.ib", "outer",
- "o.mi.rf.date_dtd.or", "all",
-
- "o.mf.s.sum", "sum(float_fd)",
- "o.mf.s.mean", "mean(float_fd)",
- "o.mf.s.median", "median(float_fd)",
- "o.mf.s.count", "count(float_fd)",
- "o.mf.rf", "long_ld",
- "o.mf.rf.long_ld.st", "0",
- "o.mf.rf.long_ld.e", "29",
- "o.mf.rf.long_ld.g", "1,4",
- "o.mf.rf.long_ld.ib", "all",
- "o.mf.rf.long_ld.or", "all",
- "o.mf.rf", "double_dd",
- "o.mf.rf.double_dd.st", "4",
- "o.mf.rf.double_dd.e", "47",
- "o.mf.rf.double_dd.g", "2,3,11",
- "o.mf.rf.double_dd.ib", "edge",
- "o.mf.rf.double_dd.or", "all",
- "o.mf.rf", "date_dtd",
- "o.mf.rf.date_dtd.st", "1004-01-01T23:59:59Z",
- "o.mf.rf.date_dtd.e", "1046-01-01T23:59:59Z",
- "o.mf.rf.date_dtd.g", "+4YEARS,+5YEARS",
- "o.mf.rf.date_dtd.ib", "upper",
- "o.mf.rf.date_dtd.ib", "edge",
- "o.mf.rf.date_dtd.or", "all"
- };
- NamedList<Object> response = queryCloudAnalytics(params);
- String responseStr = response.toString();
-
- //Int Long
- ArrayList<Double> intLong = getValueList(response, "mi", "rangeFacets", "long_ld", "sum", false);
- ArrayList<Double> intLongTest = calculateNumberStat(transformLists(intLongTestStart, 5, 30, "4,2,6,3"
- , false, true, false, false, false), "sum");
- assertEquals(responseStr, intLong,intLongTest);
- //Int Double
- ArrayList<Double> intDouble = getValueList(response, "mi", "rangeFacets", "double_dd", "mean", false);
- ArrayList<Double> intDoubleTest = calculateNumberStat(transformLists(intDoubleTestStart, 3, 39, "3,1,7"
- , false, false, true, false, true), "mean");
- assertEquals(responseStr, intDouble,intDoubleTest);
- //Int Date
- ArrayList<Long> intDate = getValueList(response, "mi", "rangeFacets", "date_dtd", "count", false);
- ArrayList<Long> intDateTest = (ArrayList<Long>)calculateStat(transformLists(intDateTestStart, 7, 44, "2,7"
- , false, true, false, true, true), "count");
- assertEquals(responseStr, intDate,intDateTest);
-
- //Float Long
- ArrayList<Double> floatLong = getValueList(response, "mf", "rangeFacets", "long_ld", "median", false);
- ArrayList<Double> floatLongTest = calculateNumberStat(transformLists(floatLongTestStart, 0, 29, "1,4"
- , false, true, true, true, true), "median");;
- assertEquals(responseStr, floatLong,floatLongTest);
- //Float Double
- ArrayList<Long> floatDouble = getValueList(response, "mf", "rangeFacets", "double_dd", "count", false);
- ArrayList<Long> floatDoubleTest = (ArrayList<Long>)calculateStat(transformLists(floatDoubleTestStart, 4, 47, "2,3,11"
- , false, false, false, true, false), "count");
- assertEquals(responseStr, floatDouble,floatDoubleTest);
- }
-
- private <T> ArrayList<ArrayList<T>> transformLists(ArrayList<ArrayList<T>> listsStart, int start, int end, int gap
- , boolean hardend, boolean incLow, boolean incUp, boolean incEdge, boolean incOut) {
- int off = (end-start)%gap;
- if (!hardend && off>0) {
- end+=gap-off;
- }
-
- ArrayList<ArrayList<T>> lists = new ArrayList<>();
- ArrayList<T> between = new ArrayList<>();
- if (incLow && incUp) {
- for (int i = start; i<end && i<listsStart.size(); i+=gap) {
- ArrayList<T> list = new ArrayList<>();
- for (int j = i; j<=i+gap && j<=end && j<listsStart.size(); j++) {
- list.addAll(listsStart.get(j));
- }
- lists.add(list);
- }
- for (int i = start; i<listsStart.size() && i<=end; i++) {
- between.addAll(listsStart.get(i));
- }
- } else if (incLow && !incUp) {
- for (int i = start; i<end && i<listsStart.size(); i+=gap) {
- ArrayList<T> list = new ArrayList<>();
- for (int j = i; j<i+gap && j<end && j<listsStart.size(); j++) {
- list.addAll(listsStart.get(j));
- }
- lists.add(list);
- }
- for (int i = start; i<listsStart.size() && i<end; i++) {
- between.addAll(listsStart.get(i));
- }
- } else if (!incLow && incUp) {
- for (int i = start; i<end && i<listsStart.size(); i+=gap) {
- ArrayList<T> list = new ArrayList<>();
- for (int j = i+1; j<=i+gap && j<=end && j<listsStart.size(); j++) {
- list.addAll(listsStart.get(j));
- }
- lists.add(list);
- }
- for (int i = start+1; i<listsStart.size() && i<=end; i++) {
- between.addAll(listsStart.get(i));
- }
- } else {
- for (int i = start; i<end && i<listsStart.size(); i+=gap) {
- ArrayList<T> list = new ArrayList<>();
- for (int j = i+1; j<i+gap && j<end && j<listsStart.size(); j++) {
- list.addAll(listsStart.get(j));
- }
- lists.add(list);
- }
- for (int i = start+1; i<listsStart.size() && i<end; i++) {
- between.addAll(listsStart.get(i));
- }
- }
-
- if (incEdge && !incLow && start>=0) {
- lists.get(0).addAll(listsStart.get(start));
- between.addAll(listsStart.get(start));
- }
- if (incEdge && !incUp && end<listsStart.size()) {
- lists.get(lists.size()-1).addAll(listsStart.get(end));
- between.addAll(listsStart.get(end));
- }
- ArrayList<T> before = new ArrayList<>();
- ArrayList<T> after = new ArrayList<>();
- if (incOut || !(incLow||incEdge)) {
- for (int i = 0; i<=start; i++) {
- before.addAll(listsStart.get(i));
- }
- } else {
- for (int i = 0; i<start; i++) {
- before.addAll(listsStart.get(i));
- }
- }
- if (incOut || !(incUp||incEdge)) {
- for (int i = end; i<listsStart.size(); i++) {
- after.addAll(listsStart.get(i));
- }
- }
- else {
- for (int i = end+1; i<listsStart.size(); i++) {
- after.addAll(listsStart.get(i));
- }
- }
- lists.add(before);
- lists.add(after);
- lists.add(between);
- return lists;
- }
-
- private <T> ArrayList<ArrayList<T>> transformLists(ArrayList<ArrayList<T>> listsStart, int start, int end, String gapString
- , boolean hardend, boolean incLow, boolean incUp, boolean incEdge, boolean incOut) {
- String[] stringGaps = gapString.split(",");
- int[] gaps = new int[stringGaps.length];
- for (int i = 0; i<gaps.length; i++) {
- gaps[i] = Integer.parseInt(stringGaps[i]);
- }
- int bigGap = 0;
- int last = gaps[gaps.length-1];
- for (int i = 0; i<gaps.length-1; i++) {
- bigGap += gaps[i];
- }
- int off = (end-start-bigGap)%last;
- if (!hardend && off>0) {
- end+=last-off;
- }
-
- ArrayList<ArrayList<T>> lists = new ArrayList<>();
- ArrayList<T> between = new ArrayList<>();
- int gap = 0;
- int gapCounter = 0;
- if (incLow && incUp) {
- for (int i = start; i<end && i<listsStart.size(); i+=gap) {
- if (gapCounter<gaps.length) {
- gap = gaps[gapCounter++];
- }
- ArrayList<T> list = new ArrayList<>();
- for (int j = i; j<=i+gap && j<=end && j<listsStart.size(); j++) {
- list.addAll(listsStart.get(j));
- }
- lists.add(list);
- }
- for (int i = start; i<listsStart.size() && i<=end; i++) {
- between.addAll(listsStart.get(i));
- }
- } else if (incLow && !incUp) {
- for (int i = start; i<end && i<listsStart.size(); i+=gap) {
- if (gapCounter<gaps.length) {
- gap = gaps[gapCounter++];
- }
- ArrayList<T> list = new ArrayList<>();
- for (int j = i; j<i+gap && j<end && j<listsStart.size(); j++) {
- list.addAll(listsStart.get(j));
- }
- lists.add(list);
- }
- for (int i = start; i<listsStart.size() && i<end; i++) {
- between.addAll(listsStart.get(i));
- }
- } else if (!incLow && incUp) {
- for (int i = start; i<end && i<listsStart.size(); i+=gap) {
- if (gapCounter<gaps.length) {
- gap = gaps[gapCounter++];
- }
- ArrayList<T> list = new ArrayList<>();
- for (int j = i+1; j<=i+gap && j<=end && j<listsStart.size(); j++) {
- list.addAll(listsStart.get(j));
- }
- lists.add(list);
- }
- for (int i = start+1; i<listsStart.size() && i<=end; i++) {
- between.addAll(listsStart.get(i));
- }
- } else {
- for (int i = start; i<end && i<listsStart.size(); i+=gap) {
- if (gapCounter<gaps.length) {
- gap = gaps[gapCounter++];
- }
- ArrayList<T> list = new ArrayList<>();
- for (int j = i+1; j<i+gap && j<end && j<listsStart.size(); j++) {
- list.addAll(listsStart.get(j));
- }
- lists.add(list);
- }
- for (int i = start+1; i<listsStart.size() && i<end; i++) {
- between.addAll(listsStart.get(i));
- }
- }
-
- if (incEdge && !incLow && start>=0) {
- lists.get(0).addAll(listsStart.get(start));
- between.addAll(listsStart.get(start));
- }
- if (incEdge && !incUp && end<listsStart.size()) {
- lists.get(lists.size()-1).addAll(listsStart.get(end));
- between.addAll(listsStart.get(end));
- }
- ArrayList<T> before = new ArrayList<>();
- ArrayList<T> after = new ArrayList<>();
- if (incOut || !(incLow||incEdge)) {
- for (int i = 0; i<=start; i++) {
- before.addAll(listsStart.get(i));
- }
- } else {
- for (int i = 0; i<start; i++) {
- before.addAll(listsStart.get(i));
- }
- }
- if (incOut || !(incUp||incEdge)) {
- for (int i = end; i<listsStart.size(); i++) {
- after.addAll(listsStart.get(i));
- }
- }
- else {
- for (int i = end+1; i<listsStart.size(); i++) {
- after.addAll(listsStart.get(i));
- }
- }
- lists.add(before);
- lists.add(after);
- lists.add(between);
- return lists;
- }
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/RangeFacetTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/RangeFacetTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/RangeFacetTest.java
index 24a7ea2..9f482bc 100644
--- a/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/RangeFacetTest.java
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/RangeFacetTest.java
@@ -16,402 +16,298 @@
*/
package org.apache.solr.analytics.facet;
-
import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import org.junit.BeforeClass;
import org.junit.Test;
-
-public class RangeFacetTest extends AbstractAnalyticsFacetTest {
- static String fileName = "rangeFacets.txt";
-
- public static final int INT = 71;
- public static final int LONG = 36;
- public static final int FLOAT = 93;
- public static final int DOUBLE = 48;
- public static final int DATE = 52;
- public static final int STRING = 28;
- public static final int NUM_LOOPS = 100;
-
- //INT
- static ArrayList<ArrayList<Integer>> intLongTestStart;
- static ArrayList<ArrayList<Integer>> intDoubleTestStart;
- static ArrayList<ArrayList<Integer>> intDateTestStart;
-
- //FLOAT
- static ArrayList<ArrayList<Float>> floatLongTestStart;
- static ArrayList<ArrayList<Float>> floatDoubleTestStart;
- static ArrayList<ArrayList<Float>> floatDateTestStart;
+public class RangeFacetTest extends SolrAnalyticsFacetTestCase {
@BeforeClass
- public static void beforeClass() throws Exception {
- initCore("solrconfig-analytics.xml","schema-analytics.xml");
- h.update("<delete><query>*:*</query></delete>");
-
- //INT
- intLongTestStart = new ArrayList<>();
- intDoubleTestStart = new ArrayList<>();
- intDateTestStart = new ArrayList<>();
-
- //FLOAT
- floatLongTestStart = new ArrayList<>();
- floatDoubleTestStart = new ArrayList<>();
- floatDateTestStart = new ArrayList<>();
-
+ public static void populate() throws Exception {
for (int j = 0; j < NUM_LOOPS; ++j) {
int i = j%INT;
long l = j%LONG;
float f = j%FLOAT;
double d = j%DOUBLE;
- int dt = j%DATE;
- int s = j%STRING;
- assertU(adoc("id", "1000" + j, "int_id", "" + i, "long_ld", "" + l, "float_fd", "" + f,
- "double_dd", "" + d, "date_dtd", (1000+dt) + "-01-01T23:59:59Z", "string_sd", "abc" + s));
- //Longs
- if (j-LONG<0) {
- ArrayList<Integer> list1 = new ArrayList<>();
- list1.add(i);
- intLongTestStart.add(list1);
- ArrayList<Float> list2 = new ArrayList<>();
- list2.add(f);
- floatLongTestStart.add(list2);
- } else {
- intLongTestStart.get((int)l).add(i);
- floatLongTestStart.get((int)l).add(f);
+ String dt = (1800+j%DATE) + "-12-31T23:59:59Z";
+ String dtm = (1800+j%DATE + 10) + "-12-31T23:59:59Z";
+ String s = "str" + (j%STRING);
+ List<String> fields = new ArrayList<>();
+ fields.add("id"); fields.add("1000"+j);
+
+ if ( i != 0 ) {
+ fields.add("int_i"); fields.add("" + i);
+ fields.add("int_im"); fields.add("" + i);
+ fields.add("int_im"); fields.add("" + (i+10));
+ }
+
+ if ( l != 0l ) {
+ fields.add("long_l"); fields.add("" + l);
+ fields.add("long_lm"); fields.add("" + l);
+ fields.add("long_lm"); fields.add("" + (l+10));
}
- //Doubles
- if (j-DOUBLE<0) {
- ArrayList<Integer> list1 = new ArrayList<>();
- list1.add(i);
- intDoubleTestStart.add(list1);
- ArrayList<Float> list2 = new ArrayList<>();
- list2.add(f);
- floatDoubleTestStart.add(list2);
- } else {
- intDoubleTestStart.get((int)d).add(i);
- floatDoubleTestStart.get((int)d).add(f);
+
+ if ( f != 0.0f ) {
+ fields.add("float_f"); fields.add("" + f);
+ fields.add("float_fm"); fields.add("" + f);
+ fields.add("float_fm"); fields.add("" + (f+10));
}
- //Dates
- if (j-DATE<0) {
- ArrayList<Integer> list1 = new ArrayList<>();
- list1.add(i);
- intDateTestStart.add(list1);
- ArrayList<Float> list2 = new ArrayList<>();
- list2.add(f);
- floatDateTestStart.add(list2);
- } else {
- intDateTestStart.get(dt).add(i);
- floatDateTestStart.get(dt).add(f);
+
+ if ( d != 0.0d ) {
+ fields.add("double_d"); fields.add("" + d);
+ fields.add("double_dm"); fields.add("" + d);
+ fields.add("double_dm"); fields.add("" + (d+10));
}
- if (usually()) {
- assertU(commit()); // to have several segments
+ if ( (j%DATE) != 0 ) {
+ fields.add("date_dt"); fields.add(dt);
+ fields.add("date_dtm"); fields.add(dt);
+ fields.add("date_dtm"); fields.add(dtm);
}
+
+ if ( (j%STRING) != 0 ) {
+ fields.add("string_s"); fields.add(s);
+ fields.add("string_sm"); fields.add(s);
+ fields.add("string_sm"); fields.add(s + "_second");
+ }
+
+ addDoc(fields);
}
+ commitDocs();
+ }
+
+ static public final int INT = 7;
+ static public final int LONG = 2;
+ static public final int FLOAT = 6;
+ static public final int DOUBLE = 5;
+ static public final int DATE = 3;
+ static public final int STRING = 4;
+ static public final int NUM_LOOPS = 20;
+
+ @Test
+ public void intRangeHardEndTest() throws Exception {
+ Map<String, String> expressions = new HashMap<>();
+ expressions.put("mean", "mean(float_f)");
+ expressions.put("count", "count(string_sm)");
- assertU(commit());
+ // Hard end on
+ addFacet("hard_end_on", "{ 'type':'range', "
+ + " 'field': 'int_im', "
+ + " 'start': '2', "
+ + " 'end' : '13', "
+ + " 'gaps' : ['2', '5', '3'], "
+ + " 'hardend' : true }");
+
+ addFacetValue("[2 TO 4)");
+ addFacetResult("mean", 3.5);
+ addFacetResult("count", 10L);
- setResponse(h.query(request(fileToStringArr(RangeFacetTest.class, fileName))));
- }
+ addFacetValue("[4 TO 9)");
+ addFacetResult("mean", 16.0/5.0);
+ addFacetResult("count", 12L);
+
+ addFacetValue("[9 TO 12)");
+ addFacetResult("mean", 2.0);
+ addFacetResult("count", 4L);
+
+ addFacetValue("[12 TO 13)");
+ addFacetResult("mean", 3.0);
+ addFacetResult("count", 4L);
+
+ // Hard end off
+ addFacet("hard_end_off", "{ 'type':'range', "
+ + " 'field': 'int_im', "
+ + " 'start': '2', "
+ + " 'end' : '13', "
+ + " 'gaps' : ['2', '5', '3'], "
+ + " 'hardend' : false }");
- @SuppressWarnings("unchecked")
- @Test
- public void rangeTest() throws Exception {
-
- //Int Long
- ArrayList<Long> intLong = getLongList("ri", "rangeFacets", "long_ld", "long", "count");
- ArrayList<Long> intLongTest = calculateStat(transformLists(intLongTestStart, 5, 30, 5
- , false, true, false, false, false), "count");
- assertEquals(getRawResponse(), intLong,intLongTest);
- //Int Double
- ArrayList<Double> intDouble = getDoubleList("ri", "rangeFacets", "double_dd", "double", "mean");
- ArrayList<Double> intDoubleTest = calculateNumberStat(transformLists(intDoubleTestStart, 3, 39, 7
- , false, false, true, false, true), "mean");
- assertEquals(getRawResponse(), intDouble,intDoubleTest);
- //Int Date
- ArrayList<Long> intDate = getLongList("ri", "rangeFacets", "date_dtd", "long", "count");
- ArrayList<Long> intDateTest = (ArrayList<Long>)calculateStat(transformLists(intDateTestStart, 7, 44, 7
- , false, true, false, true, true), "count");
- assertEquals(getRawResponse(), intDate,intDateTest);
-
- //Float Long
- ArrayList<Double> floatLong = getDoubleList("rf", "rangeFacets", "long_ld", "double", "median");
- ArrayList<Double> floatLongTest = calculateNumberStat(transformLists(floatLongTestStart, 0, 29, 4
- , false, true, true, true, true), "median");
- assertEquals(getRawResponse(), floatLong,floatLongTest);
- //Float Double
- ArrayList<Long> floatDouble = getLongList("rf", "rangeFacets", "double_dd", "long", "count");
- ArrayList<Long> floatDoubleTest = (ArrayList<Long>)calculateStat(transformLists(floatDoubleTestStart, 4, 47, 11
- , false, false, false, true, false), "count");
- assertEquals(getRawResponse(), floatDouble,floatDoubleTest);
+ addFacetValue("[2 TO 4)");
+ addFacetResult("mean", 3.5);
+ addFacetResult("count", 10L);
+
+ addFacetValue("[4 TO 9)");
+ addFacetResult("mean", 16.0/5.0);
+ addFacetResult("count", 12L);
+
+ addFacetValue("[9 TO 12)");
+ addFacetResult("mean", 2.0);
+ addFacetResult("count", 4L);
+
+ addFacetValue("[12 TO 15)");
+ addFacetResult("mean", 30.0/8.0);
+ addFacetResult("count", 14L);
+
+ testGrouping(expressions);
}
-
- @SuppressWarnings("unchecked")
@Test
- public void hardendRangeTest() throws Exception {
- //Int Long
- ArrayList<Double> intLong = getDoubleList("hi", "rangeFacets", "long_ld", "double", "sum");
- ArrayList<Double> intLongTest = calculateNumberStat(transformLists(intLongTestStart, 5, 30, 5
- , true, true, false, false, false), "sum");
- assertEquals(getRawResponse(), intLong,intLongTest);
- //Int Double
- ArrayList<Double> intDouble = getDoubleList("hi", "rangeFacets", "double_dd", "double", "mean");
- ArrayList<Double> intDoubleTest = calculateNumberStat(transformLists(intDoubleTestStart, 3, 39, 7
- , true, false, true, false, true), "mean");
- assertEquals(getRawResponse(), intDouble,intDoubleTest);
- //Int Date
- ArrayList<Long> intDate = getLongList("hi", "rangeFacets", "date_dtd", "long", "count");
- ArrayList<Long> intDateTest = (ArrayList<Long>)calculateStat(transformLists(intDateTestStart, 7, 44, 7
- , true, true, false, true, true), "count");
- assertEquals(getRawResponse(), intDate,intDateTest);
-
- //Float Long
- ArrayList<Double> floatLong = getDoubleList("hf", "rangeFacets", "long_ld", "double", "median");
- ArrayList<Double> floatLongTest = calculateNumberStat(transformLists(floatLongTestStart, 0, 29, 4
- , true, true, true, true, true), "median");
- assertEquals(getRawResponse(), floatLong,floatLongTest);
- //Float Double
- ArrayList<Long> floatDouble = getLongList("hf", "rangeFacets", "double_dd", "long", "count");
- ArrayList<Long> floatDoubleTest = (ArrayList<Long>)calculateStat(transformLists(floatDoubleTestStart, 4, 47, 11
- , true, false, false, true, false), "count");
- assertEquals(getRawResponse(), floatDouble,floatDoubleTest);
+ public void doubleOthersTest() throws Exception {
+ Map<String, String> expressions = new HashMap<>();
+ expressions.put("mean", "mean(float_f)");
+ expressions.put("count", "count(string_sm)");
+
+ addFacet("before_between", "{ 'type':'range', "
+ + " 'field': 'double_d', "
+ + " 'start': '2', "
+ + " 'end' : '4', "
+ + " 'gaps' : ['1'], "
+ + " 'others' : ['before', 'between'] }");
+
+ addFacetValue("[2.0 TO 3.0)");
+ addFacetResult("mean", 8.0/3.0);
+ addFacetResult("count", 6L);
+
+ addFacetValue("[3.0 TO 4.0)");
+ addFacetResult("mean", 2.0);
+ addFacetResult("count", 6L);
+
+ addFacetValue("(* TO 2.0)");
+ addFacetResult("mean", 10.0/3.0);
+ addFacetResult("count", 6L);
+
+ addFacetValue("[2.0 TO 4.0)");
+ addFacetResult("mean", 14.0/6.0);
+ addFacetResult("count", 12L);
+
+ addFacet("after", "{ 'type':'range', "
+ + " 'field': 'double_d', "
+ + " 'start': '2', "
+ + " 'end' : '4', "
+ + " 'gaps' : ['1'], "
+ + " 'others' : ['after'] }");
+
+ addFacetValue("[2.0 TO 3.0)");
+ addFacetResult("mean", 8.0/3.0);
+ addFacetResult("count", 6L);
+
+ addFacetValue("[3.0 TO 4.0)");
+ addFacetResult("mean", 2.0);
+ addFacetResult("count", 6L);
+
+ addFacetValue("[4.0 TO *)");
+ addFacetResult("mean", 2.5);
+ addFacetResult("count", 6L);
+
+ testGrouping(expressions);
}
- @SuppressWarnings("unchecked")
@Test
- public void multiGapTest() throws Exception {
- //Int Long
- ArrayList<Double> intLong = getDoubleList("mi", "rangeFacets", "long_ld", "double", "sum");
- ArrayList<Double> intLongTest = calculateNumberStat(transformLists(intLongTestStart, 5, 30, "4,2,6,3"
- , false, true, false, false, false), "sum");
- assertEquals(getRawResponse(), intLong,intLongTest);
- //Int Double
- ArrayList<Double> intDouble = getDoubleList("mi", "rangeFacets", "double_dd", "double", "mean");
- ArrayList<Double> intDoubleTest = calculateNumberStat(transformLists(intDoubleTestStart, 3, 39, "3,1,7"
- , false, false, true, false, true), "mean");
- assertEquals(getRawResponse(), intDouble,intDoubleTest);
- //Int Date
- ArrayList<Long> intDate = getLongList("mi", "rangeFacets", "date_dtd", "long", "count");
- ArrayList<Long> intDateTest = (ArrayList<Long>)calculateStat(transformLists(intDateTestStart, 7, 44, "2,7"
- , false, true, false, true, true), "count");
- assertEquals(getRawResponse(), intDate,intDateTest);
-
- //Float Long
- ArrayList<Double> floatLong = getDoubleList("mf", "rangeFacets", "long_ld", "double", "median");
- ArrayList<Double> floatLongTest = calculateNumberStat(transformLists(floatLongTestStart, 0, 29, "1,4"
- , false, true, true, true, true), "median");;
- assertEquals(getRawResponse(), floatLong,floatLongTest);
- //Float Double
- ArrayList<Long> floatDouble = getLongList("mf", "rangeFacets", "double_dd", "long", "count");
- ArrayList<Long> floatDoubleTest = (ArrayList<Long>)calculateStat(transformLists(floatDoubleTestStart, 4, 47, "2,3,11"
- , false, false, false, true, false), "count");
- assertEquals(getRawResponse(), floatDouble,floatDoubleTest);
+ public void dateIncludeTest() throws Exception {
+ Map<String, String> expressions = new HashMap<>();
+ expressions.put("mean", "mean(float_f)");
+ expressions.put("count", "count(string_sm)");
+
+ addFacet("lower_upper", "{ 'type':'range', "
+ + " 'field': 'date_dt', "
+ + " 'start': '1801-12-31T23:59:59Z', "
+ + " 'end' : '1803-12-31T23:59:59Z', "
+ + " 'gaps' : ['+1YEAR'], "
+ + " 'include' : ['lower', 'upper'] }");
+
+ addFacetValue("[1801-12-31T23:59:59Z TO 1802-12-31T23:59:59Z]");
+ addFacetResult("mean", 37.0/13.0);
+ addFacetResult("count", 20L);
+
+ addFacetValue("[1802-12-31T23:59:59Z TO 1803-12-31T23:59:59Z]");
+ addFacetResult("mean", 3.5);
+ addFacetResult("count", 10L);
+
+ testGrouping(expressions);
+
+ addFacet("lower_upper", "{ 'type':'range', "
+ + " 'field': 'date_dt', "
+ + " 'start': '1801-12-31T23:59:59Z', "
+ + " 'end' : '1803-12-31T23:59:59Z', "
+ + " 'gaps' : ['+1YEAR'], "
+ + " 'include' : ['lower','edge'] }");
+
+ addFacetValue("[1801-12-31T23:59:59Z TO 1802-12-31T23:59:59Z)");
+ addFacetResult("mean", 16.0/7.0);
+ addFacetResult("count", 10L);
+
+ addFacetValue("[1802-12-31T23:59:59Z TO 1803-12-31T23:59:59Z]");
+ addFacetResult("mean", 3.5);
+ addFacetResult("count", 10L);
+
+ testGrouping(expressions);
}
- private <T> ArrayList<ArrayList<T>> transformLists(ArrayList<ArrayList<T>> listsStart, int start, int end, int gap
- , boolean hardend, boolean incLow, boolean incUp, boolean incEdge, boolean incOut) {
- int off = (end-start)%gap;
- if (!hardend && off>0) {
- end+=gap-off;
- }
+ @Test
+ public void floatIncludeOuterTest() throws Exception {
+ Map<String, String> expressions = new HashMap<>();
+ expressions.put("mean", "mean(int_i)");
+ expressions.put("count", "count(string_sm)");
+
+ addFacet("include_outer", "{ 'type':'range', "
+ + " 'field': 'float_f', "
+ + " 'start': '1', "
+ + " 'end' : '5', "
+ + " 'gaps' : ['2'], "
+ + " 'include' : ['outer'], "
+ + " 'others' : ['all'] }");
- ArrayList<ArrayList<T>> lists = new ArrayList<>();
- ArrayList<T> between = new ArrayList<>();
- if (incLow && incUp) {
- for (int i = start; i<end && i<listsStart.size(); i+=gap) {
- ArrayList<T> list = new ArrayList<>();
- for (int j = i; j<=i+gap && j<=end && j<listsStart.size(); j++) {
- list.addAll(listsStart.get(j));
- }
- lists.add(list);
- }
- for (int i = start; i<listsStart.size() && i<=end; i++) {
- between.addAll(listsStart.get(i));
- }
- } else if (incLow && !incUp) {
- for (int i = start; i<end && i<listsStart.size(); i+=gap) {
- ArrayList<T> list = new ArrayList<>();
- for (int j = i; j<i+gap && j<end && j<listsStart.size(); j++) {
- list.addAll(listsStart.get(j));
- }
- lists.add(list);
- }
- for (int i = start; i<listsStart.size() && i<end; i++) {
- between.addAll(listsStart.get(i));
- }
- } else if (!incLow && incUp) {
- for (int i = start; i<end && i<listsStart.size(); i+=gap) {
- ArrayList<T> list = new ArrayList<>();
- for (int j = i+1; j<=i+gap && j<=end && j<listsStart.size(); j++) {
- list.addAll(listsStart.get(j));
- }
- lists.add(list);
- }
- for (int i = start+1; i<listsStart.size() && i<=end; i++) {
- between.addAll(listsStart.get(i));
- }
- } else {
- for (int i = start; i<end && i<listsStart.size(); i+=gap) {
- ArrayList<T> list = new ArrayList<>();
- for (int j = i+1; j<i+gap && j<end && j<listsStart.size(); j++) {
- list.addAll(listsStart.get(j));
- }
- lists.add(list);
- }
- for (int i = start+1; i<listsStart.size() && i<end; i++) {
- between.addAll(listsStart.get(i));
- }
- }
+ addFacetValue("(1.0 TO 3.0)");
+ addFacetResult("mean", 1.5);
+ addFacetResult("count", 4L);
+
+ addFacetValue("(3.0 TO 5.0)");
+ addFacetResult("mean", 3.0);
+ addFacetResult("count", 2L);
- if (incEdge && !incLow && start>=0) {
- lists.get(0).addAll(listsStart.get(start));
- between.addAll(listsStart.get(start));
- }
- if (incEdge && !incUp && end<listsStart.size()) {
- lists.get(lists.size()-1).addAll(listsStart.get(end));
- between.addAll(listsStart.get(end));
- }
- ArrayList<T> before = new ArrayList<>();
- ArrayList<T> after = new ArrayList<>();
- if (incOut || !(incLow||incEdge)) {
- for (int i = 0; i<=start; i++) {
- before.addAll(listsStart.get(i));
- }
- } else {
- for (int i = 0; i<start; i++) {
- before.addAll(listsStart.get(i));
- }
- }
- if (incOut || !(incUp||incEdge)) {
- for (int i = end; i<listsStart.size(); i++) {
- after.addAll(listsStart.get(i));
- }
- }
- else {
- for (int i = end+1; i<listsStart.size(); i++) {
- after.addAll(listsStart.get(i));
- }
- }
- lists.add(before);
- lists.add(after);
- lists.add(between);
- return lists;
+ addFacetValue("(* TO 1.0]");
+ addFacetResult("mean", 4.0);
+ addFacetResult("count", 8L);
+
+ addFacetValue("[5.0 TO *)");
+ addFacetResult("mean", 4.0);
+ addFacetResult("count", 6L);
+
+ addFacetValue("(1.0 TO 5.0)");
+ addFacetResult("mean", 18.0/8.0);
+ addFacetResult("count", 12L);
+
+ testGrouping(expressions);
}
- private <T> ArrayList<ArrayList<T>> transformLists(ArrayList<ArrayList<T>> listsStart, int start, int end, String gapString
- , boolean hardend, boolean incLow, boolean incUp, boolean incEdge, boolean incOut) {
- String[] stringGaps = gapString.split(",");
- int[] gaps = new int[stringGaps.length];
- for (int i = 0; i<gaps.length; i++) {
- gaps[i] = Integer.parseInt(stringGaps[i]);
- }
- int bigGap = 0;
- int last = gaps[gaps.length-1];
- for (int i = 0; i<gaps.length-1; i++) {
- bigGap += gaps[i];
- }
- int off = (end-start-bigGap)%last;
- if (!hardend && off>0) {
- end+=last-off;
- }
+ @Test
+ public void floatIncludeAllTest() throws Exception {
+ Map<String, String> expressions = new HashMap<>();
+ expressions.put("mean", "mean(int_i)");
+ expressions.put("count", "count(string_sm)");
- ArrayList<ArrayList<T>> lists = new ArrayList<>();
- ArrayList<T> between = new ArrayList<>();
- int gap = 0;
- int gapCounter = 0;
- if (incLow && incUp) {
- for (int i = start; i<end && i<listsStart.size(); i+=gap) {
- if (gapCounter<gaps.length) {
- gap = gaps[gapCounter++];
- }
- ArrayList<T> list = new ArrayList<>();
- for (int j = i; j<=i+gap && j<=end && j<listsStart.size(); j++) {
- list.addAll(listsStart.get(j));
- }
- lists.add(list);
- }
- for (int i = start; i<listsStart.size() && i<=end; i++) {
- between.addAll(listsStart.get(i));
- }
- } else if (incLow && !incUp) {
- for (int i = start; i<end && i<listsStart.size(); i+=gap) {
- if (gapCounter<gaps.length) {
- gap = gaps[gapCounter++];
- }
- ArrayList<T> list = new ArrayList<>();
- for (int j = i; j<i+gap && j<end && j<listsStart.size(); j++) {
- list.addAll(listsStart.get(j));
- }
- lists.add(list);
- }
- for (int i = start; i<listsStart.size() && i<end; i++) {
- between.addAll(listsStart.get(i));
- }
- } else if (!incLow && incUp) {
- for (int i = start; i<end && i<listsStart.size(); i+=gap) {
- if (gapCounter<gaps.length) {
- gap = gaps[gapCounter++];
- }
- ArrayList<T> list = new ArrayList<>();
- for (int j = i+1; j<=i+gap && j<=end && j<listsStart.size(); j++) {
- list.addAll(listsStart.get(j));
- }
- lists.add(list);
- }
- for (int i = start+1; i<listsStart.size() && i<=end; i++) {
- between.addAll(listsStart.get(i));
- }
- } else {
- for (int i = start; i<end && i<listsStart.size(); i+=gap) {
- if (gapCounter<gaps.length) {
- gap = gaps[gapCounter++];
- }
- ArrayList<T> list = new ArrayList<>();
- for (int j = i+1; j<i+gap && j<end && j<listsStart.size(); j++) {
- list.addAll(listsStart.get(j));
- }
- lists.add(list);
- }
- for (int i = start+1; i<listsStart.size() && i<end; i++) {
- between.addAll(listsStart.get(i));
- }
- }
+ addFacet("include_all", "{ 'type':'range', "
+ + " 'field': 'float_f', "
+ + " 'start': '1', "
+ + " 'end' : '5', "
+ + " 'gaps' : ['2'], "
+ + " 'include' : ['all'], "
+ + " 'others' : ['all'] }");
+
+ addFacetValue("[1.0 TO 3.0]");
+ addFacetResult("mean", 21.0/8.0);
+ addFacetResult("count", 18L);
+
+ addFacetValue("[3.0 TO 5.0]");
+ addFacetResult("mean", 3.0);
+ addFacetResult("count", 14L);
- if (incEdge && !incLow && start>=0) {
- lists.get(0).addAll(listsStart.get(start));
- between.addAll(listsStart.get(start));
- }
- if (incEdge && !incUp && end<listsStart.size()) {
- lists.get(lists.size()-1).addAll(listsStart.get(end));
- between.addAll(listsStart.get(end));
- }
- ArrayList<T> before = new ArrayList<>();
- ArrayList<T> after = new ArrayList<>();
- if (incOut || !(incLow||incEdge)) {
- for (int i = 0; i<=start; i++) {
- before.addAll(listsStart.get(i));
- }
- } else {
- for (int i = 0; i<start; i++) {
- before.addAll(listsStart.get(i));
- }
- }
- if (incOut || !(incUp||incEdge)) {
- for (int i = end; i<listsStart.size(); i++) {
- after.addAll(listsStart.get(i));
- }
- }
- else {
- for (int i = end+1; i<listsStart.size(); i++) {
- after.addAll(listsStart.get(i));
- }
- }
- lists.add(before);
- lists.add(after);
- lists.add(between);
- return lists;
+ addFacetValue("(* TO 1.0]");
+ addFacetResult("mean", 4.0);
+ addFacetResult("count", 8L);
+
+ addFacetValue("[5.0 TO *)");
+ addFacetResult("mean", 4.0);
+ addFacetResult("count", 6L);
+
+ addFacetValue("[1.0 TO 5.0]");
+ addFacetResult("mean", 3.0);
+ addFacetResult("count", 26L);
+
+ testGrouping(expressions);
}
-
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/SolrAnalyticsFacetTestCase.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/SolrAnalyticsFacetTestCase.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/SolrAnalyticsFacetTestCase.java
new file mode 100644
index 0000000..22decd7
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/SolrAnalyticsFacetTestCase.java
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.facet;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.solr.analytics.SolrAnalyticsTestCase;
+import org.junit.Before;
+
+public class SolrAnalyticsFacetTestCase extends SolrAnalyticsTestCase {
+
+ private List<FVP> facetResults;
+ private Map<String, List<FVP>> results = new HashMap<>();
+ private Map<String, String> facets = new HashMap<>();
+ private FVP fvp;
+ private int fvp_num;
+
+ @Before
+ protected void initData() {
+ results = new HashMap<>();
+ facets = new HashMap<>();
+ }
+
+ protected void addFacet(String name, String json) {
+ facets.put(name, json);
+ facetResults = new ArrayList<>();
+ results.put(name, facetResults);
+ fvp_num = 0;
+ }
+
+ protected void addFacetValue(String value) {
+ fvp = new FVP(fvp_num++, value, new HashMap<>());
+ facetResults.add(fvp);
+ }
+
+ protected void addFacetResult(String expr, Comparable<?> result) {
+ fvp.expectedResults.put(expr, result);
+ }
+
+ protected void testGrouping(Map<String,String> expressions) {
+ try {
+ testGrouping("grouping", expressions, facets, results);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ protected void testGrouping(Map<String,String> expressions, boolean sortAscending) {
+ try {
+ testGrouping("grouping", expressions, facets, results, sortAscending);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ protected void testGrouping(Map<String,String> expressions, String sortExpression, boolean sortAscending) {
+ try {
+ testGrouping("grouping", expressions, facets, results, sortExpression, sortAscending);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/ValueFacetTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/ValueFacetTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/ValueFacetTest.java
new file mode 100644
index 0000000..da117de
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/ValueFacetTest.java
@@ -0,0 +1,433 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.facet;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class ValueFacetTest extends SolrAnalyticsFacetTestCase {
+
+ @BeforeClass
+ public static void populate() throws Exception {
+ for (int j = 0; j < NUM_LOOPS; ++j) {
+ int i = j%INT;
+ long l = j%LONG;
+ float f = j%FLOAT;
+ double d = j%DOUBLE;
+ String dt = (1800+j%DATE) + "-12-31T23:59:59Z";
+ String dtm = (1800+j%DATE + 10) + "-12-31T23:59:59Z";
+ String s = "str" + (j%STRING);
+ List<String> fields = new ArrayList<>();
+ fields.add("id"); fields.add("1000"+j);
+
+ if ( i != 0 ) {
+ fields.add("int_i"); fields.add("" + i);
+ fields.add("int_im"); fields.add("" + i);
+ fields.add("int_im"); fields.add("" + (i+10));
+ }
+
+ if ( l != 0l ) {
+ fields.add("long_l"); fields.add("" + l);
+ fields.add("long_lm"); fields.add("" + l);
+ fields.add("long_lm"); fields.add("" + (l+10));
+ }
+
+ if ( f != 0.0f ) {
+ fields.add("float_f"); fields.add("" + f);
+ fields.add("float_fm"); fields.add("" + f);
+ fields.add("float_fm"); fields.add("" + (f+10));
+ }
+
+ if ( d != 0.0d ) {
+ fields.add("double_d"); fields.add("" + d);
+ fields.add("double_dm"); fields.add("" + d);
+ fields.add("double_dm"); fields.add("" + (d+10));
+ }
+
+ if ( (j%DATE) != 0 ) {
+ fields.add("date_dt"); fields.add(dt);
+ fields.add("date_dtm"); fields.add(dt);
+ fields.add("date_dtm"); fields.add(dtm);
+ }
+
+ if ( (j%STRING) != 0 ) {
+ fields.add("string_s"); fields.add(s);
+ fields.add("string_sm"); fields.add(s);
+ fields.add("string_sm"); fields.add(s + "_second");
+ }
+
+ addDoc(fields);
+ }
+ commitDocs();
+ }
+
+ static public final int INT = 7;
+ static public final int LONG = 2;
+ static public final int FLOAT = 6;
+ static public final int DOUBLE = 5;
+ static public final int DATE = 3;
+ static public final int STRING = 4;
+ static public final int NUM_LOOPS = 20;
+
+ @Test
+ public void countTest() throws Exception {
+ Map<String, String> expressions = new HashMap<>();
+ expressions.put("single", "count(float_f)");
+ expressions.put("multi", "count(string_sm)");
+
+ // Value Facet "with_missing"
+ addFacet("with_missing", "{ 'type':'value', 'expression':'fill_missing(long_l,\\'No Long\\')' }");
+
+ addFacetValue("1");
+ addFacetResult("single", 10L);
+ addFacetResult("multi", 20L);
+
+ addFacetValue("No Long");
+ addFacetResult("single", 6L);
+ addFacetResult("multi", 10L);
+
+ testGrouping(expressions, "single", true);
+ }
+
+ @Test
+ public void docCountTest() throws Exception {
+ Map<String, String> expressions = new HashMap<>();
+ expressions.put("single", "doc_count(date_dt)");
+ expressions.put("multi", "doc_count(float_fm)");
+
+ // Value Facet "with_missing"
+ addFacet("with_missing", "{ 'type':'value', 'expression':'fill_missing(string_sm,\\'No Values\\')' }");
+
+ addFacetValue("str1");
+ addFacetResult("single", 4L);
+ addFacetResult("multi", 5L);
+
+ addFacetValue("str1_second");
+ addFacetResult("single", 4L);
+ addFacetResult("multi", 5L);
+
+ addFacetValue("str2");
+ addFacetResult("single", 3L);
+ addFacetResult("multi", 3L);
+
+ addFacetValue("str2_second");
+ addFacetResult("single", 3L);
+ addFacetResult("multi", 3L);
+
+ addFacetValue("str3");
+ addFacetResult("single", 3L);
+ addFacetResult("multi", 5L);
+
+ addFacetValue("str3_second");
+ addFacetResult("single", 3L);
+ addFacetResult("multi", 5L);
+
+ addFacetValue("No Values");
+ addFacetResult("single", 3L);
+ addFacetResult("multi", 3L);
+
+ // Value Facet "no_missing"
+ addFacet("no_missing", "{ 'type':'value', 'expression':'long_l' }");
+
+ addFacetValue("1");
+ addFacetResult("single", 7L);
+ addFacetResult("multi", 10L);
+
+ testGrouping(expressions, false);
+ }
+
+ @Test
+ public void missingTest() throws Exception {
+ Map<String, String> expressions = new HashMap<>();
+ expressions.put("single", "missing(date_dt)");
+ expressions.put("multi", "missing(float_fm)");
+
+ // Value Facet "with_missing"
+ addFacet("with_missing", "{ 'type':'value', 'expression':'fill_missing(string_sm,\\'No Values\\')' }");
+
+ addFacetValue("str1");
+ addFacetResult("single", 1L);
+ addFacetResult("multi", 0L);
+
+ addFacetValue("str1_second");
+ addFacetResult("single", 1L);
+ addFacetResult("multi", 0L);
+
+ addFacetValue("str2");
+ addFacetResult("single", 2L);
+ addFacetResult("multi", 2L);
+
+ addFacetValue("str2_second");
+ addFacetResult("single", 2L);
+ addFacetResult("multi", 2L);
+
+ addFacetValue("str3");
+ addFacetResult("single", 2L);
+ addFacetResult("multi", 0L);
+
+ addFacetValue("str3_second");
+ addFacetResult("single", 2L);
+ addFacetResult("multi", 0L);
+
+ addFacetValue("No Values");
+ addFacetResult("single", 2L);
+ addFacetResult("multi", 2L);
+
+ // Value Facet "no_missing"
+ addFacet("no_missing", "{ 'type':'value', 'expression':'long_l' }");
+
+ addFacetValue("1");
+ addFacetResult("single", 3L);
+ addFacetResult("multi", 0L);
+
+ testGrouping(expressions, false);
+ }
+
+ @Test
+ public void uniqueTest() throws Exception {
+ Map<String, String> expressions = new HashMap<>();
+ expressions.put("int", "unique(int_i)");
+ expressions.put("longs", "unique(long_lm)");
+ expressions.put("float", "unique(float_f)");
+ expressions.put("doubles", "unique(double_dm)");
+ expressions.put("dates", "unique(date_dtm)");
+ expressions.put("string", "unique(string_s)");
+
+ // Value Facet "without_missing"
+ addFacet("without_missing", "{ 'type':'value', 'expression':'date_dt' }");
+
+ addFacetValue("1801-12-31T23:59:59Z");
+ addFacetResult("int", 6L);
+ addFacetResult("longs", 2L);
+ addFacetResult("float", 2L);
+ addFacetResult("doubles", 8L);
+ addFacetResult("dates", 2L);
+ addFacetResult("string", 3L);
+
+ addFacetValue("1802-12-31T23:59:59Z");
+ addFacetResult("int", 5L);
+ addFacetResult("longs", 2L);
+ addFacetResult("float", 2L);
+ addFacetResult("doubles", 8L);
+ addFacetResult("dates", 2L);
+ addFacetResult("string", 3L);
+
+ testGrouping(expressions, false);
+ }
+
+ @Test
+ public void minTest() throws Exception {
+ Map<String, String> expressions = new HashMap<>();
+ expressions.put("int", "min(int_i)");
+ expressions.put("longs", "min(long_lm)");
+ expressions.put("float", "min(float_f)");
+ expressions.put("doubles", "min(double_dm)");
+ expressions.put("dates", "min(date_dtm)");
+ expressions.put("string", "min(string_s)");
+
+ // Value Facet "without_missing"
+ addFacet("without_missing", "{ 'type':'value', 'expression':'date_dt' }");
+
+ addFacetValue("1801-12-31T23:59:59Z");
+ addFacetResult("int", 1);
+ addFacetResult("longs", 1L);
+ addFacetResult("float", 1.0F);
+ addFacetResult("doubles", 1.0);
+ addFacetResult("dates", "1801-12-31T23:59:59Z");
+ addFacetResult("string", "str1");
+
+ addFacetValue("1802-12-31T23:59:59Z");
+ addFacetResult("int", 1);
+ addFacetResult("longs", 1L);
+ addFacetResult("float", 2.0F);
+ addFacetResult("doubles", 1.0);
+ addFacetResult("dates", "1802-12-31T23:59:59Z");
+ addFacetResult("string", "str1");
+
+ testGrouping(expressions, false);
+ }
+
+ @Test
+ public void maxTest() throws Exception {
+ Map<String, String> expressions = new HashMap<>();
+ expressions.put("int", "max(int_i)");
+ expressions.put("longs", "max(long_lm)");
+ expressions.put("float", "max(float_f)");
+ expressions.put("doubles", "max(double_dm)");
+ expressions.put("dates", "max(date_dtm)");
+ expressions.put("string", "max(string_s)");
+
+ // Value Facet "without_missing"
+ addFacet("without_missing", "{ 'type':'value', 'expression':'date_dt' }");
+
+ addFacetValue("1801-12-31T23:59:59Z");
+ addFacetResult("int", 6);
+ addFacetResult("longs", 11L);
+ addFacetResult("float", 4.0F);
+ addFacetResult("doubles", 14.0);
+ addFacetResult("dates", "1811-12-31T23:59:59Z");
+ addFacetResult("string", "str3");
+
+ addFacetValue("1802-12-31T23:59:59Z");
+ addFacetResult("int", 5);
+ addFacetResult("longs", 11L);
+ addFacetResult("float", 5.0F);
+ addFacetResult("doubles", 14.0);
+ addFacetResult("dates", "1812-12-31T23:59:59Z");
+ addFacetResult("string", "str3");
+
+ testGrouping(expressions, false);
+ }
+
+ @Test
+ public void sumTest() throws Exception {
+ Map<String, String> expressions = new HashMap<>();
+ expressions.put("single", "sum(float_f)");
+ expressions.put("multi", "sum(double_dm)");
+
+ // Value Facet "without_missing"
+ addFacet("without_missing", "{ 'type':'value', 'expression':'date_dt' }");
+
+ addFacetValue("1801-12-31T23:59:59Z");
+ addFacetResult("single", 16.0);
+ addFacetResult("multi", 90.0);
+
+ addFacetValue("1802-12-31T23:59:59Z");
+ addFacetResult("single", 21.0);
+ addFacetResult("multi", 74.0);
+
+ testGrouping(expressions, false);
+ }
+
+ @Test
+ public void meanTest() throws Exception {
+ Map<String, String> expressions = new HashMap<>();
+ expressions.put("single", "mean(float_f)");
+ expressions.put("multi", "mean(double_dm)");
+
+ // Value Facet "without_missing"
+ addFacet("without_missing", "{ 'type':'value', 'expression':'date_dt' }");
+
+ addFacetValue("1801-12-31T23:59:59Z");
+ addFacetResult("single", 16.0/7.0);
+ addFacetResult("multi", 90.0/12.0);
+
+ addFacetValue("1802-12-31T23:59:59Z");
+ addFacetResult("single", 21.0/6.0);
+ addFacetResult("multi", 74.0/10.0);
+
+ testGrouping(expressions, "multi", true);
+ }
+
+ @Test
+ public void medianTest() throws Exception {
+ Map<String, String> expressions = new HashMap<>();
+ expressions.put("int", "median(int_i)");
+ expressions.put("longs", "median(long_lm)");
+ expressions.put("float", "median(float_f)");
+ expressions.put("doubles", "median(double_dm)");
+ expressions.put("dates", "median(date_dtm)");
+
+ // Value Facet "without_missing"
+ addFacet("without_missing", "{ 'type':'value', 'expression':'date_dt' }");
+
+ addFacetValue("1801-12-31T23:59:59Z");
+ addFacetResult("int", 3.5);
+ addFacetResult("longs", 6.0);
+ addFacetResult("float", 1.0);
+ addFacetResult("doubles", 7.5);
+ addFacetResult("dates", "1806-12-31T23:59:59Z");
+
+ addFacetValue("1802-12-31T23:59:59Z");
+ addFacetResult("int", 3.0);
+ addFacetResult("longs", 6.0);
+ addFacetResult("float", 3.5);
+ addFacetResult("doubles", 7.50);
+ addFacetResult("dates", "1808-01-01T11:59:59Z");
+
+ testGrouping(expressions, false);
+ }
+
+ @Test
+ public void percentileTest() throws Exception {
+ Map<String, String> expressions = new HashMap<>();
+ expressions.put("int", "percentile(20,int_i)");
+ expressions.put("longs", "percentile(80,long_lm)");
+ expressions.put("float", "percentile(40,float_f)");
+ expressions.put("doubles", "percentile(50,double_dm)");
+ expressions.put("dates", "percentile(0,date_dtm)");
+ expressions.put("string", "percentile(99.99,string_s)");
+
+ // Value Facet "without_missing"
+ addFacet("without_missing", "{ 'type':'value', 'expression':'date_dt' }");
+
+ addFacetValue("1801-12-31T23:59:59Z");
+ addFacetResult("int", 2);
+ addFacetResult("longs", 11L);
+ addFacetResult("float", 1.0F);
+ addFacetResult("doubles", 11.0);
+ addFacetResult("dates", "1801-12-31T23:59:59Z");
+ addFacetResult("string", "str3");
+
+ addFacetValue("1802-12-31T23:59:59Z");
+ addFacetResult("int", 2);
+ addFacetResult("longs", 11L);
+ addFacetResult("float", 2.0F);
+ addFacetResult("doubles", 11.0);
+ addFacetResult("dates", "1802-12-31T23:59:59Z");
+ addFacetResult("string", "str3");
+
+ testGrouping(expressions, "dates", false);
+ }
+
+ @Test
+ public void ordinalTest() throws Exception {
+ Map<String, String> expressions = new HashMap<>();
+ expressions.put("int", "ordinal(3,int_i)");
+ expressions.put("longs", "ordinal(-2,long_lm)");
+ expressions.put("float", "ordinal(-3,float_f)");
+ expressions.put("doubles", "ordinal(1,double_dm)");
+ expressions.put("dates", "ordinal(-1,date_dtm)");
+ expressions.put("string", "ordinal(4,string_s)");
+
+ // Value Facet "without_missing"
+ addFacet("without_missing", "{ 'type':'value', 'expression':'date_dt' }");
+
+ addFacetValue("1801-12-31T23:59:59Z");
+ addFacetResult("int", 3);
+ addFacetResult("longs", 11L);
+ addFacetResult("float", 4.0F);
+ addFacetResult("doubles", 1.0);
+ addFacetResult("dates", "1811-12-31T23:59:59Z");
+ addFacetResult("string", "str3");
+
+ addFacetValue("1802-12-31T23:59:59Z");
+ addFacetResult("int", 3);
+ addFacetResult("longs", 11L);
+ addFacetResult("float", 5.0F);
+ addFacetResult("doubles", 1.0);
+ addFacetResult("dates", "1812-12-31T23:59:59Z");
+ addFacetResult("string", "str2");
+
+ testGrouping(expressions, "string", false);
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/AbstractAnalyticsFieldTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/AbstractAnalyticsFieldTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/AbstractAnalyticsFieldTest.java
new file mode 100644
index 0000000..4361dea
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/AbstractAnalyticsFieldTest.java
@@ -0,0 +1,299 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.function.field;
+
+import java.io.IOException;
+import java.time.Instant;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Predicate;
+
+import org.apache.lucene.index.LeafReaderContext;
+import org.apache.lucene.search.DocIdSet;
+import org.apache.lucene.search.DocIdSetIterator;
+import org.apache.lucene.search.MatchAllDocsQuery;
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.analytics.ExpressionFactory;
+import org.apache.solr.schema.IndexSchema;
+import org.apache.solr.search.Filter;
+import org.apache.solr.search.QueryWrapperFilter;
+import org.apache.solr.search.SolrIndexSearcher;
+import org.apache.solr.util.RefCounted;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+public class AbstractAnalyticsFieldTest extends SolrTestCaseJ4 {
+
+ private static IndexSchema indexSchema;
+ private static SolrIndexSearcher searcher;
+ private static RefCounted<SolrIndexSearcher> ref;
+
+ protected static Map<String,Integer> singleInts;
+ protected static Map<String,Map<Integer,Integer>> multiInts;
+ protected static Map<String,Long> singleLongs;
+ protected static Map<String,Map<Long,Integer>> multiLongs;
+ protected static Map<String,Float> singleFloats;
+ protected static Map<String,Map<Float,Integer>> multiFloats;
+ protected static Map<String,Double> singleDoubles;
+ protected static Map<String,Map<Double,Integer>> multiDoubles;
+ protected static Map<String,Long> singleDates;
+ protected static Map<String,Map<Long,Integer>> multiDates;
+ protected static Map<String,String> singleStrings;
+ protected static Map<String,Map<String,Integer>> multiStrings;
+ protected static Map<String,Boolean> singleBooleans;
+ protected static Map<String,Map<Boolean,Integer>> multiBooleans;
+
+ private static List<String> missingDocuments;
+
+ @BeforeClass
+ public static void createSchemaAndFields() throws Exception {
+ initCore("solrconfig-analytics.xml","schema-analytics.xml");
+
+ singleInts = new HashMap<>();
+ multiInts = new HashMap<>();
+ singleLongs = new HashMap<>();
+ multiLongs = new HashMap<>();
+ singleFloats = new HashMap<>();
+ multiFloats = new HashMap<>();
+ singleDoubles = new HashMap<>();
+ multiDoubles = new HashMap<>();
+ singleDates = new HashMap<>();
+ multiDates = new HashMap<>();
+ singleStrings = new HashMap<>();
+ multiStrings = new HashMap<>();
+ singleBooleans = new HashMap<>();
+ multiBooleans = new HashMap<>();
+
+ missingDocuments = new ArrayList<>();
+
+ assertU(adoc("id", "-1"));
+ missingDocuments.add("-1");
+ assertU(adoc("id", "5"));
+ missingDocuments.add("5");
+ for (int i = 0; i < 5; ++i) {
+ assertU(adoc(
+ "id", "" + i,
+
+ "int_i_t", "" + i,
+ "int_im_t", "" + i,
+ "int_im_t", "" + (i + 10),
+ "int_im_t", "" + (i + 10),
+ "int_im_t", "" + (i + 20),
+
+ "int_i_p", "" + i,
+ "int_im_p", "" + i,
+ "int_im_p", "" + (i + 10),
+ "int_im_p", "" + (i + 10),
+ "int_im_p", "" + (i + 20),
+
+ "long_l_t", "" + i,
+ "long_lm_t", "" + i,
+ "long_lm_t", "" + (i + 10),
+ "long_lm_t", "" + (i + 10),
+ "long_lm_t", "" + (i + 20),
+
+ "long_l_p", "" + i,
+ "long_lm_p", "" + i,
+ "long_lm_p", "" + (i + 10),
+ "long_lm_p", "" + (i + 10),
+ "long_lm_p", "" + (i + 20),
+
+ "float_f_t", "" + (i + .75F),
+ "float_fm_t", "" + (i + .75F),
+ "float_fm_t", "" + (i + 10.75F),
+ "float_fm_t", "" + (i + 10.75F),
+ "float_fm_t", "" + (i + 20.75F),
+
+ "float_f_p", "" + (i + .75F),
+ "float_fm_p", "" + (i + .75F),
+ "float_fm_p", "" + (i + 10.75F),
+ "float_fm_p", "" + (i + 10.75F),
+ "float_fm_p", "" + (i + 20.75F),
+
+ "double_d_t", "" + (i + .5),
+ "double_dm_t", "" + (i + .5),
+ "double_dm_t", "" + (i + 10.5),
+ "double_dm_t", "" + (i + 10.5),
+ "double_dm_t", "" + (i + 20.5),
+
+ "double_d_p", "" + (i + .5),
+ "double_dm_p", "" + (i + .5),
+ "double_dm_p", "" + (i + 10.5),
+ "double_dm_p", "" + (i + 10.5),
+ "double_dm_p", "" + (i + 20.5),
+
+ "date_dt_t", "180" + i + "-12-31T23:59:59Z",
+ "date_dtm_t", "180" + i + "-12-31T23:59:59Z",
+ "date_dtm_t", "18" + (i + 10) + "-12-31T23:59:59Z",
+ "date_dtm_t", "18" + (i + 10) + "-12-31T23:59:59Z",
+ "date_dtm_t", "18" + (i + 20) + "-12-31T23:59:59Z",
+
+ "date_dt_p", "180" + i + "-12-31T23:59:59Z",
+ "date_dtm_p", "180" + i + "-12-31T23:59:59Z",
+ "date_dtm_p", "18" + (i + 10) + "-12-31T23:59:59Z",
+ "date_dtm_p", "18" + (i + 10) + "-12-31T23:59:59Z",
+ "date_dtm_p", "18" + (i + 20) + "-12-31T23:59:59Z",
+
+ "string_s", "abc" + i,
+ "string_sm", "abc" + i,
+ "string_sm", "def" + i,
+ "string_sm", "def" + i,
+ "string_sm", "ghi" + i,
+
+ "boolean_b", Boolean.toString(i % 3 == 0),
+ "boolean_bm", "false",
+ "boolean_bm", "true",
+ "boolean_bm", "false"
+ ));
+
+ singleInts.put(""+i, i);
+ Map<Integer, Integer> ints = new HashMap<>();
+ ints.put(i, 1);
+ ints.put(i + 10, 2);
+ ints.put(i + 20, 1);
+ multiInts.put(""+i, ints);
+
+ singleLongs.put(""+i, (long) i);
+ Map<Long, Integer> longs = new HashMap<>();
+ longs.put((long) i, 1);
+ longs.put(i + 10L, 2);
+ longs.put(i + 20L, 1);
+ multiLongs.put(""+i, longs);
+
+ singleFloats.put(""+i, i + .75F);
+ Map<Float, Integer> floats = new HashMap<>();
+ floats.put(i + .75F, 1);
+ floats.put(i + 10.75F, 2);
+ floats.put(i + 20.75F, 1);
+ multiFloats.put(""+i, floats);
+
+ singleDoubles.put(""+i, i + .5);
+ Map<Double, Integer> doubles = new HashMap<>();
+ doubles.put(i + .5, 1);
+ doubles.put(i + 10.5, 2);
+ doubles.put(i + 20.5, 1);
+ multiDoubles.put(""+i, doubles);
+
+ singleDates.put(""+i, Instant.parse("180" + i + "-12-31T23:59:59Z").toEpochMilli());
+ Map<Long, Integer> dates = new HashMap<>();
+ dates.put(Instant.parse("180" + i + "-12-31T23:59:59Z").toEpochMilli(), 1);
+ dates.put(Instant.parse("18" + ( i + 10 ) + "-12-31T23:59:59Z").toEpochMilli(), 2);
+ dates.put(Instant.parse("18" + ( i + 20 ) + "-12-31T23:59:59Z").toEpochMilli(), 1);
+ multiDates.put(""+i, dates);
+
+ singleStrings.put(""+i, "abc" + i);
+ Map<String, Integer> strings = new HashMap<>();
+ strings.put("abc" + i, 1);
+ strings.put("def" + i, 2);
+ strings.put("ghi" + i, 1);
+ multiStrings.put(""+i, strings);
+
+ singleBooleans.put(""+i, i % 3 == 0);
+ Map<Boolean, Integer> booleans = new HashMap<>();
+ booleans.put(true, 1);
+ booleans.put(false, 2);
+ multiBooleans.put(""+i, booleans);
+ }
+ assertU(commit());
+
+ ref = h.getCore().getSearcher();
+ searcher = ref.get();
+
+ indexSchema = h.getCore().getLatestSchema();
+ }
+
+ protected ExpressionFactory getExpressionFactory() {
+ ExpressionFactory fact = new ExpressionFactory(indexSchema);
+ fact.startRequest();
+ return fact;
+ }
+
+ @AfterClass
+ public static void closeSearcher() throws IOException {
+ ref.decref();
+ }
+
+ protected <T> void checkSingleFieldValues(Map<String,T> expected, Map<String,T> found, Set<String> missing) {
+ expected.forEach( (id, value) -> {
+ assertTrue("Field does not contain value for id '" + id + "'.", found.containsKey(id));
+ assertEquals(value, found.get(id));
+ });
+ assertEquals(expected.size(), found.size());
+
+ missingDocuments.forEach( id -> assertTrue("Field does not have correct information for missing id '" + id + "'.", missing.contains(id)));
+ assertEquals(missingDocuments.size(), missing.size());
+ }
+
+ protected <T> void checkMultiFieldValues(Map<String,Map<T,Integer>> expected, Map<String,Map<T,Integer>> found, Set<String> missing, boolean deduplicated) {
+ expected.forEach( (id, expectedValues) -> {
+ assertTrue("Field does not contain values for id '" + id + "'.", found.containsKey(id));
+ Map<T,Integer> foundValues = found.get(id);
+ expectedValues.forEach( (value, count) -> {
+ assertTrue("Value '" + value + "' not found for document with id '" + id + "'.", foundValues.containsKey(value));
+ if (deduplicated) {
+ assertEquals(1, foundValues.get(value).intValue());
+ } else {
+ assertEquals(count, foundValues.get(value));
+ }
+ });
+ assertEquals(expectedValues.size(), foundValues.size());
+ });
+ assertEquals(expected.size(), found.size());
+
+ missingDocuments.forEach( id -> assertTrue("Field does not have correct information for missing id '" + id + "'.", missing.contains(id)));
+ assertEquals(missingDocuments.size(), missing.size());
+ }
+
+ protected boolean emptyValueFound;
+
+ protected Set<String> collectFieldValues(AnalyticsField testField, Predicate<String> valuesFiller) throws IOException {
+ StringField idField = new StringField("id");
+ Filter filter = new QueryWrapperFilter(new MatchAllDocsQuery());
+ Set<String> missing = new HashSet<>();
+
+ List<LeafReaderContext> contexts = searcher.getTopReaderContext().leaves();
+ for (int leafNum = 0; leafNum < contexts.size(); leafNum++) {
+ LeafReaderContext context = contexts.get(leafNum);
+ DocIdSet dis = filter.getDocIdSet(context, null); // solr docsets already exclude any deleted docs
+ if (dis == null) {
+ continue;
+ }
+ DocIdSetIterator disi = dis.iterator();
+ if (disi != null) {
+ testField.doSetNextReader(context);
+ idField.doSetNextReader(context);
+ int doc = disi.nextDoc();
+ while( doc != DocIdSetIterator.NO_MORE_DOCS){
+ // Add a document to the statistics being generated
+ testField.collect(doc);
+ idField.collect(doc);
+
+ String id = idField.getString();
+ if (!valuesFiller.test(id)) {
+ missing.add(id);
+ }
+ doc = disi.nextDoc();
+ }
+ }
+ }
+ return missing;
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/BooleanFieldsTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/BooleanFieldsTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/BooleanFieldsTest.java
new file mode 100644
index 0000000..4c3b79f
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/BooleanFieldsTest.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.function.field;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.solr.analytics.ExpressionFactory;
+import org.junit.Test;
+
+public class BooleanFieldsTest extends AbstractAnalyticsFieldTest {
+
+ @Test
+ public void expressionFactoryCreationTest() {
+ ExpressionFactory fact = getExpressionFactory();
+
+ assertTrue(fact.createExpression("boolean_b") instanceof BooleanField);
+ assertTrue(fact.createExpression("boolean_bm") instanceof BooleanMultiField);
+ }
+
+ @Test
+ public void singleValuedBooleanTest() throws IOException {
+ BooleanField valueField = new BooleanField("boolean_b");
+ Map<String,Boolean> values = new HashMap<>();
+
+ Set<String> missing = collectFieldValues(valueField, id -> {
+ boolean value = valueField.getBoolean();
+ if (valueField.exists()) {
+ values.put(id, value);
+ }
+ return valueField.exists();
+ });
+
+ checkSingleFieldValues(singleBooleans, values, missing);
+ }
+
+ @Test
+ public void multiValuedBooleanTest() throws IOException {
+ BooleanMultiField valueField = new BooleanMultiField("boolean_bm");
+ Map<String,Map<Boolean,Integer>> values = new HashMap<>();
+
+ Set<String> missing = collectFieldValues(valueField, id -> {
+ Map<Boolean, Integer> doc = new HashMap<>();
+ valueField.streamBooleans( value -> {
+ doc.put(value, doc.getOrDefault(value, 0) + 1);
+ });
+ if (doc.size() > 0) {
+ values.put(id, doc);
+ }
+ return doc.size() > 0;
+ });
+
+ checkMultiFieldValues(multiBooleans, values, missing, true);
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/DateFieldsTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/DateFieldsTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/DateFieldsTest.java
new file mode 100644
index 0000000..88356dc
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/DateFieldsTest.java
@@ -0,0 +1,108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.function.field;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.solr.analytics.ExpressionFactory;
+import org.junit.Test;
+
+public class DateFieldsTest extends AbstractAnalyticsFieldTest {
+
+ @Test
+ public void expressionFactoryCreationTest() {
+ ExpressionFactory fact = getExpressionFactory();
+
+ assertTrue(fact.createExpression("date_dt_t") instanceof DateField);
+ assertTrue(fact.createExpression("date_dt_p") instanceof DateField);
+ assertTrue(fact.createExpression("date_dtm_t") instanceof DateMultiTrieField);
+ assertTrue(fact.createExpression("date_dtm_p") instanceof DateMultiPointField);
+ }
+
+ @Test
+ public void singleValuedTrieDateTest() throws IOException {
+ DateField valueField = new DateField("date_dt_t");
+ Map<String,Long> values = new HashMap<>();
+
+ Set<String> missing = collectFieldValues(valueField, id -> {
+ long value = valueField.getLong();
+ if (valueField.exists()) {
+ values.put(id, value);
+ }
+ return valueField.exists();
+ });
+
+ checkSingleFieldValues(singleDates, values, missing);
+ }
+
+ @Test
+ public void singleValuedPointDateTest() throws IOException {
+ DateField valueField = new DateField("date_dt_p");
+ Map<String,Long> values = new HashMap<>();
+
+ Set<String> missing = collectFieldValues(valueField, id -> {
+ long value = valueField.getLong();
+ if (valueField.exists()) {
+ values.put(id, value);
+ }
+ return valueField.exists();
+ });
+
+ checkSingleFieldValues(singleDates, values, missing);
+ }
+
+ @Test
+ public void multiValuedTrieDateTest() throws IOException {
+ DateMultiTrieField valueField = new DateMultiTrieField("date_dtm_t");
+ Map<String,Map<Long,Integer>> values = new HashMap<>();
+
+ Set<String> missing = collectFieldValues(valueField, id -> {
+ Map<Long, Integer> doc = new HashMap<>();
+ valueField.streamLongs( value -> {
+ doc.put(value, doc.getOrDefault(value, 0) + 1);
+ });
+ if (doc.size() > 0) {
+ values.put(id, doc);
+ }
+ return doc.size() > 0;
+ });
+
+ checkMultiFieldValues(multiDates, values, missing, true);
+ }
+
+ @Test
+ public void multiValuedPointDateTest() throws IOException {
+ DateMultiPointField valueField = new DateMultiPointField("date_dtm_p");
+ Map<String,Map<Long,Integer>> values = new HashMap<>();
+
+ Set<String> missing = collectFieldValues(valueField, id -> {
+ Map<Long, Integer> doc = new HashMap<>();
+ valueField.streamLongs( value -> {
+ doc.put(value, doc.getOrDefault(value, 0) + 1);
+ });
+ if (doc.size() > 0) {
+ values.put(id, doc);
+ }
+ return doc.size() > 0;
+ });
+
+ checkMultiFieldValues(multiDates, values, missing, false);
+ }
+}
[11/20] lucene-solr:master: SOLR-11145,
SOLR-11146: Added comprehensive unit tests for Analytics Component
2.0 as well as analytics bug fixes.
Posted by dp...@apache.org.
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/DoubleFieldsTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/DoubleFieldsTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/DoubleFieldsTest.java
new file mode 100644
index 0000000..c668b0d
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/DoubleFieldsTest.java
@@ -0,0 +1,108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.function.field;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.solr.analytics.ExpressionFactory;
+import org.junit.Test;
+
+public class DoubleFieldsTest extends AbstractAnalyticsFieldTest {
+
+ @Test
+ public void expressionFactoryCreationTest() {
+ ExpressionFactory fact = getExpressionFactory();
+
+ assertTrue(fact.createExpression("double_d_t") instanceof DoubleField);
+ assertTrue(fact.createExpression("double_d_p") instanceof DoubleField);
+ assertTrue(fact.createExpression("double_dm_t") instanceof DoubleMultiTrieField);
+ assertTrue(fact.createExpression("double_dm_p") instanceof DoubleMultiPointField);
+ }
+
+ @Test
+ public void singleValuedTrieDoubleTest() throws IOException {
+ DoubleField valueField = new DoubleField("double_d_t");
+ Map<String,Double> values = new HashMap<>();
+
+ Set<String> missing = collectFieldValues(valueField, id -> {
+ double value = valueField.getDouble();
+ if (valueField.exists()) {
+ values.put(id, value);
+ }
+ return valueField.exists();
+ });
+
+ checkSingleFieldValues(singleDoubles, values, missing);
+ }
+
+ @Test
+ public void singleValuedPointDoubleTest() throws IOException {
+ DoubleField valueField = new DoubleField("double_d_p");
+ Map<String,Double> values = new HashMap<>();
+
+ Set<String> missing = collectFieldValues(valueField, id -> {
+ double value = valueField.getDouble();
+ if (valueField.exists()) {
+ values.put(id, value);
+ }
+ return valueField.exists();
+ });
+
+ checkSingleFieldValues(singleDoubles, values, missing);
+ }
+
+ @Test
+ public void multiValuedTrieDoubleTest() throws IOException {
+ DoubleMultiTrieField valueField = new DoubleMultiTrieField("double_dm_t");
+ Map<String,Map<Double,Integer>> values = new HashMap<>();
+
+ Set<String> missing = collectFieldValues(valueField, id -> {
+ Map<Double, Integer> doc = new HashMap<>();
+ valueField.streamDoubles( value -> {
+ doc.put(value, doc.getOrDefault(value, 0) + 1);
+ });
+ if (doc.size() > 0) {
+ values.put(id, doc);
+ }
+ return doc.size() > 0;
+ });
+
+ checkMultiFieldValues(multiDoubles, values, missing, true);
+ }
+
+ @Test
+ public void multiValuedPointDoubleTest() throws IOException {
+ DoubleMultiPointField valueField = new DoubleMultiPointField("double_dm_p");
+ Map<String,Map<Double,Integer>> values = new HashMap<>();
+
+ Set<String> missing = collectFieldValues(valueField, id -> {
+ Map<Double, Integer> doc = new HashMap<>();
+ valueField.streamDoubles( value -> {
+ doc.put(value, doc.getOrDefault(value, 0) + 1);
+ });
+ if (doc.size() > 0) {
+ values.put(id, doc);
+ }
+ return doc.size() > 0;
+ });
+
+ checkMultiFieldValues(multiDoubles, values, missing, false);
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/FloatFieldsTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/FloatFieldsTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/FloatFieldsTest.java
new file mode 100644
index 0000000..b1aead6
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/FloatFieldsTest.java
@@ -0,0 +1,108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.function.field;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.solr.analytics.ExpressionFactory;
+import org.junit.Test;
+
+public class FloatFieldsTest extends AbstractAnalyticsFieldTest {
+
+ @Test
+ public void expressionFactoryCreationTest() {
+ ExpressionFactory fact = getExpressionFactory();
+
+ assertTrue(fact.createExpression("float_f_t") instanceof FloatField);
+ assertTrue(fact.createExpression("float_f_p") instanceof FloatField);
+ assertTrue(fact.createExpression("float_fm_t") instanceof FloatMultiTrieField);
+ assertTrue(fact.createExpression("float_fm_p") instanceof FloatMultiPointField);
+ }
+
+ @Test
+ public void singleValuedTrieFloatTest() throws IOException {
+ FloatField valueField = new FloatField("float_f_t");
+ Map<String,Float> values = new HashMap<>();
+
+ Set<String> missing = collectFieldValues(valueField, id -> {
+ float value = valueField.getFloat();
+ if (valueField.exists()) {
+ values.put(id, value);
+ }
+ return valueField.exists();
+ });
+
+ checkSingleFieldValues(singleFloats, values, missing);
+ }
+
+ @Test
+ public void singleValuedPointFloatTest() throws IOException {
+ FloatField valueField = new FloatField("float_f_p");
+ Map<String,Float> values = new HashMap<>();
+
+ Set<String> missing = collectFieldValues(valueField, id -> {
+ float value = valueField.getFloat();
+ if (valueField.exists()) {
+ values.put(id, value);
+ }
+ return valueField.exists();
+ });
+
+ checkSingleFieldValues(singleFloats, values, missing);
+ }
+
+ @Test
+ public void multiValuedTrieFloatTest() throws IOException {
+ FloatMultiTrieField valueField = new FloatMultiTrieField("float_fm_t");
+ Map<String,Map<Float,Integer>> values = new HashMap<>();
+
+ Set<String> missing = collectFieldValues(valueField, id -> {
+ Map<Float, Integer> doc = new HashMap<>();
+ valueField.streamFloats( value -> {
+ doc.put(value, doc.getOrDefault(value, 0) + 1);
+ });
+ if (doc.size() > 0) {
+ values.put(id, doc);
+ }
+ return doc.size() > 0;
+ });
+
+ checkMultiFieldValues(multiFloats, values, missing, true);
+ }
+
+ @Test
+ public void multiValuedPointFloatTest() throws IOException {
+ FloatMultiPointField valueField = new FloatMultiPointField("float_fm_p");
+ Map<String,Map<Float,Integer>> values = new HashMap<>();
+
+ Set<String> missing = collectFieldValues(valueField, id -> {
+ Map<Float, Integer> doc = new HashMap<>();
+ valueField.streamFloats( value -> {
+ doc.put(value, doc.getOrDefault(value, 0) + 1);
+ });
+ if (doc.size() > 0) {
+ values.put(id, doc);
+ }
+ return doc.size() > 0;
+ });
+
+ checkMultiFieldValues(multiFloats, values, missing, false);
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/IntFieldsTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/IntFieldsTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/IntFieldsTest.java
new file mode 100644
index 0000000..014d9d1
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/IntFieldsTest.java
@@ -0,0 +1,108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.function.field;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.solr.analytics.ExpressionFactory;
+import org.junit.Test;
+
+public class IntFieldsTest extends AbstractAnalyticsFieldTest {
+
+ @Test
+ public void expressionFactoryCreationTest() {
+ ExpressionFactory fact = getExpressionFactory();
+
+ assertTrue(fact.createExpression("int_i_t") instanceof IntField);
+ assertTrue(fact.createExpression("int_i_p") instanceof IntField);
+ assertTrue(fact.createExpression("int_im_t") instanceof IntMultiTrieField);
+ assertTrue(fact.createExpression("int_im_p") instanceof IntMultiPointField);
+ }
+
+ @Test
+ public void singleValuedTrieIntTest() throws IOException {
+ IntField valueField = new IntField("int_i_t");
+ Map<String,Integer> values = new HashMap<>();
+
+ Set<String> missing = collectFieldValues(valueField, id -> {
+ int value = valueField.getInt();
+ if (valueField.exists()) {
+ values.put(id, value);
+ }
+ return valueField.exists();
+ });
+
+ checkSingleFieldValues(singleInts, values, missing);
+ }
+
+ @Test
+ public void singleValuedPointIntTest() throws IOException {
+ IntField valueField = new IntField("int_i_p");
+ Map<String,Integer> values = new HashMap<>();
+
+ Set<String> missing = collectFieldValues(valueField, id -> {
+ int value = valueField.getInt();
+ if (valueField.exists()) {
+ values.put(id, value);
+ }
+ return valueField.exists();
+ });
+
+ checkSingleFieldValues(singleInts, values, missing);
+ }
+
+ @Test
+ public void multiValuedTrieIntTest() throws IOException {
+ IntMultiTrieField valueField = new IntMultiTrieField("int_im_t");
+ Map<String,Map<Integer,Integer>> values = new HashMap<>();
+
+ Set<String> missing = collectFieldValues(valueField, id -> {
+ Map<Integer, Integer> doc = new HashMap<>();
+ valueField.streamInts( value -> {
+ doc.put(value, doc.getOrDefault(value, 0) + 1);
+ });
+ if (doc.size() > 0) {
+ values.put(id, doc);
+ }
+ return doc.size() > 0;
+ });
+
+ checkMultiFieldValues(multiInts, values, missing, true);
+ }
+
+ @Test
+ public void multiValuedPointIntTest() throws IOException {
+ IntMultiPointField valueField = new IntMultiPointField("int_im_p");
+ Map<String,Map<Integer,Integer>> values = new HashMap<>();
+
+ Set<String> missing = collectFieldValues(valueField, id -> {
+ Map<Integer, Integer> doc = new HashMap<>();
+ valueField.streamInts( value -> {
+ doc.put(value, doc.getOrDefault(value, 0) + 1);
+ });
+ if (doc.size() > 0) {
+ values.put(id, doc);
+ }
+ return doc.size() > 0;
+ });
+
+ checkMultiFieldValues(multiInts, values, missing, false);
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/LongFieldsTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/LongFieldsTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/LongFieldsTest.java
new file mode 100644
index 0000000..d1fc6b8
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/LongFieldsTest.java
@@ -0,0 +1,108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.function.field;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.solr.analytics.ExpressionFactory;
+import org.junit.Test;
+
+public class LongFieldsTest extends AbstractAnalyticsFieldTest {
+
+ @Test
+ public void expressionFactoryCreationTest() {
+ ExpressionFactory fact = getExpressionFactory();
+
+ assertTrue(fact.createExpression("long_l_t") instanceof LongField);
+ assertTrue(fact.createExpression("long_l_p") instanceof LongField);
+ assertTrue(fact.createExpression("long_lm_t") instanceof LongMultiTrieField);
+ assertTrue(fact.createExpression("long_lm_p") instanceof LongMultiPointField);
+ }
+
+ @Test
+ public void singleValuedTrieLongTest() throws IOException {
+ LongField valueField = new LongField("long_l_t");
+ Map<String,Long> values = new HashMap<>();
+
+ Set<String> missing = collectFieldValues(valueField, id -> {
+ long value = valueField.getLong();
+ if (valueField.exists()) {
+ values.put(id, value);
+ }
+ return valueField.exists();
+ });
+
+ checkSingleFieldValues(singleLongs, values, missing);
+ }
+
+ @Test
+ public void singleValuedPointLongTest() throws IOException {
+ LongField valueField = new LongField("long_l_p");
+ Map<String,Long> values = new HashMap<>();
+
+ Set<String> missing = collectFieldValues(valueField, id -> {
+ long value = valueField.getLong();
+ if (valueField.exists()) {
+ values.put(id, value);
+ }
+ return valueField.exists();
+ });
+
+ checkSingleFieldValues(singleLongs, values, missing);
+ }
+
+ @Test
+ public void multiValuedTrieLongTest() throws IOException {
+ LongMultiTrieField valueField = new LongMultiTrieField("long_lm_t");
+ Map<String,Map<Long,Integer>> values = new HashMap<>();
+
+ Set<String> missing = collectFieldValues(valueField, id -> {
+ Map<Long, Integer> doc = new HashMap<>();
+ valueField.streamLongs( value -> {
+ doc.put(value, doc.getOrDefault(value, 0) + 1);
+ });
+ if (doc.size() > 0) {
+ values.put(id, doc);
+ }
+ return doc.size() > 0;
+ });
+
+ checkMultiFieldValues(multiLongs, values, missing, true);
+ }
+
+ @Test
+ public void multiValuedPointLongTest() throws IOException {
+ LongMultiPointField valueField = new LongMultiPointField("long_lm_p");
+ Map<String,Map<Long,Integer>> values = new HashMap<>();
+
+ Set<String> missing = collectFieldValues(valueField, id -> {
+ Map<Long, Integer> doc = new HashMap<>();
+ valueField.streamLongs( value -> {
+ doc.put(value, doc.getOrDefault(value, 0) + 1);
+ });
+ if (doc.size() > 0) {
+ values.put(id, doc);
+ }
+ return doc.size() > 0;
+ });
+
+ checkMultiFieldValues(multiLongs, values, missing, false);
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/StringFieldsTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/StringFieldsTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/StringFieldsTest.java
new file mode 100644
index 0000000..152a009
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/StringFieldsTest.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.function.field;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.solr.analytics.ExpressionFactory;
+import org.junit.Test;
+
+public class StringFieldsTest extends AbstractAnalyticsFieldTest {
+
+ @Test
+ public void expressionFactoryCreationTest() {
+ ExpressionFactory fact = getExpressionFactory();
+
+ assertTrue(fact.createExpression("string_s") instanceof StringField);
+ assertTrue(fact.createExpression("string_sm") instanceof StringMultiField);
+ }
+
+ @Test
+ public void singleValuedStringTest() throws IOException {
+ StringField valueField = new StringField("string_s");
+ Map<String,String> values = new HashMap<>();
+
+ Set<String> missing = collectFieldValues(valueField, id -> {
+ String value = valueField.getString();
+ if (valueField.exists()) {
+ values.put(id, value);
+ }
+ return valueField.exists();
+ });
+
+ checkSingleFieldValues(singleStrings, values, missing);
+ }
+
+ @Test
+ public void multiValuedStringTest() throws IOException {
+ StringMultiField valueField = new StringMultiField("string_sm");
+ Map<String,Map<String,Integer>> values = new HashMap<>();
+
+ Set<String> missing = collectFieldValues(valueField, id -> {
+ Map<String, Integer> doc = new HashMap<>();
+ valueField.streamStrings( value -> {
+ doc.put(value, doc.getOrDefault(value, 0) + 1);
+ });
+ if (doc.size() > 0) {
+ values.put(id, doc);
+ }
+ return doc.size() > 0;
+ });
+
+ checkMultiFieldValues(multiStrings, values, missing, true);
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/AbsoluteValueFunctionTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/AbsoluteValueFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/AbsoluteValueFunctionTest.java
new file mode 100644
index 0000000..9996c28
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/AbsoluteValueFunctionTest.java
@@ -0,0 +1,267 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.function.mapping;
+
+import java.util.Arrays;
+import java.util.Iterator;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.analytics.value.AnalyticsValueStream;
+import org.apache.solr.analytics.value.DoubleValue;
+import org.apache.solr.analytics.value.DoubleValueStream;
+import org.apache.solr.analytics.value.FloatValue;
+import org.apache.solr.analytics.value.FloatValueStream;
+import org.apache.solr.analytics.value.IntValue;
+import org.apache.solr.analytics.value.IntValueStream;
+import org.apache.solr.analytics.value.LongValue;
+import org.apache.solr.analytics.value.LongValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestIntValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestLongValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestIntValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestLongValueStream;
+import org.junit.Test;
+
+public class AbsoluteValueFunctionTest extends SolrTestCaseJ4 {
+
+ @Test
+ public void singleValueIntTest() {
+ TestIntValue val = new TestIntValue();
+
+ AnalyticsValueStream uncasted = AbsoluteValueFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof IntValue);
+ IntValue func = (IntValue) uncasted;
+
+ // Value doesn't exist
+ val.setExists(false);
+ func.getInt();
+ assertFalse(func.exists());
+
+ // Value exists
+ val.setValue(21).setExists(true);
+ assertEquals(21, func.getInt());
+ assertTrue(func.exists());
+
+ val.setValue(-100).setExists(true);
+ assertEquals(100, func.getInt());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void singleValueLongTest() {
+ TestLongValue val = new TestLongValue();
+
+ AnalyticsValueStream uncasted = AbsoluteValueFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof LongValue);
+ LongValue func = (LongValue) uncasted;
+
+ // Value doesn't exist
+ val.setExists(false);
+ func.getLong();
+ assertFalse(func.exists());
+
+ // Value exists
+ val.setValue(21L).setExists(true);
+ assertEquals(21L, func.getLong());
+ assertTrue(func.exists());
+
+ val.setValue(-100L).setExists(true);
+ assertEquals(100L, func.getLong());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void singleValueFloatTest() {
+ TestFloatValue val = new TestFloatValue();
+
+ AnalyticsValueStream uncasted = AbsoluteValueFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof FloatValue);
+ FloatValue func = (FloatValue) uncasted;
+
+ // Value doesn't exist
+ val.setExists(false);
+ func.getFloat();
+ assertFalse(func.exists());
+
+ // Value exists
+ val.setValue(21.56F).setExists(true);
+ assertEquals(21.56F, func.getFloat(), 0.00001);
+ assertTrue(func.exists());
+
+ val.setValue(-100F).setExists(true);
+ assertEquals(100F, func.getFloat(), 0.00001);
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void singleValueDoubleTest() {
+ TestDoubleValue val = new TestDoubleValue();
+
+ AnalyticsValueStream uncasted = AbsoluteValueFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof DoubleValue);
+ DoubleValue func = (DoubleValue) uncasted;
+
+ // Value doesn't exist
+ val.setExists(false);
+ func.getDouble();
+ assertFalse(func.exists());
+
+ // Value exists
+ val.setValue(21.56).setExists(true);
+ assertEquals(21.56, func.getDouble(), 0.00001);
+ assertTrue(func.exists());
+
+ val.setValue(-100.1).setExists(true);
+ assertEquals(100.1, func.getDouble(), 0.00001);
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void multiValueIntTest() {
+ TestIntValueStream val = new TestIntValueStream();
+
+ AnalyticsValueStream uncasted = AbsoluteValueFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof IntValueStream);
+ IntValueStream func = (IntValueStream) uncasted;
+
+ // No values
+ val.setValues();
+ func.streamInts( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // One value
+ val.setValues(-4);
+ Iterator<Integer> values1 = Arrays.asList(4).iterator();
+ func.streamInts( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next().intValue(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ // Multiple values
+ val.setValues(4, -10, 50, -74);
+ Iterator<Integer> values2 = Arrays.asList(4, 10, 50, 74).iterator();
+ func.streamInts( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next().intValue(), value);
+ });
+ assertFalse(values2.hasNext());
+ }
+
+ @Test
+ public void multiValueLongTest() {
+ TestLongValueStream val = new TestLongValueStream();
+
+ AnalyticsValueStream uncasted = AbsoluteValueFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof LongValueStream);
+ LongValueStream func = (LongValueStream) uncasted;
+
+ // No values
+ val.setValues();
+ func.streamLongs( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // One value
+ val.setValues(-4L);
+ Iterator<Long> values1 = Arrays.asList(4L).iterator();
+ func.streamLongs( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next().longValue(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ // Multiple values
+ val.setValues(4L, -10L, 50L, -74L);
+ Iterator<Long> values2 = Arrays.asList(4L, 10L, 50L, 74L).iterator();
+ func.streamLongs( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next().longValue(), value);
+ });
+ assertFalse(values2.hasNext());
+ }
+
+ @Test
+ public void multiValueFloatTest() {
+ TestFloatValueStream val = new TestFloatValueStream();
+
+ AnalyticsValueStream uncasted = AbsoluteValueFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof FloatValueStream);
+ FloatValueStream func = (FloatValueStream) uncasted;
+
+ // No values
+ val.setValues();
+ func.streamFloats( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // One value
+ val.setValues(-4.3F);
+ Iterator<Float> values1 = Arrays.asList(4.3F).iterator();
+ func.streamFloats( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value, .000001);
+ });
+ assertFalse(values1.hasNext());
+
+ // Multiple values
+ val.setValues(4.3F, -10F, 50.75F, -74.4446F);
+ Iterator<Float> values2 = Arrays.asList(4.3F, 10F, 50.75F, 74.4446F).iterator();
+ func.streamFloats( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value, .000001);
+ });
+ assertFalse(values2.hasNext());
+ }
+
+ @Test
+ public void multiValueDoubleTest() {
+ TestDoubleValueStream val = new TestDoubleValueStream();
+
+ AnalyticsValueStream uncasted = AbsoluteValueFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof DoubleValueStream);
+ DoubleValueStream func = (DoubleValueStream) uncasted;
+
+ // No values
+ val.setValues();
+ func.streamDoubles( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // One value
+ val.setValues(-4.3);
+ Iterator<Double> values1 = Arrays.asList(4.3).iterator();
+ func.streamDoubles( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value, .000001);
+ });
+ assertFalse(values1.hasNext());
+
+ // Multiple values
+ val.setValues(4.3, -10, 50.75, -74.4446);
+ Iterator<Double> values2 = Arrays.asList(4.3, 10.0, 50.75, 74.4446).iterator();
+ func.streamDoubles( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value, .000001);
+ });
+ assertFalse(values2.hasNext());
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/AddFunctionTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/AddFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/AddFunctionTest.java
new file mode 100644
index 0000000..87b80cb
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/AddFunctionTest.java
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.function.mapping;
+
+import java.util.Arrays;
+import java.util.Iterator;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.analytics.value.AnalyticsValueStream;
+import org.apache.solr.analytics.value.DoubleValue;
+import org.apache.solr.analytics.value.DoubleValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestIntValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestLongValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestLongValueStream;
+import org.junit.Test;
+
+public class AddFunctionTest extends SolrTestCaseJ4 {
+
+ @Test
+ public void twoSingleValueParametersTest() {
+ TestIntValue val1 = new TestIntValue();
+ TestFloatValue val2 = new TestFloatValue();
+
+ AnalyticsValueStream uncasted = AddFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2});
+ assertTrue(uncasted instanceof DoubleValue);
+ DoubleValue func = (DoubleValue) uncasted;
+
+ // Neither exists
+ val1.setExists(false);
+ val2.setExists(false);
+ func.getDouble();
+ assertFalse(func.exists());
+
+ // One exists
+ val1.setValue(30).setExists(true);
+ val2.setExists(false);
+ func.getDouble();
+ assertFalse(func.exists());
+
+ // Both exist
+ val1.setValue(30).setExists(true);
+ val2.setValue(21.56F).setExists(true);
+ assertEquals(51.56, func.getDouble(), 0.000001);
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void oneMultiValueParameterTest() {
+ TestLongValueStream val = new TestLongValueStream();
+
+ AnalyticsValueStream uncasted = AddFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof DoubleValue);
+ DoubleValue func = (DoubleValue) uncasted;
+
+ // No values
+ val.setValues();
+ func.getDouble();
+ assertFalse(func.exists());
+
+ // One value
+ val.setValues(30L);
+ assertEquals(30, func.getDouble(), 0.000001);
+ assertTrue(func.exists());
+
+ // Multiple values
+ val.setValues(30L, 20L, 55L, 61L);
+ assertEquals(166, func.getDouble(), 0.000001);
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void oneMultiOneSingleValueParameterTest() {
+ TestLongValueStream val1 = new TestLongValueStream();
+ TestDoubleValue val2 = new TestDoubleValue();
+
+ AnalyticsValueStream uncasted = AddFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2});
+ assertTrue(uncasted instanceof DoubleValueStream);
+ DoubleValueStream func = (DoubleValueStream) uncasted;
+
+ // No values, One value
+ val1.setValues();
+ val2.setValue(21.56F).setExists(true);
+ func.streamDoubles( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple values, no value
+ val1.setValues(4L, 10023L);
+ val2.setExists(false);
+ func.streamDoubles( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple values, one value
+ val1.setValues(4L, 10023L, 48L);
+ val2.setValue(21.56F).setExists(true);
+ Iterator<Double> values = Arrays.asList(25.56, 10044.56, 69.56).iterator();
+ func.streamDoubles( value -> {
+ assertTrue(values.hasNext());
+ assertEquals(values.next(), value, 0.000001);
+ });
+ assertFalse(values.hasNext());
+ }
+
+ @Test
+ public void multipleSingleValueParameterTest() {
+ TestLongValue val1 = new TestLongValue();
+ TestDoubleValue val2 = new TestDoubleValue();
+ TestFloatValue val3 = new TestFloatValue();
+ TestIntValue val4 = new TestIntValue();
+
+ AnalyticsValueStream uncasted = AddFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2, val3, val4});
+ assertTrue(uncasted instanceof DoubleValue);
+ DoubleValue func = (DoubleValue) uncasted;
+
+ // None exist
+ val1.setExists(false);
+ val2.setExists(false);
+ val3.setExists(false);
+ val4.setExists(false);
+ func.getDouble();
+ assertFalse(func.exists());
+
+ // Some exist
+ val1.setExists(false);
+ val2.setValue(30.56).setExists(true);
+ val3.setExists(false);
+ val4.setValue(12).setExists(true);
+ func.getDouble();
+ assertFalse(func.exists());
+
+ // All exist values, one value
+ val1.setValue(45L).setExists(true);
+ val2.setValue(30.56).setExists(true);
+ val3.setValue(2.5F).setExists(true);
+ val4.setValue(12).setExists(true);
+ assertEquals(90.06, func.getDouble(), 0.000001);
+ assertTrue(func.exists());
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/AndFunctionTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/AndFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/AndFunctionTest.java
new file mode 100644
index 0000000..d2e9a1b
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/AndFunctionTest.java
@@ -0,0 +1,192 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.function.mapping;
+
+import java.util.Arrays;
+import java.util.Iterator;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.analytics.function.mapping.LogicFunction.AndFunction;
+import org.apache.solr.analytics.value.AnalyticsValueStream;
+import org.apache.solr.analytics.value.BooleanValue;
+import org.apache.solr.analytics.value.BooleanValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestBooleanValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestBooleanValueStream;
+import org.junit.Test;
+
+public class AndFunctionTest extends SolrTestCaseJ4 {
+ @Test
+ public void twoSingleValueParametersTest() {
+ TestBooleanValue val1 = new TestBooleanValue();
+ TestBooleanValue val2 = new TestBooleanValue();
+
+ AnalyticsValueStream uncasted = AndFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2});
+ assertTrue(uncasted instanceof BooleanValue);
+ BooleanValue func = (BooleanValue) uncasted;
+
+ // Neither exists
+ val1.setExists(false);
+ val2.setExists(false);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ // One exists
+ val1.setValue(true).setExists(true);
+ val2.setExists(false);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ // Both exist
+ val1.setValue(false).setExists(true);
+ val2.setValue(false).setExists(true);
+ assertEquals(false, func.getBoolean());
+ assertTrue(func.exists());
+
+ val1.setValue(true).setExists(true);
+ val2.setValue(false).setExists(true);
+ assertEquals(false, func.getBoolean());
+ assertTrue(func.exists());
+
+ val1.setValue(false).setExists(true);
+ val2.setValue(true).setExists(true);
+ assertEquals(false, func.getBoolean());
+ assertTrue(func.exists());
+
+ val1.setValue(true).setExists(true);
+ val2.setValue(true).setExists(true);
+ assertEquals(true, func.getBoolean());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void oneMultiValueParameterTest() {
+ TestBooleanValueStream val = new TestBooleanValueStream();
+
+ AnalyticsValueStream uncasted = AndFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof BooleanValue);
+ BooleanValue func = (BooleanValue) uncasted;
+
+ // No values
+ val.setValues();
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ // One value
+ val.setValues(true);
+ assertEquals(true, func.getBoolean());
+ assertTrue(func.exists());
+
+ val.setValues(false);
+ assertEquals(false, func.getBoolean());
+ assertTrue(func.exists());
+
+ // Multiple values
+ val.setValues(true, true, false, true);
+ assertEquals(false, func.getBoolean());
+ assertTrue(func.exists());
+
+ val.setValues(true, true, true);
+ assertEquals(true, func.getBoolean());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void oneMultiOneSingleValueParameterTest() {
+ TestBooleanValue val1 = new TestBooleanValue();
+ TestBooleanValueStream val2 = new TestBooleanValueStream();
+
+ AnalyticsValueStream uncasted = AndFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2});
+ assertTrue(uncasted instanceof BooleanValueStream);
+ BooleanValueStream func = (BooleanValueStream) uncasted;
+
+ // No values, One value
+ val1.setValue(false).setExists(true);
+ val2.setValues();
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple values, no value
+ val1.setExists(false);
+ val2.setValues(true, false);
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple values, one value
+ val1.setValue(false).setExists(true);
+ val2.setValues(true, false, true);
+ Iterator<Boolean> values1 = Arrays.asList(false, false, false).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ val1.setValue(true).setExists(true);
+ val2.setValues(true, false, true);
+ Iterator<Boolean> values2 = Arrays.asList(true, false, true).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value);
+ });
+ assertFalse(values2.hasNext());
+ }
+
+ @Test
+ public void multipleSingleValueParameterTest() {
+ TestBooleanValue val1 = new TestBooleanValue();
+ TestBooleanValue val2 = new TestBooleanValue();
+ TestBooleanValue val3 = new TestBooleanValue();
+ TestBooleanValue val4 = new TestBooleanValue();
+
+ AnalyticsValueStream uncasted = AndFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2, val3, val4});
+ assertTrue(uncasted instanceof BooleanValue);
+ BooleanValue func = (BooleanValue) uncasted;
+
+ // None exist
+ val1.setExists(false);
+ val2.setExists(false);
+ val3.setExists(false);
+ val4.setExists(false);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ // Some exist
+ val1.setExists(false);
+ val2.setValue(true).setExists(true);
+ val3.setExists(false);
+ val4.setValue(false).setExists(true);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ // All exist values, one value
+ val1.setValue(true).setExists(true);
+ val2.setValue(false).setExists(true);
+ val3.setValue(true).setExists(true);
+ val4.setValue(true).setExists(true);
+ assertEquals(false, func.getBoolean());
+ assertTrue(func.exists());
+
+ val1.setValue(true).setExists(true);
+ val2.setValue(true).setExists(true);
+ val3.setValue(true).setExists(true);
+ val4.setValue(true).setExists(true);
+ assertEquals(true, func.getBoolean());
+ assertTrue(func.exists());
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/BottomFunctionTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/BottomFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/BottomFunctionTest.java
new file mode 100644
index 0000000..feb43d8
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/BottomFunctionTest.java
@@ -0,0 +1,406 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.function.mapping;
+
+import java.time.Instant;
+import java.time.format.DateTimeParseException;
+import java.util.Date;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.analytics.value.AnalyticsValueStream;
+import org.apache.solr.analytics.value.DateValue;
+import org.apache.solr.analytics.value.DoubleValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestDateValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestDateValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestIntValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestIntValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestLongValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestLongValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestStringValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestStringValueStream;
+import org.apache.solr.analytics.value.FloatValue;
+import org.apache.solr.analytics.value.IntValue;
+import org.apache.solr.analytics.value.LongValue;
+import org.apache.solr.analytics.value.StringValue;
+import org.junit.Test;
+
+public class BottomFunctionTest extends SolrTestCaseJ4 {
+
+ @Test
+ public void multiValueIntTest() {
+ TestIntValueStream val = new TestIntValueStream();
+
+ AnalyticsValueStream uncasted = BottomFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof IntValue);
+ IntValue func = (IntValue) uncasted;
+
+ // Neither exists
+ val.setValues();
+ func.getInt();
+ assertFalse(func.exists());
+
+ // One exists
+ val.setValues(30);
+ assertEquals(30, func.getInt());
+ assertTrue(func.exists());
+
+ // Both exist
+ val.setValues(30, 20, -10, 59);
+ assertEquals(-10, func.getInt());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void multiValueLongTest() {
+ TestLongValueStream val = new TestLongValueStream();
+
+ AnalyticsValueStream uncasted = BottomFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof LongValue);
+ LongValue func = (LongValue) uncasted;
+
+ // Neither exists
+ val.setValues();
+ func.getLong();
+ assertFalse(func.exists());
+
+ // One exists
+ val.setValues(30L);
+ assertEquals(30L, func.getLong());
+ assertTrue(func.exists());
+
+ // Both exist
+ val.setValues(30L, 20L, -10L, 59L);
+ assertEquals(-10L, func.getLong());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void multiValueFloatTest() {
+ TestFloatValueStream val = new TestFloatValueStream();
+
+ AnalyticsValueStream uncasted = BottomFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof FloatValue);
+ FloatValue func = (FloatValue) uncasted;
+
+ // Neither exists
+ val.setValues();
+ func.getFloat();
+ assertFalse(func.exists());
+
+ // One exists
+ val.setValues(30.0F);
+ assertEquals(30.0F, func.getFloat(), .000001);
+ assertTrue(func.exists());
+
+ // Both exist
+ val.setValues(30.5F, 20.01F, -10.49F, -10.48F);
+ assertEquals(-10.49F, func.getFloat(), .000001);
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void multiValueDoubleTest() {
+ TestDoubleValueStream val = new TestDoubleValueStream();
+
+ AnalyticsValueStream uncasted = BottomFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof DoubleValue);
+ DoubleValue func = (DoubleValue) uncasted;
+
+ // Neither exists
+ val.setValues();
+ func.getDouble();
+ assertFalse(func.exists());
+
+ // One exists
+ val.setValues(30.0);
+ assertEquals(30.0, func.getDouble(), .000001);
+ assertTrue(func.exists());
+
+ // Both exist
+ val.setValues(30.5, 20.01, -10.49, -10.48);
+ assertEquals(-10.49, func.getDouble(), .000001);
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void multiValueDateTest() throws DateTimeParseException {
+ TestDateValueStream val = new TestDateValueStream();
+
+ AnalyticsValueStream uncasted = BottomFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof DateValue);
+ DateValue func = (DateValue) uncasted;
+
+ // Neither exists
+ val.setValues();
+ func.getDate();
+ assertFalse(func.exists());
+
+ // One exists
+ val.setValues("1950-05-03T10:30:50Z");
+ assertEquals(Date.from(Instant.parse("1950-05-03T10:30:50Z")), func.getDate());
+ assertTrue(func.exists());
+
+ // Both exist
+ val.setValues("1950-05-03T10:30:50Z", "2200-01-01T10:00:50Z", "1800-12-31T11:30:50Z", "1930-05-020T10:45:50Z");
+ assertEquals(Date.from(Instant.parse("1800-12-31T11:30:50Z")), func.getDate());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void multiValueStringTest() {
+ TestStringValueStream val = new TestStringValueStream();
+
+ AnalyticsValueStream uncasted = BottomFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof StringValue);
+ StringValue func = (StringValue) uncasted;
+
+ // Neither exists
+ val.setValues();
+ func.getString();
+ assertFalse(func.exists());
+
+ // One exists
+ val.setValues("abc");
+ assertEquals("abc", func.getString());
+ assertTrue(func.exists());
+
+ // Both exist
+ val.setValues("1abcdef", "abc", "def", "1abc");
+ assertEquals("1abc", func.getString());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void multipleSingleValueIntTest() {
+ TestIntValue val1 = new TestIntValue();
+ TestIntValue val2 = new TestIntValue();
+ TestIntValue val3 = new TestIntValue();
+ TestIntValue val4 = new TestIntValue();
+
+ AnalyticsValueStream uncasted = BottomFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2, val3, val4});
+ assertTrue(uncasted instanceof IntValue);
+ IntValue func = (IntValue) uncasted;
+
+ // None exist
+ val1.setExists(false);
+ val2.setExists(false);
+ val3.setExists(false);
+ val4.setExists(false);
+ func.getInt();
+ assertFalse(func.exists());
+
+ // Some exist
+ val1.setValue(1000).setExists(false);
+ val2.setValue(30).setExists(true);
+ val3.setValue(-1000).setExists(false);
+ val4.setValue(12).setExists(true);
+ assertEquals(12, func.getInt());
+ assertTrue(func.exists());
+
+ // All exist values, one value
+ val1.setValue(45).setExists(true);
+ val2.setValue(30).setExists(true);
+ val3.setValue(-2).setExists(true);
+ val4.setValue(12).setExists(true);
+ assertEquals(-2, func.getInt());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void multipleSingleValueLongTest() {
+ TestLongValue val1 = new TestLongValue();
+ TestLongValue val2 = new TestLongValue();
+ TestLongValue val3 = new TestLongValue();
+ TestLongValue val4 = new TestLongValue();
+
+ AnalyticsValueStream uncasted = BottomFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2, val3, val4});
+ assertTrue(uncasted instanceof LongValue);
+ LongValue func = (LongValue) uncasted;
+
+ // None exist
+ val1.setExists(false);
+ val2.setExists(false);
+ val3.setExists(false);
+ val4.setExists(false);
+ func.getLong();
+ assertFalse(func.exists());
+
+ // Some exist
+ val1.setValue(1000L).setExists(false);
+ val2.setValue(30L).setExists(true);
+ val3.setValue(-1000L).setExists(false);
+ val4.setValue(12L).setExists(true);
+ assertEquals(12L, func.getLong());
+ assertTrue(func.exists());
+
+ // All exist values, one value
+ val1.setValue(45L).setExists(true);
+ val2.setValue(30L).setExists(true);
+ val3.setValue(-2L).setExists(true);
+ val4.setValue(12L).setExists(true);
+ assertEquals(-2L, func.getLong());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void multipleSingleValueFloatTest() {
+ TestFloatValue val1 = new TestFloatValue();
+ TestFloatValue val2 = new TestFloatValue();
+ TestFloatValue val3 = new TestFloatValue();
+ TestFloatValue val4 = new TestFloatValue();
+
+ AnalyticsValueStream uncasted = BottomFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2, val3, val4});
+ assertTrue(uncasted instanceof FloatValue);
+ FloatValue func = (FloatValue) uncasted;
+
+ // None exist
+ val1.setExists(false);
+ val2.setExists(false);
+ val3.setExists(false);
+ val4.setExists(false);
+ func.getFloat();
+ assertFalse(func.exists());
+
+ // Some exist
+ val1.setValue(1000.1233F).setExists(false);
+ val2.setValue(30.34F).setExists(true);
+ val3.setValue(-1000.3241F).setExists(false);
+ val4.setValue(12.123F).setExists(true);
+ assertEquals(12.123F, func.getFloat(), .000001);
+ assertTrue(func.exists());
+
+ // All exist values, one value
+ val1.setValue(45.43F).setExists(true);
+ val2.setValue(30.231F).setExists(true);
+ val3.setValue(-2.33F).setExists(true);
+ val4.setValue(12.5F).setExists(true);
+ assertEquals(-2.33F, func.getFloat(), .000001);
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void multipleSingleValueDoubleTest() {
+ TestDoubleValue val1 = new TestDoubleValue();
+ TestDoubleValue val2 = new TestDoubleValue();
+ TestDoubleValue val3 = new TestDoubleValue();
+ TestDoubleValue val4 = new TestDoubleValue();
+
+ AnalyticsValueStream uncasted = BottomFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2, val3, val4});
+ assertTrue(uncasted instanceof DoubleValue);
+ DoubleValue func = (DoubleValue) uncasted;
+
+ // None exist
+ val1.setExists(false);
+ val2.setExists(false);
+ val3.setExists(false);
+ val4.setExists(false);
+ func.getDouble();
+ assertFalse(func.exists());
+
+ // Some exist
+ val1.setValue(1000.1233).setExists(false);
+ val2.setValue(30.34).setExists(true);
+ val3.setValue(-1000.3241).setExists(false);
+ val4.setValue(12.123).setExists(true);
+ assertEquals(12.123, func.getDouble(), .000001);
+ assertTrue(func.exists());
+
+ // All exist values, one value
+ val1.setValue(45.43).setExists(true);
+ val2.setValue(30.231).setExists(true);
+ val3.setValue(-2.33).setExists(true);
+ val4.setValue(12.5).setExists(true);
+ assertEquals(-2.33, func.getDouble(), .000001);
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void multipleSingleValueDateTest() throws DateTimeParseException {
+ TestDateValue val1 = new TestDateValue();
+ TestDateValue val2 = new TestDateValue();
+ TestDateValue val3 = new TestDateValue();
+ TestDateValue val4 = new TestDateValue();
+
+ AnalyticsValueStream uncasted = BottomFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2, val3, val4});
+ assertTrue(uncasted instanceof DateValue);
+ DateValue func = (DateValue) uncasted;
+
+ // None exist
+ val1.setExists(false);
+ val2.setExists(false);
+ val3.setExists(false);
+ val4.setExists(false);
+ func.getDate();
+ assertFalse(func.exists());
+
+ // Some exist
+ val1.setValue("9999-05-03T10:30:50Z").setExists(false);
+ val2.setValue("1950-05-03T10:30:50Z").setExists(true);
+ val3.setValue("0000-05-03T10:30:50Z").setExists(false);
+ val4.setValue("1850-05-03T10:30:50Z").setExists(true);
+ assertEquals(Date.from(Instant.parse("1850-05-03T10:30:50Z")), func.getDate());
+ assertTrue(func.exists());
+
+ // All exist values, one value
+ val1.setValue("2200-05-03T10:30:50Z").setExists(true);
+ val2.setValue("1950-05-03T10:30:50Z").setExists(true);
+ val3.setValue("1700-05-03T10:30:50Z").setExists(true);
+ val4.setValue("1850-05-03T10:30:50Z").setExists(true);
+ assertEquals(Date.from(Instant.parse("1700-05-03T10:30:50Z")), func.getDate());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void multipleStringValueDateTest() {
+ TestStringValue val1 = new TestStringValue();
+ TestStringValue val2 = new TestStringValue();
+ TestStringValue val3 = new TestStringValue();
+ TestStringValue val4 = new TestStringValue();
+
+ AnalyticsValueStream uncasted = BottomFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2, val3, val4});
+ assertTrue(uncasted instanceof StringValue);
+ StringValue func = (StringValue) uncasted;
+
+ // None exist
+ val1.setExists(false);
+ val2.setExists(false);
+ val3.setExists(false);
+ val4.setExists(false);
+ func.getString();
+ assertFalse(func.exists());
+
+ // Some exist
+ val1.setValue("abc").setExists(true);
+ val2.setValue("1111").setExists(false);
+ val3.setValue("asdfads").setExists(true);
+ val4.setValue("zzzzzzzz").setExists(false);
+ assertEquals("abc", func.getString());
+ assertTrue(func.exists());
+
+ // All exist values, one value
+ val1.setValue("abc").setExists(true);
+ val2.setValue("abc1234").setExists(true);
+ val3.setValue("asdfads").setExists(true);
+ val4.setValue("fdgsfg").setExists(true);
+ assertEquals("abc", func.getString());
+ assertTrue(func.exists());
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/CeilingFunctionTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/CeilingFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/CeilingFunctionTest.java
new file mode 100644
index 0000000..c527df8
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/CeilingFunctionTest.java
@@ -0,0 +1,180 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.function.mapping;
+
+import java.util.Arrays;
+import java.util.Iterator;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.analytics.function.mapping.DecimalNumericConversionFunction.CeilingFunction;
+import org.apache.solr.analytics.value.AnalyticsValueStream;
+import org.apache.solr.analytics.value.IntValue;
+import org.apache.solr.analytics.value.IntValueStream;
+import org.apache.solr.analytics.value.LongValue;
+import org.apache.solr.analytics.value.LongValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestIntValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestIntValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestLongValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestLongValueStream;
+import org.junit.Test;
+
+public class CeilingFunctionTest extends SolrTestCaseJ4 {
+
+ @Test
+ public void singleValueFloatParameterTest() {
+ TestFloatValue val = new TestFloatValue();
+
+ AnalyticsValueStream uncasted = CeilingFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof IntValue);
+ IntValue func = (IntValue) uncasted;
+
+ // Value doesn't exist
+ val.setExists(false);
+ func.getInt();
+ assertFalse(func.exists());
+
+ // Value exists
+ val.setValue(21.56F).setExists(true);
+ assertEquals(22, func.getInt());
+ assertTrue(func.exists());
+
+ val.setValue(-100.3F).setExists(true);
+ assertEquals(-100, func.getInt());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void singleValueDoubleParameterTest() {
+ TestDoubleValue val = new TestDoubleValue();
+
+ AnalyticsValueStream uncasted = CeilingFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof LongValue);
+ LongValue func = (LongValue) uncasted;
+
+ // Value doesn't exist
+ val.setExists(false);
+ func.getLong();
+ assertFalse(func.exists());
+
+ // Value exists
+ val.setValue(21.56).setExists(true);
+ assertEquals(22L, func.getLong());
+ assertTrue(func.exists());
+
+ val.setValue(-100.3).setExists(true);
+ assertEquals(-100L, func.getLong());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void multiValueFloatParameterTest() {
+ TestFloatValueStream val = new TestFloatValueStream();
+
+ AnalyticsValueStream uncasted = CeilingFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof IntValueStream);
+ IntValueStream func = (IntValueStream) uncasted;
+
+ // No values
+ val.setValues();
+ func.streamInts( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // One value
+ val.setValues(-4F);
+ Iterator<Integer> values1 = Arrays.asList(-4).iterator();
+ func.streamInts( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next().intValue(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ // Multiple values
+ val.setValues(4F, -10.9999F, 50.00001F, 74.99999F);
+ Iterator<Integer> values2 = Arrays.asList(4, -10, 51, 75).iterator();
+ func.streamInts( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next().intValue(), value);
+ });
+ assertFalse(values2.hasNext());
+ }
+
+ @Test
+ public void multiValueDoubleParameterTest() {
+ TestDoubleValueStream val = new TestDoubleValueStream();
+
+ AnalyticsValueStream uncasted = CeilingFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof LongValueStream);
+ LongValueStream func = (LongValueStream) uncasted;
+
+ // No values
+ val.setValues();
+ func.streamLongs( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // One value
+ val.setValues(-4);
+ Iterator<Long> values1 = Arrays.asList(-4L).iterator();
+ func.streamLongs( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next().longValue(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ // Multiple values
+ val.setValues(4, -10.9999, 50.000001, 74.99999);
+ Iterator<Long> values2 = Arrays.asList(4L, -10L, 51L, 75L).iterator();
+ func.streamLongs( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next().longValue(), value);
+ });
+ assertFalse(values2.hasNext());
+ }
+
+ @Test
+ public void nonDecimalParameterTest() {
+ AnalyticsValueStream result;
+ AnalyticsValueStream param;
+
+ param = new TestIntValue();
+ result = CeilingFunction.creatorFunction.apply(new AnalyticsValueStream[] {param});
+ assertTrue(result instanceof IntValue);
+ assertEquals(param, result);
+
+ param = new TestIntValueStream();
+ result = CeilingFunction.creatorFunction.apply(new AnalyticsValueStream[] {param});
+ assertTrue(result instanceof IntValueStream);
+ assertEquals(param, result);
+
+ param = new TestLongValue();
+ result = CeilingFunction.creatorFunction.apply(new AnalyticsValueStream[] {param});
+ assertTrue(result instanceof LongValue);
+ assertEquals(param, result);
+
+ param = new TestLongValueStream();
+ result = CeilingFunction.creatorFunction.apply(new AnalyticsValueStream[] {param});
+ assertTrue(result instanceof LongValueStream);
+ assertEquals(param, result);
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/ConcatFunctionTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/ConcatFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/ConcatFunctionTest.java
new file mode 100644
index 0000000..db5b36e
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/ConcatFunctionTest.java
@@ -0,0 +1,317 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.function.mapping;
+
+import java.util.Arrays;
+import java.util.Iterator;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.analytics.function.mapping.ConcatFunction.SeparatedConcatFunction;
+import org.apache.solr.analytics.value.AnalyticsValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestStringValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestStringValueStream;
+import org.apache.solr.analytics.value.StringValue;
+import org.apache.solr.analytics.value.StringValueStream;
+import org.apache.solr.analytics.value.constant.ConstantStringValue;
+import org.junit.Test;
+
+public class ConcatFunctionTest extends SolrTestCaseJ4 {
+
+ @Test
+ public void oneMultiValueParameterUnseparatedTest() {
+ TestStringValueStream val = new TestStringValueStream();
+
+ AnalyticsValueStream uncasted = ConcatFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof StringValue);
+ StringValue func = (StringValue) uncasted;
+
+ // No values
+ val.setValues();
+ func.getString();
+ assertFalse(func.exists());
+
+ // One value
+ val.setValues("abc");
+ assertEquals("abc", func.getString());
+ assertTrue(func.exists());
+
+ // Multiple values
+ val.setValues("abc", "def", "ghi");
+ assertEquals("abcdefghi", func.getString());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void oneMultiValueParameterSeparatedTest() {
+ TestStringValueStream val = new TestStringValueStream();
+ ConstantStringValue sep = new ConstantStringValue("===:---");
+
+ AnalyticsValueStream uncasted = SeparatedConcatFunction.creatorFunction.apply(new AnalyticsValueStream[] {sep, val});
+ assertTrue(uncasted instanceof StringValue);
+ StringValue func = (StringValue) uncasted;
+
+ // No values
+ val.setValues();
+ func.getString();
+ assertFalse(func.exists());
+
+ // One value
+ val.setValues("abc");
+ assertEquals("abc", func.getString());
+ assertTrue(func.exists());
+
+ // Multiple values
+ val.setValues("abc", "def", "ghi");
+ assertEquals("abc===:---def===:---ghi", func.getString());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void oneSingleOneMultiValueParameterUnseperatedTest() {
+ TestStringValue val1 = new TestStringValue();
+ TestStringValueStream val2 = new TestStringValueStream();
+
+ AnalyticsValueStream uncasted = ConcatFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2});
+ assertTrue(uncasted instanceof StringValueStream);
+ StringValueStream func = (StringValueStream) uncasted;
+
+ // None exist
+ val1.setExists(false);
+ val2.setValues();
+ func.streamStrings( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // One exists
+ val1.setExists(false);
+ val2.setValues("def");
+ func.streamStrings( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ val1.setValue("abc").setExists(true);
+ val2.setValues();
+ func.streamStrings( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Both exist
+ val1.setValue("abc").setExists(true);
+ val2.setValues("def", "ghi", "jkl");
+ Iterator<String> values2 = Arrays.asList("abcdef", "abcghi", "abcjkl").iterator();
+ func.streamStrings( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value);
+ });
+ assertFalse(values2.hasNext());
+ }
+
+ @Test
+ public void oneSingleOneMultiValueParameterSeperatedTest() {
+ TestStringValue val1 = new TestStringValue();
+ TestStringValueStream val2 = new TestStringValueStream();
+ ConstantStringValue sep = new ConstantStringValue("+-;");
+
+ AnalyticsValueStream uncasted = SeparatedConcatFunction.creatorFunction.apply(new AnalyticsValueStream[] {sep, val1, val2});
+ assertTrue(uncasted instanceof StringValueStream);
+ StringValueStream func = (StringValueStream) uncasted;
+
+ // None exist
+ val1.setExists(false);
+ val2.setValues();
+ func.streamStrings( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // One exists
+ val1.setExists(false);
+ val2.setValues("def");
+ func.streamStrings( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ val1.setValue("abc").setExists(true);
+ val2.setValues();
+ func.streamStrings( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Both exist
+ val1.setValue("abc").setExists(true);
+ val2.setValues("def", "ghi", "jkl");
+ Iterator<String> values2 = Arrays.asList("abc+-;def", "abc+-;ghi", "abc+-;jkl").iterator();
+ func.streamStrings( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value);
+ });
+ assertFalse(values2.hasNext());
+ }
+
+ @Test
+ public void oneMultiOneSingleValueParameterUnseperatedTest() {
+ TestStringValueStream val1 = new TestStringValueStream();
+ TestStringValue val2 = new TestStringValue();
+
+ AnalyticsValueStream uncasted = ConcatFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2});
+ assertTrue(uncasted instanceof StringValueStream);
+ StringValueStream func = (StringValueStream) uncasted;
+
+ // None exist
+ val1.setValues();
+ val2.setExists(false);
+ func.streamStrings( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // One exists
+ val1.setValues("def");
+ val2.setExists(false);
+ func.streamStrings( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ val1.setValues();
+ val2.setValue("abc").setExists(true);
+ func.streamStrings( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Both exist
+ val1.setValues("def", "ghi", "jkl");
+ val2.setValue("abc").setExists(true);
+ Iterator<String> values2 = Arrays.asList("defabc", "ghiabc", "jklabc").iterator();
+ func.streamStrings( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value);
+ });
+ assertFalse(values2.hasNext());
+ }
+
+ @Test
+ public void oneMultiOneSingleValueParameterSeperatedTest() {
+ TestStringValueStream val1 = new TestStringValueStream();
+ TestStringValue val2 = new TestStringValue();
+ ConstantStringValue sep = new ConstantStringValue("<");
+
+ AnalyticsValueStream uncasted = SeparatedConcatFunction.creatorFunction.apply(new AnalyticsValueStream[] {sep, val1, val2});
+ assertTrue(uncasted instanceof StringValueStream);
+ StringValueStream func = (StringValueStream) uncasted;
+
+ // None exist
+ val1.setValues();
+ val2.setExists(false);
+ func.streamStrings( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // One exists
+ val1.setValues("def");
+ val2.setExists(false);
+ func.streamStrings( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ val1.setValues();
+ val2.setValue("abc").setExists(true);
+ func.streamStrings( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Both exist
+ val1.setValues("def", "ghi", "jkl");
+ val2.setValue("abc").setExists(true);
+ Iterator<String> values2 = Arrays.asList("def<abc", "ghi<abc", "jkl<abc").iterator();
+ func.streamStrings( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value);
+ });
+ assertFalse(values2.hasNext());
+ }
+
+ @Test
+ public void multipleSingleValueParameterUnseperatedTest() {
+ TestStringValue val1 = new TestStringValue();
+ TestStringValue val2 = new TestStringValue();
+ TestStringValue val3 = new TestStringValue();
+ TestStringValue val4 = new TestStringValue();
+
+ AnalyticsValueStream uncasted = ConcatFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2, val3, val4});
+ assertTrue(uncasted instanceof StringValue);
+ StringValue func = (StringValue) uncasted;
+
+ // None exist
+ val1.setExists(false);
+ val2.setExists(false);
+ val3.setExists(false);
+ val4.setExists(false);
+ func.getString();
+ assertFalse(func.exists());
+
+ // Some exist
+ val1.setExists(false);
+ val2.setValue("def").setExists(true);
+ val3.setExists(false);
+ val4.setValue("jkl").setExists(true);
+ assertEquals("defjkl", func.getString());
+ assertTrue(func.exists());
+
+ // All exist values, one value
+ val1.setValue("abc").setExists(true);
+ val2.setValue("def").setExists(true);
+ val3.setValue("ghi").setExists(true);
+ val4.setValue("jkl").setExists(true);
+ assertEquals("abcdefghijkl", func.getString());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void multipleSingleValueParameterSeperatedTest() {
+ TestStringValue val1 = new TestStringValue();
+ TestStringValue val2 = new TestStringValue();
+ TestStringValue val3 = new TestStringValue();
+ TestStringValue val4 = new TestStringValue();
+ ConstantStringValue sep = new ConstantStringValue("+:-");
+
+ AnalyticsValueStream uncasted = SeparatedConcatFunction.creatorFunction.apply(new AnalyticsValueStream[] {sep, val1, val2, val3, val4});
+ assertTrue(uncasted instanceof StringValue);
+ StringValue func = (StringValue) uncasted;
+
+ // None exist
+ val1.setExists(false);
+ val2.setExists(false);
+ val3.setExists(false);
+ val4.setExists(false);
+ func.getString();
+ assertFalse(func.exists());
+
+ // Some exist
+ val1.setExists(false);
+ val2.setValue("def").setExists(true);
+ val3.setExists(false);
+ val4.setValue("jkl").setExists(true);
+ assertEquals("def+:-jkl", func.getString());
+ assertTrue(func.exists());
+
+ // All exist values, one value
+ val1.setValue("abc").setExists(true);
+ val2.setValue("def").setExists(true);
+ val3.setValue("ghi").setExists(true);
+ val4.setValue("jkl").setExists(true);
+ assertEquals("abc+:-def+:-ghi+:-jkl", func.getString());
+ assertTrue(func.exists());
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/DateMathFunctionTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/DateMathFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/DateMathFunctionTest.java
new file mode 100644
index 0000000..f3802af
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/DateMathFunctionTest.java
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.function.mapping;
+
+import java.time.Instant;
+import java.time.format.DateTimeParseException;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.Iterator;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.analytics.value.AnalyticsValueStream;
+import org.apache.solr.analytics.value.DateValue;
+import org.apache.solr.analytics.value.DateValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestDateValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestDateValueStream;
+import org.apache.solr.analytics.value.constant.ConstantStringValue;
+import org.junit.Test;
+
+public class DateMathFunctionTest extends SolrTestCaseJ4 {
+
+ @Test
+ public void singleValueParameterTest() throws DateTimeParseException {
+ Date date1 = Date.from(Instant.parse("1810-12-02T10:30:15Z"));
+ Date date2 = Date.from(Instant.parse("1931-03-16T18:15:45Z"));
+
+ TestDateValue val = new TestDateValue();
+
+ ConstantStringValue math1 = new ConstantStringValue("+1DAY");
+ ConstantStringValue math2 = new ConstantStringValue("-1MONTH");
+ ConstantStringValue math3 = new ConstantStringValue("+11YEARS");
+
+ AnalyticsValueStream uncasted = DateMathFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, math1, math2, math3});
+ assertTrue(uncasted instanceof DateValue);
+ DateValue func = (DateValue) uncasted;
+
+ // Value doesn't exist
+ val.setExists(false);
+ func.getDate();
+ assertFalse(func.exists());
+ func.getLong();
+ assertFalse(func.exists());
+
+ // Value exists
+ val.setValue("1800-01-01T10:30:15Z").setExists(true);
+ assertEquals(date1, func.getDate());
+ assertTrue(func.exists());
+ assertEquals(date1.getTime(), func.getLong());
+ assertTrue(func.exists());
+
+ val.setValue("1920-04-15T18:15:45Z").setExists(true);
+ assertEquals(date2, func.getDate());
+ assertTrue(func.exists());
+ assertEquals(date2.getTime(), func.getLong());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void multiValueParamaterTest() throws DateTimeParseException {
+ Date date1 = Date.from(Instant.parse("1810-12-02T10:30:15Z"));
+ Date date2 = Date.from(Instant.parse("1931-03-16T18:15:45Z"));
+ Date date3 = Date.from(Instant.parse("2023-11-01T20:30:15Z"));
+
+ TestDateValueStream val = new TestDateValueStream();
+
+ ConstantStringValue math1 = new ConstantStringValue("+1DAY");
+ ConstantStringValue math2 = new ConstantStringValue("-1MONTH");
+ ConstantStringValue math3 = new ConstantStringValue("+11YEARS");
+
+ AnalyticsValueStream uncasted = DateMathFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, math1, math2, math3});
+ assertTrue(uncasted instanceof DateValueStream);
+ DateValueStream func = (DateValueStream) uncasted;
+
+ // No values
+ val.setValues();
+ func.streamDates( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+ func.streamLongs( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // One value
+ val.setValues("1800-01-01T10:30:15Z");
+ Iterator<Date> values1 = Arrays.asList(date1).iterator();
+ func.streamDates( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value);
+ });
+ assertFalse(values1.hasNext());
+ Iterator<Long> times1 = Arrays.asList(date1.getTime()).iterator();
+ func.streamLongs( value -> {
+ assertTrue(times1.hasNext());
+ assertEquals(times1.next().longValue(), value);
+ });
+ assertFalse(times1.hasNext());
+
+ // Multiple values
+ val.setValues("1800-01-01T10:30:15Z", "1920-04-15T18:15:45Z", "2012-11-30T20:30:15Z");
+ Iterator<Date> values2 = Arrays.asList(date1, date2, date3).iterator();
+ func.streamDates( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value);
+ });
+ assertFalse(values2.hasNext());
+ Iterator<Long> times2 = Arrays.asList(date1.getTime(), date2.getTime(), date3.getTime()).iterator();
+ func.streamLongs( value -> {
+ assertTrue(times2.hasNext());
+ assertEquals(times2.next().longValue(), value);
+ });
+ assertFalse(times2.hasNext());
+ }
+}
[08/20] lucene-solr:master: SOLR-11145,
SOLR-11146: Added comprehensive unit tests for Analytics Component
2.0 as well as analytics bug fixes.
Posted by dp...@apache.org.
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/IfFunctionTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/IfFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/IfFunctionTest.java
new file mode 100644
index 0000000..0a48ac9
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/IfFunctionTest.java
@@ -0,0 +1,994 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.function.mapping;
+
+import java.time.Instant;
+import java.time.format.DateTimeParseException;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.Iterator;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.analytics.value.AnalyticsValue;
+import org.apache.solr.analytics.value.AnalyticsValueStream;
+import org.apache.solr.analytics.value.BooleanValue;
+import org.apache.solr.analytics.value.BooleanValueStream;
+import org.apache.solr.analytics.value.DateValue;
+import org.apache.solr.analytics.value.DateValueStream;
+import org.apache.solr.analytics.value.DoubleValue;
+import org.apache.solr.analytics.value.DoubleValueStream;
+import org.apache.solr.analytics.value.FloatValue;
+import org.apache.solr.analytics.value.FloatValueStream;
+import org.apache.solr.analytics.value.IntValue;
+import org.apache.solr.analytics.value.IntValueStream;
+import org.apache.solr.analytics.value.LongValue;
+import org.apache.solr.analytics.value.LongValueStream;
+import org.apache.solr.analytics.value.StringValue;
+import org.apache.solr.analytics.value.StringValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestAnalyticsValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestAnalyticsValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestBooleanValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestBooleanValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestDateValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestDateValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestIntValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestIntValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestLongValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestLongValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestStringValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestStringValueStream;
+import org.junit.Test;
+
+public class IfFunctionTest extends SolrTestCaseJ4 {
+
+ @Test
+ public void castingTest() {
+ assertTrue(IfFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestBooleanValue(), new TestStringValue(), new TestStringValue()}) instanceof StringValue);
+
+ assertFalse(IfFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestBooleanValue(), new TestFloatValue(), new TestDoubleValue()}) instanceof FloatValueStream);
+
+ assertFalse(IfFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestBooleanValue(), new TestDateValue(), new TestLongValue()}) instanceof DateValueStream);
+
+ assertFalse(IfFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestBooleanValue(), new TestAnalyticsValue(), new TestStringValue()}) instanceof StringValue);
+
+ assertTrue(IfFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestBooleanValue(), new TestLongValue(), new TestFloatValue()}) instanceof DoubleValue);
+
+ assertFalse(IfFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestBooleanValue(), new TestStringValue(), new TestLongValue()}) instanceof DateValue);
+
+ assertFalse(IfFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestBooleanValue(), new TestStringValue(), new TestStringValue()}) instanceof BooleanValueStream);
+
+ assertFalse(IfFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestBooleanValue(), new TestIntValueStream(), new TestLongValue()}) instanceof LongValue);
+ }
+
+ @Test
+ public void singleValueBooleanTest() {
+ TestBooleanValue cond = new TestBooleanValue();
+ TestBooleanValue then = new TestBooleanValue();
+ TestBooleanValue els = new TestBooleanValue();
+
+ AnalyticsValueStream uncasted = IfFunction.creatorFunction.apply(new AnalyticsValueStream[] {cond, then, els});
+ assertTrue(uncasted instanceof BooleanValue);
+ BooleanValue func = (BooleanValue) uncasted;
+
+ // Condition doesn't exist
+ then.setExists(false);
+ then.setExists(false);
+ els.setExists(false);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ cond.setExists(false);
+ then.setValue(false).setExists(true);
+ els.setValue(true).setExists(true);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ // Result doesn't exist
+ cond.setValue(true).setExists(true);
+ then.setExists(false);
+ els.setValue(false).setExists(true);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ cond.setValue(false).setExists(true);
+ then.setValue(true).setExists(true);
+ els.setExists(false);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ // Value exists
+ cond.setValue(true).setExists(true);
+ then.setValue(false).setExists(true);
+ els.setValue(true).setExists(true);
+ assertEquals(false, func.getBoolean());
+ assertTrue(func.exists());
+
+ cond.setValue(true).setExists(true);
+ then.setValue(true).setExists(true);
+ els.setValue(false).setExists(true);
+ assertEquals(true, func.getBoolean());
+ assertTrue(func.exists());
+
+ cond.setValue(false).setExists(true);
+ then.setValue(false).setExists(true);
+ els.setValue(true).setExists(true);
+ assertEquals(true, func.getBoolean());
+ assertTrue(func.exists());
+
+ cond.setValue(false).setExists(true);
+ then.setValue(true).setExists(true);
+ els.setValue(false).setExists(true);
+ assertEquals(false, func.getBoolean());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void singleValueIntTest() {
+ TestBooleanValue cond = new TestBooleanValue();
+ TestIntValue then = new TestIntValue();
+ TestIntValue els = new TestIntValue();
+
+ AnalyticsValueStream uncasted = IfFunction.creatorFunction.apply(new AnalyticsValueStream[] {cond, then, els});
+ assertTrue(uncasted instanceof IntValue);
+ IntValue func = (IntValue) uncasted;
+
+ // Condition doesn't exist
+ cond.setExists(false);
+ then.setExists(false);
+ els.setExists(false);
+ func.getInt();
+ assertFalse(func.exists());
+
+ cond.setExists(false);
+ then.setValue(-234).setExists(true);
+ els.setValue(765).setExists(true);
+ func.getInt();
+ assertFalse(func.exists());
+
+ // Result doesn't exist
+ cond.setValue(true).setExists(true);
+ then.setExists(false);
+ els.setValue(23423).setExists(true);
+ func.getInt();
+ assertFalse(func.exists());
+
+ cond.setValue(false).setExists(true);
+ then.setValue(745).setExists(true);
+ els.setExists(false);
+ func.getInt();
+ assertFalse(func.exists());
+
+ // Value exists
+ cond.setValue(true).setExists(true);
+ then.setValue(234).setExists(true);
+ els.setValue(-23423).setExists(true);
+ assertEquals(234, func.getInt());
+ assertTrue(func.exists());
+
+ cond.setValue(false).setExists(true);
+ then.setValue(234).setExists(true);
+ els.setValue(-23423).setExists(true);
+ assertEquals(-23423, func.getInt());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void singleValueLongTest() {
+ TestBooleanValue cond = new TestBooleanValue();
+ TestLongValue then = new TestLongValue();
+ TestLongValue els = new TestLongValue();
+
+ AnalyticsValueStream uncasted = IfFunction.creatorFunction.apply(new AnalyticsValueStream[] {cond, then, els});
+ assertTrue(uncasted instanceof LongValue);
+ LongValue func = (LongValue) uncasted;
+
+ // Condition doesn't exist
+ cond.setExists(false);
+ then.setExists(false);
+ els.setExists(false);
+ func.getLong();
+ assertFalse(func.exists());
+
+ cond.setExists(false);
+ then.setValue(-234L).setExists(true);
+ els.setValue(765L).setExists(true);
+ func.getLong();
+ assertFalse(func.exists());
+
+ // Result doesn't exist
+ cond.setValue(true).setExists(true);
+ then.setExists(false);
+ els.setValue(23423L).setExists(true);
+ func.getLong();
+ assertFalse(func.exists());
+
+ cond.setValue(false).setExists(true);
+ then.setValue(745L).setExists(true);
+ els.setExists(false);
+ func.getLong();
+ assertFalse(func.exists());
+
+ // Value exists
+ cond.setValue(true).setExists(true);
+ then.setValue(234L).setExists(true);
+ els.setValue(-23423L).setExists(true);
+ assertEquals(234L, func.getLong());
+ assertTrue(func.exists());
+
+ cond.setValue(false).setExists(true);
+ then.setValue(234l).setExists(true);
+ els.setValue(-23423L).setExists(true);
+ assertEquals(-23423L, func.getLong());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void singleValueFloatTest() {
+ TestBooleanValue cond = new TestBooleanValue();
+ TestFloatValue then = new TestFloatValue();
+ TestFloatValue els = new TestFloatValue();
+
+ AnalyticsValueStream uncasted = IfFunction.creatorFunction.apply(new AnalyticsValueStream[] {cond, then, els});
+ assertTrue(uncasted instanceof FloatValue);
+ FloatValue func = (FloatValue) uncasted;
+
+ // Condition doesn't exist
+ cond.setExists(false);
+ then.setExists(false);
+ els.setExists(false);
+ func.getFloat();
+ assertFalse(func.exists());
+
+ cond.setExists(false);
+ then.setValue(234.7565F).setExists(true);
+ els.setValue(-234.7565F).setExists(true);
+ func.getFloat();
+ assertFalse(func.exists());
+
+ // Result doesn't exist
+ cond.setValue(true).setExists(true);
+ then.setExists(false);
+ els.setValue(234.7565F).setExists(true);
+ func.getFloat();
+ assertFalse(func.exists());
+
+ cond.setValue(false).setExists(true);
+ then.setValue(-23423.234F).setExists(true);
+ els.setExists(false);
+ func.getFloat();
+ assertFalse(func.exists());
+
+ // Value exists
+ cond.setValue(true).setExists(true);
+ then.setValue(234.7565F).setExists(true);
+ els.setValue(-23423.234F).setExists(true);
+ assertEquals(234.7565F, func.getFloat(), .0000001);
+ assertTrue(func.exists());
+
+ cond.setValue(false).setExists(true);
+ then.setValue(234.7565F).setExists(true);
+ els.setValue(-23423.234F).setExists(true);
+ assertEquals(-23423.234F, func.getFloat(), .0000001);
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void singleValueDoubleTest() {
+ TestBooleanValue cond = new TestBooleanValue();
+ TestDoubleValue then = new TestDoubleValue();
+ TestDoubleValue els = new TestDoubleValue();
+
+ AnalyticsValueStream uncasted = IfFunction.creatorFunction.apply(new AnalyticsValueStream[] {cond, then, els});
+ assertTrue(uncasted instanceof DoubleValue);
+ DoubleValue func = (DoubleValue) uncasted;
+
+ // Condition doesn't exist
+ cond.setExists(false);
+ then.setExists(false);
+ els.setExists(false);
+ func.getDouble();
+ assertFalse(func.exists());
+
+ cond.setExists(false);
+ then.setValue(234.7565).setExists(true);
+ els.setValue(-234.7565).setExists(true);
+ func.getDouble();
+ assertFalse(func.exists());
+
+ // Result doesn't exist
+ cond.setValue(true).setExists(true);
+ then.setExists(false);
+ els.setValue(234.7565).setExists(true);
+ func.getDouble();
+ assertFalse(func.exists());
+
+ cond.setValue(false).setExists(true);
+ then.setValue(-23423.234).setExists(true);
+ els.setExists(false);
+ func.getDouble();
+ assertFalse(func.exists());
+
+ // Value exists
+ cond.setValue(true).setExists(true);
+ then.setValue(234.7565).setExists(true);
+ els.setValue(-23423.234).setExists(true);
+ assertEquals(234.7565, func.getDouble(), .0000001);
+ assertTrue(func.exists());
+
+ cond.setValue(false).setExists(true);
+ then.setValue(234.7565).setExists(true);
+ els.setValue(-23423.234).setExists(true);
+ assertEquals(-23423.234, func.getDouble(), .0000001);
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void singleValueDateTest() throws DateTimeParseException {
+ Date date1 = Date.from(Instant.parse("1810-12-02T10:30:15Z"));
+ Date date2 = Date.from(Instant.parse("1950-02-23T14:54:34Z"));
+ Date date3 = Date.from(Instant.parse("2023-11-01T20:30:15Z"));
+
+ TestBooleanValue cond = new TestBooleanValue();
+ TestDateValue then = new TestDateValue();
+ TestDateValue els = new TestDateValue();
+
+ AnalyticsValueStream uncasted = IfFunction.creatorFunction.apply(new AnalyticsValueStream[] {cond, then, els});
+ assertTrue(uncasted instanceof DateValue);
+ DateValue func = (DateValue) uncasted;
+
+ // Condition doesn't exist
+ cond.setExists(false);
+ then.setExists(false);
+ els.setExists(false);
+ func.getLong();
+ assertFalse(func.exists());
+
+ cond.setExists(false);
+ then.setValue("6723-08-01T23:30:15Z").setExists(true);
+ els.setValue("2207-11-01T20:30:15Z").setExists(true);
+ func.getLong();
+ assertFalse(func.exists());
+
+ // Result doesn't exist
+ cond.setValue(true).setExists(true);
+ then.setExists(false);
+ els.setValue("1810-12-02T10:30:15Z").setExists(true);
+ func.getLong();
+ assertFalse(func.exists());
+
+ cond.setValue(false).setExists(true);
+ then.setValue("2023-11-01T20:30:15Z").setExists(true);
+ els.setExists(false);
+ func.getLong();
+ assertFalse(func.exists());
+
+ // Value exists
+ cond.setValue(true).setExists(true);
+ then.setValue("1810-12-02T10:30:15Z").setExists(true);
+ els.setValue("2023-11-01T20:30:15Z").setExists(true);
+ assertEquals(date1.getTime(), func.getLong());
+ assertTrue(func.exists());
+
+ cond.setValue(false).setExists(true);
+ then.setValue("1810-12-02T10:30:15Z").setExists(true);
+ els.setValue("2023-11-01T20:30:15Z").setExists(true);
+ assertEquals(date3.getTime(), func.getLong());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void singleValueStringTest() {
+ TestBooleanValue cond = new TestBooleanValue();
+ TestStringValue then = new TestStringValue();
+ TestStringValue els = new TestStringValue();
+
+ AnalyticsValueStream uncasted = IfFunction.creatorFunction.apply(new AnalyticsValueStream[] {cond, then, els});
+ assertTrue(uncasted instanceof StringValue);
+ StringValue func = (StringValue) uncasted;
+
+ // Condition doesn't exist
+ cond.setExists(false);
+ then.setExists(false);
+ els.setExists(false);
+ func.getString();
+ assertFalse(func.exists());
+
+ cond.setExists(false);
+ then.setValue("if the value is true").setExists(true);
+ els.setValue("when the value is false").setExists(true);
+ func.getString();
+ assertFalse(func.exists());
+
+ // Result doesn't exist
+ cond.setValue(true).setExists(true);
+ then.setExists(false);
+ els.setValue("not picked").setExists(true);
+ func.getString();
+ assertFalse(func.exists());
+
+ cond.setValue(false).setExists(true);
+ then.setValue("also not picked").setExists(true);
+ els.setExists(false);
+ func.getString();
+ assertFalse(func.exists());
+
+ // Value exists
+ cond.setValue(true).setExists(true);
+ then.setValue("abc123").setExists(true);
+ els.setValue("def456").setExists(true);
+ assertEquals("abc123", func.getString());
+ assertTrue(func.exists());
+
+ cond.setValue(false).setExists(true);
+ then.setValue("abc123").setExists(true);
+ els.setValue("def456").setExists(true);
+ assertEquals("def456", func.getString());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void singleValueObjectTest() {
+ TestBooleanValue cond = new TestBooleanValue();
+ TestAnalyticsValue then = new TestAnalyticsValue();
+ TestAnalyticsValue els = new TestAnalyticsValue();
+
+ AnalyticsValueStream uncasted = IfFunction.creatorFunction.apply(new AnalyticsValueStream[] {cond, then, els});
+ assertTrue(uncasted instanceof AnalyticsValue);
+ AnalyticsValue func = (AnalyticsValue) uncasted;
+
+ // Condition doesn't exist
+ cond.setExists(false);
+ then.setExists(false);
+ els.setExists(false);
+ func.getObject();
+ assertFalse(func.exists());
+
+ cond.setExists(false);
+ then.setValue("if the value is true").setExists(true);
+ els.setValue(new Boolean(false)).setExists(true);
+ func.getObject();
+ assertFalse(func.exists());
+
+ // Result doesn't exist
+ cond.setValue(true).setExists(true);
+ then.setExists(false);
+ els.setValue(new Long(123421324L)).setExists(true);
+ func.getObject();
+ assertFalse(func.exists());
+
+ cond.setValue(false).setExists(true);
+ then.setValue(new Float(1234324.454F)).setExists(true);
+ els.setExists(false);
+ func.getObject();
+ assertFalse(func.exists());
+
+ // Value exists
+ cond.setValue(true).setExists(true);
+ then.setValue("abc123").setExists(true);
+ els.setValue(new Date(3214)).setExists(true);
+ assertEquals("abc123", func.getObject());
+ assertTrue(func.exists());
+
+ cond.setValue(false).setExists(true);
+ then.setValue("abc123").setExists(true);
+ els.setValue(new Date(3214)).setExists(true);
+ assertEquals(new Date(3214), func.getObject());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void multiValueBooleanTest() {
+ TestBooleanValue cond = new TestBooleanValue();
+ TestBooleanValueStream then = new TestBooleanValueStream();
+ TestBooleanValueStream els = new TestBooleanValueStream();
+
+ AnalyticsValueStream uncasted = IfFunction.creatorFunction.apply(new AnalyticsValueStream[] {cond, then, els});
+ assertTrue(uncasted instanceof BooleanValueStream);
+ BooleanValueStream func = (BooleanValueStream) uncasted;
+
+ // No values
+ cond.setExists(false);
+ then.setValues();
+ els.setValues();
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ cond.setExists(false);
+ then.setValues(false, true, false);
+ els.setValues(true, true, true, false);
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Result doesn't exist
+ cond.setValue(true).setExists(true);
+ then.setValues();
+ els.setValues(true, true, true, false);
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ cond.setValue(false).setExists(true);
+ then.setValues(true, true, true, false);
+ els.setValues();
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Values exist
+ cond.setValue(true).setExists(true);
+ then.setValues(true, true, true, false);
+ els.setValues(false, false, true, false, true);
+ Iterator<Boolean> values1 = Arrays.asList(true, true, true, false).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ cond.setValue(false).setExists(true);
+ then.setValues(true, true, true, false);
+ els.setValues(false, false, true, false, true);
+ Iterator<Boolean> values2 = Arrays.asList(false, false, true, false, true).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value);
+ });
+ assertFalse(values2.hasNext());
+ }
+
+ @Test
+ public void multiValueIntTest() {
+ TestBooleanValue cond = new TestBooleanValue();
+ TestIntValueStream then = new TestIntValueStream();
+ TestIntValueStream els = new TestIntValueStream();
+
+ AnalyticsValueStream uncasted = IfFunction.creatorFunction.apply(new AnalyticsValueStream[] {cond, then, els});
+ assertTrue(uncasted instanceof IntValueStream);
+ IntValueStream func = (IntValueStream) uncasted;
+
+ // No values
+ cond.setExists(false);
+ then.setValues();
+ els.setValues();
+ func.streamInts( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ cond.setExists(false);
+ then.setValues(-132, 41543, 563);
+ els.setValues(0, 1, -2, 3);
+ func.streamInts( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Result doesn't exist
+ cond.setValue(true).setExists(true);
+ then.setValues();
+ els.setValues(0, 1, -2, 3);
+ func.streamInts( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ cond.setValue(false).setExists(true);
+ then.setValues(-132, 41543, 563);
+ els.setValues();
+ func.streamInts( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Values exist
+ cond.setValue(true).setExists(true);
+ then.setValues(-132, 41543, 563);
+ els.setValues(0, 1, -2, 3);
+ Iterator<Integer> values1 = Arrays.asList(-132, 41543, 563).iterator();
+ func.streamInts( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next().intValue(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ cond.setValue(false).setExists(true);
+ then.setValues(-132, 41543, 563);
+ els.setValues(0, 1, -2, 3);
+ Iterator<Integer> values2 = Arrays.asList(0, 1, -2, 3).iterator();
+ func.streamInts( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next().intValue(), value);
+ });
+ assertFalse(values2.hasNext());
+ }
+
+ @Test
+ public void multiValueLongTest() {
+ TestBooleanValue cond = new TestBooleanValue();
+ TestLongValueStream then = new TestLongValueStream();
+ TestLongValueStream els = new TestLongValueStream();
+
+ AnalyticsValueStream uncasted = IfFunction.creatorFunction.apply(new AnalyticsValueStream[] {cond, then, els});
+ assertTrue(uncasted instanceof LongValueStream);
+ LongValueStream func = (LongValueStream) uncasted;
+
+ // No values
+ cond.setExists(false);
+ then.setValues();
+ els.setValues();
+ func.streamLongs( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ cond.setExists(false);
+ then.setValues(-132L, 41543L, 563L);
+ els.setValues(0L, 1L, -2L, 3L);
+ func.streamLongs( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Result doesn't exist
+ cond.setValue(true).setExists(true);
+ then.setValues();
+ els.setValues(0L, 1L, -2L, 3L);
+ func.streamLongs( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ cond.setValue(false).setExists(true);
+ then.setValues(-132L, 41543L, 563L);
+ els.setValues();
+ func.streamLongs( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Values exist
+ cond.setValue(true).setExists(true);
+ then.setValues(-132L, 41543L, 563L);
+ els.setValues(0L, 1L, -2L, 3L);
+ Iterator<Long> values1 = Arrays.asList(-132L, 41543L, 563L).iterator();
+ func.streamLongs( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next().longValue(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ cond.setValue(false).setExists(true);
+ then.setValues(-132L, 41543L, 563L);
+ els.setValues(0L, 1L, -2L, 3L);
+ Iterator<Long> values2 = Arrays.asList(0L, 1L, -2L, 3L).iterator();
+ func.streamLongs( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next().longValue(), value);
+ });
+ assertFalse(values2.hasNext());
+ }
+
+ @Test
+ public void multiValueFloatTest() {
+ TestBooleanValue cond = new TestBooleanValue();
+ TestFloatValueStream then = new TestFloatValueStream();
+ TestFloatValueStream els = new TestFloatValueStream();
+
+ AnalyticsValueStream uncasted = IfFunction.creatorFunction.apply(new AnalyticsValueStream[] {cond, then, els});
+ assertTrue(uncasted instanceof FloatValueStream);
+ FloatValueStream func = (FloatValueStream) uncasted;
+
+ // No values
+ cond.setExists(false);
+ then.setValues();
+ els.setValues();
+ func.streamFloats( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ cond.setExists(false);
+ then.setValues(2134.2345F, -234.23F, 20000.0F);
+ els.setValues(.1111F , -.22222F, .333F);
+ func.streamFloats( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Result doesn't exist
+ cond.setValue(true).setExists(true);
+ then.setValues();
+ els.setValues(.1111F , -.22222F, .333F);
+ func.streamFloats( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ cond.setValue(false).setExists(true);
+ then.setValues(2134.2345F, -234.23F, 20000.0F);
+ els.setValues();
+ func.streamFloats( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Values exist
+ cond.setValue(true).setExists(true);
+ then.setValues(2134.2345F, -234.23F, 20000.0F);
+ els.setValues(.1111F , -.22222F, .333F);
+ Iterator<Float> values1 = Arrays.asList(2134.2345F, -234.23F, 20000.0F).iterator();
+ func.streamFloats( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value, .000001);
+ });
+ assertFalse(values1.hasNext());
+
+ cond.setValue(false).setExists(true);
+ then.setValues(2134.2345F, -234.23F, 20000.0F);
+ els.setValues(.1111F , -.22222F, .333F);
+ Iterator<Float> values2 = Arrays.asList(.1111F , -.22222F, .333F).iterator();
+ func.streamFloats( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value, .000001);
+ });
+ assertFalse(values2.hasNext());
+ }
+
+ @Test
+ public void multiValueDoubleTest() {
+ TestBooleanValue cond = new TestBooleanValue();
+ TestDoubleValueStream then = new TestDoubleValueStream();
+ TestDoubleValueStream els = new TestDoubleValueStream();
+
+ AnalyticsValueStream uncasted = IfFunction.creatorFunction.apply(new AnalyticsValueStream[] {cond, then, els});
+ assertTrue(uncasted instanceof DoubleValueStream);
+ DoubleValueStream func = (DoubleValueStream) uncasted;
+
+ // No values
+ cond.setExists(false);
+ then.setValues();
+ els.setValues();
+ func.streamDoubles( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ cond.setExists(false);
+ then.setValues(2134.2345, -234.23, 20000.0);
+ els.setValues(.1111 , -.22222, .333);
+ func.streamDoubles( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Result doesn't exist
+ cond.setValue(true).setExists(true);
+ then.setValues();
+ els.setValues(.1111 , -.22222, .333);
+ func.streamDoubles( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ cond.setValue(false).setExists(true);
+ then.setValues(2134.2345, -234.23, 20000.0);
+ els.setValues();
+ func.streamDoubles( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Values exist
+ cond.setValue(true).setExists(true);
+ then.setValues(2134.2345, -234.23, 20000.0);
+ els.setValues(.1111 , -.22222, .333);
+ Iterator<Double> values1 = Arrays.asList(2134.2345, -234.23, 20000.0).iterator();
+ func.streamDoubles( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value, .000001);
+ });
+ assertFalse(values1.hasNext());
+
+ cond.setValue(false).setExists(true);
+ then.setValues(2134.2345, -234.23, 20000.0);
+ els.setValues(.1111 , -.22222, .333);
+ Iterator<Double> values2 = Arrays.asList(.1111 , -.22222, .333).iterator();
+ func.streamDoubles( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value, .000001);
+ });
+ assertFalse(values2.hasNext());
+ }
+
+ @Test
+ public void multiValueDateTest() throws DateTimeParseException {
+ Date date1 = Date.from(Instant.parse("1810-12-02T10:30:15Z"));
+ Date date2 = Date.from(Instant.parse("1931-03-16T18:15:45Z"));
+ Date date3 = Date.from(Instant.parse("2023-11-01T20:30:15Z"));
+
+ TestBooleanValue cond = new TestBooleanValue();
+ TestDateValueStream then = new TestDateValueStream();
+ TestDateValueStream els = new TestDateValueStream();
+
+ AnalyticsValueStream uncasted = IfFunction.creatorFunction.apply(new AnalyticsValueStream[] {cond, then, els});
+ assertTrue(uncasted instanceof DateValueStream);
+ DateValueStream func = (DateValueStream) uncasted;
+
+ // No values
+ cond.setExists(false);
+ then.setValues();
+ els.setValues();
+ func.streamLongs( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ cond.setExists(false);
+ then.setValues("1810-12-02T10:30:15Z", "2023-11-01T20:30:15Z", "1810-12-02T10:30:15Z");
+ els.setValues("2023-11-01T20:30:15Z", "1931-03-16T18:15:45Z");
+ func.streamLongs( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Result doesn't exist
+ cond.setValue(true).setExists(true);
+ then.setValues();
+ els.setValues("2023-11-01T20:30:15Z", "1931-03-16T18:15:45Z");
+ func.streamLongs( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ cond.setValue(false).setExists(true);
+ then.setValues("1810-12-02T10:30:15Z", "2023-11-01T20:30:15Z", "1810-12-02T10:30:15Z");
+ els.setValues();
+ func.streamLongs( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Values exist
+ cond.setValue(true).setExists(true);
+ then.setValues("1810-12-02T10:30:15Z", "2023-11-01T20:30:15Z", "1810-12-02T10:30:15Z");
+ els.setValues("2023-11-01T20:30:15Z", "1931-03-16T18:15:45Z");
+ Iterator<Long> values1 = Arrays.asList(date1.getTime(), date3.getTime(), date1.getTime()).iterator();
+ func.streamLongs( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next().longValue(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ cond.setValue(false).setExists(true);
+ then.setValues("1810-12-02T10:30:15Z", "2023-11-01T20:30:15Z", "1810-12-02T10:30:15Z");
+ els.setValues("2023-11-01T20:30:15Z", "1931-03-16T18:15:45Z");
+ Iterator<Long> values2 = Arrays.asList(date3.getTime(), date2.getTime()).iterator();
+ func.streamLongs( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next().longValue(), value);
+ });
+ assertFalse(values2.hasNext());
+ }
+
+ @Test
+ public void multiValueStringTest() {
+ TestBooleanValue cond = new TestBooleanValue();
+ TestStringValueStream then = new TestStringValueStream();
+ TestStringValueStream els = new TestStringValueStream();
+
+ AnalyticsValueStream uncasted = IfFunction.creatorFunction.apply(new AnalyticsValueStream[] {cond, then, els});
+ assertTrue(uncasted instanceof StringValueStream);
+ StringValueStream func = (StringValueStream) uncasted;
+
+ // No values
+ cond.setExists(false);
+ then.setValues();
+ els.setValues();
+ func.streamStrings( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ cond.setExists(false);
+ then.setValues("abc123", "abcsdafasd", "third");
+ els.setValues("this", "is", "a", "sentence");
+ func.streamStrings( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Result doesn't exist
+ cond.setValue(true).setExists(true);
+ then.setValues();
+ els.setValues("this", "is", "a", "sentence");
+ func.streamStrings( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ cond.setValue(false).setExists(true);
+ then.setValues("abc123", "abcsdafasd", "third");
+ els.setValues();
+ func.streamStrings( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Values exist
+ cond.setValue(true).setExists(true);
+ then.setValues("abc123", "abcsdafasd", "third");
+ els.setValues("this", "is", "a", "sentence");
+ Iterator<String> values1 = Arrays.asList("abc123", "abcsdafasd", "third").iterator();
+ func.streamStrings( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ cond.setValue(false).setExists(true);
+ then.setValues("abc123", "abcsdafasd", "third");
+ els.setValues("this", "is", "a", "sentence");
+ Iterator<String> values2 = Arrays.asList("this", "is", "a", "sentence").iterator();
+ func.streamStrings( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value);
+ });
+ assertFalse(values2.hasNext());
+ }
+
+ @Test
+ public void multiValueObjectTest() {
+ TestBooleanValue cond = new TestBooleanValue();
+ TestAnalyticsValueStream then = new TestAnalyticsValueStream();
+ TestAnalyticsValueStream els = new TestAnalyticsValueStream();
+
+ AnalyticsValueStream func = IfFunction.creatorFunction.apply(new AnalyticsValueStream[] {cond, then, els});
+
+ // No values
+ cond.setExists(false);
+ then.setValues();
+ els.setValues();
+ func.streamObjects( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ cond.setExists(false);
+ then.setValues(new Date(142341), "abcsdafasd", new Double(1234.1324123));
+ els.setValues(new Float(324923.0234F), new Integer(123), new Boolean(true), "if statement");
+ func.streamObjects( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Result doesn't exist
+ cond.setValue(true).setExists(true);
+ then.setValues();
+ els.setValues(new Float(324923.0234F), new Integer(123), new Boolean(true), "if statement");
+ func.streamObjects( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ cond.setValue(false).setExists(true);
+ then.setValues(new Date(142341), "abcsdafasd", new Double(1234.1324123));
+ els.setValues();
+ func.streamObjects( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Values exist
+ cond.setValue(true).setExists(true);
+ then.setValues(new Date(142341), "abcsdafasd", new Double(1234.1324123));
+ els.setValues(new Float(324923.0234F), new Integer(123), new Boolean(true), "if statement");
+ Iterator<Object> values1 = Arrays.<Object>asList(new Date(142341), "abcsdafasd", new Double(1234.1324123)).iterator();
+ func.streamObjects( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ cond.setValue(false).setExists(true);
+ then.setValues(new Date(142341), "abcsdafasd", new Double(1234.1324123));
+ els.setValues(new Float(324923.0234F), new Integer(123), new Boolean(true), "if statement");
+ Iterator<Object> values2 = Arrays.<Object>asList(new Float(324923.0234F), new Integer(123), new Boolean(true), "if statement").iterator();
+ func.streamObjects( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value);
+ });
+ assertFalse(values2.hasNext());
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/LTEFunctionTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/LTEFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/LTEFunctionTest.java
new file mode 100644
index 0000000..6e1590e
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/LTEFunctionTest.java
@@ -0,0 +1,290 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.function.mapping;
+
+import java.util.Arrays;
+import java.util.Iterator;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.analytics.function.mapping.ComparisonFunction.LTEFunction;
+import org.apache.solr.analytics.value.AnalyticsValueStream;
+import org.apache.solr.analytics.value.BooleanValue;
+import org.apache.solr.analytics.value.BooleanValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestDateValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestDateValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValueStream;
+import org.junit.Test;
+
+public class LTEFunctionTest extends SolrTestCaseJ4 {
+
+ @Test
+ public void singleValueNumericParameterTest() {
+ TestDoubleValue base = new TestDoubleValue();
+ TestDoubleValue comp = new TestDoubleValue();
+
+ AnalyticsValueStream uncasted = LTEFunction.creatorFunction.apply(new AnalyticsValueStream[] {base, comp});
+ assertTrue(uncasted instanceof BooleanValue);
+ BooleanValue func = (BooleanValue) uncasted;
+
+ // Value doesn't exist
+ base.setExists(false);
+ comp.setExists(false);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ base.setExists(false);
+ comp.setValue(3.3).setExists(true);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ base.setValue(3.3).setExists(true);
+ comp.setExists(false);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ // Value exists
+ base.setValue(21.56).setExists(true);
+ comp.setValue(21.56).setExists(true);
+ assertEquals(true, func.getBoolean());
+ assertTrue(func.exists());
+
+ base.setValue(21.56).setExists(true);
+ comp.setValue(21.57).setExists(true);
+ assertEquals(true, func.getBoolean());
+ assertTrue(func.exists());
+
+ base.setValue(21.56).setExists(true);
+ comp.setValue(-21.57).setExists(true);
+ assertEquals(false, func.getBoolean());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void singleValueDateParameterTest() {
+ TestDateValue base = new TestDateValue();
+ TestDateValue comp = new TestDateValue();
+
+ AnalyticsValueStream uncasted = LTEFunction.creatorFunction.apply(new AnalyticsValueStream[] {base, comp});
+ assertTrue(uncasted instanceof BooleanValue);
+ BooleanValue func = (BooleanValue) uncasted;
+
+ // Value doesn't exist
+ base.setExists(false);
+ comp.setExists(false);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ base.setExists(false);
+ comp.setValue("1800-01-02T10:20:30Z").setExists(true);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ base.setValue("1800-01-02T10:20:30Z").setExists(true);
+ comp.setExists(false);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ // Value exists
+ base.setValue("1800-01-02T10:20:30Z").setExists(true);
+ comp.setValue("1800-01-02T10:20:30Z").setExists(true);
+ assertEquals(true, func.getBoolean());
+ assertTrue(func.exists());
+
+ base.setValue("1800-01-02T10:20:30Z").setExists(true);
+ comp.setValue("1800-01-02T10:20:31Z").setExists(true);
+ assertEquals(true, func.getBoolean());
+ assertTrue(func.exists());
+
+ base.setValue("1800-01-02T10:20:30Z").setExists(true);
+ comp.setValue("1000-01-02T10:20:31Z").setExists(true);
+ assertEquals(false, func.getBoolean());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void oneSingleOneMultiValueNumericParameterTest() {
+ TestDoubleValue base = new TestDoubleValue();
+ TestDoubleValueStream comp = new TestDoubleValueStream();
+
+ AnalyticsValueStream uncasted = LTEFunction.creatorFunction.apply(new AnalyticsValueStream[] {base, comp});
+ assertTrue(uncasted instanceof BooleanValueStream);
+ BooleanValueStream func = (BooleanValueStream) uncasted;
+
+ // No values
+ base.setValue(-4.2).setExists(true);
+ comp.setValues();
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ base.setExists(false);
+ comp.setValues(-4.2);
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // One value
+ base.setValue(-4.2).setExists(true);
+ comp.setValues(-4);
+ Iterator<Boolean> values1 = Arrays.asList(true).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ // Multiple values
+ base.setValue(4).setExists(true);
+ comp.setValues(4, -10, 2345, -74, 4.0001);
+ Iterator<Boolean> values2 = Arrays.asList(true, false, true, false, true).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value);
+ });
+ assertFalse(values2.hasNext());
+ }
+
+ @Test
+ public void oneMultiOneSingleValueNumericParameterTest() {
+ TestDoubleValueStream base = new TestDoubleValueStream();
+ TestDoubleValue comp = new TestDoubleValue();
+
+ AnalyticsValueStream uncasted = LTEFunction.creatorFunction.apply(new AnalyticsValueStream[] {base, comp});
+ assertTrue(uncasted instanceof BooleanValueStream);
+ BooleanValueStream func = (BooleanValueStream) uncasted;
+
+ // No values
+ base.setValues();
+ comp.setValue(-4.2).setExists(true);
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ base.setValues(-4.2);
+ comp.setExists(false);
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // One value
+ base.setValues(-4.2);
+ comp.setValue(-4).setExists(true);
+ Iterator<Boolean> values1 = Arrays.asList(true).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ // Multiple values
+ base.setValues(4, -10, 2345, -74, 4.0001);
+ comp.setValue(4).setExists(true);
+ Iterator<Boolean> values2 = Arrays.asList(true, true, false, true, false).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value);
+ });
+ assertFalse(values2.hasNext());
+ }
+
+ @Test
+ public void oneSingleOneMultiValueDateParameterTest() {
+ TestDateValue base = new TestDateValue();
+ TestDateValueStream comp = new TestDateValueStream();
+
+ AnalyticsValueStream uncasted = LTEFunction.creatorFunction.apply(new AnalyticsValueStream[] {base, comp});
+ assertTrue(uncasted instanceof BooleanValueStream);
+ BooleanValueStream func = (BooleanValueStream) uncasted;
+
+ // No values
+ base.setValue("1800-01-02T10:20:30Z").setExists(true);
+ comp.setValues();
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ base.setExists(false);
+ comp.setValues("1800-01-02T10:20:30Z");
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // One value
+ base.setValue("1803-01-02T10:20:30Z").setExists(true);
+ comp.setValues("1800-01-02T10:20:30Z");
+ Iterator<Boolean> values1 = Arrays.asList(false).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ // Multiple values
+ base.setValue("1800-01-02T10:20:30Z").setExists(true);
+ comp.setValues("1800-03-02T10:20:30Z", "1799-01-01T10:20:29Z", "1800-01-02T10:20:31Z", "1800-01-02T10:20:30Z", "1800-01-02T10:20:29Z");
+ Iterator<Boolean> values2 = Arrays.asList(true, false, true, true, false).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value);
+ });
+ assertFalse(values2.hasNext());
+ }
+
+ @Test
+ public void oneMultiOneSingleValueDateParameterTest() {
+ TestDateValueStream base = new TestDateValueStream();
+ TestDateValue comp = new TestDateValue();
+
+ AnalyticsValueStream uncasted = LTEFunction.creatorFunction.apply(new AnalyticsValueStream[] {base, comp});
+ assertTrue(uncasted instanceof BooleanValueStream);
+ BooleanValueStream func = (BooleanValueStream) uncasted;
+
+ // No values
+ base.setValues();
+ comp.setValue("1800-01-02T10:20:30Z").setExists(true);
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ base.setValues("1800-01-02T10:20:30Z");
+ comp.setExists(false);
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // One value
+ base.setValues("1800-01-02T10:20:30Z");
+ comp.setValue("1803-01-02T10:20:30Z").setExists(true);
+ Iterator<Boolean> values1 = Arrays.asList(true).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ // Multiple values
+ base.setValues("1800-03-02T10:20:30Z", "1799-01-01T10:20:29Z", "1800-01-02T10:20:31Z", "1800-01-02T10:20:30Z", "1800-01-02T10:20:29Z");
+ comp.setValue("1800-01-02T10:20:30Z").setExists(true);
+ Iterator<Boolean> values2 = Arrays.asList(false, true, false, true, true).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value);
+ });
+ assertFalse(values2.hasNext());
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/LTFunctionTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/LTFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/LTFunctionTest.java
new file mode 100644
index 0000000..f7d5e8e
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/LTFunctionTest.java
@@ -0,0 +1,290 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.function.mapping;
+
+import java.util.Arrays;
+import java.util.Iterator;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.analytics.function.mapping.ComparisonFunction.LTFunction;
+import org.apache.solr.analytics.value.AnalyticsValueStream;
+import org.apache.solr.analytics.value.BooleanValue;
+import org.apache.solr.analytics.value.BooleanValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestDateValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestDateValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValueStream;
+import org.junit.Test;
+
+public class LTFunctionTest extends SolrTestCaseJ4 {
+
+ @Test
+ public void singleValueNumericParameterTest() {
+ TestDoubleValue base = new TestDoubleValue();
+ TestDoubleValue comp = new TestDoubleValue();
+
+ AnalyticsValueStream uncasted = LTFunction.creatorFunction.apply(new AnalyticsValueStream[] {base, comp});
+ assertTrue(uncasted instanceof BooleanValue);
+ BooleanValue func = (BooleanValue) uncasted;
+
+ // Value doesn't exist
+ base.setExists(false);
+ comp.setExists(false);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ base.setExists(false);
+ comp.setValue(3.3).setExists(true);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ base.setValue(3.3).setExists(true);
+ comp.setExists(false);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ // Value exists
+ base.setValue(21.56).setExists(true);
+ comp.setValue(21.56).setExists(true);
+ assertEquals(false, func.getBoolean());
+ assertTrue(func.exists());
+
+ base.setValue(21.56).setExists(true);
+ comp.setValue(21.57).setExists(true);
+ assertEquals(true, func.getBoolean());
+ assertTrue(func.exists());
+
+ base.setValue(21.56).setExists(true);
+ comp.setValue(-21.57).setExists(true);
+ assertEquals(false, func.getBoolean());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void singleValueDateParameterTest() {
+ TestDateValue base = new TestDateValue();
+ TestDateValue comp = new TestDateValue();
+
+ AnalyticsValueStream uncasted = LTFunction.creatorFunction.apply(new AnalyticsValueStream[] {base, comp});
+ assertTrue(uncasted instanceof BooleanValue);
+ BooleanValue func = (BooleanValue) uncasted;
+
+ // Value doesn't exist
+ base.setExists(false);
+ comp.setExists(false);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ base.setExists(false);
+ comp.setValue("1800-01-02T10:20:30Z").setExists(true);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ base.setValue("1800-01-02T10:20:30Z").setExists(true);
+ comp.setExists(false);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ // Value exists
+ base.setValue("1800-01-02T10:20:30Z").setExists(true);
+ comp.setValue("1800-01-02T10:20:30Z").setExists(true);
+ assertEquals(false, func.getBoolean());
+ assertTrue(func.exists());
+
+ base.setValue("1800-01-02T10:20:30Z").setExists(true);
+ comp.setValue("1800-01-02T10:20:31Z").setExists(true);
+ assertEquals(true, func.getBoolean());
+ assertTrue(func.exists());
+
+ base.setValue("1800-01-02T10:20:30Z").setExists(true);
+ comp.setValue("1000-01-02T10:20:31Z").setExists(true);
+ assertEquals(false, func.getBoolean());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void oneSingleOneMultiValueNumericParameterTest() {
+ TestDoubleValue base = new TestDoubleValue();
+ TestDoubleValueStream comp = new TestDoubleValueStream();
+
+ AnalyticsValueStream uncasted = LTFunction.creatorFunction.apply(new AnalyticsValueStream[] {base, comp});
+ assertTrue(uncasted instanceof BooleanValueStream);
+ BooleanValueStream func = (BooleanValueStream) uncasted;
+
+ // No values
+ base.setValue(-4.2).setExists(true);
+ comp.setValues();
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ base.setExists(false);
+ comp.setValues(-4.2);
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // One value
+ base.setValue(-4.2).setExists(true);
+ comp.setValues(-4);
+ Iterator<Boolean> values1 = Arrays.asList(true).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ // Multiple values
+ base.setValue(4).setExists(true);
+ comp.setValues(4, -10, 2345, -74, 4.0001);
+ Iterator<Boolean> values2 = Arrays.asList(false, false, true, false, true).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value);
+ });
+ assertFalse(values2.hasNext());
+ }
+
+ @Test
+ public void oneMultiOneSingleValueNumericParameterTest() {
+ TestDoubleValueStream base = new TestDoubleValueStream();
+ TestDoubleValue comp = new TestDoubleValue();
+
+ AnalyticsValueStream uncasted = LTFunction.creatorFunction.apply(new AnalyticsValueStream[] {base, comp});
+ assertTrue(uncasted instanceof BooleanValueStream);
+ BooleanValueStream func = (BooleanValueStream) uncasted;
+
+ // No values
+ base.setValues();
+ comp.setValue(-4.2).setExists(true);
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ base.setValues(-4.2);
+ comp.setExists(false);
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // One value
+ base.setValues(-4.2);
+ comp.setValue(-4).setExists(true);
+ Iterator<Boolean> values1 = Arrays.asList(true).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ // Multiple values
+ base.setValues(4, -10, 2345, -74, 4.0001);
+ comp.setValue(4).setExists(true);
+ Iterator<Boolean> values2 = Arrays.asList(false, true, false, true, false).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value);
+ });
+ assertFalse(values2.hasNext());
+ }
+
+ @Test
+ public void oneSingleOneMultiValueDateParameterTest() {
+ TestDateValue base = new TestDateValue();
+ TestDateValueStream comp = new TestDateValueStream();
+
+ AnalyticsValueStream uncasted = LTFunction.creatorFunction.apply(new AnalyticsValueStream[] {base, comp});
+ assertTrue(uncasted instanceof BooleanValueStream);
+ BooleanValueStream func = (BooleanValueStream) uncasted;
+
+ // No values
+ base.setValue("1800-01-02T10:20:30Z").setExists(true);
+ comp.setValues();
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ base.setExists(false);
+ comp.setValues("1800-01-02T10:20:30Z");
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // One value
+ base.setValue("1803-01-02T10:20:30Z").setExists(true);
+ comp.setValues("1800-01-02T10:20:30Z");
+ Iterator<Boolean> values1 = Arrays.asList(false).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ // Multiple values
+ base.setValue("1800-01-02T10:20:30Z").setExists(true);
+ comp.setValues("1800-03-02T10:20:30Z", "1799-01-01T10:20:29Z", "1800-01-02T10:20:31Z", "1800-01-02T10:20:30Z", "1800-01-02T10:20:29Z");
+ Iterator<Boolean> values2 = Arrays.asList(true, false, true, false, false).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value);
+ });
+ assertFalse(values2.hasNext());
+ }
+
+ @Test
+ public void oneMultiOneSingleValueDateParameterTest() {
+ TestDateValueStream base = new TestDateValueStream();
+ TestDateValue comp = new TestDateValue();
+
+ AnalyticsValueStream uncasted = LTFunction.creatorFunction.apply(new AnalyticsValueStream[] {base, comp});
+ assertTrue(uncasted instanceof BooleanValueStream);
+ BooleanValueStream func = (BooleanValueStream) uncasted;
+
+ // No values
+ base.setValues();
+ comp.setValue("1800-01-02T10:20:30Z").setExists(true);
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ base.setValues("1800-01-02T10:20:30Z");
+ comp.setExists(false);
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // One value
+ base.setValues("1800-01-02T10:20:30Z");
+ comp.setValue("1803-01-02T10:20:30Z").setExists(true);
+ Iterator<Boolean> values1 = Arrays.asList(true).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ // Multiple values
+ base.setValues("1800-03-02T10:20:30Z", "1799-01-01T10:20:29Z", "1800-01-02T10:20:31Z", "1800-01-02T10:20:30Z", "1800-01-02T10:20:29Z");
+ comp.setValue("1800-01-02T10:20:30Z").setExists(true);
+ Iterator<Boolean> values2 = Arrays.asList(false, true, false, false, true).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value);
+ });
+ assertFalse(values2.hasNext());
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/LogFunctionTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/LogFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/LogFunctionTest.java
new file mode 100644
index 0000000..1cffb5a
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/LogFunctionTest.java
@@ -0,0 +1,186 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.function.mapping;
+
+import java.util.Arrays;
+import java.util.Iterator;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.analytics.value.AnalyticsValueStream;
+import org.apache.solr.analytics.value.DoubleValue;
+import org.apache.solr.analytics.value.DoubleValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestIntValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestIntValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestLongValueStream;
+import org.junit.Test;
+
+public class LogFunctionTest extends SolrTestCaseJ4 {
+
+ @Test
+ public void singleValueParameterTest() {
+ TestFloatValue val = new TestFloatValue();
+
+ AnalyticsValueStream uncasted = LogFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof DoubleValue);
+ DoubleValue func = (DoubleValue) uncasted;
+
+ // Value doesn't exist
+ val.setExists(false);
+ func.getDouble();
+ assertFalse(func.exists());
+
+ // Value exists
+ val.setValue(21.56F).setExists(true);
+ assertEquals(Math.log(21.56F), func.getDouble(), 0.00001);
+ assertTrue(func.exists());
+
+ val.setValue(-100F).setExists(true);
+ assertEquals(Math.log(-100F), func.getDouble(), 0.00001);
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void multiValueParameterTest() {
+ TestIntValueStream val = new TestIntValueStream();
+
+ AnalyticsValueStream uncasted = LogFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof DoubleValueStream);
+ DoubleValueStream func = (DoubleValueStream) uncasted;
+
+ // No values
+ val.setValues();
+ func.streamDoubles( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // One value
+ val.setValues(4);
+ Iterator<Double> values1 = Arrays.asList(Math.log(4)).iterator();
+ func.streamDoubles( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value, .00001);
+ });
+ assertFalse(values1.hasNext());
+
+ // Multiple values
+ val.setValues(2, 103, 502, 743);
+ Iterator<Double> values2 = Arrays.asList(Math.log(2), Math.log(103), Math.log(502), Math.log(743)).iterator();
+ func.streamDoubles( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value, .00001);
+ });
+ assertFalse(values2.hasNext());
+ }
+
+ @Test
+ public void twoSingleValueParametersTest() {
+ TestIntValue base = new TestIntValue();
+ TestFloatValue val = new TestFloatValue();
+
+ AnalyticsValueStream uncasted = LogFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, base});
+ assertTrue(uncasted instanceof DoubleValue);
+ DoubleValue func = (DoubleValue) uncasted;
+
+ // Neither exists
+ base.setExists(false);
+ val.setExists(false);
+ func.getDouble();
+ assertFalse(func.exists());
+
+ // One exists
+ base.setValue(30).setExists(true);
+ val.setExists(false);
+ func.getDouble();
+ assertFalse(func.exists());
+
+ // Both exist
+ base.setValue(6).setExists(true);
+ val.setValue(2.56F).setExists(true);
+ assertEquals(Math.log(2.56F)/Math.log(6), func.getDouble(), 0.0001);
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void oneMultiOneSingleValueParameterTest() {
+ TestLongValueStream base = new TestLongValueStream();
+ TestDoubleValue val = new TestDoubleValue();
+
+ AnalyticsValueStream uncasted = LogFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, base});
+ assertTrue(uncasted instanceof DoubleValueStream);
+ DoubleValueStream func = (DoubleValueStream) uncasted;
+
+ // No values, One value
+ base.setValues();
+ val.setValue(21.56F).setExists(true);
+ func.streamDoubles( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple values, no value
+ base.setValues(4L, 10023L);
+ val.setExists(false);
+ func.streamDoubles( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple values, one value
+ base.setValues(4L, 123L, 2L);
+ val.setValue(4.56F).setExists(true);
+ Iterator<Double> values = Arrays.asList(Math.log(4.56F)/Math.log(4L), Math.log(4.56F)/Math.log(123L), Math.log(4.56F)/Math.log(2L)).iterator();
+ func.streamDoubles( value -> {
+ assertTrue(values.hasNext());
+ assertEquals(values.next(), value, 0.0001);
+ });
+ assertFalse(values.hasNext());
+ }
+
+ @Test
+ public void oneSingleOneMultiValueParameterTest() {
+ TestDoubleValue base = new TestDoubleValue();
+ TestLongValueStream val = new TestLongValueStream();
+
+ AnalyticsValueStream uncasted = LogFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, base});
+ assertTrue(uncasted instanceof DoubleValueStream);
+ DoubleValueStream func = (DoubleValueStream) uncasted;
+
+ // No values, One value
+ base.setValue(21.56F).setExists(true);
+ val.setValues();
+ func.streamDoubles( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple values, no value
+ base.setExists(false);
+ val.setValues(4L, 10023L);
+ func.streamDoubles( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple values, one value
+ base.setValue(4.56F).setExists(true);
+ val.setValues(2L, 50L, 3L);
+ Iterator<Double> values = Arrays.asList(Math.log(2L)/Math.log(4.56F), Math.log(50L)/Math.log(4.56F), Math.log(3L)/Math.log(4.56F)).iterator();
+ func.streamDoubles( value -> {
+ assertTrue(values.hasNext());
+ assertEquals(values.next(), value, 0.0001);
+ });
+ assertFalse(values.hasNext());
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/MultFunctionTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/MultFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/MultFunctionTest.java
new file mode 100644
index 0000000..c2f5d32
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/MultFunctionTest.java
@@ -0,0 +1,155 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.function.mapping;
+
+import java.util.Arrays;
+import java.util.Iterator;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.analytics.value.AnalyticsValueStream;
+import org.apache.solr.analytics.value.DoubleValue;
+import org.apache.solr.analytics.value.DoubleValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestIntValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestLongValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestLongValueStream;
+import org.junit.Test;
+
+public class MultFunctionTest extends SolrTestCaseJ4 {
+ @Test
+ public void twoSingleValueParametersTest() {
+ TestIntValue val1 = new TestIntValue();
+ TestFloatValue val2 = new TestFloatValue();
+
+ AnalyticsValueStream uncasted = MultFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2});
+ assertTrue(uncasted instanceof DoubleValue);
+ DoubleValue func = (DoubleValue) uncasted;
+
+ // Neither exists
+ val1.setExists(false);
+ val2.setExists(false);
+ func.getDouble();
+ assertFalse(func.exists());
+
+ // One exists
+ val1.setValue(30).setExists(true);
+ val2.setExists(false);
+ func.getDouble();
+ assertFalse(func.exists());
+
+ // Both exist
+ val1.setValue(30).setExists(true);
+ val2.setValue(21.56F).setExists(true);
+ assertEquals(646.8, func.getDouble(), 0.0001);
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void oneMultiValueParameterTest() {
+ TestLongValueStream val = new TestLongValueStream();
+
+ AnalyticsValueStream uncasted = MultFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof DoubleValue);
+ DoubleValue func = (DoubleValue) uncasted;
+
+ // No values
+ val.setValues();
+ func.getDouble();
+ assertFalse(func.exists());
+
+ // One value
+ val.setValues(30L);
+ assertEquals(30, func.getDouble(), 0.00001);
+ assertTrue(func.exists());
+
+ // Multiple values
+ val.setValues(30L, 20L, 55L, 61L);
+ assertEquals(2013000, func.getDouble(), 0.00001);
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void oneMultiOneSingleValueParameterTest() {
+ TestLongValueStream val1 = new TestLongValueStream();
+ TestDoubleValue val2 = new TestDoubleValue();
+
+ AnalyticsValueStream uncasted = MultFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2});
+ assertTrue(uncasted instanceof DoubleValueStream);
+ DoubleValueStream func = (DoubleValueStream) uncasted;
+
+ // No values, One value
+ val1.setValues();
+ val2.setValue(21.56F).setExists(true);
+ func.streamDoubles( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple values, no value
+ val1.setValues(4L, 10023L);
+ val2.setExists(false);
+ func.streamDoubles( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple values, one value
+ val1.setValues(4L, 10023L, 48L);
+ val2.setValue(21.56F).setExists(true);
+ Iterator<Double> values = Arrays.asList(86.24, 216095.88, 1034.88).iterator();
+ func.streamDoubles( value -> {
+ assertTrue(values.hasNext());
+ assertEquals(values.next(), value, 0.01);
+ });
+ assertFalse(values.hasNext());
+ }
+
+ @Test
+ public void multipleSingleValueParameterTest() {
+ TestLongValue val1 = new TestLongValue();
+ TestDoubleValue val2 = new TestDoubleValue();
+ TestFloatValue val3 = new TestFloatValue();
+ TestIntValue val4 = new TestIntValue();
+
+ AnalyticsValueStream uncasted = MultFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2, val3, val4});
+ assertTrue(uncasted instanceof DoubleValue);
+ DoubleValue func = (DoubleValue) uncasted;
+
+ // None exist
+ val1.setExists(false);
+ val2.setExists(false);
+ val3.setExists(false);
+ val4.setExists(false);
+ func.getDouble();
+ assertFalse(func.exists());
+
+ // Some exist
+ val1.setExists(false);
+ val2.setValue(30.56).setExists(true);
+ val3.setExists(false);
+ val4.setValue(12).setExists(true);
+ func.getDouble();
+ assertFalse(func.exists());
+
+ // All exist values, one value
+ val1.setValue(45L).setExists(true);
+ val2.setValue(30.56).setExists(true);
+ val3.setValue(2.5F).setExists(true);
+ val4.setValue(12).setExists(true);
+ assertEquals(41256, func.getDouble(), 0.00001);
+ assertTrue(func.exists());
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/NegateFunctionTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/NegateFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/NegateFunctionTest.java
new file mode 100644
index 0000000..7b0aa13
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/NegateFunctionTest.java
@@ -0,0 +1,327 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.function.mapping;
+
+import java.util.Arrays;
+import java.util.Iterator;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.analytics.value.AnalyticsValueStream;
+import org.apache.solr.analytics.value.BooleanValue;
+import org.apache.solr.analytics.value.BooleanValueStream;
+import org.apache.solr.analytics.value.DoubleValue;
+import org.apache.solr.analytics.value.DoubleValueStream;
+import org.apache.solr.analytics.value.FloatValue;
+import org.apache.solr.analytics.value.FloatValueStream;
+import org.apache.solr.analytics.value.IntValue;
+import org.apache.solr.analytics.value.IntValueStream;
+import org.apache.solr.analytics.value.LongValue;
+import org.apache.solr.analytics.value.LongValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestBooleanValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestBooleanValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestIntValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestIntValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestLongValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestLongValueStream;
+import org.junit.Test;
+
+public class NegateFunctionTest extends SolrTestCaseJ4 {
+
+ @Test
+ public void singleValueBooleanTest() {
+ TestBooleanValue val = new TestBooleanValue();
+
+ AnalyticsValueStream uncasted = NegateFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof BooleanValue);
+ BooleanValue func = (BooleanValue) uncasted;
+
+ // Value doesn't exist
+ val.setExists(false);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ // Value exists
+ val.setValue(true).setExists(true);
+ assertEquals(false, func.getBoolean());
+ assertTrue(func.exists());
+
+ val.setValue(false).setExists(true);
+ assertEquals(true, func.getBoolean());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void singleValueIntTest() {
+ TestIntValue val = new TestIntValue();
+
+ AnalyticsValueStream uncasted = NegateFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof IntValue);
+ IntValue func = (IntValue) uncasted;
+
+ // Value doesn't exist
+ val.setExists(false);
+ func.getInt();
+ assertFalse(func.exists());
+
+ // Value exists
+ val.setValue(21).setExists(true);
+ assertEquals(-21, func.getInt());
+ assertTrue(func.exists());
+
+ val.setValue(-100).setExists(true);
+ assertEquals(100, func.getInt());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void singleValueLongTest() {
+ TestLongValue val = new TestLongValue();
+
+ AnalyticsValueStream uncasted = NegateFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof LongValue);
+ LongValue func = (LongValue) uncasted;
+
+ // Value doesn't exist
+ val.setExists(false);
+ func.getLong();
+ assertFalse(func.exists());
+
+ // Value exists
+ val.setValue(21L).setExists(true);
+ assertEquals(-21, func.getLong());
+ assertTrue(func.exists());
+
+ val.setValue(-100L).setExists(true);
+ assertEquals(100L, func.getLong());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void singleValueFloatTest() {
+ TestFloatValue val = new TestFloatValue();
+
+ AnalyticsValueStream uncasted = NegateFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof FloatValue);
+ FloatValue func = (FloatValue) uncasted;
+
+ // Value doesn't exist
+ val.setExists(false);
+ func.getFloat();
+ assertFalse(func.exists());
+
+ // Value exists
+ val.setValue(21.56F).setExists(true);
+ assertEquals(-21.56F, func.getFloat(), 0.00001);
+ assertTrue(func.exists());
+
+ val.setValue(-100F).setExists(true);
+ assertEquals(100F, func.getFloat(), 0.00001);
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void singleValueDoubleTest() {
+ TestDoubleValue val = new TestDoubleValue();
+
+ AnalyticsValueStream uncasted = NegateFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof DoubleValue);
+ DoubleValue func = (DoubleValue) uncasted;
+
+ // Value doesn't exist
+ val.setExists(false);
+ func.getDouble();
+ assertFalse(func.exists());
+
+ // Value exists
+ val.setValue(21.56).setExists(true);
+ assertEquals(-21.56, func.getDouble(), 0.00001);
+ assertTrue(func.exists());
+
+ val.setValue(-100.1).setExists(true);
+ assertEquals(100.1, func.getDouble(), 0.00001);
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void multiValueBooleanTest() {
+ TestBooleanValueStream val = new TestBooleanValueStream();
+
+ AnalyticsValueStream uncasted = NegateFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof BooleanValueStream);
+ BooleanValueStream func = (BooleanValueStream) uncasted;
+
+ // No values
+ val.setValues();
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // One value
+ val.setValues(true);
+ Iterator<Boolean> values1 = Arrays.asList(false).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ // Multiple values
+ val.setValues(true, false, true, false);
+ Iterator<Boolean> values2 = Arrays.asList(false, true, false, true).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value);
+ });
+ assertFalse(values2.hasNext());
+ }
+
+ @Test
+ public void multiValueIntTest() {
+ TestIntValueStream val = new TestIntValueStream();
+
+ AnalyticsValueStream uncasted = NegateFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof IntValueStream);
+ IntValueStream func = (IntValueStream) uncasted;
+
+ // No values
+ val.setValues();
+ func.streamInts( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // One value
+ val.setValues(-4);
+ Iterator<Integer> values1 = Arrays.asList(4).iterator();
+ func.streamInts( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next().intValue(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ // Multiple values
+ val.setValues(4, -10, 50, -74);
+ Iterator<Integer> values2 = Arrays.asList(-4, 10, -50, 74).iterator();
+ func.streamInts( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next().intValue(), value);
+ });
+ assertFalse(values2.hasNext());
+ }
+
+ @Test
+ public void multiValueLongTest() {
+ TestLongValueStream val = new TestLongValueStream();
+
+ AnalyticsValueStream uncasted = NegateFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof LongValueStream);
+ LongValueStream func = (LongValueStream) uncasted;
+
+ // No values
+ val.setValues();
+ func.streamLongs( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // One value
+ val.setValues(-4L);
+ Iterator<Long> values1 = Arrays.asList(4L).iterator();
+ func.streamLongs( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next().longValue(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ // Multiple values
+ val.setValues(4L, -10L, 50L, -74L);
+ Iterator<Long> values2 = Arrays.asList(-4L, 10L, -50L, 74L).iterator();
+ func.streamLongs( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next().longValue(), value);
+ });
+ assertFalse(values2.hasNext());
+ }
+
+ @Test
+ public void multiValueFloatTest() {
+ TestFloatValueStream val = new TestFloatValueStream();
+
+ AnalyticsValueStream uncasted = NegateFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof FloatValueStream);
+ FloatValueStream func = (FloatValueStream) uncasted;
+
+ // No values
+ val.setValues();
+ func.streamFloats( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // One value
+ val.setValues(-4.3F);
+ Iterator<Float> values1 = Arrays.asList(4.3F).iterator();
+ func.streamFloats( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value, .000001);
+ });
+ assertFalse(values1.hasNext());
+
+ // Multiple values
+ val.setValues(4.3F, -10F, 50.75F, -74.4446F);
+ Iterator<Float> values2 = Arrays.asList(-4.3F, 10F, -50.75F, 74.4446F).iterator();
+ func.streamFloats( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value, .000001);
+ });
+ assertFalse(values2.hasNext());
+ }
+
+ @Test
+ public void multiValueDoubleTest() {
+ TestDoubleValueStream val = new TestDoubleValueStream();
+
+ AnalyticsValueStream uncasted = NegateFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof DoubleValueStream);
+ DoubleValueStream func = (DoubleValueStream) uncasted;
+
+ // No values
+ val.setValues();
+ func.streamDoubles( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // One value
+ val.setValues(-4.3);
+ Iterator<Double> values1 = Arrays.asList(4.3).iterator();
+ func.streamDoubles( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value, .000001);
+ });
+ assertFalse(values1.hasNext());
+
+ // Multiple values
+ val.setValues(4.3, -10, 50.75, -74.4446);
+ Iterator<Double> values2 = Arrays.asList(-4.3, 10.0, -50.75, 74.4446).iterator();
+ func.streamDoubles( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value, .000001);
+ });
+ assertFalse(values2.hasNext());
+ }
+}
[17/20] lucene-solr:master: SOLR-11145,
SOLR-11146: Added comprehensive unit tests for Analytics Component
2.0 as well as analytics bug fixes.
Posted by dp...@apache.org.
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/AnalyticsValue.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/AnalyticsValue.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/AnalyticsValue.java
index 54a3003..5b738de 100644
--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/AnalyticsValue.java
+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/AnalyticsValue.java
@@ -17,7 +17,6 @@
package org.apache.solr.analytics.value;
import java.util.function.Consumer;
-
/**
* A single-valued analytics value.
* <p>
@@ -33,6 +32,7 @@ public interface AnalyticsValue extends AnalyticsValueStream {
* @return whether the current value exists
*/
boolean exists();
+
/**
* Get the object representation of the current value.
*
@@ -51,5 +51,9 @@ public interface AnalyticsValue extends AnalyticsValueStream {
cons.accept(value);
}
}
+ @Override
+ public AnalyticsValueStream convertToConstant() {
+ return this;
+ }
}
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/AnalyticsValueStream.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/AnalyticsValueStream.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/AnalyticsValueStream.java
index 0c02115..cba8835 100644
--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/AnalyticsValueStream.java
+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/AnalyticsValueStream.java
@@ -21,6 +21,7 @@ import java.util.Locale;
import java.util.function.Consumer;
import org.apache.solr.analytics.ExpressionFactory;
+import org.apache.solr.analytics.value.constant.ConstantValue;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrException.ErrorCode;
@@ -52,6 +53,22 @@ public interface AnalyticsValueStream {
void streamObjects(Consumer<Object> cons);
/**
+ * Converts this value to a {@link ConstantValue} if it's expression type is {@link ExpressionType#CONST}.
+ *
+ * If the value is reduced then no conversion will occur and the value itself will be returned.
+ *
+ * @return a constant representation of this value
+ */
+ AnalyticsValueStream convertToConstant();
+
+ public static abstract class AbstractAnalyticsValueStream implements AnalyticsValueStream {
+ @Override
+ public AnalyticsValueStream convertToConstant() {
+ return this;
+ }
+ }
+
+ /**
* The types of expressions.
*/
static enum ExpressionType {
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/BooleanValue.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/BooleanValue.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/BooleanValue.java
index 5d58a8b..4c742f2 100644
--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/BooleanValue.java
+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/BooleanValue.java
@@ -20,6 +20,7 @@ import java.util.function.Consumer;
import org.apache.solr.analytics.facet.compare.ExpressionComparator;
import org.apache.solr.analytics.util.function.BooleanConsumer;
+import org.apache.solr.analytics.value.constant.ConstantBooleanValue;
/**
* A single-valued analytics value that can be represented as a boolean.
@@ -78,6 +79,13 @@ public interface BooleanValue extends BooleanValueStream, AnalyticsValue {
}
}
@Override
+ public AnalyticsValue convertToConstant() {
+ if (getExpressionType().equals(ExpressionType.CONST)) {
+ return new ConstantBooleanValue(getBoolean());
+ }
+ return this;
+ }
+ @Override
public ExpressionComparator<Boolean> getObjectComparator(String expression) {
return new ExpressionComparator<>(expression);
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/BooleanValueStream.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/BooleanValueStream.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/BooleanValueStream.java
index 0827aea..b2eb19b 100644
--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/BooleanValueStream.java
+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/BooleanValueStream.java
@@ -51,5 +51,9 @@ public interface BooleanValueStream extends AnalyticsValueStream {
public void streamObjects(Consumer<Object> cons) {
streamBooleans((boolean val) -> cons.accept(val));
}
+ @Override
+ public AnalyticsValueStream convertToConstant() {
+ return this;
+ }
}
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/DateValue.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/DateValue.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/DateValue.java
index b105d58..8a0f0a9 100644
--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/DateValue.java
+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/DateValue.java
@@ -22,6 +22,7 @@ import java.util.function.Consumer;
import java.util.function.LongConsumer;
import org.apache.solr.analytics.facet.compare.ExpressionComparator;
+import org.apache.solr.analytics.value.constant.ConstantDateValue;
/**
* A single-valued analytics value that can be represented as a date.
@@ -63,8 +64,7 @@ public interface DateValue extends DateValueStream, LongValue {
}
@Override
public Object getObject() {
- long val = getLong();
- return exists() ? new Date(val) : null;
+ return getDate();
}
@Override
public void streamDates(Consumer<Date> cons) {
@@ -95,6 +95,13 @@ public interface DateValue extends DateValueStream, LongValue {
}
}
@Override
+ public AnalyticsValue convertToConstant() {
+ if (getExpressionType().equals(ExpressionType.CONST)) {
+ return new ConstantDateValue(getLong());
+ }
+ return this;
+ }
+ @Override
public ExpressionComparator<Date> getObjectComparator(String expression) {
return new ExpressionComparator<>(expression);
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/DateValueStream.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/DateValueStream.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/DateValueStream.java
index f709264..b7ab159 100644
--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/DateValueStream.java
+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/DateValueStream.java
@@ -56,7 +56,11 @@ public interface DateValueStream extends LongValueStream {
}
@Override
public void streamObjects(Consumer<Object> cons) {
- streamLongs((long val) -> cons.accept(new Date(val)));
+ streamDates((Date val) -> cons.accept(val));
+ }
+ @Override
+ public AnalyticsValueStream convertToConstant() {
+ return this;
}
}
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/DoubleValue.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/DoubleValue.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/DoubleValue.java
index ba527f0..87a1499 100644
--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/DoubleValue.java
+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/DoubleValue.java
@@ -20,6 +20,7 @@ import java.util.function.Consumer;
import java.util.function.DoubleConsumer;
import org.apache.solr.analytics.facet.compare.ExpressionComparator;
+import org.apache.solr.analytics.value.constant.ConstantDoubleValue;
/**
* A single-valued analytics value that can be represented as a date.
@@ -79,6 +80,13 @@ public interface DoubleValue extends DoubleValueStream, AnalyticsValue {
}
}
@Override
+ public AnalyticsValue convertToConstant() {
+ if (getExpressionType().equals(ExpressionType.CONST)) {
+ return new ConstantDoubleValue(getDouble());
+ }
+ return this;
+ }
+ @Override
public ExpressionComparator<Double> getObjectComparator(String expression) {
return new ExpressionComparator<>(expression);
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/DoubleValueStream.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/DoubleValueStream.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/DoubleValueStream.java
index a50c834..e0b4b30 100644
--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/DoubleValueStream.java
+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/DoubleValueStream.java
@@ -50,5 +50,9 @@ public interface DoubleValueStream extends AnalyticsValueStream {
public void streamObjects(Consumer<Object> cons) {
streamDoubles((double val) -> cons.accept(val));
}
+ @Override
+ public AnalyticsValueStream convertToConstant() {
+ return this;
+ }
}
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/FloatValue.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/FloatValue.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/FloatValue.java
index 16883d5..38893d1 100644
--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/FloatValue.java
+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/FloatValue.java
@@ -21,6 +21,7 @@ import java.util.function.DoubleConsumer;
import org.apache.solr.analytics.facet.compare.ExpressionComparator;
import org.apache.solr.analytics.util.function.FloatConsumer;
+import org.apache.solr.analytics.value.constant.ConstantFloatValue;
/**
* A single-valued analytics value that can be represented as a float.
@@ -90,6 +91,13 @@ public interface FloatValue extends FloatValueStream, AnalyticsValue {
}
}
@Override
+ public AnalyticsValue convertToConstant() {
+ if (getExpressionType().equals(ExpressionType.CONST)) {
+ return new ConstantFloatValue(getFloat());
+ }
+ return this;
+ }
+ @Override
public ExpressionComparator<Float> getObjectComparator(String expression) {
return new ExpressionComparator<>(expression);
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/FloatValueStream.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/FloatValueStream.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/FloatValueStream.java
index cf15a21..5364540 100644
--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/FloatValueStream.java
+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/FloatValueStream.java
@@ -56,5 +56,9 @@ public interface FloatValueStream extends AnalyticsValueStream {
public void streamObjects(Consumer<Object> cons) {
streamFloats((float val) -> cons.accept(val));
}
+ @Override
+ public AnalyticsValueStream convertToConstant() {
+ return this;
+ }
}
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/IntValue.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/IntValue.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/IntValue.java
index 5688357..c7353d8 100644
--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/IntValue.java
+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/IntValue.java
@@ -23,6 +23,7 @@ import java.util.function.LongConsumer;
import org.apache.solr.analytics.facet.compare.ExpressionComparator;
import org.apache.solr.analytics.util.function.FloatConsumer;
+import org.apache.solr.analytics.value.constant.ConstantIntValue;
/**
* A single-valued analytics value that can be represented as an int.
@@ -114,6 +115,13 @@ public interface IntValue extends IntValueStream, AnalyticsValue {
}
}
@Override
+ public AnalyticsValue convertToConstant() {
+ if (getExpressionType().equals(ExpressionType.CONST)) {
+ return new ConstantIntValue(getInt());
+ }
+ return this;
+ }
+ @Override
public ExpressionComparator<Integer> getObjectComparator(String expression) {
return new ExpressionComparator<>(expression);
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/IntValueStream.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/IntValueStream.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/IntValueStream.java
index 9cbe28c..e4f1014 100644
--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/IntValueStream.java
+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/IntValueStream.java
@@ -67,5 +67,9 @@ public interface IntValueStream extends AnalyticsValueStream {
public void streamObjects(Consumer<Object> cons) {
streamInts((int val) -> cons.accept(val));
}
+ @Override
+ public AnalyticsValueStream convertToConstant() {
+ return this;
+ }
}
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/LongValue.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/LongValue.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/LongValue.java
index 623cd13..2cdf16c 100644
--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/LongValue.java
+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/LongValue.java
@@ -21,6 +21,7 @@ import java.util.function.DoubleConsumer;
import java.util.function.LongConsumer;
import org.apache.solr.analytics.facet.compare.ExpressionComparator;
+import org.apache.solr.analytics.value.constant.ConstantLongValue;
/**
* A single-valued analytics value that can be represented as a long.
@@ -90,6 +91,13 @@ public interface LongValue extends LongValueStream, AnalyticsValue {
}
}
@Override
+ public AnalyticsValue convertToConstant() {
+ if (getExpressionType().equals(ExpressionType.CONST)) {
+ return new ConstantLongValue(getLong());
+ }
+ return this;
+ }
+ @Override
public ExpressionComparator<Long> getObjectComparator(String expression) {
return new ExpressionComparator<>(expression);
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/LongValueStream.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/LongValueStream.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/LongValueStream.java
index d18cb03..5446b70 100644
--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/LongValueStream.java
+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/LongValueStream.java
@@ -56,5 +56,9 @@ public interface LongValueStream extends AnalyticsValueStream {
public void streamObjects(Consumer<Object> cons) {
streamLongs((long val) -> cons.accept(val));
}
+ @Override
+ public AnalyticsValueStream convertToConstant() {
+ return this;
+ }
}
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/StringValue.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/StringValue.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/StringValue.java
index 7baf18e..47c0a33 100644
--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/StringValue.java
+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/StringValue.java
@@ -19,6 +19,7 @@ package org.apache.solr.analytics.value;
import java.util.function.Consumer;
import org.apache.solr.analytics.facet.compare.ExpressionComparator;
+import org.apache.solr.analytics.value.constant.ConstantStringValue;
/**
* A single-valued analytics value that can be represented as a string.
@@ -64,6 +65,13 @@ public interface StringValue extends StringValueStream, AnalyticsValue {
}
}
@Override
+ public AnalyticsValue convertToConstant() {
+ if (getExpressionType().equals(ExpressionType.CONST)) {
+ return new ConstantStringValue(getString());
+ }
+ return this;
+ }
+ @Override
public ExpressionComparator<String> getObjectComparator(String expression) {
return new ExpressionComparator<>(expression);
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/StringValueStream.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/StringValueStream.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/StringValueStream.java
index 2269ac4..536e475 100644
--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/StringValueStream.java
+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/StringValueStream.java
@@ -45,5 +45,9 @@ public interface StringValueStream extends AnalyticsValueStream {
public void streamObjects(Consumer<Object> cons) {
streamStrings((String val) -> cons.accept(val));
}
+ @Override
+ public AnalyticsValueStream convertToConstant() {
+ return this;
+ }
}
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/constant/ConstantValue.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/constant/ConstantValue.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/constant/ConstantValue.java
index 2e364b1..5691f64 100644
--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/constant/ConstantValue.java
+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/value/constant/ConstantValue.java
@@ -16,7 +16,8 @@
*/
package org.apache.solr.analytics.value.constant;
-import java.text.SimpleDateFormat;
+import java.time.Instant;
+import java.time.format.DateTimeParseException;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -34,29 +35,13 @@ import org.apache.solr.common.SolrException.ErrorCode;
* <ul>
* <li> Constant booleans must match one of the following in any case: true, t, false, f
* <li> Constant strings must be surrounded with "s or 's
- * <li> Constant numbers do not have to be surrounded with anything
- * <li> Constant dates must match one of the following patterns
- * <ul>
- * <li> yyyy-MM-dd
- * <li> yyyy-MM-ddXXX
- * <li> yyyy-MM-dd'T'HH:mm:ssZ
- * <li> yyyy-MM-dd'T'HH:mm:ssXXX
- * <li> yyyy-MM-dd'T'HH:mm:ss.SSSZ
- * <li> yyyy-MM-dd'T'HH:mm:ss.SSSXXX
- * </ul>
- * </li>
+ * <li> Constant numbers do not have to be surrounded with anything (floats are currently not supported)
+ * <li> Constant dates must be formated in the ISO-8601 instant format
* </ul>
*/
-public abstract class ConstantValue {
+public abstract class ConstantValue implements AnalyticsValue {
private static final Pattern truePattern = Pattern.compile("^true|t$", Pattern.CASE_INSENSITIVE);
private static final Pattern falsePattern = Pattern.compile("^false|f$", Pattern.CASE_INSENSITIVE);
- private static final SimpleDateFormat dateParserBase = new SimpleDateFormat("yyyy-MM-dd", Locale.ROOT);
- private static final SimpleDateFormat dateParser1 = new SimpleDateFormat("yyyy-MM-ddZ", Locale.ROOT);
- private static final SimpleDateFormat dateParser2 = new SimpleDateFormat("yyyy-MM-ddXXX", Locale.ROOT);
- private static final SimpleDateFormat dateParser3 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.ROOT);
- private static final SimpleDateFormat dateParser4 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX", Locale.ROOT);
- private static final SimpleDateFormat dateParser5 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.ROOT);
- private static final SimpleDateFormat dateParser6 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX", Locale.ROOT);
public static final ConstantFunction creatorFunction = (param -> {
param = param.trim();
@@ -79,50 +64,36 @@ public abstract class ConstantValue {
// Try to create a number
try {
- AnalyticsValue value = new ConstantDoubleValue(Double.parseDouble(param));
- try {
- value = new ConstantLongValue(Long.parseLong(param));
- value = new ConstantIntValue(Integer.parseInt(param));
- } catch (NumberFormatException e) {
- value = new ConstantFloatValue(Float.parseFloat(param));
+ long longTemp = Long.parseLong(param);
+ if (longTemp == (int) longTemp) {
+ return new ConstantIntValue((int) longTemp);
+ } else {
+ return new ConstantLongValue(longTemp);
}
- return value;
- } catch (NumberFormatException e) {
- // The constant is not a number
+ } catch (NumberFormatException e1) {
+ try {
+ return new ConstantDoubleValue(Double.parseDouble(param));
+ } catch (NumberFormatException e2) {}
}
// Try to create a date
try {
- AnalyticsValue value = new ConstantDateValue(dateParserBase.parse(param).getTime());
- try {
- return new ConstantDateValue(dateParser1.parse(param).getTime());
- } catch (Exception e) {}
- try {
- return new ConstantDateValue(dateParser2.parse(param).getTime());
- } catch (Exception e) {}
- try {
- return new ConstantDateValue(dateParser3.parse(param).getTime());
- } catch (Exception e) {}
- try {
- return new ConstantDateValue(dateParser4.parse(param).getTime());
- } catch (Exception e) {}
- try {
- return new ConstantDateValue(dateParser5.parse(param).getTime());
- } catch (Exception e) {}
- try {
- return new ConstantDateValue(dateParser6.parse(param).getTime());
- } catch (Exception e) {}
- return value;
- } catch (Exception e) {
+ return new ConstantDateValue(Instant.parse(param).toEpochMilli());
+ } catch (DateTimeParseException e) {
throw new SolrException(ErrorCode.BAD_REQUEST,"The parameter "+param+" could not be cast to any constant.");
}
});
+ @Override
+ public AnalyticsValue convertToConstant() {
+ return this;
+ }
+
static String createExpressionString(AnalyticsValueStream func,
Object param) {
return String.format(Locale.ROOT,"%s(%s)",
func.getName(),
param.toString());
}
-}
\ No newline at end of file
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test-files/solr/analytics/expressions.txt
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test-files/solr/analytics/expressions.txt b/solr/contrib/analytics/src/test-files/solr/analytics/expressions.txt
deleted file mode 100644
index 6f5c916..0000000
--- a/solr/contrib/analytics/src/test-files/solr/analytics/expressions.txt
+++ /dev/null
@@ -1,65 +0,0 @@
-o.ar.s.sum=sum(int_id)
-o.ar.s.unique=unique(long_ld)
-o.ar.s.su=add(sum(int_id),unique(long_ld))
-o.ar.s.mean=mean(int_id)
-o.ar.s.count=count(long_ld)
-o.ar.s.median=median(int_id)
-o.ar.s.mcm=add(mean(int_id),count(long_ld),median(int_id))
-
-o.mr.s.sum=sum(int_id)
-o.mr.s.unique=unique(long_ld)
-o.mr.s.su=mult(sum(int_id),unique(long_ld))
-o.mr.s.mean=mean(int_id)
-o.mr.s.count=count(long_ld)
-o.mr.s.median=median(int_id)
-o.mr.s.mcm=mult(mean(int_id),count(long_ld),median(int_id))
-
-o.dr.s.sum=sum(int_id)
-o.dr.s.unique=unique(long_ld)
-o.dr.s.su=div(sum(int_id),unique(long_ld))
-o.dr.s.mean=mean(int_id)
-o.dr.s.count=count(long_ld)
-o.dr.s.mc=div(mean(int_id),count(long_ld))
-
-o.pr.s.sum=sum(int_id)
-o.pr.s.unique=unique(long_ld)
-o.pr.s.su=pow(sum(int_id),unique(long_ld))
-o.pr.s.mean=mean(int_id)
-o.pr.s.count=count(long_ld)
-o.pr.s.mc=pow(mean(int_id),count(long_ld))
-
-o.nr.s.sum=sum(int_id)
-o.nr.s.s=neg(sum(int_id))
-o.nr.s.count=count(long_ld)
-o.nr.s.c=neg(count(long_ld))
-
-o.avr.s.sum=sum(int_id)
-o.avr.s.s=abs(neg(sum(int_id)))
-o.avr.s.count=count(long_ld)
-o.avr.s.c=abs(neg(count(long_ld)))
-
-o.cnr.s.c8=8
-o.cnr.s.c10=10.0
-
-o.dmr.s.median=median(date_dtd)
-o.dmr.s.cme="+2YEARS"
-o.dmr.s.dmme=date_math(median(date_dtd),"+2YEARS")
-o.dmr.s.max=max(date_dtd)
-o.dmr.s.cma="+2MONTHS"
-o.dmr.s.dmma=date_math(max(date_dtd),"+2MONTHS")
-
-o.cdr.s.cd1=1800-12-31T23:59:59Z
-o.cdr.s.cs1="1800-12-31T23:59:59Z"
-o.cdr.s.cd2=1804-06-30T23:59:59Z
-o.cdr.s.cs2="1804-06-30T23:59:59Z"
-
-o.csr.s.cs1="this is the first"
-o.csr.s.cs2="this is the second"
-o.csr.s.cs3="this is the third"
-
-o.cr.s.csmin="this is the first"
-o.cr.s.min=min(string_sd)
-o.cr.s.ccmin=concat("this is the first",min(string_sd))
-o.cr.s.csmax="this is the second"
-o.cr.s.max=max(string_sd)
-o.cr.s.ccmax=concat("this is the second",max(string_sd))
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test-files/solr/analytics/facetSorting.txt
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test-files/solr/analytics/facetSorting.txt b/solr/contrib/analytics/src/test-files/solr/analytics/facetSorting.txt
deleted file mode 100644
index 4663217..0000000
--- a/solr/contrib/analytics/src/test-files/solr/analytics/facetSorting.txt
+++ /dev/null
@@ -1,4 +0,0 @@
-o.ar.s.min=min(double_dd)
-o.ar.s.max=max(long_ld)
-o.ar.ff=string_sd
-o.ar.ff.string_sd.sortstatistic=min
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test-files/solr/analytics/fieldFacetExtras.txt
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test-files/solr/analytics/fieldFacetExtras.txt b/solr/contrib/analytics/src/test-files/solr/analytics/fieldFacetExtras.txt
deleted file mode 100644
index 3979f57..0000000
--- a/solr/contrib/analytics/src/test-files/solr/analytics/fieldFacetExtras.txt
+++ /dev/null
@@ -1,66 +0,0 @@
-o.sr.s.mean=mean(int_id)
-o.sr.s.median=median(int_id)
-o.sr.s.count=count(int_id)
-o.sr.s.percentile_20=percentile(20,int_id)
-o.sr.ff=long_ld
-o.sr.ff.long_ld.ss=mean
-o.sr.ff.long_ld.sd=asc
-o.sr.ff=float_fd
-o.sr.ff.float_fd.ss=median
-o.sr.ff.float_fd.sd=desc
-o.sr.ff=double_dd
-o.sr.ff.double_dd.ss=count
-o.sr.ff.double_dd.sd=asc
-o.sr.ff=string_sd
-o.sr.ff.string_sd.ss=percentile_20
-o.sr.ff.string_sd.sd=desc
-
-o.lr.s.mean=mean(int_id)
-o.lr.s.median=median(int_id)
-o.lr.s.count=count(int_id)
-o.lr.s.percentile_20=percentile(20,int_id)
-o.lr.ff=long_ld
-o.lr.ff.long_ld.ss=mean
-o.lr.ff.long_ld.sd=asc
-o.lr.ff.long_ld.limit=5
-o.lr.ff=float_fd
-o.lr.ff.float_fd.ss=median
-o.lr.ff.float_fd.sd=desc
-o.lr.ff.float_fd.limit=3
-o.lr.ff=double_dd
-o.lr.ff.double_dd.ss=count
-o.lr.ff.double_dd.sd=asc
-o.lr.ff.double_dd.limit=7
-o.lr.ff=string_sd
-o.lr.ff.string_sd.ss=percentile_20
-o.lr.ff.string_sd.sd=desc
-o.lr.ff.string_sd.limit=1
-
-
-
-o.offAll.s.mean=mean(int_id)
-o.offAll.ff=long_ld
-o.offAll.ff.long_ld.ss=mean
-o.offAll.ff.long_ld.sd=asc
-o.offAll.ff.long_ld.limit=7
-
-o.off0.s.mean=mean(int_id)
-o.off0.ff=long_ld
-o.off0.ff.long_ld.ss=mean
-o.off0.ff.long_ld.sd=asc
-o.off0.ff.long_ld.limit=2
-o.off0.ff.long_ld.offset=0
-
-o.off1.s.mean=mean(int_id)
-o.off1.ff=long_ld
-o.off1.ff.long_ld.ss=mean
-o.off1.ff.long_ld.sd=asc
-o.off1.ff.long_ld.limit=2
-o.off1.ff.long_ld.offset=2
-
-o.off2.s.mean=mean(int_id)
-o.off2.ff=long_ld
-o.off2.ff.long_ld.ss=mean
-o.off2.ff.long_ld.sd=asc
-o.off2.ff.long_ld.limit=3
-o.off2.ff.long_ld.offset=4
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test-files/solr/analytics/fieldFacets.txt
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test-files/solr/analytics/fieldFacets.txt b/solr/contrib/analytics/src/test-files/solr/analytics/fieldFacets.txt
deleted file mode 100644
index 5ba5953..0000000
--- a/solr/contrib/analytics/src/test-files/solr/analytics/fieldFacets.txt
+++ /dev/null
@@ -1,132 +0,0 @@
-o.sum.s.int=sum(int_id)
-o.sum.s.long=sum(long_ld)
-o.sum.s.float=sum(float_fd)
-o.sum.s.double=sum(double_dd)
-o.sum.ff=string_sd
-o.sum.ff=date_dtd
-
-o.mean.s.int=mean(int_id)
-o.mean.s.long=mean(long_ld)
-o.mean.s.float=mean(float_fd)
-o.mean.s.double=mean(double_dd)
-o.mean.ff=string_sd
-o.mean.ff=date_dtd
-
-o.sumOfSquares.s.int=sumofsquares(int_id)
-o.sumOfSquares.s.long=sumofsquares(long_ld)
-o.sumOfSquares.s.float=sumofsquares(float_fd)
-o.sumOfSquares.s.double=sumofsquares(double_dd)
-o.sumOfSquares.ff=string_sd
-o.sumOfSquares.ff=date_dtd
-
-o.stddev.s.int=stddev(int_id)
-o.stddev.s.long=stddev(long_ld)
-o.stddev.s.float=stddev(float_fd)
-o.stddev.s.double=stddev(double_dd)
-o.stddev.ff=string_sd
-o.stddev.ff=date_dtd
-
-o.median.s.int=median(int_id)
-o.median.s.long=median(long_ld)
-o.median.s.float=median(float_fd)
-o.median.s.double=median(double_dd)
-o.median.ff=string_sd
-o.median.ff=date_dtd
-
-o.percentile_20n.s.int=percentile(20,int_id)
-o.percentile_20n.s.long=percentile(20,long_ld)
-o.percentile_20n.s.float=percentile(20,float_fd)
-o.percentile_20n.s.double=percentile(20,double_dd)
-o.percentile_20n.ff=string_sd
-o.percentile_20n.ff=date_dtd
-
-o.percentile_20.s.str=percentile(20,string_sd)
-o.percentile_20.s.date=percentile(20,date_dtd)
-o.percentile_20.ff=int_id
-o.percentile_20.ff=long_ld
-
-o.percentile_60n.s.int=percentile(60,int_id)
-o.percentile_60n.s.long=percentile(60,long_ld)
-o.percentile_60n.s.float=percentile(60,float_fd)
-o.percentile_60n.s.double=percentile(60,double_dd)
-o.percentile_60n.ff=string_sd
-o.percentile_60n.ff=date_dtd
-
-o.percentile_60.s.str=percentile(60,string_sd)
-o.percentile_60.s.date=percentile(60,date_dtd)
-o.percentile_60.ff=int_id
-o.percentile_60.ff=long_ld
-
-o.minn.s.int=min(int_id)
-o.minn.s.long=min(long_ld)
-o.minn.s.float=min(float_fd)
-o.minn.s.double=min(double_dd)
-o.minn.ff=string_sd
-o.minn.ff=date_dtd
-
-o.min.s.str=min(string_sd)
-o.min.s.date=min(date_dtd)
-o.min.ff=int_id
-o.min.ff=long_ld
-
-o.maxn.s.int=max(int_id)
-o.maxn.s.long=max(long_ld)
-o.maxn.s.float=max(float_fd)
-o.maxn.s.double=max(double_dd)
-o.maxn.ff=string_sd
-o.maxn.ff=date_dtd
-
-o.max.s.str=max(string_sd)
-o.max.s.date=max(date_dtd)
-o.max.ff=int_id
-o.max.ff=long_ld
-
-o.countn.s.int=count(int_id)
-o.countn.s.long=count(long_ld)
-o.countn.s.float=count(float_fd)
-o.countn.s.double=count(double_dd)
-o.countn.ff=string_sd
-o.countn.ff=date_dtd
-
-o.count.s.str=count(string_sd)
-o.count.s.date=count(date_dtd)
-o.count.ff=int_id
-o.count.ff=long_ld
-
-o.uniquen.s.int=unique(int_id)
-o.uniquen.s.long=unique(long_ld)
-o.uniquen.s.float=unique(float_fd)
-o.uniquen.s.double=unique(double_dd)
-o.uniquen.ff=string_sd
-o.uniquen.ff=date_dtd
-
-o.unique.s.str=unique(string_sd)
-o.unique.s.date=unique(date_dtd)
-o.unique.ff=int_id
-o.unique.ff=long_ld
-
-o.missingn.s.int=missing(int_id)
-o.missingn.s.long=missing(long_ld)
-o.missingn.s.float=missing(float_fd)
-o.missingn.s.double=missing(double_dd)
-o.missingn.ff=string_sd
-o.missingn.ff=date_dtd
-
-o.missing.s.str=missing(string_sd)
-o.missing.s.date=missing(date_dtd)
-o.missing.ff=int_id
-o.missing.ff=long_ld
-
-o.multivalued.s.mean=mean(int_id)
-o.multivalued.ff=long_ldm
-o.multivalued.ff=string_sdm
-o.multivalued.ff=date_dtdm
-
-o.missingf.s.mean=mean(int_id)
-o.missingf.ff=date_dtd
-o.missingf.ff.date_dtd.dim=true
-o.missingf.ff=string_sd
-o.missingf.ff.string_sd.dim=true
-o.missingf.ff.string_sd.sm=true
-o.missingf.ff=date_dtdm
-o.missingf.ff.date_dtdm.sm=true
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test-files/solr/analytics/functions.txt
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test-files/solr/analytics/functions.txt b/solr/contrib/analytics/src/test-files/solr/analytics/functions.txt
deleted file mode 100644
index ce73583..0000000
--- a/solr/contrib/analytics/src/test-files/solr/analytics/functions.txt
+++ /dev/null
@@ -1,57 +0,0 @@
-o.ar.s.sum=sum(add(int_id,float_fd))
-o.ar.s.sumc=sum(add_if_dd)
-o.ar.s.mean=mean(add(long_ld,double_dd,float_fd))
-o.ar.s.meanc=mean(add_ldf_dd)
-
-o.mr.s.sum=sum(mult(int_id,float_fd))
-o.mr.s.sumc=sum(mult_if_dd)
-o.mr.s.mean=mean(mult(long_ld,double_dd,float_fd))
-o.mr.s.meanc=mean(mult_ldf_dd)
-
-o.dr.s.sum=sum(div(int_id,float_fd))
-o.dr.s.sumc=sum(div_if_dd)
-o.dr.s.mean=mean(div(long_ld,double_dd))
-o.dr.s.meanc=mean(div_ld_dd)
-
-o.pr.s.sum=sum(pow(int_id,float_fd))
-o.pr.s.sumc=sum(pow_if_dd)
-o.pr.s.mean=mean(pow(long_ld,double_dd))
-o.pr.s.meanc=mean(pow_ld_dd)
-
-o.nr.s.sum=sum(neg(int_id))
-o.nr.s.sumc=sum(neg_id)
-o.nr.s.mean=mean(neg(long_ld))
-o.nr.s.meanc=mean(neg_ld)
-
-o.avr.s.sum=sum(abs(neg(int_id)))
-o.avr.s.sumc=sum(int_id)
-o.avr.s.mean=mean(abs(neg(int_id)))
-o.avr.s.meanc=mean(int_id)
-
-o.cnr.s.sum=sum(8)
-o.cnr.s.sumc=sum(const_8_dd)
-o.cnr.s.mean=mean(10)
-o.cnr.s.meanc=mean(const_10_dd)
-
-o.dmr.s.median=median(date_math(date_dtd,"+2YEARS"))
-o.dmr.s.medianc=median(dm_2y_dtd)
-o.dmr.s.max=max(date_math(date_dtd,"+2MONTHS"))
-o.dmr.s.maxc=max(dm_2m_dtd)
-
-o.cdr.s.median=median(1800-06-30T23:59:59Z)
-o.cdr.s.medianc=median(const_00_dtd)
-o.cdr.s.max=max(1804-06-30T23:59:59Z)
-o.cdr.s.maxc=max(const_04_dtd)
-
-o.csr.s.min=min("this is the first")
-o.csr.s.minc=min(const_first_sd)
-o.csr.s.max=max("this is the second")
-o.csr.s.maxc=max(const_second_sd)
-
-o.cr.s.min=concat("this is the first",min(string_sd))
-o.cr.s.minc=min(concat_first_sd)
-o.cr.s.max=concat("this is the second",max(string_sd))
-o.cr.s.maxc=max(concat_second_sd)
-
-o.ms.s.min=min(miss_dd)
-o.ms.s.max=max(miss_dd)
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test-files/solr/analytics/legacy/expressions.txt
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test-files/solr/analytics/legacy/expressions.txt b/solr/contrib/analytics/src/test-files/solr/analytics/legacy/expressions.txt
new file mode 100644
index 0000000..6f5c916
--- /dev/null
+++ b/solr/contrib/analytics/src/test-files/solr/analytics/legacy/expressions.txt
@@ -0,0 +1,65 @@
+o.ar.s.sum=sum(int_id)
+o.ar.s.unique=unique(long_ld)
+o.ar.s.su=add(sum(int_id),unique(long_ld))
+o.ar.s.mean=mean(int_id)
+o.ar.s.count=count(long_ld)
+o.ar.s.median=median(int_id)
+o.ar.s.mcm=add(mean(int_id),count(long_ld),median(int_id))
+
+o.mr.s.sum=sum(int_id)
+o.mr.s.unique=unique(long_ld)
+o.mr.s.su=mult(sum(int_id),unique(long_ld))
+o.mr.s.mean=mean(int_id)
+o.mr.s.count=count(long_ld)
+o.mr.s.median=median(int_id)
+o.mr.s.mcm=mult(mean(int_id),count(long_ld),median(int_id))
+
+o.dr.s.sum=sum(int_id)
+o.dr.s.unique=unique(long_ld)
+o.dr.s.su=div(sum(int_id),unique(long_ld))
+o.dr.s.mean=mean(int_id)
+o.dr.s.count=count(long_ld)
+o.dr.s.mc=div(mean(int_id),count(long_ld))
+
+o.pr.s.sum=sum(int_id)
+o.pr.s.unique=unique(long_ld)
+o.pr.s.su=pow(sum(int_id),unique(long_ld))
+o.pr.s.mean=mean(int_id)
+o.pr.s.count=count(long_ld)
+o.pr.s.mc=pow(mean(int_id),count(long_ld))
+
+o.nr.s.sum=sum(int_id)
+o.nr.s.s=neg(sum(int_id))
+o.nr.s.count=count(long_ld)
+o.nr.s.c=neg(count(long_ld))
+
+o.avr.s.sum=sum(int_id)
+o.avr.s.s=abs(neg(sum(int_id)))
+o.avr.s.count=count(long_ld)
+o.avr.s.c=abs(neg(count(long_ld)))
+
+o.cnr.s.c8=8
+o.cnr.s.c10=10.0
+
+o.dmr.s.median=median(date_dtd)
+o.dmr.s.cme="+2YEARS"
+o.dmr.s.dmme=date_math(median(date_dtd),"+2YEARS")
+o.dmr.s.max=max(date_dtd)
+o.dmr.s.cma="+2MONTHS"
+o.dmr.s.dmma=date_math(max(date_dtd),"+2MONTHS")
+
+o.cdr.s.cd1=1800-12-31T23:59:59Z
+o.cdr.s.cs1="1800-12-31T23:59:59Z"
+o.cdr.s.cd2=1804-06-30T23:59:59Z
+o.cdr.s.cs2="1804-06-30T23:59:59Z"
+
+o.csr.s.cs1="this is the first"
+o.csr.s.cs2="this is the second"
+o.csr.s.cs3="this is the third"
+
+o.cr.s.csmin="this is the first"
+o.cr.s.min=min(string_sd)
+o.cr.s.ccmin=concat("this is the first",min(string_sd))
+o.cr.s.csmax="this is the second"
+o.cr.s.max=max(string_sd)
+o.cr.s.ccmax=concat("this is the second",max(string_sd))
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test-files/solr/analytics/legacy/facetSorting.txt
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test-files/solr/analytics/legacy/facetSorting.txt b/solr/contrib/analytics/src/test-files/solr/analytics/legacy/facetSorting.txt
new file mode 100644
index 0000000..4663217
--- /dev/null
+++ b/solr/contrib/analytics/src/test-files/solr/analytics/legacy/facetSorting.txt
@@ -0,0 +1,4 @@
+o.ar.s.min=min(double_dd)
+o.ar.s.max=max(long_ld)
+o.ar.ff=string_sd
+o.ar.ff.string_sd.sortstatistic=min
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test-files/solr/analytics/legacy/fieldFacetExtras.txt
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test-files/solr/analytics/legacy/fieldFacetExtras.txt b/solr/contrib/analytics/src/test-files/solr/analytics/legacy/fieldFacetExtras.txt
new file mode 100644
index 0000000..3979f57
--- /dev/null
+++ b/solr/contrib/analytics/src/test-files/solr/analytics/legacy/fieldFacetExtras.txt
@@ -0,0 +1,66 @@
+o.sr.s.mean=mean(int_id)
+o.sr.s.median=median(int_id)
+o.sr.s.count=count(int_id)
+o.sr.s.percentile_20=percentile(20,int_id)
+o.sr.ff=long_ld
+o.sr.ff.long_ld.ss=mean
+o.sr.ff.long_ld.sd=asc
+o.sr.ff=float_fd
+o.sr.ff.float_fd.ss=median
+o.sr.ff.float_fd.sd=desc
+o.sr.ff=double_dd
+o.sr.ff.double_dd.ss=count
+o.sr.ff.double_dd.sd=asc
+o.sr.ff=string_sd
+o.sr.ff.string_sd.ss=percentile_20
+o.sr.ff.string_sd.sd=desc
+
+o.lr.s.mean=mean(int_id)
+o.lr.s.median=median(int_id)
+o.lr.s.count=count(int_id)
+o.lr.s.percentile_20=percentile(20,int_id)
+o.lr.ff=long_ld
+o.lr.ff.long_ld.ss=mean
+o.lr.ff.long_ld.sd=asc
+o.lr.ff.long_ld.limit=5
+o.lr.ff=float_fd
+o.lr.ff.float_fd.ss=median
+o.lr.ff.float_fd.sd=desc
+o.lr.ff.float_fd.limit=3
+o.lr.ff=double_dd
+o.lr.ff.double_dd.ss=count
+o.lr.ff.double_dd.sd=asc
+o.lr.ff.double_dd.limit=7
+o.lr.ff=string_sd
+o.lr.ff.string_sd.ss=percentile_20
+o.lr.ff.string_sd.sd=desc
+o.lr.ff.string_sd.limit=1
+
+
+
+o.offAll.s.mean=mean(int_id)
+o.offAll.ff=long_ld
+o.offAll.ff.long_ld.ss=mean
+o.offAll.ff.long_ld.sd=asc
+o.offAll.ff.long_ld.limit=7
+
+o.off0.s.mean=mean(int_id)
+o.off0.ff=long_ld
+o.off0.ff.long_ld.ss=mean
+o.off0.ff.long_ld.sd=asc
+o.off0.ff.long_ld.limit=2
+o.off0.ff.long_ld.offset=0
+
+o.off1.s.mean=mean(int_id)
+o.off1.ff=long_ld
+o.off1.ff.long_ld.ss=mean
+o.off1.ff.long_ld.sd=asc
+o.off1.ff.long_ld.limit=2
+o.off1.ff.long_ld.offset=2
+
+o.off2.s.mean=mean(int_id)
+o.off2.ff=long_ld
+o.off2.ff.long_ld.ss=mean
+o.off2.ff.long_ld.sd=asc
+o.off2.ff.long_ld.limit=3
+o.off2.ff.long_ld.offset=4
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test-files/solr/analytics/legacy/fieldFacets.txt
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test-files/solr/analytics/legacy/fieldFacets.txt b/solr/contrib/analytics/src/test-files/solr/analytics/legacy/fieldFacets.txt
new file mode 100644
index 0000000..5ba5953
--- /dev/null
+++ b/solr/contrib/analytics/src/test-files/solr/analytics/legacy/fieldFacets.txt
@@ -0,0 +1,132 @@
+o.sum.s.int=sum(int_id)
+o.sum.s.long=sum(long_ld)
+o.sum.s.float=sum(float_fd)
+o.sum.s.double=sum(double_dd)
+o.sum.ff=string_sd
+o.sum.ff=date_dtd
+
+o.mean.s.int=mean(int_id)
+o.mean.s.long=mean(long_ld)
+o.mean.s.float=mean(float_fd)
+o.mean.s.double=mean(double_dd)
+o.mean.ff=string_sd
+o.mean.ff=date_dtd
+
+o.sumOfSquares.s.int=sumofsquares(int_id)
+o.sumOfSquares.s.long=sumofsquares(long_ld)
+o.sumOfSquares.s.float=sumofsquares(float_fd)
+o.sumOfSquares.s.double=sumofsquares(double_dd)
+o.sumOfSquares.ff=string_sd
+o.sumOfSquares.ff=date_dtd
+
+o.stddev.s.int=stddev(int_id)
+o.stddev.s.long=stddev(long_ld)
+o.stddev.s.float=stddev(float_fd)
+o.stddev.s.double=stddev(double_dd)
+o.stddev.ff=string_sd
+o.stddev.ff=date_dtd
+
+o.median.s.int=median(int_id)
+o.median.s.long=median(long_ld)
+o.median.s.float=median(float_fd)
+o.median.s.double=median(double_dd)
+o.median.ff=string_sd
+o.median.ff=date_dtd
+
+o.percentile_20n.s.int=percentile(20,int_id)
+o.percentile_20n.s.long=percentile(20,long_ld)
+o.percentile_20n.s.float=percentile(20,float_fd)
+o.percentile_20n.s.double=percentile(20,double_dd)
+o.percentile_20n.ff=string_sd
+o.percentile_20n.ff=date_dtd
+
+o.percentile_20.s.str=percentile(20,string_sd)
+o.percentile_20.s.date=percentile(20,date_dtd)
+o.percentile_20.ff=int_id
+o.percentile_20.ff=long_ld
+
+o.percentile_60n.s.int=percentile(60,int_id)
+o.percentile_60n.s.long=percentile(60,long_ld)
+o.percentile_60n.s.float=percentile(60,float_fd)
+o.percentile_60n.s.double=percentile(60,double_dd)
+o.percentile_60n.ff=string_sd
+o.percentile_60n.ff=date_dtd
+
+o.percentile_60.s.str=percentile(60,string_sd)
+o.percentile_60.s.date=percentile(60,date_dtd)
+o.percentile_60.ff=int_id
+o.percentile_60.ff=long_ld
+
+o.minn.s.int=min(int_id)
+o.minn.s.long=min(long_ld)
+o.minn.s.float=min(float_fd)
+o.minn.s.double=min(double_dd)
+o.minn.ff=string_sd
+o.minn.ff=date_dtd
+
+o.min.s.str=min(string_sd)
+o.min.s.date=min(date_dtd)
+o.min.ff=int_id
+o.min.ff=long_ld
+
+o.maxn.s.int=max(int_id)
+o.maxn.s.long=max(long_ld)
+o.maxn.s.float=max(float_fd)
+o.maxn.s.double=max(double_dd)
+o.maxn.ff=string_sd
+o.maxn.ff=date_dtd
+
+o.max.s.str=max(string_sd)
+o.max.s.date=max(date_dtd)
+o.max.ff=int_id
+o.max.ff=long_ld
+
+o.countn.s.int=count(int_id)
+o.countn.s.long=count(long_ld)
+o.countn.s.float=count(float_fd)
+o.countn.s.double=count(double_dd)
+o.countn.ff=string_sd
+o.countn.ff=date_dtd
+
+o.count.s.str=count(string_sd)
+o.count.s.date=count(date_dtd)
+o.count.ff=int_id
+o.count.ff=long_ld
+
+o.uniquen.s.int=unique(int_id)
+o.uniquen.s.long=unique(long_ld)
+o.uniquen.s.float=unique(float_fd)
+o.uniquen.s.double=unique(double_dd)
+o.uniquen.ff=string_sd
+o.uniquen.ff=date_dtd
+
+o.unique.s.str=unique(string_sd)
+o.unique.s.date=unique(date_dtd)
+o.unique.ff=int_id
+o.unique.ff=long_ld
+
+o.missingn.s.int=missing(int_id)
+o.missingn.s.long=missing(long_ld)
+o.missingn.s.float=missing(float_fd)
+o.missingn.s.double=missing(double_dd)
+o.missingn.ff=string_sd
+o.missingn.ff=date_dtd
+
+o.missing.s.str=missing(string_sd)
+o.missing.s.date=missing(date_dtd)
+o.missing.ff=int_id
+o.missing.ff=long_ld
+
+o.multivalued.s.mean=mean(int_id)
+o.multivalued.ff=long_ldm
+o.multivalued.ff=string_sdm
+o.multivalued.ff=date_dtdm
+
+o.missingf.s.mean=mean(int_id)
+o.missingf.ff=date_dtd
+o.missingf.ff.date_dtd.dim=true
+o.missingf.ff=string_sd
+o.missingf.ff.string_sd.dim=true
+o.missingf.ff.string_sd.sm=true
+o.missingf.ff=date_dtdm
+o.missingf.ff.date_dtdm.sm=true
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test-files/solr/analytics/legacy/functions.txt
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test-files/solr/analytics/legacy/functions.txt b/solr/contrib/analytics/src/test-files/solr/analytics/legacy/functions.txt
new file mode 100644
index 0000000..ce73583
--- /dev/null
+++ b/solr/contrib/analytics/src/test-files/solr/analytics/legacy/functions.txt
@@ -0,0 +1,57 @@
+o.ar.s.sum=sum(add(int_id,float_fd))
+o.ar.s.sumc=sum(add_if_dd)
+o.ar.s.mean=mean(add(long_ld,double_dd,float_fd))
+o.ar.s.meanc=mean(add_ldf_dd)
+
+o.mr.s.sum=sum(mult(int_id,float_fd))
+o.mr.s.sumc=sum(mult_if_dd)
+o.mr.s.mean=mean(mult(long_ld,double_dd,float_fd))
+o.mr.s.meanc=mean(mult_ldf_dd)
+
+o.dr.s.sum=sum(div(int_id,float_fd))
+o.dr.s.sumc=sum(div_if_dd)
+o.dr.s.mean=mean(div(long_ld,double_dd))
+o.dr.s.meanc=mean(div_ld_dd)
+
+o.pr.s.sum=sum(pow(int_id,float_fd))
+o.pr.s.sumc=sum(pow_if_dd)
+o.pr.s.mean=mean(pow(long_ld,double_dd))
+o.pr.s.meanc=mean(pow_ld_dd)
+
+o.nr.s.sum=sum(neg(int_id))
+o.nr.s.sumc=sum(neg_id)
+o.nr.s.mean=mean(neg(long_ld))
+o.nr.s.meanc=mean(neg_ld)
+
+o.avr.s.sum=sum(abs(neg(int_id)))
+o.avr.s.sumc=sum(int_id)
+o.avr.s.mean=mean(abs(neg(int_id)))
+o.avr.s.meanc=mean(int_id)
+
+o.cnr.s.sum=sum(8)
+o.cnr.s.sumc=sum(const_8_dd)
+o.cnr.s.mean=mean(10)
+o.cnr.s.meanc=mean(const_10_dd)
+
+o.dmr.s.median=median(date_math(date_dtd,"+2YEARS"))
+o.dmr.s.medianc=median(dm_2y_dtd)
+o.dmr.s.max=max(date_math(date_dtd,"+2MONTHS"))
+o.dmr.s.maxc=max(dm_2m_dtd)
+
+o.cdr.s.median=median(1800-06-30T23:59:59Z)
+o.cdr.s.medianc=median(const_00_dtd)
+o.cdr.s.max=max(1804-06-30T23:59:59Z)
+o.cdr.s.maxc=max(const_04_dtd)
+
+o.csr.s.min=min("this is the first")
+o.csr.s.minc=min(const_first_sd)
+o.csr.s.max=max("this is the second")
+o.csr.s.maxc=max(const_second_sd)
+
+o.cr.s.min=concat("this is the first",min(string_sd))
+o.cr.s.minc=min(concat_first_sd)
+o.cr.s.max=concat("this is the second",max(string_sd))
+o.cr.s.maxc=max(concat_second_sd)
+
+o.ms.s.min=min(miss_dd)
+o.ms.s.max=max(miss_dd)
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test-files/solr/analytics/legacy/noFacets.txt
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test-files/solr/analytics/legacy/noFacets.txt b/solr/contrib/analytics/src/test-files/solr/analytics/legacy/noFacets.txt
new file mode 100644
index 0000000..84e43eb
--- /dev/null
+++ b/solr/contrib/analytics/src/test-files/solr/analytics/legacy/noFacets.txt
@@ -0,0 +1,74 @@
+o.sr.s.int_id=sum(int_id)
+o.sr.s.long_ld=sum(long_ld)
+o.sr.s.float_fd=sum(float_fd)
+o.sr.s.double_dd=sum(double_dd)
+
+o.sosr.s.int_id=sumofsquares(int_id)
+o.sosr.s.long_ld=sumofsquares(long_ld)
+o.sosr.s.float_fd=sumofsquares(float_fd)
+o.sosr.s.double_dd=sumofsquares(double_dd)
+
+o.mr.s.int_id=mean(int_id)
+o.mr.s.long_ld=mean(long_ld)
+o.mr.s.float_fd=mean(float_fd)
+o.mr.s.double_dd=mean(double_dd)
+
+o.str.s.int_id=stddev(int_id)
+o.str.s.long_ld=stddev(long_ld)
+o.str.s.float_fd=stddev(float_fd)
+o.str.s.double_dd=stddev(double_dd)
+
+o.medr.s.int_id=median(int_id)
+o.medr.s.long_ld=median(long_ld)
+o.medr.s.float_fd=median(float_fd)
+o.medr.s.double_dd=median(double_dd)
+o.medr.s.date_dtd=median(date_dtd)
+
+o.p2r.s.int_id=percentile(20,int_id)
+o.p2r.s.long_ld=percentile(20,long_ld)
+o.p2r.s.float_fd=percentile(20,float_fd)
+o.p2r.s.double_dd=percentile(20,double_dd)
+o.p2r.s.date_dtd=percentile(20,date_dtd)
+o.p2r.s.string_sd=percentile(20,string_sd)
+
+o.p6r.s.int_id=percentile(60,int_id)
+o.p6r.s.long_ld=percentile(60,long_ld)
+o.p6r.s.float_fd=percentile(60,float_fd)
+o.p6r.s.double_dd=percentile(60,double_dd)
+o.p6r.s.date_dtd=percentile(60,date_dtd)
+o.p6r.s.string_sd=percentile(60,string_sd)
+
+o.mir.s.int_id=min(int_id)
+o.mir.s.long_ld=min(long_ld)
+o.mir.s.float_fd=min(float_fd)
+o.mir.s.double_dd=min(double_dd)
+o.mir.s.date_dtd=min(date_dtd)
+o.mir.s.string_sd=min(string_sd)
+
+o.mar.s.int_id=max(int_id)
+o.mar.s.long_ld=max(long_ld)
+o.mar.s.float_fd=max(float_fd)
+o.mar.s.double_dd=max(double_dd)
+o.mar.s.date_dtd=max(date_dtd)
+o.mar.s.string_sd=max(string_sd)
+
+o.cr.s.int_id=count(int_id)
+o.cr.s.long_ld=count(long_ld)
+o.cr.s.float_fd=count(float_fd)
+o.cr.s.double_dd=count(double_dd)
+o.cr.s.date_dtd=count(date_dtd)
+o.cr.s.string_sd=count(string_sd)
+
+o.ur.s.int_id=unique(int_id)
+o.ur.s.long_ld=unique(long_ld)
+o.ur.s.float_fd=unique(float_fd)
+o.ur.s.double_dd=unique(double_dd)
+o.ur.s.date_dtd=unique(date_dtd)
+o.ur.s.string_sd=unique(string_sd)
+
+o.misr.s.int_id=missing(int_id)
+o.misr.s.long_ld=missing(long_ld)
+o.misr.s.float_fd=missing(float_fd)
+o.misr.s.double_dd=missing(double_dd)
+o.misr.s.date_dtd=missing(date_dtd)
+o.misr.s.string_sd=missing(string_sd)
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test-files/solr/analytics/legacy/queryFacets.txt
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test-files/solr/analytics/legacy/queryFacets.txt b/solr/contrib/analytics/src/test-files/solr/analytics/legacy/queryFacets.txt
new file mode 100644
index 0000000..84d8fc6
--- /dev/null
+++ b/solr/contrib/analytics/src/test-files/solr/analytics/legacy/queryFacets.txt
@@ -0,0 +1,27 @@
+o.ir.s.sum=sum(int_id)
+o.ir.s.mean=mean(int_id)
+o.ir.s.median=median(int_id)
+o.ir.s.percentile_8=percentile(8,int_id)
+o.ir.ff=string_sd
+o.ir.ff.string_sd.h=true
+o.ir.qf=float1
+o.ir.qf.float1.q=float_fd:[* TO 50]
+o.ir.qf=float2
+o.ir.qf.float2.q=float_fd:[* TO 30]
+
+o.lr.s.sum=sum(long_ld)
+o.lr.s.mean=mean(long_ld)
+o.lr.s.median=median(long_ld)
+o.lr.s.percentile_8=percentile(8,long_ld)
+o.lr.qf=string
+o.lr.qf.string.q=string_sd:abc1
+o.lr.qf.string.q=string_sd:abc2
+
+o.fr.s.sum=sum(float_fd)
+o.fr.s.mean=mean(float_fd)
+o.fr.s.median=median(float_fd)
+o.fr.s.percentile_8=percentile(8,float_fd)
+o.fr.qf=lad
+o.fr.qf.lad.q=long_ld:[20 TO *]
+o.fr.qf.lad.q=long_ld:[30 TO *]
+o.fr.qf.lad.q=double_dd:[* TO 50]
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test-files/solr/analytics/legacy/rangeFacets.txt
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test-files/solr/analytics/legacy/rangeFacets.txt b/solr/contrib/analytics/src/test-files/solr/analytics/legacy/rangeFacets.txt
new file mode 100644
index 0000000..29aae5d
--- /dev/null
+++ b/solr/contrib/analytics/src/test-files/solr/analytics/legacy/rangeFacets.txt
@@ -0,0 +1,161 @@
+o.ri.s.sum=sum(int_id)
+o.ri.s.mean=mean(int_id)
+o.ri.s.median=median(int_id)
+o.ri.s.count=count(int_id)
+o.ri.s.sumOfSquares=sumofsquares(int_id)
+o.ri.rf=long_ld
+o.ri.rf.long_ld.st=5
+o.ri.rf.long_ld.e=30
+o.ri.rf.long_ld.g=5
+o.ri.rf.long_ld.ib=lower
+o.ri.rf.long_ld.or=all
+o.ri.rf=double_dd
+o.ri.rf.double_dd.st=3
+o.ri.rf.double_dd.e=39
+o.ri.rf.double_dd.g=7
+o.ri.rf.double_dd.ib=upper
+o.ri.rf.double_dd.ib=outer
+o.ri.rf.double_dd.or=all
+o.ri.rf=date_dtd
+o.ri.rf.date_dtd.st=1007-01-01T23:59:59Z
+o.ri.rf.date_dtd.e=1044-01-01T23:59:59Z
+o.ri.rf.date_dtd.g=+7YEARS
+o.ri.rf.date_dtd.ib=lower
+o.ri.rf.date_dtd.ib=edge
+o.ri.rf.date_dtd.ib=outer
+o.ri.rf.date_dtd.or=all
+
+o.rf.s.sum=sum(float_fd)
+o.rf.s.mean=mean(float_fd)
+o.rf.s.median=median(float_fd)
+o.rf.s.count=count(float_fd)
+o.rf.s.sumOfSquares=sumofsquares(float_fd)
+o.rf.rf=long_ld
+o.rf.rf.long_ld.st=0
+o.rf.rf.long_ld.e=29
+o.rf.rf.long_ld.g=4
+o.rf.rf.long_ld.ib=all
+o.rf.rf.long_ld.or=all
+o.rf.rf=double_dd
+o.rf.rf.double_dd.st=4
+o.rf.rf.double_dd.e=47
+o.rf.rf.double_dd.g=11
+o.rf.rf.double_dd.ib=edge
+o.rf.rf.double_dd.or=all
+o.rf.rf=date_dtd
+o.rf.rf.date_dtd.st=1004-01-01T23:59:59Z
+o.rf.rf.date_dtd.e=1046-01-01T23:59:59Z
+o.rf.rf.date_dtd.g=+5YEARS
+o.rf.rf.date_dtd.ib=upper
+o.rf.rf.date_dtd.ib=edge
+o.rf.rf.date_dtd.or=all
+
+o.hi.s.sum=sum(int_id)
+o.hi.s.mean=mean(int_id)
+o.hi.s.median=median(int_id)
+o.hi.s.count=count(int_id)
+o.hi.s.sumOfSquares=sumofsquares(int_id)
+o.hi.rf=long_ld
+o.hi.rf.long_ld.st=5
+o.hi.rf.long_ld.e=30
+o.hi.rf.long_ld.g=5
+o.hi.rf.long_ld.he=true
+o.hi.rf.long_ld.ib=lower
+o.hi.rf.long_ld.or=all
+o.hi.rf=double_dd
+o.hi.rf.double_dd.st=3
+o.hi.rf.double_dd.e=39
+o.hi.rf.double_dd.g=7
+o.hi.rf.double_dd.he=true
+o.hi.rf.double_dd.ib=upper
+o.hi.rf.double_dd.ib=outer
+o.hi.rf.double_dd.or=all
+o.hi.rf=date_dtd
+o.hi.rf.date_dtd.st=1007-01-01T23:59:59Z
+o.hi.rf.date_dtd.e=1044-01-01T23:59:59Z
+o.hi.rf.date_dtd.g=+7YEARS
+o.hi.rf.date_dtd.he=true
+o.hi.rf.date_dtd.ib=lower
+o.hi.rf.date_dtd.ib=edge
+o.hi.rf.date_dtd.ib=outer
+o.hi.rf.date_dtd.or=all
+
+o.hf.s.sum=sum(float_fd)
+o.hf.s.mean=mean(float_fd)
+o.hf.s.median=median(float_fd)
+o.hf.s.count=count(float_fd)
+o.hf.s.sumOfSquares=sumofsquares(float_fd)
+o.hf.rf=long_ld
+o.hf.rf.long_ld.st=0
+o.hf.rf.long_ld.e=29
+o.hf.rf.long_ld.g=4
+o.hf.rf.long_ld.he=true
+o.hf.rf.long_ld.ib=all
+o.hf.rf.long_ld.or=all
+o.hf.rf=double_dd
+o.hf.rf.double_dd.st=4
+o.hf.rf.double_dd.e=47
+o.hf.rf.double_dd.g=11
+o.hf.rf.double_dd.he=true
+o.hf.rf.double_dd.ib=edge
+o.hf.rf.double_dd.or=all
+o.hf.rf=date_dtd
+o.hf.rf.date_dtd.st=1004-01-01T23:59:59Z
+o.hf.rf.date_dtd.e=1046-01-01T23:59:59Z
+o.hf.rf.date_dtd.g=+5YEARS
+o.hf.rf.date_dtd.he=true
+o.hf.rf.date_dtd.ib=upper
+o.hf.rf.date_dtd.ib=edge
+o.hf.rf.date_dtd.or=all
+
+o.mi.s.sum=sum(int_id)
+o.mi.s.mean=mean(int_id)
+o.mi.s.median=median(int_id)
+o.mi.s.count=count(int_id)
+o.mi.s.sumOfSquares=sumofsquares(int_id)
+o.mi.rf=long_ld
+o.mi.rf.long_ld.st=5
+o.mi.rf.long_ld.e=30
+o.mi.rf.long_ld.g=4,2,6,3
+o.mi.rf.long_ld.ib=lower
+o.mi.rf.long_ld.or=all
+o.mi.rf=double_dd
+o.mi.rf.double_dd.st=3
+o.mi.rf.double_dd.e=39
+o.mi.rf.double_dd.g=3,1,7
+o.mi.rf.double_dd.ib=upper
+o.mi.rf.double_dd.ib=outer
+o.mi.rf.double_dd.or=all
+o.mi.rf=date_dtd
+o.mi.rf.date_dtd.st=1007-01-01T23:59:59Z
+o.mi.rf.date_dtd.e=1044-01-01T23:59:59Z
+o.mi.rf.date_dtd.g=+2YEARS,+7YEARS
+o.mi.rf.date_dtd.ib=lower
+o.mi.rf.date_dtd.ib=edge
+o.mi.rf.date_dtd.ib=outer
+o.mi.rf.date_dtd.or=all
+
+o.mf.s.sum=sum(float_fd)
+o.mf.s.mean=mean(float_fd)
+o.mf.s.median=median(float_fd)
+o.mf.s.count=count(float_fd)
+o.mf.s.sumOfSquares=sumofsquares(float_fd)
+o.mf.rf=long_ld
+o.mf.rf.long_ld.st=0
+o.mf.rf.long_ld.e=29
+o.mf.rf.long_ld.g=1,4
+o.mf.rf.long_ld.ib=all
+o.mf.rf.long_ld.or=all
+o.mf.rf=double_dd
+o.mf.rf.double_dd.st=4
+o.mf.rf.double_dd.e=47
+o.mf.rf.double_dd.g=2,3,11
+o.mf.rf.double_dd.ib=edge
+o.mf.rf.double_dd.or=all
+o.mf.rf=date_dtd
+o.mf.rf.date_dtd.st=1004-01-01T23:59:59Z
+o.mf.rf.date_dtd.e=1046-01-01T23:59:59Z
+o.mf.rf.date_dtd.g=+4YEARS,+5YEARS
+o.mf.rf.date_dtd.ib=upper
+o.mf.rf.date_dtd.ib=edge
+o.mf.rf.date_dtd.or=all
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test-files/solr/analytics/noFacets.txt
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test-files/solr/analytics/noFacets.txt b/solr/contrib/analytics/src/test-files/solr/analytics/noFacets.txt
deleted file mode 100644
index 84e43eb..0000000
--- a/solr/contrib/analytics/src/test-files/solr/analytics/noFacets.txt
+++ /dev/null
@@ -1,74 +0,0 @@
-o.sr.s.int_id=sum(int_id)
-o.sr.s.long_ld=sum(long_ld)
-o.sr.s.float_fd=sum(float_fd)
-o.sr.s.double_dd=sum(double_dd)
-
-o.sosr.s.int_id=sumofsquares(int_id)
-o.sosr.s.long_ld=sumofsquares(long_ld)
-o.sosr.s.float_fd=sumofsquares(float_fd)
-o.sosr.s.double_dd=sumofsquares(double_dd)
-
-o.mr.s.int_id=mean(int_id)
-o.mr.s.long_ld=mean(long_ld)
-o.mr.s.float_fd=mean(float_fd)
-o.mr.s.double_dd=mean(double_dd)
-
-o.str.s.int_id=stddev(int_id)
-o.str.s.long_ld=stddev(long_ld)
-o.str.s.float_fd=stddev(float_fd)
-o.str.s.double_dd=stddev(double_dd)
-
-o.medr.s.int_id=median(int_id)
-o.medr.s.long_ld=median(long_ld)
-o.medr.s.float_fd=median(float_fd)
-o.medr.s.double_dd=median(double_dd)
-o.medr.s.date_dtd=median(date_dtd)
-
-o.p2r.s.int_id=percentile(20,int_id)
-o.p2r.s.long_ld=percentile(20,long_ld)
-o.p2r.s.float_fd=percentile(20,float_fd)
-o.p2r.s.double_dd=percentile(20,double_dd)
-o.p2r.s.date_dtd=percentile(20,date_dtd)
-o.p2r.s.string_sd=percentile(20,string_sd)
-
-o.p6r.s.int_id=percentile(60,int_id)
-o.p6r.s.long_ld=percentile(60,long_ld)
-o.p6r.s.float_fd=percentile(60,float_fd)
-o.p6r.s.double_dd=percentile(60,double_dd)
-o.p6r.s.date_dtd=percentile(60,date_dtd)
-o.p6r.s.string_sd=percentile(60,string_sd)
-
-o.mir.s.int_id=min(int_id)
-o.mir.s.long_ld=min(long_ld)
-o.mir.s.float_fd=min(float_fd)
-o.mir.s.double_dd=min(double_dd)
-o.mir.s.date_dtd=min(date_dtd)
-o.mir.s.string_sd=min(string_sd)
-
-o.mar.s.int_id=max(int_id)
-o.mar.s.long_ld=max(long_ld)
-o.mar.s.float_fd=max(float_fd)
-o.mar.s.double_dd=max(double_dd)
-o.mar.s.date_dtd=max(date_dtd)
-o.mar.s.string_sd=max(string_sd)
-
-o.cr.s.int_id=count(int_id)
-o.cr.s.long_ld=count(long_ld)
-o.cr.s.float_fd=count(float_fd)
-o.cr.s.double_dd=count(double_dd)
-o.cr.s.date_dtd=count(date_dtd)
-o.cr.s.string_sd=count(string_sd)
-
-o.ur.s.int_id=unique(int_id)
-o.ur.s.long_ld=unique(long_ld)
-o.ur.s.float_fd=unique(float_fd)
-o.ur.s.double_dd=unique(double_dd)
-o.ur.s.date_dtd=unique(date_dtd)
-o.ur.s.string_sd=unique(string_sd)
-
-o.misr.s.int_id=missing(int_id)
-o.misr.s.long_ld=missing(long_ld)
-o.misr.s.float_fd=missing(float_fd)
-o.misr.s.double_dd=missing(double_dd)
-o.misr.s.date_dtd=missing(date_dtd)
-o.misr.s.string_sd=missing(string_sd)
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test-files/solr/analytics/queryFacets.txt
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test-files/solr/analytics/queryFacets.txt b/solr/contrib/analytics/src/test-files/solr/analytics/queryFacets.txt
deleted file mode 100644
index 84d8fc6..0000000
--- a/solr/contrib/analytics/src/test-files/solr/analytics/queryFacets.txt
+++ /dev/null
@@ -1,27 +0,0 @@
-o.ir.s.sum=sum(int_id)
-o.ir.s.mean=mean(int_id)
-o.ir.s.median=median(int_id)
-o.ir.s.percentile_8=percentile(8,int_id)
-o.ir.ff=string_sd
-o.ir.ff.string_sd.h=true
-o.ir.qf=float1
-o.ir.qf.float1.q=float_fd:[* TO 50]
-o.ir.qf=float2
-o.ir.qf.float2.q=float_fd:[* TO 30]
-
-o.lr.s.sum=sum(long_ld)
-o.lr.s.mean=mean(long_ld)
-o.lr.s.median=median(long_ld)
-o.lr.s.percentile_8=percentile(8,long_ld)
-o.lr.qf=string
-o.lr.qf.string.q=string_sd:abc1
-o.lr.qf.string.q=string_sd:abc2
-
-o.fr.s.sum=sum(float_fd)
-o.fr.s.mean=mean(float_fd)
-o.fr.s.median=median(float_fd)
-o.fr.s.percentile_8=percentile(8,float_fd)
-o.fr.qf=lad
-o.fr.qf.lad.q=long_ld:[20 TO *]
-o.fr.qf.lad.q=long_ld:[30 TO *]
-o.fr.qf.lad.q=double_dd:[* TO 50]
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test-files/solr/analytics/rangeFacets.txt
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test-files/solr/analytics/rangeFacets.txt b/solr/contrib/analytics/src/test-files/solr/analytics/rangeFacets.txt
deleted file mode 100644
index 29aae5d..0000000
--- a/solr/contrib/analytics/src/test-files/solr/analytics/rangeFacets.txt
+++ /dev/null
@@ -1,161 +0,0 @@
-o.ri.s.sum=sum(int_id)
-o.ri.s.mean=mean(int_id)
-o.ri.s.median=median(int_id)
-o.ri.s.count=count(int_id)
-o.ri.s.sumOfSquares=sumofsquares(int_id)
-o.ri.rf=long_ld
-o.ri.rf.long_ld.st=5
-o.ri.rf.long_ld.e=30
-o.ri.rf.long_ld.g=5
-o.ri.rf.long_ld.ib=lower
-o.ri.rf.long_ld.or=all
-o.ri.rf=double_dd
-o.ri.rf.double_dd.st=3
-o.ri.rf.double_dd.e=39
-o.ri.rf.double_dd.g=7
-o.ri.rf.double_dd.ib=upper
-o.ri.rf.double_dd.ib=outer
-o.ri.rf.double_dd.or=all
-o.ri.rf=date_dtd
-o.ri.rf.date_dtd.st=1007-01-01T23:59:59Z
-o.ri.rf.date_dtd.e=1044-01-01T23:59:59Z
-o.ri.rf.date_dtd.g=+7YEARS
-o.ri.rf.date_dtd.ib=lower
-o.ri.rf.date_dtd.ib=edge
-o.ri.rf.date_dtd.ib=outer
-o.ri.rf.date_dtd.or=all
-
-o.rf.s.sum=sum(float_fd)
-o.rf.s.mean=mean(float_fd)
-o.rf.s.median=median(float_fd)
-o.rf.s.count=count(float_fd)
-o.rf.s.sumOfSquares=sumofsquares(float_fd)
-o.rf.rf=long_ld
-o.rf.rf.long_ld.st=0
-o.rf.rf.long_ld.e=29
-o.rf.rf.long_ld.g=4
-o.rf.rf.long_ld.ib=all
-o.rf.rf.long_ld.or=all
-o.rf.rf=double_dd
-o.rf.rf.double_dd.st=4
-o.rf.rf.double_dd.e=47
-o.rf.rf.double_dd.g=11
-o.rf.rf.double_dd.ib=edge
-o.rf.rf.double_dd.or=all
-o.rf.rf=date_dtd
-o.rf.rf.date_dtd.st=1004-01-01T23:59:59Z
-o.rf.rf.date_dtd.e=1046-01-01T23:59:59Z
-o.rf.rf.date_dtd.g=+5YEARS
-o.rf.rf.date_dtd.ib=upper
-o.rf.rf.date_dtd.ib=edge
-o.rf.rf.date_dtd.or=all
-
-o.hi.s.sum=sum(int_id)
-o.hi.s.mean=mean(int_id)
-o.hi.s.median=median(int_id)
-o.hi.s.count=count(int_id)
-o.hi.s.sumOfSquares=sumofsquares(int_id)
-o.hi.rf=long_ld
-o.hi.rf.long_ld.st=5
-o.hi.rf.long_ld.e=30
-o.hi.rf.long_ld.g=5
-o.hi.rf.long_ld.he=true
-o.hi.rf.long_ld.ib=lower
-o.hi.rf.long_ld.or=all
-o.hi.rf=double_dd
-o.hi.rf.double_dd.st=3
-o.hi.rf.double_dd.e=39
-o.hi.rf.double_dd.g=7
-o.hi.rf.double_dd.he=true
-o.hi.rf.double_dd.ib=upper
-o.hi.rf.double_dd.ib=outer
-o.hi.rf.double_dd.or=all
-o.hi.rf=date_dtd
-o.hi.rf.date_dtd.st=1007-01-01T23:59:59Z
-o.hi.rf.date_dtd.e=1044-01-01T23:59:59Z
-o.hi.rf.date_dtd.g=+7YEARS
-o.hi.rf.date_dtd.he=true
-o.hi.rf.date_dtd.ib=lower
-o.hi.rf.date_dtd.ib=edge
-o.hi.rf.date_dtd.ib=outer
-o.hi.rf.date_dtd.or=all
-
-o.hf.s.sum=sum(float_fd)
-o.hf.s.mean=mean(float_fd)
-o.hf.s.median=median(float_fd)
-o.hf.s.count=count(float_fd)
-o.hf.s.sumOfSquares=sumofsquares(float_fd)
-o.hf.rf=long_ld
-o.hf.rf.long_ld.st=0
-o.hf.rf.long_ld.e=29
-o.hf.rf.long_ld.g=4
-o.hf.rf.long_ld.he=true
-o.hf.rf.long_ld.ib=all
-o.hf.rf.long_ld.or=all
-o.hf.rf=double_dd
-o.hf.rf.double_dd.st=4
-o.hf.rf.double_dd.e=47
-o.hf.rf.double_dd.g=11
-o.hf.rf.double_dd.he=true
-o.hf.rf.double_dd.ib=edge
-o.hf.rf.double_dd.or=all
-o.hf.rf=date_dtd
-o.hf.rf.date_dtd.st=1004-01-01T23:59:59Z
-o.hf.rf.date_dtd.e=1046-01-01T23:59:59Z
-o.hf.rf.date_dtd.g=+5YEARS
-o.hf.rf.date_dtd.he=true
-o.hf.rf.date_dtd.ib=upper
-o.hf.rf.date_dtd.ib=edge
-o.hf.rf.date_dtd.or=all
-
-o.mi.s.sum=sum(int_id)
-o.mi.s.mean=mean(int_id)
-o.mi.s.median=median(int_id)
-o.mi.s.count=count(int_id)
-o.mi.s.sumOfSquares=sumofsquares(int_id)
-o.mi.rf=long_ld
-o.mi.rf.long_ld.st=5
-o.mi.rf.long_ld.e=30
-o.mi.rf.long_ld.g=4,2,6,3
-o.mi.rf.long_ld.ib=lower
-o.mi.rf.long_ld.or=all
-o.mi.rf=double_dd
-o.mi.rf.double_dd.st=3
-o.mi.rf.double_dd.e=39
-o.mi.rf.double_dd.g=3,1,7
-o.mi.rf.double_dd.ib=upper
-o.mi.rf.double_dd.ib=outer
-o.mi.rf.double_dd.or=all
-o.mi.rf=date_dtd
-o.mi.rf.date_dtd.st=1007-01-01T23:59:59Z
-o.mi.rf.date_dtd.e=1044-01-01T23:59:59Z
-o.mi.rf.date_dtd.g=+2YEARS,+7YEARS
-o.mi.rf.date_dtd.ib=lower
-o.mi.rf.date_dtd.ib=edge
-o.mi.rf.date_dtd.ib=outer
-o.mi.rf.date_dtd.or=all
-
-o.mf.s.sum=sum(float_fd)
-o.mf.s.mean=mean(float_fd)
-o.mf.s.median=median(float_fd)
-o.mf.s.count=count(float_fd)
-o.mf.s.sumOfSquares=sumofsquares(float_fd)
-o.mf.rf=long_ld
-o.mf.rf.long_ld.st=0
-o.mf.rf.long_ld.e=29
-o.mf.rf.long_ld.g=1,4
-o.mf.rf.long_ld.ib=all
-o.mf.rf.long_ld.or=all
-o.mf.rf=double_dd
-o.mf.rf.double_dd.st=4
-o.mf.rf.double_dd.e=47
-o.mf.rf.double_dd.g=2,3,11
-o.mf.rf.double_dd.ib=edge
-o.mf.rf.double_dd.or=all
-o.mf.rf=date_dtd
-o.mf.rf.date_dtd.st=1004-01-01T23:59:59Z
-o.mf.rf.date_dtd.e=1046-01-01T23:59:59Z
-o.mf.rf.date_dtd.g=+4YEARS,+5YEARS
-o.mf.rf.date_dtd.ib=upper
-o.mf.rf.date_dtd.ib=edge
-o.mf.rf.date_dtd.or=all
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test-files/solr/collection1/conf/schema-analytics.xml
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test-files/solr/collection1/conf/schema-analytics.xml b/solr/contrib/analytics/src/test-files/solr/collection1/conf/schema-analytics.xml
index 527e66a..6570416 100644
--- a/solr/contrib/analytics/src/test-files/solr/collection1/conf/schema-analytics.xml
+++ b/solr/contrib/analytics/src/test-files/solr/collection1/conf/schema-analytics.xml
@@ -25,7 +25,7 @@
-->
-<schema name="schema-analytics" version="1.0">
+<schema name="schema-analytics" version="1.6">
<!-- field type definitions... note that the "name" attribute is
@@ -39,50 +39,89 @@
These are provided more for backward compatability, allowing one
to create a schema that matches an existing lucene index.
-->
- <fieldType name="int" class="${solr.tests.IntegerFieldType}" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>
- <fieldType name="float" class="${solr.tests.FloatFieldType}" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>
- <fieldType name="long" class="${solr.tests.LongFieldType}" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>
- <fieldType name="double" class="${solr.tests.DoubleFieldType}" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>
+ <fieldType name="int" class="${solr.tests.IntegerFieldType}" docValues="true" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>
+ <fieldType name="float" class="${solr.tests.FloatFieldType}" docValues="true" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>
+ <fieldType name="long" class="${solr.tests.LongFieldType}" docValues="true" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>
+ <fieldType name="double" class="${solr.tests.DoubleFieldType}" docValues="true" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>
<!-- format for date is 1995-12-31T23:59:59.999Z and only the fractional
seconds part (.999) is optional.
-->
- <fieldType name="date" class="${solr.tests.DateFieldType}" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>
-
- <fieldType name="boolean" class="solr.BoolField"/>
- <fieldType name="string" class="solr.StrField"/>
-
- <fieldType name="uuid" class="solr.UUIDField"/>
-
-
- <field name="id" type="string" docValues="true" multiValued="false" required="true"/>
-
- <field name="floatdv" type="float" indexed="false" stored="false" docValues="true" default="1"/>
- <field name="intdv" type="int" indexed="false" stored="false" docValues="true" default="2"/>
- <field name="doubledv" type="double" indexed="false" stored="false" docValues="true" default="3"/>
- <field name="longdv" type="long" indexed="false" stored="false" docValues="true" default="4"/>
- <field name="datedv" type="date" indexed="false" stored="false" docValues="true" default="1995-12-31T23:59:59.999Z"/>
-
- <field name="stringdv" type="string" indexed="false" stored="false" docValues="true" default="solr"/>
- <field name="stringdvm" type="string" indexed="false" stored="false" docValues="true" default="solr" multiValued="true"/>
-
- <dynamicField name="*_i" type="int" indexed="true" stored="true" docValues="false" multiValued="false"/>
- <dynamicField name="*_id" type="int" indexed="true" stored="true" docValues="true" multiValued="false"/>
- <dynamicField name="*_idm" type="int" indexed="true" stored="true" docValues="true" multiValued="true"/>
- <dynamicField name="*_l" type="long" indexed="true" stored="true" docValues="false" multiValued="false"/>
- <dynamicField name="*_ld" type="long" indexed="true" stored="true" docValues="true" multiValued="false"/>
- <dynamicField name="*_ldm" type="long" indexed="true" stored="true" docValues="true" multiValued="true"/>
- <dynamicField name="*_f" type="float" indexed="true" stored="true" docValues="false" multiValued="false"/>
- <dynamicField name="*_fd" type="float" indexed="true" stored="true" docValues="true" multiValued="false"/>
- <dynamicField name="*_fdm" type="float" indexed="true" stored="true" docValues="true" multiValued="true"/>
- <dynamicField name="*_d" type="double" indexed="true" stored="true" docValues="false" multiValued="false"/>
- <dynamicField name="*_dd" type="double" indexed="true" stored="true" docValues="true" multiValued="false"/>
- <dynamicField name="*_ddm" type="double" indexed="true" stored="true" docValues="true" multiValued="true"/>
- <dynamicField name="*_dt" type="date" indexed="true" stored="true" docValues="false" multiValued="false"/>
- <dynamicField name="*_dtd" type="date" indexed="true" stored="true" docValues="true" multiValued="false"/>
- <dynamicField name="*_dtdm" type="date" indexed="true" stored="true" docValues="true" multiValued="true"/>
- <dynamicField name="*_s" type="string" indexed="true" stored="true" docValues="false" multiValued="false"/>
- <dynamicField name="*_sd" type="string" indexed="true" stored="true" docValues="true" multiValued="false"/>
- <dynamicField name="*_sdm" type="string" indexed="true" stored="true" docValues="true" multiValued="true"/>
+ <fieldType name="date" class="${solr.tests.DateFieldType}" docValues="true" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>
+
+ <!-- Numeric Trie Fields -->
+ <fieldType name="int_trie" class="solr.TrieIntField" docValues="true" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>
+ <fieldType name="float_trie" class="solr.TrieFloatField" docValues="true" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>
+ <fieldType name="long_trie" class="solr.TrieLongField" docValues="true" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>
+ <fieldType name="double_trie" class="solr.TrieDoubleField" docValues="true" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>
+ <fieldType name="date_trie" class="solr.TrieDateField" docValues="true" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>
+
+ <!-- Numeric Trie Fields -->
+ <fieldType name="int_pnt" class="solr.IntPointField" docValues="true" />
+ <fieldType name="float_pnt" class="solr.FloatPointField" docValues="true" />
+ <fieldType name="long_pnt" class="solr.LongPointField" docValues="true" />
+ <fieldType name="double_pnt" class="solr.DoublePointField" docValues="true" />
+ <fieldType name="date_pnt" class="solr.DatePointField" docValues="true" />
+
+ <fieldType name="boolean" class="solr.BoolField" docValues="true"/>
+ <fieldType name="string" class="solr.StrField" docValues="true"/>
+
+
+ <field name="id" type="string" multiValued="false" required="true"/>
+
+ <dynamicField name="*_b" type="boolean" indexed="true" stored="true" multiValued="false"/>
+ <dynamicField name="*_bm" type="boolean" indexed="true" stored="true" multiValued="true"/>
+ <dynamicField name="*_bd" type="boolean" indexed="true" stored="true" multiValued="false"/>
+ <dynamicField name="*_bdm" type="boolean" indexed="true" stored="true" multiValued="true"/>
+
+ <dynamicField name="*_i" type="int" indexed="true" stored="true" multiValued="false"/>
+ <dynamicField name="*_im" type="int" indexed="true" stored="true" multiValued="true"/>
+ <dynamicField name="*_i_t" type="int_trie" indexed="true" stored="true" multiValued="false"/>
+ <dynamicField name="*_im_t" type="int_trie" indexed="true" stored="true" multiValued="true"/>
+ <dynamicField name="*_i_p" type="int_pnt" indexed="true" stored="true" multiValued="false"/>
+ <dynamicField name="*_im_p" type="int_pnt" indexed="true" stored="true" multiValued="true"/>
+ <dynamicField name="*_id" type="int" indexed="true" stored="true" multiValued="false"/>
+ <dynamicField name="*_idm" type="int" indexed="true" stored="true" multiValued="true"/>
+
+ <dynamicField name="*_l" type="long" indexed="true" stored="true" multiValued="false"/>
+ <dynamicField name="*_lm" type="long" indexed="true" stored="true" multiValued="true"/>
+ <dynamicField name="*_l_t" type="long_trie" indexed="true" stored="true" multiValued="false"/>
+ <dynamicField name="*_lm_t" type="long_trie" indexed="true" stored="true" multiValued="true"/>
+ <dynamicField name="*_l_p" type="long_pnt" indexed="true" stored="true" multiValued="false"/>
+ <dynamicField name="*_lm_p" type="long_pnt" indexed="true" stored="true" multiValued="true"/>
+ <dynamicField name="*_ld" type="long" indexed="true" stored="true" multiValued="false"/>
+ <dynamicField name="*_ldm" type="long" indexed="true" stored="true" multiValued="true"/>
+
+ <dynamicField name="*_f" type="float" indexed="true" stored="true" multiValued="false"/>
+ <dynamicField name="*_fm" type="float" indexed="true" stored="true" multiValued="true"/>
+ <dynamicField name="*_f_t" type="float_trie" indexed="true" stored="true" multiValued="false"/>
+ <dynamicField name="*_fm_t" type="float_trie" indexed="true" stored="true" multiValued="true"/>
+ <dynamicField name="*_f_p" type="float_pnt" indexed="true" stored="true" multiValued="false"/>
+ <dynamicField name="*_fm_p" type="float_pnt" indexed="true" stored="true" multiValued="true"/>
+ <dynamicField name="*_fd" type="float" indexed="true" stored="true" multiValued="false"/>
+ <dynamicField name="*_fdm" type="float" indexed="true" stored="true" multiValued="true"/>
+
+ <dynamicField name="*_d" type="double" indexed="true" stored="true" multiValued="false"/>
+ <dynamicField name="*_dm" type="double" indexed="true" stored="true" multiValued="true"/>
+ <dynamicField name="*_d_t" type="double_trie" indexed="true" stored="true" multiValued="false"/>
+ <dynamicField name="*_dm_t" type="double_trie" indexed="true" stored="true" multiValued="true"/>
+ <dynamicField name="*_d_p" type="double_pnt" indexed="true" stored="true" multiValued="false"/>
+ <dynamicField name="*_dm_p" type="double_pnt" indexed="true" stored="true" multiValued="true"/>
+ <dynamicField name="*_dd" type="double" indexed="true" stored="true" multiValued="false"/>
+ <dynamicField name="*_ddm" type="double" indexed="true" stored="true" multiValued="true"/>
+
+ <dynamicField name="*_dt" type="date" indexed="true" stored="true" multiValued="false"/>
+ <dynamicField name="*_dtm" type="date" indexed="true" stored="true" multiValued="true"/>
+ <dynamicField name="*_dt_t" type="date_trie" indexed="true" stored="true" multiValued="false"/>
+ <dynamicField name="*_dtm_t" type="date_trie" indexed="true" stored="true" multiValued="true"/>
+ <dynamicField name="*_dt_p" type="date_pnt" indexed="true" stored="true" multiValued="false"/>
+ <dynamicField name="*_dtm_p" type="date_pnt" indexed="true" stored="true" multiValued="true"/>
+ <dynamicField name="*_dtd" type="date" indexed="true" stored="true" multiValued="false"/>
+ <dynamicField name="*_dtdm" type="date" indexed="true" stored="true" multiValued="true"/>
+
+ <dynamicField name="*_s" type="string" indexed="true" stored="true" multiValued="false"/>
+ <dynamicField name="*_sm" type="string" indexed="true" stored="true" multiValued="true"/>
+ <dynamicField name="*_sd" type="string" indexed="true" stored="true" multiValued="false"/>
+ <dynamicField name="*_sdm" type="string" indexed="true" stored="true" multiValued="true"/>
<uniqueKey>id</uniqueKey>
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test-files/solr/configsets/cloud-analytics/conf/schema.xml
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test-files/solr/configsets/cloud-analytics/conf/schema.xml b/solr/contrib/analytics/src/test-files/solr/configsets/cloud-analytics/conf/schema.xml
index 0fac17f..cb9ad13 100644
--- a/solr/contrib/analytics/src/test-files/solr/configsets/cloud-analytics/conf/schema.xml
+++ b/solr/contrib/analytics/src/test-files/solr/configsets/cloud-analytics/conf/schema.xml
@@ -16,18 +16,18 @@
limitations under the License.
-->
-<!-- The Solr schema file for cloud analytics, version 1.0 -->
+<!-- The Solr schema file for cloud analytics, version 1.6 -->
-<schema name="cloud-analytics" version="1.0">
+<schema name="cloud-analytics" version="1.6">
- <fieldType name="boolean" class="solr.BoolField" sortMissingLast="true"/>
- <fieldType name="string" class="solr.StrField" sortMissingLast="true"/>
+ <fieldType name="boolean" class="solr.BoolField" docValues="true" sortMissingLast="true"/>
+ <fieldType name="string" class="solr.StrField" docValues="true" sortMissingLast="true"/>
- <fieldType name="int" class="${solr.tests.IntegerFieldType}" precisionStep="0" omitNorms="true" positionIncrementGap="0" />
- <fieldType name="float" class="${solr.tests.FloatFieldType}" precisionStep="0" omitNorms="true" positionIncrementGap="0" />
- <fieldType name="long" class="${solr.tests.LongFieldType}" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>
- <fieldType name="double" class="${solr.tests.DoubleFieldType}" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>
- <fieldType name="date" class="${solr.tests.DateFieldType}" precisionStep="0" omitNorms="true" positionIncrementGap="0" />
+ <fieldType name="int" class="${solr.tests.IntegerFieldType}" docValues="true" precisionStep="0" omitNorms="true" positionIncrementGap="0" />
+ <fieldType name="float" class="${solr.tests.FloatFieldType}" docValues="true" precisionStep="0" omitNorms="true" positionIncrementGap="0" />
+ <fieldType name="long" class="${solr.tests.LongFieldType}" docValues="true" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>
+ <fieldType name="double" class="${solr.tests.DoubleFieldType}" docValues="true" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>
+ <fieldType name="date" class="${solr.tests.DateFieldType}" docValues="true" precisionStep="0" omitNorms="true" positionIncrementGap="0" />
<field name="id" type="string" indexed="true" stored="true" multiValued="false" required="true"/>
@@ -39,20 +39,40 @@
<field name="_route_" type="string" indexed="true" stored="true" multiValued="false"/>
<!-- dynamic fields with doc-values (for analytics) -->
- <dynamicField name="*_id" type="int" docValues="true" indexed="true" stored="true"/>
- <dynamicField name="*_idm" type="int" docValues="true" indexed="true" stored="true" multiValued="true"/>
- <dynamicField name="*_sd" type="string" docValues="true" indexed="true" stored="true" />
- <dynamicField name="*_sdm" type="string" docValues="true" indexed="true" stored="true" multiValued="true"/>
- <dynamicField name="*_ld" type="long" docValues="true" indexed="true" stored="true"/>
- <dynamicField name="*_ldm" type="long" docValues="true" indexed="true" stored="true" multiValued="true"/>
- <dynamicField name="*_bd" type="boolean" docValues="true" indexed="true" stored="true"/>
- <dynamicField name="*_bdm" type="boolean" docValues="true" indexed="true" stored="true" multiValued="true"/>
- <dynamicField name="*_fd" type="float" docValues="true" indexed="true" stored="true"/>
- <dynamicField name="*_fdm" type="float" docValues="true" indexed="true" stored="true" multiValued="true"/>
- <dynamicField name="*_dd" type="double" docValues="true" indexed="true" stored="true"/>
- <dynamicField name="*_ddm" type="double" docValues="true" indexed="true" stored="true" multiValued="true"/>
- <dynamicField name="*_dtd" type="date" docValues="true" indexed="true" stored="true"/>
- <dynamicField name="*_dtdm" type="date" docValues="true" indexed="true" stored="true" multiValued="true"/>
+ <dynamicField name="*_i" type="int" indexed="true" stored="true"/>
+ <dynamicField name="*_im" type="int" indexed="true" stored="true" multiValued="true"/>
+ <dynamicField name="*_id" type="int" indexed="true" stored="true"/>
+ <dynamicField name="*_idm" type="int" indexed="true" stored="true" multiValued="true"/>
+
+ <dynamicField name="*_s" type="string" indexed="true" stored="true" />
+ <dynamicField name="*_sm" type="string" indexed="true" stored="true" multiValued="true"/>
+ <dynamicField name="*_sd" type="string" indexed="true" stored="true" />
+ <dynamicField name="*_sdm" type="string" indexed="true" stored="true" multiValued="true"/>
+
+ <dynamicField name="*_l" type="long" indexed="true" stored="true"/>
+ <dynamicField name="*_lm" type="long" indexed="true" stored="true" multiValued="true"/>
+ <dynamicField name="*_ld" type="long" indexed="true" stored="true"/>
+ <dynamicField name="*_ldm" type="long" indexed="true" stored="true" multiValued="true"/>
+
+ <dynamicField name="*_b" type="boolean" indexed="true" stored="true"/>
+ <dynamicField name="*_bm" type="boolean" indexed="true" stored="true" multiValued="true"/>
+ <dynamicField name="*_bd" type="boolean" indexed="true" stored="true"/>
+ <dynamicField name="*_bdm" type="boolean" indexed="true" stored="true" multiValued="true"/>
+
+ <dynamicField name="*_f" type="float" indexed="true" stored="true"/>
+ <dynamicField name="*_fm" type="float" indexed="true" stored="true" multiValued="true"/>
+ <dynamicField name="*_fd" type="float" indexed="true" stored="true"/>
+ <dynamicField name="*_fdm" type="float" indexed="true" stored="true" multiValued="true"/>
+
+ <dynamicField name="*_d" type="double" indexed="true" stored="true"/>
+ <dynamicField name="*_dm" type="double" indexed="true" stored="true" multiValued="true"/>
+ <dynamicField name="*_dd" type="double" indexed="true" stored="true"/>
+ <dynamicField name="*_ddm" type="double" indexed="true" stored="true" multiValued="true"/>
+
+ <dynamicField name="*_dt" type="date" indexed="true" stored="true"/>
+ <dynamicField name="*_dtm" type="date" indexed="true" stored="true" multiValued="true"/>
+ <dynamicField name="*_dtd" type="date" indexed="true" stored="true"/>
+ <dynamicField name="*_dtdm" type="date" indexed="true" stored="true" multiValued="true"/>
<uniqueKey>id</uniqueKey>
</schema>
[03/20] lucene-solr:master: SOLR-11145,
SOLR-11146: Added comprehensive unit tests for Analytics Component
2.0 as well as analytics bug fixes.
Posted by dp...@apache.org.
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyFieldFacetTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyFieldFacetTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyFieldFacetTest.java
new file mode 100644
index 0000000..92eb7ed
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyFieldFacetTest.java
@@ -0,0 +1,1065 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.legacy.facet;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.w3c.dom.Node;
+
+
+public class LegacyFieldFacetTest extends LegacyAbstractAnalyticsFacetTest{
+ static String fileName = "fieldFacets.txt";
+
+ public static final int INT = 71;
+ public static final int LONG = 36;
+ public static final int LONGM = 50;
+ public static final int FLOAT = 73;
+ public static final int FLOATM = 84;
+ public static final int DOUBLE = 49;
+ public static final int DATE = 12;
+ public static final int DATEM = 30;
+ public static final int STRING = 28;
+ public static final int STRINGM = 40;
+ public static final int NUM_LOOPS = 100;
+
+ //INT
+ private static ArrayList<ArrayList<Integer>> intDateTestStart;
+ private static ArrayList<Long> intDateTestMissing;
+ private static ArrayList<ArrayList<Integer>> intStringTestStart;
+ private static ArrayList<Long> intStringTestMissing;
+
+ //LONG
+ private static ArrayList<ArrayList<Long>> longDateTestStart;
+ private static ArrayList<Long> longDateTestMissing;
+ private static ArrayList<ArrayList<Long>> longStringTestStart;
+ private static ArrayList<Long> longStringTestMissing;
+
+ //FLOAT
+ private static ArrayList<ArrayList<Float>> floatDateTestStart;
+ private static ArrayList<Long> floatDateTestMissing;
+ private static ArrayList<ArrayList<Float>> floatStringTestStart;
+ private static ArrayList<Long> floatStringTestMissing;
+
+ //DOUBLE
+ private static ArrayList<ArrayList<Double>> doubleDateTestStart;
+ private static ArrayList<Long> doubleDateTestMissing;
+ private static ArrayList<ArrayList<Double>> doubleStringTestStart;
+ private static ArrayList<Long> doubleStringTestMissing;
+
+ //DATE
+ private static ArrayList<ArrayList<String>> dateIntTestStart;
+ private static ArrayList<Long> dateIntTestMissing;
+ private static ArrayList<ArrayList<String>> dateLongTestStart;
+ private static ArrayList<Long> dateLongTestMissing;
+
+ //String
+ private static ArrayList<ArrayList<String>> stringIntTestStart;
+ private static ArrayList<Long> stringIntTestMissing;
+ private static ArrayList<ArrayList<String>> stringLongTestStart;
+ private static ArrayList<Long> stringLongTestMissing;
+
+ //Multi-Valued
+ private static ArrayList<ArrayList<Integer>> multiLongTestStart;
+ private static ArrayList<Long> multiLongTestMissing;
+ private static ArrayList<ArrayList<Integer>> multiStringTestStart;
+ private static ArrayList<Long> multiStringTestMissing;
+ private static ArrayList<ArrayList<Integer>> multiDateTestStart;
+ private static ArrayList<Long> multiDateTestMissing;
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ initCore("solrconfig-analytics.xml","schema-analytics.xml");
+ h.update("<delete><query>*:*</query></delete>");
+
+ defaults.put("int", new Integer(0));
+ defaults.put("long", new Long(0));
+ defaults.put("float", new Float(0));
+ defaults.put("double", new Double(0));
+ defaults.put("date", "1800-12-31T23:59:59Z");
+ defaults.put("string", "str0");
+
+ //INT
+ intDateTestStart = new ArrayList<>();
+ intDateTestMissing = new ArrayList<>();
+ intStringTestStart = new ArrayList<>();
+ intStringTestMissing = new ArrayList<>();
+
+ //LONG
+ longDateTestStart = new ArrayList<>();
+ longDateTestMissing = new ArrayList<>();
+ longStringTestStart = new ArrayList<>();
+ longStringTestMissing = new ArrayList<>();
+
+ //FLOAT
+ floatDateTestStart = new ArrayList<>();
+ floatDateTestMissing = new ArrayList<>();
+ floatStringTestStart = new ArrayList<>();
+ floatStringTestMissing = new ArrayList<>();
+
+ //DOUBLE
+ doubleDateTestStart = new ArrayList<>();
+ doubleDateTestMissing = new ArrayList<>();
+ doubleStringTestStart = new ArrayList<>();
+ doubleStringTestMissing = new ArrayList<>();
+
+ //DATE
+ dateIntTestStart = new ArrayList<>();
+ dateIntTestMissing = new ArrayList<>();
+ dateLongTestStart = new ArrayList<>();
+ dateLongTestMissing = new ArrayList<>();
+
+ //String
+ stringIntTestStart = new ArrayList<>();
+ stringIntTestMissing = new ArrayList<>();
+ stringLongTestStart = new ArrayList<>();
+ stringLongTestMissing = new ArrayList<>();
+
+ //Multi-Valued
+ multiLongTestStart = new ArrayList<>();
+ multiLongTestMissing = new ArrayList<>();
+ multiStringTestStart = new ArrayList<>();
+ multiStringTestMissing = new ArrayList<>();
+ multiDateTestStart = new ArrayList<>();
+ multiDateTestMissing = new ArrayList<>();
+
+ boolean multiCanHaveDuplicates = Boolean.getBoolean(NUMERIC_POINTS_SYSPROP);
+
+ for (int j = 0; j < NUM_LOOPS; ++j) {
+ int i = j%INT;
+ long l = j%LONG;
+ long lm = j%LONGM;
+ float f = j%FLOAT;
+ double d = j%DOUBLE;
+ int dt = j%DATE;
+ int dtm = j%DATEM;
+ int s = j%STRING;
+ int sm = j%STRINGM;
+
+
+ List<String> fields = new ArrayList<>();
+ fields.add("id"); fields.add("1000"+j);
+
+ if( i != 0 ) {
+ fields.add("int_id"); fields.add("" + i);
+ }
+ if( l != 0l ) {
+ fields.add("long_ld"); fields.add("" + l);
+ fields.add("long_ldm"); fields.add("" + l);
+ }
+ if( lm != 0l ) {
+ fields.add("long_ldm"); fields.add("" + lm);
+ }
+ if( f != 0.0f ) {
+ fields.add("float_fd"); fields.add("" + f);
+ }
+ if( d != 0.0d ) {
+ fields.add("double_dd"); fields.add("" + d);
+ }
+ if( dt != 0 ) {
+ fields.add("date_dtd"); fields.add((1800+dt) + "-12-31T23:59:59Z");
+ fields.add("date_dtdm"); fields.add((1800+dt) + "-12-31T23:59:59Z");
+ }
+ if ( dtm != 0 ) {
+ fields.add("date_dtdm"); fields.add((1800+dtm) + "-12-31T23:59:59Z");
+ }
+ if ( s != 0 ) {
+ fields.add("string_sd"); fields.add("str" + s);
+ fields.add("string_sdm"); fields.add("str" + s);
+ }
+ if ( sm != 0 ) {
+ fields.add("string_sdm"); fields.add("str" + sm);
+ }
+ assertU(adoc(fields.toArray(new String[0])));
+
+ if( dt != 0 ) {
+ //Dates
+ if ( j-DATE < 0 ) {
+ ArrayList<Integer> list1 = new ArrayList<>();
+ if( i != 0 ) {
+ list1.add(i);
+ intDateTestMissing.add(0l);
+ } else {
+ intDateTestMissing.add(1l);
+ }
+ intDateTestStart.add(list1);
+ ArrayList<Long> list2 = new ArrayList<>();
+ if( l != 0l ) {
+ list2.add(l);
+ longDateTestMissing.add(0l);
+ } else {
+ longDateTestMissing.add(1l);
+ }
+ longDateTestStart.add(list2);
+ ArrayList<Float> list3 = new ArrayList<>();
+ if ( f != 0.0f ) {
+ list3.add(f);
+ floatDateTestMissing.add(0l);
+ } else {
+ floatDateTestMissing.add(1l);
+
+ }
+ floatDateTestStart.add(list3);
+ ArrayList<Double> list4 = new ArrayList<>();
+ if( d != 0.0d ) {
+ list4.add(d);
+ doubleDateTestMissing.add(0l);
+ } else {
+ doubleDateTestMissing.add(1l);
+ }
+ doubleDateTestStart.add(list4);
+ ArrayList<Integer> list5 = new ArrayList<>();
+ if( i != 0 ) {
+ list5.add(i);
+ multiDateTestMissing.add(0l);
+ } else {
+ multiDateTestMissing.add(1l);
+
+ }
+ multiDateTestStart.add(list5);
+ } else {
+ if( i != 0 ) intDateTestStart.get(dt-1).add(i); else increment(intDateTestMissing,dt-1);
+ if( l != 0l ) longDateTestStart.get(dt-1).add(l); else increment(longDateTestMissing,dt-1);
+ if( f != 0.0f ) floatDateTestStart.get(dt-1).add(f); else increment(floatDateTestMissing,dt-1);
+ if( d != 0.0d ) doubleDateTestStart.get(dt-1).add(d); else increment(doubleDateTestMissing,dt-1);
+ if( i != 0 ) multiDateTestStart.get(dt-1).add(i); else increment(multiDateTestMissing,dt-1);
+ }
+ }
+
+ if ( dtm != 0 ) {
+ if ( j-DATEM < 0 && dtm != dt ) {
+ ArrayList<Integer> list1 = new ArrayList<>();
+ if( i != 0 ) {
+ list1.add(i);
+ multiDateTestMissing.add(0l);
+ } else {
+ multiDateTestMissing.add(1l);
+ }
+ multiDateTestStart.add(list1);
+ } else if ( dtm != dt || multiCanHaveDuplicates ) {
+ if( i != 0 ) multiDateTestStart.get(dtm-1).add(i); else increment(multiDateTestMissing,dtm-1);
+ }
+ }
+
+ if( s != 0 ){
+ //Strings
+ if ( j-STRING < 0 ) {
+ ArrayList<Integer> list1 = new ArrayList<>();
+ if( i != 0 ) {
+ list1.add(i);
+ intStringTestMissing.add(0l);
+ } else {
+ intStringTestMissing.add(1l);
+ }
+ intStringTestStart.add(list1);
+ ArrayList<Long> list2 = new ArrayList<>();
+ if( l != 0l ) {
+ list2.add(l);
+ longStringTestMissing.add(0l);
+ } else {
+ longStringTestMissing.add(1l);
+ }
+ longStringTestStart.add(list2);
+ ArrayList<Float> list3 = new ArrayList<>();
+ if( f != 0.0f ){
+ list3.add(f);
+ floatStringTestMissing.add(0l);
+ } else {
+ floatStringTestMissing.add(1l);
+ }
+ floatStringTestStart.add(list3);
+ ArrayList<Double> list4 = new ArrayList<>();
+ if( d != 0.0d ) {
+ list4.add(d);
+ doubleStringTestMissing.add(0l);
+ } else {
+ doubleStringTestMissing.add(1l);
+ }
+ doubleStringTestStart.add(list4);
+ ArrayList<Integer> list5 = new ArrayList<>();
+ if( i != 0 ) {
+ list5.add(i);
+ multiStringTestMissing.add(0l);
+ } else {
+ multiStringTestMissing.add(1l);
+ }
+ multiStringTestStart.add(list5);
+ } else {
+ if( i != 0 ) intStringTestStart.get(s-1).add(i); else increment(intStringTestMissing,s-1);
+ if( l != 0l ) longStringTestStart.get(s-1).add(l); else increment(longStringTestMissing,s-1);
+ if( f != 0.0f ) floatStringTestStart.get(s-1).add(f); else increment(floatStringTestMissing,s-1);
+ if( d != 0.0d ) doubleStringTestStart.get(s-1).add(d); else increment(doubleStringTestMissing,s-1);
+ if( i != 0 ) multiStringTestStart.get(s-1).add(i); else increment(multiStringTestMissing,s-1);
+ }
+ }
+
+ //Strings
+ if( sm != 0 ){
+ if ( j-STRINGM < 0 && sm != s ) {
+ ArrayList<Integer> list1 = new ArrayList<>();
+ if( i != 0 ){
+ list1.add(i);
+ multiStringTestMissing.add(0l);
+ } else {
+ multiStringTestMissing.add(1l);
+ }
+ multiStringTestStart.add(list1);
+ } else if ( sm != s ) {
+ if( i != 0 ) multiStringTestStart.get(sm-1).add(i); else increment(multiStringTestMissing,sm-1);
+ }
+ }
+
+ //Int
+ if( i != 0 ) {
+ if ( j-INT < 0 ) {
+ ArrayList<String> list1 = new ArrayList<>();
+ if( dt != 0 ){
+ list1.add((1800+dt) + "-12-31T23:59:59Z");
+ dateIntTestMissing.add(0l);
+ } else {
+ dateIntTestMissing.add(1l);
+ }
+ dateIntTestStart.add(list1);
+ ArrayList<String> list2 = new ArrayList<>();
+ if( s != 0 ) {
+ list2.add("str"+s);
+ stringIntTestMissing.add(0l);
+ } else {
+ stringIntTestMissing.add(1l);
+ }
+ stringIntTestStart.add(list2);
+ } else {
+ if( dt != 0 ) dateIntTestStart.get(i-1).add((1800+dt) + "-12-31T23:59:59Z"); else increment(dateIntTestMissing,i-1);
+ if( s != 0 ) stringIntTestStart.get(i-1).add("str"+s); else increment(stringIntTestMissing,i-1);
+ }
+ }
+
+ //Long
+ if( l != 0 ) {
+ if ( j-LONG < 0 ) {
+ ArrayList<String> list1 = new ArrayList<>();
+ if( dt != 0 ){
+ list1.add((1800+dt) + "-12-31T23:59:59Z");
+ dateLongTestMissing.add(0l);
+ } else {
+ dateLongTestMissing.add(1l);
+ }
+ dateLongTestStart.add(list1);
+ ArrayList<String> list2 = new ArrayList<>();
+ if( s != 0 ) {
+ list2.add("str"+s);
+ stringLongTestMissing.add(0l);
+ } else {
+ stringLongTestMissing.add(1l);
+ }
+ stringLongTestStart.add(list2);
+ ArrayList<Integer> list3 = new ArrayList<>();
+ if( i != 0 ) {
+ list3.add(i);
+ multiLongTestMissing.add(0l);
+ } else {
+ multiLongTestMissing.add(1l);
+ }
+ multiLongTestStart.add(list3);
+ } else {
+ if( dt != 0 ) dateLongTestStart.get((int)l-1).add((1800+dt) + "-12-31T23:59:59Z"); else increment(dateLongTestMissing,(int)l-1);
+ if( s != 0 ) stringLongTestStart.get((int)l-1).add("str"+s); else increment(stringLongTestMissing,(int)l-1);
+ if( i != 0 ) multiLongTestStart.get((int)l-1).add(i); else increment(multiLongTestMissing,(int)l-1);
+ }
+ }
+
+ //Long
+ if( lm != 0 ) {
+ if ( j-LONGM < 0 && lm != l ) {
+ ArrayList<Integer> list1 = new ArrayList<>();
+ if( i != 0 ) {
+ list1.add(i);
+ multiLongTestMissing.add(0l);
+ } else {
+ multiLongTestMissing.add(1l);
+ }
+ multiLongTestStart.add(list1);
+ } else if ( lm != l || multiCanHaveDuplicates ) {
+ if( i != 0 ) multiLongTestStart.get((int)lm-1).add(i); else increment( multiLongTestMissing,(int)lm-1);
+ }
+ }
+
+ if (usually()) {
+ assertU(commit()); // to have several segments
+ }
+ }
+
+ assertU(commit());
+ String[] reqFacetParamas = fileToStringArr(LegacyFieldFacetTest.class, fileName);
+ String[] reqParamas = new String[reqFacetParamas.length + 2];
+ System.arraycopy(reqFacetParamas, 0, reqParamas, 0, reqFacetParamas.length);
+ reqParamas[reqFacetParamas.length] = "solr";
+ reqParamas[reqFacetParamas.length+1] = "asc";
+ setResponse(h.query(request(reqFacetParamas)));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void sumTest() throws Exception {
+ //Int Date
+ Collection<Double> intDate = getDoubleList("sum","fieldFacets", "date_dtd", "double", "int");
+ ArrayList<Double> intDateTest = calculateNumberStat(intDateTestStart, "sum");
+ assertEquals(getRawResponse(),intDate,intDateTest);
+ //Int String
+ Collection<Double> intString = getDoubleList("sum","fieldFacets", "string_sd", "double", "int");
+ ArrayList<Double> intStringTest = calculateNumberStat(intStringTestStart, "sum");
+ assertEquals(getRawResponse(),intString,intStringTest);
+
+ //Long Date
+ Collection<Double> longDate = getDoubleList("sum","fieldFacets", "date_dtd", "double", "long");
+ ArrayList<Double> longDateTest = calculateNumberStat(longDateTestStart, "sum");
+ assertEquals(getRawResponse(),longDate,longDateTest);
+ //Long String
+ Collection<Double> longString = getDoubleList("sum","fieldFacets", "string_sd", "double", "long");
+ ArrayList<Double> longStringTest = calculateNumberStat(longStringTestStart, "sum");
+ assertEquals(getRawResponse(),longString,longStringTest);
+
+ //Float Date
+ Collection<Double> floatDate = getDoubleList("sum","fieldFacets", "date_dtd", "double", "float");
+ ArrayList<Double> floatDateTest = calculateNumberStat(floatDateTestStart, "sum");
+ assertEquals(getRawResponse(),floatDate,floatDateTest);
+ //Float String
+ Collection<Double> floatString = getDoubleList("sum","fieldFacets", "string_sd", "double", "float");
+ ArrayList<Double> floatStringTest = calculateNumberStat(floatStringTestStart, "sum");
+ assertEquals(getRawResponse(),floatString,floatStringTest);
+
+ //Double Date
+ Collection<Double> doubleDate = getDoubleList("sum","fieldFacets", "date_dtd", "double", "double");
+ ArrayList<Double> doubleDateTest = calculateNumberStat(doubleDateTestStart, "sum");
+ assertEquals(getRawResponse(),doubleDate,doubleDateTest);
+ //Double String
+ Collection<Double> doubleString = getDoubleList("sum","fieldFacets", "string_sd", "double", "double");
+ ArrayList<Double> doubleStringTest = calculateNumberStat(doubleStringTestStart, "sum");
+ assertEquals(getRawResponse(),doubleString,doubleStringTest);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void meanTest() throws Exception {
+ //Int Date
+ Collection<Double> intDate = getDoubleList("mean","fieldFacets", "date_dtd", "double", "int");
+ ArrayList<Double> intDateTest = calculateNumberStat(intDateTestStart, "mean");
+ assertEquals(getRawResponse(),intDate,intDateTest);
+ //Int String
+ Collection<Double> intString = getDoubleList("mean","fieldFacets", "string_sd", "double", "int");
+ ArrayList<Double> intStringTest = calculateNumberStat(intStringTestStart, "mean");
+ assertEquals(getRawResponse(),intString,intStringTest);
+
+ //Long Date
+ Collection<Double> longDate = getDoubleList("mean","fieldFacets", "date_dtd", "double", "long");
+ ArrayList<Double> longDateTest = calculateNumberStat(longDateTestStart, "mean");
+ assertEquals(getRawResponse(),longDate,longDateTest);
+ //Long String
+ Collection<Double> longString = getDoubleList("mean","fieldFacets", "string_sd", "double", "long");
+ ArrayList<Double> longStringTest = calculateNumberStat(longStringTestStart, "mean");
+ assertEquals(getRawResponse(),longString,longStringTest);
+
+ //Float Date
+ Collection<Double> floatDate = getDoubleList("mean","fieldFacets", "date_dtd", "double", "float");
+ ArrayList<Double> floatDateTest = calculateNumberStat(floatDateTestStart, "mean");
+ assertEquals(getRawResponse(),floatDate,floatDateTest);
+ //Float String
+ Collection<Double> floatString = getDoubleList("mean","fieldFacets", "string_sd", "double", "float");
+ ArrayList<Double> floatStringTest = calculateNumberStat(floatStringTestStart, "mean");
+ assertEquals(getRawResponse(),floatString,floatStringTest);
+
+ //Double Date
+ Collection<Double> doubleDate = getDoubleList("mean","fieldFacets", "date_dtd", "double", "double");
+ ArrayList<Double> doubleDateTest = calculateNumberStat(doubleDateTestStart, "mean");
+ assertEquals(getRawResponse(),doubleDate,doubleDateTest);
+ //Double String
+ Collection<Double> doubleString = getDoubleList("mean","fieldFacets", "string_sd", "double", "double");
+ ArrayList<Double> doubleStringTest = calculateNumberStat(doubleStringTestStart, "mean");
+ assertEquals(getRawResponse(),doubleString,doubleStringTest);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void stddevFacetAscTest() throws Exception {
+ //Int Date
+ ArrayList<Double> intDate = getDoubleList("stddev","fieldFacets", "date_dtd", "double", "int");
+ ArrayList<Double> intDateTest = calculateNumberStat(intDateTestStart, "stddev");
+ checkStddevs(intDate,intDateTest);
+ //Int String
+ ArrayList<Double> intString = getDoubleList("stddev","fieldFacets", "string_sd", "double", "int");
+ ArrayList<Double> intStringTest = calculateNumberStat(intStringTestStart, "stddev");
+ checkStddevs(intString,intStringTest);
+
+ //Long Date
+ ArrayList<Double> longDate = getDoubleList("stddev","fieldFacets", "date_dtd", "double", "long");
+ ArrayList<Double> longDateTest = calculateNumberStat(longDateTestStart, "stddev");
+ checkStddevs(longDate,longDateTest);
+ //Long String
+ ArrayList<Double> longString = getDoubleList("stddev","fieldFacets", "string_sd", "double", "long");
+ ArrayList<Double> longStringTest = calculateNumberStat(longStringTestStart, "stddev");
+ checkStddevs(longString,longStringTest);
+
+ //Float Date
+ ArrayList<Double> floatDate = getDoubleList("stddev","fieldFacets", "date_dtd", "double", "float");
+ ArrayList<Double> floatDateTest = calculateNumberStat(floatDateTestStart, "stddev");
+ checkStddevs(floatDate,floatDateTest);
+ //Float String
+ ArrayList<Double> floatString = getDoubleList("stddev","fieldFacets", "string_sd", "double", "float");
+ ArrayList<Double> floatStringTest = calculateNumberStat(floatStringTestStart, "stddev");
+ checkStddevs(floatString,floatStringTest);
+
+ //Double Date
+ ArrayList<Double> doubleDate = getDoubleList("stddev","fieldFacets", "date_dtd", "double", "double");
+ ArrayList<Double> doubleDateTest = calculateNumberStat(doubleDateTestStart, "stddev");
+ checkStddevs(doubleDate,doubleDateTest);
+ //Double String
+ ArrayList<Double> doubleString = getDoubleList("stddev","fieldFacets", "string_sd", "double", "double");
+ ArrayList<Double> doubleStringTest = calculateNumberStat(doubleStringTestStart, "stddev");
+ checkStddevs(doubleString,doubleStringTest);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void medianFacetAscTest() throws Exception {
+ //Int Date
+ Collection<Double> intDate = getDoubleList( "median","fieldFacets", "date_dtd", "double", "int");
+ ArrayList<Double> intDateTest = calculateNumberStat(intDateTestStart, "median");
+ assertEquals(getRawResponse(),intDate,intDateTest);
+ //Int String
+ Collection<Double> intString = getDoubleList("median","fieldFacets", "string_sd", "double", "int");
+ ArrayList<Double> intStringTest = calculateNumberStat(intStringTestStart, "median");
+ assertEquals(getRawResponse(),intString,intStringTest);
+
+ //Long Date
+ Collection<Double> longDate = getDoubleList("median","fieldFacets", "date_dtd", "double", "long");
+ ArrayList<Double> longDateTest = calculateNumberStat(longDateTestStart, "median");
+ assertEquals(getRawResponse(),longDate,longDateTest);
+ //Long String
+ Collection<Double> longString = getDoubleList("median","fieldFacets", "string_sd", "double", "long");
+ ArrayList<Double> longStringTest = calculateNumberStat(longStringTestStart, "median");
+ assertEquals(getRawResponse(),longString,longStringTest);
+
+ //Float Date
+ Collection<Double> floatDate = getDoubleList("median","fieldFacets", "date_dtd", "double", "float");
+ ArrayList<Double> floatDateTest = calculateNumberStat(floatDateTestStart, "median");
+ assertEquals(getRawResponse(),floatDate,floatDateTest);
+ //Float String
+ Collection<Double> floatString = getDoubleList("median","fieldFacets", "string_sd", "double", "float");
+ ArrayList<Double> floatStringTest = calculateNumberStat(floatStringTestStart, "median");
+ assertEquals(getRawResponse(),floatString,floatStringTest);
+
+ //Double Date
+ Collection<Double> doubleDate = getDoubleList("median","fieldFacets", "date_dtd", "double", "double");
+ ArrayList<Double> doubleDateTest = calculateNumberStat(doubleDateTestStart, "median");
+ assertEquals(getRawResponse(),doubleDate,doubleDateTest);
+ //Double String
+ Collection<Double> doubleString = getDoubleList("median","fieldFacets", "string_sd", "double", "double");
+ ArrayList<Double> doubleStringTest = calculateNumberStat(doubleStringTestStart, "median");
+ assertEquals(getRawResponse(),doubleString,doubleStringTest);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void perc20Test() throws Exception {
+ //Int Date
+ Collection<Integer> intDate = getIntegerList("percentile_20n","fieldFacets", "date_dtd", "int", "int");
+ ArrayList<Integer> intDateTest = (ArrayList<Integer>)calculateStat(intDateTestStart, "perc_20");
+ assertEquals(getRawResponse(),intDate,intDateTest);
+ //Int String
+ Collection<Integer> intString = getIntegerList("percentile_20n","fieldFacets", "string_sd", "int", "int");
+ ArrayList<Integer> intStringTest = (ArrayList<Integer>)calculateStat(intStringTestStart, "perc_20");
+ assertEquals(getRawResponse(),intString,intStringTest);
+
+ //Long Date
+ Collection<Long> longDate = getLongList("percentile_20n","fieldFacets", "date_dtd", "long", "long");
+ ArrayList<Long> longDateTest = (ArrayList<Long>)calculateStat(longDateTestStart, "perc_20");
+ assertEquals(getRawResponse(),longDate,longDateTest);
+ //Long String
+ Collection<Long> longString = getLongList("percentile_20n","fieldFacets", "string_sd", "long", "long");
+ ArrayList<Long> longStringTest = (ArrayList<Long>)calculateStat(longStringTestStart, "perc_20");
+ assertEquals(getRawResponse(),longString,longStringTest);
+
+ //Float Date
+ Collection<Float> floatDate = getFloatList("percentile_20n","fieldFacets", "date_dtd", "float", "float");
+ ArrayList<Float> floatDateTest = (ArrayList<Float>)calculateStat(floatDateTestStart, "perc_20");
+ assertEquals(getRawResponse(),floatDate,floatDateTest);
+ //Float String
+ Collection<Float> floatString = getFloatList("percentile_20n","fieldFacets", "string_sd", "float", "float");
+ ArrayList<Float> floatStringTest = (ArrayList<Float>)calculateStat(floatStringTestStart, "perc_20");
+ assertEquals(getRawResponse(),floatString,floatStringTest);
+
+ //Double Date
+ Collection<Double> doubleDate = getDoubleList("percentile_20n","fieldFacets", "date_dtd", "double", "double");
+ ArrayList<Double> doubleDateTest = (ArrayList<Double>)calculateStat(doubleDateTestStart, "perc_20");
+ assertEquals(getRawResponse(),doubleDate,doubleDateTest);
+ //Double String
+ Collection<Double> doubleString = getDoubleList("percentile_20n","fieldFacets", "string_sd", "double", "double");
+ ArrayList<Double> doubleStringTest = (ArrayList<Double>)calculateStat(doubleStringTestStart, "perc_20");
+ assertEquals(getRawResponse(),doubleString,doubleStringTest);
+
+ //Date Int
+ Collection<String> dateInt = getStringList("percentile_20","fieldFacets", "int_id", "date", "date");
+ ArrayList<String> dateIntTest = (ArrayList<String>)calculateStat(dateIntTestStart, "perc_20");
+ assertEquals(getRawResponse(),dateInt,dateIntTest);
+ //Date Long
+ Collection<String> dateString = getStringList("percentile_20","fieldFacets", "long_ld", "date", "date");
+ ArrayList<String> dateLongTest = (ArrayList<String>)calculateStat(dateLongTestStart, "perc_20");
+ assertEquals(getRawResponse(),dateString,dateLongTest);
+
+ //String Int
+ Collection<String> stringInt = getStringList("percentile_20","fieldFacets", "int_id", "str", "str");
+ ArrayList<String> stringIntTest = (ArrayList<String>)calculateStat(stringIntTestStart, "perc_20");
+ assertEquals(getRawResponse(),stringInt,stringIntTest);
+ //String Long
+ Collection<String> stringLong = getStringList("percentile_20","fieldFacets", "long_ld", "str", "str");
+ ArrayList<String> stringLongTest = (ArrayList<String>)calculateStat(stringLongTestStart, "perc_20");
+ assertEquals(getRawResponse(),stringLong,stringLongTest);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void perc60Test() throws Exception {
+ //Int Date
+ Collection<Integer> intDate = getIntegerList("percentile_60n","fieldFacets", "date_dtd", "int", "int");
+ ArrayList<Integer> intDateTest = (ArrayList<Integer>)calculateStat(intDateTestStart, "perc_60");
+ assertEquals(getRawResponse(),intDate,intDateTest);
+ //Int String
+ Collection<Integer> intString = getIntegerList("percentile_60n","fieldFacets", "string_sd", "int", "int");
+ ArrayList<Integer> intStringTest = (ArrayList<Integer>)calculateStat(intStringTestStart, "perc_60");
+ assertEquals(getRawResponse(),intString,intStringTest);
+
+ //Long Date
+ Collection<Long> longDate = getLongList("percentile_60n","fieldFacets", "date_dtd", "long", "long");
+ ArrayList<Long> longDateTest = (ArrayList<Long>)calculateStat(longDateTestStart, "perc_60");
+ assertEquals(getRawResponse(),longDate,longDateTest);
+ //Long String
+ Collection<Long> longString = getLongList("percentile_60n","fieldFacets", "string_sd", "long", "long");
+ ArrayList<Long> longStringTest = (ArrayList<Long>)calculateStat(longStringTestStart, "perc_60");
+ assertEquals(getRawResponse(),longString,longStringTest);
+
+ //Float Date
+ Collection<Float> floatDate = getFloatList("percentile_60n","fieldFacets", "date_dtd", "float", "float");
+ ArrayList<Float> floatDateTest = (ArrayList<Float>)calculateStat(floatDateTestStart, "perc_60");
+ assertEquals(getRawResponse(),floatDate,floatDateTest);
+ //Float String
+ Collection<Float> floatString = getFloatList("percentile_60n","fieldFacets", "string_sd", "float", "float");
+ ArrayList<Float> floatStringTest = (ArrayList<Float>)calculateStat(floatStringTestStart, "perc_60");
+ assertEquals(getRawResponse(),floatString,floatStringTest);
+
+ //Double Date
+ Collection<Double> doubleDate = getDoubleList("percentile_60n","fieldFacets", "date_dtd", "double", "double");
+ ArrayList<Double> doubleDateTest = (ArrayList<Double>)calculateStat(doubleDateTestStart, "perc_60");
+ assertEquals(getRawResponse(),doubleDate,doubleDateTest);
+ //Double String
+ Collection<Double> doubleString = getDoubleList("percentile_60n","fieldFacets", "string_sd", "double", "double");
+ ArrayList<Double> doubleStringTest = (ArrayList<Double>)calculateStat(doubleStringTestStart, "perc_60");
+ assertEquals(getRawResponse(),doubleString,doubleStringTest);
+
+ //Date Int
+ Collection<String> dateInt = getStringList("percentile_60","fieldFacets", "int_id", "date", "date");
+ ArrayList<String> dateIntTest = (ArrayList<String>)calculateStat(dateIntTestStart, "perc_60");
+ assertEquals(getRawResponse(),dateInt,dateIntTest);
+ //Date Long
+ Collection<String> dateString = getStringList("percentile_60","fieldFacets", "long_ld", "date", "date");
+ ArrayList<String> dateLongTest = (ArrayList<String>)calculateStat(dateLongTestStart, "perc_60");
+ assertEquals(getRawResponse(),dateString,dateLongTest);
+
+ //String Int
+ Collection<String> stringInt = getStringList("percentile_60","fieldFacets", "int_id", "str", "str");
+ ArrayList<String> stringIntTest = (ArrayList<String>)calculateStat(stringIntTestStart, "perc_60");
+ assertEquals(getRawResponse(),stringInt,stringIntTest);
+ //String Long
+ Collection<String> stringLong = getStringList("percentile_60","fieldFacets", "long_ld", "str", "str");
+ ArrayList<String> stringLongTest = (ArrayList<String>)calculateStat(stringLongTestStart, "perc_60");
+ assertEquals(getRawResponse(),stringLong,stringLongTest);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void minTest() throws Exception {
+ //Int Date
+ Collection<Integer> intDate = getIntegerList("minn","fieldFacets", "date_dtd", "int", "int");
+ ArrayList<Integer> intDateTest = (ArrayList<Integer>)calculateStat(intDateTestStart, "min");
+ assertEquals(getRawResponse(),intDate,intDateTest);
+ //Int String
+ Collection<Integer> intString = getIntegerList("minn","fieldFacets", "string_sd", "int", "int");
+ ArrayList<Integer> intStringTest = (ArrayList<Integer>)calculateStat(intStringTestStart, "min");
+ assertEquals(getRawResponse(),intString,intStringTest);
+
+ //Long Date
+ Collection<Long> longDate = getLongList("minn","fieldFacets", "date_dtd", "long", "long");
+ ArrayList<Long> longDateTest = (ArrayList<Long>)calculateStat(longDateTestStart, "min");
+ assertEquals(getRawResponse(),longDate,longDateTest);
+ //Long String
+ Collection<Long> longString = getLongList("minn","fieldFacets", "string_sd", "long", "long");
+ ArrayList<Long> longStringTest = (ArrayList<Long>)calculateStat(longStringTestStart, "min");
+ assertEquals(getRawResponse(),longString,longStringTest);
+
+ //Float Date
+ Collection<Float> floatDate = getFloatList("minn","fieldFacets", "date_dtd", "float", "float");
+ ArrayList<Float> floatDateTest = (ArrayList<Float>)calculateStat(floatDateTestStart, "min");
+ assertEquals(getRawResponse(),floatDate,floatDateTest);
+ //Float String
+ Collection<Float> floatString = getFloatList("minn","fieldFacets", "string_sd", "float", "float");
+ ArrayList<Float> floatStringTest = (ArrayList<Float>)calculateStat(floatStringTestStart, "min");
+ assertEquals(getRawResponse(),floatString,floatStringTest);
+
+ //Double Date
+ Collection<Double> doubleDate = getDoubleList("minn","fieldFacets", "date_dtd", "double", "double");
+ ArrayList<Double> doubleDateTest = (ArrayList<Double>)calculateStat(doubleDateTestStart, "min");
+ assertEquals(getRawResponse(),doubleDate,doubleDateTest);
+ //Double String
+ Collection<Double> doubleString = getDoubleList("minn","fieldFacets", "string_sd", "double", "double");
+ ArrayList<Double> doubleStringTest = (ArrayList<Double>)calculateStat(doubleStringTestStart, "min");
+ assertEquals(getRawResponse(),doubleString,doubleStringTest);
+
+ //Date Int
+ Collection<String> dateInt = getStringList("min","fieldFacets", "int_id", "date", "date");
+ ArrayList<String> dateIntTest = (ArrayList<String>)calculateStat(dateIntTestStart, "min");
+ assertEquals(getRawResponse(),dateInt,dateIntTest);
+ //Date Long
+ Collection<String> dateString = getStringList("min","fieldFacets", "long_ld", "date", "date");
+ ArrayList<String> dateLongTest = (ArrayList<String>)calculateStat(dateLongTestStart, "min");
+ assertEquals(getRawResponse(),dateString,dateLongTest);
+
+ //String Int
+ Collection<String> stringInt = getStringList("min","fieldFacets", "int_id", "str", "str");
+ ArrayList<String> stringIntTest = (ArrayList<String>)calculateStat(stringIntTestStart, "min");
+ assertEquals(getRawResponse(),stringInt,stringIntTest);
+ //String Long
+ Collection<String> stringLong = getStringList("min","fieldFacets", "long_ld", "str", "str");
+ ArrayList<String> stringLongTest = (ArrayList<String>)calculateStat(stringLongTestStart, "min");
+ assertEquals(getRawResponse(),stringLong,stringLongTest);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void maxTest() throws Exception {
+ //Int Date
+ Collection<Integer> intDate = getIntegerList("maxn","fieldFacets", "date_dtd", "int", "int");
+ ArrayList<Integer> intDateTest = (ArrayList<Integer>)calculateStat(intDateTestStart, "max");
+ assertEquals(getRawResponse(),intDate,intDateTest);
+
+ //Int String
+ Collection<Integer> intString = getIntegerList("maxn","fieldFacets", "string_sd", "int", "int");
+ ArrayList<Integer> intStringTest = (ArrayList<Integer>)calculateStat(intStringTestStart, "max");
+ assertEquals(getRawResponse(),intString,intStringTest);
+
+ //Long Date
+ Collection<Long> longDate = getLongList("maxn","fieldFacets", "date_dtd", "long", "long");
+ ArrayList<Long> longDateTest = (ArrayList<Long>)calculateStat(longDateTestStart, "max");
+ assertEquals(getRawResponse(),longDate,longDateTest);
+
+ //Long String
+ Collection<Long> longString = getLongList("maxn","fieldFacets", "string_sd", "long", "long");
+ ArrayList<Long> longStringTest = (ArrayList<Long>)calculateStat(longStringTestStart, "max");
+ assertEquals(getRawResponse(),longString,longStringTest);
+
+ //Float Date
+ Collection<Float> floatDate = getFloatList("maxn","fieldFacets", "date_dtd", "float", "float");
+ ArrayList<Float> floatDateTest = (ArrayList<Float>)calculateStat(floatDateTestStart, "max");
+ assertEquals(getRawResponse(),floatDate,floatDateTest);
+
+ //Float String
+ Collection<Float> floatString = getFloatList("maxn","fieldFacets", "string_sd", "float", "float");
+ ArrayList<Float> floatStringTest = (ArrayList<Float>)calculateStat(floatStringTestStart, "max");
+ assertEquals(getRawResponse(),floatString,floatStringTest);
+
+ //Double Date
+ Collection<Double> doubleDate = getDoubleList("maxn","fieldFacets", "date_dtd", "double", "double");
+ ArrayList<Double> doubleDateTest = (ArrayList<Double>)calculateStat(doubleDateTestStart, "max");
+ assertEquals(getRawResponse(),doubleDate,doubleDateTest);
+
+ //Double String
+ Collection<Double> doubleString = getDoubleList("maxn","fieldFacets", "string_sd", "double", "double");
+ ArrayList<Double> doubleStringTest = (ArrayList<Double>)calculateStat(doubleStringTestStart, "max");
+ assertEquals(getRawResponse(),doubleString,doubleStringTest);
+
+ //String Int
+ Collection<String> stringInt = getStringList("max","fieldFacets", "int_id", "str", "str");
+ ArrayList<String> stringIntTest = (ArrayList<String>)calculateStat(stringIntTestStart, "max");
+ assertEquals(getRawResponse(),stringInt,stringIntTest);
+
+ //String Long
+ Collection<String> stringLong = getStringList("max","fieldFacets", "long_ld", "str", "str");
+ ArrayList<String> stringLongTest = (ArrayList<String>)calculateStat(stringLongTestStart, "max");
+ assertEquals(getRawResponse(),stringLong,stringLongTest);
+
+ //Date Int
+ Collection<String> dateInt = getStringList("max","fieldFacets", "int_id", "date", "date");
+ ArrayList<String> dateIntTest = (ArrayList<String>)calculateStat(dateIntTestStart, "max");
+ assertEquals(getRawResponse(),dateInt,dateIntTest);
+
+ //Date Long
+ Collection<String> dateString = getStringList("max","fieldFacets", "long_ld", "date", "date");
+ ArrayList<String> dateLongTest = (ArrayList<String>)calculateStat(dateLongTestStart, "max");
+ assertEquals(getRawResponse(),dateString,dateLongTest);
+
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void uniqueTest() throws Exception {
+ //Int Date
+ Collection<Long> intDate = getLongList("uniquen", "fieldFacets", "date_dtd", "long", "int");
+ ArrayList<Long> intDateTest = (ArrayList<Long>)calculateStat(intDateTestStart, "unique");
+ assertEquals(getRawResponse(),intDate,intDateTest);
+ //Int String
+ Collection<Long> intString = getLongList("uniquen", "fieldFacets", "string_sd", "long", "int");
+ ArrayList<Long> intStringTest = (ArrayList<Long>)calculateStat(intStringTestStart, "unique");
+ assertEquals(getRawResponse(),intString,intStringTest);
+
+ //Long Date
+ Collection<Long> longDate = getLongList("uniquen", "fieldFacets", "date_dtd", "long", "long");
+ ArrayList<Long> longDateTest = (ArrayList<Long>)calculateStat(longDateTestStart, "unique");
+ assertEquals(getRawResponse(),longDate,longDateTest);
+ //Long String
+ Collection<Long> longString = getLongList("uniquen", "fieldFacets", "string_sd", "long", "long");
+ ArrayList<Long> longStringTest = (ArrayList<Long>)calculateStat(longStringTestStart, "unique");
+ assertEquals(getRawResponse(),longString,longStringTest);
+
+ //Float Date
+ Collection<Long> floatDate = getLongList("uniquen", "fieldFacets", "date_dtd", "long", "float");
+ ArrayList<Long> floatDateTest = (ArrayList<Long>)calculateStat(floatDateTestStart, "unique");
+ assertEquals(getRawResponse(),floatDate,floatDateTest);
+ //Float String
+ Collection<Long> floatString = getLongList("uniquen", "fieldFacets", "string_sd", "long", "float");
+ ArrayList<Long> floatStringTest = (ArrayList<Long>)calculateStat(floatStringTestStart, "unique");
+ assertEquals(getRawResponse(),floatString,floatStringTest);
+
+ //Double Date
+ Collection<Long> doubleDate = getLongList("uniquen", "fieldFacets", "date_dtd", "long", "double");
+ ArrayList<Long> doubleDateTest = (ArrayList<Long>)calculateStat(doubleDateTestStart, "unique");
+ assertEquals(getRawResponse(),doubleDate,doubleDateTest);
+ //Double String
+ Collection<Long> doubleString = getLongList("uniquen", "fieldFacets", "string_sd", "long", "double");
+ ArrayList<Long> doubleStringTest = (ArrayList<Long>)calculateStat(doubleStringTestStart, "unique");
+ assertEquals(getRawResponse(),doubleString,doubleStringTest);
+
+ //Date Int
+ Collection<Long> dateInt = getLongList("unique", "fieldFacets", "int_id", "long", "date");
+ ArrayList<Long> dateIntTest = (ArrayList<Long>)calculateStat(dateIntTestStart, "unique");
+ assertEquals(getRawResponse(),dateInt,dateIntTest);
+ //Date Long
+ Collection<Long> dateString = getLongList("unique", "fieldFacets", "long_ld", "long", "date");
+ ArrayList<Long> dateLongTest = (ArrayList<Long>)calculateStat(dateLongTestStart, "unique");
+ assertEquals(getRawResponse(),dateString,dateLongTest);
+
+ //String Int
+ Collection<Long> stringInt = getLongList("unique", "fieldFacets", "int_id", "long", "str");
+ ArrayList<Long> stringIntTest = (ArrayList<Long>)calculateStat(stringIntTestStart, "unique");
+ assertEquals(getRawResponse(),stringInt,stringIntTest);
+ //String Long
+ Collection<Long> stringLong = getLongList("unique", "fieldFacets", "long_ld", "long", "str");
+ ArrayList<Long> stringLongTest = (ArrayList<Long>)calculateStat(stringLongTestStart, "unique");
+ assertEquals(getRawResponse(),stringLong,stringLongTest);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void countTest() throws Exception {
+ //Int Date
+ Collection<Long> intDate = getLongList("countn", "fieldFacets", "date_dtd", "long", "int");
+ ArrayList<Long> intDateTest = (ArrayList<Long>)calculateStat(intDateTestStart, "count");
+ assertEquals(getRawResponse(),intDate,intDateTest);
+
+ //Int String
+ Collection<Long> intString = getLongList("countn", "fieldFacets", "string_sd", "long", "int");
+ ArrayList<Long> intStringTest = (ArrayList<Long>)calculateStat(intStringTestStart, "count");
+ assertEquals(getRawResponse(),intString,intStringTest);
+
+ //Long Date
+ Collection<Long> longDate = getLongList("countn", "fieldFacets", "date_dtd", "long", "long");
+ ArrayList<Long> longDateTest = (ArrayList<Long>)calculateStat(longDateTestStart, "count");
+ assertEquals(getRawResponse(),longDate,longDateTest);
+
+ //Long String
+ Collection<Long> longString = getLongList("countn", "fieldFacets", "string_sd", "long", "long");
+ ArrayList<Long> longStringTest = (ArrayList<Long>)calculateStat(longStringTestStart, "count");
+ assertEquals(getRawResponse(),longString,longStringTest);
+
+ //Float Date
+ Collection<Long> floatDate = getLongList("countn", "fieldFacets", "date_dtd", "long", "float");
+ ArrayList<Long> floatDateTest = (ArrayList<Long>)calculateStat(floatDateTestStart, "count");
+ assertEquals(getRawResponse(),floatDate,floatDateTest);
+
+ //Float String
+ Collection<Long> floatString = getLongList("countn", "fieldFacets", "string_sd", "long", "float");
+ ArrayList<Long> floatStringTest = (ArrayList<Long>)calculateStat(floatStringTestStart, "count");
+ assertEquals(getRawResponse(),floatString,floatStringTest);
+
+ //Double Date
+ Collection<Long> doubleDate = getLongList("countn", "fieldFacets", "date_dtd", "long", "double");
+ ArrayList<Long> doubleDateTest = (ArrayList<Long>)calculateStat(doubleDateTestStart, "count");
+ assertEquals(getRawResponse(),doubleDate,doubleDateTest);
+
+ //Double String
+ Collection<Long> doubleString = getLongList("countn", "fieldFacets", "string_sd", "long", "double");
+ ArrayList<Long> doubleStringTest = (ArrayList<Long>)calculateStat(doubleStringTestStart, "count");
+ assertEquals(getRawResponse(),doubleString,doubleStringTest);
+
+ //Date Int
+ Collection<Long> dateInt = getLongList("count", "fieldFacets", "int_id", "long", "date");
+ ArrayList<Long> dateIntTest = (ArrayList<Long>)calculateStat(dateIntTestStart, "count");
+ assertEquals(getRawResponse(),dateIntTest,dateInt);
+
+ //Date Long
+ Collection<Long> dateLong = getLongList("count", "fieldFacets", "long_ld", "long", "date");
+ ArrayList<Long> dateLongTest = (ArrayList<Long>)calculateStat(dateLongTestStart, "count");
+ assertEquals(getRawResponse(),dateLong,dateLongTest);
+
+ //String Int
+ Collection<Long> stringInt = getLongList("count", "fieldFacets", "int_id", "long", "str");
+ ArrayList<Long> stringIntTest = (ArrayList<Long>)calculateStat(stringIntTestStart, "count");
+ assertEquals(getRawResponse(),stringInt,stringIntTest);
+
+ //String Long
+ Collection<Long> stringLong = getLongList("count", "fieldFacets", "long_ld", "long", "str");
+ ArrayList<Long> stringLongTest = (ArrayList<Long>)calculateStat(stringLongTestStart, "count");
+ assertEquals(getRawResponse(),stringLong,stringLongTest);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void missingTest() throws Exception {
+ //Int Date
+ Collection<Long> intDate = getLongList("missingn", "fieldFacets", "date_dtd", "long", "int");
+ setLatestType("int");
+ assertEquals(getRawResponse(),intDateTestMissing,intDate);
+
+ //Int String
+ Collection<Long> intString = getLongList("missingn", "fieldFacets", "string_sd", "long", "int");
+ assertEquals(getRawResponse(),intStringTestMissing,intString);
+
+ //Long Date
+ Collection<Long> longDate = getLongList("missingn", "fieldFacets", "date_dtd", "long", "long");
+ setLatestType("long");
+ assertEquals(getRawResponse(),longDateTestMissing,longDate);
+
+ //Long String
+ Collection<Long> longString = getLongList("missingn", "fieldFacets", "string_sd", "long", "long");
+ assertEquals(getRawResponse(),longStringTestMissing,longString);
+
+ //Float Date
+ Collection<Long> floatDate = getLongList("missingn", "fieldFacets", "date_dtd", "long", "float");
+ setLatestType("float");
+ assertEquals(getRawResponse(),floatDateTestMissing,floatDate);
+
+ //Float String
+ Collection<Long> floatString = getLongList("missingn", "fieldFacets", "string_sd", "long", "float");
+ assertEquals(getRawResponse(),floatStringTestMissing,floatString);
+
+ //Double Date
+ Collection<Long> doubleDate = getLongList("missingn", "fieldFacets", "date_dtd", "long", "double");
+ setLatestType("double");
+ assertEquals(getRawResponse(),doubleDateTestMissing,doubleDate);
+
+ //Double String
+ Collection<Long> doubleString = getLongList("missingn", "fieldFacets", "string_sd", "long", "double");
+ assertEquals(getRawResponse(),doubleStringTestMissing,doubleString);
+
+ //Date Int
+ Collection<Long> dateInt = getLongList("missing", "fieldFacets", "int_id", "long", "date");
+ setLatestType("date");
+ assertEquals(getRawResponse(),dateIntTestMissing,dateInt);
+
+ //Date Long
+ Collection<Long> dateLong = getLongList("missing", "fieldFacets", "long_ld", "long", "date");
+ assertEquals(getRawResponse(),dateLongTestMissing,dateLong);
+
+ //String Int
+ Collection<Long> stringInt = getLongList("missing", "fieldFacets", "int_id", "long", "str");
+ setLatestType("string");
+ assertEquals(getRawResponse(),stringIntTestMissing,stringInt);
+
+ //String Long
+ Collection<Long> stringLong = getLongList("missing", "fieldFacets", "long_ld", "long", "str");
+ assertEquals(getRawResponse(),stringLongTestMissing,stringLong);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void multiValueTest() throws Exception {
+ //Long
+ Collection<Double> lon = getDoubleList("multivalued", "fieldFacets", "long_ldm", "double", "mean");
+ ArrayList<Double> longTest = calculateNumberStat(multiLongTestStart, "mean");
+ assertEquals(getRawResponse(),lon,longTest);
+ //Date
+ Collection<Double> date = getDoubleList("multivalued", "fieldFacets", "date_dtdm", "double", "mean");
+ ArrayList<Double> dateTest = calculateNumberStat(multiDateTestStart, "mean");
+ assertEquals(getRawResponse(),date,dateTest);
+ //String
+ Collection<Double> string = getDoubleList("multivalued", "fieldFacets", "string_sdm", "double", "mean");
+ ArrayList<Double> stringTest = calculateNumberStat(multiStringTestStart, "mean");
+ assertEquals(getRawResponse(),string,stringTest);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void missingFacetTest() throws Exception {
+ //int MultiDate
+ String xPath = "/response/lst[@name='stats']/lst[@name='missingf']/lst[@name='fieldFacets']/lst[@name='date_dtdm']/lst[@name='(MISSING)']";
+ Node missingNodeXPath = getNode(xPath);
+ assertNotNull(getRawResponse(), missingNodeXPath);
+
+ ArrayList<Double> string = getDoubleList("missingf", "fieldFacets", "date_dtdm", "double", "mean");
+ //super.removeNodes(xPath, string);
+ ArrayList<Double> stringTest = calculateNumberStat(multiDateTestStart, "mean");
+ assertEquals(getRawResponse(), string,stringTest);
+
+ //Int String
+ xPath = "/response/lst[@name='stats']/lst[@name='missingf']/lst[@name='fieldFacets']/lst[@name='string_sd']/lst[@name='(MISSING)']";
+ missingNodeXPath = getNode(xPath);
+ String missingNodeXPathStr = xPath;
+ assertNotNull(getRawResponse(), missingNodeXPath);
+
+ xPath = "/response/lst[@name='stats']/lst[@name='missingf']/lst[@name='fieldFacets']/lst[@name='string_sd']/lst[@name='str0']";
+ assertNull(getRawResponse(), getNode(xPath));
+
+ List<Double> intString = getDoubleList("missingf", "fieldFacets", "string_sd", "double", "mean");
+ //removeNodes(missingNodeXPathStr, intString);
+ ArrayList<Double> intStringTest = calculateNumberStat(intStringTestStart, "mean");
+ assertEquals(getRawResponse(), intString,intStringTest);
+
+ //Int Date
+ Collection<Double> intDate = getDoubleList("missingf", "fieldFacets", "date_dtd", "double", "mean");
+ ArrayList<ArrayList<Double>> intDateMissingTestStart = (ArrayList<ArrayList<Double>>) intDateTestStart.clone();
+ ArrayList<Double> intDateTest = calculateNumberStat(intDateMissingTestStart, "mean");
+ assertEquals(getRawResponse(),intDate,intDateTest);
+ }
+
+ private void checkStddevs(ArrayList<Double> list1, ArrayList<Double> list2) {
+ Collections.sort(list1);
+ Collections.sort(list2);
+ for (int i = 0; i<list1.size(); i++) {
+ if ((Math.abs(list1.get(i)-list2.get(i))<.00000000001) == false) {
+ Assert.assertEquals(getRawResponse(), list1.get(i), list2.get(i), 0.00000000001);
+ }
+ }
+ }
+
+ public static void assertEquals(String mes, Object actual, Object expected) {
+ Collections.sort((List<Comparable>) actual);
+ Collections.sort((List<Comparable>) expected);
+ Assert.assertEquals(mes, actual, expected);
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyQueryFacetCloudTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyQueryFacetCloudTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyQueryFacetCloudTest.java
new file mode 100644
index 0000000..4c78a43
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyQueryFacetCloudTest.java
@@ -0,0 +1,159 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.legacy.facet;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.solr.client.solrj.request.UpdateRequest;
+import org.apache.solr.common.util.NamedList;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class LegacyQueryFacetCloudTest extends LegacyAbstractAnalyticsFacetCloudTest {
+ private static final int INT = 71;
+ private static final int LONG = 36;
+ private static final int FLOAT = 93;
+ private static final int DOUBLE = 49;
+ private static final int DATE = 12;
+ private static final int STRING = 7;
+ private static final int NUM_LOOPS = 100;
+
+ private static ArrayList<ArrayList<Integer>> int1TestStart = new ArrayList<>();
+ private static ArrayList<ArrayList<Integer>> int2TestStart = new ArrayList<>();
+ private static ArrayList<ArrayList<Long>> longTestStart = new ArrayList<>();
+ private static ArrayList<ArrayList<Float>> floatTestStart = new ArrayList<>();
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ cleanIndex();
+
+ //INT
+ int1TestStart.add(new ArrayList<Integer>());
+ int2TestStart.add(new ArrayList<Integer>());
+
+ //LONG
+ longTestStart.add(new ArrayList<Long>());
+ longTestStart.add(new ArrayList<Long>());
+
+ //FLOAT
+ floatTestStart.add(new ArrayList<Float>());
+ floatTestStart.add(new ArrayList<Float>());
+ floatTestStart.add(new ArrayList<Float>());
+
+ UpdateRequest req = new UpdateRequest();
+
+ for (int j = 0; j < NUM_LOOPS; ++j) {
+ int i = j%INT;
+ long l = j%LONG;
+ float f = j%FLOAT;
+ double d = j%DOUBLE;
+ int dt = j%DATE;
+ int s = j%STRING;
+
+ List<String> fields = new ArrayList<>();
+ fields.add("id"); fields.add("1000"+j);
+ fields.add("int_id"); fields.add("" + i);
+ fields.add("long_ld"); fields.add("" + l);
+ fields.add("float_fd"); fields.add("" + f);
+ fields.add("double_dd"); fields.add("" + d);
+ fields.add("date_dtd"); fields.add((1000+dt) + "-01-01T23:59:59Z");
+ fields.add("string_sd"); fields.add("abc" + s);
+ req.add(fields.toArray(new String[0]));
+
+ if (f<=50) {
+ int1TestStart.get(0).add(i);
+ }
+ if (f<=30) {
+ int2TestStart.get(0).add(i);
+ }
+ if (s == 1) {
+ longTestStart.get(0).add(l);
+ }
+ if (s == 2) {
+ longTestStart.get(1).add(l);
+ }
+ if (l>=30) {
+ floatTestStart.get(0).add(f);
+ }
+ if (d<=50) {
+ floatTestStart.get(1).add(f);
+ }
+ if (l>=20) {
+ floatTestStart.get(2).add(f);
+ }
+ }
+
+ req.commit(cluster.getSolrClient(), COLLECTIONORALIAS);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void queryTest() throws Exception {
+ String[] params = new String[] {
+ "o.ir.s.sum", "sum(int_id)",
+ "o.ir.s.mean", "mean(int_id)",
+ "o.ir.s.median", "median(int_id)",
+ "o.ir.s.percentile_8", "percentile(8,int_id)",
+ "o.ir.qf", "float1",
+ "o.ir.qf.float1.q", "float_fd:[* TO 50]",
+ "o.ir.qf", "float2",
+ "o.ir.qf.float2.q", "float_fd:[* TO 30]",
+
+ "o.lr.s.sum", "sum(long_ld)",
+ "o.lr.s.mean", "mean(long_ld)",
+ "o.lr.s.median", "median(long_ld)",
+ "o.lr.s.percentile_8", "percentile(8,long_ld)",
+ "o.lr.qf", "string",
+ "o.lr.qf.string.q", "string_sd:abc1",
+ "o.lr.qf.string.q", "string_sd:abc2",
+
+ "o.fr.s.sum", "sum(float_fd)",
+ "o.fr.s.mean", "mean(float_fd)",
+ "o.fr.s.median", "median(float_fd)",
+ "o.fr.s.percentile_8", "percentile(8,float_fd)",
+ "o.fr.qf", "lad",
+ "o.fr.qf.lad.q", "long_ld:[20 TO *]",
+ "o.fr.qf.lad.q", "long_ld:[30 TO *]",
+ "o.fr.qf.lad.q", "double_dd:[* TO 50]"
+ };
+
+ NamedList<Object> response = queryLegacyCloudAnalytics(params);
+ String responseStr = response.toString();
+
+ //Int One
+ ArrayList<Double> int1 = getValueList(response, "ir", "queryFacets", "float1", "sum", false);
+ ArrayList<Double> int1Test = calculateFacetedNumberStat(int1TestStart, "sum");
+ assertEquals(responseStr, int1, int1Test);
+ //Int Two
+ ArrayList<Integer> int2 = getValueList(response, "ir", "queryFacets", "float2", "percentile_8", false);
+ ArrayList<Integer> int2Test = (ArrayList<Integer>)calculateFacetedStat(int2TestStart, "perc_8");
+ assertEquals(responseStr, int2, int2Test);
+
+ //Long
+ ArrayList<Double> long1 = getValueList(response, "lr", "queryFacets", "string", "median", false);
+ ArrayList<Double> long1Test = calculateFacetedNumberStat(longTestStart, "median");
+ assertEquals(responseStr,long1,long1Test);
+
+ //Float
+ ArrayList<Double> float1 = getValueList(response, "fr", "queryFacets", "lad", "mean", false);
+ ArrayList<Double> float1Test = calculateFacetedNumberStat(floatTestStart, "mean");
+ assertEquals(responseStr, float1, float1Test);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyQueryFacetTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyQueryFacetTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyQueryFacetTest.java
new file mode 100644
index 0000000..62ebc3b
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyQueryFacetTest.java
@@ -0,0 +1,124 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.legacy.facet;
+
+
+import java.util.ArrayList;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class LegacyQueryFacetTest extends LegacyAbstractAnalyticsFacetTest {
+ static String fileName = "queryFacets.txt";
+
+ public final int INT = 71;
+ public final int LONG = 36;
+ public final int FLOAT = 93;
+ public final int DOUBLE = 49;
+ public final int DATE = 12;
+ public final int STRING = 28;
+ public final int NUM_LOOPS = 100;
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ initCore("solrconfig-analytics.xml","schema-analytics.xml");
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void queryTest() throws Exception {
+ h.update("<delete><query>*:*</query></delete>");
+ //INT
+ ArrayList<ArrayList<Integer>> int1TestStart = new ArrayList<>();
+ int1TestStart.add(new ArrayList<Integer>());
+ ArrayList<ArrayList<Integer>> int2TestStart = new ArrayList<>();
+ int2TestStart.add(new ArrayList<Integer>());
+
+ //LONG
+ ArrayList<ArrayList<Long>> longTestStart = new ArrayList<>();
+ longTestStart.add(new ArrayList<Long>());
+ longTestStart.add(new ArrayList<Long>());
+
+ //FLOAT
+ ArrayList<ArrayList<Float>> floatTestStart = new ArrayList<>();
+ floatTestStart.add(new ArrayList<Float>());
+ floatTestStart.add(new ArrayList<Float>());
+ floatTestStart.add(new ArrayList<Float>());
+
+ for (int j = 0; j < NUM_LOOPS; ++j) {
+ int i = j%INT;
+ long l = j%LONG;
+ float f = j%FLOAT;
+ double d = j%DOUBLE;
+ int dt = j%DATE;
+ int s = j%STRING;
+ assertU(adoc("id", "1000" + j, "int_id", "" + i, "long_ld", "" + l, "float_fd", "" + f,
+ "double_dd", "" + d, "date_dtd", (1800+dt) + "-12-31T23:59:59.999Z", "string_sd", "abc" + new Integer(s).toString().charAt(0)));
+
+ if (f<=50) {
+ int1TestStart.get(0).add(i);
+ }
+ if (f<=30) {
+ int2TestStart.get(0).add(i);
+ }
+ if (new Integer(s).toString().charAt(0)=='1') {
+ longTestStart.get(0).add(l);
+ }
+ if (new Integer(s).toString().charAt(0)=='2') {
+ longTestStart.get(1).add(l);
+ }
+ if (l>=30) {
+ floatTestStart.get(0).add(f);
+ }
+ if (d<=50) {
+ floatTestStart.get(1).add(f);
+ }
+ if (l>=20) {
+ floatTestStart.get(2).add(f);
+ }
+
+ if (usually()) {
+ assertU(commit()); // to have several segments
+ }
+ }
+
+ assertU(commit());
+
+ //Query ascending tests
+ setResponse(h.query(request(fileToStringArr(LegacyQueryFacetTest.class, fileName))));
+
+ //Int One
+ ArrayList<Double> int1 = getDoubleList("ir", "queryFacets", "float1", "double", "sum");
+ ArrayList<Double> int1Test = calculateNumberStat(int1TestStart, "sum");
+ assertEquals(getRawResponse(), int1, int1Test);
+ //Int Two
+ ArrayList<Integer> int2 = getIntegerList("ir", "queryFacets", "float2", "int", "percentile_8");
+ ArrayList<Integer> int2Test = (ArrayList<Integer>)calculateStat(int2TestStart, "perc_8");
+ assertEquals(getRawResponse(), int2, int2Test);
+
+ //Long
+ ArrayList<Double> long1 = getDoubleList("lr", "queryFacets", "string", "double", "median");
+ ArrayList<Double> long1Test = calculateNumberStat(longTestStart, "median");
+ assertEquals(getRawResponse(),long1,long1Test);
+
+ //Float
+ ArrayList<Double> float1 = getDoubleList("fr", "queryFacets", "lad", "double", "mean");
+ ArrayList<Double> float1Test = calculateNumberStat(floatTestStart, "mean");
+ assertEquals(getRawResponse(), float1, float1Test);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyRangeFacetCloudTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyRangeFacetCloudTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyRangeFacetCloudTest.java
new file mode 100644
index 0000000..95585c4
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyRangeFacetCloudTest.java
@@ -0,0 +1,588 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.legacy.facet;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.solr.client.solrj.request.UpdateRequest;
+import org.apache.solr.common.util.NamedList;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+
+public class LegacyRangeFacetCloudTest extends LegacyAbstractAnalyticsFacetCloudTest{
+ public static final int INT = 71;
+ public static final int LONG = 36;
+ public static final int FLOAT = 93;
+ public static final int DOUBLE = 48;
+ public static final int DATE = 52;
+ public static final int STRING = 28;
+ public static final int NUM_LOOPS = 100;
+
+ //INT
+ static ArrayList<ArrayList<Integer>> intLongTestStart;
+ static ArrayList<ArrayList<Integer>> intDoubleTestStart;
+ static ArrayList<ArrayList<Integer>> intDateTestStart;
+
+ //FLOAT
+ static ArrayList<ArrayList<Float>> floatLongTestStart;
+ static ArrayList<ArrayList<Float>> floatDoubleTestStart;
+ static ArrayList<ArrayList<Float>> floatDateTestStart;
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ cleanIndex();
+
+ //INT
+ intLongTestStart = new ArrayList<>();
+ intDoubleTestStart = new ArrayList<>();
+ intDateTestStart = new ArrayList<>();
+
+ //FLOAT
+ floatLongTestStart = new ArrayList<>();
+ floatDoubleTestStart = new ArrayList<>();
+ floatDateTestStart = new ArrayList<>();
+
+ UpdateRequest req = new UpdateRequest();
+
+ for (int j = 0; j < NUM_LOOPS; ++j) {
+ int i = j%INT;
+ long l = j%LONG;
+ float f = j%FLOAT;
+ double d = j%DOUBLE;
+ int dt = j%DATE;
+ int s = j%STRING;
+
+ List<String> fields = new ArrayList<>();
+ fields.add("id"); fields.add("1000"+j);
+ fields.add("int_id"); fields.add("" + i);
+ fields.add("long_ld"); fields.add("" + l);
+ fields.add("float_fd"); fields.add("" + f);
+ fields.add("double_dd"); fields.add("" + d);
+ fields.add("date_dtd"); fields.add((1000+dt) + "-01-01T23:59:59Z");
+ fields.add("string_sd"); fields.add("abc" + s);
+ req.add(fields.toArray(new String[0]));
+
+ //Longs
+ if (j-LONG<0) {
+ ArrayList<Integer> list1 = new ArrayList<>();
+ list1.add(i);
+ intLongTestStart.add(list1);
+ ArrayList<Float> list2 = new ArrayList<>();
+ list2.add(f);
+ floatLongTestStart.add(list2);
+ } else {
+ intLongTestStart.get((int)l).add(i);
+ floatLongTestStart.get((int)l).add(f);
+ }
+ //Doubles
+ if (j-DOUBLE<0) {
+ ArrayList<Integer> list1 = new ArrayList<>();
+ list1.add(i);
+ intDoubleTestStart.add(list1);
+ ArrayList<Float> list2 = new ArrayList<>();
+ list2.add(f);
+ floatDoubleTestStart.add(list2);
+ } else {
+ intDoubleTestStart.get((int)d).add(i);
+ floatDoubleTestStart.get((int)d).add(f);
+ }
+ //Dates
+ if (j-DATE<0) {
+ ArrayList<Integer> list1 = new ArrayList<>();
+ list1.add(i);
+ intDateTestStart.add(list1);
+ ArrayList<Float> list2 = new ArrayList<>();
+ list2.add(f);
+ floatDateTestStart.add(list2);
+ } else {
+ intDateTestStart.get(dt).add(i);
+ floatDateTestStart.get(dt).add(f);
+ }
+ }
+
+ req.commit(cluster.getSolrClient(), COLLECTIONORALIAS);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void rangeTest() throws Exception {
+ String[] params = new String[] {
+ "o.ri.s.sum", "sum(int_id)",
+ "o.ri.s.mean", "mean(int_id)",
+ "o.ri.s.median", "median(int_id)",
+ "o.ri.s.count", "count(int_id)",
+ "o.ri.rf", "long_ld",
+ "o.ri.rf.long_ld.st", "5",
+ "o.ri.rf.long_ld.e", "30",
+ "o.ri.rf.long_ld.g", "5",
+ "o.ri.rf.long_ld.ib", "lower",
+ "o.ri.rf.long_ld.or", "all",
+ "o.ri.rf", "double_dd",
+ "o.ri.rf.double_dd.st", "3",
+ "o.ri.rf.double_dd.e", "39",
+ "o.ri.rf.double_dd.g", "7",
+ "o.ri.rf.double_dd.ib", "upper",
+ "o.ri.rf.double_dd.ib", "outer",
+ "o.ri.rf.double_dd.or", "all",
+ "o.ri.rf", "date_dtd",
+ "o.ri.rf.date_dtd.st", "1007-01-01T23:59:59Z",
+ "o.ri.rf.date_dtd.e", "1044-01-01T23:59:59Z",
+ "o.ri.rf.date_dtd.g", "+7YEARS",
+ "o.ri.rf.date_dtd.ib", "lower",
+ "o.ri.rf.date_dtd.ib", "edge",
+ "o.ri.rf.date_dtd.ib", "outer",
+ "o.ri.rf.date_dtd.or", "all",
+
+ "o.rf.s.sum", "sum(float_fd)",
+ "o.rf.s.mean", "mean(float_fd)",
+ "o.rf.s.median", "median(float_fd)",
+ "o.rf.s.count", "count(float_fd)",
+ "o.rf.rf", "long_ld",
+ "o.rf.rf.long_ld.st", "0",
+ "o.rf.rf.long_ld.e", "29",
+ "o.rf.rf.long_ld.g", "4",
+ "o.rf.rf.long_ld.ib", "all",
+ "o.rf.rf.long_ld.or", "all",
+ "o.rf.rf", "double_dd",
+ "o.rf.rf.double_dd.st", "4",
+ "o.rf.rf.double_dd.e", "47",
+ "o.rf.rf.double_dd.g", "11",
+ "o.rf.rf.double_dd.ib", "edge",
+ "o.rf.rf.double_dd.or", "all",
+ "o.rf.rf", "date_dtd",
+ "o.rf.rf.date_dtd.st", "1004-01-01T23:59:59Z",
+ "o.rf.rf.date_dtd.e", "1046-01-01T23:59:59Z",
+ "o.rf.rf.date_dtd.g", "+5YEARS",
+ "o.rf.rf.date_dtd.ib", "upper",
+ "o.rf.rf.date_dtd.ib", "edge",
+ "o.rf.rf.date_dtd.or", "all"
+ };
+
+ NamedList<Object> response = queryLegacyCloudAnalytics(params);
+ String responseStr = response.toString();
+
+ //Int Long
+ ArrayList<Long> intLong = getValueList(response, "ri", "rangeFacets", "long_ld", "count", false);
+ ArrayList<Long> intLongTest = calculateFacetedStat(transformLists(intLongTestStart, 5, 30, 5
+ , false, true, false, false, false), "count");
+ assertEquals(responseStr, intLong,intLongTest);
+ //Int Double
+ ArrayList<Double> intDouble = getValueList(response, "ri", "rangeFacets", "double_dd", "mean", false);
+ ArrayList<Double> intDoubleTest = calculateFacetedNumberStat(transformLists(intDoubleTestStart, 3, 39, 7
+ , false, false, true, false, true), "mean");
+ assertEquals(responseStr, intDouble,intDoubleTest);
+ //Int Date
+ ArrayList<Long> intDate = getValueList(response, "ri", "rangeFacets", "date_dtd", "count", false);
+ ArrayList<Long> intDateTest = (ArrayList<Long>)calculateFacetedStat(transformLists(intDateTestStart, 7, 44, 7
+ , false, true, false, true, true), "count");
+ assertEquals(responseStr, intDate,intDateTest);
+
+ //Float Long
+ ArrayList<Double> floatLong = getValueList(response, "rf", "rangeFacets", "long_ld", "median", false);
+ ArrayList<Double> floatLongTest = calculateFacetedNumberStat(transformLists(floatLongTestStart, 0, 29, 4
+ , false, true, true, true, true), "median");
+ assertEquals(responseStr, floatLong,floatLongTest);
+ //Float Double
+ ArrayList<Long> floatDouble = getValueList(response, "rf", "rangeFacets", "double_dd", "count", false);
+ ArrayList<Long> floatDoubleTest = (ArrayList<Long>)calculateFacetedStat(transformLists(floatDoubleTestStart, 4, 47, 11
+ , false, false, false, true, false), "count");
+ assertEquals(responseStr, floatDouble,floatDoubleTest);
+ }
+
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void hardendRangeTest() throws Exception {
+ String[] params = new String[] {
+ "o.hi.s.sum", "sum(int_id)",
+ "o.hi.s.mean", "mean(int_id)",
+ "o.hi.s.median", "median(int_id)",
+ "o.hi.s.count", "count(int_id)",
+ "o.hi.rf", "long_ld",
+ "o.hi.rf.long_ld.st", "5",
+ "o.hi.rf.long_ld.e", "30",
+ "o.hi.rf.long_ld.g", "5",
+ "o.hi.rf.long_ld.he", "true",
+ "o.hi.rf.long_ld.ib", "lower",
+ "o.hi.rf.long_ld.or", "all",
+ "o.hi.rf", "double_dd",
+ "o.hi.rf.double_dd.st", "3",
+ "o.hi.rf.double_dd.e", "39",
+ "o.hi.rf.double_dd.g", "7",
+ "o.hi.rf.double_dd.he", "true",
+ "o.hi.rf.double_dd.ib", "upper",
+ "o.hi.rf.double_dd.ib", "outer",
+ "o.hi.rf.double_dd.or", "all",
+ "o.hi.rf", "date_dtd",
+ "o.hi.rf.date_dtd.st", "1007-01-01T23:59:59Z",
+ "o.hi.rf.date_dtd.e", "1044-01-01T23:59:59Z",
+ "o.hi.rf.date_dtd.g", "+7YEARS",
+ "o.hi.rf.date_dtd.he", "true",
+ "o.hi.rf.date_dtd.ib", "lower",
+ "o.hi.rf.date_dtd.ib", "edge",
+ "o.hi.rf.date_dtd.ib", "outer",
+ "o.hi.rf.date_dtd.or", "all",
+
+ "o.hf.s.sum", "sum(float_fd)",
+ "o.hf.s.mean", "mean(float_fd)",
+ "o.hf.s.median", "median(float_fd)",
+ "o.hf.s.count", "count(float_fd)",
+ "o.hf.rf", "long_ld",
+ "o.hf.rf.long_ld.st", "0",
+ "o.hf.rf.long_ld.e", "29",
+ "o.hf.rf.long_ld.g", "4",
+ "o.hf.rf.long_ld.he", "true",
+ "o.hf.rf.long_ld.ib", "all",
+ "o.hf.rf.long_ld.or", "all",
+ "o.hf.rf", "double_dd",
+ "o.hf.rf.double_dd.st", "4",
+ "o.hf.rf.double_dd.e", "47",
+ "o.hf.rf.double_dd.g", "11",
+ "o.hf.rf.double_dd.he", "true",
+ "o.hf.rf.double_dd.ib", "edge",
+ "o.hf.rf.double_dd.or", "all",
+ "o.hf.rf", "date_dtd",
+ "o.hf.rf.date_dtd.st", "1004-01-01T23:59:59Z",
+ "o.hf.rf.date_dtd.e", "1046-01-01T23:59:59Z",
+ "o.hf.rf.date_dtd.g", "+5YEARS",
+ "o.hf.rf.date_dtd.he", "true",
+ "o.hf.rf.date_dtd.ib", "upper",
+ "o.hf.rf.date_dtd.ib", "edge",
+ "o.hf.rf.date_dtd.or", "all"
+ };
+ NamedList<Object> response = queryLegacyCloudAnalytics(params);
+ String responseStr = response.toString();
+
+ //Int Long
+ ArrayList<Double> intLong = getValueList(response, "hi", "rangeFacets", "long_ld", "sum", false);
+ ArrayList<Double> intLongTest = calculateFacetedNumberStat(transformLists(intLongTestStart, 5, 30, 5
+ , true, true, false, false, false), "sum");
+ assertEquals(responseStr, intLong,intLongTest);
+ //Int Double
+ ArrayList<Double> intDouble = getValueList(response, "hi", "rangeFacets", "double_dd", "mean", false);
+ ArrayList<Double> intDoubleTest = calculateFacetedNumberStat(transformLists(intDoubleTestStart, 3, 39, 7
+ , true, false, true, false, true), "mean");
+ assertEquals(responseStr, intDouble,intDoubleTest);
+ //Int Date
+ ArrayList<Long> intDate = getValueList(response, "hi", "rangeFacets", "date_dtd", "count", false);
+ ArrayList<Long> intDateTest = (ArrayList<Long>)calculateFacetedStat(transformLists(intDateTestStart, 7, 44, 7
+ , true, true, false, true, true), "count");
+ assertEquals(responseStr, intDate,intDateTest);
+
+ //Float Long
+ ArrayList<Double> floatLong = getValueList(response, "hf", "rangeFacets", "long_ld", "median", false);
+ ArrayList<Double> floatLongTest = calculateFacetedNumberStat(transformLists(floatLongTestStart, 0, 29, 4
+ , true, true, true, true, true), "median");
+ assertEquals(responseStr, floatLong,floatLongTest);
+ //Float Double
+ ArrayList<Long> floatDouble = getValueList(response, "hf", "rangeFacets", "double_dd", "count", false);
+ ArrayList<Long> floatDoubleTest = (ArrayList<Long>)calculateFacetedStat(transformLists(floatDoubleTestStart, 4, 47, 11
+ , true, false, false, true, false), "count");
+ assertEquals(responseStr, floatDouble,floatDoubleTest);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void multiGapTest() throws Exception {
+ String[] params = new String[] {
+ "o.mi.s.sum", "sum(int_id)",
+ "o.mi.s.mean", "mean(int_id)",
+ "o.mi.s.median", "median(int_id)",
+ "o.mi.s.count", "count(int_id)",
+ "o.mi.rf", "long_ld",
+ "o.mi.rf.long_ld.st", "5",
+ "o.mi.rf.long_ld.e", "30",
+ "o.mi.rf.long_ld.g", "4,2,6,3",
+ "o.mi.rf.long_ld.ib", "lower",
+ "o.mi.rf.long_ld.or", "all",
+ "o.mi.rf", "double_dd",
+ "o.mi.rf.double_dd.st", "3",
+ "o.mi.rf.double_dd.e", "39",
+ "o.mi.rf.double_dd.g", "3,1,7",
+ "o.mi.rf.double_dd.ib", "upper",
+ "o.mi.rf.double_dd.ib", "outer",
+ "o.mi.rf.double_dd.or", "all",
+ "o.mi.rf", "date_dtd",
+ "o.mi.rf.date_dtd.st", "1007-01-01T23:59:59Z",
+ "o.mi.rf.date_dtd.e", "1044-01-01T23:59:59Z",
+ "o.mi.rf.date_dtd.g", "+2YEARS,+7YEARS",
+ "o.mi.rf.date_dtd.ib", "lower",
+ "o.mi.rf.date_dtd.ib", "edge",
+ "o.mi.rf.date_dtd.ib", "outer",
+ "o.mi.rf.date_dtd.or", "all",
+
+ "o.mf.s.sum", "sum(float_fd)",
+ "o.mf.s.mean", "mean(float_fd)",
+ "o.mf.s.median", "median(float_fd)",
+ "o.mf.s.count", "count(float_fd)",
+ "o.mf.rf", "long_ld",
+ "o.mf.rf.long_ld.st", "0",
+ "o.mf.rf.long_ld.e", "29",
+ "o.mf.rf.long_ld.g", "1,4",
+ "o.mf.rf.long_ld.ib", "all",
+ "o.mf.rf.long_ld.or", "all",
+ "o.mf.rf", "double_dd",
+ "o.mf.rf.double_dd.st", "4",
+ "o.mf.rf.double_dd.e", "47",
+ "o.mf.rf.double_dd.g", "2,3,11",
+ "o.mf.rf.double_dd.ib", "edge",
+ "o.mf.rf.double_dd.or", "all",
+ "o.mf.rf", "date_dtd",
+ "o.mf.rf.date_dtd.st", "1004-01-01T23:59:59Z",
+ "o.mf.rf.date_dtd.e", "1046-01-01T23:59:59Z",
+ "o.mf.rf.date_dtd.g", "+4YEARS,+5YEARS",
+ "o.mf.rf.date_dtd.ib", "upper",
+ "o.mf.rf.date_dtd.ib", "edge",
+ "o.mf.rf.date_dtd.or", "all"
+ };
+ NamedList<Object> response = queryLegacyCloudAnalytics(params);
+ String responseStr = response.toString();
+
+ //Int Long
+ ArrayList<Double> intLong = getValueList(response, "mi", "rangeFacets", "long_ld", "sum", false);
+ ArrayList<Double> intLongTest = calculateFacetedNumberStat(transformLists(intLongTestStart, 5, 30, "4,2,6,3"
+ , false, true, false, false, false), "sum");
+ assertEquals(responseStr, intLong,intLongTest);
+ //Int Double
+ ArrayList<Double> intDouble = getValueList(response, "mi", "rangeFacets", "double_dd", "mean", false);
+ ArrayList<Double> intDoubleTest = calculateFacetedNumberStat(transformLists(intDoubleTestStart, 3, 39, "3,1,7"
+ , false, false, true, false, true), "mean");
+ assertEquals(responseStr, intDouble,intDoubleTest);
+ //Int Date
+ ArrayList<Long> intDate = getValueList(response, "mi", "rangeFacets", "date_dtd", "count", false);
+ ArrayList<Long> intDateTest = (ArrayList<Long>)calculateFacetedStat(transformLists(intDateTestStart, 7, 44, "2,7"
+ , false, true, false, true, true), "count");
+ assertEquals(responseStr, intDate,intDateTest);
+
+ //Float Long
+ ArrayList<Double> floatLong = getValueList(response, "mf", "rangeFacets", "long_ld", "median", false);
+ ArrayList<Double> floatLongTest = calculateFacetedNumberStat(transformLists(floatLongTestStart, 0, 29, "1,4"
+ , false, true, true, true, true), "median");;
+ assertEquals(responseStr, floatLong,floatLongTest);
+ //Float Double
+ ArrayList<Long> floatDouble = getValueList(response, "mf", "rangeFacets", "double_dd", "count", false);
+ ArrayList<Long> floatDoubleTest = (ArrayList<Long>)calculateFacetedStat(transformLists(floatDoubleTestStart, 4, 47, "2,3,11"
+ , false, false, false, true, false), "count");
+ assertEquals(responseStr, floatDouble,floatDoubleTest);
+ }
+
+ private <T> ArrayList<ArrayList<T>> transformLists(ArrayList<ArrayList<T>> listsStart, int start, int end, int gap
+ , boolean hardend, boolean incLow, boolean incUp, boolean incEdge, boolean incOut) {
+ int off = (end-start)%gap;
+ if (!hardend && off>0) {
+ end+=gap-off;
+ }
+
+ ArrayList<ArrayList<T>> lists = new ArrayList<>();
+ ArrayList<T> between = new ArrayList<>();
+ if (incLow && incUp) {
+ for (int i = start; i<end && i<listsStart.size(); i+=gap) {
+ ArrayList<T> list = new ArrayList<>();
+ for (int j = i; j<=i+gap && j<=end && j<listsStart.size(); j++) {
+ list.addAll(listsStart.get(j));
+ }
+ lists.add(list);
+ }
+ for (int i = start; i<listsStart.size() && i<=end; i++) {
+ between.addAll(listsStart.get(i));
+ }
+ } else if (incLow && !incUp) {
+ for (int i = start; i<end && i<listsStart.size(); i+=gap) {
+ ArrayList<T> list = new ArrayList<>();
+ for (int j = i; j<i+gap && j<end && j<listsStart.size(); j++) {
+ list.addAll(listsStart.get(j));
+ }
+ lists.add(list);
+ }
+ for (int i = start; i<listsStart.size() && i<end; i++) {
+ between.addAll(listsStart.get(i));
+ }
+ } else if (!incLow && incUp) {
+ for (int i = start; i<end && i<listsStart.size(); i+=gap) {
+ ArrayList<T> list = new ArrayList<>();
+ for (int j = i+1; j<=i+gap && j<=end && j<listsStart.size(); j++) {
+ list.addAll(listsStart.get(j));
+ }
+ lists.add(list);
+ }
+ for (int i = start+1; i<listsStart.size() && i<=end; i++) {
+ between.addAll(listsStart.get(i));
+ }
+ } else {
+ for (int i = start; i<end && i<listsStart.size(); i+=gap) {
+ ArrayList<T> list = new ArrayList<>();
+ for (int j = i+1; j<i+gap && j<end && j<listsStart.size(); j++) {
+ list.addAll(listsStart.get(j));
+ }
+ lists.add(list);
+ }
+ for (int i = start+1; i<listsStart.size() && i<end; i++) {
+ between.addAll(listsStart.get(i));
+ }
+ }
+
+ if (incEdge && !incLow && start>=0) {
+ lists.get(0).addAll(listsStart.get(start));
+ between.addAll(listsStart.get(start));
+ }
+ if (incEdge && !incUp && end<listsStart.size()) {
+ lists.get(lists.size()-1).addAll(listsStart.get(end));
+ between.addAll(listsStart.get(end));
+ }
+ ArrayList<T> before = new ArrayList<>();
+ ArrayList<T> after = new ArrayList<>();
+ if (incOut || !(incLow||incEdge)) {
+ for (int i = 0; i<=start; i++) {
+ before.addAll(listsStart.get(i));
+ }
+ } else {
+ for (int i = 0; i<start; i++) {
+ before.addAll(listsStart.get(i));
+ }
+ }
+ if (incOut || !(incUp||incEdge)) {
+ for (int i = end; i<listsStart.size(); i++) {
+ after.addAll(listsStart.get(i));
+ }
+ }
+ else {
+ for (int i = end+1; i<listsStart.size(); i++) {
+ after.addAll(listsStart.get(i));
+ }
+ }
+ lists.add(before);
+ lists.add(after);
+ lists.add(between);
+ return lists;
+ }
+
+ private <T> ArrayList<ArrayList<T>> transformLists(ArrayList<ArrayList<T>> listsStart, int start, int end, String gapString
+ , boolean hardend, boolean incLow, boolean incUp, boolean incEdge, boolean incOut) {
+ String[] stringGaps = gapString.split(",");
+ int[] gaps = new int[stringGaps.length];
+ for (int i = 0; i<gaps.length; i++) {
+ gaps[i] = Integer.parseInt(stringGaps[i]);
+ }
+ int bigGap = 0;
+ int last = gaps[gaps.length-1];
+ for (int i = 0; i<gaps.length-1; i++) {
+ bigGap += gaps[i];
+ }
+ int off = (end-start-bigGap)%last;
+ if (!hardend && off>0) {
+ end+=last-off;
+ }
+
+ ArrayList<ArrayList<T>> lists = new ArrayList<>();
+ ArrayList<T> between = new ArrayList<>();
+ int gap = 0;
+ int gapCounter = 0;
+ if (incLow && incUp) {
+ for (int i = start; i<end && i<listsStart.size(); i+=gap) {
+ if (gapCounter<gaps.length) {
+ gap = gaps[gapCounter++];
+ }
+ ArrayList<T> list = new ArrayList<>();
+ for (int j = i; j<=i+gap && j<=end && j<listsStart.size(); j++) {
+ list.addAll(listsStart.get(j));
+ }
+ lists.add(list);
+ }
+ for (int i = start; i<listsStart.size() && i<=end; i++) {
+ between.addAll(listsStart.get(i));
+ }
+ } else if (incLow && !incUp) {
+ for (int i = start; i<end && i<listsStart.size(); i+=gap) {
+ if (gapCounter<gaps.length) {
+ gap = gaps[gapCounter++];
+ }
+ ArrayList<T> list = new ArrayList<>();
+ for (int j = i; j<i+gap && j<end && j<listsStart.size(); j++) {
+ list.addAll(listsStart.get(j));
+ }
+ lists.add(list);
+ }
+ for (int i = start; i<listsStart.size() && i<end; i++) {
+ between.addAll(listsStart.get(i));
+ }
+ } else if (!incLow && incUp) {
+ for (int i = start; i<end && i<listsStart.size(); i+=gap) {
+ if (gapCounter<gaps.length) {
+ gap = gaps[gapCounter++];
+ }
+ ArrayList<T> list = new ArrayList<>();
+ for (int j = i+1; j<=i+gap && j<=end && j<listsStart.size(); j++) {
+ list.addAll(listsStart.get(j));
+ }
+ lists.add(list);
+ }
+ for (int i = start+1; i<listsStart.size() && i<=end; i++) {
+ between.addAll(listsStart.get(i));
+ }
+ } else {
+ for (int i = start; i<end && i<listsStart.size(); i+=gap) {
+ if (gapCounter<gaps.length) {
+ gap = gaps[gapCounter++];
+ }
+ ArrayList<T> list = new ArrayList<>();
+ for (int j = i+1; j<i+gap && j<end && j<listsStart.size(); j++) {
+ list.addAll(listsStart.get(j));
+ }
+ lists.add(list);
+ }
+ for (int i = start+1; i<listsStart.size() && i<end; i++) {
+ between.addAll(listsStart.get(i));
+ }
+ }
+
+ if (incEdge && !incLow && start>=0) {
+ lists.get(0).addAll(listsStart.get(start));
+ between.addAll(listsStart.get(start));
+ }
+ if (incEdge && !incUp && end<listsStart.size()) {
+ lists.get(lists.size()-1).addAll(listsStart.get(end));
+ between.addAll(listsStart.get(end));
+ }
+ ArrayList<T> before = new ArrayList<>();
+ ArrayList<T> after = new ArrayList<>();
+ if (incOut || !(incLow||incEdge)) {
+ for (int i = 0; i<=start; i++) {
+ before.addAll(listsStart.get(i));
+ }
+ } else {
+ for (int i = 0; i<start; i++) {
+ before.addAll(listsStart.get(i));
+ }
+ }
+ if (incOut || !(incUp||incEdge)) {
+ for (int i = end; i<listsStart.size(); i++) {
+ after.addAll(listsStart.get(i));
+ }
+ }
+ else {
+ for (int i = end+1; i<listsStart.size(); i++) {
+ after.addAll(listsStart.get(i));
+ }
+ }
+ lists.add(before);
+ lists.add(after);
+ lists.add(between);
+ return lists;
+ }
+}
[10/20] lucene-solr:master: SOLR-11145,
SOLR-11146: Added comprehensive unit tests for Analytics Component
2.0 as well as analytics bug fixes.
Posted by dp...@apache.org.
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/DateParseFunctionTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/DateParseFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/DateParseFunctionTest.java
new file mode 100644
index 0000000..2f34833
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/DateParseFunctionTest.java
@@ -0,0 +1,245 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.function.mapping;
+
+import java.time.Instant;
+import java.time.format.DateTimeParseException;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.Iterator;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.analytics.value.AnalyticsValueStream;
+import org.apache.solr.analytics.value.DateValue;
+import org.apache.solr.analytics.value.DateValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestLongValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestLongValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestStringValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestStringValueStream;
+import org.junit.Test;
+
+public class DateParseFunctionTest extends SolrTestCaseJ4 {
+
+ @Test
+ public void singleValueLongTest() throws DateTimeParseException {
+ Date date1 = Date.from(Instant.parse("1800-01-01T10:30:15Z"));
+ Date date2 = Date.from(Instant.parse("1920-04-15T18:15:45Z"));
+ TestLongValue val = new TestLongValue();
+
+ AnalyticsValueStream uncasted = DateParseFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof DateValue);
+ DateValue func = (DateValue) uncasted;
+
+ // Value doesn't exist
+ val.setExists(false);
+ func.getDate();
+ assertFalse(func.exists());
+ func.getLong();
+ assertFalse(func.exists());
+
+ // Value exists
+ val.setValue(date1.getTime()).setExists(true);
+ assertEquals(date1, func.getDate());
+ assertTrue(func.exists());
+ assertEquals(date1.getTime(), func.getLong());
+ assertTrue(func.exists());
+
+ val.setValue(date2.getTime()).setExists(true);
+ assertEquals(date2, func.getDate());
+ assertTrue(func.exists());
+ assertEquals(date2.getTime(), func.getLong());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void singleValueStringTest() throws DateTimeParseException {
+ Date date1 = Date.from(Instant.parse("1800-01-01T10:30:15Z"));
+ Date date2 = Date.from(Instant.parse("1920-04-15T18:15:45Z"));
+ TestStringValue val = new TestStringValue();
+
+ AnalyticsValueStream uncasted = DateParseFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof DateValue);
+ DateValue func = (DateValue) uncasted;
+
+ // Value doesn't exist
+ val.setExists(false);
+ func.getDate();
+ assertFalse(func.exists());
+ func.getLong();
+ assertFalse(func.exists());
+
+ // Incorrect Value
+ val.setValue("1800-01T10:30:15Z").setExists(true);
+ func.getDate();
+ assertFalse(func.exists());
+ func.getLong();
+ assertFalse(func.exists());
+
+ val.setValue("1800-01-T::Z").setExists(true);
+ func.getDate();
+ assertFalse(func.exists());
+ func.getLong();
+ assertFalse(func.exists());
+
+ val.setValue("1800--01T30:30:15Z").setExists(true);
+ func.getDate();
+ assertFalse(func.exists());
+ func.getLong();
+ assertFalse(func.exists());
+
+
+ // Value exists
+ val.setValue("1800-01-01T10:30:15Z").setExists(true);
+ assertEquals(date1, func.getDate());
+ assertTrue(func.exists());
+ assertEquals(date1.getTime(), func.getLong());
+ assertTrue(func.exists());
+
+ val.setValue("1920-04-15T18:15:45Z").setExists(true);
+ assertEquals(date2, func.getDate());
+ assertTrue(func.exists());
+ assertEquals(date2.getTime(), func.getLong());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void multiValueLongTest() throws DateTimeParseException {
+ Date date1 = Date.from(Instant.parse("1800-01-01T10:30:15Z"));
+ Date date2 = Date.from(Instant.parse("1920-04-15T18:15:45Z"));
+ Date date3 = Date.from(Instant.parse("2012-11-30T20:30:15Z"));
+ TestLongValueStream val = new TestLongValueStream();
+
+ AnalyticsValueStream uncasted = DateParseFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof DateValueStream);
+ DateValueStream func = (DateValueStream) uncasted;
+
+ // No values
+ val.setValues();
+ func.streamDates( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+ func.streamLongs( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // One value
+ val.setValues(date1.getTime());
+ Iterator<Date> values1 = Arrays.asList(date1).iterator();
+ func.streamDates( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value);
+ });
+ assertFalse(values1.hasNext());
+ Iterator<Long> times1 = Arrays.asList(date1.getTime()).iterator();
+ func.streamLongs( value -> {
+ assertTrue(times1.hasNext());
+ assertEquals(times1.next().longValue(), value);
+ });
+ assertFalse(times1.hasNext());
+
+ // Multiple values
+ val.setValues(date1.getTime(), date2.getTime(), date3.getTime());
+ Iterator<Date> values2 = Arrays.asList(date1, date2, date3).iterator();
+ func.streamDates( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value);
+ });
+ assertFalse(values2.hasNext());
+ Iterator<Long> times2 = Arrays.asList(date1.getTime(), date2.getTime(), date3.getTime()).iterator();
+ func.streamLongs( value -> {
+ assertTrue(times2.hasNext());
+ assertEquals(times2.next().longValue(), value);
+ });
+ assertFalse(times2.hasNext());
+ }
+
+ @Test
+ public void multiValueStringTest() throws DateTimeParseException {
+ Date date1 = Date.from(Instant.parse("1800-01-01T10:30:15Z"));
+ Date date2 = Date.from(Instant.parse("1920-04-15T18:15:45Z"));
+ Date date3 = Date.from(Instant.parse("2012-11-30T20:30:15Z"));
+ TestStringValueStream val = new TestStringValueStream();
+
+ AnalyticsValueStream uncasted = DateParseFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof DateValueStream);
+ DateValueStream func = (DateValueStream) uncasted;
+
+ // No values
+ val.setValues();
+ func.streamDates( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+ func.streamLongs( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Incorrect value
+ val.setValues("10:30:15Z");
+ func.streamDates( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+ func.streamLongs( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ val.setValues("01-33T10:30:15Z");
+ func.streamDates( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+ func.streamLongs( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ val.setValues("1800-01T30:30:15Z");
+ func.streamDates( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+ func.streamLongs( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // One value
+ val.setValues("1800-01-01T10:30:15Z");
+ Iterator<Date> values1 = Arrays.asList(date1).iterator();
+ func.streamDates( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value);
+ });
+ assertFalse(values1.hasNext());
+ Iterator<Long> times1 = Arrays.asList(date1.getTime()).iterator();
+ func.streamLongs( value -> {
+ assertTrue(times1.hasNext());
+ assertEquals(times1.next().longValue(), value);
+ });
+ assertFalse(times1.hasNext());
+
+ // Multiple values
+ val.setValues("1800-01-01T10:30:15Z", "1920-04-15T18:15:45Z", "2012-11-30T20:30:15Z");
+ Iterator<Date> values2 = Arrays.asList(date1, date2, date3).iterator();
+ func.streamDates( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value);
+ });
+ assertFalse(values2.hasNext());
+ Iterator<Long> times2 = Arrays.asList(date1.getTime(), date2.getTime(), date3.getTime()).iterator();
+ func.streamLongs( value -> {
+ assertTrue(times2.hasNext());
+ assertEquals(times2.next().longValue(), value);
+ });
+ assertFalse(times2.hasNext());
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/DivideFunctionTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/DivideFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/DivideFunctionTest.java
new file mode 100644
index 0000000..5ca324d
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/DivideFunctionTest.java
@@ -0,0 +1,128 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.function.mapping;
+
+import java.util.Arrays;
+import java.util.Iterator;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.analytics.value.AnalyticsValueStream;
+import org.apache.solr.analytics.value.DoubleValue;
+import org.apache.solr.analytics.value.DoubleValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestIntValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestLongValueStream;
+import org.junit.Test;
+
+public class DivideFunctionTest extends SolrTestCaseJ4 {
+ @Test
+ public void twoSingleValueParametersTest() {
+ TestIntValue dividend = new TestIntValue();
+ TestFloatValue divisor = new TestFloatValue();
+
+ AnalyticsValueStream uncasted = DivideFunction.creatorFunction.apply(new AnalyticsValueStream[] {dividend, divisor});
+ assertTrue(uncasted instanceof DoubleValue);
+ DoubleValue func = (DoubleValue) uncasted;
+
+ // Neither exists
+ dividend.setExists(false);
+ divisor.setExists(false);
+ func.getDouble();
+ assertFalse(func.exists());
+
+ // One exists
+ dividend.setValue(30).setExists(true);
+ divisor.setExists(false);
+ func.getDouble();
+ assertFalse(func.exists());
+
+ // Both exist
+ dividend.setValue(60).setExists(true);
+ divisor.setValue(23.56F).setExists(true);
+ assertEquals(2.546689, func.getDouble(), 0.00001);
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void oneMultiOneSingleValueParameterTest() {
+ TestLongValueStream dividend = new TestLongValueStream();
+ TestDoubleValue divisor = new TestDoubleValue();
+
+ AnalyticsValueStream uncasted = DivideFunction.creatorFunction.apply(new AnalyticsValueStream[] {dividend, divisor});
+ assertTrue(uncasted instanceof DoubleValueStream);
+ DoubleValueStream func = (DoubleValueStream) uncasted;
+
+ // No values, One value
+ dividend.setValues();
+ divisor.setValue(21.56F).setExists(true);
+ func.streamDoubles( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple values, no value
+ dividend.setValues(4L, 10023L);
+ divisor.setExists(false);
+ func.streamDoubles( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple values, one value
+ dividend.setValues(20L, 5L, -234L);
+ divisor.setValue(44.56F).setExists(true);
+ Iterator<Double> values = Arrays.asList(0.448833, 0.112208, -5.251346).iterator();
+ func.streamDoubles( value -> {
+ assertTrue(values.hasNext());
+ assertEquals(values.next(), value, 0.00001);
+ });
+ assertFalse(values.hasNext());
+ }
+
+ @Test
+ public void oneSingleOneMultiValueParameterTest() {
+ TestDoubleValue dividend = new TestDoubleValue();
+ TestLongValueStream divisor = new TestLongValueStream();
+
+ AnalyticsValueStream uncasted = DivideFunction.creatorFunction.apply(new AnalyticsValueStream[] {dividend, divisor});
+ assertTrue(uncasted instanceof DoubleValueStream);
+ DoubleValueStream func = (DoubleValueStream) uncasted;
+
+ // No values, One value
+ dividend.setValue(21.56F).setExists(true);
+ divisor.setValues();
+ func.streamDoubles( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple values, no value
+ dividend.setExists(false);
+ divisor.setValues(4L, 10023L);
+ func.streamDoubles( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple values, one value
+ dividend.setValue(44.56F).setExists(true);
+ divisor.setValues(20L, 5L, -234L);
+ Iterator<Double> values = Arrays.asList(2.228, 8.912, -0.190427).iterator();
+ func.streamDoubles( value -> {
+ assertTrue(values.hasNext());
+ assertEquals(values.next(), value, 0.00001);
+ });
+ assertFalse(values.hasNext());
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/EqualFunctionTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/EqualFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/EqualFunctionTest.java
new file mode 100644
index 0000000..6495f96
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/EqualFunctionTest.java
@@ -0,0 +1,530 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.function.mapping;
+
+import java.util.Arrays;
+import java.util.Iterator;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.analytics.function.mapping.EqualFunction;
+import org.apache.solr.analytics.value.AnalyticsValueStream;
+import org.apache.solr.analytics.value.BooleanValue;
+import org.apache.solr.analytics.value.BooleanValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestBooleanValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestBooleanValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestDateValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestDateValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestStringValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestStringValueStream;
+import org.junit.Test;
+
+public class EqualFunctionTest extends SolrTestCaseJ4 {
+
+ @Test
+ public void singleValueBooleanParameterTest() {
+ TestBooleanValue val1 = new TestBooleanValue();
+ TestBooleanValue val2 = new TestBooleanValue();
+
+ AnalyticsValueStream uncasted = EqualFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2});
+ assertTrue(uncasted instanceof BooleanValue);
+ BooleanValue func = (BooleanValue) uncasted;
+
+ // Value doesn't exist
+ val1.setExists(false);
+ val2.setExists(false);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ val1.setExists(false);
+ val2.setValue(false).setExists(true);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ val1.setValue(true).setExists(true);
+ val2.setExists(false);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ // Value exists
+ val1.setValue(false).setExists(true);
+ val2.setValue(false).setExists(true);
+ assertEquals(true, func.getBoolean());
+ assertTrue(func.exists());
+
+ val1.setValue(false).setExists(true);
+ val2.setValue(true).setExists(true);
+ assertEquals(false, func.getBoolean());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void singleValueNumericParameterTest() {
+ TestDoubleValue val1 = new TestDoubleValue();
+ TestDoubleValue val2 = new TestDoubleValue();
+
+ AnalyticsValueStream uncasted = EqualFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2});
+ assertTrue(uncasted instanceof BooleanValue);
+ BooleanValue func = (BooleanValue) uncasted;
+
+ // Value doesn't exist
+ val1.setExists(false);
+ val2.setExists(false);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ val1.setExists(false);
+ val2.setValue(3.3).setExists(true);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ val1.setValue(3.3).setExists(true);
+ val2.setExists(false);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ // Value exists
+ val1.setValue(21.56).setExists(true);
+ val2.setValue(21.56).setExists(true);
+ assertEquals(true, func.getBoolean());
+ assertTrue(func.exists());
+
+ val1.setValue(21.56).setExists(true);
+ val2.setValue(21.57).setExists(true);
+ assertEquals(false, func.getBoolean());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void singleValueDateParameterTest() {
+ TestDateValue val1 = new TestDateValue();
+ TestDateValue val2 = new TestDateValue();
+
+ AnalyticsValueStream uncasted = EqualFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2});
+ assertTrue(uncasted instanceof BooleanValue);
+ BooleanValue func = (BooleanValue) uncasted;
+
+ // Value doesn't exist
+ val1.setExists(false);
+ val2.setExists(false);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ val1.setExists(false);
+ val2.setValue("1800-01-02T10:20:30Z").setExists(true);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ val1.setValue("1800-01-02T10:20:30Z").setExists(true);
+ val2.setExists(false);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ // Value exists
+ val1.setValue("1800-01-02T10:20:30Z").setExists(true);
+ val2.setValue("1800-01-02T10:20:30Z").setExists(true);
+ assertEquals(true, func.getBoolean());
+ assertTrue(func.exists());
+
+ val1.setValue("1800-01-02T10:20:30Z").setExists(true);
+ val2.setValue("1800-01-02T10:20:31Z").setExists(true);
+ assertEquals(false, func.getBoolean());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void singleValueStringParameterTest() {
+ TestStringValue val1 = new TestStringValue();
+ TestStringValue val2 = new TestStringValue();
+
+ AnalyticsValueStream uncasted = EqualFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2});
+ assertTrue(uncasted instanceof BooleanValue);
+ BooleanValue func = (BooleanValue) uncasted;
+
+ // Value doesn't exist
+ val1.setExists(false);
+ val2.setExists(false);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ val1.setExists(false);
+ val2.setValue("abcdefghi").setExists(true);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ val1.setValue("abcdefghi").setExists(true);
+ val2.setExists(false);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ // Value exists
+ val1.setValue("abcdefghi").setExists(true);
+ val2.setValue("abcdefghi").setExists(true);
+ assertEquals(true, func.getBoolean());
+ assertTrue(func.exists());
+
+ val1.setValue("abcdefghi1").setExists(true);
+ val2.setValue("abcdefghi2").setExists(true);
+ assertEquals(false, func.getBoolean());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void oneSingleOneMultiValueBooleanParameterTest() {
+ TestBooleanValueStream val1 = new TestBooleanValueStream();
+ TestBooleanValue val2 = new TestBooleanValue();
+
+ AnalyticsValueStream uncasted = EqualFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2});
+ assertTrue(uncasted instanceof BooleanValueStream);
+ BooleanValueStream func = (BooleanValueStream) uncasted;
+
+ // No values
+ val1.setValues();
+ val2.setValue(false).setExists(true);
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ val1.setValues(true);
+ val2.setExists(false);
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // One value
+ val1.setValues(false);
+ val2.setValue(false).setExists(true);
+ Iterator<Boolean> values1 = Arrays.asList(true).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ // Multiple values
+ val1.setValues(false, true, true, false, false);
+ val2.setValue(false).setExists(true);
+ Iterator<Boolean> values2 = Arrays.asList(true, false, false, true, true).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value);
+ });
+ assertFalse(values2.hasNext());
+ }
+
+ @Test
+ public void oneMultiOneSingleValueBooleanParameterTest() {
+ TestBooleanValueStream val1 = new TestBooleanValueStream();
+ TestBooleanValue val2 = new TestBooleanValue();
+
+ AnalyticsValueStream uncasted = EqualFunction.creatorFunction.apply(new AnalyticsValueStream[] {val2, val1});
+ assertTrue(uncasted instanceof BooleanValueStream);
+ BooleanValueStream func = (BooleanValueStream) uncasted;
+
+ // No values
+ val1.setValues();
+ val2.setValue(false).setExists(true);
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ val1.setValues(true);
+ val2.setExists(false);
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // One value
+ val1.setValues(false);
+ val2.setValue(false).setExists(true);
+ Iterator<Boolean> values1 = Arrays.asList(true).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ // Multiple values
+ val1.setValues(false, true, true, false, false);
+ val2.setValue(false).setExists(true);
+ Iterator<Boolean> values2 = Arrays.asList(true, false, false, true, true).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value);
+ });
+ assertFalse(values2.hasNext());
+ }
+
+ @Test
+ public void oneSingleOneMultiValueNumericParameterTest() {
+ TestDoubleValueStream val1 = new TestDoubleValueStream();
+ TestDoubleValue val2 = new TestDoubleValue();
+
+ AnalyticsValueStream uncasted = EqualFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2});
+ assertTrue(uncasted instanceof BooleanValueStream);
+ BooleanValueStream func = (BooleanValueStream) uncasted;
+
+ // No values
+ val1.setValues();
+ val2.setValue(-4.2).setExists(true);
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ val1.setValues(-4.2);
+ val2.setExists(false);
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // One value
+ val1.setValues(-4.2);
+ val2.setValue(-4.2).setExists(true);
+ Iterator<Boolean> values1 = Arrays.asList(true).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ // Multiple values
+ val1.setValues(4, -10, 4, -74, 4.0001);
+ val2.setValue(4).setExists(true);
+ Iterator<Boolean> values2 = Arrays.asList(true, false, true, false, false).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value);
+ });
+ assertFalse(values2.hasNext());
+ }
+
+ @Test
+ public void oneMultiOneSingleValueNumericParameterTest() {
+ TestDoubleValueStream val1 = new TestDoubleValueStream();
+ TestDoubleValue val2 = new TestDoubleValue();
+
+ AnalyticsValueStream uncasted = EqualFunction.creatorFunction.apply(new AnalyticsValueStream[] {val2, val1});
+ assertTrue(uncasted instanceof BooleanValueStream);
+ BooleanValueStream func = (BooleanValueStream) uncasted;
+
+ // No values
+ val1.setValues();
+ val2.setValue(-4.2).setExists(true);
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ val1.setValues(-4.2);
+ val2.setExists(false);
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // One value
+ val1.setValues(-4.2);
+ val2.setValue(-4.2).setExists(true);
+ Iterator<Boolean> values1 = Arrays.asList(true).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ // Multiple values
+ val1.setValues(4, -10, 4, -74, 4.0001);
+ val2.setValue(4).setExists(true);
+ Iterator<Boolean> values2 = Arrays.asList(true, false, true, false, false).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value);
+ });
+ assertFalse(values2.hasNext());
+ }
+
+ @Test
+ public void oneSingleOneMultiValueDateParameterTest() {
+ TestDateValueStream val1 = new TestDateValueStream();
+ TestDateValue val2 = new TestDateValue();
+
+ AnalyticsValueStream uncasted = EqualFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2});
+ assertTrue(uncasted instanceof BooleanValueStream);
+ BooleanValueStream func = (BooleanValueStream) uncasted;
+
+ // No values
+ val1.setValues();
+ val2.setValue("1800-01-02T10:20:30Z").setExists(true);
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ val1.setValues("1800-01-02T10:20:30Z");
+ val2.setExists(false);
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // One value
+ val1.setValues("1800-01-02T10:20:30Z");
+ val2.setValue("1800-01-02T10:20:30Z").setExists(true);
+ Iterator<Boolean> values1 = Arrays.asList(true).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ // Multiple values
+ val1.setValues("1800-01-02T10:20:30Z", "1800-01-02T10:20:31Z", "1800-01-02T10:20:30Z", "1801-01-02T10:20:30Z");
+ val2.setValue("1800-01-02T10:20:30Z").setExists(true);
+ Iterator<Boolean> values2 = Arrays.asList(true, false, true, false).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value);
+ });
+ assertFalse(values2.hasNext());
+ }
+
+ @Test
+ public void oneMultiOneSingleValueDateParameterTest() {
+ TestDateValueStream val1 = new TestDateValueStream();
+ TestDateValue val2 = new TestDateValue();
+
+ AnalyticsValueStream uncasted = EqualFunction.creatorFunction.apply(new AnalyticsValueStream[] {val2, val1});
+ assertTrue(uncasted instanceof BooleanValueStream);
+ BooleanValueStream func = (BooleanValueStream) uncasted;
+
+ // No values
+ val1.setValues();
+ val2.setValue("1800-01-02T10:20:30Z").setExists(true);
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ val1.setValues("1800-01-02T10:20:30Z");
+ val2.setExists(false);
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // One value
+ val1.setValues("1800-01-02T10:20:30Z");
+ val2.setValue("1800-01-02T10:20:30Z").setExists(true);
+ Iterator<Boolean> values1 = Arrays.asList(true).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ // Multiple values
+ val1.setValues("1800-01-02T10:20:30Z", "1800-01-02T10:20:31Z", "1800-01-02T10:20:30Z", "9999-01-02T10:20:30Z");
+ val2.setValue("1800-01-02T10:20:30Z").setExists(true);
+ Iterator<Boolean> values2 = Arrays.asList(true, false, true, false).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value);
+ });
+ assertFalse(values2.hasNext());
+ }
+
+ @Test
+ public void oneSingleOneMultiValueStringParameterTest() {
+ TestStringValueStream val1 = new TestStringValueStream();
+ TestStringValue val2 = new TestStringValue();
+
+ AnalyticsValueStream uncasted = EqualFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2});
+ assertTrue(uncasted instanceof BooleanValueStream);
+ BooleanValueStream func = (BooleanValueStream) uncasted;
+
+ // No values
+ val1.setValues();
+ val2.setValue("abcdefghi").setExists(true);
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ val1.setValues("abcdefghi");
+ val2.setExists(false);
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // One value
+ val1.setValues("abcdefghi");
+ val2.setValue("abcdefghi").setExists(true);
+ Iterator<Boolean> values1 = Arrays.asList(true).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ // Multiple values
+ val1.setValues("abcdefghi", "abcdefghi1", "sbcdefghi", "abcdefghi");
+ val2.setValue("abcdefghi").setExists(true);
+ Iterator<Boolean> values2 = Arrays.asList(true, false, false, true).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value);
+ });
+ assertFalse(values2.hasNext());
+ }
+
+ @Test
+ public void oneMultiOneSingleValueStringParameterTest() {
+ TestStringValueStream val1 = new TestStringValueStream();
+ TestStringValue val2 = new TestStringValue();
+
+ AnalyticsValueStream uncasted = EqualFunction.creatorFunction.apply(new AnalyticsValueStream[] {val2, val1});
+ assertTrue(uncasted instanceof BooleanValueStream);
+ BooleanValueStream func = (BooleanValueStream) uncasted;
+
+ // No values
+ val1.setValues();
+ val2.setValue("abcdefghi").setExists(true);
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ val1.setValues("abcdefghi");
+ val2.setExists(false);
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // One value
+ val1.setValues("abcdefghi");
+ val2.setValue("abcdefghi").setExists(true);
+ Iterator<Boolean> values1 = Arrays.asList(true).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ // Multiple values
+ val1.setValues("abcdefghi", "abcdefghi1", "sbcdefghi", "abcdefghi");
+ val2.setValue("abcdefghi").setExists(true);
+ Iterator<Boolean> values2 = Arrays.asList(true, false, false, true).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value);
+ });
+ assertFalse(values2.hasNext());
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/ExistsFunctionTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/ExistsFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/ExistsFunctionTest.java
new file mode 100644
index 0000000..89fcf42
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/ExistsFunctionTest.java
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.function.mapping;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.analytics.function.mapping.ExistsFunction;
+import org.apache.solr.analytics.value.AnalyticsValueStream;
+import org.apache.solr.analytics.value.BooleanValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestBooleanValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValueStream;
+import org.junit.Test;
+
+public class ExistsFunctionTest extends SolrTestCaseJ4 {
+
+ @Test
+ public void singleValueParameterTest() {
+ TestBooleanValue val = new TestBooleanValue();
+
+ AnalyticsValueStream uncasted = ExistsFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof BooleanValue);
+ BooleanValue func = (BooleanValue) uncasted;
+
+ val.setExists(false);
+ assertFalse(func.getBoolean());
+ assertTrue(func.exists());
+
+ val.setValue(true).setExists(true);
+ assertTrue(func.getBoolean());
+ assertTrue(func.exists());
+
+ val.setValue(false).setExists(true);
+ assertTrue(func.getBoolean());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void multiValueParameterTest() {
+ TestDoubleValueStream val = new TestDoubleValueStream();
+
+ AnalyticsValueStream uncasted = ExistsFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof BooleanValue);
+ BooleanValue func = (BooleanValue) uncasted;
+
+ val.setValues(2, 30.0);
+ assertTrue(func.getBoolean());
+ assertTrue(func.exists());
+
+ val.setValues();
+ assertFalse(func.getBoolean());
+ assertTrue(func.exists());
+
+ val.setValues(21234.65);
+ assertTrue(func.getBoolean());
+ assertTrue(func.exists());
+
+ val.setValues();
+ assertFalse(func.getBoolean());
+ assertTrue(func.exists());
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/FillMissingFunctionTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/FillMissingFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/FillMissingFunctionTest.java
new file mode 100644
index 0000000..ea82193
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/FillMissingFunctionTest.java
@@ -0,0 +1,717 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.function.mapping;
+
+import java.time.Instant;
+import java.time.format.DateTimeParseException;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.Iterator;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.analytics.value.AnalyticsValue;
+import org.apache.solr.analytics.value.AnalyticsValueStream;
+import org.apache.solr.analytics.value.BooleanValue;
+import org.apache.solr.analytics.value.BooleanValueStream;
+import org.apache.solr.analytics.value.DateValue;
+import org.apache.solr.analytics.value.DateValueStream;
+import org.apache.solr.analytics.value.DoubleValue;
+import org.apache.solr.analytics.value.DoubleValueStream;
+import org.apache.solr.analytics.value.FloatValue;
+import org.apache.solr.analytics.value.FloatValueStream;
+import org.apache.solr.analytics.value.IntValue;
+import org.apache.solr.analytics.value.IntValueStream;
+import org.apache.solr.analytics.value.LongValue;
+import org.apache.solr.analytics.value.LongValueStream;
+import org.apache.solr.analytics.value.StringValue;
+import org.apache.solr.analytics.value.StringValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestAnalyticsValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestAnalyticsValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestBooleanValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestBooleanValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestDateValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestDateValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestIntValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestIntValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestLongValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestLongValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestStringValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestStringValueStream;
+import org.junit.Test;
+
+public class FillMissingFunctionTest extends SolrTestCaseJ4 {
+
+ @Test
+ public void castingTest() {
+ assertTrue(FillMissingFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestBooleanValue(), new TestStringValue()}) instanceof StringValue);
+
+ assertFalse(FillMissingFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestIntValue(), new TestFloatValue()}) instanceof IntValue);
+
+ assertFalse(FillMissingFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestBooleanValue(), new TestStringValueStream()}) instanceof AnalyticsValue);
+
+ assertFalse(FillMissingFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestLongValue(), new TestAnalyticsValue()}) instanceof LongValue);
+
+ assertTrue(FillMissingFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestIntValue(), new TestLongValue()}) instanceof DoubleValue);
+
+ assertFalse(FillMissingFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestDateValue(), new TestStringValue()}) instanceof DateValue);
+
+ assertFalse(FillMissingFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestBooleanValueStream(), new TestStringValue()}) instanceof AnalyticsValue);
+
+ assertTrue(FillMissingFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestDoubleValue(), new TestIntValueStream()}) instanceof DoubleValueStream);
+ }
+
+ @Test
+ public void singleValueBooleanTest() {
+ TestBooleanValue val = new TestBooleanValue();
+ TestBooleanValue filler = new TestBooleanValue();
+
+ AnalyticsValueStream uncasted = FillMissingFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filler});
+ assertTrue(uncasted instanceof BooleanValue);
+ BooleanValue func = (BooleanValue) uncasted;
+
+ // Value doesn't exist
+ val.setExists(false);
+ filler.setExists(false);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ // Value exists
+ val.setValue(true).setExists(true);
+ filler.setValue(false).setExists(true);
+ assertEquals(true, func.getBoolean());
+ assertTrue(func.exists());
+
+ val.setValue(false).setExists(true);
+ filler.setValue(false).setExists(true);
+ assertEquals(false, func.getBoolean());
+ assertTrue(func.exists());
+
+ val.setValue(true).setExists(true);
+ filler.setExists(false);
+ assertEquals(true, func.getBoolean());
+ assertTrue(func.exists());
+
+ val.setValue(false).setExists(true);
+ filler.setExists(false);
+ assertEquals(false, func.getBoolean());
+ assertTrue(func.exists());
+
+ val.setExists(false);
+ filler.setValue(false).setExists(true);
+ assertEquals(false, func.getBoolean());
+ assertTrue(func.exists());
+
+ val.setExists(false);
+ filler.setValue(true).setExists(true);
+ assertEquals(true, func.getBoolean());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void singleValueIntTest() {
+ TestIntValue val = new TestIntValue();
+ TestIntValue filler = new TestIntValue();
+
+ AnalyticsValueStream uncasted = FillMissingFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filler});
+ assertTrue(uncasted instanceof IntValue);
+ IntValue func = (IntValue) uncasted;
+
+ // Value doesn't exist
+ val.setExists(false);
+ filler.setExists(false);
+ func.getInt();
+ assertFalse(func.exists());
+
+ // Value exists
+ val.setValue(21).setExists(true);
+ filler.setValue(234).setExists(true);
+ assertEquals(21, func.getInt());
+ assertTrue(func.exists());
+
+ val.setExists(false);
+ filler.setValue(-234).setExists(true);
+ assertEquals(-234, func.getInt());
+ assertTrue(func.exists());
+
+ val.setValue(52334).setExists(true);
+ filler.setExists(false);
+ assertEquals(52334, func.getInt());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void singleValueLongTest() {
+ TestLongValue val = new TestLongValue();
+ TestLongValue filler = new TestLongValue();
+
+ AnalyticsValueStream uncasted = FillMissingFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filler});
+ assertTrue(uncasted instanceof LongValue);
+ LongValue func = (LongValue) uncasted;
+
+ // Value doesn't exist
+ val.setExists(false);
+ filler.setExists(false);
+ func.getLong();
+ assertFalse(func.exists());
+
+ // Value exists
+ val.setValue(21L).setExists(true);
+ filler.setValue(234L).setExists(true);
+ assertEquals(21L, func.getLong());
+ assertTrue(func.exists());
+
+ val.setExists(false);
+ filler.setValue(234L).setExists(true);
+ assertEquals(234L, func.getLong());
+ assertTrue(func.exists());
+
+ val.setValue(-52334L).setExists(true);
+ filler.setExists(false);
+ assertEquals(-52334L, func.getLong());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void singleValueFloatTest() {
+ TestFloatValue val = new TestFloatValue();
+ TestFloatValue filler = new TestFloatValue();
+
+ AnalyticsValueStream uncasted = FillMissingFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filler});
+ assertTrue(uncasted instanceof FloatValue);
+ FloatValue func = (FloatValue) uncasted;
+
+ // Value doesn't exist
+ val.setExists(false);
+ filler.setExists(false);
+ func.getFloat();
+ assertFalse(func.exists());
+
+ // Value exists
+ val.setValue(-21.324F).setExists(true);
+ filler.setValue(23423.423342F).setExists(true);
+ assertEquals(-21.324F, func.getFloat(), .00000001);
+ assertTrue(func.exists());
+
+ val.setExists(false);
+ filler.setValue(3124123.32F).setExists(true);
+ assertEquals(3124123.32F, func.getFloat(), .00000001);
+ assertTrue(func.exists());
+
+ val.setValue(2345.345543F).setExists(true);
+ filler.setExists(false);
+ assertEquals(2345.345543F, func.getFloat(), .00000001);
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void singleValueDoubleTest() {
+ TestDoubleValue val = new TestDoubleValue();
+ TestDoubleValue filler = new TestDoubleValue();
+
+ AnalyticsValueStream uncasted = FillMissingFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filler});
+ assertTrue(uncasted instanceof DoubleValue);
+ DoubleValue func = (DoubleValue) uncasted;
+
+ // Value doesn't exist
+ val.setExists(false);
+ filler.setExists(false);
+ func.getDouble();
+ assertFalse(func.exists());
+
+ // Value exists
+ val.setValue(-21.324).setExists(true);
+ filler.setValue(23423.423342).setExists(true);
+ assertEquals(-21.324, func.getDouble(), .00000001);
+ assertTrue(func.exists());
+
+ val.setExists(false);
+ filler.setValue(3124123.32).setExists(true);
+ assertEquals(3124123.32, func.getDouble(), .00000001);
+ assertTrue(func.exists());
+
+ val.setValue(2345.345543).setExists(true);
+ filler.setExists(false);
+ assertEquals(2345.345543, func.getDouble(), .00000001);
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void singleValueDateTest() throws DateTimeParseException {
+ Date date1 = Date.from(Instant.parse("1810-12-02T10:30:15Z"));
+ Date date2 = Date.from(Instant.parse("1950-02-23T14:54:34Z"));
+ Date date3 = Date.from(Instant.parse("2023-11-01T20:30:15Z"));
+
+ TestDateValue val = new TestDateValue();
+ TestDateValue filler = new TestDateValue();
+
+ AnalyticsValueStream uncasted = FillMissingFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filler});
+ assertTrue(uncasted instanceof DateValue);
+ DateValue func = (DateValue) uncasted;
+
+ // Value doesn't exist
+ val.setExists(false);
+ filler.setExists(false);
+ func.getLong();
+ assertFalse(func.exists());
+
+ // Value exists
+ val.setValue("1810-12-02T10:30:15Z").setExists(true);
+ filler.setValue("2023-11-01T20:30:15Z").setExists(true);
+ assertEquals(date1.getTime(), func.getLong());
+ assertTrue(func.exists());
+
+ val.setExists(false);
+ filler.setValue("1950-02-23T14:54:34Z").setExists(true);
+ assertEquals(date2.getTime(), func.getLong());
+ assertTrue(func.exists());
+
+ val.setValue("2023-11-01T20:30:15Z").setExists(true);
+ filler.setExists(false);
+ assertEquals(date3.getTime(), func.getLong());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void singleValueStringTest() {
+ TestStringValue val = new TestStringValue();
+ TestStringValue filler = new TestStringValue();
+
+ AnalyticsValueStream uncasted = FillMissingFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filler});
+ assertTrue(uncasted instanceof StringValue);
+ StringValue func = (StringValue) uncasted;
+
+ // Value doesn't exist
+ val.setExists(false);
+ filler.setExists(false);
+ func.getString();
+ assertFalse(func.exists());
+
+ // Value exists
+ val.setValue("abc123").setExists(true);
+ filler.setValue("def456").setExists(true);
+ assertEquals("abc123", func.getString());
+ assertTrue(func.exists());
+
+ val.setExists(false);
+ filler.setValue("abc456").setExists(true);
+ assertEquals("abc456", func.getString());
+ assertTrue(func.exists());
+
+ val.setValue("def123").setExists(true);
+ filler.setExists(false);
+ assertEquals("def123", func.getString());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void singleValueObjectTest() {
+ TestAnalyticsValue val = new TestAnalyticsValue();
+ TestAnalyticsValue filler = new TestAnalyticsValue();
+
+ AnalyticsValueStream uncasted = FillMissingFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filler});
+ assertTrue(uncasted instanceof AnalyticsValue);
+ AnalyticsValue func = (AnalyticsValue) uncasted;
+
+ // Value doesn't exist
+ val.setExists(false);
+ filler.setExists(false);
+ func.getObject();
+ assertFalse(func.exists());
+
+ // Value exists
+ val.setValue("abc123").setExists(true);
+ filler.setValue(new Date(123)).setExists(true);
+ assertEquals("abc123", func.getObject());
+ assertTrue(func.exists());
+
+ val.setExists(false);
+ filler.setValue(new Boolean(true)).setExists(true);
+ assertEquals(new Boolean(true), func.getObject());
+ assertTrue(func.exists());
+
+ val.setValue(new Long(234)).setExists(true);
+ filler.setExists(false);
+ assertEquals(new Long(234), func.getObject());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void multiValueBooleanTest() {
+ TestBooleanValueStream val = new TestBooleanValueStream();
+ TestBooleanValueStream filler = new TestBooleanValueStream();
+
+ AnalyticsValueStream uncasted = FillMissingFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filler});
+ assertTrue(uncasted instanceof BooleanValueStream);
+ BooleanValueStream func = (BooleanValueStream) uncasted;
+
+ // No values
+ val.setValues();
+ filler.setValues();
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Values exist
+ val.setValues(true);
+ filler.setValues(true, false);
+ Iterator<Boolean> values1 = Arrays.asList(true).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ val.setValues();
+ filler.setValues(true, false);
+ Iterator<Boolean> values2 = Arrays.asList(true, false).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value);
+ });
+ assertFalse(values2.hasNext());
+
+ val.setValues(true, false, true);
+ filler.setValues();
+ Iterator<Boolean> values3 = Arrays.asList(true, false, true).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values3.hasNext());
+ assertEquals(values3.next(), value);
+ });
+ assertFalse(values3.hasNext());
+ }
+
+ @Test
+ public void multiValueIntTest() {
+ TestIntValueStream val = new TestIntValueStream();
+ TestIntValueStream filler = new TestIntValueStream();
+
+ AnalyticsValueStream uncasted = FillMissingFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filler});
+ assertTrue(uncasted instanceof IntValueStream);
+ IntValueStream func = (IntValueStream) uncasted;
+
+ // No values
+ val.setValues();
+ filler.setValues();
+ func.streamInts( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Values exist
+ val.setValues(323, -9423);
+ filler.setValues(-1234, 5433, -73843, 1245144);
+ Iterator<Integer> values1 = Arrays.asList(323, -9423).iterator();
+ func.streamInts( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next().intValue(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ val.setValues();
+ filler.setValues(312423, -12343, -23, 2);
+ Iterator<Integer> values2 = Arrays.asList(312423, -12343, -23, 2).iterator();
+ func.streamInts( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next().intValue(), value);
+ });
+ assertFalse(values2.hasNext());
+
+ val.setValues(1423, -413543);
+ filler.setValues();
+ Iterator<Integer> values3 = Arrays.asList(1423, -413543).iterator();
+ func.streamInts( value -> {
+ assertTrue(values3.hasNext());
+ assertEquals(values3.next().intValue(), value);
+ });
+ assertFalse(values3.hasNext());
+ }
+
+ @Test
+ public void multiValueLongTest() {
+ TestLongValueStream val = new TestLongValueStream();
+ TestLongValueStream filler = new TestLongValueStream();
+
+ AnalyticsValueStream uncasted = FillMissingFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filler});
+ assertTrue(uncasted instanceof LongValueStream);
+ LongValueStream func = (LongValueStream) uncasted;
+
+ // No values
+ val.setValues();
+ filler.setValues();
+ func.streamLongs( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Values exist
+ val.setValues(323L, -9423L);
+ filler.setValues(-1234L, -5433L, -73843L, 1245144L);
+ Iterator<Long> values1 = Arrays.asList(323L, -9423L).iterator();
+ func.streamLongs( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next().longValue(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ val.setValues();
+ filler.setValues(-312423L, 12343L, 23L, 2L);
+ Iterator<Long> values2 = Arrays.asList(-312423L, 12343L, 23L, 2L).iterator();
+ func.streamLongs( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next().longValue(), value);
+ });
+ assertFalse(values2.hasNext());
+
+ val.setValues(1423L, -413543L);
+ filler.setValues();
+ Iterator<Long> values3 = Arrays.asList(1423L, -413543L).iterator();
+ func.streamLongs( value -> {
+ assertTrue(values3.hasNext());
+ assertEquals(values3.next().longValue(), value);
+ });
+ assertFalse(values3.hasNext());
+ }
+
+ @Test
+ public void multiValueFloatTest() {
+ TestFloatValueStream val = new TestFloatValueStream();
+ TestFloatValueStream filler = new TestFloatValueStream();
+
+ AnalyticsValueStream uncasted = FillMissingFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filler});
+ assertTrue(uncasted instanceof FloatValueStream);
+ FloatValueStream func = (FloatValueStream) uncasted;
+
+ // No values
+ val.setValues();
+ filler.setValues();
+ func.streamFloats( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Values exist
+ val.setValues(323.213F, -9423.5F);
+ filler.setValues(-1234.9478F, -5433.234F, -73843F, 1245144.2342F);
+ Iterator<Float> values1 = Arrays.asList(323.213F, -9423.5F).iterator();
+ func.streamFloats( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value, .00000001);
+ });
+ assertFalse(values1.hasNext());
+
+ val.setValues();
+ filler.setValues(-312423.2F, 12343.234823F, 23.582F, 2.23F);
+ Iterator<Float> values2 = Arrays.asList(-312423.2F, 12343.234823F, 23.582F, 2.23F).iterator();
+ func.streamFloats( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value, .00000001);
+ });
+ assertFalse(values2.hasNext());
+
+ val.setValues(1423.23039F, -413543F);
+ filler.setValues();
+ Iterator<Float> values3 = Arrays.asList(1423.23039F, -413543F).iterator();
+ func.streamFloats( value -> {
+ assertTrue(values3.hasNext());
+ assertEquals(values3.next(), value, .00000001);
+ });
+ assertFalse(values3.hasNext());
+ }
+
+ @Test
+ public void multiValueDoubleTest() {
+ TestDoubleValueStream val = new TestDoubleValueStream();
+ TestDoubleValueStream filler = new TestDoubleValueStream();
+
+ AnalyticsValueStream uncasted = FillMissingFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filler});
+ assertTrue(uncasted instanceof DoubleValueStream);
+ DoubleValueStream func = (DoubleValueStream) uncasted;
+
+ // No values
+ val.setValues();
+ filler.setValues();
+ func.streamDoubles( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Values exist
+ val.setValues(323.213, -9423.5);
+ filler.setValues(-1234.9478, -5433.234, -73843.0, 1245144.2342);
+ Iterator<Double> values1 = Arrays.asList(323.213, -9423.5).iterator();
+ func.streamDoubles( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value, .00000001);
+ });
+ assertFalse(values1.hasNext());
+
+ val.setValues();
+ filler.setValues(-312423.2, 12343.234823, 23.582, 2.23);
+ Iterator<Double> values2 = Arrays.asList(-312423.2, 12343.234823, 23.582, 2.23).iterator();
+ func.streamDoubles( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value, .00000001);
+ });
+ assertFalse(values2.hasNext());
+
+ val.setValues(1423.23039, -413543.0);
+ filler.setValues();
+ Iterator<Double> values3 = Arrays.asList(1423.23039, -413543.0).iterator();
+ func.streamDoubles( value -> {
+ assertTrue(values3.hasNext());
+ assertEquals(values3.next(), value, .00000001);
+ });
+ assertFalse(values3.hasNext());
+ }
+
+ @Test
+ public void multiValueDateTest() throws DateTimeParseException {
+ Date date1 = Date.from(Instant.parse("1810-12-02T10:30:15Z"));
+ Date date2 = Date.from(Instant.parse("1931-03-16T18:15:45Z"));
+ Date date3 = Date.from(Instant.parse("2023-11-01T20:30:15Z"));
+
+ TestDateValueStream val = new TestDateValueStream();
+ TestDateValueStream filler = new TestDateValueStream();
+
+ AnalyticsValueStream uncasted = FillMissingFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filler});
+ assertTrue(uncasted instanceof DateValueStream);
+ DateValueStream func = (DateValueStream) uncasted;
+
+ // No values
+ val.setValues();
+ filler.setValues();
+ func.streamLongs( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Values exist
+ val.setValues("1810-12-02T10:30:15Z");
+ filler.setValues("1931-03-16T18:15:45Z", "2023-11-01T20:30:15Z");
+ Iterator<Long> values1 = Arrays.asList(date1.getTime()).iterator();
+ func.streamLongs( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next().longValue(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ val.setValues();
+ filler.setValues("1931-03-16T18:15:45Z", "1810-12-02T10:30:15Z");
+ Iterator<Long> values2 = Arrays.asList(date2.getTime(), date1.getTime()).iterator();
+ func.streamLongs( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next().longValue(), value);
+ });
+ assertFalse(values2.hasNext());
+
+ val.setValues("2023-11-01T20:30:15Z", "1931-03-16T18:15:45Z");
+ filler.setValues();
+ Iterator<Long> values3 = Arrays.asList(date3.getTime(), date2.getTime()).iterator();
+ func.streamLongs( value -> {
+ assertTrue(values3.hasNext());
+ assertEquals(values3.next().longValue(), value);
+ });
+ assertFalse(values3.hasNext());
+ }
+
+ @Test
+ public void multiValueStringTest() {
+ TestStringValueStream val = new TestStringValueStream();
+ TestStringValueStream filler = new TestStringValueStream();
+
+ AnalyticsValueStream uncasted = FillMissingFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filler});
+ assertTrue(uncasted instanceof StringValueStream);
+ StringValueStream func = (StringValueStream) uncasted;
+
+ // No values
+ val.setValues();
+ filler.setValues();
+ func.streamStrings( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Values exist
+ val.setValues("abc");
+ filler.setValues("123", "def");
+ Iterator<String> values1 = Arrays.asList("abc").iterator();
+ func.streamStrings( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ val.setValues();
+ filler.setValues("def", "12341");
+ Iterator<String> values2 = Arrays.asList("def", "12341").iterator();
+ func.streamStrings( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value);
+ });
+ assertFalse(values2.hasNext());
+
+ val.setValues("string1", "another string", "the final and last string");
+ filler.setValues();
+ Iterator<String> values3 = Arrays.asList("string1", "another string", "the final and last string").iterator();
+ func.streamStrings( value -> {
+ assertTrue(values3.hasNext());
+ assertEquals(values3.next(), value);
+ });
+ assertFalse(values3.hasNext());
+ }
+
+ @Test
+ public void multiValueObjectTest() {
+ TestAnalyticsValueStream val = new TestAnalyticsValueStream();
+ TestAnalyticsValueStream filler = new TestAnalyticsValueStream();
+
+ AnalyticsValueStream func = FillMissingFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filler});
+
+ // No values
+ val.setValues();
+ filler.setValues();
+ func.streamObjects( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Values exist
+ val.setValues("asdfs");
+ filler.setValues(new Date(12312), new Long(213123L));
+ Iterator<Object> values1 = Arrays.<Object>asList("asdfs").iterator();
+ func.streamObjects( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ val.setValues();
+ filler.setValues(new Double(3234.42), "replacement");
+ Iterator<Object> values2 = Arrays.<Object>asList(new Double(3234.42), "replacement").iterator();
+ func.streamObjects( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value);
+ });
+ assertFalse(values2.hasNext());
+
+ val.setValues(new Date(3), "3", new Float(3F));
+ filler.setValues();
+ Iterator<Object> values3 = Arrays.<Object>asList(new Date(3), "3", new Float(3F)).iterator();
+ func.streamObjects( value -> {
+ assertTrue(values3.hasNext());
+ assertEquals(values3.next(), value);
+ });
+ assertFalse(values3.hasNext());
+ }
+}
[19/20] lucene-solr:master: SOLR-11145,
SOLR-11146: Added comprehensive unit tests for Analytics Component
2.0 as well as analytics bug fixes.
Posted by dp...@apache.org.
SOLR-11145, SOLR-11146: Added comprehensive unit tests for Analytics Component 2.0 as well as analytics bug fixes.
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/86d84bff
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/86d84bff
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/86d84bff
Branch: refs/heads/master
Commit: 86d84bff82ff8c7a1f6cadfe307685a4dce2f8d9
Parents: 5446979
Author: Houston Putman <hp...@bloomberg.net>
Authored: Tue Aug 1 15:01:17 2017 +0000
Committer: Dennis Gove <dp...@gmail.com>
Committed: Tue Oct 17 13:52:02 2017 -0400
----------------------------------------------------------------------
.../solr/analytics/AnalyticsRequestParser.java | 26 -
.../solr/analytics/ExpressionFactory.java | 136 +-
.../function/field/AnalyticsField.java | 5 +
.../function/mapping/BottomFunction.java | 4 +-
.../function/mapping/CompareFunction.java | 614 ---------
.../function/mapping/ComparisonFunction.java | 318 +++++
.../function/mapping/ConcatFunction.java | 95 +-
.../function/mapping/DateMathFunction.java | 8 +-
.../function/mapping/DateParseFunction.java | 24 +-
.../DecimalNumericConversionFunction.java | 271 ++++
.../function/mapping/EqualFunction.java | 238 ++++
.../function/mapping/ExistsFunction.java | 123 ++
.../function/mapping/FillMissingFunction.java | 5 +-
.../function/mapping/FilterFunction.java | 3 +-
.../analytics/function/mapping/IfFunction.java | 3 +-
.../function/mapping/JoinFunction.java | 57 -
.../function/mapping/LogicFunction.java | 2 +-
.../mapping/NumericConvertFunction.java | 256 ----
.../function/mapping/RemoveFunction.java | 39 +-
.../function/mapping/ReplaceFunction.java | 65 +-
.../analytics/function/mapping/TopFunction.java | 4 +-
.../function/reduction/DocCountFunction.java | 2 +-
.../function/reduction/MeanFunction.java | 97 ++
.../function/reduction/OrdinalFunction.java | 44 +-
.../function/reduction/PercentileFunction.java | 16 +-
.../function/reduction/SumFunction.java | 2 +-
.../reduction/data/SortedListCollector.java | 25 +-
.../plugin/AnalyticsStatisticsCollector.java | 104 --
.../solr/analytics/util/OldAnalyticsParams.java | 3 +-
.../solr/analytics/util/OrdinalCalculator.java | 5 +-
.../solr/analytics/value/AnalyticsValue.java | 6 +-
.../analytics/value/AnalyticsValueStream.java | 17 +
.../solr/analytics/value/BooleanValue.java | 8 +
.../analytics/value/BooleanValueStream.java | 4 +
.../apache/solr/analytics/value/DateValue.java | 11 +-
.../solr/analytics/value/DateValueStream.java | 6 +-
.../solr/analytics/value/DoubleValue.java | 8 +
.../solr/analytics/value/DoubleValueStream.java | 4 +
.../apache/solr/analytics/value/FloatValue.java | 8 +
.../solr/analytics/value/FloatValueStream.java | 4 +
.../apache/solr/analytics/value/IntValue.java | 8 +
.../solr/analytics/value/IntValueStream.java | 4 +
.../apache/solr/analytics/value/LongValue.java | 8 +
.../solr/analytics/value/LongValueStream.java | 4 +
.../solr/analytics/value/StringValue.java | 8 +
.../solr/analytics/value/StringValueStream.java | 4 +
.../analytics/value/constant/ConstantValue.java | 73 +-
.../test-files/solr/analytics/expressions.txt | 65 -
.../test-files/solr/analytics/facetSorting.txt | 4 -
.../solr/analytics/fieldFacetExtras.txt | 66 -
.../test-files/solr/analytics/fieldFacets.txt | 132 --
.../src/test-files/solr/analytics/functions.txt | 57 -
.../solr/analytics/legacy/expressions.txt | 65 +
.../solr/analytics/legacy/facetSorting.txt | 4 +
.../solr/analytics/legacy/fieldFacetExtras.txt | 66 +
.../solr/analytics/legacy/fieldFacets.txt | 132 ++
.../solr/analytics/legacy/functions.txt | 57 +
.../solr/analytics/legacy/noFacets.txt | 74 ++
.../solr/analytics/legacy/queryFacets.txt | 27 +
.../solr/analytics/legacy/rangeFacets.txt | 161 +++
.../src/test-files/solr/analytics/noFacets.txt | 74 --
.../test-files/solr/analytics/queryFacets.txt | 27 -
.../test-files/solr/analytics/rangeFacets.txt | 161 ---
.../solr/collection1/conf/schema-analytics.xml | 123 +-
.../configsets/cloud-analytics/conf/schema.xml | 66 +-
.../AbstractAnalyticsStatsCloudTest.java | 187 ---
.../analytics/AbstractAnalyticsStatsTest.java | 235 ----
.../solr/analytics/ExpressionFactoryTest.java | 249 ++++
.../apache/solr/analytics/NoFacetCloudTest.java | 557 --------
.../org/apache/solr/analytics/NoFacetTest.java | 536 +++-----
.../solr/analytics/OverallAnalyticsTest.java | 320 +++++
.../solr/analytics/SolrAnalyticsTestCase.java | 349 +++++
.../analytics/expression/ExpressionTest.java | 201 ---
.../solr/analytics/expression/FunctionTest.java | 221 ----
.../facet/AbstractAnalyticsFacetCloudTest.java | 284 ----
.../facet/AbstractAnalyticsFacetTest.java | 343 -----
.../solr/analytics/facet/FacetSortingTest.java | 53 -
.../analytics/facet/FieldFacetCloudTest.java | 1212 ------------------
.../facet/FieldFacetExtrasCloudTest.java | 253 ----
.../analytics/facet/FieldFacetExtrasTest.java | 170 ---
.../solr/analytics/facet/FieldFacetTest.java | 1065 ---------------
.../solr/analytics/facet/PivotFacetTest.java | 230 ++++
.../analytics/facet/QueryFacetCloudTest.java | 159 ---
.../solr/analytics/facet/QueryFacetTest.java | 150 +--
.../analytics/facet/RangeFacetCloudTest.java | 588 ---------
.../solr/analytics/facet/RangeFacetTest.java | 620 ++++-----
.../facet/SolrAnalyticsFacetTestCase.java | 80 ++
.../solr/analytics/facet/ValueFacetTest.java | 433 +++++++
.../field/AbstractAnalyticsFieldTest.java | 299 +++++
.../function/field/BooleanFieldsTest.java | 71 +
.../function/field/DateFieldsTest.java | 108 ++
.../function/field/DoubleFieldsTest.java | 108 ++
.../function/field/FloatFieldsTest.java | 108 ++
.../analytics/function/field/IntFieldsTest.java | 108 ++
.../function/field/LongFieldsTest.java | 108 ++
.../function/field/StringFieldsTest.java | 71 +
.../mapping/AbsoluteValueFunctionTest.java | 267 ++++
.../function/mapping/AddFunctionTest.java | 156 +++
.../function/mapping/AndFunctionTest.java | 192 +++
.../function/mapping/BottomFunctionTest.java | 406 ++++++
.../function/mapping/CeilingFunctionTest.java | 180 +++
.../function/mapping/ConcatFunctionTest.java | 317 +++++
.../function/mapping/DateMathFunctionTest.java | 127 ++
.../function/mapping/DateParseFunctionTest.java | 245 ++++
.../function/mapping/DivideFunctionTest.java | 128 ++
.../function/mapping/EqualFunctionTest.java | 530 ++++++++
.../function/mapping/ExistsFunctionTest.java | 74 ++
.../mapping/FillMissingFunctionTest.java | 717 +++++++++++
.../function/mapping/FilterFunctionTest.java | 1035 +++++++++++++++
.../function/mapping/FloorFunctionTest.java | 180 +++
.../function/mapping/GTEFunctionTest.java | 290 +++++
.../function/mapping/GTFunctionTest.java | 290 +++++
.../function/mapping/IfFunctionTest.java | 994 ++++++++++++++
.../function/mapping/LTEFunctionTest.java | 290 +++++
.../function/mapping/LTFunctionTest.java | 290 +++++
.../function/mapping/LogFunctionTest.java | 186 +++
.../function/mapping/MultFunctionTest.java | 155 +++
.../function/mapping/NegateFunctionTest.java | 327 +++++
.../function/mapping/OrFunctionTest.java | 192 +++
.../function/mapping/PowerFunctionTest.java | 128 ++
.../function/mapping/RemoveFunctionTest.java | 849 ++++++++++++
.../function/mapping/ReplaceFunctionTest.java | 990 ++++++++++++++
.../function/mapping/RoundFunctionTest.java | 180 +++
.../mapping/StringCastFunctionTest.java | 87 ++
.../function/mapping/SubtractFunctionTest.java | 128 ++
.../function/mapping/TopFunctionTest.java | 406 ++++++
.../LegacyAbstractAnalyticsCloudTest.java | 167 +++
.../legacy/LegacyAbstractAnalyticsTest.java | 234 ++++
.../legacy/LegacyNoFacetCloudTest.java | 551 ++++++++
.../analytics/legacy/LegacyNoFacetTest.java | 450 +++++++
.../legacy/expression/LegacyExpressionTest.java | 201 +++
.../legacy/expression/LegacyFunctionTest.java | 221 ++++
.../LegacyAbstractAnalyticsFacetCloudTest.java | 194 +++
.../facet/LegacyAbstractAnalyticsFacetTest.java | 342 +++++
.../legacy/facet/LegacyFacetSortingTest.java | 53 +
.../legacy/facet/LegacyFieldFacetCloudTest.java | 1212 ++++++++++++++++++
.../facet/LegacyFieldFacetExtrasCloudTest.java | 253 ++++
.../facet/LegacyFieldFacetExtrasTest.java | 170 +++
.../legacy/facet/LegacyFieldFacetTest.java | 1065 +++++++++++++++
.../legacy/facet/LegacyQueryFacetCloudTest.java | 159 +++
.../legacy/facet/LegacyQueryFacetTest.java | 124 ++
.../legacy/facet/LegacyRangeFacetCloudTest.java | 588 +++++++++
.../legacy/facet/LegacyRangeFacetTest.java | 417 ++++++
.../value/CastingAnalyticsValueTest.java | 56 +
.../value/CastingBooleanValueStreamTest.java | 79 ++
.../value/CastingBooleanValueTest.java | 159 +++
.../value/CastingDateValueStreamTest.java | 111 ++
.../analytics/value/CastingDateValueTest.java | 172 +++
.../value/CastingDoubleValueStreamTest.java | 79 ++
.../analytics/value/CastingDoubleValueTest.java | 159 +++
.../value/CastingFloatValueStreamTest.java | 102 ++
.../analytics/value/CastingFloatValueTest.java | 198 +++
.../value/CastingIntValueStreamTest.java | 148 +++
.../analytics/value/CastingIntValueTest.java | 276 ++++
.../value/CastingLongValueStreamTest.java | 102 ++
.../analytics/value/CastingLongValueTest.java | 198 +++
.../value/CastingStringValueStreamTest.java | 56 +
.../analytics/value/CastingStringValueTest.java | 120 ++
.../solr/analytics/value/ConstantValueTest.java | 368 ++++++
.../solr/analytics/value/FillableTestValue.java | 641 +++++++++
160 files changed, 25063 insertions(+), 8314 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/java/org/apache/solr/analytics/AnalyticsRequestParser.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/AnalyticsRequestParser.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/AnalyticsRequestParser.java
index bfa62e2..bcb7747 100644
--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/AnalyticsRequestParser.java
+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/AnalyticsRequestParser.java
@@ -73,34 +73,8 @@ public class AnalyticsRequestParser {
public static final String analyticsParamName = "analytics";
- private static Predicate<String> request = acceptNames("request", "req");
- private static Predicate<String> functions = acceptNames("functions", "funcs", "f");
- private static Predicate<String> expressions = acceptNames("expressions", "exprs", "e");
-
- private static Predicate<String> grouping = acceptNames("grouping", "group", "g");
-
- private static Predicate<String> valueFacet = acceptNames("valuefacet", "vf");
-
- private static Predicate<String> pivotFacet = acceptNames("pivotfacet", "pf");
- private static Predicate<String> pivot = acceptNames("pivot", "p");
-
- private static Predicate<String> sort = acceptNames("sort", "s");
- private static Predicate<String> sortExpression = acceptNames("expression", "expr");
- private static Predicate<String> sortFacetValue = acceptNames("facetvalue", "fv");
- private static Predicate<String> sortDirection = acceptNames("direction", "dir");
private static Predicate<String> sortAscending = acceptNames("ascending", "asc", "a");
private static Predicate<String> sortDescending = acceptNames("descending", "desc", "d");
- private static Predicate<String> sortLimit = acceptNames("limit", "l");
- private static Predicate<String> sortOffset = acceptNames("offset", "o");
-
- private static Predicate<String> rangeFacet = acceptNames("rangefacet", "rf");
- private static Predicate<String> rangeGaps = acceptNames("gaps", "g");
- private static Predicate<String> rangeHardEnd = acceptNames("hardend", "he");
- private static Predicate<String> rangeInclude = acceptNames("include", "i");
- private static Predicate<String> rangeOthers = acceptNames("others", "o");
-
- private static Predicate<String> queryFacet = acceptNames("queryfacet", "qf");
- private static Predicate<String> query = acceptNames("query", "q");
private static Predicate<String> acceptNames(String... names) {
return Pattern.compile("^(?:" + Arrays.stream(names).reduce((a,b) -> a + "|" + b).orElse("") + ")$", Pattern.CASE_INSENSITIVE).asPredicate();
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/java/org/apache/solr/analytics/ExpressionFactory.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/ExpressionFactory.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/ExpressionFactory.java
index 1d7a793..18020b7 100644
--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/ExpressionFactory.java
+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/ExpressionFactory.java
@@ -17,6 +17,7 @@
package org.apache.solr.analytics;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
@@ -28,15 +29,14 @@ import java.util.regex.Pattern;
import org.apache.solr.analytics.function.MergingReductionCollectionManager;
import org.apache.solr.analytics.function.ReductionCollectionManager;
import org.apache.solr.analytics.function.mapping.*;
-import org.apache.solr.analytics.function.mapping.CompareFunction.EqualFunction;
-import org.apache.solr.analytics.function.mapping.CompareFunction.GTEFunction;
-import org.apache.solr.analytics.function.mapping.CompareFunction.GTFunction;
-import org.apache.solr.analytics.function.mapping.CompareFunction.LTEFunction;
-import org.apache.solr.analytics.function.mapping.CompareFunction.LTFunction;
-import org.apache.solr.analytics.function.mapping.ConcatFunction.ConcatSeparatedFunction;
-import org.apache.solr.analytics.function.mapping.NumericConvertFunction.CeilingFunction;
-import org.apache.solr.analytics.function.mapping.NumericConvertFunction.FloorFunction;
-import org.apache.solr.analytics.function.mapping.NumericConvertFunction.RoundFunction;
+import org.apache.solr.analytics.function.mapping.ComparisonFunction.GTEFunction;
+import org.apache.solr.analytics.function.mapping.ComparisonFunction.GTFunction;
+import org.apache.solr.analytics.function.mapping.ComparisonFunction.LTEFunction;
+import org.apache.solr.analytics.function.mapping.ComparisonFunction.LTFunction;
+import org.apache.solr.analytics.function.mapping.ConcatFunction.SeparatedConcatFunction;
+import org.apache.solr.analytics.function.mapping.DecimalNumericConversionFunction.CeilingFunction;
+import org.apache.solr.analytics.function.mapping.DecimalNumericConversionFunction.FloorFunction;
+import org.apache.solr.analytics.function.mapping.DecimalNumericConversionFunction.RoundFunction;
import org.apache.solr.analytics.function.mapping.LogicFunction.AndFunction;
import org.apache.solr.analytics.function.mapping.LogicFunction.OrFunction;
import org.apache.solr.analytics.function.reduction.*;
@@ -177,13 +177,17 @@ public class ExpressionFactory {
/**
* Add a variable function that will be treated like a system function.
*
- * @param functionSignature the function signature of the variable function (e.g. {@code func(a,b)} )
+ * @param functionName the function's name
+ * @param functionParams the comma separated and ordered parameters of the function (e.g. {@code "a,b"} )
* @param returnSignature the return signature of the variable function (e.g. {@code div(sum(a,b),count(b))} )
* @return this factory, to easily chain function adds
* @throws SolrException if the name of the function is not unique or the syntax of either signature is incorrect
*/
- public ExpressionFactory addSystemVariableFunction(final String functionSignature, final String returnSignature) throws SolrException {
- return addVariableFunction(functionSignature, returnSignature, systemVariableFunctions);
+ public ExpressionFactory addSystemVariableFunction(final String functionName, final String functionParams, final String returnSignature) throws SolrException {
+ return addVariableFunction(functionName,
+ Arrays.stream(functionParams.split(",")).map(param -> param.trim()).toArray(size -> new String[size]),
+ returnSignature,
+ systemVariableFunctions);
}
/**
@@ -210,12 +214,29 @@ public class ExpressionFactory {
private ExpressionFactory addVariableFunction(final String functionSignature,
final String returnSignature,
Map<String,VariableFunctionInfo> variableFunctions) throws SolrException {
- String functionName = getFunctionName(functionSignature);
+ addVariableFunction(getFunctionName(functionSignature), getParams(functionSignature, null, null), returnSignature, variableFunctions);
+ return this;
+ }
+
+ /**
+ * Add a variable function to the given map of variable functions.
+ *
+ * @param functionName the function's name
+ * @param functionParams the parameters of the function (this is ordered)
+ * @param returnSignature the return signature of the variable function (e.g. {@code div(sum(a,b),count(b))} )
+ * @param variableFunctions the map of variable functions to add the new function to
+ * @return this factory, to easily chain function adds
+ * @throws SolrException if the name of the function is not unique or the syntax of either signature is incorrect
+ */
+ private ExpressionFactory addVariableFunction(final String functionName,
+ final String[] functionParams,
+ final String returnSignature,
+ Map<String,VariableFunctionInfo> variableFunctions) throws SolrException {
if (expressionCreators.containsKey(functionName)) {
throw new SolrException(ErrorCode.BAD_REQUEST,"Users cannot define a variable function with the same name as an existing function: " + functionName);
}
VariableFunctionInfo varFuncInfo = new VariableFunctionInfo();
- varFuncInfo.params = getParams(functionSignature, null, null);
+ varFuncInfo.params = functionParams;
varFuncInfo.returnSignature = returnSignature;
variableFunctions.put(functionName, varFuncInfo);
return this;
@@ -292,13 +313,9 @@ public class ExpressionFactory {
// Not a constant
// If the expression has parens, it is an expression otherwise it is a field
if (!expressionStr.contains("(")) {
- try {
- // Try to make a field out of it
- expression = createField(schema.getField(expressionStr));
- isField = true;
- } catch (SolrException e2) {
- throw new SolrException(ErrorCode.BAD_REQUEST,"The following is not a field, constant or function : " + expressionStr);
- }
+ // Try to make a field out of it
+ expression = createField(schema.getField(expressionStr));
+ isField = true;
} else {
// Must be a function
expression = createFunction(expressionStr, varFuncParams, varFuncVarParamName, varFuncVarParamValues);
@@ -367,6 +384,9 @@ public class ExpressionFactory {
final String[] params = getParams(expressionStr, varFuncVarParamName, varFuncVarParamValues);
AnalyticsValueStream[] paramStreams = new AnalyticsValueStream[params.length];
+
+ boolean allParamsConstant = true;
+
for (int i = 0; i < params.length; i++) {
// First check if the parameter is a variable function variable otherwise create the expression
if (varFuncParams.containsKey(params[i])) {
@@ -374,7 +394,11 @@ public class ExpressionFactory {
} else {
paramStreams[i] = createExpression(params[i], varFuncParams, varFuncVarParamName, varFuncVarParamValues);
}
+
+ // Then update whether all of the params are constant
+ allParamsConstant &= paramStreams[i].getExpressionType().equals(ExpressionType.CONST);
}
+
// Check to see if the function name is a variable function name, if so apply the variables to the return signature
if (variableFunctions.containsKey(name)) {
if (variableFunctionNameHistory.contains(name)) {
@@ -386,6 +410,10 @@ public class ExpressionFactory {
boolean varLenEnd = false;
+ if (paramStreams.length < newVarFunc.params.length) {
+ throw new SolrException(ErrorCode.BAD_REQUEST,"The variable function '" + name + "' requires at least " + newVarFunc.params.length + " parameters."
+ + " Only " + paramStreams.length + " arguments given in the following invocation : " + expressionStr);
+ }
for (int i = 0; i < newVarFunc.params.length; ++i) {
String variable = newVarFunc.params[i];
if (variable.endsWith(variableLengthParamSuffix)) {
@@ -408,16 +436,23 @@ public class ExpressionFactory {
}
}
if (!varLenEnd) {
+ if (paramStreams.length > newVarFunc.params.length) {
+ throw new SolrException(ErrorCode.BAD_REQUEST,"The variable function '" + name + "' requires " + newVarFunc.params.length + " parameters."
+ + " " + paramStreams.length + " arguments given in the following invocation : " + expressionStr);
+ }
expression = createExpression(newVarFunc.returnSignature, newVarFuncParams, null, null);
}
variableFunctionNameHistory.remove(name);
- return expression;
} else if (expressionCreators.containsKey(name)) {
// It is a regular system 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;
}
@@ -751,19 +786,18 @@ public class ExpressionFactory {
expressionCreators.put(BottomFunction.name, BottomFunction.creatorFunction);
expressionCreators.put(CeilingFunction.name, CeilingFunction.creatorFunction);
expressionCreators.put(ConcatFunction.name, ConcatFunction.creatorFunction);
- expressionCreators.put(ConcatSeparatedFunction.name, ConcatSeparatedFunction.creatorFunction);
+ expressionCreators.put(SeparatedConcatFunction.name, SeparatedConcatFunction.creatorFunction);
expressionCreators.put(DateMathFunction.name, DateMathFunction.creatorFunction);
expressionCreators.put(DateParseFunction.name, DateParseFunction.creatorFunction);
expressionCreators.put(DivideFunction.name, DivideFunction.creatorFunction);
- expressionCreators.put(DocCountFunction.name, DocCountFunction.creatorFunction);
expressionCreators.put(EqualFunction.name,EqualFunction.creatorFunction);
+ expressionCreators.put(ExistsFunction.name,ExistsFunction.creatorFunction);
expressionCreators.put(FillMissingFunction.name, FillMissingFunction.creatorFunction);
expressionCreators.put(FilterFunction.name, FilterFunction.creatorFunction);
expressionCreators.put(FloorFunction.name, FloorFunction.creatorFunction);
expressionCreators.put(GTFunction.name,GTFunction.creatorFunction);
expressionCreators.put(GTEFunction.name,GTEFunction.creatorFunction);
expressionCreators.put(IfFunction.name, IfFunction.creatorFunction);
- expressionCreators.put(JoinFunction.name, JoinFunction.creatorFunction);
expressionCreators.put(LogFunction.name,LogFunction.creatorFunction);
expressionCreators.put(LTFunction.name,LTFunction.creatorFunction);
expressionCreators.put(LTEFunction.name,LTEFunction.creatorFunction);
@@ -780,7 +814,9 @@ public class ExpressionFactory {
// Reduction 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);
@@ -790,14 +826,13 @@ public class ExpressionFactory {
expressionCreators.put(UniqueFunction.name, UniqueFunction.creatorFunction);
// Variables
- addSystemVariableFunction("wmean(a,b)","div(mean(prod(a,b)),sum(b))");
- addSystemVariableFunction("mean(a)","div(sum(a),count(a))");
- addSystemVariableFunction("sumofsquares(a)","sum(pow(a,2))");
- addSystemVariableFunction("sqrt(a)","pow(a,0.5)");
- addSystemVariableFunction("variance(a)","sub(mean(pow(a,2)),pow(mean(a),2))");
- addSystemVariableFunction("stddev(a)","sqrt(variance(a))");
- addSystemVariableFunction("csv(a..)","concatsep(',',a)");
- addSystemVariableFunction("csv_output(a..)","concatsep(',',a:fillmissing(join(_,';'),''))");
+ addSystemVariableFunction(WeightedMeanVariableFunction.name, WeightedMeanVariableFunction.params, WeightedMeanVariableFunction.function);
+ addSystemVariableFunction(SumOfSquaresVariableFunction.name, SumOfSquaresVariableFunction.params, SumOfSquaresVariableFunction.function);
+ addSystemVariableFunction(SquareRootVariableFunction.name, SquareRootVariableFunction.params, SquareRootVariableFunction.function);
+ addSystemVariableFunction(VarianceVariableFunction.name, VarianceVariableFunction.params, VarianceVariableFunction.function);
+ addSystemVariableFunction(SandardDeviationVariableFunction.name, SandardDeviationVariableFunction.params, SandardDeviationVariableFunction.function);
+ addSystemVariableFunction(CSVVariableFunction.name, CSVVariableFunction.params, CSVVariableFunction.function);
+ addSystemVariableFunction(CSVOutputVariableFunction.name, CSVOutputVariableFunction.params, CSVOutputVariableFunction.function);
}
/**
@@ -818,4 +853,39 @@ public class ExpressionFactory {
class VariableFunctionInfo {
public String[] params;
public String returnSignature;
+}
+class WeightedMeanVariableFunction {
+ public static final String name = "wmean";
+ public static final String params = "a,b";
+ public static final String function = DivideFunction.name+"("+SumFunction.name+"("+MultFunction.name+"(a,b)),"+SumFunction.name+"("+FilterFunction.name+"(b,"+ExistsFunction.name+"(a))))";
+}
+class SumOfSquaresVariableFunction {
+ public static final String name = "sumofsquares";
+ public static final String params = "a";
+ public static final String function = SumFunction.name+"("+PowerFunction.name+"(a,2))";
+}
+class SquareRootVariableFunction {
+ public static final String name = "sqrt";
+ public static final String params = "a";
+ public static final String function = PowerFunction.name+"(a,0.5)";
+}
+class VarianceVariableFunction {
+ public static final String name = "variance";
+ public static final String params = "a";
+ public static final String function = SubtractFunction.name+"("+MeanFunction.name+"("+PowerFunction.name+"(a,2)),"+PowerFunction.name+"("+MeanFunction.name+"(a),2))";
+}
+class SandardDeviationVariableFunction {
+ public static final String name = "stddev";
+ public static final String params = "a";
+ public static final String function = SquareRootVariableFunction.name+"("+VarianceVariableFunction.name+"(a))";
+}
+class CSVVariableFunction {
+ public static final String name = "csv";
+ public static final String params = "a"+ExpressionFactory.variableLengthParamSuffix;
+ public static final String function = SeparatedConcatFunction.name+"(',',a)";
+}
+class CSVOutputVariableFunction {
+ public static final String name = "csv_output";
+ public static final String params = "a"+ExpressionFactory.variableLengthParamSuffix;
+ public static final String function = "concat_sep(',',a"+ExpressionFactory.variableForEachSep+FillMissingFunction.name+"("+SeparatedConcatFunction.name+"(';',"+ExpressionFactory.variableForEachParam+"),''))";
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/field/AnalyticsField.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/field/AnalyticsField.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/field/AnalyticsField.java
index dab0358..e0bbb4b 100644
--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/field/AnalyticsField.java
+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/field/AnalyticsField.java
@@ -50,6 +50,11 @@ public abstract class AnalyticsField implements AnalyticsValueStream {
return ExpressionType.FIELD;
}
+ @Override
+ public AnalyticsValueStream convertToConstant() {
+ return this;
+ }
+
/**
* Set the segment reader context
*
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/BottomFunction.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/BottomFunction.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/BottomFunction.java
index f896da4..10674fd 100644
--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/BottomFunction.java
+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/BottomFunction.java
@@ -141,7 +141,7 @@ public class BottomFunction {
}
if (param instanceof StringValueStream) {
if (params.length == 1) {
- return LambdaFunction.createStringLambdaFunction(name, (a,b) -> (a.compareTo(b)<=0)? a:b, (StringValueStream)param);
+ return LambdaFunction.createStringLambdaFunction(name, (a,b) -> (a.compareTo(b)<0)? a:b, (StringValueStream)param);
}
StringValue[] castedParams = new StringValue[params.length];
boolean tryNextType = false;
@@ -154,7 +154,7 @@ public class BottomFunction {
}
}
if (!tryNextType) {
- return LambdaFunction.createStringLambdaFunction(name, (a,b) -> (a.compareTo(b)<=0)? a:b, castedParams, false);
+ return LambdaFunction.createStringLambdaFunction(name, (a,b) -> (a.compareTo(b)<0)? a:b, castedParams, false);
}
}
throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires a comparable parameter. " +
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/CompareFunction.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/CompareFunction.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/CompareFunction.java
deleted file mode 100644
index a06f7b8..0000000
--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/CompareFunction.java
+++ /dev/null
@@ -1,614 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.solr.analytics.function.mapping;
-
-import org.apache.solr.analytics.ExpressionFactory.CreatorFunction;
-import org.apache.solr.analytics.util.function.BooleanConsumer;
-import org.apache.solr.analytics.value.AnalyticsValue;
-import org.apache.solr.analytics.value.AnalyticsValueStream;
-import org.apache.solr.analytics.value.BooleanValue;
-import org.apache.solr.analytics.value.BooleanValueStream;
-import org.apache.solr.analytics.value.DateValue;
-import org.apache.solr.analytics.value.DateValueStream;
-import org.apache.solr.analytics.value.DoubleValue;
-import org.apache.solr.analytics.value.DoubleValueStream;
-import org.apache.solr.analytics.value.StringValue;
-import org.apache.solr.analytics.value.StringValueStream;
-import org.apache.solr.analytics.value.BooleanValue.AbstractBooleanValue;
-import org.apache.solr.analytics.value.BooleanValueStream.AbstractBooleanValueStream;
-import org.apache.solr.common.SolrException;
-import org.apache.solr.common.SolrException.ErrorCode;
-
-/**
- * Contains all comparable functions. Comparable functions accept two parameters and return a BooleanValueStream.
- * The two parameters must be able to be cast to the same type.
- * <p>
- * Uses:
- * <ul>
- * <li>If a two comparable {@link AnalyticsValue}s are passed in, a {@link BooleanValue} representing the comparison of the two values for each document is returned.
- * <li>If a comparable {@link AnalyticsValue} and a comparable {@link AnalyticsValueStream} are passed in,
- * a {@link BooleanValueStream} representing the comparison of the Value and each of the values of the ValueStream for the document is returned.
- * </ul>
- */
-public class CompareFunction {
-
- private static BooleanValueStream createCompareFunction(String name, CompResultFunction comp, AnalyticsValueStream... params) {
- if (params.length != 2) {
- throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires 2 paramaters, " + params.length + " found.");
- }
- AnalyticsValueStream paramA = params[0];
- AnalyticsValueStream paramB = params[1];
- if (paramA instanceof DateValueStream && paramB instanceof DateValueStream) {
- if (paramA instanceof DateValue) {
- if (paramB instanceof DateValue) {
- return new CompareDateValueFunction(name,(DateValue)paramA,(DateValue)paramB,comp);
- }
- return new CompareDateStreamFunction(name,(DateValue)paramA,(DateValueStream)paramB,comp);
- }
- if (paramB instanceof DateValue) {
- return new CompareDateStreamFunction(name,(DateValue)paramB,(DateValueStream)paramA,reverse(comp));
- }
- } else if (paramA instanceof DoubleValueStream && paramB instanceof DoubleValueStream) {
- if (paramA instanceof DoubleValue) {
- if (paramB instanceof DoubleValue) {
- return new CompareDoubleValueFunction(name,(DoubleValue)paramA,(DoubleValue)paramB,comp);
- }
- return new CompareDoubleStreamFunction(name,(DoubleValue)paramA,(DoubleValueStream)paramB,comp);
- }
- if (paramB instanceof DoubleValue) {
- return new CompareDoubleStreamFunction(name,(DoubleValue)paramB,(DoubleValueStream)paramA,reverse(comp));
- }
- } else if (paramA instanceof StringValueStream && paramB instanceof StringValueStream) {
- if (paramA instanceof StringValue) {
- if (paramB instanceof StringValue) {
- return new CompareStringValueFunction(name,(StringValue)paramA,(StringValue)paramB,comp);
- }
- return new CompareStringStreamFunction(name,(StringValue)paramA,(StringValueStream)paramB,comp);
- }
- if (paramB instanceof StringValue) {
- return new CompareStringStreamFunction(name,(StringValue)paramB,(StringValueStream)paramA,reverse(comp));
- }
- } else {
- throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires comparable parameters.");
- }
- throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires that at least 1 parameter be single-valued.");
- }
-
- /**
- * A comparison function that tests equality.
- */
- public static class EqualFunction {
- public static final String name = "equal";
- public static final CreatorFunction creatorFunction = (params -> {
- try {
- return CompareFunction.createCompareFunction(name, val -> {
- return val == 0;
- }, params);
- } catch (SolrException e) {
- if (params.length != 2) {
- throw e;
- }
-
- AnalyticsValueStream paramA = params[0];
- AnalyticsValueStream paramB = params[1];
-
- // Booleans aren't really comparable, so just enable the equal function
- if (paramA instanceof BooleanValueStream && paramB instanceof BooleanValueStream) {
- if (paramA instanceof BooleanValue) {
- if (paramB instanceof BooleanValue) {
- return new BooleanValueEqualFunction((BooleanValue)paramA,(BooleanValue)paramB);
- }
- return new BooleanStreamEqualFunction((BooleanValue)paramA,(BooleanValueStream)paramB);
- } else if (paramB instanceof BooleanValue) {
- return new BooleanStreamEqualFunction((BooleanValue)paramB,(BooleanValueStream)paramA);
- }
- }
-
- // This means that the Objects created by the AnalyticsValueStreams are not comparable, so use the .equals() method instead
- else if (paramA instanceof AnalyticsValue) {
- if (paramB instanceof AnalyticsValue) {
- return new ValueEqualFunction((AnalyticsValue)paramA,(AnalyticsValue)paramB);
- }
- return new StreamEqualFunction((AnalyticsValue)paramA,paramB);
- }
- if (paramB instanceof AnalyticsValue) {
- return new StreamEqualFunction((AnalyticsValue)paramB,paramA);
- }
- }
- throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires that at least 1 parameter be single-valued.");
- });
- }
-
- /**
- * A comparison function that tests whether the first parameter is greater than the second parameter
- */
- public static class GTFunction {
- public static final String name = "gt";
- public static final CreatorFunction creatorFunction = (params -> {
- return CompareFunction.createCompareFunction(name, val -> {
- return val > 0;
- }, params);
- });
- }
-
- /**
- * A comparison function that tests whether the first parameter is greater than or equal to the second parameter
- */
- public static class GTEFunction {
- public static final String name = "gte";
- public static final CreatorFunction creatorFunction = (params -> {
- return CompareFunction.createCompareFunction(name, val -> {
- return val >= 0;
- }, params);
- });
- }
-
- /**
- * A comparison function that tests whether the first parameter is less than the second parameter
- */
- public static class LTFunction {
- public static final String name = "lt";
- public static final CreatorFunction creatorFunction = (params -> {
- return CompareFunction.createCompareFunction(name, val -> {
- return val < 0;
- }, params);
- });
- }
-
- /**
- * A comparison function that tests whether the first parameter is less than or equal to the second parameter
- */
- public static class LTEFunction {
- public static final String name = "lte";
- public static final CreatorFunction creatorFunction = (params -> {
- return CompareFunction.createCompareFunction(name, val -> {
- return val <= 0;
- }, params);
- });
- }
-
- private static CompResultFunction reverse(CompResultFunction original) {
- return val -> original.apply(val*-1);
- }
-}
-@FunctionalInterface
-interface CompResultFunction {
- public boolean apply(int compResult);
-}
-/**
- * A comparison function for two {@link DoubleValue}s.
- */
-class CompareDoubleValueFunction extends AbstractBooleanValue {
- private final DoubleValue exprA;
- private final DoubleValue exprB;
- private final CompResultFunction comp;
- private final String name;
- private final String funcStr;
- private final ExpressionType funcType;
-
- public CompareDoubleValueFunction(String name, DoubleValue exprA, DoubleValue exprB, CompResultFunction comp) {
- this.name = name;
- this.exprA = exprA;
- this.exprB = exprB;
- this.comp = comp;
- this.funcStr = AnalyticsValueStream.createExpressionString(name,exprA,exprB);
- this.funcType = AnalyticsValueStream.determineMappingPhase(funcStr,exprA,exprB);
- }
-
- private boolean exists = false;
- @Override
- public boolean getBoolean() {
- double valueA = exprA.getDouble();
- double valueB = exprB.getDouble();
- exists = exprA.exists() && exprB.exists();
- return exists ? comp.apply(Double.compare(valueA,valueB)) : false;
- }
- @Override
- public boolean exists() {
- return exists;
- }
-
- @Override
- public String getName() {
- return name;
- }
- @Override
- public String getExpressionStr() {
- return funcStr;
- }
- @Override
- public ExpressionType getExpressionType() {
- return funcType;
- }
-}
-/**
- * A comparison function for a {@link DoubleValue} and a {@link DoubleValueStream}.
- */
-class CompareDoubleStreamFunction extends AbstractBooleanValueStream {
- private final DoubleValue baseExpr;
- private final DoubleValueStream compExpr;
- private final CompResultFunction comp;
- private final String name;
- private final String funcStr;
- private final ExpressionType funcType;
-
- public CompareDoubleStreamFunction(String name, DoubleValue baseExpr, DoubleValueStream compExpr, CompResultFunction comp) throws SolrException {
- this.name = name;
- this.baseExpr = baseExpr;
- this.compExpr = compExpr;
- this.comp = comp;
- this.funcStr = AnalyticsValueStream.createExpressionString(name,baseExpr,compExpr);
- this.funcType = AnalyticsValueStream.determineMappingPhase(funcStr,baseExpr,compExpr);
- }
-
- @Override
- public void streamBooleans(BooleanConsumer cons) {
- double baseValue = baseExpr.getDouble();
- if (baseExpr.exists()) {
- compExpr.streamDoubles(compValue -> cons.accept(comp.apply(Double.compare(baseValue,compValue))));
- }
- }
-
- @Override
- public String getName() {
- return name;
- }
- @Override
- public String getExpressionStr() {
- return funcStr;
- }
- @Override
- public ExpressionType getExpressionType() {
- return funcType;
- }
-}
-/**
- * A comparison function for two {@link DateValue}s.
- */
-class CompareDateValueFunction extends AbstractBooleanValue {
- private final DateValue exprA;
- private final DateValue exprB;
- private final CompResultFunction comp;
- private final String name;
- private final String funcStr;
- private final ExpressionType funcType;
-
- public CompareDateValueFunction(String name, DateValue exprA, DateValue exprB, CompResultFunction comp) {
- this.name = name;
- this.exprA = exprA;
- this.exprB = exprB;
- this.comp = comp;
- this.funcStr = AnalyticsValueStream.createExpressionString(name,exprA,exprB);
- this.funcType = AnalyticsValueStream.determineMappingPhase(funcStr,exprA,exprB);
- }
-
- private boolean exists = false;
- @Override
- public boolean getBoolean() {
- long valueA = exprA.getLong();
- long valueB = exprB.getLong();
- exists = exprA.exists() && exprB.exists();
- return exists ? comp.apply(Long.compare(valueA,valueB)) : false;
- }
- @Override
- public boolean exists() {
- return exists;
- }
-
- @Override
- public String getName() {
- return name;
- }
- @Override
- public String getExpressionStr() {
- return funcStr;
- }
- @Override
- public ExpressionType getExpressionType() {
- return funcType;
- }
-}
-/**
- * A comparison function for a {@link DateValue} and a {@link DateValueStream}.
- */
-class CompareDateStreamFunction extends AbstractBooleanValueStream {
- private final DateValue baseExpr;
- private final DateValueStream compExpr;
- private final CompResultFunction comp;
- private final String name;
- private final String funcStr;
- private final ExpressionType funcType;
-
- public CompareDateStreamFunction(String name, DateValue baseExpr, DateValueStream compExpr, CompResultFunction comp) throws SolrException {
- this.name = name;
- this.baseExpr = baseExpr;
- this.compExpr = compExpr;
- this.comp = comp;
- this.funcStr = AnalyticsValueStream.createExpressionString(name,baseExpr,compExpr);
- this.funcType = AnalyticsValueStream.determineMappingPhase(funcStr,baseExpr,compExpr);
- }
-
- @Override
- public void streamBooleans(BooleanConsumer cons) {
- long baseValue = baseExpr.getLong();
- if (baseExpr.exists()) {
- compExpr.streamLongs(compValue -> cons.accept(comp.apply(Long.compare(baseValue,compValue))));
- }
- }
-
- @Override
- public String getName() {
- return name;
- }
- @Override
- public String getExpressionStr() {
- return funcStr;
- }
- @Override
- public ExpressionType getExpressionType() {
- return funcType;
- }
-}
-/**
- * A comparison function for two {@link StringValue}s.
- */
-class CompareStringValueFunction extends AbstractBooleanValue {
- private final StringValue exprA;
- private final StringValue exprB;
- private final CompResultFunction comp;
- private final String name;
- private final String funcStr;
- private final ExpressionType funcType;
-
- public CompareStringValueFunction(String name, StringValue exprA, StringValue exprB, CompResultFunction comp) {
- this.name = name;
- this.exprA = exprA;
- this.exprB = exprB;
- this.comp = comp;
- this.funcStr = AnalyticsValueStream.createExpressionString(name,exprA,exprB);
- this.funcType = AnalyticsValueStream.determineMappingPhase(funcStr,exprA,exprB);
- }
-
- private boolean exists = false;
- @Override
- public boolean getBoolean() {
- String valueA = exprA.toString();
- String valueB = exprB.toString();
- exists = exprA.exists() && exprB.exists();
- return exists ? comp.apply(valueA.compareTo(valueB)) : false;
- }
- @Override
- public boolean exists() {
- return exists;
- }
-
- @Override
- public String getName() {
- return name;
- }
- @Override
- public String getExpressionStr() {
- return funcStr;
- }
- @Override
- public ExpressionType getExpressionType() {
- return funcType;
- }
-}
-/**
- * A comparison function for a {@link StringValue} and a {@link StringValueStream}.
- */
-class CompareStringStreamFunction extends AbstractBooleanValueStream {
- private final StringValue baseExpr;
- private final StringValueStream compExpr;
- private final CompResultFunction comp;
- private final String name;
- private final String funcStr;
- private final ExpressionType funcType;
-
- public CompareStringStreamFunction(String name, StringValue baseExpr, StringValueStream compExpr, CompResultFunction comp) throws SolrException {
- this.name = name;
- this.baseExpr = baseExpr;
- this.compExpr = compExpr;
- this.comp = comp;
- this.funcStr = AnalyticsValueStream.createExpressionString(name,baseExpr,compExpr);
- this.funcType = AnalyticsValueStream.determineMappingPhase(funcStr,baseExpr,compExpr);
- }
-
- @Override
- public void streamBooleans(BooleanConsumer cons) {
- String baseValue = baseExpr.toString();
- if (baseExpr.exists()) {
- compExpr.streamStrings(compValue -> cons.accept(comp.apply(baseValue.compareTo(compValue))));
- }
- }
-
- @Override
- public String getName() {
- return name;
- }
- @Override
- public String getExpressionStr() {
- return funcStr;
- }
- @Override
- public ExpressionType getExpressionType() {
- return funcType;
- }
-}
-/**
- * An equal function for two {@link BooleanValue}s.
- */
-class BooleanValueEqualFunction extends AbstractBooleanValue {
- private final BooleanValue exprA;
- private final BooleanValue exprB;
- public static final String name = CompareFunction.EqualFunction.name;
- private final String funcStr;
- private final ExpressionType funcType;
-
- public BooleanValueEqualFunction(BooleanValue exprA, BooleanValue exprB) {
- this.exprA = exprA;
- this.exprB = exprB;
- this.funcStr = AnalyticsValueStream.createExpressionString(name,exprA,exprB);
- this.funcType = AnalyticsValueStream.determineMappingPhase(funcStr,exprA,exprB);
- }
-
- private boolean exists = false;
- @Override
- public boolean getBoolean() {
- boolean valueA = exprA.getBoolean();
- boolean valueB = exprB.getBoolean();
- exists = exprA.exists() && exprB.exists();
- return exists ? valueA == valueB : false;
- }
- @Override
- public boolean exists() {
- return exists;
- }
-
- @Override
- public String getName() {
- return name;
- }
- @Override
- public String getExpressionStr() {
- return funcStr;
- }
- @Override
- public ExpressionType getExpressionType() {
- return funcType;
- }
-}
-/**
- * An equal function for a {@link BooleanValue} and a {@link BooleanValueStream}.
- */
-class BooleanStreamEqualFunction extends AbstractBooleanValueStream {
- private final BooleanValue baseExpr;
- private final BooleanValueStream compExpr;
- public static final String name = CompareFunction.EqualFunction.name;
- private final String funcStr;
- private final ExpressionType funcType;
-
- public BooleanStreamEqualFunction(BooleanValue baseExpr, BooleanValueStream compExpr) throws SolrException {
- this.baseExpr = baseExpr;
- this.compExpr = compExpr;
- this.funcStr = AnalyticsValueStream.createExpressionString(name,baseExpr,compExpr);
- this.funcType = AnalyticsValueStream.determineMappingPhase(funcStr,baseExpr,compExpr);
- }
-
- @Override
- public void streamBooleans(BooleanConsumer cons) {
- boolean baseValue = baseExpr.getBoolean();
- if (baseExpr.exists()) {
- compExpr.streamBooleans(compValue -> cons.accept(baseValue == compValue));
- }
- }
-
- @Override
- public String getName() {
- return name;
- }
- @Override
- public String getExpressionStr() {
- return funcStr;
- }
- @Override
- public ExpressionType getExpressionType() {
- return funcType;
- }
-}
-/**
- * A catch-all equal function for two {@link AnalyticsValue}s.
- */
-class ValueEqualFunction extends AbstractBooleanValue {
- private final AnalyticsValue exprA;
- private final AnalyticsValue exprB;
- public static final String name = CompareFunction.EqualFunction.name;
- private final String funcStr;
- private final ExpressionType funcType;
-
- public ValueEqualFunction(AnalyticsValue exprA, AnalyticsValue exprB) {
- this.exprA = exprA;
- this.exprB = exprB;
- this.funcStr = AnalyticsValueStream.createExpressionString(name,exprA,exprB);
- this.funcType = AnalyticsValueStream.determineMappingPhase(funcStr,exprA,exprB);
- }
-
- private boolean exists = false;
- @Override
- public boolean getBoolean() {
- Object valueA = exprA.getObject();
- Object valueB = exprB.getObject();
- exists = exprA.exists() && exprB.exists();
- return exists ? valueA.equals(valueB) : false;
- }
- @Override
- public boolean exists() {
- return exists;
- }
-
- @Override
- public String getName() {
- return name;
- }
- @Override
- public String getExpressionStr() {
- return funcStr;
- }
- @Override
- public ExpressionType getExpressionType() {
- return funcType;
- }
-}
-/**
- * A catch-all equal function for an {@link AnalyticsValue} and an {@link AnalyticsValueStream}.
- */
-class StreamEqualFunction extends AbstractBooleanValueStream {
- private final AnalyticsValue baseExpr;
- private final AnalyticsValueStream compExpr;
- public static final String name = CompareFunction.EqualFunction.name;
- private final String funcStr;
- private final ExpressionType funcType;
-
- public StreamEqualFunction(AnalyticsValue baseExpr, AnalyticsValueStream compExpr) throws SolrException {
- this.baseExpr = baseExpr;
- this.compExpr = compExpr;
- this.funcStr = AnalyticsValueStream.createExpressionString(name,baseExpr,compExpr);
- this.funcType = AnalyticsValueStream.determineMappingPhase(funcStr,baseExpr,compExpr);
- }
-
- @Override
- public void streamBooleans(BooleanConsumer cons) {
- Object baseValue = baseExpr.getObject();
- if (baseExpr.exists()) {
- compExpr.streamObjects(compValue -> cons.accept(baseValue.equals(compValue)));
- }
- }
-
- @Override
- public String getName() {
- return name;
- }
- @Override
- public String getExpressionStr() {
- return funcStr;
- }
- @Override
- public ExpressionType getExpressionType() {
- return funcType;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/ComparisonFunction.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/ComparisonFunction.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/ComparisonFunction.java
new file mode 100644
index 0000000..1bbf9ae
--- /dev/null
+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/ComparisonFunction.java
@@ -0,0 +1,318 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.function.mapping;
+
+import org.apache.solr.analytics.ExpressionFactory.CreatorFunction;
+import org.apache.solr.analytics.function.mapping.ComparisonFunction.CompResultFunction;
+import org.apache.solr.analytics.util.function.BooleanConsumer;
+import org.apache.solr.analytics.value.AnalyticsValue;
+import org.apache.solr.analytics.value.AnalyticsValueStream;
+import org.apache.solr.analytics.value.BooleanValue;
+import org.apache.solr.analytics.value.BooleanValueStream;
+import org.apache.solr.analytics.value.DateValue;
+import org.apache.solr.analytics.value.DateValueStream;
+import org.apache.solr.analytics.value.DoubleValue;
+import org.apache.solr.analytics.value.DoubleValueStream;
+import org.apache.solr.analytics.value.BooleanValue.AbstractBooleanValue;
+import org.apache.solr.analytics.value.BooleanValueStream.AbstractBooleanValueStream;
+import org.apache.solr.common.SolrException;
+import org.apache.solr.common.SolrException.ErrorCode;
+
+/**
+ * Contains all comparable functions. Comparable functions accept two comparable (numeric and date) parameters and return a BooleanValueStream.
+ * The two parameters must be able to be cast to the same type.
+ * <p>
+ * Uses:
+ * <ul>
+ * <li>If a two comparable {@link AnalyticsValue}s are passed in, a {@link BooleanValue} representing the comparison of the two values for each document is returned.
+ * <li>If a comparable {@link AnalyticsValue} and a comparable {@link AnalyticsValueStream} are passed in,
+ * a {@link BooleanValueStream} representing the comparison of the Value and each of the values of the ValueStream for the document is returned.
+ * </ul>
+ */
+public class ComparisonFunction {
+
+ /**
+ * Create a comparison mapping function, comparing two analytics value (streams) of the same type.
+ *
+ * @param name name of the function
+ * @param comp function to find the result of a comparison
+ * @param params the parameters to compare
+ * @return an instance of the requested comparison function using the given parameters
+ */
+ public static BooleanValueStream createComparisonFunction(String name, CompResultFunction comp, AnalyticsValueStream... params) {
+ if (params.length != 2) {
+ throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires 2 paramaters, " + params.length + " found.");
+ }
+ AnalyticsValueStream paramA = params[0];
+ AnalyticsValueStream paramB = params[1];
+ if (paramA instanceof DoubleValueStream && paramB instanceof DoubleValueStream) {
+ if (paramA instanceof DoubleValue) {
+ if (paramB instanceof DoubleValue) {
+ return new CompareDoubleValueFunction(name,(DoubleValue)paramA,(DoubleValue)paramB,comp);
+ }
+ return new CompareDoubleStreamFunction(name,(DoubleValue)paramA,(DoubleValueStream)paramB,comp);
+ }
+ if (paramB instanceof DoubleValue) {
+ return new CompareDoubleStreamFunction(name,(DoubleValue)paramB,(DoubleValueStream)paramA,reverse(comp));
+ }
+ } else if (paramA instanceof DateValueStream && paramB instanceof DateValueStream) {
+ if (paramA instanceof DateValue) {
+ if (paramB instanceof DateValue) {
+ return new CompareDateValueFunction(name,(DateValue)paramA,(DateValue)paramB,comp);
+ }
+ return new CompareDateStreamFunction(name,(DateValue)paramA,(DateValueStream)paramB,comp);
+ }
+ if (paramB instanceof DateValue) {
+ return new CompareDateStreamFunction(name,(DateValue)paramB,(DateValueStream)paramA,reverse(comp));
+ }
+ } else {
+ throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires comparable (numeric or date) parameters.");
+ }
+ throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires that at least 1 parameter be single-valued.");
+ }
+
+ /**
+ * A comparison function that tests whether the first parameter is greater than the second parameter
+ */
+ public static class GTFunction {
+ public static final String name = "gt";
+ public static final CreatorFunction creatorFunction = (params -> {
+ return ComparisonFunction.createComparisonFunction(name, val -> {
+ return val > 0;
+ }, params);
+ });
+ }
+
+ /**
+ * A comparison function that tests whether the first parameter is greater than or equal to the second parameter
+ */
+ public static class GTEFunction {
+ public static final String name = "gte";
+ public static final CreatorFunction creatorFunction = (params -> {
+ return ComparisonFunction.createComparisonFunction(name, val -> {
+ return val >= 0;
+ }, params);
+ });
+ }
+
+ /**
+ * A comparison function that tests whether the first parameter is less than the second parameter
+ */
+ public static class LTFunction {
+ public static final String name = "lt";
+ public static final CreatorFunction creatorFunction = (params -> {
+ return ComparisonFunction.createComparisonFunction(name, val -> {
+ return val < 0;
+ }, params);
+ });
+ }
+
+ /**
+ * A comparison function that tests whether the first parameter is less than or equal to the second parameter
+ */
+ public static class LTEFunction {
+ public static final String name = "lte";
+ public static final CreatorFunction creatorFunction = (params -> {
+ return ComparisonFunction.createComparisonFunction(name, val -> {
+ return val <= 0;
+ }, params);
+ });
+ }
+
+ @FunctionalInterface
+ public static interface CompResultFunction {
+ public boolean apply(int compResult);
+ }
+
+ private static CompResultFunction reverse(CompResultFunction original) {
+ return val -> original.apply(val*-1);
+ }
+}
+/**
+ * A comparison function for two {@link DoubleValue}s.
+ */
+class CompareDoubleValueFunction extends AbstractBooleanValue {
+ private final DoubleValue exprA;
+ private final DoubleValue exprB;
+ private final CompResultFunction comp;
+ private final String name;
+ private final String funcStr;
+ private final ExpressionType funcType;
+
+ public CompareDoubleValueFunction(String name, DoubleValue exprA, DoubleValue exprB, CompResultFunction comp) {
+ this.name = name;
+ this.exprA = exprA;
+ this.exprB = exprB;
+ this.comp = comp;
+ this.funcStr = AnalyticsValueStream.createExpressionString(name,exprA,exprB);
+ this.funcType = AnalyticsValueStream.determineMappingPhase(funcStr,exprA,exprB);
+ }
+
+ private boolean exists = false;
+ @Override
+ public boolean getBoolean() {
+ double valueA = exprA.getDouble();
+ double valueB = exprB.getDouble();
+ exists = exprA.exists() && exprB.exists();
+ return exists ? comp.apply(Double.compare(valueA,valueB)) : false;
+ }
+ @Override
+ public boolean exists() {
+ return exists;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+ @Override
+ public String getExpressionStr() {
+ return funcStr;
+ }
+ @Override
+ public ExpressionType getExpressionType() {
+ return funcType;
+ }
+}
+/**
+ * A comparison function for a {@link DoubleValue} and a {@link DoubleValueStream}.
+ */
+class CompareDoubleStreamFunction extends AbstractBooleanValueStream {
+ private final DoubleValue baseExpr;
+ private final DoubleValueStream compExpr;
+ private final CompResultFunction comp;
+ private final String name;
+ private final String funcStr;
+ private final ExpressionType funcType;
+
+ public CompareDoubleStreamFunction(String name, DoubleValue baseExpr, DoubleValueStream compExpr, CompResultFunction comp) throws SolrException {
+ this.name = name;
+ this.baseExpr = baseExpr;
+ this.compExpr = compExpr;
+ this.comp = comp;
+ this.funcStr = AnalyticsValueStream.createExpressionString(name,baseExpr,compExpr);
+ this.funcType = AnalyticsValueStream.determineMappingPhase(funcStr,baseExpr,compExpr);
+ }
+
+ @Override
+ public void streamBooleans(BooleanConsumer cons) {
+ double baseValue = baseExpr.getDouble();
+ if (baseExpr.exists()) {
+ compExpr.streamDoubles(compValue -> cons.accept(comp.apply(Double.compare(baseValue,compValue))));
+ }
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+ @Override
+ public String getExpressionStr() {
+ return funcStr;
+ }
+ @Override
+ public ExpressionType getExpressionType() {
+ return funcType;
+ }
+}
+/**
+ * A comparison function for two {@link DateValue}s.
+ */
+class CompareDateValueFunction extends AbstractBooleanValue {
+ private final DateValue exprA;
+ private final DateValue exprB;
+ private final CompResultFunction comp;
+ private final String name;
+ private final String funcStr;
+ private final ExpressionType funcType;
+
+ public CompareDateValueFunction(String name, DateValue exprA, DateValue exprB, CompResultFunction comp) {
+ this.name = name;
+ this.exprA = exprA;
+ this.exprB = exprB;
+ this.comp = comp;
+ this.funcStr = AnalyticsValueStream.createExpressionString(name,exprA,exprB);
+ this.funcType = AnalyticsValueStream.determineMappingPhase(funcStr,exprA,exprB);
+ }
+
+ private boolean exists = false;
+ @Override
+ public boolean getBoolean() {
+ long valueA = exprA.getLong();
+ long valueB = exprB.getLong();
+ exists = exprA.exists() && exprB.exists();
+ return exists ? comp.apply(Long.compare(valueA,valueB)) : false;
+ }
+ @Override
+ public boolean exists() {
+ return exists;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+ @Override
+ public String getExpressionStr() {
+ return funcStr;
+ }
+ @Override
+ public ExpressionType getExpressionType() {
+ return funcType;
+ }
+}
+/**
+ * A comparison function for a {@link DateValue} and a {@link DateValueStream}.
+ */
+class CompareDateStreamFunction extends AbstractBooleanValueStream {
+ private final DateValue baseExpr;
+ private final DateValueStream compExpr;
+ private final CompResultFunction comp;
+ private final String name;
+ private final String funcStr;
+ private final ExpressionType funcType;
+
+ public CompareDateStreamFunction(String name, DateValue baseExpr, DateValueStream compExpr, CompResultFunction comp) throws SolrException {
+ this.name = name;
+ this.baseExpr = baseExpr;
+ this.compExpr = compExpr;
+ this.comp = comp;
+ this.funcStr = AnalyticsValueStream.createExpressionString(name,baseExpr,compExpr);
+ this.funcType = AnalyticsValueStream.determineMappingPhase(funcStr,baseExpr,compExpr);
+ }
+
+ @Override
+ public void streamBooleans(BooleanConsumer cons) {
+ long baseValue = baseExpr.getLong();
+ if (baseExpr.exists()) {
+ compExpr.streamLongs(compValue -> cons.accept(comp.apply(Long.compare(baseValue,compValue))));
+ }
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+ @Override
+ public String getExpressionStr() {
+ return funcStr;
+ }
+ @Override
+ public ExpressionType getExpressionType() {
+ return funcType;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/ConcatFunction.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/ConcatFunction.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/ConcatFunction.java
index e54e8c5..9b0809e 100644
--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/ConcatFunction.java
+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/ConcatFunction.java
@@ -18,61 +18,90 @@ package org.apache.solr.analytics.function.mapping;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrException.ErrorCode;
+
+import java.util.Arrays;
+
import org.apache.solr.analytics.ExpressionFactory.CreatorFunction;
+import org.apache.solr.analytics.function.mapping.LambdaFunction.TwoStringInStringOutLambda;
+import org.apache.solr.analytics.value.AnalyticsValueStream;
import org.apache.solr.analytics.value.StringValue;
+import org.apache.solr.analytics.value.StringValueStream;
import org.apache.solr.analytics.value.constant.ConstantStringValue;
+import org.apache.solr.analytics.value.constant.ConstantValue;
/**
* A concatenation mapping function, combining the string values of the given parameters. (At least 1 parameter is required)
* <p>
- * Multiple comparable {@link StringValue}s are passed in and a {@link StringValue} representing the concatenation of all values is returned.
+ * Uses:
+ * <ul>
+ * <li>If a single {@link StringValueStream} is passed in, a {@link StringValue} representing the concatenation of the values for each document is returned.
+ * No ordering is guaranteed while concatenating.
+ * <li>If a {@link StringValue} and a {@link StringValueStream} are passed in, a {@link StringValueStream} representing the concatenation of
+ * the Value and each of the values of the ValueStream for a document is returned.
+ * (Or the other way, since the Value and ValueStream can be used in either order)
+ * <li>If any number (more than 0) of {@link StringValue}s are passed in, a {@link StringValue} representing the concatenation of all values is returned.
+ * If any values don't exist, the overall concatenation value will still exist with an empty string used for any missing values. If none of the parameter
+ * values exist, then the overall concatenation value will not exist.
+ * </ul>
*/
public class ConcatFunction {
public static final String name = "concat";
public static final CreatorFunction creatorFunction = (params -> {
- if (params.length == 0) {
- throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires parameters.");
- }
- else if (params.length == 1 && params[0] instanceof StringValue) {
- return params[0];
- }
- StringValue[] castedParams = new StringValue[params.length];
- for (int i = 0; i < params.length; i++) {
- if (params[i] instanceof StringValue) {
- castedParams[i] = (StringValue) params[i];
- } else {
- throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires that all parameters be single-valued and convertible to string values.");
- }
- }
- return LambdaFunction.createStringLambdaFunction(name, (a,b) -> a+b, castedParams, false);
+ return createConcatFunction(name, name, (a,b) -> a + b, params);
});
/**
* A concatenation mapping function, combining the string values of the given parameters with a given separating string.
* <br>
- * Multiple comparable {@link StringValue}s are passed in and a {@link StringValue} representing the separated concatenation of all values is returned.
- * <p>
- * The first parameter must be a constant string (e.g. ",").
- * The remaining parameters are the {@link StringValue} expressions to concatenate. (At least 1 expression is required)
+ * The usage is exactly the same as the {@link ConcatFunction}, however a {@link ConstantStringValue} separator is added as the first argument
+ * of every usage. So the acceptable inputs are as follows:
+ * <ul>
+ * <li>{@value #name} ( {@link ConstantStringValue} , {@link StringValueStream} )
+ * <li>{@value #name} ( {@link ConstantStringValue} , {@link StringValueStream} , {@link StringValue} )
+ * <li>{@value #name} ( {@link ConstantStringValue} , {@link StringValue} , {@link StringValueStream} )
+ * <li>{@value #name} ( {@link ConstantStringValue} , {@link StringValue} ... )
+ * </ul>
+ * The {@link ConstantStringValue} separator is used to separate every two (or more) string during concatenation. If only one string value exists,
+ * then the separator will not be used.
*/
- public static class ConcatSeparatedFunction {
- public static final String name = "concatsep";
+ public static class SeparatedConcatFunction {
+ public static final String name = "concat_sep";
public static final CreatorFunction creatorFunction = (params -> {
if (params.length < 2) {
throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires at least 2 parameters.");
- } else if (!(params[0] instanceof ConstantStringValue)) {
+ } else if (!(params[0] instanceof StringValue && params[0] instanceof ConstantValue)) {
throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires that the first parameter to be a constant string.");
}
- final String sep = ((ConstantStringValue)params[0]).getString();
- StringValue[] castedParams = new StringValue[params.length - 1];
- for (int i = 0; i < castedParams.length; i++) {
- if (params[i + 1] instanceof StringValue) {
- castedParams[i] = (StringValue) params[i + 1];
- } else {
- throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires that all non-separator parameters be single-valued and convertible to string values.");
- }
- }
- return LambdaFunction.createStringLambdaFunction(name, (a,b) -> a + sep + b, castedParams, false);
+ final String sep = ((StringValue)params[0]).getString();
+ String uniqueName = name + "(" + sep + ")";
+ return createConcatFunction(name, uniqueName, (a,b) -> a + sep + b, Arrays.copyOfRange(params, 1, params.length));
});
}
+
+ private static StringValueStream createConcatFunction(String functionName, String uniqueName, TwoStringInStringOutLambda lambda, AnalyticsValueStream[] params) {
+ if (params.length == 0) {
+ throw new SolrException(ErrorCode.BAD_REQUEST, "The "+functionName+" function requires parameters.");
+ } else if (params.length == 1) {
+ if (params[0] instanceof StringValueStream) {
+ return LambdaFunction.createStringLambdaFunction(uniqueName, lambda, (StringValueStream)params[0]);
+ }
+ throw new SolrException(ErrorCode.BAD_REQUEST, "The "+functionName+" function requires that all parameters be string-castable.");
+ } else if (params.length == 2) {
+ // If it is not a pair of a single valued and multi valued string, then it will be taken care of below
+ if (params[0] instanceof StringValueStream && params[1] instanceof StringValueStream
+ && !(params[0] instanceof StringValue && params[1] instanceof StringValue)) {
+ return LambdaFunction.createStringLambdaFunction(uniqueName, lambda, (StringValueStream)params[0], (StringValueStream)params[1]);
+ }
+ }
+ StringValue[] castedParams = new StringValue[params.length];
+ for (int i = 0; i < params.length; i++) {
+ if (params[i] instanceof StringValue) {
+ castedParams[i] = (StringValue) params[i];
+ } else {
+ throw new SolrException(ErrorCode.BAD_REQUEST, "The "+functionName+" function requires that all parameters be string-castable, and if more than 2 parameters"
+ + " are provided then all must be single-valued.");
+ }
+ }
+ return LambdaFunction.createStringLambdaFunction(uniqueName, lambda, castedParams, false);
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/DateMathFunction.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/DateMathFunction.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/DateMathFunction.java
index 9901625..c9dab98 100644
--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/DateMathFunction.java
+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/DateMathFunction.java
@@ -24,9 +24,11 @@ import org.apache.solr.analytics.ExpressionFactory.CreatorFunction;
import org.apache.solr.analytics.value.AnalyticsValueStream;
import org.apache.solr.analytics.value.DateValue;
import org.apache.solr.analytics.value.DateValueStream;
+import org.apache.solr.analytics.value.StringValue;
import org.apache.solr.analytics.value.DateValue.AbstractDateValue;
import org.apache.solr.analytics.value.DateValueStream.AbstractDateValueStream;
import org.apache.solr.analytics.value.constant.ConstantStringValue;
+import org.apache.solr.analytics.value.constant.ConstantValue;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrException.ErrorCode;
import org.apache.solr.util.DateMathParser;
@@ -46,8 +48,8 @@ public class DateMathFunction {
}
StringBuilder mathParam = new StringBuilder();
for (int i = 1; i < params.length; ++i) {
- if (params[i] instanceof ConstantStringValue) {
- mathParam.append(((ConstantStringValue) params[i]).getString());
+ if (params[i] instanceof StringValue && params[i] instanceof ConstantValue) {
+ mathParam.append(((StringValue) params[i]).getString());
} else {
throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires all math parameters to be a constant strings.");
}
@@ -84,7 +86,7 @@ class DateMathValueFunction extends AbstractDateValue {
@Override
public long getLong() {
Date date = getDate();
- return (date == null) ? 0 : date.getTime();
+ return (exists) ? date.getTime() : 0;
}
@Override
public Date getDate() {
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/DateParseFunction.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/DateParseFunction.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/DateParseFunction.java
index 5929b88..226acac 100644
--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/DateParseFunction.java
+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/DateParseFunction.java
@@ -16,10 +16,8 @@
*/
package org.apache.solr.analytics.function.mapping;
-import java.text.DateFormat;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Locale;
+import java.time.Instant;
+import java.time.format.DateTimeParseException;
import java.util.function.LongConsumer;
import org.apache.solr.analytics.ExpressionFactory.CreatorFunction;
@@ -103,7 +101,6 @@ class LongStreamToDateParseFunction extends AbstractDateValueStream {
public static final String name = DateParseFunction.name;
private final String exprStr;
private final ExpressionType funcType;
- public static final DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss.SSS", Locale.ROOT);
public LongStreamToDateParseFunction(LongValueStream param) throws SolrException {
this.param = param;
@@ -134,7 +131,6 @@ class StringToDateParseFunction extends AbstractDateValue {
public static final String name = DateParseFunction.name;
private final String exprStr;
private final ExpressionType funcType;
- public static final DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss.SSS", Locale.ROOT);
public StringToDateParseFunction(StringValue param) throws SolrException {
this.param = param;
@@ -147,9 +143,12 @@ class StringToDateParseFunction extends AbstractDateValue {
public long getLong() {
long value = 0;
try {
- value = formatter.parse(param.toString()).getTime();
+ String paramStr = param.getString();
exists = param.exists();
- } catch (ParseException e) {
+ if (exists) {
+ value = Instant.parse(paramStr).toEpochMilli();
+ }
+ } catch (DateTimeParseException e) {
exists = false;
}
return value;
@@ -177,7 +176,6 @@ class StringStreamToDateParseFunction extends AbstractDateValueStream {
public static final String name = DateParseFunction.name;
private final String exprStr;
private final ExpressionType funcType;
- public static final DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss.SSS", Locale.ROOT);
public StringStreamToDateParseFunction(StringValueStream param) throws SolrException {
this.param = param;
@@ -189,13 +187,11 @@ class StringStreamToDateParseFunction extends AbstractDateValueStream {
public void streamLongs(LongConsumer cons) {
param.streamStrings(value -> {
try {
- cons.accept(formatter.parse(value).getTime());
- } catch (ParseException e) {
- }
+ cons.accept(Instant.parse(value).toEpochMilli());
+ } catch (DateTimeParseException e) {}
});
}
- @Override
public String getName() {
return name;
}
@@ -207,4 +203,4 @@ class StringStreamToDateParseFunction extends AbstractDateValueStream {
public ExpressionType getExpressionType() {
return funcType;
}
-}
\ No newline at end of file
+}
[20/20] lucene-solr:master: SOLR-11145,
SOLR-11146: Updates solr/CHANGES for related commit adding unit tests
and fixing a couple bugs
Posted by dp...@apache.org.
SOLR-11145, SOLR-11146: Updates solr/CHANGES for related commit adding unit tests and fixing a couple bugs
This closes #225
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/6fefcfa1
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/6fefcfa1
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/6fefcfa1
Branch: refs/heads/master
Commit: 6fefcfa18cf4ae2bd410ecc8b94579170ba842c5
Parents: 86d84bf
Author: Dennis Gove <dp...@gmail.com>
Authored: Tue Oct 17 13:45:58 2017 -0400
Committer: Dennis Gove <dp...@gmail.com>
Committed: Tue Oct 17 13:52:03 2017 -0400
----------------------------------------------------------------------
solr/CHANGES.txt | 4 ++++
1 file changed, 4 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/6fefcfa1/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 645664c..27f0440 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -54,6 +54,8 @@ Bug Fixes
* SOLR-11491: Support retrieval of cluster properties in HttpClusterStateProvider. (ab)
+* SOLR-11146: Small fixes to the mapping functions in the Analytics Component (Houston Putman)
+
Optimizations
----------------------
* SOLR-11285: Refactor autoscaling framework to avoid direct references to Zookeeper and Solr
@@ -65,6 +67,8 @@ Other Changes
----------------------
* SOLR-11478: Solr should remove itself from live_nodes in zk immediately on shutdown. (Cao Manh Dat)
+* SOLR-11145: Adds comprehensive unit tests for the Analytics Component v2 (Houston Putman)
+
================== 7.1.0 ==================
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.
[07/20] lucene-solr:master: SOLR-11145,
SOLR-11146: Added comprehensive unit tests for Analytics Component
2.0 as well as analytics bug fixes.
Posted by dp...@apache.org.
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/OrFunctionTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/OrFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/OrFunctionTest.java
new file mode 100644
index 0000000..bf8f77b
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/OrFunctionTest.java
@@ -0,0 +1,192 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.function.mapping;
+
+import java.util.Arrays;
+import java.util.Iterator;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.analytics.function.mapping.LogicFunction.OrFunction;
+import org.apache.solr.analytics.value.AnalyticsValueStream;
+import org.apache.solr.analytics.value.BooleanValue;
+import org.apache.solr.analytics.value.BooleanValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestBooleanValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestBooleanValueStream;
+import org.junit.Test;
+
+public class OrFunctionTest extends SolrTestCaseJ4 {
+ @Test
+ public void twoSingleValueParametersTest() {
+ TestBooleanValue val1 = new TestBooleanValue();
+ TestBooleanValue val2 = new TestBooleanValue();
+
+ AnalyticsValueStream uncasted = OrFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2});
+ assertTrue(uncasted instanceof BooleanValue);
+ BooleanValue func = (BooleanValue) uncasted;
+
+ // Neither exists
+ val1.setExists(false);
+ val2.setExists(false);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ // One exists
+ val1.setValue(true).setExists(true);
+ val2.setExists(false);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ // Both exist
+ val1.setValue(false).setExists(true);
+ val2.setValue(false).setExists(true);
+ assertEquals(false, func.getBoolean());
+ assertTrue(func.exists());
+
+ val1.setValue(true).setExists(true);
+ val2.setValue(false).setExists(true);
+ assertEquals(true, func.getBoolean());
+ assertTrue(func.exists());
+
+ val1.setValue(false).setExists(true);
+ val2.setValue(true).setExists(true);
+ assertEquals(true, func.getBoolean());
+ assertTrue(func.exists());
+
+ val1.setValue(true).setExists(true);
+ val2.setValue(true).setExists(true);
+ assertEquals(true, func.getBoolean());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void oneMultiValueParameterTest() {
+ TestBooleanValueStream val = new TestBooleanValueStream();
+
+ AnalyticsValueStream uncasted = OrFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof BooleanValue);
+ BooleanValue func = (BooleanValue) uncasted;
+
+ // No values
+ val.setValues();
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ // One value
+ val.setValues(true);
+ assertEquals(true, func.getBoolean());
+ assertTrue(func.exists());
+
+ val.setValues(false);
+ assertEquals(false, func.getBoolean());
+ assertTrue(func.exists());
+
+ // Multiple values
+ val.setValues(false, false, true, false);
+ assertEquals(true, func.getBoolean());
+ assertTrue(func.exists());
+
+ val.setValues(false, false, false);
+ assertEquals(false, func.getBoolean());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void oneMultiOneSingleValueParameterTest() {
+ TestBooleanValue val1 = new TestBooleanValue();
+ TestBooleanValueStream val2 = new TestBooleanValueStream();
+
+ AnalyticsValueStream uncasted = OrFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2});
+ assertTrue(uncasted instanceof BooleanValueStream);
+ BooleanValueStream func = (BooleanValueStream) uncasted;
+
+ // No values, One value
+ val1.setValue(false).setExists(true);
+ val2.setValues();
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple values, no value
+ val1.setExists(false);
+ val2.setValues(true, false);
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple values, one value
+ val1.setValue(false).setExists(true);
+ val2.setValues(true, false, true);
+ Iterator<Boolean> values1 = Arrays.asList(true, false, true).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ val1.setValue(true).setExists(true);
+ val2.setValues(true, false, true);
+ Iterator<Boolean> values2 = Arrays.asList(true, true, true).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value);
+ });
+ assertFalse(values2.hasNext());
+ }
+
+ @Test
+ public void multipleSingleValueParameterTest() {
+ TestBooleanValue val1 = new TestBooleanValue();
+ TestBooleanValue val2 = new TestBooleanValue();
+ TestBooleanValue val3 = new TestBooleanValue();
+ TestBooleanValue val4 = new TestBooleanValue();
+
+ AnalyticsValueStream uncasted = OrFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2, val3, val4});
+ assertTrue(uncasted instanceof BooleanValue);
+ BooleanValue func = (BooleanValue) uncasted;
+
+ // None exist
+ val1.setExists(false);
+ val2.setExists(false);
+ val3.setExists(false);
+ val4.setExists(false);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ // Some exist
+ val1.setExists(false);
+ val2.setValue(true).setExists(true);
+ val3.setExists(false);
+ val4.setValue(false).setExists(true);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ // All exist values, one value
+ val1.setValue(false).setExists(true);
+ val2.setValue(true).setExists(true);
+ val3.setValue(false).setExists(true);
+ val4.setValue(false).setExists(true);
+ assertEquals(true, func.getBoolean());
+ assertTrue(func.exists());
+
+ val1.setValue(false).setExists(true);
+ val2.setValue(false).setExists(true);
+ val3.setValue(false).setExists(true);
+ val4.setValue(false).setExists(true);
+ assertEquals(false, func.getBoolean());
+ assertTrue(func.exists());
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/PowerFunctionTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/PowerFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/PowerFunctionTest.java
new file mode 100644
index 0000000..a7db7d7
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/PowerFunctionTest.java
@@ -0,0 +1,128 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.function.mapping;
+
+import java.util.Arrays;
+import java.util.Iterator;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.analytics.value.AnalyticsValueStream;
+import org.apache.solr.analytics.value.DoubleValue;
+import org.apache.solr.analytics.value.DoubleValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestIntValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestLongValueStream;
+import org.junit.Test;
+
+public class PowerFunctionTest extends SolrTestCaseJ4 {
+ @Test
+ public void twoSingleValueParametersTest() {
+ TestIntValue base = new TestIntValue();
+ TestFloatValue pow = new TestFloatValue();
+
+ AnalyticsValueStream uncasted = PowerFunction.creatorFunction.apply(new AnalyticsValueStream[] {base, pow});
+ assertTrue(uncasted instanceof DoubleValue);
+ DoubleValue func = (DoubleValue) uncasted;
+
+ // Neither exists
+ base.setExists(false);
+ pow.setExists(false);
+ func.getDouble();
+ assertFalse(func.exists());
+
+ // One exists
+ base.setValue(30).setExists(true);
+ pow.setExists(false);
+ func.getDouble();
+ assertFalse(func.exists());
+
+ // Both exist
+ base.setValue(6).setExists(true);
+ pow.setValue(2.56F).setExists(true);
+ assertEquals(98.1899, func.getDouble(), 0.0001);
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void oneMultiOneSingleValueParameterTest() {
+ TestLongValueStream base = new TestLongValueStream();
+ TestDoubleValue pow = new TestDoubleValue();
+
+ AnalyticsValueStream uncasted = PowerFunction.creatorFunction.apply(new AnalyticsValueStream[] {base, pow});
+ assertTrue(uncasted instanceof DoubleValueStream);
+ DoubleValueStream func = (DoubleValueStream) uncasted;
+
+ // No values, One value
+ base.setValues();
+ pow.setValue(21.56F).setExists(true);
+ func.streamDoubles( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple values, no value
+ base.setValues(4L, 10023L);
+ pow.setExists(false);
+ func.streamDoubles( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple values, one value
+ base.setValues(4L, 123L, 10L);
+ pow.setValue(2.5F).setExists(true);
+ Iterator<Double> values = Arrays.asList(32.0, 167788.7268, 316.2277).iterator();
+ func.streamDoubles( value -> {
+ assertTrue(values.hasNext());
+ assertEquals(values.next(), value, 0.001);
+ });
+ assertFalse(values.hasNext());
+ }
+
+ @Test
+ public void oneSingleOneMultiValueParameterTest() {
+ TestDoubleValue base = new TestDoubleValue();
+ TestLongValueStream pow = new TestLongValueStream();
+
+ AnalyticsValueStream uncasted = PowerFunction.creatorFunction.apply(new AnalyticsValueStream[] {base, pow});
+ assertTrue(uncasted instanceof DoubleValueStream);
+ DoubleValueStream func = (DoubleValueStream) uncasted;
+
+ // No values, One value
+ base.setValue(21.56F).setExists(true);
+ pow.setValues();
+ func.streamDoubles( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple values, no value
+ base.setExists(false);
+ pow.setValues(4L, 10023L);
+ func.streamDoubles( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple values, one value
+ base.setValue(4.56F).setExists(true);
+ pow.setValues(2L, 5L, 3L);
+ Iterator<Double> values = Arrays.asList(20.7936, 1971.6245, 94.8188).iterator();
+ func.streamDoubles( value -> {
+ assertTrue(values.hasNext());
+ assertEquals(values.next(), value, 0.0001);
+ });
+ assertFalse(values.hasNext());
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/RemoveFunctionTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/RemoveFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/RemoveFunctionTest.java
new file mode 100644
index 0000000..05226f9
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/RemoveFunctionTest.java
@@ -0,0 +1,849 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.function.mapping;
+
+import java.time.Instant;
+import java.time.format.DateTimeParseException;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.Iterator;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.analytics.value.AnalyticsValue;
+import org.apache.solr.analytics.value.AnalyticsValueStream;
+import org.apache.solr.analytics.value.BooleanValue;
+import org.apache.solr.analytics.value.BooleanValueStream;
+import org.apache.solr.analytics.value.DateValue;
+import org.apache.solr.analytics.value.DateValueStream;
+import org.apache.solr.analytics.value.DoubleValue;
+import org.apache.solr.analytics.value.DoubleValueStream;
+import org.apache.solr.analytics.value.FloatValue;
+import org.apache.solr.analytics.value.FloatValueStream;
+import org.apache.solr.analytics.value.IntValue;
+import org.apache.solr.analytics.value.IntValueStream;
+import org.apache.solr.analytics.value.LongValue;
+import org.apache.solr.analytics.value.LongValueStream;
+import org.apache.solr.analytics.value.StringValue;
+import org.apache.solr.analytics.value.StringValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestAnalyticsValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestAnalyticsValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestBooleanValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestBooleanValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestDateValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestDateValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestIntValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestIntValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestLongValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestLongValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestStringValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestStringValueStream;
+import org.junit.Test;
+
+public class RemoveFunctionTest extends SolrTestCaseJ4 {
+
+ @Test
+ public void castingTest() {
+ assertTrue(RemoveFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestBooleanValue(), new TestStringValue()}) instanceof StringValue);
+
+ assertFalse(RemoveFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestIntValueStream(), new TestFloatValue()}) instanceof FloatValue);
+
+ assertFalse(RemoveFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestLongValueStream(), new TestDateValue()}) instanceof AnalyticsValue);
+
+ assertFalse(RemoveFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestLongValue(), new TestAnalyticsValue()}) instanceof StringValue);
+
+ assertTrue(RemoveFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestIntValue(), new TestLongValue()}) instanceof DoubleValue);
+
+ assertFalse(RemoveFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestDateValue(), new TestStringValue()}) instanceof DateValue);
+
+ assertFalse(RemoveFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestBooleanValueStream(), new TestStringValue()}) instanceof BooleanValueStream);
+
+ assertFalse(RemoveFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestDoubleValue(), new TestIntValue()}) instanceof LongValue);
+ }
+
+ @Test
+ public void singleValueBooleanTest() {
+ TestBooleanValue val = new TestBooleanValue();
+ TestBooleanValue remover = new TestBooleanValue();
+
+ AnalyticsValueStream uncasted = RemoveFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, remover});
+ assertTrue(uncasted instanceof BooleanValue);
+ BooleanValue func = (BooleanValue) uncasted;
+
+ // Value doesn't exist
+ val.setExists(false);
+ remover.setExists(false);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ val.setExists(false);
+ remover.setValue(false).setExists(true);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ // Value exists
+ val.setValue(true).setExists(true);
+ remover.setValue(false).setExists(true);
+ assertEquals(true, func.getBoolean());
+ assertTrue(func.exists());
+
+ val.setValue(true).setExists(true);
+ remover.setValue(true).setExists(true);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ val.setValue(false).setExists(true);
+ remover.setValue(true).setExists(true);
+ assertEquals(false, func.getBoolean());
+ assertTrue(func.exists());
+
+ val.setValue(false).setExists(true);
+ remover.setValue(false).setExists(true);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ val.setValue(false).setExists(true);
+ remover.setExists(false);
+ assertEquals(false, func.getBoolean());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void singleValueIntTest() {
+ TestIntValue val = new TestIntValue();
+ TestIntValue remover = new TestIntValue();
+
+ AnalyticsValueStream uncasted = RemoveFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, remover});
+ assertTrue(uncasted instanceof IntValue);
+ IntValue func = (IntValue) uncasted;
+
+ // Value doesn't exist
+ val.setExists(false);
+ remover.setExists(false);
+ func.getInt();
+ assertFalse(func.exists());
+
+ val.setExists(false);
+ remover.setValue(-234).setExists(true);
+ func.getInt();
+ assertFalse(func.exists());
+
+ // Value exists
+ val.setValue(21).setExists(true);
+ remover.setValue(234).setExists(true);
+ assertEquals(21, func.getInt());
+ assertTrue(func.exists());
+
+ val.setValue(-154).setExists(true);
+ remover.setValue(-154).setExists(true);
+ func.getInt();
+ assertFalse(func.exists());
+
+ val.setValue(52334).setExists(true);
+ remover.setExists(false);
+ assertEquals(52334, func.getInt());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void singleValueLongTest() {
+ TestLongValue val = new TestLongValue();
+ TestLongValue remover = new TestLongValue();
+
+ AnalyticsValueStream uncasted = RemoveFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, remover});
+ assertTrue(uncasted instanceof LongValue);
+ LongValue func = (LongValue) uncasted;
+
+ // Value doesn't exist
+ val.setExists(false);
+ remover.setExists(false);
+ func.getLong();
+ assertFalse(func.exists());
+
+ val.setExists(false);
+ remover.setValue(234L).setExists(true);
+ func.getLong();
+ assertFalse(func.exists());
+
+ // Value exists
+ val.setValue(21L).setExists(true);
+ remover.setValue(234L).setExists(true);
+ assertEquals(21L, func.getLong());
+ assertTrue(func.exists());
+
+ val.setValue(3421L).setExists(true);
+ remover.setValue(3421L).setExists(true);
+ func.getLong();
+ assertFalse(func.exists());
+
+ val.setValue(-52334L).setExists(true);
+ remover.setExists(false);
+ assertEquals(-52334L, func.getLong());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void singleValueFloatTest() {
+ TestFloatValue val = new TestFloatValue();
+ TestFloatValue remover = new TestFloatValue();
+
+ AnalyticsValueStream uncasted = RemoveFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, remover});
+ assertTrue(uncasted instanceof FloatValue);
+ FloatValue func = (FloatValue) uncasted;
+
+ // Value doesn't exist
+ val.setExists(false);
+ remover.setExists(false);
+ func.getFloat();
+ assertFalse(func.exists());
+
+ val.setExists(false);
+ remover.setValue(3124123.32F).setExists(true);
+ func.getFloat();
+ assertFalse(func.exists());
+
+ // Value exists
+ val.setValue(-21.324F).setExists(true);
+ remover.setValue(23423.423342F).setExists(true);
+ assertEquals(-21.324F, func.getFloat(), .00000001);
+ assertTrue(func.exists());
+
+ val.setValue(84353.452F).setExists(true);
+ remover.setValue(84353.452F).setExists(true);
+ func.getFloat();
+ assertFalse(func.exists());
+
+ val.setValue(2345.345543F).setExists(true);
+ remover.setExists(false);
+ assertEquals(2345.345543F, func.getFloat(), .00000001);
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void singleValueDoubleTest() {
+ TestDoubleValue val = new TestDoubleValue();
+ TestDoubleValue remover = new TestDoubleValue();
+
+ AnalyticsValueStream uncasted = RemoveFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, remover});
+ assertTrue(uncasted instanceof DoubleValue);
+ DoubleValue func = (DoubleValue) uncasted;
+
+ // Value doesn't exist
+ val.setExists(false);
+ remover.setExists(false);
+ func.getDouble();
+ assertFalse(func.exists());
+
+ val.setExists(false);
+ remover.setValue(3124123.32).setExists(true);
+ func.getDouble();
+ assertFalse(func.exists());
+
+ // Value exists
+ val.setValue(-21.324).setExists(true);
+ remover.setValue(23423.423342).setExists(true);
+ assertEquals(-21.324, func.getDouble(), .00000001);
+ assertTrue(func.exists());
+
+ val.setValue(84353.452).setExists(true);
+ remover.setValue(84353.452).setExists(true);
+ func.getDouble();
+ assertFalse(func.exists());
+
+ val.setValue(2345.345543).setExists(true);
+ remover.setExists(false);
+ assertEquals(2345.345543, func.getDouble(), .00000001);
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void singleValueDateTest() throws DateTimeParseException {
+ Date date1 = Date.from(Instant.parse("1810-12-02T10:30:15Z"));
+ Date date2 = Date.from(Instant.parse("1950-02-23T14:54:34Z"));
+ Date date3 = Date.from(Instant.parse("2023-11-01T20:30:15Z"));
+
+ TestDateValue val = new TestDateValue();
+ TestDateValue remover = new TestDateValue();
+
+ AnalyticsValueStream uncasted = RemoveFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, remover});
+ assertTrue(uncasted instanceof DateValue);
+ DateValue func = (DateValue) uncasted;
+
+ // Value doesn't exist
+ val.setExists(false);
+ remover.setExists(false);
+ func.getLong();
+ assertFalse(func.exists());
+
+ val.setExists(false);
+ remover.setValue("1950-02-23T14:54:34Z").setExists(true);
+ func.getLong();
+ assertFalse(func.exists());
+
+ // Value exists
+ val.setValue("1810-12-02T10:30:15Z").setExists(true);
+ remover.setValue("2023-11-01T20:30:15Z").setExists(true);
+ assertEquals(date1.getTime(), func.getLong());
+ assertTrue(func.exists());
+
+ val.setValue("1950-02-23T14:54:34Z").setExists(true);
+ remover.setValue("1950-02-23T14:54:34Z").setExists(true);
+ func.getLong();
+ assertFalse(func.exists());
+
+ val.setValue("2023-11-01T20:30:15Z").setExists(true);
+ remover.setExists(false);
+ assertEquals(date3.getTime(), func.getLong());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void singleValueStringTest() {
+ TestStringValue val = new TestStringValue();
+ TestStringValue remover = new TestStringValue();
+
+ AnalyticsValueStream uncasted = RemoveFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, remover});
+ assertTrue(uncasted instanceof StringValue);
+ StringValue func = (StringValue) uncasted;
+
+ // Value doesn't exist
+ val.setExists(false);
+ remover.setExists(false);
+ func.getString();
+ assertFalse(func.exists());
+
+ val.setExists(false);
+ remover.setValue("abc456").setExists(true);
+ func.getString();
+ assertFalse(func.exists());
+
+ // Value exists
+ val.setValue("abc123").setExists(true);
+ remover.setValue("def456").setExists(true);
+ assertEquals("abc123", func.getString());
+ assertTrue(func.exists());
+
+ val.setValue("this will be removed").setExists(true);
+ remover.setValue("this will be removed").setExists(true);
+ func.getString();
+ assertFalse(func.exists());
+
+ val.setValue("def123").setExists(true);
+ remover.setExists(false);
+ assertEquals("def123", func.getString());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void singleValueObjectTest() {
+ TestAnalyticsValue val = new TestAnalyticsValue();
+ TestAnalyticsValue remover = new TestAnalyticsValue();
+
+ AnalyticsValueStream uncasted = RemoveFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, remover});
+ assertTrue(uncasted instanceof AnalyticsValue);
+ AnalyticsValue func = (AnalyticsValue) uncasted;
+
+ // Value doesn't exist
+ val.setExists(false);
+ remover.setExists(false);
+ func.getObject();
+ assertFalse(func.exists());
+
+ val.setExists(false);
+ remover.setValue(new Boolean(true)).setExists(true);
+ func.getObject();
+ assertFalse(func.exists());
+
+ // Value exists
+ val.setValue("abc123").setExists(true);
+ remover.setValue(new Date(123)).setExists(true);
+ assertEquals("abc123", func.getObject());
+ assertTrue(func.exists());
+
+ val.setValue(new Double(23423.0)).setExists(true);
+ remover.setValue(new Double(23423.0)).setExists(true);
+ func.getObject();
+ assertFalse(func.exists());
+
+ val.setValue(new Long(234)).setExists(true);
+ remover.setExists(false);
+ assertEquals(new Long(234), func.getObject());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void multiValueBooleanTest() {
+ TestBooleanValueStream val = new TestBooleanValueStream();
+ TestBooleanValue remover = new TestBooleanValue();
+
+ AnalyticsValueStream uncasted = RemoveFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, remover});
+ assertTrue(uncasted instanceof BooleanValueStream);
+ BooleanValueStream func = (BooleanValueStream) uncasted;
+
+ // No values
+ val.setValues();
+ remover.setExists(false);
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ val.setValues();
+ remover.setValue(true).setExists(true);
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Values exist
+ val.setValues(false, true, false, true, true);
+ remover.setValue(true).setExists(true);
+ Iterator<Boolean> values1 = Arrays.asList(false, false).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ val.setValues(false, true, false, true, true);
+ remover.setExists(false);
+ Iterator<Boolean> values2 = Arrays.asList(false, true, false, true, true).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value);
+ });
+ assertFalse(values2.hasNext());
+
+ val.setValues(false, true, false, true, true);
+ remover.setValue(false).setExists(true);
+ Iterator<Boolean> values3 = Arrays.asList(true, true, true).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values3.hasNext());
+ assertEquals(values3.next(), value);
+ });
+ assertFalse(values3.hasNext());
+
+ val.setValues(false, false, false);
+ remover.setValue(false).setExists(true);
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+ }
+
+ @Test
+ public void multiValueIntTest() {
+ TestIntValueStream val = new TestIntValueStream();
+ TestIntValue remover = new TestIntValue();
+
+ AnalyticsValueStream uncasted = RemoveFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, remover});
+ assertTrue(uncasted instanceof IntValueStream);
+ IntValueStream func = (IntValueStream) uncasted;
+
+ // No values
+ val.setValues();
+ remover.setExists(false);
+ func.streamInts( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ val.setValues();
+ remover.setValue(324).setExists(true);
+ func.streamInts( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Values exist
+ val.setValues(1, 234, -234, 4439, -234, -3245);
+ remover.setValue(-234).setExists(true);
+ Iterator<Integer> values1 = Arrays.asList(1, 234, 4439, -3245).iterator();
+ func.streamInts( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next().intValue(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ val.setValues(1, 234, -234, 4439, -234, -3245);
+ remover.setExists(false);
+ Iterator<Integer> values2 = Arrays.asList(1, 234, -234, 4439, -234, -3245).iterator();
+ func.streamInts( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next().intValue(), value);
+ });
+ assertFalse(values2.hasNext());
+
+ val.setValues(1, 234, -234, 4439, -234, -3245);
+ remover.setValue(100).setExists(true);
+ Iterator<Integer> values3 = Arrays.asList(1, 234, -234, 4439, -234, -3245).iterator();
+ func.streamInts( value -> {
+ assertTrue(values3.hasNext());
+ assertEquals(values3.next().intValue(), value);
+ });
+ assertFalse(values3.hasNext());
+
+ val.setValues(1, 1);
+ remover.setValue(1).setExists(true);
+ func.streamInts( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+ }
+
+ @Test
+ public void multiValueLongTest() {
+ TestLongValueStream val = new TestLongValueStream();
+ TestLongValue remover = new TestLongValue();
+
+ AnalyticsValueStream uncasted = RemoveFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, remover});
+ assertTrue(uncasted instanceof LongValueStream);
+ LongValueStream func = (LongValueStream) uncasted;
+
+ // No values
+ val.setValues();
+ remover.setExists(false);
+ func.streamLongs( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ val.setValues();
+ remover.setValue(2323L).setExists(true);
+ func.streamLongs( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Values exist
+ val.setValues(323L, -9423L, -1234L, 23423L, -1234L, -1234L);
+ remover.setValue(-1234L).setExists(true);
+ Iterator<Long> values1 = Arrays.asList(323L, -9423L, 23423L).iterator();
+ func.streamLongs( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next().longValue(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ val.setValues(323L, -9423L, -1234L, 23423L, -1234L, -1234L);
+ remover.setExists(false);
+ Iterator<Long> values2 = Arrays.asList(323L, -9423L, -1234L, 23423L, -1234L, -1234L).iterator();
+ func.streamLongs( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next().longValue(), value);
+ });
+ assertFalse(values2.hasNext());
+
+ val.setValues(323L, -9423L, -1234L, 23423L, -1234L, -1234L);
+ remover.setValue(100L).setExists(true);
+ Iterator<Long> values3 = Arrays.asList(323L, -9423L, -1234L, 23423L, -1234L, -1234L).iterator();
+ func.streamLongs( value -> {
+ assertTrue(values3.hasNext());
+ assertEquals(values3.next().longValue(), value);
+ });
+ assertFalse(values3.hasNext());
+
+ val.setValues(10L);
+ remover.setValue(10L).setExists(true);
+ func.streamLongs( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+ }
+
+ @Test
+ public void multiValueFloatTest() {
+ TestFloatValueStream val = new TestFloatValueStream();
+ TestFloatValue remover = new TestFloatValue();
+
+ AnalyticsValueStream uncasted = RemoveFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, remover});
+ assertTrue(uncasted instanceof FloatValueStream);
+ FloatValueStream func = (FloatValueStream) uncasted;
+
+ // No values
+ val.setValues();
+ remover.setExists(false);
+ func.streamFloats( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ val.setValues();
+ remover.setValue(230.32F).setExists(true);
+ func.streamFloats( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Values exist
+ val.setValues(-1234.9478F, -9423.5F, -1234.9478F, 23423.324F, 942.0F);
+ remover.setValue(-1234.9478F).setExists(true);
+ Iterator<Float> values1 = Arrays.asList(-9423.5F, 23423.324F, 942.0F).iterator();
+ func.streamFloats( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value, .00000001);
+ });
+ assertFalse(values1.hasNext());
+
+ val.setValues(-1234.9478F, -9423.5F, -1234.9478F, 23423.324F, 942.0F);
+ remover.setExists(false);
+ Iterator<Float> values2 = Arrays.asList(-1234.9478F, -9423.5F, -1234.9478F, 23423.324F, 942.0F).iterator();
+ func.streamFloats( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value, .00000001);
+ });
+ assertFalse(values2.hasNext());
+
+ val.setValues(-1234.9478F, -9423.5F, -1234.9478F, 23423.324F, 942.0F);
+ remover.setValue(23423.5845F).setExists(true);
+ Iterator<Float> values3= Arrays.asList(-1234.9478F, -9423.5F, -1234.9478F, 23423.324F, 942.0F).iterator();
+ func.streamFloats( value -> {
+ assertTrue(values3.hasNext());
+ assertEquals(values3.next(), value, .00000001);
+ });
+ assertFalse(values3.hasNext());
+
+ val.setValues(23.56F, 23.56F, 23.56F);
+ remover.setValue(23.56F).setExists(true);
+ func.streamFloats( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+ }
+
+ @Test
+ public void multiValueDoubleTest() {
+ TestDoubleValueStream val = new TestDoubleValueStream();
+ TestDoubleValue remover = new TestDoubleValue();
+
+ AnalyticsValueStream uncasted = RemoveFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, remover});
+ assertTrue(uncasted instanceof DoubleValueStream);
+ DoubleValueStream func = (DoubleValueStream) uncasted;
+
+ // No values
+ val.setValues();
+ remover.setExists(false);
+ func.streamDoubles( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ val.setValues();
+ remover.setValue(234237.67).setExists(true);
+ func.streamDoubles( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Values exist
+ val.setValues(323.213, -9423.5, 124544.42);
+ remover.setValue(124544.42).setExists(true);
+ Iterator<Double> values1 = Arrays.asList(323.213, -9423.5).iterator();
+ func.streamDoubles( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value, .00000001);
+ });
+ assertFalse(values1.hasNext());
+
+ val.setValues(323.213, -9423.5, 124544.42);
+ remover.setExists(false);
+ Iterator<Double> values2 = Arrays.asList(323.213, -9423.5, 124544.42).iterator();
+ func.streamDoubles( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value, .00000001);
+ });
+ assertFalse(values2.hasNext());
+
+
+ val.setValues(323.213, -9423.5, 124544.42);
+ remover.setValue(345.34).setExists(true);
+ Iterator<Double> values3 = Arrays.asList(323.213, -9423.5, 124544.42).iterator();
+ func.streamDoubles( value -> {
+ assertTrue(values3.hasNext());
+ assertEquals(values3.next(), value, .00000001);
+ });
+ assertFalse(values1.hasNext());
+
+ val.setValues(3124.96, 3124.96);
+ remover.setValue(3124.96).setExists(true);
+ func.streamDoubles( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+ }
+
+ @Test
+ public void multiValueDateTest() throws DateTimeParseException {
+ Date date1 = Date.from(Instant.parse("1810-12-02T10:30:15Z"));
+ Date date2 = Date.from(Instant.parse("1931-03-16T18:15:45Z"));
+ Date date3 = Date.from(Instant.parse("2023-11-01T20:30:15Z"));
+
+ TestDateValueStream val = new TestDateValueStream();
+ TestDateValue remover = new TestDateValue();
+
+ AnalyticsValueStream uncasted = RemoveFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, remover});
+ assertTrue(uncasted instanceof DateValueStream);
+ DateValueStream func = (DateValueStream) uncasted;
+
+ // No values
+ val.setValues();
+ remover.setExists(false);
+ func.streamLongs( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ val.setValues();
+ remover.setValue("1700-12-14").setExists(true);
+ func.streamLongs( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Values exist
+ val.setValues("1810-12-02T10:30:15Z", "1931-03-16T18:15:45Z", "2023-11-01T20:30:15Z", "1931-03-16T18:15:45Z");
+ remover.setValue("1931-03-16T18:15:45Z").setExists(true);
+ Iterator<Long> values1 = Arrays.asList(date1.getTime(), date3.getTime()).iterator();
+ func.streamLongs( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next().longValue(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ val.setValues("1810-12-02T10:30:15Z", "1931-03-16T18:15:45Z", "2023-11-01T20:30:15Z", "1931-03-16T18:15:45Z");
+ remover.setExists(false);
+ Iterator<Long> values2 = Arrays.asList(date1.getTime(), date2.getTime(), date3.getTime(), date2.getTime()).iterator();
+ func.streamLongs( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next().longValue(), value);
+ });
+ assertFalse(values2.hasNext());
+
+ val.setValues("1810-12-02T10:30:15Z", "1931-03-16T18:15:45Z", "2023-11-01T20:30:15Z", "1931-03-16T18:15:45Z");
+ remover.setValue("1810-12-02T10:30:16Z").setExists(true);
+ Iterator<Long> values3 = Arrays.asList(date1.getTime(), date2.getTime(), date3.getTime(), date2.getTime()).iterator();
+ func.streamLongs( value -> {
+ assertTrue(values3.hasNext());
+ assertEquals(values3.next().longValue(), value);
+ });
+ assertFalse(values3.hasNext());
+
+ val.setValues("1810-12-02T10:30:15Z");
+ remover.setValue("1810-12-02T10:30:15Z").setExists(true);
+ func.streamLongs( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+ }
+
+ @Test
+ public void multiValueStringTest() {
+ TestStringValueStream val = new TestStringValueStream();
+ TestStringValue remover = new TestStringValue();
+
+ AnalyticsValueStream uncasted = RemoveFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, remover});
+ assertTrue(uncasted instanceof StringValueStream);
+ StringValueStream func = (StringValueStream) uncasted;
+
+ // No values
+ val.setValues();
+ remover.setExists(false);
+ func.streamStrings( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ val.setValues();
+ remover.setValue("ads").setExists(true);
+ func.streamStrings( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Values exist
+ val.setValues("abc", "123", "456", "abc");
+ remover.setValue("abc").setExists(true);
+ Iterator<String> values1 = Arrays.asList("123", "456").iterator();
+ func.streamStrings( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ val.setValues("abc", "123", "456", "abc");
+ remover.setExists(false);
+ Iterator<String> values2 = Arrays.asList("abc", "123", "456", "abc").iterator();
+ func.streamStrings( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value);
+ });
+ assertFalse(values2.hasNext());
+
+ val.setValues("string1", "another string", "the final and last string");
+ remover.setValue("not in values").setExists(true);
+ Iterator<String> values3 = Arrays.asList("string1", "another string", "the final and last string").iterator();
+ func.streamStrings( value -> {
+ assertTrue(values3.hasNext());
+ assertEquals(values3.next(), value);
+ });
+ assertFalse(values3.hasNext());
+
+ val.setValues("abc123", "abc123", "abc123", "abc123");
+ remover.setValue("abc123").setExists(true);
+ func.streamStrings( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+ }
+
+ @Test
+ public void multiValueObjectTest() {
+ TestAnalyticsValueStream val = new TestAnalyticsValueStream();
+ TestAnalyticsValue remover = new TestAnalyticsValue();
+
+ AnalyticsValueStream func = RemoveFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, remover});
+
+ // No values
+ val.setValues();
+ remover.setExists(false);
+ func.streamObjects( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ val.setValues();
+ remover.setValue("doesn't matter").setExists(true);
+ func.streamObjects( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Values exist
+ val.setValues("asdfs", new Date(12312), new Long(213123L), new Date(12312));
+ remover.setValue(new Date(12312)).setExists(true);
+ Iterator<Object> values1 = Arrays.<Object>asList("asdfs", new Long(213123L)).iterator();
+ func.streamObjects( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ val.setValues("asdfs", new Date(12312), new Long(213123L), new Date(12312));
+ remover.setExists(false);
+ Iterator<Object> values2 = Arrays.<Object>asList("asdfs", new Date(12312), new Long(213123L), new Date(12312)).iterator();
+ func.streamObjects( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value);
+ });
+ assertFalse(values2.hasNext());
+
+ val.setValues(new Date(3), "3", new Float(3F));
+ remover.setValue(new Date(4)).setExists(true);
+ Iterator<Object> values3 = Arrays.<Object>asList(new Date(3), "3", new Float(3F)).iterator();
+ func.streamObjects( value -> {
+ assertTrue(values3.hasNext());
+ assertEquals(values3.next(), value);
+ });
+ assertFalse(values3.hasNext());
+
+ val.setValues(new Date(4));
+ remover.setValue(new Date(4)).setExists(true);
+ func.streamObjects( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/ReplaceFunctionTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/ReplaceFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/ReplaceFunctionTest.java
new file mode 100644
index 0000000..c62546d
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/ReplaceFunctionTest.java
@@ -0,0 +1,990 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.function.mapping;
+
+import java.time.Instant;
+import java.time.format.DateTimeParseException;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.Iterator;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.analytics.value.AnalyticsValue;
+import org.apache.solr.analytics.value.AnalyticsValueStream;
+import org.apache.solr.analytics.value.BooleanValue;
+import org.apache.solr.analytics.value.BooleanValueStream;
+import org.apache.solr.analytics.value.DateValue;
+import org.apache.solr.analytics.value.DateValueStream;
+import org.apache.solr.analytics.value.DoubleValue;
+import org.apache.solr.analytics.value.DoubleValueStream;
+import org.apache.solr.analytics.value.FloatValue;
+import org.apache.solr.analytics.value.FloatValueStream;
+import org.apache.solr.analytics.value.IntValue;
+import org.apache.solr.analytics.value.IntValueStream;
+import org.apache.solr.analytics.value.LongValue;
+import org.apache.solr.analytics.value.LongValueStream;
+import org.apache.solr.analytics.value.StringValue;
+import org.apache.solr.analytics.value.StringValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestAnalyticsValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestAnalyticsValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestBooleanValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestBooleanValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestDateValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestDateValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestIntValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestIntValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestLongValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestLongValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestStringValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestStringValueStream;
+import org.junit.Test;
+
+public class ReplaceFunctionTest extends SolrTestCaseJ4 {
+
+ @Test
+ public void castingTest() {
+ assertTrue(ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestBooleanValue(), new TestStringValue(), new TestStringValue()}) instanceof StringValue);
+
+ assertFalse(ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestIntValueStream(), new TestFloatValue(), new TestDoubleValue()}) instanceof FloatValueStream);
+
+ assertFalse(ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestLongValueStream(), new TestDateValue(), new TestLongValue()}) instanceof DateValueStream);
+
+ assertFalse(ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestLongValue(), new TestAnalyticsValue(), new TestStringValue()}) instanceof StringValue);
+
+ assertTrue(ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestIntValue(), new TestLongValue(), new TestFloatValue()}) instanceof DoubleValue);
+
+ assertFalse(ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestDateValue(), new TestStringValue(), new TestLongValue()}) instanceof DateValue);
+
+ assertFalse(ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestBooleanValueStream(), new TestStringValue(), new TestStringValue()}) instanceof BooleanValueStream);
+
+ assertFalse(ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestDoubleValue(), new TestIntValue(), new TestLongValue()}) instanceof LongValue);
+ }
+
+ @Test
+ public void singleValueBooleanTest() {
+ TestBooleanValue val = new TestBooleanValue();
+ TestBooleanValue comp = new TestBooleanValue();
+ TestBooleanValue fill = new TestBooleanValue();
+
+ AnalyticsValueStream uncasted = ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, comp, fill});
+ assertTrue(uncasted instanceof BooleanValue);
+ BooleanValue func = (BooleanValue) uncasted;
+
+ // Value doesn't exist
+ val.setExists(false);
+ comp.setExists(false);
+ fill.setExists(false);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ val.setExists(false);
+ comp.setValue(false).setExists(true);
+ fill.setValue(true).setExists(true);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ // Comp doesn't exist
+ val.setValue(true).setExists(true);
+ comp.setExists(false);
+ fill.setValue(false).setExists(true);
+ assertEquals(true, func.getBoolean());
+ assertTrue(func.exists());
+
+ // Value exists
+ val.setValue(true).setExists(true);
+ comp.setValue(false).setExists(true);
+ fill.setValue(false).setExists(true);
+ assertEquals(true, func.getBoolean());
+ assertTrue(func.exists());
+
+ val.setValue(true).setExists(true);
+ comp.setValue(true).setExists(true);
+ fill.setValue(false).setExists(true);
+ assertEquals(false, func.getBoolean());
+ assertTrue(func.exists());
+
+ val.setValue(false).setExists(true);
+ comp.setValue(false).setExists(true);
+ fill.setExists(false);
+ func.getBoolean();
+ assertFalse(func.exists());
+ }
+
+ @Test
+ public void singleValueIntTest() {
+ TestIntValue val = new TestIntValue();
+ TestIntValue comp = new TestIntValue();
+ TestIntValue fill = new TestIntValue();
+
+ AnalyticsValueStream uncasted = ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, comp, fill});
+ assertTrue(uncasted instanceof IntValue);
+ IntValue func = (IntValue) uncasted;
+
+ // Value doesn't exist
+ val.setExists(false);
+ comp.setExists(false);
+ func.getInt();
+ assertFalse(func.exists());
+
+ val.setExists(false);
+ comp.setValue(-234).setExists(true);
+ fill.setValue(765).setExists(true);
+ func.getInt();
+ assertFalse(func.exists());
+
+ // Comp doesn't exist
+ val.setValue(745).setExists(true);
+ comp.setExists(false);
+ fill.setValue(23423).setExists(true);
+ assertEquals(745, func.getInt());
+ assertTrue(func.exists());
+
+ // Value exists
+ // Comp != Val
+ val.setValue(21).setExists(true);
+ comp.setValue(234).setExists(true);
+
+ fill.setValue(23423).setExists(true);
+ assertEquals(21, func.getInt());
+ assertTrue(func.exists());
+
+ fill.setExists(false);
+ assertEquals(21, func.getInt());
+ assertTrue(func.exists());
+
+ // Comp == Val
+ val.setValue(-154).setExists(true);
+ comp.setValue(-154).setExists(true);
+
+ fill.setExists(false);
+ func.getInt();
+ assertFalse(func.exists());
+
+ fill.setValue(23423).setExists(true);
+ assertEquals(23423, func.getInt());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void singleValueLongTest() {
+ TestLongValue val = new TestLongValue();
+ TestLongValue comp = new TestLongValue();
+ TestLongValue fill = new TestLongValue();
+
+ AnalyticsValueStream uncasted = ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, comp, fill});
+ assertTrue(uncasted instanceof LongValue);
+ LongValue func = (LongValue) uncasted;
+
+ // Value doesn't exist
+ val.setExists(false);
+ comp.setExists(false);
+ fill.setExists(false);
+ func.getLong();
+ assertFalse(func.exists());
+
+ val.setExists(false);
+ comp.setValue(234L).setExists(true);
+ fill.setValue(232584L).setExists(true);
+ func.getLong();
+ assertFalse(func.exists());
+
+ // Comp doesn't exist
+ val.setValue(745L).setExists(true);
+ comp.setExists(false);
+ fill.setValue(23423L).setExists(true);
+ assertEquals(745L, func.getLong());
+ assertTrue(func.exists());
+
+ // Value exists
+ // Comp != Val
+ val.setValue(21L).setExists(true);
+ comp.setValue(234L).setExists(true);
+
+ fill.setValue(23423L).setExists(true);
+ assertEquals(21L, func.getLong());
+ assertTrue(func.exists());
+
+ fill.setExists(false);
+ assertEquals(21L, func.getLong());
+ assertTrue(func.exists());
+
+ // Comp == Val
+ val.setValue(-154L).setExists(true);
+ comp.setValue(-154L).setExists(true);
+
+ fill.setExists(false);
+ func.getLong();
+ assertFalse(func.exists());
+
+ fill.setValue(23423L).setExists(true);
+ assertEquals(23423L, func.getLong());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void singleValueFloatTest() {
+ TestFloatValue val = new TestFloatValue();
+ TestFloatValue comp = new TestFloatValue();
+ TestFloatValue fill = new TestFloatValue();
+
+ AnalyticsValueStream uncasted = ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, comp, fill});
+ assertTrue(uncasted instanceof FloatValue);
+ FloatValue func = (FloatValue) uncasted;
+
+ // Value doesn't exist
+ val.setExists(false);
+ comp.setExists(false);
+ fill.setExists(false);
+ func.getFloat();
+ assertFalse(func.exists());
+
+ val.setExists(false);
+ comp.setValue(3124123.32F).setExists(true);
+ fill.setValue(-32473.336F).setExists(true);
+ func.getFloat();
+ assertFalse(func.exists());
+
+ // Comp doesn't exist
+ val.setValue(-745.234F).setExists(true);
+ comp.setExists(false);
+ fill.setValue(23423.324F).setExists(true);
+ assertEquals(-745.234F, func.getFloat(), .0000001);
+ assertTrue(func.exists());
+
+ // Value exists
+ // Comp != Val
+ val.setValue(3423.304F).setExists(true);
+ comp.setValue(3423.303F).setExists(true);
+
+ fill.setValue(-23.764F).setExists(true);
+ assertEquals(3423.304F, func.getFloat(), .0000001);
+ assertTrue(func.exists());
+
+ fill.setExists(false);
+ assertEquals(3423.304F, func.getFloat(), .0000001);
+ assertTrue(func.exists());
+
+ // Comp == Val
+ val.setValue(-154.45F).setExists(true);
+ comp.setValue(-154.45F).setExists(true);
+
+ fill.setExists(false);
+ func.getFloat();
+ assertFalse(func.exists());
+
+ fill.setValue(4353434.234F).setExists(true);
+ assertEquals(4353434.234F, func.getFloat(), .0000001);
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void singleValueDoubleTest() {
+ TestDoubleValue val = new TestDoubleValue();
+ TestDoubleValue comp = new TestDoubleValue();
+ TestDoubleValue fill = new TestDoubleValue();
+
+ AnalyticsValueStream uncasted = ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, comp, fill});
+ assertTrue(uncasted instanceof DoubleValue);
+ DoubleValue func = (DoubleValue) uncasted;
+
+ // Value doesn't exist
+ val.setExists(false);
+ comp.setExists(false);
+ fill.setExists(false);
+ func.getDouble();
+ assertFalse(func.exists());
+
+ val.setExists(false);
+ comp.setValue(3124123.32).setExists(true);
+ fill.setValue(-13242.34).setExists(true);
+ func.getDouble();
+ assertFalse(func.exists());
+
+ // Comp doesn't exist
+ val.setValue(-745.234).setExists(true);
+ comp.setExists(false);
+ fill.setValue(23423.324).setExists(true);
+ assertEquals(-745.234, func.getDouble(), .0000001);
+ assertTrue(func.exists());
+
+ // Value exists
+ // Comp != Val
+ val.setValue(34923.304).setExists(true);
+ comp.setValue(34923.303).setExists(true);
+
+ fill.setValue(-23.764).setExists(true);
+ assertEquals(34923.304, func.getDouble(), .0000001);
+ assertTrue(func.exists());
+
+ fill.setExists(false);
+ assertEquals(34923.304, func.getDouble(), .0000001);
+ assertTrue(func.exists());
+
+ // Comp == Val
+ val.setValue(-154.45).setExists(true);
+ comp.setValue(-154.45).setExists(true);
+
+ fill.setExists(false);
+ func.getDouble();
+ assertFalse(func.exists());
+
+ fill.setValue(4353434.234).setExists(true);
+ assertEquals(4353434.234, func.getDouble(), .0000001);
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void singleValueDateTest() throws DateTimeParseException {
+ Date date1 = Date.from(Instant.parse("1810-12-02T10:30:15Z"));
+ Date date2 = Date.from(Instant.parse("1950-02-23T14:54:34Z"));
+
+ TestDateValue val = new TestDateValue();
+ TestDateValue comp = new TestDateValue();
+ TestDateValue fill = new TestDateValue();
+
+ AnalyticsValueStream uncasted = ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, comp, fill});
+ assertTrue(uncasted instanceof DateValue);
+ DateValue func = (DateValue) uncasted;
+
+ // Value doesn't exist
+ val.setExists(false);
+ comp.setExists(false);
+ fill.setExists(false);
+ func.getLong();
+ assertFalse(func.exists());
+
+ val.setExists(false);
+ comp.setValue("1950-02-23T14:54:34Z").setExists(true);
+ fill.setValue("1350-02-26T14:34:34Z").setExists(true);
+ func.getLong();
+ assertFalse(func.exists());
+
+ // Comp doesn't exist
+ val.setValue("1950-02-23T14:54:34Z").setExists(true);
+ comp.setExists(false);
+ fill.setValue("1350-02-26T14:34:34Z").setExists(true);
+ assertEquals(date2.getTime(), func.getLong());
+ assertTrue(func.exists());
+
+ // Value exists
+ // Comp != Val
+ val.setValue("1950-02-23T14:54:34Z").setExists(true);
+ comp.setValue("1350-02-26T14:34:34Z").setExists(true);
+
+ fill.setValue("2023-11-01T20:30:15Z").setExists(true);
+ assertEquals(date2.getTime(), func.getLong());
+ assertTrue(func.exists());
+
+ fill.setExists(false);
+ assertEquals(date2.getTime(), func.getLong());
+ assertTrue(func.exists());
+
+ // Comp == Val
+ val.setValue("2023-11-01T20:30:15Z").setExists(true);
+ comp.setValue("2023-11-01T20:30:15Z").setExists(true);
+
+ fill.setExists(false);
+ func.getLong();
+ assertFalse(func.exists());
+
+ fill.setValue("1810-12-02T10:30:15Z").setExists(true);
+ assertEquals(date1.getTime(), func.getLong());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void singleValueStringTest() {
+ TestStringValue val = new TestStringValue();
+ TestStringValue comp = new TestStringValue();
+ TestStringValue fill = new TestStringValue();
+
+ AnalyticsValueStream uncasted = ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, comp, fill});
+ assertTrue(uncasted instanceof StringValue);
+ StringValue func = (StringValue) uncasted;
+
+ // Value doesn't exist
+ val.setExists(false);
+ comp.setExists(false);
+ fill.setExists(false);
+ func.getString();
+ assertFalse(func.exists());
+
+ val.setExists(false);
+ comp.setValue("abc456").setExists(true);
+ fill.setValue("not touched").setExists(true);
+ func.getString();
+ assertFalse(func.exists());
+
+ // Comp doesn't exist
+ val.setValue("abcd").setExists(true);
+ comp.setExists(false);
+ fill.setValue("12234").setExists(true);
+ assertEquals("abcd", func.getString());
+ assertTrue(func.exists());
+
+ // Value exists
+ // Comp != Val
+ val.setValue("original").setExists(true);
+ comp.setValue("different").setExists(true);
+
+ fill.setValue("anything").setExists(true);
+ assertEquals("original", func.getString());
+ assertTrue(func.exists());
+
+ fill.setExists(false);
+ assertEquals("original", func.getString());
+ assertTrue(func.exists());
+
+ // Comp == Val
+ val.setValue("the same").setExists(true);
+ comp.setValue("the same").setExists(true);
+
+ fill.setExists(false);
+ func.getString();
+ assertFalse(func.exists());
+
+ fill.setValue("replacement").setExists(true);
+ assertEquals("replacement", func.getString());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void singleValueObjectTest() {
+ TestAnalyticsValue val = new TestAnalyticsValue();
+ TestAnalyticsValue comp = new TestAnalyticsValue();
+ TestAnalyticsValue fill = new TestAnalyticsValue();
+
+ AnalyticsValueStream uncasted = ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, comp, fill});
+ assertTrue(uncasted instanceof AnalyticsValue);
+ AnalyticsValue func = (AnalyticsValue) uncasted;
+
+ // Value doesn't exist
+ val.setExists(false);
+ comp.setExists(false);
+ fill.setExists(false);
+ func.getObject();
+ assertFalse(func.exists());
+
+ val.setExists(false);
+ comp.setValue(new Boolean(true)).setExists(true);
+ fill.setValue("abc").setExists(true);
+ func.getObject();
+ assertFalse(func.exists());
+
+ // Comp doesn't exist
+ val.setValue("abcd").setExists(true);
+ comp.setExists(false);
+ fill.setValue(new Date(123321)).setExists(true);
+ assertEquals("abcd", func.getObject());
+ assertTrue(func.exists());
+
+ // Value exists
+ // Comp != Val
+ val.setValue(new Date(1234)).setExists(true);
+ comp.setValue(new Integer(1234)).setExists(true);
+
+ fill.setValue("not used").setExists(true);
+ assertEquals(new Date(1234), func.getObject());
+ assertTrue(func.exists());
+
+ fill.setExists(false);
+ assertEquals(new Date(1234), func.getObject());
+ assertTrue(func.exists());
+
+ // Comp == Val
+ val.setValue(new Float(2342.324F)).setExists(true);
+ comp.setValue(new Float(2342.324F)).setExists(true);
+
+ fill.setExists(false);
+ func.getObject();
+ assertFalse(func.exists());
+
+ fill.setValue("replacement").setExists(true);
+ assertEquals("replacement", func.getObject());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void multiValueBooleanTest() {
+ TestBooleanValueStream val = new TestBooleanValueStream();
+ TestBooleanValue comp = new TestBooleanValue();
+ TestBooleanValue fill = new TestBooleanValue();
+
+ AnalyticsValueStream uncasted = ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, comp, fill});
+ assertTrue(uncasted instanceof BooleanValueStream);
+ BooleanValueStream func = (BooleanValueStream) uncasted;
+
+ // No values
+ val.setValues();
+ comp.setExists(false);
+ fill.setExists(false);
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ val.setValues();
+ comp.setValue(true).setExists(true);
+ fill.setValue(false).setExists(true);
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Comp doesn't exist
+ val.setValues(false, true, false, true, true);
+ comp.setExists(false);
+ fill.setValue(true).setExists(true);
+ Iterator<Boolean> values1 = Arrays.asList(false, true, false, true, true).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ // Values exist
+ val.setValues(false, true, false, true, true);
+ comp.setValue(true).setExists(true);
+ fill.setValue(false).setExists(true);
+ Iterator<Boolean> values2 = Arrays.asList(false, false, false, false, false).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value);
+ });
+ assertFalse(values2.hasNext());
+
+ val.setValues(false, true, false, true, true);
+ comp.setValue(false).setExists(true);
+ fill.setExists(false);
+ Iterator<Boolean> values3 = Arrays.asList(true, true, true).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values3.hasNext());
+ assertEquals(values3.next(), value);
+ });
+ assertFalse(values3.hasNext());
+ }
+
+ @Test
+ public void multiValueIntTest() {
+ TestIntValueStream val = new TestIntValueStream();
+ TestIntValue comp = new TestIntValue();
+ TestIntValue fill = new TestIntValue();
+
+ AnalyticsValueStream uncasted = ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, comp, fill});
+ assertTrue(uncasted instanceof IntValueStream);
+ IntValueStream func = (IntValueStream) uncasted;
+
+ // No values
+ val.setValues();
+ comp.setExists(false);
+ fill.setExists(false);
+ func.streamInts( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ val.setValues();
+ comp.setValue(324).setExists(true);
+ fill.setValue(52341).setExists(true);
+ func.streamInts( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Comp doesn't exist
+ val.setValues(1, 234, -234, 4439, -234, -3245);
+ comp.setExists(false);
+ fill.setValue(52135).setExists(true);
+ Iterator<Integer> values1 = Arrays.asList(1, 234, -234, 4439, -234, -3245).iterator();
+ func.streamInts( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next().intValue(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ // Values exist
+ val.setValues(1, 234, -234, 4439, -234, -3245);
+ comp.setValue(-234).setExists(true);
+ fill.setExists(false);
+ Iterator<Integer> values2 = Arrays.asList(1, 234, 4439, -3245).iterator();
+ func.streamInts( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next().intValue(), value);
+ });
+ assertFalse(values2.hasNext());
+
+ val.setValues(1, 234, -234, 4439, -234, -3245);
+ comp.setValue(4439).setExists(true);
+ fill.setValue(-1000).setExists(true);
+ Iterator<Integer> values3 = Arrays.asList(1, 234, -234, -1000, -234, -3245).iterator();
+ func.streamInts( value -> {
+ assertTrue(values3.hasNext());
+ assertEquals(values3.next().intValue(), value);
+ });
+ assertFalse(values3.hasNext());
+ }
+
+ @Test
+ public void multiValueLongTest() {
+ TestLongValueStream val = new TestLongValueStream();
+ TestLongValue comp = new TestLongValue();
+ TestLongValue fill = new TestLongValue();
+
+ AnalyticsValueStream uncasted = ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, comp, fill});
+ assertTrue(uncasted instanceof LongValueStream);
+ LongValueStream func = (LongValueStream) uncasted;
+
+ // No values
+ val.setValues();
+ comp.setExists(false);
+ fill.setExists(false);
+ func.streamLongs( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ val.setValues();
+ comp.setValue(2323L).setExists(true);
+ fill.setValue(-5943L).setExists(true);
+ func.streamLongs( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Comp doesn't exist
+ val.setValues(1L, 234L, -234L, 4439L, -234L, -3245L);
+ comp.setExists(false);
+ fill.setValue(52135L).setExists(true);
+ Iterator<Long> values1 = Arrays.asList(1L, 234L, -234L, 4439L, -234L, -3245L).iterator();
+ func.streamLongs( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next().longValue(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ // Values exist
+ val.setValues(1L, 234L, -234L, 4439L, -234L, -3245L);
+ comp.setValue(-234L).setExists(true);
+ fill.setExists(false);
+ Iterator<Long> values2 = Arrays.asList(1L, 234L, 4439L, -3245L).iterator();
+ func.streamLongs( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next().longValue(), value);
+ });
+ assertFalse(values2.hasNext());
+
+ val.setValues(1L, 234L, -234L, 4439L, -234L, -3245L);
+ comp.setValue(4439L).setExists(true);
+ fill.setValue(-1000L).setExists(true);
+ Iterator<Long> values3 = Arrays.asList(1L, 234L, -234L, -1000L, -234L, -3245L).iterator();
+ func.streamLongs( value -> {
+ assertTrue(values3.hasNext());
+ assertEquals(values3.next().longValue(), value);
+ });
+ assertFalse(values3.hasNext());
+ }
+
+ @Test
+ public void multiValueFloatTest() {
+ TestFloatValueStream val = new TestFloatValueStream();
+ TestFloatValue comp = new TestFloatValue();
+ TestFloatValue fill = new TestFloatValue();
+
+ AnalyticsValueStream uncasted = ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, comp, fill});
+ assertTrue(uncasted instanceof FloatValueStream);
+ FloatValueStream func = (FloatValueStream) uncasted;
+
+ // No values
+ val.setValues();
+ comp.setExists(false);
+ fill.setExists(false);
+ func.streamFloats( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ val.setValues();
+ comp.setValue(-230.32F).setExists(true);
+ fill.setValue(9459.3458F).setExists(true);
+ func.streamFloats( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Comp doesn't exist
+ val.setValues(1423.3F, 423.4323F, -2349.2F, -343.43934F, 423.4323F);
+ comp.setExists(false);
+ fill.setValue(234.234F).setExists(true);
+ Iterator<Float> values1 = Arrays.asList(1423.3F, 423.4323F, -2349.2F, -343.43934F, 423.4323F).iterator();
+ func.streamFloats( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value, .000001);
+ });
+ assertFalse(values1.hasNext());
+
+ // Values exist
+ val.setValues(1423.3F, 423.4323F, -2349.2F, -343.43934F, 423.4323F);
+ comp.setValue(423.4323F).setExists(true);
+ fill.setExists(false);
+ Iterator<Float> values2 = Arrays.asList(1423.3F, -2349.2F, -343.43934F).iterator();
+ func.streamFloats( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value, .000001);
+ });
+ assertFalse(values2.hasNext());
+
+ val.setValues(1423.3F, 423.4323F, -2349.2F, -343.43934F, 423.4323F);
+ comp.setValue(423.4323F).setExists(true);
+ fill.setValue(-1000F).setExists(true);
+ Iterator<Float> values3 = Arrays.asList(1423.3F, -1000F, -2349.2F, -343.43934F, -1000F).iterator();
+ func.streamFloats( value -> {
+ assertTrue(values3.hasNext());
+ assertEquals(values3.next(), value, .000001);
+ });
+ assertFalse(values3.hasNext());
+ }
+
+ @Test
+ public void multiValueDoubleTest() {
+ TestDoubleValueStream val = new TestDoubleValueStream();
+ TestDoubleValue comp = new TestDoubleValue();
+ TestDoubleValue fill = new TestDoubleValue();
+
+ AnalyticsValueStream uncasted = ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, comp, fill});
+ assertTrue(uncasted instanceof DoubleValueStream);
+ DoubleValueStream func = (DoubleValueStream) uncasted;
+
+ // No values
+ val.setValues();
+ comp.setExists(false);
+ fill.setExists(false);
+ func.streamDoubles( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ val.setValues();
+ comp.setValue(234237.67).setExists(true);
+ fill.setValue(-234.312).setExists(true);
+ func.streamDoubles( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Comp doesn't exist
+ val.setValues(1423.3, 423.4323, -2349.2, -343.43934, 423.4323);
+ comp.setExists(false);
+ fill.setValue(234.234).setExists(true);
+ Iterator<Double> values1 = Arrays.asList(1423.3, 423.4323, -2349.2, -343.43934, 423.4323).iterator();
+ func.streamDoubles( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value, .000001);
+ });
+ assertFalse(values1.hasNext());
+
+ // Values exist
+ val.setValues(1423.3, 423.4323, -2349.2, -343.43934, 423.4323);
+ comp.setValue(423.4323).setExists(true);
+ fill.setExists(false);
+ Iterator<Double> values2 = Arrays.asList(1423.3, -2349.2, -343.43934).iterator();
+ func.streamDoubles( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value, .000001);
+ });
+ assertFalse(values2.hasNext());
+
+ val.setValues(1423.3, 423.4323, -2349.2, -343.43934, 423.4323);
+ comp.setValue(423.4323).setExists(true);
+ fill.setValue(-1000.0).setExists(true);
+ Iterator<Double> values3 = Arrays.asList(1423.3, -1000.0, -2349.2, -343.43934, -1000.0).iterator();
+ func.streamDoubles( value -> {
+ assertTrue(values3.hasNext());
+ assertEquals(values3.next(), value, .000001);
+ });
+ assertFalse(values3.hasNext());
+ }
+
+ @Test
+ public void multiValueDateTest() throws DateTimeParseException {
+ Date date1 = Date.from(Instant.parse("1810-12-02T10:30:15Z"));
+ Date date2 = Date.from(Instant.parse("1931-03-16T18:15:45Z"));
+ Date date3 = Date.from(Instant.parse("2023-11-01T20:30:15Z"));
+
+ TestDateValueStream val = new TestDateValueStream();
+ TestDateValue comp = new TestDateValue();
+ TestDateValue fill = new TestDateValue();
+
+ AnalyticsValueStream uncasted = ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, comp, fill});
+ assertTrue(uncasted instanceof DateValueStream);
+ DateValueStream func = (DateValueStream) uncasted;
+
+ // No values
+ val.setValues();
+ comp.setExists(false);
+ fill.setExists(false);
+ func.streamLongs( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ val.setValues();
+ comp.setValue("1700-12-14").setExists(true);
+ fill.setValue("3450-04-23").setExists(true);
+ func.streamLongs( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Comp doesn't exist
+ val.setValues("1810-12-02T10:30:15Z", "1931-03-16T18:15:45Z", "2023-11-01T20:30:15Z", "1931-03-16T18:15:45Z");
+ comp.setExists(false);
+ fill.setValue("1810-12-02T10:30:15Z").setExists(true);
+ Iterator<Long> values1 = Arrays.asList(date1.getTime(), date2.getTime(), date3.getTime(), date2.getTime()).iterator();
+ func.streamLongs( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next().longValue(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ // Values exist
+ val.setValues("1810-12-02T10:30:15Z", "1931-03-16T18:15:45Z", "2023-11-01T20:30:15Z", "1931-03-16T18:15:45Z");
+ comp.setValue("1931-03-16T18:15:45Z").setExists(true);
+ fill.setExists(false);
+ Iterator<Long> values2 = Arrays.asList(date1.getTime(), date3.getTime()).iterator();
+ func.streamLongs( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next().longValue(), value);
+ });
+ assertFalse(values2.hasNext());
+
+ val.setValues("1810-12-02T10:30:15Z", "1931-03-16T18:15:45Z", "2023-11-01T20:30:15Z", "1931-03-16T18:15:45Z");
+ comp.setValue("1931-03-16T18:15:45Z").setExists(true);
+ fill.setValue("1810-12-02T10:30:15Z").setExists(true);
+ Iterator<Long> values3 = Arrays.asList(date1.getTime(), date1.getTime(), date3.getTime(), date1.getTime()).iterator();
+ func.streamLongs( value -> {
+ assertTrue(values3.hasNext());
+ assertEquals(values3.next().longValue(), value);
+ });
+ assertFalse(values3.hasNext());
+ }
+
+ @Test
+ public void multiValueStringTest() {
+ TestStringValueStream val = new TestStringValueStream();
+ TestStringValue comp = new TestStringValue();
+ TestStringValue fill = new TestStringValue();
+
+ AnalyticsValueStream uncasted = ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, comp, fill});
+ assertTrue(uncasted instanceof StringValueStream);
+ StringValueStream func = (StringValueStream) uncasted;
+
+ // No values
+ val.setValues();
+ comp.setExists(false);
+ fill.setExists(false);
+ func.streamStrings( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ val.setValues();
+ comp.setValue("ads").setExists(true);
+ fill.setValue("empty").setExists(true);
+ func.streamStrings( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Comp doesn't exist
+ val.setValues("abc", "123", "456", "def", "123");
+ comp.setExists(false);
+ fill.setValue("won't show up").setExists(true);
+ Iterator<String> values1 = Arrays.asList("abc", "123", "456", "def", "123").iterator();
+ func.streamStrings( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ // Values exist
+ val.setValues("abc", "123", "456", "def", "123");
+ comp.setValue("123").setExists(true);
+ fill.setExists(false);
+ Iterator<String> values2 = Arrays.asList("abc", "456", "def").iterator();
+ func.streamStrings( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value);
+ });
+ assertFalse(values2.hasNext());
+
+ val.setValues("abc", "123", "456", "def", "123");
+ comp.setValue("456").setExists(true);
+ fill.setValue("changed").setExists(true);
+ Iterator<String> values3 = Arrays.asList("abc", "123", "changed", "def", "123").iterator();
+ func.streamStrings( value -> {
+ assertTrue(values3.hasNext());
+ assertEquals(values3.next(), value);
+ });
+ assertFalse(values3.hasNext());
+ }
+
+ @Test
+ public void multiValueObjectTest() {
+ TestAnalyticsValueStream val = new TestAnalyticsValueStream();
+ TestAnalyticsValue comp = new TestAnalyticsValue();
+ TestAnalyticsValue fill = new TestAnalyticsValue();
+
+ AnalyticsValueStream func = ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, comp, fill});
+
+ // No values
+ val.setValues();
+ comp.setExists(false);
+ fill.setExists(false);
+ func.streamObjects( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ val.setValues();
+ comp.setValue("doesn't matter").setExists(true);
+ fill.setValue("won't show up").setExists(true);
+ func.streamObjects( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Comp doesn't exist
+ val.setValues("asdfs", new Date(12312), new Long(213123L), new Date(12312));
+ comp.setExists(false);
+ fill.setValue("won't show up").setExists(true);
+ Iterator<Object> values1 = Arrays.<Object>asList("asdfs", new Date(12312), new Long(213123L), new Date(12312)).iterator();
+ func.streamObjects( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ // Values exist
+ val.setValues("asdfs", new Date(12312), new Long(213123L), new Date(12312));
+ comp.setValue("asdfs").setExists(true);
+ fill.setExists(false);
+ Iterator<Object> values2 = Arrays.<Object>asList(new Date(12312), new Long(213123L), new Date(12312)).iterator();
+ func.streamObjects( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value);
+ });
+ assertFalse(values2.hasNext());
+
+ val.setValues("asdfs", new Date(12312), new Long(213123L), new Date(12312));
+ comp.setValue(new Date(12312)).setExists(true);
+ fill.setValue(new Boolean(false)).setExists(true);
+ Iterator<Object> values3 = Arrays.<Object>asList("asdfs", new Boolean(false), new Long(213123L), new Boolean(false)).iterator();
+ func.streamObjects( value -> {
+ assertTrue(values3.hasNext());
+ assertEquals(values3.next(), value);
+ });
+ assertFalse(values3.hasNext());
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/RoundFunctionTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/RoundFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/RoundFunctionTest.java
new file mode 100644
index 0000000..2da48f5
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/RoundFunctionTest.java
@@ -0,0 +1,180 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.function.mapping;
+
+import java.util.Arrays;
+import java.util.Iterator;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.analytics.function.mapping.DecimalNumericConversionFunction.RoundFunction;
+import org.apache.solr.analytics.value.AnalyticsValueStream;
+import org.apache.solr.analytics.value.IntValue;
+import org.apache.solr.analytics.value.IntValueStream;
+import org.apache.solr.analytics.value.LongValue;
+import org.apache.solr.analytics.value.LongValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestIntValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestIntValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestLongValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestLongValueStream;
+import org.junit.Test;
+
+public class RoundFunctionTest extends SolrTestCaseJ4 {
+
+ @Test
+ public void singleValueFloatParameterTest() {
+ TestFloatValue val = new TestFloatValue();
+
+ AnalyticsValueStream uncasted = RoundFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof IntValue);
+ IntValue func = (IntValue) uncasted;
+
+ // Value doesn't exist
+ val.setExists(false);
+ func.getInt();
+ assertFalse(func.exists());
+
+ // Value exists
+ val.setValue(21.56F).setExists(true);
+ assertEquals(22, func.getInt());
+ assertTrue(func.exists());
+
+ val.setValue(-100.3F).setExists(true);
+ assertEquals(-100, func.getInt());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void singleValueDoubleParameterTest() {
+ TestDoubleValue val = new TestDoubleValue();
+
+ AnalyticsValueStream uncasted = RoundFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof LongValue);
+ LongValue func = (LongValue) uncasted;
+
+ // Value doesn't exist
+ val.setExists(false);
+ func.getLong();
+ assertFalse(func.exists());
+
+ // Value exists
+ val.setValue(21.56).setExists(true);
+ assertEquals(22L, func.getLong());
+ assertTrue(func.exists());
+
+ val.setValue(-100.3).setExists(true);
+ assertEquals(-100L, func.getLong());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void multiValueFloatParameterTest() {
+ TestFloatValueStream val = new TestFloatValueStream();
+
+ AnalyticsValueStream uncasted = RoundFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof IntValueStream);
+ IntValueStream func = (IntValueStream) uncasted;
+
+ // No values
+ val.setValues();
+ func.streamInts( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // One value
+ val.setValues(-4F);
+ Iterator<Integer> values1 = Arrays.asList(-4).iterator();
+ func.streamInts( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next().intValue(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ // Multiple values
+ val.setValues(4F, -10.9999F, 50.00001F, 74.99999F, 101.4999F, 105.5F);
+ Iterator<Integer> values2 = Arrays.asList(4, -11, 50, 75, 101, 106).iterator();
+ func.streamInts( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next().intValue(), value);
+ });
+ assertFalse(values2.hasNext());
+ }
+
+ @Test
+ public void multiValueDoubleParameterTest() {
+ TestDoubleValueStream val = new TestDoubleValueStream();
+
+ AnalyticsValueStream uncasted = RoundFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof LongValueStream);
+ LongValueStream func = (LongValueStream) uncasted;
+
+ // No values
+ val.setValues();
+ func.streamLongs( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // One value
+ val.setValues(-4);
+ Iterator<Long> values1 = Arrays.asList(-4L).iterator();
+ func.streamLongs( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next().longValue(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ // Multiple values
+ val.setValues(4, -10.9999, 50.000001, 74.99999, 101.4999, 105.5);
+ Iterator<Long> values2 = Arrays.asList(4L, -11L, 50L, 75L, 101L, 106L).iterator();
+ func.streamLongs( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next().longValue(), value);
+ });
+ assertFalse(values2.hasNext());
+ }
+
+ @Test
+ public void nonDecimalParameterTest() {
+ AnalyticsValueStream result;
+ AnalyticsValueStream param;
+
+ param = new TestIntValue();
+ result = RoundFunction.creatorFunction.apply(new AnalyticsValueStream[] {param});
+ assertTrue(result instanceof IntValue);
+ assertEquals(param, result);
+
+ param = new TestIntValueStream();
+ result = RoundFunction.creatorFunction.apply(new AnalyticsValueStream[] {param});
+ assertTrue(result instanceof IntValueStream);
+ assertEquals(param, result);
+
+ param = new TestLongValue();
+ result = RoundFunction.creatorFunction.apply(new AnalyticsValueStream[] {param});
+ assertTrue(result instanceof LongValue);
+ assertEquals(param, result);
+
+ param = new TestLongValueStream();
+ result = RoundFunction.creatorFunction.apply(new AnalyticsValueStream[] {param});
+ assertTrue(result instanceof LongValueStream);
+ assertEquals(param, result);
+ }
+
+
+}
[02/20] lucene-solr:master: SOLR-11145,
SOLR-11146: Added comprehensive unit tests for Analytics Component
2.0 as well as analytics bug fixes.
Posted by dp...@apache.org.
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyRangeFacetTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyRangeFacetTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyRangeFacetTest.java
new file mode 100644
index 0000000..329645e
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyRangeFacetTest.java
@@ -0,0 +1,417 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.legacy.facet;
+
+
+import java.util.ArrayList;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+
+public class LegacyRangeFacetTest extends LegacyAbstractAnalyticsFacetTest {
+ static String fileName = "rangeFacets.txt";
+
+ public static final int INT = 71;
+ public static final int LONG = 36;
+ public static final int FLOAT = 93;
+ public static final int DOUBLE = 48;
+ public static final int DATE = 52;
+ public static final int STRING = 28;
+ public static final int NUM_LOOPS = 100;
+
+ //INT
+ static ArrayList<ArrayList<Integer>> intLongTestStart;
+ static ArrayList<ArrayList<Integer>> intDoubleTestStart;
+ static ArrayList<ArrayList<Integer>> intDateTestStart;
+
+ //FLOAT
+ static ArrayList<ArrayList<Float>> floatLongTestStart;
+ static ArrayList<ArrayList<Float>> floatDoubleTestStart;
+ static ArrayList<ArrayList<Float>> floatDateTestStart;
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ initCore("solrconfig-analytics.xml","schema-analytics.xml");
+ h.update("<delete><query>*:*</query></delete>");
+
+ //INT
+ intLongTestStart = new ArrayList<>();
+ intDoubleTestStart = new ArrayList<>();
+ intDateTestStart = new ArrayList<>();
+
+ //FLOAT
+ floatLongTestStart = new ArrayList<>();
+ floatDoubleTestStart = new ArrayList<>();
+ floatDateTestStart = new ArrayList<>();
+
+ for (int j = 0; j < NUM_LOOPS; ++j) {
+ int i = j%INT;
+ long l = j%LONG;
+ float f = j%FLOAT;
+ double d = j%DOUBLE;
+ int dt = j%DATE;
+ int s = j%STRING;
+ assertU(adoc("id", "1000" + j, "int_id", "" + i, "long_ld", "" + l, "float_fd", "" + f,
+ "double_dd", "" + d, "date_dtd", (1000+dt) + "-01-01T23:59:59Z", "string_sd", "abc" + s));
+ //Longs
+ if (j-LONG<0) {
+ ArrayList<Integer> list1 = new ArrayList<>();
+ list1.add(i);
+ intLongTestStart.add(list1);
+ ArrayList<Float> list2 = new ArrayList<>();
+ list2.add(f);
+ floatLongTestStart.add(list2);
+ } else {
+ intLongTestStart.get((int)l).add(i);
+ floatLongTestStart.get((int)l).add(f);
+ }
+ //Doubles
+ if (j-DOUBLE<0) {
+ ArrayList<Integer> list1 = new ArrayList<>();
+ list1.add(i);
+ intDoubleTestStart.add(list1);
+ ArrayList<Float> list2 = new ArrayList<>();
+ list2.add(f);
+ floatDoubleTestStart.add(list2);
+ } else {
+ intDoubleTestStart.get((int)d).add(i);
+ floatDoubleTestStart.get((int)d).add(f);
+ }
+ //Dates
+ if (j-DATE<0) {
+ ArrayList<Integer> list1 = new ArrayList<>();
+ list1.add(i);
+ intDateTestStart.add(list1);
+ ArrayList<Float> list2 = new ArrayList<>();
+ list2.add(f);
+ floatDateTestStart.add(list2);
+ } else {
+ intDateTestStart.get(dt).add(i);
+ floatDateTestStart.get(dt).add(f);
+ }
+
+ if (usually()) {
+ assertU(commit()); // to have several segments
+ }
+ }
+
+ assertU(commit());
+
+ setResponse(h.query(request(fileToStringArr(LegacyRangeFacetTest.class, fileName))));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void rangeTest() throws Exception {
+
+ //Int Long
+ ArrayList<Long> intLong = getLongList("ri", "rangeFacets", "long_ld", "long", "count");
+ ArrayList<Long> intLongTest = calculateStat(transformLists(intLongTestStart, 5, 30, 5
+ , false, true, false, false, false), "count");
+ assertEquals(getRawResponse(), intLong,intLongTest);
+ //Int Double
+ ArrayList<Double> intDouble = getDoubleList("ri", "rangeFacets", "double_dd", "double", "mean");
+ ArrayList<Double> intDoubleTest = calculateNumberStat(transformLists(intDoubleTestStart, 3, 39, 7
+ , false, false, true, false, true), "mean");
+ assertEquals(getRawResponse(), intDouble,intDoubleTest);
+ //Int Date
+ ArrayList<Long> intDate = getLongList("ri", "rangeFacets", "date_dtd", "long", "count");
+ ArrayList<Long> intDateTest = (ArrayList<Long>)calculateStat(transformLists(intDateTestStart, 7, 44, 7
+ , false, true, false, true, true), "count");
+ assertEquals(getRawResponse(), intDate,intDateTest);
+
+ //Float Long
+ ArrayList<Double> floatLong = getDoubleList("rf", "rangeFacets", "long_ld", "double", "median");
+ ArrayList<Double> floatLongTest = calculateNumberStat(transformLists(floatLongTestStart, 0, 29, 4
+ , false, true, true, true, true), "median");
+ assertEquals(getRawResponse(), floatLong,floatLongTest);
+ //Float Double
+ ArrayList<Long> floatDouble = getLongList("rf", "rangeFacets", "double_dd", "long", "count");
+ ArrayList<Long> floatDoubleTest = (ArrayList<Long>)calculateStat(transformLists(floatDoubleTestStart, 4, 47, 11
+ , false, false, false, true, false), "count");
+ assertEquals(getRawResponse(), floatDouble,floatDoubleTest);
+ }
+
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void hardendRangeTest() throws Exception {
+ //Int Long
+ ArrayList<Double> intLong = getDoubleList("hi", "rangeFacets", "long_ld", "double", "sum");
+ ArrayList<Double> intLongTest = calculateNumberStat(transformLists(intLongTestStart, 5, 30, 5
+ , true, true, false, false, false), "sum");
+ assertEquals(getRawResponse(), intLong,intLongTest);
+ //Int Double
+ ArrayList<Double> intDouble = getDoubleList("hi", "rangeFacets", "double_dd", "double", "mean");
+ ArrayList<Double> intDoubleTest = calculateNumberStat(transformLists(intDoubleTestStart, 3, 39, 7
+ , true, false, true, false, true), "mean");
+ assertEquals(getRawResponse(), intDouble,intDoubleTest);
+ //Int Date
+ ArrayList<Long> intDate = getLongList("hi", "rangeFacets", "date_dtd", "long", "count");
+ ArrayList<Long> intDateTest = (ArrayList<Long>)calculateStat(transformLists(intDateTestStart, 7, 44, 7
+ , true, true, false, true, true), "count");
+ assertEquals(getRawResponse(), intDate,intDateTest);
+
+ //Float Long
+ ArrayList<Double> floatLong = getDoubleList("hf", "rangeFacets", "long_ld", "double", "median");
+ ArrayList<Double> floatLongTest = calculateNumberStat(transformLists(floatLongTestStart, 0, 29, 4
+ , true, true, true, true, true), "median");
+ assertEquals(getRawResponse(), floatLong,floatLongTest);
+ //Float Double
+ ArrayList<Long> floatDouble = getLongList("hf", "rangeFacets", "double_dd", "long", "count");
+ ArrayList<Long> floatDoubleTest = (ArrayList<Long>)calculateStat(transformLists(floatDoubleTestStart, 4, 47, 11
+ , true, false, false, true, false), "count");
+ assertEquals(getRawResponse(), floatDouble,floatDoubleTest);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void multiGapTest() throws Exception {
+ //Int Long
+ ArrayList<Double> intLong = getDoubleList("mi", "rangeFacets", "long_ld", "double", "sum");
+ ArrayList<Double> intLongTest = calculateNumberStat(transformLists(intLongTestStart, 5, 30, "4,2,6,3"
+ , false, true, false, false, false), "sum");
+ assertEquals(getRawResponse(), intLong,intLongTest);
+ //Int Double
+ ArrayList<Double> intDouble = getDoubleList("mi", "rangeFacets", "double_dd", "double", "mean");
+ ArrayList<Double> intDoubleTest = calculateNumberStat(transformLists(intDoubleTestStart, 3, 39, "3,1,7"
+ , false, false, true, false, true), "mean");
+ assertEquals(getRawResponse(), intDouble,intDoubleTest);
+ //Int Date
+ ArrayList<Long> intDate = getLongList("mi", "rangeFacets", "date_dtd", "long", "count");
+ ArrayList<Long> intDateTest = (ArrayList<Long>)calculateStat(transformLists(intDateTestStart, 7, 44, "2,7"
+ , false, true, false, true, true), "count");
+ assertEquals(getRawResponse(), intDate,intDateTest);
+
+ //Float Long
+ ArrayList<Double> floatLong = getDoubleList("mf", "rangeFacets", "long_ld", "double", "median");
+ ArrayList<Double> floatLongTest = calculateNumberStat(transformLists(floatLongTestStart, 0, 29, "1,4"
+ , false, true, true, true, true), "median");;
+ assertEquals(getRawResponse(), floatLong,floatLongTest);
+ //Float Double
+ ArrayList<Long> floatDouble = getLongList("mf", "rangeFacets", "double_dd", "long", "count");
+ ArrayList<Long> floatDoubleTest = (ArrayList<Long>)calculateStat(transformLists(floatDoubleTestStart, 4, 47, "2,3,11"
+ , false, false, false, true, false), "count");
+ assertEquals(getRawResponse(), floatDouble,floatDoubleTest);
+ }
+
+ private <T> ArrayList<ArrayList<T>> transformLists(ArrayList<ArrayList<T>> listsStart, int start, int end, int gap
+ , boolean hardend, boolean incLow, boolean incUp, boolean incEdge, boolean incOut) {
+ int off = (end-start)%gap;
+ if (!hardend && off>0) {
+ end+=gap-off;
+ }
+
+ ArrayList<ArrayList<T>> lists = new ArrayList<>();
+ ArrayList<T> between = new ArrayList<>();
+ if (incLow && incUp) {
+ for (int i = start; i<end && i<listsStart.size(); i+=gap) {
+ ArrayList<T> list = new ArrayList<>();
+ for (int j = i; j<=i+gap && j<=end && j<listsStart.size(); j++) {
+ list.addAll(listsStart.get(j));
+ }
+ lists.add(list);
+ }
+ for (int i = start; i<listsStart.size() && i<=end; i++) {
+ between.addAll(listsStart.get(i));
+ }
+ } else if (incLow && !incUp) {
+ for (int i = start; i<end && i<listsStart.size(); i+=gap) {
+ ArrayList<T> list = new ArrayList<>();
+ for (int j = i; j<i+gap && j<end && j<listsStart.size(); j++) {
+ list.addAll(listsStart.get(j));
+ }
+ lists.add(list);
+ }
+ for (int i = start; i<listsStart.size() && i<end; i++) {
+ between.addAll(listsStart.get(i));
+ }
+ } else if (!incLow && incUp) {
+ for (int i = start; i<end && i<listsStart.size(); i+=gap) {
+ ArrayList<T> list = new ArrayList<>();
+ for (int j = i+1; j<=i+gap && j<=end && j<listsStart.size(); j++) {
+ list.addAll(listsStart.get(j));
+ }
+ lists.add(list);
+ }
+ for (int i = start+1; i<listsStart.size() && i<=end; i++) {
+ between.addAll(listsStart.get(i));
+ }
+ } else {
+ for (int i = start; i<end && i<listsStart.size(); i+=gap) {
+ ArrayList<T> list = new ArrayList<>();
+ for (int j = i+1; j<i+gap && j<end && j<listsStart.size(); j++) {
+ list.addAll(listsStart.get(j));
+ }
+ lists.add(list);
+ }
+ for (int i = start+1; i<listsStart.size() && i<end; i++) {
+ between.addAll(listsStart.get(i));
+ }
+ }
+
+ if (incEdge && !incLow && start>=0) {
+ lists.get(0).addAll(listsStart.get(start));
+ between.addAll(listsStart.get(start));
+ }
+ if (incEdge && !incUp && end<listsStart.size()) {
+ lists.get(lists.size()-1).addAll(listsStart.get(end));
+ between.addAll(listsStart.get(end));
+ }
+ ArrayList<T> before = new ArrayList<>();
+ ArrayList<T> after = new ArrayList<>();
+ if (incOut || !(incLow||incEdge)) {
+ for (int i = 0; i<=start; i++) {
+ before.addAll(listsStart.get(i));
+ }
+ } else {
+ for (int i = 0; i<start; i++) {
+ before.addAll(listsStart.get(i));
+ }
+ }
+ if (incOut || !(incUp||incEdge)) {
+ for (int i = end; i<listsStart.size(); i++) {
+ after.addAll(listsStart.get(i));
+ }
+ }
+ else {
+ for (int i = end+1; i<listsStart.size(); i++) {
+ after.addAll(listsStart.get(i));
+ }
+ }
+ lists.add(before);
+ lists.add(after);
+ lists.add(between);
+ return lists;
+ }
+
+ private <T> ArrayList<ArrayList<T>> transformLists(ArrayList<ArrayList<T>> listsStart, int start, int end, String gapString
+ , boolean hardend, boolean incLow, boolean incUp, boolean incEdge, boolean incOut) {
+ String[] stringGaps = gapString.split(",");
+ int[] gaps = new int[stringGaps.length];
+ for (int i = 0; i<gaps.length; i++) {
+ gaps[i] = Integer.parseInt(stringGaps[i]);
+ }
+ int bigGap = 0;
+ int last = gaps[gaps.length-1];
+ for (int i = 0; i<gaps.length-1; i++) {
+ bigGap += gaps[i];
+ }
+ int off = (end-start-bigGap)%last;
+ if (!hardend && off>0) {
+ end+=last-off;
+ }
+
+ ArrayList<ArrayList<T>> lists = new ArrayList<>();
+ ArrayList<T> between = new ArrayList<>();
+ int gap = 0;
+ int gapCounter = 0;
+ if (incLow && incUp) {
+ for (int i = start; i<end && i<listsStart.size(); i+=gap) {
+ if (gapCounter<gaps.length) {
+ gap = gaps[gapCounter++];
+ }
+ ArrayList<T> list = new ArrayList<>();
+ for (int j = i; j<=i+gap && j<=end && j<listsStart.size(); j++) {
+ list.addAll(listsStart.get(j));
+ }
+ lists.add(list);
+ }
+ for (int i = start; i<listsStart.size() && i<=end; i++) {
+ between.addAll(listsStart.get(i));
+ }
+ } else if (incLow && !incUp) {
+ for (int i = start; i<end && i<listsStart.size(); i+=gap) {
+ if (gapCounter<gaps.length) {
+ gap = gaps[gapCounter++];
+ }
+ ArrayList<T> list = new ArrayList<>();
+ for (int j = i; j<i+gap && j<end && j<listsStart.size(); j++) {
+ list.addAll(listsStart.get(j));
+ }
+ lists.add(list);
+ }
+ for (int i = start; i<listsStart.size() && i<end; i++) {
+ between.addAll(listsStart.get(i));
+ }
+ } else if (!incLow && incUp) {
+ for (int i = start; i<end && i<listsStart.size(); i+=gap) {
+ if (gapCounter<gaps.length) {
+ gap = gaps[gapCounter++];
+ }
+ ArrayList<T> list = new ArrayList<>();
+ for (int j = i+1; j<=i+gap && j<=end && j<listsStart.size(); j++) {
+ list.addAll(listsStart.get(j));
+ }
+ lists.add(list);
+ }
+ for (int i = start+1; i<listsStart.size() && i<=end; i++) {
+ between.addAll(listsStart.get(i));
+ }
+ } else {
+ for (int i = start; i<end && i<listsStart.size(); i+=gap) {
+ if (gapCounter<gaps.length) {
+ gap = gaps[gapCounter++];
+ }
+ ArrayList<T> list = new ArrayList<>();
+ for (int j = i+1; j<i+gap && j<end && j<listsStart.size(); j++) {
+ list.addAll(listsStart.get(j));
+ }
+ lists.add(list);
+ }
+ for (int i = start+1; i<listsStart.size() && i<end; i++) {
+ between.addAll(listsStart.get(i));
+ }
+ }
+
+ if (incEdge && !incLow && start>=0) {
+ lists.get(0).addAll(listsStart.get(start));
+ between.addAll(listsStart.get(start));
+ }
+ if (incEdge && !incUp && end<listsStart.size()) {
+ lists.get(lists.size()-1).addAll(listsStart.get(end));
+ between.addAll(listsStart.get(end));
+ }
+ ArrayList<T> before = new ArrayList<>();
+ ArrayList<T> after = new ArrayList<>();
+ if (incOut || !(incLow||incEdge)) {
+ for (int i = 0; i<=start; i++) {
+ before.addAll(listsStart.get(i));
+ }
+ } else {
+ for (int i = 0; i<start; i++) {
+ before.addAll(listsStart.get(i));
+ }
+ }
+ if (incOut || !(incUp||incEdge)) {
+ for (int i = end; i<listsStart.size(); i++) {
+ after.addAll(listsStart.get(i));
+ }
+ }
+ else {
+ for (int i = end+1; i<listsStart.size(); i++) {
+ after.addAll(listsStart.get(i));
+ }
+ }
+ lists.add(before);
+ lists.add(after);
+ lists.add(between);
+ return lists;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingAnalyticsValueTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingAnalyticsValueTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingAnalyticsValueTest.java
new file mode 100644
index 0000000..3eb1e57
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingAnalyticsValueTest.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.value;
+
+import java.util.Arrays;
+import java.util.Iterator;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.analytics.value.FillableTestValue.TestAnalyticsValue;
+import org.junit.Test;
+
+public class CastingAnalyticsValueTest extends SolrTestCaseJ4 {
+
+ @Test
+ public void objectStreamCastingTest() {
+ TestAnalyticsValue val = new TestAnalyticsValue();
+
+ assertTrue(val instanceof AnalyticsValueStream);
+ AnalyticsValueStream casted = (AnalyticsValueStream)val;
+
+ // No values
+ val.setExists(false);
+ casted.streamObjects( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple Values
+ val.setValue("Object").setExists(true);
+ Iterator<Object> values = Arrays.<Object>asList("Object").iterator();
+ casted.streamObjects( value -> {
+ assertTrue(values.hasNext());
+ assertEquals(values.next(), value);
+ });
+ assertFalse(values.hasNext());
+ }
+
+ @Test
+ public void constantConversionTest() {
+ AnalyticsValueStream val = new TestAnalyticsValue();
+ assertSame(val, val.convertToConstant());
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingBooleanValueStreamTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingBooleanValueStreamTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingBooleanValueStreamTest.java
new file mode 100644
index 0000000..630e6fa
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingBooleanValueStreamTest.java
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.value;
+
+import java.util.Arrays;
+import java.util.Iterator;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.analytics.value.FillableTestValue.TestBooleanValueStream;
+import org.junit.Test;
+
+public class CastingBooleanValueStreamTest extends SolrTestCaseJ4 {
+
+ @Test
+ public void stringStreamCastingTest() {
+ TestBooleanValueStream val = new TestBooleanValueStream();
+
+ assertTrue(val instanceof StringValueStream);
+ StringValueStream casted = (StringValueStream)val;
+
+ // No values
+ val.setValues();
+ casted.streamStrings( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple Values
+ val.setValues(false, true, false);
+ Iterator<String> values = Arrays.asList("false", "true", "false").iterator();
+ casted.streamStrings( value -> {
+ assertTrue(values.hasNext());
+ assertEquals(values.next(), value);
+ });
+ assertFalse(values.hasNext());
+ }
+
+ @Test
+ public void objectStreamCastingTest() {
+ TestBooleanValueStream val = new TestBooleanValueStream();
+
+ assertTrue(val instanceof AnalyticsValueStream);
+ AnalyticsValueStream casted = (AnalyticsValueStream)val;
+
+ // No values
+ val.setValues();
+ casted.streamObjects( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple Values
+ val.setValues(false, true, false);
+ Iterator<Object> values = Arrays.<Object>asList(new Boolean(false), new Boolean(true), new Boolean(false)).iterator();
+ casted.streamObjects( value -> {
+ assertTrue(values.hasNext());
+ assertEquals(values.next(), value);
+ });
+ assertFalse(values.hasNext());
+ }
+
+ @Test
+ public void constantConversionTest() {
+ AnalyticsValueStream val = new TestBooleanValueStream();
+ assertSame(val, val.convertToConstant());
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingBooleanValueTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingBooleanValueTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingBooleanValueTest.java
new file mode 100644
index 0000000..1ebfe85
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingBooleanValueTest.java
@@ -0,0 +1,159 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.value;
+
+import java.util.Arrays;
+import java.util.Iterator;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.analytics.value.AnalyticsValueStream.ExpressionType;
+import org.apache.solr.analytics.value.FillableTestValue.TestBooleanValue;
+import org.apache.solr.analytics.value.constant.ConstantBooleanValue;
+import org.junit.Test;
+
+public class CastingBooleanValueTest extends SolrTestCaseJ4 {
+
+ @Test
+ public void stringCastingTest() {
+ TestBooleanValue val = new TestBooleanValue();
+
+ assertTrue(val instanceof StringValue);
+ StringValue casted = (StringValue)val;
+
+ val.setValue(false).setExists(true);
+ assertEquals("false", casted.getString());
+ assertTrue(casted.exists());
+
+ val.setValue(true).setExists(true);
+ assertEquals("true", casted.getString());
+ assertTrue(casted.exists());
+ }
+
+ @Test
+ public void objectCastingTest() {
+ TestBooleanValue val = new TestBooleanValue();
+
+ assertTrue(val instanceof AnalyticsValue);
+ AnalyticsValue casted = (AnalyticsValue)val;
+
+ val.setValue(false).setExists(true);
+ assertEquals(new Boolean(false), casted.getObject());
+ assertTrue(casted.exists());
+
+ val.setValue(true).setExists(true);
+ assertEquals(new Boolean(true), casted.getObject());
+ assertTrue(casted.exists());
+ }
+
+ @Test
+ public void booleanStreamCastingTest() {
+ TestBooleanValue val = new TestBooleanValue();
+
+ assertTrue(val instanceof BooleanValueStream);
+ BooleanValueStream casted = (BooleanValueStream)val;
+
+ // No values
+ val.setExists(false);
+ casted.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple Values
+ val.setValue(false).setExists(true);
+ Iterator<Boolean> values = Arrays.asList(false).iterator();
+ casted.streamBooleans( value -> {
+ assertTrue(values.hasNext());
+ assertEquals(values.next(), value);
+ });
+ assertFalse(values.hasNext());
+ }
+
+ @Test
+ public void stringStreamCastingTest() {
+ TestBooleanValue val = new TestBooleanValue();
+
+ assertTrue(val instanceof StringValueStream);
+ StringValueStream casted = (StringValueStream)val;
+
+ // No values
+ val.setExists(false);
+ casted.streamStrings( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple Values
+ val.setValue(false).setExists(true);
+ Iterator<String> values = Arrays.asList("false").iterator();
+ casted.streamStrings( value -> {
+ assertTrue(values.hasNext());
+ assertEquals(values.next(), value);
+ });
+ assertFalse(values.hasNext());
+ }
+
+ @Test
+ public void objectStreamCastingTest() {
+ TestBooleanValue val = new TestBooleanValue();
+
+ assertTrue(val instanceof AnalyticsValueStream);
+ AnalyticsValueStream casted = (AnalyticsValueStream)val;
+
+ // No values
+ val.setExists(false);
+ casted.streamObjects( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple Values
+ val.setValue(false).setExists(true);
+ Iterator<Object> values = Arrays.<Object>asList(new Boolean(false)).iterator();
+ casted.streamObjects( value -> {
+ assertTrue(values.hasNext());
+ assertEquals(values.next(), value);
+ });
+ assertFalse(values.hasNext());
+ }
+
+ @Test
+ public void constantConversionTest() {
+ TestBooleanValue val = new TestBooleanValue(ExpressionType.CONST);
+ val.setValue(true).setExists(true);
+ AnalyticsValueStream conv = val.convertToConstant();
+ assertTrue(conv instanceof ConstantBooleanValue);
+ assertEquals(true, ((ConstantBooleanValue)conv).getBoolean());
+
+ val = new TestBooleanValue(ExpressionType.FIELD);
+ val.setValue(true).setExists(true);
+ conv = val.convertToConstant();
+ assertSame(val, conv);
+
+ val = new TestBooleanValue(ExpressionType.UNREDUCED_MAPPING);
+ val.setValue(true).setExists(true);
+ conv = val.convertToConstant();
+ assertSame(val, conv);
+
+ val = new TestBooleanValue(ExpressionType.REDUCTION);
+ val.setValue(true).setExists(true);
+ conv = val.convertToConstant();
+ assertSame(val, conv);
+
+ val = new TestBooleanValue(ExpressionType.REDUCED_MAPPING);
+ val.setValue(true).setExists(true);
+ conv = val.convertToConstant();
+ assertSame(val, conv);
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingDateValueStreamTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingDateValueStreamTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingDateValueStreamTest.java
new file mode 100644
index 0000000..e6659ea
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingDateValueStreamTest.java
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.value;
+
+import java.time.Instant;
+import java.time.format.DateTimeParseException;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.Iterator;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.analytics.value.FillableTestValue.TestDateValueStream;
+import org.junit.Test;
+
+public class CastingDateValueStreamTest extends SolrTestCaseJ4 {
+
+ @Test
+ public void dateStreamCastingTest() throws DateTimeParseException {
+ Date date1 = Date.from(Instant.parse("1800-01-01T10:30:15Z"));
+ Date date2 = Date.from(Instant.parse("1920-04-15T18:15:45Z"));
+ Date date3 = Date.from(Instant.parse("2012-11-30T20:30:15Z"));
+ TestDateValueStream val = new TestDateValueStream();
+
+ assertTrue(val instanceof DateValueStream);
+ DateValueStream casted = (DateValueStream)val;
+
+ // No values
+ val.setValues();
+ casted.streamDates( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple Values
+ val.setValues("1800-01-01T10:30:15Z", "1920-04-15T18:15:45Z", "2012-11-30T20:30:15Z");
+ Iterator<Date> values = Arrays.asList(date1, date2, date3).iterator();
+ casted.streamDates( value -> {
+ assertTrue(values.hasNext());
+ assertEquals(values.next(), value);
+ });
+ assertFalse(values.hasNext());
+ }
+
+ @Test
+ public void stringStreamCastingTest() {
+ TestDateValueStream val = new TestDateValueStream();
+
+ assertTrue(val instanceof StringValueStream);
+ StringValueStream casted = (StringValueStream)val;
+
+ // No values
+ val.setValues();
+ casted.streamStrings( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple Values
+ val.setValues("1800-01-01T10:30:15Z", "1920-04-15T18:15:45Z", "2012-11-30T20:30:15Z");
+ Iterator<String> values = Arrays.asList("1800-01-01T10:30:15Z", "1920-04-15T18:15:45Z", "2012-11-30T20:30:15Z").iterator();
+ casted.streamStrings( value -> {
+ assertTrue(values.hasNext());
+ assertEquals(values.next(), value);
+ });
+ assertFalse(values.hasNext());
+ }
+
+ @Test
+ public void objectStreamCastingTest() throws DateTimeParseException {
+ Date date1 = Date.from(Instant.parse("1800-01-01T10:30:15Z"));
+ Date date2 = Date.from(Instant.parse("1920-04-15T18:15:45Z"));
+ Date date3 = Date.from(Instant.parse("2012-11-30T20:30:15Z"));
+ TestDateValueStream val = new TestDateValueStream();
+
+ assertTrue(val instanceof AnalyticsValueStream);
+ AnalyticsValueStream casted = (AnalyticsValueStream)val;
+
+ // No values
+ val.setValues();
+ casted.streamObjects( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple Values
+ val.setValues("1800-01-01T10:30:15Z", "1920-04-15T18:15:45Z", "2012-11-30T20:30:15Z");
+ Iterator<Object> values = Arrays.<Object>asList(date1, date2, date3).iterator();
+ casted.streamObjects( value -> {
+ assertTrue(values.hasNext());
+ assertEquals(values.next(), value);
+ });
+ assertFalse(values.hasNext());
+ }
+
+ @Test
+ public void constantConversionTest() {
+ AnalyticsValueStream val = new TestDateValueStream();
+ assertSame(val, val.convertToConstant());
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingDateValueTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingDateValueTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingDateValueTest.java
new file mode 100644
index 0000000..e0fd951
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingDateValueTest.java
@@ -0,0 +1,172 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.value;
+
+import java.time.Instant;
+import java.time.format.DateTimeParseException;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.Iterator;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.analytics.value.AnalyticsValueStream.ExpressionType;
+import org.apache.solr.analytics.value.FillableTestValue.TestDateValue;
+import org.apache.solr.analytics.value.constant.ConstantDateValue;
+import org.junit.Test;
+
+public class CastingDateValueTest extends SolrTestCaseJ4 {
+
+ @Test
+ public void dateCastingTest() throws DateTimeParseException {
+ Date date = Date.from(Instant.parse("1800-01-01T10:30:15Z"));
+ TestDateValue val = new TestDateValue();
+
+ assertTrue(val instanceof DateValue);
+ DateValue casted = (DateValue)val;
+
+ val.setValue("1800-01-01T10:30:15Z").setExists(true);
+ assertEquals(date, casted.getDate());
+ assertTrue(casted.exists());
+ }
+
+ @Test
+ public void stringCastingTest() {
+ TestDateValue val = new TestDateValue();
+
+ assertTrue(val instanceof StringValue);
+ StringValue casted = (StringValue)val;
+
+ val.setValue("1800-01-01T10:30:15Z").setExists(true);
+ assertEquals("1800-01-01T10:30:15Z", casted.getString());
+ assertTrue(casted.exists());
+ }
+
+ @Test
+ public void objectCastingTest() throws DateTimeParseException {
+ Date date = Date.from(Instant.parse("1800-01-01T10:30:15Z"));
+ TestDateValue val = new TestDateValue();
+
+ assertTrue(val instanceof AnalyticsValue);
+ AnalyticsValue casted = (AnalyticsValue)val;
+
+ val.setValue("1800-01-01T10:30:15Z").setExists(true);
+ assertEquals(date, casted.getObject());
+ assertTrue(casted.exists());
+ }
+
+ @Test
+ public void dateStreamCastingTest() throws DateTimeParseException {
+ Date date = Date.from(Instant.parse("1800-01-01T10:30:15Z"));
+ TestDateValue val = new TestDateValue();
+
+ assertTrue(val instanceof DateValueStream);
+ DateValueStream casted = (DateValueStream)val;
+
+ // No values
+ val.setExists(false);
+ casted.streamDates( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple Values
+ val.setValue("1800-01-01T10:30:15Z").setExists(true);
+ Iterator<Date> values = Arrays.asList(date).iterator();
+ casted.streamDates( value -> {
+ assertTrue(values.hasNext());
+ assertEquals(values.next(), value);
+ });
+ assertFalse(values.hasNext());
+ }
+
+ @Test
+ public void stringStreamCastingTest() {
+ TestDateValue val = new TestDateValue();
+
+ assertTrue(val instanceof StringValueStream);
+ StringValueStream casted = (StringValueStream)val;
+
+ // No values
+ val.setExists(false);
+ casted.streamStrings( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple Values
+ val.setValue("1800-01-01T10:30:15Z").setExists(true);
+ Iterator<String> values = Arrays.asList("1800-01-01T10:30:15Z").iterator();
+ casted.streamStrings( value -> {
+ assertTrue(values.hasNext());
+ assertEquals(values.next(), value);
+ });
+ assertFalse(values.hasNext());
+ }
+
+ @Test
+ public void objectStreamCastingTest() throws DateTimeParseException {
+ Date date = Date.from(Instant.parse("1800-01-01T10:30:15Z"));
+ TestDateValue val = new TestDateValue();
+
+ assertTrue(val instanceof AnalyticsValueStream);
+ AnalyticsValueStream casted = (AnalyticsValueStream)val;
+
+ // No values
+ val.setExists(false);
+ casted.streamObjects( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple Values
+ val.setValue("1800-01-01T10:30:15Z").setExists(true);
+ Iterator<Object> values = Arrays.<Object>asList(date).iterator();
+ casted.streamObjects( value -> {
+ assertTrue(values.hasNext());
+ assertEquals(values.next(), value);
+ });
+ assertFalse(values.hasNext());
+ }
+
+ @Test
+ public void constantConversionTest() throws DateTimeParseException {
+ Date date = Date.from(Instant.parse("1800-01-01T10:30:15Z"));
+
+ TestDateValue val = new TestDateValue(ExpressionType.CONST);
+ val.setValue("1800-01-01T10:30:15Z").setExists(true);
+ AnalyticsValueStream conv = val.convertToConstant();
+ assertTrue(conv instanceof ConstantDateValue);
+ assertEquals(date, ((ConstantDateValue)conv).getDate());
+
+ val = new TestDateValue(ExpressionType.FIELD);
+ val.setValue("1800-01-01T10:30:15Z").setExists(true);
+ conv = val.convertToConstant();
+ assertSame(val, conv);
+
+ val = new TestDateValue(ExpressionType.UNREDUCED_MAPPING);
+ val.setValue("1800-01-01T10:30:15Z").setExists(true);
+ conv = val.convertToConstant();
+ assertSame(val, conv);
+
+ val = new TestDateValue(ExpressionType.REDUCTION);
+ val.setValue("1800-01-01T10:30:15Z").setExists(true);
+ conv = val.convertToConstant();
+ assertSame(val, conv);
+
+ val = new TestDateValue(ExpressionType.REDUCED_MAPPING);
+ val.setValue("1800-01-01T10:30:15Z").setExists(true);
+ conv = val.convertToConstant();
+ assertSame(val, conv);
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingDoubleValueStreamTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingDoubleValueStreamTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingDoubleValueStreamTest.java
new file mode 100644
index 0000000..7f2ddc6
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingDoubleValueStreamTest.java
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.value;
+
+import java.util.Arrays;
+import java.util.Iterator;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValueStream;
+import org.junit.Test;
+
+public class CastingDoubleValueStreamTest extends SolrTestCaseJ4 {
+
+ @Test
+ public void stringStreamCastingTest() {
+ TestDoubleValueStream val = new TestDoubleValueStream();
+
+ assertTrue(val instanceof StringValueStream);
+ StringValueStream casted = (StringValueStream)val;
+
+ // No values
+ val.setValues();
+ casted.streamStrings( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple Values
+ val.setValues(20.0, -3.32, 42.5);
+ Iterator<String> values = Arrays.asList("20.0", "-3.32", "42.5").iterator();
+ casted.streamStrings( value -> {
+ assertTrue(values.hasNext());
+ assertEquals(values.next(), value);
+ });
+ assertFalse(values.hasNext());
+ }
+
+ @Test
+ public void objectStreamCastingTest() {
+ TestDoubleValueStream val = new TestDoubleValueStream();
+
+ assertTrue(val instanceof AnalyticsValueStream);
+ AnalyticsValueStream casted = (AnalyticsValueStream)val;
+
+ // No values
+ val.setValues();
+ casted.streamObjects( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple Values
+ val.setValues(20.0, -3.32, 42.5);
+ Iterator<Object> values = Arrays.<Object>asList(new Double(20.0), new Double(-3.32), new Double(42.5)).iterator();
+ casted.streamObjects( value -> {
+ assertTrue(values.hasNext());
+ assertEquals(values.next(), value);
+ });
+ assertFalse(values.hasNext());
+ }
+
+ @Test
+ public void constantConversionTest() {
+ AnalyticsValueStream val = new TestDoubleValueStream();
+ assertSame(val, val.convertToConstant());
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingDoubleValueTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingDoubleValueTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingDoubleValueTest.java
new file mode 100644
index 0000000..a4558b0
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingDoubleValueTest.java
@@ -0,0 +1,159 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.value;
+
+import java.util.Arrays;
+import java.util.Iterator;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.analytics.value.AnalyticsValueStream.ExpressionType;
+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValue;
+import org.apache.solr.analytics.value.constant.ConstantDoubleValue;
+import org.junit.Test;
+
+public class CastingDoubleValueTest extends SolrTestCaseJ4 {
+
+ @Test
+ public void stringCastingTest() {
+ TestDoubleValue val = new TestDoubleValue();
+
+ assertTrue(val instanceof StringValue);
+ StringValue casted = (StringValue)val;
+
+ val.setValue(20.0).setExists(true);
+ assertEquals("20.0", casted.getString());
+ assertTrue(casted.exists());
+
+ val.setValue(1234.0).setExists(true);
+ assertEquals("1234.0", casted.getString());
+ assertTrue(casted.exists());
+ }
+
+ @Test
+ public void objectCastingTest() {
+ TestDoubleValue val = new TestDoubleValue();
+
+ assertTrue(val instanceof AnalyticsValue);
+ AnalyticsValue casted = (AnalyticsValue)val;
+
+ val.setValue(20.0).setExists(true);
+ assertEquals(new Double(20.0), casted.getObject());
+ assertTrue(casted.exists());
+
+ val.setValue(1234.0).setExists(true);
+ assertEquals(new Double(1234.0), casted.getObject());
+ assertTrue(casted.exists());
+ }
+
+ @Test
+ public void doubleStreamCastingTest() {
+ TestDoubleValue val = new TestDoubleValue();
+
+ assertTrue(val instanceof DoubleValueStream);
+ DoubleValueStream casted = (DoubleValueStream)val;
+
+ // No values
+ val.setExists(false);
+ casted.streamDoubles( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple Values
+ val.setValue(20.0).setExists(true);
+ Iterator<Double> values = Arrays.asList(20.0).iterator();
+ casted.streamDoubles( value -> {
+ assertTrue(values.hasNext());
+ assertEquals(values.next(), value, .00001);
+ });
+ assertFalse(values.hasNext());
+ }
+
+ @Test
+ public void stringStreamCastingTest() {
+ TestDoubleValue val = new TestDoubleValue();
+
+ assertTrue(val instanceof StringValueStream);
+ StringValueStream casted = (StringValueStream)val;
+
+ // No values
+ val.setExists(false);
+ casted.streamStrings( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple Values
+ val.setValue(20.0).setExists(true);
+ Iterator<String> values = Arrays.asList("20.0").iterator();
+ casted.streamStrings( value -> {
+ assertTrue(values.hasNext());
+ assertEquals(values.next(), value);
+ });
+ assertFalse(values.hasNext());
+ }
+
+ @Test
+ public void objectStreamCastingTest() {
+ TestDoubleValue val = new TestDoubleValue();
+
+ assertTrue(val instanceof AnalyticsValueStream);
+ AnalyticsValueStream casted = (AnalyticsValueStream)val;
+
+ // No values
+ val.setExists(false);
+ casted.streamObjects( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple Values
+ val.setValue(20.0).setExists(true);
+ Iterator<Object> values = Arrays.<Object>asList(new Double(20.0)).iterator();
+ casted.streamObjects( value -> {
+ assertTrue(values.hasNext());
+ assertEquals(values.next(), value);
+ });
+ assertFalse(values.hasNext());
+ }
+
+ @Test
+ public void constantConversionTest() {
+ TestDoubleValue val = new TestDoubleValue(ExpressionType.CONST);
+ val.setValue(12354.234).setExists(true);
+ AnalyticsValueStream conv = val.convertToConstant();
+ assertTrue(conv instanceof ConstantDoubleValue);
+ assertEquals(12354.234, ((ConstantDoubleValue)conv).getDouble(), .0000001);
+
+ val = new TestDoubleValue(ExpressionType.FIELD);
+ val.setValue(12354.234).setExists(true);
+ conv = val.convertToConstant();
+ assertSame(val, conv);
+
+ val = new TestDoubleValue(ExpressionType.UNREDUCED_MAPPING);
+ val.setValue(12354.234).setExists(true);
+ conv = val.convertToConstant();
+ assertSame(val, conv);
+
+ val = new TestDoubleValue(ExpressionType.REDUCTION);
+ val.setValue(12354.234).setExists(true);
+ conv = val.convertToConstant();
+ assertSame(val, conv);
+
+ val = new TestDoubleValue(ExpressionType.REDUCED_MAPPING);
+ val.setValue(12354.234).setExists(true);
+ conv = val.convertToConstant();
+ assertSame(val, conv);
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingFloatValueStreamTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingFloatValueStreamTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingFloatValueStreamTest.java
new file mode 100644
index 0000000..2c7753e
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingFloatValueStreamTest.java
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.value;
+
+import java.util.Arrays;
+import java.util.Iterator;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValueStream;
+import org.junit.Test;
+
+public class CastingFloatValueStreamTest extends SolrTestCaseJ4 {
+
+ @Test
+ public void doubleStreamCastingTest() {
+ TestFloatValueStream val = new TestFloatValueStream();
+
+ assertTrue(val instanceof DoubleValueStream);
+ DoubleValueStream casted = (DoubleValueStream)val;
+
+ // No values
+ val.setValues();
+ casted.streamDoubles( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple Values
+ val.setValues(20F, -3.32F, 42.5F);
+ Iterator<Double> values = Arrays.asList(20.0, -3.32, 42.5).iterator();
+ casted.streamDoubles( value -> {
+ assertTrue(values.hasNext());
+ assertEquals(values.next(), value, .00001);
+ });
+ assertFalse(values.hasNext());
+ }
+
+ @Test
+ public void stringStreamCastingTest() {
+ TestFloatValueStream val = new TestFloatValueStream();
+
+ assertTrue(val instanceof StringValueStream);
+ StringValueStream casted = (StringValueStream)val;
+
+ // No values
+ val.setValues();
+ casted.streamStrings( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple Values
+ val.setValues(20F, -3.32F, 42.5F);
+ Iterator<String> values = Arrays.asList("20.0", "-3.32", "42.5").iterator();
+ casted.streamStrings( value -> {
+ assertTrue(values.hasNext());
+ assertEquals(values.next(), value);
+ });
+ assertFalse(values.hasNext());
+ }
+
+ @Test
+ public void objectStreamCastingTest() {
+ TestFloatValueStream val = new TestFloatValueStream();
+
+ assertTrue(val instanceof AnalyticsValueStream);
+ AnalyticsValueStream casted = (AnalyticsValueStream)val;
+
+ // No values
+ val.setValues();
+ casted.streamObjects( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple Values
+ val.setValues(20F, -3.32F, 42.5F);
+ Iterator<Object> values = Arrays.<Object>asList(new Float(20F), new Float(-3.32F), new Float(42.5F)).iterator();
+ casted.streamObjects( value -> {
+ assertTrue(values.hasNext());
+ assertEquals(values.next(), value);
+ });
+ assertFalse(values.hasNext());
+ }
+
+ @Test
+ public void constantConversionTest() {
+ AnalyticsValueStream val = new TestFloatValueStream();
+ assertSame(val, val.convertToConstant());
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingFloatValueTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingFloatValueTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingFloatValueTest.java
new file mode 100644
index 0000000..0f044b2
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingFloatValueTest.java
@@ -0,0 +1,198 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.value;
+
+import java.util.Arrays;
+import java.util.Iterator;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.analytics.value.AnalyticsValueStream.ExpressionType;
+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValue;
+import org.apache.solr.analytics.value.constant.ConstantFloatValue;
+import org.junit.Test;
+
+public class CastingFloatValueTest extends SolrTestCaseJ4 {
+
+ @Test
+ public void doubleCastingTest() {
+ TestFloatValue val = new TestFloatValue();
+
+ assertTrue(val instanceof DoubleValue);
+ DoubleValue casted = (DoubleValue)val;
+
+ val.setValue(20F).setExists(true);
+ assertEquals(20.0, casted.getDouble(), .00001);
+ assertTrue(casted.exists());
+
+ val.setValue(1234F).setExists(true);
+ assertEquals(1234.0, casted.getDouble(), .00001);
+ assertTrue(casted.exists());
+ }
+
+ @Test
+ public void stringCastingTest() {
+ TestFloatValue val = new TestFloatValue();
+
+ assertTrue(val instanceof StringValue);
+ StringValue casted = (StringValue)val;
+
+ val.setValue(20F).setExists(true);
+ assertEquals("20.0", casted.getString());
+ assertTrue(casted.exists());
+
+ val.setValue(1234F).setExists(true);
+ assertEquals("1234.0", casted.getString());
+ assertTrue(casted.exists());
+ }
+
+ @Test
+ public void objectCastingTest() {
+ TestFloatValue val = new TestFloatValue();
+
+ assertTrue(val instanceof AnalyticsValue);
+ AnalyticsValue casted = (AnalyticsValue)val;
+
+ val.setValue(20F).setExists(true);
+ assertEquals(new Float(20F), casted.getObject());
+ assertTrue(casted.exists());
+
+ val.setValue(1234F).setExists(true);
+ assertEquals(new Float(1234F), casted.getObject());
+ assertTrue(casted.exists());
+ }
+
+ @Test
+ public void floatStreamCastingTest() {
+ TestFloatValue val = new TestFloatValue();
+
+ assertTrue(val instanceof FloatValueStream);
+ FloatValueStream casted = (FloatValueStream)val;
+
+ // No values
+ val.setExists(false);
+ casted.streamFloats( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple Values
+ val.setValue(20F).setExists(true);
+ Iterator<Float> values = Arrays.asList(20F).iterator();
+ casted.streamFloats( value -> {
+ assertTrue(values.hasNext());
+ assertEquals(values.next(), value, .00001);
+ });
+ assertFalse(values.hasNext());
+ }
+
+ @Test
+ public void doubleStreamCastingTest() {
+ TestFloatValue val = new TestFloatValue();
+
+ assertTrue(val instanceof DoubleValueStream);
+ DoubleValueStream casted = (DoubleValueStream)val;
+
+ // No values
+ val.setExists(false);
+ casted.streamDoubles( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple Values
+ val.setValue(20F).setExists(true);
+ Iterator<Double> values = Arrays.asList(20.0).iterator();
+ casted.streamDoubles( value -> {
+ assertTrue(values.hasNext());
+ assertEquals(values.next(), value, .00001);
+ });
+ assertFalse(values.hasNext());
+ }
+
+ @Test
+ public void stringStreamCastingTest() {
+ TestFloatValue val = new TestFloatValue();
+
+ assertTrue(val instanceof StringValueStream);
+ StringValueStream casted = (StringValueStream)val;
+
+ // No values
+ val.setExists(false);
+ casted.streamStrings( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple Values
+ val.setValue(20F).setExists(true);
+ Iterator<String> values = Arrays.asList("20.0").iterator();
+ casted.streamStrings( value -> {
+ assertTrue(values.hasNext());
+ assertEquals(values.next(), value);
+ });
+ assertFalse(values.hasNext());
+ }
+
+ @Test
+ public void objectStreamCastingTest() {
+ TestFloatValue val = new TestFloatValue();
+
+ assertTrue(val instanceof AnalyticsValueStream);
+ AnalyticsValueStream casted = (AnalyticsValueStream)val;
+
+ // No values
+ val.setExists(false);
+ casted.streamObjects( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple Values
+ val.setValue(20F).setExists(true);
+ Iterator<Object> values = Arrays.<Object>asList(new Float(20F)).iterator();
+ casted.streamObjects( value -> {
+ assertTrue(values.hasNext());
+ assertEquals(values.next(), value);
+ });
+ assertFalse(values.hasNext());
+ }
+
+ @Test
+ public void constantConversionTest() {
+ TestFloatValue val = new TestFloatValue(ExpressionType.CONST);
+ val.setValue(12354.234F).setExists(true);
+ AnalyticsValueStream conv = val.convertToConstant();
+ assertTrue(conv instanceof ConstantFloatValue);
+ assertEquals(12354.234F, ((ConstantFloatValue)conv).getFloat(), .0000001);
+
+ val = new TestFloatValue(ExpressionType.FIELD);
+ val.setValue(12354.234F).setExists(true);
+ conv = val.convertToConstant();
+ assertSame(val, conv);
+
+ val = new TestFloatValue(ExpressionType.UNREDUCED_MAPPING);
+ val.setValue(12354.234F).setExists(true);
+ conv = val.convertToConstant();
+ assertSame(val, conv);
+
+ val = new TestFloatValue(ExpressionType.REDUCTION);
+ val.setValue(12354.234F).setExists(true);
+ conv = val.convertToConstant();
+ assertSame(val, conv);
+
+ val = new TestFloatValue(ExpressionType.REDUCED_MAPPING);
+ val.setValue(12354.234F).setExists(true);
+ conv = val.convertToConstant();
+ assertSame(val, conv);
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingIntValueStreamTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingIntValueStreamTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingIntValueStreamTest.java
new file mode 100644
index 0000000..f099b6e
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingIntValueStreamTest.java
@@ -0,0 +1,148 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.value;
+
+import java.util.Arrays;
+import java.util.Iterator;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.analytics.value.FillableTestValue.TestIntValueStream;
+import org.junit.Test;
+
+public class CastingIntValueStreamTest extends SolrTestCaseJ4 {
+
+ @Test
+ public void longStreamCastingTest() {
+ TestIntValueStream val = new TestIntValueStream();
+
+ assertTrue(val instanceof LongValueStream);
+ LongValueStream casted = (LongValueStream)val;
+
+ // No values
+ val.setValues();
+ casted.streamLongs( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple Values
+ val.setValues(20, -3, 42);
+ Iterator<Long> values = Arrays.asList(20L, -3L, 42L).iterator();
+ casted.streamLongs( value -> {
+ assertTrue(values.hasNext());
+ assertEquals(values.next().longValue(), value);
+ });
+ assertFalse(values.hasNext());
+ }
+
+ @Test
+ public void floatStreamCastingTest() {
+ TestIntValueStream val = new TestIntValueStream();
+
+ assertTrue(val instanceof FloatValueStream);
+ FloatValueStream casted = (FloatValueStream)val;
+
+ // No values
+ val.setValues();
+ casted.streamFloats( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple Values
+ val.setValues(20, -3, 42);
+ Iterator<Float> values = Arrays.asList(20F, -3F, 42F).iterator();
+ casted.streamFloats( value -> {
+ assertTrue(values.hasNext());
+ assertEquals(values.next(), value, .00001);
+ });
+ assertFalse(values.hasNext());
+ }
+
+ @Test
+ public void doubleStreamCastingTest() {
+ TestIntValueStream val = new TestIntValueStream();
+
+ assertTrue(val instanceof DoubleValueStream);
+ DoubleValueStream casted = (DoubleValueStream)val;
+
+ // No values
+ val.setValues();
+ casted.streamDoubles( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple Values
+ val.setValues(20, -3, 42);
+ Iterator<Double> values = Arrays.asList(20.0, -3.0, 42.0).iterator();
+ casted.streamDoubles( value -> {
+ assertTrue(values.hasNext());
+ assertEquals(values.next(), value, .00001);
+ });
+ assertFalse(values.hasNext());
+ }
+
+ @Test
+ public void stringStreamCastingTest() {
+ TestIntValueStream val = new TestIntValueStream();
+
+ assertTrue(val instanceof StringValueStream);
+ StringValueStream casted = (StringValueStream)val;
+
+ // No values
+ val.setValues();
+ casted.streamStrings( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple Values
+ val.setValues(20, -3, 42);
+ Iterator<String> values = Arrays.asList("20", "-3", "42").iterator();
+ casted.streamStrings( value -> {
+ assertTrue(values.hasNext());
+ assertEquals(values.next(), value);
+ });
+ assertFalse(values.hasNext());
+ }
+
+ @Test
+ public void objectStreamCastingTest() {
+ TestIntValueStream val = new TestIntValueStream();
+
+ assertTrue(val instanceof AnalyticsValueStream);
+ AnalyticsValueStream casted = (AnalyticsValueStream)val;
+
+ // No values
+ val.setValues();
+ casted.streamObjects( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple Values
+ val.setValues(20, -3, 42);
+ Iterator<Object> values = Arrays.<Object>asList(new Integer(20), new Integer(-3), new Integer(42)).iterator();
+ casted.streamObjects( value -> {
+ assertTrue(values.hasNext());
+ assertEquals(values.next(), value);
+ });
+ assertFalse(values.hasNext());
+ }
+
+ @Test
+ public void constantConversionTest() {
+ AnalyticsValueStream val = new TestIntValueStream();
+ assertSame(val, val.convertToConstant());
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingIntValueTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingIntValueTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingIntValueTest.java
new file mode 100644
index 0000000..65a3a7e
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingIntValueTest.java
@@ -0,0 +1,276 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.value;
+
+import java.util.Arrays;
+import java.util.Iterator;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.analytics.value.AnalyticsValueStream.ExpressionType;
+import org.apache.solr.analytics.value.FillableTestValue.TestIntValue;
+import org.apache.solr.analytics.value.constant.ConstantIntValue;
+import org.junit.Test;
+
+public class CastingIntValueTest extends SolrTestCaseJ4 {
+
+ @Test
+ public void longCastingTest() {
+ TestIntValue val = new TestIntValue();
+
+ assertTrue(val instanceof LongValue);
+ LongValue casted = (LongValue)val;
+
+ val.setValue(20).setExists(true);
+ assertEquals(20L, casted.getLong());
+ assertTrue(casted.exists());
+
+ val.setValue(1234).setExists(true);
+ assertEquals(1234L, casted.getLong());
+ assertTrue(casted.exists());
+ }
+
+ @Test
+ public void floatCastingTest() {
+ TestIntValue val = new TestIntValue();
+
+ assertTrue(val instanceof FloatValue);
+ FloatValue casted = (FloatValue)val;
+
+ val.setValue(20).setExists(true);
+ assertEquals(20F, casted.getFloat(), .00001);
+ assertTrue(casted.exists());
+
+ val.setValue(1234).setExists(true);
+ assertEquals(1234F, casted.getFloat(), .00001);
+ assertTrue(casted.exists());
+ }
+
+ @Test
+ public void doubleCastingTest() {
+ TestIntValue val = new TestIntValue();
+
+ assertTrue(val instanceof DoubleValue);
+ DoubleValue casted = (DoubleValue)val;
+
+ val.setValue(20).setExists(true);
+ assertEquals(20.0, casted.getDouble(), .00001);
+ assertTrue(casted.exists());
+
+ val.setValue(1234).setExists(true);
+ assertEquals(1234.0, casted.getDouble(), .00001);
+ assertTrue(casted.exists());
+ }
+
+ @Test
+ public void stringCastingTest() {
+ TestIntValue val = new TestIntValue();
+
+ assertTrue(val instanceof StringValue);
+ StringValue casted = (StringValue)val;
+
+ val.setValue(20).setExists(true);
+ assertEquals("20", casted.getString());
+ assertTrue(casted.exists());
+
+ val.setValue(1234).setExists(true);
+ assertEquals("1234", casted.getString());
+ assertTrue(casted.exists());
+ }
+
+ @Test
+ public void objectCastingTest() {
+ TestIntValue val = new TestIntValue();
+
+ assertTrue(val instanceof AnalyticsValue);
+ AnalyticsValue casted = (AnalyticsValue)val;
+
+ val.setValue(20).setExists(true);
+ assertEquals(new Integer(20), casted.getObject());
+ assertTrue(casted.exists());
+
+ val.setValue(1234).setExists(true);
+ assertEquals(new Integer(1234), casted.getObject());
+ assertTrue(casted.exists());
+ }
+
+ @Test
+ public void intStreamCastingTest() {
+ TestIntValue val = new TestIntValue();
+
+ assertTrue(val instanceof IntValueStream);
+ IntValueStream casted = (IntValueStream)val;
+
+ // No values
+ val.setExists(false);
+ casted.streamInts( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple Values
+ val.setValue(20).setExists(true);
+ Iterator<Integer> values = Arrays.asList(20).iterator();
+ casted.streamInts( value -> {
+ assertTrue(values.hasNext());
+ assertEquals(values.next().intValue(), value);
+ });
+ assertFalse(values.hasNext());
+ }
+
+ @Test
+ public void longStreamCastingTest() {
+ TestIntValue val = new TestIntValue();
+
+ assertTrue(val instanceof LongValueStream);
+ LongValueStream casted = (LongValueStream)val;
+
+ // No values
+ val.setExists(false);
+ casted.streamLongs( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple Values
+ val.setValue(20).setExists(true);
+ Iterator<Long> values = Arrays.asList(20L).iterator();
+ casted.streamLongs( value -> {
+ assertTrue(values.hasNext());
+ assertEquals(values.next().longValue(), value);
+ });
+ assertFalse(values.hasNext());
+ }
+
+ @Test
+ public void floatStreamCastingTest() {
+ TestIntValue val = new TestIntValue();
+
+ assertTrue(val instanceof FloatValueStream);
+ FloatValueStream casted = (FloatValueStream)val;
+
+ // No values
+ val.setExists(false);
+ casted.streamFloats( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple Values
+ val.setValue(20).setExists(true);
+ Iterator<Float> values = Arrays.asList(20F).iterator();
+ casted.streamFloats( value -> {
+ assertTrue(values.hasNext());
+ assertEquals(values.next(), value, .00001);
+ });
+ assertFalse(values.hasNext());
+ }
+
+ @Test
+ public void doubleStreamCastingTest() {
+ TestIntValue val = new TestIntValue();
+
+ assertTrue(val instanceof DoubleValueStream);
+ DoubleValueStream casted = (DoubleValueStream)val;
+
+ // No values
+ val.setExists(false);
+ casted.streamDoubles( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple Values
+ val.setValue(20).setExists(true);
+ Iterator<Double> values = Arrays.asList(20.0).iterator();
+ casted.streamDoubles( value -> {
+ assertTrue(values.hasNext());
+ assertEquals(values.next(), value, .00001);
+ });
+ assertFalse(values.hasNext());
+ }
+
+ @Test
+ public void stringStreamCastingTest() {
+ TestIntValue val = new TestIntValue();
+
+ assertTrue(val instanceof StringValueStream);
+ StringValueStream casted = (StringValueStream)val;
+
+ // No values
+ val.setExists(false);
+ casted.streamStrings( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple Values
+ val.setValue(20).setExists(true);
+ Iterator<String> values = Arrays.asList("20").iterator();
+ casted.streamStrings( value -> {
+ assertTrue(values.hasNext());
+ assertEquals(values.next(), value);
+ });
+ assertFalse(values.hasNext());
+ }
+
+ @Test
+ public void objectStreamCastingTest() {
+ TestIntValue val = new TestIntValue();
+
+ assertTrue(val instanceof AnalyticsValueStream);
+ AnalyticsValueStream casted = (AnalyticsValueStream)val;
+
+ // No values
+ val.setExists(false);
+ casted.streamObjects( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple Values
+ val.setValue(20).setExists(true);
+ Iterator<Object> values = Arrays.<Object>asList(new Integer(20)).iterator();
+ casted.streamObjects( value -> {
+ assertTrue(values.hasNext());
+ assertEquals(values.next(), value);
+ });
+ assertFalse(values.hasNext());
+ }
+
+ @Test
+ public void constantConversionTest() {
+ TestIntValue val = new TestIntValue(ExpressionType.CONST);
+ val.setValue(1234).setExists(true);
+ AnalyticsValueStream conv = val.convertToConstant();
+ assertTrue(conv instanceof ConstantIntValue);
+ assertEquals(1234, ((ConstantIntValue)conv).getInt());
+
+ val = new TestIntValue(ExpressionType.FIELD);
+ val.setValue(1234).setExists(true);
+ conv = val.convertToConstant();
+ assertSame(val, conv);
+
+ val = new TestIntValue(ExpressionType.UNREDUCED_MAPPING);
+ val.setValue(1234).setExists(true);
+ conv = val.convertToConstant();
+ assertSame(val, conv);
+
+ val = new TestIntValue(ExpressionType.REDUCTION);
+ val.setValue(1234).setExists(true);
+ conv = val.convertToConstant();
+ assertSame(val, conv);
+
+ val = new TestIntValue(ExpressionType.REDUCED_MAPPING);
+ val.setValue(1234).setExists(true);
+ conv = val.convertToConstant();
+ assertSame(val, conv);
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingLongValueStreamTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingLongValueStreamTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingLongValueStreamTest.java
new file mode 100644
index 0000000..163cbc7
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingLongValueStreamTest.java
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.value;
+
+import java.util.Arrays;
+import java.util.Iterator;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.analytics.value.FillableTestValue.TestLongValueStream;
+import org.junit.Test;
+
+public class CastingLongValueStreamTest extends SolrTestCaseJ4 {
+
+ @Test
+ public void doubleStreamCastingTest() {
+ TestLongValueStream val = new TestLongValueStream();
+
+ assertTrue(val instanceof DoubleValueStream);
+ DoubleValueStream casted = (DoubleValueStream)val;
+
+ // No values
+ val.setValues();
+ casted.streamDoubles( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple Values
+ val.setValues(20L, -3L, 42L);
+ Iterator<Double> values = Arrays.asList(20.0, -3.0, 42.0).iterator();
+ casted.streamDoubles( value -> {
+ assertTrue(values.hasNext());
+ assertEquals(values.next(), value, .00001);
+ });
+ assertFalse(values.hasNext());
+ }
+
+ @Test
+ public void stringStreamCastingTest() {
+ TestLongValueStream val = new TestLongValueStream();
+
+ assertTrue(val instanceof StringValueStream);
+ StringValueStream casted = (StringValueStream)val;
+
+ // No values
+ val.setValues();
+ casted.streamStrings( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple Values
+ val.setValues(20L, -3L, 42L);
+ Iterator<String> values = Arrays.asList("20", "-3", "42").iterator();
+ casted.streamStrings( value -> {
+ assertTrue(values.hasNext());
+ assertEquals(values.next(), value);
+ });
+ assertFalse(values.hasNext());
+ }
+
+ @Test
+ public void objectStreamCastingTest() {
+ TestLongValueStream val = new TestLongValueStream();
+
+ assertTrue(val instanceof AnalyticsValueStream);
+ AnalyticsValueStream casted = (AnalyticsValueStream)val;
+
+ // No values
+ val.setValues();
+ casted.streamObjects( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple Values
+ val.setValues(20L, -3L, 42L);
+ Iterator<Object> values = Arrays.<Object>asList(new Long(20L), new Long(-3L), new Long(42L)).iterator();
+ casted.streamObjects( value -> {
+ assertTrue(values.hasNext());
+ assertEquals(values.next(), value);
+ });
+ assertFalse(values.hasNext());
+ }
+
+ @Test
+ public void constantConversionTest() {
+ AnalyticsValueStream val = new TestLongValueStream();
+ assertSame(val, val.convertToConstant());
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingLongValueTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingLongValueTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingLongValueTest.java
new file mode 100644
index 0000000..b3df7ed
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingLongValueTest.java
@@ -0,0 +1,198 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.value;
+
+import java.util.Arrays;
+import java.util.Iterator;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.analytics.value.AnalyticsValueStream.ExpressionType;
+import org.apache.solr.analytics.value.FillableTestValue.TestLongValue;
+import org.apache.solr.analytics.value.constant.ConstantLongValue;
+import org.junit.Test;
+
+public class CastingLongValueTest extends SolrTestCaseJ4 {
+
+ @Test
+ public void doubleCastingTest() {
+ TestLongValue val = new TestLongValue();
+
+ assertTrue(val instanceof DoubleValue);
+ DoubleValue casted = (DoubleValue)val;
+
+ val.setValue(20L).setExists(true);
+ assertEquals(20.0, casted.getDouble(), .00001);
+ assertTrue(casted.exists());
+
+ val.setValue(1234L).setExists(true);
+ assertEquals(1234.0, casted.getDouble(), .00001);
+ assertTrue(casted.exists());
+ }
+
+ @Test
+ public void stringCastingTest() {
+ TestLongValue val = new TestLongValue();
+
+ assertTrue(val instanceof StringValue);
+ StringValue casted = (StringValue)val;
+
+ val.setValue(20L).setExists(true);
+ assertEquals("20", casted.getString());
+ assertTrue(casted.exists());
+
+ val.setValue(1234L).setExists(true);
+ assertEquals("1234", casted.getString());
+ assertTrue(casted.exists());
+ }
+
+ @Test
+ public void objectCastingTest() {
+ TestLongValue val = new TestLongValue();
+
+ assertTrue(val instanceof AnalyticsValue);
+ AnalyticsValue casted = (AnalyticsValue)val;
+
+ val.setValue(20L).setExists(true);
+ assertEquals(new Long(20), casted.getObject());
+ assertTrue(casted.exists());
+
+ val.setValue(1234L).setExists(true);
+ assertEquals(new Long(1234), casted.getObject());
+ assertTrue(casted.exists());
+ }
+
+ @Test
+ public void longStreamCastingTest() {
+ TestLongValue val = new TestLongValue();
+
+ assertTrue(val instanceof LongValueStream);
+ LongValueStream casted = (LongValueStream)val;
+
+ // No values
+ val.setExists(false);
+ casted.streamLongs( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple Values
+ val.setValue(20L).setExists(true);
+ Iterator<Long> values = Arrays.asList(20L).iterator();
+ casted.streamLongs( value -> {
+ assertTrue(values.hasNext());
+ assertEquals(values.next().longValue(), value);
+ });
+ assertFalse(values.hasNext());
+ }
+
+ @Test
+ public void doubleStreamCastingTest() {
+ TestLongValue val = new TestLongValue();
+
+ assertTrue(val instanceof DoubleValueStream);
+ DoubleValueStream casted = (DoubleValueStream)val;
+
+ // No values
+ val.setExists(false);
+ casted.streamDoubles( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple Values
+ val.setValue(20L).setExists(true);
+ Iterator<Double> values = Arrays.asList(20.0).iterator();
+ casted.streamDoubles( value -> {
+ assertTrue(values.hasNext());
+ assertEquals(values.next(), value, .00001);
+ });
+ assertFalse(values.hasNext());
+ }
+
+ @Test
+ public void stringStreamCastingTest() {
+ TestLongValue val = new TestLongValue();
+
+ assertTrue(val instanceof StringValueStream);
+ StringValueStream casted = (StringValueStream)val;
+
+ // No values
+ val.setExists(false);
+ casted.streamStrings( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple Values
+ val.setValue(20L).setExists(true);
+ Iterator<String> values = Arrays.asList("20").iterator();
+ casted.streamStrings( value -> {
+ assertTrue(values.hasNext());
+ assertEquals(values.next(), value);
+ });
+ assertFalse(values.hasNext());
+ }
+
+ @Test
+ public void objectStreamCastingTest() {
+ TestLongValue val = new TestLongValue();
+
+ assertTrue(val instanceof AnalyticsValueStream);
+ AnalyticsValueStream casted = (AnalyticsValueStream)val;
+
+ // No values
+ val.setExists(false);
+ casted.streamObjects( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple Values
+ val.setValue(20L).setExists(true);
+ Iterator<Object> values = Arrays.<Object>asList(new Long(20L)).iterator();
+ casted.streamObjects( value -> {
+ assertTrue(values.hasNext());
+ assertEquals(values.next(), value);
+ });
+ assertFalse(values.hasNext());
+ }
+
+ @Test
+ public void constantConversionTest() {
+ TestLongValue val = new TestLongValue(ExpressionType.CONST);
+ val.setValue(12341L).setExists(true);
+ AnalyticsValueStream conv = val.convertToConstant();
+ assertTrue(conv instanceof ConstantLongValue);
+ assertEquals(12341L, ((ConstantLongValue)conv).getLong());
+
+ val = new TestLongValue(ExpressionType.FIELD);
+ val.setValue(12341L).setExists(true);
+ conv = val.convertToConstant();
+ assertSame(val, conv);
+
+ val = new TestLongValue(ExpressionType.UNREDUCED_MAPPING);
+ val.setValue(12341L).setExists(true);
+ conv = val.convertToConstant();
+ assertSame(val, conv);
+
+ val = new TestLongValue(ExpressionType.REDUCTION);
+ val.setValue(12341L).setExists(true);
+ conv = val.convertToConstant();
+ assertSame(val, conv);
+
+ val = new TestLongValue(ExpressionType.REDUCED_MAPPING);
+ val.setValue(12341L).setExists(true);
+ conv = val.convertToConstant();
+ assertSame(val, conv);
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingStringValueStreamTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingStringValueStreamTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingStringValueStreamTest.java
new file mode 100644
index 0000000..8b1a229
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingStringValueStreamTest.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.value;
+
+import java.util.Arrays;
+import java.util.Iterator;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.analytics.value.FillableTestValue.TestStringValueStream;
+import org.junit.Test;
+
+public class CastingStringValueStreamTest extends SolrTestCaseJ4 {
+
+ @Test
+ public void objectStreamCastingTest() {
+ TestStringValueStream val = new TestStringValueStream();
+
+ assertTrue(val instanceof AnalyticsValueStream);
+ AnalyticsValueStream casted = (AnalyticsValueStream)val;
+
+ // No values
+ val.setValues();
+ casted.streamObjects( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple Values
+ val.setValues("abc", "def", "ghi");
+ Iterator<Object> values = Arrays.<Object>asList("abc", "def", "ghi").iterator();
+ casted.streamObjects( value -> {
+ assertTrue(values.hasNext());
+ assertEquals(values.next(), value);
+ });
+ assertFalse(values.hasNext());
+ }
+
+ @Test
+ public void constantConversionTest() {
+ AnalyticsValueStream val = new TestStringValueStream();
+ assertSame(val, val.convertToConstant());
+ }
+}
[14/20] lucene-solr:master: SOLR-11145,
SOLR-11146: Added comprehensive unit tests for Analytics Component
2.0 as well as analytics bug fixes.
Posted by dp...@apache.org.
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/FieldFacetCloudTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/FieldFacetCloudTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/FieldFacetCloudTest.java
deleted file mode 100644
index d4ffb40..0000000
--- a/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/FieldFacetCloudTest.java
+++ /dev/null
@@ -1,1212 +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.Collection;
-import java.util.Collections;
-import java.util.List;
-
-import org.apache.solr.client.solrj.request.UpdateRequest;
-import org.apache.solr.common.util.NamedList;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-
-public class FieldFacetCloudTest extends AbstractAnalyticsFacetCloudTest {
- public static final int INT = 71;
- public static final int LONG = 36;
- public static final int LONGM = 50;
- public static final int FLOAT = 73;
- public static final int FLOATM = 84;
- public static final int DOUBLE = 49;
- public static final int DATE = 12;
- public static final int DATEM = 30;
- public static final int STRING = 29;
- public static final int STRINGM = 41;
- public static final int NUM_LOOPS = 100;
-
- //INT
- private static ArrayList<ArrayList<Integer>> intDateTestStart;
- private static ArrayList<Long> intDateTestMissing;
- private static ArrayList<ArrayList<Integer>> intStringTestStart;
- private static ArrayList<Long> intStringTestMissing;
-
- //LONG
- private static ArrayList<ArrayList<Long>> longDateTestStart;
- private static ArrayList<Long> longDateTestMissing;
- private static ArrayList<ArrayList<Long>> longStringTestStart;
- private static ArrayList<Long> longStringTestMissing;
-
- //FLOAT
- private static ArrayList<ArrayList<Float>> floatDateTestStart;
- private static ArrayList<Long> floatDateTestMissing;
- private static ArrayList<ArrayList<Float>> floatStringTestStart;
- private static ArrayList<Long> floatStringTestMissing;
-
- //DOUBLE
- private static ArrayList<ArrayList<Double>> doubleDateTestStart;
- private static ArrayList<Long> doubleDateTestMissing;
- private static ArrayList<ArrayList<Double>> doubleStringTestStart;
- private static ArrayList<Long> doubleStringTestMissing;
-
- //DATE
- private static ArrayList<ArrayList<String>> dateIntTestStart;
- private static ArrayList<Long> dateIntTestMissing;
- private static ArrayList<ArrayList<String>> dateLongTestStart;
- private static ArrayList<Long> dateLongTestMissing;
-
- //String
- private static ArrayList<ArrayList<String>> stringIntTestStart;
- private static ArrayList<Long> stringIntTestMissing;
- private static ArrayList<ArrayList<String>> stringLongTestStart;
- private static ArrayList<Long> stringLongTestMissing;
-
- //Multi-Valued
- private static ArrayList<ArrayList<Integer>> multiLongTestStart;
- private static ArrayList<Long> multiLongTestMissing;
- private static ArrayList<ArrayList<Integer>> multiStringTestStart;
- private static ArrayList<Long> multiStringTestMissing;
- private static ArrayList<ArrayList<Integer>> multiDateTestStart;
- private static ArrayList<Long> multiDateTestMissing;
-
- @BeforeClass
- public static void beforeClass() throws Exception {
- setupCluster();
-
- //INT
- intDateTestStart = new ArrayList<>();
- intDateTestMissing = new ArrayList<>();
- intStringTestStart = new ArrayList<>();
- intStringTestMissing = new ArrayList<>();
-
- //LONG
- longDateTestStart = new ArrayList<>();
- longDateTestMissing = new ArrayList<>();
- longStringTestStart = new ArrayList<>();
- longStringTestMissing = new ArrayList<>();
-
- //FLOAT
- floatDateTestStart = new ArrayList<>();
- floatDateTestMissing = new ArrayList<>();
- floatStringTestStart = new ArrayList<>();
- floatStringTestMissing = new ArrayList<>();
-
- //DOUBLE
- doubleDateTestStart = new ArrayList<>();
- doubleDateTestMissing = new ArrayList<>();
- doubleStringTestStart = new ArrayList<>();
- doubleStringTestMissing = new ArrayList<>();
-
- //DATE
- dateIntTestStart = new ArrayList<>();
- dateIntTestMissing = new ArrayList<>();
- dateLongTestStart = new ArrayList<>();
- dateLongTestMissing = new ArrayList<>();
-
- //String
- stringIntTestStart = new ArrayList<>();
- stringIntTestMissing = new ArrayList<>();
- stringLongTestStart = new ArrayList<>();
- stringLongTestMissing = new ArrayList<>();
-
- //Multi-Valued
- multiLongTestStart = new ArrayList<>();
- multiLongTestMissing = new ArrayList<>();
- multiStringTestStart = new ArrayList<>();
- multiStringTestMissing = new ArrayList<>();
- multiDateTestStart = new ArrayList<>();
- multiDateTestMissing = new ArrayList<>();
-
- boolean multiCanHaveDuplicates = Boolean.getBoolean(NUMERIC_POINTS_SYSPROP);
-
- UpdateRequest req = new UpdateRequest();
- for (int j = 0; j < NUM_LOOPS; ++j) {
- int i = j%INT;
- long l = j%LONG;
- long lm = j%LONGM;
- float f = j%FLOAT;
- double d = j%DOUBLE;
- int dt = j%DATE;
- int dtm = j%DATEM;
- int s = j%STRING;
- int sm = j%STRINGM;
-
- List<String> fields = new ArrayList<>();
- fields.add("id"); fields.add("1000"+j);
-
- if( i != 0 ) {
- fields.add("int_id"); fields.add("" + i);
- }
- if( l != 0l ) {
- fields.add("long_ld"); fields.add("" + l);
- fields.add("long_ldm"); fields.add("" + l);
- }
- if( lm != 0l ) {
- fields.add("long_ldm"); fields.add("" + lm);
- }
- if( f != 0.0f ) {
- fields.add("float_fd"); fields.add("" + f);
- }
- if( d != 0.0d ) {
- fields.add("double_dd"); fields.add("" + d);
- }
- if( dt != 0 ) {
- fields.add("date_dtd"); fields.add((1800+dt) + "-12-31T23:59:59Z");
- fields.add("date_dtdm"); fields.add((1800+dt) + "-12-31T23:59:59Z");
- }
- if ( dtm != 0 ) {
- fields.add("date_dtdm"); fields.add((1800+dtm) + "-12-31T23:59:59Z");
- }
- if ( s != 0 ) {
- fields.add("string_sd"); fields.add("str" + s);
- fields.add("string_sdm"); fields.add("str" + s);
- }
- if ( sm != 0 ) {
- fields.add("string_sdm"); fields.add("str" + sm);
- }
- req.add(fields.toArray(new String[0]));
-
- if( dt != 0 ) {
- //Dates
- if ( j-DATE < 0 ) {
- ArrayList<Integer> list1 = new ArrayList<>();
- if( i != 0 ) {
- list1.add(i);
- intDateTestMissing.add(0l);
- } else {
- intDateTestMissing.add(1l);
- }
- intDateTestStart.add(list1);
- ArrayList<Long> list2 = new ArrayList<>();
- if( l != 0l ) {
- list2.add(l);
- longDateTestMissing.add(0l);
- } else {
- longDateTestMissing.add(1l);
- }
- longDateTestStart.add(list2);
- ArrayList<Float> list3 = new ArrayList<>();
- if ( f != 0.0f ) {
- list3.add(f);
- floatDateTestMissing.add(0l);
- } else {
- floatDateTestMissing.add(1l);
-
- }
- floatDateTestStart.add(list3);
- ArrayList<Double> list4 = new ArrayList<>();
- if( d != 0.0d ) {
- list4.add(d);
- doubleDateTestMissing.add(0l);
- } else {
- doubleDateTestMissing.add(1l);
- }
- doubleDateTestStart.add(list4);
- ArrayList<Integer> list5 = new ArrayList<>();
- if( i != 0 ) {
- list5.add(i);
- multiDateTestMissing.add(0l);
- } else {
- multiDateTestMissing.add(1l);
-
- }
- multiDateTestStart.add(list5);
- } else {
- if( i != 0 ) intDateTestStart.get(dt-1).add(i); else increment(intDateTestMissing,dt-1);
- if( l != 0l ) longDateTestStart.get(dt-1).add(l); else increment(longDateTestMissing,dt-1);
- if( f != 0.0f ) floatDateTestStart.get(dt-1).add(f); else increment(floatDateTestMissing,dt-1);
- if( d != 0.0d ) doubleDateTestStart.get(dt-1).add(d); else increment(doubleDateTestMissing,dt-1);
- if( i != 0 ) multiDateTestStart.get(dt-1).add(i); else increment(multiDateTestMissing,dt-1);
- }
- }
-
- if ( dtm != 0 ) {
- if ( j-DATEM < 0 && dtm != dt ) {
- ArrayList<Integer> list1 = new ArrayList<>();
- if( i != 0 ) {
- list1.add(i);
- multiDateTestMissing.add(0l);
- } else {
- multiDateTestMissing.add(1l);
- }
- multiDateTestStart.add(list1);
- } else if ( dtm != dt || multiCanHaveDuplicates ) {
- if( i != 0 ) multiDateTestStart.get(dtm-1).add(i); else increment(multiDateTestMissing,dtm-1);
- }
- }
-
- if( s != 0 ){
- //Strings
- if ( j-STRING < 0 ) {
- ArrayList<Integer> list1 = new ArrayList<>();
- if( i != 0 ) {
- list1.add(i);
- intStringTestMissing.add(0l);
- } else {
- intStringTestMissing.add(1l);
- }
- intStringTestStart.add(list1);
- ArrayList<Long> list2 = new ArrayList<>();
- if( l != 0l ) {
- list2.add(l);
- longStringTestMissing.add(0l);
- } else {
- longStringTestMissing.add(1l);
- }
- longStringTestStart.add(list2);
- ArrayList<Float> list3 = new ArrayList<>();
- if( f != 0.0f ){
- list3.add(f);
- floatStringTestMissing.add(0l);
- } else {
- floatStringTestMissing.add(1l);
- }
- floatStringTestStart.add(list3);
- ArrayList<Double> list4 = new ArrayList<>();
- if( d != 0.0d ) {
- list4.add(d);
- doubleStringTestMissing.add(0l);
- } else {
- doubleStringTestMissing.add(1l);
- }
- doubleStringTestStart.add(list4);
- ArrayList<Integer> list5 = new ArrayList<>();
- if( i != 0 ) {
- list5.add(i);
- multiStringTestMissing.add(0l);
- } else {
- multiStringTestMissing.add(1l);
- }
- multiStringTestStart.add(list5);
- } else {
- if( i != 0 ) intStringTestStart.get(s-1).add(i); else increment(intStringTestMissing,s-1);
- if( l != 0l ) longStringTestStart.get(s-1).add(l); else increment(longStringTestMissing,s-1);
- if( f != 0.0f ) floatStringTestStart.get(s-1).add(f); else increment(floatStringTestMissing,s-1);
- if( d != 0.0d ) doubleStringTestStart.get(s-1).add(d); else increment(doubleStringTestMissing,s-1);
- if( i != 0 ) multiStringTestStart.get(s-1).add(i); else increment(multiStringTestMissing,s-1);
- }
- }
-
- //Strings
- if( sm != 0 ){
- if ( j-STRINGM < 0 && sm != s ) {
- ArrayList<Integer> list1 = new ArrayList<>();
- if( i != 0 ){
- list1.add(i);
- multiStringTestMissing.add(0l);
- } else {
- multiStringTestMissing.add(1l);
- }
- multiStringTestStart.add(list1);
- } else if ( sm != s ) {
- if( i != 0 ) multiStringTestStart.get(sm-1).add(i); else increment(multiStringTestMissing,sm-1);
- }
- }
-
- //Int
- if( i != 0 ) {
- if ( j-INT < 0 ) {
- ArrayList<String> list1 = new ArrayList<>();
- if( dt != 0 ){
- list1.add((1800+dt) + "-12-31T23:59:59Z");
- dateIntTestMissing.add(0l);
- } else {
- dateIntTestMissing.add(1l);
- }
- dateIntTestStart.add(list1);
- ArrayList<String> list2 = new ArrayList<>();
- if( s != 0 ) {
- list2.add("str"+s);
- stringIntTestMissing.add(0l);
- } else {
- stringIntTestMissing.add(1l);
- }
- stringIntTestStart.add(list2);
- } else {
- if( dt != 0 ) dateIntTestStart.get(i-1).add((1800+dt) + "-12-31T23:59:59Z"); else increment(dateIntTestMissing,i-1);
- if( s != 0 ) stringIntTestStart.get(i-1).add("str"+s); else increment(stringIntTestMissing,i-1);
- }
- }
-
- //Long
- if( l != 0 ) {
- if ( j-LONG < 0 ) {
- ArrayList<String> list1 = new ArrayList<>();
- if( dt != 0 ){
- list1.add((1800+dt) + "-12-31T23:59:59Z");
- dateLongTestMissing.add(0l);
- } else {
- dateLongTestMissing.add(1l);
- }
- dateLongTestStart.add(list1);
- ArrayList<String> list2 = new ArrayList<>();
- if( s != 0 ) {
- list2.add("str"+s);
- stringLongTestMissing.add(0l);
- } else {
- stringLongTestMissing.add(1l);
- }
- stringLongTestStart.add(list2);
- ArrayList<Integer> list3 = new ArrayList<>();
- if( i != 0 ) {
- list3.add(i);
- multiLongTestMissing.add(0l);
- } else {
- multiLongTestMissing.add(1l);
- }
- multiLongTestStart.add(list3);
- } else {
- if( dt != 0 ) dateLongTestStart.get((int)l-1).add((1800+dt) + "-12-31T23:59:59Z"); else increment(dateLongTestMissing,(int)l-1);
- if( s != 0 ) stringLongTestStart.get((int)l-1).add("str"+s); else increment(stringLongTestMissing,(int)l-1);
- if( i != 0 ) multiLongTestStart.get((int)l-1).add(i); else increment(multiLongTestMissing,(int)l-1);
- }
- }
-
- //Long
- if( lm != 0 ) {
- if ( j-LONGM < 0 && lm != l ) {
- ArrayList<Integer> list1 = new ArrayList<>();
- if( i != 0 ) {
- list1.add(i);
- multiLongTestMissing.add(0l);
- } else {
- multiLongTestMissing.add(1l);
- }
- multiLongTestStart.add(list1);
- } else if ( lm != l || multiCanHaveDuplicates ) {
- if( i != 0 ) multiLongTestStart.get((int)lm-1).add(i); else increment( multiLongTestMissing,(int)lm-1);
- }
- }
-
- }
-
- req.commit(cluster.getSolrClient(), COLLECTIONORALIAS);
-
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void sumTest() throws Exception {
- String[] params = new String[] {
- "o.sum.s.int", "sum(int_id)",
- "o.sum.s.long", "sum(long_ld)",
- "o.sum.s.float", "sum(float_fd)",
- "o.sum.s.double", "sum(double_dd)",
- "o.sum.ff", "string_sd",
- "o.sum.ff", "date_dtd"
- };
- NamedList<Object> response = queryCloudAnalytics(params);
- String responseStr = response.toString();
-
- //Int Date
- Collection<Double> intDate = getValueList(response, "sum", "fieldFacets", "date_dtd", "int", false);
- ArrayList<Double> intDateTest = calculateNumberStat(intDateTestStart, "sum");
- assertEquals(responseStr.toString(),intDate,intDateTest);
- //Int String
- Collection<Double> intString = getValueList(response, "sum", "fieldFacets", "string_sd", "int", false);
- ArrayList<Double> intStringTest = calculateNumberStat(intStringTestStart, "sum");
- assertEquals(responseStr,intString,intStringTest);
-
- //Long Date
- Collection<Double> longDate = getValueList(response, "sum", "fieldFacets", "date_dtd", "long", false);
- ArrayList<Double> longDateTest = calculateNumberStat(longDateTestStart, "sum");
- assertEquals(responseStr,longDate,longDateTest);
- //Long String
- Collection<Double> longString = getValueList(response, "sum", "fieldFacets", "string_sd", "long", false);
- ArrayList<Double> longStringTest = calculateNumberStat(longStringTestStart, "sum");
- assertEquals(responseStr,longString,longStringTest);
-
- //Float Date
- Collection<Double> floatDate = getValueList(response, "sum", "fieldFacets", "date_dtd", "float", false);
- ArrayList<Double> floatDateTest = calculateNumberStat(floatDateTestStart, "sum");
- assertEquals(responseStr,floatDate,floatDateTest);
- //Float String
- Collection<Double> floatString = getValueList(response, "sum", "fieldFacets", "string_sd", "float", false);
- ArrayList<Double> floatStringTest = calculateNumberStat(floatStringTestStart, "sum");
- assertEquals(responseStr,floatString,floatStringTest);
-
- //Double Date
- Collection<Double> doubleDate = getValueList(response, "sum", "fieldFacets", "date_dtd", "double", false);
- ArrayList<Double> doubleDateTest = calculateNumberStat(doubleDateTestStart, "sum");
- assertEquals(responseStr,doubleDate,doubleDateTest);
- //Double String
- Collection<Double> doubleString = getValueList(response, "sum", "fieldFacets", "string_sd", "double", false);
- ArrayList<Double> doubleStringTest = calculateNumberStat(doubleStringTestStart, "sum");
- assertEquals(responseStr,doubleString,doubleStringTest);
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void meanTest() throws Exception {
- String[] params = new String[] {
- "o.mean.s.int", "mean(int_id)",
- "o.mean.s.long", "mean(long_ld)",
- "o.mean.s.float", "mean(float_fd)",
- "o.mean.s.double", "mean(double_dd)",
- "o.mean.ff", "string_sd",
- "o.mean.ff", "date_dtd"
- };
- NamedList<Object> response = queryCloudAnalytics(params);
- String responseStr = response.toString();
-
- //Int Date
- Collection<Double> intDate = getValueList(response, "mean", "fieldFacets", "date_dtd", "int", false);
- ArrayList<Double> intDateTest = calculateNumberStat(intDateTestStart, "mean");
- assertEquals(responseStr,intDate,intDateTest);
- //Int String
- Collection<Double> intString = getValueList(response, "mean", "fieldFacets", "string_sd", "int", false);
- ArrayList<Double> intStringTest = calculateNumberStat(intStringTestStart, "mean");
- assertEquals(responseStr,intString,intStringTest);
-
- //Long Date
- Collection<Double> longDate = getValueList(response, "mean", "fieldFacets", "date_dtd", "long", false);
- ArrayList<Double> longDateTest = calculateNumberStat(longDateTestStart, "mean");
- assertEquals(responseStr,longDate,longDateTest);
- //Long String
- Collection<Double> longString = getValueList(response, "mean", "fieldFacets", "string_sd", "long", false);
- ArrayList<Double> longStringTest = calculateNumberStat(longStringTestStart, "mean");
- assertEquals(responseStr,longString,longStringTest);
-
- //Float Date
- Collection<Double> floatDate = getValueList(response, "mean", "fieldFacets", "date_dtd", "float", false);
- ArrayList<Double> floatDateTest = calculateNumberStat(floatDateTestStart, "mean");
- assertEquals(responseStr,floatDate,floatDateTest);
- //Float String
- Collection<Double> floatString = getValueList(response, "mean", "fieldFacets", "string_sd", "float", false);
- ArrayList<Double> floatStringTest = calculateNumberStat(floatStringTestStart, "mean");
- assertEquals(responseStr,floatString,floatStringTest);
-
- //Double Date
- Collection<Double> doubleDate = getValueList(response, "mean", "fieldFacets", "date_dtd", "double", false);
- ArrayList<Double> doubleDateTest = calculateNumberStat(doubleDateTestStart, "mean");
- assertEquals(responseStr,doubleDate,doubleDateTest);
- //Double String
- Collection<Double> doubleString = getValueList(response, "mean", "fieldFacets", "string_sd", "double", false);
- ArrayList<Double> doubleStringTest = calculateNumberStat(doubleStringTestStart, "mean");
- assertEquals(responseStr,doubleString,doubleStringTest);
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void stddevFacetAscTest() throws Exception {
- String[] params = new String[] {
- "o.stddev.s.int", "stddev(int_id)",
- "o.stddev.s.long", "stddev(long_ld)",
- "o.stddev.s.float", "stddev(float_fd)",
- "o.stddev.s.double", "stddev(double_dd)",
- "o.stddev.ff", "string_sd",
- "o.stddev.ff", "date_dtd"
- };
- NamedList<Object> response = queryCloudAnalytics(params);
-
- //Int Date
- ArrayList<Double> intDate = getValueList(response, "stddev", "fieldFacets", "date_dtd", "int", false);
- ArrayList<Double> intDateTest = calculateNumberStat(intDateTestStart, "stddev");
- checkStddevs(response, intDate, intDateTest);
- //Int String
- ArrayList<Double> intString = getValueList(response, "stddev", "fieldFacets", "string_sd", "int", false);
- ArrayList<Double> intStringTest = calculateNumberStat(intStringTestStart, "stddev");
- checkStddevs(response, intString, intStringTest);
-
- //Long Date
- ArrayList<Double> longDate = getValueList(response, "stddev", "fieldFacets", "date_dtd", "long", false);
- ArrayList<Double> longDateTest = calculateNumberStat(longDateTestStart, "stddev");
- checkStddevs(response, longDate, longDateTest);
- //Long String
- ArrayList<Double> longString = getValueList(response, "stddev", "fieldFacets", "string_sd", "long", false);
- ArrayList<Double> longStringTest = calculateNumberStat(longStringTestStart, "stddev");
- checkStddevs(response, longString, longStringTest);
-
- //Float Date
- ArrayList<Double> floatDate = getValueList(response, "stddev", "fieldFacets", "date_dtd", "float", false);
- ArrayList<Double> floatDateTest = calculateNumberStat(floatDateTestStart, "stddev");
- checkStddevs(response, floatDate, floatDateTest);
- //Float String
- ArrayList<Double> floatString = getValueList(response, "stddev", "fieldFacets", "string_sd", "float", false);
- ArrayList<Double> floatStringTest = calculateNumberStat(floatStringTestStart, "stddev");
- checkStddevs(response, floatString, floatStringTest);
-
- //Double Date
- ArrayList<Double> doubleDate = getValueList(response, "stddev", "fieldFacets", "date_dtd", "double", false);
- ArrayList<Double> doubleDateTest = calculateNumberStat(doubleDateTestStart, "stddev");
- checkStddevs(response, doubleDate, doubleDateTest);
- //Double String
- ArrayList<Double> doubleString = getValueList(response, "stddev", "fieldFacets", "string_sd", "double", false);
- ArrayList<Double> doubleStringTest = calculateNumberStat(doubleStringTestStart, "stddev");
- checkStddevs(response, doubleString, doubleStringTest);
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void medianFacetAscTest() throws Exception {
- String[] params = new String[] {
- "o.median.s.int", "median(int_id)",
- "o.median.s.long", "median(long_ld)",
- "o.median.s.float", "median(float_fd)",
- "o.median.s.double", "median(double_dd)",
- "o.median.ff", "string_sd",
- "o.median.ff", "date_dtd"
- };
- NamedList<Object> response = queryCloudAnalytics(params);
- String responseStr = response.toString();
-
- //Int Date
- Collection<Double> intDate = getValueList(response, "median","fieldFacets", "date_dtd", "int", false);
- ArrayList<Double> intDateTest = calculateNumberStat(intDateTestStart, "median");
- assertEquals(responseStr,intDate,intDateTest);
- //Int String
- Collection<Double> intString = getValueList(response, "median", "fieldFacets", "string_sd", "int", false);
- ArrayList<Double> intStringTest = calculateNumberStat(intStringTestStart, "median");
- assertEquals(responseStr,intString,intStringTest);
-
- //Long Date
- Collection<Double> longDate = getValueList(response, "median", "fieldFacets", "date_dtd", "long", false);
- ArrayList<Double> longDateTest = calculateNumberStat(longDateTestStart, "median");
- assertEquals(responseStr,longDate,longDateTest);
- //Long String
- Collection<Double> longString = getValueList(response, "median", "fieldFacets", "string_sd", "long", false);
- ArrayList<Double> longStringTest = calculateNumberStat(longStringTestStart, "median");
- assertEquals(responseStr,longString,longStringTest);
-
- //Float Date
- Collection<Double> floatDate = getValueList(response, "median", "fieldFacets", "date_dtd", "float", false);
- ArrayList<Double> floatDateTest = calculateNumberStat(floatDateTestStart, "median");
- assertEquals(responseStr,floatDate,floatDateTest);
- //Float String
- Collection<Double> floatString = getValueList(response, "median", "fieldFacets", "string_sd", "float", false);
- ArrayList<Double> floatStringTest = calculateNumberStat(floatStringTestStart, "median");
- assertEquals(responseStr,floatString,floatStringTest);
-
- //Double Date
- Collection<Double> doubleDate = getValueList(response, "median", "fieldFacets", "date_dtd", "double", false);
- ArrayList<Double> doubleDateTest = calculateNumberStat(doubleDateTestStart, "median");
- assertEquals(responseStr,doubleDate,doubleDateTest);
- //Double String
- Collection<Double> doubleString = getValueList(response, "median", "fieldFacets", "string_sd", "double", false);
- ArrayList<Double> doubleStringTest = calculateNumberStat(doubleStringTestStart, "median");
- assertEquals(responseStr,doubleString,doubleStringTest);
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void perc20Test() throws Exception {
- String[] params = new String[] {
- "o.percentile_20n.s.int", "percentile(20,int_id)",
- "o.percentile_20n.s.long", "percentile(20,long_ld)",
- "o.percentile_20n.s.float", "percentile(20,float_fd)",
- "o.percentile_20n.s.double", "percentile(20,double_dd)",
- "o.percentile_20n.ff", "string_sd",
- "o.percentile_20n.ff", "date_dtd",
-
- "o.percentile_20.s.str", "percentile(20,string_sd)",
- "o.percentile_20.s.date", "string(percentile(20,date_dtd))",
- "o.percentile_20.ff", "int_id",
- "o.percentile_20.ff", "long_ld"
- };
- NamedList<Object> response = queryCloudAnalytics(params);
- String responseStr = response.toString();
-
- //Int Date
- Collection<Integer> intDate = getValueList(response, "percentile_20n", "fieldFacets", "date_dtd", "int", false);
- ArrayList<Integer> intDateTest = (ArrayList<Integer>)calculateStat(intDateTestStart, "perc_20");
- assertEquals(responseStr,intDate,intDateTest);
- //Int String
- Collection<Integer> intString = getValueList(response, "percentile_20n", "fieldFacets", "string_sd", "int", false);
- ArrayList<Integer> intStringTest = (ArrayList<Integer>)calculateStat(intStringTestStart, "perc_20");
- assertEquals(responseStr,intString,intStringTest);
-
- //Long Date
- Collection<Long> longDate = getValueList(response, "percentile_20n", "fieldFacets", "date_dtd", "long", false);
- ArrayList<Long> longDateTest = (ArrayList<Long>)calculateStat(longDateTestStart, "perc_20");
- assertEquals(responseStr,longDate,longDateTest);
- //Long String
- Collection<Long> longString = getValueList(response, "percentile_20n", "fieldFacets", "string_sd", "long", false);
- ArrayList<Long> longStringTest = (ArrayList<Long>)calculateStat(longStringTestStart, "perc_20");
- assertEquals(responseStr,longString,longStringTest);
-
- //Float Date
- Collection<Float> floatDate = getValueList(response, "percentile_20n", "fieldFacets", "date_dtd", "float", false);
- ArrayList<Float> floatDateTest = (ArrayList<Float>)calculateStat(floatDateTestStart, "perc_20");
- assertEquals(responseStr,floatDate,floatDateTest);
- //Float String
- Collection<Float> floatString = getValueList(response, "percentile_20n", "fieldFacets", "string_sd", "float", false);
- ArrayList<Float> floatStringTest = (ArrayList<Float>)calculateStat(floatStringTestStart, "perc_20");
- assertEquals(responseStr,floatString,floatStringTest);
-
- //Double Date
- Collection<Double> doubleDate = getValueList(response, "percentile_20n", "fieldFacets", "date_dtd", "double", false);
- ArrayList<Double> doubleDateTest = (ArrayList<Double>)calculateStat(doubleDateTestStart, "perc_20");
- assertEquals(responseStr,doubleDate,doubleDateTest);
- //Double String
- Collection<Double> doubleString = getValueList(response, "percentile_20n", "fieldFacets", "string_sd", "double", false);
- ArrayList<Double> doubleStringTest = (ArrayList<Double>)calculateStat(doubleStringTestStart, "perc_20");
- assertEquals(responseStr,doubleString,doubleStringTest);
-
- //Date Int
- Collection<String> dateInt = getValueList(response, "percentile_20", "fieldFacets", "int_id", "date", false);
- ArrayList<String> dateIntTest = (ArrayList<String>)calculateStat(dateIntTestStart, "perc_20");
- assertEquals(responseStr,dateInt,dateIntTest);
- //Date Long
- Collection<String> dateString = getValueList(response, "percentile_20", "fieldFacets", "long_ld", "date", false);
- ArrayList<String> dateLongTest = (ArrayList<String>)calculateStat(dateLongTestStart, "perc_20");
- assertEquals(responseStr,dateString,dateLongTest);
-
- //String Int
- Collection<String> stringInt = getValueList(response, "percentile_20", "fieldFacets", "int_id", "str", false);
- ArrayList<String> stringIntTest = (ArrayList<String>)calculateStat(stringIntTestStart, "perc_20");
- assertEquals(responseStr,stringInt,stringIntTest);
- //String Long
- Collection<String> stringLong = getValueList(response, "percentile_20", "fieldFacets", "long_ld", "str", false);
- ArrayList<String> stringLongTest = (ArrayList<String>)calculateStat(stringLongTestStart, "perc_20");
- assertEquals(responseStr,stringLong,stringLongTest);
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void perc60Test() throws Exception {
- String[] params = new String[] {
- "o.percentile_60n.s.int", "percentile(60,int_id)",
- "o.percentile_60n.s.long", "percentile(60,long_ld)",
- "o.percentile_60n.s.float", "percentile(60,float_fd)",
- "o.percentile_60n.s.double", "percentile(60,double_dd)",
- "o.percentile_60n.ff", "string_sd",
- "o.percentile_60n.ff", "date_dtd",
-
- "o.percentile_60.s.str", "percentile(60,string_sd)",
- "o.percentile_60.s.date", "string(percentile(60,date_dtd))",
- "o.percentile_60.ff", "int_id",
- "o.percentile_60.ff", "long_ld"
- };
- NamedList<Object> response = queryCloudAnalytics(params);
- String responseStr = response.toString();
-
- //Int Date
- Collection<Integer> intDate = getValueList(response, "percentile_60n", "fieldFacets", "date_dtd", "int", false);
- ArrayList<Integer> intDateTest = (ArrayList<Integer>)calculateStat(intDateTestStart, "perc_60");
- assertEquals(responseStr,intDate,intDateTest);
- //Int String
- Collection<Integer> intString = getValueList(response, "percentile_60n", "fieldFacets", "string_sd", "int", false);
- ArrayList<Integer> intStringTest = (ArrayList<Integer>)calculateStat(intStringTestStart, "perc_60");
- assertEquals(responseStr,intString,intStringTest);
-
- //Long Date
- Collection<Long> longDate = getValueList(response, "percentile_60n", "fieldFacets", "date_dtd", "long", false);
- ArrayList<Long> longDateTest = (ArrayList<Long>)calculateStat(longDateTestStart, "perc_60");
- assertEquals(responseStr,longDate,longDateTest);
- //Long String
- Collection<Long> longString = getValueList(response, "percentile_60n", "fieldFacets", "string_sd", "long", false);
- ArrayList<Long> longStringTest = (ArrayList<Long>)calculateStat(longStringTestStart, "perc_60");
- assertEquals(responseStr,longString,longStringTest);
-
- //Float Date
- Collection<Float> floatDate = getValueList(response, "percentile_60n", "fieldFacets", "date_dtd", "float", false);
- ArrayList<Float> floatDateTest = (ArrayList<Float>)calculateStat(floatDateTestStart, "perc_60");
- assertEquals(responseStr,floatDate,floatDateTest);
- //Float String
- Collection<Float> floatString = getValueList(response, "percentile_60n", "fieldFacets", "string_sd", "float", false);
- ArrayList<Float> floatStringTest = (ArrayList<Float>)calculateStat(floatStringTestStart, "perc_60");
- assertEquals(responseStr,floatString,floatStringTest);
-
- //Double Date
- Collection<Double> doubleDate = getValueList(response, "percentile_60n", "fieldFacets", "date_dtd", "double", false);
- ArrayList<Double> doubleDateTest = (ArrayList<Double>)calculateStat(doubleDateTestStart, "perc_60");
- assertEquals(responseStr,doubleDate,doubleDateTest);
- //Double String
- Collection<Double> doubleString = getValueList(response, "percentile_60n", "fieldFacets", "string_sd", "double", false);
- ArrayList<Double> doubleStringTest = (ArrayList<Double>)calculateStat(doubleStringTestStart, "perc_60");
- assertEquals(responseStr,doubleString,doubleStringTest);
-
- //Date Int
- Collection<String> dateInt = getValueList(response, "percentile_60", "fieldFacets", "int_id", "date", false);
- ArrayList<String> dateIntTest = (ArrayList<String>)calculateStat(dateIntTestStart, "perc_60");
- assertEquals(responseStr,dateInt,dateIntTest);
- //Date Long
- Collection<String> dateString = getValueList(response, "percentile_60", "fieldFacets", "long_ld", "date", false);
- ArrayList<String> dateLongTest = (ArrayList<String>)calculateStat(dateLongTestStart, "perc_60");
- assertEquals(responseStr,dateString,dateLongTest);
-
- //String Int
- Collection<String> stringInt = getValueList(response, "percentile_60", "fieldFacets", "int_id", "str", false);
- ArrayList<String> stringIntTest = (ArrayList<String>)calculateStat(stringIntTestStart, "perc_60");
- assertEquals(responseStr,stringInt,stringIntTest);
- //String Long
- Collection<String> stringLong = getValueList(response, "percentile_60", "fieldFacets", "long_ld", "str", false);
- ArrayList<String> stringLongTest = (ArrayList<String>)calculateStat(stringLongTestStart, "perc_60");
- assertEquals(responseStr,stringLong,stringLongTest);
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void minTest() throws Exception {
- String[] params = new String[] {
- "o.minn.s.int", "min(int_id)",
- "o.minn.s.long", "min(long_ld)",
- "o.minn.s.float", "min(float_fd)",
- "o.minn.s.double", "min(double_dd)",
- "o.minn.ff", "string_sd",
- "o.minn.ff", "date_dtd",
-
- "o.min.s.str", "min(string_sd)",
- "o.min.s.date", "string(min(date_dtd))",
- "o.min.ff", "int_id",
- "o.min.ff", "long_ld"
- };
- NamedList<Object> response = queryCloudAnalytics(params);
- String responseStr = response.toString();
-
- //Int Date
- Collection<Integer> intDate = getValueList(response, "minn", "fieldFacets", "date_dtd", "int", false);
- ArrayList<Integer> intDateTest = (ArrayList<Integer>)calculateStat(intDateTestStart, "min");
- assertEquals(responseStr,intDate,intDateTest);
- //Int String
- Collection<Integer> intString = getValueList(response, "minn", "fieldFacets", "string_sd", "int", false);
- ArrayList<Integer> intStringTest = (ArrayList<Integer>)calculateStat(intStringTestStart, "min");
- assertEquals(responseStr,intString,intStringTest);
-
- //Long Date
- Collection<Long> longDate = getValueList(response, "minn", "fieldFacets", "date_dtd", "long", false);
- ArrayList<Long> longDateTest = (ArrayList<Long>)calculateStat(longDateTestStart, "min");
- assertEquals(responseStr,longDate,longDateTest);
- //Long String
- Collection<Long> longString = getValueList(response, "minn", "fieldFacets", "string_sd", "long", false);
- ArrayList<Long> longStringTest = (ArrayList<Long>)calculateStat(longStringTestStart, "min");
- assertEquals(responseStr,longString,longStringTest);
-
- //Float Date
- Collection<Float> floatDate = getValueList(response, "minn", "fieldFacets", "date_dtd", "float", false);
- ArrayList<Float> floatDateTest = (ArrayList<Float>)calculateStat(floatDateTestStart, "min");
- assertEquals(responseStr,floatDate,floatDateTest);
- //Float String
- Collection<Float> floatString = getValueList(response, "minn", "fieldFacets", "string_sd", "float", false);
- ArrayList<Float> floatStringTest = (ArrayList<Float>)calculateStat(floatStringTestStart, "min");
- assertEquals(responseStr,floatString,floatStringTest);
-
- //Double Date
- Collection<Double> doubleDate = getValueList(response, "minn", "fieldFacets", "date_dtd", "double", false);
- ArrayList<Double> doubleDateTest = (ArrayList<Double>)calculateStat(doubleDateTestStart, "min");
- assertEquals(responseStr,doubleDate,doubleDateTest);
- //Double String
- Collection<Double> doubleString = getValueList(response, "minn", "fieldFacets", "string_sd", "double", false);
- ArrayList<Double> doubleStringTest = (ArrayList<Double>)calculateStat(doubleStringTestStart, "min");
- assertEquals(responseStr,doubleString,doubleStringTest);
-
- //Date Int
- Collection<String> dateInt = getValueList(response, "min", "fieldFacets", "int_id", "date", false);
- ArrayList<String> dateIntTest = (ArrayList<String>)calculateStat(dateIntTestStart, "min");
- assertEquals(responseStr,dateInt,dateIntTest);
- //Date Long
- Collection<String> dateString = getValueList(response, "min", "fieldFacets", "long_ld", "date", false);
- ArrayList<String> dateLongTest = (ArrayList<String>)calculateStat(dateLongTestStart, "min");
- assertEquals(responseStr,dateString,dateLongTest);
-
- //String Int
- Collection<String> stringInt = getValueList(response, "min", "fieldFacets", "int_id", "str", false);
- ArrayList<String> stringIntTest = (ArrayList<String>)calculateStat(stringIntTestStart, "min");
- assertEquals(responseStr,stringInt,stringIntTest);
- //String Long
- Collection<String> stringLong = getValueList(response, "min", "fieldFacets", "long_ld", "str", false);
- ArrayList<String> stringLongTest = (ArrayList<String>)calculateStat(stringLongTestStart, "min");
- assertEquals(responseStr,stringLong,stringLongTest);
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void maxTest() throws Exception {
- String[] params = new String[] {
- "o.maxn.s.int", "max(int_id)",
- "o.maxn.s.long", "max(long_ld)",
- "o.maxn.s.float", "max(float_fd)",
- "o.maxn.s.double", "max(double_dd)",
- "o.maxn.ff", "string_sd",
- "o.maxn.ff", "date_dtd",
-
- "o.max.s.str", "max(string_sd)",
- "o.max.s.date", "string(max(date_dtd))",
- "o.max.ff", "int_id",
- "o.max.ff", "long_ld"
- };
- NamedList<Object> response = queryCloudAnalytics(params);
- String responseStr = response.toString();
-
- //Int Date
- Collection<Integer> intDate = getValueList(response, "maxn", "fieldFacets", "date_dtd", "int", false);
- ArrayList<Integer> intDateTest = (ArrayList<Integer>)calculateStat(intDateTestStart, "max");
- assertEquals(responseStr,intDate,intDateTest);
-
- //Int String
- Collection<Integer> intString = getValueList(response, "maxn", "fieldFacets", "string_sd", "int", false);
- ArrayList<Integer> intStringTest = (ArrayList<Integer>)calculateStat(intStringTestStart, "max");
- assertEquals(responseStr,intString,intStringTest);
-
- //Long Date
- Collection<Long> longDate = getValueList(response, "maxn", "fieldFacets", "date_dtd", "long", false);
- ArrayList<Long> longDateTest = (ArrayList<Long>)calculateStat(longDateTestStart, "max");
- assertEquals(responseStr,longDate,longDateTest);
-
- //Long String
- Collection<Long> longString = getValueList(response, "maxn", "fieldFacets", "string_sd", "long", false);
- ArrayList<Long> longStringTest = (ArrayList<Long>)calculateStat(longStringTestStart, "max");
- assertEquals(responseStr,longString,longStringTest);
-
- //Float Date
- Collection<Float> floatDate = getValueList(response, "maxn", "fieldFacets", "date_dtd", "float", false);
- ArrayList<Float> floatDateTest = (ArrayList<Float>)calculateStat(floatDateTestStart, "max");
- assertEquals(responseStr,floatDate,floatDateTest);
-
- //Float String
- Collection<Float> floatString = getValueList(response, "maxn", "fieldFacets", "string_sd", "float", false);
- ArrayList<Float> floatStringTest = (ArrayList<Float>)calculateStat(floatStringTestStart, "max");
- assertEquals(responseStr,floatString,floatStringTest);
-
- //Double Date
- Collection<Double> doubleDate = getValueList(response, "maxn", "fieldFacets", "date_dtd", "double", false);
- ArrayList<Double> doubleDateTest = (ArrayList<Double>)calculateStat(doubleDateTestStart, "max");
- assertEquals(responseStr,doubleDate,doubleDateTest);
-
- //Double String
- Collection<Double> doubleString = getValueList(response, "maxn", "fieldFacets", "string_sd", "double", false);
- ArrayList<Double> doubleStringTest = (ArrayList<Double>)calculateStat(doubleStringTestStart, "max");
- assertEquals(responseStr,doubleString,doubleStringTest);
-
- //String Int
- Collection<String> stringInt = getValueList(response, "max", "fieldFacets", "int_id", "str", false);
- ArrayList<String> stringIntTest = (ArrayList<String>)calculateStat(stringIntTestStart, "max");
- assertEquals(responseStr,stringInt,stringIntTest);
-
- //String Long
- Collection<String> stringLong = getValueList(response, "max", "fieldFacets", "long_ld", "str", false);
- ArrayList<String> stringLongTest = (ArrayList<String>)calculateStat(stringLongTestStart, "max");
- assertEquals(responseStr,stringLong,stringLongTest);
-
- //Date Int
- Collection<String> dateInt = getValueList(response, "max", "fieldFacets", "int_id", "date", false);
- ArrayList<String> dateIntTest = (ArrayList<String>)calculateStat(dateIntTestStart, "max");
- assertEquals(responseStr,dateInt,dateIntTest);
-
- //Date Long
- Collection<String> dateString = getValueList(response, "max", "fieldFacets", "long_ld", "date", false);
- ArrayList<String> dateLongTest = (ArrayList<String>)calculateStat(dateLongTestStart, "max");
- assertEquals(responseStr,dateString,dateLongTest);
-
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void uniqueTest() throws Exception {
- String[] params = new String[] {
- "o.uniquen.s.int", "unique(int_id)",
- "o.uniquen.s.long", "unique(long_ld)",
- "o.uniquen.s.float", "unique(float_fd)",
- "o.uniquen.s.double", "unique(double_dd)",
- "o.uniquen.ff", "string_sd",
- "o.uniquen.ff", "date_dtd",
-
- "o.unique.s.str", "unique(string_sd)",
- "o.unique.s.date", "unique(date_dtd)",
- "o.unique.ff", "int_id",
- "o.unique.ff", "long_ld"
- };
- NamedList<Object> response = queryCloudAnalytics(params);
- String responseStr = response.toString();
-
- //Int Date
- Collection<Long> intDate = getValueList(response, "uniquen", "fieldFacets", "date_dtd", "int", false);
- ArrayList<Long> intDateTest = (ArrayList<Long>)calculateStat(intDateTestStart, "unique");
- assertEquals(responseStr,intDate,intDateTest);
- //Int String
- Collection<Long> intString = getValueList(response, "uniquen", "fieldFacets", "string_sd", "int", false);
- ArrayList<Long> intStringTest = (ArrayList<Long>)calculateStat(intStringTestStart, "unique");
- assertEquals(responseStr,intString,intStringTest);
-
- //Long Date
- Collection<Long> longDate = getValueList(response, "uniquen", "fieldFacets", "date_dtd", "long", false);
- ArrayList<Long> longDateTest = (ArrayList<Long>)calculateStat(longDateTestStart, "unique");
- assertEquals(responseStr,longDate,longDateTest);
- //Long String
- Collection<Long> longString = getValueList(response, "uniquen", "fieldFacets", "string_sd", "long", false);
- ArrayList<Long> longStringTest = (ArrayList<Long>)calculateStat(longStringTestStart, "unique");
- assertEquals(responseStr,longString,longStringTest);
-
- //Float Date
- Collection<Long> floatDate = getValueList(response, "uniquen", "fieldFacets", "date_dtd", "float", false);
- ArrayList<Long> floatDateTest = (ArrayList<Long>)calculateStat(floatDateTestStart, "unique");
- assertEquals(responseStr,floatDate,floatDateTest);
- //Float String
- Collection<Long> floatString = getValueList(response, "uniquen", "fieldFacets", "string_sd", "float", false);
- ArrayList<Long> floatStringTest = (ArrayList<Long>)calculateStat(floatStringTestStart, "unique");
- assertEquals(responseStr,floatString,floatStringTest);
-
- //Double Date
- Collection<Long> doubleDate = getValueList(response, "uniquen", "fieldFacets", "date_dtd", "double", false);
- ArrayList<Long> doubleDateTest = (ArrayList<Long>)calculateStat(doubleDateTestStart, "unique");
- assertEquals(responseStr,doubleDate,doubleDateTest);
- //Double String
- Collection<Long> doubleString = getValueList(response, "uniquen", "fieldFacets", "string_sd", "double", false);
- ArrayList<Long> doubleStringTest = (ArrayList<Long>)calculateStat(doubleStringTestStart, "unique");
- assertEquals(responseStr,doubleString,doubleStringTest);
-
- //Date Int
- Collection<Long> dateInt = getValueList(response, "unique", "fieldFacets", "int_id", "date", false);
- ArrayList<Long> dateIntTest = (ArrayList<Long>)calculateStat(dateIntTestStart, "unique");
- assertEquals(responseStr,dateInt,dateIntTest);
- //Date Long
- Collection<Long> dateString = getValueList(response, "unique", "fieldFacets", "long_ld", "date", false);
- ArrayList<Long> dateLongTest = (ArrayList<Long>)calculateStat(dateLongTestStart, "unique");
- assertEquals(responseStr,dateString,dateLongTest);
-
- //String Int
- Collection<Long> stringInt = getValueList(response, "unique", "fieldFacets", "int_id", "str", false);
- ArrayList<Long> stringIntTest = (ArrayList<Long>)calculateStat(stringIntTestStart, "unique");
- assertEquals(responseStr,stringInt,stringIntTest);
- //String Long
- Collection<Long> stringLong = getValueList(response, "unique", "fieldFacets", "long_ld", "str", false);
- ArrayList<Long> stringLongTest = (ArrayList<Long>)calculateStat(stringLongTestStart, "unique");
- assertEquals(responseStr,stringLong,stringLongTest);
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void countTest() throws Exception {
- String[] params = new String[] {
- "o.countn.s.int", "count(int_id)",
- "o.countn.s.long", "count(long_ld)",
- "o.countn.s.float", "count(float_fd)",
- "o.countn.s.double", "count(double_dd)",
- "o.countn.ff", "string_sd",
- "o.countn.ff", "date_dtd",
-
- "o.count.s.str", "count(string_sd)",
- "o.count.s.date", "count(date_dtd)",
- "o.count.ff", "int_id",
- "o.count.ff", "long_ld"
- };
- NamedList<Object> response = queryCloudAnalytics(params);
- String responseStr = response.toString();
-
- //Int Date
- Collection<Long> intDate = getValueList(response, "countn", "fieldFacets", "date_dtd", "int", false);
- ArrayList<Long> intDateTest = (ArrayList<Long>)calculateStat(intDateTestStart, "count");
- assertEquals(responseStr,intDate,intDateTest);
-
- //Int String
- Collection<Long> intString = getValueList(response, "countn", "fieldFacets", "string_sd", "int", false);
- ArrayList<Long> intStringTest = (ArrayList<Long>)calculateStat(intStringTestStart, "count");
- assertEquals(responseStr,intString,intStringTest);
-
- //Long Date
- Collection<Long> longDate = getValueList(response, "countn", "fieldFacets", "date_dtd", "long", false);
- ArrayList<Long> longDateTest = (ArrayList<Long>)calculateStat(longDateTestStart, "count");
- assertEquals(responseStr,longDate,longDateTest);
-
- //Long String
- Collection<Long> longString = getValueList(response, "countn", "fieldFacets", "string_sd", "long", false);
- ArrayList<Long> longStringTest = (ArrayList<Long>)calculateStat(longStringTestStart, "count");
- assertEquals(responseStr,longString,longStringTest);
-
- //Float Date
- Collection<Long> floatDate = getValueList(response, "countn", "fieldFacets", "date_dtd", "float", false);
- ArrayList<Long> floatDateTest = (ArrayList<Long>)calculateStat(floatDateTestStart, "count");
- assertEquals(responseStr,floatDate,floatDateTest);
-
- //Float String
- Collection<Long> floatString = getValueList(response, "countn", "fieldFacets", "string_sd", "float", false);
- ArrayList<Long> floatStringTest = (ArrayList<Long>)calculateStat(floatStringTestStart, "count");
- assertEquals(responseStr,floatString,floatStringTest);
-
- //Double Date
- Collection<Long> doubleDate = getValueList(response, "countn", "fieldFacets", "date_dtd", "double", false);
- ArrayList<Long> doubleDateTest = (ArrayList<Long>)calculateStat(doubleDateTestStart, "count");
- assertEquals(responseStr,doubleDate,doubleDateTest);
-
- //Double String
- Collection<Long> doubleString = getValueList(response, "countn", "fieldFacets", "string_sd", "double", false);
- ArrayList<Long> doubleStringTest = (ArrayList<Long>)calculateStat(doubleStringTestStart, "count");
- assertEquals(responseStr,doubleString,doubleStringTest);
-
- //Date Int
- Collection<Long> dateInt = getValueList(response, "count", "fieldFacets", "int_id", "date", false);
- ArrayList<Long> dateIntTest = (ArrayList<Long>)calculateStat(dateIntTestStart, "count");
- assertEquals(responseStr,dateIntTest,dateInt);
-
- //Date Long
- Collection<Long> dateLong = getValueList(response, "count", "fieldFacets", "long_ld", "date", false);
- ArrayList<Long> dateLongTest = (ArrayList<Long>)calculateStat(dateLongTestStart, "count");
- assertEquals(responseStr,dateLong,dateLongTest);
-
- //String Int
- Collection<Long> stringInt = getValueList(response, "count", "fieldFacets", "int_id", "str", false);
- ArrayList<Long> stringIntTest = (ArrayList<Long>)calculateStat(stringIntTestStart, "count");
- assertEquals(responseStr,stringInt,stringIntTest);
-
- //String Long
- Collection<Long> stringLong = getValueList(response, "count", "fieldFacets", "long_ld", "str", false);
- ArrayList<Long> stringLongTest = (ArrayList<Long>)calculateStat(stringLongTestStart, "count");
- assertEquals(responseStr,stringLong,stringLongTest);
- }
-
- @Test
- public void missingTest() throws Exception {
- String[] params = new String[] {
- "o.missingn.s.int", "missing(int_id)",
- "o.missingn.s.long", "missing(long_ld)",
- "o.missingn.s.float", "missing(float_fd)",
- "o.missingn.s.double", "missing(double_dd)",
- "o.missingn.ff", "string_sd",
- "o.missingn.ff", "date_dtd",
-
- "o.missing.s.str", "missing(string_sd)",
- "o.missing.s.date", "missing(date_dtd)",
- "o.missing.ff", "int_id",
- "o.missing.ff", "long_ld"
- };
- NamedList<Object> response = queryCloudAnalytics(params);
- String responseStr = response.toString();
-
- //Int Date
- Collection<Long> intDate = getValueList(response, "missingn", "fieldFacets", "date_dtd", "int", false);
- setLatestType("int");
- assertEquals(responseStr,intDateTestMissing,intDate);
-
- //Int String
- Collection<Long> intString = getValueList(response, "missingn", "fieldFacets", "string_sd", "int", false);
- assertEquals(responseStr,intStringTestMissing,intString);
-
- //Long Date
- Collection<Long> longDate = getValueList(response, "missingn", "fieldFacets", "date_dtd", "long", false);
- setLatestType("long");
- assertEquals(responseStr,longDateTestMissing,longDate);
-
- //Long String
- Collection<Long> longString = getValueList(response, "missingn", "fieldFacets", "string_sd", "long", false);
- assertEquals(responseStr,longStringTestMissing,longString);
-
- //Float Date
- Collection<Long> floatDate = getValueList(response, "missingn", "fieldFacets", "date_dtd", "float", false);
- setLatestType("float");
- assertEquals(responseStr,floatDateTestMissing,floatDate);
-
- //Float String
- Collection<Long> floatString = getValueList(response, "missingn", "fieldFacets", "string_sd", "float", false);
- assertEquals(responseStr,floatStringTestMissing,floatString);
-
- //Double Date
- Collection<Long> doubleDate = getValueList(response, "missingn", "fieldFacets", "date_dtd", "double", false);
- setLatestType("double");
- assertEquals(responseStr,doubleDateTestMissing,doubleDate);
-
- //Double String
- Collection<Long> doubleString = getValueList(response, "missingn", "fieldFacets", "string_sd", "double", false);
- assertEquals(responseStr,doubleStringTestMissing,doubleString);
-
- //Date Int
- Collection<Long> dateInt = getValueList(response, "missing", "fieldFacets", "int_id", "date", false);
- setLatestType("date");
- assertEquals(responseStr,dateIntTestMissing,dateInt);
-
- //Date Long
- Collection<Long> dateLong = getValueList(response, "missing", "fieldFacets", "long_ld", "date", false);
- assertEquals(responseStr,dateLongTestMissing,dateLong);
-
- //String Int
- Collection<Long> stringInt = getValueList(response, "missing", "fieldFacets", "int_id", "str", false);
- setLatestType("string");
- assertEquals(responseStr,stringIntTestMissing,stringInt);
-
- //String Long
- Collection<Long> stringLong = getValueList(response, "missing", "fieldFacets", "long_ld", "str", false);
- assertEquals(responseStr,stringLongTestMissing,stringLong);
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void multiValueTest() throws Exception {
- String[] params = new String[] {
- "o.multivalued.s.mean", "mean(int_id)",
- "o.multivalued.ff", "long_ldm",
- "o.multivalued.ff", "string_sdm",
- "o.multivalued.ff", "date_dtdm"
- };
- NamedList<Object> response = queryCloudAnalytics(params);
- String responseStr = response.toString();
-
- //Long
- Collection<Double> lon = getValueList(response, "multivalued", "fieldFacets", "long_ldm", "mean", false);
- ArrayList<Double> longTest = calculateNumberStat(multiLongTestStart, "mean");
- assertEquals(responseStr,lon,longTest);
- //Date
- Collection<Double> date = getValueList(response, "multivalued", "fieldFacets", "date_dtdm", "mean", false);
- ArrayList<Double> dateTest = calculateNumberStat(multiDateTestStart, "mean");
- assertEquals(responseStr,date,dateTest);
- //String
- Collection<Double> string = getValueList(response, "multivalued", "fieldFacets", "string_sdm", "mean", false);
- ArrayList<Double> stringTest = calculateNumberStat(multiStringTestStart, "mean");
- assertEquals(responseStr,string,stringTest);
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void missingFacetTest() throws Exception {
- String[] params = new String[] {
- "o.missingf.s.mean", "mean(int_id)",
- "o.missingf.ff", "date_dtd",
- "o.missingf.ff", "string_sd",
- "o.missingf.ff.string_sd.sm", "true",
- "o.missingf.ff", "date_dtdm",
- "o.missingf.ff.date_dtdm.sm", "true"
- };
- NamedList<Object> response = queryCloudAnalytics(params);
- String responseStr = response.toString();
-
- //int MultiDate
- assertTrue(responseStr, responseContainsFacetValue(response, "missingf", "fieldFacets", "date_dtdm", "(MISSING)"));
- ArrayList<Double> string = getValueList(response, "missingf", "fieldFacets", "date_dtdm", "mean", false);
- ArrayList<Double> stringTest = calculateNumberStat(multiDateTestStart, "mean");
- assertEquals(responseStr, string,stringTest);
-
- //Int String
- assertTrue(responseStr, responseContainsFacetValue(response, "missingf", "fieldFacets", "string_sd", "(MISSING)"));
- assertTrue(responseStr, !responseContainsFacetValue(response, "missingf", "fieldFacets", "string_sd", "str0"));
- List<Double> intString = getValueList(response, "missingf", "fieldFacets", "string_sd", "mean", false);
- ArrayList<Double> intStringTest = calculateNumberStat(intStringTestStart, "mean");
- assertEquals(responseStr, intString,intStringTest);
-
- //Int Date
- Collection<Double> intDate = getValueList(response, "missingf", "fieldFacets", "date_dtd", "mean", false);
- ArrayList<ArrayList<Double>> intDateMissingTestStart = (ArrayList<ArrayList<Double>>) intDateTestStart.clone();
- ArrayList<Double> intDateTest = calculateNumberStat(intDateMissingTestStart, "mean");
- assertEquals(responseStr,intDate,intDateTest);
- }
-
- private void checkStddevs(NamedList<Object> response, ArrayList<Double> list1, ArrayList<Double> list2) {
- Collections.sort(list1);
- Collections.sort(list2);
- for (int i = 0; i<list2.size(); i++) {
- if ((Math.abs(list1.get(i)-list2.get(i))<.00000000001) == false) {
- Assert.assertEquals(response.toString(), list1.get(i), list2.get(i), 0.00000000001);
- }
- }
- }
-
- @SuppressWarnings({"unchecked", "rawtypes"})
- public static void assertEquals(String mes, Object actual, Object expected) {
- Collections.sort((List<Comparable>) actual);
- Collections.sort((List<Comparable>) expected);
- Assert.assertEquals(mes, actual, expected);
- }
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/FieldFacetExtrasCloudTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/FieldFacetExtrasCloudTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/FieldFacetExtrasCloudTest.java
deleted file mode 100644
index 427b50d..0000000
--- a/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/FieldFacetExtrasCloudTest.java
+++ /dev/null
@@ -1,253 +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.Collection;
-import java.util.Collections;
-import java.util.List;
-
-import org.apache.solr.client.solrj.request.UpdateRequest;
-import org.apache.solr.common.util.NamedList;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-public class FieldFacetExtrasCloudTest extends AbstractAnalyticsFacetCloudTest {
- public static final int INT = 21;
- public static final int LONG = 22;
- public static final int FLOAT = 23;
- public static final int DOUBLE = 24;
- public static final int DATE = 25;
- public static final int STRING = 26;
- public static final int NUM_LOOPS = 100;
-
- //INT
- static ArrayList<ArrayList<Integer>> intLongTestStart;
- static ArrayList<ArrayList<Integer>> intFloatTestStart;
- static ArrayList<ArrayList<Integer>> intDoubleTestStart;
- static ArrayList<ArrayList<Integer>> intStringTestStart;
-
- @BeforeClass
- public static void beforeClass() throws Exception {
- setupCluster();
-
- //INT
- intLongTestStart = new ArrayList<>();
- intFloatTestStart = new ArrayList<>();
- intDoubleTestStart = new ArrayList<>();
- intStringTestStart = new ArrayList<>();
-
- UpdateRequest req = new UpdateRequest();
-
- for (int j = 0; j < NUM_LOOPS; ++j) {
- int i = j%INT;
- long l = j%LONG;
- float f = j%FLOAT;
- double d = j%DOUBLE;
- int dt = j%DATE;
- int s = j%STRING;
-
- List<String> fields = new ArrayList<>();
- fields.add("id"); fields.add("1000"+j);
- fields.add("int_id"); fields.add("" + i);
- fields.add("long_ld"); fields.add("" + l);
- fields.add("float_fd"); fields.add("" + f);
- fields.add("double_dd"); fields.add("" + d);
- fields.add("date_dtd"); fields.add((1800+dt) + "-12-31T23:59:59.999Z");
- fields.add("string_sd"); fields.add("abc" + s);
- req.add(fields.toArray(new String[0]));
-
- //Long
- if (j-LONG<0) {
- ArrayList<Integer> list1 = new ArrayList<>();
- list1.add(i);
- intLongTestStart.add(list1);
- } else {
- intLongTestStart.get((int)l).add(i);
- }
- //String
- if (j-FLOAT<0) {
- ArrayList<Integer> list1 = new ArrayList<>();
- list1.add(i);
- intFloatTestStart.add(list1);
- } else {
- intFloatTestStart.get((int)f).add(i);
- }
- //String
- if (j-DOUBLE<0) {
- ArrayList<Integer> list1 = new ArrayList<>();
- list1.add(i);
- intDoubleTestStart.add(list1);
- } else {
- intDoubleTestStart.get((int)d).add(i);
- }
- //String
- if (j-STRING<0) {
- ArrayList<Integer> list1 = new ArrayList<>();
- list1.add(i);
- intStringTestStart.add(list1);
- } else {
- intStringTestStart.get(s).add(i);
- }
- }
-
- req.commit(cluster.getSolrClient(), COLLECTIONORALIAS);
- }
-
- @Test
- public void limitTest() throws Exception {
- String[] params = new String[] {
- "o.lr.s.mean", "mean(int_id)",
- "o.lr.s.median", "median(int_id)",
- "o.lr.s.count", "count(int_id)",
- "o.lr.s.percentile_20", "percentile(20,int_id)",
- "o.lr.ff.long_ld", "long_ld",
- "o.lr.ff.long_ld.ss", "mean",
- "o.lr.ff.long_ld.sd", "asc",
- "o.lr.ff.long_ld.limit", "5",
- "o.lr.ff.float_fd", "float_fd",
- "o.lr.ff.float_fd.ss", "median",
- "o.lr.ff.float_fd.sd", "desc",
- "o.lr.ff.float_fd.limit", "3",
- "o.lr.ff.double_dd", "double_dd",
- "o.lr.ff.double_dd.ss", "count",
- "o.lr.ff.double_dd.sd", "asc",
- "o.lr.ff.double_dd.limit", "7",
- "o.lr.ff.string_sd", "string_sd",
- "o.lr.ff.string_sd.ss", "percentile_20",
- "o.lr.ff.string_sd.sd", "desc",
- "o.lr.ff.string_sd.limit", "1"
- };
-
- NamedList<Object> response = queryCloudAnalytics(params);
- String responseStr = response.toString();
-
- Collection<Double> lon = getValueList(response, "lr", "fieldFacets", "long_ld", "mean", false);
- assertEquals(responseStr, lon.size(),5);
- Collection<Double> flo = getValueList(response, "lr", "fieldFacets", "float_fd", "median", false);
- assertEquals(responseStr, flo.size(),3);
- Collection<Long> doub = getValueList(response, "lr", "fieldFacets", "double_dd", "count", false);
- assertEquals(responseStr, doub.size(),7);
- Collection<Integer> string = getValueList(response, "lr", "fieldFacets", "string_sd", "percentile_20", false);
- assertEquals(responseStr, string.size(),1);
- }
-
- @Test
- public void offsetTest() throws Exception {
- String[] params = new String[] {
- "o.offAll.s.mean", "mean(int_id)",
- "o.offAll.ff", "long_ld",
- "o.offAll.ff.long_ld.ss", "mean",
- "o.offAll.ff.long_ld.sd", "asc",
- "o.offAll.ff.long_ld.limit", "7",
-
- "o.off0.s.mean", "mean(int_id)",
- "o.off0.ff", "long_ld",
- "o.off0.ff.long_ld.ss", "mean",
- "o.off0.ff.long_ld.sd", "asc",
- "o.off0.ff.long_ld.limit", "2",
- "o.off0.ff.long_ld.offset", "0",
-
- "o.off1.s.mean", "mean(int_id)",
- "o.off1.ff", "long_ld",
- "o.off1.ff.long_ld.ss", "mean",
- "o.off1.ff.long_ld.sd", "asc",
- "o.off1.ff.long_ld.limit", "2",
- "o.off1.ff.long_ld.offset", "2",
-
- "o.off2.s.mean", "mean(int_id)",
- "o.off2.ff", "long_ld",
- "o.off2.ff.long_ld.ss", "mean",
- "o.off2.ff.long_ld.sd", "asc",
- "o.off2.ff.long_ld.limit", "3",
- "o.off2.ff.long_ld.offset", "4"
- };
-
- NamedList<Object> response = queryCloudAnalytics(params);
- String responseStr = response.toString();
-
- Collection<Double> lon;
-
- List<Double> all = new ArrayList<>();
- lon = getValueList(response, "off0", "fieldFacets", "long_ld", "mean", false);
- assertEquals(responseStr, lon.size(),2);
- assertArrayEquals(new Double[]{ 1.5, 2.0 }, lon.toArray(new Double[0]));
- all.addAll(lon);
-
- lon = getValueList(response, "off1", "fieldFacets", "long_ld", "mean", false);
- assertEquals(responseStr, lon.size(),2);
- assertArrayEquals(new Double[]{ 3.0, 4.0 }, lon.toArray(new Double[0]));
- all.addAll(lon);
-
- lon = getValueList(response, "off2", "fieldFacets", "long_ld", "mean", false);
- assertEquals(responseStr, lon.size(),3);
- assertArrayEquals(new Double[]{ 5.0, 5.75, 6.0 }, lon.toArray(new Double[0]));
- all.addAll(lon);
-
- lon = getValueList(response, "offAll", "fieldFacets", "long_ld", "mean", false);
- assertEquals(responseStr, lon.size(),7);
- assertArrayEquals(all.toArray(new Double[0]), lon.toArray(new Double[0]));
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void sortTest() throws Exception {
- String[] params = new String[] {
- "o.sr.s.mean", "mean(int_id)",
- "o.sr.s.median", "median(int_id)",
- "o.sr.s.count", "count(int_id)",
- "o.sr.s.percentile_20", "percentile(20,int_id)",
- "o.sr.ff", "long_ld",
- "o.sr.ff.long_ld.ss", "mean",
- "o.sr.ff.long_ld.sd", "asc",
- "o.sr.ff", "float_fd",
- "o.sr.ff.float_fd.ss", "median",
- "o.sr.ff.float_fd.sd", "desc",
- "o.sr.ff", "double_dd",
- "o.sr.ff.double_dd.ss", "count",
- "o.sr.ff.double_dd.sd", "asc",
- "o.sr.ff", "string_sd",
- "o.sr.ff.string_sd.ss", "percentile_20",
- "o.sr.ff.string_sd.sd", "desc"
- };
-
- NamedList<Object> response = queryCloudAnalytics(params);
- String responseStr = response.toString();
-
- Collection<Double> lon = getValueList(response, "sr", "fieldFacets", "long_ld", "mean", false);
- ArrayList<Double> longTest = calculateNumberStat(intLongTestStart, "mean");
- Collections.sort(longTest);
- assertEquals(responseStr, longTest,lon);
-
- Collection<Double> flo = getValueList(response, "sr", "fieldFacets", "float_fd", "median", false);
- ArrayList<Double> floatTest = calculateNumberStat(intFloatTestStart, "median");
- Collections.sort(floatTest,Collections.reverseOrder());
- assertEquals(responseStr, floatTest,flo);
-
- Collection<Long> doub = getValueList(response, "sr", "fieldFacets", "double_dd", "count", false);
- ArrayList<Long> doubleTest = (ArrayList<Long>)calculateStat(intDoubleTestStart, "count");
- Collections.sort(doubleTest);
- assertEquals(responseStr, doubleTest,doub);
-
- Collection<Integer> string = getValueList(response, "sr", "fieldFacets", "string_sd", "percentile_20", false);
- ArrayList<Integer> stringTest = (ArrayList<Integer>)calculateStat(intStringTestStart, "perc_20");
- Collections.sort(stringTest,Collections.reverseOrder());
- assertEquals(responseStr, stringTest,string);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/FieldFacetExtrasTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/FieldFacetExtrasTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/FieldFacetExtrasTest.java
deleted file mode 100644
index a7e0012..0000000
--- a/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/FieldFacetExtrasTest.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.Collection;
-import java.util.Collections;
-import java.util.List;
-
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-public class FieldFacetExtrasTest extends AbstractAnalyticsFacetTest {
- static String fileName = "fieldFacetExtras.txt";
-
- public static final int INT = 21;
- public static final int LONG = 22;
- public static final int FLOAT = 23;
- public static final int DOUBLE = 24;
- public static final int DATE = 25;
- public static final int STRING = 26;
- public static final int NUM_LOOPS = 100;
-
- //INT
- static ArrayList<ArrayList<Integer>> intLongTestStart;
- static ArrayList<ArrayList<Integer>> intFloatTestStart;
- static ArrayList<ArrayList<Integer>> intDoubleTestStart;
- static ArrayList<ArrayList<Integer>> intStringTestStart;
-
- @BeforeClass
- public static void beforeClass() throws Exception {
- initCore("solrconfig-analytics.xml","schema-analytics.xml");
- h.update("<delete><query>*:*</query></delete>");
-
- //INT
- intLongTestStart = new ArrayList<>();
- intFloatTestStart = new ArrayList<>();
- intDoubleTestStart = new ArrayList<>();
- intStringTestStart = new ArrayList<>();
-
- for (int j = 0; j < NUM_LOOPS; ++j) {
- int i = j%INT;
- long l = j%LONG;
- float f = j%FLOAT;
- double d = j%DOUBLE;
- int dt = j%DATE;
- int s = j%STRING;
- assertU(adoc("id", "1000" + j, "int_id", "" + i, "long_ld", "" + l, "float_fd", "" + f,
- "double_dd", "" + d, "date_dtd", (1800+dt) + "-12-31T23:59:59.999Z", "string_sd", "abc" + s));
- //Long
- if (j-LONG<0) {
- ArrayList<Integer> list1 = new ArrayList<>();
- list1.add(i);
- intLongTestStart.add(list1);
- } else {
- intLongTestStart.get((int)l).add(i);
- }
- //String
- if (j-FLOAT<0) {
- ArrayList<Integer> list1 = new ArrayList<>();
- list1.add(i);
- intFloatTestStart.add(list1);
- } else {
- intFloatTestStart.get((int)f).add(i);
- }
- //String
- if (j-DOUBLE<0) {
- ArrayList<Integer> list1 = new ArrayList<>();
- list1.add(i);
- intDoubleTestStart.add(list1);
- } else {
- intDoubleTestStart.get((int)d).add(i);
- }
- //String
- if (j-STRING<0) {
- ArrayList<Integer> list1 = new ArrayList<>();
- list1.add(i);
- intStringTestStart.add(list1);
- } else {
- intStringTestStart.get(s).add(i);
- }
-
- if (usually()) {
- assertU(commit()); // to have several segments
- }
- }
-
- assertU(commit());
- setResponse(h.query(request(fileToStringArr(FieldFacetExtrasTest.class, fileName))));
- }
-
- @Test
- public void limitTest() throws Exception {
-
- Collection<Double> lon = getDoubleList("lr", "fieldFacets", "long_ld", "double", "mean");
- assertEquals(getRawResponse(), lon.size(),5);
- Collection<Double> flo = getDoubleList("lr", "fieldFacets", "float_fd", "double", "median");
- assertEquals(getRawResponse(), flo.size(),3);
- Collection<Long> doub = getLongList("lr", "fieldFacets", "double_dd", "long", "count");
- assertEquals(getRawResponse(), doub.size(),7);
- Collection<Integer> string = getIntegerList("lr", "fieldFacets", "string_sd", "int", "percentile_20");
- assertEquals(getRawResponse(), string.size(),1);
- }
-
- @Test
- public void offsetTest() throws Exception {
-
- Collection<Double> lon;
-
- List<Double> all = new ArrayList<>();
- lon = getDoubleList("off0", "fieldFacets", "long_ld", "double", "mean");
- assertEquals(getRawResponse(), lon.size(),2);
- assertArrayEquals(new Double[]{ 1.5, 2.0 }, lon.toArray(new Double[0]));
- all.addAll(lon);
-
- lon = getDoubleList("off1", "fieldFacets", "long_ld", "double", "mean");
- assertEquals(getRawResponse(), lon.size(),2);
- assertArrayEquals(new Double[]{ 3.0, 4.0 }, lon.toArray(new Double[0]));
- all.addAll(lon);
-
- lon = getDoubleList("off2", "fieldFacets", "long_ld", "double", "mean");
- assertEquals(getRawResponse(), lon.size(),3);
- assertArrayEquals(new Double[]{ 5.0, 5.75, 6.0 }, lon.toArray(new Double[0]));
- all.addAll(lon);
-
- lon = getDoubleList("offAll", "fieldFacets", "long_ld", "double", "mean");
- assertEquals(getRawResponse(), lon.size(),7);
- assertArrayEquals(all.toArray(new Double[0]), lon.toArray(new Double[0]));
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void sortTest() throws Exception {
- Collection<Double> lon = getDoubleList("sr", "fieldFacets", "long_ld", "double", "mean");
- ArrayList<Double> longTest = calculateNumberStat(intLongTestStart, "mean");
- Collections.sort(longTest);
- assertEquals(getRawResponse(), longTest,lon);
-
- Collection<Double> flo = getDoubleList("sr", "fieldFacets", "float_fd", "double", "median");
- ArrayList<Double> floatTest = calculateNumberStat(intFloatTestStart, "median");
- Collections.sort(floatTest,Collections.reverseOrder());
- assertEquals(getRawResponse(), floatTest,flo);
-
- Collection<Long> doub = getLongList("sr", "fieldFacets", "double_dd", "long", "count");
- ArrayList<Long> doubleTest = (ArrayList<Long>)calculateStat(intDoubleTestStart, "count");
- Collections.sort(doubleTest);
- assertEquals(getRawResponse(), doubleTest,doub);
-
- Collection<Integer> string = getIntegerList("sr", "fieldFacets", "string_sd", "int", "percentile_20");
- ArrayList<Integer> stringTest = (ArrayList<Integer>)calculateStat(intStringTestStart, "perc_20");
- Collections.sort(stringTest,Collections.reverseOrder());
- assertEquals(getRawResponse(), stringTest,string);
- }
-
-}
[06/20] lucene-solr:master: SOLR-11145,
SOLR-11146: Added comprehensive unit tests for Analytics Component
2.0 as well as analytics bug fixes.
Posted by dp...@apache.org.
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/StringCastFunctionTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/StringCastFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/StringCastFunctionTest.java
new file mode 100644
index 0000000..79ef86a
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/StringCastFunctionTest.java
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.function.mapping;
+
+import java.util.Arrays;
+import java.util.Iterator;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.analytics.value.AnalyticsValueStream;
+import org.apache.solr.analytics.value.StringValue;
+import org.apache.solr.analytics.value.StringValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestBooleanValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestIntValue;
+import org.junit.Test;
+
+public class StringCastFunctionTest extends SolrTestCaseJ4 {
+
+ @Test
+ public void singleValueParameterTest() {
+ TestIntValue val = new TestIntValue();
+
+ AnalyticsValueStream uncasted = StringCastFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof StringValue);
+ StringValue func = (StringValue) uncasted;
+
+ // Value doesn't exist
+ val.setExists(false);
+ func.getObject();
+ assertFalse(func.exists());
+
+ // Value exists
+ val.setValue(21).setExists(true);
+ assertEquals("21", func.getObject());
+ assertTrue(func.exists());
+
+ val.setValue(-100).setExists(true);
+ assertEquals("-100", func.getObject());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void multiValueParameterTest() {
+ TestBooleanValueStream val = new TestBooleanValueStream();
+
+ AnalyticsValueStream uncasted = StringCastFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof StringValueStream);
+ StringValueStream func = (StringValueStream) uncasted;
+
+ // No values
+ val.setValues();
+ func.streamStrings( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // One value
+ val.setValues(true);
+ Iterator<String> values1 = Arrays.asList("true").iterator();
+ func.streamObjects( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ // Multiple values
+ val.setValues(true, true, false, false);
+ Iterator<String> values2 = Arrays.asList("true", "true", "false", "false").iterator();
+ func.streamObjects( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value);
+ });
+ assertFalse(values2.hasNext());
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/SubtractFunctionTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/SubtractFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/SubtractFunctionTest.java
new file mode 100644
index 0000000..1095bba
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/SubtractFunctionTest.java
@@ -0,0 +1,128 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.function.mapping;
+
+import java.util.Arrays;
+import java.util.Iterator;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.analytics.value.AnalyticsValueStream;
+import org.apache.solr.analytics.value.DoubleValue;
+import org.apache.solr.analytics.value.DoubleValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestIntValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestLongValueStream;
+import org.junit.Test;
+
+public class SubtractFunctionTest extends SolrTestCaseJ4 {
+ @Test
+ public void twoSingleValueParametersTest() {
+ TestIntValue minuend = new TestIntValue();
+ TestFloatValue subtrahend = new TestFloatValue();
+
+ AnalyticsValueStream uncasted = SubtractFunction.creatorFunction.apply(new AnalyticsValueStream[] {minuend, subtrahend});
+ assertTrue(uncasted instanceof DoubleValue);
+ DoubleValue func = (DoubleValue) uncasted;
+
+ // Neither exists
+ minuend.setExists(false);
+ subtrahend.setExists(false);
+ func.getDouble();
+ assertFalse(func.exists());
+
+ // One exists
+ minuend.setValue(30).setExists(true);
+ subtrahend.setExists(false);
+ func.getDouble();
+ assertFalse(func.exists());
+
+ // Both exist
+ minuend.setValue(60).setExists(true);
+ subtrahend.setValue(23.56F).setExists(true);
+ assertEquals(36.44, func.getDouble(), 0.00001);
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void oneMultiOneSingleValueParameterTest() {
+ TestLongValueStream minuend = new TestLongValueStream();
+ TestDoubleValue subtrahend = new TestDoubleValue();
+
+ AnalyticsValueStream uncasted = SubtractFunction.creatorFunction.apply(new AnalyticsValueStream[] {minuend, subtrahend});
+ assertTrue(uncasted instanceof DoubleValueStream);
+ DoubleValueStream func = (DoubleValueStream) uncasted;
+
+ // No values, One value
+ minuend.setValues();
+ subtrahend.setValue(21.56F).setExists(true);
+ func.streamDoubles( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple values, no value
+ minuend.setValues(4L, 10023L);
+ subtrahend.setExists(false);
+ func.streamDoubles( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple values, one value
+ minuend.setValues(20L, 5L, 234L);
+ subtrahend.setValue(44.56F).setExists(true);
+ Iterator<Double> values = Arrays.asList(-24.56, -39.56, 189.44).iterator();
+ func.streamDoubles( value -> {
+ assertTrue(values.hasNext());
+ assertEquals(values.next(), value, 0.00001);
+ });
+ assertFalse(values.hasNext());
+ }
+
+ @Test
+ public void oneSingleOneMultiValueParameterTest() {
+ TestDoubleValue minuend = new TestDoubleValue();
+ TestLongValueStream subtrahend = new TestLongValueStream();
+
+ AnalyticsValueStream uncasted = SubtractFunction.creatorFunction.apply(new AnalyticsValueStream[] {minuend, subtrahend});
+ assertTrue(uncasted instanceof DoubleValueStream);
+ DoubleValueStream func = (DoubleValueStream) uncasted;
+
+ // No values, One value
+ minuend.setValue(21.56F).setExists(true);
+ subtrahend.setValues();
+ func.streamDoubles( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple values, no value
+ minuend.setExists(false);
+ subtrahend.setValues(4L, 10023L);
+ func.streamDoubles( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple values, one value
+ minuend.setValue(44.56F).setExists(true);
+ subtrahend.setValues(20L, 5L, 234L);
+ Iterator<Double> values = Arrays.asList(24.56, 39.56, -189.44).iterator();
+ func.streamDoubles( value -> {
+ assertTrue(values.hasNext());
+ assertEquals(values.next(), value, 0.00001);
+ });
+ assertFalse(values.hasNext());
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/TopFunctionTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/TopFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/TopFunctionTest.java
new file mode 100644
index 0000000..419f883
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/TopFunctionTest.java
@@ -0,0 +1,406 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.function.mapping;
+
+import java.time.Instant;
+import java.time.format.DateTimeParseException;
+import java.util.Date;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.analytics.value.AnalyticsValueStream;
+import org.apache.solr.analytics.value.DateValue;
+import org.apache.solr.analytics.value.DoubleValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestDateValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestDateValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestIntValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestIntValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestLongValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestLongValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestStringValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestStringValueStream;
+import org.apache.solr.analytics.value.FloatValue;
+import org.apache.solr.analytics.value.IntValue;
+import org.apache.solr.analytics.value.LongValue;
+import org.apache.solr.analytics.value.StringValue;
+import org.junit.Test;
+
+public class TopFunctionTest extends SolrTestCaseJ4 {
+
+ @Test
+ public void multiValueIntTest() {
+ TestIntValueStream val = new TestIntValueStream();
+
+ AnalyticsValueStream uncasted = TopFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof IntValue);
+ IntValue func = (IntValue) uncasted;
+
+ // Neither exists
+ val.setValues();
+ func.getInt();
+ assertFalse(func.exists());
+
+ // One exists
+ val.setValues(30);
+ assertEquals(30, func.getInt());
+ assertTrue(func.exists());
+
+ // Both exist
+ val.setValues(30, 20, -10, 59);
+ assertEquals(59, func.getInt());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void multiValueLongTest() {
+ TestLongValueStream val = new TestLongValueStream();
+
+ AnalyticsValueStream uncasted = TopFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof LongValue);
+ LongValue func = (LongValue) uncasted;
+
+ // Neither exists
+ val.setValues();
+ func.getLong();
+ assertFalse(func.exists());
+
+ // One exists
+ val.setValues(30L);
+ assertEquals(30L, func.getLong());
+ assertTrue(func.exists());
+
+ // Both exist
+ val.setValues(30L, 20L, -10L, 59L);
+ assertEquals(59L, func.getLong());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void multiValueFloatTest() {
+ TestFloatValueStream val = new TestFloatValueStream();
+
+ AnalyticsValueStream uncasted = TopFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof FloatValue);
+ FloatValue func = (FloatValue) uncasted;
+
+ // Neither exists
+ val.setValues();
+ func.getFloat();
+ assertFalse(func.exists());
+
+ // One exists
+ val.setValues(30.0F);
+ assertEquals(30.0F, func.getFloat(), .000001);
+ assertTrue(func.exists());
+
+ // Both exist
+ val.setValues(30.5F, 20.01F, -10.49F, -10.48F);
+ assertEquals(30.5F, func.getFloat(), .000001);
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void multiValueDoubleTest() {
+ TestDoubleValueStream val = new TestDoubleValueStream();
+
+ AnalyticsValueStream uncasted = TopFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof DoubleValue);
+ DoubleValue func = (DoubleValue) uncasted;
+
+ // Neither exists
+ val.setValues();
+ func.getDouble();
+ assertFalse(func.exists());
+
+ // One exists
+ val.setValues(30.0);
+ assertEquals(30.0, func.getDouble(), .000001);
+ assertTrue(func.exists());
+
+ // Both exist
+ val.setValues(30.5, 20.01, -10.49, -10.48);
+ assertEquals(30.5, func.getDouble(), .000001);
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void multiValueDateTest() throws DateTimeParseException {
+ TestDateValueStream val = new TestDateValueStream();
+
+ AnalyticsValueStream uncasted = TopFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof DateValue);
+ DateValue func = (DateValue) uncasted;
+
+ // Neither exists
+ val.setValues();
+ func.getDate();
+ assertFalse(func.exists());
+
+ // One exists
+ val.setValues("1950-05-03T10:30:50Z");
+ assertEquals(Date.from(Instant.parse("1950-05-03T10:30:50Z")), func.getDate());
+ assertTrue(func.exists());
+
+ // Both exist
+ val.setValues("1950-05-03T10:30:50Z", "2200-01-01T10:00:50Z", "1800-12-31T11:30:50Z", "1930-05-020T10:45:50Z");
+ assertEquals(Date.from(Instant.parse("2200-01-01T10:00:50Z")), func.getDate());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void multiValueStringTest() {
+ TestStringValueStream val = new TestStringValueStream();
+
+ AnalyticsValueStream uncasted = TopFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof StringValue);
+ StringValue func = (StringValue) uncasted;
+
+ // Neither exists
+ val.setValues();
+ func.getString();
+ assertFalse(func.exists());
+
+ // One exists
+ val.setValues("abc");
+ assertEquals("abc", func.getString());
+ assertTrue(func.exists());
+
+ // Both exist
+ val.setValues("1abcdef", "abc", "def", "def1", "1abc");
+ assertEquals("def1", func.getString());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void multipleSingleValueIntTest() {
+ TestIntValue val1 = new TestIntValue();
+ TestIntValue val2 = new TestIntValue();
+ TestIntValue val3 = new TestIntValue();
+ TestIntValue val4 = new TestIntValue();
+
+ AnalyticsValueStream uncasted = TopFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2, val3, val4});
+ assertTrue(uncasted instanceof IntValue);
+ IntValue func = (IntValue) uncasted;
+
+ // None exist
+ val1.setExists(false);
+ val2.setExists(false);
+ val3.setExists(false);
+ val4.setExists(false);
+ func.getInt();
+ assertFalse(func.exists());
+
+ // Some exist
+ val1.setValue(1000).setExists(false);
+ val2.setValue(30).setExists(true);
+ val3.setValue(-1000).setExists(false);
+ val4.setValue(12).setExists(true);
+ assertEquals(30, func.getInt());
+ assertTrue(func.exists());
+
+ // All exist values, one value
+ val1.setValue(45).setExists(true);
+ val2.setValue(30).setExists(true);
+ val3.setValue(-2).setExists(true);
+ val4.setValue(12).setExists(true);
+ assertEquals(45, func.getInt());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void multipleSingleValueLongTest() {
+ TestLongValue val1 = new TestLongValue();
+ TestLongValue val2 = new TestLongValue();
+ TestLongValue val3 = new TestLongValue();
+ TestLongValue val4 = new TestLongValue();
+
+ AnalyticsValueStream uncasted = TopFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2, val3, val4});
+ assertTrue(uncasted instanceof LongValue);
+ LongValue func = (LongValue) uncasted;
+
+ // None exist
+ val1.setExists(false);
+ val2.setExists(false);
+ val3.setExists(false);
+ val4.setExists(false);
+ func.getLong();
+ assertFalse(func.exists());
+
+ // Some exist
+ val1.setValue(1000L).setExists(false);
+ val2.setValue(30L).setExists(true);
+ val3.setValue(-1000L).setExists(false);
+ val4.setValue(12L).setExists(true);
+ assertEquals(30L, func.getLong());
+ assertTrue(func.exists());
+
+ // All exist values, one value
+ val1.setValue(45L).setExists(true);
+ val2.setValue(30L).setExists(true);
+ val3.setValue(-2L).setExists(true);
+ val4.setValue(12L).setExists(true);
+ assertEquals(45L, func.getLong());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void multipleSingleValueFloatTest() {
+ TestFloatValue val1 = new TestFloatValue();
+ TestFloatValue val2 = new TestFloatValue();
+ TestFloatValue val3 = new TestFloatValue();
+ TestFloatValue val4 = new TestFloatValue();
+
+ AnalyticsValueStream uncasted = TopFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2, val3, val4});
+ assertTrue(uncasted instanceof FloatValue);
+ FloatValue func = (FloatValue) uncasted;
+
+ // None exist
+ val1.setExists(false);
+ val2.setExists(false);
+ val3.setExists(false);
+ val4.setExists(false);
+ func.getFloat();
+ assertFalse(func.exists());
+
+ // Some exist
+ val1.setValue(1000.1233F).setExists(false);
+ val2.setValue(30.34F).setExists(true);
+ val3.setValue(-1000.3241F).setExists(false);
+ val4.setValue(12.123F).setExists(true);
+ assertEquals(30.34F, func.getFloat(), .000001);
+ assertTrue(func.exists());
+
+ // All exist values, one value
+ val1.setValue(45.43F).setExists(true);
+ val2.setValue(30.231F).setExists(true);
+ val3.setValue(-2.33F).setExists(true);
+ val4.setValue(12.5F).setExists(true);
+ assertEquals(45.43F, func.getFloat(), .000001);
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void multipleSingleValueDoubleTest() {
+ TestDoubleValue val1 = new TestDoubleValue();
+ TestDoubleValue val2 = new TestDoubleValue();
+ TestDoubleValue val3 = new TestDoubleValue();
+ TestDoubleValue val4 = new TestDoubleValue();
+
+ AnalyticsValueStream uncasted = TopFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2, val3, val4});
+ assertTrue(uncasted instanceof DoubleValue);
+ DoubleValue func = (DoubleValue) uncasted;
+
+ // None exist
+ val1.setExists(false);
+ val2.setExists(false);
+ val3.setExists(false);
+ val4.setExists(false);
+ func.getDouble();
+ assertFalse(func.exists());
+
+ // Some exist
+ val1.setValue(1000.1233).setExists(false);
+ val2.setValue(30.34).setExists(true);
+ val3.setValue(-1000.3241).setExists(false);
+ val4.setValue(12.123).setExists(true);
+ assertEquals(30.34, func.getDouble(), .000001);
+ assertTrue(func.exists());
+
+ // All exist values, one value
+ val1.setValue(45.43).setExists(true);
+ val2.setValue(30.231).setExists(true);
+ val3.setValue(-2.33).setExists(true);
+ val4.setValue(12.5).setExists(true);
+ assertEquals(45.43, func.getDouble(), .000001);
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void multipleSingleValueDateTest() throws DateTimeParseException {
+ TestDateValue val1 = new TestDateValue();
+ TestDateValue val2 = new TestDateValue();
+ TestDateValue val3 = new TestDateValue();
+ TestDateValue val4 = new TestDateValue();
+
+ AnalyticsValueStream uncasted = TopFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2, val3, val4});
+ assertTrue(uncasted instanceof DateValue);
+ DateValue func = (DateValue) uncasted;
+
+ // None exist
+ val1.setExists(false);
+ val2.setExists(false);
+ val3.setExists(false);
+ val4.setExists(false);
+ func.getDate();
+ assertFalse(func.exists());
+
+ // Some exist
+ val1.setValue("9999-05-03T10:30:50Z").setExists(false);
+ val2.setValue("1950-05-03T10:30:50Z").setExists(true);
+ val3.setValue("0000-05-03T10:30:50Z").setExists(false);
+ val4.setValue("1850-05-03T10:30:50Z").setExists(true);
+ assertEquals(Date.from(Instant.parse("1950-05-03T10:30:50Z")), func.getDate());
+ assertTrue(func.exists());
+
+ // All exist values, one value
+ val1.setValue("2200-05-03T10:30:50Z").setExists(true);
+ val2.setValue("1950-05-03T10:30:50Z").setExists(true);
+ val3.setValue("1700-05-03T10:30:50Z").setExists(true);
+ val4.setValue("1850-05-03T10:30:50Z").setExists(true);
+ assertEquals(Date.from(Instant.parse("2200-05-03T10:30:50Z")), func.getDate());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void multipleStringValueDateTest() {
+ TestStringValue val1 = new TestStringValue();
+ TestStringValue val2 = new TestStringValue();
+ TestStringValue val3 = new TestStringValue();
+ TestStringValue val4 = new TestStringValue();
+
+ AnalyticsValueStream uncasted = TopFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2, val3, val4});
+ assertTrue(uncasted instanceof StringValue);
+ StringValue func = (StringValue) uncasted;
+
+ // None exist
+ val1.setExists(false);
+ val2.setExists(false);
+ val3.setExists(false);
+ val4.setExists(false);
+ func.getString();
+ assertFalse(func.exists());
+
+ // Some exist
+ val1.setValue("abc").setExists(true);
+ val2.setValue("1111").setExists(false);
+ val3.setValue("asdfads").setExists(true);
+ val4.setValue("zzzzzzzz").setExists(false);
+ assertEquals("asdfads", func.getString());
+ assertTrue(func.exists());
+
+ // All exist values, one value
+ val1.setValue("abc").setExists(true);
+ val2.setValue("abc1234").setExists(true);
+ val3.setValue("fdgsfg1").setExists(true);
+ val4.setValue("fdgsfg").setExists(true);
+ assertEquals("fdgsfg1", func.getString());
+ assertTrue(func.exists());
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/LegacyAbstractAnalyticsCloudTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/LegacyAbstractAnalyticsCloudTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/LegacyAbstractAnalyticsCloudTest.java
new file mode 100644
index 0000000..f34c667
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/LegacyAbstractAnalyticsCloudTest.java
@@ -0,0 +1,167 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.legacy;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+
+import org.apache.solr.analytics.util.AnalyticsResponseHeadings;
+import org.apache.solr.analytics.util.MedianCalculator;
+import org.apache.solr.analytics.util.OrdinalCalculator;
+import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.request.CollectionAdminRequest;
+import org.apache.solr.client.solrj.request.QueryRequest;
+import org.apache.solr.client.solrj.request.UpdateRequest;
+import org.apache.solr.client.solrj.response.QueryResponse;
+import org.apache.solr.cloud.AbstractDistribZkTestBase;
+import org.apache.solr.cloud.SolrCloudTestCase;
+import org.apache.solr.common.params.ModifiableSolrParams;
+import org.apache.solr.common.util.NamedList;
+import org.junit.BeforeClass;
+
+public class LegacyAbstractAnalyticsCloudTest extends SolrCloudTestCase {
+
+ protected static final String COLLECTIONORALIAS = "collection1";
+ protected static final int TIMEOUT = DEFAULT_TIMEOUT;
+ protected static final String id = "id";
+
+ @BeforeClass
+ public static void setupCollection() throws Exception {
+ configureCluster(4)
+ .addConfig("conf", configset("cloud-analytics"))
+ .configure();
+
+ CollectionAdminRequest.createCollection(COLLECTIONORALIAS, "conf", 2, 1).process(cluster.getSolrClient());
+ AbstractDistribZkTestBase.waitForRecoveriesToFinish(COLLECTIONORALIAS, cluster.getSolrClient().getZkStateReader(),
+ false, true, TIMEOUT);
+ cleanIndex();
+ }
+
+ public static void cleanIndex() throws Exception {
+ new UpdateRequest()
+ .deleteByQuery("*:*")
+ .commit(cluster.getSolrClient(), COLLECTIONORALIAS);
+ }
+
+ protected static final String[] BASEPARMS = new String[]{ "q", "*:*", "indent", "true", "olap", "true", "rows", "0" };
+
+ public static enum VAL_TYPE {
+ INTEGER("int"),
+ LONG("long"),
+ FLOAT("float"),
+ DOUBLE("double"),
+ STRING("str"),
+ DATE("date");
+
+ private VAL_TYPE (final String text) {
+ this.text = text;
+ }
+
+ private final String text;
+
+ @Override
+ public String toString() {
+ return text;
+ }
+ }
+
+ protected NamedList<Object> queryLegacyCloudAnalytics(String[] testParams) throws SolrServerException, IOException, InterruptedException {
+ ModifiableSolrParams params = new ModifiableSolrParams();
+ params.set("q", "*:*");
+ params.set("indent", "true");
+ params.set("olap", "true");
+ params.set("rows", "0");
+ for (int i = 0; i + 1 < testParams.length;) {
+ params.add(testParams[i++], testParams[i++]);
+ }
+ cluster.waitForAllNodes(10000);
+ QueryRequest qreq = new QueryRequest(params);
+ QueryResponse resp = qreq.process(cluster.getSolrClient(), COLLECTIONORALIAS);
+ return resp.getResponse();
+ }
+
+ @SuppressWarnings("unchecked")
+ protected <T> T getValue(NamedList<Object> response, String infoName, String exprName) {
+ return (T)response.findRecursive(AnalyticsResponseHeadings.COMPLETED_OLD_HEADER,
+ infoName,
+ exprName);
+ }
+
+ public <T extends Number & Comparable<T>> Double calculateNumberStat(ArrayList<T> list, String stat) {
+ Double result;
+ if (stat.equals("median")) {
+ result = MedianCalculator.getMedian(list);
+ } else if (stat.equals("mean")) {
+ double d = 0;
+ for (T element : list) {
+ d += element.doubleValue();
+ }
+ result = Double.valueOf(d/list.size());
+ } else if (stat.equals("sum")) {
+ double d = 0;
+ for (T element : list) {
+ d += element.doubleValue();
+ }
+ result = Double.valueOf(d);
+ } else if (stat.equals("sumOfSquares")) {
+ double d = 0;
+ for (T element : list) {
+ d += element.doubleValue()*element.doubleValue();
+ }
+ result = Double.valueOf(d);
+ } else if (stat.equals("stddev")) {
+ double sum = 0;
+ double sumSquares = 0;
+ for (T element : list) {
+ sum += element.doubleValue();
+ sumSquares += element.doubleValue()*element.doubleValue();
+ }
+ result = Math.sqrt(sumSquares/list.size()-sum*sum/(list.size()*list.size()));
+ } else {
+ throw new IllegalArgumentException();
+ }
+ return result;
+ }
+
+ public <T extends Comparable<T>> Object calculateStat(ArrayList<T> list, String stat) {
+ Object result;
+ if (stat.contains("perc_")) {
+ ArrayList<Integer> percs = new ArrayList<>(1);
+ int ord = (int) Math.ceil(Double.parseDouble(stat.substring(5))/100 * list.size()) - 1;
+ percs.add(ord);
+ OrdinalCalculator.putOrdinalsInPosition(list, percs);
+ result = list.get(percs.get(0));
+ } else if (stat.equals("count")) {
+ result = Long.valueOf(list.size());
+ } else if (stat.equals("unique")) {
+ HashSet<T> set = new HashSet<>();
+ set.addAll(list);
+ result = Long.valueOf((long)set.size());
+ } else if (stat.equals("max")) {
+ Collections.sort(list);
+ result = list.get(list.size()-1);
+ } else if (stat.equals("min")) {
+ Collections.sort(list);
+ result = list.get(0);
+ } else {
+ result = null;
+ }
+ return result;
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/LegacyAbstractAnalyticsTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/LegacyAbstractAnalyticsTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/LegacyAbstractAnalyticsTest.java
new file mode 100644
index 0000000..3488f63
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/LegacyAbstractAnalyticsTest.java
@@ -0,0 +1,234 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.legacy;
+
+import java.io.ByteArrayInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Scanner;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpressionException;
+import javax.xml.xpath.XPathFactory;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.lucene.util.IOUtils;
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.analytics.util.AnalyticsResponseHeadings;
+import org.apache.solr.analytics.util.MedianCalculator;
+import org.apache.solr.analytics.util.OrdinalCalculator;
+import org.apache.solr.request.SolrQueryRequest;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.w3c.dom.Document;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+import com.google.common.collect.ObjectArrays;
+
+public class LegacyAbstractAnalyticsTest extends SolrTestCaseJ4 {
+
+ protected static final String[] BASEPARMS = new String[]{ "q", "*:*", "indent", "true", "olap", "true", "rows", "0" };
+ protected static final HashMap<String,Object> defaults = new HashMap<>();
+
+ public static enum VAL_TYPE {
+ INTEGER("int"),
+ LONG("long"),
+ FLOAT("float"),
+ DOUBLE("double"),
+ STRING("str"),
+ DATE("date");
+
+ private VAL_TYPE (final String text) {
+ this.text = text;
+ }
+
+ private final String text;
+
+ @Override
+ public String toString() {
+ return text;
+ }
+ }
+
+ static private Document doc;
+ static private XPathFactory xPathFact;
+
+ static private String rawResponse;
+
+ @BeforeClass
+ public static void beforeClassAbstractAnalysis() {
+ xPathFact = XPathFactory.newInstance();
+ }
+
+ @AfterClass
+ public static void afterClassAbstractAnalysis() {
+ xPathFact = null;
+ doc = null;
+ rawResponse = null;
+ defaults.clear();
+ }
+
+ public static void setResponse(String response) throws ParserConfigurationException, IOException, SAXException {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ factory.setNamespaceAware(true); // never forget this!
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ doc = builder.parse(new InputSource(new ByteArrayInputStream(response.getBytes(StandardCharsets.UTF_8))));
+ rawResponse = response;
+ }
+
+ protected String getRawResponse() {
+ return rawResponse;
+ }
+
+ public Object getStatResult(String section, String name, VAL_TYPE type) throws XPathExpressionException {
+
+ // Construct the XPath expression. The form better not change or all these will fail.
+ StringBuilder sb = new StringBuilder("/response/lst[@name='"+AnalyticsResponseHeadings.COMPLETED_OLD_HEADER+"']/lst[@name='").append(section).append("']");
+
+ // This is a little fragile in that it demands the elements have the same name as type, i.e. when looking for a
+ // VAL_TYPE.DOUBLE, the element in question is <double name="blah">47.0</double>.
+ sb.append("/").append(type.toString()).append("[@name='").append(name).append("']");
+ String val = xPathFact.newXPath().compile(sb.toString()).evaluate(doc, XPathConstants.STRING).toString();
+ try {
+ switch (type) {
+ case INTEGER: return Integer.parseInt(val);
+ case DOUBLE: return Double.parseDouble(val);
+ case FLOAT: return Float.parseFloat(val);
+ case LONG: return Long.parseLong(val);
+ case STRING: assertTrue(rawResponse, val != null && val.length() > 0 ); return val;
+ case DATE: assertTrue(rawResponse, val != null && val.length() > 0 ); return val;
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail("Caught exception in getStatResult, xPath = " + sb.toString() + " \nraw data: " + rawResponse);
+ }
+ fail("Unknown type used in getStatResult");
+ return null; // Really can't get here, but the compiler thinks we can!
+ }
+
+
+ public <T extends Number & Comparable<T>> Double calculateNumberStat(ArrayList<T> list, String stat) {
+ Double result;
+ if (stat.equals("median")) {
+ result = MedianCalculator.getMedian(list);
+ } else if (stat.equals("mean")) {
+ double d = 0;
+ for (T element : list) {
+ d += element.doubleValue();
+ }
+ result = Double.valueOf(d/list.size());
+ } else if (stat.equals("sum")) {
+ double d = 0;
+ for (T element : list) {
+ d += element.doubleValue();
+ }
+ result = Double.valueOf(d);
+ } else if (stat.equals("sumOfSquares")) {
+ double d = 0;
+ for (T element : list) {
+ d += element.doubleValue()*element.doubleValue();
+ }
+ result = Double.valueOf(d);
+ } else if (stat.equals("stddev")) {
+ double sum = 0;
+ double sumSquares = 0;
+ for (T element : list) {
+ sum += element.doubleValue();
+ sumSquares += element.doubleValue()*element.doubleValue();
+ }
+ result = Math.sqrt(sumSquares/list.size()-sum*sum/(list.size()*list.size()));
+ } else {
+ throw new IllegalArgumentException();
+ }
+ return result;
+ }
+
+ public <T extends Comparable<T>> Object calculateStat(ArrayList<T> list, String stat) {
+ Object result;
+ if (stat.contains("perc_")) {
+ ArrayList<Integer> percs = new ArrayList<>(1);
+ int ord = (int) Math.ceil(Double.parseDouble(stat.substring(5))/100 * list.size()) - 1;
+ percs.add(ord);
+ OrdinalCalculator.putOrdinalsInPosition(list, percs);
+ result = list.get(percs.get(0));
+ } else if (stat.equals("count")) {
+ result = Long.valueOf(list.size());
+ } else if (stat.equals("unique")) {
+ HashSet<T> set = new HashSet<>();
+ set.addAll(list);
+ result = Long.valueOf((long)set.size());
+ } else if (stat.equals("max")) {
+ Collections.sort(list);
+ result = list.get(list.size()-1);
+ } else if (stat.equals("min")) {
+ Collections.sort(list);
+ result = list.get(0);
+ } else {
+ result = null;
+ }
+ return result;
+ }
+
+ @SuppressWarnings("unchecked")
+ public <T extends Comparable<T>> Long calculateMissing(ArrayList<T> list, String type) {
+ T def = (T)defaults.get(type);
+ long miss = 0;
+ for (T element : list) {
+ if (element.compareTo(def)==0) {
+ miss++;
+ }
+ }
+ return Long.valueOf(miss);
+ }
+
+ public static SolrQueryRequest request(String...args){
+ return SolrTestCaseJ4.req( ObjectArrays.concat(BASEPARMS, args,String.class) );
+ }
+
+ public static String[] fileToStringArr(Class<?> clazz, String fileName) throws FileNotFoundException {
+ InputStream in = clazz.getResourceAsStream("/solr/analytics/legacy/" + fileName);
+ if (in == null) throw new FileNotFoundException("Resource not found: " + fileName);
+ Scanner file = new Scanner(in, "UTF-8");
+ try {
+ ArrayList<String> strList = new ArrayList<>();
+ while (file.hasNextLine()) {
+ String line = file.nextLine();
+ line = line.trim();
+ if( StringUtils.isBlank(line) || line.startsWith("#")){
+ continue;
+ }
+ String[] param = line.split("=");
+ strList.add(param[0]);
+ strList.add(param[1]);
+ }
+ return strList.toArray(new String[0]);
+ } finally {
+ IOUtils.closeWhileHandlingException(file, in);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/LegacyNoFacetCloudTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/LegacyNoFacetCloudTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/LegacyNoFacetCloudTest.java
new file mode 100644
index 0000000..7489f3f
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/LegacyNoFacetCloudTest.java
@@ -0,0 +1,551 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.legacy;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.solr.client.solrj.request.UpdateRequest;
+import org.apache.solr.common.util.NamedList;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class LegacyNoFacetCloudTest extends LegacyAbstractAnalyticsCloudTest {
+ static public final int INT = 71;
+ static public final int LONG = 36;
+ static public final int FLOAT = 93;
+ static public final int DOUBLE = 49;
+ static public final int DATE = 12;
+ static public final int STRING = 28;
+ static public final int NUM_LOOPS = 100;
+
+ //INT
+ static ArrayList<Integer> intTestStart;
+ static long intMissing = 0;
+
+ //LONG
+ static ArrayList<Long> longTestStart;
+ static long longMissing = 0;
+
+ //FLOAT
+ static ArrayList<Float> floatTestStart;
+ static long floatMissing = 0;
+
+ //DOUBLE
+ static ArrayList<Double> doubleTestStart;
+ static long doubleMissing = 0;
+
+ //DATE
+ static ArrayList<String> dateTestStart;
+ static long dateMissing = 0;
+
+ //STR
+ static ArrayList<String> stringTestStart;
+ static long stringMissing = 0;
+
+ @BeforeClass
+ public static void populate() throws Exception {
+ cleanIndex();
+
+ intTestStart = new ArrayList<>();
+ longTestStart = new ArrayList<>();
+ floatTestStart = new ArrayList<>();
+ doubleTestStart = new ArrayList<>();
+ dateTestStart = new ArrayList<>();
+ stringTestStart = new ArrayList<>();
+
+ UpdateRequest req = new UpdateRequest();
+ for (int j = 0; j < NUM_LOOPS; ++j) {
+ int i = j%INT;
+ long l = j%LONG;
+ float f = j%FLOAT;
+ double d = j%DOUBLE;
+ String dt = (1800+j%DATE) + "-12-31T23:59:59Z";
+ String s = "str" + (j%STRING);
+ List<String> fields = new ArrayList<>();
+ fields.add("id"); fields.add("1000"+j);
+
+ if( i != 0 ){
+ fields.add("int_id"); fields.add("" + i);
+ intTestStart.add(i);
+ } else intMissing++;
+
+ if( l != 0l ){
+ fields.add("long_ld"); fields.add("" + l);
+ longTestStart.add(l);
+ } else longMissing++;
+
+ if( f != 0.0f ){
+ fields.add("float_fd"); fields.add("" + f);
+ floatTestStart.add(f);
+ } else floatMissing++;
+
+ if( d != 0.0d ){
+ fields.add("double_dd"); fields.add("" + d);
+ doubleTestStart.add(d);
+ } else doubleMissing++;
+
+ if( (j%DATE) != 0 ){
+ fields.add("date_dtd"); fields.add(dt);
+ dateTestStart.add(dt);
+ } else dateMissing++;
+
+ if( (j%STRING) != 0 ){
+ fields.add("string_sd"); fields.add(s);
+ stringTestStart.add(s);
+ } else stringMissing++;
+
+ req.add(fields.toArray(new String[0]));
+ }
+ req.commit(cluster.getSolrClient(), COLLECTIONORALIAS);
+ }
+
+ @Test
+ public void sumTest() throws Exception {
+ String[] params = new String[] {
+ "o.sr.s.int_id", "sum(int_id)",
+ "o.sr.s.long_ld", "sum(long_ld)",
+ "o.sr.s.float_fd", "sum(float_fd)",
+ "o.sr.s.double_dd", "sum(double_dd)"
+ };
+ NamedList<Object> response = queryLegacyCloudAnalytics(params);
+ String responseStr = response.toString();
+
+ //Int
+ Double intResult = getValue(response, "sr", "int_id");
+ Double intTest = (Double)calculateNumberStat(intTestStart, "sum");
+ assertEquals(responseStr, intResult,intTest);
+
+ //Long
+ Double longResult = getValue(response, "sr", "long_ld");
+ Double longTest = (Double)calculateNumberStat(longTestStart, "sum");
+ assertEquals(responseStr, longResult,longTest);
+
+ //Float
+ Double floatResult = getValue(response, "sr", "float_fd");
+ Double floatTest = (Double)calculateNumberStat(floatTestStart, "sum");
+ assertEquals(responseStr, floatResult,floatTest);
+
+ //Double
+ Double doubleResult = getValue(response, "sr", "double_dd");
+ Double doubleTest = (Double) calculateNumberStat(doubleTestStart, "sum");
+ assertEquals(responseStr, doubleResult,doubleTest);
+ }
+
+ @Test
+ public void meanTest() throws Exception {
+ String[] params = new String[] {
+ "o.mr.s.int_id", "mean(int_id)",
+ "o.mr.s.long_ld", "mean(long_ld)",
+ "o.mr.s.float_fd", "mean(float_fd)",
+ "o.mr.s.double_dd", "mean(double_dd)"
+ };
+ NamedList<Object> response = queryLegacyCloudAnalytics(params);
+ String responseStr = response.toString();
+
+ //Int
+ Double intResult = getValue(response, "mr", "int_id");
+ Double intTest = (Double)calculateNumberStat(intTestStart, "mean");
+ assertEquals(responseStr, intResult,intTest);
+
+ //Long
+ Double longResult = getValue(response, "mr", "long_ld");
+ Double longTest = (Double)calculateNumberStat(longTestStart, "mean");
+ assertEquals(responseStr, longResult,longTest);
+
+ //Float
+ Double floatResult = getValue(response, "mr", "float_fd");
+ Double floatTest = (Double)calculateNumberStat(floatTestStart, "mean");
+ assertEquals(responseStr, floatResult,floatTest);
+
+ //Double
+ Double doubleResult = getValue(response, "mr", "double_dd");
+ Double doubleTest = (Double)calculateNumberStat(doubleTestStart, "mean");
+ assertEquals(responseStr, doubleResult,doubleTest);
+ }
+
+ @Test
+ public void stddevTest() throws Exception {
+ String[] params = new String[] {
+ "o.str.s.int_id", "stddev(int_id)",
+ "o.str.s.long_ld", "stddev(long_ld)",
+ "o.str.s.float_fd", "stddev(float_fd)",
+ "o.str.s.double_dd", "stddev(double_dd)"
+ };
+ NamedList<Object> response = queryLegacyCloudAnalytics(params);
+ String responseStr = response.toString();
+
+ //Int
+ Double intResult = getValue(response, "str", "int_id");
+ Double intTest = (Double)calculateNumberStat(intTestStart, "stddev");
+ assertEquals(responseStr, intResult, intTest, 0.00000000001);
+
+ //Long
+ Double longResult = getValue(response, "str", "long_ld");
+ Double longTest = (Double)calculateNumberStat(longTestStart, "stddev");
+ assertEquals(responseStr, longResult, longTest, 0.00000000001);
+
+ //Float
+ Double floatResult = getValue(response, "str", "float_fd");
+ Double floatTest = (Double)calculateNumberStat(floatTestStart, "stddev");
+ assertEquals(responseStr, floatResult, floatTest, 0.00000000001);
+
+
+ //Double
+ Double doubleResult = getValue(response, "str", "double_dd");
+ Double doubleTest = (Double)calculateNumberStat(doubleTestStart, "stddev");
+ assertEquals(responseStr, doubleResult, doubleTest, 0.00000000001);
+ }
+
+ @Test
+ public void medianTest() throws Exception {
+ String[] params = new String[] {
+ "o.medr.s.int_id", "median(int_id)",
+ "o.medr.s.long_ld", "median(long_ld)",
+ "o.medr.s.float_fd", "median(float_fd)",
+ "o.medr.s.double_dd", "median(double_dd)",
+ "o.medr.s.date_dtd", "median(date_dtd)"
+ };
+ NamedList<Object> response = queryLegacyCloudAnalytics(params);
+ String responseStr = response.toString();
+
+ //Int
+ Double intResult = getValue(response, "medr", "int_id");
+ Double intTest = (Double)calculateNumberStat(intTestStart, "median");
+ assertEquals(responseStr, intResult,intTest);
+
+ //Long
+ Double longResult = getValue(response, "medr", "long_ld");
+ Double longTest = (Double)calculateNumberStat(longTestStart, "median");
+ assertEquals(responseStr, longResult,longTest);
+
+ //Float
+ Double floatResult = getValue(response, "medr", "float_fd");
+ Double floatTest = (Double)calculateNumberStat(floatTestStart, "median");
+ assertEquals(responseStr, floatResult,floatTest);
+
+ //Double
+ Double doubleResult = getValue(response, "medr", "double_dd");
+ Double doubleTest = (Double)calculateNumberStat(doubleTestStart, "median");
+ assertEquals(responseStr, doubleResult,doubleTest);
+
+ // TODO: Add test for date median
+ }
+
+ @Test
+ public void perc20Test() throws Exception {
+ String[] params = new String[] {
+ "o.p2r.s.int_id", "percentile(20,int_id)",
+ "o.p2r.s.long_ld", "percentile(20,long_ld)",
+ "o.p2r.s.float_fd", "percentile(20,float_fd)",
+ "o.p2r.s.double_dd", "percentile(20,double_dd)",
+ "o.p2r.s.date_dtd", "string(percentile(20,date_dtd))",
+ "o.p2r.s.string_sd", "percentile(20,string_sd)"
+ };
+ NamedList<Object> response = queryLegacyCloudAnalytics(params);
+ String responseStr = response.toString();
+
+ //Int 20
+ Integer intResult = getValue(response, "p2r", "int_id");
+ Integer intTest = (Integer)calculateStat(intTestStart, "perc_20");
+ assertEquals(responseStr, intResult,intTest);
+
+ //Long 20
+ Long longResult = getValue(response, "p2r", "long_ld");
+ Long longTest = (Long)calculateStat(longTestStart, "perc_20");
+ assertEquals(responseStr, longResult,longTest);
+
+ //Float 20
+ Float floatResult = getValue(response, "p2r", "float_fd");
+ Float floatTest = (Float)calculateStat(floatTestStart, "perc_20");
+ assertEquals(responseStr, floatResult,floatTest);
+
+ //Double 20
+ Double doubleResult = getValue(response, "p2r", "double_dd");
+ Double doubleTest = (Double)calculateStat(doubleTestStart, "perc_20");
+ assertEquals(responseStr, doubleResult,doubleTest);
+
+ //Date 20
+ String dateResult = getValue(response, "p2r", "date_dtd");
+ String dateTest = (String)calculateStat(dateTestStart, "perc_20");
+ assertEquals(responseStr, dateResult,dateTest);
+
+ //String 20
+ String stringResult = getValue(response, "p2r", "string_sd");
+ String stringTest = (String)calculateStat(stringTestStart, "perc_20");
+ assertEquals(responseStr, stringResult,stringTest);
+ }
+
+ @Test
+ public void perc60Test() throws Exception {
+ String[] params = new String[] {
+ "o.p6r.s.int_id", "percentile(60,int_id)",
+ "o.p6r.s.long_ld", "percentile(60,long_ld)",
+ "o.p6r.s.float_fd", "percentile(60,float_fd)",
+ "o.p6r.s.double_dd", "percentile(60,double_dd)",
+ "o.p6r.s.date_dtd", "string(percentile(60,date_dtd))",
+ "o.p6r.s.string_sd", "percentile(60,string_sd)"
+ };
+ NamedList<Object> response = queryLegacyCloudAnalytics(params);
+ String responseStr = response.toString();
+
+ //Int 60
+ Integer intResult = getValue(response, "p6r", "int_id");
+ Integer intTest = (Integer)calculateStat(intTestStart, "perc_60");
+ assertEquals(responseStr, intResult,intTest);
+
+ //Long 60
+ Long longResult = getValue(response, "p6r", "long_ld");
+ Long longTest = (Long)calculateStat(longTestStart, "perc_60");
+ assertEquals(responseStr, longResult,longTest);
+
+ //Float 60
+ Float floatResult = getValue(response, "p6r", "float_fd");
+ Float floatTest = (Float)calculateStat(floatTestStart, "perc_60");
+ assertEquals(responseStr, floatResult,floatTest);
+
+ //Double 60
+ Double doubleResult = getValue(response, "p6r", "double_dd");
+ Double doubleTest = (Double)calculateStat(doubleTestStart, "perc_60");
+ assertEquals(responseStr, doubleResult,doubleTest);
+
+ //Date 60
+ String dateResult = getValue(response, "p6r", "date_dtd");
+ String dateTest = (String)calculateStat(dateTestStart, "perc_60");
+ assertEquals(responseStr, dateResult,dateTest);
+
+ //String 60
+ String stringResult = getValue(response, "p6r", "string_sd");
+ String stringTest = (String)calculateStat(stringTestStart, "perc_60");
+ assertEquals(responseStr, stringResult,stringTest);
+ }
+
+ @Test
+ public void minTest() throws Exception {
+ String[] params = new String[] {
+ "o.mir.s.int_id", "min(int_id)",
+ "o.mir.s.long_ld", "min(long_ld)",
+ "o.mir.s.float_fd", "min(float_fd)",
+ "o.mir.s.double_dd", "min(double_dd)",
+ "o.mir.s.date_dtd", "string(min(date_dtd))",
+ "o.mir.s.string_sd", "min(string_sd)"
+ };
+ NamedList<Object> response = queryLegacyCloudAnalytics(params);
+ String responseStr = response.toString();
+
+ //Int
+ Integer intResult = getValue(response, "mir", "int_id");
+ Integer intTest = (Integer)calculateStat(intTestStart, "min");
+ assertEquals(responseStr, intResult,intTest);
+
+ //Long
+ Long longResult = getValue(response, "mir", "long_ld");
+ Long longTest = (Long)calculateStat(longTestStart, "min");
+ assertEquals(responseStr, longResult,longTest);
+
+ //Float
+ Float floatResult = getValue(response, "mir", "float_fd");
+ Float floatTest = (Float)calculateStat(floatTestStart, "min");
+ assertEquals(responseStr, floatResult,floatTest);
+
+ //Double
+ Double doubleResult = getValue(response, "mir", "double_dd");
+ Double doubleTest = (Double)calculateStat(doubleTestStart, "min");
+ assertEquals(responseStr, doubleResult,doubleTest);
+
+ //Date
+ String dateResult = getValue(response, "mir", "date_dtd");
+ String dateTest = (String)calculateStat(dateTestStart, "min");
+ assertEquals(responseStr, dateResult,dateTest);
+
+ //String
+ String stringResult = getValue(response, "mir", "string_sd");
+ String stringTest = (String)calculateStat(stringTestStart, "min");
+ assertEquals(responseStr, stringResult,stringTest);
+ }
+
+ @Test
+ public void maxTest() throws Exception {
+ String[] params = new String[] {
+ "o.mar.s.int_id", "max(int_id)",
+ "o.mar.s.long_ld", "max(long_ld)",
+ "o.mar.s.float_fd", "max(float_fd)",
+ "o.mar.s.double_dd", "max(double_dd)",
+ "o.mar.s.date_dtd", "string(max(date_dtd))",
+ "o.mar.s.string_sd", "max(string_sd)"
+ };
+ NamedList<Object> response = queryLegacyCloudAnalytics(params);
+ String responseStr = response.toString();
+
+ //Int
+ Integer intResult = getValue(response, "mar", "int_id");
+ Integer intTest = (Integer)calculateStat(intTestStart, "max");
+ assertEquals(responseStr, intResult,intTest);
+
+ //Long
+ Long longResult = getValue(response, "mar", "long_ld");
+ Long longTest = (Long)calculateStat(longTestStart, "max");
+ assertEquals(responseStr, longResult,longTest);
+
+ //Float
+ Float floatResult = getValue(response, "mar", "float_fd");
+ Float floatTest = (Float)calculateStat(floatTestStart, "max");
+ assertEquals(responseStr, floatResult,floatTest);
+
+ //Double
+ Double doubleResult = getValue(response, "mar", "double_dd");
+ Double doubleTest = (Double)calculateStat(doubleTestStart, "max");
+ assertEquals(responseStr, doubleResult,doubleTest);
+
+ //Date
+ String dateResult = getValue(response, "mar", "date_dtd");
+ String dateTest = (String)calculateStat(dateTestStart, "max");
+ assertEquals(responseStr, dateResult,dateTest);
+
+ //String
+ String stringResult = getValue(response, "mar", "string_sd");
+ String stringTest = (String)calculateStat(stringTestStart, "max");
+ assertEquals(responseStr, stringResult,stringTest);
+ }
+
+ @Test
+ public void uniqueTest() throws Exception {
+ String[] params = new String[] {
+ "o.ur.s.int_id", "unique(int_id)",
+ "o.ur.s.long_ld", "unique(long_ld)",
+ "o.ur.s.float_fd", "unique(float_fd)",
+ "o.ur.s.double_dd", "unique(double_dd)",
+ "o.ur.s.date_dtd", "unique(date_dtd)",
+ "o.ur.s.string_sd", "unique(string_sd)"
+ };
+ NamedList<Object> response = queryLegacyCloudAnalytics(params);
+ String responseStr = response.toString();
+
+ //Int
+ Long intResult = getValue(response, "ur", "int_id");
+ Long intTest = (Long)calculateStat(intTestStart, "unique");
+ assertEquals(responseStr, intResult,intTest);
+
+ //Long
+ Long longResult = getValue(response, "ur", "long_ld");
+ Long longTest = (Long)calculateStat(longTestStart, "unique");
+ assertEquals(responseStr, longResult,longTest);
+
+ //Float
+ Long floatResult = getValue(response, "ur", "float_fd");
+ Long floatTest = (Long)calculateStat(floatTestStart, "unique");
+ assertEquals(responseStr, floatResult,floatTest);
+
+ //Double
+ Long doubleResult = getValue(response, "ur", "double_dd");
+ Long doubleTest = (Long)calculateStat(doubleTestStart, "unique");
+ assertEquals(responseStr, doubleResult,doubleTest);
+
+ //Date
+ Long dateResult = getValue(response, "ur", "date_dtd");
+ Long dateTest = (Long)calculateStat(dateTestStart, "unique");
+ assertEquals(responseStr, dateResult,dateTest);
+
+ //String
+ Long stringResult = getValue(response, "ur", "string_sd");
+ Long stringTest = (Long)calculateStat(stringTestStart, "unique");
+ assertEquals(responseStr, stringResult,stringTest);
+ }
+
+ @Test
+ public void countTest() throws Exception {
+ String[] params = new String[] {
+ "o.cr.s.int_id", "count(int_id)",
+ "o.cr.s.long_ld", "count(long_ld)",
+ "o.cr.s.float_fd", "count(float_fd)",
+ "o.cr.s.double_dd", "count(double_dd)",
+ "o.cr.s.date_dtd", "count(date_dtd)",
+ "o.cr.s.string_sd", "count(string_sd)"
+ };
+ NamedList<Object> response = queryLegacyCloudAnalytics(params);
+ String responseStr = response.toString();
+
+ //Int
+ Long intResult = getValue(response, "cr", "int_id");
+ Long intTest = (Long)calculateStat(intTestStart, "count");
+ assertEquals(responseStr, intResult,intTest);
+
+ //Long
+ Long longResult = getValue(response, "cr", "long_ld");
+ Long longTest = (Long)calculateStat(longTestStart, "count");
+ assertEquals(responseStr, longResult,longTest);
+
+ //Float
+ Long floatResult = getValue(response, "cr", "float_fd");
+ Long floatTest = (Long)calculateStat(floatTestStart, "count");
+ assertEquals(responseStr, floatResult,floatTest);
+
+ //Double
+ Long doubleResult = getValue(response, "cr", "double_dd");
+ Long doubleTest = (Long)calculateStat(doubleTestStart, "count");
+ assertEquals(responseStr, doubleResult,doubleTest);
+
+ //Date
+ Long dateResult = getValue(response, "cr", "date_dtd");
+ Long dateTest = (Long)calculateStat(dateTestStart, "count");
+ assertEquals(responseStr, dateResult,dateTest);
+
+ //String
+ Long stringResult = getValue(response, "cr", "string_sd");
+ Long stringTest = (Long)calculateStat(stringTestStart, "count");
+ assertEquals(responseStr, stringResult,stringTest);
+ }
+
+ @Test
+ public void missingDefaultTest() throws Exception {
+ String[] params = new String[] {
+ "o.misr.s.int_id", "missing(int_id)",
+ "o.misr.s.long_ld", "missing(long_ld)",
+ "o.misr.s.float_fd", "missing(float_fd)",
+ "o.misr.s.double_dd", "missing(double_dd)",
+ "o.misr.s.date_dtd", "missing(date_dtd)",
+ "o.misr.s.string_sd", "missing(string_sd)"
+ };
+ NamedList<Object> response = queryLegacyCloudAnalytics(params);
+ String responseStr = response.toString();
+
+ //Int
+ long intResult = getValue(response, "misr", "int_id");
+ assertEquals(responseStr, intMissing,intResult);
+
+ //Long
+ long longResult = getValue(response, "misr", "long_ld");
+ assertEquals(responseStr, longMissing,longResult);
+
+ //Float
+ long floatResult = getValue(response, "misr", "float_fd");
+ assertEquals(responseStr, floatMissing,floatResult);
+
+ //Double
+ long doubleResult = getValue(response, "misr", "double_dd");
+ assertEquals(responseStr, doubleMissing,doubleResult);
+
+ //Date
+ long dateResult = getValue(response, "misr", "date_dtd");
+ assertEquals(responseStr, dateMissing,dateResult);
+
+ //String
+ long stringResult = getValue(response, "misr", "string_sd");
+ assertEquals(responseStr, stringMissing, stringResult);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/LegacyNoFacetTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/LegacyNoFacetTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/LegacyNoFacetTest.java
new file mode 100644
index 0000000..4fb573d
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/LegacyNoFacetTest.java
@@ -0,0 +1,450 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.legacy;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class LegacyNoFacetTest extends LegacyAbstractAnalyticsTest {
+ static String fileName = "noFacets.txt";
+
+ static public final int INT = 71;
+ static public final int LONG = 36;
+ static public final int FLOAT = 93;
+ static public final int DOUBLE = 49;
+ static public final int DATE = 12;
+ static public final int STRING = 28;
+ static public final int NUM_LOOPS = 100;
+
+ //INT
+ static ArrayList<Integer> intTestStart;
+ static long intMissing = 0;
+
+ //LONG
+ static ArrayList<Long> longTestStart;
+ static long longMissing = 0;
+
+ //FLOAT
+ static ArrayList<Float> floatTestStart;
+ static long floatMissing = 0;
+
+ //DOUBLE
+ static ArrayList<Double> doubleTestStart;
+ static long doubleMissing = 0;
+
+ //DATE
+ static ArrayList<String> dateTestStart;
+ static long dateMissing = 0;
+
+ //STR
+ static ArrayList<String> stringTestStart;
+ static long stringMissing = 0;
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ initCore("solrconfig-analytics.xml","schema-analytics.xml");
+ h.update("<delete><query>*:*</query></delete>");
+ defaults.put("int_id", new Integer(0));
+ defaults.put("long_ld", new Long(0));
+ defaults.put("float_fd", new Float(0));
+ defaults.put("double_dd", new Double(0));
+ defaults.put("date_dtd", "1800-12-31T23:59:59Z");
+ defaults.put("string_sd", "str0");
+
+ intTestStart = new ArrayList<>();
+ longTestStart = new ArrayList<>();
+ floatTestStart = new ArrayList<>();
+ doubleTestStart = new ArrayList<>();
+ dateTestStart = new ArrayList<>();
+ stringTestStart = new ArrayList<>();
+
+ for (int j = 0; j < NUM_LOOPS; ++j) {
+ int i = j%INT;
+ long l = j%LONG;
+ float f = j%FLOAT;
+ double d = j%DOUBLE;
+ String dt = (1800+j%DATE) + "-12-31T23:59:59Z";
+ String s = "str" + (j%STRING);
+ List<String> fields = new ArrayList<>();
+ fields.add("id"); fields.add("1000"+j);
+
+ if( i != 0 ){
+ fields.add("int_id"); fields.add("" + i);
+ intTestStart.add(i);
+ } else intMissing++;
+
+ if( l != 0l ){
+ fields.add("long_ld"); fields.add("" + l);
+ longTestStart.add(l);
+ } else longMissing++;
+
+ if( f != 0.0f ){
+ fields.add("float_fd"); fields.add("" + f);
+ floatTestStart.add(f);
+ } else floatMissing++;
+
+ if( d != 0.0d ){
+ fields.add("double_dd"); fields.add("" + d);
+ doubleTestStart.add(d);
+ } else doubleMissing++;
+
+ if( (j%DATE) != 0 ){
+ fields.add("date_dtd"); fields.add(dt);
+ dateTestStart.add(dt);
+ } else dateMissing++;
+
+ if( (j%STRING) != 0 ){
+ fields.add("string_sd"); fields.add(s);
+ stringTestStart.add(s);
+ } else stringMissing++;
+
+ assertU(adoc(fields.toArray(new String[0])));
+
+
+ if (usually()) {
+ assertU(commit()); // to have several segments
+ }
+ }
+
+ assertU(commit());
+
+ //Sort ascending tests
+ setResponse(h.query(request(fileToStringArr(LegacyNoFacetTest.class, fileName))));
+ }
+
+ @Test
+ public void sumTest() throws Exception {
+ //Int
+ Double intResult = (Double)getStatResult("sr", "int_id", VAL_TYPE.DOUBLE);
+ Double intTest = (Double)calculateNumberStat(intTestStart, "sum");
+ assertEquals(getRawResponse(), intResult,intTest);
+
+ //Long
+ Double longResult = (Double)getStatResult("sr", "long_ld", VAL_TYPE.DOUBLE);
+ Double longTest = (Double)calculateNumberStat(longTestStart, "sum");
+ assertEquals(getRawResponse(), longResult,longTest);
+
+ //Float
+ Double floatResult = (Double)getStatResult("sr", "float_fd", VAL_TYPE.DOUBLE);
+ Double floatTest = (Double)calculateNumberStat(floatTestStart, "sum");
+ assertEquals(getRawResponse(), floatResult,floatTest);
+
+ //Double
+ Double doubleResult = (Double)getStatResult("sr", "double_dd", VAL_TYPE.DOUBLE);
+ Double doubleTest = (Double) calculateNumberStat(doubleTestStart, "sum");
+ assertEquals(getRawResponse(), doubleResult,doubleTest);
+ }
+
+ @Test
+ public void meanTest() throws Exception {
+ //Int
+ Double intResult = (Double)getStatResult("mr", "int_id", VAL_TYPE.DOUBLE);
+ Double intTest = (Double)calculateNumberStat(intTestStart, "mean");
+ assertEquals(getRawResponse(), intResult,intTest);
+
+ //Long
+ Double longResult = (Double)getStatResult("mr", "long_ld", VAL_TYPE.DOUBLE);
+ Double longTest = (Double)calculateNumberStat(longTestStart, "mean");
+ assertEquals(getRawResponse(), longResult,longTest);
+
+ //Float
+ Double floatResult = (Double)getStatResult("mr", "float_fd", VAL_TYPE.DOUBLE);
+ Double floatTest = (Double)calculateNumberStat(floatTestStart, "mean");
+ assertEquals(getRawResponse(), floatResult,floatTest);
+
+ //Double
+ Double doubleResult = (Double)getStatResult("mr", "double_dd", VAL_TYPE.DOUBLE);
+ Double doubleTest = (Double)calculateNumberStat(doubleTestStart, "mean");
+ assertEquals(getRawResponse(), doubleResult,doubleTest);
+ }
+
+ @Test
+ public void stddevTest() throws Exception {
+ //Int
+ Double intResult = (Double)getStatResult("str", "int_id", VAL_TYPE.DOUBLE);
+ Double intTest = (Double)calculateNumberStat(intTestStart, "stddev");
+ assertEquals(getRawResponse(), intResult, intTest, 0.00000000001);
+
+ //Long
+ Double longResult = (Double)getStatResult("str", "long_ld", VAL_TYPE.DOUBLE);
+ Double longTest = (Double)calculateNumberStat(longTestStart, "stddev");
+ assertEquals(getRawResponse(), longResult, longTest, 0.00000000001);
+
+ //Float
+ Double floatResult = (Double)getStatResult("str", "float_fd", VAL_TYPE.DOUBLE);
+ Double floatTest = (Double)calculateNumberStat(floatTestStart, "stddev");
+ assertEquals(getRawResponse(), floatResult, floatTest, 0.00000000001);
+
+
+ //Double
+ Double doubleResult = (Double)getStatResult("str", "double_dd", VAL_TYPE.DOUBLE);
+ Double doubleTest = (Double)calculateNumberStat(doubleTestStart, "stddev");
+ assertEquals(getRawResponse(), doubleResult, doubleTest, 0.00000000001);
+ }
+
+ @Test
+ public void medianTest() throws Exception {
+ //Int
+ Double intResult = (Double)getStatResult("medr", "int_id", VAL_TYPE.DOUBLE);
+ Double intTest = (Double)calculateNumberStat(intTestStart, "median");
+ assertEquals(getRawResponse(), intResult,intTest);
+
+ //Long
+ Double longResult = (Double)getStatResult("medr", "long_ld", VAL_TYPE.DOUBLE);
+ Double longTest = (Double)calculateNumberStat(longTestStart, "median");
+ assertEquals(getRawResponse(), longResult,longTest);
+
+ //Float
+ Double floatResult = (Double)getStatResult("medr", "float_fd", VAL_TYPE.DOUBLE);
+ Double floatTest = (Double)calculateNumberStat(floatTestStart, "median");
+ assertEquals(getRawResponse(), floatResult,floatTest);
+
+ //Double
+ Double doubleResult = (Double)getStatResult("medr", "double_dd", VAL_TYPE.DOUBLE);
+ Double doubleTest = (Double)calculateNumberStat(doubleTestStart, "median");
+ assertEquals(getRawResponse(), doubleResult,doubleTest);
+ }
+
+ @Test
+ public void perc20Test() throws Exception {
+ //Int 20
+ Integer intResult = (Integer)getStatResult("p2r", "int_id", VAL_TYPE.INTEGER);
+ Integer intTest = (Integer)calculateStat(intTestStart, "perc_20");
+ assertEquals(getRawResponse(), intResult,intTest);
+
+ //Long 20
+ Long longResult = (Long)getStatResult("p2r", "long_ld", VAL_TYPE.LONG);
+ Long longTest = (Long)calculateStat(longTestStart, "perc_20");
+ assertEquals(getRawResponse(), longResult,longTest);
+
+ //Float 20
+ Float floatResult = (Float)getStatResult("p2r", "float_fd", VAL_TYPE.FLOAT);
+ Float floatTest = (Float)calculateStat(floatTestStart, "perc_20");
+ //assertEquals(getRawResponse(), floatResult,floatTest);
+
+ //Double 20
+ Double doubleResult = (Double)getStatResult("p2r", "double_dd", VAL_TYPE.DOUBLE);
+ Double doubleTest = (Double)calculateStat(doubleTestStart, "perc_20");
+ assertEquals(getRawResponse(), doubleResult,doubleTest);
+
+ //Date 20
+ String dateResult = (String)getStatResult("p2r", "date_dtd", VAL_TYPE.DATE);
+ String dateTest = (String)calculateStat(dateTestStart, "perc_20");
+ assertEquals(getRawResponse(), dateResult,dateTest);
+
+ //String 20
+ String stringResult = (String)getStatResult("p2r", "string_sd", VAL_TYPE.STRING);
+ String stringTest = (String)calculateStat(stringTestStart, "perc_20");
+ assertEquals(getRawResponse(), stringResult,stringTest);
+ }
+
+ @Test
+ public void perc60Test() throws Exception {
+ //Int 60
+ Integer intResult = (Integer)getStatResult("p6r", "int_id", VAL_TYPE.INTEGER);
+ Integer intTest = (Integer)calculateStat(intTestStart, "perc_60");
+ assertEquals(getRawResponse(), intResult,intTest);
+
+ //Long 60
+ Long longResult = (Long)getStatResult("p6r", "long_ld", VAL_TYPE.LONG);
+ Long longTest = (Long)calculateStat(longTestStart, "perc_60");
+ assertEquals(getRawResponse(), longResult,longTest);
+
+ //Float 60
+ Float floatResult = (Float)getStatResult("p6r", "float_fd", VAL_TYPE.FLOAT);
+ Float floatTest = (Float)calculateStat(floatTestStart, "perc_60");
+ assertEquals(getRawResponse(), floatResult,floatTest);
+
+ //Double 60
+ Double doubleResult = (Double)getStatResult("p6r", "double_dd", VAL_TYPE.DOUBLE);
+ Double doubleTest = (Double)calculateStat(doubleTestStart, "perc_60");
+ assertEquals(getRawResponse(), doubleResult,doubleTest);
+
+ //Date 60
+ String dateResult = (String)getStatResult("p6r", "date_dtd", VAL_TYPE.DATE);
+ String dateTest = (String)calculateStat(dateTestStart, "perc_60");
+ assertEquals(getRawResponse(), dateResult,dateTest);
+
+ //String 60
+ String stringResult = (String)getStatResult("p6r", "string_sd", VAL_TYPE.STRING);
+ String stringTest = (String)calculateStat(stringTestStart, "perc_60");
+ assertEquals(getRawResponse(), stringResult,stringTest);
+ }
+
+ @Test
+ public void minTest() throws Exception {
+ //Int
+ Integer intResult = ((Integer)getStatResult("mir", "int_id", VAL_TYPE.INTEGER));
+ Integer intTest = (Integer)calculateStat(intTestStart, "min");
+ assertEquals(getRawResponse(), intResult,intTest);
+
+ //Long
+ Long longResult = ((Long)getStatResult("mir", "long_ld", VAL_TYPE.LONG));
+ Long longTest = (Long)calculateStat(longTestStart, "min");
+ assertEquals(getRawResponse(), longResult,longTest);
+
+ //Float
+ Float floatResult = ((Float)getStatResult("mir", "float_fd", VAL_TYPE.FLOAT));
+ Float floatTest = (Float)calculateStat(floatTestStart, "min");
+ assertEquals(getRawResponse(), floatResult,floatTest);
+
+ //Double
+ Double doubleResult = (Double)getStatResult("mir", "double_dd", VAL_TYPE.DOUBLE);
+ Double doubleTest = (Double)calculateStat(doubleTestStart, "min");
+ assertEquals(getRawResponse(), doubleResult,doubleTest);
+
+ //Date
+ String dateResult = (String)getStatResult("mir", "date_dtd", VAL_TYPE.DATE);
+ String dateTest = (String)calculateStat(dateTestStart, "min");
+ assertEquals(getRawResponse(), dateResult,dateTest);
+
+ //String
+ String stringResult = (String)getStatResult("mir", "string_sd", VAL_TYPE.STRING);
+ String stringTest = (String)calculateStat(stringTestStart, "min");
+ assertEquals(getRawResponse(), stringResult,stringTest);
+ }
+
+ @Test
+ public void maxTest() throws Exception {
+ //Int
+ Integer intResult = ((Integer)getStatResult("mar", "int_id", VAL_TYPE.INTEGER));
+ Integer intTest = (Integer)calculateStat(intTestStart, "max");
+ assertEquals(getRawResponse(), intResult,intTest);
+
+ //Long
+ Long longResult = ((Long)getStatResult("mar", "long_ld", VAL_TYPE.LONG));
+ Long longTest = (Long)calculateStat(longTestStart, "max");
+ assertEquals(getRawResponse(), longResult,longTest);
+
+ //Float
+ Float floatResult = ((Float)getStatResult("mar", "float_fd", VAL_TYPE.FLOAT));
+ Float floatTest = (Float)calculateStat(floatTestStart, "max");
+ assertEquals(getRawResponse(), floatResult,floatTest);
+
+ //Double
+ Double doubleResult = (Double)getStatResult("mar", "double_dd", VAL_TYPE.DOUBLE);
+ Double doubleTest = (Double)calculateStat(doubleTestStart, "max");
+ assertEquals(getRawResponse(), doubleResult,doubleTest);
+
+ //Date
+ String dateResult = (String)getStatResult("mar", "date_dtd", VAL_TYPE.DATE);
+ String dateTest = (String)calculateStat(dateTestStart, "max");
+ assertEquals(getRawResponse(), dateResult,dateTest);
+
+ //String
+ String stringResult = (String)getStatResult("mar", "string_sd", VAL_TYPE.STRING);
+ String stringTest = (String)calculateStat(stringTestStart, "max");
+ assertEquals(getRawResponse(), stringResult,stringTest);
+ }
+
+ @Test
+ public void uniqueTest() throws Exception {
+ //Int
+ Long intResult = (Long)getStatResult("ur", "int_id", VAL_TYPE.LONG);
+ Long intTest = (Long)calculateStat(intTestStart, "unique");
+ assertEquals(getRawResponse(), intResult,intTest);
+
+ //Long
+ Long longResult = (Long)getStatResult("ur", "long_ld", VAL_TYPE.LONG);
+ Long longTest = (Long)calculateStat(longTestStart, "unique");
+ assertEquals(getRawResponse(), longResult,longTest);
+
+ //Float
+ Long floatResult = (Long)getStatResult("ur", "float_fd", VAL_TYPE.LONG);
+ Long floatTest = (Long)calculateStat(floatTestStart, "unique");
+ assertEquals(getRawResponse(), floatResult,floatTest);
+
+ //Double
+ Long doubleResult = (Long)getStatResult("ur", "double_dd", VAL_TYPE.LONG);
+ Long doubleTest = (Long)calculateStat(doubleTestStart, "unique");
+ assertEquals(getRawResponse(), doubleResult,doubleTest);
+
+ //Date
+ Long dateResult = (Long)getStatResult("ur", "date_dtd", VAL_TYPE.LONG);
+ Long dateTest = (Long)calculateStat(dateTestStart, "unique");
+ assertEquals(getRawResponse(), dateResult,dateTest);
+
+ //String
+ Long stringResult = (Long)getStatResult("ur", "string_sd", VAL_TYPE.LONG);
+ Long stringTest = (Long)calculateStat(stringTestStart, "unique");
+ assertEquals(getRawResponse(), stringResult,stringTest);
+ }
+
+ @Test
+ public void countTest() throws Exception {
+ //Int
+ Long intResult = (Long)getStatResult("cr", "int_id", VAL_TYPE.LONG);
+ Long intTest = (Long)calculateStat(intTestStart, "count");
+ assertEquals(getRawResponse(), intResult,intTest);
+
+ //Long
+ Long longResult = (Long)getStatResult("cr", "long_ld", VAL_TYPE.LONG);
+ Long longTest = (Long)calculateStat(longTestStart, "count");
+ assertEquals(getRawResponse(), longResult,longTest);
+
+ //Float
+ Long floatResult = (Long)getStatResult("cr", "float_fd", VAL_TYPE.LONG);
+ Long floatTest = (Long)calculateStat(floatTestStart, "count");
+ assertEquals(getRawResponse(), floatResult,floatTest);
+
+ //Double
+ Long doubleResult = (Long)getStatResult("cr", "double_dd", VAL_TYPE.LONG);
+ Long doubleTest = (Long)calculateStat(doubleTestStart, "count");
+ assertEquals(getRawResponse(), doubleResult,doubleTest);
+
+ //Date
+ Long dateResult = (Long)getStatResult("cr", "date_dtd", VAL_TYPE.LONG);
+ Long dateTest = (Long)calculateStat(dateTestStart, "count");
+ assertEquals(getRawResponse(), dateResult,dateTest);
+
+ //String
+ Long stringResult = (Long)getStatResult("cr", "string_sd", VAL_TYPE.LONG);
+ Long stringTest = (Long)calculateStat(stringTestStart, "count");
+ assertEquals(getRawResponse(), stringResult,stringTest);
+ }
+
+ @Test
+ public void missingDefaultTest() throws Exception {
+ //Int
+ long intResult = (Long)getStatResult("misr", "int_id", VAL_TYPE.LONG);
+ assertEquals(getRawResponse(), intMissing,intResult);
+
+ //Long
+ long longResult = (Long)getStatResult("misr", "long_ld", VAL_TYPE.LONG);
+ assertEquals(getRawResponse(), longMissing,longResult);
+
+ //Float
+ long floatResult = (Long)getStatResult("misr", "float_fd", VAL_TYPE.LONG);
+ assertEquals(getRawResponse(), floatMissing,floatResult);
+
+ //Double
+ long doubleResult = (Long)getStatResult("misr", "double_dd", VAL_TYPE.LONG);
+ assertEquals(getRawResponse(), doubleMissing,doubleResult);
+
+ //Date
+ long dateResult = (Long)getStatResult("misr", "date_dtd", VAL_TYPE.LONG);
+ assertEquals(getRawResponse(), dateMissing,dateResult);
+
+ //String
+ long stringResult = (Long)getStatResult("misr", "string_sd", VAL_TYPE.LONG);
+ assertEquals(getRawResponse(), stringMissing, stringResult);
+ }
+
+}
[05/20] lucene-solr:master: SOLR-11145,
SOLR-11146: Added comprehensive unit tests for Analytics Component
2.0 as well as analytics bug fixes.
Posted by dp...@apache.org.
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/expression/LegacyExpressionTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/expression/LegacyExpressionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/expression/LegacyExpressionTest.java
new file mode 100644
index 0000000..89fe2c7
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/expression/LegacyExpressionTest.java
@@ -0,0 +1,201 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.legacy.expression;
+
+import java.time.Instant;
+import java.util.Date;
+
+import org.apache.solr.analytics.legacy.LegacyAbstractAnalyticsTest;
+import org.apache.solr.util.DateMathParser;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class LegacyExpressionTest extends LegacyAbstractAnalyticsTest {
+ private static final String fileName = "expressions.txt";
+
+ private static final int INT = 71;
+ private static final int LONG = 36;
+ private static final int FLOAT = 93;
+ private static final int DOUBLE = 49;
+ private static final int DATE = 12;
+ private static final int STRING = 28;
+ private static final int NUM_LOOPS = 100;
+
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ initCore("solrconfig-analytics.xml", "schema-analytics.xml");
+ h.update("<delete><query>*:*</query></delete>");
+
+ for (int j = 0; j < NUM_LOOPS; ++j) {
+ int i = j % INT;
+ long l = j % LONG;
+ float f = j % FLOAT;
+ double d = j % DOUBLE;
+ String dt = (1800 + j % DATE) + "-12-31T23:59:59Z";
+ String s = "str" + (j % STRING);
+ assertU(adoc("id", "1000" + j, "int_id", "" + i, "long_ld", "" + l, "float_fd", "" + f,
+ "double_dd", "" + d, "date_dtd", dt, "string_sd", s));
+
+ if (usually()) {
+ assertU(commit()); // to have several segments
+ }
+ }
+
+ assertU(commit());
+
+ setResponse(h.query(request(fileToStringArr(LegacyExpressionTest.class, fileName))));
+ }
+
+ @Test
+ public void addTest() throws Exception {
+ double sumResult = (Double) getStatResult("ar", "sum", VAL_TYPE.DOUBLE);
+ double uniqueResult = ((Long) getStatResult("ar", "unique", VAL_TYPE.LONG)).doubleValue();
+ double result = (Double) getStatResult("ar", "su", VAL_TYPE.DOUBLE);
+ assertEquals(getRawResponse(), sumResult + uniqueResult, result, 0.0);
+
+ double meanResult = (Double) getStatResult("ar", "mean", VAL_TYPE.DOUBLE);
+ double medianResult = (Double) getStatResult("ar", "median", VAL_TYPE.DOUBLE);
+ double countResult = ((Long) getStatResult("ar", "count", VAL_TYPE.LONG)).doubleValue();
+ result = (Double) getStatResult("ar", "mcm", VAL_TYPE.DOUBLE);
+ assertEquals(getRawResponse(), meanResult + countResult + medianResult, result, 0.0);
+ }
+
+ @Test
+ public void multiplyTest() throws Exception {
+ double sumResult = (Double) getStatResult("mr", "sum", VAL_TYPE.DOUBLE);
+ double uniqueResult = ((Long) getStatResult("mr", "unique", VAL_TYPE.LONG)).doubleValue();
+ double result = (Double) getStatResult("mr", "su", VAL_TYPE.DOUBLE);
+ assertEquals(getRawResponse(), sumResult * uniqueResult, result, 0.0);
+
+ double meanResult = (Double) getStatResult("mr", "mean", VAL_TYPE.DOUBLE);
+ double medianResult = (Double) getStatResult("mr", "median", VAL_TYPE.DOUBLE);
+ double countResult = ((Long) getStatResult("mr", "count", VAL_TYPE.LONG)).doubleValue();
+ result = (Double) getStatResult("mr", "mcm", VAL_TYPE.DOUBLE);
+ assertEquals(getRawResponse(), meanResult * countResult * medianResult, result, 0.0);
+ }
+
+ @Test
+ public void divideTest() throws Exception {
+ double sumResult = (Double) getStatResult("dr", "sum", VAL_TYPE.DOUBLE);
+ double uniqueResult = ((Long) getStatResult("dr", "unique", VAL_TYPE.LONG)).doubleValue();
+ double result = (Double) getStatResult("dr", "su", VAL_TYPE.DOUBLE);
+ assertEquals(getRawResponse(), sumResult / uniqueResult, result, 0.0);
+
+ double meanResult = (Double) getStatResult("dr", "mean", VAL_TYPE.DOUBLE);
+ double countResult = ((Long) getStatResult("dr", "count", VAL_TYPE.LONG)).doubleValue();
+ result = (Double) getStatResult("dr", "mc", VAL_TYPE.DOUBLE);
+ assertEquals(getRawResponse(), meanResult / countResult, result, 0.0);
+ }
+
+ @Test
+ public void powerTest() throws Exception {
+ double sumResult = (Double) getStatResult("pr", "sum", VAL_TYPE.DOUBLE);
+ double uniqueResult = ((Long) getStatResult("pr", "unique", VAL_TYPE.LONG)).doubleValue();
+ double result = (Double) getStatResult("pr", "su", VAL_TYPE.DOUBLE);
+ assertEquals(getRawResponse(), Math.pow(sumResult, uniqueResult), result, 0.0);
+
+ double meanResult = (Double) getStatResult("pr", "mean", VAL_TYPE.DOUBLE);
+ double countResult = ((Long) getStatResult("pr", "count", VAL_TYPE.LONG)).doubleValue();
+ result = (Double) getStatResult("pr", "mc", VAL_TYPE.DOUBLE);
+ assertEquals(getRawResponse(), Math.pow(meanResult, countResult), result, 0.0);
+ }
+
+ @Test
+ public void negateTest() throws Exception {
+ double sumResult = (Double) getStatResult("nr", "sum", VAL_TYPE.DOUBLE);
+ double result = (Double) getStatResult("nr", "s", VAL_TYPE.DOUBLE);
+ assertEquals(getRawResponse(), -1 * sumResult, result, 0.0);
+
+ long countResult = ((Long) getStatResult("nr", "count", VAL_TYPE.LONG));
+ long lresult = (Long) getStatResult("nr", "c", VAL_TYPE.LONG);
+ assertEquals(getRawResponse(), -1 * countResult, lresult, 0.0);
+ }
+
+ @Test
+ public void absoluteValueTest() throws Exception {
+ double sumResult = (Double) getStatResult("avr", "sum", VAL_TYPE.DOUBLE);
+ double result = (Double) getStatResult("avr", "s", VAL_TYPE.DOUBLE);
+ assertEquals(getRawResponse(), sumResult, result, 0.0);
+
+ long countResult = ((Long) getStatResult("avr", "count", VAL_TYPE.LONG));
+ long lresult = (Long) getStatResult("avr", "c", VAL_TYPE.LONG);
+ assertEquals(getRawResponse(), countResult, lresult, 0.0);
+ }
+
+ @Test
+ public void constantNumberTest() throws Exception {
+ int result = (Integer) getStatResult("cnr", "c8", VAL_TYPE.INTEGER);
+ assertEquals(getRawResponse(), 8, result, 0.0);
+
+ double dresult = (Double) getStatResult("cnr", "c10", VAL_TYPE.DOUBLE);
+ assertEquals(getRawResponse(), 10.0, dresult, 0.0);
+ }
+
+ @Test
+ public void dateMathTest() throws Exception {
+ String math = (String) getStatResult("dmr", "cme", VAL_TYPE.STRING);
+ DateMathParser dateMathParser = new DateMathParser();
+ dateMathParser.setNow(new Date(Instant.parse((String) getStatResult("dmr", "median", VAL_TYPE.DATE)).toEpochMilli()));
+ String dateMath = (String) getStatResult("dmr", "dmme", VAL_TYPE.DATE);
+ assertEquals(getRawResponse(), new Date(Instant.parse(dateMath).toEpochMilli()), dateMathParser.parseMath(math));
+
+ math = (String) getStatResult("dmr", "cma", VAL_TYPE.STRING);
+ dateMathParser = new DateMathParser();
+ dateMathParser.setNow(new Date(Instant.parse((String) getStatResult("dmr", "max", VAL_TYPE.DATE)).toEpochMilli()));
+ dateMath = (String) getStatResult("dmr", "dmma", VAL_TYPE.DATE);
+ assertEquals(getRawResponse(), new Date(Instant.parse(dateMath).toEpochMilli()), dateMathParser.parseMath(math));
+ }
+
+ @Test
+ public void constantDateTest() throws Exception {
+ String date = (String) getStatResult("cdr", "cd1", VAL_TYPE.DATE);
+ String str = (String) getStatResult("cdr", "cs1", VAL_TYPE.STRING);
+ assertEquals(getRawResponse(), date, str);
+
+ date = (String) getStatResult("cdr", "cd2", VAL_TYPE.DATE);
+ str = (String) getStatResult("cdr", "cs2", VAL_TYPE.STRING);
+ assertEquals(getRawResponse(), date, str);
+ }
+
+ @Test
+ public void constantStringTest() throws Exception {
+ String str = (String) getStatResult("csr", "cs1", VAL_TYPE.STRING);
+ assertEquals(getRawResponse(), str, "this is the first");
+
+ str = (String) getStatResult("csr", "cs2", VAL_TYPE.STRING);
+ assertEquals(getRawResponse(), str, "this is the second");
+
+ str = (String) getStatResult("csr", "cs3", VAL_TYPE.STRING);
+ assertEquals(getRawResponse(), str, "this is the third");
+ }
+
+ @Test
+ public void concatenateTest() throws Exception {
+ StringBuilder builder = new StringBuilder();
+ builder.append((String) getStatResult("cr", "csmin", VAL_TYPE.STRING));
+ builder.append((String) getStatResult("cr", "min", VAL_TYPE.STRING));
+ String concat = (String) getStatResult("cr", "ccmin", VAL_TYPE.STRING);
+ assertEquals(getRawResponse(), concat, builder.toString());
+
+ builder.setLength(0);
+ builder.append((String) getStatResult("cr", "csmax", VAL_TYPE.STRING));
+ builder.append((String) getStatResult("cr", "max", VAL_TYPE.STRING));
+ concat = (String) getStatResult("cr", "ccmax", VAL_TYPE.STRING);
+ assertEquals(getRawResponse(), concat, builder.toString());
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/expression/LegacyFunctionTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/expression/LegacyFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/expression/LegacyFunctionTest.java
new file mode 100644
index 0000000..85c1333
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/expression/LegacyFunctionTest.java
@@ -0,0 +1,221 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.legacy.expression;
+
+
+import org.apache.solr.analytics.legacy.LegacyAbstractAnalyticsTest;
+import org.apache.solr.analytics.legacy.facet.LegacyAbstractAnalyticsFacetTest;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class LegacyFunctionTest extends LegacyAbstractAnalyticsTest {
+ static String fileName = "functions.txt";
+
+ static public final int INT = 71;
+ static public final int LONG = 36;
+ static public final int FLOAT = 93;
+ static public final int DOUBLE = 49;
+ static public final int DATE = 12;
+ static public final int STRING = 28;
+ static public final int NUM_LOOPS = 100;
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ initCore("solrconfig-analytics.xml","schema-analytics.xml");
+ h.update("<delete><query>*:*</query></delete>");
+
+ for (int j = 0; j < NUM_LOOPS; ++j) {
+ int i = j%INT+1;
+ long l = j%LONG+1;
+ float f = j%FLOAT+1;
+ double d = j%DOUBLE+1;
+ double d0 = j%DOUBLE;
+ String dt = (1800+j%DATE) + "-06-30T23:59:59Z";
+ String s = "str" + (j%STRING);
+
+ double add_if = (double)i+f;
+ double add_ldf = (double)l+d+f;
+ double mult_if = (double)i*f;
+ double mult_ldf = (double)l*d*f;
+ double div_if = (double)i/f;
+ double div_ld = (double)l/d;
+ double pow_if = Math.pow(i,f);
+ double pow_ld = Math.pow(l,d);
+ int neg_i = i*-1;
+ long neg_l = l*-1;
+ String dm_2y = (1802+j%DATE) + "-06-30T23:59:59Z";
+ String dm_2m = (1800+j%DATE) + "-08-30T23:59:59Z";
+ String concat_first = "this is the first"+s;
+ String concat_second = "this is the second"+s;
+
+ assertU(adoc(LegacyAbstractAnalyticsFacetTest.filter("id", "1000" + j, "int_id", "" + i, "long_ld", "" + l, "float_fd", "" + f,
+ "double_dd", "" + d, "date_dtd", dt, "string_sd", s,
+ "add_if_dd", ""+add_if, "add_ldf_dd", ""+add_ldf, "mult_if_dd", ""+mult_if, "mult_ldf_dd", ""+mult_ldf,
+ "div_if_dd", ""+div_if, "div_ld_dd", ""+div_ld, "pow_if_dd", ""+pow_if, "pow_ld_dd", ""+pow_ld,
+ "neg_id", ""+neg_i, "neg_ld", ""+neg_l, "const_8_dd", "8", "const_10_dd", "10", "dm_2y_dtd", dm_2y, "dm_2m_dtd", dm_2m,
+ "const_00_dtd", "1800-06-30T23:59:59Z", "const_04_dtd", "1804-06-30T23:59:59Z", "const_first_sd", "this is the first", "const_second_sd", "this is the second",
+ "concat_first_sd", concat_first, "concat_second_sd", concat_second, "miss_dd", ""+d0 )));
+
+
+ if (usually()) {
+ assertU(commit()); // to have several segments
+ }
+ }
+
+ assertU(commit());
+
+ setResponse(h.query(request(fileToStringArr(LegacyFunctionTest.class, fileName))));
+ }
+
+ @Test
+ public void addTest() throws Exception {
+ double result = (Double)getStatResult("ar", "sum", VAL_TYPE.DOUBLE);
+ double calculated = (Double)getStatResult("ar", "sumc", VAL_TYPE.DOUBLE);
+ assertEquals(getRawResponse(), result, calculated, 0.0);
+ // TODO checfk why asserted 2times
+ assertEquals(getRawResponse(), result, calculated, 0.0);
+
+ result = (Double)getStatResult("ar", "mean", VAL_TYPE.DOUBLE);
+ calculated = (Double)getStatResult("ar", "meanc", VAL_TYPE.DOUBLE);
+ assertTrue(result==calculated);
+ assertEquals(getRawResponse(), result, calculated, 0.0);
+ }
+
+ @Test
+ public void multiplyTest() throws Exception {
+ double result = (Double)getStatResult("mr", "sum", VAL_TYPE.DOUBLE);
+ double calculated = (Double)getStatResult("mr", "sumc", VAL_TYPE.DOUBLE);
+ assertEquals(getRawResponse(), result, calculated, 0.0);
+
+ result = (Double)getStatResult("mr", "mean", VAL_TYPE.DOUBLE);
+ calculated = (Double)getStatResult("mr", "meanc", VAL_TYPE.DOUBLE);
+ assertEquals(getRawResponse(), result, calculated, 0.0);
+ }
+
+ @Test
+ public void divideTest() throws Exception {
+ Double result = (Double)getStatResult("dr", "sum", VAL_TYPE.DOUBLE);
+ Double calculated = (Double)getStatResult("dr", "sumc", VAL_TYPE.DOUBLE);
+ assertEquals(getRawResponse(), result, calculated, 0.0);
+
+ result = (Double)getStatResult("dr", "mean", VAL_TYPE.DOUBLE);
+ calculated = (Double)getStatResult("dr", "meanc", VAL_TYPE.DOUBLE);
+ assertEquals(getRawResponse(), result, calculated, 0.0);
+ }
+
+ @Test
+ public void powerTest() throws Exception {
+ double result = (Double)getStatResult("pr", "sum", VAL_TYPE.DOUBLE);
+ double calculated = (Double)getStatResult("pr", "sumc", VAL_TYPE.DOUBLE);
+ assertEquals(getRawResponse(), result, calculated, 0.0);
+ assertEquals(getRawResponse(), result, calculated, 0.0);
+
+ result = (Double)getStatResult("pr", "mean", VAL_TYPE.DOUBLE);
+ calculated = (Double)getStatResult("pr", "meanc", VAL_TYPE.DOUBLE);
+ assertEquals(getRawResponse(), result, calculated, 0.0);
+ assertEquals(getRawResponse(), result, calculated, 0.0);
+ }
+
+ @Test
+ public void negateTest() throws Exception {
+ double result = (Double)getStatResult("nr", "sum", VAL_TYPE.DOUBLE);
+ double calculated = (Double)getStatResult("nr", "sumc", VAL_TYPE.DOUBLE);
+ assertEquals(getRawResponse(), result, calculated, 0.0);
+
+ result = (Double)getStatResult("nr", "mean", VAL_TYPE.DOUBLE);
+ calculated = (Double)getStatResult("nr", "meanc", VAL_TYPE.DOUBLE);
+ assertEquals(getRawResponse(), result, calculated, 0.0);
+ }
+
+ @Test
+ public void absoluteValueTest() throws Exception {
+ double result = (Double)getStatResult("avr", "sum", VAL_TYPE.DOUBLE);
+ double calculated = (Double)getStatResult("avr", "sumc", VAL_TYPE.DOUBLE);
+ assertEquals(getRawResponse(), result, calculated, 0.0);
+
+ result = (Double)getStatResult("avr", "mean", VAL_TYPE.DOUBLE);
+ calculated = (Double)getStatResult("avr", "meanc", VAL_TYPE.DOUBLE);
+ assertEquals(getRawResponse(), result, calculated, 0.0);
+ }
+
+ @Test
+ public void constantNumberTest() throws Exception {
+ double result = (Double)getStatResult("cnr", "sum", VAL_TYPE.DOUBLE);
+ double calculated = (Double)getStatResult("cnr", "sumc", VAL_TYPE.DOUBLE);
+ assertEquals(getRawResponse(), result, calculated, 0.0);
+ assertEquals(getRawResponse(), result, calculated, 0.0);
+
+ result = (Double)getStatResult("cnr", "mean", VAL_TYPE.DOUBLE);
+ calculated = (Double)getStatResult("cnr", "meanc", VAL_TYPE.DOUBLE);
+ assertEquals(getRawResponse(), result, calculated, 0.0);
+ assertEquals(getRawResponse(), result, calculated, 0.0);
+ }
+
+ @Test
+ public void dateMathTest() throws Exception {
+ String result = (String)getStatResult("dmr", "median", VAL_TYPE.DATE);
+ String calculated = (String)getStatResult("dmr", "medianc", VAL_TYPE.DATE);
+ assertEquals(getRawResponse(), result, calculated);
+
+ result = (String)getStatResult("dmr", "max", VAL_TYPE.DATE);
+ calculated = (String)getStatResult("dmr", "maxc", VAL_TYPE.DATE);
+ assertEquals(getRawResponse(), result, calculated);
+ }
+
+ @Test
+ public void constantDateTest() throws Exception {
+ String result = (String)getStatResult("cdr", "median", VAL_TYPE.DATE);
+ String calculated = (String)getStatResult("cdr", "medianc", VAL_TYPE.DATE);
+ assertEquals(getRawResponse(), result, calculated);
+ assertEquals(getRawResponse(), result, calculated);
+
+ result = (String)getStatResult("cdr", "max", VAL_TYPE.DATE);
+ calculated = (String)getStatResult("cdr", "maxc", VAL_TYPE.DATE);
+ assertEquals(getRawResponse(), result, calculated);
+ }
+
+ @Test
+ public void constantStringTest() throws Exception {
+ String result = (String)getStatResult("csr", "min", VAL_TYPE.STRING);
+ String calculated = (String)getStatResult("csr", "minc", VAL_TYPE.STRING);
+ assertEquals(getRawResponse(), result, calculated);
+
+ result = (String)getStatResult("csr", "max", VAL_TYPE.STRING);
+ calculated = (String)getStatResult("csr", "maxc", VAL_TYPE.STRING);
+ assertEquals(getRawResponse(), result, calculated);
+ }
+
+ @Test
+ public void concatenateTest() throws Exception {
+ String result = (String)getStatResult("cr", "min", VAL_TYPE.STRING);
+ String calculated = (String)getStatResult("cr", "minc", VAL_TYPE.STRING);
+ assertEquals(getRawResponse(), result, calculated);
+
+ result = (String)getStatResult("cr", "max", VAL_TYPE.STRING);
+ calculated = (String)getStatResult("cr", "maxc", VAL_TYPE.STRING);
+ assertEquals(getRawResponse(), result, calculated);
+ }
+
+ @Test
+ public void missingTest() throws Exception {
+ double min = (Double)getStatResult("ms", "min", VAL_TYPE.DOUBLE);
+ double max = (Double)getStatResult("ms", "max", VAL_TYPE.DOUBLE);
+ assertEquals(getRawResponse(), 48.0d, max, 0.0);
+ assertEquals(getRawResponse(), 1.0d, min, 0.0);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyAbstractAnalyticsFacetCloudTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyAbstractAnalyticsFacetCloudTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyAbstractAnalyticsFacetCloudTest.java
new file mode 100644
index 0000000..783177d
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyAbstractAnalyticsFacetCloudTest.java
@@ -0,0 +1,194 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.legacy.facet;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+
+import org.apache.solr.analytics.legacy.LegacyAbstractAnalyticsCloudTest;
+import org.apache.solr.analytics.util.AnalyticsResponseHeadings;
+import org.apache.solr.analytics.util.MedianCalculator;
+import org.apache.solr.analytics.util.OrdinalCalculator;
+import org.apache.solr.common.util.NamedList;
+import org.junit.AfterClass;
+
+public class LegacyAbstractAnalyticsFacetCloudTest extends LegacyAbstractAnalyticsCloudTest {
+ protected static final HashMap<String,Object> defaults = new HashMap<>();
+
+ protected String latestType = "";
+
+ @AfterClass
+ public static void afterClassAbstractAnalysis() {
+ defaults.clear();
+ }
+
+ @SuppressWarnings("unchecked")
+ protected <T> ArrayList<T> getValueList(NamedList<Object> response, String infoName, String facetType, String facetName, String exprName, boolean includeMissing) {
+ NamedList<NamedList<Object>> facetList =
+ (NamedList<NamedList<Object>>)response.findRecursive(AnalyticsResponseHeadings.COMPLETED_OLD_HEADER,
+ infoName,
+ facetType,
+ facetName);
+
+ ArrayList<T> results = new ArrayList<>();
+ facetList.forEach( (name, expressions) -> {
+ if (!includeMissing && !name.equals("(MISSING)")) {
+ T result = (T)expressions.get(exprName);
+ if (result != null)
+ results.add(result);
+ }
+ });
+ return results;
+ }
+
+ protected boolean responseContainsFacetValue(NamedList<Object> response, String infoName, String facetType, String facetName, String facetValue) {
+ return null != response.findRecursive(AnalyticsResponseHeadings.COMPLETED_OLD_HEADER,
+ infoName,
+ facetType,
+ facetName,
+ facetValue);
+ }
+
+
+ public static void increment(List<Long> list, int idx){
+ Long i = list.remove(idx);
+ list.add(idx, i+1);
+ }
+
+ protected void setLatestType(String latestType) {
+ this.latestType = latestType;
+ }
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ public <T extends Number & Comparable<T>> ArrayList calculateFacetedNumberStat(ArrayList<ArrayList<T>> lists, String stat) {
+ ArrayList result;
+ if (stat.equals("median")) {
+ result = new ArrayList<Double>();
+ for (List<T> list : lists) {
+ result.add(MedianCalculator.getMedian(list));
+ }
+ } else if (stat.equals("mean")) {
+ result = new ArrayList<Double>();
+ for (List<T> list : lists) {
+ double d = 0;
+ for (T element : list) {
+ d += element.doubleValue();
+ }
+ result.add(d/list.size());
+ }
+ } else if (stat.equals("sum")) {
+ result = new ArrayList<Double>();
+ for (Collection<T> list : lists) {
+ double d = 0;
+ for (T element : list) {
+ d += element.doubleValue();
+ }
+ result.add(d);
+ }
+ } else if (stat.equals("sumOfSquares")) {
+ result = new ArrayList<Double>();
+ for (List<T> list : lists) {
+ double d = 0;
+ for (T element : list) {
+ d += element.doubleValue()*element.doubleValue();
+ }
+ result.add(d);
+ }
+ } else if (stat.equals("stddev")) {
+ result = new ArrayList<Double>();
+ for (List<T> list : lists) {
+ double sum = 0;
+ double sumSquares = 0;
+ for (T element : list) {
+ sum += element.doubleValue();
+ sumSquares += element.doubleValue()*element.doubleValue();
+ }
+ String res = Double.toString(Math.sqrt(sumSquares/list.size()-sum*sum/(list.size()*list.size())));
+ result.add(Double.parseDouble(res));
+ }
+ } else {
+ throw new IllegalArgumentException();
+ }
+ return result;
+ }
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ public <T extends Comparable<T>> ArrayList calculateFacetedStat(ArrayList<ArrayList<T>> lists, String stat) {
+ ArrayList result;
+ if (stat.contains("perc_")) {
+ result = new ArrayList<T>();
+ for (List<T> list : lists) {
+ if( list.size() == 0) continue;
+ int ord = (int) Math.ceil(Double.parseDouble(stat.substring(5))/100 * list.size()) - 1;
+ ArrayList<Integer> percs = new ArrayList<>(1);
+ percs.add(ord);
+ OrdinalCalculator.putOrdinalsInPosition(list, percs);
+ result.add(list.get(ord));
+ }
+ } else if (stat.equals("count")) {
+ result = new ArrayList<Long>();
+ for (List<T> list : lists) {
+ result.add((long)list.size());
+ }
+ } else if (stat.equals("missing")) {
+ result = new ArrayList<Long>();
+ for (ArrayList<T> list : lists) {
+ result.add(calculateMissing(list,latestType));
+ }
+ } else if (stat.equals("unique")) {
+ result = new ArrayList<Long>();
+ for (List<T> list : lists) {
+ HashSet<T> set = new HashSet<>();
+ set.addAll(list);
+ result.add((long)set.size());
+ }
+ } else if (stat.equals("max")) {
+ result = new ArrayList<T>();
+ for (List<T> list : lists) {
+ if( list.size() == 0) continue;
+ Collections.sort(list);
+ result.add(list.get(list.size()-1));
+ }
+ } else if (stat.equals("min")) {
+ result = new ArrayList<T>();
+ for (List<T> list : lists) {
+ if( list.size() == 0) continue;
+ Collections.sort((List<T>)list);
+ result.add(list.get(0));
+ }
+ } else {
+ result = null;
+ }
+ return result;
+ }
+
+ @SuppressWarnings("unchecked")
+ public <T extends Comparable<T>> Long calculateMissing(ArrayList<T> list, String type) {
+ T def = (T)defaults.get(type);
+ long miss = 0;
+ for (T element : list) {
+ if (element.compareTo(def)==0) {
+ miss++;
+ }
+ }
+ return Long.valueOf(miss);
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyAbstractAnalyticsFacetTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyAbstractAnalyticsFacetTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyAbstractAnalyticsFacetTest.java
new file mode 100644
index 0000000..68c9826
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyAbstractAnalyticsFacetTest.java
@@ -0,0 +1,342 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.legacy.facet;
+
+import java.io.ByteArrayInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Scanner;
+
+import org.apache.lucene.util.IOUtils;
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.analytics.util.AnalyticsResponseHeadings;
+import org.apache.solr.analytics.util.MedianCalculator;
+import org.apache.solr.analytics.util.OrdinalCalculator;
+import org.apache.solr.request.SolrQueryRequest;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+import com.google.common.collect.ObjectArrays;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpressionException;
+import javax.xml.xpath.XPathFactory;
+
+public class LegacyAbstractAnalyticsFacetTest extends SolrTestCaseJ4 {
+ protected static final HashMap<String,Object> defaults = new HashMap<>();
+
+ protected String latestType = "";
+
+ private static Document doc;
+ private static XPathFactory xPathFact;
+ private static String rawResponse;
+
+ @BeforeClass
+ public static void beforeClassAbstractAnalysis() {
+ xPathFact = XPathFactory.newInstance();
+ }
+
+ @AfterClass
+ public static void afterClassAbstractAnalysis() {
+ xPathFact = null;
+ doc = null;
+ rawResponse = null;
+ defaults.clear();
+ }
+
+ protected static void setResponse(String response) throws ParserConfigurationException, IOException, SAXException {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ factory.setNamespaceAware(true); // never forget this!
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ doc = builder.parse(new InputSource(new ByteArrayInputStream(response.getBytes(StandardCharsets.UTF_8))));
+ rawResponse = response;
+ }
+
+ protected String getRawResponse() {
+ return rawResponse;
+ }
+
+ protected Node getNode(String xPath) throws XPathExpressionException {
+ return (Node)xPathFact.newXPath().compile(xPath).evaluate(doc, XPathConstants.NODE);
+ }
+ private NodeList getNodes(String n1, String n2, String n3, String element, String n4) throws XPathExpressionException {
+ // Construct the XPath expression. The form better not change or all these will fail.
+ StringBuilder sb = new StringBuilder("/response/lst[@name='"+AnalyticsResponseHeadings.COMPLETED_OLD_HEADER+"']/lst[@name='").append(n1).append("']");
+ sb.append("/lst[@name='").append(n2).append("']");
+ sb.append("/lst[@name='").append(n3).append("']");
+ sb.append("/lst[@name!='(MISSING)']");
+ sb.append("//").append(element).append("[@name='").append(n4).append("']");
+ return (NodeList)xPathFact.newXPath().compile(sb.toString()).evaluate(doc, XPathConstants.NODESET);
+
+ }
+ protected ArrayList<String> getStringList(String n1, String n2, String n3, String element, String n4)
+ throws XPathExpressionException {
+ ArrayList<String> ret = new ArrayList<>();
+ NodeList nodes = getNodes(n1, n2, n3, element, n4);
+ for (int idx = 0; idx < nodes.getLength(); ++idx) {
+ ret.add(nodes.item(idx).getTextContent());
+ }
+ return ret;
+ }
+
+ protected ArrayList<Integer> getIntegerList(String n1, String n2, String n3, String element, String n4)
+ throws XPathExpressionException {
+ ArrayList<Integer> ret = new ArrayList<>();
+ NodeList nodes = getNodes(n1, n2, n3, element, n4);
+ for (int idx = 0; idx < nodes.getLength(); ++idx) {
+ ret.add(Integer.parseInt(nodes.item(idx).getTextContent()));
+ }
+ return ret;
+ }
+ protected ArrayList<Long> getLongList(String n1, String n2, String n3, String element, String n4)
+ throws XPathExpressionException {
+ ArrayList<Long> ret = new ArrayList<>();
+ NodeList nodes = getNodes(n1, n2, n3, element, n4);
+ for (int idx = 0; idx < nodes.getLength(); ++idx) {
+ ret.add(Long.parseLong(nodes.item(idx).getTextContent()));
+ }
+ return ret;
+ }
+ protected ArrayList<Float> getFloatList(String n1, String n2, String n3, String element, String n4)
+ throws XPathExpressionException {
+ ArrayList<Float> ret = new ArrayList<>();
+ NodeList nodes = getNodes(n1, n2, n3, element, n4);
+ for (int idx = 0; idx < nodes.getLength(); ++idx) {
+ ret.add(Float.parseFloat(nodes.item(idx).getTextContent()));
+ }
+ return ret;
+ }
+
+ protected ArrayList<Double> getDoubleList(String n1, String n2, String n3, String element, String n4)
+ throws XPathExpressionException {
+ ArrayList<Double> ret = new ArrayList<>();
+ NodeList nodes = getNodes(n1, n2, n3, element, n4);
+ for (int idx = 0; idx < nodes.getLength(); ++idx) {
+ ret.add(Double.parseDouble(nodes.item(idx).getTextContent()));
+ }
+ return ret;
+ }
+
+
+ public static void increment(List<Long> list, int idx){
+ Long i = list.remove(idx);
+ list.add(idx, i+1);
+ }
+
+ public static String[] filter(String...args){
+ List<String> l = new ArrayList<>();
+ for( int i=0; i <args.length; i+=2){
+ if( args[i+1].equals("0") || args[i+1].equals("0.0") ||
+ args[i+1].equals("1800-12-31T23:59:59Z") || args[i+1].equals("str0") ||
+ args[i+1].equals("this is the firststr0") ||
+ args[i+1].equals("this is the secondstr0") ){
+ continue;
+ }
+ l.add(args[i]);
+ l.add(args[i+1]);
+ }
+ return l.toArray(new String[0]);
+ }
+
+ protected void setLatestType(String latestType) {
+ this.latestType = latestType;
+ }
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ public <T extends Number & Comparable<T>> ArrayList calculateNumberStat(ArrayList<ArrayList<T>> lists, String stat) {
+ ArrayList result;
+ if (stat.equals("median")) {
+ result = new ArrayList<Double>();
+ for (List<T> list : lists) {
+ result.add(MedianCalculator.getMedian(list));
+ }
+ } else if (stat.equals("mean")) {
+ result = new ArrayList<Double>();
+ for (List<T> list : lists) {
+ double d = 0;
+ for (T element : list) {
+ d += element.doubleValue();
+ }
+ result.add(d/list.size());
+ }
+ } else if (stat.equals("sum")) {
+ result = new ArrayList<Double>();
+ for (Collection<T> list : lists) {
+ double d = 0;
+ for (T element : list) {
+ d += element.doubleValue();
+ }
+ result.add(d);
+ }
+ } else if (stat.equals("sumOfSquares")) {
+ result = new ArrayList<Double>();
+ for (List<T> list : lists) {
+ double d = 0;
+ for (T element : list) {
+ d += element.doubleValue()*element.doubleValue();
+ }
+ result.add(d);
+ }
+ } else if (stat.equals("stddev")) {
+ result = new ArrayList<Double>();
+ for (List<T> list : lists) {
+ double sum = 0;
+ double sumSquares = 0;
+ for (T element : list) {
+ sum += element.doubleValue();
+ sumSquares += element.doubleValue()*element.doubleValue();
+ }
+ String res = Double.toString(Math.sqrt(sumSquares/list.size()-sum*sum/(list.size()*list.size())));
+ result.add(Double.parseDouble(res));
+ }
+ } else {
+ throw new IllegalArgumentException();
+ }
+ return result;
+ }
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ public <T extends Comparable<T>> ArrayList calculateStat(ArrayList<ArrayList<T>> lists, String stat) {
+ ArrayList result;
+ if (stat.contains("perc_")) {
+ result = new ArrayList<T>();
+ for (List<T> list : lists) {
+ if( list.size() == 0) continue;
+ int ord = (int) Math.ceil(Double.parseDouble(stat.substring(5))/100 * list.size()) - 1;
+ ArrayList<Integer> percs = new ArrayList<>(1);
+ percs.add(ord);
+ OrdinalCalculator.putOrdinalsInPosition(list, percs);
+ result.add(list.get(ord));
+ }
+ } else if (stat.equals("count")) {
+ result = new ArrayList<Long>();
+ for (List<T> list : lists) {
+ //if( list.size() == 0) continue;
+ result.add((long)list.size());
+ }
+ } else if (stat.equals("missing")) {
+ result = new ArrayList<Long>();
+ for (ArrayList<T> list : lists) {
+ if( list.size() == 0) continue;
+ result.add(calculateMissing(list,latestType));
+ }
+ } else if (stat.equals("unique")) {
+ result = new ArrayList<Long>();
+ for (List<T> list : lists) {
+ HashSet<T> set = new HashSet<>();
+ set.addAll(list);
+ result.add((long)set.size());
+ }
+ } else if (stat.equals("max")) {
+ result = new ArrayList<T>();
+ for (List<T> list : lists) {
+ if( list.size() == 0) continue;
+ Collections.sort(list);
+ result.add(list.get(list.size()-1));
+ }
+ } else if (stat.equals("min")) {
+ result = new ArrayList<T>();
+ for (List<T> list : lists) {
+ if( list.size() == 0) continue;
+ Collections.sort((List<T>)list);
+ result.add(list.get(0));
+ }
+ } else {
+ result = null;
+ }
+ return result;
+ }
+
+ @SuppressWarnings("unchecked")
+ public <T extends Comparable<T>> Long calculateMissing(ArrayList<T> list, String type) {
+ T def = (T)defaults.get(type);
+ long miss = 0;
+ for (T element : list) {
+ if (element.compareTo(def)==0) {
+ miss++;
+ }
+ }
+ return Long.valueOf(miss);
+ }
+
+ public static SolrQueryRequest request(String...args){
+ return SolrTestCaseJ4.req( ObjectArrays.concat(BASEPARMS, args,String.class) );
+ }
+
+ public static final String[] BASEPARMS = new String[]{ "q", "*:*", "indent", "true", "olap", "true", "rows", "0" };
+
+
+ public static String[] fileToStringArr(Class<?> clazz, String fileName) throws FileNotFoundException {
+ InputStream in = clazz.getResourceAsStream("/solr/analytics/legacy/" + fileName);
+ if (in == null) throw new FileNotFoundException("Resource not found: " + fileName);
+ Scanner file = new Scanner(in, "UTF-8");
+ try {
+ ArrayList<String> strList = new ArrayList<>();
+ while (file.hasNextLine()) {
+ String line = file.nextLine();
+ if (line.length()<2) {
+ continue;
+ }
+ int commentStart = line.indexOf("//");
+ if (commentStart >= 0) {
+ line = line.substring(0,commentStart);
+ }
+ String[] param = line.split("=");
+ if (param.length != 2) {
+ continue;
+ }
+ strList.add(param[0]);
+ strList.add(param[1]);
+ }
+ return strList.toArray(new String[0]);
+ } finally {
+ IOUtils.closeWhileHandlingException(file, in);
+ }
+ }
+
+ protected void removeNodes(String xPath, List<Double> string) throws XPathExpressionException {
+ NodeList missingNodes = getNodes(xPath);
+ List<Double> result = new ArrayList<Double>();
+ for (int idx = 0; idx < missingNodes.getLength(); ++idx) {
+ result.add(Double.parseDouble(missingNodes.item(idx).getTextContent()));
+ }
+ string.removeAll(result);
+ }
+
+ protected NodeList getNodes(String xPath) throws XPathExpressionException {
+ StringBuilder sb = new StringBuilder(xPath);
+ return (NodeList) xPathFact.newXPath().compile(sb.toString()).evaluate(doc, XPathConstants.NODESET);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyFacetSortingTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyFacetSortingTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyFacetSortingTest.java
new file mode 100644
index 0000000..d89c713
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyFacetSortingTest.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.legacy.facet;
+
+import org.apache.solr.analytics.legacy.LegacyAbstractAnalyticsTest;
+import org.apache.solr.analytics.legacy.expression.LegacyExpressionTest;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class LegacyFacetSortingTest extends LegacyAbstractAnalyticsTest {
+ private static String fileName = "facetSorting.txt";
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ initCore("solrconfig-analytics.xml", "schema-analytics.xml");
+ h.update("<delete><query>*:*</query></delete>");
+
+ // The data set below is so generated that in bucket corresponding fieldFacet B, double_dd column has null values
+ // and in bucket C corresponding to fieldFacet C has null values for column long_ld.
+ // FieldFaceting occurs on string_sd field
+ assertU(adoc("id", "1001", "string_sd", "A", "double_dd", "" + 3, "long_ld", "" + 1));
+ assertU(adoc("id", "1002", "string_sd", "A", "double_dd", "" + 25, "long_ld", "" + 2));
+ assertU(adoc("id", "1003", "string_sd", "B", "long_ld", "" + 3));
+ assertU(adoc("id", "1004", "string_sd", "B", "long_ld", "" + 4));
+ assertU(adoc("id", "1005", "string_sd", "C", "double_dd", "" + 17));
+
+ assertU(commit());
+ String response = h.query(request(fileToStringArr(LegacyExpressionTest.class, fileName)));
+ setResponse(response);
+ }
+
+ @Test
+ public void addTest() throws Exception {
+ Double minResult = (Double) getStatResult("ar", "min", VAL_TYPE.DOUBLE);
+ Long maxResult = (Long) getStatResult("ar", "max", VAL_TYPE.LONG);
+ assertEquals(Double.valueOf(minResult), Double.valueOf(3.0));
+ assertEquals(Long.valueOf(maxResult),Long.valueOf(4));
+ }
+}
[18/20] lucene-solr:master: SOLR-11145,
SOLR-11146: Added comprehensive unit tests for Analytics Component
2.0 as well as analytics bug fixes.
Posted by dp...@apache.org.
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/DecimalNumericConversionFunction.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/DecimalNumericConversionFunction.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/DecimalNumericConversionFunction.java
new file mode 100644
index 0000000..df91c95
--- /dev/null
+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/DecimalNumericConversionFunction.java
@@ -0,0 +1,271 @@
+/*
+ * 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.function.mapping.DecimalNumericConversionFunction.ConvertDoubleFunction;
+import org.apache.solr.analytics.function.mapping.DecimalNumericConversionFunction.ConvertFloatFunction;
+import org.apache.solr.analytics.value.AnalyticsValueStream;
+import org.apache.solr.analytics.value.DoubleValue;
+import org.apache.solr.analytics.value.DoubleValueStream;
+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.IntValue.AbstractIntValue;
+import org.apache.solr.analytics.value.IntValueStream.AbstractIntValueStream;
+import org.apache.solr.analytics.value.LongValue.AbstractLongValue;
+import org.apache.solr.analytics.value.LongValueStream.AbstractLongValueStream;
+import org.apache.solr.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 -> (int)Math.round(val), val -> (long)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}.
+ */
+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}.
+ */
+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}.
+ */
+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}.
+ */
+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;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/EqualFunction.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/EqualFunction.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/EqualFunction.java
new file mode 100644
index 0000000..6e3c651
--- /dev/null
+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/EqualFunction.java
@@ -0,0 +1,238 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.function.mapping;
+
+import org.apache.solr.analytics.ExpressionFactory.CreatorFunction;
+import org.apache.solr.analytics.util.function.BooleanConsumer;
+import org.apache.solr.analytics.value.AnalyticsValue;
+import org.apache.solr.analytics.value.AnalyticsValueStream;
+import org.apache.solr.analytics.value.BooleanValue;
+import org.apache.solr.analytics.value.BooleanValueStream;
+import org.apache.solr.analytics.value.BooleanValue.AbstractBooleanValue;
+import org.apache.solr.analytics.value.BooleanValueStream.AbstractBooleanValueStream;
+import org.apache.solr.analytics.value.DoubleValueStream;
+import org.apache.solr.common.SolrException;
+import org.apache.solr.common.SolrException.ErrorCode;
+
+/**
+ * An equals mapping function, returning whether two values are equal.
+ * <p>
+ * Uses:
+ * <ul>
+ * <li>If two Values are passed in, a {@link BooleanValue} representing the equality of the two values for each document is returned.
+ * <li>If an {@link AnalyticsValue} and an {@link AnalyticsValueStream} are passed in,
+ * a {@link BooleanValueStream} representing the equality of the Value and each of the values of the ValueStream for the document is returned.
+ * </ul>
+ */
+public class EqualFunction {
+ public static final String name = "equal";
+ public static final CreatorFunction creatorFunction = (params -> {
+ if (params.length != 2) {
+ throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires 2 paramaters, " + params.length + " found.");
+ }
+
+ AnalyticsValueStream paramA = params[0];
+ AnalyticsValueStream paramB = params[1];
+
+ // Booleans aren't really comparable, so just enable the equal function
+ if (paramA instanceof BooleanValueStream && paramB instanceof BooleanValueStream) {
+ if (paramA instanceof BooleanValue) {
+ if (paramB instanceof BooleanValue) {
+ return new BooleanValueEqualFunction((BooleanValue)paramA,(BooleanValue)paramB);
+ }
+ return new BooleanStreamEqualFunction((BooleanValue)paramA,(BooleanValueStream)paramB);
+ } else if (paramB instanceof BooleanValue) {
+ return new BooleanStreamEqualFunction((BooleanValue)paramB,(BooleanValueStream)paramA);
+ }
+ } else if (paramA instanceof DoubleValueStream && paramB instanceof DoubleValueStream) {
+ return ComparisonFunction.createComparisonFunction(name, val -> {
+ return val == 0;
+ }, params);
+ } else if (paramA instanceof AnalyticsValue) {
+ // This means that the Objects created by the AnalyticsValueStreams are not comparable, so use the .equals() method instead
+ if (paramB instanceof AnalyticsValue) {
+ return new ValueEqualFunction((AnalyticsValue)paramA,(AnalyticsValue)paramB);
+ }
+ return new StreamEqualFunction((AnalyticsValue)paramA,paramB);
+ } else if (paramB instanceof AnalyticsValue) {
+ return new StreamEqualFunction((AnalyticsValue)paramB,paramA);
+ }
+ throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires that at least 1 parameter be single-valued.");
+ });
+}
+/**
+ * An equal function for two {@link BooleanValue}s.
+ */
+class BooleanValueEqualFunction extends AbstractBooleanValue {
+ private final BooleanValue exprA;
+ private final BooleanValue exprB;
+ public static final String name = EqualFunction.name;
+ private final String funcStr;
+ private final ExpressionType funcType;
+
+ public BooleanValueEqualFunction(BooleanValue exprA, BooleanValue exprB) {
+ this.exprA = exprA;
+ this.exprB = exprB;
+ this.funcStr = AnalyticsValueStream.createExpressionString(name,exprA,exprB);
+ this.funcType = AnalyticsValueStream.determineMappingPhase(funcStr,exprA,exprB);
+ }
+
+ private boolean exists = false;
+ @Override
+ public boolean getBoolean() {
+ boolean valueA = exprA.getBoolean();
+ boolean valueB = exprB.getBoolean();
+ exists = exprA.exists() && exprB.exists();
+ return exists ? valueA == valueB : false;
+ }
+ @Override
+ public boolean exists() {
+ return exists;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+ @Override
+ public String getExpressionStr() {
+ return funcStr;
+ }
+ @Override
+ public ExpressionType getExpressionType() {
+ return funcType;
+ }
+}
+/**
+ * An equal function for a {@link BooleanValue} and a {@link BooleanValueStream}.
+ */
+class BooleanStreamEqualFunction extends AbstractBooleanValueStream {
+ private final BooleanValue baseExpr;
+ private final BooleanValueStream compExpr;
+ public static final String name = EqualFunction.name;
+ private final String funcStr;
+ private final ExpressionType funcType;
+
+ public BooleanStreamEqualFunction(BooleanValue baseExpr, BooleanValueStream compExpr) throws SolrException {
+ this.baseExpr = baseExpr;
+ this.compExpr = compExpr;
+ this.funcStr = AnalyticsValueStream.createExpressionString(name,baseExpr,compExpr);
+ this.funcType = AnalyticsValueStream.determineMappingPhase(funcStr,baseExpr,compExpr);
+ }
+
+ @Override
+ public void streamBooleans(BooleanConsumer cons) {
+ boolean baseValue = baseExpr.getBoolean();
+ if (baseExpr.exists()) {
+ compExpr.streamBooleans(compValue -> cons.accept(baseValue == compValue));
+ }
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+ @Override
+ public String getExpressionStr() {
+ return funcStr;
+ }
+ @Override
+ public ExpressionType getExpressionType() {
+ return funcType;
+ }
+}
+/**
+ * A catch-all equal function for two {@link AnalyticsValue}s.
+ */
+class ValueEqualFunction extends AbstractBooleanValue {
+ private final AnalyticsValue exprA;
+ private final AnalyticsValue exprB;
+ public static final String name = EqualFunction.name;
+ private final String funcStr;
+ private final ExpressionType funcType;
+
+ public ValueEqualFunction(AnalyticsValue exprA, AnalyticsValue exprB) {
+ this.exprA = exprA;
+ this.exprB = exprB;
+ this.funcStr = AnalyticsValueStream.createExpressionString(name,exprA,exprB);
+ this.funcType = AnalyticsValueStream.determineMappingPhase(funcStr,exprA,exprB);
+ }
+
+ private boolean exists = false;
+ @Override
+ public boolean getBoolean() {
+ Object valueA = exprA.getObject();
+ Object valueB = exprB.getObject();
+ exists = exprA.exists() && exprB.exists();
+ return exists ? valueA.equals(valueB) : false;
+ }
+ @Override
+ public boolean exists() {
+ return exists;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+ @Override
+ public String getExpressionStr() {
+ return funcStr;
+ }
+ @Override
+ public ExpressionType getExpressionType() {
+ return funcType;
+ }
+}
+/**
+ * A catch-all equal function for an {@link AnalyticsValue} and an {@link AnalyticsValueStream}.
+ */
+class StreamEqualFunction extends AbstractBooleanValueStream {
+ private final AnalyticsValue baseExpr;
+ private final AnalyticsValueStream compExpr;
+ public static final String name = EqualFunction.name;
+ private final String funcStr;
+ private final ExpressionType funcType;
+
+ public StreamEqualFunction(AnalyticsValue baseExpr, AnalyticsValueStream compExpr) throws SolrException {
+ this.baseExpr = baseExpr;
+ this.compExpr = compExpr;
+ this.funcStr = AnalyticsValueStream.createExpressionString(name,baseExpr,compExpr);
+ this.funcType = AnalyticsValueStream.determineMappingPhase(funcStr,baseExpr,compExpr);
+ }
+
+ @Override
+ public void streamBooleans(BooleanConsumer cons) {
+ Object baseValue = baseExpr.getObject();
+ if (baseExpr.exists()) {
+ compExpr.streamObjects(compValue -> cons.accept(baseValue.equals(compValue)));
+ }
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+ @Override
+ public String getExpressionStr() {
+ return funcStr;
+ }
+ @Override
+ public ExpressionType getExpressionType() {
+ return funcType;
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/ExistsFunction.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/ExistsFunction.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/ExistsFunction.java
new file mode 100644
index 0000000..dbdca47
--- /dev/null
+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/ExistsFunction.java
@@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.function.mapping;
+
+import org.apache.solr.common.SolrException;
+import org.apache.solr.common.SolrException.ErrorCode;
+
+import org.apache.solr.analytics.ExpressionFactory.CreatorFunction;
+import org.apache.solr.analytics.value.AnalyticsValue;
+import org.apache.solr.analytics.value.AnalyticsValueStream;
+import org.apache.solr.analytics.value.BooleanValue;
+import org.apache.solr.analytics.value.BooleanValue.AbstractBooleanValue;
+
+/**
+ * A mapping function to test if a value.
+ * <p>
+ * Any {@link AnalyticsValueStream} can be passed in, and a {@link BooleanValue} will be returned representing whether a value exists.
+ */
+public class ExistsFunction {
+ public static final String name = "exists";
+ public static final CreatorFunction creatorFunction = (params -> {
+ if (params.length != 1) {
+ throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires 1 parameter.");
+ }
+ AnalyticsValueStream param = params[0];
+ if (param instanceof AnalyticsValue) {
+ return new ValueExistsFunction((AnalyticsValue)param);
+ }
+ return new ValueStreamExistsFunction(param);
+ });
+}
+/**
+ * Exists function that supports {@link AnalyticsValueStream}s.
+ */
+class ValueStreamExistsFunction extends AbstractBooleanValue {
+ private final AnalyticsValueStream param;
+ public static final String name = ExistsFunction.name;
+ private final String exprStr;
+ private final ExpressionType funcType;
+
+ public ValueStreamExistsFunction(AnalyticsValueStream param) throws SolrException {
+ this.param = param;
+ this.exprStr = AnalyticsValueStream.createExpressionString(name,param);
+ this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,param);
+ }
+
+ private boolean exists;
+ @Override
+ public boolean getBoolean() {
+ exists = false;
+ param.streamObjects(val -> exists = true);
+ return exists;
+ }
+ @Override
+ public boolean exists() {
+ return true;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+ @Override
+ public String getExpressionStr() {
+ return exprStr;
+ }
+ @Override
+ public ExpressionType getExpressionType() {
+ return funcType;
+ }
+}
+/**
+ * Exists function that supports {@link AnalyticsValue}s.
+ */
+class ValueExistsFunction extends AbstractBooleanValue {
+ private final AnalyticsValue param;
+ public static final String name = ExistsFunction.name;
+ private final String exprStr;
+ private final ExpressionType funcType;
+
+ public ValueExistsFunction(AnalyticsValue param) throws SolrException {
+ this.param = param;
+ this.exprStr = AnalyticsValueStream.createExpressionString(name,param);
+ this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,param);
+ }
+
+ @Override
+ public boolean getBoolean() {
+ param.getObject();
+ return param.exists();
+ }
+ @Override
+ public boolean exists() {
+ return true;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+ @Override
+ public String getExpressionStr() {
+ return exprStr;
+ }
+ @Override
+ public ExpressionType getExpressionType() {
+ return funcType;
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/FillMissingFunction.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/FillMissingFunction.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/FillMissingFunction.java
index 188d698..837bbe6 100644
--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/FillMissingFunction.java
+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/FillMissingFunction.java
@@ -41,6 +41,7 @@ import org.apache.solr.analytics.value.LongValueStream;
import org.apache.solr.analytics.value.StringValue;
import org.apache.solr.analytics.value.StringValueStream;
import org.apache.solr.analytics.value.AnalyticsValue.AbstractAnalyticsValue;
+import org.apache.solr.analytics.value.AnalyticsValueStream.AbstractAnalyticsValueStream;
import org.apache.solr.analytics.value.BooleanValue.AbstractBooleanValue;
import org.apache.solr.analytics.value.BooleanValueStream.AbstractBooleanValueStream;
import org.apache.solr.analytics.value.DateValue.AbstractDateValue;
@@ -71,7 +72,7 @@ import org.apache.solr.common.SolrException.ErrorCode;
* (e.g. {@value #name}(double,int) will return a double)
*/
public class FillMissingFunction {
- public static final String name = "fillmissing";
+ public static final String name = "fill_missing";
public static final CreatorFunction creatorFunction = (params -> {
if (params.length != 2) {
@@ -128,7 +129,7 @@ public class FillMissingFunction {
return new StreamFillMissingFunction(baseExpr,fillExpr);
});
}
-class StreamFillMissingFunction implements AnalyticsValueStream, Consumer<Object> {
+class StreamFillMissingFunction extends AbstractAnalyticsValueStream implements Consumer<Object> {
private final AnalyticsValueStream baseExpr;
private final AnalyticsValueStream fillExpr;
public static final String name = FillMissingFunction.name;
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/FilterFunction.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/FilterFunction.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/FilterFunction.java
index 84a3e30..afd2c2a 100644
--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/FilterFunction.java
+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/FilterFunction.java
@@ -41,6 +41,7 @@ import org.apache.solr.analytics.value.LongValueStream;
import org.apache.solr.analytics.value.StringValue;
import org.apache.solr.analytics.value.StringValueStream;
import org.apache.solr.analytics.value.AnalyticsValue.AbstractAnalyticsValue;
+import org.apache.solr.analytics.value.AnalyticsValueStream.AbstractAnalyticsValueStream;
import org.apache.solr.analytics.value.BooleanValue.AbstractBooleanValue;
import org.apache.solr.analytics.value.BooleanValueStream.AbstractBooleanValueStream;
import org.apache.solr.analytics.value.DateValue.AbstractDateValue;
@@ -128,7 +129,7 @@ public class FilterFunction {
return new StreamFilterFunction(baseExpr,filterExpr);
});
}
-class StreamFilterFunction implements AnalyticsValueStream {
+class StreamFilterFunction extends AbstractAnalyticsValueStream {
private final AnalyticsValueStream baseExpr;
private final BooleanValue filterExpr;
public static final String name = FilterFunction.name;
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/IfFunction.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/IfFunction.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/IfFunction.java
index e2fd163..0e4f1b9 100644
--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/IfFunction.java
+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/IfFunction.java
@@ -41,6 +41,7 @@ import org.apache.solr.analytics.value.LongValueStream;
import org.apache.solr.analytics.value.StringValue;
import org.apache.solr.analytics.value.StringValueStream;
import org.apache.solr.analytics.value.AnalyticsValue.AbstractAnalyticsValue;
+import org.apache.solr.analytics.value.AnalyticsValueStream.AbstractAnalyticsValueStream;
import org.apache.solr.analytics.value.BooleanValue.AbstractBooleanValue;
import org.apache.solr.analytics.value.BooleanValueStream.AbstractBooleanValueStream;
import org.apache.solr.analytics.value.DateValue.AbstractDateValue;
@@ -70,7 +71,7 @@ import org.apache.solr.common.SolrException.ErrorCode;
* If two {@link AnalyticsValue}s are passed as the if-else parameters, an {@link AnalyticsValue} will be returned.
* If either parameter isn't single-valued, a {@link AnalyticsValueStream} will be returned.
*/
-public class IfFunction implements AnalyticsValueStream {
+public class IfFunction extends AbstractAnalyticsValueStream {
private final BooleanValue ifExpr;
private final AnalyticsValueStream thenExpr;
private final AnalyticsValueStream elseExpr;
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/JoinFunction.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/JoinFunction.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/JoinFunction.java
deleted file mode 100644
index 528aae2..0000000
--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/JoinFunction.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.solr.analytics.function.mapping;
-
-import org.apache.solr.common.SolrException;
-import org.apache.solr.common.SolrException.ErrorCode;
-import org.apache.solr.analytics.ExpressionFactory.CreatorFunction;
-import org.apache.solr.analytics.value.AnalyticsValueStream;
-import org.apache.solr.analytics.value.StringValue;
-import org.apache.solr.analytics.value.StringValueStream;
-import org.apache.solr.analytics.value.constant.ConstantStringValue;
-
-/**
- * A string join mapping function.
- * <p>
- * Takes a {@link StringValueStream} as the first parameter and a {@link ConstantStringValue} (e.g. ",") as the second parameter
- * and a {@link StringValue} is returned.
- * <br>
- * The second parameter is used as the separator while joining all values the first parameter has for a document.
- * No order is guaranteed while joining the string values
- */
-public class JoinFunction {
- public static final String name = "join";
- public static final CreatorFunction creatorFunction = (params -> {
- if (params.length != 2) {
- throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires 2 parameters.");
- }
- AnalyticsValueStream param1 = params[0];
- AnalyticsValueStream param2 = params[1];
- if (!(param2 instanceof ConstantStringValue)) {
- throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires the second parameter to be a constant string");
- }
- String sep = ((StringValue)param2).getString();
- if (!(param1 instanceof StringValueStream)) {
- throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires the first parameter to be castable to a string");
- }
- if (param1 instanceof StringValue) {
- return param1;
- }
- String uniqueName = name + "(" + sep + ")";
- return LambdaFunction.createStringLambdaFunction(uniqueName, (a,b) -> a + sep + b, (StringValueStream)params[0]);
- });
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/LogicFunction.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/LogicFunction.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/LogicFunction.java
index 806cb0a..93dea53 100644
--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/LogicFunction.java
+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/LogicFunction.java
@@ -53,7 +53,7 @@ public class LogicFunction {
AnalyticsValueStream param1 = params[0];
AnalyticsValueStream param2 = params[1];
if (param1 instanceof BooleanValueStream && param2 instanceof BooleanValueStream) {
- return LambdaFunction.createBooleanLambdaFunction(name, (a,b) -> a && b, (BooleanValueStream)param1, (BooleanValueStream)param2);
+ return LambdaFunction.createBooleanLambdaFunction(name, comp, (BooleanValueStream)param1, (BooleanValueStream)param2);
}
throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires boolean parameters.");
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/NumericConvertFunction.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/NumericConvertFunction.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/NumericConvertFunction.java
deleted file mode 100644
index 2381f60..0000000
--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/NumericConvertFunction.java
+++ /dev/null
@@ -1,256 +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.IntValueStream;
-import org.apache.solr.analytics.value.LongValue;
-import org.apache.solr.analytics.value.LongValueStream;
-import org.apache.solr.analytics.value.IntValue.AbstractIntValue;
-import org.apache.solr.analytics.value.IntValueStream.AbstractIntValueStream;
-import org.apache.solr.analytics.value.LongValue.AbstractLongValue;
-import org.apache.solr.analytics.value.LongValueStream.AbstractLongValueStream;
-import org.apache.solr.common.SolrException;
-import org.apache.solr.common.SolrException.ErrorCode;
-
-/**
- * An abstract numeric converting mapping function. For example "round()" would convert a float to an int and a double to a long.
- * <p>
- * Takes a numeric Double or Float ValueStream or Value and returns a Long or Int ValueStream or Value, repectively.
- */
-public class NumericConvertFunction {
-
- private static LongValueStream createConvertFunction(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 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 NumericConvertFunction.createConvertFunction(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 NumericConvertFunction.createConvertFunction(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 NumericConvertFunction.createConvertFunction(name, val -> (int)Math.round(val), val -> (long)Math.round(val), params);
- });
- }
-
-}
-@FunctionalInterface
-interface ConvertFloatFunction {
- public int convert(float value);
-}
-@FunctionalInterface
-interface ConvertDoubleFunction {
- public long convert(double value);
-}
-/**
- * A function to convert a {@link FloatValue} to a {@link IntValue}.
- */
-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}.
- */
-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}.
- */
-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}.
- */
-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;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/RemoveFunction.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/RemoveFunction.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/RemoveFunction.java
index 5800a1b..3ae070b 100644
--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/RemoveFunction.java
+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/RemoveFunction.java
@@ -26,6 +26,7 @@ import org.apache.solr.analytics.util.function.BooleanConsumer;
import org.apache.solr.analytics.util.function.FloatConsumer;
import org.apache.solr.analytics.value.AnalyticsValue;
import org.apache.solr.analytics.value.AnalyticsValueStream;
+import org.apache.solr.analytics.value.AnalyticsValueStream.AbstractAnalyticsValueStream;
import org.apache.solr.analytics.value.BooleanValue;
import org.apache.solr.analytics.value.BooleanValueStream;
import org.apache.solr.analytics.value.DateValue;
@@ -77,7 +78,7 @@ public class RemoveFunction {
throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires 2 paramaters, " + params.length + " found.");
}
if (!(params[1] instanceof AnalyticsValue)) {
- throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires the remove paramater to be single-valued.");
+ throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires the remove (2nd) paramater to be single-valued.");
}
AnalyticsValueStream baseExpr = params[0];
@@ -131,7 +132,7 @@ public class RemoveFunction {
return new StreamRemoveFunction(baseExpr,removeExpr);
});
}
-class StreamRemoveFunction implements AnalyticsValueStream {
+class StreamRemoveFunction extends AbstractAnalyticsValueStream {
private final AnalyticsValueStream baseExpr;
private final AnalyticsValue removeExpr;
public static final String name = RemoveFunction.name;
@@ -150,7 +151,7 @@ class StreamRemoveFunction implements AnalyticsValueStream {
Object removeValue = removeExpr.getObject();
if (removeExpr.exists()) {
baseExpr.streamObjects(value -> {
- if (removeValue.equals(value)) cons.accept(value);
+ if (!removeValue.equals(value)) cons.accept(value);
});
} else {
baseExpr.streamObjects(cons);
@@ -193,7 +194,7 @@ class ValueRemoveFunction extends AbstractAnalyticsValue {
Object value = baseExpr.getObject();
exists = false;
if (baseExpr.exists()) {
- exists = value.equals(removeExpr.toString()) ? removeExpr.exists()? false : true : true;
+ exists = value.equals(removeExpr.getObject()) ? (removeExpr.exists() ? false : true) : true;
}
return value;
}
@@ -237,7 +238,7 @@ class BooleanStreamRemoveFunction extends AbstractBooleanValueStream {
boolean removeValue = removeExpr.getBoolean();
if (removeExpr.exists()) {
baseExpr.streamBooleans(value -> {
- if (removeValue==value) cons.accept(value);
+ if (removeValue != value) cons.accept(value);
});
} else {
baseExpr.streamBooleans(cons);
@@ -280,7 +281,7 @@ class BooleanRemoveFunction extends AbstractBooleanValue {
boolean value = baseExpr.getBoolean();
exists = false;
if (baseExpr.exists()) {
- exists = value==removeExpr.getBoolean() ? removeExpr.exists()? false : true : true;
+ exists = value==removeExpr.getBoolean() ? (removeExpr.exists() ? false : true) : true;
}
return value;
}
@@ -321,7 +322,7 @@ class IntStreamRemoveFunction extends AbstractIntValueStream {
int removeValue = removeExpr.getInt();
if (removeExpr.exists()) {
baseExpr.streamInts(value -> {
- if (removeValue==value) cons.accept(value);
+ if (removeValue != value) cons.accept(value);
});
} else {
baseExpr.streamInts(cons);
@@ -362,7 +363,7 @@ class IntRemoveFunction extends AbstractIntValue {
int value = baseExpr.getInt();
exists = false;
if (baseExpr.exists()) {
- exists = value==removeExpr.getInt() ? removeExpr.exists()? false : true : true;
+ exists = value==removeExpr.getInt() ? (removeExpr.exists() ? false : true) : true;
}
return value;
}
@@ -403,7 +404,7 @@ class LongStreamRemoveFunction extends AbstractLongValueStream {
long removeValue = removeExpr.getLong();
if (removeExpr.exists()) {
baseExpr.streamLongs(value -> {
- if (removeValue==value) cons.accept(value);
+ if (removeValue != value) cons.accept(value);
});
} else {
baseExpr.streamLongs(cons);
@@ -444,7 +445,7 @@ class LongRemoveFunction extends AbstractLongValue {
long value = baseExpr.getLong();
exists = false;
if (baseExpr.exists()) {
- exists = value==removeExpr.getLong() ? removeExpr.exists()? false : true : true;
+ exists = value==removeExpr.getLong() ? (removeExpr.exists() ? false : true) : true;
}
return value;
}
@@ -485,7 +486,7 @@ class FloatStreamRemoveFunction extends AbstractFloatValueStream {
float removeValue = removeExpr.getFloat();
if (removeExpr.exists()) {
baseExpr.streamFloats(value -> {
- if (removeValue==value) cons.accept(value);
+ if (removeValue != value) cons.accept(value);
});
} else {
baseExpr.streamFloats(cons);
@@ -526,7 +527,7 @@ class FloatRemoveFunction extends AbstractFloatValue {
float value = baseExpr.getFloat();
exists = false;
if (baseExpr.exists()) {
- exists = value==removeExpr.getFloat() ? removeExpr.exists()? false : true : true;
+ exists = value==removeExpr.getFloat() ? (removeExpr.exists() ? false : true) : true;
}
return value;
}
@@ -567,7 +568,7 @@ class DoubleStreamRemoveFunction extends AbstractDoubleValueStream {
double removeValue = removeExpr.getDouble();
if (removeExpr.exists()) {
baseExpr.streamDoubles(value -> {
- if (removeValue==value) cons.accept(value);
+ if (removeValue != value) cons.accept(value);
});
} else {
baseExpr.streamDoubles(cons);
@@ -608,7 +609,7 @@ class DoubleRemoveFunction extends AbstractDoubleValue {
double value = baseExpr.getDouble();
exists = false;
if (baseExpr.exists()) {
- exists = value==removeExpr.getDouble() ? removeExpr.exists()? false : true : true;
+ exists = value==removeExpr.getDouble() ? (removeExpr.exists() ? false : true) : true;
}
return value;
}
@@ -649,7 +650,7 @@ class DateStreamRemoveFunction extends AbstractDateValueStream {
long removeValue = removeExpr.getLong();
if (removeExpr.exists()) {
baseExpr.streamLongs(value -> {
- if (removeValue==value) cons.accept(value);
+ if (removeValue != value) cons.accept(value);
});
} else {
baseExpr.streamLongs(cons);
@@ -690,7 +691,7 @@ class DateRemoveFunction extends AbstractDateValue {
long value = baseExpr.getLong();
exists = false;
if (baseExpr.exists()) {
- exists = value==removeExpr.getLong() ? removeExpr.exists() ? false : true : true;
+ exists = value==removeExpr.getLong() ? (removeExpr.exists() ? false : true) : true;
}
return value;
}
@@ -728,10 +729,10 @@ class StringStreamRemoveFunction extends AbstractStringValueStream {
@Override
public void streamStrings(Consumer<String> cons) {
- String removeValue = removeExpr.toString();
+ String removeValue = removeExpr.getString();
if (removeExpr.exists()) {
baseExpr.streamStrings(value -> {
- if (removeValue.equals(value)) cons.accept(value);
+ if (!removeValue.equals(value)) cons.accept(value);
});
} else {
baseExpr.streamStrings(cons);
@@ -772,7 +773,7 @@ class StringRemoveFunction extends AbstractStringValue {
String value = baseExpr.getString();
exists = false;
if (baseExpr.exists()) {
- exists = value.equals(removeExpr.getString()) ? removeExpr.exists()? false : true : true;
+ exists = value.equals(removeExpr.getString()) ? (removeExpr.exists() ? false : true) : true;
}
return value;
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/ReplaceFunction.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/ReplaceFunction.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/ReplaceFunction.java
index 0d9e278..f878393 100644
--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/ReplaceFunction.java
+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/ReplaceFunction.java
@@ -41,6 +41,7 @@ import org.apache.solr.analytics.value.LongValueStream;
import org.apache.solr.analytics.value.StringValue;
import org.apache.solr.analytics.value.StringValueStream;
import org.apache.solr.analytics.value.AnalyticsValue.AbstractAnalyticsValue;
+import org.apache.solr.analytics.value.AnalyticsValueStream.AbstractAnalyticsValueStream;
import org.apache.solr.analytics.value.BooleanValue.AbstractBooleanValue;
import org.apache.solr.analytics.value.BooleanValueStream.AbstractBooleanValueStream;
import org.apache.solr.analytics.value.DateValue.AbstractDateValue;
@@ -136,7 +137,7 @@ public class ReplaceFunction {
});
}
-class StreamReplaceFunction implements AnalyticsValueStream {
+class StreamReplaceFunction extends AbstractAnalyticsValueStream {
private final AnalyticsValueStream baseExpr;
private final AnalyticsValue compExpr;
private final AnalyticsValue fillExpr;
@@ -156,8 +157,8 @@ class StreamReplaceFunction implements AnalyticsValueStream {
public void streamObjects(Consumer<Object> cons) {
Object compValue = compExpr.getObject();
if (compExpr.exists()) {
- Object fillValue = fillExpr.getObject();
- boolean fillExists = fillExpr.exists();
+ final Object fillValue = fillExpr.getObject();
+ final boolean fillExists = fillExpr.exists();
baseExpr.streamObjects(value -> {
if (value.equals(compValue)) {
if (fillExists) {
@@ -209,7 +210,7 @@ class ValueReplaceFunction extends AbstractAnalyticsValue {
Object value = baseExpr.getObject();
exists = baseExpr.exists();
Object comp = compExpr.getObject();
- if (value.equals(comp) && exists==compExpr.exists()) {
+ if (exists && compExpr.exists() && value.equals(comp)) {
value = fillExpr.getObject();
exists = fillExpr.exists();
}
@@ -253,10 +254,10 @@ class BooleanStreamReplaceFunction extends AbstractBooleanValueStream {
public void streamBooleans(BooleanConsumer cons) {
boolean compValue = compExpr.getBoolean();
if (compExpr.exists()) {
- boolean fillValue = fillExpr.getBoolean();
- boolean fillExists = fillExpr.exists();
+ final boolean fillValue = fillExpr.getBoolean();
+ final boolean fillExists = fillExpr.exists();
baseExpr.streamBooleans(value -> {
- if (value==compValue) {
+ if (value == compValue) {
if (fillExists) {
cons.accept(fillValue);
}
@@ -306,7 +307,7 @@ class BooleanReplaceFunction extends AbstractBooleanValue {
boolean value = baseExpr.getBoolean();
exists = baseExpr.exists();
boolean comp = compExpr.getBoolean();
- if (value==comp && exists==compExpr.exists()) {
+ if (exists && compExpr.exists() && value == comp) {
value = fillExpr.getBoolean();
exists = fillExpr.exists();
}
@@ -350,10 +351,10 @@ class IntStreamReplaceFunction extends AbstractIntValueStream {
public void streamInts(IntConsumer cons) {
int compValue = compExpr.getInt();
if (compExpr.exists()) {
- int fillValue = fillExpr.getInt();
- boolean fillExists = fillExpr.exists();
+ final int fillValue = fillExpr.getInt();
+ final boolean fillExists = fillExpr.exists();
baseExpr.streamInts(value -> {
- if (value==compValue) {
+ if (value == compValue) {
if (fillExists) {
cons.accept(fillValue);
}
@@ -403,7 +404,7 @@ class IntReplaceFunction extends AbstractIntValue {
int value = baseExpr.getInt();
exists = baseExpr.exists();
int comp = compExpr.getInt();
- if (value==comp && exists==compExpr.exists()) {
+ if (exists && compExpr.exists() && value == comp) {
value = fillExpr.getInt();
exists = fillExpr.exists();
}
@@ -447,10 +448,10 @@ class LongStreamReplaceFunction extends AbstractLongValueStream {
public void streamLongs(LongConsumer cons) {
long compValue = compExpr.getLong();
if (compExpr.exists()) {
- long fillValue = fillExpr.getLong();
- boolean fillExists = fillExpr.exists();
+ final long fillValue = fillExpr.getLong();
+ final boolean fillExists = fillExpr.exists();
baseExpr.streamLongs(value -> {
- if (value==compValue) {
+ if (value == compValue) {
if (fillExists) {
cons.accept(fillValue);
}
@@ -500,7 +501,7 @@ class LongReplaceFunction extends AbstractLongValue {
long value = baseExpr.getLong();
exists = baseExpr.exists();
long comp = compExpr.getLong();
- if (value==comp && exists==compExpr.exists()) {
+ if (exists && compExpr.exists() && value == comp) {
value = fillExpr.getLong();
exists = fillExpr.exists();
}
@@ -544,10 +545,10 @@ class FloatStreamReplaceFunction extends AbstractFloatValueStream {
public void streamFloats(FloatConsumer cons) {
float compValue = compExpr.getFloat();
if (compExpr.exists()) {
- float fillValue = fillExpr.getFloat();
- boolean fillExists = fillExpr.exists();
+ final float fillValue = fillExpr.getFloat();
+ final boolean fillExists = fillExpr.exists();
baseExpr.streamFloats(value -> {
- if (value==compValue) {
+ if (value == compValue) {
if (fillExists) {
cons.accept(fillValue);
}
@@ -597,7 +598,7 @@ class FloatReplaceFunction extends AbstractFloatValue {
float value = baseExpr.getFloat();
exists = baseExpr.exists();
float comp = compExpr.getFloat();
- if (value==comp && exists==compExpr.exists()) {
+ if (exists && compExpr.exists() && value == comp) {
value = fillExpr.getFloat();
exists = fillExpr.exists();
}
@@ -641,10 +642,10 @@ class DoubleStreamReplaceFunction extends AbstractDoubleValueStream {
public void streamDoubles(DoubleConsumer cons) {
double compValue = compExpr.getDouble();
if (compExpr.exists()) {
- double fillValue = fillExpr.getDouble();
- boolean fillExists = fillExpr.exists();
+ final double fillValue = fillExpr.getDouble();
+ final boolean fillExists = fillExpr.exists();
baseExpr.streamDoubles(value -> {
- if (value==compValue) {
+ if (value == compValue) {
if (fillExists) {
cons.accept(fillValue);
}
@@ -694,7 +695,7 @@ class DoubleReplaceFunction extends AbstractDoubleValue {
double value = baseExpr.getDouble();
exists = baseExpr.exists();
double comp = compExpr.getDouble();
- if (value==comp && exists==compExpr.exists()) {
+ if (exists && compExpr.exists() && value == comp) {
value = fillExpr.getDouble();
exists = fillExpr.exists();
}
@@ -738,10 +739,10 @@ class DateStreamReplaceFunction extends AbstractDateValueStream {
public void streamLongs(LongConsumer cons) {
long compValue = compExpr.getLong();
if (compExpr.exists()) {
- long fillValue = fillExpr.getLong();
- boolean fillExists = fillExpr.exists();
+ final long fillValue = fillExpr.getLong();
+ final boolean fillExists = fillExpr.exists();
baseExpr.streamLongs(value -> {
- if (value==compValue) {
+ if (value == compValue) {
if (fillExists) {
cons.accept(fillValue);
}
@@ -791,7 +792,7 @@ class DateReplaceFunction extends AbstractDateValue {
long value = baseExpr.getLong();
exists = baseExpr.exists();
long comp = compExpr.getLong();
- if (value==comp && exists==compExpr.exists()) {
+ if (exists && compExpr.exists() && value == comp) {
value = fillExpr.getLong();
exists = fillExpr.exists();
}
@@ -833,10 +834,10 @@ class StringStreamReplaceFunction extends AbstractStringValueStream {
@Override
public void streamStrings(Consumer<String> cons) {
- String compValue = compExpr.toString();
+ String compValue = compExpr.getString();
if (compExpr.exists()) {
- String fillValue = fillExpr.toString();
- boolean fillExists = fillExpr.exists();
+ final String fillValue = fillExpr.getString();
+ final boolean fillExists = fillExpr.exists();
baseExpr.streamStrings(value -> {
if (value.equals(compValue)) {
if (fillExists) {
@@ -888,7 +889,7 @@ class StringReplaceFunction extends AbstractStringValue {
String value = baseExpr.getString();
exists = baseExpr.exists();
String comp = compExpr.getString();
- if (value.equals(comp) && exists==compExpr.exists()) {
+ if (exists && compExpr.exists() && value.equals(comp)) {
value = fillExpr.getString();
exists = fillExpr.exists();
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/TopFunction.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/TopFunction.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/TopFunction.java
index 801d1ea..a0d8754 100644
--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/TopFunction.java
+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/TopFunction.java
@@ -141,7 +141,7 @@ public class TopFunction {
}
if (param instanceof StringValueStream) {
if (params.length == 1) {
- return LambdaFunction.createStringLambdaFunction(name, (a,b) -> (a.compareTo(b)>=0)? a:b, (StringValueStream)param);
+ return LambdaFunction.createStringLambdaFunction(name, (a,b) -> (a.compareTo(b)>0)? a:b, (StringValueStream)param);
}
StringValue[] castedParams = new StringValue[params.length];
boolean tryNextType = false;
@@ -154,7 +154,7 @@ public class TopFunction {
}
}
if (!tryNextType) {
- return LambdaFunction.createStringLambdaFunction(name, (a,b) -> (a.compareTo(b)>=0)? a:b, castedParams, false);
+ return LambdaFunction.createStringLambdaFunction(name, (a,b) -> (a.compareTo(b)>0)? a:b, castedParams, false);
}
}
throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires a comparable parameter. " +
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/reduction/DocCountFunction.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/reduction/DocCountFunction.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/reduction/DocCountFunction.java
index f009b59..d3e4be1 100644
--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/reduction/DocCountFunction.java
+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/reduction/DocCountFunction.java
@@ -35,7 +35,7 @@ import org.apache.solr.common.SolrException.ErrorCode;
*/
public class DocCountFunction extends AbstractLongValue implements ReductionFunction {
private CountCollector collector;
- public static final String name = "docCount";
+ public static final String name = "doc_count";
private final String exprStr;
public static final CreatorFunction creatorFunction = (params -> {
if (params.length == 0) {
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/reduction/MeanFunction.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/reduction/MeanFunction.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/reduction/MeanFunction.java
new file mode 100644
index 0000000..322f2f2
--- /dev/null
+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/reduction/MeanFunction.java
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.function.reduction;
+
+import java.io.Serializable;
+import java.util.function.UnaryOperator;
+
+import org.apache.solr.analytics.ExpressionFactory.CreatorFunction;
+import org.apache.solr.analytics.function.ReductionFunction;
+import org.apache.solr.analytics.function.reduction.data.CountCollector;
+import org.apache.solr.analytics.function.reduction.data.CountCollector.ExpressionCountCollector;
+import org.apache.solr.analytics.function.reduction.data.ReductionData;
+import org.apache.solr.analytics.function.reduction.data.ReductionDataCollector;
+import org.apache.solr.analytics.function.reduction.data.SumCollector;
+import org.apache.solr.analytics.value.AnalyticsValueStream;
+import org.apache.solr.analytics.value.DoubleValueStream;
+import org.apache.solr.analytics.value.DoubleValue.AbstractDoubleValue;
+import org.apache.solr.common.SolrException;
+import org.apache.solr.common.SolrException.ErrorCode;
+
+/**
+ * A reduction function which returns the mean of the values of the given expression.
+ */
+public class MeanFunction extends AbstractDoubleValue implements ReductionFunction {
+ private SumCollector sumCollector;
+ private CountCollector countCollector;
+ public static final String name = "mean";
+ private final String exprStr;
+ public static final CreatorFunction creatorFunction = (params -> {
+ if (params.length != 1) {
+ throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires 1 paramater, " + params.length + " found.");
+ }
+ DoubleValueStream casted;
+ try {
+ casted = (DoubleValueStream) params[0];
+ }
+ catch (ClassCastException e) {
+ throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires numeric parameter. " +
+ "Incorrect parameter: "+params[0].getExpressionStr());
+ }
+ return new MeanFunction(casted);
+ });
+
+ public MeanFunction(DoubleValueStream param) {
+ this.sumCollector = new SumCollector(param);
+ this.countCollector = new ExpressionCountCollector(param);
+ this.exprStr = AnalyticsValueStream.createExpressionString(name,param);
+ }
+
+ @Override
+ public double getDouble() {
+ return (countCollector.count() > 0)? sumCollector.sum() / countCollector.count() : 0;
+ }
+ @Override
+ public boolean exists() {
+ return sumCollector.exists() && countCollector.count() > 0;
+ }
+
+ @Override
+ public void synchronizeDataCollectors(UnaryOperator<ReductionDataCollector<?>> sync) {
+ sumCollector = (SumCollector) sync.apply(sumCollector);
+ countCollector = (CountCollector) sync.apply(countCollector);
+ }
+
+ @Override
+ public String getExpressionStr() {
+ return exprStr;
+ }
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public ExpressionType getExpressionType() {
+ return ExpressionType.REDUCTION;
+ }
+
+ protected static class SumData extends ReductionData implements Serializable {
+ private static final long serialVersionUID = 5920718235872898338L;
+ double sum;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/reduction/OrdinalFunction.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/reduction/OrdinalFunction.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/reduction/OrdinalFunction.java
index 0b86cdf..cd05947 100644
--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/reduction/OrdinalFunction.java
+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/reduction/OrdinalFunction.java
@@ -41,7 +41,7 @@ import org.apache.solr.analytics.value.FloatValue.AbstractFloatValue;
import org.apache.solr.analytics.value.IntValue.AbstractIntValue;
import org.apache.solr.analytics.value.LongValue.AbstractLongValue;
import org.apache.solr.analytics.value.StringValue.AbstractStringValue;
-import org.apache.solr.analytics.value.constant.ConstantIntValue;
+import org.apache.solr.analytics.value.constant.ConstantValue;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrException.ErrorCode;
@@ -56,7 +56,7 @@ public class OrdinalFunction {
}
AnalyticsValueStream percValue = params[0];
int ord = 0;
- if (params[0] instanceof ConstantIntValue) {
+ if (params[0] instanceof IntValue && params[0] instanceof ConstantValue) {
ord = ((IntValue)percValue).getInt();
if (ord == 0) {
throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires the ordinal to be >= 1 or <= -1, 0 is not accepted.");
@@ -81,10 +81,10 @@ public class OrdinalFunction {
throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires a comparable parameter.");
});
- protected static String createOrdinalExpressionString(AnalyticsValueStream param, double perc) {
+ protected static String createOrdinalExpressionString(AnalyticsValueStream param, double ord) {
return String.format(Locale.ROOT, "%s(%s,%s)",
name,
- (int)(perc*100),
+ ord,
param.getExpressionStr());
}
}
@@ -108,7 +108,6 @@ class IntOrdinalFunction extends AbstractIntValue implements ReductionFunction {
} else {
return (ordinal * -1) <= size ? collector.get(size + ordinal) : 0;
}
-
}
@Override
public boolean exists() {
@@ -118,11 +117,7 @@ class IntOrdinalFunction extends AbstractIntValue implements ReductionFunction {
@Override
public void synchronizeDataCollectors(UnaryOperator<ReductionDataCollector<?>> sync) {
collector = (SortedIntListCollector)sync.apply(collector);
- if (ordinal > 0) {
- collector.calcOrdinal(ordinal);
- } else {
- collector.calcReverseOrdinal(ordinal*-1);
- }
+ collector.calcOrdinal(ordinal);
}
@Override
@@ -158,7 +153,6 @@ class LongOrdinalFunction extends AbstractLongValue implements ReductionFunction
} else {
return (ordinal * -1) <= size ? collector.get(size + ordinal) : 0;
}
-
}
@Override
public boolean exists() {
@@ -168,11 +162,7 @@ class LongOrdinalFunction extends AbstractLongValue implements ReductionFunction
@Override
public void synchronizeDataCollectors(UnaryOperator<ReductionDataCollector<?>> sync) {
collector = (SortedLongListCollector)sync.apply(collector);
- if (ordinal > 0) {
- collector.calcOrdinal(ordinal);
- } else {
- collector.calcReverseOrdinal(ordinal*-1);
- }
+ collector.calcOrdinal(ordinal);
}
@Override
@@ -208,7 +198,6 @@ class FloatOrdinalFunction extends AbstractFloatValue implements ReductionFuncti
} else {
return (ordinal * -1) <= size ? collector.get(size + ordinal) : 0;
}
-
}
@Override
public boolean exists() {
@@ -218,11 +207,7 @@ class FloatOrdinalFunction extends AbstractFloatValue implements ReductionFuncti
@Override
public void synchronizeDataCollectors(UnaryOperator<ReductionDataCollector<?>> sync) {
collector = (SortedFloatListCollector)sync.apply(collector);
- if (ordinal > 0) {
- collector.calcOrdinal(ordinal);
- } else {
- collector.calcReverseOrdinal(ordinal*-1);
- }
+ collector.calcOrdinal(ordinal);
}
@Override
@@ -258,7 +243,6 @@ class DoubleOrdinalFunction extends AbstractDoubleValue implements ReductionFunc
} else {
return (ordinal * -1) <= size ? collector.get(size + ordinal) : 0;
}
-
}
@Override
public boolean exists() {
@@ -268,11 +252,7 @@ class DoubleOrdinalFunction extends AbstractDoubleValue implements ReductionFunc
@Override
public void synchronizeDataCollectors(UnaryOperator<ReductionDataCollector<?>> sync) {
collector = (SortedDoubleListCollector)sync.apply(collector);
- if (ordinal > 0) {
- collector.calcOrdinal(ordinal);
- } else {
- collector.calcReverseOrdinal(ordinal*-1);
- }
+ collector.calcOrdinal(ordinal);
}
@Override
@@ -308,7 +288,6 @@ class DateOrdinalFunction extends AbstractDateValue implements ReductionFunction
} else {
return (ordinal * -1) <= size ? collector.get(size + ordinal) : 0;
}
-
}
@Override
public boolean exists() {
@@ -354,7 +333,6 @@ class StringOrdinalFunction extends AbstractStringValue implements ReductionFunc
} else {
return (ordinal * -1) <= size ? collector.get(size + ordinal) : null;
}
-
}
@Override
public boolean exists() {
@@ -364,11 +342,7 @@ class StringOrdinalFunction extends AbstractStringValue implements ReductionFunc
@Override
public void synchronizeDataCollectors(UnaryOperator<ReductionDataCollector<?>> sync) {
collector = (SortedStringListCollector)sync.apply(collector);
- if (ordinal > 0) {
- collector.calcOrdinal(ordinal);
- } else {
- collector.calcReverseOrdinal(ordinal*-1);
- }
+ collector.calcOrdinal(ordinal);
}
@Override
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/reduction/PercentileFunction.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/reduction/PercentileFunction.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/reduction/PercentileFunction.java
index 4277d90..a329160 100644
--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/reduction/PercentileFunction.java
+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/reduction/PercentileFunction.java
@@ -29,9 +29,9 @@ import org.apache.solr.analytics.function.reduction.data.SortedListCollector.Sor
import org.apache.solr.analytics.function.reduction.data.SortedListCollector.SortedStringListCollector;
import org.apache.solr.analytics.value.AnalyticsValueStream;
import org.apache.solr.analytics.value.DateValueStream;
+import org.apache.solr.analytics.value.DoubleValue;
import org.apache.solr.analytics.value.DoubleValueStream;
import org.apache.solr.analytics.value.FloatValueStream;
-import org.apache.solr.analytics.value.IntValue;
import org.apache.solr.analytics.value.IntValueStream;
import org.apache.solr.analytics.value.LongValueStream;
import org.apache.solr.analytics.value.StringValueStream;
@@ -41,7 +41,7 @@ import org.apache.solr.analytics.value.FloatValue.AbstractFloatValue;
import org.apache.solr.analytics.value.IntValue.AbstractIntValue;
import org.apache.solr.analytics.value.LongValue.AbstractLongValue;
import org.apache.solr.analytics.value.StringValue.AbstractStringValue;
-import org.apache.solr.analytics.value.constant.ConstantIntValue;
+import org.apache.solr.analytics.value.constant.ConstantValue;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrException.ErrorCode;
@@ -56,14 +56,14 @@ public class PercentileFunction {
}
AnalyticsValueStream percValue = params[0];
double perc = 0;
- if (percValue instanceof ConstantIntValue) {
- perc = ((IntValue)percValue).getInt();
- if (perc < 0 || perc > 99) {
- throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires a percentile between 0 and 99, " + ((int)perc) + " found.");
+ if (percValue instanceof DoubleValue && percValue instanceof ConstantValue) {
+ perc = ((DoubleValue)percValue).getDouble();
+ if (perc < 0 || perc >= 100) {
+ throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires a percentile between [0, 100), " + perc + " found.");
}
perc /= 100;
} else {
- throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires a constant int value (the percentile) as the first argument.");
+ throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires a constant double value (the percentile) as the first argument.");
}
AnalyticsValueStream param = params[1];
if (param instanceof DateValueStream) {
@@ -85,7 +85,7 @@ public class PercentileFunction {
protected static String createPercentileExpressionString(AnalyticsValueStream param, double perc) {
return String.format(Locale.ROOT, "%s(%s,%s)",
name,
- (int)(perc*100),
+ perc,
param.getExpressionStr());
}
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/reduction/SumFunction.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/reduction/SumFunction.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/reduction/SumFunction.java
index 7d4e939..fec1a38 100644
--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/reduction/SumFunction.java
+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/reduction/SumFunction.java
@@ -31,7 +31,7 @@ import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrException.ErrorCode;
/**
- * A reduction function which returns the sum of the sorted values of the given expression.
+ * A reduction function which returns the sum of the values of the given expression.
*/
public class SumFunction extends AbstractDoubleValue implements ReductionFunction {
private SumCollector collector;
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/reduction/data/SortedListCollector.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/reduction/data/SortedListCollector.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/reduction/data/SortedListCollector.java
index c0de54b..bc0c4d4 100644
--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/reduction/data/SortedListCollector.java
+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/reduction/data/SortedListCollector.java
@@ -68,7 +68,6 @@ public abstract class SortedListCollector<T extends Comparable<T>> extends Reduc
calcMedian = false;
calcPercs = new HashSet<>();
calcOrds = new HashSet<>();
- calcRevOrds = new HashSet<>();
}
private List<T> list;
@@ -76,7 +75,6 @@ public abstract class SortedListCollector<T extends Comparable<T>> extends Reduc
private boolean calcMedian;
private Set<Double> calcPercs;
private Set<Integer> calcOrds;
- private Set<Integer> calcRevOrds;
public int size() {
return list.size();
@@ -108,20 +106,10 @@ public abstract class SortedListCollector<T extends Comparable<T>> extends Reduc
}
/**
- * Informs the collector that the following reverse ordinal needs to be computed.
- * Reverse ordinals are ordinals that start at the end of the list.
- *
- * @param reverseOrdinal requested reverseOrdinal
- */
- public void calcReverseOrdinal(int reverseOrdinal) {
- calcRevOrds.add(reverseOrdinal);
- }
-
- /**
* Once the data has been set by either {@link #setData} or {@link #setMergedData},
* this returns the value at the given sorted index.
*
- * Only the indices specified by {@link #calcMedian}, {@link #calcPercentile}, {@link #calcOrdinal}, and {@link #calcReverseOrdinal}
+ * Only the indices specified by {@link #calcMedian}, {@link #calcPercentile}, and {@link #calcOrdinal}
* will contain valid data. All other indices may return unsorted data.
*
* @param index the index of the sorted data to return
@@ -207,11 +195,14 @@ public abstract class SortedListCollector<T extends Comparable<T>> extends Reduc
// Ordinals start at 0 and end at size-1
Set<Integer> ordinals = new HashSet<>();
for (double percentile : calcPercs) {
- ordinals.add((int) Math.ceil(percentile * size) - 1);
+ ordinals.add((int) Math.round(percentile * size - .5));
}
- ordinals.addAll(calcOrds);
- for (int reverseOrdinal : calcRevOrds) {
- ordinals.add(size + reverseOrdinal);
+ for (int ordinal : calcOrds) {
+ if (ordinal > 0) {
+ ordinals.add(ordinal - 1);
+ } else if (ordinal < 0){
+ ordinals.add(size + ordinal);
+ }
}
if (calcMedian) {
int mid = list.size() / 2;
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/java/org/apache/solr/analytics/plugin/AnalyticsStatisticsCollector.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/plugin/AnalyticsStatisticsCollector.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/plugin/AnalyticsStatisticsCollector.java
deleted file mode 100644
index 4c99323..0000000
--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/plugin/AnalyticsStatisticsCollector.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.solr.analytics.plugin;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.concurrent.atomic.AtomicLong;
-
-import com.codahale.metrics.Timer;
-import org.apache.solr.util.stats.MetricUtils;
-
-public class AnalyticsStatisticsCollector {
- private final AtomicLong numRequests;
- private final AtomicLong numAnalyticsRequests;
- private final AtomicLong numStatsRequests;
- private final AtomicLong numCollectedStats;
- private final AtomicLong numFieldFacets;
- private final AtomicLong numRangeFacets;
- private final AtomicLong numQueryFacets;
- private final AtomicLong numQueries;
- private final Timer requestTimes;
-
- public Timer.Context currentTimer;
-
- public AnalyticsStatisticsCollector() {
- numRequests = new AtomicLong();
- numAnalyticsRequests = new AtomicLong();
- numStatsRequests = new AtomicLong();
- numCollectedStats = new AtomicLong();
- numFieldFacets = new AtomicLong();
- numRangeFacets = new AtomicLong();
- numQueryFacets = new AtomicLong();
- numQueries = new AtomicLong();
- requestTimes = new Timer();
- }
-
- public void startRequest() {
- numRequests.incrementAndGet();
- currentTimer = requestTimes.time();
- }
-
- public void addRequests(long num) {
- numAnalyticsRequests.addAndGet(num);
- }
-
- public void addStatsRequests(long num) {
- numStatsRequests.addAndGet(num);
- }
-
- public void addStatsCollected(long num) {
- numCollectedStats.addAndGet(num);
- }
-
- public void addFieldFacets(long num) {
- numFieldFacets.addAndGet(num);
- }
-
- public void addRangeFacets(long num) {
- numRangeFacets.addAndGet(num);
- }
-
- public void addQueryFacets(long num) {
- numQueryFacets.addAndGet(num);
- }
-
- public void addQueries(long num) {
- numQueries.addAndGet(num);
- }
-
- public void endRequest() {
- currentTimer.stop();
- }
-
- public Map<String, Object> getStatistics() {
-
- Map<String, Object> map = new HashMap<>();
- MetricUtils.convertTimer("", requestTimes, MetricUtils.PropertyFilter.ALL, false, false, ".", (k, v) -> {
- map.putAll((Map<String, Object>)v);
- });
- map.put("requests", numRequests.longValue());
- map.put("analyticsRequests", numAnalyticsRequests.longValue());
- map.put("statsRequests", numStatsRequests.longValue());
- map.put("statsCollected", numCollectedStats.longValue());
- map.put("fieldFacets", numFieldFacets.longValue());
- map.put("rangeFacets", numRangeFacets.longValue());
- map.put("queryFacets", numQueryFacets.longValue());
- map.put("queriesInQueryFacets", numQueries.longValue());
- return map;
- }
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/java/org/apache/solr/analytics/util/OldAnalyticsParams.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/util/OldAnalyticsParams.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/util/OldAnalyticsParams.java
index 084d997..86203fc 100644
--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/util/OldAnalyticsParams.java
+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/util/OldAnalyticsParams.java
@@ -27,6 +27,7 @@ import org.apache.solr.analytics.AnalyticsRequestParser.AnalyticsExpressionSortR
import org.apache.solr.analytics.AnalyticsRequestParser.AnalyticsRangeFacetRequest;
import org.apache.solr.analytics.AnalyticsRequestParser.AnalyticsSortRequest;
import org.apache.solr.analytics.AnalyticsRequestParser.AnalyticsValueFacetRequest;
+import org.apache.solr.analytics.function.mapping.FillMissingFunction;
/**
* Specifies the format of the old olap-style analytics requests.
@@ -80,7 +81,7 @@ public interface OldAnalyticsParams {
} else if (isOffset.test(param)) {
getSort(facet).offset = Integer.parseInt(value);
} else if (isShowMissing.test(param)) {
- facet.expression = "fillmissing(" + facet.expression + ",\"(MISSING)\")";
+ facet.expression = FillMissingFunction.name + "(" + facet.expression + ",\"(MISSING)\")";
} else if (isSortExpr.test(param)) {
AnalyticsSortRequest sort = getSort(facet);
AnalyticsExpressionSortRequest criterion;
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/java/org/apache/solr/analytics/util/OrdinalCalculator.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/util/OrdinalCalculator.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/util/OrdinalCalculator.java
index e484e7c..23ff70e 100644
--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/util/OrdinalCalculator.java
+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/util/OrdinalCalculator.java
@@ -44,11 +44,8 @@ public class OrdinalCalculator {
for (int ord : ordinals) {
ords[i++] = ord;
}
- Arrays.sort(ords);
+ ords = Arrays.stream(ords).sorted().filter( ord -> ord >= 0 && ord < size).toArray();
- if (ords[0] < 0 || ords[ords.length - 1] > size - 1) {
- throw new IllegalArgumentException();
- }
distributeAndFind(list, ords, 0, ords.length - 1);
}
[13/20] lucene-solr:master: SOLR-11145,
SOLR-11146: Added comprehensive unit tests for Analytics Component
2.0 as well as analytics bug fixes.
Posted by dp...@apache.org.
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/FieldFacetTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/FieldFacetTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/FieldFacetTest.java
deleted file mode 100644
index d30413e..0000000
--- a/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/FieldFacetTest.java
+++ /dev/null
@@ -1,1065 +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.Collection;
-import java.util.Collections;
-import java.util.List;
-
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.w3c.dom.Node;
-
-
-public class FieldFacetTest extends AbstractAnalyticsFacetTest{
- static String fileName = "fieldFacets.txt";
-
- public static final int INT = 71;
- public static final int LONG = 36;
- public static final int LONGM = 50;
- public static final int FLOAT = 73;
- public static final int FLOATM = 84;
- public static final int DOUBLE = 49;
- public static final int DATE = 12;
- public static final int DATEM = 30;
- public static final int STRING = 28;
- public static final int STRINGM = 40;
- public static final int NUM_LOOPS = 100;
-
- //INT
- private static ArrayList<ArrayList<Integer>> intDateTestStart;
- private static ArrayList<Long> intDateTestMissing;
- private static ArrayList<ArrayList<Integer>> intStringTestStart;
- private static ArrayList<Long> intStringTestMissing;
-
- //LONG
- private static ArrayList<ArrayList<Long>> longDateTestStart;
- private static ArrayList<Long> longDateTestMissing;
- private static ArrayList<ArrayList<Long>> longStringTestStart;
- private static ArrayList<Long> longStringTestMissing;
-
- //FLOAT
- private static ArrayList<ArrayList<Float>> floatDateTestStart;
- private static ArrayList<Long> floatDateTestMissing;
- private static ArrayList<ArrayList<Float>> floatStringTestStart;
- private static ArrayList<Long> floatStringTestMissing;
-
- //DOUBLE
- private static ArrayList<ArrayList<Double>> doubleDateTestStart;
- private static ArrayList<Long> doubleDateTestMissing;
- private static ArrayList<ArrayList<Double>> doubleStringTestStart;
- private static ArrayList<Long> doubleStringTestMissing;
-
- //DATE
- private static ArrayList<ArrayList<String>> dateIntTestStart;
- private static ArrayList<Long> dateIntTestMissing;
- private static ArrayList<ArrayList<String>> dateLongTestStart;
- private static ArrayList<Long> dateLongTestMissing;
-
- //String
- private static ArrayList<ArrayList<String>> stringIntTestStart;
- private static ArrayList<Long> stringIntTestMissing;
- private static ArrayList<ArrayList<String>> stringLongTestStart;
- private static ArrayList<Long> stringLongTestMissing;
-
- //Multi-Valued
- private static ArrayList<ArrayList<Integer>> multiLongTestStart;
- private static ArrayList<Long> multiLongTestMissing;
- private static ArrayList<ArrayList<Integer>> multiStringTestStart;
- private static ArrayList<Long> multiStringTestMissing;
- private static ArrayList<ArrayList<Integer>> multiDateTestStart;
- private static ArrayList<Long> multiDateTestMissing;
-
- @BeforeClass
- public static void beforeClass() throws Exception {
- initCore("solrconfig-analytics.xml","schema-analytics.xml");
- h.update("<delete><query>*:*</query></delete>");
-
- defaults.put("int", new Integer(0));
- defaults.put("long", new Long(0));
- defaults.put("float", new Float(0));
- defaults.put("double", new Double(0));
- defaults.put("date", "1800-12-31T23:59:59Z");
- defaults.put("string", "str0");
-
- //INT
- intDateTestStart = new ArrayList<>();
- intDateTestMissing = new ArrayList<>();
- intStringTestStart = new ArrayList<>();
- intStringTestMissing = new ArrayList<>();
-
- //LONG
- longDateTestStart = new ArrayList<>();
- longDateTestMissing = new ArrayList<>();
- longStringTestStart = new ArrayList<>();
- longStringTestMissing = new ArrayList<>();
-
- //FLOAT
- floatDateTestStart = new ArrayList<>();
- floatDateTestMissing = new ArrayList<>();
- floatStringTestStart = new ArrayList<>();
- floatStringTestMissing = new ArrayList<>();
-
- //DOUBLE
- doubleDateTestStart = new ArrayList<>();
- doubleDateTestMissing = new ArrayList<>();
- doubleStringTestStart = new ArrayList<>();
- doubleStringTestMissing = new ArrayList<>();
-
- //DATE
- dateIntTestStart = new ArrayList<>();
- dateIntTestMissing = new ArrayList<>();
- dateLongTestStart = new ArrayList<>();
- dateLongTestMissing = new ArrayList<>();
-
- //String
- stringIntTestStart = new ArrayList<>();
- stringIntTestMissing = new ArrayList<>();
- stringLongTestStart = new ArrayList<>();
- stringLongTestMissing = new ArrayList<>();
-
- //Multi-Valued
- multiLongTestStart = new ArrayList<>();
- multiLongTestMissing = new ArrayList<>();
- multiStringTestStart = new ArrayList<>();
- multiStringTestMissing = new ArrayList<>();
- multiDateTestStart = new ArrayList<>();
- multiDateTestMissing = new ArrayList<>();
-
- boolean multiCanHaveDuplicates = Boolean.getBoolean(NUMERIC_POINTS_SYSPROP);
-
- for (int j = 0; j < NUM_LOOPS; ++j) {
- int i = j%INT;
- long l = j%LONG;
- long lm = j%LONGM;
- float f = j%FLOAT;
- double d = j%DOUBLE;
- int dt = j%DATE;
- int dtm = j%DATEM;
- int s = j%STRING;
- int sm = j%STRINGM;
-
-
- List<String> fields = new ArrayList<>();
- fields.add("id"); fields.add("1000"+j);
-
- if( i != 0 ) {
- fields.add("int_id"); fields.add("" + i);
- }
- if( l != 0l ) {
- fields.add("long_ld"); fields.add("" + l);
- fields.add("long_ldm"); fields.add("" + l);
- }
- if( lm != 0l ) {
- fields.add("long_ldm"); fields.add("" + lm);
- }
- if( f != 0.0f ) {
- fields.add("float_fd"); fields.add("" + f);
- }
- if( d != 0.0d ) {
- fields.add("double_dd"); fields.add("" + d);
- }
- if( dt != 0 ) {
- fields.add("date_dtd"); fields.add((1800+dt) + "-12-31T23:59:59Z");
- fields.add("date_dtdm"); fields.add((1800+dt) + "-12-31T23:59:59Z");
- }
- if ( dtm != 0 ) {
- fields.add("date_dtdm"); fields.add((1800+dtm) + "-12-31T23:59:59Z");
- }
- if ( s != 0 ) {
- fields.add("string_sd"); fields.add("str" + s);
- fields.add("string_sdm"); fields.add("str" + s);
- }
- if ( sm != 0 ) {
- fields.add("string_sdm"); fields.add("str" + sm);
- }
- assertU(adoc(fields.toArray(new String[0])));
-
- if( dt != 0 ) {
- //Dates
- if ( j-DATE < 0 ) {
- ArrayList<Integer> list1 = new ArrayList<>();
- if( i != 0 ) {
- list1.add(i);
- intDateTestMissing.add(0l);
- } else {
- intDateTestMissing.add(1l);
- }
- intDateTestStart.add(list1);
- ArrayList<Long> list2 = new ArrayList<>();
- if( l != 0l ) {
- list2.add(l);
- longDateTestMissing.add(0l);
- } else {
- longDateTestMissing.add(1l);
- }
- longDateTestStart.add(list2);
- ArrayList<Float> list3 = new ArrayList<>();
- if ( f != 0.0f ) {
- list3.add(f);
- floatDateTestMissing.add(0l);
- } else {
- floatDateTestMissing.add(1l);
-
- }
- floatDateTestStart.add(list3);
- ArrayList<Double> list4 = new ArrayList<>();
- if( d != 0.0d ) {
- list4.add(d);
- doubleDateTestMissing.add(0l);
- } else {
- doubleDateTestMissing.add(1l);
- }
- doubleDateTestStart.add(list4);
- ArrayList<Integer> list5 = new ArrayList<>();
- if( i != 0 ) {
- list5.add(i);
- multiDateTestMissing.add(0l);
- } else {
- multiDateTestMissing.add(1l);
-
- }
- multiDateTestStart.add(list5);
- } else {
- if( i != 0 ) intDateTestStart.get(dt-1).add(i); else increment(intDateTestMissing,dt-1);
- if( l != 0l ) longDateTestStart.get(dt-1).add(l); else increment(longDateTestMissing,dt-1);
- if( f != 0.0f ) floatDateTestStart.get(dt-1).add(f); else increment(floatDateTestMissing,dt-1);
- if( d != 0.0d ) doubleDateTestStart.get(dt-1).add(d); else increment(doubleDateTestMissing,dt-1);
- if( i != 0 ) multiDateTestStart.get(dt-1).add(i); else increment(multiDateTestMissing,dt-1);
- }
- }
-
- if ( dtm != 0 ) {
- if ( j-DATEM < 0 && dtm != dt ) {
- ArrayList<Integer> list1 = new ArrayList<>();
- if( i != 0 ) {
- list1.add(i);
- multiDateTestMissing.add(0l);
- } else {
- multiDateTestMissing.add(1l);
- }
- multiDateTestStart.add(list1);
- } else if ( dtm != dt || multiCanHaveDuplicates ) {
- if( i != 0 ) multiDateTestStart.get(dtm-1).add(i); else increment(multiDateTestMissing,dtm-1);
- }
- }
-
- if( s != 0 ){
- //Strings
- if ( j-STRING < 0 ) {
- ArrayList<Integer> list1 = new ArrayList<>();
- if( i != 0 ) {
- list1.add(i);
- intStringTestMissing.add(0l);
- } else {
- intStringTestMissing.add(1l);
- }
- intStringTestStart.add(list1);
- ArrayList<Long> list2 = new ArrayList<>();
- if( l != 0l ) {
- list2.add(l);
- longStringTestMissing.add(0l);
- } else {
- longStringTestMissing.add(1l);
- }
- longStringTestStart.add(list2);
- ArrayList<Float> list3 = new ArrayList<>();
- if( f != 0.0f ){
- list3.add(f);
- floatStringTestMissing.add(0l);
- } else {
- floatStringTestMissing.add(1l);
- }
- floatStringTestStart.add(list3);
- ArrayList<Double> list4 = new ArrayList<>();
- if( d != 0.0d ) {
- list4.add(d);
- doubleStringTestMissing.add(0l);
- } else {
- doubleStringTestMissing.add(1l);
- }
- doubleStringTestStart.add(list4);
- ArrayList<Integer> list5 = new ArrayList<>();
- if( i != 0 ) {
- list5.add(i);
- multiStringTestMissing.add(0l);
- } else {
- multiStringTestMissing.add(1l);
- }
- multiStringTestStart.add(list5);
- } else {
- if( i != 0 ) intStringTestStart.get(s-1).add(i); else increment(intStringTestMissing,s-1);
- if( l != 0l ) longStringTestStart.get(s-1).add(l); else increment(longStringTestMissing,s-1);
- if( f != 0.0f ) floatStringTestStart.get(s-1).add(f); else increment(floatStringTestMissing,s-1);
- if( d != 0.0d ) doubleStringTestStart.get(s-1).add(d); else increment(doubleStringTestMissing,s-1);
- if( i != 0 ) multiStringTestStart.get(s-1).add(i); else increment(multiStringTestMissing,s-1);
- }
- }
-
- //Strings
- if( sm != 0 ){
- if ( j-STRINGM < 0 && sm != s ) {
- ArrayList<Integer> list1 = new ArrayList<>();
- if( i != 0 ){
- list1.add(i);
- multiStringTestMissing.add(0l);
- } else {
- multiStringTestMissing.add(1l);
- }
- multiStringTestStart.add(list1);
- } else if ( sm != s ) {
- if( i != 0 ) multiStringTestStart.get(sm-1).add(i); else increment(multiStringTestMissing,sm-1);
- }
- }
-
- //Int
- if( i != 0 ) {
- if ( j-INT < 0 ) {
- ArrayList<String> list1 = new ArrayList<>();
- if( dt != 0 ){
- list1.add((1800+dt) + "-12-31T23:59:59Z");
- dateIntTestMissing.add(0l);
- } else {
- dateIntTestMissing.add(1l);
- }
- dateIntTestStart.add(list1);
- ArrayList<String> list2 = new ArrayList<>();
- if( s != 0 ) {
- list2.add("str"+s);
- stringIntTestMissing.add(0l);
- } else {
- stringIntTestMissing.add(1l);
- }
- stringIntTestStart.add(list2);
- } else {
- if( dt != 0 ) dateIntTestStart.get(i-1).add((1800+dt) + "-12-31T23:59:59Z"); else increment(dateIntTestMissing,i-1);
- if( s != 0 ) stringIntTestStart.get(i-1).add("str"+s); else increment(stringIntTestMissing,i-1);
- }
- }
-
- //Long
- if( l != 0 ) {
- if ( j-LONG < 0 ) {
- ArrayList<String> list1 = new ArrayList<>();
- if( dt != 0 ){
- list1.add((1800+dt) + "-12-31T23:59:59Z");
- dateLongTestMissing.add(0l);
- } else {
- dateLongTestMissing.add(1l);
- }
- dateLongTestStart.add(list1);
- ArrayList<String> list2 = new ArrayList<>();
- if( s != 0 ) {
- list2.add("str"+s);
- stringLongTestMissing.add(0l);
- } else {
- stringLongTestMissing.add(1l);
- }
- stringLongTestStart.add(list2);
- ArrayList<Integer> list3 = new ArrayList<>();
- if( i != 0 ) {
- list3.add(i);
- multiLongTestMissing.add(0l);
- } else {
- multiLongTestMissing.add(1l);
- }
- multiLongTestStart.add(list3);
- } else {
- if( dt != 0 ) dateLongTestStart.get((int)l-1).add((1800+dt) + "-12-31T23:59:59Z"); else increment(dateLongTestMissing,(int)l-1);
- if( s != 0 ) stringLongTestStart.get((int)l-1).add("str"+s); else increment(stringLongTestMissing,(int)l-1);
- if( i != 0 ) multiLongTestStart.get((int)l-1).add(i); else increment(multiLongTestMissing,(int)l-1);
- }
- }
-
- //Long
- if( lm != 0 ) {
- if ( j-LONGM < 0 && lm != l ) {
- ArrayList<Integer> list1 = new ArrayList<>();
- if( i != 0 ) {
- list1.add(i);
- multiLongTestMissing.add(0l);
- } else {
- multiLongTestMissing.add(1l);
- }
- multiLongTestStart.add(list1);
- } else if ( lm != l || multiCanHaveDuplicates ) {
- if( i != 0 ) multiLongTestStart.get((int)lm-1).add(i); else increment( multiLongTestMissing,(int)lm-1);
- }
- }
-
- if (usually()) {
- assertU(commit()); // to have several segments
- }
- }
-
- assertU(commit());
- String[] reqFacetParamas = fileToStringArr(FieldFacetTest.class, fileName);
- String[] reqParamas = new String[reqFacetParamas.length + 2];
- System.arraycopy(reqFacetParamas, 0, reqParamas, 0, reqFacetParamas.length);
- reqParamas[reqFacetParamas.length] = "solr";
- reqParamas[reqFacetParamas.length+1] = "asc";
- setResponse(h.query(request(reqFacetParamas)));
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void sumTest() throws Exception {
- //Int Date
- Collection<Double> intDate = getDoubleList("sum","fieldFacets", "date_dtd", "double", "int");
- ArrayList<Double> intDateTest = calculateNumberStat(intDateTestStart, "sum");
- assertEquals(getRawResponse(),intDate,intDateTest);
- //Int String
- Collection<Double> intString = getDoubleList("sum","fieldFacets", "string_sd", "double", "int");
- ArrayList<Double> intStringTest = calculateNumberStat(intStringTestStart, "sum");
- assertEquals(getRawResponse(),intString,intStringTest);
-
- //Long Date
- Collection<Double> longDate = getDoubleList("sum","fieldFacets", "date_dtd", "double", "long");
- ArrayList<Double> longDateTest = calculateNumberStat(longDateTestStart, "sum");
- assertEquals(getRawResponse(),longDate,longDateTest);
- //Long String
- Collection<Double> longString = getDoubleList("sum","fieldFacets", "string_sd", "double", "long");
- ArrayList<Double> longStringTest = calculateNumberStat(longStringTestStart, "sum");
- assertEquals(getRawResponse(),longString,longStringTest);
-
- //Float Date
- Collection<Double> floatDate = getDoubleList("sum","fieldFacets", "date_dtd", "double", "float");
- ArrayList<Double> floatDateTest = calculateNumberStat(floatDateTestStart, "sum");
- assertEquals(getRawResponse(),floatDate,floatDateTest);
- //Float String
- Collection<Double> floatString = getDoubleList("sum","fieldFacets", "string_sd", "double", "float");
- ArrayList<Double> floatStringTest = calculateNumberStat(floatStringTestStart, "sum");
- assertEquals(getRawResponse(),floatString,floatStringTest);
-
- //Double Date
- Collection<Double> doubleDate = getDoubleList("sum","fieldFacets", "date_dtd", "double", "double");
- ArrayList<Double> doubleDateTest = calculateNumberStat(doubleDateTestStart, "sum");
- assertEquals(getRawResponse(),doubleDate,doubleDateTest);
- //Double String
- Collection<Double> doubleString = getDoubleList("sum","fieldFacets", "string_sd", "double", "double");
- ArrayList<Double> doubleStringTest = calculateNumberStat(doubleStringTestStart, "sum");
- assertEquals(getRawResponse(),doubleString,doubleStringTest);
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void meanTest() throws Exception {
- //Int Date
- Collection<Double> intDate = getDoubleList("mean","fieldFacets", "date_dtd", "double", "int");
- ArrayList<Double> intDateTest = calculateNumberStat(intDateTestStart, "mean");
- assertEquals(getRawResponse(),intDate,intDateTest);
- //Int String
- Collection<Double> intString = getDoubleList("mean","fieldFacets", "string_sd", "double", "int");
- ArrayList<Double> intStringTest = calculateNumberStat(intStringTestStart, "mean");
- assertEquals(getRawResponse(),intString,intStringTest);
-
- //Long Date
- Collection<Double> longDate = getDoubleList("mean","fieldFacets", "date_dtd", "double", "long");
- ArrayList<Double> longDateTest = calculateNumberStat(longDateTestStart, "mean");
- assertEquals(getRawResponse(),longDate,longDateTest);
- //Long String
- Collection<Double> longString = getDoubleList("mean","fieldFacets", "string_sd", "double", "long");
- ArrayList<Double> longStringTest = calculateNumberStat(longStringTestStart, "mean");
- assertEquals(getRawResponse(),longString,longStringTest);
-
- //Float Date
- Collection<Double> floatDate = getDoubleList("mean","fieldFacets", "date_dtd", "double", "float");
- ArrayList<Double> floatDateTest = calculateNumberStat(floatDateTestStart, "mean");
- assertEquals(getRawResponse(),floatDate,floatDateTest);
- //Float String
- Collection<Double> floatString = getDoubleList("mean","fieldFacets", "string_sd", "double", "float");
- ArrayList<Double> floatStringTest = calculateNumberStat(floatStringTestStart, "mean");
- assertEquals(getRawResponse(),floatString,floatStringTest);
-
- //Double Date
- Collection<Double> doubleDate = getDoubleList("mean","fieldFacets", "date_dtd", "double", "double");
- ArrayList<Double> doubleDateTest = calculateNumberStat(doubleDateTestStart, "mean");
- assertEquals(getRawResponse(),doubleDate,doubleDateTest);
- //Double String
- Collection<Double> doubleString = getDoubleList("mean","fieldFacets", "string_sd", "double", "double");
- ArrayList<Double> doubleStringTest = calculateNumberStat(doubleStringTestStart, "mean");
- assertEquals(getRawResponse(),doubleString,doubleStringTest);
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void stddevFacetAscTest() throws Exception {
- //Int Date
- ArrayList<Double> intDate = getDoubleList("stddev","fieldFacets", "date_dtd", "double", "int");
- ArrayList<Double> intDateTest = calculateNumberStat(intDateTestStart, "stddev");
- checkStddevs(intDate,intDateTest);
- //Int String
- ArrayList<Double> intString = getDoubleList("stddev","fieldFacets", "string_sd", "double", "int");
- ArrayList<Double> intStringTest = calculateNumberStat(intStringTestStart, "stddev");
- checkStddevs(intString,intStringTest);
-
- //Long Date
- ArrayList<Double> longDate = getDoubleList("stddev","fieldFacets", "date_dtd", "double", "long");
- ArrayList<Double> longDateTest = calculateNumberStat(longDateTestStart, "stddev");
- checkStddevs(longDate,longDateTest);
- //Long String
- ArrayList<Double> longString = getDoubleList("stddev","fieldFacets", "string_sd", "double", "long");
- ArrayList<Double> longStringTest = calculateNumberStat(longStringTestStart, "stddev");
- checkStddevs(longString,longStringTest);
-
- //Float Date
- ArrayList<Double> floatDate = getDoubleList("stddev","fieldFacets", "date_dtd", "double", "float");
- ArrayList<Double> floatDateTest = calculateNumberStat(floatDateTestStart, "stddev");
- checkStddevs(floatDate,floatDateTest);
- //Float String
- ArrayList<Double> floatString = getDoubleList("stddev","fieldFacets", "string_sd", "double", "float");
- ArrayList<Double> floatStringTest = calculateNumberStat(floatStringTestStart, "stddev");
- checkStddevs(floatString,floatStringTest);
-
- //Double Date
- ArrayList<Double> doubleDate = getDoubleList("stddev","fieldFacets", "date_dtd", "double", "double");
- ArrayList<Double> doubleDateTest = calculateNumberStat(doubleDateTestStart, "stddev");
- checkStddevs(doubleDate,doubleDateTest);
- //Double String
- ArrayList<Double> doubleString = getDoubleList("stddev","fieldFacets", "string_sd", "double", "double");
- ArrayList<Double> doubleStringTest = calculateNumberStat(doubleStringTestStart, "stddev");
- checkStddevs(doubleString,doubleStringTest);
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void medianFacetAscTest() throws Exception {
- //Int Date
- Collection<Double> intDate = getDoubleList( "median","fieldFacets", "date_dtd", "double", "int");
- ArrayList<Double> intDateTest = calculateNumberStat(intDateTestStart, "median");
- assertEquals(getRawResponse(),intDate,intDateTest);
- //Int String
- Collection<Double> intString = getDoubleList("median","fieldFacets", "string_sd", "double", "int");
- ArrayList<Double> intStringTest = calculateNumberStat(intStringTestStart, "median");
- assertEquals(getRawResponse(),intString,intStringTest);
-
- //Long Date
- Collection<Double> longDate = getDoubleList("median","fieldFacets", "date_dtd", "double", "long");
- ArrayList<Double> longDateTest = calculateNumberStat(longDateTestStart, "median");
- assertEquals(getRawResponse(),longDate,longDateTest);
- //Long String
- Collection<Double> longString = getDoubleList("median","fieldFacets", "string_sd", "double", "long");
- ArrayList<Double> longStringTest = calculateNumberStat(longStringTestStart, "median");
- assertEquals(getRawResponse(),longString,longStringTest);
-
- //Float Date
- Collection<Double> floatDate = getDoubleList("median","fieldFacets", "date_dtd", "double", "float");
- ArrayList<Double> floatDateTest = calculateNumberStat(floatDateTestStart, "median");
- assertEquals(getRawResponse(),floatDate,floatDateTest);
- //Float String
- Collection<Double> floatString = getDoubleList("median","fieldFacets", "string_sd", "double", "float");
- ArrayList<Double> floatStringTest = calculateNumberStat(floatStringTestStart, "median");
- assertEquals(getRawResponse(),floatString,floatStringTest);
-
- //Double Date
- Collection<Double> doubleDate = getDoubleList("median","fieldFacets", "date_dtd", "double", "double");
- ArrayList<Double> doubleDateTest = calculateNumberStat(doubleDateTestStart, "median");
- assertEquals(getRawResponse(),doubleDate,doubleDateTest);
- //Double String
- Collection<Double> doubleString = getDoubleList("median","fieldFacets", "string_sd", "double", "double");
- ArrayList<Double> doubleStringTest = calculateNumberStat(doubleStringTestStart, "median");
- assertEquals(getRawResponse(),doubleString,doubleStringTest);
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void perc20Test() throws Exception {
- //Int Date
- Collection<Integer> intDate = getIntegerList("percentile_20n","fieldFacets", "date_dtd", "int", "int");
- ArrayList<Integer> intDateTest = (ArrayList<Integer>)calculateStat(intDateTestStart, "perc_20");
- assertEquals(getRawResponse(),intDate,intDateTest);
- //Int String
- Collection<Integer> intString = getIntegerList("percentile_20n","fieldFacets", "string_sd", "int", "int");
- ArrayList<Integer> intStringTest = (ArrayList<Integer>)calculateStat(intStringTestStart, "perc_20");
- assertEquals(getRawResponse(),intString,intStringTest);
-
- //Long Date
- Collection<Long> longDate = getLongList("percentile_20n","fieldFacets", "date_dtd", "long", "long");
- ArrayList<Long> longDateTest = (ArrayList<Long>)calculateStat(longDateTestStart, "perc_20");
- assertEquals(getRawResponse(),longDate,longDateTest);
- //Long String
- Collection<Long> longString = getLongList("percentile_20n","fieldFacets", "string_sd", "long", "long");
- ArrayList<Long> longStringTest = (ArrayList<Long>)calculateStat(longStringTestStart, "perc_20");
- assertEquals(getRawResponse(),longString,longStringTest);
-
- //Float Date
- Collection<Float> floatDate = getFloatList("percentile_20n","fieldFacets", "date_dtd", "float", "float");
- ArrayList<Float> floatDateTest = (ArrayList<Float>)calculateStat(floatDateTestStart, "perc_20");
- assertEquals(getRawResponse(),floatDate,floatDateTest);
- //Float String
- Collection<Float> floatString = getFloatList("percentile_20n","fieldFacets", "string_sd", "float", "float");
- ArrayList<Float> floatStringTest = (ArrayList<Float>)calculateStat(floatStringTestStart, "perc_20");
- assertEquals(getRawResponse(),floatString,floatStringTest);
-
- //Double Date
- Collection<Double> doubleDate = getDoubleList("percentile_20n","fieldFacets", "date_dtd", "double", "double");
- ArrayList<Double> doubleDateTest = (ArrayList<Double>)calculateStat(doubleDateTestStart, "perc_20");
- assertEquals(getRawResponse(),doubleDate,doubleDateTest);
- //Double String
- Collection<Double> doubleString = getDoubleList("percentile_20n","fieldFacets", "string_sd", "double", "double");
- ArrayList<Double> doubleStringTest = (ArrayList<Double>)calculateStat(doubleStringTestStart, "perc_20");
- assertEquals(getRawResponse(),doubleString,doubleStringTest);
-
- //Date Int
- Collection<String> dateInt = getStringList("percentile_20","fieldFacets", "int_id", "date", "date");
- ArrayList<String> dateIntTest = (ArrayList<String>)calculateStat(dateIntTestStart, "perc_20");
- assertEquals(getRawResponse(),dateInt,dateIntTest);
- //Date Long
- Collection<String> dateString = getStringList("percentile_20","fieldFacets", "long_ld", "date", "date");
- ArrayList<String> dateLongTest = (ArrayList<String>)calculateStat(dateLongTestStart, "perc_20");
- assertEquals(getRawResponse(),dateString,dateLongTest);
-
- //String Int
- Collection<String> stringInt = getStringList("percentile_20","fieldFacets", "int_id", "str", "str");
- ArrayList<String> stringIntTest = (ArrayList<String>)calculateStat(stringIntTestStart, "perc_20");
- assertEquals(getRawResponse(),stringInt,stringIntTest);
- //String Long
- Collection<String> stringLong = getStringList("percentile_20","fieldFacets", "long_ld", "str", "str");
- ArrayList<String> stringLongTest = (ArrayList<String>)calculateStat(stringLongTestStart, "perc_20");
- assertEquals(getRawResponse(),stringLong,stringLongTest);
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void perc60Test() throws Exception {
- //Int Date
- Collection<Integer> intDate = getIntegerList("percentile_60n","fieldFacets", "date_dtd", "int", "int");
- ArrayList<Integer> intDateTest = (ArrayList<Integer>)calculateStat(intDateTestStart, "perc_60");
- assertEquals(getRawResponse(),intDate,intDateTest);
- //Int String
- Collection<Integer> intString = getIntegerList("percentile_60n","fieldFacets", "string_sd", "int", "int");
- ArrayList<Integer> intStringTest = (ArrayList<Integer>)calculateStat(intStringTestStart, "perc_60");
- assertEquals(getRawResponse(),intString,intStringTest);
-
- //Long Date
- Collection<Long> longDate = getLongList("percentile_60n","fieldFacets", "date_dtd", "long", "long");
- ArrayList<Long> longDateTest = (ArrayList<Long>)calculateStat(longDateTestStart, "perc_60");
- assertEquals(getRawResponse(),longDate,longDateTest);
- //Long String
- Collection<Long> longString = getLongList("percentile_60n","fieldFacets", "string_sd", "long", "long");
- ArrayList<Long> longStringTest = (ArrayList<Long>)calculateStat(longStringTestStart, "perc_60");
- assertEquals(getRawResponse(),longString,longStringTest);
-
- //Float Date
- Collection<Float> floatDate = getFloatList("percentile_60n","fieldFacets", "date_dtd", "float", "float");
- ArrayList<Float> floatDateTest = (ArrayList<Float>)calculateStat(floatDateTestStart, "perc_60");
- assertEquals(getRawResponse(),floatDate,floatDateTest);
- //Float String
- Collection<Float> floatString = getFloatList("percentile_60n","fieldFacets", "string_sd", "float", "float");
- ArrayList<Float> floatStringTest = (ArrayList<Float>)calculateStat(floatStringTestStart, "perc_60");
- assertEquals(getRawResponse(),floatString,floatStringTest);
-
- //Double Date
- Collection<Double> doubleDate = getDoubleList("percentile_60n","fieldFacets", "date_dtd", "double", "double");
- ArrayList<Double> doubleDateTest = (ArrayList<Double>)calculateStat(doubleDateTestStart, "perc_60");
- assertEquals(getRawResponse(),doubleDate,doubleDateTest);
- //Double String
- Collection<Double> doubleString = getDoubleList("percentile_60n","fieldFacets", "string_sd", "double", "double");
- ArrayList<Double> doubleStringTest = (ArrayList<Double>)calculateStat(doubleStringTestStart, "perc_60");
- assertEquals(getRawResponse(),doubleString,doubleStringTest);
-
- //Date Int
- Collection<String> dateInt = getStringList("percentile_60","fieldFacets", "int_id", "date", "date");
- ArrayList<String> dateIntTest = (ArrayList<String>)calculateStat(dateIntTestStart, "perc_60");
- assertEquals(getRawResponse(),dateInt,dateIntTest);
- //Date Long
- Collection<String> dateString = getStringList("percentile_60","fieldFacets", "long_ld", "date", "date");
- ArrayList<String> dateLongTest = (ArrayList<String>)calculateStat(dateLongTestStart, "perc_60");
- assertEquals(getRawResponse(),dateString,dateLongTest);
-
- //String Int
- Collection<String> stringInt = getStringList("percentile_60","fieldFacets", "int_id", "str", "str");
- ArrayList<String> stringIntTest = (ArrayList<String>)calculateStat(stringIntTestStart, "perc_60");
- assertEquals(getRawResponse(),stringInt,stringIntTest);
- //String Long
- Collection<String> stringLong = getStringList("percentile_60","fieldFacets", "long_ld", "str", "str");
- ArrayList<String> stringLongTest = (ArrayList<String>)calculateStat(stringLongTestStart, "perc_60");
- assertEquals(getRawResponse(),stringLong,stringLongTest);
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void minTest() throws Exception {
- //Int Date
- Collection<Integer> intDate = getIntegerList("minn","fieldFacets", "date_dtd", "int", "int");
- ArrayList<Integer> intDateTest = (ArrayList<Integer>)calculateStat(intDateTestStart, "min");
- assertEquals(getRawResponse(),intDate,intDateTest);
- //Int String
- Collection<Integer> intString = getIntegerList("minn","fieldFacets", "string_sd", "int", "int");
- ArrayList<Integer> intStringTest = (ArrayList<Integer>)calculateStat(intStringTestStart, "min");
- assertEquals(getRawResponse(),intString,intStringTest);
-
- //Long Date
- Collection<Long> longDate = getLongList("minn","fieldFacets", "date_dtd", "long", "long");
- ArrayList<Long> longDateTest = (ArrayList<Long>)calculateStat(longDateTestStart, "min");
- assertEquals(getRawResponse(),longDate,longDateTest);
- //Long String
- Collection<Long> longString = getLongList("minn","fieldFacets", "string_sd", "long", "long");
- ArrayList<Long> longStringTest = (ArrayList<Long>)calculateStat(longStringTestStart, "min");
- assertEquals(getRawResponse(),longString,longStringTest);
-
- //Float Date
- Collection<Float> floatDate = getFloatList("minn","fieldFacets", "date_dtd", "float", "float");
- ArrayList<Float> floatDateTest = (ArrayList<Float>)calculateStat(floatDateTestStart, "min");
- assertEquals(getRawResponse(),floatDate,floatDateTest);
- //Float String
- Collection<Float> floatString = getFloatList("minn","fieldFacets", "string_sd", "float", "float");
- ArrayList<Float> floatStringTest = (ArrayList<Float>)calculateStat(floatStringTestStart, "min");
- assertEquals(getRawResponse(),floatString,floatStringTest);
-
- //Double Date
- Collection<Double> doubleDate = getDoubleList("minn","fieldFacets", "date_dtd", "double", "double");
- ArrayList<Double> doubleDateTest = (ArrayList<Double>)calculateStat(doubleDateTestStart, "min");
- assertEquals(getRawResponse(),doubleDate,doubleDateTest);
- //Double String
- Collection<Double> doubleString = getDoubleList("minn","fieldFacets", "string_sd", "double", "double");
- ArrayList<Double> doubleStringTest = (ArrayList<Double>)calculateStat(doubleStringTestStart, "min");
- assertEquals(getRawResponse(),doubleString,doubleStringTest);
-
- //Date Int
- Collection<String> dateInt = getStringList("min","fieldFacets", "int_id", "date", "date");
- ArrayList<String> dateIntTest = (ArrayList<String>)calculateStat(dateIntTestStart, "min");
- assertEquals(getRawResponse(),dateInt,dateIntTest);
- //Date Long
- Collection<String> dateString = getStringList("min","fieldFacets", "long_ld", "date", "date");
- ArrayList<String> dateLongTest = (ArrayList<String>)calculateStat(dateLongTestStart, "min");
- assertEquals(getRawResponse(),dateString,dateLongTest);
-
- //String Int
- Collection<String> stringInt = getStringList("min","fieldFacets", "int_id", "str", "str");
- ArrayList<String> stringIntTest = (ArrayList<String>)calculateStat(stringIntTestStart, "min");
- assertEquals(getRawResponse(),stringInt,stringIntTest);
- //String Long
- Collection<String> stringLong = getStringList("min","fieldFacets", "long_ld", "str", "str");
- ArrayList<String> stringLongTest = (ArrayList<String>)calculateStat(stringLongTestStart, "min");
- assertEquals(getRawResponse(),stringLong,stringLongTest);
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void maxTest() throws Exception {
- //Int Date
- Collection<Integer> intDate = getIntegerList("maxn","fieldFacets", "date_dtd", "int", "int");
- ArrayList<Integer> intDateTest = (ArrayList<Integer>)calculateStat(intDateTestStart, "max");
- assertEquals(getRawResponse(),intDate,intDateTest);
-
- //Int String
- Collection<Integer> intString = getIntegerList("maxn","fieldFacets", "string_sd", "int", "int");
- ArrayList<Integer> intStringTest = (ArrayList<Integer>)calculateStat(intStringTestStart, "max");
- assertEquals(getRawResponse(),intString,intStringTest);
-
- //Long Date
- Collection<Long> longDate = getLongList("maxn","fieldFacets", "date_dtd", "long", "long");
- ArrayList<Long> longDateTest = (ArrayList<Long>)calculateStat(longDateTestStart, "max");
- assertEquals(getRawResponse(),longDate,longDateTest);
-
- //Long String
- Collection<Long> longString = getLongList("maxn","fieldFacets", "string_sd", "long", "long");
- ArrayList<Long> longStringTest = (ArrayList<Long>)calculateStat(longStringTestStart, "max");
- assertEquals(getRawResponse(),longString,longStringTest);
-
- //Float Date
- Collection<Float> floatDate = getFloatList("maxn","fieldFacets", "date_dtd", "float", "float");
- ArrayList<Float> floatDateTest = (ArrayList<Float>)calculateStat(floatDateTestStart, "max");
- assertEquals(getRawResponse(),floatDate,floatDateTest);
-
- //Float String
- Collection<Float> floatString = getFloatList("maxn","fieldFacets", "string_sd", "float", "float");
- ArrayList<Float> floatStringTest = (ArrayList<Float>)calculateStat(floatStringTestStart, "max");
- assertEquals(getRawResponse(),floatString,floatStringTest);
-
- //Double Date
- Collection<Double> doubleDate = getDoubleList("maxn","fieldFacets", "date_dtd", "double", "double");
- ArrayList<Double> doubleDateTest = (ArrayList<Double>)calculateStat(doubleDateTestStart, "max");
- assertEquals(getRawResponse(),doubleDate,doubleDateTest);
-
- //Double String
- Collection<Double> doubleString = getDoubleList("maxn","fieldFacets", "string_sd", "double", "double");
- ArrayList<Double> doubleStringTest = (ArrayList<Double>)calculateStat(doubleStringTestStart, "max");
- assertEquals(getRawResponse(),doubleString,doubleStringTest);
-
- //String Int
- Collection<String> stringInt = getStringList("max","fieldFacets", "int_id", "str", "str");
- ArrayList<String> stringIntTest = (ArrayList<String>)calculateStat(stringIntTestStart, "max");
- assertEquals(getRawResponse(),stringInt,stringIntTest);
-
- //String Long
- Collection<String> stringLong = getStringList("max","fieldFacets", "long_ld", "str", "str");
- ArrayList<String> stringLongTest = (ArrayList<String>)calculateStat(stringLongTestStart, "max");
- assertEquals(getRawResponse(),stringLong,stringLongTest);
-
- //Date Int
- Collection<String> dateInt = getStringList("max","fieldFacets", "int_id", "date", "date");
- ArrayList<String> dateIntTest = (ArrayList<String>)calculateStat(dateIntTestStart, "max");
- assertEquals(getRawResponse(),dateInt,dateIntTest);
-
- //Date Long
- Collection<String> dateString = getStringList("max","fieldFacets", "long_ld", "date", "date");
- ArrayList<String> dateLongTest = (ArrayList<String>)calculateStat(dateLongTestStart, "max");
- assertEquals(getRawResponse(),dateString,dateLongTest);
-
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void uniqueTest() throws Exception {
- //Int Date
- Collection<Long> intDate = getLongList("uniquen", "fieldFacets", "date_dtd", "long", "int");
- ArrayList<Long> intDateTest = (ArrayList<Long>)calculateStat(intDateTestStart, "unique");
- assertEquals(getRawResponse(),intDate,intDateTest);
- //Int String
- Collection<Long> intString = getLongList("uniquen", "fieldFacets", "string_sd", "long", "int");
- ArrayList<Long> intStringTest = (ArrayList<Long>)calculateStat(intStringTestStart, "unique");
- assertEquals(getRawResponse(),intString,intStringTest);
-
- //Long Date
- Collection<Long> longDate = getLongList("uniquen", "fieldFacets", "date_dtd", "long", "long");
- ArrayList<Long> longDateTest = (ArrayList<Long>)calculateStat(longDateTestStart, "unique");
- assertEquals(getRawResponse(),longDate,longDateTest);
- //Long String
- Collection<Long> longString = getLongList("uniquen", "fieldFacets", "string_sd", "long", "long");
- ArrayList<Long> longStringTest = (ArrayList<Long>)calculateStat(longStringTestStart, "unique");
- assertEquals(getRawResponse(),longString,longStringTest);
-
- //Float Date
- Collection<Long> floatDate = getLongList("uniquen", "fieldFacets", "date_dtd", "long", "float");
- ArrayList<Long> floatDateTest = (ArrayList<Long>)calculateStat(floatDateTestStart, "unique");
- assertEquals(getRawResponse(),floatDate,floatDateTest);
- //Float String
- Collection<Long> floatString = getLongList("uniquen", "fieldFacets", "string_sd", "long", "float");
- ArrayList<Long> floatStringTest = (ArrayList<Long>)calculateStat(floatStringTestStart, "unique");
- assertEquals(getRawResponse(),floatString,floatStringTest);
-
- //Double Date
- Collection<Long> doubleDate = getLongList("uniquen", "fieldFacets", "date_dtd", "long", "double");
- ArrayList<Long> doubleDateTest = (ArrayList<Long>)calculateStat(doubleDateTestStart, "unique");
- assertEquals(getRawResponse(),doubleDate,doubleDateTest);
- //Double String
- Collection<Long> doubleString = getLongList("uniquen", "fieldFacets", "string_sd", "long", "double");
- ArrayList<Long> doubleStringTest = (ArrayList<Long>)calculateStat(doubleStringTestStart, "unique");
- assertEquals(getRawResponse(),doubleString,doubleStringTest);
-
- //Date Int
- Collection<Long> dateInt = getLongList("unique", "fieldFacets", "int_id", "long", "date");
- ArrayList<Long> dateIntTest = (ArrayList<Long>)calculateStat(dateIntTestStart, "unique");
- assertEquals(getRawResponse(),dateInt,dateIntTest);
- //Date Long
- Collection<Long> dateString = getLongList("unique", "fieldFacets", "long_ld", "long", "date");
- ArrayList<Long> dateLongTest = (ArrayList<Long>)calculateStat(dateLongTestStart, "unique");
- assertEquals(getRawResponse(),dateString,dateLongTest);
-
- //String Int
- Collection<Long> stringInt = getLongList("unique", "fieldFacets", "int_id", "long", "str");
- ArrayList<Long> stringIntTest = (ArrayList<Long>)calculateStat(stringIntTestStart, "unique");
- assertEquals(getRawResponse(),stringInt,stringIntTest);
- //String Long
- Collection<Long> stringLong = getLongList("unique", "fieldFacets", "long_ld", "long", "str");
- ArrayList<Long> stringLongTest = (ArrayList<Long>)calculateStat(stringLongTestStart, "unique");
- assertEquals(getRawResponse(),stringLong,stringLongTest);
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void countTest() throws Exception {
- //Int Date
- Collection<Long> intDate = getLongList("countn", "fieldFacets", "date_dtd", "long", "int");
- ArrayList<Long> intDateTest = (ArrayList<Long>)calculateStat(intDateTestStart, "count");
- assertEquals(getRawResponse(),intDate,intDateTest);
-
- //Int String
- Collection<Long> intString = getLongList("countn", "fieldFacets", "string_sd", "long", "int");
- ArrayList<Long> intStringTest = (ArrayList<Long>)calculateStat(intStringTestStart, "count");
- assertEquals(getRawResponse(),intString,intStringTest);
-
- //Long Date
- Collection<Long> longDate = getLongList("countn", "fieldFacets", "date_dtd", "long", "long");
- ArrayList<Long> longDateTest = (ArrayList<Long>)calculateStat(longDateTestStart, "count");
- assertEquals(getRawResponse(),longDate,longDateTest);
-
- //Long String
- Collection<Long> longString = getLongList("countn", "fieldFacets", "string_sd", "long", "long");
- ArrayList<Long> longStringTest = (ArrayList<Long>)calculateStat(longStringTestStart, "count");
- assertEquals(getRawResponse(),longString,longStringTest);
-
- //Float Date
- Collection<Long> floatDate = getLongList("countn", "fieldFacets", "date_dtd", "long", "float");
- ArrayList<Long> floatDateTest = (ArrayList<Long>)calculateStat(floatDateTestStart, "count");
- assertEquals(getRawResponse(),floatDate,floatDateTest);
-
- //Float String
- Collection<Long> floatString = getLongList("countn", "fieldFacets", "string_sd", "long", "float");
- ArrayList<Long> floatStringTest = (ArrayList<Long>)calculateStat(floatStringTestStart, "count");
- assertEquals(getRawResponse(),floatString,floatStringTest);
-
- //Double Date
- Collection<Long> doubleDate = getLongList("countn", "fieldFacets", "date_dtd", "long", "double");
- ArrayList<Long> doubleDateTest = (ArrayList<Long>)calculateStat(doubleDateTestStart, "count");
- assertEquals(getRawResponse(),doubleDate,doubleDateTest);
-
- //Double String
- Collection<Long> doubleString = getLongList("countn", "fieldFacets", "string_sd", "long", "double");
- ArrayList<Long> doubleStringTest = (ArrayList<Long>)calculateStat(doubleStringTestStart, "count");
- assertEquals(getRawResponse(),doubleString,doubleStringTest);
-
- //Date Int
- Collection<Long> dateInt = getLongList("count", "fieldFacets", "int_id", "long", "date");
- ArrayList<Long> dateIntTest = (ArrayList<Long>)calculateStat(dateIntTestStart, "count");
- assertEquals(getRawResponse(),dateIntTest,dateInt);
-
- //Date Long
- Collection<Long> dateLong = getLongList("count", "fieldFacets", "long_ld", "long", "date");
- ArrayList<Long> dateLongTest = (ArrayList<Long>)calculateStat(dateLongTestStart, "count");
- assertEquals(getRawResponse(),dateLong,dateLongTest);
-
- //String Int
- Collection<Long> stringInt = getLongList("count", "fieldFacets", "int_id", "long", "str");
- ArrayList<Long> stringIntTest = (ArrayList<Long>)calculateStat(stringIntTestStart, "count");
- assertEquals(getRawResponse(),stringInt,stringIntTest);
-
- //String Long
- Collection<Long> stringLong = getLongList("count", "fieldFacets", "long_ld", "long", "str");
- ArrayList<Long> stringLongTest = (ArrayList<Long>)calculateStat(stringLongTestStart, "count");
- assertEquals(getRawResponse(),stringLong,stringLongTest);
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void missingTest() throws Exception {
- //Int Date
- Collection<Long> intDate = getLongList("missingn", "fieldFacets", "date_dtd", "long", "int");
- setLatestType("int");
- assertEquals(getRawResponse(),intDateTestMissing,intDate);
-
- //Int String
- Collection<Long> intString = getLongList("missingn", "fieldFacets", "string_sd", "long", "int");
- assertEquals(getRawResponse(),intStringTestMissing,intString);
-
- //Long Date
- Collection<Long> longDate = getLongList("missingn", "fieldFacets", "date_dtd", "long", "long");
- setLatestType("long");
- assertEquals(getRawResponse(),longDateTestMissing,longDate);
-
- //Long String
- Collection<Long> longString = getLongList("missingn", "fieldFacets", "string_sd", "long", "long");
- assertEquals(getRawResponse(),longStringTestMissing,longString);
-
- //Float Date
- Collection<Long> floatDate = getLongList("missingn", "fieldFacets", "date_dtd", "long", "float");
- setLatestType("float");
- assertEquals(getRawResponse(),floatDateTestMissing,floatDate);
-
- //Float String
- Collection<Long> floatString = getLongList("missingn", "fieldFacets", "string_sd", "long", "float");
- assertEquals(getRawResponse(),floatStringTestMissing,floatString);
-
- //Double Date
- Collection<Long> doubleDate = getLongList("missingn", "fieldFacets", "date_dtd", "long", "double");
- setLatestType("double");
- assertEquals(getRawResponse(),doubleDateTestMissing,doubleDate);
-
- //Double String
- Collection<Long> doubleString = getLongList("missingn", "fieldFacets", "string_sd", "long", "double");
- assertEquals(getRawResponse(),doubleStringTestMissing,doubleString);
-
- //Date Int
- Collection<Long> dateInt = getLongList("missing", "fieldFacets", "int_id", "long", "date");
- setLatestType("date");
- assertEquals(getRawResponse(),dateIntTestMissing,dateInt);
-
- //Date Long
- Collection<Long> dateLong = getLongList("missing", "fieldFacets", "long_ld", "long", "date");
- assertEquals(getRawResponse(),dateLongTestMissing,dateLong);
-
- //String Int
- Collection<Long> stringInt = getLongList("missing", "fieldFacets", "int_id", "long", "str");
- setLatestType("string");
- assertEquals(getRawResponse(),stringIntTestMissing,stringInt);
-
- //String Long
- Collection<Long> stringLong = getLongList("missing", "fieldFacets", "long_ld", "long", "str");
- assertEquals(getRawResponse(),stringLongTestMissing,stringLong);
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void multiValueTest() throws Exception {
- //Long
- Collection<Double> lon = getDoubleList("multivalued", "fieldFacets", "long_ldm", "double", "mean");
- ArrayList<Double> longTest = calculateNumberStat(multiLongTestStart, "mean");
- assertEquals(getRawResponse(),lon,longTest);
- //Date
- Collection<Double> date = getDoubleList("multivalued", "fieldFacets", "date_dtdm", "double", "mean");
- ArrayList<Double> dateTest = calculateNumberStat(multiDateTestStart, "mean");
- assertEquals(getRawResponse(),date,dateTest);
- //String
- Collection<Double> string = getDoubleList("multivalued", "fieldFacets", "string_sdm", "double", "mean");
- ArrayList<Double> stringTest = calculateNumberStat(multiStringTestStart, "mean");
- assertEquals(getRawResponse(),string,stringTest);
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void missingFacetTest() throws Exception {
- //int MultiDate
- String xPath = "/response/lst[@name='stats']/lst[@name='missingf']/lst[@name='fieldFacets']/lst[@name='date_dtdm']/lst[@name='(MISSING)']";
- Node missingNodeXPath = getNode(xPath);
- assertNotNull(getRawResponse(), missingNodeXPath);
-
- ArrayList<Double> string = getDoubleList("missingf", "fieldFacets", "date_dtdm", "double", "mean");
- //super.removeNodes(xPath, string);
- ArrayList<Double> stringTest = calculateNumberStat(multiDateTestStart, "mean");
- assertEquals(getRawResponse(), string,stringTest);
-
- //Int String
- xPath = "/response/lst[@name='stats']/lst[@name='missingf']/lst[@name='fieldFacets']/lst[@name='string_sd']/lst[@name='(MISSING)']";
- missingNodeXPath = getNode(xPath);
- String missingNodeXPathStr = xPath;
- assertNotNull(getRawResponse(), missingNodeXPath);
-
- xPath = "/response/lst[@name='stats']/lst[@name='missingf']/lst[@name='fieldFacets']/lst[@name='string_sd']/lst[@name='str0']";
- assertNull(getRawResponse(), getNode(xPath));
-
- List<Double> intString = getDoubleList("missingf", "fieldFacets", "string_sd", "double", "mean");
- //removeNodes(missingNodeXPathStr, intString);
- ArrayList<Double> intStringTest = calculateNumberStat(intStringTestStart, "mean");
- assertEquals(getRawResponse(), intString,intStringTest);
-
- //Int Date
- Collection<Double> intDate = getDoubleList("missingf", "fieldFacets", "date_dtd", "double", "mean");
- ArrayList<ArrayList<Double>> intDateMissingTestStart = (ArrayList<ArrayList<Double>>) intDateTestStart.clone();
- ArrayList<Double> intDateTest = calculateNumberStat(intDateMissingTestStart, "mean");
- assertEquals(getRawResponse(),intDate,intDateTest);
- }
-
- private void checkStddevs(ArrayList<Double> list1, ArrayList<Double> list2) {
- Collections.sort(list1);
- Collections.sort(list2);
- for (int i = 0; i<list1.size(); i++) {
- if ((Math.abs(list1.get(i)-list2.get(i))<.00000000001) == false) {
- Assert.assertEquals(getRawResponse(), list1.get(i), list2.get(i), 0.00000000001);
- }
- }
- }
-
- public static void assertEquals(String mes, Object actual, Object expected) {
- Collections.sort((List<Comparable>) actual);
- Collections.sort((List<Comparable>) expected);
- Assert.assertEquals(mes, actual, expected);
- }
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/PivotFacetTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/PivotFacetTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/PivotFacetTest.java
new file mode 100644
index 0000000..be0e853
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/PivotFacetTest.java
@@ -0,0 +1,230 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.facet;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class PivotFacetTest extends SolrAnalyticsFacetTestCase {
+
+ @BeforeClass
+ public static void populate() throws Exception {
+ for (int j = 0; j < NUM_LOOPS; ++j) {
+ int i = j%INT;
+ long l = j%LONG;
+ float f = j%FLOAT;
+ double d = j%DOUBLE;
+ String dt = (1800+j%DATE) + "-12-31T23:59:59Z";
+ String dtm = (1800+j%DATE + 10) + "-12-31T23:59:59Z";
+ String s = "str" + (j%STRING);
+ List<String> fields = new ArrayList<>();
+ fields.add("id"); fields.add("1000"+j);
+
+ if ( i != 0 ) {
+ fields.add("int_i"); fields.add("" + i);
+ fields.add("int_im"); fields.add("" + i);
+ fields.add("int_im"); fields.add("" + (i+10));
+ }
+
+ if ( l != 0l ) {
+ fields.add("long_l"); fields.add("" + l);
+ fields.add("long_lm"); fields.add("" + l);
+ fields.add("long_lm"); fields.add("" + (l+10));
+ }
+
+ if ( f != 0.0f ) {
+ fields.add("float_f"); fields.add("" + f);
+ fields.add("float_fm"); fields.add("" + f);
+ fields.add("float_fm"); fields.add("" + (f+10));
+ }
+
+ if ( d != 0.0d ) {
+ fields.add("double_d"); fields.add("" + d);
+ fields.add("double_dm"); fields.add("" + d);
+ fields.add("double_dm"); fields.add("" + (d+10));
+ }
+
+ if ( (j%DATE) != 0 ) {
+ fields.add("date_dt"); fields.add(dt);
+ fields.add("date_dtm"); fields.add(dt);
+ fields.add("date_dtm"); fields.add(dtm);
+ }
+
+ if ( (j%STRING) != 0 ) {
+ fields.add("string_s"); fields.add(s);
+ fields.add("string_sm"); fields.add(s);
+ fields.add("string_sm"); fields.add(s + "_second");
+ }
+
+ addDoc(fields);
+ }
+ commitDocs();
+ }
+
+ static public final int INT = 7;
+ static public final int LONG = 2;
+ static public final int FLOAT = 6;
+ static public final int DOUBLE = 5;
+ static public final int DATE = 3;
+ static public final int STRING = 4;
+ static public final int NUM_LOOPS = 20;
+
+ @Test
+ public void pivotFacetTest() throws Exception {
+ String analyticsRequest = "{"
+ + "\n 'groupings': { "
+ + "\n 'grouping' : { "
+ + "\n 'expressions' : { "
+ + "\n 'mean' : 'mean(fill_missing(int_i,0))', "
+ + "\n 'count' : 'count(long_lm)' "
+ + "\n }, "
+ + "\n 'facets' : { "
+ + "\n 'pivoting' : { "
+ + "\n 'type' : 'pivot', "
+ + "\n 'pivots' : [ "
+ + "\n { "
+ + "\n 'name' : 'strings', "
+ + "\n 'expression' : 'string_sm', "
+ + "\n 'sort' : { "
+ + "\n 'criteria' : [ "
+ + "\n { "
+ + "\n 'type' : 'expression', "
+ + "\n 'expression' : 'mean', "
+ + "\n 'direction' : 'ascending' "
+ + "\n }, "
+ + "\n { "
+ + "\n 'type' : 'facetvalue', "
+ + "\n 'direction' : 'descending' "
+ + "\n } "
+ + "\n ], "
+ + "\n 'limit' : 3, "
+ + "\n 'offset' : 1 "
+ + "\n } "
+ + "\n }, "
+ + "\n { "
+ + "\n 'name' : 'date', "
+ + "\n 'expression' : 'fill_missing(date_dt, \\'No Date\\')', "
+ + "\n 'sort' : { "
+ + "\n 'criteria' : [ "
+ + "\n { "
+ + "\n 'type' : 'expression', "
+ + "\n 'expression' : 'count', "
+ + "\n 'direction' : 'ascending' "
+ + "\n }, "
+ + "\n { "
+ + "\n 'type' : 'expression', "
+ + "\n 'expression' : 'mean', "
+ + "\n 'direction' : 'ascending' "
+ + "\n } "
+ + "\n ], "
+ + "\n 'limit' : 2 "
+ + "\n } "
+ + "\n } "
+ + "\n ] "
+ + "\n } "
+ + "\n } "
+ + "\n } "
+ + "\n } "
+ + "\n} ";
+
+ String test = "groupings=={'grouping':{'pivoting':["
+ + "\n { "
+ + "\n 'pivot' : 'strings', "
+ + "\n 'value' : 'str3', "
+ + "\n 'results' : { "
+ + "\n 'mean' : 2.6, "
+ + "\n 'count' : 10 "
+ + "\n }, "
+ + "\n 'children' : [ "
+ + "\n { "
+ + "\n 'pivot' : 'date', "
+ + "\n 'value' : '1802-12-31T23:59:59Z', "
+ + "\n 'results' : { "
+ + "\n 'mean' : 4.0, "
+ + "\n 'count' : 2 "
+ + "\n } "
+ + "\n }, "
+ + "\n { "
+ + "\n 'pivot' : 'date', "
+ + "\n 'value' : 'No Date', "
+ + "\n 'results' : { "
+ + "\n 'mean' : 2.0, "
+ + "\n 'count' : 4 "
+ + "\n } "
+ + "\n } "
+ + "\n ]"
+ + "\n }, "
+ + "\n { "
+ + "\n 'pivot' : 'strings', "
+ + "\n 'value' : 'str2_second', "
+ + "\n 'results' : { "
+ + "\n 'mean' : 3.0, "
+ + "\n 'count' : 0 "
+ + "\n }, "
+ + "\n 'children' : [ "
+ + "\n { "
+ + "\n 'pivot' : 'date', "
+ + "\n 'value' : '1802-12-31T23:59:59Z', "
+ + "\n 'results' : { "
+ + "\n 'mean' : 1.0, "
+ + "\n 'count' : 0 "
+ + "\n } "
+ + "\n }, "
+ + "\n { "
+ + "\n 'pivot' : 'date', "
+ + "\n 'value' : '1801-12-31T23:59:59Z', "
+ + "\n 'results' : { "
+ + "\n 'mean' : 3.0, "
+ + "\n 'count' : 0 "
+ + "\n } "
+ + "\n } "
+ + "\n ]"
+ + "\n }, "
+ + "\n { "
+ + "\n 'pivot' : 'strings', "
+ + "\n 'value' : 'str2', "
+ + "\n 'results' : { "
+ + "\n 'mean' : 3.0, "
+ + "\n 'count' : 0 "
+ + "\n }, "
+ + "\n 'children' : [ "
+ + "\n { "
+ + "\n 'pivot' : 'date', "
+ + "\n 'value' : '1802-12-31T23:59:59Z', "
+ + "\n 'results' : { "
+ + "\n 'mean' : 1.0, "
+ + "\n 'count' : 0 "
+ + "\n } "
+ + "\n }, "
+ + "\n { "
+ + "\n 'pivot' : 'date', "
+ + "\n 'value' : '1801-12-31T23:59:59Z', "
+ + "\n 'results' : { "
+ + "\n 'mean' : 3.0, "
+ + "\n 'count' : 0 "
+ + "\n } "
+ + "\n } "
+ + "\n ]"
+ + "\n } "
+ + "\n]}}";
+
+ testAnalytics(analyticsRequest, test);
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/QueryFacetCloudTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/QueryFacetCloudTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/QueryFacetCloudTest.java
deleted file mode 100644
index 42b5abe..0000000
--- a/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/QueryFacetCloudTest.java
+++ /dev/null
@@ -1,159 +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.List;
-
-import org.apache.solr.client.solrj.request.UpdateRequest;
-import org.apache.solr.common.util.NamedList;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-public class QueryFacetCloudTest extends AbstractAnalyticsFacetCloudTest {
- private static final int INT = 71;
- private static final int LONG = 36;
- private static final int FLOAT = 93;
- private static final int DOUBLE = 49;
- private static final int DATE = 12;
- private static final int STRING = 7;
- private static final int NUM_LOOPS = 100;
-
- private static ArrayList<ArrayList<Integer>> int1TestStart = new ArrayList<>();
- private static ArrayList<ArrayList<Integer>> int2TestStart = new ArrayList<>();
- private static ArrayList<ArrayList<Long>> longTestStart = new ArrayList<>();
- private static ArrayList<ArrayList<Float>> floatTestStart = new ArrayList<>();
-
- @BeforeClass
- public static void beforeClass() throws Exception {
- setupCluster();
-
- //INT
- int1TestStart.add(new ArrayList<Integer>());
- int2TestStart.add(new ArrayList<Integer>());
-
- //LONG
- longTestStart.add(new ArrayList<Long>());
- longTestStart.add(new ArrayList<Long>());
-
- //FLOAT
- floatTestStart.add(new ArrayList<Float>());
- floatTestStart.add(new ArrayList<Float>());
- floatTestStart.add(new ArrayList<Float>());
-
- UpdateRequest req = new UpdateRequest();
-
- for (int j = 0; j < NUM_LOOPS; ++j) {
- int i = j%INT;
- long l = j%LONG;
- float f = j%FLOAT;
- double d = j%DOUBLE;
- int dt = j%DATE;
- int s = j%STRING;
-
- List<String> fields = new ArrayList<>();
- fields.add("id"); fields.add("1000"+j);
- fields.add("int_id"); fields.add("" + i);
- fields.add("long_ld"); fields.add("" + l);
- fields.add("float_fd"); fields.add("" + f);
- fields.add("double_dd"); fields.add("" + d);
- fields.add("date_dtd"); fields.add((1000+dt) + "-01-01T23:59:59Z");
- fields.add("string_sd"); fields.add("abc" + s);
- req.add(fields.toArray(new String[0]));
-
- if (f<=50) {
- int1TestStart.get(0).add(i);
- }
- if (f<=30) {
- int2TestStart.get(0).add(i);
- }
- if (s == 1) {
- longTestStart.get(0).add(l);
- }
- if (s == 2) {
- longTestStart.get(1).add(l);
- }
- if (l>=30) {
- floatTestStart.get(0).add(f);
- }
- if (d<=50) {
- floatTestStart.get(1).add(f);
- }
- if (l>=20) {
- floatTestStart.get(2).add(f);
- }
- }
-
- req.commit(cluster.getSolrClient(), COLLECTIONORALIAS);
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void queryTest() throws Exception {
- String[] params = new String[] {
- "o.ir.s.sum", "sum(int_id)",
- "o.ir.s.mean", "mean(int_id)",
- "o.ir.s.median", "median(int_id)",
- "o.ir.s.percentile_8", "percentile(8,int_id)",
- "o.ir.qf", "float1",
- "o.ir.qf.float1.q", "float_fd:[* TO 50]",
- "o.ir.qf", "float2",
- "o.ir.qf.float2.q", "float_fd:[* TO 30]",
-
- "o.lr.s.sum", "sum(long_ld)",
- "o.lr.s.mean", "mean(long_ld)",
- "o.lr.s.median", "median(long_ld)",
- "o.lr.s.percentile_8", "percentile(8,long_ld)",
- "o.lr.qf", "string",
- "o.lr.qf.string.q", "string_sd:abc1",
- "o.lr.qf.string.q", "string_sd:abc2",
-
- "o.fr.s.sum", "sum(float_fd)",
- "o.fr.s.mean", "mean(float_fd)",
- "o.fr.s.median", "median(float_fd)",
- "o.fr.s.percentile_8", "percentile(8,float_fd)",
- "o.fr.qf", "lad",
- "o.fr.qf.lad.q", "long_ld:[20 TO *]",
- "o.fr.qf.lad.q", "long_ld:[30 TO *]",
- "o.fr.qf.lad.q", "double_dd:[* TO 50]"
- };
-
- NamedList<Object> response = queryCloudAnalytics(params);
- String responseStr = response.toString();
-
- //Int One
- ArrayList<Double> int1 = getValueList(response, "ir", "queryFacets", "float1", "sum", false);
- ArrayList<Double> int1Test = calculateNumberStat(int1TestStart, "sum");
- assertEquals(responseStr, int1, int1Test);
- //Int Two
- ArrayList<Integer> int2 = getValueList(response, "ir", "queryFacets", "float2", "percentile_8", false);
- ArrayList<Integer> int2Test = (ArrayList<Integer>)calculateStat(int2TestStart, "perc_8");
- assertEquals(responseStr, int2, int2Test);
-
- //Long
- ArrayList<Double> long1 = getValueList(response, "lr", "queryFacets", "string", "median", false);
- ArrayList<Double> long1Test = calculateNumberStat(longTestStart, "median");
- assertEquals(responseStr,long1,long1Test);
-
- //Float
- ArrayList<Double> float1 = getValueList(response, "fr", "queryFacets", "lad", "mean", false);
- ArrayList<Double> float1Test = calculateNumberStat(floatTestStart, "mean");
- assertEquals(responseStr, float1, float1Test);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/QueryFacetTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/QueryFacetTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/QueryFacetTest.java
index e892dc9..63a62c8 100644
--- a/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/QueryFacetTest.java
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/QueryFacetTest.java
@@ -16,109 +16,95 @@
*/
package org.apache.solr.analytics.facet;
-
import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import org.junit.BeforeClass;
import org.junit.Test;
-public class QueryFacetTest extends AbstractAnalyticsFacetTest {
- static String fileName = "queryFacets.txt";
-
- public final int INT = 71;
- public final int LONG = 36;
- public final int FLOAT = 93;
- public final int DOUBLE = 49;
- public final int DATE = 12;
- public final int STRING = 28;
- public final int NUM_LOOPS = 100;
-
+public class QueryFacetTest extends SolrAnalyticsFacetTestCase {
+
@BeforeClass
- public static void beforeClass() throws Exception {
- initCore("solrconfig-analytics.xml","schema-analytics.xml");
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void queryTest() throws Exception {
- h.update("<delete><query>*:*</query></delete>");
- //INT
- ArrayList<ArrayList<Integer>> int1TestStart = new ArrayList<>();
- int1TestStart.add(new ArrayList<Integer>());
- ArrayList<ArrayList<Integer>> int2TestStart = new ArrayList<>();
- int2TestStart.add(new ArrayList<Integer>());
-
- //LONG
- ArrayList<ArrayList<Long>> longTestStart = new ArrayList<>();
- longTestStart.add(new ArrayList<Long>());
- longTestStart.add(new ArrayList<Long>());
-
- //FLOAT
- ArrayList<ArrayList<Float>> floatTestStart = new ArrayList<>();
- floatTestStart.add(new ArrayList<Float>());
- floatTestStart.add(new ArrayList<Float>());
- floatTestStart.add(new ArrayList<Float>());
-
+ public static void populate() throws Exception {
for (int j = 0; j < NUM_LOOPS; ++j) {
int i = j%INT;
long l = j%LONG;
float f = j%FLOAT;
double d = j%DOUBLE;
- int dt = j%DATE;
- int s = j%STRING;
- assertU(adoc("id", "1000" + j, "int_id", "" + i, "long_ld", "" + l, "float_fd", "" + f,
- "double_dd", "" + d, "date_dtd", (1800+dt) + "-12-31T23:59:59.999Z", "string_sd", "abc" + new Integer(s).toString().charAt(0)));
-
- if (f<=50) {
- int1TestStart.get(0).add(i);
- }
- if (f<=30) {
- int2TestStart.get(0).add(i);
- }
- if (new Integer(s).toString().charAt(0)=='1') {
- longTestStart.get(0).add(l);
+ String dt = (1800+j%DATE) + "-12-31T23:59:59Z";
+ String dtm = (1800+j%DATE + 10) + "-12-31T23:59:59Z";
+ String s = "str" + (j%STRING);
+ List<String> fields = new ArrayList<>();
+ fields.add("id"); fields.add("1000"+j);
+
+ if ( i != 0 ) {
+ fields.add("int_i"); fields.add("" + i);
+ fields.add("int_im"); fields.add("" + i);
+ fields.add("int_im"); fields.add("" + (i+10));
}
- if (new Integer(s).toString().charAt(0)=='2') {
- longTestStart.get(1).add(l);
+
+ if ( l != 0l ) {
+ fields.add("long_l"); fields.add("" + l);
+ fields.add("long_lm"); fields.add("" + l);
+ fields.add("long_lm"); fields.add("" + (l+10));
}
- if (l>=30) {
- floatTestStart.get(0).add(f);
+
+ if ( f != 0.0f ) {
+ fields.add("float_f"); fields.add("" + f);
+ fields.add("float_fm"); fields.add("" + f);
+ fields.add("float_fm"); fields.add("" + (f+10));
}
- if (d<=50) {
- floatTestStart.get(1).add(f);
+
+ if ( d != 0.0d ) {
+ fields.add("double_d"); fields.add("" + d);
+ fields.add("double_dm"); fields.add("" + d);
+ fields.add("double_dm"); fields.add("" + (d+10));
}
- if (l>=20) {
- floatTestStart.get(2).add(f);
+
+ if ( (j%DATE) != 0 ) {
+ fields.add("date_dt"); fields.add(dt);
+ fields.add("date_dtm"); fields.add(dt);
+ fields.add("date_dtm"); fields.add(dtm);
}
- if (usually()) {
- assertU(commit()); // to have several segments
+ if ( (j%STRING) != 0 ) {
+ fields.add("string_s"); fields.add(s);
+ fields.add("string_sm"); fields.add(s);
+ fields.add("string_sm"); fields.add(s + "_second");
}
+
+ addDoc(fields);
}
+ commitDocs();
+ }
+
+ static public final int INT = 7;
+ static public final int LONG = 2;
+ static public final int FLOAT = 6;
+ static public final int DOUBLE = 5;
+ static public final int DATE = 3;
+ static public final int STRING = 4;
+ static public final int NUM_LOOPS = 20;
+
+ @Test
+ public void queryFacetTest() throws Exception {
+ Map<String, String> expressions = new HashMap<>();
+ expressions.put("mean", "mean(int_i)");
+ expressions.put("count", "count(string_sm)");
- assertU(commit());
+ // Value Facet "with_missing"
+ addFacet("with_missing", "{ 'type':'query', 'queries':{'q1':'long_l:1 AND float_f:1.0','q2':'double_dm:[3 TO 11] OR double_dm:1'}}");
+
+ addFacetValue("q1");
+ addFacetResult("mean", 4.0);
+ addFacetResult("count", 8L);
- //Query ascending tests
- setResponse(h.query(request(fileToStringArr(QueryFacetTest.class, fileName))));
+ addFacetValue("q2");
+ addFacetResult("mean", 38.0/11.0);
+ addFacetResult("count", 18L);
- //Int One
- ArrayList<Double> int1 = getDoubleList("ir", "queryFacets", "float1", "double", "sum");
- ArrayList<Double> int1Test = calculateNumberStat(int1TestStart, "sum");
- assertEquals(getRawResponse(), int1, int1Test);
- //Int Two
- ArrayList<Integer> int2 = getIntegerList("ir", "queryFacets", "float2", "int", "percentile_8");
- ArrayList<Integer> int2Test = (ArrayList<Integer>)calculateStat(int2TestStart, "perc_8");
- assertEquals(getRawResponse(), int2, int2Test);
-
- //Long
- ArrayList<Double> long1 = getDoubleList("lr", "queryFacets", "string", "double", "median");
- ArrayList<Double> long1Test = calculateNumberStat(longTestStart, "median");
- assertEquals(getRawResponse(),long1,long1Test);
-
- //Float
- ArrayList<Double> float1 = getDoubleList("fr", "queryFacets", "lad", "double", "mean");
- ArrayList<Double> float1Test = calculateNumberStat(floatTestStart, "mean");
- assertEquals(getRawResponse(), float1, float1Test);
+ testGrouping(expressions);
}
-
}
[09/20] lucene-solr:master: SOLR-11145,
SOLR-11146: Added comprehensive unit tests for Analytics Component
2.0 as well as analytics bug fixes.
Posted by dp...@apache.org.
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/FilterFunctionTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/FilterFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/FilterFunctionTest.java
new file mode 100644
index 0000000..e2bcc73
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/FilterFunctionTest.java
@@ -0,0 +1,1035 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.function.mapping;
+
+import java.time.Instant;
+import java.time.format.DateTimeParseException;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.Iterator;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.analytics.value.AnalyticsValue;
+import org.apache.solr.analytics.value.AnalyticsValueStream;
+import org.apache.solr.analytics.value.BooleanValue;
+import org.apache.solr.analytics.value.BooleanValueStream;
+import org.apache.solr.analytics.value.DateValue;
+import org.apache.solr.analytics.value.DateValueStream;
+import org.apache.solr.analytics.value.DoubleValue;
+import org.apache.solr.analytics.value.DoubleValueStream;
+import org.apache.solr.analytics.value.FloatValue;
+import org.apache.solr.analytics.value.FloatValueStream;
+import org.apache.solr.analytics.value.IntValue;
+import org.apache.solr.analytics.value.IntValueStream;
+import org.apache.solr.analytics.value.LongValue;
+import org.apache.solr.analytics.value.LongValueStream;
+import org.apache.solr.analytics.value.StringValue;
+import org.apache.solr.analytics.value.StringValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestAnalyticsValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestAnalyticsValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestBooleanValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestBooleanValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestDateValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestDateValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestIntValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestIntValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestLongValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestLongValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestStringValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestStringValueStream;
+import org.junit.Test;
+
+public class FilterFunctionTest extends SolrTestCaseJ4 {
+
+ @Test
+ public void singleValueBooleanTest() {
+ TestBooleanValue val = new TestBooleanValue();
+ TestBooleanValue filter = new TestBooleanValue();
+
+ AnalyticsValueStream uncasted = FilterFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filter});
+ assertTrue(uncasted instanceof BooleanValue);
+ BooleanValue func = (BooleanValue) uncasted;
+
+ // Value doesn't exist
+ val.setExists(false);
+ filter.setExists(false);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ val.setValue(true).setExists(true);
+ filter.setExists(false);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ val.setExists(false);
+ filter.setValue(true).setExists(true);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ // Value exists
+ val.setValue(true).setExists(true);
+ filter.setValue(true).setExists(true);
+ assertEquals(true, func.getBoolean());
+ assertTrue(func.exists());
+
+ val.setValue(true).setExists(true);
+ filter.setValue(false).setExists(true);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ val.setValue(false).setExists(true);
+ filter.setValue(true).setExists(true);
+ assertEquals(false, func.getBoolean());
+ assertTrue(func.exists());
+
+ val.setValue(false).setExists(true);
+ filter.setValue(false).setExists(true);
+ func.getBoolean();
+ assertFalse(func.exists());
+ }
+
+ @Test
+ public void singleValueIntTest() {
+ TestIntValue val = new TestIntValue();
+ TestBooleanValue filter = new TestBooleanValue();
+
+ AnalyticsValueStream uncasted = FilterFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filter});
+ assertTrue(uncasted instanceof IntValue);
+ IntValue func = (IntValue) uncasted;
+
+ // Value doesn't exist
+ val.setExists(false);
+ filter.setExists(false);
+ func.getInt();
+ assertFalse(func.exists());
+
+ val.setValue(32).setExists(true);
+ filter.setExists(false);
+ func.getInt();
+ assertFalse(func.exists());
+
+ val.setExists(false);
+ filter.setValue(true).setExists(true);
+ func.getInt();
+ assertFalse(func.exists());
+
+ // Value exists
+ val.setValue(21).setExists(true);
+ filter.setValue(true).setExists(true);
+ assertEquals(21, func.getInt());
+ assertTrue(func.exists());
+
+ val.setValue(-100).setExists(true);
+ filter.setValue(false).setExists(true);
+ func.getInt();
+ assertFalse(func.exists());
+
+ val.setValue(50).setExists(true);
+ filter.setValue(true).setExists(true);
+ assertEquals(50, func.getInt());
+ assertTrue(func.exists());
+
+ val.setValue(5432).setExists(true);
+ filter.setValue(false).setExists(true);
+ func.getInt();
+ assertFalse(func.exists());
+ }
+
+ @Test
+ public void singleValueLongTest() {
+ TestLongValue val = new TestLongValue();
+ TestBooleanValue filter = new TestBooleanValue();
+
+ AnalyticsValueStream uncasted = FilterFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filter});
+ assertTrue(uncasted instanceof LongValue);
+ LongValue func = (LongValue) uncasted;
+
+ // Value doesn't exist
+ val.setExists(false);
+ filter.setExists(false);
+ func.getLong();
+ assertFalse(func.exists());
+
+ val.setValue(32L).setExists(true);
+ filter.setExists(false);
+ func.getLong();
+ assertFalse(func.exists());
+
+ val.setExists(false);
+ filter.setValue(true).setExists(true);
+ func.getLong();
+ assertFalse(func.exists());
+
+ // Value exists
+ val.setValue(21L).setExists(true);
+ filter.setValue(true).setExists(true);
+ assertEquals(21L, func.getLong());
+ assertTrue(func.exists());
+
+ val.setValue(-100L).setExists(true);
+ filter.setValue(false).setExists(true);
+ func.getLong();
+ assertFalse(func.exists());
+
+ val.setValue(50L).setExists(true);
+ filter.setValue(true).setExists(true);
+ assertEquals(50L, func.getLong());
+ assertTrue(func.exists());
+
+ val.setValue(3245L).setExists(true);
+ filter.setValue(false).setExists(true);
+ func.getLong();
+ assertFalse(func.exists());
+ }
+
+ @Test
+ public void singleValueFloatTest() {
+ TestFloatValue val = new TestFloatValue();
+ TestBooleanValue filter = new TestBooleanValue();
+
+ AnalyticsValueStream uncasted = FilterFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filter});
+ assertTrue(uncasted instanceof FloatValue);
+ FloatValue func = (FloatValue) uncasted;
+
+ // Value doesn't exist
+ val.setExists(false);
+ filter.setExists(false);
+ func.getFloat();
+ assertFalse(func.exists());
+
+ val.setValue(32.123F).setExists(true);
+ filter.setExists(false);
+ func.getFloat();
+ assertFalse(func.exists());
+
+ val.setExists(false);
+ filter.setValue(true).setExists(true);
+ func.getFloat();
+ assertFalse(func.exists());
+
+ // Value exists
+ val.setValue(21.453F).setExists(true);
+ filter.setValue(true).setExists(true);
+ assertEquals(21.453F, func.getFloat(), .000001);
+ assertTrue(func.exists());
+
+ val.setValue(-100.123F).setExists(true);
+ filter.setValue(false).setExists(true);
+ func.getFloat();
+ assertFalse(func.exists());
+
+ val.setValue(50.5F).setExists(true);
+ filter.setValue(true).setExists(true);
+ assertEquals(50.5F, func.getFloat(), .000001);
+ assertTrue(func.exists());
+
+ val.setValue(25643.23F).setExists(true);
+ filter.setValue(false).setExists(true);
+ func.getFloat();
+ assertFalse(func.exists());
+ }
+
+ @Test
+ public void singleValueDoubleTest() {
+ TestDoubleValue val = new TestDoubleValue();
+ TestBooleanValue filter = new TestBooleanValue();
+
+ AnalyticsValueStream uncasted = FilterFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filter});
+ assertTrue(uncasted instanceof DoubleValue);
+ DoubleValue func = (DoubleValue) uncasted;
+
+ // Value doesn't exist
+ val.setExists(false);
+ filter.setExists(false);
+ func.getDouble();
+ assertFalse(func.exists());
+
+ val.setValue(32.123).setExists(true);
+ filter.setExists(false);
+ func.getDouble();
+ assertFalse(func.exists());
+
+ val.setExists(false);
+ filter.setValue(true).setExists(true);
+ func.getDouble();
+ assertFalse(func.exists());
+
+ // Value exists
+ val.setValue(21.453).setExists(true);
+ filter.setValue(true).setExists(true);
+ assertEquals(21.453, func.getDouble(), .000001);
+ assertTrue(func.exists());
+
+ val.setValue(-100.123).setExists(true);
+ filter.setValue(false).setExists(true);
+ func.getDouble();
+ assertFalse(func.exists());
+
+ val.setValue(50.5).setExists(true);
+ filter.setValue(true).setExists(true);
+ assertEquals(50.5, func.getDouble(), .000001);
+ assertTrue(func.exists());
+
+ val.setValue(25643.23).setExists(true);
+ filter.setValue(false).setExists(true);
+ func.getDouble();
+ assertFalse(func.exists());
+ }
+
+ @Test
+ public void singleValueDateTest() throws DateTimeParseException {
+ Date date1 = Date.from(Instant.parse("1810-12-02T10:30:15Z"));
+ Date date3 = Date.from(Instant.parse("2023-11-01T20:30:15Z"));
+
+ TestDateValue val = new TestDateValue();
+ TestBooleanValue filter = new TestBooleanValue();
+
+ AnalyticsValueStream uncasted = FilterFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filter});
+ assertTrue(uncasted instanceof DateValue);
+ DateValue func = (DateValue) uncasted;
+
+ // Value doesn't exist
+ val.setExists(false);
+ filter.setExists(false);
+ func.getLong();
+ assertFalse(func.exists());
+
+ val.setValue("1810-12-02T10:30:15Z").setExists(true);
+ filter.setExists(false);
+ func.getLong();
+ assertFalse(func.exists());
+
+ val.setExists(false);
+ filter.setValue(true).setExists(true);
+ func.getLong();
+ assertFalse(func.exists());
+
+ // Value exists
+ val.setValue("1810-12-02T10:30:15Z").setExists(true);
+ filter.setValue(true).setExists(true);
+ assertEquals(date1.getTime(), func.getLong());
+ assertTrue(func.exists());
+
+ val.setValue("1931-03-16T18:15:45Z").setExists(true);
+ filter.setValue(false).setExists(true);
+ func.getLong();
+ assertFalse(func.exists());
+
+ val.setValue("2023-11-01T20:30:15Z").setExists(true);
+ filter.setValue(true).setExists(true);
+ assertEquals(date3.getTime(), func.getLong());
+ assertTrue(func.exists());
+
+ val.setValue("1810-12-02T10:30:15Z").setExists(true);
+ filter.setValue(false).setExists(true);
+ func.getLong();
+ assertFalse(func.exists());
+ }
+
+ @Test
+ public void singleValueStringTest() {
+ TestStringValue val = new TestStringValue();
+ TestBooleanValue filter = new TestBooleanValue();
+
+ AnalyticsValueStream uncasted = FilterFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filter});
+ assertTrue(uncasted instanceof StringValue);
+ StringValue func = (StringValue) uncasted;
+
+ // Value doesn't exist
+ val.setExists(false);
+ filter.setExists(false);
+ func.getString();
+ assertFalse(func.exists());
+
+ val.setValue("abc123").setExists(true);
+ filter.setExists(false);
+ func.getString();
+ assertFalse(func.exists());
+
+ val.setExists(false);
+ filter.setValue(true).setExists(true);
+ func.getString();
+ assertFalse(func.exists());
+
+ // Value exists
+ val.setValue("abc").setExists(true);
+ filter.setValue(true).setExists(true);
+ assertEquals("abc", func.getString());
+ assertTrue(func.exists());
+
+ val.setValue("def").setExists(true);
+ filter.setValue(false).setExists(true);
+ func.getString();
+ assertFalse(func.exists());
+
+ val.setValue("123").setExists(true);
+ filter.setValue(true).setExists(true);
+ assertEquals("123", func.getString());
+ assertTrue(func.exists());
+
+ val.setValue("456").setExists(true);
+ filter.setValue(false).setExists(true);
+ func.getString();
+ assertFalse(func.exists());
+ }
+
+ @Test
+ public void singleValueObjectTest() {
+ TestAnalyticsValue val = new TestAnalyticsValue();
+ TestBooleanValue filter = new TestBooleanValue();
+
+ AnalyticsValueStream uncasted = FilterFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filter});
+ assertTrue(uncasted instanceof AnalyticsValue);
+ AnalyticsValue func = (AnalyticsValue) uncasted;
+
+ // Value doesn't exist
+ val.setExists(false);
+ filter.setExists(false);
+ func.getObject();
+ assertFalse(func.exists());
+
+ val.setValue("1810-12-02T10:30:15Z").setExists(true);
+ filter.setExists(false);
+ func.getObject();
+ assertFalse(func.exists());
+
+ val.setExists(false);
+ filter.setValue(true).setExists(true);
+ func.getObject();
+ assertFalse(func.exists());
+
+ // Value exists
+ val.setValue(new Long(3)).setExists(true);
+ filter.setValue(true).setExists(true);
+ assertEquals(new Long(3), func.getObject());
+ assertTrue(func.exists());
+
+ val.setValue(new Date(2)).setExists(true);
+ filter.setValue(false).setExists(true);
+ func.getObject();
+ assertFalse(func.exists());
+
+ val.setValue("3").setExists(true);
+ filter.setValue(true).setExists(true);
+ assertEquals("3", func.getObject());
+ assertTrue(func.exists());
+
+ val.setValue(new TestAnalyticsValue()).setExists(true);
+ filter.setValue(false).setExists(true);
+ func.getObject();
+ assertFalse(func.exists());
+ }
+
+ @Test
+ public void multiValueBooleanTest() {
+ TestBooleanValueStream val = new TestBooleanValueStream();
+ TestBooleanValue filter = new TestBooleanValue();
+
+ AnalyticsValueStream uncasted = FilterFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filter});
+ assertTrue(uncasted instanceof BooleanValueStream);
+ BooleanValueStream func = (BooleanValueStream) uncasted;
+
+ // No values
+ val.setValues();
+ filter.setExists(false);
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ val.setValues(false, true, false);
+ filter.setExists(false);
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ val.setValues();
+ filter.setValue(true).setExists(true);
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // One value
+ val.setValues(true);
+
+ filter.setValue(true).setExists(true);
+ Iterator<Boolean> values1 = Arrays.asList(true).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ filter.setValue(false).setExists(true);
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ filter.setValue(true).setExists(true);
+ Iterator<Boolean> values2 = Arrays.asList(true).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value);
+ });
+ assertFalse(values2.hasNext());
+
+ // Multiple values
+ val.setValues(false, false, true, true);
+
+ filter.setValue(false).setExists(true);
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ filter.setValue(true).setExists(true);
+ Iterator<Boolean> values3 = Arrays.asList(false, false, true, true).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values3.hasNext());
+ assertEquals(values3.next(), value);
+ });
+ assertFalse(values3.hasNext());
+
+ filter.setValue(false).setExists(true);
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+ }
+
+ @Test
+ public void multiValueIntTest() {
+ TestIntValueStream val = new TestIntValueStream();
+ TestBooleanValue filter = new TestBooleanValue();
+
+ AnalyticsValueStream uncasted = FilterFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filter});
+ assertTrue(uncasted instanceof IntValueStream);
+ IntValueStream func = (IntValueStream) uncasted;
+
+ // No values
+ val.setValues();
+ filter.setExists(false);
+ func.streamInts( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ val.setValues(1, 3, 5);
+ filter.setExists(false);
+ func.streamInts( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ val.setValues();
+ filter.setValue(true).setExists(true);
+ func.streamInts( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // One value
+ val.setValues(-4);
+
+ filter.setValue(true).setExists(true);
+ Iterator<Integer> values1 = Arrays.asList(-4).iterator();
+ func.streamInts( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next().intValue(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ filter.setValue(false).setExists(true);
+ func.streamInts( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ filter.setValue(true).setExists(true);
+ Iterator<Integer> values2 = Arrays.asList(-4).iterator();
+ func.streamInts( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next().intValue(), value);
+ });
+ assertFalse(values2.hasNext());
+
+ // Multiple values
+ val.setValues(4, -10, 50, -74);
+
+ filter.setValue(false).setExists(true);
+ func.streamInts( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ filter.setValue(true).setExists(true);
+ Iterator<Integer> values3 = Arrays.asList(4, -10, 50, -74).iterator();
+ func.streamInts( value -> {
+ assertTrue(values3.hasNext());
+ assertEquals(values3.next().intValue(), value);
+ });
+ assertFalse(values3.hasNext());
+
+ filter.setValue(false).setExists(true);
+ func.streamInts( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+ }
+
+ @Test
+ public void multiValueLongTest() {
+ TestLongValueStream val = new TestLongValueStream();
+ TestBooleanValue filter = new TestBooleanValue();
+
+ AnalyticsValueStream uncasted = FilterFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filter});
+ assertTrue(uncasted instanceof LongValueStream);
+ LongValueStream func = (LongValueStream) uncasted;
+
+ // No values
+ val.setValues();
+ filter.setExists(false);
+ func.streamLongs( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ val.setValues(1L, 3L, 5L);
+ filter.setExists(false);
+ func.streamLongs( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ val.setValues();
+ filter.setValue(true).setExists(true);
+ func.streamLongs( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // One value
+ val.setValues(-4L);
+
+ filter.setValue(true).setExists(true);
+ Iterator<Long> values1 = Arrays.asList(-4L).iterator();
+ func.streamLongs( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next().longValue(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ filter.setValue(false).setExists(true);
+ func.streamLongs( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ filter.setValue(true).setExists(true);
+ Iterator<Long> values2 = Arrays.asList(-4L).iterator();
+ func.streamLongs( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next().longValue(), value);
+ });
+ assertFalse(values2.hasNext());
+
+ // Multiple values
+ val.setValues(4L, -10L, 50L, -74L);
+
+ filter.setValue(false).setExists(true);
+ func.streamLongs( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ filter.setValue(true).setExists(true);
+ Iterator<Long> values3 = Arrays.asList(4L, -10L, 50L, -74L).iterator();
+ func.streamLongs( value -> {
+ assertTrue(values3.hasNext());
+ assertEquals(values3.next().longValue(), value);
+ });
+ assertFalse(values3.hasNext());
+
+ filter.setValue(false).setExists(true);
+ func.streamLongs( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+ }
+
+ @Test
+ public void multiValueFloatTest() {
+ TestFloatValueStream val = new TestFloatValueStream();
+ TestBooleanValue filter = new TestBooleanValue();
+
+ AnalyticsValueStream uncasted = FilterFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filter});
+ assertTrue(uncasted instanceof FloatValueStream);
+ FloatValueStream func = (FloatValueStream) uncasted;
+
+ // No values
+ val.setValues();
+ filter.setExists(false);
+ func.streamFloats( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ val.setValues(50.343F, -74.9874F, 2342332342.32F);
+ filter.setExists(false);
+ func.streamFloats( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ val.setValues();
+ filter.setValue(true).setExists(true);
+ func.streamFloats( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // One value
+ val.setValues(-4.23423F);
+
+ filter.setValue(true).setExists(true);
+ Iterator<Float> values1 = Arrays.asList(-4.23423F).iterator();
+ func.streamFloats( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value, .0000001);
+ });
+ assertFalse(values1.hasNext());
+
+ filter.setValue(false).setExists(true);
+ func.streamFloats( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ filter.setValue(true).setExists(true);
+ Iterator<Float> values2 = Arrays.asList(-4.23423F).iterator();
+ func.streamFloats( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value, .0000001);
+ });
+ assertFalse(values2.hasNext());
+
+ // Multiple values
+ val.setValues(4.3F, -10.134F, 50.343F, -74.9874F);
+
+ filter.setValue(false).setExists(true);
+ func.streamFloats( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ filter.setValue(true).setExists(true);
+ Iterator<Float> values3 = Arrays.asList(4.3F, -10.134F, 50.343F, -74.9874F).iterator();
+ func.streamFloats( value -> {
+ assertTrue(values3.hasNext());
+ assertEquals(values3.next(), value, .0000001);
+ });
+ assertFalse(values3.hasNext());
+
+ filter.setValue(false).setExists(true);
+ func.streamFloats( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+ }
+
+ @Test
+ public void multiValueDoubleTest() {
+ TestDoubleValueStream val = new TestDoubleValueStream();
+ TestBooleanValue filter = new TestBooleanValue();
+
+ AnalyticsValueStream uncasted = FilterFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filter});
+ assertTrue(uncasted instanceof DoubleValueStream);
+ DoubleValueStream func = (DoubleValueStream) uncasted;
+
+ // No values
+ val.setValues();
+ filter.setExists(false);
+ func.streamDoubles( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ val.setValues(50.343, -74.9874, 2342332342.32);
+ filter.setExists(false);
+ func.streamDoubles( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ val.setValues();
+ filter.setValue(true).setExists(true);
+ func.streamDoubles( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // One value
+ val.setValues(-4.23423);
+
+ filter.setValue(true).setExists(true);
+ Iterator<Double> values1 = Arrays.asList(-4.23423).iterator();
+ func.streamDoubles( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value, .0000001);
+ });
+ assertFalse(values1.hasNext());
+
+ filter.setValue(false).setExists(true);
+ func.streamDoubles( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ filter.setValue(true).setExists(true);
+ Iterator<Double> values2 = Arrays.asList(-4.23423).iterator();
+ func.streamDoubles( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value, .0000001);
+ });
+ assertFalse(values2.hasNext());
+
+ // Multiple values
+ val.setValues(4.3, -10.134, 50.343, -74.9874);
+
+ filter.setValue(false).setExists(true);
+ func.streamDoubles( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ filter.setValue(true).setExists(true);
+ Iterator<Double> values3 = Arrays.asList(4.3, -10.134, 50.343, -74.9874).iterator();
+ func.streamDoubles( value -> {
+ assertTrue(values3.hasNext());
+ assertEquals(values3.next(), value, .0000001);
+ });
+ assertFalse(values3.hasNext());
+
+ filter.setValue(false).setExists(true);
+ func.streamDoubles( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+ }
+
+ @Test
+ public void multiValueDateTest() throws DateTimeParseException {
+ Date date1 = Date.from(Instant.parse("1810-12-02T10:30:15Z"));
+ Date date2 = Date.from(Instant.parse("1931-03-16T18:15:45Z"));
+ Date date3 = Date.from(Instant.parse("2023-11-01T20:30:15Z"));
+
+ TestDateValueStream val = new TestDateValueStream();
+ TestBooleanValue filter = new TestBooleanValue();
+
+ AnalyticsValueStream uncasted = FilterFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filter});
+ assertTrue(uncasted instanceof DateValueStream);
+ DateValueStream func = (DateValueStream) uncasted;
+
+ // No values
+ val.setValues();
+ filter.setExists(false);
+ func.streamLongs( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ val.setValues("1810-12-02T10:30:15Z", "1850-12-02T20:30:15Z");
+ filter.setExists(false);
+ func.streamLongs( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ val.setValues();
+ filter.setValue(true).setExists(true);
+ func.streamLongs( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // One value
+ val.setValues("1810-12-02T10:30:15Z");
+
+ filter.setValue(true).setExists(true);
+ Iterator<Long> values1 = Arrays.asList(date1.getTime()).iterator();
+ func.streamLongs( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next().longValue(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ filter.setValue(false).setExists(true);
+ func.streamLongs( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ filter.setValue(true).setExists(true);
+ Iterator<Long> values2 = Arrays.asList(date1.getTime()).iterator();
+ func.streamLongs( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next().longValue(), value);
+ });
+ assertFalse(values2.hasNext());
+
+ // Multiple values
+ val.setValues("1810-12-02T10:30:15Z", "1931-03-16T18:15:45Z", "2023-11-01T20:30:15Z");
+
+ filter.setValue(false).setExists(true);
+ func.streamLongs( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ filter.setValue(true).setExists(true);
+ Iterator<Long> values3 = Arrays.asList(date1.getTime(), date2.getTime(), date3.getTime()).iterator();
+ func.streamLongs( value -> {
+ assertTrue(values3.hasNext());
+ assertEquals(values3.next().longValue(), value);
+ });
+ assertFalse(values3.hasNext());
+
+ filter.setValue(false).setExists(true);
+ func.streamLongs( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+ }
+
+ @Test
+ public void multiValueStringTest() {
+ TestStringValueStream val = new TestStringValueStream();
+ TestBooleanValue filter = new TestBooleanValue();
+
+ AnalyticsValueStream uncasted = FilterFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filter});
+ assertTrue(uncasted instanceof StringValueStream);
+ StringValueStream func = (StringValueStream) uncasted;
+
+ // No values
+ val.setValues();
+ filter.setExists(false);
+ func.streamStrings( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ val.setValues("abc", "123", "def", "456");
+ filter.setExists(false);
+ func.streamStrings( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ val.setValues();
+ filter.setValue(true).setExists(true);
+ func.streamStrings( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // One value
+ val.setValues("abcdef");
+
+ filter.setValue(true).setExists(true);
+ Iterator<String> values1 = Arrays.asList("abcdef").iterator();
+ func.streamStrings( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ filter.setValue(false).setExists(true);
+ func.streamStrings( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ filter.setValue(true).setExists(true);
+ Iterator<String> values2 = Arrays.asList("abcdef").iterator();
+ func.streamStrings( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value);
+ });
+ assertFalse(values2.hasNext());
+
+ // Multiple values
+ val.setValues("abc", "123", "def", "456");
+
+ filter.setValue(false).setExists(true);
+ func.streamStrings( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ filter.setValue(true).setExists(true);
+ Iterator<String> values3 = Arrays.asList("abc", "123", "def", "456").iterator();
+ func.streamStrings( value -> {
+ assertTrue(values3.hasNext());
+ assertEquals(values3.next(), value);
+ });
+ assertFalse(values3.hasNext());
+
+ filter.setValue(false).setExists(true);
+ func.streamStrings( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+ }
+
+ @Test
+ public void multiValueObjectTest() {
+ TestAnalyticsValueStream val = new TestAnalyticsValueStream();
+ TestBooleanValue filter = new TestBooleanValue();
+
+ AnalyticsValueStream func = FilterFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, filter});
+
+ // No values
+ val.setValues();
+ filter.setExists(false);
+ func.streamObjects( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ val.setValues(new Integer(3), "3", new Date(3));
+ filter.setExists(false);
+ func.streamObjects( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ val.setValues();
+ filter.setValue(true).setExists(true);
+ func.streamObjects( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // One value
+ Object obj = new TestAnalyticsValueStream();
+ val.setValues(obj);
+
+ filter.setValue(true).setExists(true);
+ Iterator<Object> values1 = Arrays.<Object>asList(obj).iterator();
+ func.streamObjects( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ filter.setValue(false).setExists(true);
+ func.streamObjects( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ filter.setValue(true).setExists(true);
+ Iterator<Object> values2 = Arrays.<Object>asList(obj).iterator();
+ func.streamObjects( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value);
+ });
+ assertFalse(values2.hasNext());
+
+ // Multiple values
+ val.setValues(new Integer(3), "3", new Date(3));
+
+ filter.setValue(false).setExists(true);
+ func.streamObjects( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ filter.setValue(true).setExists(true);
+ Iterator<Object> values3 = Arrays.<Object>asList(new Integer(3), "3", new Date(3)).iterator();
+ func.streamObjects( value -> {
+ assertTrue(values3.hasNext());
+ assertEquals(values3.next(), value);
+ });
+ assertFalse(values3.hasNext());
+
+ filter.setValue(false).setExists(true);
+ func.streamObjects( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/FloorFunctionTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/FloorFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/FloorFunctionTest.java
new file mode 100644
index 0000000..ba94fb6
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/FloorFunctionTest.java
@@ -0,0 +1,180 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.function.mapping;
+
+import java.util.Arrays;
+import java.util.Iterator;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.analytics.function.mapping.DecimalNumericConversionFunction.FloorFunction;
+import org.apache.solr.analytics.value.AnalyticsValueStream;
+import org.apache.solr.analytics.value.IntValue;
+import org.apache.solr.analytics.value.IntValueStream;
+import org.apache.solr.analytics.value.LongValue;
+import org.apache.solr.analytics.value.LongValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestIntValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestIntValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestLongValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestLongValueStream;
+import org.junit.Test;
+
+public class FloorFunctionTest extends SolrTestCaseJ4 {
+
+ @Test
+ public void singleValueFloatParameterTest() {
+ TestFloatValue val = new TestFloatValue();
+
+ AnalyticsValueStream uncasted = FloorFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof IntValue);
+ IntValue func = (IntValue) uncasted;
+
+ // Value doesn't exist
+ val.setExists(false);
+ func.getInt();
+ assertFalse(func.exists());
+
+ // Value exists
+ val.setValue(21.56F).setExists(true);
+ assertEquals(21, func.getInt());
+ assertTrue(func.exists());
+
+ val.setValue(-100.3F).setExists(true);
+ assertEquals(-101, func.getInt());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void singleValueDoubleParameterTest() {
+ TestDoubleValue val = new TestDoubleValue();
+
+ AnalyticsValueStream uncasted = FloorFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof LongValue);
+ LongValue func = (LongValue) uncasted;
+
+ // Value doesn't exist
+ val.setExists(false);
+ func.getLong();
+ assertFalse(func.exists());
+
+ // Value exists
+ val.setValue(21.56).setExists(true);
+ assertEquals(21L, func.getLong());
+ assertTrue(func.exists());
+
+ val.setValue(-100.3).setExists(true);
+ assertEquals(-101L, func.getLong());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void multiValueFloatParameterTest() {
+ TestFloatValueStream val = new TestFloatValueStream();
+
+ AnalyticsValueStream uncasted = FloorFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof IntValueStream);
+ IntValueStream func = (IntValueStream) uncasted;
+
+ // No values
+ val.setValues();
+ func.streamInts( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // One value
+ val.setValues(-4F);
+ Iterator<Integer> values1 = Arrays.asList(-4).iterator();
+ func.streamInts( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next().intValue(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ // Multiple values
+ val.setValues(4F, -10.9999F, 50.00001F, 74.99999F);
+ Iterator<Integer> values2 = Arrays.asList(4, -11, 50, 74).iterator();
+ func.streamInts( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next().intValue(), value);
+ });
+ assertFalse(values2.hasNext());
+ }
+
+ @Test
+ public void multiValueDoubleParameterTest() {
+ TestDoubleValueStream val = new TestDoubleValueStream();
+
+ AnalyticsValueStream uncasted = FloorFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof LongValueStream);
+ LongValueStream func = (LongValueStream) uncasted;
+
+ // No values
+ val.setValues();
+ func.streamLongs( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // One value
+ val.setValues(-4);
+ Iterator<Long> values1 = Arrays.asList(-4L).iterator();
+ func.streamLongs( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next().longValue(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ // Multiple values
+ val.setValues(4, -10.9999, 50.000001, 74.99999);
+ Iterator<Long> values2 = Arrays.asList(4L, -11L, 50L, 74L).iterator();
+ func.streamLongs( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next().longValue(), value);
+ });
+ assertFalse(values2.hasNext());
+ }
+
+ @Test
+ public void nonDecimalParameterTest() {
+ AnalyticsValueStream result;
+ AnalyticsValueStream param;
+
+ param = new TestIntValue();
+ result = FloorFunction.creatorFunction.apply(new AnalyticsValueStream[] {param});
+ assertTrue(result instanceof IntValue);
+ assertEquals(param, result);
+
+ param = new TestIntValueStream();
+ result = FloorFunction.creatorFunction.apply(new AnalyticsValueStream[] {param});
+ assertTrue(result instanceof IntValueStream);
+ assertEquals(param, result);
+
+ param = new TestLongValue();
+ result = FloorFunction.creatorFunction.apply(new AnalyticsValueStream[] {param});
+ assertTrue(result instanceof LongValue);
+ assertEquals(param, result);
+
+ param = new TestLongValueStream();
+ result = FloorFunction.creatorFunction.apply(new AnalyticsValueStream[] {param});
+ assertTrue(result instanceof LongValueStream);
+ assertEquals(param, result);
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/GTEFunctionTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/GTEFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/GTEFunctionTest.java
new file mode 100644
index 0000000..b6883c5
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/GTEFunctionTest.java
@@ -0,0 +1,290 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.function.mapping;
+
+import java.util.Arrays;
+import java.util.Iterator;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.analytics.function.mapping.ComparisonFunction.GTEFunction;
+import org.apache.solr.analytics.value.AnalyticsValueStream;
+import org.apache.solr.analytics.value.BooleanValue;
+import org.apache.solr.analytics.value.BooleanValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestDateValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestDateValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValueStream;
+import org.junit.Test;
+
+public class GTEFunctionTest extends SolrTestCaseJ4 {
+
+ @Test
+ public void singleValueNumericParameterTest() {
+ TestDoubleValue base = new TestDoubleValue();
+ TestDoubleValue comp = new TestDoubleValue();
+
+ AnalyticsValueStream uncasted = GTEFunction.creatorFunction.apply(new AnalyticsValueStream[] {base, comp});
+ assertTrue(uncasted instanceof BooleanValue);
+ BooleanValue func = (BooleanValue) uncasted;
+
+ // Value doesn't exist
+ base.setExists(false);
+ comp.setExists(false);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ base.setExists(false);
+ comp.setValue(3.3).setExists(true);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ base.setValue(3.3).setExists(true);
+ comp.setExists(false);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ // Value exists
+ base.setValue(21.56).setExists(true);
+ comp.setValue(21.56).setExists(true);
+ assertEquals(true, func.getBoolean());
+ assertTrue(func.exists());
+
+ base.setValue(21.56).setExists(true);
+ comp.setValue(21.57).setExists(true);
+ assertEquals(false, func.getBoolean());
+ assertTrue(func.exists());
+
+ base.setValue(21.56).setExists(true);
+ comp.setValue(-21.57).setExists(true);
+ assertEquals(true, func.getBoolean());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void singleValueDateParameterTest() {
+ TestDateValue base = new TestDateValue();
+ TestDateValue comp = new TestDateValue();
+
+ AnalyticsValueStream uncasted = GTEFunction.creatorFunction.apply(new AnalyticsValueStream[] {base, comp});
+ assertTrue(uncasted instanceof BooleanValue);
+ BooleanValue func = (BooleanValue) uncasted;
+
+ // Value doesn't exist
+ base.setExists(false);
+ comp.setExists(false);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ base.setExists(false);
+ comp.setValue("1800-01-02T10:20:30Z").setExists(true);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ base.setValue("1800-01-02T10:20:30Z").setExists(true);
+ comp.setExists(false);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ // Value exists
+ base.setValue("1800-01-02T10:20:30Z").setExists(true);
+ comp.setValue("1800-01-02T10:20:30Z").setExists(true);
+ assertEquals(true, func.getBoolean());
+ assertTrue(func.exists());
+
+ base.setValue("1800-01-02T10:20:30Z").setExists(true);
+ comp.setValue("1800-01-02T10:20:31Z").setExists(true);
+ assertEquals(false, func.getBoolean());
+ assertTrue(func.exists());
+
+ base.setValue("1800-01-02T10:20:30Z").setExists(true);
+ comp.setValue("1000-01-02T10:20:31Z").setExists(true);
+ assertEquals(true, func.getBoolean());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void oneSingleOneMultiValueNumericParameterTest() {
+ TestDoubleValue base = new TestDoubleValue();
+ TestDoubleValueStream comp = new TestDoubleValueStream();
+
+ AnalyticsValueStream uncasted = GTEFunction.creatorFunction.apply(new AnalyticsValueStream[] {base, comp});
+ assertTrue(uncasted instanceof BooleanValueStream);
+ BooleanValueStream func = (BooleanValueStream) uncasted;
+
+ // No values
+ base.setValue(-4.2).setExists(true);
+ comp.setValues();
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ base.setExists(false);
+ comp.setValues(-4.2);
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // One value
+ base.setValue(-4.2).setExists(true);
+ comp.setValues(-4);
+ Iterator<Boolean> values1 = Arrays.asList(false).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ // Multiple values
+ base.setValue(4).setExists(true);
+ comp.setValues(4, -10, 2345, -74, 4.0001);
+ Iterator<Boolean> values2 = Arrays.asList(true, true, false, true, false).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value);
+ });
+ assertFalse(values2.hasNext());
+ }
+
+ @Test
+ public void oneMultiOneSingleValueNumericParameterTest() {
+ TestDoubleValueStream base = new TestDoubleValueStream();
+ TestDoubleValue comp = new TestDoubleValue();
+
+ AnalyticsValueStream uncasted = GTEFunction.creatorFunction.apply(new AnalyticsValueStream[] {base, comp});
+ assertTrue(uncasted instanceof BooleanValueStream);
+ BooleanValueStream func = (BooleanValueStream) uncasted;
+
+ // No values
+ base.setValues();
+ comp.setValue(-4.2).setExists(true);
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ base.setValues(-4.2);
+ comp.setExists(false);
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // One value
+ base.setValues(-4.2);
+ comp.setValue(-4).setExists(true);
+ Iterator<Boolean> values1 = Arrays.asList(false).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ // Multiple values
+ base.setValues(4, -10, 2345, -74, 4.0001);
+ comp.setValue(4).setExists(true);
+ Iterator<Boolean> values2 = Arrays.asList(true, false, true, false, true).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value);
+ });
+ assertFalse(values2.hasNext());
+ }
+
+ @Test
+ public void oneSingleOneMultiValueDateParameterTest() {
+ TestDateValue base = new TestDateValue();
+ TestDateValueStream comp = new TestDateValueStream();
+
+ AnalyticsValueStream uncasted = GTEFunction.creatorFunction.apply(new AnalyticsValueStream[] {base, comp});
+ assertTrue(uncasted instanceof BooleanValueStream);
+ BooleanValueStream func = (BooleanValueStream) uncasted;
+
+ // No values
+ base.setValue("1800-01-02T10:20:30Z").setExists(true);
+ comp.setValues();
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ base.setExists(false);
+ comp.setValues("1800-01-02T10:20:30Z");
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // One value
+ base.setValue("1803-01-02T10:20:30Z").setExists(true);
+ comp.setValues("1800-01-02T10:20:30Z");
+ Iterator<Boolean> values1 = Arrays.asList(true).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ // Multiple values
+ base.setValue("1800-01-02T10:20:30Z").setExists(true);
+ comp.setValues("1800-03-02T10:20:30Z", "1799-01-01T10:20:29Z", "1800-01-02T10:20:31Z", "1800-01-02T10:20:30Z", "1800-01-02T10:20:29Z");
+ Iterator<Boolean> values2 = Arrays.asList(false, true, false, true, true).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value);
+ });
+ assertFalse(values2.hasNext());
+ }
+
+ @Test
+ public void oneMultiOneSingleValueDateParameterTest() {
+ TestDateValueStream base = new TestDateValueStream();
+ TestDateValue comp = new TestDateValue();
+
+ AnalyticsValueStream uncasted = GTEFunction.creatorFunction.apply(new AnalyticsValueStream[] {base, comp});
+ assertTrue(uncasted instanceof BooleanValueStream);
+ BooleanValueStream func = (BooleanValueStream) uncasted;
+
+ // No values
+ base.setValues();
+ comp.setValue("1800-01-02T10:20:30Z").setExists(true);
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ base.setValues("1800-01-02T10:20:30Z");
+ comp.setExists(false);
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // One value
+ base.setValues("1800-01-02T10:20:30Z");
+ comp.setValue("1803-01-02T10:20:30Z").setExists(true);
+ Iterator<Boolean> values1 = Arrays.asList(false).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ // Multiple values
+ base.setValues("1800-03-02T10:20:30Z", "1799-01-01T10:20:29Z", "1800-01-02T10:20:31Z", "1800-01-02T10:20:30Z", "1800-01-02T10:20:29Z");
+ comp.setValue("1800-01-02T10:20:30Z").setExists(true);
+ Iterator<Boolean> values2 = Arrays.asList(true, false, true, true, false).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value);
+ });
+ assertFalse(values2.hasNext());
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/GTFunctionTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/GTFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/GTFunctionTest.java
new file mode 100644
index 0000000..03c34e5
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/GTFunctionTest.java
@@ -0,0 +1,290 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.function.mapping;
+
+import java.util.Arrays;
+import java.util.Iterator;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.analytics.function.mapping.ComparisonFunction.GTFunction;
+import org.apache.solr.analytics.value.AnalyticsValueStream;
+import org.apache.solr.analytics.value.BooleanValue;
+import org.apache.solr.analytics.value.BooleanValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestDateValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestDateValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValueStream;
+import org.junit.Test;
+
+public class GTFunctionTest extends SolrTestCaseJ4 {
+
+ @Test
+ public void singleValueNumericParameterTest() {
+ TestDoubleValue base = new TestDoubleValue();
+ TestDoubleValue comp = new TestDoubleValue();
+
+ AnalyticsValueStream uncasted = GTFunction.creatorFunction.apply(new AnalyticsValueStream[] {base, comp});
+ assertTrue(uncasted instanceof BooleanValue);
+ BooleanValue func = (BooleanValue) uncasted;
+
+ // Value doesn't exist
+ base.setExists(false);
+ comp.setExists(false);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ base.setExists(false);
+ comp.setValue(3.3).setExists(true);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ base.setValue(3.3).setExists(true);
+ comp.setExists(false);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ // Value exists
+ base.setValue(21.56).setExists(true);
+ comp.setValue(21.56).setExists(true);
+ assertEquals(false, func.getBoolean());
+ assertTrue(func.exists());
+
+ base.setValue(21.56).setExists(true);
+ comp.setValue(21.57).setExists(true);
+ assertEquals(false, func.getBoolean());
+ assertTrue(func.exists());
+
+ base.setValue(21.56).setExists(true);
+ comp.setValue(-21.57).setExists(true);
+ assertEquals(true, func.getBoolean());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void singleValueDateParameterTest() {
+ TestDateValue base = new TestDateValue();
+ TestDateValue comp = new TestDateValue();
+
+ AnalyticsValueStream uncasted = GTFunction.creatorFunction.apply(new AnalyticsValueStream[] {base, comp});
+ assertTrue(uncasted instanceof BooleanValue);
+ BooleanValue func = (BooleanValue) uncasted;
+
+ // Value doesn't exist
+ base.setExists(false);
+ comp.setExists(false);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ base.setExists(false);
+ comp.setValue("1800-01-02T10:20:30Z").setExists(true);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ base.setValue("1800-01-02T10:20:30Z").setExists(true);
+ comp.setExists(false);
+ func.getBoolean();
+ assertFalse(func.exists());
+
+ // Value exists
+ base.setValue("1800-01-02T10:20:30Z").setExists(true);
+ comp.setValue("1800-01-02T10:20:30Z").setExists(true);
+ assertEquals(false, func.getBoolean());
+ assertTrue(func.exists());
+
+ base.setValue("1800-01-02T10:20:30Z").setExists(true);
+ comp.setValue("1800-01-02T10:20:31Z").setExists(true);
+ assertEquals(false, func.getBoolean());
+ assertTrue(func.exists());
+
+ base.setValue("1800-01-02T10:20:30Z").setExists(true);
+ comp.setValue("1000-01-02T10:20:31Z").setExists(true);
+ assertEquals(true, func.getBoolean());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void oneSingleOneMultiValueNumericParameterTest() {
+ TestDoubleValue base = new TestDoubleValue();
+ TestDoubleValueStream comp = new TestDoubleValueStream();
+
+ AnalyticsValueStream uncasted = GTFunction.creatorFunction.apply(new AnalyticsValueStream[] {base, comp});
+ assertTrue(uncasted instanceof BooleanValueStream);
+ BooleanValueStream func = (BooleanValueStream) uncasted;
+
+ // No values
+ base.setValue(-4.2).setExists(true);
+ comp.setValues();
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ base.setExists(false);
+ comp.setValues(-4.2);
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // One value
+ base.setValue(-4.2).setExists(true);
+ comp.setValues(-4);
+ Iterator<Boolean> values1 = Arrays.asList(false).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ // Multiple values
+ base.setValue(4).setExists(true);
+ comp.setValues(4, -10, 2345, -74, 4.0001);
+ Iterator<Boolean> values2 = Arrays.asList(false, true, false, true, false).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value);
+ });
+ assertFalse(values2.hasNext());
+ }
+
+ @Test
+ public void oneMultiOneSingleValueNumericParameterTest() {
+ TestDoubleValueStream base = new TestDoubleValueStream();
+ TestDoubleValue comp = new TestDoubleValue();
+
+ AnalyticsValueStream uncasted = GTFunction.creatorFunction.apply(new AnalyticsValueStream[] {base, comp});
+ assertTrue(uncasted instanceof BooleanValueStream);
+ BooleanValueStream func = (BooleanValueStream) uncasted;
+
+ // No values
+ base.setValues();
+ comp.setValue(-4.2).setExists(true);
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ base.setValues(-4.2);
+ comp.setExists(false);
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // One value
+ base.setValues(-4.2);
+ comp.setValue(-4).setExists(true);
+ Iterator<Boolean> values1 = Arrays.asList(false).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ // Multiple values
+ base.setValues(4, -10, 2345, -74, 4.0001);
+ comp.setValue(4).setExists(true);
+ Iterator<Boolean> values2 = Arrays.asList(false, false, true, false, true).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value);
+ });
+ assertFalse(values2.hasNext());
+ }
+
+ @Test
+ public void oneSingleOneMultiValueDateParameterTest() {
+ TestDateValue base = new TestDateValue();
+ TestDateValueStream comp = new TestDateValueStream();
+
+ AnalyticsValueStream uncasted = GTFunction.creatorFunction.apply(new AnalyticsValueStream[] {base, comp});
+ assertTrue(uncasted instanceof BooleanValueStream);
+ BooleanValueStream func = (BooleanValueStream) uncasted;
+
+ // No values
+ base.setValue("1800-01-02T10:20:30Z").setExists(true);
+ comp.setValues();
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ base.setExists(false);
+ comp.setValues("1800-01-02T10:20:30Z");
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // One value
+ base.setValue("1803-01-02T10:20:30Z").setExists(true);
+ comp.setValues("1800-01-02T10:20:30Z");
+ Iterator<Boolean> values1 = Arrays.asList(true).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ // Multiple values
+ base.setValue("1800-01-02T10:20:30Z").setExists(true);
+ comp.setValues("1800-03-02T10:20:30Z", "1799-01-01T10:20:29Z", "1800-01-02T10:20:31Z", "1800-01-02T10:20:30Z", "1800-01-02T10:20:29Z");
+ Iterator<Boolean> values2 = Arrays.asList(false, true, false, false, true).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value);
+ });
+ assertFalse(values2.hasNext());
+ }
+
+ @Test
+ public void oneMultiOneSingleValueDateParameterTest() {
+ TestDateValueStream base = new TestDateValueStream();
+ TestDateValue comp = new TestDateValue();
+
+ AnalyticsValueStream uncasted = GTFunction.creatorFunction.apply(new AnalyticsValueStream[] {base, comp});
+ assertTrue(uncasted instanceof BooleanValueStream);
+ BooleanValueStream func = (BooleanValueStream) uncasted;
+
+ // No values
+ base.setValues();
+ comp.setValue("1800-01-02T10:20:30Z").setExists(true);
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ base.setValues("1800-01-02T10:20:30Z");
+ comp.setExists(false);
+ func.streamBooleans( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // One value
+ base.setValues("1800-01-02T10:20:30Z");
+ comp.setValue("1803-01-02T10:20:30Z").setExists(true);
+ Iterator<Boolean> values1 = Arrays.asList(false).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ // Multiple values
+ base.setValues("1800-03-02T10:20:30Z", "1799-01-01T10:20:29Z", "1800-01-02T10:20:31Z", "1800-01-02T10:20:30Z", "1800-01-02T10:20:29Z");
+ comp.setValue("1800-01-02T10:20:30Z").setExists(true);
+ Iterator<Boolean> values2 = Arrays.asList(true, false, true, false, false).iterator();
+ func.streamBooleans( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value);
+ });
+ assertFalse(values2.hasNext());
+ }
+}
[04/20] lucene-solr:master: SOLR-11145,
SOLR-11146: Added comprehensive unit tests for Analytics Component
2.0 as well as analytics bug fixes.
Posted by dp...@apache.org.
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyFieldFacetCloudTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyFieldFacetCloudTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyFieldFacetCloudTest.java
new file mode 100644
index 0000000..1124140
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyFieldFacetCloudTest.java
@@ -0,0 +1,1212 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.legacy.facet;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.solr.client.solrj.request.UpdateRequest;
+import org.apache.solr.common.util.NamedList;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+
+public class LegacyFieldFacetCloudTest extends LegacyAbstractAnalyticsFacetCloudTest {
+ public static final int INT = 71;
+ public static final int LONG = 36;
+ public static final int LONGM = 50;
+ public static final int FLOAT = 73;
+ public static final int FLOATM = 84;
+ public static final int DOUBLE = 49;
+ public static final int DATE = 12;
+ public static final int DATEM = 30;
+ public static final int STRING = 29;
+ public static final int STRINGM = 41;
+ public static final int NUM_LOOPS = 100;
+
+ //INT
+ private static ArrayList<ArrayList<Integer>> intDateTestStart;
+ private static ArrayList<Long> intDateTestMissing;
+ private static ArrayList<ArrayList<Integer>> intStringTestStart;
+ private static ArrayList<Long> intStringTestMissing;
+
+ //LONG
+ private static ArrayList<ArrayList<Long>> longDateTestStart;
+ private static ArrayList<Long> longDateTestMissing;
+ private static ArrayList<ArrayList<Long>> longStringTestStart;
+ private static ArrayList<Long> longStringTestMissing;
+
+ //FLOAT
+ private static ArrayList<ArrayList<Float>> floatDateTestStart;
+ private static ArrayList<Long> floatDateTestMissing;
+ private static ArrayList<ArrayList<Float>> floatStringTestStart;
+ private static ArrayList<Long> floatStringTestMissing;
+
+ //DOUBLE
+ private static ArrayList<ArrayList<Double>> doubleDateTestStart;
+ private static ArrayList<Long> doubleDateTestMissing;
+ private static ArrayList<ArrayList<Double>> doubleStringTestStart;
+ private static ArrayList<Long> doubleStringTestMissing;
+
+ //DATE
+ private static ArrayList<ArrayList<String>> dateIntTestStart;
+ private static ArrayList<Long> dateIntTestMissing;
+ private static ArrayList<ArrayList<String>> dateLongTestStart;
+ private static ArrayList<Long> dateLongTestMissing;
+
+ //String
+ private static ArrayList<ArrayList<String>> stringIntTestStart;
+ private static ArrayList<Long> stringIntTestMissing;
+ private static ArrayList<ArrayList<String>> stringLongTestStart;
+ private static ArrayList<Long> stringLongTestMissing;
+
+ //Multi-Valued
+ private static ArrayList<ArrayList<Integer>> multiLongTestStart;
+ private static ArrayList<Long> multiLongTestMissing;
+ private static ArrayList<ArrayList<Integer>> multiStringTestStart;
+ private static ArrayList<Long> multiStringTestMissing;
+ private static ArrayList<ArrayList<Integer>> multiDateTestStart;
+ private static ArrayList<Long> multiDateTestMissing;
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ cleanIndex();
+
+ //INT
+ intDateTestStart = new ArrayList<>();
+ intDateTestMissing = new ArrayList<>();
+ intStringTestStart = new ArrayList<>();
+ intStringTestMissing = new ArrayList<>();
+
+ //LONG
+ longDateTestStart = new ArrayList<>();
+ longDateTestMissing = new ArrayList<>();
+ longStringTestStart = new ArrayList<>();
+ longStringTestMissing = new ArrayList<>();
+
+ //FLOAT
+ floatDateTestStart = new ArrayList<>();
+ floatDateTestMissing = new ArrayList<>();
+ floatStringTestStart = new ArrayList<>();
+ floatStringTestMissing = new ArrayList<>();
+
+ //DOUBLE
+ doubleDateTestStart = new ArrayList<>();
+ doubleDateTestMissing = new ArrayList<>();
+ doubleStringTestStart = new ArrayList<>();
+ doubleStringTestMissing = new ArrayList<>();
+
+ //DATE
+ dateIntTestStart = new ArrayList<>();
+ dateIntTestMissing = new ArrayList<>();
+ dateLongTestStart = new ArrayList<>();
+ dateLongTestMissing = new ArrayList<>();
+
+ //String
+ stringIntTestStart = new ArrayList<>();
+ stringIntTestMissing = new ArrayList<>();
+ stringLongTestStart = new ArrayList<>();
+ stringLongTestMissing = new ArrayList<>();
+
+ //Multi-Valued
+ multiLongTestStart = new ArrayList<>();
+ multiLongTestMissing = new ArrayList<>();
+ multiStringTestStart = new ArrayList<>();
+ multiStringTestMissing = new ArrayList<>();
+ multiDateTestStart = new ArrayList<>();
+ multiDateTestMissing = new ArrayList<>();
+
+ boolean multiCanHaveDuplicates = Boolean.getBoolean(NUMERIC_POINTS_SYSPROP);
+
+ UpdateRequest req = new UpdateRequest();
+ for (int j = 0; j < NUM_LOOPS; ++j) {
+ int i = j%INT;
+ long l = j%LONG;
+ long lm = j%LONGM;
+ float f = j%FLOAT;
+ double d = j%DOUBLE;
+ int dt = j%DATE;
+ int dtm = j%DATEM;
+ int s = j%STRING;
+ int sm = j%STRINGM;
+
+ List<String> fields = new ArrayList<>();
+ fields.add("id"); fields.add("1000"+j);
+
+ if( i != 0 ) {
+ fields.add("int_id"); fields.add("" + i);
+ }
+ if( l != 0l ) {
+ fields.add("long_ld"); fields.add("" + l);
+ fields.add("long_ldm"); fields.add("" + l);
+ }
+ if( lm != 0l ) {
+ fields.add("long_ldm"); fields.add("" + lm);
+ }
+ if( f != 0.0f ) {
+ fields.add("float_fd"); fields.add("" + f);
+ }
+ if( d != 0.0d ) {
+ fields.add("double_dd"); fields.add("" + d);
+ }
+ if( dt != 0 ) {
+ fields.add("date_dtd"); fields.add((1800+dt) + "-12-31T23:59:59Z");
+ fields.add("date_dtdm"); fields.add((1800+dt) + "-12-31T23:59:59Z");
+ }
+ if ( dtm != 0 ) {
+ fields.add("date_dtdm"); fields.add((1800+dtm) + "-12-31T23:59:59Z");
+ }
+ if ( s != 0 ) {
+ fields.add("string_sd"); fields.add("str" + s);
+ fields.add("string_sdm"); fields.add("str" + s);
+ }
+ if ( sm != 0 ) {
+ fields.add("string_sdm"); fields.add("str" + sm);
+ }
+ req.add(fields.toArray(new String[0]));
+
+ if( dt != 0 ) {
+ //Dates
+ if ( j-DATE < 0 ) {
+ ArrayList<Integer> list1 = new ArrayList<>();
+ if( i != 0 ) {
+ list1.add(i);
+ intDateTestMissing.add(0l);
+ } else {
+ intDateTestMissing.add(1l);
+ }
+ intDateTestStart.add(list1);
+ ArrayList<Long> list2 = new ArrayList<>();
+ if( l != 0l ) {
+ list2.add(l);
+ longDateTestMissing.add(0l);
+ } else {
+ longDateTestMissing.add(1l);
+ }
+ longDateTestStart.add(list2);
+ ArrayList<Float> list3 = new ArrayList<>();
+ if ( f != 0.0f ) {
+ list3.add(f);
+ floatDateTestMissing.add(0l);
+ } else {
+ floatDateTestMissing.add(1l);
+
+ }
+ floatDateTestStart.add(list3);
+ ArrayList<Double> list4 = new ArrayList<>();
+ if( d != 0.0d ) {
+ list4.add(d);
+ doubleDateTestMissing.add(0l);
+ } else {
+ doubleDateTestMissing.add(1l);
+ }
+ doubleDateTestStart.add(list4);
+ ArrayList<Integer> list5 = new ArrayList<>();
+ if( i != 0 ) {
+ list5.add(i);
+ multiDateTestMissing.add(0l);
+ } else {
+ multiDateTestMissing.add(1l);
+
+ }
+ multiDateTestStart.add(list5);
+ } else {
+ if( i != 0 ) intDateTestStart.get(dt-1).add(i); else increment(intDateTestMissing,dt-1);
+ if( l != 0l ) longDateTestStart.get(dt-1).add(l); else increment(longDateTestMissing,dt-1);
+ if( f != 0.0f ) floatDateTestStart.get(dt-1).add(f); else increment(floatDateTestMissing,dt-1);
+ if( d != 0.0d ) doubleDateTestStart.get(dt-1).add(d); else increment(doubleDateTestMissing,dt-1);
+ if( i != 0 ) multiDateTestStart.get(dt-1).add(i); else increment(multiDateTestMissing,dt-1);
+ }
+ }
+
+ if ( dtm != 0 ) {
+ if ( j-DATEM < 0 && dtm != dt ) {
+ ArrayList<Integer> list1 = new ArrayList<>();
+ if( i != 0 ) {
+ list1.add(i);
+ multiDateTestMissing.add(0l);
+ } else {
+ multiDateTestMissing.add(1l);
+ }
+ multiDateTestStart.add(list1);
+ } else if ( dtm != dt || multiCanHaveDuplicates ) {
+ if( i != 0 ) multiDateTestStart.get(dtm-1).add(i); else increment(multiDateTestMissing,dtm-1);
+ }
+ }
+
+ if( s != 0 ){
+ //Strings
+ if ( j-STRING < 0 ) {
+ ArrayList<Integer> list1 = new ArrayList<>();
+ if( i != 0 ) {
+ list1.add(i);
+ intStringTestMissing.add(0l);
+ } else {
+ intStringTestMissing.add(1l);
+ }
+ intStringTestStart.add(list1);
+ ArrayList<Long> list2 = new ArrayList<>();
+ if( l != 0l ) {
+ list2.add(l);
+ longStringTestMissing.add(0l);
+ } else {
+ longStringTestMissing.add(1l);
+ }
+ longStringTestStart.add(list2);
+ ArrayList<Float> list3 = new ArrayList<>();
+ if( f != 0.0f ){
+ list3.add(f);
+ floatStringTestMissing.add(0l);
+ } else {
+ floatStringTestMissing.add(1l);
+ }
+ floatStringTestStart.add(list3);
+ ArrayList<Double> list4 = new ArrayList<>();
+ if( d != 0.0d ) {
+ list4.add(d);
+ doubleStringTestMissing.add(0l);
+ } else {
+ doubleStringTestMissing.add(1l);
+ }
+ doubleStringTestStart.add(list4);
+ ArrayList<Integer> list5 = new ArrayList<>();
+ if( i != 0 ) {
+ list5.add(i);
+ multiStringTestMissing.add(0l);
+ } else {
+ multiStringTestMissing.add(1l);
+ }
+ multiStringTestStart.add(list5);
+ } else {
+ if( i != 0 ) intStringTestStart.get(s-1).add(i); else increment(intStringTestMissing,s-1);
+ if( l != 0l ) longStringTestStart.get(s-1).add(l); else increment(longStringTestMissing,s-1);
+ if( f != 0.0f ) floatStringTestStart.get(s-1).add(f); else increment(floatStringTestMissing,s-1);
+ if( d != 0.0d ) doubleStringTestStart.get(s-1).add(d); else increment(doubleStringTestMissing,s-1);
+ if( i != 0 ) multiStringTestStart.get(s-1).add(i); else increment(multiStringTestMissing,s-1);
+ }
+ }
+
+ //Strings
+ if( sm != 0 ){
+ if ( j-STRINGM < 0 && sm != s ) {
+ ArrayList<Integer> list1 = new ArrayList<>();
+ if( i != 0 ){
+ list1.add(i);
+ multiStringTestMissing.add(0l);
+ } else {
+ multiStringTestMissing.add(1l);
+ }
+ multiStringTestStart.add(list1);
+ } else if ( sm != s ) {
+ if( i != 0 ) multiStringTestStart.get(sm-1).add(i); else increment(multiStringTestMissing,sm-1);
+ }
+ }
+
+ //Int
+ if( i != 0 ) {
+ if ( j-INT < 0 ) {
+ ArrayList<String> list1 = new ArrayList<>();
+ if( dt != 0 ){
+ list1.add((1800+dt) + "-12-31T23:59:59Z");
+ dateIntTestMissing.add(0l);
+ } else {
+ dateIntTestMissing.add(1l);
+ }
+ dateIntTestStart.add(list1);
+ ArrayList<String> list2 = new ArrayList<>();
+ if( s != 0 ) {
+ list2.add("str"+s);
+ stringIntTestMissing.add(0l);
+ } else {
+ stringIntTestMissing.add(1l);
+ }
+ stringIntTestStart.add(list2);
+ } else {
+ if( dt != 0 ) dateIntTestStart.get(i-1).add((1800+dt) + "-12-31T23:59:59Z"); else increment(dateIntTestMissing,i-1);
+ if( s != 0 ) stringIntTestStart.get(i-1).add("str"+s); else increment(stringIntTestMissing,i-1);
+ }
+ }
+
+ //Long
+ if( l != 0 ) {
+ if ( j-LONG < 0 ) {
+ ArrayList<String> list1 = new ArrayList<>();
+ if( dt != 0 ){
+ list1.add((1800+dt) + "-12-31T23:59:59Z");
+ dateLongTestMissing.add(0l);
+ } else {
+ dateLongTestMissing.add(1l);
+ }
+ dateLongTestStart.add(list1);
+ ArrayList<String> list2 = new ArrayList<>();
+ if( s != 0 ) {
+ list2.add("str"+s);
+ stringLongTestMissing.add(0l);
+ } else {
+ stringLongTestMissing.add(1l);
+ }
+ stringLongTestStart.add(list2);
+ ArrayList<Integer> list3 = new ArrayList<>();
+ if( i != 0 ) {
+ list3.add(i);
+ multiLongTestMissing.add(0l);
+ } else {
+ multiLongTestMissing.add(1l);
+ }
+ multiLongTestStart.add(list3);
+ } else {
+ if( dt != 0 ) dateLongTestStart.get((int)l-1).add((1800+dt) + "-12-31T23:59:59Z"); else increment(dateLongTestMissing,(int)l-1);
+ if( s != 0 ) stringLongTestStart.get((int)l-1).add("str"+s); else increment(stringLongTestMissing,(int)l-1);
+ if( i != 0 ) multiLongTestStart.get((int)l-1).add(i); else increment(multiLongTestMissing,(int)l-1);
+ }
+ }
+
+ //Long
+ if( lm != 0 ) {
+ if ( j-LONGM < 0 && lm != l ) {
+ ArrayList<Integer> list1 = new ArrayList<>();
+ if( i != 0 ) {
+ list1.add(i);
+ multiLongTestMissing.add(0l);
+ } else {
+ multiLongTestMissing.add(1l);
+ }
+ multiLongTestStart.add(list1);
+ } else if ( lm != l || multiCanHaveDuplicates ) {
+ if( i != 0 ) multiLongTestStart.get((int)lm-1).add(i); else increment( multiLongTestMissing,(int)lm-1);
+ }
+ }
+
+ }
+
+ req.commit(cluster.getSolrClient(), COLLECTIONORALIAS);
+
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void sumTest() throws Exception {
+ String[] params = new String[] {
+ "o.sum.s.int", "sum(int_id)",
+ "o.sum.s.long", "sum(long_ld)",
+ "o.sum.s.float", "sum(float_fd)",
+ "o.sum.s.double", "sum(double_dd)",
+ "o.sum.ff", "string_sd",
+ "o.sum.ff", "date_dtd"
+ };
+ NamedList<Object> response = queryLegacyCloudAnalytics(params);
+ String responseStr = response.toString();
+
+ //Int Date
+ Collection<Double> intDate = getValueList(response, "sum", "fieldFacets", "date_dtd", "int", false);
+ ArrayList<Double> intDateTest = calculateFacetedNumberStat(intDateTestStart, "sum");
+ assertEquals(responseStr.toString(),intDate,intDateTest);
+ //Int String
+ Collection<Double> intString = getValueList(response, "sum", "fieldFacets", "string_sd", "int", false);
+ ArrayList<Double> intStringTest = calculateFacetedNumberStat(intStringTestStart, "sum");
+ assertEquals(responseStr,intString,intStringTest);
+
+ //Long Date
+ Collection<Double> longDate = getValueList(response, "sum", "fieldFacets", "date_dtd", "long", false);
+ ArrayList<Double> longDateTest = calculateFacetedNumberStat(longDateTestStart, "sum");
+ assertEquals(responseStr,longDate,longDateTest);
+ //Long String
+ Collection<Double> longString = getValueList(response, "sum", "fieldFacets", "string_sd", "long", false);
+ ArrayList<Double> longStringTest = calculateFacetedNumberStat(longStringTestStart, "sum");
+ assertEquals(responseStr,longString,longStringTest);
+
+ //Float Date
+ Collection<Double> floatDate = getValueList(response, "sum", "fieldFacets", "date_dtd", "float", false);
+ ArrayList<Double> floatDateTest = calculateFacetedNumberStat(floatDateTestStart, "sum");
+ assertEquals(responseStr,floatDate,floatDateTest);
+ //Float String
+ Collection<Double> floatString = getValueList(response, "sum", "fieldFacets", "string_sd", "float", false);
+ ArrayList<Double> floatStringTest = calculateFacetedNumberStat(floatStringTestStart, "sum");
+ assertEquals(responseStr,floatString,floatStringTest);
+
+ //Double Date
+ Collection<Double> doubleDate = getValueList(response, "sum", "fieldFacets", "date_dtd", "double", false);
+ ArrayList<Double> doubleDateTest = calculateFacetedNumberStat(doubleDateTestStart, "sum");
+ assertEquals(responseStr,doubleDate,doubleDateTest);
+ //Double String
+ Collection<Double> doubleString = getValueList(response, "sum", "fieldFacets", "string_sd", "double", false);
+ ArrayList<Double> doubleStringTest = calculateFacetedNumberStat(doubleStringTestStart, "sum");
+ assertEquals(responseStr,doubleString,doubleStringTest);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void meanTest() throws Exception {
+ String[] params = new String[] {
+ "o.mean.s.int", "mean(int_id)",
+ "o.mean.s.long", "mean(long_ld)",
+ "o.mean.s.float", "mean(float_fd)",
+ "o.mean.s.double", "mean(double_dd)",
+ "o.mean.ff", "string_sd",
+ "o.mean.ff", "date_dtd"
+ };
+ NamedList<Object> response = queryLegacyCloudAnalytics(params);
+ String responseStr = response.toString();
+
+ //Int Date
+ Collection<Double> intDate = getValueList(response, "mean", "fieldFacets", "date_dtd", "int", false);
+ ArrayList<Double> intDateTest = calculateFacetedNumberStat(intDateTestStart, "mean");
+ assertEquals(responseStr,intDate,intDateTest);
+ //Int String
+ Collection<Double> intString = getValueList(response, "mean", "fieldFacets", "string_sd", "int", false);
+ ArrayList<Double> intStringTest = calculateFacetedNumberStat(intStringTestStart, "mean");
+ assertEquals(responseStr,intString,intStringTest);
+
+ //Long Date
+ Collection<Double> longDate = getValueList(response, "mean", "fieldFacets", "date_dtd", "long", false);
+ ArrayList<Double> longDateTest = calculateFacetedNumberStat(longDateTestStart, "mean");
+ assertEquals(responseStr,longDate,longDateTest);
+ //Long String
+ Collection<Double> longString = getValueList(response, "mean", "fieldFacets", "string_sd", "long", false);
+ ArrayList<Double> longStringTest = calculateFacetedNumberStat(longStringTestStart, "mean");
+ assertEquals(responseStr,longString,longStringTest);
+
+ //Float Date
+ Collection<Double> floatDate = getValueList(response, "mean", "fieldFacets", "date_dtd", "float", false);
+ ArrayList<Double> floatDateTest = calculateFacetedNumberStat(floatDateTestStart, "mean");
+ assertEquals(responseStr,floatDate,floatDateTest);
+ //Float String
+ Collection<Double> floatString = getValueList(response, "mean", "fieldFacets", "string_sd", "float", false);
+ ArrayList<Double> floatStringTest = calculateFacetedNumberStat(floatStringTestStart, "mean");
+ assertEquals(responseStr,floatString,floatStringTest);
+
+ //Double Date
+ Collection<Double> doubleDate = getValueList(response, "mean", "fieldFacets", "date_dtd", "double", false);
+ ArrayList<Double> doubleDateTest = calculateFacetedNumberStat(doubleDateTestStart, "mean");
+ assertEquals(responseStr,doubleDate,doubleDateTest);
+ //Double String
+ Collection<Double> doubleString = getValueList(response, "mean", "fieldFacets", "string_sd", "double", false);
+ ArrayList<Double> doubleStringTest = calculateFacetedNumberStat(doubleStringTestStart, "mean");
+ assertEquals(responseStr,doubleString,doubleStringTest);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void stddevFacetAscTest() throws Exception {
+ String[] params = new String[] {
+ "o.stddev.s.int", "stddev(int_id)",
+ "o.stddev.s.long", "stddev(long_ld)",
+ "o.stddev.s.float", "stddev(float_fd)",
+ "o.stddev.s.double", "stddev(double_dd)",
+ "o.stddev.ff", "string_sd",
+ "o.stddev.ff", "date_dtd"
+ };
+ NamedList<Object> response = queryLegacyCloudAnalytics(params);
+
+ //Int Date
+ ArrayList<Double> intDate = getValueList(response, "stddev", "fieldFacets", "date_dtd", "int", false);
+ ArrayList<Double> intDateTest = calculateFacetedNumberStat(intDateTestStart, "stddev");
+ checkStddevs(response, intDate, intDateTest);
+ //Int String
+ ArrayList<Double> intString = getValueList(response, "stddev", "fieldFacets", "string_sd", "int", false);
+ ArrayList<Double> intStringTest = calculateFacetedNumberStat(intStringTestStart, "stddev");
+ checkStddevs(response, intString, intStringTest);
+
+ //Long Date
+ ArrayList<Double> longDate = getValueList(response, "stddev", "fieldFacets", "date_dtd", "long", false);
+ ArrayList<Double> longDateTest = calculateFacetedNumberStat(longDateTestStart, "stddev");
+ checkStddevs(response, longDate, longDateTest);
+ //Long String
+ ArrayList<Double> longString = getValueList(response, "stddev", "fieldFacets", "string_sd", "long", false);
+ ArrayList<Double> longStringTest = calculateFacetedNumberStat(longStringTestStart, "stddev");
+ checkStddevs(response, longString, longStringTest);
+
+ //Float Date
+ ArrayList<Double> floatDate = getValueList(response, "stddev", "fieldFacets", "date_dtd", "float", false);
+ ArrayList<Double> floatDateTest = calculateFacetedNumberStat(floatDateTestStart, "stddev");
+ checkStddevs(response, floatDate, floatDateTest);
+ //Float String
+ ArrayList<Double> floatString = getValueList(response, "stddev", "fieldFacets", "string_sd", "float", false);
+ ArrayList<Double> floatStringTest = calculateFacetedNumberStat(floatStringTestStart, "stddev");
+ checkStddevs(response, floatString, floatStringTest);
+
+ //Double Date
+ ArrayList<Double> doubleDate = getValueList(response, "stddev", "fieldFacets", "date_dtd", "double", false);
+ ArrayList<Double> doubleDateTest = calculateFacetedNumberStat(doubleDateTestStart, "stddev");
+ checkStddevs(response, doubleDate, doubleDateTest);
+ //Double String
+ ArrayList<Double> doubleString = getValueList(response, "stddev", "fieldFacets", "string_sd", "double", false);
+ ArrayList<Double> doubleStringTest = calculateFacetedNumberStat(doubleStringTestStart, "stddev");
+ checkStddevs(response, doubleString, doubleStringTest);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void medianFacetAscTest() throws Exception {
+ String[] params = new String[] {
+ "o.median.s.int", "median(int_id)",
+ "o.median.s.long", "median(long_ld)",
+ "o.median.s.float", "median(float_fd)",
+ "o.median.s.double", "median(double_dd)",
+ "o.median.ff", "string_sd",
+ "o.median.ff", "date_dtd"
+ };
+ NamedList<Object> response = queryLegacyCloudAnalytics(params);
+ String responseStr = response.toString();
+
+ //Int Date
+ Collection<Double> intDate = getValueList(response, "median","fieldFacets", "date_dtd", "int", false);
+ ArrayList<Double> intDateTest = calculateFacetedNumberStat(intDateTestStart, "median");
+ assertEquals(responseStr,intDate,intDateTest);
+ //Int String
+ Collection<Double> intString = getValueList(response, "median", "fieldFacets", "string_sd", "int", false);
+ ArrayList<Double> intStringTest = calculateFacetedNumberStat(intStringTestStart, "median");
+ assertEquals(responseStr,intString,intStringTest);
+
+ //Long Date
+ Collection<Double> longDate = getValueList(response, "median", "fieldFacets", "date_dtd", "long", false);
+ ArrayList<Double> longDateTest = calculateFacetedNumberStat(longDateTestStart, "median");
+ assertEquals(responseStr,longDate,longDateTest);
+ //Long String
+ Collection<Double> longString = getValueList(response, "median", "fieldFacets", "string_sd", "long", false);
+ ArrayList<Double> longStringTest = calculateFacetedNumberStat(longStringTestStart, "median");
+ assertEquals(responseStr,longString,longStringTest);
+
+ //Float Date
+ Collection<Double> floatDate = getValueList(response, "median", "fieldFacets", "date_dtd", "float", false);
+ ArrayList<Double> floatDateTest = calculateFacetedNumberStat(floatDateTestStart, "median");
+ assertEquals(responseStr,floatDate,floatDateTest);
+ //Float String
+ Collection<Double> floatString = getValueList(response, "median", "fieldFacets", "string_sd", "float", false);
+ ArrayList<Double> floatStringTest = calculateFacetedNumberStat(floatStringTestStart, "median");
+ assertEquals(responseStr,floatString,floatStringTest);
+
+ //Double Date
+ Collection<Double> doubleDate = getValueList(response, "median", "fieldFacets", "date_dtd", "double", false);
+ ArrayList<Double> doubleDateTest = calculateFacetedNumberStat(doubleDateTestStart, "median");
+ assertEquals(responseStr,doubleDate,doubleDateTest);
+ //Double String
+ Collection<Double> doubleString = getValueList(response, "median", "fieldFacets", "string_sd", "double", false);
+ ArrayList<Double> doubleStringTest = calculateFacetedNumberStat(doubleStringTestStart, "median");
+ assertEquals(responseStr,doubleString,doubleStringTest);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void perc20Test() throws Exception {
+ String[] params = new String[] {
+ "o.percentile_20n.s.int", "percentile(20,int_id)",
+ "o.percentile_20n.s.long", "percentile(20,long_ld)",
+ "o.percentile_20n.s.float", "percentile(20,float_fd)",
+ "o.percentile_20n.s.double", "percentile(20,double_dd)",
+ "o.percentile_20n.ff", "string_sd",
+ "o.percentile_20n.ff", "date_dtd",
+
+ "o.percentile_20.s.str", "percentile(20,string_sd)",
+ "o.percentile_20.s.date", "string(percentile(20,date_dtd))",
+ "o.percentile_20.ff", "int_id",
+ "o.percentile_20.ff", "long_ld"
+ };
+ NamedList<Object> response = queryLegacyCloudAnalytics(params);
+ String responseStr = response.toString();
+
+ //Int Date
+ Collection<Integer> intDate = getValueList(response, "percentile_20n", "fieldFacets", "date_dtd", "int", false);
+ ArrayList<Integer> intDateTest = (ArrayList<Integer>)calculateFacetedStat(intDateTestStart, "perc_20");
+ assertEquals(responseStr,intDate,intDateTest);
+ //Int String
+ Collection<Integer> intString = getValueList(response, "percentile_20n", "fieldFacets", "string_sd", "int", false);
+ ArrayList<Integer> intStringTest = (ArrayList<Integer>)calculateFacetedStat(intStringTestStart, "perc_20");
+ assertEquals(responseStr,intString,intStringTest);
+
+ //Long Date
+ Collection<Long> longDate = getValueList(response, "percentile_20n", "fieldFacets", "date_dtd", "long", false);
+ ArrayList<Long> longDateTest = (ArrayList<Long>)calculateFacetedStat(longDateTestStart, "perc_20");
+ assertEquals(responseStr,longDate,longDateTest);
+ //Long String
+ Collection<Long> longString = getValueList(response, "percentile_20n", "fieldFacets", "string_sd", "long", false);
+ ArrayList<Long> longStringTest = (ArrayList<Long>)calculateFacetedStat(longStringTestStart, "perc_20");
+ assertEquals(responseStr,longString,longStringTest);
+
+ //Float Date
+ Collection<Float> floatDate = getValueList(response, "percentile_20n", "fieldFacets", "date_dtd", "float", false);
+ ArrayList<Float> floatDateTest = (ArrayList<Float>)calculateFacetedStat(floatDateTestStart, "perc_20");
+ assertEquals(responseStr,floatDate,floatDateTest);
+ //Float String
+ Collection<Float> floatString = getValueList(response, "percentile_20n", "fieldFacets", "string_sd", "float", false);
+ ArrayList<Float> floatStringTest = (ArrayList<Float>)calculateFacetedStat(floatStringTestStart, "perc_20");
+ assertEquals(responseStr,floatString,floatStringTest);
+
+ //Double Date
+ Collection<Double> doubleDate = getValueList(response, "percentile_20n", "fieldFacets", "date_dtd", "double", false);
+ ArrayList<Double> doubleDateTest = (ArrayList<Double>)calculateFacetedStat(doubleDateTestStart, "perc_20");
+ assertEquals(responseStr,doubleDate,doubleDateTest);
+ //Double String
+ Collection<Double> doubleString = getValueList(response, "percentile_20n", "fieldFacets", "string_sd", "double", false);
+ ArrayList<Double> doubleStringTest = (ArrayList<Double>)calculateFacetedStat(doubleStringTestStart, "perc_20");
+ assertEquals(responseStr,doubleString,doubleStringTest);
+
+ //Date Int
+ Collection<String> dateInt = getValueList(response, "percentile_20", "fieldFacets", "int_id", "date", false);
+ ArrayList<String> dateIntTest = (ArrayList<String>)calculateFacetedStat(dateIntTestStart, "perc_20");
+ assertEquals(responseStr,dateInt,dateIntTest);
+ //Date Long
+ Collection<String> dateString = getValueList(response, "percentile_20", "fieldFacets", "long_ld", "date", false);
+ ArrayList<String> dateLongTest = (ArrayList<String>)calculateFacetedStat(dateLongTestStart, "perc_20");
+ assertEquals(responseStr,dateString,dateLongTest);
+
+ //String Int
+ Collection<String> stringInt = getValueList(response, "percentile_20", "fieldFacets", "int_id", "str", false);
+ ArrayList<String> stringIntTest = (ArrayList<String>)calculateFacetedStat(stringIntTestStart, "perc_20");
+ assertEquals(responseStr,stringInt,stringIntTest);
+ //String Long
+ Collection<String> stringLong = getValueList(response, "percentile_20", "fieldFacets", "long_ld", "str", false);
+ ArrayList<String> stringLongTest = (ArrayList<String>)calculateFacetedStat(stringLongTestStart, "perc_20");
+ assertEquals(responseStr,stringLong,stringLongTest);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void perc60Test() throws Exception {
+ String[] params = new String[] {
+ "o.percentile_60n.s.int", "percentile(60,int_id)",
+ "o.percentile_60n.s.long", "percentile(60,long_ld)",
+ "o.percentile_60n.s.float", "percentile(60,float_fd)",
+ "o.percentile_60n.s.double", "percentile(60,double_dd)",
+ "o.percentile_60n.ff", "string_sd",
+ "o.percentile_60n.ff", "date_dtd",
+
+ "o.percentile_60.s.str", "percentile(60,string_sd)",
+ "o.percentile_60.s.date", "string(percentile(60,date_dtd))",
+ "o.percentile_60.ff", "int_id",
+ "o.percentile_60.ff", "long_ld"
+ };
+ NamedList<Object> response = queryLegacyCloudAnalytics(params);
+ String responseStr = response.toString();
+
+ //Int Date
+ Collection<Integer> intDate = getValueList(response, "percentile_60n", "fieldFacets", "date_dtd", "int", false);
+ ArrayList<Integer> intDateTest = (ArrayList<Integer>)calculateFacetedStat(intDateTestStart, "perc_60");
+ assertEquals(responseStr,intDate,intDateTest);
+ //Int String
+ Collection<Integer> intString = getValueList(response, "percentile_60n", "fieldFacets", "string_sd", "int", false);
+ ArrayList<Integer> intStringTest = (ArrayList<Integer>)calculateFacetedStat(intStringTestStart, "perc_60");
+ assertEquals(responseStr,intString,intStringTest);
+
+ //Long Date
+ Collection<Long> longDate = getValueList(response, "percentile_60n", "fieldFacets", "date_dtd", "long", false);
+ ArrayList<Long> longDateTest = (ArrayList<Long>)calculateFacetedStat(longDateTestStart, "perc_60");
+ assertEquals(responseStr,longDate,longDateTest);
+ //Long String
+ Collection<Long> longString = getValueList(response, "percentile_60n", "fieldFacets", "string_sd", "long", false);
+ ArrayList<Long> longStringTest = (ArrayList<Long>)calculateFacetedStat(longStringTestStart, "perc_60");
+ assertEquals(responseStr,longString,longStringTest);
+
+ //Float Date
+ Collection<Float> floatDate = getValueList(response, "percentile_60n", "fieldFacets", "date_dtd", "float", false);
+ ArrayList<Float> floatDateTest = (ArrayList<Float>)calculateFacetedStat(floatDateTestStart, "perc_60");
+ assertEquals(responseStr,floatDate,floatDateTest);
+ //Float String
+ Collection<Float> floatString = getValueList(response, "percentile_60n", "fieldFacets", "string_sd", "float", false);
+ ArrayList<Float> floatStringTest = (ArrayList<Float>)calculateFacetedStat(floatStringTestStart, "perc_60");
+ assertEquals(responseStr,floatString,floatStringTest);
+
+ //Double Date
+ Collection<Double> doubleDate = getValueList(response, "percentile_60n", "fieldFacets", "date_dtd", "double", false);
+ ArrayList<Double> doubleDateTest = (ArrayList<Double>)calculateFacetedStat(doubleDateTestStart, "perc_60");
+ assertEquals(responseStr,doubleDate,doubleDateTest);
+ //Double String
+ Collection<Double> doubleString = getValueList(response, "percentile_60n", "fieldFacets", "string_sd", "double", false);
+ ArrayList<Double> doubleStringTest = (ArrayList<Double>)calculateFacetedStat(doubleStringTestStart, "perc_60");
+ assertEquals(responseStr,doubleString,doubleStringTest);
+
+ //Date Int
+ Collection<String> dateInt = getValueList(response, "percentile_60", "fieldFacets", "int_id", "date", false);
+ ArrayList<String> dateIntTest = (ArrayList<String>)calculateFacetedStat(dateIntTestStart, "perc_60");
+ assertEquals(responseStr,dateInt,dateIntTest);
+ //Date Long
+ Collection<String> dateString = getValueList(response, "percentile_60", "fieldFacets", "long_ld", "date", false);
+ ArrayList<String> dateLongTest = (ArrayList<String>)calculateFacetedStat(dateLongTestStart, "perc_60");
+ assertEquals(responseStr,dateString,dateLongTest);
+
+ //String Int
+ Collection<String> stringInt = getValueList(response, "percentile_60", "fieldFacets", "int_id", "str", false);
+ ArrayList<String> stringIntTest = (ArrayList<String>)calculateFacetedStat(stringIntTestStart, "perc_60");
+ assertEquals(responseStr,stringInt,stringIntTest);
+ //String Long
+ Collection<String> stringLong = getValueList(response, "percentile_60", "fieldFacets", "long_ld", "str", false);
+ ArrayList<String> stringLongTest = (ArrayList<String>)calculateFacetedStat(stringLongTestStart, "perc_60");
+ assertEquals(responseStr,stringLong,stringLongTest);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void minTest() throws Exception {
+ String[] params = new String[] {
+ "o.minn.s.int", "min(int_id)",
+ "o.minn.s.long", "min(long_ld)",
+ "o.minn.s.float", "min(float_fd)",
+ "o.minn.s.double", "min(double_dd)",
+ "o.minn.ff", "string_sd",
+ "o.minn.ff", "date_dtd",
+
+ "o.min.s.str", "min(string_sd)",
+ "o.min.s.date", "string(min(date_dtd))",
+ "o.min.ff", "int_id",
+ "o.min.ff", "long_ld"
+ };
+ NamedList<Object> response = queryLegacyCloudAnalytics(params);
+ String responseStr = response.toString();
+
+ //Int Date
+ Collection<Integer> intDate = getValueList(response, "minn", "fieldFacets", "date_dtd", "int", false);
+ ArrayList<Integer> intDateTest = (ArrayList<Integer>)calculateFacetedStat(intDateTestStart, "min");
+ assertEquals(responseStr,intDate,intDateTest);
+ //Int String
+ Collection<Integer> intString = getValueList(response, "minn", "fieldFacets", "string_sd", "int", false);
+ ArrayList<Integer> intStringTest = (ArrayList<Integer>)calculateFacetedStat(intStringTestStart, "min");
+ assertEquals(responseStr,intString,intStringTest);
+
+ //Long Date
+ Collection<Long> longDate = getValueList(response, "minn", "fieldFacets", "date_dtd", "long", false);
+ ArrayList<Long> longDateTest = (ArrayList<Long>)calculateFacetedStat(longDateTestStart, "min");
+ assertEquals(responseStr,longDate,longDateTest);
+ //Long String
+ Collection<Long> longString = getValueList(response, "minn", "fieldFacets", "string_sd", "long", false);
+ ArrayList<Long> longStringTest = (ArrayList<Long>)calculateFacetedStat(longStringTestStart, "min");
+ assertEquals(responseStr,longString,longStringTest);
+
+ //Float Date
+ Collection<Float> floatDate = getValueList(response, "minn", "fieldFacets", "date_dtd", "float", false);
+ ArrayList<Float> floatDateTest = (ArrayList<Float>)calculateFacetedStat(floatDateTestStart, "min");
+ assertEquals(responseStr,floatDate,floatDateTest);
+ //Float String
+ Collection<Float> floatString = getValueList(response, "minn", "fieldFacets", "string_sd", "float", false);
+ ArrayList<Float> floatStringTest = (ArrayList<Float>)calculateFacetedStat(floatStringTestStart, "min");
+ assertEquals(responseStr,floatString,floatStringTest);
+
+ //Double Date
+ Collection<Double> doubleDate = getValueList(response, "minn", "fieldFacets", "date_dtd", "double", false);
+ ArrayList<Double> doubleDateTest = (ArrayList<Double>)calculateFacetedStat(doubleDateTestStart, "min");
+ assertEquals(responseStr,doubleDate,doubleDateTest);
+ //Double String
+ Collection<Double> doubleString = getValueList(response, "minn", "fieldFacets", "string_sd", "double", false);
+ ArrayList<Double> doubleStringTest = (ArrayList<Double>)calculateFacetedStat(doubleStringTestStart, "min");
+ assertEquals(responseStr,doubleString,doubleStringTest);
+
+ //Date Int
+ Collection<String> dateInt = getValueList(response, "min", "fieldFacets", "int_id", "date", false);
+ ArrayList<String> dateIntTest = (ArrayList<String>)calculateFacetedStat(dateIntTestStart, "min");
+ assertEquals(responseStr,dateInt,dateIntTest);
+ //Date Long
+ Collection<String> dateString = getValueList(response, "min", "fieldFacets", "long_ld", "date", false);
+ ArrayList<String> dateLongTest = (ArrayList<String>)calculateFacetedStat(dateLongTestStart, "min");
+ assertEquals(responseStr,dateString,dateLongTest);
+
+ //String Int
+ Collection<String> stringInt = getValueList(response, "min", "fieldFacets", "int_id", "str", false);
+ ArrayList<String> stringIntTest = (ArrayList<String>)calculateFacetedStat(stringIntTestStart, "min");
+ assertEquals(responseStr,stringInt,stringIntTest);
+ //String Long
+ Collection<String> stringLong = getValueList(response, "min", "fieldFacets", "long_ld", "str", false);
+ ArrayList<String> stringLongTest = (ArrayList<String>)calculateFacetedStat(stringLongTestStart, "min");
+ assertEquals(responseStr,stringLong,stringLongTest);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void maxTest() throws Exception {
+ String[] params = new String[] {
+ "o.maxn.s.int", "max(int_id)",
+ "o.maxn.s.long", "max(long_ld)",
+ "o.maxn.s.float", "max(float_fd)",
+ "o.maxn.s.double", "max(double_dd)",
+ "o.maxn.ff", "string_sd",
+ "o.maxn.ff", "date_dtd",
+
+ "o.max.s.str", "max(string_sd)",
+ "o.max.s.date", "string(max(date_dtd))",
+ "o.max.ff", "int_id",
+ "o.max.ff", "long_ld"
+ };
+ NamedList<Object> response = queryLegacyCloudAnalytics(params);
+ String responseStr = response.toString();
+
+ //Int Date
+ Collection<Integer> intDate = getValueList(response, "maxn", "fieldFacets", "date_dtd", "int", false);
+ ArrayList<Integer> intDateTest = (ArrayList<Integer>)calculateFacetedStat(intDateTestStart, "max");
+ assertEquals(responseStr,intDate,intDateTest);
+
+ //Int String
+ Collection<Integer> intString = getValueList(response, "maxn", "fieldFacets", "string_sd", "int", false);
+ ArrayList<Integer> intStringTest = (ArrayList<Integer>)calculateFacetedStat(intStringTestStart, "max");
+ assertEquals(responseStr,intString,intStringTest);
+
+ //Long Date
+ Collection<Long> longDate = getValueList(response, "maxn", "fieldFacets", "date_dtd", "long", false);
+ ArrayList<Long> longDateTest = (ArrayList<Long>)calculateFacetedStat(longDateTestStart, "max");
+ assertEquals(responseStr,longDate,longDateTest);
+
+ //Long String
+ Collection<Long> longString = getValueList(response, "maxn", "fieldFacets", "string_sd", "long", false);
+ ArrayList<Long> longStringTest = (ArrayList<Long>)calculateFacetedStat(longStringTestStart, "max");
+ assertEquals(responseStr,longString,longStringTest);
+
+ //Float Date
+ Collection<Float> floatDate = getValueList(response, "maxn", "fieldFacets", "date_dtd", "float", false);
+ ArrayList<Float> floatDateTest = (ArrayList<Float>)calculateFacetedStat(floatDateTestStart, "max");
+ assertEquals(responseStr,floatDate,floatDateTest);
+
+ //Float String
+ Collection<Float> floatString = getValueList(response, "maxn", "fieldFacets", "string_sd", "float", false);
+ ArrayList<Float> floatStringTest = (ArrayList<Float>)calculateFacetedStat(floatStringTestStart, "max");
+ assertEquals(responseStr,floatString,floatStringTest);
+
+ //Double Date
+ Collection<Double> doubleDate = getValueList(response, "maxn", "fieldFacets", "date_dtd", "double", false);
+ ArrayList<Double> doubleDateTest = (ArrayList<Double>)calculateFacetedStat(doubleDateTestStart, "max");
+ assertEquals(responseStr,doubleDate,doubleDateTest);
+
+ //Double String
+ Collection<Double> doubleString = getValueList(response, "maxn", "fieldFacets", "string_sd", "double", false);
+ ArrayList<Double> doubleStringTest = (ArrayList<Double>)calculateFacetedStat(doubleStringTestStart, "max");
+ assertEquals(responseStr,doubleString,doubleStringTest);
+
+ //String Int
+ Collection<String> stringInt = getValueList(response, "max", "fieldFacets", "int_id", "str", false);
+ ArrayList<String> stringIntTest = (ArrayList<String>)calculateFacetedStat(stringIntTestStart, "max");
+ assertEquals(responseStr,stringInt,stringIntTest);
+
+ //String Long
+ Collection<String> stringLong = getValueList(response, "max", "fieldFacets", "long_ld", "str", false);
+ ArrayList<String> stringLongTest = (ArrayList<String>)calculateFacetedStat(stringLongTestStart, "max");
+ assertEquals(responseStr,stringLong,stringLongTest);
+
+ //Date Int
+ Collection<String> dateInt = getValueList(response, "max", "fieldFacets", "int_id", "date", false);
+ ArrayList<String> dateIntTest = (ArrayList<String>)calculateFacetedStat(dateIntTestStart, "max");
+ assertEquals(responseStr,dateInt,dateIntTest);
+
+ //Date Long
+ Collection<String> dateString = getValueList(response, "max", "fieldFacets", "long_ld", "date", false);
+ ArrayList<String> dateLongTest = (ArrayList<String>)calculateFacetedStat(dateLongTestStart, "max");
+ assertEquals(responseStr,dateString,dateLongTest);
+
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void uniqueTest() throws Exception {
+ String[] params = new String[] {
+ "o.uniquen.s.int", "unique(int_id)",
+ "o.uniquen.s.long", "unique(long_ld)",
+ "o.uniquen.s.float", "unique(float_fd)",
+ "o.uniquen.s.double", "unique(double_dd)",
+ "o.uniquen.ff", "string_sd",
+ "o.uniquen.ff", "date_dtd",
+
+ "o.unique.s.str", "unique(string_sd)",
+ "o.unique.s.date", "unique(date_dtd)",
+ "o.unique.ff", "int_id",
+ "o.unique.ff", "long_ld"
+ };
+ NamedList<Object> response = queryLegacyCloudAnalytics(params);
+ String responseStr = response.toString();
+
+ //Int Date
+ Collection<Long> intDate = getValueList(response, "uniquen", "fieldFacets", "date_dtd", "int", false);
+ ArrayList<Long> intDateTest = (ArrayList<Long>)calculateFacetedStat(intDateTestStart, "unique");
+ assertEquals(responseStr,intDate,intDateTest);
+ //Int String
+ Collection<Long> intString = getValueList(response, "uniquen", "fieldFacets", "string_sd", "int", false);
+ ArrayList<Long> intStringTest = (ArrayList<Long>)calculateFacetedStat(intStringTestStart, "unique");
+ assertEquals(responseStr,intString,intStringTest);
+
+ //Long Date
+ Collection<Long> longDate = getValueList(response, "uniquen", "fieldFacets", "date_dtd", "long", false);
+ ArrayList<Long> longDateTest = (ArrayList<Long>)calculateFacetedStat(longDateTestStart, "unique");
+ assertEquals(responseStr,longDate,longDateTest);
+ //Long String
+ Collection<Long> longString = getValueList(response, "uniquen", "fieldFacets", "string_sd", "long", false);
+ ArrayList<Long> longStringTest = (ArrayList<Long>)calculateFacetedStat(longStringTestStart, "unique");
+ assertEquals(responseStr,longString,longStringTest);
+
+ //Float Date
+ Collection<Long> floatDate = getValueList(response, "uniquen", "fieldFacets", "date_dtd", "float", false);
+ ArrayList<Long> floatDateTest = (ArrayList<Long>)calculateFacetedStat(floatDateTestStart, "unique");
+ assertEquals(responseStr,floatDate,floatDateTest);
+ //Float String
+ Collection<Long> floatString = getValueList(response, "uniquen", "fieldFacets", "string_sd", "float", false);
+ ArrayList<Long> floatStringTest = (ArrayList<Long>)calculateFacetedStat(floatStringTestStart, "unique");
+ assertEquals(responseStr,floatString,floatStringTest);
+
+ //Double Date
+ Collection<Long> doubleDate = getValueList(response, "uniquen", "fieldFacets", "date_dtd", "double", false);
+ ArrayList<Long> doubleDateTest = (ArrayList<Long>)calculateFacetedStat(doubleDateTestStart, "unique");
+ assertEquals(responseStr,doubleDate,doubleDateTest);
+ //Double String
+ Collection<Long> doubleString = getValueList(response, "uniquen", "fieldFacets", "string_sd", "double", false);
+ ArrayList<Long> doubleStringTest = (ArrayList<Long>)calculateFacetedStat(doubleStringTestStart, "unique");
+ assertEquals(responseStr,doubleString,doubleStringTest);
+
+ //Date Int
+ Collection<Long> dateInt = getValueList(response, "unique", "fieldFacets", "int_id", "date", false);
+ ArrayList<Long> dateIntTest = (ArrayList<Long>)calculateFacetedStat(dateIntTestStart, "unique");
+ assertEquals(responseStr,dateInt,dateIntTest);
+ //Date Long
+ Collection<Long> dateString = getValueList(response, "unique", "fieldFacets", "long_ld", "date", false);
+ ArrayList<Long> dateLongTest = (ArrayList<Long>)calculateFacetedStat(dateLongTestStart, "unique");
+ assertEquals(responseStr,dateString,dateLongTest);
+
+ //String Int
+ Collection<Long> stringInt = getValueList(response, "unique", "fieldFacets", "int_id", "str", false);
+ ArrayList<Long> stringIntTest = (ArrayList<Long>)calculateFacetedStat(stringIntTestStart, "unique");
+ assertEquals(responseStr,stringInt,stringIntTest);
+ //String Long
+ Collection<Long> stringLong = getValueList(response, "unique", "fieldFacets", "long_ld", "str", false);
+ ArrayList<Long> stringLongTest = (ArrayList<Long>)calculateFacetedStat(stringLongTestStart, "unique");
+ assertEquals(responseStr,stringLong,stringLongTest);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void countTest() throws Exception {
+ String[] params = new String[] {
+ "o.countn.s.int", "count(int_id)",
+ "o.countn.s.long", "count(long_ld)",
+ "o.countn.s.float", "count(float_fd)",
+ "o.countn.s.double", "count(double_dd)",
+ "o.countn.ff", "string_sd",
+ "o.countn.ff", "date_dtd",
+
+ "o.count.s.str", "count(string_sd)",
+ "o.count.s.date", "count(date_dtd)",
+ "o.count.ff", "int_id",
+ "o.count.ff", "long_ld"
+ };
+ NamedList<Object> response = queryLegacyCloudAnalytics(params);
+ String responseStr = response.toString();
+
+ //Int Date
+ Collection<Long> intDate = getValueList(response, "countn", "fieldFacets", "date_dtd", "int", false);
+ ArrayList<Long> intDateTest = (ArrayList<Long>)calculateFacetedStat(intDateTestStart, "count");
+ assertEquals(responseStr,intDate,intDateTest);
+
+ //Int String
+ Collection<Long> intString = getValueList(response, "countn", "fieldFacets", "string_sd", "int", false);
+ ArrayList<Long> intStringTest = (ArrayList<Long>)calculateFacetedStat(intStringTestStart, "count");
+ assertEquals(responseStr,intString,intStringTest);
+
+ //Long Date
+ Collection<Long> longDate = getValueList(response, "countn", "fieldFacets", "date_dtd", "long", false);
+ ArrayList<Long> longDateTest = (ArrayList<Long>)calculateFacetedStat(longDateTestStart, "count");
+ assertEquals(responseStr,longDate,longDateTest);
+
+ //Long String
+ Collection<Long> longString = getValueList(response, "countn", "fieldFacets", "string_sd", "long", false);
+ ArrayList<Long> longStringTest = (ArrayList<Long>)calculateFacetedStat(longStringTestStart, "count");
+ assertEquals(responseStr,longString,longStringTest);
+
+ //Float Date
+ Collection<Long> floatDate = getValueList(response, "countn", "fieldFacets", "date_dtd", "float", false);
+ ArrayList<Long> floatDateTest = (ArrayList<Long>)calculateFacetedStat(floatDateTestStart, "count");
+ assertEquals(responseStr,floatDate,floatDateTest);
+
+ //Float String
+ Collection<Long> floatString = getValueList(response, "countn", "fieldFacets", "string_sd", "float", false);
+ ArrayList<Long> floatStringTest = (ArrayList<Long>)calculateFacetedStat(floatStringTestStart, "count");
+ assertEquals(responseStr,floatString,floatStringTest);
+
+ //Double Date
+ Collection<Long> doubleDate = getValueList(response, "countn", "fieldFacets", "date_dtd", "double", false);
+ ArrayList<Long> doubleDateTest = (ArrayList<Long>)calculateFacetedStat(doubleDateTestStart, "count");
+ assertEquals(responseStr,doubleDate,doubleDateTest);
+
+ //Double String
+ Collection<Long> doubleString = getValueList(response, "countn", "fieldFacets", "string_sd", "double", false);
+ ArrayList<Long> doubleStringTest = (ArrayList<Long>)calculateFacetedStat(doubleStringTestStart, "count");
+ assertEquals(responseStr,doubleString,doubleStringTest);
+
+ //Date Int
+ Collection<Long> dateInt = getValueList(response, "count", "fieldFacets", "int_id", "date", false);
+ ArrayList<Long> dateIntTest = (ArrayList<Long>)calculateFacetedStat(dateIntTestStart, "count");
+ assertEquals(responseStr,dateIntTest,dateInt);
+
+ //Date Long
+ Collection<Long> dateLong = getValueList(response, "count", "fieldFacets", "long_ld", "date", false);
+ ArrayList<Long> dateLongTest = (ArrayList<Long>)calculateFacetedStat(dateLongTestStart, "count");
+ assertEquals(responseStr,dateLong,dateLongTest);
+
+ //String Int
+ Collection<Long> stringInt = getValueList(response, "count", "fieldFacets", "int_id", "str", false);
+ ArrayList<Long> stringIntTest = (ArrayList<Long>)calculateFacetedStat(stringIntTestStart, "count");
+ assertEquals(responseStr,stringInt,stringIntTest);
+
+ //String Long
+ Collection<Long> stringLong = getValueList(response, "count", "fieldFacets", "long_ld", "str", false);
+ ArrayList<Long> stringLongTest = (ArrayList<Long>)calculateFacetedStat(stringLongTestStart, "count");
+ assertEquals(responseStr,stringLong,stringLongTest);
+ }
+
+ @Test
+ public void missingTest() throws Exception {
+ String[] params = new String[] {
+ "o.missingn.s.int", "missing(int_id)",
+ "o.missingn.s.long", "missing(long_ld)",
+ "o.missingn.s.float", "missing(float_fd)",
+ "o.missingn.s.double", "missing(double_dd)",
+ "o.missingn.ff", "string_sd",
+ "o.missingn.ff", "date_dtd",
+
+ "o.missing.s.str", "missing(string_sd)",
+ "o.missing.s.date", "missing(date_dtd)",
+ "o.missing.ff", "int_id",
+ "o.missing.ff", "long_ld"
+ };
+ NamedList<Object> response = queryLegacyCloudAnalytics(params);
+ String responseStr = response.toString();
+
+ //Int Date
+ Collection<Long> intDate = getValueList(response, "missingn", "fieldFacets", "date_dtd", "int", false);
+ setLatestType("int");
+ assertEquals(responseStr,intDateTestMissing,intDate);
+
+ //Int String
+ Collection<Long> intString = getValueList(response, "missingn", "fieldFacets", "string_sd", "int", false);
+ assertEquals(responseStr,intStringTestMissing,intString);
+
+ //Long Date
+ Collection<Long> longDate = getValueList(response, "missingn", "fieldFacets", "date_dtd", "long", false);
+ setLatestType("long");
+ assertEquals(responseStr,longDateTestMissing,longDate);
+
+ //Long String
+ Collection<Long> longString = getValueList(response, "missingn", "fieldFacets", "string_sd", "long", false);
+ assertEquals(responseStr,longStringTestMissing,longString);
+
+ //Float Date
+ Collection<Long> floatDate = getValueList(response, "missingn", "fieldFacets", "date_dtd", "float", false);
+ setLatestType("float");
+ assertEquals(responseStr,floatDateTestMissing,floatDate);
+
+ //Float String
+ Collection<Long> floatString = getValueList(response, "missingn", "fieldFacets", "string_sd", "float", false);
+ assertEquals(responseStr,floatStringTestMissing,floatString);
+
+ //Double Date
+ Collection<Long> doubleDate = getValueList(response, "missingn", "fieldFacets", "date_dtd", "double", false);
+ setLatestType("double");
+ assertEquals(responseStr,doubleDateTestMissing,doubleDate);
+
+ //Double String
+ Collection<Long> doubleString = getValueList(response, "missingn", "fieldFacets", "string_sd", "double", false);
+ assertEquals(responseStr,doubleStringTestMissing,doubleString);
+
+ //Date Int
+ Collection<Long> dateInt = getValueList(response, "missing", "fieldFacets", "int_id", "date", false);
+ setLatestType("date");
+ assertEquals(responseStr,dateIntTestMissing,dateInt);
+
+ //Date Long
+ Collection<Long> dateLong = getValueList(response, "missing", "fieldFacets", "long_ld", "date", false);
+ assertEquals(responseStr,dateLongTestMissing,dateLong);
+
+ //String Int
+ Collection<Long> stringInt = getValueList(response, "missing", "fieldFacets", "int_id", "str", false);
+ setLatestType("string");
+ assertEquals(responseStr,stringIntTestMissing,stringInt);
+
+ //String Long
+ Collection<Long> stringLong = getValueList(response, "missing", "fieldFacets", "long_ld", "str", false);
+ assertEquals(responseStr,stringLongTestMissing,stringLong);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void multiValueTest() throws Exception {
+ String[] params = new String[] {
+ "o.multivalued.s.mean", "mean(int_id)",
+ "o.multivalued.ff", "long_ldm",
+ "o.multivalued.ff", "string_sdm",
+ "o.multivalued.ff", "date_dtdm"
+ };
+ NamedList<Object> response = queryLegacyCloudAnalytics(params);
+ String responseStr = response.toString();
+
+ //Long
+ Collection<Double> lon = getValueList(response, "multivalued", "fieldFacets", "long_ldm", "mean", false);
+ ArrayList<Double> longTest = calculateFacetedNumberStat(multiLongTestStart, "mean");
+ assertEquals(responseStr,lon,longTest);
+ //Date
+ Collection<Double> date = getValueList(response, "multivalued", "fieldFacets", "date_dtdm", "mean", false);
+ ArrayList<Double> dateTest = calculateFacetedNumberStat(multiDateTestStart, "mean");
+ assertEquals(responseStr,date,dateTest);
+ //String
+ Collection<Double> string = getValueList(response, "multivalued", "fieldFacets", "string_sdm", "mean", false);
+ ArrayList<Double> stringTest = calculateFacetedNumberStat(multiStringTestStart, "mean");
+ assertEquals(responseStr,string,stringTest);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void missingFacetTest() throws Exception {
+ String[] params = new String[] {
+ "o.missingf.s.mean", "mean(int_id)",
+ "o.missingf.ff", "date_dtd",
+ "o.missingf.ff", "string_sd",
+ "o.missingf.ff.string_sd.sm", "true",
+ "o.missingf.ff", "date_dtdm",
+ "o.missingf.ff.date_dtdm.sm", "true"
+ };
+ NamedList<Object> response = queryLegacyCloudAnalytics(params);
+ String responseStr = response.toString();
+
+ //int MultiDate
+ assertTrue(responseStr, responseContainsFacetValue(response, "missingf", "fieldFacets", "date_dtdm", "(MISSING)"));
+ ArrayList<Double> string = getValueList(response, "missingf", "fieldFacets", "date_dtdm", "mean", false);
+ ArrayList<Double> stringTest = calculateFacetedNumberStat(multiDateTestStart, "mean");
+ assertEquals(responseStr, string,stringTest);
+
+ //Int String
+ assertTrue(responseStr, responseContainsFacetValue(response, "missingf", "fieldFacets", "string_sd", "(MISSING)"));
+ assertTrue(responseStr, !responseContainsFacetValue(response, "missingf", "fieldFacets", "string_sd", "str0"));
+ List<Double> intString = getValueList(response, "missingf", "fieldFacets", "string_sd", "mean", false);
+ ArrayList<Double> intStringTest = calculateFacetedNumberStat(intStringTestStart, "mean");
+ assertEquals(responseStr, intString,intStringTest);
+
+ //Int Date
+ Collection<Double> intDate = getValueList(response, "missingf", "fieldFacets", "date_dtd", "mean", false);
+ ArrayList<ArrayList<Double>> intDateMissingTestStart = (ArrayList<ArrayList<Double>>) intDateTestStart.clone();
+ ArrayList<Double> intDateTest = calculateFacetedNumberStat(intDateMissingTestStart, "mean");
+ assertEquals(responseStr,intDate,intDateTest);
+ }
+
+ private void checkStddevs(NamedList<Object> response, ArrayList<Double> list1, ArrayList<Double> list2) {
+ Collections.sort(list1);
+ Collections.sort(list2);
+ for (int i = 0; i<list2.size(); i++) {
+ if ((Math.abs(list1.get(i)-list2.get(i))<.00000000001) == false) {
+ Assert.assertEquals(response.toString(), list1.get(i), list2.get(i), 0.00000000001);
+ }
+ }
+ }
+
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ public static void assertEquals(String mes, Object actual, Object expected) {
+ Collections.sort((List<Comparable>) actual);
+ Collections.sort((List<Comparable>) expected);
+ Assert.assertEquals(mes, actual, expected);
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyFieldFacetExtrasCloudTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyFieldFacetExtrasCloudTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyFieldFacetExtrasCloudTest.java
new file mode 100644
index 0000000..808269a
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyFieldFacetExtrasCloudTest.java
@@ -0,0 +1,253 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.legacy.facet;
+
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.solr.client.solrj.request.UpdateRequest;
+import org.apache.solr.common.util.NamedList;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class LegacyFieldFacetExtrasCloudTest extends LegacyAbstractAnalyticsFacetCloudTest {
+ public static final int INT = 21;
+ public static final int LONG = 22;
+ public static final int FLOAT = 23;
+ public static final int DOUBLE = 24;
+ public static final int DATE = 25;
+ public static final int STRING = 26;
+ public static final int NUM_LOOPS = 100;
+
+ //INT
+ static ArrayList<ArrayList<Integer>> intLongTestStart;
+ static ArrayList<ArrayList<Integer>> intFloatTestStart;
+ static ArrayList<ArrayList<Integer>> intDoubleTestStart;
+ static ArrayList<ArrayList<Integer>> intStringTestStart;
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ cleanIndex();
+
+ //INT
+ intLongTestStart = new ArrayList<>();
+ intFloatTestStart = new ArrayList<>();
+ intDoubleTestStart = new ArrayList<>();
+ intStringTestStart = new ArrayList<>();
+
+ UpdateRequest req = new UpdateRequest();
+
+ for (int j = 0; j < NUM_LOOPS; ++j) {
+ int i = j%INT;
+ long l = j%LONG;
+ float f = j%FLOAT;
+ double d = j%DOUBLE;
+ int dt = j%DATE;
+ int s = j%STRING;
+
+ List<String> fields = new ArrayList<>();
+ fields.add("id"); fields.add("1000"+j);
+ fields.add("int_id"); fields.add("" + i);
+ fields.add("long_ld"); fields.add("" + l);
+ fields.add("float_fd"); fields.add("" + f);
+ fields.add("double_dd"); fields.add("" + d);
+ fields.add("date_dtd"); fields.add((1800+dt) + "-12-31T23:59:59.999Z");
+ fields.add("string_sd"); fields.add("abc" + s);
+ req.add(fields.toArray(new String[0]));
+
+ //Long
+ if (j-LONG<0) {
+ ArrayList<Integer> list1 = new ArrayList<>();
+ list1.add(i);
+ intLongTestStart.add(list1);
+ } else {
+ intLongTestStart.get((int)l).add(i);
+ }
+ //String
+ if (j-FLOAT<0) {
+ ArrayList<Integer> list1 = new ArrayList<>();
+ list1.add(i);
+ intFloatTestStart.add(list1);
+ } else {
+ intFloatTestStart.get((int)f).add(i);
+ }
+ //String
+ if (j-DOUBLE<0) {
+ ArrayList<Integer> list1 = new ArrayList<>();
+ list1.add(i);
+ intDoubleTestStart.add(list1);
+ } else {
+ intDoubleTestStart.get((int)d).add(i);
+ }
+ //String
+ if (j-STRING<0) {
+ ArrayList<Integer> list1 = new ArrayList<>();
+ list1.add(i);
+ intStringTestStart.add(list1);
+ } else {
+ intStringTestStart.get(s).add(i);
+ }
+ }
+
+ req.commit(cluster.getSolrClient(), COLLECTIONORALIAS);
+ }
+
+ @Test
+ public void limitTest() throws Exception {
+ String[] params = new String[] {
+ "o.lr.s.mean", "mean(int_id)",
+ "o.lr.s.median", "median(int_id)",
+ "o.lr.s.count", "count(int_id)",
+ "o.lr.s.percentile_20", "percentile(20,int_id)",
+ "o.lr.ff.long_ld", "long_ld",
+ "o.lr.ff.long_ld.ss", "mean",
+ "o.lr.ff.long_ld.sd", "asc",
+ "o.lr.ff.long_ld.limit", "5",
+ "o.lr.ff.float_fd", "float_fd",
+ "o.lr.ff.float_fd.ss", "median",
+ "o.lr.ff.float_fd.sd", "desc",
+ "o.lr.ff.float_fd.limit", "3",
+ "o.lr.ff.double_dd", "double_dd",
+ "o.lr.ff.double_dd.ss", "count",
+ "o.lr.ff.double_dd.sd", "asc",
+ "o.lr.ff.double_dd.limit", "7",
+ "o.lr.ff.string_sd", "string_sd",
+ "o.lr.ff.string_sd.ss", "percentile_20",
+ "o.lr.ff.string_sd.sd", "desc",
+ "o.lr.ff.string_sd.limit", "1"
+ };
+
+ NamedList<Object> response = queryLegacyCloudAnalytics(params);
+ String responseStr = response.toString();
+
+ Collection<Double> lon = getValueList(response, "lr", "fieldFacets", "long_ld", "mean", false);
+ assertEquals(responseStr, lon.size(),5);
+ Collection<Double> flo = getValueList(response, "lr", "fieldFacets", "float_fd", "median", false);
+ assertEquals(responseStr, flo.size(),3);
+ Collection<Long> doub = getValueList(response, "lr", "fieldFacets", "double_dd", "count", false);
+ assertEquals(responseStr, doub.size(),7);
+ Collection<Integer> string = getValueList(response, "lr", "fieldFacets", "string_sd", "percentile_20", false);
+ assertEquals(responseStr, string.size(),1);
+ }
+
+ @Test
+ public void offsetTest() throws Exception {
+ String[] params = new String[] {
+ "o.offAll.s.mean", "mean(int_id)",
+ "o.offAll.ff", "long_ld",
+ "o.offAll.ff.long_ld.ss", "mean",
+ "o.offAll.ff.long_ld.sd", "asc",
+ "o.offAll.ff.long_ld.limit", "7",
+
+ "o.off0.s.mean", "mean(int_id)",
+ "o.off0.ff", "long_ld",
+ "o.off0.ff.long_ld.ss", "mean",
+ "o.off0.ff.long_ld.sd", "asc",
+ "o.off0.ff.long_ld.limit", "2",
+ "o.off0.ff.long_ld.offset", "0",
+
+ "o.off1.s.mean", "mean(int_id)",
+ "o.off1.ff", "long_ld",
+ "o.off1.ff.long_ld.ss", "mean",
+ "o.off1.ff.long_ld.sd", "asc",
+ "o.off1.ff.long_ld.limit", "2",
+ "o.off1.ff.long_ld.offset", "2",
+
+ "o.off2.s.mean", "mean(int_id)",
+ "o.off2.ff", "long_ld",
+ "o.off2.ff.long_ld.ss", "mean",
+ "o.off2.ff.long_ld.sd", "asc",
+ "o.off2.ff.long_ld.limit", "3",
+ "o.off2.ff.long_ld.offset", "4"
+ };
+
+ NamedList<Object> response = queryLegacyCloudAnalytics(params);
+ String responseStr = response.toString();
+
+ Collection<Double> lon;
+
+ List<Double> all = new ArrayList<>();
+ lon = getValueList(response, "off0", "fieldFacets", "long_ld", "mean", false);
+ assertEquals(responseStr, lon.size(),2);
+ assertArrayEquals(new Double[]{ 1.5, 2.0 }, lon.toArray(new Double[0]));
+ all.addAll(lon);
+
+ lon = getValueList(response, "off1", "fieldFacets", "long_ld", "mean", false);
+ assertEquals(responseStr, lon.size(),2);
+ assertArrayEquals(new Double[]{ 3.0, 4.0 }, lon.toArray(new Double[0]));
+ all.addAll(lon);
+
+ lon = getValueList(response, "off2", "fieldFacets", "long_ld", "mean", false);
+ assertEquals(responseStr, lon.size(),3);
+ assertArrayEquals(new Double[]{ 5.0, 5.75, 6.0 }, lon.toArray(new Double[0]));
+ all.addAll(lon);
+
+ lon = getValueList(response, "offAll", "fieldFacets", "long_ld", "mean", false);
+ assertEquals(responseStr, lon.size(),7);
+ assertArrayEquals(all.toArray(new Double[0]), lon.toArray(new Double[0]));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void sortTest() throws Exception {
+ String[] params = new String[] {
+ "o.sr.s.mean", "mean(int_id)",
+ "o.sr.s.median", "median(int_id)",
+ "o.sr.s.count", "count(int_id)",
+ "o.sr.s.percentile_20", "percentile(20,int_id)",
+ "o.sr.ff", "long_ld",
+ "o.sr.ff.long_ld.ss", "mean",
+ "o.sr.ff.long_ld.sd", "asc",
+ "o.sr.ff", "float_fd",
+ "o.sr.ff.float_fd.ss", "median",
+ "o.sr.ff.float_fd.sd", "desc",
+ "o.sr.ff", "double_dd",
+ "o.sr.ff.double_dd.ss", "count",
+ "o.sr.ff.double_dd.sd", "asc",
+ "o.sr.ff", "string_sd",
+ "o.sr.ff.string_sd.ss", "percentile_20",
+ "o.sr.ff.string_sd.sd", "desc"
+ };
+
+ NamedList<Object> response = queryLegacyCloudAnalytics(params);
+ String responseStr = response.toString();
+
+ Collection<Double> lon = getValueList(response, "sr", "fieldFacets", "long_ld", "mean", false);
+ ArrayList<Double> longTest = calculateFacetedNumberStat(intLongTestStart, "mean");
+ Collections.sort(longTest);
+ assertEquals(responseStr, longTest,lon);
+
+ Collection<Double> flo = getValueList(response, "sr", "fieldFacets", "float_fd", "median", false);
+ ArrayList<Double> floatTest = calculateFacetedNumberStat(intFloatTestStart, "median");
+ Collections.sort(floatTest,Collections.reverseOrder());
+ assertEquals(responseStr, floatTest,flo);
+
+ Collection<Long> doub = getValueList(response, "sr", "fieldFacets", "double_dd", "count", false);
+ ArrayList<Long> doubleTest = (ArrayList<Long>)calculateFacetedStat(intDoubleTestStart, "count");
+ Collections.sort(doubleTest);
+ assertEquals(responseStr, doubleTest,doub);
+
+ Collection<Integer> string = getValueList(response, "sr", "fieldFacets", "string_sd", "percentile_20", false);
+ ArrayList<Integer> stringTest = (ArrayList<Integer>)calculateFacetedStat(intStringTestStart, "perc_20");
+ Collections.sort(stringTest,Collections.reverseOrder());
+ assertEquals(responseStr, stringTest,string);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyFieldFacetExtrasTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyFieldFacetExtrasTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyFieldFacetExtrasTest.java
new file mode 100644
index 0000000..ac3046c
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyFieldFacetExtrasTest.java
@@ -0,0 +1,170 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.legacy.facet;
+
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class LegacyFieldFacetExtrasTest extends LegacyAbstractAnalyticsFacetTest {
+ static String fileName = "fieldFacetExtras.txt";
+
+ public static final int INT = 21;
+ public static final int LONG = 22;
+ public static final int FLOAT = 23;
+ public static final int DOUBLE = 24;
+ public static final int DATE = 25;
+ public static final int STRING = 26;
+ public static final int NUM_LOOPS = 100;
+
+ //INT
+ static ArrayList<ArrayList<Integer>> intLongTestStart;
+ static ArrayList<ArrayList<Integer>> intFloatTestStart;
+ static ArrayList<ArrayList<Integer>> intDoubleTestStart;
+ static ArrayList<ArrayList<Integer>> intStringTestStart;
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ initCore("solrconfig-analytics.xml","schema-analytics.xml");
+ h.update("<delete><query>*:*</query></delete>");
+
+ //INT
+ intLongTestStart = new ArrayList<>();
+ intFloatTestStart = new ArrayList<>();
+ intDoubleTestStart = new ArrayList<>();
+ intStringTestStart = new ArrayList<>();
+
+ for (int j = 0; j < NUM_LOOPS; ++j) {
+ int i = j%INT;
+ long l = j%LONG;
+ float f = j%FLOAT;
+ double d = j%DOUBLE;
+ int dt = j%DATE;
+ int s = j%STRING;
+ assertU(adoc("id", "1000" + j, "int_id", "" + i, "long_ld", "" + l, "float_fd", "" + f,
+ "double_dd", "" + d, "date_dtd", (1800+dt) + "-12-31T23:59:59.999Z", "string_sd", "abc" + s));
+ //Long
+ if (j-LONG<0) {
+ ArrayList<Integer> list1 = new ArrayList<>();
+ list1.add(i);
+ intLongTestStart.add(list1);
+ } else {
+ intLongTestStart.get((int)l).add(i);
+ }
+ //String
+ if (j-FLOAT<0) {
+ ArrayList<Integer> list1 = new ArrayList<>();
+ list1.add(i);
+ intFloatTestStart.add(list1);
+ } else {
+ intFloatTestStart.get((int)f).add(i);
+ }
+ //String
+ if (j-DOUBLE<0) {
+ ArrayList<Integer> list1 = new ArrayList<>();
+ list1.add(i);
+ intDoubleTestStart.add(list1);
+ } else {
+ intDoubleTestStart.get((int)d).add(i);
+ }
+ //String
+ if (j-STRING<0) {
+ ArrayList<Integer> list1 = new ArrayList<>();
+ list1.add(i);
+ intStringTestStart.add(list1);
+ } else {
+ intStringTestStart.get(s).add(i);
+ }
+
+ if (usually()) {
+ assertU(commit()); // to have several segments
+ }
+ }
+
+ assertU(commit());
+ setResponse(h.query(request(fileToStringArr(LegacyFieldFacetExtrasTest.class, fileName))));
+ }
+
+ @Test
+ public void limitTest() throws Exception {
+
+ Collection<Double> lon = getDoubleList("lr", "fieldFacets", "long_ld", "double", "mean");
+ assertEquals(getRawResponse(), lon.size(),5);
+ Collection<Double> flo = getDoubleList("lr", "fieldFacets", "float_fd", "double", "median");
+ assertEquals(getRawResponse(), flo.size(),3);
+ Collection<Long> doub = getLongList("lr", "fieldFacets", "double_dd", "long", "count");
+ assertEquals(getRawResponse(), doub.size(),7);
+ Collection<Integer> string = getIntegerList("lr", "fieldFacets", "string_sd", "int", "percentile_20");
+ assertEquals(getRawResponse(), string.size(),1);
+ }
+
+ @Test
+ public void offsetTest() throws Exception {
+
+ Collection<Double> lon;
+
+ List<Double> all = new ArrayList<>();
+ lon = getDoubleList("off0", "fieldFacets", "long_ld", "double", "mean");
+ assertEquals(getRawResponse(), lon.size(),2);
+ assertArrayEquals(new Double[]{ 1.5, 2.0 }, lon.toArray(new Double[0]));
+ all.addAll(lon);
+
+ lon = getDoubleList("off1", "fieldFacets", "long_ld", "double", "mean");
+ assertEquals(getRawResponse(), lon.size(),2);
+ assertArrayEquals(new Double[]{ 3.0, 4.0 }, lon.toArray(new Double[0]));
+ all.addAll(lon);
+
+ lon = getDoubleList("off2", "fieldFacets", "long_ld", "double", "mean");
+ assertEquals(getRawResponse(), lon.size(),3);
+ assertArrayEquals(new Double[]{ 5.0, 5.75, 6.0 }, lon.toArray(new Double[0]));
+ all.addAll(lon);
+
+ lon = getDoubleList("offAll", "fieldFacets", "long_ld", "double", "mean");
+ assertEquals(getRawResponse(), lon.size(),7);
+ assertArrayEquals(all.toArray(new Double[0]), lon.toArray(new Double[0]));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void sortTest() throws Exception {
+ Collection<Double> lon = getDoubleList("sr", "fieldFacets", "long_ld", "double", "mean");
+ ArrayList<Double> longTest = calculateNumberStat(intLongTestStart, "mean");
+ Collections.sort(longTest);
+ assertEquals(getRawResponse(), longTest,lon);
+
+ Collection<Double> flo = getDoubleList("sr", "fieldFacets", "float_fd", "double", "median");
+ ArrayList<Double> floatTest = calculateNumberStat(intFloatTestStart, "median");
+ Collections.sort(floatTest,Collections.reverseOrder());
+ assertEquals(getRawResponse(), floatTest,flo);
+
+ Collection<Long> doub = getLongList("sr", "fieldFacets", "double_dd", "long", "count");
+ ArrayList<Long> doubleTest = (ArrayList<Long>)calculateStat(intDoubleTestStart, "count");
+ Collections.sort(doubleTest);
+ assertEquals(getRawResponse(), doubleTest,doub);
+
+ Collection<Integer> string = getIntegerList("sr", "fieldFacets", "string_sd", "int", "percentile_20");
+ ArrayList<Integer> stringTest = (ArrayList<Integer>)calculateStat(intStringTestStart, "perc_20");
+ Collections.sort(stringTest,Collections.reverseOrder());
+ assertEquals(getRawResponse(), stringTest,string);
+ }
+
+}
[15/20] lucene-solr:master: SOLR-11145,
SOLR-11146: Added comprehensive unit tests for Analytics Component
2.0 as well as analytics bug fixes.
Posted by dp...@apache.org.
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/SolrAnalyticsTestCase.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/SolrAnalyticsTestCase.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/SolrAnalyticsTestCase.java
new file mode 100644
index 0000000..993c1d3
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/SolrAnalyticsTestCase.java
@@ -0,0 +1,349 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics;
+
+import java.io.IOException;
+import java.time.Instant;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import org.apache.solr.JSONTestUtil;
+import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.request.CollectionAdminRequest;
+import org.apache.solr.client.solrj.request.QueryRequest;
+import org.apache.solr.client.solrj.request.UpdateRequest;
+import org.apache.solr.client.solrj.response.QueryResponse;
+import org.apache.solr.cloud.AbstractDistribZkTestBase;
+import org.apache.solr.cloud.SolrCloudTestCase;
+import org.apache.solr.common.params.ModifiableSolrParams;
+import org.apache.solr.common.params.SolrParams;
+import org.apache.solr.common.util.Utils;
+import org.junit.BeforeClass;
+
+public class SolrAnalyticsTestCase extends SolrCloudTestCase {
+ private static final double DEFAULT_DELTA = .0000001;
+
+ protected static final String COLLECTIONORALIAS = "collection1";
+ protected static final int TIMEOUT = DEFAULT_TIMEOUT;
+ protected static final String id = "id";
+
+ private static UpdateRequest cloudReq;
+
+ @BeforeClass
+ public static void setupCollection() throws Exception {
+ // Single-sharded core
+ initCore("solrconfig-analytics.xml", "schema-analytics.xml");
+ h.update("<delete><query>*:*</query></delete>");
+
+ // Solr Cloud
+ configureCluster(4)
+ .addConfig("conf", configset("cloud-analytics"))
+ .configure();
+
+ CollectionAdminRequest.createCollection(COLLECTIONORALIAS, "conf", 2, 1).process(cluster.getSolrClient());
+ AbstractDistribZkTestBase.waitForRecoveriesToFinish(COLLECTIONORALIAS, cluster.getSolrClient().getZkStateReader(),
+ false, true, TIMEOUT);
+
+ new UpdateRequest()
+ .deleteByQuery("*:*")
+ .commit(cluster.getSolrClient(), COLLECTIONORALIAS);
+
+ cloudReq = new UpdateRequest();
+ }
+
+ protected static void cleanIndex() throws Exception {
+ h.update("<delete><query>*:*</query></delete>");
+
+ new UpdateRequest()
+ .deleteByQuery("*:*")
+ .commit(cluster.getSolrClient(), COLLECTIONORALIAS);
+ }
+
+ protected static void addDoc(List<String> fieldsAndValues) {
+ assertU(adoc(fieldsAndValues.toArray(new String[0])));
+ cloudReq.add(fieldsAndValues.toArray(new String[0]));
+ }
+
+ protected static void commitDocs() {
+ assertU(commit());
+ try {
+ cloudReq.commit(cluster.getSolrClient(), COLLECTIONORALIAS);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ cloudReq = new UpdateRequest();
+ }
+
+ private void testResults(SolrParams params, String analyticsRequest, String... tests) {
+ String coreJson = queryCoreJson(params);
+ Object cloudObj = queryCloudObject(params);
+
+ for (String test : tests) {
+ if (test == null || test.length()==0) continue;
+ // Single-Sharded
+ String err = null;
+ try {
+ err = JSONTestUtil.match(coreJson, test, DEFAULT_DELTA);
+ } catch (Exception e) {
+ err = e.getMessage();
+ } finally {
+ assertNull("query failed JSON validation. test= Single-Sharded Collection" +
+ "\n error=" + err +
+ "\n expected =" + test +
+ "\n response = " + coreJson +
+ "\n analyticsRequest = " + analyticsRequest, err);
+ }
+
+ // Cloud
+ err = null;
+ try {
+ err = JSONTestUtil.matchObj(cloudObj, test, DEFAULT_DELTA);
+ } catch (Exception e) {
+ err = e.getMessage();
+ } finally {
+ assertNull("query failed JSON validation. test= Solr Cloud Collection" +
+ "\n error=" + err +
+ "\n expected =" + test +
+ "\n response = " + Utils.toJSONString(cloudObj) +
+ "\n analyticsRequest = " + analyticsRequest, err);
+ }
+ }
+ }
+
+ private String queryCoreJson(SolrParams params) {
+ try {
+ return JQ(req(params));
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private Object queryCloudObject(SolrParams params) {
+ QueryResponse resp;
+ try {
+ cluster.waitForAllNodes(10000);
+ QueryRequest qreq = new QueryRequest(params);
+ resp = qreq.process(cluster.getSolrClient(), COLLECTIONORALIAS);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ return convertDatesToStrings(resp.getResponse().asShallowMap());
+ }
+
+ protected void testAnalytics(String analyticsRequest, String... tests) throws IOException, InterruptedException, SolrServerException {
+ ModifiableSolrParams params = new ModifiableSolrParams();
+ params.set("q", "*:*");
+ params.set("indent", "true");
+ params.set("rows", "0");
+ params.set("wt", "json");
+
+ params.set("analytics", analyticsRequest);
+
+ String[] revisedTests = Arrays.stream(tests).map( test -> "analytics_response/" + test).toArray( size -> new String[size]);
+ testResults(params, analyticsRequest, revisedTests);
+ }
+
+ protected void testExpressions(Map<String, ETP> expressions) throws Exception {
+ StringBuilder analyticsRequest = new StringBuilder("{ \"expressions\": {");
+ String expressionsStr = expressions.entrySet()
+ .stream()
+ .map( entry -> '"' + entry.getKey() + "\":\"" + entry.getValue().expression + '"')
+ .reduce((a,b) -> a + ',' + b)
+ .orElseGet(() -> "");
+ analyticsRequest.append(expressionsStr);
+ analyticsRequest.append("}}");
+
+ String results = expressions.entrySet()
+ .stream()
+ .map( entry -> '"' + entry.getKey() + "\":" + entry.getValue().expectedResultStr())
+ .reduce((a,b) -> a + ',' + b)
+ .orElseGet(() -> "");
+
+ testAnalytics(analyticsRequest.toString(), "results=={"+results+", \"_UNORDERED_\":true}");
+ }
+
+ protected void testGrouping(String grouping,
+ Map<String, String> expressions,
+ Map<String, String> facets,
+ Map<String, List<FVP>> results,
+ boolean sortAscending) throws Exception {
+ testGroupingSorted(grouping,
+ expressions,
+ facets,
+ results,
+ ", 'sort': { 'criteria' : [{'type': 'facetvalue', 'direction': '" + (sortAscending ? "ascending" : "descending") + "'}]}",
+ (fvp1, fvp2) -> fvp1.facetValue.compareTo(fvp2.facetValue),
+ sortAscending);
+ }
+
+ @SuppressWarnings("unchecked")
+ protected void testGrouping(String grouping,
+ Map<String, String> expressions,
+ Map<String, String> facets,
+ Map<String, List<FVP>> results,
+ String sortExpression,
+ boolean sortAscending) throws Exception {
+ testGroupingSorted(grouping,
+ expressions,
+ facets,
+ results,
+ ", 'sort': { 'criteria' : [{'type': 'expression', 'expression': '" + sortExpression + "', 'direction': '" + (sortAscending ? "ascending" : "descending") + "'}]}",
+ (fvp1, fvp2) -> fvp1.expectedResults.get(sortExpression).compareTo(fvp2.expectedResults.get(sortExpression)),
+ sortAscending);
+ }
+
+ protected void testGrouping(String grouping,
+ Map<String, String> expressions,
+ Map<String, String> facets,
+ Map<String, List<FVP>> results) throws Exception {
+ testGroupingSorted(grouping,
+ expressions,
+ facets,
+ results,
+ "",
+ (fvp1, fvp2) -> fvp1.compareTo(fvp2),
+ true);
+ }
+
+ private void testGroupingSorted(String grouping,
+ Map<String, String> expressions,
+ Map<String, String> facets,
+ Map<String, List<FVP>> results,
+ String sort,
+ Comparator<FVP> comparator,
+ boolean sortAscending) throws Exception {
+ StringBuilder analyticsRequest = new StringBuilder("{ \"groupings\": { \"" + grouping + "\" : { \"expressions\" : {");
+ String expressionsStr = expressions.entrySet()
+ .stream()
+ .map( entry -> '"' + entry.getKey() + "\":\"" + entry.getValue() + '"')
+ .collect(Collectors.joining(" , "));
+ analyticsRequest.append(expressionsStr);
+ analyticsRequest.append("}, \"facets\": {");
+ String facetsStr = facets.entrySet()
+ .stream()
+ .map( entry -> '"' + entry.getKey() + "\":" + entry.getValue().replaceFirst("}\\s*$", sort) + "}")
+ .collect(Collectors.joining(" , "));
+ analyticsRequest.append(facetsStr);
+ analyticsRequest.append("}}}}");
+
+ String groupingResults = results.entrySet()
+ .stream()
+ .map( facet -> {
+ String resultList = facet.getValue()
+ .stream()
+ .sorted(sortAscending ? comparator : comparator.reversed())
+ .map( fvp -> fvp.toJsonResults() )
+ .collect(Collectors.joining(" , "));
+ return '"' + facet.getKey() + "\" : [ " + resultList + " ]";
+ })
+ .collect(Collectors.joining(" , "));
+
+ testAnalytics(analyticsRequest.toString(), "groupings/" + grouping + "=={"+groupingResults+", \"_UNORDERED_\":true}");
+ }
+
+ private static String resultToJson(Object result) {
+ if (result instanceof String) {
+ return '"' + result.toString() + '"';
+ }
+ return result.toString();
+ }
+
+ /*
+ * Expression Test Pair, contains the expression and the expected result
+ */
+ protected static class ETP {
+ final String expression;
+ final Object expectedResult;
+
+ public ETP(String expression, Object expectedResult) {
+ this.expression = expression;
+ this.expectedResult = expectedResult;
+ }
+
+ public String expectedResultStr() {
+ if (expectedResult instanceof String) {
+ return '"' + expectedResult.toString() + '"';
+ }
+ return expectedResult.toString();
+ }
+ }
+
+ /*
+ * FacetValuePair, contains the expression and the expected result
+ */
+ @SuppressWarnings("rawtypes")
+ protected static class FVP implements Comparable<FVP> {
+ final private int order;
+ final public String facetValue;
+ final public Map<String, Comparable> expectedResults;
+
+ public FVP(int order, String facetValue, Map<String, Comparable> expectedResults) {
+ this.order = order;
+ this.facetValue = facetValue;
+ this.expectedResults = expectedResults;
+ }
+
+ public String toJsonResults() {
+ String valueResults = expectedResults.entrySet()
+ .stream()
+ .map( result -> '"' + result.getKey() + "\":" + resultToJson(result.getValue()))
+ .collect(Collectors.joining(" , "));
+ return "{ \"value\" : \"" + facetValue + "\", \"results\": { " + valueResults + ", \"_UNORDERED_\":true } }";
+ }
+
+ @Override
+ public int compareTo(FVP other) {
+ return Integer.compare(order, other.order);
+ }
+ }
+
+ /*
+ * FacetValuePair, contains the expression and the expected result
+ */
+ @SuppressWarnings("rawtypes")
+ protected static class PivotFVP extends FVP {
+ final public String pivot;
+ final public List<FVP> children;
+
+ public PivotFVP(int order, String pivot, String facetValue, Map<String, Comparable> expectedResults) {
+ super(order, facetValue, expectedResults);
+ this.pivot = pivot;
+ children = new ArrayList<>();
+ }
+
+ public void addChild(FVP child) {
+ children.add(child);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ protected static Object convertDatesToStrings(Object value) {
+ if (value instanceof Date) {
+ return Instant.ofEpochMilli(((Date)value).getTime()).toString();
+ } else if (value instanceof Map) {
+ ((Map<String,Object>)value).replaceAll( (key, obj) -> convertDatesToStrings(obj));
+ } else if (value instanceof List) {
+ ((List<Object>)value).replaceAll( obj -> convertDatesToStrings(obj));
+ }
+ return value;
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/expression/ExpressionTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/expression/ExpressionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/expression/ExpressionTest.java
deleted file mode 100644
index eeecbe6..0000000
--- a/solr/contrib/analytics/src/test/org/apache/solr/analytics/expression/ExpressionTest.java
+++ /dev/null
@@ -1,201 +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.expression;
-
-import java.time.Instant;
-import java.util.Date;
-
-import org.apache.solr.analytics.AbstractAnalyticsStatsTest;
-import org.apache.solr.util.DateMathParser;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-public class ExpressionTest extends AbstractAnalyticsStatsTest {
- private static final String fileName = "expressions.txt";
-
- private static final int INT = 71;
- private static final int LONG = 36;
- private static final int FLOAT = 93;
- private static final int DOUBLE = 49;
- private static final int DATE = 12;
- private static final int STRING = 28;
- private static final int NUM_LOOPS = 100;
-
-
- @BeforeClass
- public static void beforeClass() throws Exception {
- initCore("solrconfig-analytics.xml", "schema-analytics.xml");
- h.update("<delete><query>*:*</query></delete>");
-
- for (int j = 0; j < NUM_LOOPS; ++j) {
- int i = j % INT;
- long l = j % LONG;
- float f = j % FLOAT;
- double d = j % DOUBLE;
- String dt = (1800 + j % DATE) + "-12-31T23:59:59Z";
- String s = "str" + (j % STRING);
- assertU(adoc("id", "1000" + j, "int_id", "" + i, "long_ld", "" + l, "float_fd", "" + f,
- "double_dd", "" + d, "date_dtd", dt, "string_sd", s));
-
- if (usually()) {
- assertU(commit()); // to have several segments
- }
- }
-
- assertU(commit());
-
- setResponse(h.query(request(fileToStringArr(ExpressionTest.class, fileName))));
- }
-
- @Test
- public void addTest() throws Exception {
- double sumResult = (Double) getStatResult("ar", "sum", VAL_TYPE.DOUBLE);
- double uniqueResult = ((Long) getStatResult("ar", "unique", VAL_TYPE.LONG)).doubleValue();
- double result = (Double) getStatResult("ar", "su", VAL_TYPE.DOUBLE);
- assertEquals(getRawResponse(), sumResult + uniqueResult, result, 0.0);
-
- double meanResult = (Double) getStatResult("ar", "mean", VAL_TYPE.DOUBLE);
- double medianResult = (Double) getStatResult("ar", "median", VAL_TYPE.DOUBLE);
- double countResult = ((Long) getStatResult("ar", "count", VAL_TYPE.LONG)).doubleValue();
- result = (Double) getStatResult("ar", "mcm", VAL_TYPE.DOUBLE);
- assertEquals(getRawResponse(), meanResult + countResult + medianResult, result, 0.0);
- }
-
- @Test
- public void multiplyTest() throws Exception {
- double sumResult = (Double) getStatResult("mr", "sum", VAL_TYPE.DOUBLE);
- double uniqueResult = ((Long) getStatResult("mr", "unique", VAL_TYPE.LONG)).doubleValue();
- double result = (Double) getStatResult("mr", "su", VAL_TYPE.DOUBLE);
- assertEquals(getRawResponse(), sumResult * uniqueResult, result, 0.0);
-
- double meanResult = (Double) getStatResult("mr", "mean", VAL_TYPE.DOUBLE);
- double medianResult = (Double) getStatResult("mr", "median", VAL_TYPE.DOUBLE);
- double countResult = ((Long) getStatResult("mr", "count", VAL_TYPE.LONG)).doubleValue();
- result = (Double) getStatResult("mr", "mcm", VAL_TYPE.DOUBLE);
- assertEquals(getRawResponse(), meanResult * countResult * medianResult, result, 0.0);
- }
-
- @Test
- public void divideTest() throws Exception {
- double sumResult = (Double) getStatResult("dr", "sum", VAL_TYPE.DOUBLE);
- double uniqueResult = ((Long) getStatResult("dr", "unique", VAL_TYPE.LONG)).doubleValue();
- double result = (Double) getStatResult("dr", "su", VAL_TYPE.DOUBLE);
- assertEquals(getRawResponse(), sumResult / uniqueResult, result, 0.0);
-
- double meanResult = (Double) getStatResult("dr", "mean", VAL_TYPE.DOUBLE);
- double countResult = ((Long) getStatResult("dr", "count", VAL_TYPE.LONG)).doubleValue();
- result = (Double) getStatResult("dr", "mc", VAL_TYPE.DOUBLE);
- assertEquals(getRawResponse(), meanResult / countResult, result, 0.0);
- }
-
- @Test
- public void powerTest() throws Exception {
- double sumResult = (Double) getStatResult("pr", "sum", VAL_TYPE.DOUBLE);
- double uniqueResult = ((Long) getStatResult("pr", "unique", VAL_TYPE.LONG)).doubleValue();
- double result = (Double) getStatResult("pr", "su", VAL_TYPE.DOUBLE);
- assertEquals(getRawResponse(), Math.pow(sumResult, uniqueResult), result, 0.0);
-
- double meanResult = (Double) getStatResult("pr", "mean", VAL_TYPE.DOUBLE);
- double countResult = ((Long) getStatResult("pr", "count", VAL_TYPE.LONG)).doubleValue();
- result = (Double) getStatResult("pr", "mc", VAL_TYPE.DOUBLE);
- assertEquals(getRawResponse(), Math.pow(meanResult, countResult), result, 0.0);
- }
-
- @Test
- public void negateTest() throws Exception {
- double sumResult = (Double) getStatResult("nr", "sum", VAL_TYPE.DOUBLE);
- double result = (Double) getStatResult("nr", "s", VAL_TYPE.DOUBLE);
- assertEquals(getRawResponse(), -1 * sumResult, result, 0.0);
-
- long countResult = ((Long) getStatResult("nr", "count", VAL_TYPE.LONG));
- long lresult = (Long) getStatResult("nr", "c", VAL_TYPE.LONG);
- assertEquals(getRawResponse(), -1 * countResult, lresult, 0.0);
- }
-
- @Test
- public void absoluteValueTest() throws Exception {
- double sumResult = (Double) getStatResult("avr", "sum", VAL_TYPE.DOUBLE);
- double result = (Double) getStatResult("avr", "s", VAL_TYPE.DOUBLE);
- assertEquals(getRawResponse(), sumResult, result, 0.0);
-
- long countResult = ((Long) getStatResult("avr", "count", VAL_TYPE.LONG));
- long lresult = (Long) getStatResult("avr", "c", VAL_TYPE.LONG);
- assertEquals(getRawResponse(), countResult, lresult, 0.0);
- }
-
- @Test
- public void constantNumberTest() throws Exception {
- int result = (Integer) getStatResult("cnr", "c8", VAL_TYPE.INTEGER);
- assertEquals(getRawResponse(), 8, result, 0.0);
-
- float dresult = (Float) getStatResult("cnr", "c10", VAL_TYPE.FLOAT);
- assertEquals(getRawResponse(), 10.0f, dresult, 0.0);
- }
-
- @Test
- public void dateMathTest() throws Exception {
- String math = (String) getStatResult("dmr", "cme", VAL_TYPE.STRING);
- DateMathParser dateMathParser = new DateMathParser();
- dateMathParser.setNow(new Date(Instant.parse((String) getStatResult("dmr", "median", VAL_TYPE.DATE)).toEpochMilli()));
- String dateMath = (String) getStatResult("dmr", "dmme", VAL_TYPE.DATE);
- assertEquals(getRawResponse(), new Date(Instant.parse(dateMath).toEpochMilli()), dateMathParser.parseMath(math));
-
- math = (String) getStatResult("dmr", "cma", VAL_TYPE.STRING);
- dateMathParser = new DateMathParser();
- dateMathParser.setNow(new Date(Instant.parse((String) getStatResult("dmr", "max", VAL_TYPE.DATE)).toEpochMilli()));
- dateMath = (String) getStatResult("dmr", "dmma", VAL_TYPE.DATE);
- assertEquals(getRawResponse(), new Date(Instant.parse(dateMath).toEpochMilli()), dateMathParser.parseMath(math));
- }
-
- @Test
- public void constantDateTest() throws Exception {
- String date = (String) getStatResult("cdr", "cd1", VAL_TYPE.DATE);
- String str = (String) getStatResult("cdr", "cs1", VAL_TYPE.STRING);
- assertEquals(getRawResponse(), date, str);
-
- date = (String) getStatResult("cdr", "cd2", VAL_TYPE.DATE);
- str = (String) getStatResult("cdr", "cs2", VAL_TYPE.STRING);
- assertEquals(getRawResponse(), date, str);
- }
-
- @Test
- public void constantStringTest() throws Exception {
- String str = (String) getStatResult("csr", "cs1", VAL_TYPE.STRING);
- assertEquals(getRawResponse(), str, "this is the first");
-
- str = (String) getStatResult("csr", "cs2", VAL_TYPE.STRING);
- assertEquals(getRawResponse(), str, "this is the second");
-
- str = (String) getStatResult("csr", "cs3", VAL_TYPE.STRING);
- assertEquals(getRawResponse(), str, "this is the third");
- }
-
- @Test
- public void concatenateTest() throws Exception {
- StringBuilder builder = new StringBuilder();
- builder.append((String) getStatResult("cr", "csmin", VAL_TYPE.STRING));
- builder.append((String) getStatResult("cr", "min", VAL_TYPE.STRING));
- String concat = (String) getStatResult("cr", "ccmin", VAL_TYPE.STRING);
- assertEquals(getRawResponse(), concat, builder.toString());
-
- builder.setLength(0);
- builder.append((String) getStatResult("cr", "csmax", VAL_TYPE.STRING));
- builder.append((String) getStatResult("cr", "max", VAL_TYPE.STRING));
- concat = (String) getStatResult("cr", "ccmax", VAL_TYPE.STRING);
- assertEquals(getRawResponse(), concat, builder.toString());
- }
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/expression/FunctionTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/expression/FunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/expression/FunctionTest.java
deleted file mode 100644
index dac7921..0000000
--- a/solr/contrib/analytics/src/test/org/apache/solr/analytics/expression/FunctionTest.java
+++ /dev/null
@@ -1,221 +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.expression;
-
-
-import org.apache.solr.analytics.AbstractAnalyticsStatsTest;
-import org.apache.solr.analytics.facet.AbstractAnalyticsFacetTest;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-public class FunctionTest extends AbstractAnalyticsStatsTest {
- static String fileName = "functions.txt";
-
- static public final int INT = 71;
- static public final int LONG = 36;
- static public final int FLOAT = 93;
- static public final int DOUBLE = 49;
- static public final int DATE = 12;
- static public final int STRING = 28;
- static public final int NUM_LOOPS = 100;
-
- @BeforeClass
- public static void beforeClass() throws Exception {
- initCore("solrconfig-analytics.xml","schema-analytics.xml");
- h.update("<delete><query>*:*</query></delete>");
-
- for (int j = 0; j < NUM_LOOPS; ++j) {
- int i = j%INT+1;
- long l = j%LONG+1;
- float f = j%FLOAT+1;
- double d = j%DOUBLE+1;
- double d0 = j%DOUBLE;
- String dt = (1800+j%DATE) + "-06-30T23:59:59Z";
- String s = "str" + (j%STRING);
-
- double add_if = (double)i+f;
- double add_ldf = (double)l+d+f;
- double mult_if = (double)i*f;
- double mult_ldf = (double)l*d*f;
- double div_if = (double)i/f;
- double div_ld = (double)l/d;
- double pow_if = Math.pow(i,f);
- double pow_ld = Math.pow(l,d);
- int neg_i = i*-1;
- long neg_l = l*-1;
- String dm_2y = (1802+j%DATE) + "-06-30T23:59:59Z";
- String dm_2m = (1800+j%DATE) + "-08-30T23:59:59Z";
- String concat_first = "this is the first"+s;
- String concat_second = "this is the second"+s;
-
- assertU(adoc(AbstractAnalyticsFacetTest.filter("id", "1000" + j, "int_id", "" + i, "long_ld", "" + l, "float_fd", "" + f,
- "double_dd", "" + d, "date_dtd", dt, "string_sd", s,
- "add_if_dd", ""+add_if, "add_ldf_dd", ""+add_ldf, "mult_if_dd", ""+mult_if, "mult_ldf_dd", ""+mult_ldf,
- "div_if_dd", ""+div_if, "div_ld_dd", ""+div_ld, "pow_if_dd", ""+pow_if, "pow_ld_dd", ""+pow_ld,
- "neg_id", ""+neg_i, "neg_ld", ""+neg_l, "const_8_dd", "8", "const_10_dd", "10", "dm_2y_dtd", dm_2y, "dm_2m_dtd", dm_2m,
- "const_00_dtd", "1800-06-30T23:59:59Z", "const_04_dtd", "1804-06-30T23:59:59Z", "const_first_sd", "this is the first", "const_second_sd", "this is the second",
- "concat_first_sd", concat_first, "concat_second_sd", concat_second, "miss_dd", ""+d0 )));
-
-
- if (usually()) {
- assertU(commit()); // to have several segments
- }
- }
-
- assertU(commit());
-
- setResponse(h.query(request(fileToStringArr(FunctionTest.class, fileName))));
- }
-
- @Test
- public void addTest() throws Exception {
- double result = (Double)getStatResult("ar", "sum", VAL_TYPE.DOUBLE);
- double calculated = (Double)getStatResult("ar", "sumc", VAL_TYPE.DOUBLE);
- assertEquals(getRawResponse(), result, calculated, 0.0);
- // TODO checfk why asserted 2times
- assertEquals(getRawResponse(), result, calculated, 0.0);
-
- result = (Double)getStatResult("ar", "mean", VAL_TYPE.DOUBLE);
- calculated = (Double)getStatResult("ar", "meanc", VAL_TYPE.DOUBLE);
- assertTrue(result==calculated);
- assertEquals(getRawResponse(), result, calculated, 0.0);
- }
-
- @Test
- public void multiplyTest() throws Exception {
- double result = (Double)getStatResult("mr", "sum", VAL_TYPE.DOUBLE);
- double calculated = (Double)getStatResult("mr", "sumc", VAL_TYPE.DOUBLE);
- assertEquals(getRawResponse(), result, calculated, 0.0);
-
- result = (Double)getStatResult("mr", "mean", VAL_TYPE.DOUBLE);
- calculated = (Double)getStatResult("mr", "meanc", VAL_TYPE.DOUBLE);
- assertEquals(getRawResponse(), result, calculated, 0.0);
- }
-
- @Test
- public void divideTest() throws Exception {
- Double result = (Double)getStatResult("dr", "sum", VAL_TYPE.DOUBLE);
- Double calculated = (Double)getStatResult("dr", "sumc", VAL_TYPE.DOUBLE);
- assertEquals(getRawResponse(), result, calculated, 0.0);
-
- result = (Double)getStatResult("dr", "mean", VAL_TYPE.DOUBLE);
- calculated = (Double)getStatResult("dr", "meanc", VAL_TYPE.DOUBLE);
- assertEquals(getRawResponse(), result, calculated, 0.0);
- }
-
- @Test
- public void powerTest() throws Exception {
- double result = (Double)getStatResult("pr", "sum", VAL_TYPE.DOUBLE);
- double calculated = (Double)getStatResult("pr", "sumc", VAL_TYPE.DOUBLE);
- assertEquals(getRawResponse(), result, calculated, 0.0);
- assertEquals(getRawResponse(), result, calculated, 0.0);
-
- result = (Double)getStatResult("pr", "mean", VAL_TYPE.DOUBLE);
- calculated = (Double)getStatResult("pr", "meanc", VAL_TYPE.DOUBLE);
- assertEquals(getRawResponse(), result, calculated, 0.0);
- assertEquals(getRawResponse(), result, calculated, 0.0);
- }
-
- @Test
- public void negateTest() throws Exception {
- double result = (Double)getStatResult("nr", "sum", VAL_TYPE.DOUBLE);
- double calculated = (Double)getStatResult("nr", "sumc", VAL_TYPE.DOUBLE);
- assertEquals(getRawResponse(), result, calculated, 0.0);
-
- result = (Double)getStatResult("nr", "mean", VAL_TYPE.DOUBLE);
- calculated = (Double)getStatResult("nr", "meanc", VAL_TYPE.DOUBLE);
- assertEquals(getRawResponse(), result, calculated, 0.0);
- }
-
- @Test
- public void absoluteValueTest() throws Exception {
- double result = (Double)getStatResult("avr", "sum", VAL_TYPE.DOUBLE);
- double calculated = (Double)getStatResult("avr", "sumc", VAL_TYPE.DOUBLE);
- assertEquals(getRawResponse(), result, calculated, 0.0);
-
- result = (Double)getStatResult("avr", "mean", VAL_TYPE.DOUBLE);
- calculated = (Double)getStatResult("avr", "meanc", VAL_TYPE.DOUBLE);
- assertEquals(getRawResponse(), result, calculated, 0.0);
- }
-
- @Test
- public void constantNumberTest() throws Exception {
- double result = (Double)getStatResult("cnr", "sum", VAL_TYPE.DOUBLE);
- double calculated = (Double)getStatResult("cnr", "sumc", VAL_TYPE.DOUBLE);
- assertEquals(getRawResponse(), result, calculated, 0.0);
- assertEquals(getRawResponse(), result, calculated, 0.0);
-
- result = (Double)getStatResult("cnr", "mean", VAL_TYPE.DOUBLE);
- calculated = (Double)getStatResult("cnr", "meanc", VAL_TYPE.DOUBLE);
- assertEquals(getRawResponse(), result, calculated, 0.0);
- assertEquals(getRawResponse(), result, calculated, 0.0);
- }
-
- @Test
- public void dateMathTest() throws Exception {
- String result = (String)getStatResult("dmr", "median", VAL_TYPE.DATE);
- String calculated = (String)getStatResult("dmr", "medianc", VAL_TYPE.DATE);
- assertEquals(getRawResponse(), result, calculated);
-
- result = (String)getStatResult("dmr", "max", VAL_TYPE.DATE);
- calculated = (String)getStatResult("dmr", "maxc", VAL_TYPE.DATE);
- assertEquals(getRawResponse(), result, calculated);
- }
-
- @Test
- public void constantDateTest() throws Exception {
- String result = (String)getStatResult("cdr", "median", VAL_TYPE.DATE);
- String calculated = (String)getStatResult("cdr", "medianc", VAL_TYPE.DATE);
- assertEquals(getRawResponse(), result, calculated);
- assertEquals(getRawResponse(), result, calculated);
-
- result = (String)getStatResult("cdr", "max", VAL_TYPE.DATE);
- calculated = (String)getStatResult("cdr", "maxc", VAL_TYPE.DATE);
- assertEquals(getRawResponse(), result, calculated);
- }
-
- @Test
- public void constantStringTest() throws Exception {
- String result = (String)getStatResult("csr", "min", VAL_TYPE.STRING);
- String calculated = (String)getStatResult("csr", "minc", VAL_TYPE.STRING);
- assertEquals(getRawResponse(), result, calculated);
-
- result = (String)getStatResult("csr", "max", VAL_TYPE.STRING);
- calculated = (String)getStatResult("csr", "maxc", VAL_TYPE.STRING);
- assertEquals(getRawResponse(), result, calculated);
- }
-
- @Test
- public void concatenateTest() throws Exception {
- String result = (String)getStatResult("cr", "min", VAL_TYPE.STRING);
- String calculated = (String)getStatResult("cr", "minc", VAL_TYPE.STRING);
- assertEquals(getRawResponse(), result, calculated);
-
- result = (String)getStatResult("cr", "max", VAL_TYPE.STRING);
- calculated = (String)getStatResult("cr", "maxc", VAL_TYPE.STRING);
- assertEquals(getRawResponse(), result, calculated);
- }
-
- @Test
- public void missingTest() throws Exception {
- double min = (Double)getStatResult("ms", "min", VAL_TYPE.DOUBLE);
- double max = (Double)getStatResult("ms", "max", VAL_TYPE.DOUBLE);
- assertEquals(getRawResponse(), 48.0d, max, 0.0);
- assertEquals(getRawResponse(), 1.0d, min, 0.0);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/AbstractAnalyticsFacetCloudTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/AbstractAnalyticsFacetCloudTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/AbstractAnalyticsFacetCloudTest.java
deleted file mode 100644
index 99e5103..0000000
--- a/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/AbstractAnalyticsFacetCloudTest.java
+++ /dev/null
@@ -1,284 +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.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Scanner;
-
-import org.apache.commons.lang.StringUtils;
-import org.apache.lucene.util.IOUtils;
-import org.apache.solr.analytics.util.AnalyticsResponseHeadings;
-import org.apache.solr.analytics.util.MedianCalculator;
-import org.apache.solr.analytics.util.OrdinalCalculator;
-import org.apache.solr.client.solrj.SolrServerException;
-import org.apache.solr.client.solrj.request.CollectionAdminRequest;
-import org.apache.solr.client.solrj.request.QueryRequest;
-import org.apache.solr.client.solrj.request.UpdateRequest;
-import org.apache.solr.client.solrj.response.QueryResponse;
-import org.apache.solr.cloud.AbstractDistribZkTestBase;
-import org.apache.solr.cloud.SolrCloudTestCase;
-import org.apache.solr.common.params.ModifiableSolrParams;
-import org.apache.solr.common.util.NamedList;
-import org.junit.AfterClass;
-
-public class AbstractAnalyticsFacetCloudTest extends SolrCloudTestCase {
- protected static final HashMap<String,Object> defaults = new HashMap<>();
-
- protected static final String COLLECTIONORALIAS = "collection1";
- protected static final int TIMEOUT = DEFAULT_TIMEOUT;
- protected static final String id = "id";
-
- public static void setupCluster() throws Exception {
- configureCluster(2)
- .addConfig("conf", configset("cloud-analytics"))
- .configure();
-
- CollectionAdminRequest.createCollection(COLLECTIONORALIAS, "conf", 2, 1).process(cluster.getSolrClient());
- AbstractDistribZkTestBase.waitForRecoveriesToFinish(COLLECTIONORALIAS, cluster.getSolrClient().getZkStateReader(),
- false, true, TIMEOUT);
-
- cleanIndex();
- }
-
- public static void cleanIndex() throws Exception {
- new UpdateRequest()
- .deleteByQuery("*:*")
- .commit(cluster.getSolrClient(), COLLECTIONORALIAS);
- }
-
- protected String latestType = "";
-
- @AfterClass
- public static void afterClassAbstractAnalysis() {
- defaults.clear();
- }
-
- protected NamedList<Object> queryCloudAnalytics(String[] testParams) throws SolrServerException, IOException, InterruptedException {
- ModifiableSolrParams params = new ModifiableSolrParams();
- params.set("q", "*:*");
- params.set("indent", "true");
- params.set("olap", "true");
- params.set("rows", "0");
- for (int i = 0; i + 1 < testParams.length;) {
- params.add(testParams[i++], testParams[i++]);
- }
- cluster.waitForAllNodes(10000);
- QueryRequest qreq = new QueryRequest(params);
- QueryResponse resp = qreq.process(cluster.getSolrClient(), COLLECTIONORALIAS);
- return resp.getResponse();
- }
-
- @SuppressWarnings("unchecked")
- protected <T> ArrayList<T> getValueList(NamedList<Object> response, String infoName, String facetType, String facetName, String exprName, boolean includeMissing) {
- NamedList<NamedList<Object>> facetList =
- (NamedList<NamedList<Object>>)response.findRecursive(AnalyticsResponseHeadings.COMPLETED_OLD_HEADER,
- infoName,
- facetType,
- facetName);
-
- ArrayList<T> results = new ArrayList<>();
- facetList.forEach( (name, expressions) -> {
- if (!includeMissing && !name.equals("(MISSING)")) {
- T result = (T)expressions.get(exprName);
- if (result != null)
- results.add(result);
- }
- });
- return results;
- }
-
- protected boolean responseContainsFacetValue(NamedList<Object> response, String infoName, String facetType, String facetName, String facetValue) {
- return null != response.findRecursive(AnalyticsResponseHeadings.COMPLETED_OLD_HEADER,
- infoName,
- facetType,
- facetName,
- facetValue);
- }
-
-
- public static void increment(List<Long> list, int idx){
- Long i = list.remove(idx);
- list.add(idx, i+1);
- }
-
- public static String[] filter(String...args){
- List<String> l = new ArrayList<>();
- for( int i=0; i <args.length; i+=2){
- if( args[i+1].equals("0") || args[i+1].equals("0.0") ||
- args[i+1].equals("1800-12-31T23:59:59Z") || args[i+1].equals("str0") ||
- args[i+1].equals("this is the firststr0") ||
- args[i+1].equals("this is the secondstr0") ){
- continue;
- }
- l.add(args[i]);
- l.add(args[i+1]);
- }
- return l.toArray(new String[0]);
- }
-
- protected void setLatestType(String latestType) {
- this.latestType = latestType;
- }
-
- @SuppressWarnings({ "unchecked", "rawtypes" })
- public <T extends Number & Comparable<T>> ArrayList calculateNumberStat(ArrayList<ArrayList<T>> lists, String stat) {
- ArrayList result;
- if (stat.equals("median")) {
- result = new ArrayList<Double>();
- for (List<T> list : lists) {
- result.add(MedianCalculator.getMedian(list));
- }
- } else if (stat.equals("mean")) {
- result = new ArrayList<Double>();
- for (List<T> list : lists) {
- double d = 0;
- for (T element : list) {
- d += element.doubleValue();
- }
- result.add(d/list.size());
- }
- } else if (stat.equals("sum")) {
- result = new ArrayList<Double>();
- for (Collection<T> list : lists) {
- double d = 0;
- for (T element : list) {
- d += element.doubleValue();
- }
- result.add(d);
- }
- } else if (stat.equals("sumOfSquares")) {
- result = new ArrayList<Double>();
- for (List<T> list : lists) {
- double d = 0;
- for (T element : list) {
- d += element.doubleValue()*element.doubleValue();
- }
- result.add(d);
- }
- } else if (stat.equals("stddev")) {
- result = new ArrayList<Double>();
- for (List<T> list : lists) {
- double sum = 0;
- double sumSquares = 0;
- for (T element : list) {
- sum += element.doubleValue();
- sumSquares += element.doubleValue()*element.doubleValue();
- }
- String res = Double.toString(Math.sqrt(sumSquares/list.size()-sum*sum/(list.size()*list.size())));
- result.add(Double.parseDouble(res));
- }
- } else {
- throw new IllegalArgumentException();
- }
- return result;
- }
-
- @SuppressWarnings({ "unchecked", "rawtypes" })
- public <T extends Comparable<T>> ArrayList calculateStat(ArrayList<ArrayList<T>> lists, String stat) {
- ArrayList result;
- if (stat.contains("perc_")) {
- result = new ArrayList<T>();
- for (List<T> list : lists) {
- if( list.size() == 0) continue;
- int ord = (int) Math.ceil(Double.parseDouble(stat.substring(5))/100 * list.size()) - 1;
- ArrayList<Integer> percs = new ArrayList<>(1);
- percs.add(ord);
- OrdinalCalculator.putOrdinalsInPosition(list, percs);
- result.add(list.get(ord));
- }
- } else if (stat.equals("count")) {
- result = new ArrayList<Long>();
- for (List<T> list : lists) {
- result.add((long)list.size());
- }
- } else if (stat.equals("missing")) {
- result = new ArrayList<Long>();
- for (ArrayList<T> list : lists) {
- result.add(calculateMissing(list,latestType));
- }
- } else if (stat.equals("unique")) {
- result = new ArrayList<Long>();
- for (List<T> list : lists) {
- HashSet<T> set = new HashSet<>();
- set.addAll(list);
- result.add((long)set.size());
- }
- } else if (stat.equals("max")) {
- result = new ArrayList<T>();
- for (List<T> list : lists) {
- if( list.size() == 0) continue;
- Collections.sort(list);
- result.add(list.get(list.size()-1));
- }
- } else if (stat.equals("min")) {
- result = new ArrayList<T>();
- for (List<T> list : lists) {
- if( list.size() == 0) continue;
- Collections.sort((List<T>)list);
- result.add(list.get(0));
- }
- } else {
- result = null;
- }
- return result;
- }
-
- @SuppressWarnings("unchecked")
- public <T extends Comparable<T>> Long calculateMissing(ArrayList<T> list, String type) {
- T def = (T)defaults.get(type);
- long miss = 0;
- for (T element : list) {
- if (element.compareTo(def)==0) {
- miss++;
- }
- }
- return Long.valueOf(miss);
- }
-
- public static ModifiableSolrParams fileToParams(Class<?> clazz, String fileName) throws FileNotFoundException {
- InputStream in = clazz.getResourceAsStream(fileName);
- if (in == null) throw new FileNotFoundException("Resource not found: " + fileName);
- Scanner file = new Scanner(in, "UTF-8");
- try {
- ModifiableSolrParams params = new ModifiableSolrParams();
- params.set("q", "*:*");
- params.set("indent", "true");
- params.set("olap", "true");
- params.set("rows", "0");
- while (file.hasNextLine()) {
- String line = file.nextLine();
- line = line.trim();
- if( StringUtils.isBlank(line) || line.startsWith("#")){
- continue;
- }
- String[] param = line.split("=");
- params.set(param[0], param[1]);
- }
- return params;
- } finally {
- IOUtils.closeWhileHandlingException(file, in);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/AbstractAnalyticsFacetTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/AbstractAnalyticsFacetTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/AbstractAnalyticsFacetTest.java
deleted file mode 100644
index ff0e7da..0000000
--- a/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/AbstractAnalyticsFacetTest.java
+++ /dev/null
@@ -1,343 +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.ByteArrayInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Scanner;
-
-import org.apache.lucene.util.IOUtils;
-import org.apache.solr.SolrTestCaseJ4;
-import org.apache.solr.analytics.util.AnalyticsResponseHeadings;
-import org.apache.solr.analytics.util.MedianCalculator;
-import org.apache.solr.analytics.util.OrdinalCalculator;
-import org.apache.solr.request.SolrQueryRequest;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-
-import com.google.common.collect.ObjectArrays;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.xpath.XPathConstants;
-import javax.xml.xpath.XPathExpressionException;
-import javax.xml.xpath.XPathFactory;
-
-@SolrTestCaseJ4.SuppressPointFields(bugUrl="https://issues.apache.org/jira/browse/SOLR-10949")
-public class AbstractAnalyticsFacetTest extends SolrTestCaseJ4 {
- protected static final HashMap<String,Object> defaults = new HashMap<>();
-
- protected String latestType = "";
-
- private static Document doc;
- private static XPathFactory xPathFact;
- private static String rawResponse;
-
- @BeforeClass
- public static void beforeClassAbstractAnalysis() {
- xPathFact = XPathFactory.newInstance();
- }
-
- @AfterClass
- public static void afterClassAbstractAnalysis() {
- xPathFact = null;
- doc = null;
- rawResponse = null;
- defaults.clear();
- }
-
- protected static void setResponse(String response) throws ParserConfigurationException, IOException, SAXException {
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- factory.setNamespaceAware(true); // never forget this!
- DocumentBuilder builder = factory.newDocumentBuilder();
- doc = builder.parse(new InputSource(new ByteArrayInputStream(response.getBytes(StandardCharsets.UTF_8))));
- rawResponse = response;
- }
-
- protected String getRawResponse() {
- return rawResponse;
- }
-
- protected Node getNode(String xPath) throws XPathExpressionException {
- return (Node)xPathFact.newXPath().compile(xPath).evaluate(doc, XPathConstants.NODE);
- }
- private NodeList getNodes(String n1, String n2, String n3, String element, String n4) throws XPathExpressionException {
- // Construct the XPath expression. The form better not change or all these will fail.
- StringBuilder sb = new StringBuilder("/response/lst[@name='"+AnalyticsResponseHeadings.COMPLETED_OLD_HEADER+"']/lst[@name='").append(n1).append("']");
- sb.append("/lst[@name='").append(n2).append("']");
- sb.append("/lst[@name='").append(n3).append("']");
- sb.append("/lst[@name!='(MISSING)']");
- sb.append("//").append(element).append("[@name='").append(n4).append("']");
- return (NodeList)xPathFact.newXPath().compile(sb.toString()).evaluate(doc, XPathConstants.NODESET);
-
- }
- protected ArrayList<String> getStringList(String n1, String n2, String n3, String element, String n4)
- throws XPathExpressionException {
- ArrayList<String> ret = new ArrayList<>();
- NodeList nodes = getNodes(n1, n2, n3, element, n4);
- for (int idx = 0; idx < nodes.getLength(); ++idx) {
- ret.add(nodes.item(idx).getTextContent());
- }
- return ret;
- }
-
- protected ArrayList<Integer> getIntegerList(String n1, String n2, String n3, String element, String n4)
- throws XPathExpressionException {
- ArrayList<Integer> ret = new ArrayList<>();
- NodeList nodes = getNodes(n1, n2, n3, element, n4);
- for (int idx = 0; idx < nodes.getLength(); ++idx) {
- ret.add(Integer.parseInt(nodes.item(idx).getTextContent()));
- }
- return ret;
- }
- protected ArrayList<Long> getLongList(String n1, String n2, String n3, String element, String n4)
- throws XPathExpressionException {
- ArrayList<Long> ret = new ArrayList<>();
- NodeList nodes = getNodes(n1, n2, n3, element, n4);
- for (int idx = 0; idx < nodes.getLength(); ++idx) {
- ret.add(Long.parseLong(nodes.item(idx).getTextContent()));
- }
- return ret;
- }
- protected ArrayList<Float> getFloatList(String n1, String n2, String n3, String element, String n4)
- throws XPathExpressionException {
- ArrayList<Float> ret = new ArrayList<>();
- NodeList nodes = getNodes(n1, n2, n3, element, n4);
- for (int idx = 0; idx < nodes.getLength(); ++idx) {
- ret.add(Float.parseFloat(nodes.item(idx).getTextContent()));
- }
- return ret;
- }
-
- protected ArrayList<Double> getDoubleList(String n1, String n2, String n3, String element, String n4)
- throws XPathExpressionException {
- ArrayList<Double> ret = new ArrayList<>();
- NodeList nodes = getNodes(n1, n2, n3, element, n4);
- for (int idx = 0; idx < nodes.getLength(); ++idx) {
- ret.add(Double.parseDouble(nodes.item(idx).getTextContent()));
- }
- return ret;
- }
-
-
- public static void increment(List<Long> list, int idx){
- Long i = list.remove(idx);
- list.add(idx, i+1);
- }
-
- public static String[] filter(String...args){
- List<String> l = new ArrayList<>();
- for( int i=0; i <args.length; i+=2){
- if( args[i+1].equals("0") || args[i+1].equals("0.0") ||
- args[i+1].equals("1800-12-31T23:59:59Z") || args[i+1].equals("str0") ||
- args[i+1].equals("this is the firststr0") ||
- args[i+1].equals("this is the secondstr0") ){
- continue;
- }
- l.add(args[i]);
- l.add(args[i+1]);
- }
- return l.toArray(new String[0]);
- }
-
- protected void setLatestType(String latestType) {
- this.latestType = latestType;
- }
-
- @SuppressWarnings({ "unchecked", "rawtypes" })
- public <T extends Number & Comparable<T>> ArrayList calculateNumberStat(ArrayList<ArrayList<T>> lists, String stat) {
- ArrayList result;
- if (stat.equals("median")) {
- result = new ArrayList<Double>();
- for (List<T> list : lists) {
- result.add(MedianCalculator.getMedian(list));
- }
- } else if (stat.equals("mean")) {
- result = new ArrayList<Double>();
- for (List<T> list : lists) {
- double d = 0;
- for (T element : list) {
- d += element.doubleValue();
- }
- result.add(d/list.size());
- }
- } else if (stat.equals("sum")) {
- result = new ArrayList<Double>();
- for (Collection<T> list : lists) {
- double d = 0;
- for (T element : list) {
- d += element.doubleValue();
- }
- result.add(d);
- }
- } else if (stat.equals("sumOfSquares")) {
- result = new ArrayList<Double>();
- for (List<T> list : lists) {
- double d = 0;
- for (T element : list) {
- d += element.doubleValue()*element.doubleValue();
- }
- result.add(d);
- }
- } else if (stat.equals("stddev")) {
- result = new ArrayList<Double>();
- for (List<T> list : lists) {
- double sum = 0;
- double sumSquares = 0;
- for (T element : list) {
- sum += element.doubleValue();
- sumSquares += element.doubleValue()*element.doubleValue();
- }
- String res = Double.toString(Math.sqrt(sumSquares/list.size()-sum*sum/(list.size()*list.size())));
- result.add(Double.parseDouble(res));
- }
- } else {
- throw new IllegalArgumentException();
- }
- return result;
- }
-
- @SuppressWarnings({ "unchecked", "rawtypes" })
- public <T extends Comparable<T>> ArrayList calculateStat(ArrayList<ArrayList<T>> lists, String stat) {
- ArrayList result;
- if (stat.contains("perc_")) {
- result = new ArrayList<T>();
- for (List<T> list : lists) {
- if( list.size() == 0) continue;
- int ord = (int) Math.ceil(Double.parseDouble(stat.substring(5))/100 * list.size()) - 1;
- ArrayList<Integer> percs = new ArrayList<>(1);
- percs.add(ord);
- OrdinalCalculator.putOrdinalsInPosition(list, percs);
- result.add(list.get(ord));
- }
- } else if (stat.equals("count")) {
- result = new ArrayList<Long>();
- for (List<T> list : lists) {
- //if( list.size() == 0) continue;
- result.add((long)list.size());
- }
- } else if (stat.equals("missing")) {
- result = new ArrayList<Long>();
- for (ArrayList<T> list : lists) {
- if( list.size() == 0) continue;
- result.add(calculateMissing(list,latestType));
- }
- } else if (stat.equals("unique")) {
- result = new ArrayList<Long>();
- for (List<T> list : lists) {
- HashSet<T> set = new HashSet<>();
- set.addAll(list);
- result.add((long)set.size());
- }
- } else if (stat.equals("max")) {
- result = new ArrayList<T>();
- for (List<T> list : lists) {
- if( list.size() == 0) continue;
- Collections.sort(list);
- result.add(list.get(list.size()-1));
- }
- } else if (stat.equals("min")) {
- result = new ArrayList<T>();
- for (List<T> list : lists) {
- if( list.size() == 0) continue;
- Collections.sort((List<T>)list);
- result.add(list.get(0));
- }
- } else {
- result = null;
- }
- return result;
- }
-
- @SuppressWarnings("unchecked")
- public <T extends Comparable<T>> Long calculateMissing(ArrayList<T> list, String type) {
- T def = (T)defaults.get(type);
- long miss = 0;
- for (T element : list) {
- if (element.compareTo(def)==0) {
- miss++;
- }
- }
- return Long.valueOf(miss);
- }
-
- public static SolrQueryRequest request(String...args){
- return SolrTestCaseJ4.req( ObjectArrays.concat(BASEPARMS, args,String.class) );
- }
-
- public static final String[] BASEPARMS = new String[]{ "q", "*:*", "indent", "true", "olap", "true", "rows", "0" };
-
-
- public static String[] fileToStringArr(Class<?> clazz, String fileName) throws FileNotFoundException {
- InputStream in = clazz.getResourceAsStream("/solr/analytics/" + fileName);
- if (in == null) throw new FileNotFoundException("Resource not found: " + fileName);
- Scanner file = new Scanner(in, "UTF-8");
- try {
- ArrayList<String> strList = new ArrayList<>();
- while (file.hasNextLine()) {
- String line = file.nextLine();
- if (line.length()<2) {
- continue;
- }
- int commentStart = line.indexOf("//");
- if (commentStart >= 0) {
- line = line.substring(0,commentStart);
- }
- String[] param = line.split("=");
- if (param.length != 2) {
- continue;
- }
- strList.add(param[0]);
- strList.add(param[1]);
- }
- return strList.toArray(new String[0]);
- } finally {
- IOUtils.closeWhileHandlingException(file, in);
- }
- }
-
- protected void removeNodes(String xPath, List<Double> string) throws XPathExpressionException {
- NodeList missingNodes = getNodes(xPath);
- List<Double> result = new ArrayList<Double>();
- for (int idx = 0; idx < missingNodes.getLength(); ++idx) {
- result.add(Double.parseDouble(missingNodes.item(idx).getTextContent()));
- }
- string.removeAll(result);
- }
-
- protected NodeList getNodes(String xPath) throws XPathExpressionException {
- StringBuilder sb = new StringBuilder(xPath);
- return (NodeList) xPathFact.newXPath().compile(sb.toString()).evaluate(doc, XPathConstants.NODESET);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/FacetSortingTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/FacetSortingTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/FacetSortingTest.java
deleted file mode 100644
index ef09014..0000000
--- a/solr/contrib/analytics/src/test/org/apache/solr/analytics/facet/FacetSortingTest.java
+++ /dev/null
@@ -1,53 +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.AbstractAnalyticsStatsTest;
-import org.apache.solr.analytics.expression.ExpressionTest;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-public class FacetSortingTest extends AbstractAnalyticsStatsTest {
- private static String fileName = "facetSorting.txt";
-
- @BeforeClass
- public static void beforeClass() throws Exception {
- initCore("solrconfig-analytics.xml", "schema-analytics.xml");
- h.update("<delete><query>*:*</query></delete>");
-
- // The data set below is so generated that in bucket corresponding fieldFacet B, double_dd column has null values
- // and in bucket C corresponding to fieldFacet C has null values for column long_ld.
- // FieldFaceting occurs on string_sd field
- assertU(adoc("id", "1001", "string_sd", "A", "double_dd", "" + 3, "long_ld", "" + 1));
- assertU(adoc("id", "1002", "string_sd", "A", "double_dd", "" + 25, "long_ld", "" + 2));
- assertU(adoc("id", "1003", "string_sd", "B", "long_ld", "" + 3));
- assertU(adoc("id", "1004", "string_sd", "B", "long_ld", "" + 4));
- assertU(adoc("id", "1005", "string_sd", "C", "double_dd", "" + 17));
-
- assertU(commit());
- String response = h.query(request(fileToStringArr(ExpressionTest.class, fileName)));
- setResponse(response);
- }
-
- @Test
- public void addTest() throws Exception {
- Double minResult = (Double) getStatResult("ar", "min", VAL_TYPE.DOUBLE);
- Long maxResult = (Long) getStatResult("ar", "max", VAL_TYPE.LONG);
- assertEquals(Double.valueOf(minResult), Double.valueOf(3.0));
- assertEquals(Long.valueOf(maxResult),Long.valueOf(4));
- }
-}
[16/20] lucene-solr:master: SOLR-11145,
SOLR-11146: Added comprehensive unit tests for Analytics Component
2.0 as well as analytics bug fixes.
Posted by dp...@apache.org.
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/AbstractAnalyticsStatsCloudTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/AbstractAnalyticsStatsCloudTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/AbstractAnalyticsStatsCloudTest.java
deleted file mode 100644
index 59ebbcb..0000000
--- a/solr/contrib/analytics/src/test/org/apache/solr/analytics/AbstractAnalyticsStatsCloudTest.java
+++ /dev/null
@@ -1,187 +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.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-
-import org.apache.solr.analytics.util.AnalyticsResponseHeadings;
-import org.apache.solr.analytics.util.MedianCalculator;
-import org.apache.solr.analytics.util.OrdinalCalculator;
-import org.apache.solr.client.solrj.SolrServerException;
-import org.apache.solr.client.solrj.request.CollectionAdminRequest;
-import org.apache.solr.client.solrj.request.QueryRequest;
-import org.apache.solr.client.solrj.request.UpdateRequest;
-import org.apache.solr.client.solrj.response.QueryResponse;
-import org.apache.solr.cloud.AbstractDistribZkTestBase;
-import org.apache.solr.cloud.SolrCloudTestCase;
-import org.apache.solr.common.params.ModifiableSolrParams;
-import org.apache.solr.common.util.NamedList;
-import org.junit.AfterClass;
-
-public class AbstractAnalyticsStatsCloudTest extends SolrCloudTestCase {
-
- protected static final String[] BASEPARMS = new String[]{ "q", "*:*", "indent", "true", "olap", "true", "rows", "0" };
- protected static final HashMap<String,Object> defaults = new HashMap<>();
-
- public static enum VAL_TYPE {
- INTEGER("int"),
- LONG("long"),
- FLOAT("float"),
- DOUBLE("double"),
- STRING("str"),
- DATE("date");
-
- private VAL_TYPE (final String text) {
- this.text = text;
- }
-
- private final String text;
-
- @Override
- public String toString() {
- return text;
- }
- }
-
-
-
- protected static final String COLLECTIONORALIAS = "collection1";
- protected static final int TIMEOUT = DEFAULT_TIMEOUT;
- protected static final String id = "id";
-
- public static void setupCluster() throws Exception {
- configureCluster(4)
- .addConfig("conf", configset("cloud-analytics"))
- .configure();
-
- CollectionAdminRequest.createCollection(COLLECTIONORALIAS, "conf", 2, 1).process(cluster.getSolrClient());
- AbstractDistribZkTestBase.waitForRecoveriesToFinish(COLLECTIONORALIAS, cluster.getSolrClient().getZkStateReader(),
- false, true, TIMEOUT);
- cleanIndex();
- }
-
- public static void cleanIndex() throws Exception {
- new UpdateRequest()
- .deleteByQuery("*:*")
- .commit(cluster.getSolrClient(), COLLECTIONORALIAS);
- }
-
- @AfterClass
- public static void afterClassAbstractAnalysis() {
- defaults.clear();
- }
-
- protected NamedList<Object> queryCloudAnalytics(String[] testParams) throws SolrServerException, IOException, InterruptedException {
- ModifiableSolrParams params = new ModifiableSolrParams();
- params.set("q", "*:*");
- params.set("indent", "true");
- params.set("olap", "true");
- params.set("rows", "0");
- for (int i = 0; i + 1 < testParams.length;) {
- params.set(testParams[i++], testParams[i++]);
- }
- cluster.waitForAllNodes(10000);
- QueryRequest qreq = new QueryRequest(params);
- QueryResponse resp = qreq.process(cluster.getSolrClient(), COLLECTIONORALIAS);
- return resp.getResponse();
- }
-
- @SuppressWarnings("unchecked")
- protected <T> T getValue(NamedList<Object> response, String infoName, String exprName) {
- return (T)response.findRecursive(AnalyticsResponseHeadings.COMPLETED_OLD_HEADER,
- infoName,
- exprName);
- }
-
- public <T extends Number & Comparable<T>> Double calculateNumberStat(ArrayList<T> list, String stat) {
- Double result;
- if (stat.equals("median")) {
- result = MedianCalculator.getMedian(list);
- } else if (stat.equals("mean")) {
- double d = 0;
- for (T element : list) {
- d += element.doubleValue();
- }
- result = Double.valueOf(d/list.size());
- } else if (stat.equals("sum")) {
- double d = 0;
- for (T element : list) {
- d += element.doubleValue();
- }
- result = Double.valueOf(d);
- } else if (stat.equals("sumOfSquares")) {
- double d = 0;
- for (T element : list) {
- d += element.doubleValue()*element.doubleValue();
- }
- result = Double.valueOf(d);
- } else if (stat.equals("stddev")) {
- double sum = 0;
- double sumSquares = 0;
- for (T element : list) {
- sum += element.doubleValue();
- sumSquares += element.doubleValue()*element.doubleValue();
- }
- result = Math.sqrt(sumSquares/list.size()-sum*sum/(list.size()*list.size()));
- } else {
- throw new IllegalArgumentException();
- }
- return result;
- }
-
- public <T extends Comparable<T>> Object calculateStat(ArrayList<T> list, String stat) {
- Object result;
- if (stat.contains("perc_")) {
- ArrayList<Integer> percs = new ArrayList<>(1);
- int ord = (int) Math.ceil(Double.parseDouble(stat.substring(5))/100 * list.size()) - 1;
- percs.add(ord);
- OrdinalCalculator.putOrdinalsInPosition(list, percs);
- result = list.get(percs.get(0));
- } else if (stat.equals("count")) {
- result = Long.valueOf(list.size());
- } else if (stat.equals("unique")) {
- HashSet<T> set = new HashSet<>();
- set.addAll(list);
- result = Long.valueOf((long)set.size());
- } else if (stat.equals("max")) {
- Collections.sort(list);
- result = list.get(list.size()-1);
- } else if (stat.equals("min")) {
- Collections.sort(list);
- result = list.get(0);
- } else {
- result = null;
- }
- return result;
- }
-
- @SuppressWarnings("unchecked")
- public <T extends Comparable<T>> Long calculateMissing(ArrayList<T> list, String type) {
- T def = (T)defaults.get(type);
- long miss = 0;
- for (T element : list) {
- if (element.compareTo(def)==0) {
- miss++;
- }
- }
- return Long.valueOf(miss);
- }
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/AbstractAnalyticsStatsTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/AbstractAnalyticsStatsTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/AbstractAnalyticsStatsTest.java
deleted file mode 100644
index 18f51a9..0000000
--- a/solr/contrib/analytics/src/test/org/apache/solr/analytics/AbstractAnalyticsStatsTest.java
+++ /dev/null
@@ -1,235 +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.ByteArrayInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Scanner;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.xpath.XPathConstants;
-import javax.xml.xpath.XPathExpressionException;
-import javax.xml.xpath.XPathFactory;
-
-import org.apache.commons.lang.StringUtils;
-import org.apache.lucene.util.IOUtils;
-import org.apache.solr.SolrTestCaseJ4;
-import org.apache.solr.analytics.util.AnalyticsResponseHeadings;
-import org.apache.solr.analytics.util.MedianCalculator;
-import org.apache.solr.analytics.util.OrdinalCalculator;
-import org.apache.solr.request.SolrQueryRequest;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.w3c.dom.Document;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-
-import com.google.common.collect.ObjectArrays;
-
-@SolrTestCaseJ4.SuppressPointFields(bugUrl="https://issues.apache.org/jira/browse/SOLR-10949")
-public class AbstractAnalyticsStatsTest extends SolrTestCaseJ4 {
-
- protected static final String[] BASEPARMS = new String[]{ "q", "*:*", "indent", "true", "olap", "true", "rows", "0" };
- protected static final HashMap<String,Object> defaults = new HashMap<>();
-
- public static enum VAL_TYPE {
- INTEGER("int"),
- LONG("long"),
- FLOAT("float"),
- DOUBLE("double"),
- STRING("str"),
- DATE("date");
-
- private VAL_TYPE (final String text) {
- this.text = text;
- }
-
- private final String text;
-
- @Override
- public String toString() {
- return text;
- }
- }
-
- static private Document doc;
- static private XPathFactory xPathFact;
-
- static private String rawResponse;
-
- @BeforeClass
- public static void beforeClassAbstractAnalysis() {
- xPathFact = XPathFactory.newInstance();
- }
-
- @AfterClass
- public static void afterClassAbstractAnalysis() {
- xPathFact = null;
- doc = null;
- rawResponse = null;
- defaults.clear();
- }
-
- public static void setResponse(String response) throws ParserConfigurationException, IOException, SAXException {
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- factory.setNamespaceAware(true); // never forget this!
- DocumentBuilder builder = factory.newDocumentBuilder();
- doc = builder.parse(new InputSource(new ByteArrayInputStream(response.getBytes(StandardCharsets.UTF_8))));
- rawResponse = response;
- }
-
- protected String getRawResponse() {
- return rawResponse;
- }
-
- public Object getStatResult(String section, String name, VAL_TYPE type) throws XPathExpressionException {
-
- // Construct the XPath expression. The form better not change or all these will fail.
- StringBuilder sb = new StringBuilder("/response/lst[@name='"+AnalyticsResponseHeadings.COMPLETED_OLD_HEADER+"']/lst[@name='").append(section).append("']");
-
- // This is a little fragile in that it demands the elements have the same name as type, i.e. when looking for a
- // VAL_TYPE.DOUBLE, the element in question is <double name="blah">47.0</double>.
- sb.append("/").append(type.toString()).append("[@name='").append(name).append("']");
- String val = xPathFact.newXPath().compile(sb.toString()).evaluate(doc, XPathConstants.STRING).toString();
- try {
- switch (type) {
- case INTEGER: return Integer.parseInt(val);
- case DOUBLE: return Double.parseDouble(val);
- case FLOAT: return Float.parseFloat(val);
- case LONG: return Long.parseLong(val);
- case STRING: assertTrue(rawResponse, val != null && val.length() > 0 ); return val;
- case DATE: assertTrue(rawResponse, val != null && val.length() > 0 ); return val;
- }
- } catch (Exception e) {
- e.printStackTrace();
- fail("Caught exception in getStatResult, xPath = " + sb.toString() + " \nraw data: " + rawResponse);
- }
- fail("Unknown type used in getStatResult");
- return null; // Really can't get here, but the compiler thinks we can!
- }
-
-
- public <T extends Number & Comparable<T>> Double calculateNumberStat(ArrayList<T> list, String stat) {
- Double result;
- if (stat.equals("median")) {
- result = MedianCalculator.getMedian(list);
- } else if (stat.equals("mean")) {
- double d = 0;
- for (T element : list) {
- d += element.doubleValue();
- }
- result = Double.valueOf(d/list.size());
- } else if (stat.equals("sum")) {
- double d = 0;
- for (T element : list) {
- d += element.doubleValue();
- }
- result = Double.valueOf(d);
- } else if (stat.equals("sumOfSquares")) {
- double d = 0;
- for (T element : list) {
- d += element.doubleValue()*element.doubleValue();
- }
- result = Double.valueOf(d);
- } else if (stat.equals("stddev")) {
- double sum = 0;
- double sumSquares = 0;
- for (T element : list) {
- sum += element.doubleValue();
- sumSquares += element.doubleValue()*element.doubleValue();
- }
- result = Math.sqrt(sumSquares/list.size()-sum*sum/(list.size()*list.size()));
- } else {
- throw new IllegalArgumentException();
- }
- return result;
- }
-
- public <T extends Comparable<T>> Object calculateStat(ArrayList<T> list, String stat) {
- Object result;
- if (stat.contains("perc_")) {
- ArrayList<Integer> percs = new ArrayList<>(1);
- int ord = (int) Math.ceil(Double.parseDouble(stat.substring(5))/100 * list.size()) - 1;
- percs.add(ord);
- OrdinalCalculator.putOrdinalsInPosition(list, percs);
- result = list.get(percs.get(0));
- } else if (stat.equals("count")) {
- result = Long.valueOf(list.size());
- } else if (stat.equals("unique")) {
- HashSet<T> set = new HashSet<>();
- set.addAll(list);
- result = Long.valueOf((long)set.size());
- } else if (stat.equals("max")) {
- Collections.sort(list);
- result = list.get(list.size()-1);
- } else if (stat.equals("min")) {
- Collections.sort(list);
- result = list.get(0);
- } else {
- result = null;
- }
- return result;
- }
-
- @SuppressWarnings("unchecked")
- public <T extends Comparable<T>> Long calculateMissing(ArrayList<T> list, String type) {
- T def = (T)defaults.get(type);
- long miss = 0;
- for (T element : list) {
- if (element.compareTo(def)==0) {
- miss++;
- }
- }
- return Long.valueOf(miss);
- }
-
- public static SolrQueryRequest request(String...args){
- return SolrTestCaseJ4.req( ObjectArrays.concat(BASEPARMS, args,String.class) );
- }
-
- public static String[] fileToStringArr(Class<?> clazz, String fileName) throws FileNotFoundException {
- InputStream in = clazz.getResourceAsStream("/solr/analytics/" + fileName);
- if (in == null) throw new FileNotFoundException("Resource not found: " + fileName);
- Scanner file = new Scanner(in, "UTF-8");
- try {
- ArrayList<String> strList = new ArrayList<>();
- while (file.hasNextLine()) {
- String line = file.nextLine();
- line = line.trim();
- if( StringUtils.isBlank(line) || line.startsWith("#")){
- continue;
- }
- String[] param = line.split("=");
- strList.add(param[0]);
- strList.add(param[1]);
- }
- return strList.toArray(new String[0]);
- } finally {
- IOUtils.closeWhileHandlingException(file, in);
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/ExpressionFactoryTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/ExpressionFactoryTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/ExpressionFactoryTest.java
new file mode 100644
index 0000000..b4f5b95
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/ExpressionFactoryTest.java
@@ -0,0 +1,249 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.analytics.function.ReductionCollectionManager;
+import org.apache.solr.analytics.value.constant.ConstantValue;
+import org.apache.solr.schema.IndexSchema;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class ExpressionFactoryTest extends SolrTestCaseJ4 {
+
+ private static IndexSchema indexSchema;
+
+ @BeforeClass
+ public static void createSchemaAndFields() throws Exception {
+ initCore("solrconfig-analytics.xml","schema-analytics.xml");
+ assertU(adoc("id", "1",
+ "int_i", "1",
+ "int_im", "1",
+ "long_l", "1",
+ "long_lm", "1",
+ "float_f", "1",
+ "float_fm", "1",
+ "double_d", "1",
+ "double_dm", "1",
+ "date_dt", "1800-12-31T23:59:59Z",
+ "date_dtm", "1800-12-31T23:59:59Z",
+ "string_s", "1",
+ "string_sm", "1",
+ "boolean_b", "true",
+ "boolean_bm", "false"
+ ));
+ assertU(commit());
+
+ indexSchema = h.getCore().getLatestSchema();
+ }
+
+ private ExpressionFactory getExpressionFactory() {
+ ExpressionFactory fact = new ExpressionFactory(indexSchema);
+ fact.startRequest();
+ return fact;
+ }
+
+ @Test
+ public void userDefinedVariableFunctionTest() {
+ ExpressionFactory fact = getExpressionFactory();
+
+ // Single parameter function
+ fact.startRequest();
+ fact.addUserDefinedVariableFunction("single_func(a)", "sum(add(a,double_d,float_f))");
+ assertEquals("div(sum(add(int_i,double_d,float_f)),count(string_s))", fact.createExpression("div(single_func(int_i),count(string_s))").getExpressionStr());
+
+ // Multi parameter function
+ fact.startRequest();
+ fact.addUserDefinedVariableFunction("multi_func(a,b,c)", "median(if(boolean_b,add(a,b),c))");
+ assertEquals("div(median(if(boolean_b,add(int_i,double_d),float_f)),count(string_s))", fact.createExpression("div(multi_func(int_i,double_d,float_f),count(string_s))").getExpressionStr());
+
+ // Function within function
+ fact.startRequest();
+ fact.addUserDefinedVariableFunction("inner_func(a,b)", "div(add(a,b),b)");
+ fact.addUserDefinedVariableFunction("outer_func(a,b,c)", "pow(inner_func(a,b),c)");
+ assertEquals("div(median(pow(div(add(int_i,double_d),double_d),float_f)),count(string_s))", fact.createExpression("div(median(outer_func(int_i,double_d,float_f)),count(string_s))").getExpressionStr());
+
+ // Variable parameter function
+ fact.startRequest();
+ fact.addUserDefinedVariableFunction("var_func(a,b..)", "div(add(b),a)");
+ assertEquals("unique(div(add(double_d,float_f),int_i))", fact.createExpression("unique(var_func(int_i,double_d,float_f))").getExpressionStr());
+ assertEquals("unique(div(add(double_d,float_f,long_l),int_i))", fact.createExpression("unique(var_func(int_i,double_d,float_f,long_l))").getExpressionStr());
+
+ // Variable parameter function with for-each
+ fact.startRequest();
+ fact.addUserDefinedVariableFunction("var_func_fe(a,b..)", "div(add(b:abs(_)),a)");
+ assertEquals("unique(div(add(abs(double_d),abs(float_f)),int_i))", fact.createExpression("unique(var_func_fe(int_i,double_d,float_f))").getExpressionStr());
+ assertEquals("unique(div(add(abs(double_d),abs(float_f),abs(long_l)),int_i))", fact.createExpression("unique(var_func_fe(int_i,double_d,float_f,long_l))").getExpressionStr());
+ }
+
+ @Test
+ public void reuseFunctionsTest() {
+ ExpressionFactory fact = getExpressionFactory();
+
+ // Two ungrouped exactly the same expression
+ fact.startRequest();
+ assertTrue("The objects of the two mapping expressions are not the same.",
+ fact.createExpression("pow(int_i,double_d)") == fact.createExpression("pow(int_i,double_d)"));
+ assertTrue("The objects of the two reduced expressions are not the same.",
+ fact.createExpression("unique(add(int_i,double_d))") == fact.createExpression("unique(add(int_i,double_d))"));
+
+ // Two ungrouped different expressions
+ fact.startRequest();
+ assertFalse("The objects of the two mapping expressions are not the same.",
+ fact.createExpression("pow(int_i,double_d)") == fact.createExpression("pow(int_i,float_f)"));
+ assertFalse("The objects of the two reduced expressions are not the same.",
+ fact.createExpression("unique(add(int_i,double_d))") == fact.createExpression("unique(add(int_i,float_f))"));
+
+ // Grouped and ungrouped mapping expression
+ fact.startRequest();
+ Object ungrouped = fact.createExpression("pow(int_i,double_d)");
+ fact.startGrouping();
+ Object grouped = fact.createExpression("pow(int_i,double_d)");
+ assertTrue("The objects of the two mapping expressions are not the same.", ungrouped == grouped);
+
+ // Grouped and ungrouped diferent mapping expressions
+ fact.startRequest();
+ ungrouped = fact.createExpression("pow(int_i,double_d)");
+ fact.startGrouping();
+ grouped = fact.createExpression("pow(int_i,float_f)");
+ assertFalse("The objects of the two mapping expressions are not the same.", ungrouped == grouped);
+
+ // Grouped and ungrouped reduced expression.
+ fact.startRequest();
+ ungrouped = fact.createExpression("unique(add(int_i,double_d))");
+ fact.startGrouping();
+ grouped = fact.createExpression("unique(add(int_i,double_d))");
+ assertTrue("The objects of the two mapping expressions are not the same.", ungrouped == grouped);
+
+ // Grouped and ungrouped different reduced expressions.
+ fact.startRequest();
+ ungrouped = fact.createExpression("unique(add(int_i,double_d))");
+ fact.startGrouping();
+ grouped = fact.createExpression("unique(add(int_i,float_f))");
+ assertFalse("The objects of the two mapping expressions are the same.", ungrouped == grouped);
+ }
+
+ @Test
+ public void constantFunctionConversionTest() {
+ ExpressionFactory fact = getExpressionFactory();
+ fact.startRequest();
+
+ assertTrue(fact.createExpression("add(1,2)") instanceof ConstantValue);
+ assertTrue(fact.createExpression("add(1,2,2,3,4)") instanceof ConstantValue);
+ assertTrue(fact.createExpression("add(1)") instanceof ConstantValue);
+ assertTrue(fact.createExpression("concat(add(1,2), ' is a number')") instanceof ConstantValue);
+
+ assertFalse(fact.createExpression("sum(add(1,2))") instanceof ConstantValue);
+ assertFalse(fact.createExpression("sum(int_i)") instanceof ConstantValue);
+ assertFalse(fact.createExpression("sub(1,long_l)") instanceof ConstantValue);
+ }
+
+ public void testReductionManager(ReductionCollectionManager manager, boolean hasExpressions, String... fields) {
+ Set<String> usedFields = new HashSet<>(Arrays.asList(fields));
+ manager.getUsedFields().forEach( field -> {
+ assertTrue("Field '" + field.getName() + "' is either not unique or should not exist in the reductionManager.", usedFields.remove(field.getName()));
+ });
+ assertEquals(hasExpressions, manager.needsCollection());
+ }
+
+ @Test
+ public void reductionManagerCreationTest() {
+ ExpressionFactory fact = getExpressionFactory();
+
+ // No expressions
+ fact.startRequest();
+ testReductionManager(fact.createReductionManager(false), false);
+
+ // No fields
+ fact.startRequest();
+ fact.createExpression("sum(add(1,2))");
+ testReductionManager(fact.createReductionManager(false), true);
+
+ // Multiple expressions
+ fact.startRequest();
+ fact.createExpression("unique(add(int_i,float_f))");
+ fact.createExpression("sum(add(int_i,double_d))");
+ testReductionManager(fact.createReductionManager(false), true, "int_i", "float_f", "double_d");
+ }
+
+ @Test
+ public void groupingReductionManagerCreationTest() {
+ ExpressionFactory fact = getExpressionFactory();
+
+ // No grouped expressions
+ fact.startRequest();
+ fact.createExpression("unique(add(int_i,float_f))");
+ fact.createExpression("sum(add(int_i,double_d))");
+ fact.startGrouping();
+ testReductionManager(fact.createGroupingReductionManager(false), false);
+
+ // No grouped fields
+ fact.startRequest();
+ fact.createExpression("unique(add(int_i,float_f))");
+ fact.createExpression("sum(add(int_i,double_d))");
+ fact.startGrouping();
+ fact.createExpression("sum(add(1,2))");
+ testReductionManager(fact.createGroupingReductionManager(false), true);
+
+ // Single grouping, no ungrouped
+ fact.startRequest();
+ fact.startGrouping();
+ fact.createExpression("unique(add(int_i,float_f))");
+ fact.createExpression("sum(add(int_i,double_d))");
+ testReductionManager(fact.createGroupingReductionManager(false), true, "int_i", "float_f", "double_d");
+
+ // Single grouping, with ungrouped
+ fact.startRequest();
+ fact.createExpression("count(string_s)");
+ fact.startGrouping();
+ fact.createExpression("unique(add(int_i,float_f))");
+ fact.createExpression("sum(add(int_i,double_d))");
+ testReductionManager(fact.createGroupingReductionManager(false), true, "int_i", "float_f", "double_d");
+
+ // Multiple groupings, no ungrouped
+ fact.startRequest();
+ fact.startGrouping();
+ fact.createExpression("unique(add(int_i,float_f))");
+ fact.createExpression("sum(add(int_i,double_d))");
+ testReductionManager(fact.createGroupingReductionManager(false), true, "int_i", "float_f", "double_d");
+ fact.startGrouping();
+ testReductionManager(fact.createGroupingReductionManager(false), false);
+ fact.startGrouping();
+ fact.createExpression("unique(add(int_i,float_f))");
+ fact.createExpression("ordinal(1,concat(string_s,'-extra'))");
+ testReductionManager(fact.createGroupingReductionManager(false), true, "int_i", "float_f", "string_s");
+
+ // Multiple groupings, with grouped
+ fact.startRequest();
+ fact.createExpression("count(string_s)");
+ fact.createExpression("median(date_math(date_dt,'+1DAY'))");
+ fact.startGrouping();
+ fact.createExpression("unique(add(int_i,float_f))");
+ fact.createExpression("sum(add(int_i,double_d))");
+ testReductionManager(fact.createGroupingReductionManager(false), true, "int_i", "float_f", "double_d");
+ fact.startGrouping();
+ testReductionManager(fact.createGroupingReductionManager(false), false);
+ fact.startGrouping();
+ fact.createExpression("unique(add(int_i,float_f))");
+ fact.createExpression("ordinal(1,concat(string_s,'-extra'))");
+ testReductionManager(fact.createGroupingReductionManager(false), true, "int_i", "float_f", "string_s");
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/NoFacetCloudTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/NoFacetCloudTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/NoFacetCloudTest.java
deleted file mode 100644
index 71503af..0000000
--- a/solr/contrib/analytics/src/test/org/apache/solr/analytics/NoFacetCloudTest.java
+++ /dev/null
@@ -1,557 +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.List;
-
-import org.apache.solr.client.solrj.request.UpdateRequest;
-import org.apache.solr.common.util.NamedList;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-public class NoFacetCloudTest extends AbstractAnalyticsStatsCloudTest {
- static public final int INT = 71;
- static public final int LONG = 36;
- static public final int FLOAT = 93;
- static public final int DOUBLE = 49;
- static public final int DATE = 12;
- static public final int STRING = 28;
- static public final int NUM_LOOPS = 100;
-
- //INT
- static ArrayList<Integer> intTestStart;
- static long intMissing = 0;
-
- //LONG
- static ArrayList<Long> longTestStart;
- static long longMissing = 0;
-
- //FLOAT
- static ArrayList<Float> floatTestStart;
- static long floatMissing = 0;
-
- //DOUBLE
- static ArrayList<Double> doubleTestStart;
- static long doubleMissing = 0;
-
- //DATE
- static ArrayList<String> dateTestStart;
- static long dateMissing = 0;
-
- //STR
- static ArrayList<String> stringTestStart;
- static long stringMissing = 0;
-
- @BeforeClass
- public static void populate() throws Exception {
- setupCluster();
- defaults.put("int_id", new Integer(0));
- defaults.put("long_ld", new Long(0));
- defaults.put("float_fd", new Float(0));
- defaults.put("double_dd", new Double(0));
- defaults.put("date_dtd", "1800-12-31T23:59:59Z");
- defaults.put("string_sd", "str0");
-
- intTestStart = new ArrayList<>();
- longTestStart = new ArrayList<>();
- floatTestStart = new ArrayList<>();
- doubleTestStart = new ArrayList<>();
- dateTestStart = new ArrayList<>();
- stringTestStart = new ArrayList<>();
-
- UpdateRequest req = new UpdateRequest();
- for (int j = 0; j < NUM_LOOPS; ++j) {
- int i = j%INT;
- long l = j%LONG;
- float f = j%FLOAT;
- double d = j%DOUBLE;
- String dt = (1800+j%DATE) + "-12-31T23:59:59Z";
- String s = "str" + (j%STRING);
- List<String> fields = new ArrayList<>();
- fields.add("id"); fields.add("1000"+j);
-
- if( i != 0 ){
- fields.add("int_id"); fields.add("" + i);
- intTestStart.add(i);
- } else intMissing++;
-
- if( l != 0l ){
- fields.add("long_ld"); fields.add("" + l);
- longTestStart.add(l);
- } else longMissing++;
-
- if( f != 0.0f ){
- fields.add("float_fd"); fields.add("" + f);
- floatTestStart.add(f);
- } else floatMissing++;
-
- if( d != 0.0d ){
- fields.add("double_dd"); fields.add("" + d);
- doubleTestStart.add(d);
- } else doubleMissing++;
-
- if( (j%DATE) != 0 ){
- fields.add("date_dtd"); fields.add(dt);
- dateTestStart.add(dt);
- } else dateMissing++;
-
- if( (j%STRING) != 0 ){
- fields.add("string_sd"); fields.add(s);
- stringTestStart.add(s);
- } else stringMissing++;
-
- req.add(fields.toArray(new String[0]));
- }
- req.commit(cluster.getSolrClient(), COLLECTIONORALIAS);
- }
-
- @Test
- public void sumTest() throws Exception {
- String[] params = new String[] {
- "o.sr.s.int_id", "sum(int_id)",
- "o.sr.s.long_ld", "sum(long_ld)",
- "o.sr.s.float_fd", "sum(float_fd)",
- "o.sr.s.double_dd", "sum(double_dd)"
- };
- NamedList<Object> response = queryCloudAnalytics(params);
- String responseStr = response.toString();
-
- //Int
- Double intResult = getValue(response, "sr", "int_id");
- Double intTest = (Double)calculateNumberStat(intTestStart, "sum");
- assertEquals(responseStr, intResult,intTest);
-
- //Long
- Double longResult = getValue(response, "sr", "long_ld");
- Double longTest = (Double)calculateNumberStat(longTestStart, "sum");
- assertEquals(responseStr, longResult,longTest);
-
- //Float
- Double floatResult = getValue(response, "sr", "float_fd");
- Double floatTest = (Double)calculateNumberStat(floatTestStart, "sum");
- assertEquals(responseStr, floatResult,floatTest);
-
- //Double
- Double doubleResult = getValue(response, "sr", "double_dd");
- Double doubleTest = (Double) calculateNumberStat(doubleTestStart, "sum");
- assertEquals(responseStr, doubleResult,doubleTest);
- }
-
- @Test
- public void meanTest() throws Exception {
- String[] params = new String[] {
- "o.mr.s.int_id", "mean(int_id)",
- "o.mr.s.long_ld", "mean(long_ld)",
- "o.mr.s.float_fd", "mean(float_fd)",
- "o.mr.s.double_dd", "mean(double_dd)"
- };
- NamedList<Object> response = queryCloudAnalytics(params);
- String responseStr = response.toString();
-
- //Int
- Double intResult = getValue(response, "mr", "int_id");
- Double intTest = (Double)calculateNumberStat(intTestStart, "mean");
- assertEquals(responseStr, intResult,intTest);
-
- //Long
- Double longResult = getValue(response, "mr", "long_ld");
- Double longTest = (Double)calculateNumberStat(longTestStart, "mean");
- assertEquals(responseStr, longResult,longTest);
-
- //Float
- Double floatResult = getValue(response, "mr", "float_fd");
- Double floatTest = (Double)calculateNumberStat(floatTestStart, "mean");
- assertEquals(responseStr, floatResult,floatTest);
-
- //Double
- Double doubleResult = getValue(response, "mr", "double_dd");
- Double doubleTest = (Double)calculateNumberStat(doubleTestStart, "mean");
- assertEquals(responseStr, doubleResult,doubleTest);
- }
-
- @Test
- public void stddevTest() throws Exception {
- String[] params = new String[] {
- "o.str.s.int_id", "stddev(int_id)",
- "o.str.s.long_ld", "stddev(long_ld)",
- "o.str.s.float_fd", "stddev(float_fd)",
- "o.str.s.double_dd", "stddev(double_dd)"
- };
- NamedList<Object> response = queryCloudAnalytics(params);
- String responseStr = response.toString();
-
- //Int
- Double intResult = getValue(response, "str", "int_id");
- Double intTest = (Double)calculateNumberStat(intTestStart, "stddev");
- assertEquals(responseStr, intResult, intTest, 0.00000000001);
-
- //Long
- Double longResult = getValue(response, "str", "long_ld");
- Double longTest = (Double)calculateNumberStat(longTestStart, "stddev");
- assertEquals(responseStr, longResult, longTest, 0.00000000001);
-
- //Float
- Double floatResult = getValue(response, "str", "float_fd");
- Double floatTest = (Double)calculateNumberStat(floatTestStart, "stddev");
- assertEquals(responseStr, floatResult, floatTest, 0.00000000001);
-
-
- //Double
- Double doubleResult = getValue(response, "str", "double_dd");
- Double doubleTest = (Double)calculateNumberStat(doubleTestStart, "stddev");
- assertEquals(responseStr, doubleResult, doubleTest, 0.00000000001);
- }
-
- @Test
- public void medianTest() throws Exception {
- String[] params = new String[] {
- "o.medr.s.int_id", "median(int_id)",
- "o.medr.s.long_ld", "median(long_ld)",
- "o.medr.s.float_fd", "median(float_fd)",
- "o.medr.s.double_dd", "median(double_dd)",
- "o.medr.s.date_dtd", "median(date_dtd)"
- };
- NamedList<Object> response = queryCloudAnalytics(params);
- String responseStr = response.toString();
-
- //Int
- Double intResult = getValue(response, "medr", "int_id");
- Double intTest = (Double)calculateNumberStat(intTestStart, "median");
- assertEquals(responseStr, intResult,intTest);
-
- //Long
- Double longResult = getValue(response, "medr", "long_ld");
- Double longTest = (Double)calculateNumberStat(longTestStart, "median");
- assertEquals(responseStr, longResult,longTest);
-
- //Float
- Double floatResult = getValue(response, "medr", "float_fd");
- Double floatTest = (Double)calculateNumberStat(floatTestStart, "median");
- assertEquals(responseStr, floatResult,floatTest);
-
- //Double
- Double doubleResult = getValue(response, "medr", "double_dd");
- Double doubleTest = (Double)calculateNumberStat(doubleTestStart, "median");
- assertEquals(responseStr, doubleResult,doubleTest);
-
- // TODO: Add test for date median
- }
-
- @Test
- public void perc20Test() throws Exception {
- String[] params = new String[] {
- "o.p2r.s.int_id", "percentile(20,int_id)",
- "o.p2r.s.long_ld", "percentile(20,long_ld)",
- "o.p2r.s.float_fd", "percentile(20,float_fd)",
- "o.p2r.s.double_dd", "percentile(20,double_dd)",
- "o.p2r.s.date_dtd", "string(percentile(20,date_dtd))",
- "o.p2r.s.string_sd", "percentile(20,string_sd)"
- };
- NamedList<Object> response = queryCloudAnalytics(params);
- String responseStr = response.toString();
-
- //Int 20
- Integer intResult = getValue(response, "p2r", "int_id");
- Integer intTest = (Integer)calculateStat(intTestStart, "perc_20");
- assertEquals(responseStr, intResult,intTest);
-
- //Long 20
- Long longResult = getValue(response, "p2r", "long_ld");
- Long longTest = (Long)calculateStat(longTestStart, "perc_20");
- assertEquals(responseStr, longResult,longTest);
-
- //Float 20
- Float floatResult = getValue(response, "p2r", "float_fd");
- Float floatTest = (Float)calculateStat(floatTestStart, "perc_20");
- assertEquals(responseStr, floatResult,floatTest);
-
- //Double 20
- Double doubleResult = getValue(response, "p2r", "double_dd");
- Double doubleTest = (Double)calculateStat(doubleTestStart, "perc_20");
- assertEquals(responseStr, doubleResult,doubleTest);
-
- //Date 20
- String dateResult = getValue(response, "p2r", "date_dtd");
- String dateTest = (String)calculateStat(dateTestStart, "perc_20");
- assertEquals(responseStr, dateResult,dateTest);
-
- //String 20
- String stringResult = getValue(response, "p2r", "string_sd");
- String stringTest = (String)calculateStat(stringTestStart, "perc_20");
- assertEquals(responseStr, stringResult,stringTest);
- }
-
- @Test
- public void perc60Test() throws Exception {
- String[] params = new String[] {
- "o.p6r.s.int_id", "percentile(60,int_id)",
- "o.p6r.s.long_ld", "percentile(60,long_ld)",
- "o.p6r.s.float_fd", "percentile(60,float_fd)",
- "o.p6r.s.double_dd", "percentile(60,double_dd)",
- "o.p6r.s.date_dtd", "string(percentile(60,date_dtd))",
- "o.p6r.s.string_sd", "percentile(60,string_sd)"
- };
- NamedList<Object> response = queryCloudAnalytics(params);
- String responseStr = response.toString();
-
- //Int 60
- Integer intResult = getValue(response, "p6r", "int_id");
- Integer intTest = (Integer)calculateStat(intTestStart, "perc_60");
- assertEquals(responseStr, intResult,intTest);
-
- //Long 60
- Long longResult = getValue(response, "p6r", "long_ld");
- Long longTest = (Long)calculateStat(longTestStart, "perc_60");
- assertEquals(responseStr, longResult,longTest);
-
- //Float 60
- Float floatResult = getValue(response, "p6r", "float_fd");
- Float floatTest = (Float)calculateStat(floatTestStart, "perc_60");
- assertEquals(responseStr, floatResult,floatTest);
-
- //Double 60
- Double doubleResult = getValue(response, "p6r", "double_dd");
- Double doubleTest = (Double)calculateStat(doubleTestStart, "perc_60");
- assertEquals(responseStr, doubleResult,doubleTest);
-
- //Date 60
- String dateResult = getValue(response, "p6r", "date_dtd");
- String dateTest = (String)calculateStat(dateTestStart, "perc_60");
- assertEquals(responseStr, dateResult,dateTest);
-
- //String 60
- String stringResult = getValue(response, "p6r", "string_sd");
- String stringTest = (String)calculateStat(stringTestStart, "perc_60");
- assertEquals(responseStr, stringResult,stringTest);
- }
-
- @Test
- public void minTest() throws Exception {
- String[] params = new String[] {
- "o.mir.s.int_id", "min(int_id)",
- "o.mir.s.long_ld", "min(long_ld)",
- "o.mir.s.float_fd", "min(float_fd)",
- "o.mir.s.double_dd", "min(double_dd)",
- "o.mir.s.date_dtd", "string(min(date_dtd))",
- "o.mir.s.string_sd", "min(string_sd)"
- };
- NamedList<Object> response = queryCloudAnalytics(params);
- String responseStr = response.toString();
-
- //Int
- Integer intResult = getValue(response, "mir", "int_id");
- Integer intTest = (Integer)calculateStat(intTestStart, "min");
- assertEquals(responseStr, intResult,intTest);
-
- //Long
- Long longResult = getValue(response, "mir", "long_ld");
- Long longTest = (Long)calculateStat(longTestStart, "min");
- assertEquals(responseStr, longResult,longTest);
-
- //Float
- Float floatResult = getValue(response, "mir", "float_fd");
- Float floatTest = (Float)calculateStat(floatTestStart, "min");
- assertEquals(responseStr, floatResult,floatTest);
-
- //Double
- Double doubleResult = getValue(response, "mir", "double_dd");
- Double doubleTest = (Double)calculateStat(doubleTestStart, "min");
- assertEquals(responseStr, doubleResult,doubleTest);
-
- //Date
- String dateResult = getValue(response, "mir", "date_dtd");
- String dateTest = (String)calculateStat(dateTestStart, "min");
- assertEquals(responseStr, dateResult,dateTest);
-
- //String
- String stringResult = getValue(response, "mir", "string_sd");
- String stringTest = (String)calculateStat(stringTestStart, "min");
- assertEquals(responseStr, stringResult,stringTest);
- }
-
- @Test
- public void maxTest() throws Exception {
- String[] params = new String[] {
- "o.mar.s.int_id", "max(int_id)",
- "o.mar.s.long_ld", "max(long_ld)",
- "o.mar.s.float_fd", "max(float_fd)",
- "o.mar.s.double_dd", "max(double_dd)",
- "o.mar.s.date_dtd", "string(max(date_dtd))",
- "o.mar.s.string_sd", "max(string_sd)"
- };
- NamedList<Object> response = queryCloudAnalytics(params);
- String responseStr = response.toString();
-
- //Int
- Integer intResult = getValue(response, "mar", "int_id");
- Integer intTest = (Integer)calculateStat(intTestStart, "max");
- assertEquals(responseStr, intResult,intTest);
-
- //Long
- Long longResult = getValue(response, "mar", "long_ld");
- Long longTest = (Long)calculateStat(longTestStart, "max");
- assertEquals(responseStr, longResult,longTest);
-
- //Float
- Float floatResult = getValue(response, "mar", "float_fd");
- Float floatTest = (Float)calculateStat(floatTestStart, "max");
- assertEquals(responseStr, floatResult,floatTest);
-
- //Double
- Double doubleResult = getValue(response, "mar", "double_dd");
- Double doubleTest = (Double)calculateStat(doubleTestStart, "max");
- assertEquals(responseStr, doubleResult,doubleTest);
-
- //Date
- String dateResult = getValue(response, "mar", "date_dtd");
- String dateTest = (String)calculateStat(dateTestStart, "max");
- assertEquals(responseStr, dateResult,dateTest);
-
- //String
- String stringResult = getValue(response, "mar", "string_sd");
- String stringTest = (String)calculateStat(stringTestStart, "max");
- assertEquals(responseStr, stringResult,stringTest);
- }
-
- @Test
- public void uniqueTest() throws Exception {
- String[] params = new String[] {
- "o.ur.s.int_id", "unique(int_id)",
- "o.ur.s.long_ld", "unique(long_ld)",
- "o.ur.s.float_fd", "unique(float_fd)",
- "o.ur.s.double_dd", "unique(double_dd)",
- "o.ur.s.date_dtd", "unique(date_dtd)",
- "o.ur.s.string_sd", "unique(string_sd)"
- };
- NamedList<Object> response = queryCloudAnalytics(params);
- String responseStr = response.toString();
-
- //Int
- Long intResult = getValue(response, "ur", "int_id");
- Long intTest = (Long)calculateStat(intTestStart, "unique");
- assertEquals(responseStr, intResult,intTest);
-
- //Long
- Long longResult = getValue(response, "ur", "long_ld");
- Long longTest = (Long)calculateStat(longTestStart, "unique");
- assertEquals(responseStr, longResult,longTest);
-
- //Float
- Long floatResult = getValue(response, "ur", "float_fd");
- Long floatTest = (Long)calculateStat(floatTestStart, "unique");
- assertEquals(responseStr, floatResult,floatTest);
-
- //Double
- Long doubleResult = getValue(response, "ur", "double_dd");
- Long doubleTest = (Long)calculateStat(doubleTestStart, "unique");
- assertEquals(responseStr, doubleResult,doubleTest);
-
- //Date
- Long dateResult = getValue(response, "ur", "date_dtd");
- Long dateTest = (Long)calculateStat(dateTestStart, "unique");
- assertEquals(responseStr, dateResult,dateTest);
-
- //String
- Long stringResult = getValue(response, "ur", "string_sd");
- Long stringTest = (Long)calculateStat(stringTestStart, "unique");
- assertEquals(responseStr, stringResult,stringTest);
- }
-
- @Test
- public void countTest() throws Exception {
- String[] params = new String[] {
- "o.cr.s.int_id", "count(int_id)",
- "o.cr.s.long_ld", "count(long_ld)",
- "o.cr.s.float_fd", "count(float_fd)",
- "o.cr.s.double_dd", "count(double_dd)",
- "o.cr.s.date_dtd", "count(date_dtd)",
- "o.cr.s.string_sd", "count(string_sd)"
- };
- NamedList<Object> response = queryCloudAnalytics(params);
- String responseStr = response.toString();
-
- //Int
- Long intResult = getValue(response, "cr", "int_id");
- Long intTest = (Long)calculateStat(intTestStart, "count");
- assertEquals(responseStr, intResult,intTest);
-
- //Long
- Long longResult = getValue(response, "cr", "long_ld");
- Long longTest = (Long)calculateStat(longTestStart, "count");
- assertEquals(responseStr, longResult,longTest);
-
- //Float
- Long floatResult = getValue(response, "cr", "float_fd");
- Long floatTest = (Long)calculateStat(floatTestStart, "count");
- assertEquals(responseStr, floatResult,floatTest);
-
- //Double
- Long doubleResult = getValue(response, "cr", "double_dd");
- Long doubleTest = (Long)calculateStat(doubleTestStart, "count");
- assertEquals(responseStr, doubleResult,doubleTest);
-
- //Date
- Long dateResult = getValue(response, "cr", "date_dtd");
- Long dateTest = (Long)calculateStat(dateTestStart, "count");
- assertEquals(responseStr, dateResult,dateTest);
-
- //String
- Long stringResult = getValue(response, "cr", "string_sd");
- Long stringTest = (Long)calculateStat(stringTestStart, "count");
- assertEquals(responseStr, stringResult,stringTest);
- }
-
- @Test
- public void missingDefaultTest() throws Exception {
- String[] params = new String[] {
- "o.misr.s.int_id", "missing(int_id)",
- "o.misr.s.long_ld", "missing(long_ld)",
- "o.misr.s.float_fd", "missing(float_fd)",
- "o.misr.s.double_dd", "missing(double_dd)",
- "o.misr.s.date_dtd", "missing(date_dtd)",
- "o.misr.s.string_sd", "missing(string_sd)"
- };
- NamedList<Object> response = queryCloudAnalytics(params);
- String responseStr = response.toString();
-
- //Int
- long intResult = getValue(response, "misr", "int_id");
- assertEquals(responseStr, intMissing,intResult);
-
- //Long
- long longResult = getValue(response, "misr", "long_ld");
- assertEquals(responseStr, longMissing,longResult);
-
- //Float
- long floatResult = getValue(response, "misr", "float_fd");
- assertEquals(responseStr, floatMissing,floatResult);
-
- //Double
- long doubleResult = getValue(response, "misr", "double_dd");
- assertEquals(responseStr, doubleMissing,doubleResult);
-
- //Date
- long dateResult = getValue(response, "misr", "date_dtd");
- assertEquals(responseStr, dateMissing,dateResult);
-
- //String
- long stringResult = getValue(response, "misr", "string_sd");
- assertEquals(responseStr, stringMissing, stringResult);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/NoFacetTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/NoFacetTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/NoFacetTest.java
index cfd1176..6a5f8c5 100644
--- a/solr/contrib/analytics/src/test/org/apache/solr/analytics/NoFacetTest.java
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/NoFacetTest.java
@@ -17,434 +17,232 @@
package org.apache.solr.analytics;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.junit.BeforeClass;
import org.junit.Test;
-public class NoFacetTest extends AbstractAnalyticsStatsTest {
- static String fileName = "noFacets.txt";
-
- static public final int INT = 71;
- static public final int LONG = 36;
- static public final int FLOAT = 93;
- static public final int DOUBLE = 49;
- static public final int DATE = 12;
- static public final int STRING = 28;
- static public final int NUM_LOOPS = 100;
-
- //INT
- static ArrayList<Integer> intTestStart;
- static long intMissing = 0;
-
- //LONG
- static ArrayList<Long> longTestStart;
- static long longMissing = 0;
-
- //FLOAT
- static ArrayList<Float> floatTestStart;
- static long floatMissing = 0;
-
- //DOUBLE
- static ArrayList<Double> doubleTestStart;
- static long doubleMissing = 0;
-
- //DATE
- static ArrayList<String> dateTestStart;
- static long dateMissing = 0;
-
- //STR
- static ArrayList<String> stringTestStart;
- static long stringMissing = 0;
+public class NoFacetTest extends SolrAnalyticsTestCase {
@BeforeClass
- public static void beforeClass() throws Exception {
- initCore("solrconfig-analytics.xml","schema-analytics.xml");
- h.update("<delete><query>*:*</query></delete>");
- defaults.put("int_id", new Integer(0));
- defaults.put("long_ld", new Long(0));
- defaults.put("float_fd", new Float(0));
- defaults.put("double_dd", new Double(0));
- defaults.put("date_dtd", "1800-12-31T23:59:59Z");
- defaults.put("string_sd", "str0");
-
- intTestStart = new ArrayList<>();
- longTestStart = new ArrayList<>();
- floatTestStart = new ArrayList<>();
- doubleTestStart = new ArrayList<>();
- dateTestStart = new ArrayList<>();
- stringTestStart = new ArrayList<>();
-
+ public static void populate() throws Exception {
for (int j = 0; j < NUM_LOOPS; ++j) {
int i = j%INT;
long l = j%LONG;
float f = j%FLOAT;
double d = j%DOUBLE;
String dt = (1800+j%DATE) + "-12-31T23:59:59Z";
+ String dtm = (1800+j%DATE + 10) + "-12-31T23:59:59Z";
String s = "str" + (j%STRING);
List<String> fields = new ArrayList<>();
fields.add("id"); fields.add("1000"+j);
- if( i != 0 ){
- fields.add("int_id"); fields.add("" + i);
- intTestStart.add(i);
- } else intMissing++;
-
- if( l != 0l ){
- fields.add("long_ld"); fields.add("" + l);
- longTestStart.add(l);
- } else longMissing++;
-
- if( f != 0.0f ){
- fields.add("float_fd"); fields.add("" + f);
- floatTestStart.add(f);
- } else floatMissing++;
-
- if( d != 0.0d ){
- fields.add("double_dd"); fields.add("" + d);
- doubleTestStart.add(d);
- } else doubleMissing++;
+ if ( i != 0 ) {
+ fields.add("int_i"); fields.add("" + i);
+ fields.add("int_im"); fields.add("" + i);
+ fields.add("int_im"); fields.add("" + (i+10));
+ }
- if( (j%DATE) != 0 ){
- fields.add("date_dtd"); fields.add(dt);
- dateTestStart.add(dt);
- } else dateMissing++;
+ if ( l != 0l ) {
+ fields.add("long_l"); fields.add("" + l);
+ fields.add("long_lm"); fields.add("" + l);
+ fields.add("long_lm"); fields.add("" + (l+10));
+ }
- if( (j%STRING) != 0 ){
- fields.add("string_sd"); fields.add(s);
- stringTestStart.add(s);
- } else stringMissing++;
+ if ( f != 0.0f ) {
+ fields.add("float_f"); fields.add("" + f);
+ fields.add("float_fm"); fields.add("" + f);
+ fields.add("float_fm"); fields.add("" + (f+10));
+ }
- assertU(adoc(fields.toArray(new String[0])));
+ if ( d != 0.0d ) {
+ fields.add("double_d"); fields.add("" + d);
+ fields.add("double_dm"); fields.add("" + d);
+ fields.add("double_dm"); fields.add("" + (d+10));
+ }
+ if ( (j%DATE) != 0 ) {
+ fields.add("date_dt"); fields.add(dt);
+ fields.add("date_dtm"); fields.add(dt);
+ fields.add("date_dtm"); fields.add(dtm);
+ }
- if (usually()) {
- assertU(commit()); // to have several segments
+ if ( (j%STRING) != 0 ) {
+ fields.add("string_s"); fields.add(s);
+ fields.add("string_sm"); fields.add(s);
+ fields.add("string_sm"); fields.add(s + "_second");
}
+
+ addDoc(fields);
}
+ commitDocs();
+ }
+
+ static public final int INT = 7;
+ static public final int LONG = 2;
+ static public final int FLOAT = 6;
+ static public final int DOUBLE = 5;
+ static public final int DATE = 3;
+ static public final int STRING = 4;
+ static public final int NUM_LOOPS = 20;
+
+ @Test
+ public void countTest() throws Exception {
+ Map<String, ETP> expressions = new HashMap<>();
+ expressions.put("single", new ETP("count(long_l)", 10L));
+ expressions.put("multi", new ETP("count(string_sm)", 30L));
- assertU(commit());
+ testExpressions(expressions);
+ }
+
+ @Test
+ public void docCountTest() throws Exception {
+ Map<String, ETP> expressions = new HashMap<>();
+ expressions.put("single", new ETP("doc_count(date_dt)", 13L));
+ expressions.put("multi", new ETP("doc_count(float_fm)", 16L));
- //Sort ascending tests
- setResponse(h.query(request(fileToStringArr(NoFacetTest.class, fileName))));
+ testExpressions(expressions);
}
@Test
- public void sumTest() throws Exception {
- //Int
- Double intResult = (Double)getStatResult("sr", "int_id", VAL_TYPE.DOUBLE);
- Double intTest = (Double)calculateNumberStat(intTestStart, "sum");
- assertEquals(getRawResponse(), intResult,intTest);
-
- //Long
- Double longResult = (Double)getStatResult("sr", "long_ld", VAL_TYPE.DOUBLE);
- Double longTest = (Double)calculateNumberStat(longTestStart, "sum");
- assertEquals(getRawResponse(), longResult,longTest);
-
- //Float
- Double floatResult = (Double)getStatResult("sr", "float_fd", VAL_TYPE.DOUBLE);
- Double floatTest = (Double)calculateNumberStat(floatTestStart, "sum");
- assertEquals(getRawResponse(), floatResult,floatTest);
+ public void missingTest() throws Exception {
+ Map<String, ETP> expressions = new HashMap<>();
+ expressions.put("single", new ETP("missing(string_s)", 5L));
+ expressions.put("multi", new ETP("missing(date_dtm)", 7L));
- //Double
- Double doubleResult = (Double)getStatResult("sr", "double_dd", VAL_TYPE.DOUBLE);
- Double doubleTest = (Double) calculateNumberStat(doubleTestStart, "sum");
- assertEquals(getRawResponse(), doubleResult,doubleTest);
+ testExpressions(expressions);
}
@Test
- public void meanTest() throws Exception {
- //Int
- Double intResult = (Double)getStatResult("mr", "int_id", VAL_TYPE.DOUBLE);
- Double intTest = (Double)calculateNumberStat(intTestStart, "mean");
- assertEquals(getRawResponse(), intResult,intTest);
-
- //Long
- Double longResult = (Double)getStatResult("mr", "long_ld", VAL_TYPE.DOUBLE);
- Double longTest = (Double)calculateNumberStat(longTestStart, "mean");
- assertEquals(getRawResponse(), longResult,longTest);
-
- //Float
- Double floatResult = (Double)getStatResult("mr", "float_fd", VAL_TYPE.DOUBLE);
- Double floatTest = (Double)calculateNumberStat(floatTestStart, "mean");
- assertEquals(getRawResponse(), floatResult,floatTest);
-
- //Double
- Double doubleResult = (Double)getStatResult("mr", "double_dd", VAL_TYPE.DOUBLE);
- Double doubleTest = (Double)calculateNumberStat(doubleTestStart, "mean");
- assertEquals(getRawResponse(), doubleResult,doubleTest);
+ public void uniqueTest() throws Exception {
+ Map<String, ETP> expressions = new HashMap<>();
+ expressions.put("int", new ETP("unique(int_i)", 6L));
+ expressions.put("longs", new ETP("unique(long_lm)", 2L));
+ expressions.put("float", new ETP("unique(float_f)", 5L));
+ expressions.put("doubles", new ETP("unique(double_dm)", 8L));
+ expressions.put("dates", new ETP("unique(date_dt)", 2L));
+ expressions.put("strings", new ETP("unique(string_sm)", 6L));
+
+ testExpressions(expressions);
}
@Test
- public void stddevTest() throws Exception {
- //Int
- Double intResult = (Double)getStatResult("str", "int_id", VAL_TYPE.DOUBLE);
- Double intTest = (Double)calculateNumberStat(intTestStart, "stddev");
- assertEquals(getRawResponse(), intResult, intTest, 0.00000000001);
-
- //Long
- Double longResult = (Double)getStatResult("str", "long_ld", VAL_TYPE.DOUBLE);
- Double longTest = (Double)calculateNumberStat(longTestStart, "stddev");
- assertEquals(getRawResponse(), longResult, longTest, 0.00000000001);
-
- //Float
- Double floatResult = (Double)getStatResult("str", "float_fd", VAL_TYPE.DOUBLE);
- Double floatTest = (Double)calculateNumberStat(floatTestStart, "stddev");
- assertEquals(getRawResponse(), floatResult, floatTest, 0.00000000001);
-
-
- //Double
- Double doubleResult = (Double)getStatResult("str", "double_dd", VAL_TYPE.DOUBLE);
- Double doubleTest = (Double)calculateNumberStat(doubleTestStart, "stddev");
- assertEquals(getRawResponse(), doubleResult, doubleTest, 0.00000000001);
+ public void minTest() throws Exception {
+ Map<String, ETP> expressions = new HashMap<>();
+ expressions.put("int", new ETP("min(int_i)", 1));
+ expressions.put("longs", new ETP("min(long_lm)", 1L));
+ expressions.put("float", new ETP("min(float_f)", 1.0F));
+ expressions.put("doubles", new ETP("min(double_dm)", 1.0));
+ expressions.put("dates", new ETP("min(date_dt)", "1801-12-31T23:59:59Z"));
+ expressions.put("strings", new ETP("min(string_sm)", "str1"));
+
+ testExpressions(expressions);
}
@Test
- public void medianTest() throws Exception {
- //Int
- Double intResult = (Double)getStatResult("medr", "int_id", VAL_TYPE.DOUBLE);
- Double intTest = (Double)calculateNumberStat(intTestStart, "median");
- assertEquals(getRawResponse(), intResult,intTest);
-
- //Long
- Double longResult = (Double)getStatResult("medr", "long_ld", VAL_TYPE.DOUBLE);
- Double longTest = (Double)calculateNumberStat(longTestStart, "median");
- assertEquals(getRawResponse(), longResult,longTest);
+ public void maxTest() throws Exception {
+ Map<String, ETP> expressions = new HashMap<>();
+ expressions.put("int", new ETP("max(int_i)", 6));
+ expressions.put("longs", new ETP("max(long_lm)", 11L));
+ expressions.put("float", new ETP("max(float_f)", 5.0F));
+ expressions.put("doubles", new ETP("max(double_dm)", 14.0));
+ expressions.put("dates", new ETP("max(date_dt)", "1802-12-31T23:59:59Z"));
+ expressions.put("strings", new ETP("max(string_sm)", "str3_second"));
+
+ testExpressions(expressions);
+ }
+
+ @Test
+ public void sumTest() throws Exception {
+ Map<String, ETP> expressions = new HashMap<>();
+ expressions.put("single", new ETP("sum(int_i)", 57.0));
+ expressions.put("multi", new ETP("sum(long_lm)", 120.0));
- //Float
- Double floatResult = (Double)getStatResult("medr", "float_fd", VAL_TYPE.DOUBLE);
- Double floatTest = (Double)calculateNumberStat(floatTestStart, "median");
- assertEquals(getRawResponse(), floatResult,floatTest);
+ testExpressions(expressions);
+ }
+
+ @Test
+ public void meanTest() throws Exception {
+ Map<String, ETP> expressions = new HashMap<>();
+ expressions.put("single", new ETP("mean(int_i)", 3.3529411764));
+ expressions.put("multi", new ETP("mean(long_lm)", 6.0));
- //Double
- Double doubleResult = (Double)getStatResult("medr", "double_dd", VAL_TYPE.DOUBLE);
- Double doubleTest = (Double)calculateNumberStat(doubleTestStart, "median");
- assertEquals(getRawResponse(), doubleResult,doubleTest);
+ testExpressions(expressions);
}
@Test
- public void perc20Test() throws Exception {
- //Int 20
- Integer intResult = (Integer)getStatResult("p2r", "int_id", VAL_TYPE.INTEGER);
- Integer intTest = (Integer)calculateStat(intTestStart, "perc_20");
- assertEquals(getRawResponse(), intResult,intTest);
-
- //Long 20
- Long longResult = (Long)getStatResult("p2r", "long_ld", VAL_TYPE.LONG);
- Long longTest = (Long)calculateStat(longTestStart, "perc_20");
- assertEquals(getRawResponse(), longResult,longTest);
-
- //Float 20
- Float floatResult = (Float)getStatResult("p2r", "float_fd", VAL_TYPE.FLOAT);
- Float floatTest = (Float)calculateStat(floatTestStart, "perc_20");
- //assertEquals(getRawResponse(), floatResult,floatTest);
-
- //Double 20
- Double doubleResult = (Double)getStatResult("p2r", "double_dd", VAL_TYPE.DOUBLE);
- Double doubleTest = (Double)calculateStat(doubleTestStart, "perc_20");
- assertEquals(getRawResponse(), doubleResult,doubleTest);
-
- //Date 20
- String dateResult = (String)getStatResult("p2r", "date_dtd", VAL_TYPE.DATE);
- String dateTest = (String)calculateStat(dateTestStart, "perc_20");
- assertEquals(getRawResponse(), dateResult,dateTest);
-
- //String 20
- String stringResult = (String)getStatResult("p2r", "string_sd", VAL_TYPE.STRING);
- String stringTest = (String)calculateStat(stringTestStart, "perc_20");
- assertEquals(getRawResponse(), stringResult,stringTest);
+ public void weightedMeanTest() throws Exception {
+ Map<String, ETP> expressions = new HashMap<>();
+ expressions.put("single", new ETP("wmean(int_i, long_l)", 3.33333333333));
+ expressions.put("multi", new ETP("wmean(double_d, float_f)", 2.470588235));
+
+ testExpressions(expressions);
}
@Test
- public void perc60Test() throws Exception {
- //Int 60
- Integer intResult = (Integer)getStatResult("p6r", "int_id", VAL_TYPE.INTEGER);
- Integer intTest = (Integer)calculateStat(intTestStart, "perc_60");
- assertEquals(getRawResponse(), intResult,intTest);
-
- //Long 60
- Long longResult = (Long)getStatResult("p6r", "long_ld", VAL_TYPE.LONG);
- Long longTest = (Long)calculateStat(longTestStart, "perc_60");
- assertEquals(getRawResponse(), longResult,longTest);
-
- //Float 60
- Float floatResult = (Float)getStatResult("p6r", "float_fd", VAL_TYPE.FLOAT);
- Float floatTest = (Float)calculateStat(floatTestStart, "perc_60");
- assertEquals(getRawResponse(), floatResult,floatTest);
-
- //Double 60
- Double doubleResult = (Double)getStatResult("p6r", "double_dd", VAL_TYPE.DOUBLE);
- Double doubleTest = (Double)calculateStat(doubleTestStart, "perc_60");
- assertEquals(getRawResponse(), doubleResult,doubleTest);
-
- //Date 60
- String dateResult = (String)getStatResult("p6r", "date_dtd", VAL_TYPE.DATE);
- String dateTest = (String)calculateStat(dateTestStart, "perc_60");
- assertEquals(getRawResponse(), dateResult,dateTest);
-
- //String 60
- String stringResult = (String)getStatResult("p6r", "string_sd", VAL_TYPE.STRING);
- String stringTest = (String)calculateStat(stringTestStart, "perc_60");
- assertEquals(getRawResponse(), stringResult,stringTest);
+ public void sumOfSquaresTest() throws Exception {
+ Map<String, ETP> expressions = new HashMap<>();
+ expressions.put("single", new ETP("sumofsquares(int_i)", 237.0));
+ expressions.put("multi", new ETP("sumofsquares(long_lm)", 1220.0));
+
+ testExpressions(expressions);
}
@Test
- public void minTest() throws Exception {
- //Int
- Integer intResult = ((Integer)getStatResult("mir", "int_id", VAL_TYPE.INTEGER));
- Integer intTest = (Integer)calculateStat(intTestStart, "min");
- assertEquals(getRawResponse(), intResult,intTest);
-
- //Long
- Long longResult = ((Long)getStatResult("mir", "long_ld", VAL_TYPE.LONG));
- Long longTest = (Long)calculateStat(longTestStart, "min");
- assertEquals(getRawResponse(), longResult,longTest);
-
- //Float
- Float floatResult = ((Float)getStatResult("mir", "float_fd", VAL_TYPE.FLOAT));
- Float floatTest = (Float)calculateStat(floatTestStart, "min");
- assertEquals(getRawResponse(), floatResult,floatTest);
-
- //Double
- Double doubleResult = (Double)getStatResult("mir", "double_dd", VAL_TYPE.DOUBLE);
- Double doubleTest = (Double)calculateStat(doubleTestStart, "min");
- assertEquals(getRawResponse(), doubleResult,doubleTest);
-
- //Date
- String dateResult = (String)getStatResult("mir", "date_dtd", VAL_TYPE.DATE);
- String dateTest = (String)calculateStat(dateTestStart, "min");
- assertEquals(getRawResponse(), dateResult,dateTest);
-
- //String
- String stringResult = (String)getStatResult("mir", "string_sd", VAL_TYPE.STRING);
- String stringTest = (String)calculateStat(stringTestStart, "min");
- assertEquals(getRawResponse(), stringResult,stringTest);
+ public void varianceTest() throws Exception {
+ Map<String, ETP> expressions = new HashMap<>();
+ expressions.put("single", new ETP("variance(int_i)", 2.6989619377162));
+ expressions.put("multi", new ETP("variance(long_lm)", 25.0));
+
+ testExpressions(expressions);
}
@Test
- public void maxTest() throws Exception {
- //Int
- Integer intResult = ((Integer)getStatResult("mar", "int_id", VAL_TYPE.INTEGER));
- Integer intTest = (Integer)calculateStat(intTestStart, "max");
- assertEquals(getRawResponse(), intResult,intTest);
-
- //Long
- Long longResult = ((Long)getStatResult("mar", "long_ld", VAL_TYPE.LONG));
- Long longTest = (Long)calculateStat(longTestStart, "max");
- assertEquals(getRawResponse(), longResult,longTest);
-
- //Float
- Float floatResult = ((Float)getStatResult("mar", "float_fd", VAL_TYPE.FLOAT));
- Float floatTest = (Float)calculateStat(floatTestStart, "max");
- assertEquals(getRawResponse(), floatResult,floatTest);
-
- //Double
- Double doubleResult = (Double)getStatResult("mar", "double_dd", VAL_TYPE.DOUBLE);
- Double doubleTest = (Double)calculateStat(doubleTestStart, "max");
- assertEquals(getRawResponse(), doubleResult,doubleTest);
-
- //Date
- String dateResult = (String)getStatResult("mar", "date_dtd", VAL_TYPE.DATE);
- String dateTest = (String)calculateStat(dateTestStart, "max");
- assertEquals(getRawResponse(), dateResult,dateTest);
-
- //String
- String stringResult = (String)getStatResult("mar", "string_sd", VAL_TYPE.STRING);
- String stringTest = (String)calculateStat(stringTestStart, "max");
- assertEquals(getRawResponse(), stringResult,stringTest);
+ public void standardDeviationTest() throws Exception {
+ Map<String, ETP> expressions = new HashMap<>();
+ expressions.put("single", new ETP("stddev(int_i)", 1.6428517698551));
+ expressions.put("multi", new ETP("stddev(long_lm)", 5.0));
+
+ testExpressions(expressions);
}
@Test
- public void uniqueTest() throws Exception {
- //Int
- Long intResult = (Long)getStatResult("ur", "int_id", VAL_TYPE.LONG);
- Long intTest = (Long)calculateStat(intTestStart, "unique");
- assertEquals(getRawResponse(), intResult,intTest);
-
- //Long
- Long longResult = (Long)getStatResult("ur", "long_ld", VAL_TYPE.LONG);
- Long longTest = (Long)calculateStat(longTestStart, "unique");
- assertEquals(getRawResponse(), longResult,longTest);
-
- //Float
- Long floatResult = (Long)getStatResult("ur", "float_fd", VAL_TYPE.LONG);
- Long floatTest = (Long)calculateStat(floatTestStart, "unique");
- assertEquals(getRawResponse(), floatResult,floatTest);
-
- //Double
- Long doubleResult = (Long)getStatResult("ur", "double_dd", VAL_TYPE.LONG);
- Long doubleTest = (Long)calculateStat(doubleTestStart, "unique");
- assertEquals(getRawResponse(), doubleResult,doubleTest);
-
- //Date
- Long dateResult = (Long)getStatResult("ur", "date_dtd", VAL_TYPE.LONG);
- Long dateTest = (Long)calculateStat(dateTestStart, "unique");
- assertEquals(getRawResponse(), dateResult,dateTest);
-
- //String
- Long stringResult = (Long)getStatResult("ur", "string_sd", VAL_TYPE.LONG);
- Long stringTest = (Long)calculateStat(stringTestStart, "unique");
- assertEquals(getRawResponse(), stringResult,stringTest);
+ public void medianTest() throws Exception {
+ Map<String, ETP> expressions = new HashMap<>();
+ expressions.put("int", new ETP("median(int_i)", 3.0));
+ expressions.put("longs", new ETP("median(long_lm)", 6.0));
+ expressions.put("float", new ETP("median(float_f)", 3.0));
+ expressions.put("doubles", new ETP("median(double_dm)", 7.5));
+ expressions.put("dates", new ETP("median(date_dt)", "1801-12-31T23:59:59Z"));
+
+ testExpressions(expressions);
}
@Test
- public void countTest() throws Exception {
- //Int
- Long intResult = (Long)getStatResult("cr", "int_id", VAL_TYPE.LONG);
- Long intTest = (Long)calculateStat(intTestStart, "count");
- assertEquals(getRawResponse(), intResult,intTest);
-
- //Long
- Long longResult = (Long)getStatResult("cr", "long_ld", VAL_TYPE.LONG);
- Long longTest = (Long)calculateStat(longTestStart, "count");
- assertEquals(getRawResponse(), longResult,longTest);
-
- //Float
- Long floatResult = (Long)getStatResult("cr", "float_fd", VAL_TYPE.LONG);
- Long floatTest = (Long)calculateStat(floatTestStart, "count");
- assertEquals(getRawResponse(), floatResult,floatTest);
-
- //Double
- Long doubleResult = (Long)getStatResult("cr", "double_dd", VAL_TYPE.LONG);
- Long doubleTest = (Long)calculateStat(doubleTestStart, "count");
- assertEquals(getRawResponse(), doubleResult,doubleTest);
-
- //Date
- Long dateResult = (Long)getStatResult("cr", "date_dtd", VAL_TYPE.LONG);
- Long dateTest = (Long)calculateStat(dateTestStart, "count");
- assertEquals(getRawResponse(), dateResult,dateTest);
-
- //String
- Long stringResult = (Long)getStatResult("cr", "string_sd", VAL_TYPE.LONG);
- Long stringTest = (Long)calculateStat(stringTestStart, "count");
- assertEquals(getRawResponse(), stringResult,stringTest);
- }
-
+ public void percentileTest() throws Exception {
+ Map<String, ETP> expressions = new HashMap<>();
+ expressions.put("int", new ETP("percentile(20,int_i)", 2));
+ expressions.put("longs", new ETP("percentile(80,long_lm)", 11L));
+ expressions.put("float", new ETP("percentile(40,float_f)", 2.0F));
+ expressions.put("doubles", new ETP("percentile(50,double_dm)", 11.0));
+ expressions.put("dates", new ETP("percentile(0,date_dt)", "1801-12-31T23:59:59Z"));
+ expressions.put("strings", new ETP("percentile(99.99,string_sm)", "str3_second"));
+
+ testExpressions(expressions);
+ }
+
@Test
- public void missingDefaultTest() throws Exception {
- //Int
- long intResult = (Long)getStatResult("misr", "int_id", VAL_TYPE.LONG);
- assertEquals(getRawResponse(), intMissing,intResult);
-
- //Long
- long longResult = (Long)getStatResult("misr", "long_ld", VAL_TYPE.LONG);
- assertEquals(getRawResponse(), longMissing,longResult);
-
- //Float
- long floatResult = (Long)getStatResult("misr", "float_fd", VAL_TYPE.LONG);
- assertEquals(getRawResponse(), floatMissing,floatResult);
-
- //Double
- long doubleResult = (Long)getStatResult("misr", "double_dd", VAL_TYPE.LONG);
- assertEquals(getRawResponse(), doubleMissing,doubleResult);
-
- //Date
- long dateResult = (Long)getStatResult("misr", "date_dtd", VAL_TYPE.LONG);
- assertEquals(getRawResponse(), dateMissing,dateResult);
-
- //String
- long stringResult = (Long)getStatResult("misr", "string_sd", VAL_TYPE.LONG);
- assertEquals(getRawResponse(), stringMissing, stringResult);
+ public void ordinalTest() throws Exception {
+ Map<String, ETP> expressions = new HashMap<>();
+ expressions.put("int", new ETP("ordinal(15,int_i)", 5));
+ expressions.put("longs", new ETP("ordinal(11,long_lm)", 11L));
+ expressions.put("float", new ETP("ordinal(-5,float_f)", 4.0F));
+ expressions.put("doubles", new ETP("ordinal(1,double_dm)", 1.0));
+ expressions.put("dates", new ETP("ordinal(-1,date_dt)", "1802-12-31T23:59:59Z"));
+ expressions.put("strings", new ETP("ordinal(6,string_sm)", "str1_second"));
+
+ testExpressions(expressions);
}
-
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/OverallAnalyticsTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/OverallAnalyticsTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/OverallAnalyticsTest.java
new file mode 100644
index 0000000..de6d6d2
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/OverallAnalyticsTest.java
@@ -0,0 +1,320 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.solr.analytics.facet.SolrAnalyticsFacetTestCase;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class OverallAnalyticsTest extends SolrAnalyticsFacetTestCase {
+
+ @BeforeClass
+ public static void populate() throws Exception {
+ for (int j = 0; j < NUM_LOOPS; ++j) {
+ int i = j%INT;
+ long l = j%LONG;
+ float f = j%FLOAT;
+ double d = j%DOUBLE;
+ String dt = (1800+j%DATE) + "-12-31T23:59:59Z";
+ String dtm = (1800+j%DATE + 10) + "-12-31T23:59:59Z";
+ String s = "str" + (j%STRING);
+ List<String> fields = new ArrayList<>();
+ fields.add("id"); fields.add("1000"+j);
+
+ if ( i != 0 ) {
+ fields.add("int_i"); fields.add("" + i);
+ fields.add("int_im"); fields.add("" + i);
+ fields.add("int_im"); fields.add("" + (i+10));
+ }
+
+ if ( l != 0l ) {
+ fields.add("long_l"); fields.add("" + l);
+ fields.add("long_lm"); fields.add("" + l);
+ fields.add("long_lm"); fields.add("" + (l+10));
+ }
+
+ if ( f != 0.0f ) {
+ fields.add("float_f"); fields.add("" + f);
+ fields.add("float_fm"); fields.add("" + f);
+ fields.add("float_fm"); fields.add("" + (f+10));
+ }
+
+ if ( d != 0.0d ) {
+ fields.add("double_d"); fields.add("" + d);
+ fields.add("double_dm"); fields.add("" + d);
+ fields.add("double_dm"); fields.add("" + (d+10));
+ }
+
+ if ( (j%DATE) != 0 ) {
+ fields.add("date_dt"); fields.add(dt);
+ fields.add("date_dtm"); fields.add(dt);
+ fields.add("date_dtm"); fields.add(dtm);
+ }
+
+ if ( (j%STRING) != 0 ) {
+ fields.add("string_s"); fields.add(s);
+ fields.add("string_sm"); fields.add(s);
+ fields.add("string_sm"); fields.add(s + "_second");
+ }
+
+ addDoc(fields);
+ }
+ commitDocs();
+ }
+
+ static public final int INT = 7;
+ static public final int LONG = 2;
+ static public final int FLOAT = 6;
+ static public final int DOUBLE = 5;
+ static public final int DATE = 3;
+ static public final int STRING = 4;
+ static public final int NUM_LOOPS = 20;
+
+ @Test
+ public void pivotFacetTest() throws Exception {
+ String analyticsRequest = "{"
+ + "\n 'expressions' : { "
+ + "\n 'floor_mean_add' : 'floor(mean(add(int_i,long_lm)))', "
+ + "\n 'consts' : 'max(mod(\\'_\\', string_s, 1800-01-01T11:59:59Z))' "
+ + "\n }, "
+ + "\n 'functions' : { "
+ + "\n 'mod(a,b..)' : 'concat_sep(a, b:concat(_,\\'-con\\'))', "
+ + "\n 'rep_0(num)' : 'fill_missing(num,0)' "
+ + "\n }, "
+ + "\n 'groupings': { "
+ + "\n 'grouping0' : { "
+ + "\n 'expressions' : { "
+ + "\n 'mean' : 'mean(float_f)', "
+ + "\n 'count2' : 'count(string_sm)' "
+ + "\n }, "
+ + "\n 'facets' : { "
+ + "\n 'ranges' : { "
+ + "\n 'type' : 'range', "
+ + "\n 'field': 'int_im', "
+ + "\n 'start': '2', "
+ + "\n 'end' : '13', "
+ + "\n 'gaps' : ['2', '5', '3'], "
+ + "\n 'hardend' : false "
+ + "\n } "
+ + "\n } "
+ + "\n }, "
+ + "\n 'grouping1' : { "
+ + "\n 'expressions' : { "
+ + "\n 'mean' : 'mean(rep_0(int_i))', "
+ + "\n 'count' : 'count(long_lm)' "
+ + "\n }, "
+ + "\n 'facets' : { "
+ + "\n 'queries' : { "
+ + "\n 'type' : 'query', "
+ + "\n 'queries' : { "
+ + "\n 'float < 3' : 'float_f:[* TO 3]', "
+ + "\n 'string = 1, date = 2' : 'string_s:\"str1\" AND date_dt:\"1802-12-31T23:59:59Z\"' "
+ + "\n } "
+ + "\n }, "
+ + "\n 'pivoting' : { "
+ + "\n 'type' : 'pivot', "
+ + "\n 'pivots' : [ "
+ + "\n { "
+ + "\n 'name' : 'strings', "
+ + "\n 'expression' : 'string_sm', "
+ + "\n 'sort' : { "
+ + "\n 'criteria' : [ "
+ + "\n { "
+ + "\n 'type' : 'expression', "
+ + "\n 'expression' : 'mean', "
+ + "\n 'direction' : 'ascending' "
+ + "\n }, "
+ + "\n { "
+ + "\n 'type' : 'facetvalue', "
+ + "\n 'direction' : 'descending' "
+ + "\n } "
+ + "\n ], "
+ + "\n 'limit' : 3, "
+ + "\n 'offset' : 1 "
+ + "\n } "
+ + "\n }, "
+ + "\n { "
+ + "\n 'name' : 'date', "
+ + "\n 'expression' : 'fill_missing(date_dt, \\'No Date\\')', "
+ + "\n 'sort' : { "
+ + "\n 'criteria' : [ "
+ + "\n { "
+ + "\n 'type' : 'expression', "
+ + "\n 'expression' : 'count', "
+ + "\n 'direction' : 'ascending' "
+ + "\n }, "
+ + "\n { "
+ + "\n 'type' : 'expression', "
+ + "\n 'expression' : 'mean', "
+ + "\n 'direction' : 'ascending' "
+ + "\n } "
+ + "\n ], "
+ + "\n 'limit' : 2 "
+ + "\n } "
+ + "\n } "
+ + "\n ] "
+ + "\n } "
+ + "\n } "
+ + "\n } "
+ + "\n } "
+ + "\n} ";
+
+ String test = "== {"
+ + "\n 'results' : { "
+ + "\n 'floor_mean_add' : 9, "
+ + "\n 'consts' : 'str3-con_1800-01-01T11:59:59Z-con' "
+ + "\n }, "
+ + "\n 'groupings' : { "
+ + "\n 'grouping0' : { "
+ + "\n 'ranges' : [ "
+ + "\n { "
+ + "\n 'value' : '[2 TO 4)', "
+ + "\n 'results' : { "
+ + "\n 'mean' : 3.5, "
+ + "\n 'count2' : 10 "
+ + "\n } "
+ + "\n }, "
+ + "\n { "
+ + "\n 'value' : '[4 TO 9)', "
+ + "\n 'results' : { "
+ + "\n 'mean' : 3.2, "
+ + "\n 'count2' : 12 "
+ + "\n } "
+ + "\n }, "
+ + "\n { "
+ + "\n 'value' : '[9 TO 12)', "
+ + "\n 'results' : { "
+ + "\n 'mean' : 2.0, "
+ + "\n 'count2' : 4 "
+ + "\n } "
+ + "\n }, "
+ + "\n { "
+ + "\n 'value' : '[12 TO 15)', "
+ + "\n 'results' : { "
+ + "\n 'mean' : 3.75, "
+ + "\n 'count2' : 14 "
+ + "\n } "
+ + "\n } "
+ + "\n ] "
+ + "\n }, "
+ + "\n 'grouping1': { "
+ + "\n 'queries' : [ "
+ + "\n { "
+ + "\n 'value' : 'float < 3', "
+ + "\n 'results' : { "
+ + "\n 'mean' : 2.1, "
+ + "\n 'count' : 14 "
+ + "\n } "
+ + "\n }, "
+ + "\n { "
+ + "\n 'value' : 'string = 1, date = 2', "
+ + "\n 'results' : { "
+ + "\n 'mean' : 4.0, "
+ + "\n 'count' : 4 "
+ + "\n } "
+ + "\n } "
+ + "\n ], "
+ + "\n 'pivoting':["
+ + "\n { "
+ + "\n 'pivot' : 'strings', "
+ + "\n 'value' : 'str3', "
+ + "\n 'results' : { "
+ + "\n 'mean' : 2.6, "
+ + "\n 'count' : 10 "
+ + "\n }, "
+ + "\n 'children' : [ "
+ + "\n { "
+ + "\n 'pivot' : 'date', "
+ + "\n 'value' : '1802-12-31T23:59:59Z', "
+ + "\n 'results' : { "
+ + "\n 'mean' : 4.0, "
+ + "\n 'count' : 2 "
+ + "\n } "
+ + "\n }, "
+ + "\n { "
+ + "\n 'pivot' : 'date', "
+ + "\n 'value' : 'No Date', "
+ + "\n 'results' : { "
+ + "\n 'mean' : 2.0, "
+ + "\n 'count' : 4 "
+ + "\n } "
+ + "\n } "
+ + "\n ]"
+ + "\n }, "
+ + "\n { "
+ + "\n 'pivot' : 'strings', "
+ + "\n 'value' : 'str2_second', "
+ + "\n 'results' : { "
+ + "\n 'mean' : 3.0, "
+ + "\n 'count' : 0 "
+ + "\n }, "
+ + "\n 'children' : [ "
+ + "\n { "
+ + "\n 'pivot' : 'date', "
+ + "\n 'value' : '1802-12-31T23:59:59Z', "
+ + "\n 'results' : { "
+ + "\n 'mean' : 1.0, "
+ + "\n 'count' : 0 "
+ + "\n } "
+ + "\n }, "
+ + "\n { "
+ + "\n 'pivot' : 'date', "
+ + "\n 'value' : '1801-12-31T23:59:59Z', "
+ + "\n 'results' : { "
+ + "\n 'mean' : 3.0, "
+ + "\n 'count' : 0 "
+ + "\n } "
+ + "\n } "
+ + "\n ]"
+ + "\n }, "
+ + "\n { "
+ + "\n 'pivot' : 'strings', "
+ + "\n 'value' : 'str2', "
+ + "\n 'results' : { "
+ + "\n 'mean' : 3.0, "
+ + "\n 'count' : 0 "
+ + "\n }, "
+ + "\n 'children' : [ "
+ + "\n { "
+ + "\n 'pivot' : 'date', "
+ + "\n 'value' : '1802-12-31T23:59:59Z', "
+ + "\n 'results' : { "
+ + "\n 'mean' : 1.0, "
+ + "\n 'count' : 0 "
+ + "\n } "
+ + "\n }, "
+ + "\n { "
+ + "\n 'pivot' : 'date', "
+ + "\n 'value' : '1801-12-31T23:59:59Z', "
+ + "\n 'results' : { "
+ + "\n 'mean' : 3.0, "
+ + "\n 'count' : 0 "
+ + "\n } "
+ + "\n } "
+ + "\n ]"
+ + "\n } "
+ + "\n ]"
+ + "\n }"
+ + "\n }"
+ + "\n}";
+
+ testAnalytics(analyticsRequest, test);
+ }
+}