somu-imply commented on code in PR #12493: URL: https://github.com/apache/druid/pull/12493#discussion_r867523539
########## processing/src/main/java/org/apache/druid/query/aggregation/last/StringLastVectorAggregator.java: ########## @@ -0,0 +1,176 @@ +/* + * 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.druid.query.aggregation.last; + +import org.apache.druid.java.util.common.DateTimes; +import org.apache.druid.query.aggregation.SerializablePairLongString; +import org.apache.druid.query.aggregation.VectorAggregator; +import org.apache.druid.query.aggregation.first.StringFirstLastUtils; +import org.apache.druid.segment.DimensionHandlerUtils; +import org.apache.druid.segment.vector.BaseLongVectorValueSelector; +import org.apache.druid.segment.vector.VectorObjectSelector; + +import javax.annotation.Nullable; +import java.nio.ByteBuffer; + +public class StringLastVectorAggregator implements VectorAggregator +{ + private static final SerializablePairLongString INIT = new SerializablePairLongString( + DateTimes.MIN.getMillis(), + null + ); + private final BaseLongVectorValueSelector timeSelector; + private final VectorObjectSelector valueSelector; + private final int maxStringBytes; + protected long lastTime; + protected String lastValue; + + public StringLastVectorAggregator( + final BaseLongVectorValueSelector timeSelector, + final VectorObjectSelector valueSelector, + final int maxStringBytes + ) + { + this.timeSelector = timeSelector; + this.valueSelector = valueSelector; + this.maxStringBytes = maxStringBytes; + } + + @Override + public void init(ByteBuffer buf, int position) + { + StringFirstLastUtils.writePair(buf, position, INIT, maxStringBytes); + } + + @Override + public void aggregate(ByteBuffer buf, int position, int startRow, int endRow) + { + if (timeSelector == null) { + return; + } + long[] times = timeSelector.getLongVector(); + Object[] objectsWhichMightBeStrings = valueSelector.getObjectVector(); + + lastTime = buf.getLong(position); + int index = endRow - 1; + for (int i = endRow - 1; i >= startRow; i--) { + if (objectsWhichMightBeStrings[i] != null) { + index = i; + break; + } + } + final boolean foldNeeded = StringFirstLastUtils.objectNeedsFoldCheck(objectsWhichMightBeStrings[index]); + if (foldNeeded) { Review Comment: I chose to keep it similar as to the normal aggregator for the same flow which is `Check if the selector class could possibly be a SerializablePairLongString (either a superclass or subclass).` -- 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]
