This is an automated email from the ASF dual-hosted git repository.
abhishek pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/druid.git
The following commit(s) were added to refs/heads/master by this push:
new 2938b8de53f fix issue with NestedPathArrayElement not correctly
handling negative index for Object[] like it has for List (#15650)
2938b8de53f is described below
commit 2938b8de53f5a39be7697734afcfffbe1be18300
Author: Clint Wylie <[email protected]>
AuthorDate: Tue Jan 9 20:16:08 2024 -0800
fix issue with NestedPathArrayElement not correctly handling negative index
for Object[] like it has for List (#15650)
---
.../druid/segment/nested/NestedPathArrayElement.java | 12 +++++++++---
.../druid/segment/nested/NestedPathFinderTest.java | 16 +++++++++++++++-
2 files changed, 24 insertions(+), 4 deletions(-)
diff --git
a/processing/src/main/java/org/apache/druid/segment/nested/NestedPathArrayElement.java
b/processing/src/main/java/org/apache/druid/segment/nested/NestedPathArrayElement.java
index 5bba77fbc97..7f1bd38b466 100644
---
a/processing/src/main/java/org/apache/druid/segment/nested/NestedPathArrayElement.java
+++
b/processing/src/main/java/org/apache/druid/segment/nested/NestedPathArrayElement.java
@@ -46,15 +46,21 @@ public class NestedPathArrayElement implements
NestedPathPart
List<?> currentList = (List<?>) input;
final int currentSize = currentList.size();
if (index < 0) {
- if (currentSize + index >= 0) {
- return currentList.get(currentSize + index);
+ final int adjusted = currentSize + index;
+ if (adjusted >= 0) {
+ return currentList.get(adjusted);
}
} else if (currentList.size() > index) {
return currentList.get(index);
}
} else if (input instanceof Object[]) {
Object[] currentList = (Object[]) input;
- if (currentList.length > index) {
+ if (index < 0) {
+ final int adjusted = currentList.length + index;
+ if (adjusted >= 0) {
+ return currentList[adjusted];
+ }
+ } else if (currentList.length > index) {
return currentList[index];
}
}
diff --git
a/processing/src/test/java/org/apache/druid/segment/nested/NestedPathFinderTest.java
b/processing/src/test/java/org/apache/druid/segment/nested/NestedPathFinderTest.java
index 5f0a328f687..40e6f494be7 100644
---
a/processing/src/test/java/org/apache/druid/segment/nested/NestedPathFinderTest.java
+++
b/processing/src/test/java/org/apache/druid/segment/nested/NestedPathFinderTest.java
@@ -36,7 +36,8 @@ public class NestedPathFinderTest
"y", ImmutableMap.of("a", "hello", "b", "world"),
"z", "foo",
"[sneaky]", "bar",
- "[also_sneaky]", ImmutableList.of(ImmutableMap.of("a", "x"),
ImmutableMap.of("b", "y", "c", "z"))
+ "[also_sneaky]", ImmutableList.of(ImmutableMap.of("a", "x"),
ImmutableMap.of("b", "y", "c", "z")),
+ "objarray", new Object[]{"a", "b", "c"}
);
@Test
@@ -436,6 +437,19 @@ public class NestedPathFinderTest
pathParts = NestedPathFinder.parseJqPath(".x[-4]");
Assert.assertNull(NestedPathFinder.find(NESTER, pathParts));
+ // object array
+ pathParts = NestedPathFinder.parseJqPath(".objarray[1]");
+ Assert.assertEquals("b", NestedPathFinder.find(NESTER, pathParts));
+
+ pathParts = NestedPathFinder.parseJqPath(".objarray[-1]");
+ Assert.assertEquals("c", NestedPathFinder.find(NESTER, pathParts));
+
+ pathParts = NestedPathFinder.parseJqPath(".objarray[-2]");
+ Assert.assertEquals("b", NestedPathFinder.find(NESTER, pathParts));
+
+ pathParts = NestedPathFinder.parseJqPath(".objarray[-4]");
+ Assert.assertNull(NestedPathFinder.find(NESTER, pathParts));
+
// nonexistent
pathParts = NestedPathFinder.parseJqPath(".x[1].y.z");
Assert.assertNull(NestedPathFinder.find(NESTER, pathParts));
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]