Skip to content

Commit

Permalink
spark agent #262 special Databricks Window handling (#282)
Browse files Browse the repository at this point in the history
* spark agent #262 special Databricks Window handling

* spark agent #262 add method comment
  • Loading branch information
cerveada authored Aug 16, 2021
1 parent d9887e3 commit 356db36
Showing 1 changed file with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,34 @@

package za.co.absa.spline.harvester.builder

import org.apache.spark.sql.catalyst.expressions.{Alias, Attribute, Expression}
import org.apache.spark.sql.catalyst.expressions.{Alias, Attribute, Expression, NamedExpression}
import org.apache.spark.sql.catalyst.plans.logical.Window
import za.co.absa.commons.reflect.ReflectionUtils
import za.co.absa.spline.harvester.ComponentCreatorFactory
import za.co.absa.spline.harvester.postprocessing.PostProcessor

import scala.util.Try

class WindowNodeBuilder
(override val operation: Window)
(override val componentCreatorFactory: ComponentCreatorFactory, postProcessor: PostProcessor)
extends GenericNodeBuilder(operation)(componentCreatorFactory, postProcessor) {

override def resolveAttributeChild(attribute: Attribute): Option[Expression] = {
operation.windowExpressions
extractNamedExpressions(operation)
.find(_.exprId == attribute.exprId)
.map(_.asInstanceOf[Alias])
}

/**
* This method solves Spark and Databricks differences (See issue #262)
*/
private def extractNamedExpressions(operation: Window): Seq[NamedExpression] = {
def extractField(name: String) =
ReflectionUtils.extractFieldValue[Seq[NamedExpression]](operation, name)

Try(extractField("windowExpressions"))
.getOrElse(extractField("projectList"))
}

}

0 comments on commit 356db36

Please sign in to comment.