Skip to content

Commit

Permalink
Removed _nofColumns. Some code cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
floriankramer committed Mar 9, 2019
1 parent 8b8bec9 commit 2e1ac17
Show file tree
Hide file tree
Showing 21 changed files with 68 additions and 91 deletions.
2 changes: 1 addition & 1 deletion src/WriteIndexListsMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ int main(int argc, char** argv) {
auto qet = queryPlanner.createExecutionTree(q);
const auto res = qet.getResult();
AD_CHECK(res->size() > 0);
AD_CHECK(res->_nofColumns == 1);
AD_CHECK(res->_data.cols() == 1);
string personlistFile = indexName + ".list.scientists";
std::ofstream f(personlistFile.c_str());
const IdTable& ids = res->_data;
Expand Down
3 changes: 1 addition & 2 deletions src/engine/CountAvailablePredicates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ size_t CountAvailablePredicates::getCostEstimate() {
// _____________________________________________________________________________
void CountAvailablePredicates::computeResult(ResultTable* result) {
LOG(DEBUG) << "CountAvailablePredicates result computation..." << std::endl;
result->_nofColumns = 2;
result->_data.setCols(result->_nofColumns);
result->_data.setCols(2);
result->_sortedBy = resultSortedOn();
result->_resultTypes.push_back(ResultTable::ResultType::KB);
result->_resultTypes.push_back(ResultTable::ResultType::VERBATIM);
Expand Down
3 changes: 1 addition & 2 deletions src/engine/Distinct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ void Distinct::computeResult(ResultTable* result) {
runtimeInfo.setDescriptor("DISTINCT");
runtimeInfo.addChild(_subtree->getRootOperation()->getRuntimeInfo());
LOG(DEBUG) << "Distinct result computation..." << endl;
result->_nofColumns = subRes->_nofColumns;
result->_data.setCols(result->_nofColumns);
result->_data.setCols(subRes->_data.cols());
result->_resultTypes.insert(result->_resultTypes.end(),
subRes->_resultTypes.begin(),
subRes->_resultTypes.end());
Expand Down
5 changes: 2 additions & 3 deletions src/engine/Filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,13 @@ void Filter::computeResult(ResultTable* result) {
runtimeInfo.setDescriptor(getDescriptor());
runtimeInfo.addChild(_subtree->getRootOperation()->getRuntimeInfo());
LOG(DEBUG) << "Filter result computation..." << endl;
result->_nofColumns = subRes->_nofColumns;
result->_data.setCols(result->_nofColumns);
result->_data.setCols(subRes->_data.cols());
result->_resultTypes.insert(result->_resultTypes.end(),
subRes->_resultTypes.begin(),
subRes->_resultTypes.end());
result->_localVocab = subRes->_localVocab;
size_t lhsInd = _subtree->getVariableColumn(_lhs);
int width = result->_nofColumns;
int width = result->_data.cols();
if (_rhs[0] == '?') {
size_t rhsInd = _subtree->getVariableColumn(_rhs);
CALL_FIXED_SIZE_1(width, computeResultDynamicValue, &result->_data, lhsInd,
Expand Down
11 changes: 5 additions & 6 deletions src/engine/GroupBy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -657,8 +657,7 @@ void GroupBy::computeResult(ResultTable* result) {
std::vector<size_t> groupByColumns;

result->_sortedBy = resultSortedOn();
result->_nofColumns = getResultWidth();
result->_data.setCols(result->_nofColumns);
result->_data.setCols(getResultWidth());

std::vector<Aggregate> aggregates;
aggregates.reserve(_aliases.size() + _groupByVariables.size());
Expand Down Expand Up @@ -795,8 +794,8 @@ void GroupBy::computeResult(ResultTable* result) {
runtimeInfo.addChild(_subtree->getRootOperation()->getRuntimeInfo());

// populate the result type vector
result->_resultTypes.resize(result->_nofColumns);
for (size_t i = 0; i < result->_nofColumns; i++) {
result->_resultTypes.resize(result->_data.cols());
for (size_t i = 0; i < result->_data.cols(); i++) {
switch (aggregates[i]._type) {
case AggregateType::AVG:
result->_resultTypes[i] = ResultTable::ResultType::FLOAT;
Expand Down Expand Up @@ -834,8 +833,8 @@ void GroupBy::computeResult(ResultTable* result) {
}

std::vector<ResultTable::ResultType> inputResultTypes;
inputResultTypes.reserve(subresult->_nofColumns);
for (size_t i = 0; i < subresult->_nofColumns; i++) {
inputResultTypes.reserve(subresult->_data.cols());
for (size_t i = 0; i < subresult->_data.cols(); i++) {
inputResultTypes.push_back(subresult->getResultType(i));
}

Expand Down
5 changes: 2 additions & 3 deletions src/engine/HasPredicateScan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,7 @@ size_t HasPredicateScan::getCostEstimate() {

void HasPredicateScan::computeResult(ResultTable* result) {
LOG(DEBUG) << "HasPredicateScan result computation..." << std::endl;
result->_nofColumns = getResultWidth();
result->_data.setCols(result->_nofColumns);
result->_data.setCols(getResultWidth());
result->_sortedBy = resultSortedOn();

const std::vector<PatternID>& hasPattern = getIndex().getHasPattern();
Expand Down Expand Up @@ -233,7 +232,7 @@ void HasPredicateScan::computeResult(ResultTable* result) {
subresult->_resultTypes.end());
result->_resultTypes.push_back(ResultTable::ResultType::KB);
int inWidth = subresult->_data.cols();
int outWidth = result->_nofColumns;
int outWidth = result->_data.cols();
CALL_FIXED_SIZE_2(inWidth, outWidth, HasPredicateScan::computeSubqueryS,
&result->_data, subresult->_data, _subtreeColIndex,
hasPattern, hasPredicate, patterns);
Expand Down
12 changes: 12 additions & 0 deletions src/engine/IdTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ class IdTableImpl {
using iterator_category = std::forward_iterator_tag;

iterator() : _data(nullptr), _row(0) {}
// This constructor has to take three arguments for compatibility with
// IdTableImpl<0> which doesn't know the number of columns at compile time.
// To prevent compiler warnings about unused parameters the third parameter
// (the number of columns) is not given a name.
iterator(Id* data, size_t row, size_t) : _data(data), _row(row) {}
virtual ~iterator() {}

Expand Down Expand Up @@ -205,6 +209,10 @@ class IdTableImpl<0> {
}

Row& operator=(const Row& other) {
// Check for self assignment.
if (&other == this) {
return *this;
}
if (_allocated) {
// If we manage our own storage recreate that to fit the other row
delete[] _data;
Expand All @@ -219,6 +227,10 @@ class IdTableImpl<0> {
}

Row& operator=(Row&& other) {
// Check for self assignment.
if (&other == this) {
return *this;
}
// This class cannot use move semantics if at least one of the two
// rows invovled in an assigment does not manage it's data, but rather
// functions as a view into an IdTable
Expand Down
27 changes: 9 additions & 18 deletions src/engine/IndexScan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,17 +169,15 @@ void IndexScan::computeResult(ResultTable* result) {

// _____________________________________________________________________________
void IndexScan::computePSOboundS(ResultTable* result) const {
result->_nofColumns = 1;
result->_data.setCols(result->_nofColumns);
result->_data.setCols(1);
result->_resultTypes.push_back(ResultTable::ResultType::KB);
result->_sortedBy = {0};
_executionContext->getIndex().scanPSO(_predicate, _subject, &result->_data);
}

// _____________________________________________________________________________
void IndexScan::computePSOfreeS(ResultTable* result) const {
result->_nofColumns = 2;
result->_data.setCols(result->_nofColumns);
result->_data.setCols(2);
result->_resultTypes.push_back(ResultTable::ResultType::KB);
result->_resultTypes.push_back(ResultTable::ResultType::KB);
result->_sortedBy = {0, 1};
Expand All @@ -188,17 +186,15 @@ void IndexScan::computePSOfreeS(ResultTable* result) const {

// _____________________________________________________________________________
void IndexScan::computePOSboundO(ResultTable* result) const {
result->_nofColumns = 1;
result->_data.setCols(result->_nofColumns);
result->_data.setCols(1);
result->_resultTypes.push_back(ResultTable::ResultType::KB);
result->_sortedBy = {0};
_executionContext->getIndex().scanPOS(_predicate, _object, &result->_data);
}

// _____________________________________________________________________________
void IndexScan::computePOSfreeO(ResultTable* result) const {
result->_nofColumns = 2;
result->_data.setCols(result->_nofColumns);
result->_data.setCols(2);
result->_resultTypes.push_back(ResultTable::ResultType::KB);
result->_resultTypes.push_back(ResultTable::ResultType::KB);
result->_sortedBy = {0, 1};
Expand Down Expand Up @@ -240,8 +236,7 @@ size_t IndexScan::computeSizeEstimate() {

// _____________________________________________________________________________
void IndexScan::computeSPOfreeP(ResultTable* result) const {
result->_nofColumns = 2;
result->_data.setCols(result->_nofColumns);
result->_data.setCols(2);
result->_resultTypes.push_back(ResultTable::ResultType::KB);
result->_resultTypes.push_back(ResultTable::ResultType::KB);
result->_sortedBy = {0, 1};
Expand All @@ -250,17 +245,15 @@ void IndexScan::computeSPOfreeP(ResultTable* result) const {

// _____________________________________________________________________________
void IndexScan::computeSOPboundO(ResultTable* result) const {
result->_nofColumns = 1;
result->_data.setCols(result->_nofColumns);
result->_data.setCols(1);
result->_resultTypes.push_back(ResultTable::ResultType::KB);
result->_sortedBy = {0};
_executionContext->getIndex().scanSOP(_subject, _object, &result->_data);
}

// _____________________________________________________________________________
void IndexScan::computeSOPfreeO(ResultTable* result) const {
result->_nofColumns = 2;
result->_data.setCols(result->_nofColumns);
result->_data.setCols(2);
result->_resultTypes.push_back(ResultTable::ResultType::KB);
result->_resultTypes.push_back(ResultTable::ResultType::KB);
result->_sortedBy = {0, 1};
Expand All @@ -269,8 +262,7 @@ void IndexScan::computeSOPfreeO(ResultTable* result) const {

// _____________________________________________________________________________
void IndexScan::computeOPSfreeP(ResultTable* result) const {
result->_nofColumns = 2;
result->_data.setCols(result->_nofColumns);
result->_data.setCols(2);
result->_resultTypes.push_back(ResultTable::ResultType::KB);
result->_resultTypes.push_back(ResultTable::ResultType::KB);
result->_sortedBy = {0, 1};
Expand All @@ -279,8 +271,7 @@ void IndexScan::computeOPSfreeP(ResultTable* result) const {

// _____________________________________________________________________________
void IndexScan::computeOSPfreeS(ResultTable* result) const {
result->_nofColumns = 2;
result->_data.setCols(result->_nofColumns);
result->_data.setCols(2);
result->_resultTypes.push_back(ResultTable::ResultType::KB);
result->_resultTypes.push_back(ResultTable::ResultType::KB);
result->_sortedBy = {0, 1};
Expand Down
27 changes: 11 additions & 16 deletions src/engine/Join.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,8 @@ void Join::computeResult(ResultTable* result) {
LOG(TRACE) << "Either side is empty thus join result is empty" << endl;
runtimeInfo.addDetail("Either side was empty", "");
size_t resWidth = leftWidth + rightWidth - 1;
result->_nofColumns = resWidth;
result->_data.setCols(result->_nofColumns);
result->_resultTypes.resize(result->_nofColumns);
result->_data.setCols(resWidth);
result->_resultTypes.resize(result->_data.cols());
result->_sortedBy = {_leftJoinCol};
return;
}
Expand All @@ -94,9 +93,8 @@ void Join::computeResult(ResultTable* result) {
LOG(TRACE) << "Left side empty thus join result is empty" << endl;
runtimeInfo.addDetail("The left side was empty", "");
size_t resWidth = leftWidth + rightWidth - 1;
result->_nofColumns = resWidth;
result->_data.setCols(result->_nofColumns);
result->_resultTypes.resize(result->_nofColumns);
result->_data.setCols(resWidth);
result->_resultTypes.resize(result->_data.cols());
result->_sortedBy = {_leftJoinCol};
return;
}
Expand All @@ -109,13 +107,12 @@ void Join::computeResult(ResultTable* result) {

AD_CHECK(result);

result->_nofColumns = leftWidth + rightWidth - 1;
result->_data.setCols(result->_nofColumns);
result->_resultTypes.reserve(result->_nofColumns);
result->_data.setCols(leftWidth + rightWidth - 1);
result->_resultTypes.reserve(result->_data.cols());
result->_resultTypes.insert(result->_resultTypes.end(),
leftRes->_resultTypes.begin(),
leftRes->_resultTypes.end());
for (size_t i = 0; i < rightRes->_nofColumns; i++) {
for (size_t i = 0; i < rightRes->_data.cols(); i++) {
if (i != _rightJoinCol) {
result->_resultTypes.push_back(rightRes->_resultTypes[i]);
}
Expand Down Expand Up @@ -242,11 +239,10 @@ void Join::computeResultForJoinWithFullScanDummy(ResultTable* result) const {
LOG(DEBUG) << "Join by making multiple scans..." << endl;
if (isFullScanDummy(_left)) {
AD_CHECK(!isFullScanDummy(_right))
result->_nofColumns = _right->getResultWidth() + 2;
result->_data.setCols(result->_nofColumns);
result->_data.setCols(_right->getResultWidth() + 2);
result->_sortedBy = {2 + _rightJoinCol};
shared_ptr<const ResultTable> nonDummyRes = _right->getResult();
result->_resultTypes.reserve(result->_nofColumns);
result->_resultTypes.reserve(result->_data.cols());
result->_resultTypes.push_back(ResultTable::ResultType::KB);
result->_resultTypes.push_back(ResultTable::ResultType::KB);
result->_resultTypes.insert(result->_resultTypes.end(),
Expand All @@ -255,12 +251,11 @@ void Join::computeResultForJoinWithFullScanDummy(ResultTable* result) const {
doComputeJoinWithFullScanDummyLeft(nonDummyRes->_data, &result->_data);
} else {
AD_CHECK(!isFullScanDummy(_left))
result->_nofColumns = _left->getResultWidth() + 2;
result->_data.setCols(result->_nofColumns);
result->_data.setCols(_left->getResultWidth() + 2);
result->_sortedBy = {_leftJoinCol};

shared_ptr<const ResultTable> nonDummyRes = _left->getResult();
result->_resultTypes.reserve(result->_nofColumns);
result->_resultTypes.reserve(result->_data.cols());
result->_resultTypes.insert(result->_resultTypes.end(),
nonDummyRes->_resultTypes.begin(),
nonDummyRes->_resultTypes.end());
Expand Down
9 changes: 4 additions & 5 deletions src/engine/MultiColumnJoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,9 @@ void MultiColumnJoin::computeResult(ResultTable* result) {
runtimeInfo.setDescriptor("MultiColumnJoin on " + joinVars);

result->_sortedBy = resultSortedOn();
result->_nofColumns = getResultWidth();
result->_data.setCols(result->_nofColumns);
result->_data.setCols(getResultWidth());

AD_CHECK_GE(result->_nofColumns, _joinColumns.size());
AD_CHECK_GE(result->_data.cols(), _joinColumns.size());

const auto leftResult = _left->getResult();
const auto rightResult = _right->getResult();
Expand All @@ -87,11 +86,11 @@ void MultiColumnJoin::computeResult(ResultTable* result) {
LOG(DEBUG) << "MultiColumnJoin subresult computation done." << std::endl;

// compute the result types
result->_resultTypes.reserve(result->_nofColumns);
result->_resultTypes.reserve(result->_data.cols());
result->_resultTypes.insert(result->_resultTypes.end(),
leftResult->_resultTypes.begin(),
leftResult->_resultTypes.end());
for (size_t col = 0; col < rightResult->_nofColumns; col++) {
for (size_t col = 0; col < rightResult->_data.cols(); col++) {
bool isJoinColumn = false;
for (const std::array<Id, 2>& a : _joinColumns) {
if (a[1] == col) {
Expand Down
9 changes: 4 additions & 5 deletions src/engine/OptionalJoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,9 @@ void OptionalJoin::computeResult(ResultTable* result) {
runtimeInfo.setDescriptor("OptionalJoin on " + joinVars);

result->_sortedBy = resultSortedOn();
result->_nofColumns = getResultWidth();
result->_data.setCols(result->_nofColumns);
result->_data.setCols(getResultWidth());

AD_CHECK_GE(result->_nofColumns, _joinColumns.size());
AD_CHECK_GE(result->_data.cols(), _joinColumns.size());

const auto leftResult = _left->getResult();
const auto rightResult = _right->getResult();
Expand All @@ -89,11 +88,11 @@ void OptionalJoin::computeResult(ResultTable* result) {
LOG(DEBUG) << "OptionalJoin subresult computation done." << std::endl;

// compute the result types
result->_resultTypes.reserve(result->_nofColumns);
result->_resultTypes.reserve(result->_data.cols());
result->_resultTypes.insert(result->_resultTypes.end(),
leftResult->_resultTypes.begin(),
leftResult->_resultTypes.end());
for (size_t col = 0; col < rightResult->_nofColumns; col++) {
for (size_t col = 0; col < rightResult->_data.cols(); col++) {
bool isJoinColumn = false;
for (const std::array<Id, 2>& a : _joinColumns) {
if (a[1] == col) {
Expand Down
6 changes: 2 additions & 4 deletions src/engine/OrderBy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ void OrderBy::computeResult(ResultTable* result) {
runtimeInfo.setDescriptor("OrderBy on " + orderByVars);
runtimeInfo.addChild(_subtree->getRootOperation()->getRuntimeInfo());
LOG(DEBUG) << "OrderBy result computation..." << endl;
result->_nofColumns = subRes->_nofColumns;
result->_data.setCols(result->_nofColumns);
result->_data.setCols(subRes->_data.cols());
result->_resultTypes.insert(result->_resultTypes.end(),
subRes->_resultTypes.begin(),
subRes->_resultTypes.end());
Expand All @@ -79,8 +78,7 @@ void OrderBy::computeResult(ResultTable* result) {
subRes->_data.end());

int width = result->_data.cols();
// CALL_FIXED_SIZE_1(width, getEngine().sort, &result->_data,
// OBComp(_sortIndices));
// TODO(florian): Check if the lambda is a performance problem
CALL_FIXED_SIZE_1(width, getEngine().sort, &result->_data,
[this](const auto& a, const auto& b) {
for (auto& entry : _sortIndices) {
Expand Down
3 changes: 1 addition & 2 deletions src/engine/ResultTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

// _____________________________________________________________________________
ResultTable::ResultTable()
: _nofColumns(0),
_sortedBy(),
: _sortedBy(),
_resultTypes(),
_localVocab(std::make_shared<std::vector<std::string>>()),
_status(ResultTable::IN_PROGRESS) {}
Expand Down
2 changes: 0 additions & 2 deletions src/engine/ResultTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ class ResultTable {
LOCAL_VOCAB
};

size_t _nofColumns;

/**
* @brief This vector contains a list of column indices by which the result
* is sorted. This vector may be empty if the result is not sorted
Expand Down
3 changes: 1 addition & 2 deletions src/engine/Sort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ void Sort::computeResult(ResultTable* result) {
runtimeInfo.addChild(_subtree->getRootOperation()->getRuntimeInfo());

LOG(DEBUG) << "Sort result computation..." << endl;
result->_nofColumns = subRes->_nofColumns;
result->_data.setCols(result->_nofColumns);
result->_data.setCols(subRes->_data.cols());
result->_resultTypes.insert(result->_resultTypes.end(),
subRes->_resultTypes.begin(),
subRes->_resultTypes.end());
Expand Down

0 comments on commit 2e1ac17

Please sign in to comment.