Menu

(Solved) : Given Starter Code Write Transform Use Eliminate Zeros Dists Template Simplifies Compariso Q38012644 . . .

Given this starter code:

import grgapache.spark.sa.catalyst.plans.logical. [LogicalPlan, Sorty import gng.apache.spark.sal.catalyst.rules.Rule import

Write a transform in (use Eliminate Zeros Dists as a template)that simplifies comparison expressions that always evaluate toeither true or false. E.g.,

For example select from T where dist(xi, yl, x2, y2) -1 should simplify to select * from T since dist must always be non-nega

import grgapache.spark.sa.catalyst.plans.logical. [LogicalPlan, Sorty import gng.apache.spark.sal.catalyst.rules.Rule import grg.apache.spark.sal.types. [BooleanType, DoubleType) object Transforms // check if a ScalaUDF Expression is our dist UDF def isDistUdf (udf: ScalaUDF): Boolean { udf. udfName.getorElse (“”) “dist” // get an Expression representing the dist sq UDF with the provided /I arguments def getDistSqUdf(args: Seq [Expression]): ScalaUDF= { ScalaUDF (xl: Double, yl: Double, x2: Double, y2: Double) -> I val yDìff yl -y2 ; DoubleType, args, Seq (DoubleType, DoubleType, DoubleType, DoubleType), udfNameOption.apply(“dist_sq”)) /Return any additional optimization passes here def getoptimizationPasses (spark: SparkSession): Seq[Rule [LogicalPlan]] – Seq (EliminateZeroDists (spark)) case class EliminateZeroDists (spark: SparkSession) extends Rule [LogicalPlan] def apply (plan : LogicalPlan) : LogicalPlan= plan trans formAllExpressions { ScalaUDF if isDistudf (udf) case udf: “ udf.children (0) -uat.children (2) && udf.children (1)- udf.children (3)Literal (0.0, DoubleType) For example select from T where dist(xi, yl, x2, y2) -1 should simplify to select * from T since dist must always be non-negative. Show transcribed image text

Expert Answer


Answer to Given Starter Code Write Transform Use Eliminate Zeros Dists Template Simplifies Compariso Q38012644 . . .

OR