Search in sources :

Example 41 with QueryModel

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

the class UnaryFunctionQueryTest method plusFunctionTest.

@Test
public void plusFunctionTest() {
    QueryModel queryModel = new QueryModel(intakeForm.getFormId());
    queryModel.selectExpr("+1").as("posOne");
    queryModel.selectExpr("+1.0").as("posOneDouble");
    queryModel.selectExpr("+1*2").as("posOneByTwo");
    queryModel.selectExpr("+1.0*2.0").as("posOneByTwoDouble");
    queryModel.selectExpr("2*(+1)").as("twoByPosOne");
    queryModel.selectExpr("2.0*(+1.0)").as("twoByPosOneDouble");
    ColumnSet columnSet = builder.build(queryModel);
    ColumnView posOne = columnSet.getColumnView("posOne");
    ColumnView posOneDouble = columnSet.getColumnView("posOneDouble");
    ColumnView posOneByTwo = columnSet.getColumnView("posOneByTwo");
    ColumnView posOneByTwoDouble = columnSet.getColumnView("posOneByTwoDouble");
    ColumnView twoByPosOne = columnSet.getColumnView("twoByPosOne");
    ColumnView twoByPosOneDouble = columnSet.getColumnView("twoByPosOneDouble");
    assertThat(posOne.numRows(), equalTo(IntakeForm.ROW_COUNT));
    assertThat(posOne.getDouble(0), equalTo(1.0));
    assertThat(posOneDouble.getDouble(0), equalTo(1.0));
    assertThat(posOneByTwo.getDouble(0), equalTo(2.0));
    assertThat(posOneByTwoDouble.getDouble(0), equalTo(2.0));
    assertThat(twoByPosOne.getDouble(0), equalTo(2.0));
    assertThat(twoByPosOneDouble.getDouble(0), equalTo(2.0));
}
Also used : ColumnView(org.activityinfo.model.query.ColumnView) ColumnSet(org.activityinfo.model.query.ColumnSet) QueryModel(org.activityinfo.model.query.QueryModel) Test(org.junit.Test)

Example 42 with QueryModel

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

the class UnaryFunctionQueryTest method minusFunctionTest.

@Test
public void minusFunctionTest() {
    QueryModel queryModel = new QueryModel(intakeForm.getFormId());
    queryModel.selectExpr("-1").as("negOne");
    queryModel.selectExpr("-1.0").as("negOneDouble");
    queryModel.selectExpr("-1*2").as("negOneByTwo");
    queryModel.selectExpr("-1.0*2.0").as("negOneByTwoDouble");
    queryModel.selectExpr("2*(-1)").as("twoByNegOne");
    queryModel.selectExpr("2.0*(-1.0)").as("twoByNegOneDouble");
    ColumnSet columnSet = builder.build(queryModel);
    ColumnView negOne = columnSet.getColumnView("negOne");
    ColumnView negOneDouble = columnSet.getColumnView("negOneDouble");
    ColumnView negOneByTwo = columnSet.getColumnView("negOneByTwo");
    ColumnView negOneByTwoDouble = columnSet.getColumnView("negOneByTwoDouble");
    ColumnView twoByNegOne = columnSet.getColumnView("twoByNegOne");
    ColumnView twoByNegOneDouble = columnSet.getColumnView("twoByNegOneDouble");
    assertThat(negOne.numRows(), equalTo(IntakeForm.ROW_COUNT));
    assertThat(negOne.getDouble(0), equalTo(-1.0));
    assertThat(negOneDouble.getDouble(0), equalTo(-1.0));
    assertThat(negOneByTwo.getDouble(0), equalTo(-2.0));
    assertThat(negOneByTwoDouble.getDouble(0), equalTo(-2.0));
    assertThat(twoByNegOne.getDouble(0), equalTo(-2.0));
    assertThat(twoByNegOneDouble.getDouble(0), equalTo(-2.0));
}
Also used : ColumnView(org.activityinfo.model.query.ColumnView) ColumnSet(org.activityinfo.model.query.ColumnSet) QueryModel(org.activityinfo.model.query.QueryModel) Test(org.junit.Test)

Example 43 with QueryModel

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

the class UnaryFunctionQueryTest method multiplyFunctionTest.

@Test
public void multiplyFunctionTest() {
    QueryModel queryModel = new QueryModel(intakeForm.getFormId());
    makeQueryExprAndExpectColumnModelException(queryModel, "*1", "multOne");
    makeQueryExprAndExpectColumnModelException(queryModel, "*1.0", "multOneDouble");
    makeQueryExprAndExpectColumnModelException(queryModel, "1*", "oneMult");
    makeQueryExprAndExpectColumnModelException(queryModel, "1.0*", "oneMultDouble");
}
Also used : QueryModel(org.activityinfo.model.query.QueryModel) Test(org.junit.Test)

Example 44 with QueryModel

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

the class AnalysisResult method computePoints.

private static Observable<MeasureResultSet> computePoints(FormStore formStore, EffectiveMeasure measure) {
    QueryModel queryModel = new QueryModel(measure.getFormId());
    queryModel.selectExpr(measure.getModel().getFormula()).as("value");
    for (EffectiveMapping dim : measure.getDimensions()) {
        queryModel.addColumns(dim.getRequiredColumns());
    }
    Observable<ColumnSet> columnSet = formStore.query(queryModel);
    Observable<MeasureResultSet> resultSet = columnSet.transform(columns -> {
        MeasureResultBuilder builder = new MeasureResultBuilder(measure, columns);
        builder.execute();
        return builder.getResult();
    });
    return resultSet;
}
Also used : ColumnSet(org.activityinfo.model.query.ColumnSet) QueryModel(org.activityinfo.model.query.QueryModel)

Example 45 with QueryModel

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

the class OfflineStoreGwtTest method verifyWeCanQuery.

private Promise<Void> verifyWeCanQuery(Void input) {
    QueryModel queryModel = new QueryModel(survey.getFormId());
    queryModel.selectResourceId().as("id");
    queryModel.selectExpr(survey.getGenderFieldId().asString()).as("gender");
    queryModel.selectExpr(survey.getAgeFieldId().asString()).as("age");
    queryModel.selectExpr(survey.getNameFieldId().asString()).as("name");
    return offlineStore.query(queryModel).once().then(new Function<ColumnSet, Void>() {

        @Nullable
        @Override
        public Void apply(@Nullable ColumnSet columnSet) {
            assertEquals(survey.getRowCount() + 2, columnSet.getNumRows());
            return null;
        }
    });
}
Also used : ColumnSet(org.activityinfo.model.query.ColumnSet) QueryModel(org.activityinfo.model.query.QueryModel) Nullable(javax.annotation.Nullable)

Aggregations

QueryModel (org.activityinfo.model.query.QueryModel)59 ColumnSet (org.activityinfo.model.query.ColumnSet)40 Test (org.junit.Test)30 ColumnView (org.activityinfo.model.query.ColumnView)21 ColumnSetBuilder (org.activityinfo.store.query.server.ColumnSetBuilder)13 NullFormSupervisor (org.activityinfo.store.query.shared.NullFormSupervisor)11 FormTree (org.activityinfo.model.formTree.FormTree)9 ResourceId (org.activityinfo.model.resource.ResourceId)9 FormClass (org.activityinfo.model.form.FormClass)7 Nullable (javax.annotation.Nullable)6 FormField (org.activityinfo.model.form.FormField)6 ColumnModel (org.activityinfo.model.query.ColumnModel)6 NullFormScanCache (org.activityinfo.store.query.shared.NullFormScanCache)6 QuantityType (org.activityinfo.model.type.number.QuantityType)5 DimensionCategory (org.activityinfo.legacy.shared.reports.content.DimensionCategory)4 RowBasedJsonWriter (org.activityinfo.store.query.output.RowBasedJsonWriter)4 Charsets (com.google.common.base.Charsets)3 Operation (io.swagger.v3.oas.annotations.Operation)3 FieldPath (org.activityinfo.model.formTree.FieldPath)3 FormTreeBuilder (org.activityinfo.model.formTree.FormTreeBuilder)3