-
Notifications
You must be signed in to change notification settings - Fork 76
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
Feature/350 fix tests #351
Changes from 5 commits
36a09f0
b9bd2ae
693e396
d98ff53
0803dc2
5a383d1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,7 +48,9 @@ | |
<maven.shade.plugin.version>3.2.1</maven.shade.plugin.version> | ||
|
||
<!-- Spark --> | ||
<spark-32.version>3.2.1</spark-32.version> | ||
<spark.default.version>3.2.4</spark.default.version> | ||
<avro.default.version>1.10.2</avro.default.version> | ||
<jackson.core.default.version>2.12.3</jackson.core.default.version> | ||
|
||
<!-- Cross build properties --> | ||
|
||
|
@@ -63,13 +65,15 @@ | |
<scala.compat.version>2.12</scala.compat.version> | ||
|
||
<!--Platforms--> | ||
<spark.version>${spark-32.version}</spark.version> | ||
<spark.version>${spark.default.version}</spark.version> | ||
<avro.version>${avro.default.version}</avro.version> | ||
<jackson.core.version>${jackson.core.default.version}</jackson.core.version> | ||
|
||
<spark.avro.version>${spark.version}</spark.avro.version> | ||
<kafka.spark.version>0-10</kafka.spark.version> | ||
<confluent.version>6.2.1</confluent.version> | ||
|
||
<!--Libs--> | ||
<avro.version>1.10.2</avro.version> | ||
<jacoco.version>0.8.10</jacoco.version> | ||
|
||
<!--Tests--> | ||
|
@@ -119,6 +123,20 @@ | |
</developer> | ||
</developers> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.avro</groupId> | ||
<artifactId>avro</artifactId> | ||
<version>${avro.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-core</artifactId> | ||
<version>${jackson.core.version}</version> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
<dependencies> | ||
<!-- Tests --> | ||
<dependency> | ||
|
@@ -159,14 +177,6 @@ | |
<version>${spark.avro.version}</version> | ||
</dependency> | ||
|
||
<!-- Avro --> | ||
<dependency> | ||
<groupId>org.apache.avro</groupId> | ||
<artifactId>avro</artifactId> | ||
<version>${avro.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<!-- Spark Kafka --> | ||
<dependency> | ||
<groupId>org.apache.spark</groupId> | ||
|
@@ -362,12 +372,36 @@ | |
<profile> | ||
<id>spark-3.2</id> | ||
<properties> | ||
<spark.version>${spark-32.version}</spark.version> | ||
<avro.version>1.10.2</avro.version> | ||
<confluent.version>6.2.1</confluent.version> | ||
<spark.version>${spark.default.version}</spark.version> | ||
<avro.version>${avro.default.version}</avro.version> | ||
<jackson.core.version>${jackson.core.default.version}</jackson.core.version> | ||
</properties> | ||
</profile> | ||
|
||
</profile> | ||
<profile> | ||
<id>spark-3.3</id> | ||
<properties> | ||
<spark.version>3.3.4</spark.version> | ||
<avro.version>1.11.0</avro.version> | ||
<jackson.core.version>2.13.4.2</jackson.core.version> | ||
</properties> | ||
</profile> | ||
<profile> | ||
<id>spark-3.4</id> | ||
<properties> | ||
<spark.version>3.4.2</spark.version> | ||
<avro.version>1.11.1</avro.version> | ||
<jackson.core.version>2.14.2</jackson.core.version> | ||
</properties> | ||
</profile> | ||
<profile> | ||
<id>spark-3.5</id> | ||
<properties> | ||
<spark.version>3.5.0</spark.version> | ||
<avro.version>1.11.2</avro.version> | ||
<jackson.core.version>2.15.2</jackson.core.version> | ||
</properties> | ||
</profile> | ||
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.
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. Yes, I guess we can set it as a constant then. If we want to make it dynamic it in the future, we can always change it |
||
<profile> | ||
<id>uber</id> | ||
<build> | ||
|
@@ -563,11 +597,9 @@ | |
<artifactId>jacoco-maven-plugin</artifactId> | ||
<version>${jacoco.version}</version> | ||
<configuration> | ||
<!-- examples of class excluding --> | ||
<!-- excludes> | ||
<exclude>za/co/absa/enceladus/migrations/continuous/EntityVersionMap.class</exclude> | ||
<exclude>za/co/absa/enceladus/rest_api/exceptions/ValidationException.class</exclude> | ||
</excludes --> | ||
<excludes> | ||
<exclude>za/co/absa/abris/examples/**</exclude> | ||
</excludes> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
|
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.") | ||
} | ||
} | ||
} |
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.
Since the dependency is not declared, where is the Avro coming from? Confluent or Spark?
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.
It's coming from Spark. But I realize that it's basically luck, I didn't think of confluent.
The reason why I removed it is because in principle we should compile against the Avro version that Spark sets, because Avro is packaged with the Spark runtime.
We could just set the Avro version for each Spark version, but we also need to set the version for jackson-core, because Spark does actually override it. E.g. Avro 1.11.2 depends on jackson-core 2.14.2, but Spark 3.5.0 overrides this and uses jackson-core 2.15.2
Another, perhaps radical approach would be to import the pom of spark-parent, and thereby its dependencyManagement section (https://github.com/apache/spark/blob/master/pom.xml#L434-L2857). Then we would be sure that we always use the same dependencies as Spark does. However, unfortunately it's overly intrusive since it defines not only the runtime dependencies, but also test dependencies like scalatest, scalacheck etc.
So for now, I think the better solution is to just define the versions of avro and jackson-core along with the spark version in the respective profiles
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.
I did this for spline agent, but we have separated pom for the uber-jar creation there if I remember correctly.
But I agree, this is a good solution.