Search in sources :

Example 31 with JetSqlRow

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

the class MapIndexScanPTest method test_whenFilterExistsWithoutSpecificProjection_sorted.

@Test
public void test_whenFilterExistsWithoutSpecificProjection_sorted() {
    List<JetSqlRow> expected = new ArrayList<>();
    for (int i = count; i > 0; i--) {
        map.put(i, new Person("value-" + i, i));
        if (i > count / 2) {
            expected.add(jetRow((count - i + 1), "value-" + (count - i + 1), (count - i + 1)));
        }
    }
    IndexConfig indexConfig = new IndexConfig(IndexType.SORTED, "age").setName(randomName());
    map.addIndex(indexConfig);
    IndexFilter filter = new IndexRangeFilter(intValue(0), true, intValue(count / 2), true);
    MapIndexScanMetadata metadata = metadata(indexConfig.getName(), filter, 2, false);
    TestSupport.verifyProcessor(adaptSupplier(MapIndexScanP.readMapIndexSupplier(metadata))).hazelcastInstance(instance()).jobConfig(new JobConfig().setArgument(SQL_ARGUMENTS_KEY_NAME, emptyList())).outputChecker(LENIENT_SAME_ITEMS_IN_ORDER).disableSnapshots().disableProgressAssertion().expectOutput(expected);
}
Also used : IndexRangeFilter(com.hazelcast.sql.impl.exec.scan.index.IndexRangeFilter) IndexConfig(com.hazelcast.config.IndexConfig) ArrayList(java.util.ArrayList) MapIndexScanMetadata(com.hazelcast.sql.impl.exec.scan.MapIndexScanMetadata) JetSqlRow(com.hazelcast.sql.impl.row.JetSqlRow) IndexFilter(com.hazelcast.sql.impl.exec.scan.index.IndexFilter) JobConfig(com.hazelcast.jet.config.JobConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 32 with JetSqlRow

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

the class PlanExecutor method execute.

SqlResult execute(ExplainStatementPlan plan) {
    Stream<String> planRows;
    SqlRowMetadata metadata = new SqlRowMetadata(singletonList(new SqlColumnMetadata("rel", VARCHAR, false)));
    InternalSerializationService serializationService = Util.getSerializationService(hazelcastInstance);
    planRows = Arrays.stream(plan.getRel().explain().split(LE));
    return new SqlResultImpl(QueryId.create(hazelcastInstance.getLocalEndpoint().getUuid()), new StaticQueryResultProducerImpl(planRows.map(rel -> new JetSqlRow(serializationService, new Object[] { rel })).iterator()), metadata, false);
}
Also used : UpdateSqlResultImpl(com.hazelcast.sql.impl.UpdateSqlResultImpl) Arrays(java.util.Arrays) DropViewPlan(com.hazelcast.jet.sql.impl.SqlPlanImpl.DropViewPlan) SelectPlan(com.hazelcast.jet.sql.impl.SqlPlanImpl.SelectPlan) TimeoutException(java.util.concurrent.TimeoutException) Extractors(com.hazelcast.query.impl.getters.Extractors) SQL_ARGUMENTS_KEY_NAME(com.hazelcast.sql.impl.expression.ExpressionEvalContext.SQL_ARGUMENTS_KEY_NAME) CreateIndexPlan(com.hazelcast.jet.sql.impl.SqlPlanImpl.CreateIndexPlan) SqlRowMetadata(com.hazelcast.sql.SqlRowMetadata) QueryParameterMetadata(com.hazelcast.sql.impl.QueryParameterMetadata) Collections.singletonList(java.util.Collections.singletonList) MapProxyImpl(com.hazelcast.map.impl.proxy.MapProxyImpl) ParameterConverter(com.hazelcast.sql.impl.ParameterConverter) SqlNode(org.apache.calcite.sql.SqlNode) Map(java.util.Map) VARCHAR(com.hazelcast.sql.SqlColumnType.VARCHAR) CreateJobPlan(com.hazelcast.jet.sql.impl.SqlPlanImpl.CreateJobPlan) CreateMappingPlan(com.hazelcast.jet.sql.impl.SqlPlanImpl.CreateMappingPlan) DropMappingPlan(com.hazelcast.jet.sql.impl.SqlPlanImpl.DropMappingPlan) CancellationException(java.util.concurrent.CancellationException) JobConfig(com.hazelcast.jet.config.JobConfig) AlterJobPlan(com.hazelcast.jet.sql.impl.SqlPlanImpl.AlterJobPlan) QueryResultRegistry(com.hazelcast.sql.impl.state.QueryResultRegistry) IMapUpdatePlan(com.hazelcast.jet.sql.impl.SqlPlanImpl.IMapUpdatePlan) IndexConfig(com.hazelcast.config.IndexConfig) IMapSelectPlan(com.hazelcast.jet.sql.impl.SqlPlanImpl.IMapSelectPlan) Objects(java.util.Objects) Util(com.hazelcast.jet.impl.util.Util) List(java.util.List) ExpressionEvalContext(com.hazelcast.sql.impl.expression.ExpressionEvalContext) Stream(java.util.stream.Stream) JobStateSnapshot(com.hazelcast.jet.JobStateSnapshot) EmptyRow(com.hazelcast.sql.impl.row.EmptyRow) DropJobPlan(com.hazelcast.jet.sql.impl.SqlPlanImpl.DropJobPlan) DmlPlan(com.hazelcast.jet.sql.impl.SqlPlanImpl.DmlPlan) RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) UNIQUE_KEY_TRANSFORMATION(com.hazelcast.jet.sql.impl.parse.SqlCreateIndex.UNIQUE_KEY_TRANSFORMATION) SqlResult(com.hazelcast.sql.SqlResult) Entry(java.util.Map.Entry) SqlErrorCode(com.hazelcast.sql.impl.SqlErrorCode) UniqueKeyTransformation(com.hazelcast.config.BitmapIndexOptions.UniqueKeyTransformation) QueryDataType(com.hazelcast.sql.impl.type.QueryDataType) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) SqlColumnMetadata(com.hazelcast.sql.SqlColumnMetadata) IMapSinkPlan(com.hazelcast.jet.sql.impl.SqlPlanImpl.IMapSinkPlan) EntryRemovingProcessor(com.hazelcast.map.impl.EntryRemovingProcessor) ArrayList(java.util.ArrayList) JetSqlRow(com.hazelcast.sql.impl.row.JetSqlRow) IndexType(com.hazelcast.config.IndexType) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) IMapInsertPlan(com.hazelcast.jet.sql.impl.SqlPlanImpl.IMapInsertPlan) View(com.hazelcast.sql.impl.schema.view.View) IMapDeletePlan(com.hazelcast.jet.sql.impl.SqlPlanImpl.IMapDeletePlan) KEY_SQL_QUERY_TEXT(com.hazelcast.jet.config.JobConfigArguments.KEY_SQL_QUERY_TEXT) Job(com.hazelcast.jet.Job) QueryException(com.hazelcast.sql.impl.QueryException) HazelcastInstance(com.hazelcast.core.HazelcastInstance) NodeEngine(com.hazelcast.spi.impl.NodeEngine) MapContainer(com.hazelcast.map.impl.MapContainer) CreateViewPlan(com.hazelcast.jet.sql.impl.SqlPlanImpl.CreateViewPlan) DropSnapshotPlan(com.hazelcast.jet.sql.impl.SqlPlanImpl.DropSnapshotPlan) TableResolverImpl(com.hazelcast.jet.sql.impl.schema.TableResolverImpl) MapService(com.hazelcast.map.impl.MapService) QueryId(com.hazelcast.sql.impl.QueryId) RelNode(org.apache.calcite.rel.RelNode) BitmapIndexOptions(com.hazelcast.config.BitmapIndexOptions) ShowStatementTarget(com.hazelcast.jet.sql.impl.parse.SqlShowStatement.ShowStatementTarget) MapServiceContext(com.hazelcast.map.impl.MapServiceContext) HazelcastTypeUtils.toHazelcastType(com.hazelcast.jet.sql.impl.validate.types.HazelcastTypeUtils.toHazelcastType) CreateSnapshotPlan(com.hazelcast.jet.sql.impl.SqlPlanImpl.CreateSnapshotPlan) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) ShowStatementPlan(com.hazelcast.jet.sql.impl.SqlPlanImpl.ShowStatementPlan) UNIQUE_KEY(com.hazelcast.jet.sql.impl.parse.SqlCreateIndex.UNIQUE_KEY) ExplainStatementPlan(com.hazelcast.jet.sql.impl.SqlPlanImpl.ExplainStatementPlan) Util.getNodeEngine(com.hazelcast.jet.impl.util.Util.getNodeEngine) KEY_SQL_UNBOUNDED(com.hazelcast.jet.config.JobConfigArguments.KEY_SQL_UNBOUNDED) AbstractJetInstance(com.hazelcast.jet.impl.AbstractJetInstance) JetServiceBackend(com.hazelcast.jet.impl.JetServiceBackend) IMap(com.hazelcast.map.IMap) SqlRowMetadata(com.hazelcast.sql.SqlRowMetadata) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) JetSqlRow(com.hazelcast.sql.impl.row.JetSqlRow) UpdateSqlResultImpl(com.hazelcast.sql.impl.UpdateSqlResultImpl) SqlColumnMetadata(com.hazelcast.sql.SqlColumnMetadata)

Example 33 with JetSqlRow

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

the class PlanExecutor method execute.

SqlResult execute(IMapSelectPlan plan, QueryId queryId, List<Object> arguments, long timeout) {
    List<Object> args = prepareArguments(plan.parameterMetadata(), arguments);
    InternalSerializationService serializationService = Util.getSerializationService(hazelcastInstance);
    ExpressionEvalContext evalContext = new ExpressionEvalContext(args, serializationService);
    Object key = plan.keyCondition().eval(EmptyRow.INSTANCE, evalContext);
    CompletableFuture<JetSqlRow> future = hazelcastInstance.getMap(plan.mapName()).getAsync(key).toCompletableFuture().thenApply(value -> plan.rowProjectorSupplier().get(evalContext, Extractors.newBuilder(serializationService).build()).project(key, value));
    JetSqlRow row = await(future, timeout);
    return new SqlResultImpl(queryId, new StaticQueryResultProducerImpl(row), plan.rowMetadata(), false);
}
Also used : ExpressionEvalContext(com.hazelcast.sql.impl.expression.ExpressionEvalContext) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) JetSqlRow(com.hazelcast.sql.impl.row.JetSqlRow) UpdateSqlResultImpl(com.hazelcast.sql.impl.UpdateSqlResultImpl)

Example 34 with JetSqlRow

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

the class QueryResultProducerImpl method consume.

public void consume(Inbox inbox) {
    ensureNotDone();
    if (limit <= 0) {
        done.compareAndSet(null, new ResultLimitReachedException());
        ensureNotDone();
    }
    while (offset > 0 && inbox.poll() != null) {
        offset--;
    }
    for (JetSqlRow row; (row = (JetSqlRow) inbox.peek()) != null && rows.offer(row); ) {
        inbox.remove();
        if (limit != Long.MAX_VALUE) {
            limit -= 1;
            if (limit < 1) {
                done.compareAndSet(null, new ResultLimitReachedException());
                ensureNotDone();
            }
        }
    }
}
Also used : ResultLimitReachedException(com.hazelcast.sql.impl.ResultLimitReachedException) JetSqlRow(com.hazelcast.sql.impl.row.JetSqlRow)

Example 35 with JetSqlRow

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

the class CreateDagVisitor method onCombine.

public Vertex onCombine(AggregateCombinePhysicalRel rel) {
    AggregateOperation<?, JetSqlRow> aggregateOperation = rel.aggrOp();
    Vertex vertex = dag.newUniqueVertex("Combine", ProcessorMetaSupplier.forceTotalParallelismOne(ProcessorSupplier.of(Processors.combineP(aggregateOperation)), localMemberAddress));
    connectInput(rel.getInput(), vertex, edge -> edge.distributeTo(localMemberAddress).allToOne(""));
    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