clintropolis commented on a change in pull request #6016: Druid 'Shapeshifting' 
Columns
URL: https://github.com/apache/incubator-druid/pull/6016#discussion_r209760963
 
 

 ##########
 File path: 
processing/src/main/java/io/druid/segment/data/codecs/ints/ConstantIntFormDecoder.java
 ##########
 @@ -0,0 +1,74 @@
+/*
+ * 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 io.druid.segment.data.codecs.ints;
+
+import io.druid.segment.data.ShapeShiftingColumnarInts;
+import io.druid.segment.data.codecs.BaseFormDecoder;
+import io.druid.segment.data.codecs.DirectFormDecoder;
+
+import java.nio.ByteOrder;
+import java.util.Arrays;
+
+/**
+ * Decoder used if all values are the same within a chunk are constant.
+ *
+ * layout:
+ * | header: IntCodecs.CONSTANT (byte) | constant value (int) |
+ */
+public final class ConstantIntFormDecoder extends 
BaseFormDecoder<ShapeShiftingColumnarInts>
+    implements DirectFormDecoder<ShapeShiftingColumnarInts>
+{
+  public ConstantIntFormDecoder(final byte logValuesPerChunk, final ByteOrder 
byteOrder)
+  {
+    super(logValuesPerChunk, byteOrder);
+  }
+
+  @Override
+  public void transform(ShapeShiftingColumnarInts columnarInts)
+  {
+    final int startOffset = columnarInts.getCurrentValuesStartOffset();
+    final int currentConstant = 
columnarInts.getCurrentValueBuffer().getInt(startOffset);
+    Arrays.fill(columnarInts.getDecodedValues(), currentConstant);
+  }
+
+  @Override
+  public void transformBuffer(ShapeShiftingColumnarInts columnarInts)
+  {
+    final int startOffset = columnarInts.getCurrentValuesStartOffset();
+    final int currentConstant = 
columnarInts.getCurrentValueBuffer().getInt(startOffset);
+    columnarInts.setCurrentBytesPerValue(0);
+    columnarInts.setCurrentConstant(currentConstant);
+  }
+
+  @Override
+  public void transformUnsafe(ShapeShiftingColumnarInts columnarInts)
+  {
+    final int startOffset = columnarInts.getCurrentValuesStartOffset();
+    final int currentConstant = 
columnarInts.getCurrentValueBuffer().getInt(startOffset);
+    columnarInts.setCurrentBytesPerValue(0);
+    columnarInts.setCurrentConstant(currentConstant);
 
 Review comment:
   Yeah, they are exactly the same in this decoder (and zero) and nearly the 
same in most other implementations since they have a fair bit in common, I 
think it makes sense to combine these methods since it doesn't hurt to both set 
a current buffer offset and also if the buffer is direct, a current buffer 
address in the column during transform, so these can easily be consolidated.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to