Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GLUTEN-6103][VL] Support array_sort #6104

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1872,4 +1872,17 @@ class TestOperator extends VeloxWholeStageTransformerSuite with AdaptiveSparkPla
}
}
}

test("array_sort") {
runQueryAndCompare("""
|select array_sort(collect_list(l_orderkey))
|from lineitem
|where l_partkey in (1552, 674, 1062)
|group by l_partkey
|""".stripMargin) {
df =>
val op = collect(df.queryExecution.executedPlan) { case p: ProjectExecTransformer => p }
assert(op.size == 2)
}
}
}
1 change: 1 addition & 0 deletions cpp/velox/operators/functions/RegistrationAllFunctions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ void registerFunctionOverwrite() {
velox::functions::registerBinaryIntegral<velox::functions::CheckedMinusFunction>({"check_subtract"});
velox::functions::registerBinaryIntegral<velox::functions::CheckedMultiplyFunction>({"check_multiply"});
velox::functions::registerBinaryIntegral<velox::functions::CheckedDivideFunction>({"check_divide"});
velox::functions::prestosql::registerArrayFunctions("presto_");
}
} // namespace

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,25 @@ object ExpressionConverter extends SQLConfHelper with Logging {
Seq(replaceWithExpressionTransformerInternal(c.child, attributeSeq, expressionsMap)),
c
)
case ArraySort(argument, function, _) if BackendsApiManager.getBackendName == "velox" =>
// scalastyle:off
// We use a special expressions mapping here to translate function name
// of LessThan/GreaterThan/EqualTo to lt/gt/eq, instead of lessthan/greaterthan/equalto.
// Refer to https://github.com/facebookincubator/velox/blob/main/velox/functions/prestosql/SimpleComparisonMatcher.cpp#L79
// scalastyle:on
val specialExpressionsMap = expressionsMap ++ Map(
(Sig[LessThan]("")).expClass -> "presto_lt",
(Sig[GreaterThan]("")).expClass -> "presto_gt",
(Sig[EqualTo]("")).expClass -> "presto_eq"
)
GenericExpressionTransformer(
substraitExprName,
Seq(
replaceWithExpressionTransformerInternal(argument, attributeSeq, expressionsMap),
replaceWithExpressionTransformerInternal(function, attributeSeq, specialExpressionsMap)
),
expr
)
case expr =>
GenericExpressionTransformer(
substraitExprName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ object ExpressionMappings {
Sig[ArrayMin](ARRAY_MIN),
Sig[ArrayJoin](ARRAY_JOIN),
Sig[SortArray](SORT_ARRAY),
Sig[ArraySort](ARRAY_SORT),
Sig[ArraysOverlap](ARRAYS_OVERLAP),
Sig[ArrayPosition](ARRAY_POSITION),
Sig[ArrayDistinct](ARRAY_DISTINCT),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ object ExpressionNames {
final val ARRAY_MIN = "array_min"
final val ARRAY_JOIN = "array_join"
final val SORT_ARRAY = "sort_array"
final val ARRAY_SORT = "presto_array_sort"
final val ARRAYS_OVERLAP = "arrays_overlap"
final val ARRAY_POSITION = "array_position"
final val ARRAY_DISTINCT = "array_distinct"
Expand Down
Loading