Skip to content

Commit

Permalink
Merge pull request #116 from niklas88/arm_cleanups
Browse files Browse the repository at this point in the history
Correct some uses of wrong variable types preventing QLever from running on ARM
  • Loading branch information
niklas88 committed Aug 30, 2018
2 parents 10c01c3 + 9242f0e commit 67a43ec
Show file tree
Hide file tree
Showing 15 changed files with 82 additions and 76 deletions.
2 changes: 1 addition & 1 deletion src/engine/CountAvailablePredicates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ void CountAvailablePredicates::computePatternTrick(
ad_utility::HashMap<Id, size_t> predicateCounts;
ad_utility::HashMap<size_t, size_t> patternCounts;
size_t posInput = 0;
size_t lastSubject = ID_NO_VALUE;
Id lastSubject = ID_NO_VALUE;
while (posInput < input->size()) {
while ((*input)[posInput][subjectColumn] == lastSubject &&
posInput < input->size()) {
Expand Down
22 changes: 11 additions & 11 deletions src/engine/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ class Engine {
const typename B::value_type* b,
size_t sizeA, int joinColumnBitmap_a,
int joinColumnBitmap_b,
const std::vector<size_t>& joinColumnAToB,
const std::vector<Id>& joinColumnAToB,
unsigned int resultSize, R& res) {
assert(!(aEmpty && bEmpty));
if (aEmpty) {
Expand Down Expand Up @@ -442,11 +442,11 @@ class Engine {
* @param joinColumns
* @param result
*/
template <typename A, typename B, typename R, int K>
template <typename A, typename B, typename R, size_t K>
static void optionalJoin(const A& a, const B& b, bool aOptional,
bool bOptional,
const vector<array<size_t, 2>>& joinColumns,
vector<R>* result, unsigned int resultSize) {
const vector<array<Id, 2>>& joinColumns,
vector<R>* result, size_t resultSize) {
// check for trivial cases
if ((a.size() == 0 && b.size() == 0) || (a.size() == 0 && !aOptional) ||
(b.size() == 0 && !bOptional)) {
Expand All @@ -455,23 +455,23 @@ class Engine {

int joinColumnBitmap_a = 0;
int joinColumnBitmap_b = 0;
for (const array<size_t, 2>& jc : joinColumns) {
for (const array<Id, 2>& jc : joinColumns) {
joinColumnBitmap_a |= (1 << jc[0]);
joinColumnBitmap_b |= (1 << jc[1]);
}

// When a is optional this is used to quickly determine
// in which column of b the value of a joined column can be found.
std::vector<size_t> joinColumnAToB;
std::vector<Id> joinColumnAToB;
if (aOptional) {
uint32_t maxJoinColA = 0;
for (const array<size_t, 2>& jc : joinColumns) {
for (const array<Id, 2>& jc : joinColumns) {
if (jc[0] > maxJoinColA) {
maxJoinColA = jc[0];
}
}
joinColumnAToB.resize(maxJoinColA + 1);
for (const array<size_t, 2>& jc : joinColumns) {
for (const array<Id, 2>& jc : joinColumns) {
joinColumnAToB[jc[0]] = jc[1];
}
}
Expand Down Expand Up @@ -543,7 +543,7 @@ class Engine {
matched = true;
for (size_t joinColIndex = 0; joinColIndex < joinColumns.size();
joinColIndex++) {
const array<size_t, 2>& joinColumn = joinColumns[joinColIndex];
const array<Id, 2>& joinColumn = joinColumns[joinColIndex];
if (a[ia][joinColumn[0]] < b[ib][joinColumn[1]]) {
if (bOptional) {
R res = newOptionalResult<R, K>()(resultSize);
Expand Down Expand Up @@ -585,7 +585,7 @@ class Engine {
ib++;

// do the rows still match?
for (const array<size_t, 2>& jc : joinColumns) {
for (const array<Id, 2>& jc : joinColumns) {
if (ib == b.size() || a[ia][jc[0]] != b[ib][jc[1]]) {
matched = false;
break;
Expand All @@ -595,7 +595,7 @@ class Engine {
ia++;
// Check if the next row in a also matches the initial row in b
matched = true;
for (const array<size_t, 2>& jc : joinColumns) {
for (const array<Id, 2>& jc : joinColumns) {
if (ia == a.size() || a[ia][jc[0]] != b[initIb][jc[1]]) {
matched = false;
break;
Expand Down
2 changes: 1 addition & 1 deletion src/engine/GroupBy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ void GroupBy::computeResult(ResultTable* result) const {
aggregates.reserve(_aliases.size() + _groupByVariables.size());

// parse the group by columns
std::unordered_map<string, Id> subtreeVarCols =
std::unordered_map<string, size_t> subtreeVarCols =
_subtree->getVariableColumnMap();
for (const string& var : _groupByVariables) {
auto it = subtreeVarCols.find(var);
Expand Down
51 changes: 28 additions & 23 deletions src/engine/OptionalJoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ OptionalJoin::OptionalJoin(QueryExecutionContext* qec,
std::shared_ptr<QueryExecutionTree> t1,
bool t1Optional,
std::shared_ptr<QueryExecutionTree> t2,
bool t2Optional, const vector<array<size_t, 2>>& jcs)
bool t2Optional, const vector<array<Id, 2>>& jcs)
: Operation(qec), _joinColumns(jcs), _multiplicitiesComputed(false) {
// Make sure subtrees are ordered so that identical queries can be identified.
AD_CHECK_GT(jcs.size(), 0);
Expand Down Expand Up @@ -57,13 +57,14 @@ string OptionalJoin::asString(size_t indent) const {
}

// Used to generate all up to 125 combinations of left, right and result size.
template <int I, int J, int K>
template <size_t I, size_t J, size_t K>
struct meta_for {
void operator()(int i, int j, int k, shared_ptr<const ResultTable> leftResult,
void operator()(size_t i, size_t j, size_t k,
shared_ptr<const ResultTable> leftResult,
shared_ptr<const ResultTable> rightResult, bool leftOptional,
bool rightOptional,
const std::vector<std::array<size_t, 2>>& joinColumns,
ResultTable* result, int resultSize) const {
const std::vector<std::array<Id, 2>>& joinColumns,
ResultTable* result, size_t resultSize) const {
if (I == i) {
if (J == j) {
if (K == k) {
Expand Down Expand Up @@ -94,13 +95,14 @@ struct meta_for {
}
};

template <int I, int K>
template <size_t I, size_t K>
struct meta_for<I, 6, K> {
void operator()(int i, int j, int k, shared_ptr<const ResultTable> leftResult,
void operator()(size_t i, size_t j, size_t k,
shared_ptr<const ResultTable> leftResult,
shared_ptr<const ResultTable> rightResult, bool leftOptional,
bool rightOptional,
const std::vector<std::array<size_t, 2>>& joinColumns,
ResultTable* result, int resultSize) const {
const std::vector<std::array<Id, 2>>& joinColumns,
ResultTable* result, size_t resultSize) const {
// avoid unused warnings from the compiler (there would be a lot of them)
(void)i;
(void)j;
Expand All @@ -113,13 +115,14 @@ struct meta_for<I, 6, K> {
}
};

template <int I, int J>
template <size_t I, size_t J>
struct meta_for<I, J, 6> {
void operator()(int i, int j, int k, shared_ptr<const ResultTable> leftResult,
void operator()(size_t i, size_t j, size_t k,
shared_ptr<const ResultTable> leftResult,
shared_ptr<const ResultTable> rightResult, bool leftOptional,
bool rightOptional,
const std::vector<std::array<size_t, 2>>& joinColumns,
ResultTable* result, int resultSize) const {
const std::vector<std::array<Id, 2>>& joinColumns,
ResultTable* result, size_t resultSize) const {
// avoid unused warnings from the compiler (there would be a lot of them)
(void)i;
(void)j;
Expand All @@ -133,13 +136,14 @@ struct meta_for<I, J, 6> {
}
};

template <int J>
template <size_t J>
struct meta_for<6, J, 6> {
void operator()(int i, int j, int k, shared_ptr<const ResultTable> leftResult,
void operator()(size_t i, size_t j, size_t k,
shared_ptr<const ResultTable> leftResult,
shared_ptr<const ResultTable> rightResult, bool leftOptional,
bool rightOptional,
const std::vector<std::array<size_t, 2>>& joinColumns,
ResultTable* result, int resultSize) const {
const std::vector<std::array<Id, 2>>& joinColumns,
ResultTable* result, size_t resultSize) const {
// avoid unused warnings from the compiler (there would be a lot of them)
(void)i;
(void)j;
Expand All @@ -155,11 +159,12 @@ struct meta_for<6, J, 6> {

template <>
struct meta_for<6, 6, 6> {
void operator()(int i, int j, int k, shared_ptr<const ResultTable> leftResult,
void operator()(size_t i, size_t j, size_t k,
shared_ptr<const ResultTable> leftResult,
shared_ptr<const ResultTable> rightResult, bool leftOptional,
bool rightOptional,
const std::vector<std::array<size_t, 2>>& joinColumns,
ResultTable* result, int resultSize) const {
const std::vector<std::array<Id, 2>>& joinColumns,
ResultTable* result, size_t resultSize) const {
// avoid unused warnings from the compiler (there would be a lot of them)
(void)i;
(void)j;
Expand Down Expand Up @@ -191,7 +196,7 @@ void OptionalJoin::computeResult(ResultTable* result) const {
leftResult->_resultTypes.end());
for (size_t col = 0; col < rightResult->_nofColumns; col++) {
bool isJoinColumn = false;
for (const std::array<size_t, 2>& a : _joinColumns) {
for (const std::array<Id, 2>& a : _joinColumns) {
if (a[1] == col) {
isJoinColumn = true;
break;
Expand Down Expand Up @@ -226,7 +231,7 @@ std::unordered_map<string, size_t> OptionalJoin::getVariableColumns() const {
bool isJoinColumn = false;
// Reduce the index for every column of _right that is beeing joined on,
// and the index of which is smaller than the index of it.
for (const std::array<size_t, 2>& a : _joinColumns) {
for (const std::array<Id, 2>& a : _joinColumns) {
if (a[1] < it->second) {
columnIndex--;
} else if (a[1] == it->second) {
Expand Down Expand Up @@ -327,7 +332,7 @@ void OptionalJoin::computeSizeEstimateAndMultiplicities() {
} else {
_sizeEstimate = multResult * numDistinctResult;
}
// Don't estimate 0 since then some parent operations
// Don't estimate 0 since then some parent operations
// (in particular joins) using isKnownEmpty() will
// will assume the size to be exactly zero
_sizeEstimate += 1;
Expand Down
4 changes: 2 additions & 2 deletions src/engine/OptionalJoin.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class OptionalJoin : public Operation {
OptionalJoin(QueryExecutionContext* qec,
std::shared_ptr<QueryExecutionTree> t1, bool t1Optional,
std::shared_ptr<QueryExecutionTree> t2, bool t2Optional,
const std::vector<array<size_t, 2>>& joinCols);
const std::vector<array<Id, 2>>& joinCols);

virtual string asString(size_t indent = 0) const;

Expand Down Expand Up @@ -51,7 +51,7 @@ class OptionalJoin : public Operation {
bool _leftOptional;
bool _rightOptional;

std::vector<std::array<size_t, 2>> _joinColumns;
std::vector<std::array<Id, 2>> _joinColumns;

vector<float> _multiplicities;
size_t _sizeEstimate;
Expand Down
6 changes: 3 additions & 3 deletions src/engine/QueryPlanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1298,15 +1298,15 @@ bool QueryPlanner::connected(const QueryPlanner::SubtreePlan& a,
}

// _____________________________________________________________________________
vector<array<size_t, 2>> QueryPlanner::getJoinColumns(
vector<array<Id, 2>> QueryPlanner::getJoinColumns(
const QueryPlanner::SubtreePlan& a,
const QueryPlanner::SubtreePlan& b) const {
vector<array<size_t, 2>> jcs;
vector<array<Id, 2>> jcs;
for (auto it = a._qet.get()->getVariableColumnMap().begin();
it != a._qet.get()->getVariableColumnMap().end(); ++it) {
auto itt = b._qet.get()->getVariableColumnMap().find(it->first);
if (itt != b._qet.get()->getVariableColumnMap().end()) {
jcs.push_back(array<size_t, 2>{{it->second, itt->second}});
jcs.push_back(array<Id, 2>{{it->second, itt->second}});
}
}
return jcs;
Expand Down
4 changes: 2 additions & 2 deletions src/engine/QueryPlanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ class QueryPlanner {
bool connected(const SubtreePlan& a, const SubtreePlan& b,
const TripleGraph& graph) const;

vector<array<size_t, 2>> getJoinColumns(const SubtreePlan& a,
const SubtreePlan& b) const;
vector<array<Id, 2>> getJoinColumns(const SubtreePlan& a,
const SubtreePlan& b) const;

string getPruningKey(const SubtreePlan& plan, size_t orderedOnCol) const;

Expand Down
2 changes: 1 addition & 1 deletion src/engine/TwoColumnJoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ using std::string;
TwoColumnJoin::TwoColumnJoin(QueryExecutionContext* qec,
std::shared_ptr<QueryExecutionTree> t1,
std::shared_ptr<QueryExecutionTree> t2,
const vector<array<size_t, 2>>& jcs)
const vector<array<Id, 2>>& jcs)
: Operation(qec) {
// Make sure subtrees are ordered so that identical queries can be identified.
AD_CHECK_EQ(jcs.size(), 2);
Expand Down
2 changes: 1 addition & 1 deletion src/engine/TwoColumnJoin.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class TwoColumnJoin : public Operation {
TwoColumnJoin(QueryExecutionContext* qec,
std::shared_ptr<QueryExecutionTree> t1,
std::shared_ptr<QueryExecutionTree> t2,
const std::vector<array<size_t, 2>>& joinCols);
const std::vector<array<Id, 2>>& joinCols);

virtual string asString(size_t indent = 0) const;

Expand Down
7 changes: 5 additions & 2 deletions src/index/IndexMetaData.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#pragma once

#include <array>
#include <limits>
#include <utility>
#include <vector>

Expand Down Expand Up @@ -153,7 +154,9 @@ using IndexMetaDataMmapView = IndexMetaData<
MetaDataWrapperDense<ad_utility::MmapVectorView<FullRelationMetaData>>>;

// constants for Magic Numbers to separate different types of MetaData;
const size_t MAGIC_NUMBER_MMAP_META_DATA = static_cast<size_t>(-1);
const size_t MAGIC_NUMBER_SPARSE_META_DATA = static_cast<size_t>(-2);
const uint64_t MAGIC_NUMBER_MMAP_META_DATA =
std::numeric_limits<uint64_t>::max();
const uint64_t MAGIC_NUMBER_SPARSE_META_DATA =
std::numeric_limits<uint64_t>::max() - 1;

#include "./IndexMetaDataImpl.h"
4 changes: 2 additions & 2 deletions src/index/IndexMetaDataImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ template <class MapType>
void IndexMetaData<MapType>::createFromByteBufferSparse(unsigned char* buf) {
size_t nofBytesDone = 0;
// read magic number
size_t magicNumber = *reinterpret_cast<size_t*>(buf);
uint64_t magicNumber = *reinterpret_cast<uint64_t*>(buf);
if (magicNumber == MAGIC_NUMBER_MMAP_META_DATA) {
LOG(INFO)
<< "ERROR: magic number of MetaData indicates that we are trying "
Expand Down Expand Up @@ -94,7 +94,7 @@ void IndexMetaData<MapType>::createFromByteBufferSparse(unsigned char* buf) {
template <class MapType>
void IndexMetaData<MapType>::createFromByteBufferMmap(unsigned char* buf) {
// read magic number
size_t magicNumber = *reinterpret_cast<size_t*>(buf);
uint64_t magicNumber = *reinterpret_cast<uint64_t*>(buf);
if (magicNumber != MAGIC_NUMBER_MMAP_META_DATA) {
LOG(INFO) << "ERROR: No or wrong magic number found in persistent "
"mmap-based meta data. "
Expand Down
4 changes: 2 additions & 2 deletions src/util/MmapVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ class MmapVector {
std::string _filename = "";
AccessPattern _pattern = AccessPattern::None;
static constexpr float ResizeFactor = 1.5;
static constexpr int MagicNumber = 7601577;
static constexpr int Version = 0;
static constexpr uint32_t MagicNumber = 7601577;
static constexpr uint32_t Version = 0;
};

// MmapVector variation that only supports read-access to a previously created
Expand Down

0 comments on commit 67a43ec

Please sign in to comment.