diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-09-27 16:15:44 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-09-27 16:15:44 +0200 |
commit | 5830d7e0d1d35494823f5fa61a4871b8d9df1c9d (patch) | |
tree | 1383d9b6ad926a97ee8376175c6bee01182dc096 /common/datastorequery.cpp | |
parent | 529db49c496f4f668cec3f7c59d2d0ec78c50c9a (diff) | |
download | sink-5830d7e0d1d35494823f5fa61a4871b8d9df1c9d.tar.gz sink-5830d7e0d1d35494823f5fa61a4871b8d9df1c9d.zip |
Use the Query::filter api.
Diffstat (limited to 'common/datastorequery.cpp')
-rw-r--r-- | common/datastorequery.cpp | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/common/datastorequery.cpp b/common/datastorequery.cpp index 0fc9234..3c4ae00 100644 --- a/common/datastorequery.cpp +++ b/common/datastorequery.cpp | |||
@@ -146,6 +146,7 @@ public: | |||
146 | typedef QSharedPointer<Reduce> Ptr; | 146 | typedef QSharedPointer<Reduce> Ptr; |
147 | 147 | ||
148 | QHash<QByteArray, QVariant> mAggregateValues; | 148 | QHash<QByteArray, QVariant> mAggregateValues; |
149 | QSet<QByteArray> mReducedValues; | ||
149 | QByteArray mReductionProperty; | 150 | QByteArray mReductionProperty; |
150 | QByteArray mSelectionProperty; | 151 | QByteArray mSelectionProperty; |
151 | Query::Reduce::Selector::Comparator mSelectionComparator; | 152 | Query::Reduce::Selector::Comparator mSelectionComparator; |
@@ -184,7 +185,9 @@ public: | |||
184 | bool foundValue = false; | 185 | bool foundValue = false; |
185 | while(!foundValue && mSource->next([this, callback, &foundValue](Sink::Operation operation, const QByteArray &uid, const Sink::EntityBuffer &entityBuffer) { | 186 | while(!foundValue && mSource->next([this, callback, &foundValue](Sink::Operation operation, const QByteArray &uid, const Sink::EntityBuffer &entityBuffer) { |
186 | auto reductionValue = getProperty(entityBuffer.entity(), mReductionProperty); | 187 | auto reductionValue = getProperty(entityBuffer.entity(), mReductionProperty); |
187 | if (!mAggregateValues.contains(getByteArray(reductionValue))) { | 188 | if (!mReducedValues.contains(getByteArray(reductionValue))) { |
189 | //Only reduce every value once. | ||
190 | mReducedValues.insert(getByteArray(reductionValue)); | ||
188 | QVariant selectionResultValue; | 191 | QVariant selectionResultValue; |
189 | QByteArray selectionResult; | 192 | QByteArray selectionResult; |
190 | auto results = indexLookup(mReductionProperty, reductionValue); | 193 | auto results = indexLookup(mReductionProperty, reductionValue); |
@@ -373,17 +376,16 @@ QVector<QByteArray> DataStoreQuery::indexLookup(const QByteArray &property, cons | |||
373 | void DataStoreQuery::setupQuery() | 376 | void DataStoreQuery::setupQuery() |
374 | { | 377 | { |
375 | FilterBase::Ptr baseSet; | 378 | FilterBase::Ptr baseSet; |
376 | QSet<QByteArray> remainingFilters; | 379 | QSet<QByteArray> remainingFilters = mQuery.getBaseFilters().keys().toSet(); |
377 | QByteArray appliedSorting; | 380 | QByteArray appliedSorting; |
378 | if (!mQuery.ids.isEmpty()) { | 381 | if (!mQuery.ids.isEmpty()) { |
379 | mSource = Source::Ptr::create(mQuery.ids.toVector(), this); | 382 | mSource = Source::Ptr::create(mQuery.ids.toVector(), this); |
380 | baseSet = mSource; | 383 | baseSet = mSource; |
381 | remainingFilters = mQuery.propertyFilter.keys().toSet(); | ||
382 | } else { | 384 | } else { |
383 | QSet<QByteArray> appliedFilters; | 385 | QSet<QByteArray> appliedFilters; |
384 | 386 | ||
385 | auto resultSet = mTypeIndex.query(mQuery, appliedFilters, appliedSorting, mTransaction); | 387 | auto resultSet = mTypeIndex.query(mQuery, appliedFilters, appliedSorting, mTransaction); |
386 | remainingFilters = mQuery.propertyFilter.keys().toSet() - appliedFilters; | 388 | remainingFilters = remainingFilters - appliedFilters; |
387 | 389 | ||
388 | // We do a full scan if there were no indexes available to create the initial set. | 390 | // We do a full scan if there were no indexes available to create the initial set. |
389 | if (appliedFilters.isEmpty()) { | 391 | if (appliedFilters.isEmpty()) { |
@@ -394,12 +396,12 @@ void DataStoreQuery::setupQuery() | |||
394 | } | 396 | } |
395 | baseSet = mSource; | 397 | baseSet = mSource; |
396 | } | 398 | } |
397 | if (!mQuery.propertyFilter.isEmpty()) { | 399 | if (!mQuery.getBaseFilters().isEmpty()) { |
398 | auto filter = Filter::Ptr::create(baseSet, this); | 400 | auto filter = Filter::Ptr::create(baseSet, this); |
399 | filter->propertyFilter = mQuery.propertyFilter; | 401 | //For incremental queries the remaining filters are not sufficient |
400 | /* for (const auto &f : remainingFilters) { */ | 402 | for (const auto &f : mQuery.getBaseFilters().keys()) { |
401 | /* filter->propertyFilter.insert(f, mQuery.propertyFilter.value(f)); */ | 403 | filter->propertyFilter.insert(f, mQuery.getFilter(f)); |
402 | /* } */ | 404 | } |
403 | baseSet = filter; | 405 | baseSet = filter; |
404 | } | 406 | } |
405 | /* if (appliedSorting.isEmpty() && !mQuery.sortProperty.isEmpty()) { */ | 407 | /* if (appliedSorting.isEmpty() && !mQuery.sortProperty.isEmpty()) { */ |
@@ -407,15 +409,16 @@ void DataStoreQuery::setupQuery() | |||
407 | /* baseSet = Sort::Ptr::create(baseSet, mQuery.sortProperty); */ | 409 | /* baseSet = Sort::Ptr::create(baseSet, mQuery.sortProperty); */ |
408 | /* } */ | 410 | /* } */ |
409 | 411 | ||
412 | //Setup the rest of the filter stages on top of the base set | ||
410 | for (const auto &stage : mQuery.filterStages) { | 413 | for (const auto &stage : mQuery.filterStages) { |
411 | if (auto filter = stage.dynamicCast<Query::Filter>()) { | 414 | if (auto filter = stage.dynamicCast<Query::Filter>()) { |
412 | 415 | auto f = Filter::Ptr::create(baseSet, this); | |
416 | f->propertyFilter = filter->propertyFilter; | ||
417 | baseSet = f; | ||
413 | } else if (auto filter = stage.dynamicCast<Query::Reduce>()) { | 418 | } else if (auto filter = stage.dynamicCast<Query::Reduce>()) { |
414 | auto reduce = Reduce::Ptr::create(filter->property, filter->selector.property, filter->selector.comparator, baseSet, this); | 419 | baseSet = Reduce::Ptr::create(filter->property, filter->selector.property, filter->selector.comparator, baseSet, this); |
415 | baseSet = reduce; | ||
416 | } else if (auto filter = stage.dynamicCast<Query::Bloom>()) { | 420 | } else if (auto filter = stage.dynamicCast<Query::Bloom>()) { |
417 | auto reduce = Bloom::Ptr::create(filter->property, baseSet, this); | 421 | baseSet = Bloom::Ptr::create(filter->property, baseSet, this); |
418 | baseSet = reduce; | ||
419 | } | 422 | } |
420 | } | 423 | } |
421 | 424 | ||