-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: Add spark-4.0 profile and shims (#407)
This PR adds the spark-4.0 profile and shims This is an initial commit. Tests with the spark-4.0 profile do not pass yet. Tests for spark-3.x should pass.
- Loading branch information
1 parent
479a97a
commit 9b3e87b
Showing
52 changed files
with
1,125 additions
and
162 deletions.
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
81 changes: 81 additions & 0 deletions
81
common/src/main/spark-3.x/org/apache/spark/sql/comet/shims/ShimCometParquetUtils.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,81 @@ | ||
/* | ||
* 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.comet.shims | ||
|
||
import org.apache.spark.sql.types._ | ||
|
||
trait ShimCometParquetUtils { | ||
// The following is copied from QueryExecutionErrors | ||
// TODO: remove after dropping Spark 3.2.0 support and directly use | ||
// QueryExecutionErrors.foundDuplicateFieldInFieldIdLookupModeError | ||
def foundDuplicateFieldInFieldIdLookupModeError( | ||
requiredId: Int, | ||
matchedFields: String): Throwable = { | ||
new RuntimeException(s""" | ||
|Found duplicate field(s) "$requiredId": $matchedFields | ||
|in id mapping mode | ||
""".stripMargin.replaceAll("\n", " ")) | ||
} | ||
|
||
// The followings are copied from org.apache.spark.sql.execution.datasources.parquet.ParquetUtils | ||
// TODO: remove after dropping Spark 3.2.0 support and directly use ParquetUtils | ||
/** | ||
* A StructField metadata key used to set the field id of a column in the Parquet schema. | ||
*/ | ||
val FIELD_ID_METADATA_KEY = "parquet.field.id" | ||
|
||
/** | ||
* Whether there exists a field in the schema, whether inner or leaf, has the parquet field ID | ||
* metadata. | ||
*/ | ||
def hasFieldIds(schema: StructType): Boolean = { | ||
def recursiveCheck(schema: DataType): Boolean = { | ||
schema match { | ||
case st: StructType => | ||
st.exists(field => hasFieldId(field) || recursiveCheck(field.dataType)) | ||
|
||
case at: ArrayType => recursiveCheck(at.elementType) | ||
|
||
case mt: MapType => recursiveCheck(mt.keyType) || recursiveCheck(mt.valueType) | ||
|
||
case _ => | ||
// No need to really check primitive types, just to terminate the recursion | ||
false | ||
} | ||
} | ||
if (schema.isEmpty) false else recursiveCheck(schema) | ||
} | ||
|
||
def hasFieldId(field: StructField): Boolean = | ||
field.metadata.contains(FIELD_ID_METADATA_KEY) | ||
|
||
def getFieldId(field: StructField): Int = { | ||
require( | ||
hasFieldId(field), | ||
s"The key `$FIELD_ID_METADATA_KEY` doesn't exist in the metadata of " + field) | ||
try { | ||
Math.toIntExact(field.metadata.getLong(FIELD_ID_METADATA_KEY)) | ||
} catch { | ||
case _: ArithmeticException | _: ClassCastException => | ||
throw new IllegalArgumentException( | ||
s"The key `$FIELD_ID_METADATA_KEY` must be a 32-bit integer") | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
common/src/main/spark-4.0/org/apache/comet/shims/ShimBatchReader.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,37 @@ | ||
/* | ||
* 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.shims | ||
|
||
import org.apache.spark.paths.SparkPath | ||
import org.apache.spark.sql.catalyst.InternalRow | ||
import org.apache.spark.sql.execution.datasources.PartitionedFile | ||
|
||
object ShimBatchReader { | ||
def newPartitionedFile(partitionValues: InternalRow, file: String): PartitionedFile = | ||
PartitionedFile( | ||
partitionValues, | ||
SparkPath.fromUrlString(file), | ||
-1, // -1 means we read the entire file | ||
-1, | ||
Array.empty[String], | ||
0, | ||
0 | ||
) | ||
} |
31 changes: 31 additions & 0 deletions
31
common/src/main/spark-4.0/org/apache/comet/shims/ShimFileFormat.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,31 @@ | ||
/* | ||
* 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.shims | ||
|
||
import org.apache.spark.sql.execution.datasources.FileFormat | ||
import org.apache.spark.sql.execution.datasources.parquet.ParquetFileFormat | ||
|
||
object ShimFileFormat { | ||
// A name for a temporary column that holds row indexes computed by the file format reader | ||
// until they can be placed in the _metadata struct. | ||
val ROW_INDEX_TEMPORARY_COLUMN_NAME = ParquetFileFormat.ROW_INDEX_TEMPORARY_COLUMN_NAME | ||
|
||
val OPTION_RETURNING_BATCH = FileFormat.OPTION_RETURNING_BATCH | ||
} |
29 changes: 29 additions & 0 deletions
29
common/src/main/spark-4.0/org/apache/comet/shims/ShimResolveDefaultColumns.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,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.comet.shims | ||
|
||
|
||
import org.apache.spark.sql.catalyst.util.ResolveDefaultColumns | ||
import org.apache.spark.sql.types.{StructField, StructType} | ||
|
||
object ShimResolveDefaultColumns { | ||
def getExistenceDefaultValue(field: StructField): Any = | ||
ResolveDefaultColumns.getExistenceDefaultValues(StructType(Seq(field))).head | ||
} |
Oops, something went wrong.