Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@yunchipang
Copy link
Contributor

Problem

Spark 4 introduced changes to the LogicalRelation constructor signature, causing test failures and requiring version-specific exclusions.
Closes: #3885

Solution

Create a LogicalRelationFactory utility class that uses reflection to automatically detect and call the appropriate constructor based on the available Spark version.

Checklist

  • You've signed-off your work
  • Your pull request title follows our guidelines
  • Your changes are accompanied by tests (if relevant)
  • Your change contains a small diff and is self-contained
  • You've updated any relevant documentation (if relevant)
  • Your comment includes a one-liner for the changelog about the specific purpose of the change (not required for changes to tests, docs, or CI config)
  • You've versioned the core OpenLineage model or facets according to SchemaVer (if relevant)
  • You've added a header to source files (if relevant)

SPDX-License-Identifier: Apache-2.0
Copyright 2018-2025 contributors to the OpenLineage project

@yunchipang yunchipang requested a review from a team as a code owner July 24, 2025 03:55
@boring-cyborg boring-cyborg bot added area:integration/spark area:tests Testing code language:java Uses Java programming language labels Jul 24, 2025
@mobuchowski
Copy link
Member

@yunchipang this one also has PMD issues:

> Task :shared:pmdMain FAILED
/home/circleci/openlineage/integration/spark/shared/src/main/java/io/openlineage/spark/agent/util/LogicalRelationFactory.java:42:       AvoidLiteralsInIfCondition:     Avoid using Literals in Conditional Statements
/home/circleci/openlineage/integration/spark/shared/src/main/java/io/openlineage/spark/agent/util/LogicalRelationFactory.java:47:       AvoidLiteralsInIfCondition:     Avoid using Literals in Conditional Statements

Comment on lines +42 to +53
try {
Constructor<?> constructor = getLogicalRelationConstructor();
if (constructor.getParameterCount() == SPARK_3_PARAM_COUNT) {
return Optional.of(
(LogicalRelation)
constructor.newInstance(relation, attributes, catalogTable, isStreaming));
} else if (constructor.getParameterCount() == SPARK_4_PARAM_COUNT) {
return Optional.of(
(LogicalRelation)
constructor.newInstance(
relation, attributes, catalogTable, isStreaming, Option.empty()));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice workaround 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the review!

@mobuchowski mobuchowski merged commit 77e9158 into OpenLineage:main Jul 25, 2025
26 checks passed
@yunchipang yunchipang deleted the 3885-fix-tests-uses-LogicalRelation branch July 25, 2025 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:integration/spark area:tests Testing code language:java Uses Java programming language

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Spark4] Fix tests which instantiate LogicalRelation

2 participants