Search in sources :

Example 31 with ColumnView

use of org.activityinfo.model.query.ColumnView in project activityinfo by bedatadriven.

the class RealValuedFunction method binaryFunctionColumnCall.

private ColumnView binaryFunctionColumnCall(int numRows, List<ColumnView> arguments) {
    ColumnView x = arguments.get(0);
    ColumnView y = arguments.get(1);
    double[] result = new double[x.numRows()];
    for (int i = 0; i < result.length; i++) {
        double xd = x.getDouble(i);
        double yd = y.getDouble(i);
        if (Double.isNaN(xd) && Double.isNaN(yd)) {
            result[i] = Double.NaN;
        } else {
            if (Double.isNaN(xd)) {
                xd = 0;
            }
            if (Double.isNaN(yd)) {
                yd = 0;
            }
            result[i] = apply(xd, yd);
        }
    }
    return new DoubleArrayColumnView(result);
}
Also used : ColumnView(org.activityinfo.model.query.ColumnView) DoubleArrayColumnView(org.activityinfo.model.query.DoubleArrayColumnView) DoubleArrayColumnView(org.activityinfo.model.query.DoubleArrayColumnView)

Example 32 with ColumnView

use of org.activityinfo.model.query.ColumnView in project activityinfo by bedatadriven.

the class SearchFunction method columnApply.

@Override
public ColumnView columnApply(int numRows, List<ColumnView> arguments) {
    ColumnView substring = arguments.get(0);
    ColumnView string = arguments.get(1);
    ColumnView startIndex;
    if (arguments.size() == 3) {
        startIndex = arguments.get(3);
    } else {
        startIndex = new ConstantColumnView(numRows, 1d);
    }
    double[] result = new double[numRows];
    for (int i = 0; i < numRows; i++) {
        result[i] = apply(substring.getString(i), string.getString(i), startIndex.getDouble(i));
    }
    return new DoubleArrayColumnView(result);
}
Also used : ColumnView(org.activityinfo.model.query.ColumnView) DoubleArrayColumnView(org.activityinfo.model.query.DoubleArrayColumnView) ConstantColumnView(org.activityinfo.model.query.ConstantColumnView) DoubleArrayColumnView(org.activityinfo.model.query.DoubleArrayColumnView) ConstantColumnView(org.activityinfo.model.query.ConstantColumnView)

Example 33 with ColumnView

use of org.activityinfo.model.query.ColumnView in project activityinfo by bedatadriven.

the class ImportWithMultiClassRangeTest method school.

private Set<ResourceId> school(String name) {
    // Find id of the school with this name
    ResourceId id = null;
    ColumnView nameColumn = resultSet.getColumnView("name");
    ColumnView idColumn = resultSet.getColumnView("id");
    for (int i = 0; i < resultSet.getNumRows(); i++) {
        if (name.equals(nameColumn.getString(i))) {
            id = ResourceId.valueOf(idColumn.getString(i));
            break;
        }
    }
    if (id == null) {
        throw new AssertionError("No school named '" + name + "'");
    }
    Promise<FormInstance> record = locator.getFormInstance(SCHOOL_FORM_CLASS, id);
    ReferenceValue value = (ReferenceValue) record.get().get(CuidAdapter.field(SCHOOL_FORM_CLASS, CuidAdapter.ADMIN_FIELD));
    Set<ResourceId> recordIds = new HashSet<>();
    for (RecordRef recordRef : value.getReferences()) {
        recordIds.add(recordRef.getRecordId());
    }
    return recordIds;
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) ReferenceValue(org.activityinfo.model.type.ReferenceValue) ColumnView(org.activityinfo.model.query.ColumnView) RecordRef(org.activityinfo.model.type.RecordRef) FormInstance(org.activityinfo.model.form.FormInstance) HashSet(java.util.HashSet)

Example 34 with ColumnView

use of org.activityinfo.model.query.ColumnView in project activityinfo by bedatadriven.

the class ApiTestHarness method createDatabase.

public TestDatabase createDatabase() {
    String name = aliasTable.createAlias("db");
    ActivityInfoClient client = client();
    ResourceId databaseId = client.createDatabase(name);
    int id = CuidAdapter.getLegacyIdFromCuid(databaseId);
    // Query list of partners
    QueryModel queryModel = new QueryModel(CuidAdapter.partnerFormId(id));
    queryModel.selectResourceId().as("id");
    ColumnSet columnSet = client.queryTable(queryModel);
    ColumnView partnerIdView = columnSet.getColumnView("id");
    ResourceId firstPartnerId = ResourceId.valueOf(partnerIdView.getString(0));
    return new TestDatabase(databaseId, name, firstPartnerId);
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) ActivityInfoClient(org.activityinfo.client.ActivityInfoClient) ColumnView(org.activityinfo.model.query.ColumnView) ColumnSet(org.activityinfo.model.query.ColumnSet) QueryModel(org.activityinfo.model.query.QueryModel)

Example 35 with ColumnView

use of org.activityinfo.model.query.ColumnView in project activityinfo by bedatadriven.

the class DateFunctionQueryTest method testToday.

@Test
public void testToday() {
    TestingStorageProvider catalog = new TestingStorageProvider();
    IntakeForm intakeForm = catalog.getIntakeForm();
    ColumnSetBuilder builder = new ColumnSetBuilder(catalog, new NullFormScanCache(), new NullFormSupervisor());
    QueryModel queryModel = new QueryModel(intakeForm.getFormId());
    queryModel.selectExpr("TODAY()").as("today");
    queryModel.selectExpr("YEARFRAC(TODAY(), DOB)").as("age");
    queryModel.selectExpr("DOB").as("dob");
    ColumnSet columnSet = builder.build(queryModel);
    ColumnView today = columnSet.getColumnView("today");
    ColumnView age = columnSet.getColumnView("age");
    ColumnView dob = columnSet.getColumnView("dob");
    for (int i = 0; i < columnSet.getNumRows(); i++) {
        if (dob.getString(i) != null) {
            double ageInYears = age.getDouble(i);
            System.out.println(dob.get(i) + " " + ageInYears);
            if (Double.isNaN(ageInYears)) {
                throw new AssertionError();
            }
        }
    }
    System.out.println(age);
}
Also used : ColumnSetBuilder(org.activityinfo.store.query.server.ColumnSetBuilder) NullFormScanCache(org.activityinfo.store.query.shared.NullFormScanCache) ColumnView(org.activityinfo.model.query.ColumnView) ColumnSet(org.activityinfo.model.query.ColumnSet) NullFormSupervisor(org.activityinfo.store.query.shared.NullFormSupervisor) QueryModel(org.activityinfo.model.query.QueryModel) Test(org.junit.Test)

Aggregations

ColumnView (org.activityinfo.model.query.ColumnView)67 ColumnSet (org.activityinfo.model.query.ColumnSet)22 Test (org.junit.Test)22 QueryModel (org.activityinfo.model.query.QueryModel)21 ColumnSetBuilder (org.activityinfo.store.query.server.ColumnSetBuilder)8 ResourceId (org.activityinfo.model.resource.ResourceId)7 NullFormSupervisor (org.activityinfo.store.query.shared.NullFormSupervisor)7 DoubleArrayColumnView (org.activityinfo.model.query.DoubleArrayColumnView)6 NullFormScanCache (org.activityinfo.store.query.shared.NullFormScanCache)6 DimensionCategory (org.activityinfo.legacy.shared.reports.content.DimensionCategory)5 FormClass (org.activityinfo.model.form.FormClass)5 FormTree (org.activityinfo.model.formTree.FormTree)5 FormulaNode (org.activityinfo.model.formula.FormulaNode)4 Nullable (javax.annotation.Nullable)3 FormulaSyntaxException (org.activityinfo.model.formula.diagnostic.FormulaSyntaxException)3 ColumnModel (org.activityinfo.model.query.ColumnModel)3 RecordRef (org.activityinfo.model.type.RecordRef)3 PrintWriter (java.io.PrintWriter)2 HashSet (java.util.HashSet)2 EntityCategory (org.activityinfo.legacy.shared.reports.content.EntityCategory)2