Search in sources :

Example 1 with TableFilter

use of org.activityinfo.store.query.shared.TableFilter in project activityinfo by bedatadriven.

the class ForeignKeyTest method filtering.

@Test
public void filtering() {
    // Build the unfiltered foreign key map
    // That maps row indexes to foreign keys
    ResourceId formId = ResourceId.valueOf("a00001");
    ForeignKeyBuilder builder = new ForeignKeyBuilder(formId, new PendingSlot<ForeignKey>());
    builder.onNext(new ReferenceValue(new RecordRef(formId, ResourceId.valueOf("s0272548382"))));
    builder.onNext(new ReferenceValue(new RecordRef(formId, ResourceId.valueOf("s0272548382"))));
    builder.onNext(new ReferenceValue(new RecordRef(formId, ResourceId.valueOf("s0362622291"))));
    builder.onNext(new ReferenceValue(new RecordRef(formId, ResourceId.valueOf("s0362622291"))));
    builder.onNext(new ReferenceValue(new RecordRef(formId, ResourceId.valueOf("s0890848243"))));
    builder.onNext(new ReferenceValue(new RecordRef(formId, ResourceId.valueOf("s0890848243"))));
    ForeignKey fkMap = builder.build();
    // Now define a filter that includes only the 4th and 5th rows
    BitSet bitSet = new BitSet();
    bitSet.set(4);
    bitSet.set(5);
    TableFilter filter = new TableFilter(bitSet);
    // Apply the filter to the ForeignKey map and verify the results
    ForeignKey filteredKey = filter.apply(fkMap);
    assertThat(filteredKey.getKey(0), equalTo("s0890848243"));
    assertThat(filteredKey.getKey(1), equalTo("s0890848243"));
}
Also used : ForeignKeyBuilder(org.activityinfo.store.query.server.join.ForeignKeyBuilder) ResourceId(org.activityinfo.model.resource.ResourceId) TableFilter(org.activityinfo.store.query.shared.TableFilter) ReferenceValue(org.activityinfo.model.type.ReferenceValue) RecordRef(org.activityinfo.model.type.RecordRef) BitSet(java.util.BitSet) ForeignKey(org.activityinfo.store.query.shared.columns.ForeignKey) Test(org.junit.Test)

Example 2 with TableFilter

use of org.activityinfo.store.query.shared.TableFilter in project activityinfo by bedatadriven.

the class ParentMask method get.

@Override
public TableFilter get() {
    if (result == null) {
        BitSet bitSet = new BitSet();
        PrimaryKeyMap parentKeyMap = parentKeySlot.get();
        ColumnView parentView = parentIdSlot.get();
        for (int i = 0; i < parentView.numRows(); i++) {
            String parentId = parentView.getString(i);
            bitSet.set(i, parentKeyMap.contains(parentId));
        }
        result = new TableFilter(bitSet);
    }
    return result;
}
Also used : TableFilter(org.activityinfo.store.query.shared.TableFilter) BitSet(java.util.BitSet) ColumnView(org.activityinfo.model.query.ColumnView)

Aggregations

BitSet (java.util.BitSet)2 TableFilter (org.activityinfo.store.query.shared.TableFilter)2 ColumnView (org.activityinfo.model.query.ColumnView)1 ResourceId (org.activityinfo.model.resource.ResourceId)1 RecordRef (org.activityinfo.model.type.RecordRef)1 ReferenceValue (org.activityinfo.model.type.ReferenceValue)1 ForeignKeyBuilder (org.activityinfo.store.query.server.join.ForeignKeyBuilder)1 ForeignKey (org.activityinfo.store.query.shared.columns.ForeignKey)1 Test (org.junit.Test)1