-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Spark 3.5: Iceberg / DataFusion Comet integration #12147
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 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
27 changes: 27 additions & 0 deletions
27
spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/OrcBatchReadConf.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,27 @@ | ||
/* | ||
* 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; | ||
|
||
import java.io.Serializable; | ||
import org.immutables.value.Value; | ||
|
||
@Value.Immutable | ||
public interface OrcBatchReadConf extends Serializable { | ||
int batchSize(); | ||
} |
29 changes: 29 additions & 0 deletions
29
spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/ParquetBatchReadConf.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,29 @@ | ||
/* | ||
* 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; | ||
|
||
import java.io.Serializable; | ||
import org.immutables.value.Value; | ||
|
||
@Value.Immutable | ||
public interface ParquetBatchReadConf extends Serializable { | ||
int batchSize(); | ||
|
||
ParquetReaderType readerType(); | ||
} |
47 changes: 47 additions & 0 deletions
47
spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/ParquetReaderType.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,47 @@ | ||
/* | ||
* 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; | ||
|
||
import org.apache.iceberg.relocated.com.google.common.base.Preconditions; | ||
|
||
/** Enumerates the types of Parquet readers. */ | ||
public enum ParquetReaderType { | ||
/** ICEBERG type utilizes the built-in Parquet reader. */ | ||
ICEBERG, | ||
|
||
/** | ||
* COMET type changes the Parquet reader to the Apache DataFusion Comet Parquet reader. Comet | ||
* Parquet reader performs I/O and decompression in the JVM but decodes in native to improve | ||
* performance. Additionally, Comet will convert Spark's physical plan into a native physical plan | ||
* and execute this plan natively. | ||
* | ||
* <p>TODO: Implement {@link org.apache.comet.parquet.SupportsComet} in SparkScan to convert Spark | ||
* physical plan to native physical plan for native execution. | ||
*/ | ||
COMET; | ||
|
||
public static ParquetReaderType fromString(String typeAsString) { | ||
Preconditions.checkArgument(typeAsString != null, "Parquet reader type is null"); | ||
try { | ||
return ParquetReaderType.valueOf(typeAsString.toUpperCase()); | ||
} catch (IllegalArgumentException e) { | ||
throw new IllegalArgumentException("Unknown parquet reader type: " + typeAsString); | ||
} | ||
} | ||
} |
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
150 changes: 150 additions & 0 deletions
150
.../v3.5/spark/src/main/java/org/apache/iceberg/spark/data/vectorized/CometColumnReader.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,150 @@ | ||
/* | ||
* 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.data.vectorized; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
import org.apache.comet.parquet.AbstractColumnReader; | ||
import org.apache.comet.parquet.ColumnReader; | ||
import org.apache.comet.parquet.TypeUtil; | ||
import org.apache.comet.parquet.Utils; | ||
import org.apache.comet.shaded.arrow.c.CometSchemaImporter; | ||
import org.apache.comet.shaded.arrow.memory.RootAllocator; | ||
import org.apache.iceberg.parquet.VectorizedReader; | ||
import org.apache.iceberg.relocated.com.google.common.base.Preconditions; | ||
import org.apache.iceberg.spark.SparkSchemaUtil; | ||
import org.apache.iceberg.types.Types; | ||
import org.apache.parquet.column.ColumnDescriptor; | ||
import org.apache.parquet.column.page.PageReadStore; | ||
import org.apache.parquet.column.page.PageReader; | ||
import org.apache.parquet.hadoop.metadata.ColumnChunkMetaData; | ||
import org.apache.parquet.hadoop.metadata.ColumnPath; | ||
import org.apache.spark.sql.types.DataType; | ||
import org.apache.spark.sql.types.Metadata; | ||
import org.apache.spark.sql.types.StructField; | ||
import org.apache.spark.sql.vectorized.ColumnVector; | ||
|
||
class CometColumnReader implements VectorizedReader<ColumnVector> { | ||
// use the Comet default batch size | ||
public static final int DEFAULT_BATCH_SIZE = 8192; | ||
|
||
private final ColumnDescriptor descriptor; | ||
private final DataType sparkType; | ||
|
||
// The delegated ColumnReader from Comet side | ||
private AbstractColumnReader delegate; | ||
private boolean initialized = false; | ||
private int batchSize = DEFAULT_BATCH_SIZE; | ||
private CometSchemaImporter importer; | ||
|
||
CometColumnReader(DataType sparkType, ColumnDescriptor descriptor) { | ||
this.sparkType = sparkType; | ||
this.descriptor = descriptor; | ||
} | ||
|
||
CometColumnReader(Types.NestedField field) { | ||
DataType dataType = SparkSchemaUtil.convert(field.type()); | ||
StructField structField = new StructField(field.name(), dataType, false, Metadata.empty()); | ||
this.sparkType = dataType; | ||
this.descriptor = TypeUtil.convertToParquet(structField); | ||
} | ||
|
||
public AbstractColumnReader delegate() { | ||
return delegate; | ||
} | ||
|
||
void setDelegate(AbstractColumnReader delegate) { | ||
this.delegate = delegate; | ||
} | ||
|
||
void setInitialized(boolean initialized) { | ||
this.initialized = initialized; | ||
} | ||
|
||
public int batchSize() { | ||
return batchSize; | ||
} | ||
|
||
/** | ||
* This method is to initialized/reset the CometColumnReader. This needs to be called for each row | ||
* group after readNextRowGroup, so a new dictionary encoding can be set for each of the new row | ||
* groups. | ||
*/ | ||
public void reset() { | ||
if (importer != null) { | ||
importer.close(); | ||
} | ||
|
||
if (delegate != null) { | ||
delegate.close(); | ||
} | ||
|
||
this.importer = new CometSchemaImporter(new RootAllocator()); | ||
this.delegate = Utils.getColumnReader(sparkType, descriptor, importer, batchSize, false, false); | ||
this.initialized = true; | ||
} | ||
|
||
public ColumnDescriptor descriptor() { | ||
return descriptor; | ||
} | ||
|
||
/** Returns the Spark data type for this column. */ | ||
public DataType sparkType() { | ||
return sparkType; | ||
} | ||
|
||
/** | ||
* Set the page reader to be 'pageReader'. | ||
* | ||
* <p>NOTE: this should be called before reading a new Parquet column chunk, and after {@link | ||
* CometColumnReader#reset} is called. | ||
*/ | ||
public void setPageReader(PageReader pageReader) throws IOException { | ||
Preconditions.checkState(initialized, "Invalid state: 'reset' should be called first"); | ||
((ColumnReader) delegate).setPageReader(pageReader); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
// close resources on native side | ||
if (importer != null) { | ||
importer.close(); | ||
} | ||
|
||
if (delegate != null) { | ||
delegate.close(); | ||
} | ||
} | ||
|
||
@Override | ||
public void setBatchSize(int size) { | ||
this.batchSize = size; | ||
} | ||
|
||
@Override | ||
public void setRowGroupInfo( | ||
PageReadStore pageReadStore, Map<ColumnPath, ColumnChunkMetaData> map, long size) { | ||
throw new UnsupportedOperationException("Not supported"); | ||
} | ||
|
||
@Override | ||
public ColumnVector read(ColumnVector reuse, int numRowsToRead) { | ||
throw new UnsupportedOperationException("Not supported"); | ||
} | ||
} |
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.
Missing an empty line.