Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/18468#discussion_r128144719
--- Diff:
sql/core/src/main/java/org/apache/spark/sql/execution/vectorized/CachedBatchColumnVector.java
---
@@ -0,0 +1,416 @@
+/*
+ * 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.spark.sql.execution.vectorized;
+
+import java.nio.ByteBuffer;
+
+import org.apache.spark.memory.MemoryMode;
+import org.apache.spark.sql.execution.columnar.*;
+import org.apache.spark.sql.types.*;
+import org.apache.spark.unsafe.types.UTF8String;
+
+/**
+ * A column backed by an in memory JVM array.
+ */
+public final class CachedBatchColumnVector extends ColumnVector {
+
+ // keep compressed data
+ private byte[] buffer;
+
+ // accessor for a column
+ private ColumnAccessor columnAccessor;
+
+ // a row where the compressed data is extracted
+ private ColumnVector columnVector;
+
+ // an accessor uses only row 0 in columnVector
+ private final int ROWID = 0;
+
+ // Keep row id that was previously accessed
+ private int previousRowId = -1;
+
+
+ public CachedBatchColumnVector(byte[] buffer, int numRows, DataType
type) {
+ super(numRows, DataTypes.NullType, MemoryMode.ON_HEAP);
+ initialize(buffer, type);
+ reserveInternal(numRows);
+ reset();
+ }
+
+ @Override
+ public long valuesNativeAddress() {
+ throw new RuntimeException("Cannot get native address for on heap
column");
+ }
+ @Override
+ public long nullsNativeAddress() {
+ throw new RuntimeException("Cannot get native address for on heap
column");
+ }
+
+ @Override
+ public void close() {
+ }
+
+ private void setColumnAccessor() {
+ ByteBuffer byteBuffer = ByteBuffer.wrap(buffer);
+ columnAccessor = ColumnAccessor$.MODULE$.apply(type, byteBuffer);
+ }
+
+ // call extractTo() before getting actual data
+ private void prepareAccess(int rowId) {
+ if (previousRowId + 1 == rowId) {
+ assert (columnAccessor.hasNext());
+ columnAccessor.extractTo(columnVector, ROWID);
+ previousRowId = rowId;
+ } else if (previousRowId != rowId) {
+ throw new UnsupportedOperationException("Row access order must be
sequentially ascending." +
+ " Internal row " + rowId + "is accessed after internal row "+
previousRowId + "was accessed.");
+ }
+ }
+
+ //
+ // APIs dealing with nulls
+ //
+
+ @Override
+ public void putNotNull(int rowId) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void putNull(int rowId) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void putNulls(int rowId, int count) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void putNotNulls(int rowId, int count) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean isNullAt(int rowId) {
+ prepareAccess(rowId);
+ return columnVector.isNullAt(ROWID);
+ }
+
+ //
+ // APIs dealing with Booleans
+ //
+
+ @Override
+ public void putBoolean(int rowId, boolean value) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void putBooleans(int rowId, int count, boolean value) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean getBoolean(int rowId) {
+ prepareAccess(rowId);
+ return columnVector.getBoolean(ROWID);
+ }
+
+ @Override
+ public boolean[] getBooleans(int rowId, int count) {
+ throw new UnsupportedOperationException();
+ }
+
+ //
+
+ //
+ // APIs dealing with Bytes
+ //
+
+ @Override
+ public void putByte(int rowId, byte value) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void putBytes(int rowId, int count, byte value) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void putBytes(int rowId, int count, byte[] src, int srcIndex) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public byte getByte(int rowId) {
+ prepareAccess(rowId);
+ return columnVector.getByte(ROWID);
+ }
+
+ @Override
+ public byte[] getBytes(int rowId, int count) {
+ throw new UnsupportedOperationException();
+ }
+
+ //
+ // APIs dealing with Shorts
+ //
+
+ @Override
+ public void putShort(int rowId, short value) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void putShorts(int rowId, int count, short value) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void putShorts(int rowId, int count, short[] src, int srcIndex) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public short getShort(int rowId) {
+ prepareAccess(rowId);
+ return columnVector.getShort(ROWID);
+ }
+
+ @Override
+ public short[] getShorts(int rowId, int count) {
+ throw new UnsupportedOperationException();
+ }
+
+ //
+ // APIs dealing with Ints
+ //
+
+ @Override
+ public void putInt(int rowId, int value) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void putInts(int rowId, int count, int value) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void putInts(int rowId, int count, int[] src, int srcIndex) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void putIntsLittleEndian(int rowId, int count, byte[] src, int
srcIndex) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int getInt(int rowId) {
+ prepareAccess(rowId);
+ return columnVector.getInt(ROWID);
+ }
+
+ @Override
+ public int[] getInts(int rowId, int count) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * Returns the dictionary Id for rowId.
+ * This should only be called when the ColumnVector is dictionaryIds.
+ * We have this separate method for dictionaryIds as per SPARK-16928.
+ */
+ public int getDictId(int rowId) {
+ throw new UnsupportedOperationException();
+ }
+
+ //
+ // APIs dealing with Longs
+ //
+
+ @Override
+ public void putLong(int rowId, long value) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void putLongs(int rowId, int count, long value) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void putLongs(int rowId, int count, long[] src, int srcIndex) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void putLongsLittleEndian(int rowId, int count, byte[] src, int
srcIndex) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public long getLong(int rowId) {
+ prepareAccess(rowId);
+ return columnVector.getLong(ROWID);
+ }
+
+ @Override
+ public long[] getLongs(int rowId, int count) {
+ throw new UnsupportedOperationException();
+ }
+
+ //
+ // APIs dealing with floats
+ //
+
+ @Override
+ public void putFloat(int rowId, float value) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void putFloats(int rowId, int count, float value) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void putFloats(int rowId, int count, float[] src, int srcIndex) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void putFloats(int rowId, int count, byte[] src, int srcIndex) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public float getFloat(int rowId) {
+ prepareAccess(rowId);
+ return columnVector.getFloat(ROWID);
+ }
+
+ @Override
+ public float[] getFloats(int rowId, int count) {
+ throw new UnsupportedOperationException();
+ }
+
+ //
+ // APIs dealing with doubles
+ //
+
+ @Override
+ public void putDouble(int rowId, double value) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void putDoubles(int rowId, int count, double value) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void putDoubles(int rowId, int count, double[] src, int srcIndex)
{
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void putDoubles(int rowId, int count, byte[] src, int srcIndex) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public double getDouble(int rowId) {
+ prepareAccess(rowId);
+ return columnVector.getDouble(ROWID);
+ }
+
+ @Override
+ public double[] getDoubles(int rowId, int count) {
+ throw new UnsupportedOperationException();
+ }
+
+ //
+ // APIs dealing with Arrays
+ //
+
+ @Override
+ public int getArrayLength(int rowId) {
+ throw new UnsupportedOperationException();
+ }
+ @Override
+ public int getArrayOffset(int rowId) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void putArray(int rowId, int offset, int length) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void loadBytes(ColumnVector.Array array) {
+ throw new UnsupportedOperationException();
+ }
+
+ //
+ // APIs dealing with Byte Arrays
+ //
+
+ @Override
+ public int putByteArray(int rowId, byte[] value, int offset, int length)
{
+ throw new UnsupportedOperationException();
+ }
+
+ public final UTF8String getUTF8String(int rowId) {
+ prepareAccess(rowId);
+ return columnVector.getUTF8String(ROWID);
+ }
+
+ // Spilt this function out since it is the slow path.
+ @Override
+ protected void reserveInternal(int newCapacity) {
+ capacity = newCapacity;
+ }
+
+ private void initialize(byte[] buffer, DataType type) {
+ this.buffer = buffer;
+ this.type = type;
+
+ if (columnAccessor == null) {
+ setColumnAccessor();
--- End diff --
can we inline this method?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]