Package com.google.visualization.datasource.query

Examples of com.google.visualization.datasource.query.ScalarFunctionColumn


    // select name, dept, hour(lunchTime)
    Query q = new Query();
    QuerySelection selection = new QuerySelection();
    selection.addColumn(new SimpleColumn("name"));
    selection.addColumn(new SimpleColumn("dept"));
    selection.addColumn(new ScalarFunctionColumn(
        Lists.newArrayList((AbstractColumn) new SimpleColumn("lunchTime")),
        TimeComponentExtractor.getInstance(
            TimeComponentExtractor.TimeComponent.HOUR)));

    q.setSelection(selection);
View Full Code Here


    // Add selection.
    QuerySelection selection = new QuerySelection();
    selection.addColumn(new AggregationColumn(new SimpleColumn("age"),
        AggregationType.SUM));
    selection.addColumn(new SimpleColumn("dept"));
    selection.addColumn(new ScalarFunctionColumn(
        Lists.newArrayList((AbstractColumn) new AggregationColumn(
            new SimpleColumn("lunchTime"), AggregationType.MIN)),
        TimeComponentExtractor.getInstance(
            TimeComponentExtractor.TimeComponent.HOUR)));
    q.setSelection(selection);

    // Add group.
    QueryGroup group = new QueryGroup();
    group.addColumn(new SimpleColumn("dept"));
    q.setGroup(group);

    q.validate();

    DataTable result = QueryEngine.executeQuery(q, res, ULocale.US);

    // Test column description
    List<ColumnDescription> cols = result.getColumnDescriptions();

    assertEquals(3, cols.size());
    assertEquals("sum-age", cols.get(0).getId());
    assertEquals("dept", cols.get(1).getId());
    assertEquals("hour_min-lunchTime", cols.get(2).getId());

    String[][] resultStrings = MockDataSource.queryResultToStringMatrix(result);
    assertEquals(3, resultStrings.length);

    assertStringArraysEqual(new String[]{"92.0", "Eng", "12.0"},
        resultStrings[0]);
    assertStringArraysEqual(new String[]{"24.0", "Marketing", "13.0"},
        resultStrings[1]);
    assertStringArraysEqual(new String[]{"57.0", "Sales", "12.0"},
        resultStrings[2]);

    // Test group-by column with scalar function in the selection:
    // select count(name), hour(lunchTime) group by lunchtime
    q = new Query();
    // Add selection
    QuerySelection selection1 = new QuerySelection();
    selection1.addColumn(new AggregationColumn(new SimpleColumn("name"),
        AggregationType.COUNT));
    selection1.addColumn(new ScalarFunctionColumn(
        Lists.newArrayList((AbstractColumn) new SimpleColumn("lunchTime")),
        TimeComponentExtractor.getInstance(
            TimeComponentExtractor.TimeComponent.HOUR)));
    q.setSelection(selection1);
View Full Code Here

    // Add selection.
    QuerySelection selection = new QuerySelection();
    selection.addColumn(new AggregationColumn(new SimpleColumn("age"),
        AggregationType.SUM));
    selection.addColumn(new ScalarFunctionColumn(
        Lists.newArrayList((AbstractColumn) new AggregationColumn(
            new SimpleColumn("lunchTime"), AggregationType.MIN)),
        TimeComponentExtractor.getInstance(
            TimeComponentExtractor.TimeComponent.HOUR)));
    q.setSelection(selection);
View Full Code Here

    // Add selection.
    QuerySelection selection = new QuerySelection();
    selection.addColumn(new AggregationColumn(new SimpleColumn("age"),
        AggregationType.SUM));
    selection.addColumn(new ScalarFunctionColumn(
        Lists.newArrayList((AbstractColumn) new SimpleColumn("hireDate")),
        TimeComponentExtractor.getInstance(
            TimeComponentExtractor.TimeComponent.DAY)));
    selection.addColumn(new ScalarFunctionColumn(
        Lists.newArrayList((AbstractColumn) new AggregationColumn(
            new SimpleColumn("lunchTime"), AggregationType.MIN)),
        TimeComponentExtractor.getInstance(
            TimeComponentExtractor.TimeComponent.HOUR)));
    q.setSelection(selection);
View Full Code Here

    // Add selection.
    QuerySelection selection = new QuerySelection();
    selection.addColumn(new AggregationColumn(new SimpleColumn("age"),
        AggregationType.SUM));
    selection.addColumn(new ScalarFunctionColumn(
        Lists.newArrayList((AbstractColumn) new SimpleColumn("hireDate")),
        TimeComponentExtractor.getInstance(
            TimeComponentExtractor.TimeComponent.DAY)));
    selection.addColumn(new ScalarFunctionColumn(
        Lists.newArrayList((AbstractColumn) new AggregationColumn(
            new SimpleColumn("lunchTime"), AggregationType.MIN)),
        TimeComponentExtractor.getInstance(
            TimeComponentExtractor.TimeComponent.HOUR)));
    q.setSelection(selection);
View Full Code Here

    // select day(hireDate), hireDate, age order by day(hireDate)
    Query q = new Query();

    // Add selection.
    QuerySelection selection = new QuerySelection();
    selection.addColumn(new ScalarFunctionColumn(
        Lists.newArrayList((AbstractColumn) new SimpleColumn("hireDate")),
        TimeComponentExtractor.getInstance(
            TimeComponentExtractor.TimeComponent.DAY)));
    selection.addColumn(new SimpleColumn("hireDate"));
    selection.addColumn(new SimpleColumn("age"));
    q.setSelection(selection);

    // Add sort.
    QuerySort sort = new QuerySort();
    sort.addSort(new ScalarFunctionColumn(
        Lists.newArrayList((AbstractColumn) new SimpleColumn("hireDate")),
        TimeComponentExtractor.getInstance(
            TimeComponentExtractor.TimeComponent.DAY)), SortOrder.ASCENDING);
    q.setSort(sort);
View Full Code Here

    // select day(hireDate) + age * hour(seniorityStartTime), age
    Query q = new Query();

    // Add selection.
    QuerySelection selection = new QuerySelection();
    AbstractColumn col1  = new ScalarFunctionColumn(
        Lists.<AbstractColumn>newArrayList(new SimpleColumn("hireDate")),
        TimeComponentExtractor.getInstance(
            TimeComponentExtractor.TimeComponent.DAY));
    AbstractColumn col2 = new SimpleColumn("age");
    AbstractColumn col3  = new ScalarFunctionColumn(
        Lists.<AbstractColumn>newArrayList(
            new SimpleColumn("seniorityStartTime")),
        TimeComponentExtractor.getInstance(
            TimeComponentExtractor.TimeComponent.HOUR));
    AbstractColumn col4 = new ScalarFunctionColumn(
        Lists.<AbstractColumn>newArrayList(col2, col3), Product.getInstance());
    AbstractColumn col5 = new ScalarFunctionColumn(
        Lists.<AbstractColumn>newArrayList(col1, col4), Sum.getInstance());
    selection.addColumn(col5);
    selection.addColumn(new SimpleColumn("age"));
    q.setSelection(selection);
    q.validate();
View Full Code Here

    // select sum(age), day(hireDate) - hour(seniorityStartTime)
    // group by day(hireDate) - hour(seniorityStartTime)
    Query q = new Query();

    AbstractColumn col1  = new ScalarFunctionColumn(
        Lists.<AbstractColumn>newArrayList(new SimpleColumn("hireDate")),
        TimeComponentExtractor.getInstance(
            TimeComponentExtractor.TimeComponent.DAY));
    AbstractColumn col2  = new ScalarFunctionColumn(
        Lists.<AbstractColumn>newArrayList(
            new SimpleColumn("seniorityStartTime")),
        TimeComponentExtractor.getInstance(
            TimeComponentExtractor.TimeComponent.HOUR));
    AbstractColumn col3 = new ScalarFunctionColumn(
        Lists.<AbstractColumn>newArrayList(col1, col2),
        Difference.getInstance());

    // Add selection
    QuerySelection selection = new QuerySelection();
View Full Code Here

    // select day(hireDate), hour(seniorityStartTime) where
    // day(hireDate) - hour(seniorityStartTime) < -5
    // group by day(hireDate) - hour(seniorityStartTime)
    Query q = new Query();

    AbstractColumn col1  = new ScalarFunctionColumn(
        Lists.<AbstractColumn>newArrayList(new SimpleColumn("hireDate")),
        TimeComponentExtractor.getInstance(
            TimeComponentExtractor.TimeComponent.DAY));
    AbstractColumn col2  = new ScalarFunctionColumn(
        Lists.<AbstractColumn>newArrayList(
            new SimpleColumn("seniorityStartTime")),
        TimeComponentExtractor.getInstance(
            TimeComponentExtractor.TimeComponent.HOUR));
    AbstractColumn col3 = new ScalarFunctionColumn(
        Lists.<AbstractColumn>newArrayList(col1, col2),
        Difference.getInstance());

    // Add selection
    QuerySelection selection = new QuerySelection();
View Full Code Here

    DataTable res = MockDataSource.getData(0);

    // selection with modulo ('weight' is a column id): "select weight, weight % 10"
    Query q = new Query();

    AbstractColumn col1 = new ScalarFunctionColumn(
        Lists.<AbstractColumn>newArrayList(), new Constant(new NumberValue(10)));
    AbstractColumn col2 = new ScalarFunctionColumn(
        Lists.<AbstractColumn>newArrayList(new SimpleColumn("weight"), col1),
        Modulo.getInstance());

    // Add selection
    QuerySelection selection = new QuerySelection();
View Full Code Here

TOP

Related Classes of com.google.visualization.datasource.query.ScalarFunctionColumn

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.