You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by ja...@apache.org on 2017/10/10 21:00:26 UTC
[geode] branch develop updated: GEODE-3714: Removed repetitive
looping code when evaluating
This is an automated email from the ASF dual-hosted git repository.
jasonhuynh pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git
The following commit(s) were added to refs/heads/develop by this push:
new 991b5c2 GEODE-3714: Removed repetitive looping code when evaluating
991b5c2 is described below
commit 991b5c2b5f06803fa87d16a4d26a0603737ef77a
Author: Jason Huynh <hu...@gmail.com>
AuthorDate: Wed Sep 27 15:27:55 2017 -0700
GEODE-3714: Removed repetitive looping code when evaluating
---
.../geode/cache/query/internal/CompiledIn.java | 65 ++-------------------
.../cache/query/internal/CompiledInJUnitTest.java | 68 +++++++++++++++++++++-
2 files changed, 73 insertions(+), 60 deletions(-)
diff --git a/geode-core/src/main/java/org/apache/geode/cache/query/internal/CompiledIn.java b/geode-core/src/main/java/org/apache/geode/cache/query/internal/CompiledIn.java
index 2532f19..2a6566d 100644
--- a/geode-core/src/main/java/org/apache/geode/cache/query/internal/CompiledIn.java
+++ b/geode-core/src/main/java/org/apache/geode/cache/query/internal/CompiledIn.java
@@ -410,7 +410,7 @@ public class CompiledIn extends AbstractCompiledValue implements Indexable {
*
* Invariant: the receiver is dependent on the current iterator.
*/
- private SelectResults singleBaseCollectionFilterEvaluate(ExecutionContext context,
+ SelectResults singleBaseCollectionFilterEvaluate(ExecutionContext context,
SelectResults intermediateResults, boolean completeExpansionNeeded,
CompiledValue iterOperands, IndexInfo indexInfo, RuntimeIterator[] indpndntItr,
boolean isIntersection, boolean conditioningNeeded, boolean evalProj)
@@ -562,69 +562,16 @@ public class CompiledIn extends AbstractCompiledValue implements Indexable {
}
}
} else {
+
if (!evalColln.getClass().isArray()) {
throw new TypeMismatchException("Operand of IN cannot be interpreted as a Collection. "
+ "Is instance of " + evalColln.getClass().getName());
}
- if (evalColln instanceof Object[]) {
- Object[] arr = (Object[]) evalColln;
- for (int i = 0; i < arr.length; ++i) {
- this.queryIndex(arr[i], indexInfo, results, iterOperands, indpndntItr, context,
- projAttrib, conditioningNeeded);
- }
-
- } else if (evalColln instanceof long[]) {
- long[] a = (long[]) evalColln;
- for (int i = 0; i < a.length; i++) {
- this.queryIndex(a[i], indexInfo, results, iterOperands, indpndntItr, context,
- projAttrib, conditioningNeeded);
- }
-
- } else if (evalColln instanceof double[]) {
- double[] a = (double[]) evalColln;
- for (int i = 0; i < a.length; i++) {
- this.queryIndex(a[i], indexInfo, results, iterOperands, indpndntItr, context,
- projAttrib, conditioningNeeded);
- }
-
- } else if (evalColln instanceof float[]) {
- float[] a = (float[]) evalColln;
- for (int i = 0; i < a.length; i++) {
- this.queryIndex(a[i], indexInfo, results, iterOperands, indpndntItr, context,
- projAttrib, conditioningNeeded);
- }
- } else if (evalColln instanceof int[]) {
- int[] a = (int[]) evalColln;
- for (int i = 0; i < a.length; i++) {
- this.queryIndex(a[i], indexInfo, results, iterOperands, indpndntItr, context,
- projAttrib, conditioningNeeded);
- }
- } else if (evalColln instanceof short[]) {
- short[] a = (short[]) evalColln;
- for (int i = 0; i < a.length; i++) {
- this.queryIndex(a[i], indexInfo, results, iterOperands, indpndntItr, context,
- projAttrib, conditioningNeeded);
- }
-
- } else if (evalColln instanceof char[]) {
- char[] a = (char[]) evalColln;
- for (int i = 0; i < a.length; i++) {
- this.queryIndex(a[i], indexInfo, results, iterOperands, indpndntItr, context,
- projAttrib, conditioningNeeded);
- }
-
- } else if (evalColln instanceof byte[]) {
- byte[] a = (byte[]) evalColln;
- for (int i = 0; i < a.length; i++) {
- this.queryIndex(a[i], indexInfo, results, iterOperands, indpndntItr, context,
- projAttrib, conditioningNeeded);
- }
-
- } else {
- throw new TypeMismatchException(
- "Operand of IN cannot be interpreted as a Comparable Object. Operand is of type ="
- + evalColln.getClass());
+ int evalCollnLength = Array.getLength(evalColln);
+ for (int i = 0; i < evalCollnLength; ++i) {
+ this.queryIndex(Array.get(evalColln, i), indexInfo, results, iterOperands, indpndntItr,
+ context, projAttrib, conditioningNeeded);
}
}
diff --git a/geode-core/src/test/java/org/apache/geode/cache/query/internal/CompiledInJUnitTest.java b/geode-core/src/test/java/org/apache/geode/cache/query/internal/CompiledInJUnitTest.java
index 3d31877..a622964 100644
--- a/geode-core/src/test/java/org/apache/geode/cache/query/internal/CompiledInJUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/cache/query/internal/CompiledInJUnitTest.java
@@ -26,6 +26,7 @@ import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.apache.geode.cache.query.TypeMismatchException;
+import org.apache.geode.cache.query.internal.index.IndexProtocol;
import org.apache.geode.pdx.internal.EnumInfo;
import org.apache.geode.pdx.internal.EnumInfo.PdxInstanceEnumInfo;
import org.apache.geode.test.junit.categories.UnitTest;
@@ -442,12 +443,77 @@ public class CompiledInJUnitTest {
@Test
public void testCompiledInCanEvaluate() throws Exception {
when(colln.evaluate(isA(ExecutionContext.class))).thenReturn(new ArrayList());
-
CompiledIn compiledIn = new CompiledIn(elm, colln);
Object result = compiledIn.evaluate(context);
assertNotNull(result);
}
+ @Test
+ public void whenPassingIntegerArrayToSingleCollectionFilterEvaluateDoesNotThrowTypeMismatchException()
+ throws Exception {
+ int[] intCollection = new int[] {1, 2};
+ when(colln.evaluate(any())).thenReturn(intCollection);
+ callSingleCollectionFilterEvaluateBehavior(intCollection);
+ }
+
+ @Test
+ public void whenPassingLongArrayToSingleCollectionFilterEvaluateDoesNotThrowTypeMismatchException()
+ throws Exception {
+ long[] longCollection = new long[] {1, 2};
+ callSingleCollectionFilterEvaluateBehavior(longCollection);
+ }
+
+ @Test
+ public void whenPassingDoubleArrayToSingleCollectionFilterEvaluateDoesNotThrowTypeMismatchException()
+ throws Exception {
+ double[] doubleCollection = new double[] {1, 2};
+ callSingleCollectionFilterEvaluateBehavior(doubleCollection);
+ }
+
+ @Test
+ public void whenPassingCharArrayToSingleCollectionFilterEvaluateDoesNotThrowTypeMismatchException()
+ throws Exception {
+ char[] charCollection = new char[] {1, 2};
+ callSingleCollectionFilterEvaluateBehavior(charCollection);
+ }
+
+ @Test
+ public void whenPassingFloatArrayToSingleCollectionFilterEvaluateDoesNotThrowTypeMismatchException()
+ throws Exception {
+ float[] floatCollection = new float[] {1, 2};
+ callSingleCollectionFilterEvaluateBehavior(floatCollection);
+ }
+
+ @Test
+ public void whenPassingShortArrayToSingleCollectionFilterEvaluateDoesNotThrowTypeMismatchException()
+ throws Exception {
+ short[] shortCollection = new short[] {1, 2};
+ callSingleCollectionFilterEvaluateBehavior(shortCollection);
+ }
+
+ @Test
+ public void whenPassingByteArrayToSingleCollectionFilterEvaluateDoesNotThrowTypeMismatchException()
+ throws Exception {
+ byte[] byteCollection = new byte[] {1, 2};
+ callSingleCollectionFilterEvaluateBehavior(byteCollection);
+ }
+
+ @Test
+ public void whenPassingObjectArrayToSingleCollectionFilterEvaluateDoesNotThrowTypeMismatchException()
+ throws Exception {
+ Object[] objectCollection = new Object[] {1, 2};
+ callSingleCollectionFilterEvaluateBehavior(objectCollection);
+ }
+
+ public void callSingleCollectionFilterEvaluateBehavior(Object collection) throws Exception {
+ CompiledIn compiledIn = new CompiledIn(elm, colln);
+ when(colln.evaluate(any())).thenReturn(collection);
+ IndexInfo indexInfo =
+ new IndexInfo(null, null, mock(IndexProtocol.class), 1, new int[] {1}, 90);
+ compiledIn.singleBaseCollectionFilterEvaluate(context, new ResultsSet(), false, null, indexInfo,
+ null, false, false, false);
+ }
+
private PdxInstanceEnumInfo createPdxInstanceEnumInfo(Enum<?> e, int enumId) {
EnumInfo ei = new EnumInfo(e);
return (PdxInstanceEnumInfo) ei.getPdxInstance(enumId);
--
To stop receiving notification emails like this one, please contact
['"commits@geode.apache.org" <co...@geode.apache.org>'].