github-code-scanning[bot] commented on code in PR #14462:
URL: https://github.com/apache/druid/pull/14462#discussion_r1356140288
##########
processing/src/main/java/org/apache/druid/query/aggregation/first/NumericFirstVectorAggregator.java:
##########
@@ -110,20 +135,45 @@
int positionOffset
)
{
- boolean[] nulls = useDefault ? null : valueSelector.getNullVector();
- long[] timeVector = timeSelector.getLongVector();
+ final long[] timeVector = timeSelector.getLongVector();
+ final Object[] objectsWhichMightBeNumeric =
valueSelector.getObjectVector();
+ final boolean[] nullValueVector =
FirstLastUtils.getNullVector(objectsWhichMightBeNumeric);
+ boolean[] nulls = useDefault ? null : nullValueVector;
+
+ // iterate once over the object vector to find first non null element and
+ // determine if the type is Pair or not
+ boolean foldNeeded = false;
+ for (Object obj : objectsWhichMightBeNumeric) {
+ if (obj != null) {
+ foldNeeded = FirstLastUtils.objectNeedsFoldCheck(obj, pairClass);
+ break;
+ }
+ }
for (int i = 0; i < numRows; i++) {
int position = positions[i] + positionOffset;
int row = rows == null ? i : rows[i];
- long firstTime = buf.getLong(position);
- if (timeVector[row] < firstTime) {
- if (useDefault || nulls == null || !nulls[row]) {
- updateTimeWithValue(buf, position, timeVector[row], row);
+ firstTime = buf.getLong(position);
+
+ if (foldNeeded) {
+ final SerializablePair<Long, Number> inPair = (SerializablePair<Long,
Number>) objectsWhichMightBeNumeric[row];
+ if (useDefault || inPair != null) {
+ if (inPair.lhs < firstTime) {
+ updateTimeWithValue(buf, position, inPair.lhs, inPair.rhs);
+ }
} else {
- updateTimeWithNull(buf, position, timeVector[row]);
+ updateTimeWithNull(buf, position, inPair.lhs);
Review Comment:
## Dereferenced variable is always null
Variable [inPair](1) is always null at this dereference.
[Show more
details](https://github.com/apache/druid/security/code-scanning/5888)
##########
processing/src/main/java/org/apache/druid/query/aggregation/first/NumericFirstVectorAggregator.java:
##########
@@ -110,20 +135,45 @@
int positionOffset
)
{
- boolean[] nulls = useDefault ? null : valueSelector.getNullVector();
- long[] timeVector = timeSelector.getLongVector();
+ final long[] timeVector = timeSelector.getLongVector();
+ final Object[] objectsWhichMightBeNumeric =
valueSelector.getObjectVector();
+ final boolean[] nullValueVector =
FirstLastUtils.getNullVector(objectsWhichMightBeNumeric);
+ boolean[] nulls = useDefault ? null : nullValueVector;
+
+ // iterate once over the object vector to find first non null element and
+ // determine if the type is Pair or not
+ boolean foldNeeded = false;
+ for (Object obj : objectsWhichMightBeNumeric) {
+ if (obj != null) {
+ foldNeeded = FirstLastUtils.objectNeedsFoldCheck(obj, pairClass);
+ break;
+ }
+ }
for (int i = 0; i < numRows; i++) {
int position = positions[i] + positionOffset;
int row = rows == null ? i : rows[i];
- long firstTime = buf.getLong(position);
- if (timeVector[row] < firstTime) {
- if (useDefault || nulls == null || !nulls[row]) {
- updateTimeWithValue(buf, position, timeVector[row], row);
+ firstTime = buf.getLong(position);
+
+ if (foldNeeded) {
+ final SerializablePair<Long, Number> inPair = (SerializablePair<Long,
Number>) objectsWhichMightBeNumeric[row];
+ if (useDefault || inPair != null) {
+ if (inPair.lhs < firstTime) {
Review Comment:
## Dereferenced variable may be null
Variable [inPair](1) may be null at this access as suggested by [this](2)
null guard.
[Show more
details](https://github.com/apache/druid/security/code-scanning/5889)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]