Search in sources :

Example 36 with ColumnView

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

the class EnumerationQueryTest method enumRefTests.

@Test
public void enumRefTests() {
    TestingStorageProvider catalog = new TestingStorageProvider();
    ColumnSetBuilder builder = new ColumnSetBuilder(catalog, new NullFormScanCache(), new NullFormSupervisor());
    IntakeForm intakeForm = catalog.getIntakeForm();
    QueryModel queryModel = new QueryModel(intakeForm.getFormId());
    queryModel.selectField(intakeForm.getNationalityFieldId()).as("nationality");
    queryModel.selectExpr(intakeForm.getNationalityFieldId() + "==" + "\"" + intakeForm.getPalestinianId() + "\"").as("palestinian");
    queryModel.selectExpr("\"" + intakeForm.getPalestinianId() + "\"" + "==" + intakeForm.getNationalityFieldId()).as("palestinianInverse");
    ColumnSet columnSet = builder.build(queryModel);
    ColumnView nationality = columnSet.getColumnView("nationality");
    ColumnView palestinian = columnSet.getColumnView("palestinian");
    ColumnView palestinianInverse = columnSet.getColumnView("palestinianInverse");
    // Correct Tests
    assertThat(nationality.get(1).toString(), equalTo(NAT_PAL));
    assertThat(Boolean.valueOf(palestinian.get(1).toString()), equalTo(true));
    assertThat(Boolean.valueOf(palestinianInverse.get(1).toString()), equalTo(true));
    // Incorrect Tests
    // Multiple selected values should return null
    assertThat(nationality.get(5), equalTo(null));
}
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 37 with ColumnView

use of org.activityinfo.model.query.ColumnView 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 38 with ColumnView

use of org.activityinfo.model.query.ColumnView 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 39 with ColumnView

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

the class UnaryFunctionBase method columnApply.

@Override
public ColumnView columnApply(int numRows, List<ColumnView> arguments) {
    checkArity(arguments, MAXARGS);
    ColumnView unaryArgument = arguments.get(0);
    return columnApply(numRows, unaryArgument);
}
Also used : ColumnView(org.activityinfo.model.query.ColumnView)

Example 40 with ColumnView

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

the class DateFunction method columnApply.

@Override
public ColumnView columnApply(int numRows, List<ColumnView> arguments) {
    ColumnView year = arguments.get(0);
    ColumnView month = arguments.get(1);
    ColumnView day = arguments.get(2);
    String[] dates = new String[numRows];
    for (int i = 0; i < numRows; i++) {
        dates[i] = apply(year.getDouble(i), month.getDouble(i), day.getDouble(i)).toString();
    }
    return new StringArrayColumnView(dates);
}
Also used : ColumnView(org.activityinfo.model.query.ColumnView) StringArrayColumnView(org.activityinfo.model.query.StringArrayColumnView) StringArrayColumnView(org.activityinfo.model.query.StringArrayColumnView)

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