-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[spark] PaimonSplitScan supports column pruning and filter push down (#…
- Loading branch information
1 parent
1b09de9
commit 3e87195
Showing
13 changed files
with
341 additions
and
119 deletions.
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
paimon-core/src/main/java/org/apache/paimon/table/KnownSplitsTable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* 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.paimon.table; | ||
|
||
import org.apache.paimon.table.source.DataSplit; | ||
import org.apache.paimon.table.source.InnerTableRead; | ||
import org.apache.paimon.table.source.InnerTableScan; | ||
import org.apache.paimon.types.RowType; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* A table to hold some known data splits. For now, it is only used by internal for Spark engine. | ||
*/ | ||
public class KnownSplitsTable implements ReadonlyTable { | ||
private final InnerTable origin; | ||
private final DataSplit[] splits; | ||
|
||
KnownSplitsTable(InnerTable origin, DataSplit[] splits) { | ||
this.origin = origin; | ||
this.splits = splits; | ||
} | ||
|
||
public static KnownSplitsTable create(InnerTable origin, DataSplit[] splits) { | ||
return new KnownSplitsTable(origin, splits); | ||
} | ||
|
||
public DataSplit[] splits() { | ||
return splits; | ||
} | ||
|
||
@Override | ||
public String name() { | ||
return origin.name(); | ||
} | ||
|
||
@Override | ||
public RowType rowType() { | ||
return origin.rowType(); | ||
} | ||
|
||
@Override | ||
public List<String> primaryKeys() { | ||
return origin.primaryKeys(); | ||
} | ||
|
||
@Override | ||
public List<String> partitionKeys() { | ||
return origin.partitionKeys(); | ||
} | ||
|
||
@Override | ||
public Map<String, String> options() { | ||
return origin.options(); | ||
} | ||
|
||
@Override | ||
public InnerTableRead newRead() { | ||
return origin.newRead(); | ||
} | ||
|
||
// ===== unused method =========================================== | ||
|
||
@Override | ||
public InnerTableScan newScan() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public Table copy(Map<String, String> dynamicOptions) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...paimon-spark-common/src/main/scala/org/apache/paimon/spark/ColumnPruningAndPushDown.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* 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.paimon.spark | ||
|
||
import org.apache.paimon.predicate.{Predicate, PredicateBuilder} | ||
import org.apache.paimon.spark.schema.PaimonMetadataColumn | ||
import org.apache.paimon.table.Table | ||
import org.apache.paimon.table.source.ReadBuilder | ||
import org.apache.paimon.types.RowType | ||
|
||
import org.apache.spark.sql.connector.read.Scan | ||
import org.apache.spark.sql.types.StructType | ||
|
||
trait ColumnPruningAndPushDown extends Scan { | ||
def table: Table | ||
def requiredSchema: StructType | ||
def filters: Seq[Predicate] | ||
def pushDownLimit: Option[Int] = None | ||
|
||
val tableRowType: RowType = table.rowType | ||
val tableSchema: StructType = SparkTypeUtils.fromPaimonRowType(tableRowType) | ||
|
||
final def partitionType: StructType = { | ||
SparkTypeUtils.toSparkPartitionType(table) | ||
} | ||
|
||
private[paimon] val (requiredTableFields, metadataFields) = { | ||
val nameToField = tableSchema.map(field => (field.name, field)).toMap | ||
val _tableFields = requiredSchema.flatMap(field => nameToField.get(field.name)) | ||
val _metadataFields = | ||
requiredSchema | ||
.filterNot(field => tableSchema.fieldNames.contains(field.name)) | ||
.filter(field => PaimonMetadataColumn.SUPPORTED_METADATA_COLUMNS.contains(field.name)) | ||
(_tableFields, _metadataFields) | ||
} | ||
|
||
lazy val readBuilder: ReadBuilder = { | ||
val _readBuilder = table.newReadBuilder() | ||
val projection = | ||
requiredTableFields.map(field => tableSchema.fieldNames.indexOf(field.name)).toArray | ||
_readBuilder.withProjection(projection) | ||
if (filters.nonEmpty) { | ||
val pushedPredicate = PredicateBuilder.and(filters: _*) | ||
_readBuilder.withFilter(pushedPredicate) | ||
} | ||
pushDownLimit.foreach(_readBuilder.withLimit) | ||
_readBuilder | ||
} | ||
|
||
final def metadataColumns: Seq[PaimonMetadataColumn] = { | ||
metadataFields.map(field => PaimonMetadataColumn.get(field.name, partitionType)) | ||
} | ||
|
||
override def readSchema(): StructType = { | ||
StructType(requiredTableFields ++ metadataFields) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.