-
Notifications
You must be signed in to change notification settings - Fork 267
feat: Support basic Delta scans #3035
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
Open
Kimahriman
wants to merge
9
commits into
apache:main
Choose a base branch
from
Kimahriman:delta-scan
base: main
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.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6c01551
work on getting delta scans working
Kimahriman 82dada0
More tests
Kimahriman 0a995ef
Scalafix
Kimahriman 86ff296
Support Spark 3.4
Kimahriman a31f3a0
Remove unnecessary dependency and fix tests for Spark 4
Kimahriman b0bbba8
Add test for CDF
Kimahriman 2076f1e
Add new suite to CI
Kimahriman ef51e5e
Add a snippet to supported sources
Kimahriman aa51b22
Fix md
Kimahriman 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -112,6 +112,12 @@ under the License. | |
| </exclusion> | ||
| </exclusions> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.google.guava</groupId> | ||
| <artifactId>failureaccess</artifactId> | ||
| <version>1.0.3</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
|
Comment on lines
+115
to
+120
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. Without this I'm getting an error creating the Delta tables: Not sure why, could use some help figuring out what is missing with Guava from where |
||
| <dependency> | ||
| <groupId>org.codehaus.jackson</groupId> | ||
| <artifactId>jackson-mapper-asl</artifactId> | ||
|
|
@@ -188,6 +194,12 @@ under the License. | |
| <version>1.5.2</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>io.delta</groupId> | ||
| <artifactId>delta-core_${scala.binary.version}</artifactId> | ||
| <version>2.4.0</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <!-- Jetty 9.4.x for Spark 3.4 (JDK 11, javax.* packages) --> | ||
| <dependency> | ||
| <groupId>org.eclipse.jetty</groupId> | ||
|
|
@@ -216,6 +228,12 @@ under the License. | |
| <version>1.8.1</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>io.delta</groupId> | ||
| <artifactId>delta-spark_${scala.binary.version}</artifactId> | ||
| <version>3.3.2</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <!-- Jetty 9.4.x for Spark 3.5 (JDK 11, javax.* packages) --> | ||
| <dependency> | ||
| <groupId>org.eclipse.jetty</groupId> | ||
|
|
@@ -241,6 +259,12 @@ under the License. | |
| <version>1.10.0</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>io.delta</groupId> | ||
| <artifactId>delta-spark_${scala.binary.version}</artifactId> | ||
| <version>4.0.0</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <!-- Jetty 11.x for Spark 4.0 (jakarta.servlet) --> | ||
| <dependency> | ||
| <groupId>org.eclipse.jetty</groupId> | ||
|
|
||
121 changes: 121 additions & 0 deletions
121
spark/src/main/scala/org/apache/comet/delta/DeltaReflection.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,121 @@ | ||
| /* | ||
| * 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.comet.delta | ||
|
|
||
| import org.apache.spark.internal.Logging | ||
|
|
||
| /** | ||
| * Shared reflection utilities for Delta operations. | ||
| * | ||
| * This object provides common reflection methods used across Comet for interacting with Delta | ||
| * classes without requiring a runtime dependency on Delta | ||
| */ | ||
| object DeltaReflection extends Logging { | ||
|
|
||
| /** | ||
| * Gets the Delta Protocol from a Spark FileFormat | ||
| */ | ||
| def getProtocol(fileFormat: Any): Option[Any] = { | ||
| try { | ||
| val field = fileFormat.getClass.getDeclaredField("protocol") | ||
| field.setAccessible(true) | ||
| Some(field.get(fileFormat)) | ||
| } catch { | ||
| case e: Exception => | ||
| logError( | ||
| s"Delta reflection failure: Failed to get protocol from FileFormat: ${e.getMessage}") | ||
| None | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Gets the tasks from a SparkScan. | ||
| * | ||
| * The tasks() method is protected in SparkScan, requiring reflection to access. | ||
| */ | ||
| def getMinReaderVersion(protocol: Any): Option[Int] = { | ||
| try { | ||
| val field = protocol.getClass.getDeclaredField("minReaderVersion") | ||
| field.setAccessible(true) | ||
| Some(field.get(protocol).asInstanceOf[Int]) | ||
| } catch { | ||
| case e: Exception => | ||
| logError( | ||
| "Delta reflection failure: Failed to get minReaderVersion from protocol: " + | ||
| s"${e.getMessage}") | ||
| None | ||
| } | ||
| } | ||
|
|
||
| def getReaderFeatures(protocol: Any): Option[Set[String]] = { | ||
| try { | ||
| val field = protocol.getClass.getDeclaredField("readerFeatures") | ||
| field.setAccessible(true) | ||
| Some(field.get(protocol).asInstanceOf[Option[Set[String]]].getOrElse(Set.empty)) | ||
| } catch { | ||
| case e: Exception => | ||
| logError( | ||
| "Delta reflection failure: Failed to get minReaderVersion from protocol: " + | ||
| s"${e.getMessage}") | ||
| None | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Pre-extracted Delta metadata for native scan execution. | ||
| * | ||
| * This class holds all metadata extracted from Delta during the planning/validation phase in | ||
| * CometScanRule. By extracting all metadata once during validation (where reflection failures | ||
| * trigger fallback to Spark), we avoid redundant reflection during serialization (where failures | ||
| * would be fatal runtime errors). | ||
| * | ||
| * @param minReaderVersion | ||
| * The minimum reader version of the table | ||
| * @param readerFeatures | ||
| * A list of enabled reader features on the table | ||
| */ | ||
| case class CometDeltaNativeScanMetadata(minReaderVersion: Int, readerFeatures: Set[String]) | ||
|
|
||
| object CometDeltaNativeScanMetadata extends Logging { | ||
| import DeltaReflection._ | ||
|
|
||
| /** | ||
| * Extracts all Delta metadata needed for native scan execution. | ||
| * | ||
| * This method performs all reflection operations once during planning/validation. If any | ||
| * reflection operation fails, returns None to trigger fallback to Spark. | ||
| * | ||
| * @param fileFormat | ||
| * The FileFormat instance from the HadoopFsRelation | ||
| * @return | ||
| * Some(metadata) if all reflection succeeds, None to trigger fallback | ||
| */ | ||
| def extract(fileFormat: Any): Option[CometDeltaNativeScanMetadata] = { | ||
| getProtocol(fileFormat).flatMap { protocol => | ||
| for { | ||
| minReaderVersion <- getMinReaderVersion(protocol) | ||
| readerFeatures <- getReaderFeatures(protocol) | ||
| } yield { | ||
| CometDeltaNativeScanMetadata(minReaderVersion, readerFeatures) | ||
| } | ||
| } | ||
| } | ||
| } |
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
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
With opendal enabled by default in #2929, I was getting failures finding libhdfs.so running unit tests on Linux. The
hdrsdependency below for macos was purely activating thevendoredfeature of hdfs-sys, so I just enabled that globally here so you don't needlibhdfsavailable for developing on Linux either