Skip to content

Commit

Permalink
Fix code syle
Browse files Browse the repository at this point in the history
  • Loading branch information
PHILO-HE committed Jun 24, 2024
1 parent 874a61f commit 0d4062f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 24 deletions.
45 changes: 25 additions & 20 deletions velox/functions/sparksql/ConcatWs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,8 @@ class ConcatWs : public exec::VectorFunction {
}
copyToBuffer(
value,
isConstantSeparator()
? StringView(separator_.value())
: decodedSeparator->valueAt<StringView>(row));
isConstantSeparator() ? StringView(separator_.value())
: decodedSeparator->valueAt<StringView>(row));
j++;
}
flatResult.setNoCopy(row, StringView(start, rawBuffer - start));
Expand All @@ -311,7 +310,8 @@ class ConcatWs : public exec::VectorFunction {
if (isConstantSeparator()) {
auto constant = args[0]->as<ConstantVector<StringView>>();
if (constant->isNullAt(0)) {
auto localResult = BaseVector::createNullConstant(outputType, rows.end(), context.pool());
auto localResult = BaseVector::createNullConstant(
outputType, rows.end(), context.pool());
context.moveOrCopyResult(localResult, rows, result);
// rows.applyToSelected([&](auto row) { result->setNull(row, true); });
return;
Expand All @@ -326,13 +326,12 @@ class ConcatWs : public exec::VectorFunction {
rows.applyToSelected(
[&](auto row) { flatResult->setNoCopy(row, StringView("")); });
} else {
rows.applyToSelected(
[&](auto row) {
if (decodedSeparator->isNullAt(row)) {
result->setNull(row, true);
} else {
flatResult->setNoCopy(row, StringView(""));
}
rows.applyToSelected([&](auto row) {
if (decodedSeparator->isNullAt(row)) {
result->setNull(row, true);
} else {
flatResult->setNoCopy(row, StringView(""));
}
});
}
return;
Expand All @@ -345,23 +344,26 @@ class ConcatWs : public exec::VectorFunction {
const std::optional<std::string> separator_;
};

TypePtr ConcatWsCallToSpecialForm::resolveType(const std::vector<TypePtr>& /*argTypes*/) {
return VARCHAR();
TypePtr ConcatWsCallToSpecialForm::resolveType(
const std::vector<TypePtr>& /*argTypes*/) {
return VARCHAR();
}

exec::ExprPtr ConcatWsCallToSpecialForm::constructSpecialForm(
const TypePtr& type,
std::vector<exec::ExprPtr>&& args,
bool trackCpuUsage,
const core::QueryConfig& config) {
const TypePtr& type,
std::vector<exec::ExprPtr>&& args,
bool trackCpuUsage,
const core::QueryConfig& config) {
auto numArgs = args.size();
VELOX_USER_CHECK_GE(
numArgs,
1,
"concat_ws requires one arguments at least, but got {}.",
numArgs);
VELOX_USER_CHECK(args[0]->type()->isVarchar(), "The first argument of concat_ws must be a varchar.");
for (size_t i = 1; i < args.size(); i++){
VELOX_USER_CHECK(
args[0]->type()->isVarchar(),
"The first argument of concat_ws must be a varchar.");
for (size_t i = 1; i < args.size(); i++) {
VELOX_USER_CHECK(
args[i]->type()->isVarchar() ||
(args[i]->type()->isArray() &&
Expand All @@ -374,7 +376,10 @@ exec::ExprPtr ConcatWsCallToSpecialForm::constructSpecialForm(
auto constantExpr = std::dynamic_pointer_cast<exec::ConstantExpr>(args[0]);

if (constantExpr != nullptr) {
separator = constantExpr->value()->asUnchecked<ConstantVector<StringView>>()->valueAt(0).str();
separator = constantExpr->value()
->asUnchecked<ConstantVector<StringView>>()
->valueAt(0)
.str();
}
auto concatWsFunction = std::make_shared<ConcatWs>(separator);
return std::make_shared<exec::Expr>(
Expand Down
8 changes: 4 additions & 4 deletions velox/functions/sparksql/tests/ConcatWsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ TEST_F(ConcatWsTest, mixedStringAndArrayArgs) {
}

TEST_F(ConcatWsTest, nonconstantSeparator) {
auto separatorVector =
makeNullableFlatVector<StringView>({"##", "--", "~~", "**", std::nullopt});
auto separatorVector = makeNullableFlatVector<StringView>(
{"##", "--", "~~", "**", std::nullopt});
auto arrayVector = makeNullableArrayVector<StringView>({
{"red", "blue"},
{"blue", std::nullopt, "yellow", std::nullopt, "orange"},
Expand All @@ -257,8 +257,8 @@ TEST_F(ConcatWsTest, nonconstantSeparator) {
}

TEST_F(ConcatWsTest, separatorOnly) {
auto separatorVector =
makeNullableFlatVector<StringView>({"##", std::nullopt, "~~", "**", std::nullopt});
auto separatorVector = makeNullableFlatVector<StringView>(
{"##", std::nullopt, "~~", "**", std::nullopt});
auto result = evaluate<SimpleVector<StringView>>(
"concat_ws(c0)", makeRowVector({separatorVector}));
auto expected = makeNullableFlatVector<StringView>({
Expand Down

0 comments on commit 0d4062f

Please sign in to comment.