Skip to content

Commit

Permalink
Separate the impl for backends
Browse files Browse the repository at this point in the history
  • Loading branch information
PHILO-HE committed Nov 24, 2023
1 parent 585275e commit 1efa667
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,14 @@ class CHSparkPlanExecApi extends SparkPlanExecApi {
left: ExpressionTransformer,
right: ExpressionTransformer,
original: GetMapValue): ExpressionTransformer =
new GetMapValueTransformer(substraitExprName, left, right, original.failOnError, original)
GetMapValueTransformer(substraitExprName, left, right, original.failOnError, original)

override def genRandTransformer(
substraitExprName: String,
explicitSeed: ExpressionTransformer,
original: Rand): ExpressionTransformer = {
GenericExpressionTransformer(substraitExprName, Seq(explicitSeed), original)
}

/**
* Generate ShuffleDependency for ColumnarShuffleExchangeExec.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,8 @@ class GlutenClickHouseTPCHParquetSuite extends GlutenClickHouseTPCHAbstractSuite
}

test("test 'function rand'") {
// TODO: add rand(1), rand(null) test back.
runSql("select rand() from range(10)")(checkOperatorMatch[ProjectExecTransformer])
runSql("select rand(), rand(1), rand(null) from range(10)")(
checkOperatorMatch[ProjectExecTransformer])
}

test("test 'function date_add/date_sub/datediff'") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ trait SparkPlanExecApi {
GenericExpressionTransformer(substraitExprName, Seq(srcExpr, regexExpr, limitExpr), original)
}

def genRandTransformer(
substraitExprName: String,
explicitSeed: ExpressionTransformer,
original: Rand): ExpressionTransformer = {
RandTransformer(substraitExprName, explicitSeed, original)
}

/** Generate an expression transformer to transform GetMapValue to Substrait. */
def genGetMapValueTransformer(
substraitExprName: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ object ExpressionConverter extends SQLConfHelper with Logging {
replaceWithExpressionTransformer(m.child, attributeSeq),
m)
case rand: Rand =>
RandTransformer(
BackendsApiManager.getSparkPlanExecApiInstance.genRandTransformer(
substraitExprName,
replaceWithExpressionTransformer(rand.child, attributeSeq),
rand)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,6 @@ case class RandTransformer(
functionMap,
ConverterUtils.makeFuncName(substraitExprName, Seq(original.child.dataType)))
val inputNodes = Lists.newArrayList[ExpressionNode]()
// inputNodes.add(explicitSeed.doTransform(args))
// val partitionIndex = TaskContext.getPartitionId()
// val partitionIndexNode = ExpressionBuilder.makeLiteral(partitionIndex, IntegerType, false)
// inputNodes.add(partitionIndexNode)
val typeNode = ConverterUtils.getTypeNode(original.dataType, original.nullable)
ExpressionBuilder.makeScalarFunction(functionId, inputNodes, typeNode)
}
Expand Down

0 comments on commit 1efa667

Please sign in to comment.