Package org.apache.metamodel

Examples of org.apache.metamodel.DataContext


    Column fooColumn = source.getColumnByQualifiedLabel("schema.table.foo");
    assertNotNull(fooColumn);

    Map<Column, TypeConverter<?, ?>> converters = new HashMap<Column, TypeConverter<?, ?>>();
    converters.put(fooColumn, new StringToIntegerConverter());
    DataContext converted = Converters.addTypeConverter(source, fooColumn,
        new StringToIntegerConverter());

    // only select "bar" which is not converted
    Table table = converted.getDefaultSchema().getTableByName("table");
    Query query = converted.query().from(table).select("bar").toQuery();
    assertEquals("SELECT table.bar FROM schema.table", query.toSql());

    DataSet ds = converted.executeQuery(query);
    assertEquals(InMemoryDataSet.class, ds.getClass());

  }
View Full Code Here


        if (delegate == null) {
            throw new UnsupportedOperationException("Unsupported DataContext type: " + _type);
        }

        final DataContext dataContext = delegate.createDataContext(this);
        if (dataContext == null) {
            throw new IllegalStateException("Factory method failed to produce a non-null DataContext instance");
        }

        return dataContext;
View Full Code Here

                .readFileAsString(targetFile).replaceAll("\n", "!LINEBREAK!"));
    }

    public void testHandlingOfEmptyLinesMultipleLinesSupport() throws Exception {
        // test with multiline values
        DataContext dc = new CsvDataContext(new File("src/test/resources/csv_with_empty_lines.csv"),
                new CsvConfiguration(1, false, true));
        testHandlingOfEmptyLines(dc);
    }
View Full Code Here

        testHandlingOfEmptyLines(dc);
    }

    public void testHandlingOfEmptyLinesSingleLinesSupport() throws Exception {
        // test with only single line values
        DataContext dc = new CsvDataContext(new File("src/test/resources/csv_with_empty_lines.csv"),
                new CsvConfiguration(1, false, false));
        testHandlingOfEmptyLines(dc);
    }
View Full Code Here

        assertFalse(ds.next());
        ds.close();
    }

    public void testEmptyFileNoHeaderLine() throws Exception {
        DataContext dc = new CsvDataContext(new File("src/test/resources/empty_file.csv"), new CsvConfiguration(
                CsvConfiguration.NO_COLUMN_NAME_LINE));
        assertEquals(1, dc.getDefaultSchema().getTableCount());

        Table table = dc.getDefaultSchema().getTables()[0];
        assertEquals("empty_file.csv", table.getName());
        assertEquals(0, table.getColumnCount());
    }
View Full Code Here

        assertEquals("empty_file.csv", table.getName());
        assertEquals(0, table.getColumnCount());
    }

    public void testUnexistingHeaderLine() throws Exception {
        DataContext dc = new CsvDataContext(new File("src/test/resources/csv_people.csv"), new CsvConfiguration(20));
        assertEquals(1, dc.getDefaultSchema().getTableCount());

        Table table = dc.getDefaultSchema().getTables()[0];
        assertEquals("csv_people.csv", table.getName());
        assertEquals(0, table.getColumnCount());
    }
View Full Code Here

    }

    public void testInconsistentColumns() throws Exception {
        CsvConfiguration conf = new CsvConfiguration(CsvConfiguration.DEFAULT_COLUMN_NAME_LINE, "UTF8", ',', '"', '\\',
                true);
        DataContext dc = new CsvDataContext(new File("src/test/resources/csv_inconsistent_columns.csv"), conf);
        DataSet ds = dc.query().from("csv_inconsistent_columns.csv").select("hello").and("world").execute();
        assertTrue(ds.next());
        assertTrue(ds.next());

        try {
            ds.next();
View Full Code Here

        assertTrue(ds.next());
        assertFalse(ds.next());
    }

    public void testApproximatedCountSmallFile() throws Exception {
        DataContext dc = new CsvDataContext(new File("src/test/resources/csv_people.csv"));

        Table table = dc.getDefaultSchema().getTables()[0];
        Query q = dc.query().from(table).selectCount().toQuery();
        SelectItem selectItem = q.getSelectClause().getItem(0);
        selectItem.setFunctionApproximationAllowed(true);

        DataSet ds = dc.executeQuery(q);
        assertTrue(ds.next());
        Object[] values = ds.getRow().getValues();
        assertEquals(1, values.length);
        assertEquals(9, ((Long) ds.getRow().getValue(selectItem)).intValue());
        assertEquals(9, ((Long) values[0]).intValue());
View Full Code Here

        assertEquals("[michael]", Arrays.toString(result.get(0)));
        assertEquals("[hillary]", Arrays.toString(result.get(1)));
    }

    public void testGetFromInputStream() throws Exception {
        DataContext dc = null;

        // repeat this step a few times to test temp-file creation, see Ticket
        // #437
        for (int i = 0; i < 5; i++) {
            File file = new File("src/test/resources/tickets.csv");
            FileInputStream inputStream = new FileInputStream(file);
            dc = new CsvDataContext(inputStream, new CsvConfiguration());
        }

        Schema schema = dc.getDefaultSchema();
        String name = schema.getTable(0).getName();
        assertTrue(name.startsWith("metamodel"));
        assertTrue(name.endsWith("csv"));

        // Test two seperate reads to ensure that the temp file is working
View Full Code Here

        doTicketFileTests(dc);
    }

    public void testMultilineExample() throws Exception {
        File file = new File("src/test/resources/tickets.csv");
        DataContext dc = new CsvDataContext(file);
        Schema schema = dc.getDefaultSchema();
        Table table = schema.getTableByName("tickets.csv");
        Column descColumn = table.getColumnByName("_description");

        assertNotNull(table);
        assertNotNull(descColumn);
View Full Code Here

TOP

Related Classes of org.apache.metamodel.DataContext

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.