-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-37933][SQL] Limit push down for parquet vectorized reader #35256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,6 +56,9 @@ public class VectorizedParquetRecordReader extends SpecificParquetRecordReaderBa | |
| // The capacity of vectorized batch. | ||
| private int capacity; | ||
|
|
||
| // The pushed down Limit to read | ||
| private int limit; | ||
|
|
||
| /** | ||
| * Batch of rows that we assemble and the current index we've returned. Every time this | ||
| * batch is used up (batchIdx == numBatched), we populated the batch. | ||
|
|
@@ -139,14 +142,34 @@ public VectorizedParquetRecordReader( | |
| String int96RebaseMode, | ||
| String int96RebaseTz, | ||
| boolean useOffHeap, | ||
| int capacity) { | ||
| int capacity, | ||
| int limit) { | ||
| this.convertTz = convertTz; | ||
| this.datetimeRebaseMode = datetimeRebaseMode; | ||
| this.datetimeRebaseTz = datetimeRebaseTz; | ||
| this.int96RebaseMode = int96RebaseMode; | ||
| this.int96RebaseTz = int96RebaseTz; | ||
| MEMORY_MODE = useOffHeap ? MemoryMode.OFF_HEAP : MemoryMode.ON_HEAP; | ||
| this.capacity = capacity; | ||
| this.limit = limit; | ||
| } | ||
|
|
||
| public VectorizedParquetRecordReader( | ||
| ZoneId convertTz, | ||
| String datetimeRebaseMode, | ||
| String datetimeRebaseTz, | ||
| String int96RebaseMode, | ||
| String int96RebaseTz, | ||
| boolean useOffHeap, | ||
| int capacity) { | ||
| this.convertTz = convertTz; | ||
| this.datetimeRebaseMode = datetimeRebaseMode; | ||
| this.datetimeRebaseTz = datetimeRebaseTz; | ||
| this.int96RebaseMode = int96RebaseMode; | ||
| this.int96RebaseTz = int96RebaseTz; | ||
| MEMORY_MODE = useOffHeap ? MemoryMode.OFF_HEAP : MemoryMode.ON_HEAP; | ||
| this.capacity = capacity; | ||
| this.limit = Integer.MAX_VALUE; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can use: this(convertTz, datetimeRebaseMode, datetimeRebaseTz, int96RebaseMode, int96RebaseTz,
useOffHeap, capacity, Integer.MAX_VALUE);
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
| } | ||
|
|
||
| // For test only. | ||
|
|
@@ -302,10 +325,13 @@ public boolean nextBatch() throws IOException { | |
| vector.reset(); | ||
| } | ||
| columnarBatch.setNumRows(0); | ||
| if (rowsReturned >= totalRowCount) return false; | ||
| if (rowsReturned >= totalRowCount || rowsReturned >= limit) { | ||
| return false; | ||
| } | ||
| checkEndOfRowGroup(); | ||
|
|
||
| int num = (int) Math.min((long) capacity, totalCountLoadedSoFar - rowsReturned); | ||
| int num = (int) Math.min((long) capacity, | ||
| Math.min((long) limit - rowsReturned, totalCountLoadedSoFar - rowsReturned)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indentation is off
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
| for (int i = 0; i < columnReaders.length; ++i) { | ||
| if (columnReaders[i] == null) continue; | ||
| columnReaders[i].readBatch(num, columnVectors[i]); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /* | ||
| * 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.datasources.parquet | ||
|
|
||
| import scala.util.Random | ||
|
|
||
| import org.apache.spark.sql.QueryTest | ||
| import org.apache.spark.sql.execution.CollectLimitExec | ||
| import org.apache.spark.sql.execution.datasources.v2.BatchScanExec | ||
| import org.apache.spark.sql.execution.datasources.v2.parquet.ParquetScan | ||
| import org.apache.spark.sql.internal.SQLConf | ||
| import org.apache.spark.sql.test.SharedSparkSession | ||
|
|
||
| /** | ||
| * A test suite that tests Parquet based limit pushdown optimization. | ||
| */ | ||
| class ParquetLimitPushDownSuite extends QueryTest with ParquetTest with SharedSparkSession { | ||
| test("[SPARK-37933] test limit pushdown for vectorized parquet reader") { | ||
| import testImplicits._ | ||
| withSQLConf( | ||
| SQLConf.PARQUET_LIMIT_PUSHDOWN_ENABLED.key -> "true", | ||
| SQLConf.PARQUET_VECTORIZED_READER_ENABLED.key -> "true", | ||
| SQLConf.USE_V1_SOURCE_LIST.key -> "") { | ||
| withTempPath { path => | ||
| (1 to 1024).map(i => (101, i)).toDF("a", "b").coalesce(1).write.parquet(path.getPath) | ||
| val pushedLimit = Random.nextInt(100) | ||
| val df = spark.read.parquet(path.getPath).limit(pushedLimit) | ||
| val sparkPlan = df.queryExecution.sparkPlan | ||
| sparkPlan foreachUp { | ||
| case r@ BatchScanExec(_, f: ParquetScan, _) => | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. space between
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
| assert(f.pushedLimit.contains(pushedLimit)) | ||
| assert(r.executeColumnar().map(_.numRows()).sum() == pushedLimit) | ||
| case CollectLimitExec(limit, _) => | ||
| assert(limit == pushedLimit) | ||
| } | ||
| assert(df.count() == pushedLimit) | ||
| } | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
4-space indentation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed