Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial commit of substrait-cpp #2

Merged
merged 15 commits into from
Dec 11, 2022
Merged
87 changes: 87 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
---
AccessModifierOffset: -1
AlignAfterOpenBracket: AlwaysBreak
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: true
AlignOperands: false
AlignTrailingComments: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: true
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: false
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ForEachMacros: [ FOR_EACH, FOR_EACH_R, FOR_EACH_RANGE, ]
IncludeCategories:
- Regex: '^<.*\.h(pp)?>'
Priority: 1
- Regex: '^<.*'
Priority: 2
- Regex: '.*'
Priority: 3
IndentCaseLabels: true
IndentWidth: 2
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: false
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Left
ReflowComments: true
SortIncludes: true
SpaceAfterCStyleCast: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 8
UseTab: Never
...
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@
*.exe
*.out
*.app

src/proto/substrait
12 changes: 12 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[submodule "third_party/yaml-cpp"]
path = third_party/yaml-cpp
url = https://github.com/jbeder/yaml-cpp.git
[submodule "third_party/googletest"]
path = third_party/googletest
url = https://github.com/google/googletest.git
[submodule "third_party/substrait"]
path = third_party/substrait
url = https://github.com/substrait-io/substrait.git
[submodule "third_party/fmt"]
path = third_party/fmt
url = https://github.com/fmtlib/fmt
33 changes: 33 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Licensed 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.
chaojun-zhang marked this conversation as resolved.
Show resolved Hide resolved
cmake_minimum_required(VERSION 3.10)

# set the project name
project(substrait-cpp)

message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

option(
BUILD_TESTING
"Enable substrait-cpp tests. This will enable all other build options automatically."
ON)

find_package(Protobuf REQUIRED)
include_directories(${PROTOBUF_INCLUDE_DIRS})

add_subdirectory(third_party)
include_directories(include)
add_subdirectory(substrait)
46 changes: 46 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# 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.

.PHONY: all clean build debug release

BUILD_TYPE := Release

all: debug

clean:
@rm -rf build-*

build-common:
@mkdir -p build-${BUILD_TYPE}
@cd build-${BUILD_TYPE} && \
cmake -Wno-dev \
-DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
-DPREFER_STATIC_LIBS=OFF \
$(FORCE_COLOR) \
..

build:
VERBOSE=1 cmake --build build-${BUILD_TYPE} -j $${CPU_COUNT:-`nproc`} || \
cmake --build build-${BUILD_TYPE}

debug:
@$(MAKE) build-common BUILD_TYPE=Debug
@$(MAKE) build BUILD_TYPE=Debug

release:
@$(MAKE) build-common BUILD_TYPE=Release
@$(MAKE) build BUILD_TYPE=Release
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,36 @@
# substrait-cpp

Planned home for CPP libraries to help build/consume Substrait query plans.

## Getting Started

We provide scripts to help developers setup and install substrait-cpp dependencies.

### Get the substrait-cpp Source
```
git clone --recursive https://github.com/substrait-io/substrait-cpp.git
cd substrait-cpp
# if you are updating an existing checkout
git submodule sync --recursive
git submodule update --init --recursive
```

### Setting up on Linux (Ubuntu 20.04 or later)

Once you have checked out substrait-cpp, you can setup and build like so:

```shell
$ ./scripts/setup-ubuntu.sh
$ make
```

## Community

The main communication channel with the substrait through the
[substrait chanel](http://substrait.slack.com).


chaojun-zhang marked this conversation as resolved.
Show resolved Hide resolved
## License

substrait-cpp is licensed under the Apache 2.0 License. A copy of the license
[can be found here.](LICENSE)
chaojun-zhang marked this conversation as resolved.
Show resolved Hide resolved
141 changes: 141 additions & 0 deletions include/substrait/common/Exceptions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
/*
* Licensed 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.
*/

#pragma once

#include <memory>
#include <utility>
#include "fmt/format.h"
chaojun-zhang marked this conversation as resolved.
Show resolved Hide resolved

namespace io::substrait::common {
chaojun-zhang marked this conversation as resolved.
Show resolved Hide resolved
namespace error_code {

//====================== User Error Codes ======================:

// An error raised when an argument verification fails
inline constexpr auto kInvalidArgument = "INVALID_ARGUMENT";

// An error raised when a requested operation is not supported.
inline constexpr auto kUnsupported = "UNSUPPORTED";
chaojun-zhang marked this conversation as resolved.
Show resolved Hide resolved

//====================== Runtime Error Codes ======================:

// An error raised when the current state of a component is invalid.
inline constexpr auto kInvalidState = "INVALID_STATE";

// An error raised when unreachable code point was executed.
inline constexpr auto kUnreachableCode = "UNREACHABLE_CODE";

// An error raised when a requested operation is not yet supported.
inline constexpr auto kNotImplemented = "NOT_IMPLEMENTED";

// An error raised when a method has been passed an illegal or inappropriate
// argument.
inline constexpr auto kIllegalArgument = "ILLEGAL_ARGUMENT";
chaojun-zhang marked this conversation as resolved.
Show resolved Hide resolved

} // namespace error_code

class SubstraitException : public std::exception {
public:
enum class Type { kUser = 0, kSystem = 1 };
chaojun-zhang marked this conversation as resolved.
Show resolved Hide resolved

SubstraitException(
const std::string& exceptionCode,
const std::string& exceptionMessage,
Type exceptionType = Type::kSystem,
const std::string& exceptionName = "SubstraitException");

// Inherited
[[nodiscard]] const char* what() const noexcept override {
return msg_.c_str();
}

private:
const std::string msg_;
};

class SubstraitUserError : public SubstraitException {
public:
SubstraitUserError(
const std::string& exceptionCode,
const std::string& exceptionMessage,
const std::string& exceptionName = "SubstraitUserError")
: SubstraitException(
exceptionCode,
exceptionMessage,
Type::kUser,
exceptionName) {}
};

class SubstraitRuntimeError final : public SubstraitException {
public:
SubstraitRuntimeError(
const std::string& exceptionCode,
const std::string& exceptionMessage,
const std::string& exceptionName = "SubstraitRuntimeError")
: SubstraitException(
exceptionCode,
exceptionMessage,
Type::kSystem,
exceptionName) {}
};

template <typename... Args>
std::string errorMessage(fmt::string_view fmt, const Args&... args) {
return fmt::vformat(fmt, fmt::make_format_args(args...));
}

#define SUBSTRAIT_THROW(exception, errorCode, ...) \
{ \
auto message = io::substrait::common::errorMessage(__VA_ARGS__); \
throw exception(errorCode, message); \
}

#define SUBSTRAIT_UNSUPPORTED(...) \
SUBSTRAIT_THROW( \
::io::substrait::common::SubstraitUserError, \
::io::substrait::common::error_code::kUnsupported, \
##__VA_ARGS__)

#define SUBSTRAIT_UNREACHABLE(...) \
SUBSTRAIT_THROW( \
::io::substrait::common::SubstraitRuntimeError, \
::io::substrait::common::error_code::kUnreachableCode, \
##__VA_ARGS__)

#define SUBSTRAIT_FAIL(...) \
SUBSTRAIT_THROW( \
::io::substrait::common::SubstraitRuntimeError, \
::io::substrait::common::error_code::kInvalidState, \
##__VA_ARGS__)

#define SUBSTRAIT_USER_FAIL(...) \
SUBSTRAIT_THROW( \
::io::substrait::common::SubstraitUserError, \
::io::substrait::common::error_code::kInvalidState, \
##__VA_ARGS__)

#define SUBSTRAIT_NYI(...) \
SUBSTRAIT_THROW( \
::io::substrait::common::SubstraitRuntimeError, \
::io::substrait::common::error_code::kNotImplemented, \
##__VA_ARGS__)

#define SUBSTRAIT_ILLEGAL_ARGUMENT(...) \
SUBSTRAIT_THROW( \
::io::substrait::common::SubstraitUserError, \
::io::substrait::common::error_code::kIllegalArgument, \
##__VA_ARGS__)

} // namespace io::substrait::common
Loading