Package com.google.visualization.datasource.query

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


    table.addColumn(aggreationColumnDescription);

    List<AbstractColumn> simpleColumns =
        Lists.newArrayList((AbstractColumn) new SimpleColumn("simpleColumn"));
    List<AbstractColumn> aggregationColumns =
        Lists.newArrayList((AbstractColumn) new AggregationColumn(
            new SimpleColumn("simpleColumn"), AggregationType.MIN));
    ScalarFunctionColumnTitle titleYear =
        new ScalarFunctionColumnTitle(Lists.<Value>newArrayList(),
            new ScalarFunctionColumn(simpleColumns,
                TimeComponentExtractor.getInstance(
View Full Code Here


    QueryGroup group = new QueryGroup();
    group.addColumn(new SimpleColumn("Year"));
    group.addColumn(new SimpleColumn("Band"));
    q.setGroup(group);
    QuerySelection selection = new QuerySelection();
    selection.addColumn(new AggregationColumn(new SimpleColumn("Songs"),
        AggregationType.MAX));
    selection.addColumn(new AggregationColumn(new SimpleColumn("Songs"),
        AggregationType.MIN));
    selection.addColumn(new SimpleColumn("Year"));
    selection.addColumn(new AggregationColumn(new SimpleColumn("Songs"),
        AggregationType.AVG));
    selection.addColumn(new AggregationColumn(new SimpleColumn("Sales"),
        AggregationType.SUM));
    q.setSelection(selection);
    q.validate();

    DataTable result = QueryEngine.executeQuery(q, res, ULocale.US);
View Full Code Here

    QueryPivot pivot = new QueryPivot();
    pivot.addColumn(new SimpleColumn("Band"));
    pivot.addColumn(new SimpleColumn("Songs"));
    q.setPivot(pivot);
    QuerySelection selection = new QuerySelection();
    selection.addColumn(new AggregationColumn(new SimpleColumn("Sales"),
        AggregationType.MAX));
    selection.addColumn(new SimpleColumn("Year"));
    selection.addColumn(new AggregationColumn(new SimpleColumn("Sales"),
        AggregationType.MIN));
    selection.addColumn(new AggregationColumn(new SimpleColumn("Fans"),
        AggregationType.AVG));
    q.setSelection(selection);
    q.validate();

    DataTable result = QueryEngine.executeQuery(q, res, ULocale.US);
View Full Code Here

    // select sum(age), count(dept), hour(lunchTime) group by hour(lunchtime)
    Query q = new Query();

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

    // Add group.
    QueryGroup group = new QueryGroup();
    group.addColumn(new ScalarFunctionColumn(
        Lists.newArrayList((AbstractColumn) new SimpleColumn("lunchTime")),
        TimeComponentExtractor.getInstance(
            TimeComponentExtractor.TimeComponent.HOUR)));
    q.setGroup(group);

    q.validate();

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

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

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

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

    assertStringArraysEqual(new String[]{"119.0", "4.0", "12.0"},
        resultStrings[0]);
    assertStringArraysEqual(new String[]{"54.0", "2.0", "13.0"},
        resultStrings[1]);

    // Select sum(age), count(name), datediff(hireDate, seniorityStartTime),
    // dept group by datediff(hireDate, seniorityStartTime), dept.
    q = new Query();

    // Add selection.
    selection = new QuerySelection();
    selection.addColumn(new AggregationColumn(new SimpleColumn("age"),
        AggregationType.SUM));
    selection.addColumn(new AggregationColumn(new SimpleColumn("name"),
        AggregationType.COUNT));
    selection.addColumn(new ScalarFunctionColumn(
        Lists.<AbstractColumn>newArrayList(
            new SimpleColumn("seniorityStartTime"),
            new SimpleColumn("hireDate")), DateDiff.getInstance()));
View Full Code Here

    // select sum(age), count(dept) pivot hour(lunchtime)
    Query q = new Query();

    // Add selection.
    QuerySelection selection = new QuerySelection();
    selection.addColumn(new AggregationColumn(new SimpleColumn("age"),
        AggregationType.SUM));
    selection.addColumn(new AggregationColumn(new SimpleColumn("dept"),
        AggregationType.COUNT));
    q.setSelection(selection);

    // Add pivot.
    QueryPivot pivot = new QueryPivot();
    pivot.addColumn(new ScalarFunctionColumn(
        Lists.newArrayList((AbstractColumn) new SimpleColumn("lunchTime")),
        TimeComponentExtractor.getInstance(
            TimeComponentExtractor.TimeComponent.HOUR)));
    q.setPivot(pivot);

    q.validate();
    DataTable result = QueryEngine.executeQuery(q, res.clone(), ULocale.US);
    // Test column description
    List<ColumnDescription> cols = result.getColumnDescriptions();

    assertEquals(4, cols.size());
    assertEquals("12.0 sum-age", cols.get(0).getId());
    assertEquals("13.0 sum-age", cols.get(1).getId());
    assertEquals("12.0 count-dept", cols.get(2).getId());
    assertEquals("13.0 count-dept", cols.get(3).getId());

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

    assertStringArraysEqual(new String[]{"119.0", "54.0", "4.0", "2.0"},
        resultStrings[0]);

    // select count(dept) pivot hour(lunchtime), datediff(hireDate,
    // seniorityStartTime)
    Query q1 = new Query();

    // Add selection.
    QuerySelection selection1 = new QuerySelection();
    selection1.addColumn(new AggregationColumn(new SimpleColumn("dept"),
        AggregationType.COUNT));
    q1.setSelection(selection1);

    // Add pivot.
    QueryPivot pivot1 = new QueryPivot();
View Full Code Here

    // pivot isSenior.
    Query q = new Query();

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

    // Add group.
    QueryGroup group = new QueryGroup();
    group.addColumn(new ScalarFunctionColumn(
        Lists.newArrayList((AbstractColumn) new SimpleColumn("lunchTime")),
        TimeComponentExtractor.getInstance(
            TimeComponentExtractor.TimeComponent.HOUR)));
    q.setGroup(group);

    // Add pivot.
    QueryPivot pivot = new QueryPivot();
    pivot.addColumn(new SimpleColumn("isSenior"));
    q.setPivot(pivot);

    q.validate();

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

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

    assertEquals(5, cols.size());
    assertEquals("false sum-age", cols.get(0).getId());
    assertEquals("true sum-age", cols.get(1).getId());
    assertEquals("false count-dept", cols.get(2).getId());
    assertEquals("true count-dept", cols.get(3).getId());
    assertEquals("hour_lunchTime", cols.get(4).getId());

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

    assertStringArraysEqual(new String[]{"52.0", "67.0", "2.0", "2.0", "12.0"},
        resultStrings[0]);
    assertStringArraysEqual(new String[]{"30.0", "24.0", "1.0", "1.0", "13.0"},
        resultStrings[1]);

    res = MockDataSource.getData(3);

    // select count(dept), datediff(hireDate, seniorityStartTime) group by
    // datediff(hireDate, seniorityStartTime) pivot isSenior.
    q = new Query();

    // Add selection.
    selection = new QuerySelection();
    selection.addColumn(new AggregationColumn(new SimpleColumn("dept"),
        AggregationType.COUNT));
    selection.addColumn(new ScalarFunctionColumn(
        Lists.<AbstractColumn>newArrayList(
            new SimpleColumn("seniorityStartTime"),
            new SimpleColumn("hireDate")), DateDiff.getInstance()));
View Full Code Here

    // select sum(age), count(dept) group by isSenior pivot hour(lunchtime)
    Query q = new Query();

    // Add selection.
    QuerySelection selection = new QuerySelection();
    selection.addColumn(new AggregationColumn(new SimpleColumn("age"),
        AggregationType.SUM));
    selection.addColumn(new AggregationColumn(new SimpleColumn("dept"),
        AggregationType.COUNT));
    selection.addColumn(new SimpleColumn("isSenior"));
    q.setSelection(selection);

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

    // Add pivot.
    QueryPivot pivot = new QueryPivot();
    pivot.addColumn(new ScalarFunctionColumn(
        Lists.newArrayList((AbstractColumn) new SimpleColumn("lunchTime")),
        TimeComponentExtractor.getInstance(
            TimeComponentExtractor.TimeComponent.HOUR)));
    q.setPivot(pivot);

    q.validate();

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

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

    assertEquals(5, cols.size());
    assertEquals("12.0 sum-age", cols.get(0).getId());
    assertEquals("13.0 sum-age", cols.get(1).getId());
    assertEquals("12.0 count-dept", cols.get(2).getId());
    assertEquals("13.0 count-dept", cols.get(3).getId());
    assertEquals("isSenior", cols.get(4).getId());

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

    assertStringArraysEqual(new String[]{"52.0", "30.0", "2.0", "1.0",
        "false"}, resultStrings[0]);
    assertStringArraysEqual(new String[]{"67.0", "24.0", "2.0", "1.0",
        "true"}, resultStrings[1]);

    // selectcount(dept) group by isSenior pivot datediff(hireDate,
    // seniorityStartTime)
    q = new Query();
    res = MockDataSource.getData(3);

    // Add selection.
    selection = new QuerySelection();
    selection.addColumn(new AggregationColumn(new SimpleColumn("dept"),
        AggregationType.COUNT));
    selection.addColumn(new SimpleColumn("isSenior"));
    q.setSelection(selection);

    // Add Group.
View Full Code Here

    // year(seniorityStartTime) pivot hour(lunchtime)
    Query q = new Query();

    // Add selection.
    QuerySelection selection = new QuerySelection();
    selection.addColumn(new AggregationColumn(new SimpleColumn("dept"),
        AggregationType.COUNT));
    selection.addColumn(new ScalarFunctionColumn(
        Lists.newArrayList((AbstractColumn)
            new SimpleColumn("seniorityStartTime")), TimeComponentExtractor.
        getInstance(TimeComponentExtractor.TimeComponent.YEAR)));
View Full Code Here

    // select sum(age), dept, hour(min(lunchTime)) group by dept
    Query q = new Query();

    // 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)));
View Full Code Here

    // select sum(age), hour(min(lunchTime)) pivot dept
    Query q = new Query();

    // 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

TOP

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

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.