Search in sources :

Example 1 with Source

use of org.apache.calcite.util.Source in project calcite by apache.

the class FileSchema method addTable.

private boolean addTable(ImmutableMap.Builder<String, Table> builder, Map<String, Object> tableDef) throws MalformedURLException {
    final String tableName = (String) tableDef.get("name");
    final String url = (String) tableDef.get("url");
    final Source source0 = Sources.url(url);
    final Source source;
    if (baseDirectory == null) {
        source = source0;
    } else {
        source = Sources.of(baseDirectory).append(source0);
    }
    return addTable(builder, source, tableName, tableDef);
}
Also used : Source(org.apache.calcite.util.Source)

Example 2 with Source

use of org.apache.calcite.util.Source in project calcite by apache.

the class FileReaderTest method testFileReaderHeadings.

/**
 * Test {@link FileReader} with static file - headings.
 */
@Test
public void testFileReaderHeadings() throws FileReaderException {
    final Source source = Sources.file(null, file("target/test-classes/tableOK.html"));
    FileReader t = new FileReader(source);
    Elements headings = t.getHeadings();
    assertTrue(headings.get(1).text().equals("H1"));
}
Also used : Elements(org.jsoup.select.Elements) Source(org.apache.calcite.util.Source) Test(org.junit.Test)

Example 3 with Source

use of org.apache.calcite.util.Source in project calcite by apache.

the class FileReaderTest method testFileReaderBadSelector.

/**
 * Tests failed {@link FileReader} instantiation - bad selector.
 */
@Test(expected = FileReaderException.class)
public void testFileReaderBadSelector() throws FileReaderException {
    final Source source = Sources.file(null, file("target/test-classes/tableOK.html"));
    FileReader t = new FileReader(source, "table:eq(1)");
    t.refresh();
}
Also used : Source(org.apache.calcite.util.Source) Test(org.junit.Test)

Example 4 with Source

use of org.apache.calcite.util.Source in project calcite by apache.

the class FileReaderTest method testFileReaderDataBadFile.

/**
 * Tests {@link FileReader} with bad static file - data.
 */
@Test
public void testFileReaderDataBadFile() throws FileReaderException {
    final Source source = Sources.file(null, file("target/test-classes/tableNoTheadTbody.html"));
    FileReader t = new FileReader(source);
    Iterator<Elements> i = t.iterator();
    Elements row = i.next();
    assertTrue(row.get(2).text().equals("R0C2"));
    row = i.next();
    assertTrue(row.get(0).text().equals("R1C0"));
}
Also used : Elements(org.jsoup.select.Elements) Source(org.apache.calcite.util.Source) Test(org.junit.Test)

Example 5 with Source

use of org.apache.calcite.util.Source in project calcite by apache.

the class FileReaderTest method testFileReaderMalUrl.

/**
 * Tests failed {@link FileReader} instantiation - malformed URL.
 */
@Test
public void testFileReaderMalUrl() throws FileReaderException {
    try {
        final Source badSource = Sources.url("bad" + CITIES_SOURCE.path());
        fail("expected exception, got " + badSource);
    } catch (RuntimeException e) {
        assertThat(e.getCause(), instanceOf(MalformedURLException.class));
        assertThat(e.getCause().getMessage(), is("unknown protocol: badhttp"));
    }
}
Also used : Source(org.apache.calcite.util.Source) Test(org.junit.Test)

Aggregations

Source (org.apache.calcite.util.Source)14 Test (org.junit.Test)8 Elements (org.jsoup.select.Elements)6 File (java.io.File)4 Table (org.apache.calcite.schema.Table)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 FilenameFilter (java.io.FilenameFilter)2 MalformedURLException (java.net.MalformedURLException)2 CsvFilterableTable (org.apache.calcite.adapter.csv.CsvFilterableTable)2 JsonTable (org.apache.calcite.adapter.csv.JsonTable)2 RelProtoDataType (org.apache.calcite.rel.type.RelProtoDataType)2