-
Notifications
You must be signed in to change notification settings - Fork 92
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
spline #605 MergeIntoNodeBuilder: java.lang.IllegalArgumentException #606
Merged
wajda
merged 8 commits into
release/1.0
from
bugfix/spline-spark-agent-605-merge-attr-transpose
Mar 3, 2023
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
62244c9
spline #605 MergeIntoNodeBuilder: java.lang.IllegalArgumentException:…
wajda 73a03f8
spline #605 Addressing PR comment: rename `src` (that is of type Opti…
wajda ec82e1d
spline #605 minor code style: remove redundant `override val`
wajda 015388d
spline #605 minor Refactoring and code style
wajda d40b4af
spline #605 Refactoring: move `extractChildren(Node)` method from `Li…
wajda fdfdb44
spline #605 Reimplement MERGE INTO attribute dependency resolving alg…
wajda 9d2acf0
Merge branch 'release/1.0' into bugfix/spline-spark-agent-605-merge-a…
wajda ce751f2
spline #605 Refactoring: Rename type alias Attributes -> IOAttributes…
wajda 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
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 |
---|---|---|
|
@@ -16,56 +16,94 @@ | |
|
||
package za.co.absa.spline.harvester.builder.plan | ||
|
||
import org.apache.spark.sql.catalyst.expressions.{Expression => SparkExpression} | ||
import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan | ||
import za.co.absa.commons.reflect.ReflectionUtils.extractValue | ||
import za.co.absa.spline.harvester.IdGeneratorsBundle | ||
import za.co.absa.spline.harvester.ModelConstants.CommonExtras | ||
import za.co.absa.spline.harvester.builder.plan.MergeIntoNodeBuilder._ | ||
import za.co.absa.spline.harvester.converter.{DataConverter, DataTypeConverter} | ||
import za.co.absa.spline.harvester.postprocessing.PostProcessor | ||
import za.co.absa.spline.producer.model.{AttrRef, Attribute, DataOperation, FunctionalExpression} | ||
import za.co.absa.spline.producer.model._ | ||
|
||
class MergeIntoNodeBuilder | ||
(override val logicalPlan: LogicalPlan) | ||
(logicalPlan: LogicalPlan) | ||
(idGenerators: IdGeneratorsBundle, dataTypeConverter: DataTypeConverter, dataConverter: DataConverter, postProcessor: PostProcessor) | ||
extends GenericPlanNodeBuilder(logicalPlan)(idGenerators, dataTypeConverter, dataConverter, postProcessor) { | ||
|
||
private lazy val mergeInputs: Seq[Seq[Attribute]] = inputAttributes.transpose | ||
|
||
override lazy val functionalExpressions: Seq[FunctionalExpression] = Seq.empty | ||
|
||
override lazy val outputAttributes: Seq[Attribute] = | ||
mergeInputs.map(constructMergeAttribute) | ||
|
||
private def constructMergeAttribute(attributes: Seq[Attribute]) = { | ||
val attr1 = attributes.head | ||
val idRefs = attributes.map(a => AttrRef(a.id)) | ||
Attribute( | ||
id = idGenerators.attributeIdGenerator.nextId(), | ||
dataType = attr1.dataType, | ||
childRefs = idRefs, | ||
extra = Map(CommonExtras.Synthetic -> true), | ||
name = attr1.name | ||
) | ||
override lazy val outputAttributes: Seq[Attribute] = { | ||
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. Will this method work when the input attributes are synthetic? I think in this case the proper way is to take |
||
val target: LogicalPlan = extractTarget(logicalPlan) | ||
val trgAttrs: Seq[Attribute] = target.output.map(attributeConverter.convert) | ||
|
||
val dependenciesByAttrName: Map[String, Seq[AttrOrExprRef]] = | ||
(extractMatchedClauses(logicalPlan) ++ extractNonMatchedClauses(logicalPlan)) | ||
.flatMap(extractClauseActions) | ||
.map((a: DeltaMergeAction) => { | ||
val trgAttrName = extractActionTargetAttrName(a) | ||
val srcExpr = extractActionSourceExpression(a) | ||
trgAttrName -> exprToRefConverter.convert(srcExpr) | ||
}) | ||
.groupBy { case (attrName, _) => attrName } | ||
.mapValues(_.map({ case (_, ref) => ref }).distinct) | ||
|
||
val outAttrs = trgAttrs.map(trgAttr => { | ||
val targetRef = AttrRef(trgAttr.id) | ||
val sourceRefs: Seq[AttrOrExprRef] = dependenciesByAttrName(trgAttr.name) | ||
Attribute( | ||
id = idGenerators.attributeIdGenerator.nextId(), | ||
dataType = trgAttr.dataType, | ||
childRefs = (targetRef +: sourceRefs).distinct, | ||
extra = Map(CommonExtras.Synthetic -> true), | ||
name = trgAttr.name | ||
) | ||
}) | ||
|
||
outAttrs | ||
} | ||
|
||
override def build(): DataOperation = { | ||
|
||
val condition = extractValue[Any](logicalPlan, "condition").toString | ||
val matchedClauses = extractValue[Seq[Any]](logicalPlan, "matchedClauses").map(_.toString) | ||
val notMatchedClauses = extractValue[Seq[Any]](logicalPlan, "notMatchedClauses").map(_.toString) | ||
val conditionStr = extractCondition(logicalPlan).toString | ||
val matchedClausesStr = extractMatchedClauses(logicalPlan).map(_.toString) | ||
val notMatchedClausesStr = extractNonMatchedClauses(logicalPlan).map(_.toString) | ||
|
||
val dop = DataOperation( | ||
id = operationId, | ||
name = logicalPlan.nodeName, | ||
childIds = childIds, | ||
output = outputAttributes.map(_.id), | ||
params = Map( | ||
"condition" -> condition, | ||
"matchedClauses" -> matchedClauses, | ||
"notMatchedClauses" -> notMatchedClauses), | ||
"condition" -> conditionStr, | ||
"matchedClauses" -> matchedClausesStr, | ||
"notMatchedClauses" -> notMatchedClausesStr), | ||
extra = Map.empty | ||
) | ||
|
||
postProcessor.process(dop) | ||
} | ||
} | ||
|
||
object MergeIntoNodeBuilder { | ||
|
||
type DeltaMergeIntoClause = SparkExpression | ||
type DeltaMergeAction = SparkExpression | ||
|
||
def extractChildren(mergeNode: LogicalPlan): Seq[LogicalPlan] = Seq(extractSource(mergeNode), extractTarget(mergeNode)) | ||
|
||
private def extractSource(mergeNode: LogicalPlan): LogicalPlan = extractValue[LogicalPlan](mergeNode, "source") | ||
|
||
private def extractTarget(mergeNode: LogicalPlan): LogicalPlan = extractValue[LogicalPlan](mergeNode, "target") | ||
|
||
private def extractCondition(mergeNode: LogicalPlan): SparkExpression = extractValue[SparkExpression](mergeNode, "condition") | ||
|
||
private def extractMatchedClauses(mergeNode: LogicalPlan): Seq[DeltaMergeIntoClause] = extractValue[Seq[DeltaMergeIntoClause]](mergeNode, "matchedClauses") | ||
|
||
private def extractNonMatchedClauses(mergeNode: LogicalPlan): Seq[DeltaMergeIntoClause] = extractValue[Seq[DeltaMergeIntoClause]](mergeNode, "notMatchedClauses") | ||
|
||
private def extractClauseActions(clause: DeltaMergeIntoClause): Seq[DeltaMergeAction] = extractValue[Seq[DeltaMergeAction]](clause, "actions") | ||
|
||
private def extractActionTargetAttrName(clause: DeltaMergeAction): String = extractValue[Seq[String]](clause, "targetColNameParts").head | ||
|
||
private def extractActionSourceExpression(clause: DeltaMergeAction): SparkExpression = extractValue[SparkExpression](clause, "expr") | ||
} |
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
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.
I feel like this will only decrease the readability. I don't see any problems with using
Seq[Attribute]
as a type.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 was primarily introduced to get rid of
Seq[Seq[Attribute]]
in other places.