Skip to content

Commit 0bdde98

Browse files
committed
fix code style
1 parent 24a05e1 commit 0bdde98

File tree

8 files changed

+89
-131
lines changed

8 files changed

+89
-131
lines changed

src/Extension.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ Extension::load(const std::vector<std::string> &extensionFiles) {
192192
for (const auto &extensionUri : extensionFiles) {
193193
const auto &node = YAML::LoadFile(extensionUri);
194194

195-
auto &scalarFunctions = node["scalar_functions"];
195+
const auto &scalarFunctions = node["scalar_functions"];
196196
if (scalarFunctions && scalarFunctions.IsSequence()) {
197197
for (auto &scalarFunctionNode : scalarFunctions) {
198198
const auto functionName = scalarFunctionNode["name"].as<std::string>();
@@ -247,7 +247,8 @@ void Extension::addWindowFunctionVariant(
247247
} else {
248248
std::vector<FunctionVariantPtr> variants;
249249
variants.emplace_back(functionVariant);
250-
windowFunctionVariantMap_.insert({functionVariant->name, variants});
250+
windowFunctionVariantMap_.insert(
251+
{functionVariant->name, std::move(variants)});
251252
}
252253
}
253254

src/Extension.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ class Extension {
4646
load(const std::vector<std::string> &extensionFiles);
4747

4848
/// Add a scalar function variant.
49-
void addScalarFunctionVariant(const FunctionVariantPtr& functionVariant);
49+
void addScalarFunctionVariant(const FunctionVariantPtr &functionVariant);
5050

5151
/// Add a aggregate function variant.
52-
void addAggregateFunctionVariant(const FunctionVariantPtr& functionVariant);
52+
void addAggregateFunctionVariant(const FunctionVariantPtr &functionVariant);
5353

5454
/// Add a window function variant.
5555
void addWindowFunctionVariant(const FunctionVariantPtr &functionVariant);

src/FunctionLookup.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace io::substrait {
1818

1919
FunctionVariantPtr
2020
FunctionLookup::lookupScalarFunction(const std::string &functionName,
21-
const std::vector<TypePtr> &types) const {
21+
const std::vector<TypePtr> &types) const {
2222
const auto &functionMappings = functionMapping_->scalaMapping();
2323
const auto &substraitFunctionName =
2424
functionMappings.find(functionName) != functionMappings.end()
@@ -27,9 +27,8 @@ FunctionLookup::lookupScalarFunction(const std::string &functionName,
2727
return extension_->lookupScalarFunction(substraitFunctionName, types);
2828
}
2929

30-
FunctionVariantPtr
31-
FunctionLookup::lookupAggregateFunction(const std::string &functionName,
32-
const std::vector<TypePtr> &types) const {
30+
FunctionVariantPtr FunctionLookup::lookupAggregateFunction(
31+
const std::string &functionName, const std::vector<TypePtr> &types) const {
3332
const auto &functionMappings = functionMapping_->aggregateMapping();
3433
const auto &substraitFunctionName =
3534
functionMappings.find(functionName) != functionMappings.end()
@@ -40,7 +39,7 @@ FunctionLookup::lookupAggregateFunction(const std::string &functionName,
4039

4140
FunctionVariantPtr
4241
FunctionLookup::lookupWindowFunction(const std::string &functionName,
43-
const std::vector<TypePtr> &types) const {
42+
const std::vector<TypePtr> &types) const {
4443
const auto &functionMappings = functionMapping_->windowMapping();
4544
const auto &substraitFunctionName =
4645
functionMappings.find(functionName) != functionMappings.end()

src/FunctionMapping.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,5 @@ class FunctionMapping {
4444
}
4545
};
4646

47-
using FunctionMappingPtr = std::shared_ptr<const FunctionMapping >;
47+
using FunctionMappingPtr = std::shared_ptr<const FunctionMapping>;
4848
} // namespace io::substrait

src/Type.cpp

Lines changed: 43 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -76,66 +76,50 @@ TypePtr Type::decode(const std::string &rawType) {
7676

7777
if (TypeTraits<TypeKind::kList>::typeString == baseType) {
7878
return std::make_shared<ListType>(nestedTypes[0]);
79-
} else if (TypeTraits<TypeKind::kMap>::typeString ==
80-
baseType) {
79+
} else if (TypeTraits<TypeKind::kMap>::typeString == baseType) {
8180
return std::make_shared<MapType>(nestedTypes[0], nestedTypes[1]);
82-
} else if (TypeTraits<TypeKind::kDecimal>::typeString ==
83-
baseType) {
81+
} else if (TypeTraits<TypeKind::kDecimal>::typeString == baseType) {
8482
auto precision =
85-
std::dynamic_pointer_cast<const StringLiteralType>(
86-
nestedTypes[0]);
87-
auto scale = std::dynamic_pointer_cast<const StringLiteralType>(
88-
nestedTypes[1]);
83+
std::dynamic_pointer_cast<const StringLiteralType>(nestedTypes[0]);
84+
auto scale =
85+
std::dynamic_pointer_cast<const StringLiteralType>(nestedTypes[1]);
8986
return std::make_shared<DecimalType>(precision, scale);
90-
} else if (TypeTraits<TypeKind::kVarchar>::typeString ==
91-
baseType) {
92-
auto length = std::dynamic_pointer_cast<const StringLiteralType>(
93-
nestedTypes[0]);
87+
} else if (TypeTraits<TypeKind::kVarchar>::typeString == baseType) {
88+
auto length =
89+
std::dynamic_pointer_cast<const StringLiteralType>(nestedTypes[0]);
9490
return std::make_shared<VarcharType>(length);
95-
} else if (TypeTraits<TypeKind::kFixedChar>::typeString ==
96-
baseType) {
97-
auto length = std::dynamic_pointer_cast<const StringLiteralType>(
98-
nestedTypes[0]);
91+
} else if (TypeTraits<TypeKind::kFixedChar>::typeString == baseType) {
92+
auto length =
93+
std::dynamic_pointer_cast<const StringLiteralType>(nestedTypes[0]);
9994
return std::make_shared<FixedCharType>(length);
100-
} else if (TypeTraits<TypeKind::kFixedBinary>::typeString ==
101-
baseType) {
102-
auto length = std::dynamic_pointer_cast<const StringLiteralType>(
103-
nestedTypes[0]);
95+
} else if (TypeTraits<TypeKind::kFixedBinary>::typeString == baseType) {
96+
auto length =
97+
std::dynamic_pointer_cast<const StringLiteralType>(nestedTypes[0]);
10498
return std::make_shared<FixedBinaryType>(length);
105-
} else if (TypeTraits<TypeKind::kStruct>::typeString ==
106-
baseType) {
99+
} else if (TypeTraits<TypeKind::kStruct>::typeString == baseType) {
107100
return std::make_shared<StructType>(nestedTypes);
108101
} else {
109102
throw std::runtime_error("Unsupported substrait type: " + rawType);
110103
}
111104
}
112105

113-
#define SCALAR_TYPE_MAPPING(typeKind) \
106+
#define SCALAR_TYPE_MAPPING(typeKind) \
114107
{ \
115-
TypeTraits<TypeKind::typeKind>::typeString, \
108+
TypeTraits<TypeKind::typeKind>::typeString, \
116109
std::make_shared<TypeBase<TypeKind::typeKind>>( \
117-
TypeBase<TypeKind::typeKind>()) \
110+
TypeBase<TypeKind::typeKind>()) \
118111
}
119112

120-
const std::unordered_map<std::string, TypePtr> &
121-
Type::scalarTypeMapping() {
113+
const std::unordered_map<std::string, TypePtr> &Type::scalarTypeMapping() {
122114
static const std::unordered_map<std::string, TypePtr> scalarTypeMap{
123-
SCALAR_TYPE_MAPPING(kBool),
124-
SCALAR_TYPE_MAPPING(kI8),
125-
SCALAR_TYPE_MAPPING(kI16),
126-
SCALAR_TYPE_MAPPING(kI32),
127-
SCALAR_TYPE_MAPPING(kI64),
128-
SCALAR_TYPE_MAPPING(kFp32),
129-
SCALAR_TYPE_MAPPING(kFp64),
130-
SCALAR_TYPE_MAPPING(kString),
131-
SCALAR_TYPE_MAPPING(kBinary),
132-
SCALAR_TYPE_MAPPING(kTimestamp),
133-
SCALAR_TYPE_MAPPING(kTimestampTz),
134-
SCALAR_TYPE_MAPPING(kDate),
135-
SCALAR_TYPE_MAPPING(kTime),
136-
SCALAR_TYPE_MAPPING(kIntervalDay),
137-
SCALAR_TYPE_MAPPING(kIntervalYear),
138-
SCALAR_TYPE_MAPPING(kUuid),
115+
SCALAR_TYPE_MAPPING(kBool), SCALAR_TYPE_MAPPING(kI8),
116+
SCALAR_TYPE_MAPPING(kI16), SCALAR_TYPE_MAPPING(kI32),
117+
SCALAR_TYPE_MAPPING(kI64), SCALAR_TYPE_MAPPING(kFp32),
118+
SCALAR_TYPE_MAPPING(kFp64), SCALAR_TYPE_MAPPING(kString),
119+
SCALAR_TYPE_MAPPING(kBinary), SCALAR_TYPE_MAPPING(kTimestamp),
120+
SCALAR_TYPE_MAPPING(kTimestampTz), SCALAR_TYPE_MAPPING(kDate),
121+
SCALAR_TYPE_MAPPING(kTime), SCALAR_TYPE_MAPPING(kIntervalDay),
122+
SCALAR_TYPE_MAPPING(kIntervalYear), SCALAR_TYPE_MAPPING(kUuid),
139123
};
140124
return scalarTypeMap;
141125
}
@@ -149,8 +133,7 @@ const std::string FixedBinaryType::signature() const {
149133
return sign.str();
150134
}
151135

152-
bool FixedBinaryType::isSameAs(
153-
const std::shared_ptr<const Type> &other) const {
136+
bool FixedBinaryType::isSameAs(const std::shared_ptr<const Type> &other) const {
154137
if (const auto &type =
155138
std::dynamic_pointer_cast<const FixedBinaryType>(other)) {
156139
return true;
@@ -167,10 +150,8 @@ const std::string DecimalType::signature() const {
167150
return signature.str();
168151
}
169152

170-
bool DecimalType::isSameAs(
171-
const std::shared_ptr<const Type> &other) const {
172-
if (const auto &type =
173-
std::dynamic_pointer_cast<const DecimalType>(other)) {
153+
bool DecimalType::isSameAs(const std::shared_ptr<const Type> &other) const {
154+
if (const auto &type = std::dynamic_pointer_cast<const DecimalType>(other)) {
174155
return true;
175156
}
176157
return false;
@@ -185,8 +166,7 @@ const std::string FixedCharType::signature() const {
185166
return sign.str();
186167
}
187168

188-
bool FixedCharType::isSameAs(
189-
const std::shared_ptr<const Type> &other) const {
169+
bool FixedCharType::isSameAs(const std::shared_ptr<const Type> &other) const {
190170
if (const auto &type =
191171
std::dynamic_pointer_cast<const FixedCharType>(other)) {
192172
return true;
@@ -203,10 +183,8 @@ const std::string VarcharType::signature() const {
203183
return sign.str();
204184
}
205185

206-
bool VarcharType::isSameAs(
207-
const std::shared_ptr<const Type> &other) const {
208-
if (const auto &type =
209-
std::dynamic_pointer_cast<const VarcharType>(other)) {
186+
bool VarcharType::isSameAs(const std::shared_ptr<const Type> &other) const {
187+
if (const auto &type = std::dynamic_pointer_cast<const VarcharType>(other)) {
210188
return true;
211189
}
212190
return false;
@@ -228,10 +206,8 @@ const std::string StructType::signature() const {
228206
return signature.str();
229207
}
230208

231-
bool StructType::isSameAs(
232-
const std::shared_ptr<const Type> &other) const {
233-
if (const auto &type =
234-
std::dynamic_pointer_cast<const StructType>(other)) {
209+
bool StructType::isSameAs(const std::shared_ptr<const Type> &other) const {
210+
if (const auto &type = std::dynamic_pointer_cast<const StructType>(other)) {
235211
bool sameSize = type->children_.size() == children_.size();
236212
if (sameSize) {
237213
for (int i = 0; i < children_.size(); i++) {
@@ -256,10 +232,8 @@ const std::string MapType::signature() const {
256232
return signature.str();
257233
}
258234

259-
bool MapType::isSameAs(
260-
const std::shared_ptr<const Type> &other) const {
261-
if (const auto &type =
262-
std::dynamic_pointer_cast<const MapType>(other)) {
235+
bool MapType::isSameAs(const std::shared_ptr<const Type> &other) const {
236+
if (const auto &type = std::dynamic_pointer_cast<const MapType>(other)) {
263237
return keyType_->isSameAs(type->keyType_) &&
264238
valueType_->isSameAs(type->valueType_);
265239
}
@@ -275,17 +249,14 @@ const std::string ListType::signature() const {
275249
return signature.str();
276250
}
277251

278-
bool ListType::isSameAs(
279-
const std::shared_ptr<const Type> &other) const {
280-
if (const auto &type =
281-
std::dynamic_pointer_cast<const ListType>(other)) {
252+
bool ListType::isSameAs(const std::shared_ptr<const Type> &other) const {
253+
if (const auto &type = std::dynamic_pointer_cast<const ListType>(other)) {
282254
return elementType_->isSameAs(type->elementType_);
283255
}
284256
return false;
285257
}
286258

287-
bool UsedDefinedType::isSameAs(
288-
const std::shared_ptr<const Type> &other) const {
259+
bool UsedDefinedType::isSameAs(const std::shared_ptr<const Type> &other) const {
289260
if (const auto &type =
290261
std::dynamic_pointer_cast<const UsedDefinedType>(other)) {
291262
return type->value_ == value_;
@@ -305,11 +276,9 @@ bool StringLiteralType::isSameAs(
305276
return false;
306277
}
307278

308-
#define DEFINE_SCALAR_ACCESSOR(typeKind) \
309-
std::shared_ptr<const ScalarType<TypeKind::typeKind>> \
310-
typeKind() { \
311-
return std::make_shared< \
312-
const ScalarType<TypeKind::typeKind>>(); \
279+
#define DEFINE_SCALAR_ACCESSOR(typeKind) \
280+
std::shared_ptr<const ScalarType<TypeKind::typeKind>> typeKind() { \
281+
return std::make_shared<const ScalarType<TypeKind::typeKind>>(); \
313282
}
314283

315284
DEFINE_SCALAR_ACCESSOR(kBool);

src/tests/FunctionLookupTest.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
/*
2-
* Copyright (c) Facebook, Inc. and its affiliates.
3-
*
42
* Licensed under the Apache License, Version 2.0 (the "License");
53
* you may not use this file except in compliance with the License.
64
* You may obtain a copy of the License at
@@ -25,6 +23,7 @@ class VeloxFunctionMappings : public FunctionMapping {
2523
static const std::shared_ptr<VeloxFunctionMappings> make() {
2624
return std::make_shared<VeloxFunctionMappings>();
2725
}
26+
2827
/// scalar function names in difference between velox and Substrait.
2928
const FunctionMap scalaMapping() const override {
3029
static const FunctionMap scalarMappings{
@@ -120,4 +119,4 @@ TEST_F(SubstraitFunctionLookupTest, string_function) {
120119
"like:opt_vchar<L1>_vchar<L2>");
121120
testScalarFunctionLookup("substr", {kString(), kI32(), kI32()},
122121
"substring:str_i64_i64");
123-
}
122+
}

0 commit comments

Comments
 (0)