Search in sources :

Example 6 with JetSqlRow

use of com.hazelcast.sql.impl.row.JetSqlRow in project hazelcast by hazelcast.

the class Projector method project.

Object project(JetSqlRow values) {
    Row row = values.getRow();
    target.init();
    for (int i = 0; i < injectors.length; i++) {
        Object projected = evaluate(projection.get(i), row, evalContext);
        Object value = getToConverter(types[i]).convert(projected);
        injectors[i].set(value);
    }
    return target.conclude();
}
Also used : JetSqlRow(com.hazelcast.sql.impl.row.JetSqlRow) Row(com.hazelcast.sql.impl.row.Row)

Example 7 with JetSqlRow

use of com.hazelcast.sql.impl.row.JetSqlRow in project hazelcast by hazelcast.

the class StreamSqlConnector method fullScanReader.

@Nonnull
@Override
public Vertex fullScanReader(@Nonnull DAG dag, @Nonnull Table table0, @Nullable Expression<Boolean> predicate, @Nonnull List<Expression<?>> projections, @Nullable FunctionEx<ExpressionEvalContext, EventTimePolicy<JetSqlRow>> eventTimePolicyProvider) {
    if (eventTimePolicyProvider != null) {
        throw QueryException.error("Ordering functions are not supported on top of " + TYPE_NAME + " mappings");
    }
    StreamTable table = (StreamTable) table0;
    StreamSourceTransform<JetSqlRow> source = (StreamSourceTransform<JetSqlRow>) table.items(predicate, projections);
    ProcessorMetaSupplier pms = source.metaSupplierFn.apply(EventTimePolicy.noEventTime());
    return dag.newUniqueVertex(table.toString(), pms);
}
Also used : StreamSourceTransform(com.hazelcast.jet.impl.pipeline.transform.StreamSourceTransform) JetSqlRow(com.hazelcast.sql.impl.row.JetSqlRow) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier) Nonnull(javax.annotation.Nonnull)

Example 8 with JetSqlRow

use of com.hazelcast.sql.impl.row.JetSqlRow in project hazelcast by hazelcast.

the class SeriesSqlConnector method fullScanReader.

@Nonnull
@Override
public Vertex fullScanReader(@Nonnull DAG dag, @Nonnull Table table0, @Nullable Expression<Boolean> predicate, @Nonnull List<Expression<?>> projections, @Nullable FunctionEx<ExpressionEvalContext, EventTimePolicy<JetSqlRow>> eventTimePolicyProvider) {
    if (eventTimePolicyProvider != null) {
        throw QueryException.error("Ordering functions are not supported on top of " + TYPE_NAME + " mappings");
    }
    SeriesTable table = (SeriesTable) table0;
    BatchSource<JetSqlRow> source = table.items(predicate, projections);
    ProcessorMetaSupplier pms = ((BatchSourceTransform<JetSqlRow>) source).metaSupplier;
    return dag.newUniqueVertex(table.toString(), pms);
}
Also used : 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 JetSqlRow

use of com.hazelcast.sql.impl.row.JetSqlRow in project hazelcast by hazelcast.

the class CreateDagVisitor method onSlidingWindowAggregate.

public Vertex onSlidingWindowAggregate(SlidingWindowAggregatePhysicalRel rel) {
    FunctionEx<JetSqlRow, ?> groupKeyFn = rel.groupKeyFn();
    AggregateOperation<?, JetSqlRow> aggregateOperation = rel.aggrOp();
    Expression<?> timestampExpression = rel.timestampExpression();
    ToLongFunctionEx<JetSqlRow> timestampFn = row -> WindowUtils.extractMillis(timestampExpression.eval(row.getRow(), MOCK_EEC));
    SlidingWindowPolicy windowPolicy = rel.windowPolicyProvider().apply(MOCK_EEC);
    KeyedWindowResultFunction<? super Object, ? super JetSqlRow, ?> resultMapping = rel.outputValueMapping();
    if (rel.numStages() == 1) {
        Vertex vertex = dag.newUniqueVertex("Sliding-Window-AggregateByKey", Processors.aggregateToSlidingWindowP(singletonList(groupKeyFn), singletonList(timestampFn), TimestampKind.EVENT, windowPolicy, 0, aggregateOperation, resultMapping));
        connectInput(rel.getInput(), vertex, edge -> edge.distributeTo(localMemberAddress).allToOne(""));
        return vertex;
    } else {
        assert rel.numStages() == 2;
        Vertex vertex1 = dag.newUniqueVertex("Sliding-Window-AccumulateByKey", Processors.accumulateByFrameP(singletonList(groupKeyFn), singletonList(timestampFn), TimestampKind.EVENT, windowPolicy, aggregateOperation));
        Vertex vertex2 = dag.newUniqueVertex("Sliding-Window-CombineByKey", Processors.combineToSlidingWindowP(windowPolicy, aggregateOperation, resultMapping));
        connectInput(rel.getInput(), vertex1, edge -> edge.partitioned(groupKeyFn));
        dag.edge(between(vertex1, vertex2).distributed().partitioned(entryKey()));
        return vertex2;
    }
}
Also used : Address(com.hazelcast.cluster.Address) Traverser(com.hazelcast.jet.Traverser) ExpressionValues(com.hazelcast.jet.sql.impl.opt.ExpressionValues) PlanObjectKey(com.hazelcast.sql.impl.optimizer.PlanObjectKey) Processors.mapP(com.hazelcast.jet.core.processor.Processors.mapP) SourceProcessors.convenientSourceP(com.hazelcast.jet.core.processor.SourceProcessors.convenientSourceP) QueryParameterMetadata(com.hazelcast.sql.impl.QueryParameterMetadata) Collections.singletonList(java.util.Collections.singletonList) BiFunctionEx(com.hazelcast.function.BiFunctionEx) HazelcastTable(com.hazelcast.jet.sql.impl.schema.HazelcastTable) ObjectArrayKey(com.hazelcast.jet.sql.impl.ObjectArrayKey) SlidingWindowPolicy(com.hazelcast.jet.core.SlidingWindowPolicy) SqlConnectorUtil(com.hazelcast.jet.sql.impl.connector.SqlConnectorUtil) AggregateOperation(com.hazelcast.jet.aggregate.AggregateOperation) Functions.entryKey(com.hazelcast.function.Functions.entryKey) SqlConnectorUtil.getJetSqlConnector(com.hazelcast.jet.sql.impl.connector.SqlConnectorUtil.getJetSqlConnector) DAG(com.hazelcast.jet.core.DAG) RootResultConsumerSink.rootResultConsumerSink(com.hazelcast.jet.sql.impl.processors.RootResultConsumerSink.rootResultConsumerSink) ServiceFactories(com.hazelcast.jet.pipeline.ServiceFactories) FunctionEx(com.hazelcast.function.FunctionEx) KeyedWindowResultFunction(com.hazelcast.jet.core.function.KeyedWindowResultFunction) Predicate(java.util.function.Predicate) Collections.emptyList(java.util.Collections.emptyList) Set(java.util.Set) ConsumerEx(com.hazelcast.function.ConsumerEx) IMapSqlConnector(com.hazelcast.jet.sql.impl.connector.map.IMapSqlConnector) ExpressionUtil(com.hazelcast.jet.sql.impl.ExpressionUtil) Processors.filterUsingServiceP(com.hazelcast.jet.core.processor.Processors.filterUsingServiceP) List(java.util.List) ExpressionEvalContext(com.hazelcast.sql.impl.expression.ExpressionEvalContext) Processors.mapUsingServiceP(com.hazelcast.jet.core.processor.Processors.mapUsingServiceP) Table(com.hazelcast.sql.impl.schema.Table) ComparatorEx(com.hazelcast.function.ComparatorEx) QueryDataType(com.hazelcast.sql.impl.type.QueryDataType) Processors(com.hazelcast.jet.core.processor.Processors) Processors.flatMapUsingServiceP(com.hazelcast.jet.core.processor.Processors.flatMapUsingServiceP) TimestampKind(com.hazelcast.jet.core.TimestampKind) Function(java.util.function.Function) JetSqlRow(com.hazelcast.sql.impl.row.JetSqlRow) HashSet(java.util.HashSet) Edge.from(com.hazelcast.jet.core.Edge.from) Edge(com.hazelcast.jet.core.Edge) Expression(com.hazelcast.sql.impl.expression.Expression) ProcessorSupplier(com.hazelcast.jet.core.ProcessorSupplier) VertexWithInputConfig(com.hazelcast.jet.sql.impl.connector.SqlConnector.VertexWithInputConfig) SingleRel(org.apache.calcite.rel.SingleRel) Nullable(javax.annotation.Nullable) JetJoinInfo(com.hazelcast.jet.sql.impl.JetJoinInfo) NodeEngine(com.hazelcast.spi.impl.NodeEngine) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier) RelNode(org.apache.calcite.rel.RelNode) Consumer(java.util.function.Consumer) Vertex(com.hazelcast.jet.core.Vertex) ToLongFunctionEx(com.hazelcast.function.ToLongFunctionEx) SqlHashJoinP(com.hazelcast.jet.sql.impl.processors.SqlHashJoinP) ConstantExpression(com.hazelcast.sql.impl.expression.ConstantExpression) Processors.sortP(com.hazelcast.jet.core.processor.Processors.sortP) DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) WindowUtils(com.hazelcast.jet.sql.impl.aggregate.WindowUtils) Edge.between(com.hazelcast.jet.core.Edge.between) Vertex(com.hazelcast.jet.core.Vertex) SlidingWindowPolicy(com.hazelcast.jet.core.SlidingWindowPolicy) JetSqlRow(com.hazelcast.sql.impl.row.JetSqlRow)

Example 10 with JetSqlRow

use of com.hazelcast.sql.impl.row.JetSqlRow in project hazelcast by hazelcast.

the class CreateDagVisitor method onFilter.

public Vertex onFilter(FilterPhysicalRel rel) {
    Expression<Boolean> filter = rel.filter(parameterMetadata);
    Vertex vertex = dag.newUniqueVertex("Filter", filterUsingServiceP(ServiceFactories.nonSharedService(ctx -> ExpressionUtil.filterFn(filter, ExpressionEvalContext.from(ctx))), (Predicate<JetSqlRow> filterFn, JetSqlRow row) -> filterFn.test(row)));
    connectInputPreserveCollation(rel, vertex);
    return vertex;
}
Also used : Vertex(com.hazelcast.jet.core.Vertex) JetSqlRow(com.hazelcast.sql.impl.row.JetSqlRow)

Aggregations

JetSqlRow (com.hazelcast.sql.impl.row.JetSqlRow)50 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)16 QuickTest (com.hazelcast.test.annotation.QuickTest)16 Test (org.junit.Test)16 ExpressionEvalContext (com.hazelcast.sql.impl.expression.ExpressionEvalContext)15 ArrayList (java.util.ArrayList)14 Vertex (com.hazelcast.jet.core.Vertex)13 List (java.util.List)9 IndexConfig (com.hazelcast.config.IndexConfig)8 JobConfig (com.hazelcast.jet.config.JobConfig)8 ProcessorMetaSupplier (com.hazelcast.jet.core.ProcessorMetaSupplier)8 NodeEngine (com.hazelcast.spi.impl.NodeEngine)8 Expression (com.hazelcast.sql.impl.expression.Expression)8 QueryDataType (com.hazelcast.sql.impl.type.QueryDataType)8 FunctionEx (com.hazelcast.function.FunctionEx)7 QueryParameterMetadata (com.hazelcast.sql.impl.QueryParameterMetadata)7 DAG (com.hazelcast.jet.core.DAG)6 ObjectArrayKey (com.hazelcast.jet.sql.impl.ObjectArrayKey)6 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)5 Traverser (com.hazelcast.jet.Traverser)5