-
Notifications
You must be signed in to change notification settings - Fork 199
wip: [AURON #1676] Enable native BatchScanExec for Iceberg COW tables #1677
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
Draft
ShreyeshArangath
wants to merge
10
commits into
apache:master
Choose a base branch
from
ShreyeshArangath:sarangat/iceberg-scan
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+975
−9
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
08160a3
add the workflow definition from #1541
a31e855
add icebergsourceutil and tests
5eebfe1
add convertIcebergBatchScanExec
7c64e26
add utility functions
2b5a23e
attempt to add a partitionconverter
20da4cb
add META-INF and cleanup code
eb341ec
some more cleanup
9c34745
fix styling
462ac00
Merge branch 'apache-master' into sarangat/iceberg-scan
2705252
fix the tests
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,68 @@ | ||
| # | ||
| # 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. | ||
| # | ||
|
|
||
| name: Iceberg | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| push: | ||
| branches: | ||
| - master | ||
| - branch-* | ||
| pull_request: | ||
| branches: | ||
| - master | ||
| - branch-* | ||
|
|
||
| concurrency: | ||
| group: iceberg-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| test-flink: | ||
| name: Test Iceberg ${{ matrix.iceberg }} javaVersion ${{ matrix.javaver }} scalaVersion ${{ matrix.scalaver }} | ||
| runs-on: ubuntu-24.04 | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| iceberg: [ "1.9" ] | ||
| javaver: [ "11", "17"] | ||
| scalaver: [ "2.12" ] | ||
| module: [ "thirdparty/auron-iceberg" ] | ||
| sparkver: [ "spark-3.4", "spark-3.5" ] | ||
|
|
||
|
|
||
| steps: | ||
| - name: Checkout Auron | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup Java and Maven cache | ||
| uses: actions/setup-java@v4 | ||
| with: | ||
| distribution: 'adopt-hotspot' | ||
| java-version: ${{ matrix.javaver }} | ||
| cache: 'maven' | ||
|
|
||
| - name: Test Iceberg Module | ||
| run: ./build/mvn -B test -X -pl ${{ matrix.module }} -am -Pscala-${{ matrix.scalaver }} -Piceberg-${{ matrix.iceberg }} -P${{ matrix.sparkver }} -Prelease | ||
|
|
||
| - name: Upload reports | ||
| if: failure() | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: ${{ matrix.module }}-test-report | ||
| path: ${{ matrix.module }}/target/surefire-reports | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
18 changes: 18 additions & 0 deletions
18
...berg/src/main/resources/META-INF.services/org.apache.spark.sql.auron.AuronConvertProvider
This file contains hidden or 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,18 @@ | ||
| # | ||
| # 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. | ||
| # | ||
|
|
||
| org.apache.spark.sql.auron.iceberg.IcebergConvertProvider |
166 changes: 166 additions & 0 deletions
166
...on-iceberg/src/main/scala/org/apache/iceberg/spark/source/IcebergPartitionConverter.scala
This file contains hidden or 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,166 @@ | ||
| /* | ||
| * 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.iceberg.spark.source | ||
|
|
||
| import java.nio.ByteBuffer | ||
|
|
||
| import org.apache.iceberg.{FileScanTask, Table} | ||
| import org.apache.iceberg.spark.SparkSchemaUtil | ||
| import org.apache.spark.sql.catalyst.InternalRow | ||
| import org.apache.spark.sql.types._ | ||
| import org.apache.spark.sql.types.Decimal | ||
| import org.apache.spark.unsafe.types.UTF8String | ||
|
|
||
| // Converts Iceberg partition data to Spark InternalRow. | ||
| class IcebergPartitionConverter(table: Table) { | ||
|
|
||
| private case class FieldAccessor(javaClass: Class[_], convert: Any => Any) | ||
|
|
||
| private val tableSparkPartitionSchema: StructType = | ||
| SparkSchemaUtil.convert(table.spec().partitionType().asSchema()) | ||
|
|
||
| require( | ||
| table.spec().partitionType().fields().size() == tableSparkPartitionSchema.fields.length, | ||
| s"Mismatch between Iceberg partition fields (${table.spec().partitionType().fields().size()}) " + | ||
| s"and Spark partition schema (${tableSparkPartitionSchema.fields.length})") | ||
|
|
||
| private def javaClassFor(dt: DataType): Class[_] = dt match { | ||
| case BooleanType => classOf[java.lang.Boolean] | ||
| case IntegerType | DateType => classOf[java.lang.Integer] | ||
| case LongType | TimestampType => classOf[java.lang.Long] | ||
| case dt if dt.typeName == "timestamp_ntz" => classOf[java.lang.Long] | ||
| case dt if dt.typeName == "time" => classOf[java.lang.Long] | ||
| case FloatType => classOf[java.lang.Float] | ||
| case DoubleType => classOf[java.lang.Double] | ||
| case StringType => classOf[CharSequence] | ||
| case BinaryType => classOf[java.nio.ByteBuffer] | ||
| case _: DecimalType => classOf[java.math.BigDecimal] | ||
| case other => | ||
| throw new UnsupportedOperationException( | ||
| s"Unsupported Spark partition type from partitionType.asSchema(): $other") | ||
| } | ||
|
|
||
| private def converterFor(dt: DataType): Any => Any = dt match { | ||
| case StringType => | ||
| (raw: Any) => | ||
| if (raw == null) null | ||
| else | ||
| raw match { | ||
| case cs: CharSequence => UTF8String.fromString(cs.toString) | ||
| case other => UTF8String.fromString(other.toString) | ||
| } | ||
|
|
||
| case IntegerType | BooleanType | LongType | FloatType | DoubleType => | ||
| (raw: Any) => raw | ||
|
|
||
| case DateType => | ||
| (raw: Any) => | ||
| if (raw == null) null | ||
| else raw.asInstanceOf[Integer].intValue() | ||
|
|
||
| case TimestampType => | ||
| (raw: Any) => | ||
| if (raw == null) null | ||
| else raw.asInstanceOf[Long] | ||
|
|
||
| case dt if dt.typeName == "timestamp_ntz" => | ||
| (raw: Any) => | ||
| if (raw == null) null | ||
| else raw.asInstanceOf[Long] | ||
|
|
||
| case dt if dt.typeName == "time" => | ||
| (raw: Any) => | ||
| if (raw == null) null | ||
| else raw.asInstanceOf[Long] | ||
|
|
||
| case BinaryType => | ||
| (raw: Any) => | ||
| if (raw == null) null | ||
| else | ||
| raw match { | ||
| case bb: ByteBuffer => | ||
| val dup = bb.duplicate() | ||
| val arr = new Array[Byte](dup.remaining()) | ||
| dup.get(arr) | ||
| arr | ||
| case arr: Array[Byte] => arr | ||
| case other => | ||
| throw new IllegalArgumentException( | ||
| s"Unexpected binary partition value type: ${other.getClass}") | ||
| } | ||
|
|
||
| case d: DecimalType => | ||
| (raw: Any) => | ||
| if (raw == null) null | ||
| else { | ||
| val bd: java.math.BigDecimal = raw match { | ||
| case bd: java.math.BigDecimal => bd | ||
| case s: String => new java.math.BigDecimal(s) | ||
| case other => new java.math.BigDecimal(other.toString) | ||
| } | ||
| val normalized = bd.setScale(d.scale, java.math.RoundingMode.UNNECESSARY) | ||
| Decimal(normalized, d.precision, d.scale) | ||
| } | ||
|
|
||
| case other => | ||
| (_: Any) => | ||
| throw new UnsupportedOperationException( | ||
| s"Unsupported Spark partition type in converter from partitionType.asSchema(): $other") | ||
| } | ||
|
|
||
| private def buildFieldAccessors(sparkSchema: StructType): Array[FieldAccessor] = { | ||
| val sFields = sparkSchema.fields | ||
| sFields.map { field => | ||
| val dt = field.dataType | ||
| FieldAccessor(javaClass = javaClassFor(dt), convert = converterFor(dt)) | ||
| } | ||
| } | ||
|
|
||
| private val specCache = scala.collection.mutable | ||
| .AnyRefMap[org.apache.iceberg.PartitionSpec, (StructType, Array[FieldAccessor])]() | ||
|
|
||
| private def accessorsFor( | ||
| spec: org.apache.iceberg.PartitionSpec): (StructType, Array[FieldAccessor]) = { | ||
| specCache.getOrElseUpdate( | ||
| spec, { | ||
| val pt = spec.partitionType() | ||
| val sps = SparkSchemaUtil.convert(pt.asSchema()) | ||
| require( | ||
| pt.fields().size() == sps.fields.length, | ||
| s"Mismatch between Iceberg partition fields (${pt.fields().size()}) and Spark partition schema (${sps.fields.length})") | ||
| (sps, buildFieldAccessors(sps)) | ||
| }) | ||
| } | ||
|
|
||
| def convert(task: FileScanTask): InternalRow = { | ||
| val (sparkSchema, fieldAccessors) = accessorsFor(task.spec()) | ||
| val partitionData = task.file().partition() | ||
| if (partitionData == null || fieldAccessors.isEmpty) { | ||
| InternalRow.empty | ||
| } else { | ||
| val values = fieldAccessors.indices.map { i => | ||
| val accessor = fieldAccessors(i) | ||
| val jcls = accessor.javaClass.asInstanceOf[Class[Any]] | ||
| val raw = partitionData.get(i, jcls) | ||
| accessor.convert(raw) | ||
| } | ||
| InternalRow.fromSeq(values) | ||
| } | ||
| } | ||
|
|
||
| def schema: StructType = tableSparkPartitionSchema | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Borrowed from #1541 as its not merged in yet.