You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by ooq <gi...@git.apache.org> on 2016/07/13 08:04:50 UTC

[GitHub] spark pull request #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashM...

GitHub user ooq opened a pull request:

    https://github.com/apache/spark/pull/14174

    [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGenerator

    ## What changes were proposed in this pull request?
    
    This PR is the first step for the following feature:
    
    For hash aggregation in Spark SQL, we use a fast aggregation hashmap to act as a "cache" in order to boost aggregation performance. Previously, the hashmap is backed by a `ColumnarBatch`. This has performance issues when we have wide schema for the aggregation table (large number of key fields or value fields). 
    In this JIRA, we support another implementation of fast hashmap, which is backed by a `RowBatch`. We then automatically pick between the two implementations based on certain knobs.
    
    In this first-step PR, implementations for `RowBatch` and `RowBasedHashMapGenerator` are added. 
    
    ## How was this patch tested?
    
    `RowBatch` could be tested through unit tests (added later). Otherwise, tests and benchmarks will be added in a separate PR in the series. 
    


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/ooq/spark rowbasedfastaggmap-pr1

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/spark/pull/14174.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #14174
    
----
commit c87f26b318b5d673ac95454df5c1cb9a56c677eb
Author: Qifan Pu <qi...@gmail.com>
Date:   2016-07-13T07:35:06Z

    add RowBatch and RowBasedHashMapGenerator

----


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


[GitHub] spark pull request #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashM...

Posted by sameeragarwal <gi...@git.apache.org>.
Github user sameeragarwal commented on a diff in the pull request:

    https://github.com/apache/spark/pull/14174#discussion_r71253029
  
    --- Diff: sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/RowBasedKeyValueBatch.java ---
    @@ -0,0 +1,322 @@
    +/*
    + * 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.catalyst.expressions;
    +
    +import java.io.IOException;
    +
    +import org.apache.spark.memory.MemoryConsumer;
    +import org.apache.spark.memory.TaskMemoryManager;
    +import org.apache.spark.sql.types.*;
    +import org.apache.spark.unsafe.memory.MemoryBlock;
    +import org.apache.spark.unsafe.Platform;
    +
    +
    +/**
    + * RowBasedKeyValueBatch stores key value pairs in contiguous memory region.
    + *
    + * Each key or value is stored as a single UnsafeRow. The format for each record looks like this:
    + * [4 bytes total size = (klen + vlen + 4)] [4 bytes key size = klen]
    + * [UnsafeRow for key of length klen] [UnsafeRow for Value of length vlen]
    + * [8 bytes pointer to next]
    + * Thus, record length = 8 + klen + vlen + 8
    + *
    + * RowBasedKeyValueBatch will automatically acquire new pages (MemoryBlock) when the current page
    + * is used up.
    + *
    + * TODO: making each entry more compact, e.g., combine key and value into a single UnsafeRow
    + */
    +public final class RowBasedKeyValueBatch extends MemoryConsumer{
    --- End diff --
    
    nit: `MemoryConsumer {`


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    **[Test build #62498 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/62498/consoleFull)** for PR 14174 at commit [`b04ff88`](https://github.com/apache/spark/commit/b04ff887ac10ee2f9bdd66c0c83b007521b5016c).


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    Merged build finished. Test PASSed.


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/62483/
    Test PASSed.


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by ooq <gi...@git.apache.org>.
Github user ooq commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    hi @viirya , you can find the benchmark numbers here in this PR: https://github.com/apache/spark/pull/14266


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


[GitHub] spark pull request #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashM...

Posted by sameeragarwal <gi...@git.apache.org>.
Github user sameeragarwal commented on a diff in the pull request:

    https://github.com/apache/spark/pull/14174#discussion_r71253164
  
    --- Diff: sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/RowBasedKeyValueBatch.java ---
    @@ -0,0 +1,322 @@
    +/*
    + * 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.catalyst.expressions;
    +
    +import java.io.IOException;
    +
    +import org.apache.spark.memory.MemoryConsumer;
    +import org.apache.spark.memory.TaskMemoryManager;
    +import org.apache.spark.sql.types.*;
    +import org.apache.spark.unsafe.memory.MemoryBlock;
    +import org.apache.spark.unsafe.Platform;
    +
    +
    +/**
    + * RowBasedKeyValueBatch stores key value pairs in contiguous memory region.
    + *
    + * Each key or value is stored as a single UnsafeRow. The format for each record looks like this:
    + * [4 bytes total size = (klen + vlen + 4)] [4 bytes key size = klen]
    + * [UnsafeRow for key of length klen] [UnsafeRow for Value of length vlen]
    + * [8 bytes pointer to next]
    + * Thus, record length = 8 + klen + vlen + 8
    + *
    + * RowBasedKeyValueBatch will automatically acquire new pages (MemoryBlock) when the current page
    + * is used up.
    + *
    + * TODO: making each entry more compact, e.g., combine key and value into a single UnsafeRow
    + */
    +public final class RowBasedKeyValueBatch extends MemoryConsumer{
    +  private static final int DEFAULT_CAPACITY = 1 << 16;
    +  private static final long DEFAULT_PAGE_SIZE = 64 * 1024 * 1024;
    +
    +  private final StructType keySchema;
    +  private final StructType valueSchema;
    +  private final int capacity;
    +  private int numRows = 0;
    +
    +  // Staging row returned from getRow.
    +  final UnsafeRow keyRow;
    +  final UnsafeRow valueRow;
    +
    +  // ids for current key row and value row being retrieved
    +  private int keyRowId = -1;
    +
    +  // full addresses for key rows and value rows
    +  private long[] keyOffsets;
    +
    +  // if all data types in the schema are fixed length
    +  private boolean allFixedLength;
    +  private int klen;
    +  private int vlen;
    +  private int recordLength;
    +
    +  private MemoryBlock currentAndOnlyPage = null;
    +  private Object currentAndOnlyBase = null;
    +  private long recordStartOffset;
    +  private long pageCursor = 0;
    +
    +  public static RowBasedKeyValueBatch allocate(StructType keySchema, StructType valueSchema,
    +                                               TaskMemoryManager manager) {
    +    return new RowBasedKeyValueBatch(keySchema, valueSchema, DEFAULT_CAPACITY, manager);
    +  }
    +
    +  public static RowBasedKeyValueBatch allocate(StructType keySchema, StructType valueSchema,
    +                                               TaskMemoryManager manager, int maxRows) {
    +    return new RowBasedKeyValueBatch(keySchema, valueSchema, maxRows, manager);
    +  }
    +
    +  public int numRows() { return numRows; }
    +
    +  public void close() {
    +    if (currentAndOnlyPage != null) {
    +      freePage(currentAndOnlyPage);
    +      currentAndOnlyPage = null;
    +    }
    +  }
    +
    +  private boolean acquireNewPage(long required) {
    --- End diff --
    
    nit: `requiredSize`


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    **[Test build #62497 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/62497/consoleFull)** for PR 14174 at commit [`d939488`](https://github.com/apache/spark/commit/d9394888977c97fe95f1642ad9f613dcbee1e4fa).


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    **[Test build #62222 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/62222/consoleFull)** for PR 14174 at commit [`c87f26b`](https://github.com/apache/spark/commit/c87f26b318b5d673ac95454df5c1cb9a56c677eb).


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


[GitHub] spark pull request #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashM...

Posted by sameeragarwal <gi...@git.apache.org>.
Github user sameeragarwal commented on a diff in the pull request:

    https://github.com/apache/spark/pull/14174#discussion_r71253434
  
    --- Diff: sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/RowBasedKeyValueBatch.java ---
    @@ -0,0 +1,322 @@
    +/*
    + * 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.catalyst.expressions;
    +
    +import java.io.IOException;
    +
    +import org.apache.spark.memory.MemoryConsumer;
    +import org.apache.spark.memory.TaskMemoryManager;
    +import org.apache.spark.sql.types.*;
    +import org.apache.spark.unsafe.memory.MemoryBlock;
    +import org.apache.spark.unsafe.Platform;
    +
    +
    +/**
    + * RowBasedKeyValueBatch stores key value pairs in contiguous memory region.
    + *
    + * Each key or value is stored as a single UnsafeRow. The format for each record looks like this:
    + * [4 bytes total size = (klen + vlen + 4)] [4 bytes key size = klen]
    + * [UnsafeRow for key of length klen] [UnsafeRow for Value of length vlen]
    + * [8 bytes pointer to next]
    + * Thus, record length = 8 + klen + vlen + 8
    + *
    + * RowBasedKeyValueBatch will automatically acquire new pages (MemoryBlock) when the current page
    + * is used up.
    + *
    + * TODO: making each entry more compact, e.g., combine key and value into a single UnsafeRow
    + */
    +public final class RowBasedKeyValueBatch extends MemoryConsumer{
    +  private static final int DEFAULT_CAPACITY = 1 << 16;
    +  private static final long DEFAULT_PAGE_SIZE = 64 * 1024 * 1024;
    +
    +  private final StructType keySchema;
    +  private final StructType valueSchema;
    +  private final int capacity;
    +  private int numRows = 0;
    +
    +  // Staging row returned from getRow.
    +  final UnsafeRow keyRow;
    +  final UnsafeRow valueRow;
    +
    +  // ids for current key row and value row being retrieved
    +  private int keyRowId = -1;
    +
    +  // full addresses for key rows and value rows
    +  private long[] keyOffsets;
    +
    +  // if all data types in the schema are fixed length
    +  private boolean allFixedLength;
    +  private int klen;
    +  private int vlen;
    +  private int recordLength;
    +
    +  private MemoryBlock currentAndOnlyPage = null;
    +  private Object currentAndOnlyBase = null;
    +  private long recordStartOffset;
    +  private long pageCursor = 0;
    +
    +  public static RowBasedKeyValueBatch allocate(StructType keySchema, StructType valueSchema,
    +                                               TaskMemoryManager manager) {
    +    return new RowBasedKeyValueBatch(keySchema, valueSchema, DEFAULT_CAPACITY, manager);
    +  }
    +
    +  public static RowBasedKeyValueBatch allocate(StructType keySchema, StructType valueSchema,
    +                                               TaskMemoryManager manager, int maxRows) {
    +    return new RowBasedKeyValueBatch(keySchema, valueSchema, maxRows, manager);
    +  }
    +
    +  public int numRows() { return numRows; }
    +
    +  public void close() {
    +    if (currentAndOnlyPage != null) {
    +      freePage(currentAndOnlyPage);
    +      currentAndOnlyPage = null;
    +    }
    +  }
    +
    +  private boolean acquireNewPage(long required) {
    +    try {
    +      currentAndOnlyPage = allocatePage(required);
    +    } catch (OutOfMemoryError e) {
    +      return false;
    +    }
    +    currentAndOnlyBase = currentAndOnlyPage.getBaseObject();
    +    Platform.putInt(currentAndOnlyBase, currentAndOnlyPage.getBaseOffset(), 0);
    +    pageCursor = 4;
    +    recordStartOffset = pageCursor + currentAndOnlyPage.getBaseOffset();
    +
    +    return true;
    +  }
    +
    +  private long getKeyOffsetForFixedLengthRecords(int rowId) {
    +    return recordStartOffset + rowId * recordLength + 8;
    +  }
    +
    +  public UnsafeRow appendRow(Object kbase, long koff, int klen,
    --- End diff --
    
    Can we add a small comment saying that this returns the value row?


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


[GitHub] spark pull request #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashM...

Posted by sameeragarwal <gi...@git.apache.org>.
Github user sameeragarwal commented on a diff in the pull request:

    https://github.com/apache/spark/pull/14174#discussion_r71252969
  
    --- Diff: sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/RowBasedKeyValueBatch.java ---
    @@ -0,0 +1,322 @@
    +/*
    + * 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.catalyst.expressions;
    +
    +import java.io.IOException;
    +
    +import org.apache.spark.memory.MemoryConsumer;
    +import org.apache.spark.memory.TaskMemoryManager;
    +import org.apache.spark.sql.types.*;
    +import org.apache.spark.unsafe.memory.MemoryBlock;
    +import org.apache.spark.unsafe.Platform;
    +
    +
    +/**
    + * RowBasedKeyValueBatch stores key value pairs in contiguous memory region.
    + *
    + * Each key or value is stored as a single UnsafeRow. The format for each record looks like this:
    + * [4 bytes total size = (klen + vlen + 4)] [4 bytes key size = klen]
    + * [UnsafeRow for key of length klen] [UnsafeRow for Value of length vlen]
    + * [8 bytes pointer to next]
    + * Thus, record length = 8 + klen + vlen + 8
    + *
    + * RowBasedKeyValueBatch will automatically acquire new pages (MemoryBlock) when the current page
    + * is used up.
    --- End diff --
    
    Let's update/add docs about why this data structure is backed by a single page.


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    **[Test build #62483 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/62483/consoleFull)** for PR 14174 at commit [`8f538b1`](https://github.com/apache/spark/commit/8f538b177e36ccc5fb690a3b29eb03ca72d1a4b2).


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


[GitHub] spark pull request #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashM...

Posted by sameeragarwal <gi...@git.apache.org>.
Github user sameeragarwal commented on a diff in the pull request:

    https://github.com/apache/spark/pull/14174#discussion_r71253765
  
    --- Diff: sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/RowBasedKeyValueBatch.java ---
    @@ -0,0 +1,322 @@
    +/*
    + * 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.catalyst.expressions;
    +
    +import java.io.IOException;
    +
    +import org.apache.spark.memory.MemoryConsumer;
    +import org.apache.spark.memory.TaskMemoryManager;
    +import org.apache.spark.sql.types.*;
    +import org.apache.spark.unsafe.memory.MemoryBlock;
    +import org.apache.spark.unsafe.Platform;
    +
    +
    +/**
    + * RowBasedKeyValueBatch stores key value pairs in contiguous memory region.
    + *
    + * Each key or value is stored as a single UnsafeRow. The format for each record looks like this:
    + * [4 bytes total size = (klen + vlen + 4)] [4 bytes key size = klen]
    + * [UnsafeRow for key of length klen] [UnsafeRow for Value of length vlen]
    + * [8 bytes pointer to next]
    + * Thus, record length = 8 + klen + vlen + 8
    + *
    + * RowBasedKeyValueBatch will automatically acquire new pages (MemoryBlock) when the current page
    + * is used up.
    + *
    + * TODO: making each entry more compact, e.g., combine key and value into a single UnsafeRow
    + */
    +public final class RowBasedKeyValueBatch extends MemoryConsumer{
    +  private static final int DEFAULT_CAPACITY = 1 << 16;
    +  private static final long DEFAULT_PAGE_SIZE = 64 * 1024 * 1024;
    +
    +  private final StructType keySchema;
    +  private final StructType valueSchema;
    +  private final int capacity;
    +  private int numRows = 0;
    +
    +  // Staging row returned from getRow.
    +  final UnsafeRow keyRow;
    +  final UnsafeRow valueRow;
    +
    +  // ids for current key row and value row being retrieved
    +  private int keyRowId = -1;
    +
    +  // full addresses for key rows and value rows
    +  private long[] keyOffsets;
    +
    +  // if all data types in the schema are fixed length
    +  private boolean allFixedLength;
    +  private int klen;
    +  private int vlen;
    +  private int recordLength;
    +
    +  private MemoryBlock currentAndOnlyPage = null;
    +  private Object currentAndOnlyBase = null;
    +  private long recordStartOffset;
    +  private long pageCursor = 0;
    +
    +  public static RowBasedKeyValueBatch allocate(StructType keySchema, StructType valueSchema,
    +                                               TaskMemoryManager manager) {
    +    return new RowBasedKeyValueBatch(keySchema, valueSchema, DEFAULT_CAPACITY, manager);
    +  }
    +
    +  public static RowBasedKeyValueBatch allocate(StructType keySchema, StructType valueSchema,
    +                                               TaskMemoryManager manager, int maxRows) {
    +    return new RowBasedKeyValueBatch(keySchema, valueSchema, maxRows, manager);
    +  }
    +
    +  public int numRows() { return numRows; }
    +
    +  public void close() {
    +    if (currentAndOnlyPage != null) {
    +      freePage(currentAndOnlyPage);
    +      currentAndOnlyPage = null;
    +    }
    +  }
    +
    +  private boolean acquireNewPage(long required) {
    +    try {
    +      currentAndOnlyPage = allocatePage(required);
    +    } catch (OutOfMemoryError e) {
    +      return false;
    +    }
    +    currentAndOnlyBase = currentAndOnlyPage.getBaseObject();
    +    Platform.putInt(currentAndOnlyBase, currentAndOnlyPage.getBaseOffset(), 0);
    +    pageCursor = 4;
    +    recordStartOffset = pageCursor + currentAndOnlyPage.getBaseOffset();
    +
    +    return true;
    +  }
    +
    +  private long getKeyOffsetForFixedLengthRecords(int rowId) {
    +    return recordStartOffset + rowId * recordLength + 8;
    +  }
    +
    +  public UnsafeRow appendRow(Object kbase, long koff, int klen,
    +                             Object vbase, long voff, int vlen) {
    +    final long recordLength = 8 + klen + vlen + 8;
    +    // if run out of max supported rows or page size, return null
    +    if (numRows >= capacity || currentAndOnlyPage == null
    +            || currentAndOnlyPage.size() - pageCursor < recordLength) {
    +      return null;
    +    }
    +
    +    final Object base = currentAndOnlyBase;
    +    long offset = currentAndOnlyPage.getBaseOffset() + pageCursor;
    +    final long recordOffset = offset;
    +    if (!allFixedLength) { // we only put lengths info for variable length
    +      Platform.putInt(base, offset, klen + vlen + 4);
    +      Platform.putInt(base, offset + 4, klen);
    +    }
    +    offset += 8;
    +    Platform.copyMemory(kbase, koff, base, offset, klen);
    +    offset += klen;
    +    Platform.copyMemory(vbase, voff, base, offset, vlen);
    +    offset += vlen;
    +    Platform.putLong(base, offset, 0);
    +
    +    offset = currentAndOnlyPage.getBaseOffset();
    +    Platform.putInt(base, offset, Platform.getInt(base, offset) + 1);
    --- End diff --
    
    Given that this can never spill, could we just increment and use `numRows` here?


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    Merged build finished. Test PASSed.


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


[GitHub] spark pull request #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashM...

Posted by sameeragarwal <gi...@git.apache.org>.
Github user sameeragarwal commented on a diff in the pull request:

    https://github.com/apache/spark/pull/14174#discussion_r71253225
  
    --- Diff: sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/RowBasedKeyValueBatch.java ---
    @@ -0,0 +1,322 @@
    +/*
    + * 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.catalyst.expressions;
    +
    +import java.io.IOException;
    +
    +import org.apache.spark.memory.MemoryConsumer;
    +import org.apache.spark.memory.TaskMemoryManager;
    +import org.apache.spark.sql.types.*;
    +import org.apache.spark.unsafe.memory.MemoryBlock;
    +import org.apache.spark.unsafe.Platform;
    +
    +
    +/**
    + * RowBasedKeyValueBatch stores key value pairs in contiguous memory region.
    + *
    + * Each key or value is stored as a single UnsafeRow. The format for each record looks like this:
    + * [4 bytes total size = (klen + vlen + 4)] [4 bytes key size = klen]
    + * [UnsafeRow for key of length klen] [UnsafeRow for Value of length vlen]
    + * [8 bytes pointer to next]
    + * Thus, record length = 8 + klen + vlen + 8
    + *
    + * RowBasedKeyValueBatch will automatically acquire new pages (MemoryBlock) when the current page
    + * is used up.
    + *
    + * TODO: making each entry more compact, e.g., combine key and value into a single UnsafeRow
    + */
    +public final class RowBasedKeyValueBatch extends MemoryConsumer{
    +  private static final int DEFAULT_CAPACITY = 1 << 16;
    +  private static final long DEFAULT_PAGE_SIZE = 64 * 1024 * 1024;
    +
    +  private final StructType keySchema;
    +  private final StructType valueSchema;
    +  private final int capacity;
    +  private int numRows = 0;
    +
    +  // Staging row returned from getRow.
    +  final UnsafeRow keyRow;
    +  final UnsafeRow valueRow;
    +
    +  // ids for current key row and value row being retrieved
    +  private int keyRowId = -1;
    +
    +  // full addresses for key rows and value rows
    +  private long[] keyOffsets;
    +
    +  // if all data types in the schema are fixed length
    +  private boolean allFixedLength;
    +  private int klen;
    +  private int vlen;
    +  private int recordLength;
    +
    +  private MemoryBlock currentAndOnlyPage = null;
    +  private Object currentAndOnlyBase = null;
    +  private long recordStartOffset;
    +  private long pageCursor = 0;
    +
    +  public static RowBasedKeyValueBatch allocate(StructType keySchema, StructType valueSchema,
    +                                               TaskMemoryManager manager) {
    +    return new RowBasedKeyValueBatch(keySchema, valueSchema, DEFAULT_CAPACITY, manager);
    +  }
    +
    +  public static RowBasedKeyValueBatch allocate(StructType keySchema, StructType valueSchema,
    +                                               TaskMemoryManager manager, int maxRows) {
    +    return new RowBasedKeyValueBatch(keySchema, valueSchema, maxRows, manager);
    +  }
    +
    +  public int numRows() { return numRows; }
    +
    +  public void close() {
    +    if (currentAndOnlyPage != null) {
    +      freePage(currentAndOnlyPage);
    +      currentAndOnlyPage = null;
    +    }
    +  }
    +
    +  private boolean acquireNewPage(long required) {
    +    try {
    +      currentAndOnlyPage = allocatePage(required);
    +    } catch (OutOfMemoryError e) {
    +      return false;
    --- End diff --
    
    It's also log the exception here


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


[GitHub] spark pull request #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashM...

Posted by sameeragarwal <gi...@git.apache.org>.
Github user sameeragarwal commented on a diff in the pull request:

    https://github.com/apache/spark/pull/14174#discussion_r71253373
  
    --- Diff: sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/RowBasedKeyValueBatch.java ---
    @@ -0,0 +1,322 @@
    +/*
    + * 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.catalyst.expressions;
    +
    +import java.io.IOException;
    +
    +import org.apache.spark.memory.MemoryConsumer;
    +import org.apache.spark.memory.TaskMemoryManager;
    +import org.apache.spark.sql.types.*;
    +import org.apache.spark.unsafe.memory.MemoryBlock;
    +import org.apache.spark.unsafe.Platform;
    +
    +
    +/**
    + * RowBasedKeyValueBatch stores key value pairs in contiguous memory region.
    + *
    + * Each key or value is stored as a single UnsafeRow. The format for each record looks like this:
    + * [4 bytes total size = (klen + vlen + 4)] [4 bytes key size = klen]
    + * [UnsafeRow for key of length klen] [UnsafeRow for Value of length vlen]
    + * [8 bytes pointer to next]
    + * Thus, record length = 8 + klen + vlen + 8
    + *
    + * RowBasedKeyValueBatch will automatically acquire new pages (MemoryBlock) when the current page
    + * is used up.
    + *
    + * TODO: making each entry more compact, e.g., combine key and value into a single UnsafeRow
    + */
    +public final class RowBasedKeyValueBatch extends MemoryConsumer{
    +  private static final int DEFAULT_CAPACITY = 1 << 16;
    +  private static final long DEFAULT_PAGE_SIZE = 64 * 1024 * 1024;
    +
    +  private final StructType keySchema;
    +  private final StructType valueSchema;
    +  private final int capacity;
    +  private int numRows = 0;
    +
    +  // Staging row returned from getRow.
    +  final UnsafeRow keyRow;
    +  final UnsafeRow valueRow;
    +
    +  // ids for current key row and value row being retrieved
    +  private int keyRowId = -1;
    +
    +  // full addresses for key rows and value rows
    +  private long[] keyOffsets;
    +
    +  // if all data types in the schema are fixed length
    +  private boolean allFixedLength;
    +  private int klen;
    +  private int vlen;
    +  private int recordLength;
    +
    +  private MemoryBlock currentAndOnlyPage = null;
    +  private Object currentAndOnlyBase = null;
    +  private long recordStartOffset;
    +  private long pageCursor = 0;
    +
    +  public static RowBasedKeyValueBatch allocate(StructType keySchema, StructType valueSchema,
    +                                               TaskMemoryManager manager) {
    +    return new RowBasedKeyValueBatch(keySchema, valueSchema, DEFAULT_CAPACITY, manager);
    +  }
    +
    +  public static RowBasedKeyValueBatch allocate(StructType keySchema, StructType valueSchema,
    +                                               TaskMemoryManager manager, int maxRows) {
    +    return new RowBasedKeyValueBatch(keySchema, valueSchema, maxRows, manager);
    +  }
    +
    +  public int numRows() { return numRows; }
    +
    +  public void close() {
    +    if (currentAndOnlyPage != null) {
    +      freePage(currentAndOnlyPage);
    +      currentAndOnlyPage = null;
    +    }
    +  }
    +
    +  private boolean acquireNewPage(long required) {
    +    try {
    +      currentAndOnlyPage = allocatePage(required);
    +    } catch (OutOfMemoryError e) {
    +      return false;
    +    }
    +    currentAndOnlyBase = currentAndOnlyPage.getBaseObject();
    +    Platform.putInt(currentAndOnlyBase, currentAndOnlyPage.getBaseOffset(), 0);
    +    pageCursor = 4;
    +    recordStartOffset = pageCursor + currentAndOnlyPage.getBaseOffset();
    +
    +    return true;
    +  }
    +
    +  private long getKeyOffsetForFixedLengthRecords(int rowId) {
    +    return recordStartOffset + rowId * recordLength + 8;
    +  }
    +
    +  public UnsafeRow appendRow(Object kbase, long koff, int klen,
    +                             Object vbase, long voff, int vlen) {
    +    final long recordLength = 8 + klen + vlen + 8;
    +    // if run out of max supported rows or page size, return null
    +    if (numRows >= capacity || currentAndOnlyPage == null
    +            || currentAndOnlyPage.size() - pageCursor < recordLength) {
    --- End diff --
    
    can fold this into the line above


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


[GitHub] spark pull request #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashM...

Posted by sameeragarwal <gi...@git.apache.org>.
Github user sameeragarwal commented on a diff in the pull request:

    https://github.com/apache/spark/pull/14174#discussion_r71254165
  
    --- Diff: sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/RowBasedKeyValueBatch.java ---
    @@ -0,0 +1,322 @@
    +/*
    + * 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.catalyst.expressions;
    +
    +import java.io.IOException;
    +
    +import org.apache.spark.memory.MemoryConsumer;
    +import org.apache.spark.memory.TaskMemoryManager;
    +import org.apache.spark.sql.types.*;
    +import org.apache.spark.unsafe.memory.MemoryBlock;
    +import org.apache.spark.unsafe.Platform;
    +
    +
    +/**
    + * RowBasedKeyValueBatch stores key value pairs in contiguous memory region.
    + *
    + * Each key or value is stored as a single UnsafeRow. The format for each record looks like this:
    + * [4 bytes total size = (klen + vlen + 4)] [4 bytes key size = klen]
    + * [UnsafeRow for key of length klen] [UnsafeRow for Value of length vlen]
    + * [8 bytes pointer to next]
    + * Thus, record length = 8 + klen + vlen + 8
    + *
    + * RowBasedKeyValueBatch will automatically acquire new pages (MemoryBlock) when the current page
    + * is used up.
    + *
    + * TODO: making each entry more compact, e.g., combine key and value into a single UnsafeRow
    + */
    +public final class RowBasedKeyValueBatch extends MemoryConsumer{
    +  private static final int DEFAULT_CAPACITY = 1 << 16;
    +  private static final long DEFAULT_PAGE_SIZE = 64 * 1024 * 1024;
    +
    +  private final StructType keySchema;
    +  private final StructType valueSchema;
    +  private final int capacity;
    +  private int numRows = 0;
    +
    +  // Staging row returned from getRow.
    +  final UnsafeRow keyRow;
    +  final UnsafeRow valueRow;
    +
    +  // ids for current key row and value row being retrieved
    +  private int keyRowId = -1;
    +
    +  // full addresses for key rows and value rows
    +  private long[] keyOffsets;
    +
    +  // if all data types in the schema are fixed length
    +  private boolean allFixedLength;
    +  private int klen;
    +  private int vlen;
    +  private int recordLength;
    +
    +  private MemoryBlock currentAndOnlyPage = null;
    +  private Object currentAndOnlyBase = null;
    +  private long recordStartOffset;
    +  private long pageCursor = 0;
    +
    +  public static RowBasedKeyValueBatch allocate(StructType keySchema, StructType valueSchema,
    +                                               TaskMemoryManager manager) {
    +    return new RowBasedKeyValueBatch(keySchema, valueSchema, DEFAULT_CAPACITY, manager);
    +  }
    +
    +  public static RowBasedKeyValueBatch allocate(StructType keySchema, StructType valueSchema,
    +                                               TaskMemoryManager manager, int maxRows) {
    +    return new RowBasedKeyValueBatch(keySchema, valueSchema, maxRows, manager);
    +  }
    +
    +  public int numRows() { return numRows; }
    +
    +  public void close() {
    +    if (currentAndOnlyPage != null) {
    +      freePage(currentAndOnlyPage);
    +      currentAndOnlyPage = null;
    +    }
    +  }
    +
    +  private boolean acquireNewPage(long required) {
    +    try {
    +      currentAndOnlyPage = allocatePage(required);
    +    } catch (OutOfMemoryError e) {
    +      return false;
    +    }
    +    currentAndOnlyBase = currentAndOnlyPage.getBaseObject();
    +    Platform.putInt(currentAndOnlyBase, currentAndOnlyPage.getBaseOffset(), 0);
    +    pageCursor = 4;
    +    recordStartOffset = pageCursor + currentAndOnlyPage.getBaseOffset();
    +
    +    return true;
    +  }
    +
    +  private long getKeyOffsetForFixedLengthRecords(int rowId) {
    +    return recordStartOffset + rowId * recordLength + 8;
    +  }
    +
    +  public UnsafeRow appendRow(Object kbase, long koff, int klen,
    +                             Object vbase, long voff, int vlen) {
    +    final long recordLength = 8 + klen + vlen + 8;
    +    // if run out of max supported rows or page size, return null
    +    if (numRows >= capacity || currentAndOnlyPage == null
    +            || currentAndOnlyPage.size() - pageCursor < recordLength) {
    +      return null;
    +    }
    +
    +    final Object base = currentAndOnlyBase;
    +    long offset = currentAndOnlyPage.getBaseOffset() + pageCursor;
    +    final long recordOffset = offset;
    +    if (!allFixedLength) { // we only put lengths info for variable length
    +      Platform.putInt(base, offset, klen + vlen + 4);
    +      Platform.putInt(base, offset + 4, klen);
    +    }
    +    offset += 8;
    +    Platform.copyMemory(kbase, koff, base, offset, klen);
    +    offset += klen;
    +    Platform.copyMemory(vbase, voff, base, offset, vlen);
    +    offset += vlen;
    +    Platform.putLong(base, offset, 0);
    +
    +    offset = currentAndOnlyPage.getBaseOffset();
    +    Platform.putInt(base, offset, Platform.getInt(base, offset) + 1);
    +    pageCursor += recordLength;
    +
    +
    +    if (!allFixedLength) keyOffsets[numRows] = recordOffset + 8;
    +
    +    keyRowId = numRows;
    +    keyRow.pointTo(base, recordOffset + 8, klen);
    +    valueRow.pointTo(base, recordOffset + 8 + klen, vlen + 4);
    +    numRows++;
    +    return valueRow;
    +  }
    +
    +  /**
    +   * Returns the key row in this batch at `rowId`. Returned key row is reused across calls.
    +   */
    +  public UnsafeRow getKeyRow(int rowId) {
    +    assert(rowId >= 0);
    +    assert(rowId < numRows);
    +    if (keyRowId != rowId) { // if keyRowId == rowId, desired keyRow is already cached
    +      if (allFixedLength) {
    +        long offset = getKeyOffsetForFixedLengthRecords(rowId);
    +        keyRow.pointTo(currentAndOnlyBase, offset, klen);
    +      } else {
    +        long offset = keyOffsets[rowId];
    +        klen = Platform.getInt(currentAndOnlyBase, offset - 4);
    +        keyRow.pointTo(currentAndOnlyBase, offset, klen);
    +      }
    +      // set keyRowId so we can check if desired row is cached
    +      keyRowId = rowId;
    +    }
    +    return keyRow;
    +  }
    +
    +  /**
    +   * Returns the value row in this batch at `rowId`.
    +   * It can be a faster path if `keyRowId` is equal to `rowId`, which means the preceding
    +   * key row has just been accessed. This is always the case so far.
    +   * Returned value row is reused across calls.
    +   */
    +  public UnsafeRow getValueRow(int rowId) {
    +    return getValueFromKey(rowId);
    +  }
    +
    +  /**
    +   * Returns the value row in this batch at `rowId`.
    +   * It can be a faster path if `keyRowId` is equal to `rowId`, which means the preceding
    +   * key row has just been accessed. This is always the case so far.
    +   * Returned value row is reused across calls.
    +   */
    +  private UnsafeRow getValueFromKey(int rowId) {
    +    if (keyRowId != rowId) {
    +      getKeyRow(rowId);
    +    }
    +    assert(rowId >= 0);
    +    if (allFixedLength) {
    +      valueRow.pointTo(currentAndOnlyBase,
    +              keyRow.getBaseOffset() + klen,
    +              vlen + 4);
    +    } else {
    +      long offset = keyOffsets[rowId];
    +      vlen = Platform.getInt(currentAndOnlyBase, offset - 8) - klen - 4;
    +      valueRow.pointTo(currentAndOnlyBase,
    +              offset + klen,
    +              vlen + 4);
    +    }
    +    return valueRow;
    +  }
    +
    +  public long spill(long size, MemoryConsumer trigger) throws IOException {
    +    throw new OutOfMemoryError("row batch should never spill");
    +  }
    +
    +  /**
    +   * Returns an iterator to go through all rows
    +   */
    +  public org.apache.spark.unsafe.KVIterator<UnsafeRow, UnsafeRow> rowIterator() {
    +    return new org.apache.spark.unsafe.KVIterator<UnsafeRow, UnsafeRow>() {
    +      private final UnsafeRow key = new UnsafeRow(keySchema.length());
    +      private final UnsafeRow value = new UnsafeRow(valueSchema.length());
    +
    +      private long offsetInPage = 0;
    +      private int recordsInPage = 0;
    +
    +      private int currentklen;
    +      private int currentvlen;
    +      private int totalLength;
    +
    +      private boolean inited = false;
    +
    +      private void init() {
    +        if (currentAndOnlyPage != null) {
    +          offsetInPage = currentAndOnlyPage.getBaseOffset();
    +          recordsInPage = Platform.getInt(currentAndOnlyBase, offsetInPage);
    +          offsetInPage += 4;
    +        }
    +        inited = true;
    +      }
    +
    +      @Override
    +      public boolean next() {
    +        if (!inited) init();
    +        //searching for the next non empty page is records is now zero
    +        if (recordsInPage == 0) {
    +          freeCurrentPage();
    +          return false;
    +        }
    +
    +        if (allFixedLength) {
    +          totalLength = klen + vlen + 4;
    +          currentklen = klen;
    +          currentvlen = vlen;
    +        } else {
    +          totalLength = Platform.getInt(currentAndOnlyBase, offsetInPage);
    --- End diff --
    
    Can we just subtract 4 here and above so that it's actually `totalLength` (i.e., totalLength = Platform.getInt(currentAndOnlyBase, offsetInPage) - 4;). You would then have to make slight modifications to the code below but I think it might be less confusing to read.


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


[GitHub] spark pull request #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashM...

Posted by sameeragarwal <gi...@git.apache.org>.
Github user sameeragarwal commented on a diff in the pull request:

    https://github.com/apache/spark/pull/14174#discussion_r71407743
  
    --- Diff: sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/RowBasedKeyValueBatch.java ---
    @@ -0,0 +1,322 @@
    +/*
    + * 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.catalyst.expressions;
    +
    +import java.io.IOException;
    +
    +import org.apache.spark.memory.MemoryConsumer;
    +import org.apache.spark.memory.TaskMemoryManager;
    +import org.apache.spark.sql.types.*;
    +import org.apache.spark.unsafe.memory.MemoryBlock;
    +import org.apache.spark.unsafe.Platform;
    +
    +
    +/**
    + * RowBasedKeyValueBatch stores key value pairs in contiguous memory region.
    + *
    + * Each key or value is stored as a single UnsafeRow. The format for each record looks like this:
    + * [4 bytes total size = (klen + vlen + 4)] [4 bytes key size = klen]
    + * [UnsafeRow for key of length klen] [UnsafeRow for Value of length vlen]
    + * [8 bytes pointer to next]
    + * Thus, record length = 8 + klen + vlen + 8
    + *
    + * RowBasedKeyValueBatch will automatically acquire new pages (MemoryBlock) when the current page
    + * is used up.
    + *
    + * TODO: making each entry more compact, e.g., combine key and value into a single UnsafeRow
    + */
    +public final class RowBasedKeyValueBatch extends MemoryConsumer{
    +  private static final int DEFAULT_CAPACITY = 1 << 16;
    +  private static final long DEFAULT_PAGE_SIZE = 64 * 1024 * 1024;
    +
    +  private final StructType keySchema;
    +  private final StructType valueSchema;
    +  private final int capacity;
    +  private int numRows = 0;
    +
    +  // Staging row returned from getRow.
    +  final UnsafeRow keyRow;
    +  final UnsafeRow valueRow;
    +
    +  // ids for current key row and value row being retrieved
    +  private int keyRowId = -1;
    +
    +  // full addresses for key rows and value rows
    +  private long[] keyOffsets;
    +
    +  // if all data types in the schema are fixed length
    +  private boolean allFixedLength;
    +  private int klen;
    +  private int vlen;
    +  private int recordLength;
    +
    +  private MemoryBlock currentAndOnlyPage = null;
    +  private Object currentAndOnlyBase = null;
    +  private long recordStartOffset;
    +  private long pageCursor = 0;
    +
    +  public static RowBasedKeyValueBatch allocate(StructType keySchema, StructType valueSchema,
    +                                               TaskMemoryManager manager) {
    +    return new RowBasedKeyValueBatch(keySchema, valueSchema, DEFAULT_CAPACITY, manager);
    +  }
    +
    +  public static RowBasedKeyValueBatch allocate(StructType keySchema, StructType valueSchema,
    +                                               TaskMemoryManager manager, int maxRows) {
    +    return new RowBasedKeyValueBatch(keySchema, valueSchema, maxRows, manager);
    +  }
    +
    +  public int numRows() { return numRows; }
    +
    +  public void close() {
    +    if (currentAndOnlyPage != null) {
    +      freePage(currentAndOnlyPage);
    +      currentAndOnlyPage = null;
    +    }
    +  }
    +
    +  private boolean acquireNewPage(long required) {
    +    try {
    +      currentAndOnlyPage = allocatePage(required);
    +    } catch (OutOfMemoryError e) {
    +      return false;
    +    }
    +    currentAndOnlyBase = currentAndOnlyPage.getBaseObject();
    +    Platform.putInt(currentAndOnlyBase, currentAndOnlyPage.getBaseOffset(), 0);
    +    pageCursor = 4;
    +    recordStartOffset = pageCursor + currentAndOnlyPage.getBaseOffset();
    +
    +    return true;
    +  }
    +
    +  private long getKeyOffsetForFixedLengthRecords(int rowId) {
    +    return recordStartOffset + rowId * recordLength + 8;
    +  }
    +
    +  public UnsafeRow appendRow(Object kbase, long koff, int klen,
    +                             Object vbase, long voff, int vlen) {
    +    final long recordLength = 8 + klen + vlen + 8;
    +    // if run out of max supported rows or page size, return null
    +    if (numRows >= capacity || currentAndOnlyPage == null
    +            || currentAndOnlyPage.size() - pageCursor < recordLength) {
    +      return null;
    +    }
    +
    +    final Object base = currentAndOnlyBase;
    +    long offset = currentAndOnlyPage.getBaseOffset() + pageCursor;
    +    final long recordOffset = offset;
    +    if (!allFixedLength) { // we only put lengths info for variable length
    +      Platform.putInt(base, offset, klen + vlen + 4);
    +      Platform.putInt(base, offset + 4, klen);
    +    }
    +    offset += 8;
    +    Platform.copyMemory(kbase, koff, base, offset, klen);
    +    offset += klen;
    +    Platform.copyMemory(vbase, voff, base, offset, vlen);
    +    offset += vlen;
    +    Platform.putLong(base, offset, 0);
    +
    +    offset = currentAndOnlyPage.getBaseOffset();
    +    Platform.putInt(base, offset, Platform.getInt(base, offset) + 1);
    +    pageCursor += recordLength;
    +
    +
    +    if (!allFixedLength) keyOffsets[numRows] = recordOffset + 8;
    +
    +    keyRowId = numRows;
    +    keyRow.pointTo(base, recordOffset + 8, klen);
    +    valueRow.pointTo(base, recordOffset + 8 + klen, vlen + 4);
    +    numRows++;
    +    return valueRow;
    +  }
    +
    +  /**
    +   * Returns the key row in this batch at `rowId`. Returned key row is reused across calls.
    +   */
    +  public UnsafeRow getKeyRow(int rowId) {
    +    assert(rowId >= 0);
    +    assert(rowId < numRows);
    +    if (keyRowId != rowId) { // if keyRowId == rowId, desired keyRow is already cached
    +      if (allFixedLength) {
    +        long offset = getKeyOffsetForFixedLengthRecords(rowId);
    +        keyRow.pointTo(currentAndOnlyBase, offset, klen);
    +      } else {
    +        long offset = keyOffsets[rowId];
    +        klen = Platform.getInt(currentAndOnlyBase, offset - 4);
    +        keyRow.pointTo(currentAndOnlyBase, offset, klen);
    +      }
    +      // set keyRowId so we can check if desired row is cached
    +      keyRowId = rowId;
    +    }
    +    return keyRow;
    +  }
    +
    +  /**
    +   * Returns the value row in this batch at `rowId`.
    +   * It can be a faster path if `keyRowId` is equal to `rowId`, which means the preceding
    +   * key row has just been accessed. This is always the case so far.
    +   * Returned value row is reused across calls.
    +   */
    +  public UnsafeRow getValueRow(int rowId) {
    +    return getValueFromKey(rowId);
    +  }
    +
    +  /**
    +   * Returns the value row in this batch at `rowId`.
    +   * It can be a faster path if `keyRowId` is equal to `rowId`, which means the preceding
    +   * key row has just been accessed. This is always the case so far.
    +   * Returned value row is reused across calls.
    +   */
    +  private UnsafeRow getValueFromKey(int rowId) {
    +    if (keyRowId != rowId) {
    +      getKeyRow(rowId);
    +    }
    +    assert(rowId >= 0);
    +    if (allFixedLength) {
    +      valueRow.pointTo(currentAndOnlyBase,
    +              keyRow.getBaseOffset() + klen,
    +              vlen + 4);
    +    } else {
    +      long offset = keyOffsets[rowId];
    +      vlen = Platform.getInt(currentAndOnlyBase, offset - 8) - klen - 4;
    +      valueRow.pointTo(currentAndOnlyBase,
    +              offset + klen,
    +              vlen + 4);
    +    }
    +    return valueRow;
    +  }
    +
    +  public long spill(long size, MemoryConsumer trigger) throws IOException {
    +    throw new OutOfMemoryError("row batch should never spill");
    +  }
    +
    +  /**
    +   * Returns an iterator to go through all rows
    +   */
    +  public org.apache.spark.unsafe.KVIterator<UnsafeRow, UnsafeRow> rowIterator() {
    +    return new org.apache.spark.unsafe.KVIterator<UnsafeRow, UnsafeRow>() {
    +      private final UnsafeRow key = new UnsafeRow(keySchema.length());
    +      private final UnsafeRow value = new UnsafeRow(valueSchema.length());
    +
    +      private long offsetInPage = 0;
    +      private int recordsInPage = 0;
    +
    +      private int currentklen;
    +      private int currentvlen;
    +      private int totalLength;
    +
    +      private boolean inited = false;
    +
    +      private void init() {
    +        if (currentAndOnlyPage != null) {
    +          offsetInPage = currentAndOnlyPage.getBaseOffset();
    +          recordsInPage = Platform.getInt(currentAndOnlyBase, offsetInPage);
    +          offsetInPage += 4;
    +        }
    +        inited = true;
    +      }
    +
    +      @Override
    +      public boolean next() {
    +        if (!inited) init();
    +        //searching for the next non empty page is records is now zero
    +        if (recordsInPage == 0) {
    +          freeCurrentPage();
    +          return false;
    +        }
    +
    +        if (allFixedLength) {
    +          totalLength = klen + vlen + 4;
    +          currentklen = klen;
    +          currentvlen = vlen;
    +        } else {
    +          totalLength = Platform.getInt(currentAndOnlyBase, offsetInPage);
    --- End diff --
    
    In BytesToBytesMap [here](https://github.com/apache/spark/blob/master/core/src/main/java/org/apache/spark/unsafe/map/BytesToBytesMap.java#L55). It seems that it has to do something with being compatible with [UnsafeKVExternalSorter] (https://github.com/apache/spark/blob/master/sql/core/src/main/java/org/apache/spark/sql/execution/UnsafeKVExternalSorter.java#L266-L270) but I'm not sure why the latter needs it.


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


[GitHub] spark pull request #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashM...

Posted by sameeragarwal <gi...@git.apache.org>.
Github user sameeragarwal commented on a diff in the pull request:

    https://github.com/apache/spark/pull/14174#discussion_r71923918
  
    --- Diff: sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/RowBasedKeyValueBatch.java ---
    @@ -0,0 +1,182 @@
    +/*
    + * 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.catalyst.expressions;
    +
    +import java.io.IOException;
    +
    +import org.apache.spark.memory.MemoryConsumer;
    +import org.apache.spark.memory.TaskMemoryManager;
    +import org.apache.spark.sql.types.*;
    +import org.apache.spark.unsafe.memory.MemoryBlock;
    +
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +
    +/**
    + * RowBasedKeyValueBatch stores key value pairs in contiguous memory region.
    + *
    + * Each key or value is stored as a single UnsafeRow. Each record contains one key and one value
    + * and some auxiliary data, which differs based on implementation:
    + * i.e., `FixedLengthRowBasedKeyValueBatch` and `VariableLengthRowBasedKeyValueBatch`.
    + *
    + * We use `FixedLengthRowBasedKeyValueBatch` if all fiends in the key and the value are fixed-length
    --- End diff --
    
    nit: fields


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    Merged build finished. Test PASSed.


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    **[Test build #62836 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/62836/consoleFull)** for PR 14174 at commit [`5bd4bca`](https://github.com/apache/spark/commit/5bd4bca5c20cd1f59436280d641c6c3a17fef290).


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


[GitHub] spark pull request #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashM...

Posted by sameeragarwal <gi...@git.apache.org>.
Github user sameeragarwal commented on a diff in the pull request:

    https://github.com/apache/spark/pull/14174#discussion_r71253124
  
    --- Diff: sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/RowBasedKeyValueBatch.java ---
    @@ -0,0 +1,322 @@
    +/*
    + * 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.catalyst.expressions;
    +
    +import java.io.IOException;
    +
    +import org.apache.spark.memory.MemoryConsumer;
    +import org.apache.spark.memory.TaskMemoryManager;
    +import org.apache.spark.sql.types.*;
    +import org.apache.spark.unsafe.memory.MemoryBlock;
    +import org.apache.spark.unsafe.Platform;
    +
    +
    +/**
    + * RowBasedKeyValueBatch stores key value pairs in contiguous memory region.
    + *
    + * Each key or value is stored as a single UnsafeRow. The format for each record looks like this:
    + * [4 bytes total size = (klen + vlen + 4)] [4 bytes key size = klen]
    + * [UnsafeRow for key of length klen] [UnsafeRow for Value of length vlen]
    + * [8 bytes pointer to next]
    + * Thus, record length = 8 + klen + vlen + 8
    + *
    + * RowBasedKeyValueBatch will automatically acquire new pages (MemoryBlock) when the current page
    + * is used up.
    + *
    + * TODO: making each entry more compact, e.g., combine key and value into a single UnsafeRow
    + */
    +public final class RowBasedKeyValueBatch extends MemoryConsumer{
    +  private static final int DEFAULT_CAPACITY = 1 << 16;
    +  private static final long DEFAULT_PAGE_SIZE = 64 * 1024 * 1024;
    +
    +  private final StructType keySchema;
    +  private final StructType valueSchema;
    +  private final int capacity;
    +  private int numRows = 0;
    +
    +  // Staging row returned from getRow.
    +  final UnsafeRow keyRow;
    +  final UnsafeRow valueRow;
    +
    +  // ids for current key row and value row being retrieved
    +  private int keyRowId = -1;
    +
    +  // full addresses for key rows and value rows
    +  private long[] keyOffsets;
    +
    +  // if all data types in the schema are fixed length
    +  private boolean allFixedLength;
    +  private int klen;
    +  private int vlen;
    +  private int recordLength;
    +
    +  private MemoryBlock currentAndOnlyPage = null;
    --- End diff --
    
    might be just okay to call them `page` and `base` for brevity. We should make it clear in the class docs about why that's the current/only page


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    Test FAILed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/62559/
    Test FAILed.


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    **[Test build #62563 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/62563/consoleFull)** for PR 14174 at commit [`b23d737`](https://github.com/apache/spark/commit/b23d7371e80f07a2f5ed6b0963322a9db627b6cf).


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


[GitHub] spark pull request #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashM...

Posted by sameeragarwal <gi...@git.apache.org>.
Github user sameeragarwal commented on a diff in the pull request:

    https://github.com/apache/spark/pull/14174#discussion_r71253796
  
    --- Diff: sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/RowBasedKeyValueBatch.java ---
    @@ -0,0 +1,322 @@
    +/*
    + * 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.catalyst.expressions;
    +
    +import java.io.IOException;
    +
    +import org.apache.spark.memory.MemoryConsumer;
    +import org.apache.spark.memory.TaskMemoryManager;
    +import org.apache.spark.sql.types.*;
    +import org.apache.spark.unsafe.memory.MemoryBlock;
    +import org.apache.spark.unsafe.Platform;
    +
    +
    +/**
    + * RowBasedKeyValueBatch stores key value pairs in contiguous memory region.
    + *
    + * Each key or value is stored as a single UnsafeRow. The format for each record looks like this:
    + * [4 bytes total size = (klen + vlen + 4)] [4 bytes key size = klen]
    + * [UnsafeRow for key of length klen] [UnsafeRow for Value of length vlen]
    + * [8 bytes pointer to next]
    + * Thus, record length = 8 + klen + vlen + 8
    + *
    + * RowBasedKeyValueBatch will automatically acquire new pages (MemoryBlock) when the current page
    + * is used up.
    + *
    + * TODO: making each entry more compact, e.g., combine key and value into a single UnsafeRow
    + */
    +public final class RowBasedKeyValueBatch extends MemoryConsumer{
    +  private static final int DEFAULT_CAPACITY = 1 << 16;
    +  private static final long DEFAULT_PAGE_SIZE = 64 * 1024 * 1024;
    +
    +  private final StructType keySchema;
    +  private final StructType valueSchema;
    +  private final int capacity;
    +  private int numRows = 0;
    +
    +  // Staging row returned from getRow.
    +  final UnsafeRow keyRow;
    +  final UnsafeRow valueRow;
    +
    +  // ids for current key row and value row being retrieved
    +  private int keyRowId = -1;
    +
    +  // full addresses for key rows and value rows
    +  private long[] keyOffsets;
    +
    +  // if all data types in the schema are fixed length
    +  private boolean allFixedLength;
    +  private int klen;
    +  private int vlen;
    +  private int recordLength;
    +
    +  private MemoryBlock currentAndOnlyPage = null;
    +  private Object currentAndOnlyBase = null;
    +  private long recordStartOffset;
    +  private long pageCursor = 0;
    +
    +  public static RowBasedKeyValueBatch allocate(StructType keySchema, StructType valueSchema,
    +                                               TaskMemoryManager manager) {
    +    return new RowBasedKeyValueBatch(keySchema, valueSchema, DEFAULT_CAPACITY, manager);
    +  }
    +
    +  public static RowBasedKeyValueBatch allocate(StructType keySchema, StructType valueSchema,
    +                                               TaskMemoryManager manager, int maxRows) {
    +    return new RowBasedKeyValueBatch(keySchema, valueSchema, maxRows, manager);
    +  }
    +
    +  public int numRows() { return numRows; }
    +
    +  public void close() {
    +    if (currentAndOnlyPage != null) {
    +      freePage(currentAndOnlyPage);
    +      currentAndOnlyPage = null;
    +    }
    +  }
    +
    +  private boolean acquireNewPage(long required) {
    +    try {
    +      currentAndOnlyPage = allocatePage(required);
    +    } catch (OutOfMemoryError e) {
    +      return false;
    +    }
    +    currentAndOnlyBase = currentAndOnlyPage.getBaseObject();
    +    Platform.putInt(currentAndOnlyBase, currentAndOnlyPage.getBaseOffset(), 0);
    +    pageCursor = 4;
    +    recordStartOffset = pageCursor + currentAndOnlyPage.getBaseOffset();
    +
    +    return true;
    +  }
    +
    +  private long getKeyOffsetForFixedLengthRecords(int rowId) {
    +    return recordStartOffset + rowId * recordLength + 8;
    +  }
    +
    +  public UnsafeRow appendRow(Object kbase, long koff, int klen,
    +                             Object vbase, long voff, int vlen) {
    +    final long recordLength = 8 + klen + vlen + 8;
    +    // if run out of max supported rows or page size, return null
    +    if (numRows >= capacity || currentAndOnlyPage == null
    +            || currentAndOnlyPage.size() - pageCursor < recordLength) {
    +      return null;
    +    }
    +
    +    final Object base = currentAndOnlyBase;
    +    long offset = currentAndOnlyPage.getBaseOffset() + pageCursor;
    +    final long recordOffset = offset;
    +    if (!allFixedLength) { // we only put lengths info for variable length
    +      Platform.putInt(base, offset, klen + vlen + 4);
    +      Platform.putInt(base, offset + 4, klen);
    +    }
    +    offset += 8;
    +    Platform.copyMemory(kbase, koff, base, offset, klen);
    +    offset += klen;
    +    Platform.copyMemory(vbase, voff, base, offset, vlen);
    +    offset += vlen;
    +    Platform.putLong(base, offset, 0);
    +
    +    offset = currentAndOnlyPage.getBaseOffset();
    +    Platform.putInt(base, offset, Platform.getInt(base, offset) + 1);
    +    pageCursor += recordLength;
    +
    +
    --- End diff --
    
    nit: delete extra new line


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    **[Test build #62643 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/62643/consoleFull)** for PR 14174 at commit [`79ca51a`](https://github.com/apache/spark/commit/79ca51a1ba25f0fcf11d7181c276399dd09334f8).


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    **[Test build #62748 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/62748/consoleFull)** for PR 14174 at commit [`bbaf568`](https://github.com/apache/spark/commit/bbaf5680e277d4d79f1710346807c1e4fb25ba93).
     * This patch passes all tests.
     * This patch merges cleanly.
     * This patch adds no public classes.


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by ooq <gi...@git.apache.org>.
Github user ooq commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    Closing this now. Open another PR for cleaner commit history: https://github.com/apache/spark/pull/14349


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/62748/
    Test PASSed.


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    **[Test build #62453 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/62453/consoleFull)** for PR 14174 at commit [`2c1973a`](https://github.com/apache/spark/commit/2c1973a872e5b8d99a55234724ec24acbc5f70ff).


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by sameeragarwal <gi...@git.apache.org>.
Github user sameeragarwal commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    This looks pretty solid! I left some non-critical comments around readability and structuring. I'll take a pass on the test suites once those are addressed.


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by sameeragarwal <gi...@git.apache.org>.
Github user sameeragarwal commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    @ooq Thanks, can you show what the generated code looks like? Also, can we add some unit tests for these data structures? 


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    **[Test build #62749 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/62749/consoleFull)** for PR 14174 at commit [`7131a53`](https://github.com/apache/spark/commit/7131a536fe0605e9e04937e4f3ac1b13e37d7803).


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by ooq <gi...@git.apache.org>.
Github user ooq commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    Thanks for the comments @sameeragarwal . I addressed all of them and also refactored both generators to extend an abstract class `HashMapGenerator`.


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    **[Test build #62559 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/62559/consoleFull)** for PR 14174 at commit [`700e53f`](https://github.com/apache/spark/commit/700e53f4faaf5046bd02b496639fda0c3dd0d4ba).


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    **[Test build #62557 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/62557/consoleFull)** for PR 14174 at commit [`b988d1d`](https://github.com/apache/spark/commit/b988d1dd7030edc603d054f09d2d23c29ea5603d).


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    **[Test build #62836 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/62836/consoleFull)** for PR 14174 at commit [`5bd4bca`](https://github.com/apache/spark/commit/5bd4bca5c20cd1f59436280d641c6c3a17fef290).
     * This patch passes all tests.
     * This patch merges cleanly.
     * This patch adds no public classes.


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/62497/
    Test PASSed.


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    **[Test build #62230 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/62230/consoleFull)** for PR 14174 at commit [`45641e5`](https://github.com/apache/spark/commit/45641e5a7df341522518b19bf4a4662d14d64b48).


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    Merged build finished. Test PASSed.


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


[GitHub] spark pull request #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashM...

Posted by sameeragarwal <gi...@git.apache.org>.
Github user sameeragarwal commented on a diff in the pull request:

    https://github.com/apache/spark/pull/14174#discussion_r71253933
  
    --- Diff: sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/RowBasedKeyValueBatch.java ---
    @@ -0,0 +1,322 @@
    +/*
    + * 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.catalyst.expressions;
    +
    +import java.io.IOException;
    +
    +import org.apache.spark.memory.MemoryConsumer;
    +import org.apache.spark.memory.TaskMemoryManager;
    +import org.apache.spark.sql.types.*;
    +import org.apache.spark.unsafe.memory.MemoryBlock;
    +import org.apache.spark.unsafe.Platform;
    +
    +
    +/**
    + * RowBasedKeyValueBatch stores key value pairs in contiguous memory region.
    + *
    + * Each key or value is stored as a single UnsafeRow. The format for each record looks like this:
    + * [4 bytes total size = (klen + vlen + 4)] [4 bytes key size = klen]
    + * [UnsafeRow for key of length klen] [UnsafeRow for Value of length vlen]
    + * [8 bytes pointer to next]
    + * Thus, record length = 8 + klen + vlen + 8
    + *
    + * RowBasedKeyValueBatch will automatically acquire new pages (MemoryBlock) when the current page
    + * is used up.
    + *
    + * TODO: making each entry more compact, e.g., combine key and value into a single UnsafeRow
    + */
    +public final class RowBasedKeyValueBatch extends MemoryConsumer{
    +  private static final int DEFAULT_CAPACITY = 1 << 16;
    +  private static final long DEFAULT_PAGE_SIZE = 64 * 1024 * 1024;
    +
    +  private final StructType keySchema;
    +  private final StructType valueSchema;
    +  private final int capacity;
    +  private int numRows = 0;
    +
    +  // Staging row returned from getRow.
    +  final UnsafeRow keyRow;
    +  final UnsafeRow valueRow;
    +
    +  // ids for current key row and value row being retrieved
    +  private int keyRowId = -1;
    +
    +  // full addresses for key rows and value rows
    +  private long[] keyOffsets;
    +
    +  // if all data types in the schema are fixed length
    +  private boolean allFixedLength;
    +  private int klen;
    +  private int vlen;
    +  private int recordLength;
    +
    +  private MemoryBlock currentAndOnlyPage = null;
    +  private Object currentAndOnlyBase = null;
    +  private long recordStartOffset;
    +  private long pageCursor = 0;
    +
    +  public static RowBasedKeyValueBatch allocate(StructType keySchema, StructType valueSchema,
    +                                               TaskMemoryManager manager) {
    +    return new RowBasedKeyValueBatch(keySchema, valueSchema, DEFAULT_CAPACITY, manager);
    +  }
    +
    +  public static RowBasedKeyValueBatch allocate(StructType keySchema, StructType valueSchema,
    +                                               TaskMemoryManager manager, int maxRows) {
    +    return new RowBasedKeyValueBatch(keySchema, valueSchema, maxRows, manager);
    +  }
    +
    +  public int numRows() { return numRows; }
    +
    +  public void close() {
    +    if (currentAndOnlyPage != null) {
    +      freePage(currentAndOnlyPage);
    +      currentAndOnlyPage = null;
    +    }
    +  }
    +
    +  private boolean acquireNewPage(long required) {
    +    try {
    +      currentAndOnlyPage = allocatePage(required);
    +    } catch (OutOfMemoryError e) {
    +      return false;
    +    }
    +    currentAndOnlyBase = currentAndOnlyPage.getBaseObject();
    +    Platform.putInt(currentAndOnlyBase, currentAndOnlyPage.getBaseOffset(), 0);
    +    pageCursor = 4;
    +    recordStartOffset = pageCursor + currentAndOnlyPage.getBaseOffset();
    +
    +    return true;
    +  }
    +
    +  private long getKeyOffsetForFixedLengthRecords(int rowId) {
    +    return recordStartOffset + rowId * recordLength + 8;
    +  }
    +
    +  public UnsafeRow appendRow(Object kbase, long koff, int klen,
    +                             Object vbase, long voff, int vlen) {
    +    final long recordLength = 8 + klen + vlen + 8;
    +    // if run out of max supported rows or page size, return null
    +    if (numRows >= capacity || currentAndOnlyPage == null
    +            || currentAndOnlyPage.size() - pageCursor < recordLength) {
    +      return null;
    +    }
    +
    +    final Object base = currentAndOnlyBase;
    +    long offset = currentAndOnlyPage.getBaseOffset() + pageCursor;
    +    final long recordOffset = offset;
    +    if (!allFixedLength) { // we only put lengths info for variable length
    +      Platform.putInt(base, offset, klen + vlen + 4);
    +      Platform.putInt(base, offset + 4, klen);
    +    }
    +    offset += 8;
    +    Platform.copyMemory(kbase, koff, base, offset, klen);
    +    offset += klen;
    +    Platform.copyMemory(vbase, voff, base, offset, vlen);
    +    offset += vlen;
    +    Platform.putLong(base, offset, 0);
    +
    +    offset = currentAndOnlyPage.getBaseOffset();
    +    Platform.putInt(base, offset, Platform.getInt(base, offset) + 1);
    +    pageCursor += recordLength;
    +
    +
    +    if (!allFixedLength) keyOffsets[numRows] = recordOffset + 8;
    +
    +    keyRowId = numRows;
    +    keyRow.pointTo(base, recordOffset + 8, klen);
    +    valueRow.pointTo(base, recordOffset + 8 + klen, vlen + 4);
    +    numRows++;
    +    return valueRow;
    +  }
    +
    +  /**
    +   * Returns the key row in this batch at `rowId`. Returned key row is reused across calls.
    +   */
    +  public UnsafeRow getKeyRow(int rowId) {
    +    assert(rowId >= 0);
    +    assert(rowId < numRows);
    +    if (keyRowId != rowId) { // if keyRowId == rowId, desired keyRow is already cached
    +      if (allFixedLength) {
    +        long offset = getKeyOffsetForFixedLengthRecords(rowId);
    +        keyRow.pointTo(currentAndOnlyBase, offset, klen);
    +      } else {
    +        long offset = keyOffsets[rowId];
    +        klen = Platform.getInt(currentAndOnlyBase, offset - 4);
    +        keyRow.pointTo(currentAndOnlyBase, offset, klen);
    +      }
    +      // set keyRowId so we can check if desired row is cached
    +      keyRowId = rowId;
    +    }
    +    return keyRow;
    +  }
    +
    +  /**
    +   * Returns the value row in this batch at `rowId`.
    +   * It can be a faster path if `keyRowId` is equal to `rowId`, which means the preceding
    +   * key row has just been accessed. This is always the case so far.
    +   * Returned value row is reused across calls.
    +   */
    +  public UnsafeRow getValueRow(int rowId) {
    +    return getValueFromKey(rowId);
    +  }
    +
    +  /**
    +   * Returns the value row in this batch at `rowId`.
    +   * It can be a faster path if `keyRowId` is equal to `rowId`, which means the preceding
    +   * key row has just been accessed. This is always the case so far.
    +   * Returned value row is reused across calls.
    +   */
    +  private UnsafeRow getValueFromKey(int rowId) {
    +    if (keyRowId != rowId) {
    +      getKeyRow(rowId);
    +    }
    +    assert(rowId >= 0);
    +    if (allFixedLength) {
    +      valueRow.pointTo(currentAndOnlyBase,
    +              keyRow.getBaseOffset() + klen,
    +              vlen + 4);
    +    } else {
    +      long offset = keyOffsets[rowId];
    +      vlen = Platform.getInt(currentAndOnlyBase, offset - 8) - klen - 4;
    +      valueRow.pointTo(currentAndOnlyBase,
    +              offset + klen,
    +              vlen + 4);
    --- End diff --
    
    out of curiosity, why do we need to add 4 here?


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


[GitHub] spark pull request #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashM...

Posted by sameeragarwal <gi...@git.apache.org>.
Github user sameeragarwal commented on a diff in the pull request:

    https://github.com/apache/spark/pull/14174#discussion_r71253615
  
    --- Diff: sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/RowBasedKeyValueBatch.java ---
    @@ -0,0 +1,322 @@
    +/*
    + * 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.catalyst.expressions;
    +
    +import java.io.IOException;
    +
    +import org.apache.spark.memory.MemoryConsumer;
    +import org.apache.spark.memory.TaskMemoryManager;
    +import org.apache.spark.sql.types.*;
    +import org.apache.spark.unsafe.memory.MemoryBlock;
    +import org.apache.spark.unsafe.Platform;
    +
    +
    +/**
    + * RowBasedKeyValueBatch stores key value pairs in contiguous memory region.
    + *
    + * Each key or value is stored as a single UnsafeRow. The format for each record looks like this:
    + * [4 bytes total size = (klen + vlen + 4)] [4 bytes key size = klen]
    + * [UnsafeRow for key of length klen] [UnsafeRow for Value of length vlen]
    + * [8 bytes pointer to next]
    + * Thus, record length = 8 + klen + vlen + 8
    + *
    + * RowBasedKeyValueBatch will automatically acquire new pages (MemoryBlock) when the current page
    + * is used up.
    + *
    + * TODO: making each entry more compact, e.g., combine key and value into a single UnsafeRow
    + */
    +public final class RowBasedKeyValueBatch extends MemoryConsumer{
    +  private static final int DEFAULT_CAPACITY = 1 << 16;
    +  private static final long DEFAULT_PAGE_SIZE = 64 * 1024 * 1024;
    +
    +  private final StructType keySchema;
    +  private final StructType valueSchema;
    +  private final int capacity;
    +  private int numRows = 0;
    +
    +  // Staging row returned from getRow.
    +  final UnsafeRow keyRow;
    +  final UnsafeRow valueRow;
    +
    +  // ids for current key row and value row being retrieved
    +  private int keyRowId = -1;
    +
    +  // full addresses for key rows and value rows
    +  private long[] keyOffsets;
    +
    +  // if all data types in the schema are fixed length
    +  private boolean allFixedLength;
    +  private int klen;
    +  private int vlen;
    +  private int recordLength;
    +
    +  private MemoryBlock currentAndOnlyPage = null;
    +  private Object currentAndOnlyBase = null;
    +  private long recordStartOffset;
    +  private long pageCursor = 0;
    +
    +  public static RowBasedKeyValueBatch allocate(StructType keySchema, StructType valueSchema,
    +                                               TaskMemoryManager manager) {
    +    return new RowBasedKeyValueBatch(keySchema, valueSchema, DEFAULT_CAPACITY, manager);
    +  }
    +
    +  public static RowBasedKeyValueBatch allocate(StructType keySchema, StructType valueSchema,
    +                                               TaskMemoryManager manager, int maxRows) {
    +    return new RowBasedKeyValueBatch(keySchema, valueSchema, maxRows, manager);
    +  }
    +
    +  public int numRows() { return numRows; }
    +
    +  public void close() {
    +    if (currentAndOnlyPage != null) {
    +      freePage(currentAndOnlyPage);
    +      currentAndOnlyPage = null;
    +    }
    +  }
    +
    +  private boolean acquireNewPage(long required) {
    +    try {
    +      currentAndOnlyPage = allocatePage(required);
    +    } catch (OutOfMemoryError e) {
    +      return false;
    +    }
    +    currentAndOnlyBase = currentAndOnlyPage.getBaseObject();
    +    Platform.putInt(currentAndOnlyBase, currentAndOnlyPage.getBaseOffset(), 0);
    +    pageCursor = 4;
    +    recordStartOffset = pageCursor + currentAndOnlyPage.getBaseOffset();
    +
    +    return true;
    +  }
    +
    +  private long getKeyOffsetForFixedLengthRecords(int rowId) {
    +    return recordStartOffset + rowId * recordLength + 8;
    +  }
    +
    +  public UnsafeRow appendRow(Object kbase, long koff, int klen,
    +                             Object vbase, long voff, int vlen) {
    +    final long recordLength = 8 + klen + vlen + 8;
    +    // if run out of max supported rows or page size, return null
    +    if (numRows >= capacity || currentAndOnlyPage == null
    +            || currentAndOnlyPage.size() - pageCursor < recordLength) {
    +      return null;
    +    }
    +
    +    final Object base = currentAndOnlyBase;
    +    long offset = currentAndOnlyPage.getBaseOffset() + pageCursor;
    +    final long recordOffset = offset;
    +    if (!allFixedLength) { // we only put lengths info for variable length
    +      Platform.putInt(base, offset, klen + vlen + 4);
    +      Platform.putInt(base, offset + 4, klen);
    +    }
    +    offset += 8;
    --- End diff --
    
    We seem to be wasting space here for fixed length. As discussed offline, let's just have the fixed length case in a different class that extends this class (or a common base class). This would significantly make it easier to reason about the 2 cases. As a side affect, we can then also set klen, vlen etc. to final for the fixed length case.


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    **[Test build #62559 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/62559/consoleFull)** for PR 14174 at commit [`700e53f`](https://github.com/apache/spark/commit/700e53f4faaf5046bd02b496639fda0c3dd0d4ba).
     * This patch **fails to build**.
     * This patch merges cleanly.
     * This patch adds the following public classes _(experimental)_:
      * `abstract class HashMapGenerator(`
      * `  case class Buffer(dataType: DataType, name: String)`


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


[GitHub] spark pull request #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashM...

Posted by sameeragarwal <gi...@git.apache.org>.
Github user sameeragarwal commented on a diff in the pull request:

    https://github.com/apache/spark/pull/14174#discussion_r71254034
  
    --- Diff: sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/RowBasedKeyValueBatch.java ---
    @@ -0,0 +1,322 @@
    +/*
    + * 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.catalyst.expressions;
    +
    +import java.io.IOException;
    +
    +import org.apache.spark.memory.MemoryConsumer;
    +import org.apache.spark.memory.TaskMemoryManager;
    +import org.apache.spark.sql.types.*;
    +import org.apache.spark.unsafe.memory.MemoryBlock;
    +import org.apache.spark.unsafe.Platform;
    +
    +
    +/**
    + * RowBasedKeyValueBatch stores key value pairs in contiguous memory region.
    + *
    + * Each key or value is stored as a single UnsafeRow. The format for each record looks like this:
    + * [4 bytes total size = (klen + vlen + 4)] [4 bytes key size = klen]
    + * [UnsafeRow for key of length klen] [UnsafeRow for Value of length vlen]
    + * [8 bytes pointer to next]
    + * Thus, record length = 8 + klen + vlen + 8
    + *
    + * RowBasedKeyValueBatch will automatically acquire new pages (MemoryBlock) when the current page
    + * is used up.
    + *
    + * TODO: making each entry more compact, e.g., combine key and value into a single UnsafeRow
    + */
    +public final class RowBasedKeyValueBatch extends MemoryConsumer{
    +  private static final int DEFAULT_CAPACITY = 1 << 16;
    +  private static final long DEFAULT_PAGE_SIZE = 64 * 1024 * 1024;
    +
    +  private final StructType keySchema;
    +  private final StructType valueSchema;
    +  private final int capacity;
    +  private int numRows = 0;
    +
    +  // Staging row returned from getRow.
    +  final UnsafeRow keyRow;
    +  final UnsafeRow valueRow;
    +
    +  // ids for current key row and value row being retrieved
    +  private int keyRowId = -1;
    +
    +  // full addresses for key rows and value rows
    +  private long[] keyOffsets;
    +
    +  // if all data types in the schema are fixed length
    +  private boolean allFixedLength;
    +  private int klen;
    +  private int vlen;
    +  private int recordLength;
    +
    +  private MemoryBlock currentAndOnlyPage = null;
    +  private Object currentAndOnlyBase = null;
    +  private long recordStartOffset;
    +  private long pageCursor = 0;
    +
    +  public static RowBasedKeyValueBatch allocate(StructType keySchema, StructType valueSchema,
    +                                               TaskMemoryManager manager) {
    +    return new RowBasedKeyValueBatch(keySchema, valueSchema, DEFAULT_CAPACITY, manager);
    +  }
    +
    +  public static RowBasedKeyValueBatch allocate(StructType keySchema, StructType valueSchema,
    +                                               TaskMemoryManager manager, int maxRows) {
    +    return new RowBasedKeyValueBatch(keySchema, valueSchema, maxRows, manager);
    +  }
    +
    +  public int numRows() { return numRows; }
    +
    +  public void close() {
    +    if (currentAndOnlyPage != null) {
    +      freePage(currentAndOnlyPage);
    +      currentAndOnlyPage = null;
    +    }
    +  }
    +
    +  private boolean acquireNewPage(long required) {
    +    try {
    +      currentAndOnlyPage = allocatePage(required);
    +    } catch (OutOfMemoryError e) {
    +      return false;
    +    }
    +    currentAndOnlyBase = currentAndOnlyPage.getBaseObject();
    +    Platform.putInt(currentAndOnlyBase, currentAndOnlyPage.getBaseOffset(), 0);
    +    pageCursor = 4;
    +    recordStartOffset = pageCursor + currentAndOnlyPage.getBaseOffset();
    +
    +    return true;
    +  }
    +
    +  private long getKeyOffsetForFixedLengthRecords(int rowId) {
    +    return recordStartOffset + rowId * recordLength + 8;
    +  }
    +
    +  public UnsafeRow appendRow(Object kbase, long koff, int klen,
    +                             Object vbase, long voff, int vlen) {
    +    final long recordLength = 8 + klen + vlen + 8;
    +    // if run out of max supported rows or page size, return null
    +    if (numRows >= capacity || currentAndOnlyPage == null
    +            || currentAndOnlyPage.size() - pageCursor < recordLength) {
    +      return null;
    +    }
    +
    +    final Object base = currentAndOnlyBase;
    +    long offset = currentAndOnlyPage.getBaseOffset() + pageCursor;
    +    final long recordOffset = offset;
    +    if (!allFixedLength) { // we only put lengths info for variable length
    +      Platform.putInt(base, offset, klen + vlen + 4);
    +      Platform.putInt(base, offset + 4, klen);
    +    }
    +    offset += 8;
    +    Platform.copyMemory(kbase, koff, base, offset, klen);
    +    offset += klen;
    +    Platform.copyMemory(vbase, voff, base, offset, vlen);
    +    offset += vlen;
    +    Platform.putLong(base, offset, 0);
    +
    +    offset = currentAndOnlyPage.getBaseOffset();
    +    Platform.putInt(base, offset, Platform.getInt(base, offset) + 1);
    +    pageCursor += recordLength;
    +
    +
    +    if (!allFixedLength) keyOffsets[numRows] = recordOffset + 8;
    +
    +    keyRowId = numRows;
    +    keyRow.pointTo(base, recordOffset + 8, klen);
    +    valueRow.pointTo(base, recordOffset + 8 + klen, vlen + 4);
    +    numRows++;
    +    return valueRow;
    +  }
    +
    +  /**
    +   * Returns the key row in this batch at `rowId`. Returned key row is reused across calls.
    +   */
    +  public UnsafeRow getKeyRow(int rowId) {
    +    assert(rowId >= 0);
    +    assert(rowId < numRows);
    +    if (keyRowId != rowId) { // if keyRowId == rowId, desired keyRow is already cached
    +      if (allFixedLength) {
    +        long offset = getKeyOffsetForFixedLengthRecords(rowId);
    +        keyRow.pointTo(currentAndOnlyBase, offset, klen);
    +      } else {
    +        long offset = keyOffsets[rowId];
    +        klen = Platform.getInt(currentAndOnlyBase, offset - 4);
    +        keyRow.pointTo(currentAndOnlyBase, offset, klen);
    +      }
    +      // set keyRowId so we can check if desired row is cached
    +      keyRowId = rowId;
    +    }
    +    return keyRow;
    +  }
    +
    +  /**
    +   * Returns the value row in this batch at `rowId`.
    +   * It can be a faster path if `keyRowId` is equal to `rowId`, which means the preceding
    +   * key row has just been accessed. This is always the case so far.
    +   * Returned value row is reused across calls.
    +   */
    +  public UnsafeRow getValueRow(int rowId) {
    +    return getValueFromKey(rowId);
    +  }
    +
    +  /**
    +   * Returns the value row in this batch at `rowId`.
    +   * It can be a faster path if `keyRowId` is equal to `rowId`, which means the preceding
    +   * key row has just been accessed. This is always the case so far.
    +   * Returned value row is reused across calls.
    +   */
    +  private UnsafeRow getValueFromKey(int rowId) {
    +    if (keyRowId != rowId) {
    +      getKeyRow(rowId);
    +    }
    +    assert(rowId >= 0);
    +    if (allFixedLength) {
    +      valueRow.pointTo(currentAndOnlyBase,
    +              keyRow.getBaseOffset() + klen,
    +              vlen + 4);
    +    } else {
    +      long offset = keyOffsets[rowId];
    +      vlen = Platform.getInt(currentAndOnlyBase, offset - 8) - klen - 4;
    +      valueRow.pointTo(currentAndOnlyBase,
    +              offset + klen,
    +              vlen + 4);
    +    }
    +    return valueRow;
    +  }
    +
    +  public long spill(long size, MemoryConsumer trigger) throws IOException {
    +    throw new OutOfMemoryError("row batch should never spill");
    +  }
    +
    +  /**
    +   * Returns an iterator to go through all rows
    +   */
    +  public org.apache.spark.unsafe.KVIterator<UnsafeRow, UnsafeRow> rowIterator() {
    +    return new org.apache.spark.unsafe.KVIterator<UnsafeRow, UnsafeRow>() {
    +      private final UnsafeRow key = new UnsafeRow(keySchema.length());
    +      private final UnsafeRow value = new UnsafeRow(valueSchema.length());
    +
    +      private long offsetInPage = 0;
    +      private int recordsInPage = 0;
    +
    +      private int currentklen;
    +      private int currentvlen;
    +      private int totalLength;
    +
    +      private boolean inited = false;
    --- End diff --
    
    nit: maybe `initialized`?


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    **[Test build #62483 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/62483/consoleFull)** for PR 14174 at commit [`8f538b1`](https://github.com/apache/spark/commit/8f538b177e36ccc5fb690a3b29eb03ca72d1a4b2).
     * This patch passes all tests.
     * This patch merges cleanly.
     * This patch adds no public classes.


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


[GitHub] spark pull request #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashM...

Posted by ooq <gi...@git.apache.org>.
Github user ooq commented on a diff in the pull request:

    https://github.com/apache/spark/pull/14174#discussion_r71253773
  
    --- Diff: sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/RowBasedKeyValueBatch.java ---
    @@ -0,0 +1,322 @@
    +/*
    + * 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.catalyst.expressions;
    +
    +import java.io.IOException;
    +
    +import org.apache.spark.memory.MemoryConsumer;
    +import org.apache.spark.memory.TaskMemoryManager;
    +import org.apache.spark.sql.types.*;
    +import org.apache.spark.unsafe.memory.MemoryBlock;
    +import org.apache.spark.unsafe.Platform;
    +
    +
    +/**
    + * RowBasedKeyValueBatch stores key value pairs in contiguous memory region.
    + *
    + * Each key or value is stored as a single UnsafeRow. The format for each record looks like this:
    + * [4 bytes total size = (klen + vlen + 4)] [4 bytes key size = klen]
    + * [UnsafeRow for key of length klen] [UnsafeRow for Value of length vlen]
    + * [8 bytes pointer to next]
    + * Thus, record length = 8 + klen + vlen + 8
    + *
    + * RowBasedKeyValueBatch will automatically acquire new pages (MemoryBlock) when the current page
    + * is used up.
    + *
    + * TODO: making each entry more compact, e.g., combine key and value into a single UnsafeRow
    + */
    +public final class RowBasedKeyValueBatch extends MemoryConsumer{
    +  private static final int DEFAULT_CAPACITY = 1 << 16;
    +  private static final long DEFAULT_PAGE_SIZE = 64 * 1024 * 1024;
    +
    +  private final StructType keySchema;
    +  private final StructType valueSchema;
    +  private final int capacity;
    +  private int numRows = 0;
    +
    +  // Staging row returned from getRow.
    +  final UnsafeRow keyRow;
    +  final UnsafeRow valueRow;
    +
    +  // ids for current key row and value row being retrieved
    +  private int keyRowId = -1;
    +
    +  // full addresses for key rows and value rows
    +  private long[] keyOffsets;
    +
    +  // if all data types in the schema are fixed length
    +  private boolean allFixedLength;
    +  private int klen;
    +  private int vlen;
    +  private int recordLength;
    +
    +  private MemoryBlock currentAndOnlyPage = null;
    +  private Object currentAndOnlyBase = null;
    +  private long recordStartOffset;
    +  private long pageCursor = 0;
    +
    +  public static RowBasedKeyValueBatch allocate(StructType keySchema, StructType valueSchema,
    +                                               TaskMemoryManager manager) {
    +    return new RowBasedKeyValueBatch(keySchema, valueSchema, DEFAULT_CAPACITY, manager);
    +  }
    +
    +  public static RowBasedKeyValueBatch allocate(StructType keySchema, StructType valueSchema,
    +                                               TaskMemoryManager manager, int maxRows) {
    +    return new RowBasedKeyValueBatch(keySchema, valueSchema, maxRows, manager);
    +  }
    +
    +  public int numRows() { return numRows; }
    +
    +  public void close() {
    +    if (currentAndOnlyPage != null) {
    +      freePage(currentAndOnlyPage);
    +      currentAndOnlyPage = null;
    +    }
    +  }
    +
    +  private boolean acquireNewPage(long required) {
    +    try {
    +      currentAndOnlyPage = allocatePage(required);
    +    } catch (OutOfMemoryError e) {
    +      return false;
    +    }
    +    currentAndOnlyBase = currentAndOnlyPage.getBaseObject();
    +    Platform.putInt(currentAndOnlyBase, currentAndOnlyPage.getBaseOffset(), 0);
    +    pageCursor = 4;
    +    recordStartOffset = pageCursor + currentAndOnlyPage.getBaseOffset();
    +
    +    return true;
    +  }
    +
    +  private long getKeyOffsetForFixedLengthRecords(int rowId) {
    +    return recordStartOffset + rowId * recordLength + 8;
    +  }
    +
    +  public UnsafeRow appendRow(Object kbase, long koff, int klen,
    +                             Object vbase, long voff, int vlen) {
    +    final long recordLength = 8 + klen + vlen + 8;
    +    // if run out of max supported rows or page size, return null
    +    if (numRows >= capacity || currentAndOnlyPage == null
    +            || currentAndOnlyPage.size() - pageCursor < recordLength) {
    +      return null;
    +    }
    +
    +    final Object base = currentAndOnlyBase;
    +    long offset = currentAndOnlyPage.getBaseOffset() + pageCursor;
    +    final long recordOffset = offset;
    +    if (!allFixedLength) { // we only put lengths info for variable length
    +      Platform.putInt(base, offset, klen + vlen + 4);
    +      Platform.putInt(base, offset + 4, klen);
    +    }
    +    offset += 8;
    --- End diff --
    
    Sounds good. Let's do that.


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


[GitHub] spark pull request #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashM...

Posted by sameeragarwal <gi...@git.apache.org>.
Github user sameeragarwal commented on a diff in the pull request:

    https://github.com/apache/spark/pull/14174#discussion_r71924045
  
    --- Diff: sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/RowBasedKeyValueBatch.java ---
    @@ -0,0 +1,182 @@
    +/*
    + * 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.catalyst.expressions;
    +
    +import java.io.IOException;
    +
    +import org.apache.spark.memory.MemoryConsumer;
    +import org.apache.spark.memory.TaskMemoryManager;
    +import org.apache.spark.sql.types.*;
    +import org.apache.spark.unsafe.memory.MemoryBlock;
    +
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +
    +/**
    + * RowBasedKeyValueBatch stores key value pairs in contiguous memory region.
    + *
    + * Each key or value is stored as a single UnsafeRow. Each record contains one key and one value
    + * and some auxiliary data, which differs based on implementation:
    + * i.e., `FixedLengthRowBasedKeyValueBatch` and `VariableLengthRowBasedKeyValueBatch`.
    + *
    + * We use `FixedLengthRowBasedKeyValueBatch` if all fiends in the key and the value are fixed-length
    + * data types. Otherwise we use `VariableLengthRowBasedKeyValueBatch`.
    + *
    + * RowBasedKeyValueBatch is backed by a single page / MemoryBlock (defaults to 64MB). If the page
    + * is full, the aggregate logic should fallback to a second level, larger hash map. We intentionally
    + * use the single-page design because it simplifies memory address encoding & decoding for each
    + * key-value pair. Because the maximum capacity for RowBasedKeyValueBatch is only 2^16, it is
    + * unlikely we need a second page anyway. Filling the page requires an average size for key value
    + * pairs to be larger than 1024 bytes.
    + *
    + */
    +public abstract class RowBasedKeyValueBatch extends MemoryConsumer {
    +  protected final Logger logger = LoggerFactory.getLogger(RowBasedKeyValueBatch.class);
    +
    +  protected static final int DEFAULT_CAPACITY = 1 << 16;
    --- End diff --
    
    This and `DEFAULT_PAGE_SIZE` can probably be private?


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    Merged build finished. Test PASSed.


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    **[Test build #62222 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/62222/consoleFull)** for PR 14174 at commit [`c87f26b`](https://github.com/apache/spark/commit/c87f26b318b5d673ac95454df5c1cb9a56c677eb).
     * This patch **fails Scala style tests**.
     * This patch merges cleanly.
     * This patch adds the following public classes _(experimental)_:
      * `public final class RowBatch extends MemoryConsumer`
      * `class RowBasedHashMapGenerator(`
      * `  case class Buffer(dataType: DataType, name: String)`
      * `       |public class $generatedClassName extends org.apache.spark.memory.MemoryConsumer`


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by viirya <gi...@git.apache.org>.
Github user viirya commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    @ooq Thanks!


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    **[Test build #62453 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/62453/consoleFull)** for PR 14174 at commit [`2c1973a`](https://github.com/apache/spark/commit/2c1973a872e5b8d99a55234724ec24acbc5f70ff).
     * This patch passes all tests.
     * This patch merges cleanly.
     * This patch adds no public classes.


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by ooq <gi...@git.apache.org>.
Github user ooq commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    cc @sameeragarwal @davies @rxin 


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    Merged build finished. Test PASSed.


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/62498/
    Test PASSed.


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    **[Test build #62557 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/62557/consoleFull)** for PR 14174 at commit [`b988d1d`](https://github.com/apache/spark/commit/b988d1dd7030edc603d054f09d2d23c29ea5603d).
     * This patch passes all tests.
     * This patch merges cleanly.
     * This patch adds the following public classes _(experimental)_:
      * `public final class FixedLengthRowBasedKeyValueBatch extends RowBasedKeyValueBatch `
      * `public final class VariableLengthRowBasedKeyValueBatch extends RowBasedKeyValueBatch `


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by sameeragarwal <gi...@git.apache.org>.
Github user sameeragarwal commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    LGTM. cc @ericl


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    **[Test build #62748 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/62748/consoleFull)** for PR 14174 at commit [`bbaf568`](https://github.com/apache/spark/commit/bbaf5680e277d4d79f1710346807c1e4fb25ba93).


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


[GitHub] spark pull request #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashM...

Posted by sameeragarwal <gi...@git.apache.org>.
Github user sameeragarwal commented on a diff in the pull request:

    https://github.com/apache/spark/pull/14174#discussion_r71253283
  
    --- Diff: sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/RowBasedKeyValueBatch.java ---
    @@ -0,0 +1,322 @@
    +/*
    + * 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.catalyst.expressions;
    +
    +import java.io.IOException;
    +
    +import org.apache.spark.memory.MemoryConsumer;
    +import org.apache.spark.memory.TaskMemoryManager;
    +import org.apache.spark.sql.types.*;
    +import org.apache.spark.unsafe.memory.MemoryBlock;
    +import org.apache.spark.unsafe.Platform;
    +
    +
    +/**
    + * RowBasedKeyValueBatch stores key value pairs in contiguous memory region.
    + *
    + * Each key or value is stored as a single UnsafeRow. The format for each record looks like this:
    + * [4 bytes total size = (klen + vlen + 4)] [4 bytes key size = klen]
    + * [UnsafeRow for key of length klen] [UnsafeRow for Value of length vlen]
    + * [8 bytes pointer to next]
    + * Thus, record length = 8 + klen + vlen + 8
    + *
    + * RowBasedKeyValueBatch will automatically acquire new pages (MemoryBlock) when the current page
    + * is used up.
    + *
    + * TODO: making each entry more compact, e.g., combine key and value into a single UnsafeRow
    + */
    +public final class RowBasedKeyValueBatch extends MemoryConsumer{
    +  private static final int DEFAULT_CAPACITY = 1 << 16;
    +  private static final long DEFAULT_PAGE_SIZE = 64 * 1024 * 1024;
    +
    +  private final StructType keySchema;
    +  private final StructType valueSchema;
    +  private final int capacity;
    +  private int numRows = 0;
    +
    +  // Staging row returned from getRow.
    +  final UnsafeRow keyRow;
    +  final UnsafeRow valueRow;
    +
    +  // ids for current key row and value row being retrieved
    +  private int keyRowId = -1;
    +
    +  // full addresses for key rows and value rows
    +  private long[] keyOffsets;
    +
    +  // if all data types in the schema are fixed length
    +  private boolean allFixedLength;
    +  private int klen;
    +  private int vlen;
    +  private int recordLength;
    +
    +  private MemoryBlock currentAndOnlyPage = null;
    +  private Object currentAndOnlyBase = null;
    +  private long recordStartOffset;
    +  private long pageCursor = 0;
    +
    +  public static RowBasedKeyValueBatch allocate(StructType keySchema, StructType valueSchema,
    +                                               TaskMemoryManager manager) {
    +    return new RowBasedKeyValueBatch(keySchema, valueSchema, DEFAULT_CAPACITY, manager);
    +  }
    +
    +  public static RowBasedKeyValueBatch allocate(StructType keySchema, StructType valueSchema,
    +                                               TaskMemoryManager manager, int maxRows) {
    +    return new RowBasedKeyValueBatch(keySchema, valueSchema, maxRows, manager);
    +  }
    +
    +  public int numRows() { return numRows; }
    +
    +  public void close() {
    +    if (currentAndOnlyPage != null) {
    +      freePage(currentAndOnlyPage);
    +      currentAndOnlyPage = null;
    +    }
    +  }
    +
    +  private boolean acquireNewPage(long required) {
    +    try {
    +      currentAndOnlyPage = allocatePage(required);
    +    } catch (OutOfMemoryError e) {
    +      return false;
    +    }
    +    currentAndOnlyBase = currentAndOnlyPage.getBaseObject();
    +    Platform.putInt(currentAndOnlyBase, currentAndOnlyPage.getBaseOffset(), 0);
    +    pageCursor = 4;
    +    recordStartOffset = pageCursor + currentAndOnlyPage.getBaseOffset();
    +
    +    return true;
    +  }
    +
    +  private long getKeyOffsetForFixedLengthRecords(int rowId) {
    +    return recordStartOffset + rowId * recordLength + 8;
    --- End diff --
    
    Let's explicitly cast `recordLength` as long to prevent inadvertant overflows while multiplying 2 integers


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    Merged build finished. Test PASSed.


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    Merged build finished. Test PASSed.


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    Merged build finished. Test PASSed.


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/62563/
    Test PASSed.


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


[GitHub] spark pull request #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashM...

Posted by sameeragarwal <gi...@git.apache.org>.
Github user sameeragarwal commented on a diff in the pull request:

    https://github.com/apache/spark/pull/14174#discussion_r71253903
  
    --- Diff: sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/RowBasedKeyValueBatch.java ---
    @@ -0,0 +1,322 @@
    +/*
    + * 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.catalyst.expressions;
    +
    +import java.io.IOException;
    +
    +import org.apache.spark.memory.MemoryConsumer;
    +import org.apache.spark.memory.TaskMemoryManager;
    +import org.apache.spark.sql.types.*;
    +import org.apache.spark.unsafe.memory.MemoryBlock;
    +import org.apache.spark.unsafe.Platform;
    +
    +
    +/**
    + * RowBasedKeyValueBatch stores key value pairs in contiguous memory region.
    + *
    + * Each key or value is stored as a single UnsafeRow. The format for each record looks like this:
    + * [4 bytes total size = (klen + vlen + 4)] [4 bytes key size = klen]
    + * [UnsafeRow for key of length klen] [UnsafeRow for Value of length vlen]
    + * [8 bytes pointer to next]
    + * Thus, record length = 8 + klen + vlen + 8
    + *
    + * RowBasedKeyValueBatch will automatically acquire new pages (MemoryBlock) when the current page
    + * is used up.
    + *
    + * TODO: making each entry more compact, e.g., combine key and value into a single UnsafeRow
    + */
    +public final class RowBasedKeyValueBatch extends MemoryConsumer{
    +  private static final int DEFAULT_CAPACITY = 1 << 16;
    +  private static final long DEFAULT_PAGE_SIZE = 64 * 1024 * 1024;
    +
    +  private final StructType keySchema;
    +  private final StructType valueSchema;
    +  private final int capacity;
    +  private int numRows = 0;
    +
    +  // Staging row returned from getRow.
    +  final UnsafeRow keyRow;
    +  final UnsafeRow valueRow;
    +
    +  // ids for current key row and value row being retrieved
    +  private int keyRowId = -1;
    +
    +  // full addresses for key rows and value rows
    +  private long[] keyOffsets;
    +
    +  // if all data types in the schema are fixed length
    +  private boolean allFixedLength;
    +  private int klen;
    +  private int vlen;
    +  private int recordLength;
    +
    +  private MemoryBlock currentAndOnlyPage = null;
    +  private Object currentAndOnlyBase = null;
    +  private long recordStartOffset;
    +  private long pageCursor = 0;
    +
    +  public static RowBasedKeyValueBatch allocate(StructType keySchema, StructType valueSchema,
    +                                               TaskMemoryManager manager) {
    +    return new RowBasedKeyValueBatch(keySchema, valueSchema, DEFAULT_CAPACITY, manager);
    +  }
    +
    +  public static RowBasedKeyValueBatch allocate(StructType keySchema, StructType valueSchema,
    +                                               TaskMemoryManager manager, int maxRows) {
    +    return new RowBasedKeyValueBatch(keySchema, valueSchema, maxRows, manager);
    +  }
    +
    +  public int numRows() { return numRows; }
    +
    +  public void close() {
    +    if (currentAndOnlyPage != null) {
    +      freePage(currentAndOnlyPage);
    +      currentAndOnlyPage = null;
    +    }
    +  }
    +
    +  private boolean acquireNewPage(long required) {
    +    try {
    +      currentAndOnlyPage = allocatePage(required);
    +    } catch (OutOfMemoryError e) {
    +      return false;
    +    }
    +    currentAndOnlyBase = currentAndOnlyPage.getBaseObject();
    +    Platform.putInt(currentAndOnlyBase, currentAndOnlyPage.getBaseOffset(), 0);
    +    pageCursor = 4;
    +    recordStartOffset = pageCursor + currentAndOnlyPage.getBaseOffset();
    +
    +    return true;
    +  }
    +
    +  private long getKeyOffsetForFixedLengthRecords(int rowId) {
    +    return recordStartOffset + rowId * recordLength + 8;
    +  }
    +
    +  public UnsafeRow appendRow(Object kbase, long koff, int klen,
    +                             Object vbase, long voff, int vlen) {
    +    final long recordLength = 8 + klen + vlen + 8;
    +    // if run out of max supported rows or page size, return null
    +    if (numRows >= capacity || currentAndOnlyPage == null
    +            || currentAndOnlyPage.size() - pageCursor < recordLength) {
    +      return null;
    +    }
    +
    +    final Object base = currentAndOnlyBase;
    +    long offset = currentAndOnlyPage.getBaseOffset() + pageCursor;
    +    final long recordOffset = offset;
    +    if (!allFixedLength) { // we only put lengths info for variable length
    +      Platform.putInt(base, offset, klen + vlen + 4);
    +      Platform.putInt(base, offset + 4, klen);
    +    }
    +    offset += 8;
    +    Platform.copyMemory(kbase, koff, base, offset, klen);
    +    offset += klen;
    +    Platform.copyMemory(vbase, voff, base, offset, vlen);
    +    offset += vlen;
    +    Platform.putLong(base, offset, 0);
    +
    +    offset = currentAndOnlyPage.getBaseOffset();
    +    Platform.putInt(base, offset, Platform.getInt(base, offset) + 1);
    +    pageCursor += recordLength;
    +
    +
    +    if (!allFixedLength) keyOffsets[numRows] = recordOffset + 8;
    +
    +    keyRowId = numRows;
    +    keyRow.pointTo(base, recordOffset + 8, klen);
    +    valueRow.pointTo(base, recordOffset + 8 + klen, vlen + 4);
    +    numRows++;
    +    return valueRow;
    +  }
    +
    +  /**
    +   * Returns the key row in this batch at `rowId`. Returned key row is reused across calls.
    +   */
    +  public UnsafeRow getKeyRow(int rowId) {
    +    assert(rowId >= 0);
    +    assert(rowId < numRows);
    +    if (keyRowId != rowId) { // if keyRowId == rowId, desired keyRow is already cached
    +      if (allFixedLength) {
    +        long offset = getKeyOffsetForFixedLengthRecords(rowId);
    +        keyRow.pointTo(currentAndOnlyBase, offset, klen);
    +      } else {
    +        long offset = keyOffsets[rowId];
    +        klen = Platform.getInt(currentAndOnlyBase, offset - 4);
    +        keyRow.pointTo(currentAndOnlyBase, offset, klen);
    +      }
    +      // set keyRowId so we can check if desired row is cached
    +      keyRowId = rowId;
    +    }
    +    return keyRow;
    +  }
    +
    +  /**
    +   * Returns the value row in this batch at `rowId`.
    +   * It can be a faster path if `keyRowId` is equal to `rowId`, which means the preceding
    +   * key row has just been accessed. This is always the case so far.
    +   * Returned value row is reused across calls.
    +   */
    +  public UnsafeRow getValueRow(int rowId) {
    +    return getValueFromKey(rowId);
    +  }
    +
    +  /**
    +   * Returns the value row in this batch at `rowId`.
    +   * It can be a faster path if `keyRowId` is equal to `rowId`, which means the preceding
    +   * key row has just been accessed. This is always the case so far.
    +   * Returned value row is reused across calls.
    +   */
    +  private UnsafeRow getValueFromKey(int rowId) {
    +    if (keyRowId != rowId) {
    +      getKeyRow(rowId);
    +    }
    +    assert(rowId >= 0);
    +    if (allFixedLength) {
    +      valueRow.pointTo(currentAndOnlyBase,
    +              keyRow.getBaseOffset() + klen,
    +              vlen + 4);
    +    } else {
    +      long offset = keyOffsets[rowId];
    +      vlen = Platform.getInt(currentAndOnlyBase, offset - 8) - klen - 4;
    +      valueRow.pointTo(currentAndOnlyBase,
    --- End diff --
    
    nit: these can all be in a single line


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    **[Test build #62563 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/62563/consoleFull)** for PR 14174 at commit [`b23d737`](https://github.com/apache/spark/commit/b23d7371e80f07a2f5ed6b0963322a9db627b6cf).
     * This patch passes all tests.
     * This patch merges cleanly.
     * This patch adds no public classes.


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by viirya <gi...@git.apache.org>.
Github user viirya commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    Since it looks like a performance improvment, can you provide benchmark result?


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by ooq <gi...@git.apache.org>.
Github user ooq commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    hey @sameeragarwal, the diff of the generated code can be found here (with the left side for vectorized hashmap and right side for the new, row-based one): https://gist.github.com/ooq/d25d4de4c445752c6e1a810262c2e5c1/revisions?diff=split
    Below is my code to generate them:
    ```
      test("generated code comparison for vectorized vs. rowbased") {
        val N = 20 << 23
    
        sparkSession.conf.set("spark.sql.codegen.wholeStage", "true")
        sparkSession.conf.set("spark.sql.codegen.aggregate.map.columns.max", "30")
    
        sparkSession.range(N)
          .selectExpr(
            "id & 1023 as k1",
            "cast (id & 1023 as string) as k2")
          .createOrReplaceTempView("test")
    
        // dataframe/query
        val query = sparkSession.sql("select count(k1), sum(k1) from test group by k1, k2")
    
        // vectorized
        sparkSession.conf.set("spark.sql.codegen.aggregate.map.enforce.impl", "vectorized")
        query.queryExecution.debug.codegen()
    
        // row based
        sparkSession.conf.set("spark.sql.codegen.aggregate.map.enforce.impl", "rowbased")
        query.queryExecution.debug.codegen()
      }
    ```


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    Merged build finished. Test PASSed.


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


[GitHub] spark pull request #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashM...

Posted by sameeragarwal <gi...@git.apache.org>.
Github user sameeragarwal commented on a diff in the pull request:

    https://github.com/apache/spark/pull/14174#discussion_r71404176
  
    --- Diff: sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/RowBasedKeyValueBatch.java ---
    @@ -0,0 +1,322 @@
    +/*
    + * 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.catalyst.expressions;
    +
    +import java.io.IOException;
    +
    +import org.apache.spark.memory.MemoryConsumer;
    +import org.apache.spark.memory.TaskMemoryManager;
    +import org.apache.spark.sql.types.*;
    +import org.apache.spark.unsafe.memory.MemoryBlock;
    +import org.apache.spark.unsafe.Platform;
    +
    +
    +/**
    + * RowBasedKeyValueBatch stores key value pairs in contiguous memory region.
    + *
    + * Each key or value is stored as a single UnsafeRow. The format for each record looks like this:
    + * [4 bytes total size = (klen + vlen + 4)] [4 bytes key size = klen]
    + * [UnsafeRow for key of length klen] [UnsafeRow for Value of length vlen]
    + * [8 bytes pointer to next]
    + * Thus, record length = 8 + klen + vlen + 8
    + *
    + * RowBasedKeyValueBatch will automatically acquire new pages (MemoryBlock) when the current page
    + * is used up.
    + *
    + * TODO: making each entry more compact, e.g., combine key and value into a single UnsafeRow
    + */
    +public final class RowBasedKeyValueBatch extends MemoryConsumer{
    +  private static final int DEFAULT_CAPACITY = 1 << 16;
    +  private static final long DEFAULT_PAGE_SIZE = 64 * 1024 * 1024;
    +
    +  private final StructType keySchema;
    +  private final StructType valueSchema;
    +  private final int capacity;
    +  private int numRows = 0;
    +
    +  // Staging row returned from getRow.
    +  final UnsafeRow keyRow;
    +  final UnsafeRow valueRow;
    +
    +  // ids for current key row and value row being retrieved
    +  private int keyRowId = -1;
    +
    +  // full addresses for key rows and value rows
    +  private long[] keyOffsets;
    +
    +  // if all data types in the schema are fixed length
    +  private boolean allFixedLength;
    +  private int klen;
    +  private int vlen;
    +  private int recordLength;
    +
    +  private MemoryBlock currentAndOnlyPage = null;
    +  private Object currentAndOnlyBase = null;
    +  private long recordStartOffset;
    +  private long pageCursor = 0;
    +
    +  public static RowBasedKeyValueBatch allocate(StructType keySchema, StructType valueSchema,
    +                                               TaskMemoryManager manager) {
    +    return new RowBasedKeyValueBatch(keySchema, valueSchema, DEFAULT_CAPACITY, manager);
    +  }
    +
    +  public static RowBasedKeyValueBatch allocate(StructType keySchema, StructType valueSchema,
    +                                               TaskMemoryManager manager, int maxRows) {
    +    return new RowBasedKeyValueBatch(keySchema, valueSchema, maxRows, manager);
    +  }
    +
    +  public int numRows() { return numRows; }
    +
    +  public void close() {
    +    if (currentAndOnlyPage != null) {
    +      freePage(currentAndOnlyPage);
    +      currentAndOnlyPage = null;
    +    }
    +  }
    +
    +  private boolean acquireNewPage(long required) {
    +    try {
    +      currentAndOnlyPage = allocatePage(required);
    +    } catch (OutOfMemoryError e) {
    +      return false;
    +    }
    +    currentAndOnlyBase = currentAndOnlyPage.getBaseObject();
    +    Platform.putInt(currentAndOnlyBase, currentAndOnlyPage.getBaseOffset(), 0);
    +    pageCursor = 4;
    +    recordStartOffset = pageCursor + currentAndOnlyPage.getBaseOffset();
    +
    +    return true;
    +  }
    +
    +  private long getKeyOffsetForFixedLengthRecords(int rowId) {
    +    return recordStartOffset + rowId * recordLength + 8;
    +  }
    +
    +  public UnsafeRow appendRow(Object kbase, long koff, int klen,
    +                             Object vbase, long voff, int vlen) {
    +    final long recordLength = 8 + klen + vlen + 8;
    +    // if run out of max supported rows or page size, return null
    +    if (numRows >= capacity || currentAndOnlyPage == null
    +            || currentAndOnlyPage.size() - pageCursor < recordLength) {
    +      return null;
    +    }
    +
    +    final Object base = currentAndOnlyBase;
    +    long offset = currentAndOnlyPage.getBaseOffset() + pageCursor;
    +    final long recordOffset = offset;
    +    if (!allFixedLength) { // we only put lengths info for variable length
    +      Platform.putInt(base, offset, klen + vlen + 4);
    +      Platform.putInt(base, offset + 4, klen);
    +    }
    +    offset += 8;
    +    Platform.copyMemory(kbase, koff, base, offset, klen);
    +    offset += klen;
    +    Platform.copyMemory(vbase, voff, base, offset, vlen);
    +    offset += vlen;
    +    Platform.putLong(base, offset, 0);
    +
    +    offset = currentAndOnlyPage.getBaseOffset();
    +    Platform.putInt(base, offset, Platform.getInt(base, offset) + 1);
    +    pageCursor += recordLength;
    +
    +
    +    if (!allFixedLength) keyOffsets[numRows] = recordOffset + 8;
    +
    +    keyRowId = numRows;
    +    keyRow.pointTo(base, recordOffset + 8, klen);
    +    valueRow.pointTo(base, recordOffset + 8 + klen, vlen + 4);
    +    numRows++;
    +    return valueRow;
    +  }
    +
    +  /**
    +   * Returns the key row in this batch at `rowId`. Returned key row is reused across calls.
    +   */
    +  public UnsafeRow getKeyRow(int rowId) {
    +    assert(rowId >= 0);
    +    assert(rowId < numRows);
    +    if (keyRowId != rowId) { // if keyRowId == rowId, desired keyRow is already cached
    +      if (allFixedLength) {
    +        long offset = getKeyOffsetForFixedLengthRecords(rowId);
    +        keyRow.pointTo(currentAndOnlyBase, offset, klen);
    +      } else {
    +        long offset = keyOffsets[rowId];
    +        klen = Platform.getInt(currentAndOnlyBase, offset - 4);
    +        keyRow.pointTo(currentAndOnlyBase, offset, klen);
    +      }
    +      // set keyRowId so we can check if desired row is cached
    +      keyRowId = rowId;
    +    }
    +    return keyRow;
    +  }
    +
    +  /**
    +   * Returns the value row in this batch at `rowId`.
    +   * It can be a faster path if `keyRowId` is equal to `rowId`, which means the preceding
    +   * key row has just been accessed. This is always the case so far.
    +   * Returned value row is reused across calls.
    +   */
    +  public UnsafeRow getValueRow(int rowId) {
    +    return getValueFromKey(rowId);
    +  }
    +
    +  /**
    +   * Returns the value row in this batch at `rowId`.
    +   * It can be a faster path if `keyRowId` is equal to `rowId`, which means the preceding
    +   * key row has just been accessed. This is always the case so far.
    +   * Returned value row is reused across calls.
    +   */
    +  private UnsafeRow getValueFromKey(int rowId) {
    +    if (keyRowId != rowId) {
    +      getKeyRow(rowId);
    +    }
    +    assert(rowId >= 0);
    +    if (allFixedLength) {
    +      valueRow.pointTo(currentAndOnlyBase,
    +              keyRow.getBaseOffset() + klen,
    +              vlen + 4);
    +    } else {
    +      long offset = keyOffsets[rowId];
    +      vlen = Platform.getInt(currentAndOnlyBase, offset - 8) - klen - 4;
    +      valueRow.pointTo(currentAndOnlyBase,
    +              offset + klen,
    +              vlen + 4);
    +    }
    +    return valueRow;
    +  }
    +
    +  public long spill(long size, MemoryConsumer trigger) throws IOException {
    +    throw new OutOfMemoryError("row batch should never spill");
    +  }
    +
    +  /**
    +   * Returns an iterator to go through all rows
    +   */
    +  public org.apache.spark.unsafe.KVIterator<UnsafeRow, UnsafeRow> rowIterator() {
    +    return new org.apache.spark.unsafe.KVIterator<UnsafeRow, UnsafeRow>() {
    +      private final UnsafeRow key = new UnsafeRow(keySchema.length());
    +      private final UnsafeRow value = new UnsafeRow(valueSchema.length());
    +
    +      private long offsetInPage = 0;
    +      private int recordsInPage = 0;
    +
    +      private int currentklen;
    +      private int currentvlen;
    +      private int totalLength;
    +
    +      private boolean inited = false;
    +
    +      private void init() {
    +        if (currentAndOnlyPage != null) {
    +          offsetInPage = currentAndOnlyPage.getBaseOffset();
    +          recordsInPage = Platform.getInt(currentAndOnlyBase, offsetInPage);
    +          offsetInPage += 4;
    +        }
    +        inited = true;
    +      }
    +
    +      @Override
    +      public boolean next() {
    +        if (!inited) init();
    +        //searching for the next non empty page is records is now zero
    +        if (recordsInPage == 0) {
    +          freeCurrentPage();
    +          return false;
    +        }
    +
    +        if (allFixedLength) {
    +          totalLength = klen + vlen + 4;
    +          currentklen = klen;
    +          currentvlen = vlen;
    +        } else {
    +          totalLength = Platform.getInt(currentAndOnlyBase, offsetInPage);
    --- End diff --
    
    I'm not entirely sure why the bytes to bytes map used `klen + vlen + 4` in the first place, but it seemed intentional (@rxin do you know?). It could have something to do with the spilling logic in which case it should be safe to remove here. But if we don't find the reason, perhaps we can just add 4 to be consistent with the previous implementation for now and revisit this in future.


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/62230/
    Test PASSed.


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    **[Test build #62749 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/62749/consoleFull)** for PR 14174 at commit [`7131a53`](https://github.com/apache/spark/commit/7131a536fe0605e9e04937e4f3ac1b13e37d7803).
     * This patch passes all tests.
     * This patch merges cleanly.
     * This patch adds no public classes.


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/62557/
    Test PASSed.


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


[GitHub] spark pull request #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashM...

Posted by ooq <gi...@git.apache.org>.
Github user ooq commented on a diff in the pull request:

    https://github.com/apache/spark/pull/14174#discussion_r71402778
  
    --- Diff: sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/RowBasedKeyValueBatch.java ---
    @@ -0,0 +1,322 @@
    +/*
    + * 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.catalyst.expressions;
    +
    +import java.io.IOException;
    +
    +import org.apache.spark.memory.MemoryConsumer;
    +import org.apache.spark.memory.TaskMemoryManager;
    +import org.apache.spark.sql.types.*;
    +import org.apache.spark.unsafe.memory.MemoryBlock;
    +import org.apache.spark.unsafe.Platform;
    +
    +
    +/**
    + * RowBasedKeyValueBatch stores key value pairs in contiguous memory region.
    + *
    + * Each key or value is stored as a single UnsafeRow. The format for each record looks like this:
    + * [4 bytes total size = (klen + vlen + 4)] [4 bytes key size = klen]
    + * [UnsafeRow for key of length klen] [UnsafeRow for Value of length vlen]
    + * [8 bytes pointer to next]
    + * Thus, record length = 8 + klen + vlen + 8
    + *
    + * RowBasedKeyValueBatch will automatically acquire new pages (MemoryBlock) when the current page
    + * is used up.
    + *
    + * TODO: making each entry more compact, e.g., combine key and value into a single UnsafeRow
    + */
    +public final class RowBasedKeyValueBatch extends MemoryConsumer{
    +  private static final int DEFAULT_CAPACITY = 1 << 16;
    +  private static final long DEFAULT_PAGE_SIZE = 64 * 1024 * 1024;
    +
    +  private final StructType keySchema;
    +  private final StructType valueSchema;
    +  private final int capacity;
    +  private int numRows = 0;
    +
    +  // Staging row returned from getRow.
    +  final UnsafeRow keyRow;
    +  final UnsafeRow valueRow;
    +
    +  // ids for current key row and value row being retrieved
    +  private int keyRowId = -1;
    +
    +  // full addresses for key rows and value rows
    +  private long[] keyOffsets;
    +
    +  // if all data types in the schema are fixed length
    +  private boolean allFixedLength;
    +  private int klen;
    +  private int vlen;
    +  private int recordLength;
    +
    +  private MemoryBlock currentAndOnlyPage = null;
    +  private Object currentAndOnlyBase = null;
    +  private long recordStartOffset;
    +  private long pageCursor = 0;
    +
    +  public static RowBasedKeyValueBatch allocate(StructType keySchema, StructType valueSchema,
    +                                               TaskMemoryManager manager) {
    +    return new RowBasedKeyValueBatch(keySchema, valueSchema, DEFAULT_CAPACITY, manager);
    +  }
    +
    +  public static RowBasedKeyValueBatch allocate(StructType keySchema, StructType valueSchema,
    +                                               TaskMemoryManager manager, int maxRows) {
    +    return new RowBasedKeyValueBatch(keySchema, valueSchema, maxRows, manager);
    +  }
    +
    +  public int numRows() { return numRows; }
    +
    +  public void close() {
    +    if (currentAndOnlyPage != null) {
    +      freePage(currentAndOnlyPage);
    +      currentAndOnlyPage = null;
    +    }
    +  }
    +
    +  private boolean acquireNewPage(long required) {
    +    try {
    +      currentAndOnlyPage = allocatePage(required);
    +    } catch (OutOfMemoryError e) {
    +      return false;
    +    }
    +    currentAndOnlyBase = currentAndOnlyPage.getBaseObject();
    +    Platform.putInt(currentAndOnlyBase, currentAndOnlyPage.getBaseOffset(), 0);
    +    pageCursor = 4;
    +    recordStartOffset = pageCursor + currentAndOnlyPage.getBaseOffset();
    +
    +    return true;
    +  }
    +
    +  private long getKeyOffsetForFixedLengthRecords(int rowId) {
    +    return recordStartOffset + rowId * recordLength + 8;
    +  }
    +
    +  public UnsafeRow appendRow(Object kbase, long koff, int klen,
    +                             Object vbase, long voff, int vlen) {
    +    final long recordLength = 8 + klen + vlen + 8;
    +    // if run out of max supported rows or page size, return null
    +    if (numRows >= capacity || currentAndOnlyPage == null
    +            || currentAndOnlyPage.size() - pageCursor < recordLength) {
    +      return null;
    +    }
    +
    +    final Object base = currentAndOnlyBase;
    +    long offset = currentAndOnlyPage.getBaseOffset() + pageCursor;
    +    final long recordOffset = offset;
    +    if (!allFixedLength) { // we only put lengths info for variable length
    +      Platform.putInt(base, offset, klen + vlen + 4);
    +      Platform.putInt(base, offset + 4, klen);
    +    }
    +    offset += 8;
    +    Platform.copyMemory(kbase, koff, base, offset, klen);
    +    offset += klen;
    +    Platform.copyMemory(vbase, voff, base, offset, vlen);
    +    offset += vlen;
    +    Platform.putLong(base, offset, 0);
    +
    +    offset = currentAndOnlyPage.getBaseOffset();
    +    Platform.putInt(base, offset, Platform.getInt(base, offset) + 1);
    +    pageCursor += recordLength;
    +
    +
    +    if (!allFixedLength) keyOffsets[numRows] = recordOffset + 8;
    +
    +    keyRowId = numRows;
    +    keyRow.pointTo(base, recordOffset + 8, klen);
    +    valueRow.pointTo(base, recordOffset + 8 + klen, vlen + 4);
    +    numRows++;
    +    return valueRow;
    +  }
    +
    +  /**
    +   * Returns the key row in this batch at `rowId`. Returned key row is reused across calls.
    +   */
    +  public UnsafeRow getKeyRow(int rowId) {
    +    assert(rowId >= 0);
    +    assert(rowId < numRows);
    +    if (keyRowId != rowId) { // if keyRowId == rowId, desired keyRow is already cached
    +      if (allFixedLength) {
    +        long offset = getKeyOffsetForFixedLengthRecords(rowId);
    +        keyRow.pointTo(currentAndOnlyBase, offset, klen);
    +      } else {
    +        long offset = keyOffsets[rowId];
    +        klen = Platform.getInt(currentAndOnlyBase, offset - 4);
    +        keyRow.pointTo(currentAndOnlyBase, offset, klen);
    +      }
    +      // set keyRowId so we can check if desired row is cached
    +      keyRowId = rowId;
    +    }
    +    return keyRow;
    +  }
    +
    +  /**
    +   * Returns the value row in this batch at `rowId`.
    +   * It can be a faster path if `keyRowId` is equal to `rowId`, which means the preceding
    +   * key row has just been accessed. This is always the case so far.
    +   * Returned value row is reused across calls.
    +   */
    +  public UnsafeRow getValueRow(int rowId) {
    +    return getValueFromKey(rowId);
    +  }
    +
    +  /**
    +   * Returns the value row in this batch at `rowId`.
    +   * It can be a faster path if `keyRowId` is equal to `rowId`, which means the preceding
    +   * key row has just been accessed. This is always the case so far.
    +   * Returned value row is reused across calls.
    +   */
    +  private UnsafeRow getValueFromKey(int rowId) {
    +    if (keyRowId != rowId) {
    +      getKeyRow(rowId);
    +    }
    +    assert(rowId >= 0);
    +    if (allFixedLength) {
    +      valueRow.pointTo(currentAndOnlyBase,
    +              keyRow.getBaseOffset() + klen,
    +              vlen + 4);
    +    } else {
    +      long offset = keyOffsets[rowId];
    +      vlen = Platform.getInt(currentAndOnlyBase, offset - 8) - klen - 4;
    +      valueRow.pointTo(currentAndOnlyBase,
    +              offset + klen,
    +              vlen + 4);
    +    }
    +    return valueRow;
    +  }
    +
    +  public long spill(long size, MemoryConsumer trigger) throws IOException {
    +    throw new OutOfMemoryError("row batch should never spill");
    +  }
    +
    +  /**
    +   * Returns an iterator to go through all rows
    +   */
    +  public org.apache.spark.unsafe.KVIterator<UnsafeRow, UnsafeRow> rowIterator() {
    +    return new org.apache.spark.unsafe.KVIterator<UnsafeRow, UnsafeRow>() {
    +      private final UnsafeRow key = new UnsafeRow(keySchema.length());
    +      private final UnsafeRow value = new UnsafeRow(valueSchema.length());
    +
    +      private long offsetInPage = 0;
    +      private int recordsInPage = 0;
    +
    +      private int currentklen;
    +      private int currentvlen;
    +      private int totalLength;
    +
    +      private boolean inited = false;
    +
    +      private void init() {
    +        if (currentAndOnlyPage != null) {
    +          offsetInPage = currentAndOnlyPage.getBaseOffset();
    +          recordsInPage = Platform.getInt(currentAndOnlyBase, offsetInPage);
    +          offsetInPage += 4;
    +        }
    +        inited = true;
    +      }
    +
    +      @Override
    +      public boolean next() {
    +        if (!inited) init();
    +        //searching for the next non empty page is records is now zero
    +        if (recordsInPage == 0) {
    +          freeCurrentPage();
    +          return false;
    +        }
    +
    +        if (allFixedLength) {
    +          totalLength = klen + vlen + 4;
    +          currentklen = klen;
    +          currentvlen = vlen;
    +        } else {
    +          totalLength = Platform.getInt(currentAndOnlyBase, offsetInPage);
    --- End diff --
    
    Makes sense. Do you think it makes easier to do `Platform.putInt(base, offset, klen + vlen);` instead of `Platform.putInt(base, offset, klen + vlen + 4);`? I personally think the former is less confusing and I went with later to be consistent with previous implementations.


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


[GitHub] spark pull request #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashM...

Posted by sameeragarwal <gi...@git.apache.org>.
Github user sameeragarwal commented on a diff in the pull request:

    https://github.com/apache/spark/pull/14174#discussion_r71254476
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/RowBasedHashMapGenerator.scala ---
    @@ -0,0 +1,338 @@
    +/*
    + * 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.aggregate
    +
    +import org.apache.spark.sql.catalyst.expressions.UnsafeRow
    +import org.apache.spark.sql.catalyst.expressions.aggregate.{AggregateExpression, DeclarativeAggregate}
    +import org.apache.spark.sql.catalyst.expressions.codegen.{CodegenContext, ExprCode}
    +import org.apache.spark.sql.types._
    +
    +/**
    + * This is a helper class to generate an append-only row-based hash map that can act as a 'cache'
    + * for extremely fast key-value lookups while evaluating aggregates (and fall back to the
    + * `BytesToBytesMap` if a given key isn't found). This is 'codegened' in HashAggregate to speed
    + * up aggregates w/ key.
    + *
    + * We also have VectorizedHashMapGenerator, which generates a append-only vectorized hash map.
    + * We choose one of the two as the 1st level, fast hash map during aggregation.
    + *
    + * NOTE: This row-based hash map currently doesn't support nullable keys and falls back to the
    + * `BytesToBytesMap` to store them.
    + */
    +class RowBasedHashMapGenerator(
    --- End diff --
    
    One thing that might be nice to do (perhaps as part of a small followup PR) is to reduce the code duplication between this and the `VectorizedHashMapGenerator` by having these 2 just extend a base class `HashMapGenerator`.


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/62749/
    Test PASSed.


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    **[Test build #62230 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/62230/consoleFull)** for PR 14174 at commit [`45641e5`](https://github.com/apache/spark/commit/45641e5a7df341522518b19bf4a4662d14d64b48).
     * This patch passes all tests.
     * This patch merges cleanly.
     * This patch adds no public classes.


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/62836/
    Test PASSed.


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    Test FAILed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/62222/
    Test FAILed.


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/62643/
    Test PASSed.


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


[GitHub] spark pull request #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashM...

Posted by sameeragarwal <gi...@git.apache.org>.
Github user sameeragarwal commented on a diff in the pull request:

    https://github.com/apache/spark/pull/14174#discussion_r71252862
  
    --- Diff: sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/RowBasedKeyValueBatch.java ---
    @@ -0,0 +1,322 @@
    +/*
    + * 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.catalyst.expressions;
    +
    +import java.io.IOException;
    +
    +import org.apache.spark.memory.MemoryConsumer;
    +import org.apache.spark.memory.TaskMemoryManager;
    +import org.apache.spark.sql.types.*;
    +import org.apache.spark.unsafe.memory.MemoryBlock;
    +import org.apache.spark.unsafe.Platform;
    +
    +
    +/**
    + * RowBasedKeyValueBatch stores key value pairs in contiguous memory region.
    + *
    + * Each key or value is stored as a single UnsafeRow. The format for each record looks like this:
    + * [4 bytes total size = (klen + vlen + 4)] [4 bytes key size = klen]
    + * [UnsafeRow for key of length klen] [UnsafeRow for Value of length vlen]
    + * [8 bytes pointer to next]
    + * Thus, record length = 8 + klen + vlen + 8
    --- End diff --
    
    nit: record length = 4 + 4 + klen + vlen + 8


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    **[Test build #62498 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/62498/consoleFull)** for PR 14174 at commit [`b04ff88`](https://github.com/apache/spark/commit/b04ff887ac10ee2f9bdd66c0c83b007521b5016c).
     * This patch passes all tests.
     * This patch merges cleanly.
     * This patch adds no public classes.


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


[GitHub] spark pull request #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashM...

Posted by ooq <gi...@git.apache.org>.
Github user ooq closed the pull request at:

    https://github.com/apache/spark/pull/14174


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    Merged build finished. Test PASSed.


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    Merged build finished. Test FAILed.


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


[GitHub] spark pull request #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashM...

Posted by sameeragarwal <gi...@git.apache.org>.
Github user sameeragarwal commented on a diff in the pull request:

    https://github.com/apache/spark/pull/14174#discussion_r71253992
  
    --- Diff: sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/RowBasedKeyValueBatch.java ---
    @@ -0,0 +1,322 @@
    +/*
    + * 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.catalyst.expressions;
    +
    +import java.io.IOException;
    +
    +import org.apache.spark.memory.MemoryConsumer;
    +import org.apache.spark.memory.TaskMemoryManager;
    +import org.apache.spark.sql.types.*;
    +import org.apache.spark.unsafe.memory.MemoryBlock;
    +import org.apache.spark.unsafe.Platform;
    +
    +
    +/**
    + * RowBasedKeyValueBatch stores key value pairs in contiguous memory region.
    + *
    + * Each key or value is stored as a single UnsafeRow. The format for each record looks like this:
    + * [4 bytes total size = (klen + vlen + 4)] [4 bytes key size = klen]
    + * [UnsafeRow for key of length klen] [UnsafeRow for Value of length vlen]
    + * [8 bytes pointer to next]
    + * Thus, record length = 8 + klen + vlen + 8
    + *
    + * RowBasedKeyValueBatch will automatically acquire new pages (MemoryBlock) when the current page
    + * is used up.
    + *
    + * TODO: making each entry more compact, e.g., combine key and value into a single UnsafeRow
    + */
    +public final class RowBasedKeyValueBatch extends MemoryConsumer{
    +  private static final int DEFAULT_CAPACITY = 1 << 16;
    +  private static final long DEFAULT_PAGE_SIZE = 64 * 1024 * 1024;
    +
    +  private final StructType keySchema;
    +  private final StructType valueSchema;
    +  private final int capacity;
    +  private int numRows = 0;
    +
    +  // Staging row returned from getRow.
    +  final UnsafeRow keyRow;
    +  final UnsafeRow valueRow;
    +
    +  // ids for current key row and value row being retrieved
    +  private int keyRowId = -1;
    +
    +  // full addresses for key rows and value rows
    +  private long[] keyOffsets;
    +
    +  // if all data types in the schema are fixed length
    +  private boolean allFixedLength;
    +  private int klen;
    +  private int vlen;
    +  private int recordLength;
    +
    +  private MemoryBlock currentAndOnlyPage = null;
    +  private Object currentAndOnlyBase = null;
    +  private long recordStartOffset;
    +  private long pageCursor = 0;
    +
    +  public static RowBasedKeyValueBatch allocate(StructType keySchema, StructType valueSchema,
    +                                               TaskMemoryManager manager) {
    +    return new RowBasedKeyValueBatch(keySchema, valueSchema, DEFAULT_CAPACITY, manager);
    +  }
    +
    +  public static RowBasedKeyValueBatch allocate(StructType keySchema, StructType valueSchema,
    +                                               TaskMemoryManager manager, int maxRows) {
    +    return new RowBasedKeyValueBatch(keySchema, valueSchema, maxRows, manager);
    +  }
    +
    +  public int numRows() { return numRows; }
    +
    +  public void close() {
    +    if (currentAndOnlyPage != null) {
    +      freePage(currentAndOnlyPage);
    +      currentAndOnlyPage = null;
    +    }
    +  }
    +
    +  private boolean acquireNewPage(long required) {
    +    try {
    +      currentAndOnlyPage = allocatePage(required);
    +    } catch (OutOfMemoryError e) {
    +      return false;
    +    }
    +    currentAndOnlyBase = currentAndOnlyPage.getBaseObject();
    +    Platform.putInt(currentAndOnlyBase, currentAndOnlyPage.getBaseOffset(), 0);
    +    pageCursor = 4;
    +    recordStartOffset = pageCursor + currentAndOnlyPage.getBaseOffset();
    +
    +    return true;
    +  }
    +
    +  private long getKeyOffsetForFixedLengthRecords(int rowId) {
    +    return recordStartOffset + rowId * recordLength + 8;
    +  }
    +
    +  public UnsafeRow appendRow(Object kbase, long koff, int klen,
    +                             Object vbase, long voff, int vlen) {
    +    final long recordLength = 8 + klen + vlen + 8;
    +    // if run out of max supported rows or page size, return null
    +    if (numRows >= capacity || currentAndOnlyPage == null
    +            || currentAndOnlyPage.size() - pageCursor < recordLength) {
    +      return null;
    +    }
    +
    +    final Object base = currentAndOnlyBase;
    +    long offset = currentAndOnlyPage.getBaseOffset() + pageCursor;
    +    final long recordOffset = offset;
    +    if (!allFixedLength) { // we only put lengths info for variable length
    +      Platform.putInt(base, offset, klen + vlen + 4);
    +      Platform.putInt(base, offset + 4, klen);
    +    }
    +    offset += 8;
    +    Platform.copyMemory(kbase, koff, base, offset, klen);
    +    offset += klen;
    +    Platform.copyMemory(vbase, voff, base, offset, vlen);
    +    offset += vlen;
    +    Platform.putLong(base, offset, 0);
    +
    +    offset = currentAndOnlyPage.getBaseOffset();
    +    Platform.putInt(base, offset, Platform.getInt(base, offset) + 1);
    +    pageCursor += recordLength;
    +
    +
    +    if (!allFixedLength) keyOffsets[numRows] = recordOffset + 8;
    +
    +    keyRowId = numRows;
    +    keyRow.pointTo(base, recordOffset + 8, klen);
    +    valueRow.pointTo(base, recordOffset + 8 + klen, vlen + 4);
    +    numRows++;
    +    return valueRow;
    +  }
    +
    +  /**
    +   * Returns the key row in this batch at `rowId`. Returned key row is reused across calls.
    +   */
    +  public UnsafeRow getKeyRow(int rowId) {
    +    assert(rowId >= 0);
    +    assert(rowId < numRows);
    +    if (keyRowId != rowId) { // if keyRowId == rowId, desired keyRow is already cached
    +      if (allFixedLength) {
    +        long offset = getKeyOffsetForFixedLengthRecords(rowId);
    +        keyRow.pointTo(currentAndOnlyBase, offset, klen);
    +      } else {
    +        long offset = keyOffsets[rowId];
    +        klen = Platform.getInt(currentAndOnlyBase, offset - 4);
    +        keyRow.pointTo(currentAndOnlyBase, offset, klen);
    +      }
    +      // set keyRowId so we can check if desired row is cached
    +      keyRowId = rowId;
    +    }
    +    return keyRow;
    +  }
    +
    +  /**
    +   * Returns the value row in this batch at `rowId`.
    +   * It can be a faster path if `keyRowId` is equal to `rowId`, which means the preceding
    +   * key row has just been accessed. This is always the case so far.
    +   * Returned value row is reused across calls.
    +   */
    +  public UnsafeRow getValueRow(int rowId) {
    +    return getValueFromKey(rowId);
    +  }
    +
    +  /**
    +   * Returns the value row in this batch at `rowId`.
    +   * It can be a faster path if `keyRowId` is equal to `rowId`, which means the preceding
    +   * key row has just been accessed. This is always the case so far.
    +   * Returned value row is reused across calls.
    +   */
    +  private UnsafeRow getValueFromKey(int rowId) {
    +    if (keyRowId != rowId) {
    +      getKeyRow(rowId);
    +    }
    +    assert(rowId >= 0);
    +    if (allFixedLength) {
    +      valueRow.pointTo(currentAndOnlyBase,
    +              keyRow.getBaseOffset() + klen,
    +              vlen + 4);
    +    } else {
    +      long offset = keyOffsets[rowId];
    +      vlen = Platform.getInt(currentAndOnlyBase, offset - 8) - klen - 4;
    +      valueRow.pointTo(currentAndOnlyBase,
    +              offset + klen,
    +              vlen + 4);
    +    }
    +    return valueRow;
    +  }
    +
    +  public long spill(long size, MemoryConsumer trigger) throws IOException {
    +    throw new OutOfMemoryError("row batch should never spill");
    --- End diff --
    
    Let's log this before throwing.


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    **[Test build #62497 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/62497/consoleFull)** for PR 14174 at commit [`d939488`](https://github.com/apache/spark/commit/d9394888977c97fe95f1642ad9f613dcbee1e4fa).
     * This patch passes all tests.
     * This patch merges cleanly.
     * This patch adds no public classes.


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    Merged build finished. Test FAILed.


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


[GitHub] spark pull request #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashM...

Posted by rxin <gi...@git.apache.org>.
Github user rxin commented on a diff in the pull request:

    https://github.com/apache/spark/pull/14174#discussion_r71405503
  
    --- Diff: sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/RowBasedKeyValueBatch.java ---
    @@ -0,0 +1,322 @@
    +/*
    + * 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.catalyst.expressions;
    +
    +import java.io.IOException;
    +
    +import org.apache.spark.memory.MemoryConsumer;
    +import org.apache.spark.memory.TaskMemoryManager;
    +import org.apache.spark.sql.types.*;
    +import org.apache.spark.unsafe.memory.MemoryBlock;
    +import org.apache.spark.unsafe.Platform;
    +
    +
    +/**
    + * RowBasedKeyValueBatch stores key value pairs in contiguous memory region.
    + *
    + * Each key or value is stored as a single UnsafeRow. The format for each record looks like this:
    + * [4 bytes total size = (klen + vlen + 4)] [4 bytes key size = klen]
    + * [UnsafeRow for key of length klen] [UnsafeRow for Value of length vlen]
    + * [8 bytes pointer to next]
    + * Thus, record length = 8 + klen + vlen + 8
    + *
    + * RowBasedKeyValueBatch will automatically acquire new pages (MemoryBlock) when the current page
    + * is used up.
    + *
    + * TODO: making each entry more compact, e.g., combine key and value into a single UnsafeRow
    + */
    +public final class RowBasedKeyValueBatch extends MemoryConsumer{
    +  private static final int DEFAULT_CAPACITY = 1 << 16;
    +  private static final long DEFAULT_PAGE_SIZE = 64 * 1024 * 1024;
    +
    +  private final StructType keySchema;
    +  private final StructType valueSchema;
    +  private final int capacity;
    +  private int numRows = 0;
    +
    +  // Staging row returned from getRow.
    +  final UnsafeRow keyRow;
    +  final UnsafeRow valueRow;
    +
    +  // ids for current key row and value row being retrieved
    +  private int keyRowId = -1;
    +
    +  // full addresses for key rows and value rows
    +  private long[] keyOffsets;
    +
    +  // if all data types in the schema are fixed length
    +  private boolean allFixedLength;
    +  private int klen;
    +  private int vlen;
    +  private int recordLength;
    +
    +  private MemoryBlock currentAndOnlyPage = null;
    +  private Object currentAndOnlyBase = null;
    +  private long recordStartOffset;
    +  private long pageCursor = 0;
    +
    +  public static RowBasedKeyValueBatch allocate(StructType keySchema, StructType valueSchema,
    +                                               TaskMemoryManager manager) {
    +    return new RowBasedKeyValueBatch(keySchema, valueSchema, DEFAULT_CAPACITY, manager);
    +  }
    +
    +  public static RowBasedKeyValueBatch allocate(StructType keySchema, StructType valueSchema,
    +                                               TaskMemoryManager manager, int maxRows) {
    +    return new RowBasedKeyValueBatch(keySchema, valueSchema, maxRows, manager);
    +  }
    +
    +  public int numRows() { return numRows; }
    +
    +  public void close() {
    +    if (currentAndOnlyPage != null) {
    +      freePage(currentAndOnlyPage);
    +      currentAndOnlyPage = null;
    +    }
    +  }
    +
    +  private boolean acquireNewPage(long required) {
    +    try {
    +      currentAndOnlyPage = allocatePage(required);
    +    } catch (OutOfMemoryError e) {
    +      return false;
    +    }
    +    currentAndOnlyBase = currentAndOnlyPage.getBaseObject();
    +    Platform.putInt(currentAndOnlyBase, currentAndOnlyPage.getBaseOffset(), 0);
    +    pageCursor = 4;
    +    recordStartOffset = pageCursor + currentAndOnlyPage.getBaseOffset();
    +
    +    return true;
    +  }
    +
    +  private long getKeyOffsetForFixedLengthRecords(int rowId) {
    +    return recordStartOffset + rowId * recordLength + 8;
    +  }
    +
    +  public UnsafeRow appendRow(Object kbase, long koff, int klen,
    +                             Object vbase, long voff, int vlen) {
    +    final long recordLength = 8 + klen + vlen + 8;
    +    // if run out of max supported rows or page size, return null
    +    if (numRows >= capacity || currentAndOnlyPage == null
    +            || currentAndOnlyPage.size() - pageCursor < recordLength) {
    +      return null;
    +    }
    +
    +    final Object base = currentAndOnlyBase;
    +    long offset = currentAndOnlyPage.getBaseOffset() + pageCursor;
    +    final long recordOffset = offset;
    +    if (!allFixedLength) { // we only put lengths info for variable length
    +      Platform.putInt(base, offset, klen + vlen + 4);
    +      Platform.putInt(base, offset + 4, klen);
    +    }
    +    offset += 8;
    +    Platform.copyMemory(kbase, koff, base, offset, klen);
    +    offset += klen;
    +    Platform.copyMemory(vbase, voff, base, offset, vlen);
    +    offset += vlen;
    +    Platform.putLong(base, offset, 0);
    +
    +    offset = currentAndOnlyPage.getBaseOffset();
    +    Platform.putInt(base, offset, Platform.getInt(base, offset) + 1);
    +    pageCursor += recordLength;
    +
    +
    +    if (!allFixedLength) keyOffsets[numRows] = recordOffset + 8;
    +
    +    keyRowId = numRows;
    +    keyRow.pointTo(base, recordOffset + 8, klen);
    +    valueRow.pointTo(base, recordOffset + 8 + klen, vlen + 4);
    +    numRows++;
    +    return valueRow;
    +  }
    +
    +  /**
    +   * Returns the key row in this batch at `rowId`. Returned key row is reused across calls.
    +   */
    +  public UnsafeRow getKeyRow(int rowId) {
    +    assert(rowId >= 0);
    +    assert(rowId < numRows);
    +    if (keyRowId != rowId) { // if keyRowId == rowId, desired keyRow is already cached
    +      if (allFixedLength) {
    +        long offset = getKeyOffsetForFixedLengthRecords(rowId);
    +        keyRow.pointTo(currentAndOnlyBase, offset, klen);
    +      } else {
    +        long offset = keyOffsets[rowId];
    +        klen = Platform.getInt(currentAndOnlyBase, offset - 4);
    +        keyRow.pointTo(currentAndOnlyBase, offset, klen);
    +      }
    +      // set keyRowId so we can check if desired row is cached
    +      keyRowId = rowId;
    +    }
    +    return keyRow;
    +  }
    +
    +  /**
    +   * Returns the value row in this batch at `rowId`.
    +   * It can be a faster path if `keyRowId` is equal to `rowId`, which means the preceding
    +   * key row has just been accessed. This is always the case so far.
    +   * Returned value row is reused across calls.
    +   */
    +  public UnsafeRow getValueRow(int rowId) {
    +    return getValueFromKey(rowId);
    +  }
    +
    +  /**
    +   * Returns the value row in this batch at `rowId`.
    +   * It can be a faster path if `keyRowId` is equal to `rowId`, which means the preceding
    +   * key row has just been accessed. This is always the case so far.
    +   * Returned value row is reused across calls.
    +   */
    +  private UnsafeRow getValueFromKey(int rowId) {
    +    if (keyRowId != rowId) {
    +      getKeyRow(rowId);
    +    }
    +    assert(rowId >= 0);
    +    if (allFixedLength) {
    +      valueRow.pointTo(currentAndOnlyBase,
    +              keyRow.getBaseOffset() + klen,
    +              vlen + 4);
    +    } else {
    +      long offset = keyOffsets[rowId];
    +      vlen = Platform.getInt(currentAndOnlyBase, offset - 8) - klen - 4;
    +      valueRow.pointTo(currentAndOnlyBase,
    +              offset + klen,
    +              vlen + 4);
    +    }
    +    return valueRow;
    +  }
    +
    +  public long spill(long size, MemoryConsumer trigger) throws IOException {
    +    throw new OutOfMemoryError("row batch should never spill");
    +  }
    +
    +  /**
    +   * Returns an iterator to go through all rows
    +   */
    +  public org.apache.spark.unsafe.KVIterator<UnsafeRow, UnsafeRow> rowIterator() {
    +    return new org.apache.spark.unsafe.KVIterator<UnsafeRow, UnsafeRow>() {
    +      private final UnsafeRow key = new UnsafeRow(keySchema.length());
    +      private final UnsafeRow value = new UnsafeRow(valueSchema.length());
    +
    +      private long offsetInPage = 0;
    +      private int recordsInPage = 0;
    +
    +      private int currentklen;
    +      private int currentvlen;
    +      private int totalLength;
    +
    +      private boolean inited = false;
    +
    +      private void init() {
    +        if (currentAndOnlyPage != null) {
    +          offsetInPage = currentAndOnlyPage.getBaseOffset();
    +          recordsInPage = Platform.getInt(currentAndOnlyBase, offsetInPage);
    +          offsetInPage += 4;
    +        }
    +        inited = true;
    +      }
    +
    +      @Override
    +      public boolean next() {
    +        if (!inited) init();
    +        //searching for the next non empty page is records is now zero
    +        if (recordsInPage == 0) {
    +          freeCurrentPage();
    +          return false;
    +        }
    +
    +        if (allFixedLength) {
    +          totalLength = klen + vlen + 4;
    +          currentklen = klen;
    +          currentvlen = vlen;
    +        } else {
    +          totalLength = Platform.getInt(currentAndOnlyBase, offsetInPage);
    --- End diff --
    
    where was it doing it in the past? if there is no documentation on why we should document it.



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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    **[Test build #62643 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/62643/consoleFull)** for PR 14174 at commit [`79ca51a`](https://github.com/apache/spark/commit/79ca51a1ba25f0fcf11d7181c276399dd09334f8).
     * This patch passes all tests.
     * This patch merges cleanly.
     * This patch adds the following public classes _(experimental)_:
      * `       |public class $generatedClassName `


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


[GitHub] spark issue #14174: [SPARK-16524][SQL] Add RowBatch and RowBasedHashMapGener...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/14174
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/62453/
    Test PASSed.


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