You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by cloud-fan <gi...@git.apache.org> on 2017/07/19 12:29:26 UTC

[GitHub] spark pull request #18468: [SPARK-20783][SQL] Create CachedBatchColumnVector...

Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/18468#discussion_r128231184
  
    --- Diff: sql/core/src/main/java/org/apache/spark/sql/execution/vectorized/CachedBatchColumnVector.java ---
    @@ -0,0 +1,407 @@
    +/*
    + * 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 data compressed thru ColumnAccessor
    + * this is a wrapper to read compressed data for table cache
    + */
    +public final class CachedBatchColumnVector extends ColumnVector {
    +
    +  // 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() {
    +  }
    +
    +  // call extractTo() for rowId only once before getting actual data
    +  private void prepareAccess(int rowId) {
    +    if (previousRowId == rowId) {
    +      // do nothing
    +    } else if (previousRowId < rowId) {
    +      for (int i = previousRowId + 1; i <= rowId; i++) {
    +        assert (columnAccessor.hasNext());
    +        columnAccessor.extractTo(columnVector, ROWID);
    --- End diff --
    
    Can we keep the value in `MutableUnsafeRow` instead of `ColumnVector`? Then we don't need to change `ColumnAccessor` to support `ColumnVector`.


---
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