Skip to content

Commit

Permalink
[GLUTEN-8598][CH] Fix diff for cast string to long (#8701)
Browse files Browse the repository at this point in the history
  • Loading branch information
exmy authored Feb 11, 2025
1 parent 39950cf commit cc7a355
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,17 @@ class GlutenFunctionValidateSuite extends GlutenClickHouseWholeStageTransformerS
compareResultsAgainstVanillaSpark(sql, true, { _ => })
}

test("GLUTEN-8598 Fix diff for cast string to long") {
withSQLConf(
SQLConf.OPTIMIZER_EXCLUDED_RULES.key ->
(ConstantFolding.ruleName + "," + NullPropagation.ruleName)) {
runQueryAndCompare(
"select cast(' \t2570852431\n' as long), cast('25708\t52431\n' as long)",
noFallBack = false
)(checkGlutenOperatorMatch[ProjectExecTransformer])
}
}

test("Test transform_keys/transform_values") {
val sql = """
|select id, sort_array(map_entries(m1)), sort_array(map_entries(m2)) from(
Expand Down
5 changes: 3 additions & 2 deletions cpp-ch/local-engine/Parser/ExpressionParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,9 @@ ExpressionParser::NodeRawConstPtr ExpressionParser::parseExpression(ActionsDAG &
else if (isString(denull_input_type) && isInt(denull_output_type))
{
/// Spark cast(x as INT) if x is String -> CH cast(trim(x) as INT)
/// Refer to https://github.com/apache/incubator-gluten/issues/4956
args[0] = toFunctionNode(actions_dag, "trim", {args[0]});
/// Refer to https://github.com/apache/incubator-gluten/issues/4956 and https://github.com/apache/incubator-gluten/issues/8598
auto trim_str_arg = addConstColumn(actions_dag, std::make_shared<DataTypeString>(), " \t\n\r\f");
args[0] = toFunctionNode(actions_dag, "trimBothSpark", {args[0], trim_str_arg});
args.emplace_back(addConstColumn(actions_dag, std::make_shared<DataTypeString>(), output_type->getName()));
result_node = toFunctionNode(actions_dag, "CAST", args);
}
Expand Down

0 comments on commit cc7a355

Please sign in to comment.