Package com.google.visualization.datasource.datatable

Examples of com.google.visualization.datasource.datatable.ColumnDescription


        falseRow.addCell(new TableCell("a"));
        falseRow.addCell(new TableCell(123));
        falseRow.addCell(new TableCell("b"));

        DataTable table = new DataTable();
        table.addColumn(new ColumnDescription("c1", ValueType.TEXT, "c1"));
        table.addColumn(new ColumnDescription("c2", ValueType.TEXT, "c2"));
        table.addColumn(new ColumnDescription("c3", ValueType.TEXT, "c3"));

        ColumnColumnFilter filter1 = new ColumnColumnFilter(new SimpleColumn("c1"),
                new SimpleColumn("c3"), ComparisonFilter.Operator.EQ);
        ColumnValueFilter filter2 = new ColumnValueFilter(new SimpleColumn("c2"),
                new NumberValue(100), ComparisonFilter.Operator.GT);
View Full Code Here


        assertTrue(catched);

        // Working example with a table description filled only with types.
        reader = new StringReader("1,a,true\n4,x13a,false\n1400,4,true");
        List<ColumnDescription> columnDescriptions = Lists.newArrayList();
        columnDescriptions.add(new ColumnDescription("i1", ValueType.NUMBER, null));
        columnDescriptions.add(new ColumnDescription("i2", ValueType.TEXT, null));
        columnDescriptions.add(new ColumnDescription("i3", ValueType.DATE, null));
        dataTable = CsvDataSourceHelper.read(reader, columnDescriptions, false);
        assertEquals(3, dataTable.getNumberOfRows());
        assertEquals(3, dataTable.getNumberOfColumns());
        assertEquals(new NumberValue(1), dataTable.getRow(0).getCell(0).getValue());
        assertEquals(new TextValue("a"), dataTable.getRow(0).getCell(1).getValue());
        assertEquals(DateValue.getNullValue(), dataTable.getRow(0).getCell(2).getValue());
        assertEquals(new NumberValue(4), dataTable.getRow(1).getCell(0).getValue());
        assertEquals(new TextValue("x13a"), dataTable.getRow(1).getCell(1).getValue());
        assertEquals(DateValue.getNullValue(), dataTable.getRow(1).getCell(2).getValue());
        assertEquals(new NumberValue(1400), dataTable.getRow(2).getCell(0).getValue());
        assertEquals(new TextValue("4"), dataTable.getRow(2).getCell(1).getValue());
        assertEquals(DateValue.getNullValue(), dataTable.getRow(2).getCell(2).getValue());

        // Working example with a table description filled only with types.
        reader = new StringReader("1,a,2004-03-01\n4,x13a,2005-04-02\n1400,4,2006-05-03");
        columnDescriptions = Lists.newArrayList();
        columnDescriptions.add(new ColumnDescription("i1", ValueType.NUMBER, null));
        columnDescriptions.add(new ColumnDescription("i2", ValueType.TEXT, null));
        columnDescriptions.add(new ColumnDescription("i3", ValueType.DATE, null));
        dataTable = CsvDataSourceHelper.read(reader, columnDescriptions, false);
        assertEquals(3, dataTable.getNumberOfRows());
        assertEquals(3, dataTable.getNumberOfColumns());
        assertEquals(new NumberValue(1), dataTable.getRow(0).getCell(0).getValue());
        assertEquals(new TextValue("a"), dataTable.getRow(0).getCell(1).getValue());
        assertEquals(new DateValue(2004, 2, 1), dataTable.getRow(0).getCell(2).getValue());
        assertEquals(new NumberValue(4), dataTable.getRow(1).getCell(0).getValue());
        assertEquals(new TextValue("x13a"), dataTable.getRow(1).getCell(1).getValue());
        assertEquals(new DateValue(2005, 3, 2), dataTable.getRow(1).getCell(2).getValue());
        assertEquals(new NumberValue(1400), dataTable.getRow(2).getCell(0).getValue());
        assertEquals(new TextValue("4"), dataTable.getRow(2).getCell(1).getValue());
        assertEquals(new DateValue(2006, 4, 3), dataTable.getRow(2).getCell(2).getValue());
        assertEquals("i1", dataTable.getColumnDescription(0).getId());
        assertEquals("Column0", dataTable.getColumnDescription(0).getLabel());
        assertEquals("i2", dataTable.getColumnDescription(1).getId());
        assertEquals("Column1", dataTable.getColumnDescription(1).getLabel());
        assertEquals("i3", dataTable.getColumnDescription(2).getId());
        assertEquals("Column2", dataTable.getColumnDescription(2).getLabel());

        // Working example with header rows.
        reader = new StringReader("1,a,2004-03-01\n4,x13a,2005-04-02\n1400,4,2006-05-03");
        columnDescriptions = Lists.newArrayList();
        columnDescriptions.add(new ColumnDescription("i1", ValueType.NUMBER, null));
        columnDescriptions.add(new ColumnDescription("i2", ValueType.TEXT, null));
        columnDescriptions.add(new ColumnDescription("i3", ValueType.DATE, null));
        dataTable = CsvDataSourceHelper.read(reader, columnDescriptions, true);
        assertEquals(2, dataTable.getNumberOfRows());
        assertEquals(3, dataTable.getNumberOfColumns());
        assertEquals(new NumberValue(4), dataTable.getRow(0).getCell(0).getValue());
        assertEquals(new TextValue("x13a"), dataTable.getRow(0).getCell(1).getValue());
        assertEquals(new DateValue(2005, 3, 2), dataTable.getRow(0).getCell(2).getValue());
        assertEquals(new NumberValue(1400), dataTable.getRow(1).getCell(0).getValue());
        assertEquals(new TextValue("4"), dataTable.getRow(1).getCell(1).getValue());
        assertEquals(new DateValue(2006, 4, 3), dataTable.getRow(1).getCell(2).getValue());
        assertEquals("i1", dataTable.getColumnDescription(0).getId());
        assertEquals("1", dataTable.getColumnDescription(0).getLabel());
        assertEquals("i2", dataTable.getColumnDescription(1).getId());
        assertEquals("a", dataTable.getColumnDescription(1).getLabel());
        assertEquals("i3", dataTable.getColumnDescription(2).getId());
        assertEquals("2004-03-01", dataTable.getColumnDescription(2).getLabel());

        // Bad table description for that data.
        catched = false;
        try {
            reader = new StringReader("true\nfalse\nfalse");
            columnDescriptions = Lists.newArrayList();
            dataTable = CsvDataSourceHelper.read(reader, columnDescriptions, false);
        }
        catch(CsvDataSourceException e) {
            catched = true;
            assertEquals(ReasonType.INTERNAL_ERROR, e.getReasonType());
            assertEquals(
                    "Wrong number of columns in the data.",
                    e.getMessageToUser());
        }
        assertTrue(catched);

        // Working example with a null table description.
        reader = new StringReader("true,false\ntrue,false\ntrue,false\nfalse,false");
        columnDescriptions = null;
        dataTable = CsvDataSourceHelper.read(reader, columnDescriptions, false);
        assertEquals(4, dataTable.getNumberOfRows());
        assertEquals(2, dataTable.getNumberOfColumns());
        assertEquals(new TextValue("true"), dataTable.getRow(0).getCell(0).getValue());
        assertEquals(new TextValue("false"), dataTable.getRow(0).getCell(1).getValue());
        assertEquals(new TextValue("true"), dataTable.getRow(1).getCell(0).getValue());
        assertEquals(new TextValue("false"), dataTable.getRow(1).getCell(1).getValue());
        assertEquals(new TextValue("true"), dataTable.getRow(2).getCell(0).getValue());
        assertEquals(new TextValue("false"), dataTable.getRow(2).getCell(1).getValue());
        assertEquals(new TextValue("false"), dataTable.getRow(3).getCell(0).getValue());
        assertEquals(new TextValue("false"), dataTable.getRow(3).getCell(1).getValue());

        // Working example with a table description filled with types.
        reader = new StringReader("true,false\ntrue,false\ntrue,false\nfalse,false");
        columnDescriptions = Lists.newArrayList();
        columnDescriptions.add(new ColumnDescription("1", ValueType.BOOLEAN, "123"));
        columnDescriptions.add(new ColumnDescription("2", ValueType.BOOLEAN, "123"));
        dataTable = CsvDataSourceHelper.read(reader, columnDescriptions, false);
        assertEquals(4, dataTable.getNumberOfRows());
        assertEquals(2, dataTable.getNumberOfColumns());
        assertEquals(BooleanValue.TRUE, dataTable.getRow(0).getCell(0).getValue());
        assertEquals(BooleanValue.FALSE, dataTable.getRow(0).getCell(1).getValue());
View Full Code Here

        trueRow.addCell(new TableCell("a"));
        trueRow.addCell(new TableCell(123));
        trueRow.addCell(new TableCell("b"));

        DataTable table = new DataTable();
        table.addColumn(new ColumnDescription("c1", ValueType.TEXT, "c1"));
        table.addColumn(new ColumnDescription("c2", ValueType.TEXT, "c2"));
        table.addColumn(new ColumnDescription("c3", ValueType.TEXT, "c3"));

        ColumnColumnFilter filter1 = new ColumnColumnFilter(new SimpleColumn("c1"),
                new SimpleColumn("c3"), ComparisonFilter.Operator.NE);
        ColumnValueFilter filter2 = new ColumnValueFilter(new SimpleColumn("c2"),
                new NumberValue(1000), ComparisonFilter.Operator.GT);
View Full Code Here

    public void testPatterns() throws CsvDataSourceException, IOException {
        // Working example with header rows.
        Reader reader = new StringReader("1,a,20040301\n4,x13a,20050402\n1400,4,20060503");
        List<ColumnDescription> columnDescriptions = Lists.newArrayList();
        columnDescriptions.add(new ColumnDescription("i1", ValueType.NUMBER, null));
        columnDescriptions.add(new ColumnDescription("i2", ValueType.TEXT, null));

        ColumnDescription columnDescription = new ColumnDescription("i3", ValueType.DATE, null);
        columnDescription.setPattern("yyyyMMdd");
        columnDescriptions.add(columnDescription);

        DataTable dataTable = CsvDataSourceHelper.read(reader, columnDescriptions, true);
        assertEquals(2, dataTable.getNumberOfRows());
        assertEquals(3, dataTable.getNumberOfColumns());
View Full Code Here

    public void testWhitespaces() throws CsvDataSourceException, IOException {
        // Working example with header rows.
        Reader reader = new StringReader("   1   ,2,   3\n4   , 5 , 6");
        List<ColumnDescription> columnDescriptions = Lists.newArrayList();
        columnDescriptions.add(new ColumnDescription("i1", ValueType.NUMBER, null));
        columnDescriptions.add(new ColumnDescription("i2", ValueType.NUMBER, null));
        columnDescriptions.add(new ColumnDescription("i3", ValueType.NUMBER, null));

        DataTable dataTable = CsvDataSourceHelper.read(reader, columnDescriptions, true);
        assertEquals(1, dataTable.getNumberOfRows());
        assertEquals(3, dataTable.getNumberOfColumns());
        assertEquals(new NumberValue(4), dataTable.getRow(0).getCell(0).getValue());
View Full Code Here

    public void testEmptyStrings() throws CsvDataSourceException, IOException {
        // Working example with header rows.
        Reader reader = new StringReader("   1   ,,2,   3\n4   , 5 , 6,\n 7 ,,,10");
        List<ColumnDescription> columnDescriptions = Lists.newArrayList();
        columnDescriptions.add(new ColumnDescription("i1", ValueType.NUMBER, null));
        columnDescriptions.add(new ColumnDescription("i2", ValueType.NUMBER, null));
        columnDescriptions.add(new ColumnDescription("i3", ValueType.NUMBER, null));
        columnDescriptions.add(new ColumnDescription("i4", ValueType.NUMBER, null));

        DataTable dataTable = CsvDataSourceHelper.read(reader, columnDescriptions, true);
        assertEquals(2, dataTable.getNumberOfRows());
        assertEquals(4, dataTable.getNumberOfColumns());
        assertEquals(new NumberValue(4), dataTable.getRow(0).getCell(0).getValue());
View Full Code Here

        assertEquals("3", dataTable.getColumnDescription(3).getLabel());
    }

    public void testReadWithLocale() throws IOException, CsvDataSourceException {
        List<ColumnDescription> columnDescriptions = Lists.newArrayList();
        columnDescriptions.add(new ColumnDescription("A", ValueType.NUMBER, "A"));
        columnDescriptions.add(new ColumnDescription("B", ValueType.TIMEOFDAY, "B"));
        TimeOfDayValue hindiTimeOfDayValue = new TimeOfDayValue(1, 12, 1);
        String hindiTimeOfDayString = "\u0966\u0967\u003a\u0967\u0968\u003a\u0966\u0967";
        Reader reader = new StringReader("1," + hindiTimeOfDayString);
        DataTable dataTable = CsvDataSourceHelper.read(reader, columnDescriptions, false,
                new ULocale("hi_IN"));
View Full Code Here

    public void testGetValue() {
        ScalarFunction scalarFunction = TimeComponentExtractor.getInstance(
                TimeComponentExtractor.TimeComponent.YEAR);

        DataTable table = new DataTable();
        table.addColumn(new ColumnDescription("dateCol", ValueType.DATE, "dateCol"));
        table.addColumn(new ColumnDescription("numberCol", ValueType.NUMBER, "numberCol"));
        table.addColumn(new ColumnDescription("timeOfDayCol", ValueType.TIMEOFDAY, "timeOfDayCol"));
        table.addColumn(new ColumnDescription("dateTimeCol", ValueType.DATETIME, "dateTimeCol"));

        TableRow row = new TableRow();
        row.addCell(new TableCell(new DateValue(2008, 5, 3)));
        row.addCell(new TableCell(new NumberValue(23)));
        row.addCell(new TableCell(new TimeOfDayValue(13, 12, 11)));
View Full Code Here

    public void testGetValueType() {
        ScalarFunction scalarFunction = TimeComponentExtractor.getInstance(
                TimeComponentExtractor.TimeComponent.YEAR);
        DataTable table = new DataTable();
        table.addColumn(new ColumnDescription("dateCol", ValueType.DATE, "dateCol"));
        List<AbstractColumn> columns =
                Lists.newArrayList((AbstractColumn) new SimpleColumn("dateCol"));
        ScalarFunctionColumn sfc = new ScalarFunctionColumn(columns, scalarFunction);
        ValueType valueType = sfc.getValueType(table);
        assertEquals(ValueType.NUMBER, valueType);
View Full Code Here

        row.addCell(new TableCell("a"));
        row.addCell(new TableCell(123));
        row.addCell(new TableCell("a"));

        DataTable table = new DataTable();
        table.addColumn(new ColumnDescription("c1", ValueType.TEXT, "c1"));
        table.addColumn(new ColumnDescription("c2", ValueType.TEXT, "c2"));
        table.addColumn(new ColumnDescription("c3", ValueType.TEXT, "c3"));

        ColumnColumnFilter filter = new ColumnColumnFilter(new SimpleColumn("c1"),
                new SimpleColumn("c3"), ComparisonFilter.Operator.LE);
        assertTrue(filter.isMatch(table, row));
    }
View Full Code Here

TOP

Related Classes of com.google.visualization.datasource.datatable.ColumnDescription

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.