Search in sources :

Example 6 with SqlColumnMetadata

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

the class SqlConsole method determineAlignments.

private static Alignment[] determineAlignments(SqlRowMetadata metadata) {
    int colCount = metadata.getColumnCount();
    Alignment[] alignments = new Alignment[colCount];
    for (int i = 0; i < colCount; i++) {
        SqlColumnMetadata colMetadata = metadata.getColumn(i);
        SqlColumnType type = colMetadata.getType();
        switch(type) {
            case BIGINT:
            case DECIMAL:
            case DOUBLE:
            case INTEGER:
            case REAL:
            case SMALLINT:
            case TINYINT:
                alignments[i] = Alignment.RIGHT;
                break;
            case BOOLEAN:
            case DATE:
            case NULL:
            case OBJECT:
            case TIMESTAMP:
            case VARCHAR:
            case TIMESTAMP_WITH_TIME_ZONE:
            default:
                alignments[i] = Alignment.LEFT;
        }
    }
    return alignments;
}
Also used : SqlColumnMetadata(com.hazelcast.sql.SqlColumnMetadata) SqlColumnType(com.hazelcast.sql.SqlColumnType)

Example 7 with SqlColumnMetadata

use of com.hazelcast.sql.SqlColumnMetadata 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 8 with SqlColumnMetadata

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

the class SqlRowImpl method toString.

@Override
public String toString() {
    StringJoiner joiner = new StringJoiner(", ", "[", "]");
    for (int i = 0; i < rowMetadata.getColumnCount(); i++) {
        SqlColumnMetadata columnMetadata = rowMetadata.getColumn(i);
        // toString() is often called by the debugger, it must not mutate the state by serializing or deserializing.
        Object columnValue = row.getMaybeSerialized(i);
        joiner.add(columnMetadata.getName() + ' ' + columnMetadata.getType() + '=' + columnValue);
    }
    return joiner.toString();
}
Also used : SqlColumnMetadata(com.hazelcast.sql.SqlColumnMetadata) StringJoiner(java.util.StringJoiner)

Example 9 with SqlColumnMetadata

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

the class QueryClientStateRegistry method fetchInternal.

private SqlPage fetchInternal(QueryClientState clientCursor, int cursorBufferSize, InternalSerializationService serializationService, boolean respondImmediately) {
    List<SqlColumnMetadata> columns = clientCursor.getSqlResult().getRowMetadata().getColumns();
    List<SqlColumnType> columnTypes = new ArrayList<>(columns.size());
    for (SqlColumnMetadata column : columns) {
        columnTypes.add(column.getType());
    }
    if (respondImmediately) {
        return SqlPage.fromRows(columnTypes, Collections.emptyList(), false, serializationService);
    }
    ResultIterator<SqlRow> iterator = clientCursor.getIterator();
    try {
        List<SqlRow> rows = new ArrayList<>(cursorBufferSize);
        boolean last = fetchPage(iterator, rows, cursorBufferSize);
        return SqlPage.fromRows(columnTypes, rows, last, serializationService);
    } catch (HazelcastSqlException e) {
        // it happens, the cursor is already closed with the error, so we just re-throw.
        throw e;
    } catch (Exception e) {
        // Any other exception indicates that something has happened outside of the internal query state. For example,
        // we may fail to serialize a specific column value to Data. We have to close the cursor in this case.
        AbstractSqlResult result = clientCursor.getSqlResult();
        QueryException error = QueryException.error("Failed to prepare the SQL result for the client: " + e.getMessage(), e);
        result.close(error);
        throw error;
    }
}
Also used : SqlRow(com.hazelcast.sql.SqlRow) ArrayList(java.util.ArrayList) SqlColumnType(com.hazelcast.sql.SqlColumnType) HazelcastSqlException(com.hazelcast.sql.HazelcastSqlException) QueryException(com.hazelcast.sql.impl.QueryException) QueryException(com.hazelcast.sql.impl.QueryException) AbstractSqlResult(com.hazelcast.sql.impl.AbstractSqlResult) SqlColumnMetadata(com.hazelcast.sql.SqlColumnMetadata) HazelcastSqlException(com.hazelcast.sql.HazelcastSqlException)

Example 10 with SqlColumnMetadata

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

the class ShowStatementTest method test_showStatement_metadata.

@Test
public void test_showStatement_metadata() {
    SqlRowMetadata expectedMetadata = new SqlRowMetadata(singletonList(new SqlColumnMetadata("name", SqlColumnType.VARCHAR, false)));
    assertThat(sqlService.execute("show mappings").getRowMetadata()).isEqualTo(expectedMetadata);
    assertThat(sqlService.execute("show jobs").getRowMetadata()).isEqualTo(expectedMetadata);
}
Also used : SqlRowMetadata(com.hazelcast.sql.SqlRowMetadata) SqlColumnMetadata(com.hazelcast.sql.SqlColumnMetadata) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

SqlColumnMetadata (com.hazelcast.sql.SqlColumnMetadata)11 SqlRowMetadata (com.hazelcast.sql.SqlRowMetadata)5 ArrayList (java.util.ArrayList)5 SqlColumnType (com.hazelcast.sql.SqlColumnType)4 BitmapIndexOptions (com.hazelcast.config.BitmapIndexOptions)2 UniqueKeyTransformation (com.hazelcast.config.BitmapIndexOptions.UniqueKeyTransformation)2 IndexConfig (com.hazelcast.config.IndexConfig)2 IndexType (com.hazelcast.config.IndexType)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)2 Job (com.hazelcast.jet.Job)2 JobStateSnapshot (com.hazelcast.jet.JobStateSnapshot)2 JobConfig (com.hazelcast.jet.config.JobConfig)2 KEY_SQL_QUERY_TEXT (com.hazelcast.jet.config.JobConfigArguments.KEY_SQL_QUERY_TEXT)2 KEY_SQL_UNBOUNDED (com.hazelcast.jet.config.JobConfigArguments.KEY_SQL_UNBOUNDED)2 AbstractJetInstance (com.hazelcast.jet.impl.AbstractJetInstance)2 JetServiceBackend (com.hazelcast.jet.impl.JetServiceBackend)2 Util (com.hazelcast.jet.impl.util.Util)2 Util.getNodeEngine (com.hazelcast.jet.impl.util.Util.getNodeEngine)2 AlterJobPlan (com.hazelcast.jet.sql.impl.SqlPlanImpl.AlterJobPlan)2