Search in sources :

Example 91 with Table

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

the class Elasticsearch5Schema method getTableMap.

@Override
protected Map<String, Table> getTableMap() {
    final ImmutableMap.Builder<String, Table> builder = ImmutableMap.builder();
    try {
        final GetMappingsResponse response = client.admin().indices().getMappings(new GetMappingsRequest().indices(index)).get();
        ImmutableOpenMap<String, MappingMetaData> mapping = response.getMappings().get(index);
        for (ObjectObjectCursor<String, MappingMetaData> c : mapping) {
            builder.put(c.key, new Elasticsearch5Table(client, index, c.key));
        }
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return builder.build();
}
Also used : Table(org.apache.calcite.schema.Table) MappingMetaData(org.elasticsearch.cluster.metadata.MappingMetaData) GetMappingsRequest(org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest) ImmutableMap(com.google.common.collect.ImmutableMap) GetMappingsResponse(org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse)

Example 92 with Table

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

the class GeodeSchema method getTableMap.

@Override
protected Map<String, Table> getTableMap() {
    if (tableMap == null) {
        final ImmutableMap.Builder<String, Table> builder = ImmutableMap.builder();
        // Extract the first entity of each Regions and use it to build a table types
        for (String regionName : regionNames) {
            Region region = GeodeUtils.createRegionProxy(clientCache, regionName);
            Iterator regionIterator = region.keySetOnServer().iterator();
            Object firstRegionEntry = region.get(regionIterator.next());
            // TODO: how to handle empty Regions? JMX?
            Table table = new GeodeTable(this, regionName, createRelDataType(firstRegionEntry), clientCache);
            builder.put(regionName, table);
        }
        tableMap = builder.build();
    }
    return tableMap;
}
Also used : Table(org.apache.calcite.schema.Table) Iterator(java.util.Iterator) Region(org.apache.geode.cache.Region) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 93 with Table

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

the class FlinkCalciteCatalogReaderTest method testGetNonFlinkPreparingTableBase.

@Test
public void testGetNonFlinkPreparingTableBase() {
    Table nonFlinkTableMock = mock(Table.class);
    when(nonFlinkTableMock.getRowType(typeFactory)).thenReturn(mock(RelDataType.class));
    rootSchemaPlus.add(tableMockName, nonFlinkTableMock);
    Prepare.PreparingTable resultTable = catalogReader.getTable(Collections.singletonList(tableMockName));
    assertFalse(resultTable instanceof FlinkPreparingTableBase);
}
Also used : ConnectorCatalogTable(org.apache.flink.table.catalog.ConnectorCatalogTable) CatalogSchemaTable(org.apache.flink.table.planner.catalog.CatalogSchemaTable) CatalogTable(org.apache.flink.table.catalog.CatalogTable) ResolvedCatalogTable(org.apache.flink.table.catalog.ResolvedCatalogTable) ContextResolvedTable(org.apache.flink.table.catalog.ContextResolvedTable) Table(org.apache.calcite.schema.Table) Prepare(org.apache.calcite.prepare.Prepare) FlinkPreparingTableBase(org.apache.flink.table.planner.plan.schema.FlinkPreparingTableBase) RelDataType(org.apache.calcite.rel.type.RelDataType) Test(org.junit.Test)

Example 94 with Table

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

the class SqlValidatorImpl method checkConstraint.

/**
 * Validates updates against the constraint of a modifiable view.
 *
 * @param validatorTable A {@link SqlValidatorTable} that may wrap a ModifiableViewTable
 * @param update The UPDATE parse tree node
 * @param targetRowType The target type
 */
private void checkConstraint(SqlValidatorTable validatorTable, SqlUpdate update, RelDataType targetRowType) {
    final ModifiableViewTable modifiableViewTable = validatorTable.unwrap(ModifiableViewTable.class);
    if (modifiableViewTable != null) {
        final Table table = modifiableViewTable.unwrap(Table.class);
        final RelDataType tableRowType = table.getRowType(typeFactory);
        final Map<Integer, RexNode> projectMap = RelOptUtil.getColumnConstraints(modifiableViewTable, targetRowType, typeFactory);
        final Map<String, Integer> nameToIndex = SqlValidatorUtil.mapNameToIndex(tableRowType.getFieldList());
        // Validate update values against the view constraint.
        final List<SqlNode> targets = update.getTargetColumnList().getList();
        final List<SqlNode> sources = update.getSourceExpressionList().getList();
        for (final Pair<SqlNode, SqlNode> column : Pair.zip(targets, sources)) {
            final String columnName = ((SqlIdentifier) column.left).getSimple();
            final Integer columnIndex = nameToIndex.get(columnName);
            if (projectMap.containsKey(columnIndex)) {
                final RexNode columnConstraint = projectMap.get(columnIndex);
                final ValidationError validationError = new ValidationError(column.right, RESOURCE.viewConstraintNotSatisfied(columnName, Util.last(validatorTable.getQualifiedName())));
                RelOptUtil.validateValueAgainstConstraint(column.right, columnConstraint, validationError);
            }
        }
    }
}
Also used : Table(org.apache.calcite.schema.Table) SqlStdOperatorTable(org.apache.calcite.sql.fun.SqlStdOperatorTable) ModifiableViewTable(org.apache.calcite.schema.impl.ModifiableViewTable) RelOptTable(org.apache.calcite.plan.RelOptTable) SqlOperatorTable(org.apache.calcite.sql.SqlOperatorTable) RelDataType(org.apache.calcite.rel.type.RelDataType) BitString(org.apache.calcite.util.BitString) SqlIdentifier(org.apache.calcite.sql.SqlIdentifier) BigInteger(java.math.BigInteger) ModifiableViewTable(org.apache.calcite.schema.impl.ModifiableViewTable) RexNode(org.apache.calcite.rex.RexNode) SqlNode(org.apache.calcite.sql.SqlNode)

Example 95 with Table

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

the class SqlValidatorImpl method isRolledUpColumnAllowedInAgg.

// Returns true iff the given column is valid inside the given aggCall.
private boolean isRolledUpColumnAllowedInAgg(SqlIdentifier identifier, SqlValidatorScope scope, SqlCall aggCall, SqlNode parent) {
    Pair<String, String> pair = findTableColumnPair(identifier, scope);
    if (pair == null) {
        return true;
    }
    String columnName = pair.right;
    SqlValidatorTable sqlValidatorTable = scope.fullyQualify(identifier).namespace.getTable();
    if (sqlValidatorTable != null) {
        Table table = sqlValidatorTable.unwrap(Table.class);
        return table.rolledUpColumnValidInsideAgg(columnName, aggCall, parent, catalogReader.getConfig());
    }
    return true;
}
Also used : Table(org.apache.calcite.schema.Table) SqlStdOperatorTable(org.apache.calcite.sql.fun.SqlStdOperatorTable) ModifiableViewTable(org.apache.calcite.schema.impl.ModifiableViewTable) RelOptTable(org.apache.calcite.plan.RelOptTable) SqlOperatorTable(org.apache.calcite.sql.SqlOperatorTable) BitString(org.apache.calcite.util.BitString)

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