Skip to content

Commit

Permalink
[VL] support uuid function
Browse files Browse the repository at this point in the history
  • Loading branch information
zhli1142015 committed Mar 20, 2024
1 parent 6514392 commit a273baa
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import org.apache.spark.sql.catalyst.{AggregateFunctionRewriteRule, FlushableHas
import org.apache.spark.sql.catalyst.analysis.FunctionRegistry.FunctionBuilder
import org.apache.spark.sql.catalyst.catalog.BucketSpec
import org.apache.spark.sql.catalyst.catalog.CatalogTypes.TablePartitionSpec
import org.apache.spark.sql.catalyst.expressions.{Alias, Ascending, Attribute, Cast, CreateNamedStruct, ElementAt, Expression, ExpressionInfo, Generator, GetArrayItem, GetMapValue, GetStructField, If, IsNaN, Literal, Murmur3Hash, NamedExpression, NaNvl, PosExplode, Round, SortOrder, StringSplit, StringTrim}
import org.apache.spark.sql.catalyst.expressions.{Alias, Ascending, Attribute, Cast, CreateNamedStruct, ElementAt, Expression, ExpressionInfo, Generator, GetArrayItem, GetMapValue, GetStructField, If, IsNaN, Literal, Murmur3Hash, NamedExpression, NaNvl, PosExplode, Round, SortOrder, StringSplit, StringTrim, Uuid}
import org.apache.spark.sql.catalyst.expressions.aggregate.{AggregateExpression, HLLAdapter}
import org.apache.spark.sql.catalyst.optimizer.BuildSide
import org.apache.spark.sql.catalyst.plans.JoinType
Expand Down Expand Up @@ -129,6 +129,13 @@ class SparkPlanExecApiImpl extends SparkPlanExecApi {
)
}

/** Transform Uuid to Substrait. */
override def genUuidTransformer(
substraitExprName: String,
original: Uuid): ExpressionTransformer = {
UuidTransformer(substraitExprName, original)
}

/** Transform map_entries to Substrait. */
override def genMapEntriesTransformer(
substraitExprName: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import io.glutenproject.substrait.rel.LocalFilesNode.ReadFileFormat
import io.glutenproject.substrait.rel.LocalFilesNode.ReadFileFormat.{DwrfReadFormat, OrcReadFormat, ParquetReadFormat}

import org.apache.spark.sql.catalyst.catalog.BucketSpec
import org.apache.spark.sql.catalyst.expressions.{Alias, CumeDist, DenseRank, Descending, Expression, Lag, Lead, Literal, NamedExpression, NthValue, NTile, PercentRank, Rand, RangeFrame, Rank, RowNumber, SortOrder, SpecialFrameBoundary, SpecifiedWindowFrame}
import org.apache.spark.sql.catalyst.expressions.{Alias, CumeDist, DenseRank, Descending, Expression, Lag, Lead, Literal, NamedExpression, NthValue, NTile, PercentRank, Rand, RangeFrame, Rank, RowNumber, SortOrder, SpecialFrameBoundary, SpecifiedWindowFrame, Uuid}
import org.apache.spark.sql.catalyst.expressions.aggregate.{AggregateExpression, Count, Sum}
import org.apache.spark.sql.catalyst.plans.JoinType
import org.apache.spark.sql.catalyst.util.CharVarcharUtils
Expand Down Expand Up @@ -388,6 +388,7 @@ object BackendSettings extends BackendSettingsApi {
// Block directly falling back the below functions by FallbackEmptySchemaRelation.
case alias: Alias => checkExpr(alias.child)
case _: Rand => true
case _: Uuid => true
case _ => false
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ class VeloxFunctionsValidateSuite extends VeloxWholeStageTransformerSuite {
}
}

<<<<<<< HEAD
test("Test make_timestamp function") {
withTempPath {
path =>
Expand Down Expand Up @@ -510,6 +511,11 @@ class VeloxFunctionsValidateSuite extends VeloxWholeStageTransformerSuite {
|""".stripMargin) {
checkOperatorMatch[ProjectExecTransformer]
}
=======
test("Test uuid function") {
runQueryAndCompare("""SELECT uuid() from lineitem limit 100""".stripMargin, false) {
checkOperatorMatch[ProjectExecTransformer]
>>>>>>> 4968b83b1 ([VL] support uuid function)
}
}
}
1 change: 1 addition & 0 deletions docs/velox-backend-support-progress.md
Original file line number Diff line number Diff line change
Expand Up @@ -428,3 +428,4 @@ Gluten supports 199 functions. (Draw to right to see all data types)
| spark_partition_id | | | S | | | | | | | | | | | | | | | | | | | |
| stack | | | | | | | | | | | | | | | | | | | | | | |
| xxhash64 | xxhash64 | xxhash64 | | | | | | | | | | | | | | | | | | | | |
| uuid | uuid | uuid | S | | | | | | | | | | | | | | | | | | | |
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ trait SparkPlanExecApi {
throw new GlutenNotSupportException("NaNvl is not supported")
}

def genUuidTransformer(substraitExprName: String, original: Uuid): ExpressionTransformer = {
GenericExpressionTransformer(substraitExprName, Seq(), original)
}

/** Transform map_entries to Substrait. */
def genMapEntriesTransformer(
substraitExprName: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,8 @@ object ExpressionConverter extends SQLConfHelper with Logging {
val childrenTransformers =
e.children.map(replaceWithExpressionTransformerInternal(_, attributeSeq, expressionsMap))
e.getTransformer(childrenTransformers)
case u: Uuid =>
BackendsApiManager.getSparkPlanExecApiInstance.genUuidTransformer(substraitExprName, u)
case expr =>
GenericExpressionTransformer(
substraitExprName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,18 @@ case class GetArrayStructFieldsTransformer(
ExpressionBuilder.makeScalarFunction(functionId, inputNodes, typeNode)
}
}

case class UuidTransformer(substraitExprName: String, original: Uuid)
extends ExpressionTransformer {

override def doTransform(args: java.lang.Object): ExpressionNode = {
val functionMap = args.asInstanceOf[java.util.HashMap[String, java.lang.Long]]
val functionId = ExpressionBuilder.newScalarFunction(
functionMap,
ConverterUtils.makeFuncName(substraitExprName, Seq(LongType)))
val seed = Literal(original.randomSeed.get)
val inputNodes = Lists.newArrayList[ExpressionNode](LiteralTransformer(seed).doTransform(args))
val typeNode = ConverterUtils.getTypeNode(original.dataType, original.nullable)
ExpressionBuilder.makeScalarFunction(functionId, inputNodes, typeNode)
}
}

0 comments on commit a273baa

Please sign in to comment.