-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Works for Spark 3.5.0 * Update GH action to run for latest spark versions * Let Avro dependency be managed by Spark * Exclude examples from code coverage * Explicitly set avro and jackson versions * Fix version
- Loading branch information
1 parent
ec6772b
commit fda9b4f
Showing
6 changed files
with
100 additions
and
26 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
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
42 changes: 42 additions & 0 deletions
42
src/main/scala/za/co/absa/abris/examples/utils/CompatibleRowEncoder.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,42 @@ | ||
/* | ||
* Copyright 2019 ABSA Group Limited | ||
* | ||
* Licensed 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 za.co.absa.abris.examples.utils | ||
|
||
import org.apache.spark.sql.{Encoder, Row} | ||
import org.apache.spark.sql.types.StructType | ||
|
||
import scala.util.Try | ||
|
||
object CompatibleRowEncoder { | ||
def apply(schema: StructType): Encoder[Row] = { | ||
// Spark < 3.5.0 | ||
val rowEncoderTry = Try { | ||
val rowEncoderClass = Class.forName("org.apache.spark.sql.catalyst.encoders.RowEncoder") | ||
val applyMethod = rowEncoderClass.getMethod("apply", classOf[StructType]) | ||
applyMethod.invoke(null, schema).asInstanceOf[Encoder[Row]] | ||
} | ||
|
||
// Spark >= 3.5.0 | ||
rowEncoderTry.orElse(Try { | ||
val encodersClass = Class.forName("org.apache.spark.sql.Encoders") | ||
val rowMethod = encodersClass.getMethod("row", classOf[StructType]) | ||
rowMethod.invoke(null, schema).asInstanceOf[Encoder[Row]] | ||
}).getOrElse { | ||
throw new IllegalStateException("Neither RowEncoder.apply nor Encoders.row is available in the Spark version.") | ||
} | ||
} | ||
} |
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