com.sparkutils.quality.impl.longPair.AsUUID.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of quality_9.1.dbr_3.1_2.12 Show documentation
Show all versions of quality_9.1.dbr_3.1_2.12 Show documentation
A Spark library for managing in-process data quality rules via Spark SQL
The newest version!
package com.sparkutils.quality.impl.longPair
import org.apache.spark.sql.Column
import org.apache.spark.sql.catalyst.expressions.codegen.{CodegenContext, ExprCode}
import org.apache.spark.sql.catalyst.expressions.{BinaryExpression, Expression}
import org.apache.spark.sql.types.{DataType, StringType}
import org.apache.spark.unsafe.types.UTF8String
object AsUUID {
def apply(lower: Column, higher: Column): Column =
new Column(AsUUID(lower.expr, higher.expr))
}
/**
* Converts a lower and higher pair of longs into a uuid string
* @param left
* @param right
*/
case class AsUUID(left: Expression, right: Expression) extends BinaryExpression {
protected def withNewChildrenInternal(newLeft: Expression, newRight: Expression): Expression = copy(left = newLeft, right = newRight)
override protected def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode =
defineCodeGen(ctx, ev, (lower, higher) => s"org.apache.spark.unsafe.types.UTF8String.fromString(new java.util.UUID($higher, $lower).toString())")
override def dataType: DataType = StringType
override protected def nullSafeEval(lower: Any, higher: Any): Any =
UTF8String.fromString(new java.util.UUID(higher.asInstanceOf[Long], lower.asInstanceOf[Long]).toString)
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy