Skip to content

Commit

Permalink
[GLUTEN-6669][CH] Fix diff of cast string to boolean (#6711)
Browse files Browse the repository at this point in the history
  • Loading branch information
exmy authored Aug 6, 2024
1 parent cc1f495 commit 6ab62fc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2435,6 +2435,16 @@ class GlutenClickHouseTPCHSaltNullParquetSuite extends GlutenClickHouseTPCHAbstr
}
}

test("GLUTEN-6669: test cast string to boolean") {
withSQLConf(
SQLConf.OPTIMIZER_EXCLUDED_RULES.key -> (ConstantFolding.ruleName + "," + NullPropagation.ruleName)) {
runQueryAndCompare(
"select cast('1' as boolean), cast('t' as boolean), cast('all' as boolean), cast('f' as boolean)",
noFallBack = false
)(checkGlutenOperatorMatch[ProjectExecTransformer])
}
}

test("GLUTEN-4032: fix shuffle read coredump after union") {
val sql =
"""
Expand Down
8 changes: 7 additions & 1 deletion cpp-ch/local-engine/Parser/SerializedPlanParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,7 @@ const ActionsDAG::Node * SerializedPlanParser::parseExpression(ActionsDAG& actio
throw Exception(ErrorCodes::BAD_ARGUMENTS, "Doesn't have type or input in cast node.");
ActionsDAG::NodeRawConstPtrs args;

String cast_function = "CAST";
const auto & input = rel.cast().input();
args.emplace_back(parseExpression(actions_dag, input));

Expand Down Expand Up @@ -1144,10 +1145,15 @@ const ActionsDAG::Node * SerializedPlanParser::parseExpression(ActionsDAG& actio
/// Refer to https://github.com/apache/incubator-gluten/issues/4956
args[0] = toFunctionNode(actions_dag, "trim", {args[0]});
}
else if (isString(non_nullable_input_type) && substrait_type.has_bool_())
{
/// cast(string to boolean)
cast_function = "accurateCastOrNull";
}

/// Common process
args.emplace_back(addColumn(actions_dag, std::make_shared<DataTypeString>(), output_type->getName()));
function_node = toFunctionNode(actions_dag, "CAST", args);
function_node = toFunctionNode(actions_dag, cast_function, args);
}

actions_dag.addOrReplaceInOutputs(*function_node);
Expand Down

0 comments on commit 6ab62fc

Please sign in to comment.