Search in sources :

Example 1 with CsvFilterableTable

use of org.apache.calcite.adapter.csv.CsvFilterableTable in project calcite by apache.

the class FileSchema method addTable.

private boolean addTable(ImmutableMap.Builder<String, Table> builder, Source source, String tableName, Map<String, Object> tableDef) {
    final Source sourceSansGz = source.trim(".gz");
    final Source sourceSansJson = sourceSansGz.trimOrNull(".json");
    if (sourceSansJson != null) {
        JsonTable table = new JsonTable(source);
        builder.put(Util.first(tableName, sourceSansJson.path()), table);
        return true;
    }
    final Source sourceSansCsv = sourceSansGz.trimOrNull(".csv");
    if (sourceSansCsv != null) {
        final Table table = new CsvFilterableTable(source, null);
        builder.put(Util.first(tableName, sourceSansCsv.path()), table);
        return true;
    }
    if (tableDef != null) {
        try {
            FileTable table = FileTable.create(source, tableDef);
            builder.put(Util.first(tableName, source.path()), table);
            return true;
        } catch (Exception e) {
            throw new RuntimeException("Unable to instantiate table for: " + tableName);
        }
    }
    return false;
}
Also used : JsonTable(org.apache.calcite.adapter.csv.JsonTable) Table(org.apache.calcite.schema.Table) CsvFilterableTable(org.apache.calcite.adapter.csv.CsvFilterableTable) JsonTable(org.apache.calcite.adapter.csv.JsonTable) CsvFilterableTable(org.apache.calcite.adapter.csv.CsvFilterableTable) Source(org.apache.calcite.util.Source) MalformedURLException(java.net.MalformedURLException)

Aggregations

MalformedURLException (java.net.MalformedURLException)1 CsvFilterableTable (org.apache.calcite.adapter.csv.CsvFilterableTable)1 JsonTable (org.apache.calcite.adapter.csv.JsonTable)1 Table (org.apache.calcite.schema.Table)1 Source (org.apache.calcite.util.Source)1