Skip to content

Commit

Permalink
Fix comment
Browse files Browse the repository at this point in the history
  • Loading branch information
PHILO-HE committed Dec 2, 2024
1 parent ef14f24 commit 6fae42f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
2 changes: 1 addition & 1 deletion velox/functions/sparksql/ConcatWs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ class ConcatWs : public exec::VectorFunction {
auto size = arrayVector->sizeAt(indices[row]);
auto offset = arrayVector->offsetAt(indices[row]);

for (int k = 0; k < size; ++k) {
for (auto k = 0; k < size; ++k) {
if (!decodedElements[i].isNullAt(offset + k)) {
auto element = decodedElements[i].valueAt<StringView>(offset + k);
copyToBuffer(element.data(), element.size());
Expand Down
35 changes: 17 additions & 18 deletions velox/functions/sparksql/tests/ConcatWsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdint.h>
#include "velox/functions/sparksql/tests/SparkFunctionBaseTest.h"
#include "velox/type/Type.h"

#include <stdint.h>

namespace facebook::velox::functions::sparksql::test {
namespace {

Expand All @@ -36,17 +35,17 @@ class ConcatWsTest : public SparkFunctionBaseTest {

void testConcatWsFlatVector(
const std::vector<std::vector<std::string>>& inputTable,
const size_t argsCount,
const size_t& argsCount,
const std::string& separator) {
std::vector<VectorPtr> inputVectors;

for (int i = 0; i < argsCount; i++) {
for (auto i = 0; i < argsCount; i++) {
inputVectors.emplace_back(
BaseVector::create(VARCHAR(), inputTable.size(), execCtx_.pool()));
}

for (int row = 0; row < inputTable.size(); row++) {
for (int col = 0; col < argsCount; col++) {
for (auto row = 0; row < inputTable.size(); row++) {
for (auto col = 0; col < argsCount; col++) {
std::static_pointer_cast<FlatVector<StringView>>(inputVectors[col])
->set(row, StringView(inputTable[row][col]));
}
Expand All @@ -55,7 +54,7 @@ class ConcatWsTest : public SparkFunctionBaseTest {
auto buildConcatQuery = [&]() {
std::string output = "concat_ws('" + separator + "'";

for (int i = 0; i < argsCount; i++) {
for (auto i = 0; i < argsCount; i++) {
output += ",c" + std::to_string(i);
}
output += ")";
Expand All @@ -67,7 +66,7 @@ class ConcatWsTest : public SparkFunctionBaseTest {
auto produceExpectedResult = [&](const std::vector<std::string>& inputs) {
auto isFirst = true;
std::string output;
for (int i = 0; i < inputs.size(); i++) {
for (auto i = 0; i < inputs.size(); i++) {
auto value = inputs[i];
if (isFirst) {
isFirst = false;
Expand All @@ -79,7 +78,7 @@ class ConcatWsTest : public SparkFunctionBaseTest {
return output;
};

for (int i = 0; i < inputTable.size(); ++i) {
for (auto i = 0; i < inputTable.size(); ++i) {
EXPECT_EQ(result->valueAt(i), produceExpectedResult(inputTable[i]))
<< "at " << i;
}
Expand All @@ -93,22 +92,22 @@ TEST_F(ConcatWsTest, stringArgs) {
auto c1 = generateRandomString(20);
auto result = evaluate<SimpleVector<StringView>>(
fmt::format("concat_ws('-', '{}', '{}')", c0, c1), rows);
for (int i = 0; i < 10; ++i) {
for (auto i = 0; i < 10; ++i) {
EXPECT_EQ(result->valueAt(i), c0 + "-" + c1);
}

// Test with variable arguments.
size_t maxArgsCount = 10;
size_t rowCount = 100;
size_t maxStringLength = 100;
const size_t maxArgsCount = 10;
const size_t rowCount = 100;
const size_t maxStringLength = 100;

std::vector<std::vector<std::string>> inputTable;
for (int argsCount = 1; argsCount <= maxArgsCount; argsCount++) {
for (auto argsCount = 1; argsCount <= maxArgsCount; argsCount++) {
inputTable.clear();
inputTable.resize(rowCount, std::vector<std::string>(argsCount));

for (int row = 0; row < rowCount; row++) {
for (int col = 0; col < argsCount; col++) {
for (auto row = 0; row < rowCount; row++) {
for (auto col = 0; col < argsCount; col++) {
inputTable[row][col] =
generateRandomString(folly::Random::rand32() % maxStringLength);
}
Expand Down Expand Up @@ -137,7 +136,7 @@ TEST_F(ConcatWsTest, stringArgsWithNulls) {
velox::test::assertEqualVectors(expected, result);
}

TEST_F(ConcatWsTest, mixedConstantAndNonconstantStringArgs) {
TEST_F(ConcatWsTest, mixedConstantAndNonConstantStringArgs) {
size_t maxStringLength = 100;
std::string value;
auto data = makeRowVector({
Expand Down Expand Up @@ -256,7 +255,7 @@ TEST_F(ConcatWsTest, mixedStringAndArrayArgs) {
velox::test::assertEqualVectors(expected, result);
}

TEST_F(ConcatWsTest, nonconstantSeparator) {
TEST_F(ConcatWsTest, nonConstantSeparator) {
auto separatorVector = makeNullableFlatVector<StringView>(
{"##", "--", "~~", "**", std::nullopt});
auto arrayVector = makeNullableArrayVector<StringView>({
Expand Down

0 comments on commit 6fae42f

Please sign in to comment.