Search in sources :

Example 1 with ColumnView

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

the class AnalysisViewModelTest method dumpQuery.

private void dumpQuery(ResourceId formId, String... columns) {
    if (DUMP_RAW_DATA) {
        try {
            File tempFile = File.createTempFile("query", ".csv");
            try (PrintWriter writer = new PrintWriter(tempFile)) {
                QueryModel model = new QueryModel(formId);
                for (int i = 0; i < columns.length; i++) {
                    model.selectExpr(columns[i]).as("c" + i);
                }
                ColumnSet columnSet = assertLoads(formStore.query(model));
                for (int i = 0; i < columns.length; i++) {
                    if (i > 0) {
                        writer.print(",");
                    }
                    writer.print(columns[i]);
                }
                writer.println();
                for (int i = 0; i < columnSet.getNumRows(); i++) {
                    for (int j = 0; j < columns.length; j++) {
                        if (j > 0) {
                            writer.print(",");
                        }
                        ColumnView columnView = columnSet.getColumnView("c" + j);
                        Object cell = columnView.get(i);
                        String cells = "";
                        if (cell != null) {
                            cells = cell.toString();
                        }
                        writer.print(cells);
                    }
                    writer.println();
                }
            }
            System.out.println("Dumped data to " + tempFile);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
Also used : ColumnView(org.activityinfo.model.query.ColumnView) ColumnSet(org.activityinfo.model.query.ColumnSet) File(java.io.File) QueryModel(org.activityinfo.model.query.QueryModel) PrintWriter(java.io.PrintWriter)

Example 2 with ColumnView

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

the class OfflineStoreGwtTest method verifyWeCanQueryRecords.

private Promise<Void> verifyWeCanQueryRecords(Void input) {
    QueryModel queryModel = new QueryModel(survey.getFormId());
    queryModel.selectResourceId().as("id");
    queryModel.selectField(survey.getNameFieldId()).as("name");
    queryModel.selectField(survey.getAgeFieldId()).as("age");
    return formStore.query(queryModel).once().then(columnSet -> {
        assertEquals(survey.getRowCount(), columnSet.getNumRows());
        ColumnView name = columnSet.getColumnView("name");
        ColumnView age = columnSet.getColumnView("age");
        assertEquals(survey.getRowCount(), columnSet.getNumRows());
        assertEquals("Melanie", name.get(0));
        assertEquals("Joe", name.get(1));
        assertEquals("Matilda", name.get(2));
        return null;
    });
}
Also used : ColumnView(org.activityinfo.model.query.ColumnView) QueryModel(org.activityinfo.model.query.QueryModel)

Example 3 with ColumnView

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

the class Presenter method choices.

private Supplier<Promise<List<Choice>>> choices(final Level level) {
    final QueryModel queryModel = new QueryModel(level.getFormId());
    queryModel.selectResourceId().as("id");
    queryModel.selectExpr("label").as("label");
    if (!level.isRoot()) {
        Choice selectedParent = getSelection(level.getParent());
        queryModel.selectExpr("parent").as("parent");
        queryModel.setFilter(Formulas.equals(new SymbolNode("parent"), Formulas.idConstant(selectedParent.getRef().getRecordId())));
    }
    return new Supplier<Promise<List<Choice>>>() {

        @Override
        public Promise<List<Choice>> get() {
            return locator.queryTable(queryModel).then(new Function<ColumnSet, List<Choice>>() {

                @Nullable
                @Override
                public List<Choice> apply(ColumnSet input) {
                    ColumnView id = input.getColumnView("id");
                    ColumnView label = input.getColumnView("label");
                    ColumnView parent = input.getColumnView("parent");
                    List<Choice> choices = new ArrayList<>();
                    for (int i = 0; i < input.getNumRows(); i++) {
                        if (parent == null) {
                            choices.add(new Choice(level.getFormId(), ResourceId.valueOf(id.getString(i)), label.getString(i)));
                        } else {
                            choices.add(new Choice(level.getFormId(), ResourceId.valueOf(id.getString(i)), label.getString(i), new RecordRef(level.getParent().getFormId(), ResourceId.valueOf(parent.getString(i)))));
                        }
                    }
                    return choices;
                }
            });
        }
    };
}
Also used : SymbolNode(org.activityinfo.model.formula.SymbolNode) ColumnView(org.activityinfo.model.query.ColumnView) RecordRef(org.activityinfo.model.type.RecordRef) Supplier(com.google.common.base.Supplier) ColumnSet(org.activityinfo.model.query.ColumnSet) QueryModel(org.activityinfo.model.query.QueryModel) Nullable(javax.annotation.Nullable)

Example 4 with ColumnView

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

the class FieldScoreMatrix method scoreTextColumnMatch.

private double scoreTextColumnMatch(FieldProfile sourceProfile, FieldProfile targetProfile) {
    ColumnView source = sourceProfile.getView();
    ColumnView target = targetProfile.getView();
    if (source.numRows() <= target.numRows()) {
        return scoreTextColumnMatch(source, target);
    } else {
        return scoreTextColumnMatch(target, source);
    }
}
Also used : ColumnView(org.activityinfo.model.query.ColumnView)

Example 5 with ColumnView

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

the class BinaryBooleanOperator method columnApply.

@Override
public ColumnView columnApply(int numRows, List<ColumnView> arguments) {
    checkArity(arguments, 2);
    ColumnView a = arguments.get(0);
    ColumnView b = arguments.get(1);
    if (a.numRows() != b.numRows()) {
        throw new FormulaSyntaxException("Arguments must have the same number of rows");
    }
    int[] result = new int[a.numRows()];
    for (int i = 0; i < result.length; i++) {
        int ai = a.getBoolean(i);
        int bi = b.getBoolean(i);
        result[i] = apply(ai, bi);
    }
    return new BooleanColumnView(result);
}
Also used : FormulaSyntaxException(org.activityinfo.model.formula.diagnostic.FormulaSyntaxException) ColumnView(org.activityinfo.model.query.ColumnView) BooleanColumnView(org.activityinfo.model.query.BooleanColumnView) BooleanColumnView(org.activityinfo.model.query.BooleanColumnView)

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