spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kiszk <...@git.apache.org>
Subject [GitHub] spark pull request #18468: [SPARK-20873][SQL] Creat CachedBatchColumnVector ...
Date Tue, 18 Jul 2017 13:08:29 GMT
Github user kiszk commented on a diff in the pull request:

    https://github.com/apache/spark/pull/18468#discussion_r127969028
  
    --- Diff: sql/core/src/main/java/org/apache/spark/sql/execution/vectorized/CachedBatchColumnVector.java
---
    @@ -0,0 +1,421 @@
    +/*
    + * 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 implements java.io.Serializable
{
    +
    +  // keep compressed data
    +  private byte[] buffer;
    +
    +  // whether a row is already extracted or not. If extractTo() is called, set true
    +  // e.g. when isNullAt() and getInt() ara called, extractTo() must be called only once
    +  private boolean[] calledExtractTo;
    +
    +  // accessor for a column
    +  private transient ColumnAccessor columnAccessor;
    +
    +  // a row where the compressed data is extracted
    +  private transient ColumnVector columnVector;
    +
    +  // an accessor uses only row 0 in columnVector
    +  private final int ROWID = 0;
    +
    +
    +  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);
    +    calledExtractTo = new boolean[capacity];
    +  }
    +
    +  // call extractTo() before getting actual data
    +  private void prepareAccess(int rowId) {
    +    if (!calledExtractTo[rowId]) {
    +      assert (columnAccessor.hasNext());
    +      columnAccessor.extractTo(columnVector, ROWID);
    +      calledExtractTo[rowId] = true;
    +    }
    +  }
    +
    +  //
    +  // 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) {
    --- End diff --
    
    I see. I will add code to track access order for each getter.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Mime
View raw message