Search in sources :

Example 36 with SqlResult

use of com.hazelcast.sql.SqlResult in project hazelcast by hazelcast.

the class SqlMappingTest method when_mappingIsDropped_then_itIsNotAvailable.

@Test
public void when_mappingIsDropped_then_itIsNotAvailable() {
    // given
    String name = randomName();
    createMapping(name, Integer.class, Person.class);
    // when
    SqlResult dropResult = sqlService.execute("DROP MAPPING " + name);
    // then
    assertThat(dropResult.updateCount()).isEqualTo(0);
    assertThatThrownBy(() -> sqlService.execute("SELECT * FROM public." + name)).isInstanceOf(HazelcastSqlException.class).hasMessageContaining("Object '" + name + "' not found within 'hazelcast.public'");
}
Also used : SqlResult(com.hazelcast.sql.SqlResult) HazelcastSqlException(com.hazelcast.sql.HazelcastSqlException) Test(org.junit.Test)

Example 37 with SqlResult

use of com.hazelcast.sql.SqlResult 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 38 with SqlResult

use of com.hazelcast.sql.SqlResult in project hazelcast by hazelcast.

the class SqlFilterProjectTest method test_queryMetadata.

@Test
public void test_queryMetadata() {
    TestAllTypesSqlConnector.create(sqlService, "t");
    SqlResult result = sqlService.execute("SELECT * FROM t");
    assertThat(result.updateCount()).isEqualTo(-1);
    assertThat(result.getRowMetadata().getColumnCount()).isEqualTo(15);
    assertThat(result.getRowMetadata().getColumn(0).getName()).isEqualTo("string");
    assertThat(result.getRowMetadata().getColumn(0).getType()).isEqualTo(SqlColumnType.VARCHAR);
    assertThat(result.getRowMetadata().getColumn(1).getName()).isEqualTo("boolean");
    assertThat(result.getRowMetadata().getColumn(1).getType()).isEqualTo(SqlColumnType.BOOLEAN);
    assertThat(result.getRowMetadata().getColumn(2).getName()).isEqualTo("byte");
    assertThat(result.getRowMetadata().getColumn(2).getType()).isEqualTo(SqlColumnType.TINYINT);
    assertThat(result.getRowMetadata().getColumn(3).getName()).isEqualTo("short");
    assertThat(result.getRowMetadata().getColumn(3).getType()).isEqualTo(SqlColumnType.SMALLINT);
    assertThat(result.getRowMetadata().getColumn(4).getName()).isEqualTo("int");
    assertThat(result.getRowMetadata().getColumn(4).getType()).isEqualTo(SqlColumnType.INTEGER);
    assertThat(result.getRowMetadata().getColumn(5).getName()).isEqualTo("long");
    assertThat(result.getRowMetadata().getColumn(5).getType()).isEqualTo(SqlColumnType.BIGINT);
    assertThat(result.getRowMetadata().getColumn(6).getName()).isEqualTo("float");
    assertThat(result.getRowMetadata().getColumn(6).getType()).isEqualTo(SqlColumnType.REAL);
    assertThat(result.getRowMetadata().getColumn(7).getName()).isEqualTo("double");
    assertThat(result.getRowMetadata().getColumn(7).getType()).isEqualTo(SqlColumnType.DOUBLE);
    assertThat(result.getRowMetadata().getColumn(8).getName()).isEqualTo("decimal");
    assertThat(result.getRowMetadata().getColumn(8).getType()).isEqualTo(SqlColumnType.DECIMAL);
    assertThat(result.getRowMetadata().getColumn(9).getName()).isEqualTo("time");
    assertThat(result.getRowMetadata().getColumn(9).getType()).isEqualTo(SqlColumnType.TIME);
    assertThat(result.getRowMetadata().getColumn(10).getName()).isEqualTo("date");
    assertThat(result.getRowMetadata().getColumn(10).getType()).isEqualTo(SqlColumnType.DATE);
    assertThat(result.getRowMetadata().getColumn(11).getName()).isEqualTo("timestamp");
    assertThat(result.getRowMetadata().getColumn(11).getType()).isEqualTo(SqlColumnType.TIMESTAMP);
    assertThat(result.getRowMetadata().getColumn(12).getName()).isEqualTo("timestampTz");
    assertThat(result.getRowMetadata().getColumn(12).getType()).isEqualTo(SqlColumnType.TIMESTAMP_WITH_TIME_ZONE);
    assertThat(result.getRowMetadata().getColumn(13).getName()).isEqualTo("map");
    assertThat(result.getRowMetadata().getColumn(13).getType()).isEqualTo(SqlColumnType.OBJECT);
    assertThat(result.getRowMetadata().getColumn(14).getName()).isEqualTo("object");
    assertThat(result.getRowMetadata().getColumn(14).getType()).isEqualTo(SqlColumnType.OBJECT);
}
Also used : SqlResult(com.hazelcast.sql.SqlResult) Test(org.junit.Test)

Example 39 with SqlResult

use of com.hazelcast.sql.SqlResult in project hazelcast by hazelcast.

the class SqlFilterProjectTest method test_sinkMetadata.

@Test
public void test_sinkMetadata() {
    createMapping("m", Integer.class, Integer.class);
    SqlResult result = sqlService.execute("SINK INTO m(__key, this) VALUES (1, 1), (2, 2)");
    assertThat(result.updateCount()).isEqualTo(0);
}
Also used : SqlResult(com.hazelcast.sql.SqlResult) Test(org.junit.Test)

Example 40 with SqlResult

use of com.hazelcast.sql.SqlResult in project hazelcast by hazelcast.

the class SqlFilterProjectTest method test_dynamicParameterMetadata.

@Test
public void test_dynamicParameterMetadata() {
    TestBatchSqlConnector.create(sqlService, "t", 1);
    SqlResult result = sqlService.execute("SELECT CAST(? AS VARCHAR) FROM t", 1);
    assertThat(result.getRowMetadata().getColumnCount()).isEqualTo(1);
    assertThat(result.getRowMetadata().getColumn(0).getType()).isEqualTo(SqlColumnType.VARCHAR);
}
Also used : SqlResult(com.hazelcast.sql.SqlResult) Test(org.junit.Test)

Aggregations

SqlResult (com.hazelcast.sql.SqlResult)60 Test (org.junit.Test)38 SqlRow (com.hazelcast.sql.SqlRow)31 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)23 QuickTest (com.hazelcast.test.annotation.QuickTest)23 SqlStatement (com.hazelcast.sql.SqlStatement)14 HazelcastInstance (com.hazelcast.core.HazelcastInstance)13 ArrayList (java.util.ArrayList)9 Job (com.hazelcast.jet.Job)8 HazelcastSqlException (com.hazelcast.sql.HazelcastSqlException)8 SqlService (com.hazelcast.sql.SqlService)8 JobConfig (com.hazelcast.jet.config.JobConfig)7 JetSqlRow (com.hazelcast.sql.impl.row.JetSqlRow)6 HashMap (java.util.HashMap)5 SqlRowMetadata (com.hazelcast.sql.SqlRowMetadata)4 List (java.util.List)4 CompletableFuture (java.util.concurrent.CompletableFuture)4 TimeoutException (java.util.concurrent.TimeoutException)4 ClientConfig (com.hazelcast.client.config.ClientConfig)3 IndexConfig (com.hazelcast.config.IndexConfig)3