Search in sources :

Example 51 with Table

use of org.apache.calcite.schema.Table in project druid by druid-io.

the class DruidSchemaTest method testGetTableMap.

@Test
public void testGetTableMap() {
    Assert.assertEquals(ImmutableSet.of("foo", "foo2"), schema.getTableNames());
    final Map<String, Table> tableMap = schema.getTableMap();
    Assert.assertEquals(ImmutableSet.of("foo", "foo2"), tableMap.keySet());
    final DruidTable fooTable = (DruidTable) tableMap.get("foo");
    final RelDataType rowType = fooTable.getRowType(new JavaTypeFactoryImpl());
    final List<RelDataTypeField> fields = rowType.getFieldList();
    Assert.assertEquals(6, fields.size());
    Assert.assertEquals("__time", fields.get(0).getName());
    Assert.assertEquals(SqlTypeName.TIMESTAMP, fields.get(0).getType().getSqlTypeName());
    Assert.assertEquals("cnt", fields.get(1).getName());
    Assert.assertEquals(SqlTypeName.BIGINT, fields.get(1).getType().getSqlTypeName());
    Assert.assertEquals("dim1", fields.get(2).getName());
    Assert.assertEquals(SqlTypeName.VARCHAR, fields.get(2).getType().getSqlTypeName());
    Assert.assertEquals("m1", fields.get(3).getName());
    Assert.assertEquals(SqlTypeName.BIGINT, fields.get(3).getType().getSqlTypeName());
    Assert.assertEquals("unique_dim1", fields.get(4).getName());
    Assert.assertEquals(SqlTypeName.OTHER, fields.get(4).getType().getSqlTypeName());
    Assert.assertEquals("dim2", fields.get(5).getName());
    Assert.assertEquals(SqlTypeName.VARCHAR, fields.get(5).getType().getSqlTypeName());
}
Also used : RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) DruidTable(io.druid.sql.calcite.table.DruidTable) Table(org.apache.calcite.schema.Table) JavaTypeFactoryImpl(org.apache.calcite.jdbc.JavaTypeFactoryImpl) DruidTable(io.druid.sql.calcite.table.DruidTable) RelDataType(org.apache.calcite.rel.type.RelDataType) Test(org.junit.Test)

Example 52 with Table

use of org.apache.calcite.schema.Table in project drill by apache.

the class AbstractSchema method getTablesByNames.

/**
   * Get the collection of {@link Table} tables specified in the tableNames.
   *
   * @param  tableNames the requested tables, specified by the table names
   * @return the collection of requested tables
   */
public List<Pair<String, ? extends Table>> getTablesByNames(final List<String> tableNames) {
    final List<Pair<String, ? extends Table>> tables = Lists.newArrayList();
    for (String tableName : tableNames) {
        final Table table = getTable(tableName);
        if (table == null) {
            // tables as INFO SCHEMA is about showing tables which the use has access to query.
            continue;
        }
        tables.add(Pair.of(tableName, table));
    }
    return tables;
}
Also used : Table(org.apache.calcite.schema.Table) Pair(org.apache.commons.lang3.tuple.Pair)

Example 53 with Table

use of org.apache.calcite.schema.Table in project lucene-solr by apache.

the class SolrSchema method getTableMap.

@Override
protected Map<String, Table> getTableMap() {
    String zk = this.properties.getProperty("zk");
    try (CloudSolrClient cloudSolrClient = new CloudSolrClient.Builder().withZkHost(zk).build()) {
        cloudSolrClient.connect();
        ZkStateReader zkStateReader = cloudSolrClient.getZkStateReader();
        ClusterState clusterState = zkStateReader.getClusterState();
        final ImmutableMap.Builder<String, Table> builder = ImmutableMap.builder();
        for (String collection : clusterState.getCollectionsMap().keySet()) {
            builder.put(collection, new SolrTable(this, collection));
        }
        Aliases aliases = zkStateReader.getAliases();
        if (aliases.collectionAliasSize() > 0) {
            for (Map.Entry<String, String> alias : aliases.getCollectionAliasMap().entrySet()) {
                builder.put(alias.getKey(), new SolrTable(this, alias.getValue()));
            }
        }
        return builder.build();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : ClusterState(org.apache.solr.common.cloud.ClusterState) Table(org.apache.calcite.schema.Table) Aliases(org.apache.solr.common.cloud.Aliases) IOException(java.io.IOException) ImmutableMap(com.google.common.collect.ImmutableMap) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient) ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map)

Example 54 with Table

use of org.apache.calcite.schema.Table in project drill by axbaretto.

the class AbstractSchema method getTablesByNames.

/**
 * Get the collection of {@link Table} tables specified in the tableNames.
 *
 * @param  tableNames the requested tables, specified by the table names
 * @return the collection of requested tables
 */
public List<Pair<String, ? extends Table>> getTablesByNames(final List<String> tableNames) {
    final List<Pair<String, ? extends Table>> tables = Lists.newArrayList();
    for (String tableName : tableNames) {
        final Table table = getTable(tableName);
        if (table == null) {
            // tables as INFO SCHEMA is about showing tables which the use has access to query.
            continue;
        }
        tables.add(Pair.of(tableName, table));
    }
    return tables;
}
Also used : Table(org.apache.calcite.schema.Table) Pair(org.apache.commons.lang3.tuple.Pair)

Example 55 with Table

use of org.apache.calcite.schema.Table in project drill by axbaretto.

the class DirPrunedEnumerableTableScan method create.

/**
 * Creates an DirPrunedEnumerableTableScan.
 */
public static EnumerableTableScan create(RelOptCluster cluster, RelOptTable relOptTable, String digestFromSelection) {
    final Table table = relOptTable.unwrap(Table.class);
    Class elementType = EnumerableTableScan.deduceElementType(table);
    final RelTraitSet traitSet = cluster.traitSetOf(EnumerableConvention.INSTANCE).replaceIfs(RelCollationTraitDef.INSTANCE, new Supplier<List<RelCollation>>() {

        public List<RelCollation> get() {
            if (table != null) {
                return table.getStatistic().getCollations();
            }
            return ImmutableList.of();
        }
    });
    return new DirPrunedEnumerableTableScan(cluster, traitSet, relOptTable, elementType, digestFromSelection);
}
Also used : Table(org.apache.calcite.schema.Table) RelOptTable(org.apache.calcite.plan.RelOptTable) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) RelTraitSet(org.apache.calcite.plan.RelTraitSet)

Aggregations

Table (org.apache.calcite.schema.Table)104 SqlStdOperatorTable (org.apache.calcite.sql.fun.SqlStdOperatorTable)38 RelOptTable (org.apache.calcite.plan.RelOptTable)33 Test (org.junit.Test)27 RelDataType (org.apache.calcite.rel.type.RelDataType)22 SqlOperatorTable (org.apache.calcite.sql.SqlOperatorTable)22 SchemaPlus (org.apache.calcite.schema.SchemaPlus)20 ProjectableFilterableTable (org.apache.calcite.schema.ProjectableFilterableTable)17 ScannableTable (org.apache.calcite.schema.ScannableTable)17 JavaTypeFactoryImpl (org.apache.calcite.jdbc.JavaTypeFactoryImpl)16 FilterableTable (org.apache.calcite.schema.FilterableTable)15 AbstractTable (org.apache.calcite.schema.impl.AbstractTable)15 StreamableTable (org.apache.calcite.schema.StreamableTable)14 ArrayList (java.util.ArrayList)13 ModifiableViewTable (org.apache.calcite.schema.impl.ModifiableViewTable)13 JavaTypeFactory (org.apache.calcite.adapter.java.JavaTypeFactory)12 RelNode (org.apache.calcite.rel.RelNode)12 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)10 BitString (org.apache.calcite.util.BitString)10 ImmutableMap (com.google.common.collect.ImmutableMap)9