Search in sources :

Example 6 with ColumnView

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

the class YearFracFunction method columnApply.

@Override
public ColumnView columnApply(int numRows, List<ColumnView> arguments) {
    if (arguments.size() != 2) {
        throw new FormulaSyntaxException("YEARFRAC() requires two arguments");
    }
    ColumnView startView = arguments.get(0);
    ColumnView endView = arguments.get(1);
    double[] result = new double[numRows];
    for (int i = 0; i < numRows; i++) {
        String start = startView.getString(i);
        String end = endView.getString(i);
        if (start == null || end == null) {
            result[i] = Double.NaN;
        } else {
            result[i] = compute(LocalDate.parse(start), LocalDate.parse(end));
        }
    }
    return new DoubleArrayColumnView(result);
}
Also used : FormulaSyntaxException(org.activityinfo.model.formula.diagnostic.FormulaSyntaxException) ColumnView(org.activityinfo.model.query.ColumnView) DoubleArrayColumnView(org.activityinfo.model.query.DoubleArrayColumnView) DoubleArrayColumnView(org.activityinfo.model.query.DoubleArrayColumnView)

Example 7 with ColumnView

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

the class AddDateFunction method columnApply.

@Override
public ColumnView columnApply(int numRows, List<ColumnView> arguments) {
    ColumnView dateView = arguments.get(0);
    ColumnView daysView = arguments.get(1);
    String[] result = new String[dateView.numRows()];
    for (int i = 0; i < dateView.numRows(); i++) {
        LocalDate date = LocalDate.parse(dateView.getString(i));
        int days = (int) daysView.getDouble(i);
        result[i] = date.plusDays(days).toString();
    }
    return new StringArrayColumnView(result);
}
Also used : ColumnView(org.activityinfo.model.query.ColumnView) StringArrayColumnView(org.activityinfo.model.query.StringArrayColumnView) LocalDate(org.activityinfo.model.type.time.LocalDate) StringArrayColumnView(org.activityinfo.model.query.StringArrayColumnView)

Example 8 with ColumnView

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

the class DateComponentFunction method columnApply.

@Override
public ColumnView columnApply(int numRows, List<ColumnView> arguments) {
    checkArity(arguments, 1);
    ColumnView view = arguments.get(0);
    double[] result = new double[view.numRows()];
    for (int i = 0; i < view.numRows(); i++) {
        String date = view.getString(i);
        if (date == null) {
            result[i] = Double.NaN;
        } else {
            result[i] = apply(date);
        }
    }
    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 9 with ColumnView

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

the class ComparisonOperator 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");
    }
    if (a.getType() == ColumnType.NUMBER && b.getType() == ColumnType.NUMBER) {
        return columnApplyNumber(a, b);
    } else if (a.getType() == ColumnType.STRING && b.getType() == ColumnType.STRING) {
        if (a instanceof EnumColumnView) {
            return columnApplyEnum((EnumColumnView) a, b);
        } else if (b instanceof EnumColumnView) {
            return columnApplyEnum((EnumColumnView) b, a);
        } else {
            return columnApplyString(a, b);
        }
    } else {
        throw new FormulaSyntaxException("Comparsion between incompatible types: " + a.getType() + ", " + b.getType());
    }
}
Also used : FormulaSyntaxException(org.activityinfo.model.formula.diagnostic.FormulaSyntaxException) EnumColumnView(org.activityinfo.model.query.EnumColumnView) ColumnView(org.activityinfo.model.query.ColumnView) BooleanColumnView(org.activityinfo.model.query.BooleanColumnView) EnumColumnView(org.activityinfo.model.query.EnumColumnView)

Example 10 with ColumnView

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

the class GetSitesHandler method extractSiteData.

private SiteDTO[] extractSiteData(List<FieldBinding> fieldBindings, ColumnSet columnSet) {
    ColumnSet finalColumnSet;
    SiteDTO[] sites;
    if (offset > 0 || limit > 0) {
        Map<String, ColumnView> paginatedColumns = Maps.newHashMap();
        int[] index = generatePaginationIndex(columnSet.getNumRows());
        sites = initialiseSites(index.length);
        for (Map.Entry<String, ColumnView> column : columnSet.getColumns().entrySet()) {
            paginatedColumns.put(column.getKey(), column.getValue().select(index));
        }
        finalColumnSet = new ColumnSet(index.length, paginatedColumns);
    } else {
        sites = initialiseSites(columnSet.getNumRows());
        finalColumnSet = columnSet;
    }
    for (FieldBinding binding : fieldBindings) {
        binding.extractFieldData(sites, finalColumnSet);
    }
    return sites;
}
Also used : ColumnView(org.activityinfo.model.query.ColumnView) ColumnSet(org.activityinfo.model.query.ColumnSet)

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