Skip to content

Commit 13e43ee

Browse files
style(clang-tidy): apply more fixes found by clang-tidy
This PR applies more fixes found by `clang-tidy`. Curiously, they only show up with #148, which consumes `abseil-cpp` differently. Signed-off-by: Ingo Müller <ingomueller@google.com>
1 parent 83b2ec1 commit 13e43ee

13 files changed

Lines changed: 40 additions & 38 deletions

export/planloader/planloader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ SerializedPlan* load_substrait_plan(const char* filename) {
2424
strncpy(newPlan->error_message, errMsg.data(), errMsg.length() + 1);
2525
return newPlan;
2626
}
27-
::substrait::proto::Plan plan = *planOrError;
27+
const ::substrait::proto::Plan& plan = *planOrError;
2828
std::string text = plan.SerializeAsString();
2929
newPlan->buffer = new unsigned char[text.length() + 1];
3030
memcpy(newPlan->buffer, text.data(), text.length() + 1);

src/substrait/common/PlanTransformerTool.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ int main(int argc, char* argv[]) {
3838

3939
auto planOrError = io::substrait::loadPlan(argv[1]);
4040
if (!planOrError.ok()) {
41-
std::cerr << planOrError.status() << std::endl;
41+
std::cerr << planOrError.status() << '\n';
4242
return EXIT_FAILURE;
4343
}
4444

4545
auto format = io::substrait::planFileFormatFromText(argv[3]);
4646

4747
auto result = io::substrait::savePlan(*planOrError, argv[2], format);
4848
if (!result.ok()) {
49-
std::cerr << result << std::endl;
49+
std::cerr << result << '\n';
5050
return EXIT_FAILURE;
5151
}
5252

src/substrait/expression/DecimalLiteral.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ DecimalLiteral DecimalLiteral::fromString(
5656
}
5757
std::uint8_t valueBytes[16];
5858
uint128ToBytes(v, valueBytes);
59-
return {std::string((const char*)valueBytes, 16), precision, scale};
59+
return {
60+
std::string(reinterpret_cast<const char*>(valueBytes), 16),
61+
precision,
62+
scale};
6063
}
6164

6265
bool DecimalLiteral::isValid() {

src/substrait/textplan/SymbolTable.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* SPDX-License-Identifier: Apache-2.0 */
22
#include "substrait/textplan/SymbolTable.h"
33

4+
#include <algorithm>
45
#include <any>
56
#include <iomanip>
67
#include <map>
@@ -27,7 +28,7 @@ const std::string& symbolTypeName(SymbolType type) {
2728
"kSourceDetail",
2829
"kField",
2930
};
30-
auto typeNum = int32_t(type);
31+
auto typeNum = static_cast<int32_t>(type);
3132
if (typeNum == -1) {
3233
static std::string unknown = "kUnknown";
3334
return unknown;
@@ -136,9 +137,7 @@ void SymbolTable::setParentQueryLocation(
136137
int highestIndex = -1;
137138
for (const auto& sym : symbols_) {
138139
if (sym->parentQueryLocation == location) {
139-
if (sym->parentQueryIndex > highestIndex) {
140-
highestIndex = sym->parentQueryIndex;
141-
}
140+
highestIndex = std::max(sym->parentQueryIndex, highestIndex);
142141
}
143142
}
144143
symbols_[index]->parentQueryIndex = highestIndex + 1;
@@ -236,7 +235,7 @@ std::string SymbolTable::toDebugString() const {
236235
if (!relationData->subQueryPipelines.empty()) {
237236
result << " SQC=" << relationData->subQueryPipelines.size();
238237
}
239-
result << std::endl;
238+
result << '\n';
240239

241240
int32_t fieldNum = 0;
242241
for (const auto& field : relationData->fieldReferences) {
@@ -248,7 +247,7 @@ std::string SymbolTable::toDebugString() const {
248247
if (!field->alias.empty()) {
249248
result << " " << field->alias;
250249
}
251-
result << std::endl;
250+
result << '\n';
252251
}
253252

254253
for (const auto& field : relationData->generatedFieldReferences) {
@@ -266,7 +265,7 @@ std::string SymbolTable::toDebugString() const {
266265
} else if (!field->alias.empty()) {
267266
result << " " << field->alias;
268267
}
269-
result << std::endl;
268+
result << '\n';
270269
}
271270

272271
int32_t outputFieldNum = 0;
@@ -279,12 +278,12 @@ std::string SymbolTable::toDebugString() const {
279278
if (!field->alias.empty()) {
280279
result << " " << field->alias;
281280
}
282-
result << std::endl;
281+
result << '\n';
283282
}
284283
textAlreadyWritten = true;
285284
}
286285
if (textAlreadyWritten) {
287-
result << std::endl;
286+
result << '\n';
288287
}
289288
return result.str();
290289
}

src/substrait/textplan/converter/Tool.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace {
1717
void convertPlanToText(const char* filename) {
1818
auto planOrError = loadPlan(filename);
1919
if (!planOrError.ok()) {
20-
std::cerr << planOrError.status() << std::endl;
20+
std::cerr << planOrError.status() << '\n';
2121
return;
2222
}
2323

@@ -29,7 +29,7 @@ void convertPlanToText(const char* filename) {
2929
auto errors = result.getAllErrors();
3030
if (!errors.empty()) {
3131
for (const auto& err : errors) {
32-
std::cerr << err << std::endl;
32+
std::cerr << err << '\n';
3333
}
3434
}
3535
std::cout << textResult;

src/substrait/textplan/converter/tests/BinaryToTextPlanConversionTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ TEST_F(BinaryToTextPlanConversionTest, FullSample) {
685685
ASSERT_TRUE(jsonOrError.ok());
686686
auto planOrError = loadFromJson(*jsonOrError);
687687
ASSERT_TRUE(planOrError.ok());
688-
auto plan = *planOrError;
688+
const auto& plan = *planOrError;
689689
EXPECT_THAT(plan.extensions_size(), ::testing::Eq(7));
690690

691691
auto expectedOutputOrError = readFromFile("data/q6_first_stage.golden.splan");

src/substrait/textplan/parser/ParseText.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ std::optional<antlr4::ANTLRInputStream> loadTextFile(
2323
std::string_view filename) {
2424
std::ifstream stream(std::string{filename});
2525
if (stream.bad() || stream.fail()) {
26-
std::cout << "Bad stream." << std::endl;
26+
std::cout << "Bad stream." << '\n';
2727
return std::nullopt;
2828
}
2929
if (!stream.is_open()) {
30-
std::cout << "Stream is not open." << std::endl;
30+
std::cout << "Stream is not open." << '\n';
3131
return std::nullopt;
3232
}
3333
return {stream};

src/substrait/textplan/parser/SubstraitPlanRelationVisitor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const std::string kSortDirectionPrefix = "sortdirection";
3535

3636
const std::string kIntermediateNodeName = "intermediate";
3737

38-
enum RelationFilterBehavior {
38+
enum RelationFilterBehavior : std::int8_t {
3939
kDefault = 0,
4040
kBestEffort = 1,
4141
kPostJoin = 2,

src/substrait/textplan/parser/SubstraitPlanSubqueryRelationVisitor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const std::string kAggregationInvocationPrefix = "aggregationinvocation";
3333
const std::string kJoinTypePrefix = "jointype";
3434
const std::string kSortDirectionPrefix = "sortdirection";
3535

36-
enum RelationFilterBehavior {
36+
enum RelationFilterBehavior : std::int8_t {
3737
kDefault = 0,
3838
kBestEffort = 1,
3939
kPostJoin = 2,

src/substrait/textplan/parser/Tool.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ namespace {
1212
void readText(const char* filename) {
1313
auto stream = io::substrait::textplan::loadTextFile(filename);
1414
if (!stream.has_value()) {
15-
std::cerr << "An error occurred while reading: " << filename << std::endl;
15+
std::cerr << "An error occurred while reading: " << filename << '\n';
1616
return;
1717
}
1818
auto parseResult = io::substrait::textplan::parseStream(&*stream);
1919
if (!parseResult.successful()) {
2020
for (const std::string& msg : parseResult.getAllErrors()) {
21-
std::cout << msg << std::endl;
21+
std::cout << msg << '\n';
2222
}
2323
return;
2424
}
@@ -28,7 +28,7 @@ void readText(const char* filename) {
2828
parseResult.getSymbolTable(), &errorListener);
2929
if (errorListener.hasErrors()) {
3030
for (const std::string& msg : errorListener.getErrorMessages()) {
31-
std::cout << msg << std::endl;
31+
std::cout << msg << '\n';
3232
}
3333
return;
3434
}

0 commit comments

Comments
 (0)