Skip to content

Commit

Permalink
HPCC-32469 Add support for non-keyed index filtering
Browse files Browse the repository at this point in the history
Rowservice index reads with filters on non-keyed fields failed.

Signed-off-by: Jake Smith <jake.smith@lexisnexisrisk.com>
  • Loading branch information
jakesmith committed Sep 20, 2024
1 parent 91fb11c commit 6c2bec2
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
12 changes: 7 additions & 5 deletions fs/dafsserver/dafsserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1176,7 +1176,7 @@ class CRemoteDiskBaseActivity : public CSimpleInterfaceOf<IRemoteReadActivity>,
bool opened = false;
bool eofSeen = false;
const RtlRecord *record = nullptr;
RowFilter filters;
RowFilter filter;
RtlDynRow *filterRow = nullptr;
// virtual field values
StringAttr logicalFilename;
Expand All @@ -1186,8 +1186,8 @@ class CRemoteDiskBaseActivity : public CSimpleInterfaceOf<IRemoteReadActivity>,
{
if (filterRow)
{
filterRow->setRow(buffer, filters.getNumFieldsRequired());
return filters.matches(*filterRow);
filterRow->setRow(buffer, filter.getNumFieldsRequired());
return filter.matches(*filterRow);
}
else
return true;
Expand Down Expand Up @@ -1217,7 +1217,7 @@ class CRemoteDiskBaseActivity : public CSimpleInterfaceOf<IRemoteReadActivity>,
filterRow = new RtlDynRow(*record);
Owned<IPropertyTreeIterator> filterIter = config.getElements("keyFilter");
ForEach(*filterIter)
filters.addFilter(*record, filterIter->query().queryProp(nullptr));
filter.addFilter(*record, filterIter->query().queryProp(nullptr));
}
}
// IRemoteReadActivity impl.
Expand Down Expand Up @@ -2228,6 +2228,7 @@ class CRemoteIndexBaseActivity : public CRemoteDiskBaseActivity
unsigned fileCrc = 0;
Owned<IKeyIndex> keyIndex;
Owned<IKeyManager> keyManager;
RowFilter keyFilter;

void checkOpen()
{
Expand All @@ -2243,7 +2244,7 @@ class CRemoteIndexBaseActivity : public CRemoteDiskBaseActivity

keyIndex.setown(createKeyIndex(fileName, crc, isTlk, 0));
keyManager.setown(createLocalKeyManager(*record, keyIndex, nullptr, true, false));
filters.createSegmentMonitors(keyManager);
keyFilter.createSegmentMonitors(keyManager);
keyManager->finishSegmentMonitors();
keyManager->reset();

Expand All @@ -2260,6 +2261,7 @@ class CRemoteIndexBaseActivity : public CRemoteDiskBaseActivity
CRemoteIndexBaseActivity(IPropertyTree &config, IFileDescriptor *fileDesc) : PARENT(config, fileDesc)
{
setupInputMeta(config, getTypeInfoOutputMetaData(config, "input", false));
filter.splitIntoKeyFilter(*record, keyFilter);

isTlk = config.getPropBool("isTlk");
fileCrc = config.getPropInt("crc");
Expand Down
28 changes: 28 additions & 0 deletions rtl/eclrtl/rtlnewkey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2245,6 +2245,27 @@ void RowFilter::extractMemKeyFilter(const RtlRecord & record, const UnsignedArra
}
}

void RowFilter::splitIntoKeyFilter(const RtlRecord & record, RowFilter &keyFilter)
{
if (0 == filters.ordinality())
return;

unsigned numKeyedFields = record.getNumKeyedFields();
ForEachItemInRev(i, filters)
{
const IFieldFilter & cur = filters.item(i);
if (cur.queryFieldIndex() < numKeyedFields)
{
keyFilter.addFilter(OLINK(cur));
filters.remove(i);
}
}
keyFilter.sortByFieldOrder(); // NB: need to be ordered ahead of keyFilter.createSegmentMonitors being used
//There is either a payload filter, in which case numFieldsRequired will not change, or now no filter
if (filters.ordinality() == 0)
numFieldsRequired = 0;
}

const IFieldFilter *RowFilter::findFilter(unsigned fieldNum) const
{
ForEachItemIn(i, filters)
Expand Down Expand Up @@ -2298,6 +2319,13 @@ void RowFilter::remapField(unsigned filterIdx, unsigned newFieldNum)
filters.replace(*filters.item(filterIdx).remap(newFieldNum), filterIdx);
}

void RowFilter::sortByFieldOrder()
{
if (0 == filters.ordinality())
return;
filters.sort(compareFieldFilters);
}

//---------------------------------------------------------------------------------------------------------------------

bool RowCursor::setRowForward(const byte * row)
Expand Down
2 changes: 2 additions & 0 deletions rtl/eclrtl/rtlnewkey.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class ECLRTL_API RowFilter
void createSegmentMonitors(IIndexReadContext *irc);
void extractKeyFilter(const RtlRecord & record, IConstArrayOf<IFieldFilter> & keyFilters) const;
void extractMemKeyFilter(const RtlRecord & record, const UnsignedArray &sortOrder, IConstArrayOf<IFieldFilter> & keyFilters) const;
void splitIntoKeyFilter(const RtlRecord & record, RowFilter &keyFilter);
unsigned numFilterFields() const { return filters.ordinality(); }
const IFieldFilter & queryFilter(unsigned i) const { return filters.item(i); }
const IFieldFilter *findFilter(unsigned fieldIdx) const;
Expand All @@ -75,6 +76,7 @@ class ECLRTL_API RowFilter
void remove(unsigned idx);
RowFilter & clear();
void appendFilters(const IConstArrayOf<IFieldFilter> &_filters);
void sortByFieldOrder();
protected:
IConstArrayOf<IFieldFilter> filters;
unsigned numFieldsRequired = 0;
Expand Down

0 comments on commit 6c2bec2

Please sign in to comment.