Search in sources :

Example 16 with ColumnSet

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

the class SurveyTest method updateTransaction.

@Test
public void updateTransaction() {
    RecordTransactionBuilder tx = new RecordTransactionBuilder();
    tx.create(survey.getGenerator().get());
    tx.create(survey.getGenerator().get());
    client.update(tx.build());
    QueryModel queryModel = new QueryModel(survey.getFormId());
    queryModel.selectField(survey.getGenderFieldId()).as("gender");
    ColumnSet columnSet = client.queryTable(queryModel);
    assertThat(columnSet.getNumRows(), equalTo(2));
}
Also used : RecordTransactionBuilder(org.activityinfo.model.resource.RecordTransactionBuilder) ColumnSet(org.activityinfo.model.query.ColumnSet) QueryModel(org.activityinfo.model.query.QueryModel) Test(org.junit.Test)

Example 17 with ColumnSet

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

the class DateFunctionQueryTest method invalidArityTest.

@Test
public void invalidArityTest() {
    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("YEARFRAC(TODAY())").as("age");
    ColumnSet columnSet = builder.build(queryModel);
    ColumnView age = columnSet.getColumnView("age");
    assertThat(age.numRows(), equalTo(IntakeForm.ROW_COUNT));
    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)

Example 18 with ColumnSet

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

the class DateFunctionQueryTest method testFloorToday.

@Test
public void testFloorToday() {
    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("FLOOR(YEARFRAC(\"2017-05-05\", DOB))").as("ageFloored");
    queryModel.selectExpr("FLOOR(1.5)").as("floor");
    queryModel.selectExpr("DOB").as("dob");
    ColumnSet columnSet = builder.build(queryModel);
    ColumnView floor = columnSet.getColumnView("floor");
    ColumnView ageFloored = columnSet.getColumnView("ageFloored");
    assertThat(floor.numRows(), equalTo(intakeForm.getRecords().size()));
    assertThat(floor.getDouble(0), equalTo(1.0));
    assertThat(ageFloored.getDouble(0), equalTo(45.0));
    assertThat(ageFloored.getDouble(3), equalTo(29.0));
    System.out.println(ageFloored);
}
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)

Example 19 with ColumnSet

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

the class EnumerationQueryTest method enumIdTests.

@Test
public void enumIdTests() {
    TestingStorageProvider catalog = new TestingStorageProvider();
    ColumnSetBuilder builder = new ColumnSetBuilder(catalog, new NullFormScanCache(), new NullFormSupervisor());
    QueryModel queryModel = new QueryModel(EmptyForm.FORM_ID);
    queryModel.selectField(EmptyForm.ENUM_FIELD_ID).as("emptyEnum");
    queryModel.selectField(EmptyForm.POP_ENUM_FIELD_ID).as("populatedEnum");
    ColumnSet columnSet = builder.build(queryModel);
    ColumnView emptyEnum = columnSet.getColumnView("emptyEnum");
    ColumnView populatedEnum = columnSet.getColumnView("populatedEnum");
    // // Standard Enum Id Checks
    // Null check on empty set first
    assertThat(emptyEnum.get(0), equalTo(null));
    assertThat(((EnumColumnView) emptyEnum).getId(0), equalTo(null));
    // Value check on populated set
    assertThat(populatedEnum.get(0).toString(), equalTo("One"));
    assertThat(((EnumColumnView) populatedEnum).getId(0), equalTo(EmptyForm.ENUM_ONE_ID.asString()));
    // // Selected Row Enum Id Checks
    ColumnView emptySelectedRow = emptyEnum.select(new int[] { 0 });
    ColumnView populatedSelectedRow = populatedEnum.select(new int[] { 0 });
    // Null check on empty set first
    assertThat(emptySelectedRow.get(0), equalTo(null));
    assertThat(((EnumColumnView) emptySelectedRow).getId(0), equalTo(null));
    // Value check on populated set
    assertThat(populatedSelectedRow.get(0).toString(), equalTo("One"));
    assertThat(((EnumColumnView) populatedSelectedRow).getId(0), equalTo(EmptyForm.ENUM_ONE_ID.asString()));
}
Also used : ColumnSetBuilder(org.activityinfo.store.query.server.ColumnSetBuilder) NullFormScanCache(org.activityinfo.store.query.shared.NullFormScanCache) ColumnView(org.activityinfo.model.query.ColumnView) EnumColumnView(org.activityinfo.model.query.EnumColumnView) ColumnSet(org.activityinfo.model.query.ColumnSet) NullFormSupervisor(org.activityinfo.store.query.shared.NullFormSupervisor) QueryModel(org.activityinfo.model.query.QueryModel) Test(org.junit.Test)

Example 20 with ColumnSet

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

the class SubFormDeletionTest method parentQueries.

@Test
public void parentQueries() {
    QueryModel queryModel = new QueryModel(ReferralSubForm.FORM_ID);
    queryModel.selectResourceId().as("id");
    queryModel.selectExpr("URGENCY").as("Urgency");
    ColumnSet columnSet = query(queryModel);
}
Also used : ColumnSet(org.activityinfo.model.query.ColumnSet) QueryModel(org.activityinfo.model.query.QueryModel) Test(org.junit.Test)

Aggregations

ColumnSet (org.activityinfo.model.query.ColumnSet)50 QueryModel (org.activityinfo.model.query.QueryModel)42 Test (org.junit.Test)28 ColumnView (org.activityinfo.model.query.ColumnView)24 ColumnSetBuilder (org.activityinfo.store.query.server.ColumnSetBuilder)14 FormTree (org.activityinfo.model.formTree.FormTree)12 NullFormSupervisor (org.activityinfo.store.query.shared.NullFormSupervisor)12 ResourceId (org.activityinfo.model.resource.ResourceId)10 FormClass (org.activityinfo.model.form.FormClass)7 NullFormScanCache (org.activityinfo.store.query.shared.NullFormScanCache)7 Nullable (javax.annotation.Nullable)6 Charsets (com.google.common.base.Charsets)5 Operation (io.swagger.v3.oas.annotations.Operation)5 FormTreeBuilder (org.activityinfo.model.formTree.FormTreeBuilder)5 ColumnModel (org.activityinfo.model.query.ColumnModel)5 RowBasedJsonWriter (org.activityinfo.store.query.output.RowBasedJsonWriter)5 PrintWriter (java.io.PrintWriter)4 DimensionCategory (org.activityinfo.legacy.shared.reports.content.DimensionCategory)4 FormField (org.activityinfo.model.form.FormField)4 RecordRef (org.activityinfo.model.type.RecordRef)4