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);
}
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"));
}
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();
}
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"));
}
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"));
}
}
Aggregations