rash67 commented on code in PR #12879: URL: https://github.com/apache/druid/pull/12879#discussion_r957607116
########## processing/src/main/java/org/apache/druid/query/aggregation/SerializablePairLongStringBufferStore.java: ########## @@ -0,0 +1,174 @@ +/* + * 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; + +import org.apache.druid.java.util.common.io.smoosh.FileSmoosher; +import org.apache.druid.segment.serde.Serializer; +import org.apache.druid.segment.serde.cell.CellWriter; +import org.apache.druid.segment.serde.cell.DeserializingIOIterator; +import org.apache.druid.segment.serde.cell.IOIterator; +import org.apache.druid.segment.serde.cell.IntSerializer; +import org.apache.druid.segment.serde.cell.NativeClearedByteBufferProvider; +import org.apache.druid.segment.writeout.SegmentWriteOutMedium; +import org.apache.druid.segment.writeout.WriteOutBytes; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import java.io.IOException; +import java.nio.channels.WritableByteChannel; + +public class SerializablePairLongStringBufferStore +{ + private static final SerializablePairLongStringSimpleStagedSerde SERDE = + new SerializablePairLongStringSimpleStagedSerde(); + + private final WriteOutBytes writeOutBytes; + private final IntSerializer intSerializer = new IntSerializer(); + + private long minValue = Long.MAX_VALUE; + private long maxValue = Long.MIN_VALUE; + + public SerializablePairLongStringBufferStore(WriteOutBytes writeOutBytes) + { + this.writeOutBytes = writeOutBytes; + } + + public void store(@Nullable SerializablePairLongString pairLongString) throws IOException + { + if (pairLongString != null && pairLongString.lhs != null) { + minValue = Math.min(minValue, pairLongString.lhs); + maxValue = Math.max(maxValue, pairLongString.lhs); + } + + byte[] bytes = SERDE.serialize(pairLongString); + + writeOutBytes.write(intSerializer.serialize(bytes.length)); + writeOutBytes.write(bytes); Review Comment: sort of. that's what i tried to do when you said i was going down the path of GenericIndexed. The problem is you need to do something during that first pass. Here it's finding a min and max. So that simple class needs at least one abstract method/function-object to process each line. that's a far cry from GenericIndexed or what I started to do in that abstraction we held off, but as that first pass does anything more complicated, the "first-pass-serialization-thingy" needs to change. the code re-use becomes pretty small because you have to extend the base class, add your variables for state, modify them in a callback in store(), and expose those variables to this BufferStore class (since the createColumnHeader() method uses them). the actual code re-use is 1. serialize to temp store 2. "processItem()" abstract function 3. call iterator() -> return new DeserializingIOIterator<>(writeOutBytes.asInputStream(), SERDE); it almost seems like it makes things *more* complex? discuss in a sync? -- 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]
