use of org.activityinfo.model.query.ColumnView in project activityinfo by bedatadriven.
the class CompactingDoubleColumnBuilderTest method intOverflow.
@Test
public void intOverflow() {
// construct column which has absolute values greater than an int32, but within a range of int32 of each other
CompactingDoubleColumnBuilder builder = new CompactingDoubleColumnBuilder(new PendingSlot<ColumnView>(), DUMMY);
builder.onNext(10316050152d);
builder.onNext(10316050151d);
ColumnView result = builder.build();
ColumnView doubleResult = builder.buildDouble();
assertEquivalent(result, doubleResult);
}
use of org.activityinfo.model.query.ColumnView in project activityinfo by bedatadriven.
the class CompactingDoubleColumnBuilderTest method comprehensiveByte16.
@Test
public void comprehensiveByte16() {
CompactingDoubleColumnBuilder builder = new CompactingDoubleColumnBuilder(new PendingSlot<ColumnView>(), DUMMY);
builder.onNext(Double.NaN);
for (int i = 0; i < IntColumnView16.MAX_RANGE; i++) {
builder.onNext(i);
}
ColumnView result = builder.build();
assertThat(result, instanceOf(IntColumnView16.class));
assertEquivalent(result, builder.buildDouble());
}
use of org.activityinfo.model.query.ColumnView in project activityinfo by bedatadriven.
the class CompactingEnumColumnBuilderTest method buildCompact.
@Test
public void buildCompact() {
EnumItem a = new EnumItem(ResourceId.valueOf("a"), "Enumerated Item A");
EnumItem b = new EnumItem(ResourceId.valueOf("b"), "Enumerated Item B");
EnumItem c = new EnumItem(ResourceId.valueOf("c"), "Enumerated Item C");
EnumType enumType = new EnumType(Cardinality.SINGLE, a, b, c);
CompactingEnumColumnBuilder builder = new CompactingEnumColumnBuilder(new PendingSlot<ColumnView>(), enumType);
for (int i = 0; i < 13; i++) {
builder.onNext(new EnumValue(a.getId()));
builder.onNext(new EnumValue(b.getId()));
builder.onNext(new EnumValue(c.getId()));
builder.onNext(null);
}
ColumnView column8 = builder.build8();
ColumnView column32 = builder.build32();
for (int i = 0; i < column32.numRows(); i++) {
if (!Objects.equals(column8.getString(i), column32.getString(i))) {
throw new AssertionError("Vectors not equal at index " + i);
}
}
assertThat(builder.build(), instanceOf(DiscreteStringColumnView8.class));
}
use of org.activityinfo.model.query.ColumnView 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;
}
use of org.activityinfo.model.query.ColumnView in project activityinfo by bedatadriven.
the class SerialNumberTest method testWithPrefix.
@Test
public void testWithPrefix() {
TestDatabase database = harness.createDatabase();
ActivityInfoClient client = harness.client();
FormClass formClass = new FormClass(harness.newFormId());
formClass.setLabel("Test Prefix");
formClass.setDatabaseId(database.getId());
FormField partnerField = CuidAdapter.partnerField(formClass);
formClass.addElement(partnerField);
FormField provinceField = formClass.addField(harness.newFieldId()).setType(TextType.SIMPLE).setLabel("Province Code").setCode("PROVINCE").setRequired(true);
FormField fileNumberField = formClass.addField(harness.newFieldId()).setCode("SN").setType(new SerialNumberType("PROVINCE", 5)).setLabel("Record Number");
client.createForm(formClass);
FormInstance kunduz1 = new FormInstance(harness.newRecordId(), formClass.getId());
kunduz1.set(provinceField.getId(), "KUNDUZ");
kunduz1.set(partnerField.getId(), database.getDefaultPartner());
client.createRecord(kunduz1);
FormInstance kunduz2 = new FormInstance(harness.newRecordId(), formClass.getId());
kunduz2.set(provinceField.getId(), "KUNDUZ");
kunduz2.set(partnerField.getId(), database.getDefaultPartner());
client.createRecord(kunduz2);
FormInstance takhar = new FormInstance(harness.newRecordId(), formClass.getId());
takhar.set(provinceField.getId(), "TAKHAR");
takhar.set(partnerField.getId(), database.getDefaultPartner());
client.createRecord(takhar);
// Verify that the serial numbers have been assigned
kunduz1 = client.getTypedRecord(formClass, kunduz1.getId());
kunduz2 = client.getTypedRecord(formClass, kunduz2.getId());
takhar = client.getTypedRecord(formClass, takhar.getId());
assertThat(kunduz1.get(fileNumberField.getId()), equalTo((FieldValue) new SerialNumber("KUNDUZ", 1)));
assertThat(kunduz2.get(fileNumberField.getId()), equalTo((FieldValue) new SerialNumber("KUNDUZ", 2)));
assertThat(takhar.get(fileNumberField.getId()), equalTo((FieldValue) new SerialNumber("TAKHAR", 1)));
// Now verify that we can query a table with serial numbers
QueryModel queryModel = new QueryModel(formClass.getId());
queryModel.selectResourceId().as("id");
queryModel.selectField("SN");
ColumnSet columnSet = client.queryTable(queryModel);
ColumnView sn = columnSet.getColumnView("SN");
}
Aggregations