-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-37483][SQL] Support push down top N to JDBC data source V2 #34738
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 all commits
4872dcc
90e0250
63d9168
8abbb34
39eab85
52213ed
730e5d0
bf105ca
3b9d980
9c0cbc0
ac24274
2d1bb55
944bf6b
082ded9
4f69ee8
eb32095
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 |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| /* | ||
| * 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.connector.read; | ||
|
|
||
| import org.apache.spark.annotation.Evolving; | ||
| import org.apache.spark.sql.connector.expressions.SortOrder; | ||
|
|
||
| /** | ||
| * A mix-in interface for {@link ScanBuilder}. Data sources can implement this interface to | ||
| * push down top N(query with ORDER BY ... LIMIT n). Please note that the combination of top N | ||
| * with other operations such as AGGREGATE, GROUP BY, CLUSTER BY, DISTRIBUTE BY, etc. | ||
| * is NOT pushed down. | ||
| * | ||
| * @since 3.3.0 | ||
| */ | ||
| @Evolving | ||
| public interface SupportsPushDownTopN extends ScanBuilder { | ||
|
|
||
| /** | ||
| * Pushes down top N to the data source. | ||
| */ | ||
| boolean pushTopN(SortOrder[] orders, int limit); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,7 +40,7 @@ import org.apache.spark.sql.catalyst.rules.Rule | |
| import org.apache.spark.sql.catalyst.streaming.StreamingRelationV2 | ||
| import org.apache.spark.sql.connector.catalog.SupportsRead | ||
| import org.apache.spark.sql.connector.catalog.TableCapability._ | ||
| import org.apache.spark.sql.connector.expressions.FieldReference | ||
| import org.apache.spark.sql.connector.expressions.{FieldReference, NullOrdering, SortDirection, SortOrder => SortOrderV2, SortValue} | ||
| import org.apache.spark.sql.connector.expressions.aggregate.{AggregateFunc, Count, CountStar, Max, Min, Sum} | ||
| import org.apache.spark.sql.errors.QueryCompilationErrors | ||
| import org.apache.spark.sql.execution.{InSubqueryExec, RowDataSourceScanExec, SparkPlan} | ||
|
|
@@ -336,7 +336,7 @@ object DataSourceStrategy | |
| l.output.toStructType, | ||
| Set.empty, | ||
| Set.empty, | ||
| PushedDownOperators(None, None, None), | ||
| PushedDownOperators(None, None, None, Seq.empty), | ||
| toCatalystRDD(l, baseRelation.buildScan()), | ||
| baseRelation, | ||
| None) :: Nil | ||
|
|
@@ -410,7 +410,7 @@ object DataSourceStrategy | |
| requestedColumns.toStructType, | ||
| pushedFilters.toSet, | ||
| handledFilters, | ||
| PushedDownOperators(None, None, None), | ||
| PushedDownOperators(None, None, None, Seq.empty), | ||
| scanBuilder(requestedColumns, candidatePredicates, pushedFilters), | ||
| relation.relation, | ||
| relation.catalogTable.map(_.identifier)) | ||
|
|
@@ -433,7 +433,7 @@ object DataSourceStrategy | |
| requestedColumns.toStructType, | ||
| pushedFilters.toSet, | ||
| handledFilters, | ||
| PushedDownOperators(None, None, None), | ||
| PushedDownOperators(None, None, None, Seq.empty), | ||
| scanBuilder(requestedColumns, candidatePredicates, pushedFilters), | ||
| relation.relation, | ||
| relation.catalogTable.map(_.identifier)) | ||
|
|
@@ -726,6 +726,21 @@ object DataSourceStrategy | |
| } | ||
| } | ||
|
|
||
| protected[sql] def translateSortOrders(sortOrders: Seq[SortOrder]): Seq[SortOrderV2] = { | ||
| sortOrders.map { | ||
|
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. Hi, All. This broke Scala 2.13 compilation. |
||
| case SortOrder(PushableColumnWithoutNestedColumn(name), directionV1, nullOrderingV1, _) => | ||
|
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. In addition, this will cause |
||
| val directionV2 = directionV1 match { | ||
| case Ascending => SortDirection.ASCENDING | ||
| case Descending => SortDirection.DESCENDING | ||
| } | ||
| val nullOrderingV2 = nullOrderingV1 match { | ||
| case NullsFirst => NullOrdering.NULLS_FIRST | ||
| case NullsLast => NullOrdering.NULLS_LAST | ||
| } | ||
| SortValue(FieldReference(name), directionV2, nullOrderingV2) | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Convert RDD of Row into RDD of InternalRow with objects in catalyst types | ||
| */ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.