-
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 #34918
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
70117e9
45f7084
e3e87bd
02fb7a2
ae42f09
79caffa
0dd9bb4
a95a2f3
bfdf849
afc2bc6
b24a804
29e8265
0682f06
8f11248
c440970
5a2f8b8
31d4ea5
bbecf9d
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,24 @@ object DataSourceStrategy | |
| } | ||
| } | ||
|
|
||
| protected[sql] def translateSortOrders(sortOrders: Seq[SortOrder]): Seq[SortOrderV2] = { | ||
| def translateOortOrder(sortOrder: SortOrder): Option[SortOrderV2] = sortOrder match { | ||
| case SortOrder(PushableColumnWithoutNestedColumn(name), directionV1, nullOrderingV1, _) => | ||
| 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 | ||
| } | ||
| Some(SortValue(FieldReference(name), directionV2, nullOrderingV2)) | ||
| case _ => None | ||
| } | ||
|
|
||
| sortOrders.flatMap(translateOortOrder) | ||
|
||
| } | ||
|
|
||
| /** | ||
| * 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.