Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • thomasb/tardisdb
  • tardisDB/tardisdb
2 results
Show changes
Commits on Source (326)
Showing
with 868 additions and 121 deletions
*
# IDE
.idea/
!*.c
!*.h
!*.cpp
!*.hpp
!*.tcc
!*.sql
!*.script
!*.patch
!*.txt
!*.sh
!*.tex
!*.bib
!*.ods
!*.png
!*.eps
!*.pdf
!*.ll
!*.md
!*.cmd
!*.csv
!Makefile
!Readme
!empty
!.gitignore
# even if they are in subdirectories
!*/
# sample data
tables/
# build dirs
cmake-build-*/
......
# ---------------------------------------------------------------------------
# TARDISDB
# ---------------------------------------------------------------------------
stages:
- build
- test
build_debug:
stage: build
script:
- mkdir -p build
- cd build
- cmake -GNinja -DCMAKE_BUILD_TYPE=Debug -DTUPLE_STREAM_REQUIRED=true ..
- ninja
cache:
key: "$CI_COMMIT_REF_NAME-debug"
paths:
- build/
policy: pull-push
artifacts:
paths:
- ./build/tester
expire_in: 1 hrs
tags:
- "clang-6.0"
- "llvm-7.0"
- "cmake"
- "python3"
tester:
stage: test
script:
- ./build/tester
dependencies:
- build_debug
tags:
- "clang-6.0"
- "llvm-6.0"
- "cmake"
- "python3"
\ No newline at end of file
cmake_minimum_required(VERSION 3.5)
project(protodb)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD 17)
### set up llvm
find_package(LLVM REQUIRED CONFIG)
set(LIBXML_AVAILABLE false)
set(ENABLE_PERFBENCHMARKING false)
set(USE_DATA_VERSIONING true)
set(USE_HYRISE false)
set(TUPLE_STREAM_REQUIRED true)
##################
### boost ########
##################
if(APPLE)
list(APPEND CMAKE_PREFIX_PATH /usr/local/opt/boost/lib/cmake/Boost-1.72.0)
endif(APPLE)
find_package(Boost)
INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIRS} )
##################
### llvm #########
##################
if(APPLE)
list(APPEND CMAKE_PREFIX_PATH /usr/local/opt/llvm@7)
find_package(LLVM 7.1 REQUIRED CONFIG)
else(NOT APPLE)
find_package(LLVM 7 REQUIRED CONFIG)
endif(APPLE)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
include_directories(${LLVM_INCLUDE_DIRS} .)
llvm_map_components_to_libnames(LLVM_LIBS
support
core
irreader
ExecutionEngine
nativecodegen
X86AsmParser
mcjit
Passes
InstCombine
ScalarOpts
)
##################
### vendor #######
##################
include("${CMAKE_SOURCE_DIR}/vendor/googletest.cmake")
include("${CMAKE_SOURCE_DIR}/vendor/gflags.cmake")
if(ENABLE_PERFBENCHMARKING)
include("${CMAKE_SOURCE_DIR}/vendor/perfevent.cmake")
endif(ENABLE_PERFBENCHMARKING)
if(USE_HYRISE)
include("${CMAKE_SOURCE_DIR}/vendor/hyrise.cmake")
endif(USE_HYRISE)
##################
### config #######
##################
include_directories(.
${LLVM_INCLUDE_DIRS}
${GFLAGS_INCLUDE_DIR}
${HYRISE_INCLUDE_DIR}
${CMAKE_SOURCE_DIR}/include/tardisdb
)
add_definitions(${LLVM_DEFINITIONS})
llvm_map_components_to_libnames(LLVM_LIBS
support
core
irreader
ExecutionEngine
nativecodegen
X86AsmParser
mcjit
Passes
InstCombine
ScalarOpts
)
##################
### libraries ####
##################
if(NOT USE_HYRISE)
include(tools/sqlParser/local.cmake)
endif(NOT USE_HYRISE)
include(tools/semanticalAnalyser/local.cmake)
include(tools/queryCompiler/local.cmake)
include(tools/queryExecutor/local.cmake)
if(LIBXML_AVAILABLE)
include(tools/wikiParser/local.cmake)
endif(LIBXML_AVAILABLE)
if (DEFINED PISTACHE_INCLUDE)
include_directories("${PISTACHE_INCLUDE}")
endif()
if (DEFINED PISTACHE_LIBRARY_PATH)
link_directories("${PISTACHE_LIBRARY_PATH}")
endif()
##################
### tests ########
##################
include("${CMAKE_SOURCE_DIR}/test/local.cmake")
##################
### tools ########
##################
add_executable(sql sql.cpp)
target_link_libraries(sql dblib queryCompiler queryExecutor)
### locate source files
add_executable(server server.cpp)
target_link_libraries(server dblib queryCompiler queryExecutor pistache pthread)
##################
### benchmark ####
##################
add_executable(semanticalBench benchmark/semanticalBench.cpp)
target_link_libraries(semanticalBench dblib queryCompiler queryExecutor gflags pthread)
if(LIBXML_AVAILABLE)
target_compile_definitions(semanticalBench PUBLIC -D LIBXML_AVAILABLE=true)
target_link_libraries(semanticalBench wikiparser)
endif(LIBXML_AVAILABLE)
if(USE_DATA_VERSIONING)
target_compile_definitions(semanticalBench PUBLIC -D USE_DATA_VERSIONING=true)
endif(USE_DATA_VERSIONING)
if(ENABLE_PERFBENCHMARKING)
target_compile_definitions(semanticalBench PUBLIC -D PERF_AVAILABLE=true)
endif(ENABLE_PERFBENCHMARKING)
##################
### DBLIB ########
##################
file(GLOB_RECURSE ALGEBRA_FILES "algebra/*.cpp" "algebra/*.hpp" "algebra/*.tcc")
file(GLOB_RECURSE CODEGEN_FILES "codegen/*.cpp" "codegen/*.hpp" "codegen/*.tcc")
file(GLOB_RECURSE FOUNDATIONS_FILES "foundations/*.cpp" "foundations/*.hpp" "foundations/*.tcc")
file(GLOB_RECURSE NATIVE_FILES "native/*.cpp" "native/*.hpp" "native/*.tcc")
file(GLOB_RECURSE SQL_FILES "sql/*.cpp" "sql/*.hpp" "sql/*.tcc")
file(GLOB_RECURSE QUERIES_FILES "queries/*.cpp" "queries/*.hpp" "queries/*.tcc")
file(GLOB_RECURSE QUERY_COMPILER_FILES "query_compiler/*.cpp" "query_compiler/*.hpp" "query_compiler/*.tcc")
#file(GLOB_RECURSE TESTS_FILES "tests/*.cpp" "tests/*.hpp" "tests/*.tcc")
file(GLOB_RECURSE UTILS_FILES "utils/*.cpp" "utils/*.hpp" "utils/*.tcc")
set(SOURCE_FILES
main.cpp
set(THIRD_PARTY_FILES third_party/hexdump.cpp third_party/hexdump.hpp)
set(DB_LIB_SOURCE_FILES
${ALGEBRA_FILES}
${CODEGEN_FILES}
${FOUNDATIONS_FILES}
......@@ -44,19 +138,11 @@ set(SOURCE_FILES
${QUERIES_FILES}
${QUERY_COMPILER_FILES}
${UTILS_FILES}
${THIRD_PARTY_FILES}
)
set(THIRD_PARTY third_party/hexdump.cpp third_party/hexdump.hpp)
set(TESTS
# tests/join_test.cpp # TODO update
tests/if_test.cpp
tests/loop_test.cpp
tests/interop_test.cpp
tests/codegen_test.cpp
set(TEST_SOURCE_FILES
tests/types_test.cpp
# tests/query_test.cpp
tests/expression_test.cpp
tests/groupby_test.cpp
tests/tests.cpp
tests/tests.hpp
......@@ -84,15 +170,53 @@ add_custom_target(
### all generated files
set(GENERATED_SOURCE_FILES ${LOADER_FILE})
### main library
add_library(dblib ${DB_LIB_SOURCE_FILES})
if(TUPLE_STREAM_REQUIRED)
target_compile_definitions(dblib PUBLIC -D TUPLE_STREAM_REQUIRED=true)
endif(TUPLE_STREAM_REQUIRED)
if(USE_DATA_VERSIONING)
target_compile_definitions(dblib PUBLIC -D USE_DATA_VERSIONING=true)
endif(USE_DATA_VERSIONING)
target_link_libraries(dblib semanticalAnalyser LLVM)
if(USE_HYRISE)
target_compile_definitions(dblib PUBLIC -D USE_HYRISE=true)
target_link_libraries(dblib hyriselib)
else(NOT USE_HYRISE)
target_compile_definitions(dblib PUBLIC -D USE_HYRISE=false)
target_link_libraries(dblib sqlparser)
endif(USE_HYRISE)
### main application
add_executable(protodb ${SOURCE_FILES} ${GENERATED_SOURCE_FILES} ${THIRD_PARTY} ${TESTS})
#target_link_libraries(protodb ${LLVM_LIBS})
target_link_libraries(protodb LLVM)
add_executable(protodb main.cpp ${GENERATED_SOURCE_FILES} ${TEST_SOURCE_FILES})
target_link_libraries(protodb dblib queryCompiler queryExecutor)
### set up dependencies
add_dependencies(GenerateLoader schema_parser)
add_dependencies(protodb GenerateLoader)
### sub projects
add_subdirectory(standalone_tests)
add_subdirectory(schema_parser)
### benchmarks
set(RD_BENCH_SOURCE_FILES
benchmark/random.cpp
)
add_executable(rd_bench ${RD_BENCH_SOURCE_FILES})
target_link_libraries(rd_bench dblib)
##################
### install ######
##################
MACRO(INSTALL_HEADERS_WITH_DIRECTORY HEADER_LIST)
FOREACH(HEADER ${${HEADER_LIST}})
get_filename_component(DIR ${HEADER} DIRECTORY)
install(FILES ${HEADER} DESTINATION include/${DIR})
ENDFOREACH(HEADER)
ENDMACRO(INSTALL_HEADERS_WITH_DIRECTORY)
file(GLOB_RECURSE HS RELATIVE ${CMAKE_SOURCE_DIR} "*.hpp" "*.tcc")
INSTALL_HEADERS_WITH_DIRECTORY(HS)
install(TARGETS dblib DESTINATION lib)
install(TARGETS sql protodb rd_bench DESTINATION bin)
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
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.
......@@ -54,8 +54,8 @@ void Operator::updateRequiredSets()
//-----------------------------------------------------------------------------
// NullaryOperator
NullaryOperator::NullaryOperator(QueryContext & context) :
Operator(context)
NullaryOperator::NullaryOperator(IUFactory & iuFactory) :
Operator(iuFactory)
{ }
NullaryOperator::~NullaryOperator()
......@@ -81,7 +81,7 @@ void NullaryOperator::updateRequiredSetsTraverser()
//-----------------------------------------------------------------------------
// UnaryOperator
UnaryOperator::UnaryOperator(std::unique_ptr<Operator> input) :
Operator(input->getContext()),
Operator(input->getIUFactory()),
child(std::move(input))
{
child->parent = this;
......@@ -113,7 +113,7 @@ void UnaryOperator::updateRequiredSetsTraverser()
// BinaryOperator
BinaryOperator::BinaryOperator(std::unique_ptr<Operator> leftInput, std::unique_ptr<Operator> rightInput) :
Operator(leftInput->getContext()),
Operator(leftInput->getIUFactory()),
leftChild(std::move(leftInput)),
rightChild(std::move(rightInput))
{
......@@ -191,7 +191,7 @@ const iu_set_t & Aggregator::getRequired()
void Aggregator::computeProduced()
{
_produced = _context.iuFactory.createIU(getResultType());
_produced = _iuFactory.createIU(getResultType());
}
void Keep::computeRequired()
......@@ -205,8 +205,8 @@ void Sum::computeRequired()
_required = collectRequired(*_expression);
}
Avg::Avg(QueryContext & context, logical_exp_op_t exp) :
Aggregator(context),
Avg::Avg(IUFactory & iuFactory, logical_exp_op_t exp) :
Aggregator(iuFactory),
_expression(std::move(exp))
{
Sql::SqlType type = _expression->getType();
......@@ -352,9 +352,14 @@ void TableScan::computeProduced()
// collect the produced attributes
for (const std::string & columnName : _table.getColumnNames()) {
auto columnInformation = _table.getCI(columnName);
auto iu = _context.iuFactory.createIU(*this, columnInformation);
auto iu = _iuFactory.createIU(getUID(), columnInformation);
produced.insert(iu);
}
//Produce TID column
std::unique_ptr<ColumnInformation> &columnInformation = _table.getTIDColumnInformation();
auto iu = _iuFactory.createIU(getUID(), columnInformation.get());
produced.insert(iu);
}
void TableScan::computeRequired()
......@@ -364,10 +369,83 @@ void TableScan::computeRequired()
iu_set_t expected = computeExpected(parent, this);
required.insert(expected.begin(), expected.end());
}
//-----------------------------------------------------------------------------
// Delete operator
Delete::Delete(std::unique_ptr<Operator> child, iu_p_t &tidIU, Table & table, branch_id_t branchId) :
UnaryOperator(std::move(child)), _table(table), tidIU(std::move(tidIU)), branchId(branchId) { }
Delete::~Delete() { }
void Delete::accept(OperatorVisitor & visitor) {
visitor.visit(*this);
}
void Delete::computeProduced() {
produced.clear();
}
void Delete::computeRequired() {
// "selection" represents the required attributes of the Result operator
required.insert(tidIU);
}
//-----------------------------------------------------------------------------
// Insert operator
Insert::Insert(IUFactory &iuFactory, Table & table, Native::Sql::SqlTuple *tuple, branch_id_t branchId) :
NullaryOperator(iuFactory), _table(table), sqlTuple(tuple), branchId(branchId) { }
Insert::~Insert() { }
void Insert::accept(OperatorVisitor & visitor) {
visitor.visit(*this);
}
void Insert::computeProduced() {
produced.clear();
}
void Insert::computeRequired() {
}
//-----------------------------------------------------------------------------
// Update operator
Update::Update(std::unique_ptr<Operator> child, std::vector<std::pair<iu_p_t,std::string>> &updateIUValuePairs, Table & table, branch_id_t branchId) :
UnaryOperator(std::move(child)), _table(table), branchId(branchId), updateIUValuePairs(std::move(updateIUValuePairs)) { }
Update::Update(std::unique_ptr<Operator> child, std::vector<std::pair<iu_p_t,std::string>> &updateIUValuePairs, Table & table) :
UnaryOperator(std::move(child)), _table(table), branchId(0), updateIUValuePairs(std::move(updateIUValuePairs)) { }
Update::~Update() { }
void Update::accept(OperatorVisitor & visitor) {
visitor.visit(*this);
}
void Update::computeProduced() {
produced.clear();
}
void Update::computeRequired() {
// "selection" represents the required attributes of the Result operator
for (auto &iu : updateIUValuePairs) {
required.insert(iu.first);
}
}
//-----------------------------------------------------------------------------
// Result operator
#if TUPLE_STREAM_REQUIRED
Result::Type Result::_type = Type::TupleStreamHandler;
#else
Result::Type Result::_type = Type::PrintToStdOut;
#endif
Result::Result(std::unique_ptr<Operator> child, const std::vector<iu_p_t> & selection) :
UnaryOperator(std::move(child)),
selection(selection)
......@@ -523,6 +601,27 @@ struct Verifier : public OperatorVisitor {
op.getChild().accept(*this);
}
void visit(Insert & op) override
{
}
void visit(Update & op) override
{
if (!_result) { return; }
test(op, op.getChild());
op.getChild().accept(*this);
}
void visit(Delete & op) override
{
if (!_result) { return; }
test(op, op.getChild());
op.getChild().accept(*this);
}
void visit(Result & op) override
{
if (!_result) { return; }
......
......@@ -3,10 +3,11 @@
#include <cstdint>
#include <memory>
#include "native/sql/SqlTuple.hpp"
#include "algebra/logical/expressions.hpp"
#include "foundations/InformationUnit.hpp"
#include "foundations/QueryContext.hpp"
#include "foundations/IUFactory.hpp"
namespace Algebra {
namespace Logical {
......@@ -22,11 +23,10 @@ class Operator {
public:
size_t cardinality;
Operator(QueryContext & context) :
_context(context)
Operator(IUFactory &iuFactory) :
_iuFactory(iuFactory)
{
_uid = _context.operatorUID;
_context.operatorUID += 1;
_uid = _iuFactory.getUID();
}
Operator(const Operator &) = delete;
......@@ -37,7 +37,7 @@ public:
virtual void accept(OperatorVisitor & visitor) = 0;
QueryContext & getContext() const { return _context; }
IUFactory & getIUFactory() const { return _iuFactory; }
Operator * getParent() const { return parent; }
......@@ -69,7 +69,7 @@ protected:
virtual void updateRequiredSetsTraverser() = 0;
Operator * parent = nullptr;
QueryContext & _context;
IUFactory &_iuFactory;
iu_set_t produced;
iu_set_t required;
......@@ -86,6 +86,9 @@ private:
class GroupBy;
class Join;
class Map;
class Update;
class Insert;
class Delete;
class Result;
class Select;
class TableScan;
......@@ -99,6 +102,9 @@ struct OperatorVisitor {
virtual void visit(GroupBy & op) = 0;
virtual void visit(Join & op) = 0;
virtual void visit(Map & op) = 0;
virtual void visit(Update & op) = 0;
virtual void visit(Insert & op) = 0;
virtual void visit(Delete & op) = 0;
virtual void visit(Result & op) = 0;
virtual void visit(Select & op) = 0;
virtual void visit(TableScan & op) = 0;
......@@ -109,7 +115,7 @@ struct OperatorVisitor {
class NullaryOperator : public Operator {
public:
NullaryOperator(QueryContext & context);
NullaryOperator(IUFactory &iuFactory);
~NullaryOperator() override;
......@@ -256,16 +262,15 @@ struct AggregatorVisitor;
class Aggregator {
public:
Aggregator(QueryContext & context) :
_context(context)
Aggregator(IUFactory &iuFactory) :
_iuFactory(iuFactory)
{ }
virtual ~Aggregator() { }
virtual void accept(AggregatorVisitor & visitor) = 0;
QueryContext & getContext() const { return _context; }
IUFactory & getIUFactory() const { return _iuFactory; }
iu_p_t getProduced();
// the expression could contain multiple iu references
......@@ -279,7 +284,7 @@ protected:
virtual void computeProduced();
virtual void computeRequired() = 0;
QueryContext & _context;
IUFactory & _iuFactory;
Operator * parent = nullptr;
iu_p_t _produced;
......@@ -309,8 +314,8 @@ struct AggregatorVisitor {
class Keep : public Aggregator {
public:
Keep(QueryContext & context, iu_p_t keep) :
Aggregator(context),
Keep(IUFactory &iuFactory, iu_p_t keep) :
Aggregator(iuFactory),
_keep(keep)
{ }
......@@ -328,8 +333,8 @@ protected:
class Sum : public Aggregator {
public:
Sum(QueryContext & context, logical_exp_op_t exp) :
Aggregator(context),
Sum(IUFactory &iuFactory, logical_exp_op_t exp) :
Aggregator(iuFactory),
_expression(std::move(exp))
{ }
......@@ -349,7 +354,7 @@ private:
class Avg : public Aggregator {
public:
Avg(QueryContext & context, logical_exp_op_t exp);
Avg(IUFactory &iuFactory, logical_exp_op_t exp);
~Avg() override { }
......@@ -367,8 +372,8 @@ private:
class CountAll : public Aggregator {
public:
CountAll(QueryContext & context) :
Aggregator(context)
CountAll(IUFactory &iuFactory) :
Aggregator(iuFactory)
{ }
~CountAll() override { }
......@@ -383,8 +388,8 @@ protected:
class Min : public Aggregator {
public:
Min(QueryContext & context, logical_exp_op_t exp) :
Aggregator(context),
Min(IUFactory &iuFactory, logical_exp_op_t exp) :
Aggregator(iuFactory),
_expression(std::move(exp))
{ }
......@@ -420,12 +425,93 @@ protected:
};
//-----------------------------------------------------------------------------
// Update operator
class Delete : public UnaryOperator {
public:
Delete(std::unique_ptr<Operator> child, iu_p_t &tidIU, Table & table, branch_id_t branchId);
~Delete() override;
void accept(OperatorVisitor & visitor) override;
Table & getTable() const { return _table; }
iu_p_t &getTIDIU() { return tidIU; }
branch_id_t getBranchId() { return branchId; }
protected:
void computeProduced() override;
void computeRequired() override;
Table & _table;
iu_p_t tidIU;
branch_id_t branchId;
};
//-----------------------------------------------------------------------------
// Insert operator
class Insert : public NullaryOperator {
public:
Insert(IUFactory &iuFactory, Table & table, Native::Sql::SqlTuple *tuple, branch_id_t branchId);
~Insert() override;
void accept(OperatorVisitor & visitor) override;
Table & getTable() const { return _table; }
Native::Sql::SqlTuple *getTuple() { return sqlTuple; }
branch_id_t getBranchId() { return branchId; }
protected:
void computeProduced() override;
void computeRequired() override;
Table & _table;
branch_id_t branchId;
Native::Sql::SqlTuple *sqlTuple;
};
//-----------------------------------------------------------------------------
// Update operator
class Update : public UnaryOperator {
public:
Update(std::unique_ptr<Operator> child, std::vector<std::pair<iu_p_t,std::string>> &updateIUValuePairs, Table & table, branch_id_t branchId);
Update(std::unique_ptr<Operator> child, std::vector<std::pair<iu_p_t,std::string>> &updateIUValuePairs, Table & table);
~Update() override;
void accept(OperatorVisitor & visitor) override;
Table & getTable() const { return _table; }
branch_id_t getBranchId() { return branchId; }
std::vector<std::pair<iu_p_t,std::string>> &getUpdateIUValuePairs() { return updateIUValuePairs; }
protected:
void computeProduced() override;
void computeRequired() override;
Table & _table;
branch_id_t branchId;
std::vector<std::pair<iu_p_t,std::string>> updateIUValuePairs;
};
//-----------------------------------------------------------------------------
// Result operator
class Result : public UnaryOperator {
public:
enum class Type { PrintToStdOut } _type = Type::PrintToStdOut;
static enum class Type { PrintToStdOut, TupleStreamHandler } _type;
std::vector<iu_p_t> selection;
......@@ -445,8 +531,14 @@ protected:
class TableScan : public NullaryOperator {
public:
TableScan(QueryContext & context, Table & table) :
NullaryOperator(context),
TableScan(IUFactory &iuFactory, Table & table, branch_id_t branchId) :
NullaryOperator(iuFactory),
_table(table),
branchId(branchId)
{ }
TableScan(IUFactory &iuFactory, Table & table) :
NullaryOperator(iuFactory),
_table(table)
{ }
......@@ -456,11 +548,14 @@ public:
Table & getTable() const { return _table; }
branch_id_t getBranchId() { return branchId; }
protected:
void computeProduced() override;
void computeRequired() override;
Table & _table;
branch_id_t branchId;
};
//-----------------------------------------------------------------------------
......
#include <llvm/IR/TypeBuilder.h>
#include "algebra/physical/Delete.hpp"
#include "sql/SqlUtils.hpp"
#include "sql/SqlValues.hpp"
#include "foundations/version_management.hpp"
using namespace Sql;
namespace Algebra {
namespace Physical {
Delete::Delete(const logical_operator_t & logicalOperator, std::unique_ptr<Operator> input, iu_p_t &tidIU, Table & table, QueryContext &queryContext, branch_id_t branchId) :
UnaryOperator(std::move(logicalOperator), std::move(input), queryContext), table(table), tidIU(std::move(tidIU)), branchId(branchId) { }
Delete::~Delete()
{ }
void Delete::produce()
{
tupleCountPtr = _codeGen->CreateAlloca(cg_size_t::getType());
#ifdef __APPLE__
_codeGen->CreateStore(cg_size_t(0ull), tupleCountPtr);
#else
_codeGen->CreateStore(cg_size_t(0ul), tupleCountPtr);
#endif
child->produce();
cg_size_t tupleCnt(_codeGen->CreateLoad(tupleCountPtr));
Functions::genPrintfCall("Deleted %lu tuples\n", tupleCnt);
}
#if !USE_DATA_VERSIONING
void delete_tuple_without_versioning(tid_t tid, Table & table, QueryContext & ctx) {
table.removeRow(tid);
}
#endif
void Delete::consume(const iu_value_mapping_t & values, const Operator & src)
{
cg_size_t tid;
for (auto iu : getRequired()) {
if (iu->columnInformation->columnName.compare("tid") == 0) {
tid = cg_size_t(values.at(iu)->getLLVMValue());
break;
}
}
// Call the delete_tuple function in version_management.hpp
#if USE_DATA_VERSIONING
genDeleteCall((void *)&delete_tuple_with_branchId, tid);
#else
genDeleteCall((void *)&delete_tuple_without_versioning, tid);
#endif
// increment tuple counter
cg_size_t prevCnt(_codeGen->CreateLoad(tupleCountPtr));
_codeGen->CreateStore(prevCnt + 1ul, tupleCountPtr);
}
void Delete::genDeleteCall(void* funcPtr, cg_size_t tid) {
llvm::FunctionType * funcDeleteTupleTy = llvm::TypeBuilder<void (size_t, void *, void *), false>::get(_codeGen.getLLVMContext());
llvm::Function * func = llvm::cast<llvm::Function>( getThreadLocalCodeGen().getCurrentModuleGen().getModule().getOrInsertFunction("delete_tuple_with_branchId", funcDeleteTupleTy) );
getThreadLocalCodeGen().getCurrentModuleGen().addFunctionMapping(func,funcPtr);
_codeGen->CreateCall(func, {tid, cg_u32_t(branchId), cg_ptr8_t::fromRawPointer(&table), _codeGen.getCurrentFunctionGen().getArg(1)});
}
} // end namespace Physical
} // end namespace Algebra
//
// Created by Blum Thomas on 2020-05-21.
//
#ifndef PROTODB_DELETE_HPP
#define PROTODB_DELETE_HPP
#include "algebra/physical/Operator.hpp"
namespace Algebra {
namespace Physical {
class Delete : public UnaryOperator {
public:
Delete(const logical_operator_t & logicalOperator, std::unique_ptr<Operator> input, iu_p_t &tidIU, Table & table, QueryContext &queryContext, branch_id_t branchId);
virtual ~Delete();
void produce() override;
void consume(const iu_value_mapping_t & values, const Operator & src) override;
private:
Table & table;
llvm::Value * tupleCountPtr;
iu_p_t tidIU;
branch_id_t branchId;
void genDeleteCall(void* funcPtr, cg_size_t tid);
};
} // end namespace Physical
} // end namespace Algebra
#endif //PROTODB_DELETE_HPP
......@@ -320,8 +320,8 @@ llvm::Type * Min::getEntryType()
using namespace Aggregations;
GroupBy::GroupBy(const logical_operator_t & logicalOperator, std::unique_ptr<Operator> input,
std::vector<std::unique_ptr<Aggregations::Aggregator>> aggregations) :
UnaryOperator(std::move(logicalOperator), std::move(input)),
std::vector<std::unique_ptr<Aggregations::Aggregator>> aggregations, QueryContext &queryContext) :
UnaryOperator(std::move(logicalOperator), std::move(input), queryContext),
_aggregations(std::move(aggregations))
{
createGroupType();
......
......@@ -152,7 +152,7 @@ class CountDistinct : public Aggregator {
class GroupBy : public UnaryOperator {
public:
GroupBy(const logical_operator_t & logicalOperator, std::unique_ptr<Operator> input,
std::vector<std::unique_ptr<Aggregations::Aggregator>> aggregations);
std::vector<std::unique_ptr<Aggregations::Aggregator>> aggregations, QueryContext &queryContext);
virtual ~GroupBy();
......
......@@ -179,7 +179,11 @@ using join_pair_vec_t = HashJoin::join_pair_vec_t;
template<Side side>
static cg_hash_t genJoinHash(const join_pair_vec_t & joinPairs, const iu_value_mapping_t & values)
{
#ifdef __APPLE__
cg_hash_t seed(0ull);
#else
cg_hash_t seed(0ul);
#endif
// iterate over each join pair and calculate the combined hash
bool first = true;
......@@ -200,8 +204,8 @@ static cg_hash_t genJoinHash(const join_pair_vec_t & joinPairs, const iu_value_m
HashJoin::HashJoin(const logical_operator_t & logicalOperator,
std::unique_ptr<Operator> left, std::unique_ptr<Operator> right,
join_pair_vec_t pairs) :
BinaryOperator(std::move(logicalOperator), std::move(left), std::move(right)),
join_pair_vec_t pairs, QueryContext &queryContext) :
BinaryOperator(std::move(logicalOperator), std::move(left), std::move(right), queryContext),
joinPairs(std::move(pairs))
{
// sanity check:
......
......@@ -15,7 +15,7 @@ public:
/// \param pairs: vector of (left expr, right expr) pairs
HashJoin(const logical_operator_t & logicalOperator,
std::unique_ptr<Operator> left, std::unique_ptr<Operator> right,
join_pair_vec_t pairs);
join_pair_vec_t pairs, QueryContext &queryContext);
virtual ~HashJoin();
......
#include "algebra/physical/Insert.hpp"
#include "sql/SqlUtils.hpp"
#include "sql/SqlValues.hpp"
#include "foundations/version_management.hpp"
#include <llvm/IR/TypeBuilder.h>
#include <iostream>
using namespace Sql;
namespace Algebra {
namespace Physical {
Insert::Insert(const logical_operator_t & logicalOperator, Table & table, Native::Sql::SqlTuple *tuple, QueryContext &context, branch_id_t branchId) :
NullaryOperator(std::move(logicalOperator),context) , table(table), tuple(tuple), context(context), branchId(branchId)
{
}
Insert::~Insert()
{ }
#if !USE_DATA_VERSIONING
tid_t insert_tuple_without_versioning(Native::Sql::SqlTuple & tuple, Table & table, QueryContext & ctx) {
tid_t tid;
// store tuple
table.addRow(0);
size_t column_idx = 0;
for (auto & value : tuple.values) {
void * ptr = const_cast<void *>(table.getColumn(column_idx).back());
value->store(ptr);
column_idx += 1;
}
return tid;
}
#endif
void Insert::produce()
{
#if USE_DATA_VERSIONING
genInsertCall((void *)&insert_tuple_with_branchId);
#else
genInsertCall((void *)&insert_tuple_without_versioning);
#endif
}
void Insert::genInsertCall(void *funcPtr) {
llvm::FunctionType * funcTy = llvm::TypeBuilder<void (void *, void *, void *), false>::get(_codeGen.getLLVMContext());
llvm::Function * func = llvm::cast<llvm::Function>( getThreadLocalCodeGen().getCurrentModuleGen().getModule().getOrInsertFunction("insert_tuple_with_binding", funcTy) );
getThreadLocalCodeGen().getCurrentModuleGen().addFunctionMapping(func,funcPtr);
_codeGen->CreateCall(func, {cg_ptr8_t::fromRawPointer(tuple), cg_ptr8_t::fromRawPointer(&table), _codeGen.getCurrentFunctionGen().getArg(1), cg_u32_t(branchId)});
}
} // end namespace Physical
} // end namespace Algebra
#ifndef PROTODB_INSERT_HPP
#define PROTODB_INSERT_HPP
#include "algebra/physical/Operator.hpp"
#include "native/sql/SqlTuple.hpp"
namespace Algebra {
namespace Physical {
/// The print operator
class Insert : public NullaryOperator {
public:
Insert(const logical_operator_t & logicalOperator, Table & table, Native::Sql::SqlTuple *tuple, QueryContext &context, branch_id_t branchId);
virtual ~Insert();
void produce() override;
private:
Native::Sql::SqlTuple *tuple;
Table & table;
QueryContext &context;
branch_id_t branchId;
void genInsertCall(void *funcPtr);
};
} // end namespace Physical
} // end namespace Algebra
#endif //PROTODB_INSERT_HPP
......@@ -12,9 +12,9 @@ namespace Physical {
//-----------------------------------------------------------------------------
// Operator
Operator::Operator(const logical_operator_t & logicalOperator) :
_codeGen(logicalOperator.getContext().codeGen),
_context(logicalOperator.getContext()),
Operator::Operator(const logical_operator_t & logicalOperator, QueryContext &queryContext) :
_codeGen(queryContext.codeGen),
_context(queryContext),
_logicalOperator(std::move(logicalOperator))
{ }
......@@ -44,8 +44,8 @@ const iu_set_t & Operator::getRequired()
//-----------------------------------------------------------------------------
// NullaryOperator
NullaryOperator::NullaryOperator(const logical_operator_t & logicalOperator) :
Operator(std::move(logicalOperator))
NullaryOperator::NullaryOperator(const logical_operator_t & logicalOperator, QueryContext &queryContext) :
Operator(std::move(logicalOperator),queryContext)
{ }
NullaryOperator::~NullaryOperator()
......@@ -63,8 +63,8 @@ size_t NullaryOperator::arity() const
//-----------------------------------------------------------------------------
// UnaryOperator
UnaryOperator::UnaryOperator(const logical_operator_t & logicalOperator, std::unique_ptr<Operator> input) :
Operator(std::move(logicalOperator)),
UnaryOperator::UnaryOperator(const logical_operator_t & logicalOperator, std::unique_ptr<Operator> input, QueryContext &queryContext) :
Operator(std::move(logicalOperator),queryContext),
child(std::move(input))
{
child->setParent(this);
......@@ -81,8 +81,8 @@ size_t UnaryOperator::arity() const
//-----------------------------------------------------------------------------
// BinaryOperator
BinaryOperator::BinaryOperator(const logical_operator_t & logicalOperator, std::unique_ptr<Operator> leftInput,
std::unique_ptr<Operator> rightInput) :
Operator(std::move(logicalOperator)),
std::unique_ptr<Operator> rightInput, QueryContext &queryContext) :
Operator(std::move(logicalOperator), queryContext),
_leftChild(std::move(leftInput)),
_rightChild(std::move(rightInput))
{
......
......@@ -8,7 +8,7 @@
#include "algebra/logical/operators.hpp"
#include "codegen/CodeGen.hpp"
#include "foundations/InformationUnit.hpp"
#include "foundations/QueryContext.hpp"
#include "queryCompiler/QueryContext.hpp"
#include "sql/SqlType.hpp"
#include "sql/SqlValues.hpp"
......@@ -20,7 +20,7 @@ using iu_value_mapping_t = std::unordered_map<iu_p_t, Sql::Value *>;
class Operator {
public:
Operator(const logical_operator_t & logicalOperator);
Operator(const logical_operator_t & logicalOperator, QueryContext &queryContext);
virtual ~Operator();
......@@ -57,7 +57,7 @@ protected:
class NullaryOperator : public Operator {
public:
NullaryOperator(const logical_operator_t & logicalOperator);
NullaryOperator(const logical_operator_t & logicalOperator, QueryContext &queryContext);
virtual ~NullaryOperator();
......@@ -68,7 +68,7 @@ public:
class UnaryOperator : public Operator {
public:
UnaryOperator(const logical_operator_t & logicalOperator, std::unique_ptr<Operator> input);
UnaryOperator(const logical_operator_t & logicalOperator, std::unique_ptr<Operator> input, QueryContext &queryContext);
virtual ~UnaryOperator();
......@@ -81,7 +81,7 @@ protected:
class BinaryOperator : public Operator {
public:
BinaryOperator(const logical_operator_t & logicalOperator, std::unique_ptr<Operator> leftInput,
std::unique_ptr<Operator> rightInput);
std::unique_ptr<Operator> rightInput, QueryContext &queryContext);
virtual ~BinaryOperator();
......
......@@ -10,8 +10,8 @@ using namespace Sql;
namespace Algebra {
namespace Physical {
Print::Print(const logical_operator_t & logicalOperator, std::unique_ptr<Operator> input) :
UnaryOperator(std::move(logicalOperator), std::move(input))
Print::Print(const logical_operator_t & logicalOperator, std::unique_ptr<Operator> input, QueryContext &queryContext) :
UnaryOperator(std::move(logicalOperator), std::move(input), queryContext)
{ }
Print::~Print()
......@@ -20,12 +20,20 @@ Print::~Print()
void Print::produce()
{
tupleCountPtr = _codeGen->CreateAlloca(cg_size_t::getType());
#ifdef __APPLE__
_codeGen->CreateStore(cg_size_t(0ull), tupleCountPtr);
#else
_codeGen->CreateStore(cg_size_t(0ul), tupleCountPtr);
#endif
child->produce();
cg_size_t tupleCnt(_codeGen->CreateLoad(tupleCountPtr));
#ifdef __APPLE__
IfGen check(tupleCnt == cg_size_t(0ull));
#else
IfGen check(tupleCnt == cg_size_t(0ul));
#endif
{
Functions::genPrintfCall("Empty result set\n");
}
......
......@@ -9,7 +9,7 @@ namespace Physical {
/// The print operator
class Print : public UnaryOperator {
public:
Print(const logical_operator_t & logicalOperator, std::unique_ptr<Operator> input);
Print(const logical_operator_t & logicalOperator, std::unique_ptr<Operator> input, QueryContext &queryContext);
virtual ~Print();
......
......@@ -8,8 +8,8 @@ using namespace Sql;
namespace Algebra {
namespace Physical {
Select::Select(const logical_operator_t & logicalOperator, std::unique_ptr<Operator> input, Expressions::exp_op_t exp) :
UnaryOperator(std::move(logicalOperator), std::move(input)),
Select::Select(const logical_operator_t & logicalOperator, std::unique_ptr<Operator> input, Expressions::exp_op_t exp, QueryContext &queryContext) :
UnaryOperator(std::move(logicalOperator), std::move(input), queryContext),
_exp(std::move(exp))
{ }
......
......@@ -12,7 +12,7 @@ class Select : public UnaryOperator {
public:
enum ArithmeticOperator { Equals };
Select(const logical_operator_t & logicalOperator, std::unique_ptr<Operator> input, Expressions::exp_op_t exp);
Select(const logical_operator_t & logicalOperator, std::unique_ptr<Operator> input, Expressions::exp_op_t exp, QueryContext &queryContext);
virtual ~Select();
......