Search in sources :

Example 6 with Table

use of com.hazelcast.sql.impl.schema.Table in project hazelcast by hazelcast.

the class TableResolverImpl method getTables.

@Nonnull
@Override
public List<Table> getTables() {
    Collection<Object> objects = tableStorage.allObjects();
    List<Table> tables = new ArrayList<>(objects.size() + 3);
    for (Object o : objects) {
        if (o instanceof Mapping) {
            tables.add(toTable((Mapping) o));
        } else if (o instanceof View) {
            tables.add(toTable((View) o));
        } else {
            throw new RuntimeException("Unexpected: " + o);
        }
    }
    Collection<Mapping> mappings = objects.stream().filter(o -> o instanceof Mapping).map(m -> (Mapping) m).collect(Collectors.toList());
    Collection<View> views = objects.stream().filter(o -> o instanceof View).map(v -> (View) v).collect(Collectors.toList());
    tables.add(new TablesTable(CATALOG, SCHEMA_NAME_INFORMATION_SCHEMA, SCHEMA_NAME_PUBLIC, mappings, views));
    tables.add(new MappingsTable(CATALOG, SCHEMA_NAME_INFORMATION_SCHEMA, SCHEMA_NAME_PUBLIC, mappings));
    tables.add(new MappingColumnsTable(CATALOG, SCHEMA_NAME_INFORMATION_SCHEMA, SCHEMA_NAME_PUBLIC, mappings, views));
    tables.add(new ViewsTable(CATALOG, SCHEMA_NAME_INFORMATION_SCHEMA, SCHEMA_NAME_PUBLIC, views));
    return tables;
}
Also used : SqlConnectorCache(com.hazelcast.jet.sql.impl.connector.SqlConnectorCache) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) LinkedHashMap(java.util.LinkedHashMap) ViewsTable(com.hazelcast.jet.sql.impl.connector.infoschema.ViewsTable) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) ConstantTableStatistics(com.hazelcast.sql.impl.schema.ConstantTableStatistics) SqlConnector(com.hazelcast.jet.sql.impl.connector.SqlConnector) MappingsTable(com.hazelcast.jet.sql.impl.connector.infoschema.MappingsTable) View(com.hazelcast.sql.impl.schema.view.View) Nonnull(javax.annotation.Nonnull) QueryException(com.hazelcast.sql.impl.QueryException) EntryEvent(com.hazelcast.core.EntryEvent) ViewTable(com.hazelcast.jet.sql.impl.connector.virtual.ViewTable) NodeEngine(com.hazelcast.spi.impl.NodeEngine) Collection(java.util.Collection) MappingColumnsTable(com.hazelcast.jet.sql.impl.connector.infoschema.MappingColumnsTable) Collectors(java.util.stream.Collectors) Mapping(com.hazelcast.sql.impl.schema.Mapping) TableField(com.hazelcast.sql.impl.schema.TableField) TablesTable(com.hazelcast.jet.sql.impl.connector.infoschema.TablesTable) TableResolver(com.hazelcast.sql.impl.schema.TableResolver) List(java.util.List) CATALOG(com.hazelcast.sql.impl.QueryUtils.CATALOG) MappingField(com.hazelcast.sql.impl.schema.MappingField) Table(com.hazelcast.sql.impl.schema.Table) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ViewsTable(com.hazelcast.jet.sql.impl.connector.infoschema.ViewsTable) MappingsTable(com.hazelcast.jet.sql.impl.connector.infoschema.MappingsTable) ViewTable(com.hazelcast.jet.sql.impl.connector.virtual.ViewTable) MappingColumnsTable(com.hazelcast.jet.sql.impl.connector.infoschema.MappingColumnsTable) TablesTable(com.hazelcast.jet.sql.impl.connector.infoschema.TablesTable) Table(com.hazelcast.sql.impl.schema.Table) ViewsTable(com.hazelcast.jet.sql.impl.connector.infoschema.ViewsTable) TablesTable(com.hazelcast.jet.sql.impl.connector.infoschema.TablesTable) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Mapping(com.hazelcast.sql.impl.schema.Mapping) View(com.hazelcast.sql.impl.schema.view.View) MappingsTable(com.hazelcast.jet.sql.impl.connector.infoschema.MappingsTable) MappingColumnsTable(com.hazelcast.jet.sql.impl.connector.infoschema.MappingColumnsTable) Nonnull(javax.annotation.Nonnull)

Example 7 with Table

use of com.hazelcast.sql.impl.schema.Table in project hazelcast by hazelcast.

the class TestAbstractSqlConnector method fullScanReader.

@Nonnull
@Override
public Vertex fullScanReader(@Nonnull DAG dag, @Nonnull Table table_, @Nullable Expression<Boolean> predicate, @Nonnull List<Expression<?>> projection, @Nullable FunctionEx<ExpressionEvalContext, EventTimePolicy<JetSqlRow>> eventTimePolicyProvider) {
    TestTable table = (TestTable) table_;
    List<Object[]> rows = table.rows;
    boolean streaming = table.streaming;
    FunctionEx<Context, TestDataGenerator> createContextFn = ctx -> {
        ExpressionEvalContext evalContext = ExpressionEvalContext.from(ctx);
        EventTimePolicy<JetSqlRow> eventTimePolicy = eventTimePolicyProvider == null ? EventTimePolicy.noEventTime() : eventTimePolicyProvider.apply(evalContext);
        return new TestDataGenerator(rows, predicate, projection, evalContext, eventTimePolicy, streaming);
    };
    ProcessorMetaSupplier pms = createProcessorSupplier(createContextFn);
    return dag.newUniqueVertex(table.toString(), pms);
}
Also used : ExpressionEvalContext(com.hazelcast.sql.impl.expression.ExpressionEvalContext) Context(com.hazelcast.jet.core.Processor.Context) Traverser(com.hazelcast.jet.Traverser) Arrays(java.util.Arrays) PlanObjectKey(com.hazelcast.sql.impl.optimizer.PlanObjectKey) EventTimePolicy(com.hazelcast.jet.core.EventTimePolicy) QueryDataTypeFamily(com.hazelcast.sql.impl.type.QueryDataTypeFamily) ArrayList(java.util.ArrayList) JetSqlRow(com.hazelcast.sql.impl.row.JetSqlRow) String.join(java.lang.String.join) Map(java.util.Map) ConstantTableStatistics(com.hazelcast.sql.impl.schema.ConstantTableStatistics) SqlConnector(com.hazelcast.jet.sql.impl.connector.SqlConnector) DAG(com.hazelcast.jet.core.DAG) Expression(com.hazelcast.sql.impl.expression.Expression) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) EventTimeMapper(com.hazelcast.jet.core.EventTimeMapper) QueryException(com.hazelcast.sql.impl.QueryException) FunctionEx(com.hazelcast.function.FunctionEx) SqlService(com.hazelcast.sql.SqlService) NodeEngine(com.hazelcast.spi.impl.NodeEngine) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier) JetTable(com.hazelcast.jet.sql.impl.schema.JetTable) Traversers(com.hazelcast.jet.Traversers) ExpressionUtil(com.hazelcast.jet.sql.impl.ExpressionUtil) Collectors.joining(java.util.stream.Collectors.joining) Objects(java.util.Objects) Vertex(com.hazelcast.jet.core.Vertex) TableField(com.hazelcast.sql.impl.schema.TableField) List(java.util.List) ExpressionEvalContext(com.hazelcast.sql.impl.expression.ExpressionEvalContext) QueryDataTypeUtils.resolveTypeForTypeFamily(com.hazelcast.sql.impl.type.QueryDataTypeUtils.resolveTypeForTypeFamily) Context(com.hazelcast.jet.core.Processor.Context) MappingField(com.hazelcast.sql.impl.schema.MappingField) SourceBuilder(com.hazelcast.jet.pipeline.SourceBuilder) Table(com.hazelcast.sql.impl.schema.Table) ExpressionEvalContext(com.hazelcast.sql.impl.expression.ExpressionEvalContext) EventTimePolicy(com.hazelcast.jet.core.EventTimePolicy) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier) Nonnull(javax.annotation.Nonnull)

Example 8 with Table

use of com.hazelcast.sql.impl.schema.Table in project hazelcast by hazelcast.

the class TestAllTypesSqlConnector method fullScanReader.

@Nonnull
@Override
public Vertex fullScanReader(@Nonnull DAG dag, @Nonnull Table table, @Nullable Expression<Boolean> predicate, @Nonnull List<Expression<?>> projection, @Nullable FunctionEx<ExpressionEvalContext, EventTimePolicy<JetSqlRow>> eventTimePolicyProvider) {
    if (eventTimePolicyProvider != null) {
        throw QueryException.error("Ordering function are not supported for " + TYPE_NAME + " mappings");
    }
    BatchSource<JetSqlRow> source = SourceBuilder.batch("batch", ExpressionEvalContext::from).<JetSqlRow>fillBufferFn((ctx, buf) -> {
        JetSqlRow row = ExpressionUtil.evaluate(predicate, projection, VALUES, ctx);
        if (row != null) {
            buf.add(row);
        }
        buf.close();
    }).build();
    ProcessorMetaSupplier pms = ((BatchSourceTransform<JetSqlRow>) source).metaSupplier;
    return dag.newUniqueVertex(table.toString(), pms);
}
Also used : ExpressionEvalContext(com.hazelcast.sql.impl.expression.ExpressionEvalContext) QueryDataType(com.hazelcast.sql.impl.type.QueryDataType) LocalDateTime(java.time.LocalDateTime) PlanObjectKey(com.hazelcast.sql.impl.optimizer.PlanObjectKey) EventTimePolicy(com.hazelcast.jet.core.EventTimePolicy) JetSqlRow(com.hazelcast.sql.impl.row.JetSqlRow) BigDecimal(java.math.BigDecimal) TEST_SS(com.hazelcast.jet.sql.SqlTestSupport.TEST_SS) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) ConstantTableStatistics(com.hazelcast.sql.impl.schema.ConstantTableStatistics) LocalTime(java.time.LocalTime) SqlConnector(com.hazelcast.jet.sql.impl.connector.SqlConnector) DAG(com.hazelcast.jet.core.DAG) Expression(com.hazelcast.sql.impl.expression.Expression) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) QueryException(com.hazelcast.sql.impl.QueryException) FunctionEx(com.hazelcast.function.FunctionEx) SqlService(com.hazelcast.sql.SqlService) NodeEngine(com.hazelcast.spi.impl.NodeEngine) BatchSource(com.hazelcast.jet.pipeline.BatchSource) Util.toList(com.hazelcast.jet.impl.util.Util.toList) ImmutableMap(com.google.common.collect.ImmutableMap) BatchSourceTransform(com.hazelcast.jet.impl.pipeline.transform.BatchSourceTransform) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier) JetTable(com.hazelcast.jet.sql.impl.schema.JetTable) SqlTestSupport(com.hazelcast.jet.sql.SqlTestSupport) ExpressionUtil(com.hazelcast.jet.sql.impl.ExpressionUtil) Objects(java.util.Objects) Vertex(com.hazelcast.jet.core.Vertex) TableField(com.hazelcast.sql.impl.schema.TableField) List(java.util.List) ExpressionEvalContext(com.hazelcast.sql.impl.expression.ExpressionEvalContext) OffsetDateTime(java.time.OffsetDateTime) LocalDate(java.time.LocalDate) UTC(java.time.ZoneOffset.UTC) MappingField(com.hazelcast.sql.impl.schema.MappingField) SourceBuilder(com.hazelcast.jet.pipeline.SourceBuilder) Table(com.hazelcast.sql.impl.schema.Table) JetSqlRow(com.hazelcast.sql.impl.row.JetSqlRow) BatchSourceTransform(com.hazelcast.jet.impl.pipeline.transform.BatchSourceTransform) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier) Nonnull(javax.annotation.Nonnull)

Example 9 with Table

use of com.hazelcast.sql.impl.schema.Table in project hazelcast by hazelcast.

the class PlanCacheChecker method check.

public void check() {
    if (planCache.size() == 0) {
        return;
    }
    // Collect object IDs
    SqlCatalog catalog = new SqlCatalog(tableResolvers);
    Set<PlanObjectKey> objectKeys = new HashSet<>();
    for (Map<String, Table> tableMap : catalog.getSchemas().values()) {
        for (Table table : tableMap.values()) {
            PlanObjectKey objectKey = table.getObjectKey();
            if (objectKey != null) {
                objectKeys.add(objectKey);
            }
        }
    }
    // Prepare partition distribution
    Map<UUID, PartitionIdSet> partitions = QueryUtils.createPartitionMap(nodeEngine, null, false);
    // Do check
    planCache.check(new PlanCheckContext(objectKeys, partitions));
}
Also used : SqlCatalog(com.hazelcast.sql.impl.schema.SqlCatalog) PlanCheckContext(com.hazelcast.sql.impl.optimizer.PlanCheckContext) Table(com.hazelcast.sql.impl.schema.Table) PlanObjectKey(com.hazelcast.sql.impl.optimizer.PlanObjectKey) PartitionIdSet(com.hazelcast.internal.util.collection.PartitionIdSet) UUID(java.util.UUID) HashSet(java.util.HashSet)

Example 10 with Table

use of com.hazelcast.sql.impl.schema.Table in project hazelcast by hazelcast.

the class CreateDagVisitor method onMapIndexScan.

public Vertex onMapIndexScan(IndexScanMapPhysicalRel rel) {
    Table table = rel.getTable().unwrap(HazelcastTable.class).getTarget();
    collectObjectKeys(table);
    return SqlConnectorUtil.<IMapSqlConnector>getJetSqlConnector(table).indexScanReader(dag, localMemberAddress, table, rel.getIndex(), rel.filter(parameterMetadata), rel.projection(parameterMetadata), rel.getIndexFilter(), rel.getComparator(), rel.isDescending());
}
Also used : HazelcastTable(com.hazelcast.jet.sql.impl.schema.HazelcastTable) Table(com.hazelcast.sql.impl.schema.Table) HazelcastTable(com.hazelcast.jet.sql.impl.schema.HazelcastTable)

Aggregations

Table (com.hazelcast.sql.impl.schema.Table)14 HazelcastTable (com.hazelcast.jet.sql.impl.schema.HazelcastTable)9 Vertex (com.hazelcast.jet.core.Vertex)7 SqlConnector (com.hazelcast.jet.sql.impl.connector.SqlConnector)5 Map (java.util.Map)4 NodeEngine (com.hazelcast.spi.impl.NodeEngine)3 QueryException (com.hazelcast.sql.impl.QueryException)3 PlanObjectKey (com.hazelcast.sql.impl.optimizer.PlanObjectKey)3 ConstantTableStatistics (com.hazelcast.sql.impl.schema.ConstantTableStatistics)3 MappingField (com.hazelcast.sql.impl.schema.MappingField)3 TableField (com.hazelcast.sql.impl.schema.TableField)3 List (java.util.List)3 Nonnull (javax.annotation.Nonnull)3 FunctionEx (com.hazelcast.function.FunctionEx)2 DAG (com.hazelcast.jet.core.DAG)2 EventTimePolicy (com.hazelcast.jet.core.EventTimePolicy)2 ProcessorMetaSupplier (com.hazelcast.jet.core.ProcessorMetaSupplier)2 SourceBuilder (com.hazelcast.jet.pipeline.SourceBuilder)2 ExpressionUtil (com.hazelcast.jet.sql.impl.ExpressionUtil)2 VertexWithInputConfig (com.hazelcast.jet.sql.impl.connector.SqlConnector.VertexWithInputConfig)2