Skip to content

Commit

Permalink
ORC-1307: Add .clang-format to enforce C++ code style
Browse files Browse the repository at this point in the history
This closes #1308
  • Loading branch information
wgtmac authored Nov 8, 2022
1 parent d4f4ea7 commit b5cbed4
Show file tree
Hide file tree
Showing 139 changed files with 19,154 additions and 22,734 deletions.
26 changes: 26 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
---
Language: Cpp
BasedOnStyle: Google
ColumnLimit: 100
IndentWidth: 2
NamespaceIndentation: All
UseTab: Never
AllowShortFunctionsOnASingleLine: Empty
DerivePointerAlignment: false
IncludeBlocks: Preserve
16 changes: 16 additions & 0 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,19 @@ jobs:
cd java
mvn install -DskipTests
mvn javadoc:javadoc
formatting-check:
name: "C++ format check"
runs-on: ubuntu-20.04
strategy:
matrix:
path:
- 'c++'
- 'tools'
steps:
- uses: actions/checkout@v3
- name: Run clang-format style check for C++ code
uses: jidicula/[email protected]
with:
clang-format-version: '13'
check-path: ${{ matrix.path }}
8 changes: 4 additions & 4 deletions c++/include/orc/BloomFilter.hh
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
namespace orc {

class BloomFilter {
public:
public:
virtual ~BloomFilter();

// test if the element exists in BloomFilter
virtual bool testBytes(const char * data, int64_t length) const = 0;
virtual bool testBytes(const char* data, int64_t length) const = 0;
virtual bool testLong(int64_t data) const = 0;
virtual bool testDouble(double data) const = 0;
};
Expand All @@ -40,6 +40,6 @@ namespace orc {
std::vector<std::shared_ptr<BloomFilter>> entries;
};

}
} // namespace orc

#endif //ORC_BLOOMFILTER_HH
#endif // ORC_BLOOMFILTER_HH
16 changes: 7 additions & 9 deletions c++/include/orc/ColumnPrinter.hh
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,31 @@
#ifndef ORC_COLUMN_PRINTER_HH
#define ORC_COLUMN_PRINTER_HH

#include "orc/orc-config.hh"
#include "orc/OrcFile.hh"
#include "orc/Vector.hh"
#include "orc/orc-config.hh"

#include <stdio.h>
#include <string>
#include <memory>
#include <string>
#include <vector>

namespace orc {

class ColumnPrinter {
protected:
std::string &buffer;
bool hasNulls ;
protected:
std::string& buffer;
bool hasNulls;
const char* notNull;

public:
public:
ColumnPrinter(std::string&);
virtual ~ColumnPrinter();
virtual void printRow(uint64_t rowId) = 0;
// should be called once at the start of each batch of rows
virtual void reset(const ColumnVectorBatch& batch);
};

ORC_UNIQUE_PTR<ColumnPrinter> createColumnPrinter(std::string&,
const Type* type);
}
ORC_UNIQUE_PTR<ColumnPrinter> createColumnPrinter(std::string&, const Type* type);
} // namespace orc
#endif
57 changes: 22 additions & 35 deletions c++/include/orc/Common.hh
Original file line number Diff line number Diff line change
Expand Up @@ -19,47 +19,45 @@
#ifndef ORC_COMMON_HH
#define ORC_COMMON_HH

#include "orc/Vector.hh"
#include "orc/Type.hh"
#include "orc/Exceptions.hh"
#include "orc/Type.hh"
#include "orc/Vector.hh"

#include <string>

namespace orc {

class FileVersion {
private:
private:
uint32_t majorVersion;
uint32_t minorVersion;
public:

public:
static const FileVersion& v_0_11();
static const FileVersion& v_0_12();
static const FileVersion& UNSTABLE_PRE_2_0();

FileVersion(uint32_t major, uint32_t minor) :
majorVersion(major), minorVersion(minor) {
}
FileVersion(uint32_t major, uint32_t minor) : majorVersion(major), minorVersion(minor) {}

/**
* Get major version
*/
uint32_t getMajor() const {
return this->majorVersion;
return this->majorVersion;
}

/**
* Get minor version
*/
uint32_t getMinor() const {
return this->minorVersion;
return this->minorVersion;
}

bool operator == (const FileVersion & right) const {
return this->majorVersion == right.getMajor() &&
this->minorVersion == right.getMinor();
bool operator==(const FileVersion& right) const {
return this->majorVersion == right.getMajor() && this->minorVersion == right.getMinor();
}

bool operator != (const FileVersion & right) const {
bool operator!=(const FileVersion& right) const {
return !(*this == right);
}

Expand Down Expand Up @@ -140,7 +138,7 @@ namespace orc {
std::string streamKindToString(StreamKind kind);

class StreamInformation {
public:
public:
virtual ~StreamInformation();

virtual StreamKind getKind() const = 0;
Expand All @@ -159,7 +157,7 @@ namespace orc {
std::string columnEncodingKindToString(ColumnEncodingKind kind);

class StripeInformation {
public:
public:
virtual ~StripeInformation();

/**
Expand All @@ -184,7 +182,7 @@ namespace orc {
* Get the length of the stripe's data.
* @return the number of bytes in the stripe
*/
virtual uint64_t getDataLength()const = 0;
virtual uint64_t getDataLength() const = 0;

/**
* Get the length of the stripe's tail section, which contains its index.
Expand All @@ -206,8 +204,7 @@ namespace orc {
/**
* Get the StreamInformation for the given stream.
*/
virtual ORC_UNIQUE_PTR<StreamInformation>
getStreamInformation(uint64_t streamId) const = 0;
virtual ORC_UNIQUE_PTR<StreamInformation> getStreamInformation(uint64_t streamId) const = 0;

/**
* Get the column encoding for the given column.
Expand Down Expand Up @@ -238,10 +235,8 @@ namespace orc {
template <>
inline bool compare(Decimal val1, Decimal val2) {
// compare integral parts
Int128 integral1 = scaleDownInt128ByPowerOfTen(val1.value,
val1.scale);
Int128 integral2 = scaleDownInt128ByPowerOfTen(val2.value,
val2.scale);
Int128 integral1 = scaleDownInt128ByPowerOfTen(val1.value, val1.scale);
Int128 integral2 = scaleDownInt128ByPowerOfTen(val2.value, val2.scale);

if (integral1 < integral2) {
return true;
Expand All @@ -253,25 +248,17 @@ namespace orc {
// unnecessary to check overflow here because the scaled number will not
// exceed original ones
bool overflow = false, positive = val1.value >= 0;
val1.value -= scaleUpInt128ByPowerOfTen(integral1,
val1.scale,
overflow);
val2.value -= scaleUpInt128ByPowerOfTen(integral2,
val2.scale,
overflow);
val1.value -= scaleUpInt128ByPowerOfTen(integral1, val1.scale, overflow);
val2.value -= scaleUpInt128ByPowerOfTen(integral2, val2.scale, overflow);

int32_t diff = val1.scale - val2.scale;
if (diff > 0) {
val2.value = scaleUpInt128ByPowerOfTen(val2.value,
diff,
overflow);
val2.value = scaleUpInt128ByPowerOfTen(val2.value, diff, overflow);
if (overflow) {
return positive ? true : false;
}
} else {
val1.value = scaleUpInt128ByPowerOfTen(val1.value,
-diff,
overflow);
val1.value = scaleUpInt128ByPowerOfTen(val1.value, -diff, overflow);
if (overflow) {
return positive ? false : true;
}
Expand Down Expand Up @@ -317,6 +304,6 @@ namespace orc {
return !(lhs != rhs);
}

}
} // namespace orc

#endif
23 changes: 13 additions & 10 deletions c++/include/orc/Exceptions.hh
Original file line number Diff line number Diff line change
Expand Up @@ -26,35 +26,38 @@

namespace orc {

class NotImplementedYet: public std::logic_error {
public:
class NotImplementedYet : public std::logic_error {
public:
explicit NotImplementedYet(const std::string& what_arg);
explicit NotImplementedYet(const char* what_arg);
virtual ~NotImplementedYet() ORC_NOEXCEPT;
NotImplementedYet(const NotImplementedYet&);
private:

private:
NotImplementedYet& operator=(const NotImplementedYet&);
};

class ParseError: public std::runtime_error {
public:
class ParseError : public std::runtime_error {
public:
explicit ParseError(const std::string& what_arg);
explicit ParseError(const char* what_arg);
virtual ~ParseError() ORC_NOEXCEPT;
ParseError(const ParseError&);
private:

private:
ParseError& operator=(const ParseError&);
};

class InvalidArgument: public std::runtime_error {
public:
class InvalidArgument : public std::runtime_error {
public:
explicit InvalidArgument(const std::string& what_arg);
explicit InvalidArgument(const char* what_arg);
virtual ~InvalidArgument() ORC_NOEXCEPT;
InvalidArgument(const InvalidArgument&);
private:

private:
InvalidArgument& operator=(const InvalidArgument&);
};
}
} // namespace orc

#endif
Loading

0 comments on commit b5cbed4

Please sign in to comment.