Search in sources :

Example 1 with ASC_NULLS_FIRST

use of io.trino.spi.connector.SortOrder.ASC_NULLS_FIRST in project trino by trinodb.

the class TestPartialTopNWithPresortedInput method createLocalQueryRunner.

@Override
protected LocalQueryRunner createLocalQueryRunner() {
    Session session = testSessionBuilder().setCatalog(MOCK_CATALOG).setSchema(TEST_SCHEMA).build();
    LocalQueryRunner queryRunner = LocalQueryRunner.builder(session).build();
    MockConnectorFactory mockFactory = MockConnectorFactory.builder().withGetTableProperties((connectorSession, handle) -> {
        MockConnectorTableHandle tableHandle = (MockConnectorTableHandle) handle;
        if (tableHandle.getTableName().equals(tableA)) {
            return new ConnectorTableProperties(TupleDomain.all(), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableList.of(new SortingProperty<>(columnHandleA, ASC_NULLS_FIRST)));
        }
        throw new IllegalArgumentException();
    }).withGetColumns(schemaTableName -> {
        if (schemaTableName.equals(tableA)) {
            return ImmutableList.of(new ColumnMetadata(columnNameA, VARCHAR), new ColumnMetadata(columnNameB, VARCHAR));
        }
        throw new IllegalArgumentException();
    }).build();
    queryRunner.createCatalog(MOCK_CATALOG, mockFactory, ImmutableMap.of());
    return queryRunner;
}
Also used : OPTIMIZED_AND_VALIDATED(io.trino.sql.planner.LogicalPlanner.Stage.OPTIMIZED_AND_VALIDATED) PlanMatchPattern(io.trino.sql.planner.assertions.PlanMatchPattern) Test(org.testng.annotations.Test) PARTIAL(io.trino.sql.planner.plan.TopNNode.Step.PARTIAL) PlanMatchPattern.limit(io.trino.sql.planner.assertions.PlanMatchPattern.limit) MockConnectorFactory(io.trino.connector.MockConnectorFactory) LongLiteral(io.trino.sql.tree.LongLiteral) PlanMatchPattern.exchange(io.trino.sql.planner.assertions.PlanMatchPattern.exchange) LOCAL(io.trino.sql.planner.plan.ExchangeNode.Scope.LOCAL) REPARTITION(io.trino.sql.planner.plan.ExchangeNode.Type.REPARTITION) ASCENDING(io.trino.sql.tree.SortItem.Ordering.ASCENDING) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) PlanMatchPattern.values(io.trino.sql.planner.assertions.PlanMatchPattern.values) SchemaTableName(io.trino.spi.connector.SchemaTableName) SortingProperty(io.trino.spi.connector.SortingProperty) ASC_NULLS_FIRST(io.trino.spi.connector.SortOrder.ASC_NULLS_FIRST) FIRST(io.trino.sql.tree.SortItem.NullOrdering.FIRST) List(java.util.List) ASC_NULLS_LAST(io.trino.spi.connector.SortOrder.ASC_NULLS_LAST) TestingSession.testSessionBuilder(io.trino.testing.TestingSession.testSessionBuilder) PlanMatchPattern.anyTree(io.trino.sql.planner.assertions.PlanMatchPattern.anyTree) GATHER(io.trino.sql.planner.plan.ExchangeNode.Type.GATHER) Optional(java.util.Optional) PlanMatchPattern.output(io.trino.sql.planner.assertions.PlanMatchPattern.output) Session(io.trino.Session) PlannerContext(io.trino.sql.PlannerContext) ValidateLimitWithPresortedInput(io.trino.sql.planner.sanity.ValidateLimitWithPresortedInput) TypeAnalyzer.createTestingTypeAnalyzer(io.trino.sql.planner.TypeAnalyzer.createTestingTypeAnalyzer) ColumnMetadata(io.trino.spi.connector.ColumnMetadata) PlanMatchPattern.window(io.trino.sql.planner.assertions.PlanMatchPattern.window) PlanAssert(io.trino.sql.planner.assertions.PlanAssert) VARCHAR(io.trino.spi.type.VarcharType.VARCHAR) ImmutableList(com.google.common.collect.ImmutableList) PlanMatchPattern.sort(io.trino.sql.planner.assertions.PlanMatchPattern.sort) LocalQueryRunner(io.trino.testing.LocalQueryRunner) ColumnHandle(io.trino.spi.connector.ColumnHandle) BasePlanTest(io.trino.sql.planner.assertions.BasePlanTest) LAST(io.trino.sql.tree.SortItem.NullOrdering.LAST) Language(org.intellij.lang.annotations.Language) MockConnectorColumnHandle(io.trino.connector.MockConnectorColumnHandle) FINAL(io.trino.sql.planner.plan.TopNNode.Step.FINAL) PlanMatchPattern.topN(io.trino.sql.planner.assertions.PlanMatchPattern.topN) TupleDomain(io.trino.spi.predicate.TupleDomain) MockConnectorTableHandle(io.trino.connector.MockConnectorTableHandle) ConnectorTableProperties(io.trino.spi.connector.ConnectorTableProperties) REMOTE(io.trino.sql.planner.plan.ExchangeNode.Scope.REMOTE) WarningCollector(io.trino.execution.warnings.WarningCollector) Plan(io.trino.sql.planner.Plan) PlanMatchPattern.tableScan(io.trino.sql.planner.assertions.PlanMatchPattern.tableScan) MockConnectorFactory(io.trino.connector.MockConnectorFactory) ColumnMetadata(io.trino.spi.connector.ColumnMetadata) MockConnectorTableHandle(io.trino.connector.MockConnectorTableHandle) SortingProperty(io.trino.spi.connector.SortingProperty) ConnectorTableProperties(io.trino.spi.connector.ConnectorTableProperties) LocalQueryRunner(io.trino.testing.LocalQueryRunner) Session(io.trino.Session)

Example 2 with ASC_NULLS_FIRST

use of io.trino.spi.connector.SortOrder.ASC_NULLS_FIRST in project trino by trinodb.

the class TestValidateLimitWithPresortedInput method createLocalQueryRunner.

@Override
protected LocalQueryRunner createLocalQueryRunner() {
    Session session = testSessionBuilder().setCatalog(MOCK_CATALOG).setSchema(TEST_SCHEMA).build();
    LocalQueryRunner queryRunner = LocalQueryRunner.builder(session).build();
    MockConnectorFactory mockFactory = MockConnectorFactory.builder().withGetTableProperties((connectorSession, handle) -> {
        MockConnectorTableHandle tableHandle = (MockConnectorTableHandle) handle;
        if (tableHandle.getTableName().equals(MOCK_TABLE_NAME)) {
            return new ConnectorTableProperties(TupleDomain.all(), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableList.of(new SortingProperty<>(COLUMN_HANDLE_A, ASC_NULLS_FIRST), new SortingProperty<>(COLUMN_HANDLE_C, ASC_NULLS_FIRST)));
        }
        throw new IllegalArgumentException();
    }).withGetColumns(schemaTableName -> {
        if (schemaTableName.equals(MOCK_TABLE_NAME)) {
            return ImmutableList.of(new ColumnMetadata(COLUMN_NAME_A, VARCHAR), new ColumnMetadata(COLUMN_NAME_B, VARCHAR), new ColumnMetadata(COLUMN_NAME_C, VARCHAR));
        }
        throw new IllegalArgumentException();
    }).build();
    queryRunner.createCatalog(MOCK_CATALOG, mockFactory, ImmutableMap.of());
    return queryRunner;
}
Also used : TypeAnalyzer.createTestingTypeAnalyzer(io.trino.sql.planner.TypeAnalyzer.createTestingTypeAnalyzer) ColumnMetadata(io.trino.spi.connector.ColumnMetadata) Test(org.testng.annotations.Test) Function(java.util.function.Function) PlanNode(io.trino.sql.planner.plan.PlanNode) CatalogName(io.trino.connector.CatalogName) VARCHAR(io.trino.spi.type.VarcharType.VARCHAR) ImmutableList(com.google.common.collect.ImmutableList) MockConnectorFactory(io.trino.connector.MockConnectorFactory) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) LongLiteral(io.trino.sql.tree.LongLiteral) LocalQueryRunner(io.trino.testing.LocalQueryRunner) PlanBuilder(io.trino.sql.planner.iterative.rule.test.PlanBuilder) ColumnHandle(io.trino.spi.connector.ColumnHandle) BasePlanTest(io.trino.sql.planner.assertions.BasePlanTest) VerifyException(com.google.common.base.VerifyException) ImmutableMap(com.google.common.collect.ImmutableMap) MockConnectorColumnHandle(io.trino.connector.MockConnectorColumnHandle) TestingTransactionHandle(io.trino.testing.TestingTransactionHandle) TupleDomain(io.trino.spi.predicate.TupleDomain) SchemaTableName(io.trino.spi.connector.SchemaTableName) SortingProperty(io.trino.spi.connector.SortingProperty) ASC_NULLS_FIRST(io.trino.spi.connector.SortOrder.ASC_NULLS_FIRST) MockConnectorTableHandle(io.trino.connector.MockConnectorTableHandle) TestingSession.testSessionBuilder(io.trino.testing.TestingSession.testSessionBuilder) TableHandle(io.trino.metadata.TableHandle) ConnectorTableProperties(io.trino.spi.connector.ConnectorTableProperties) TypeAnalyzer(io.trino.sql.planner.TypeAnalyzer) BIGINT(io.trino.spi.type.BigintType.BIGINT) WarningCollector(io.trino.execution.warnings.WarningCollector) TypeProvider(io.trino.sql.planner.TypeProvider) Optional(java.util.Optional) PlanBuilder.expression(io.trino.sql.planner.iterative.rule.test.PlanBuilder.expression) PlanNodeIdAllocator(io.trino.sql.planner.PlanNodeIdAllocator) Session(io.trino.Session) MockConnectorFactory(io.trino.connector.MockConnectorFactory) ColumnMetadata(io.trino.spi.connector.ColumnMetadata) MockConnectorTableHandle(io.trino.connector.MockConnectorTableHandle) SortingProperty(io.trino.spi.connector.SortingProperty) ConnectorTableProperties(io.trino.spi.connector.ConnectorTableProperties) LocalQueryRunner(io.trino.testing.LocalQueryRunner) Session(io.trino.Session)

Example 3 with ASC_NULLS_FIRST

use of io.trino.spi.connector.SortOrder.ASC_NULLS_FIRST in project trino by trinodb.

the class RaptorMetadata method beginInsert.

@Override
public ConnectorInsertTableHandle beginInsert(ConnectorSession session, ConnectorTableHandle tableHandle) {
    RaptorTableHandle handle = (RaptorTableHandle) tableHandle;
    long tableId = handle.getTableId();
    ImmutableList.Builder<RaptorColumnHandle> columnHandlesBuilder = ImmutableList.builder();
    ImmutableList.Builder<Type> columnTypes = ImmutableList.builder();
    for (TableColumn column : dao.listTableColumns(tableId)) {
        columnHandlesBuilder.add(new RaptorColumnHandle(column.getColumnName(), column.getColumnId(), column.getDataType()));
        columnTypes.add(column.getDataType());
    }
    long transactionId = shardManager.beginTransaction();
    setTransactionId(transactionId);
    Optional<String> externalBatchId = getExternalBatchId(session);
    List<RaptorColumnHandle> sortColumnHandles = getSortColumnHandles(tableId);
    List<RaptorColumnHandle> bucketColumnHandles = getBucketColumnHandles(tableId);
    ImmutableList<RaptorColumnHandle> columnHandles = columnHandlesBuilder.build();
    Optional<RaptorColumnHandle> temporalColumnHandle = Optional.ofNullable(dao.getTemporalColumnId(tableId)).map(temporalColumnId -> getOnlyElement(columnHandles.stream().filter(columnHandle -> columnHandle.getColumnId() == temporalColumnId).collect(toList())));
    return new RaptorInsertTableHandle(transactionId, tableId, columnHandles, columnTypes.build(), externalBatchId, sortColumnHandles, nCopies(sortColumnHandles.size(), ASC_NULLS_FIRST), handle.getBucketCount(), bucketColumnHandles, temporalColumnHandle);
}
Also used : ORGANIZED_PROPERTY(io.trino.plugin.raptor.legacy.RaptorTableProperties.ORGANIZED_PROPERTY) SHARD_UUID_COLUMN_TYPE(io.trino.plugin.raptor.legacy.RaptorColumnHandle.SHARD_UUID_COLUMN_TYPE) NOT_SUPPORTED(io.trino.spi.StandardErrorCode.NOT_SUPPORTED) ObjectMapperProvider(io.airlift.json.ObjectMapperProvider) TableNotFoundException(io.trino.spi.connector.TableNotFoundException) RaptorTableProperties.isOrganized(io.trino.plugin.raptor.legacy.RaptorTableProperties.isOrganized) ShardDelta(io.trino.plugin.raptor.legacy.metadata.ShardDelta) RaptorColumnHandle.shardUuidColumnHandle(io.trino.plugin.raptor.legacy.RaptorColumnHandle.shardUuidColumnHandle) ConnectorOutputTableHandle(io.trino.spi.connector.ConnectorOutputTableHandle) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle) Map(java.util.Map) RaptorSessionProperties.getExternalBatchId(io.trino.plugin.raptor.legacy.RaptorSessionProperties.getExternalBatchId) RAPTOR_ERROR(io.trino.plugin.raptor.legacy.RaptorErrorCode.RAPTOR_ERROR) ViewNotFoundException(io.trino.spi.connector.ViewNotFoundException) Set(java.util.Set) DatabaseUtil.onDemandDao(io.trino.plugin.raptor.legacy.util.DatabaseUtil.onDemandDao) SchemaTableName(io.trino.spi.connector.SchemaTableName) ConnectorPartitioningHandle(io.trino.spi.connector.ConnectorPartitioningHandle) SchemaTablePrefix(io.trino.spi.connector.SchemaTablePrefix) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) ConnectorTablePartitioning(io.trino.spi.connector.ConnectorTablePartitioning) DATE(io.trino.spi.type.DateType.DATE) ConnectorTableLayout(io.trino.spi.connector.ConnectorTableLayout) ConnectorInsertTableHandle(io.trino.spi.connector.ConnectorInsertTableHandle) Slice(io.airlift.slice.Slice) ColumnMetadata(io.trino.spi.connector.ColumnMetadata) TIMESTAMP_MILLIS(io.trino.spi.type.TimestampType.TIMESTAMP_MILLIS) ConnectorTableMetadata(io.trino.spi.connector.ConnectorTableMetadata) BUCKETED_ON_PROPERTY(io.trino.plugin.raptor.legacy.RaptorTableProperties.BUCKETED_ON_PROPERTY) Multimaps(com.google.common.collect.Multimaps) ArrayList(java.util.ArrayList) OptionalLong(java.util.OptionalLong) ColumnRangesSystemTable(io.trino.plugin.raptor.legacy.systemtables.ColumnRangesSystemTable) RaptorTableProperties.getSortColumns(io.trino.plugin.raptor.legacy.RaptorTableProperties.getSortColumns) ColumnHandle(io.trino.spi.connector.ColumnHandle) ORDERING_PROPERTY(io.trino.plugin.raptor.legacy.RaptorTableProperties.ORDERING_PROPERTY) INVALID_TABLE_PROPERTY(io.trino.spi.StandardErrorCode.INVALID_TABLE_PROPERTY) Jdbi(org.jdbi.v3.core.Jdbi) SHARD_UUID_COLUMN_NAME(io.trino.plugin.raptor.legacy.RaptorColumnHandle.SHARD_UUID_COLUMN_NAME) DatabaseUtil.runTransaction(io.trino.plugin.raptor.legacy.util.DatabaseUtil.runTransaction) MoreCollectors.toOptional(com.google.common.collect.MoreCollectors.toOptional) ConstraintApplicationResult(io.trino.spi.connector.ConstraintApplicationResult) DatabaseUtil.daoTransaction(io.trino.plugin.raptor.legacy.util.DatabaseUtil.daoTransaction) TableColumn(io.trino.plugin.raptor.legacy.metadata.TableColumn) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) ConnectorSession(io.trino.spi.connector.ConnectorSession) Table(io.trino.plugin.raptor.legacy.metadata.Table) JsonCodec.jsonCodec(io.airlift.json.JsonCodec.jsonCodec) ShardInfo(io.trino.plugin.raptor.legacy.metadata.ShardInfo) ConnectorTableProperties(io.trino.spi.connector.ConnectorTableProperties) TreeMap(java.util.TreeMap) ShardManager(io.trino.plugin.raptor.legacy.metadata.ShardManager) RaptorColumnHandle.bucketNumberColumnHandle(io.trino.plugin.raptor.legacy.RaptorColumnHandle.bucketNumberColumnHandle) ColumnInfo(io.trino.plugin.raptor.legacy.metadata.ColumnInfo) ViewResult(io.trino.plugin.raptor.legacy.metadata.ViewResult) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) RaptorTableProperties.getBucketColumns(io.trino.plugin.raptor.legacy.RaptorTableProperties.getBucketColumns) RaptorSessionProperties.getOneSplitPerBucketThreshold(io.trino.plugin.raptor.legacy.RaptorSessionProperties.getOneSplitPerBucketThreshold) ALREADY_EXISTS(io.trino.spi.StandardErrorCode.ALREADY_EXISTS) ConnectorViewDefinition(io.trino.spi.connector.ConnectorViewDefinition) INTEGER(io.trino.spi.type.IntegerType.INTEGER) MetadataDao(io.trino.plugin.raptor.legacy.metadata.MetadataDao) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Collections.nCopies(java.util.Collections.nCopies) Collection(java.util.Collection) ColumnRangesSystemTable.getSourceTable(io.trino.plugin.raptor.legacy.systemtables.ColumnRangesSystemTable.getSourceTable) ComputedStatistics(io.trino.spi.statistics.ComputedStatistics) TrinoException(io.trino.spi.TrinoException) UUID(java.util.UUID) ConnectorOutputMetadata(io.trino.spi.connector.ConnectorOutputMetadata) ASC_NULLS_FIRST(io.trino.spi.connector.SortOrder.ASC_NULLS_FIRST) String.format(java.lang.String.format) Preconditions.checkState(com.google.common.base.Preconditions.checkState) DISTRIBUTION_NAME_PROPERTY(io.trino.plugin.raptor.legacy.RaptorTableProperties.DISTRIBUTION_NAME_PROPERTY) List(java.util.List) BUCKET_COUNT_PROPERTY(io.trino.plugin.raptor.legacy.RaptorTableProperties.BUCKET_COUNT_PROPERTY) JsonCodecFactory(io.airlift.json.JsonCodecFactory) Optional(java.util.Optional) ConnectorMetadata(io.trino.spi.connector.ConnectorMetadata) SystemTable(io.trino.spi.connector.SystemTable) SortedMap(java.util.SortedMap) JsonCodec(io.airlift.json.JsonCodec) RaptorColumnHandle.isHiddenColumn(io.trino.plugin.raptor.legacy.RaptorColumnHandle.isHiddenColumn) RaptorColumnHandle.shardRowIdHandle(io.trino.plugin.raptor.legacy.RaptorColumnHandle.shardRowIdHandle) Constraint(io.trino.spi.connector.Constraint) Logger(io.airlift.log.Logger) Type(io.trino.spi.type.Type) OptionalInt(java.util.OptionalInt) AtomicReference(java.util.concurrent.atomic.AtomicReference) Collectors.toCollection(java.util.stream.Collectors.toCollection) Distribution(io.trino.plugin.raptor.legacy.metadata.Distribution) RaptorTableProperties.getDistributionName(io.trino.plugin.raptor.legacy.RaptorTableProperties.getDistributionName) ImmutableList(com.google.common.collect.ImmutableList) BUCKET_NUMBER_COLUMN_NAME(io.trino.plugin.raptor.legacy.RaptorColumnHandle.BUCKET_NUMBER_COLUMN_NAME) Objects.requireNonNull(java.util.Objects.requireNonNull) NOT_FOUND(io.trino.spi.StandardErrorCode.NOT_FOUND) RaptorTableProperties.getTemporalColumn(io.trino.plugin.raptor.legacy.RaptorTableProperties.getTemporalColumn) TupleDomain(io.trino.spi.predicate.TupleDomain) Maps(com.google.common.collect.Maps) LongConsumer(java.util.function.LongConsumer) TEMPORAL_COLUMN_PROPERTY(io.trino.plugin.raptor.legacy.RaptorTableProperties.TEMPORAL_COLUMN_PROPERTY) RaptorBucketFunction.validateBucketType(io.trino.plugin.raptor.legacy.RaptorBucketFunction.validateBucketType) Collectors.toList(java.util.stream.Collectors.toList) DatabaseUtil.runIgnoringConstraintViolation(io.trino.plugin.raptor.legacy.util.DatabaseUtil.runIgnoringConstraintViolation) RaptorTableProperties.getBucketCount(io.trino.plugin.raptor.legacy.RaptorTableProperties.getBucketCount) ImmutableList(com.google.common.collect.ImmutableList) TableColumn(io.trino.plugin.raptor.legacy.metadata.TableColumn) Type(io.trino.spi.type.Type) RaptorBucketFunction.validateBucketType(io.trino.plugin.raptor.legacy.RaptorBucketFunction.validateBucketType)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 Session (io.trino.Session)2 MockConnectorColumnHandle (io.trino.connector.MockConnectorColumnHandle)2 MockConnectorFactory (io.trino.connector.MockConnectorFactory)2 MockConnectorTableHandle (io.trino.connector.MockConnectorTableHandle)2 WarningCollector (io.trino.execution.warnings.WarningCollector)2 ColumnHandle (io.trino.spi.connector.ColumnHandle)2 ColumnMetadata (io.trino.spi.connector.ColumnMetadata)2 ConnectorTableProperties (io.trino.spi.connector.ConnectorTableProperties)2 SchemaTableName (io.trino.spi.connector.SchemaTableName)2 ASC_NULLS_FIRST (io.trino.spi.connector.SortOrder.ASC_NULLS_FIRST)2 SortingProperty (io.trino.spi.connector.SortingProperty)2 TupleDomain (io.trino.spi.predicate.TupleDomain)2 VARCHAR (io.trino.spi.type.VarcharType.VARCHAR)2 TypeAnalyzer.createTestingTypeAnalyzer (io.trino.sql.planner.TypeAnalyzer.createTestingTypeAnalyzer)2 BasePlanTest (io.trino.sql.planner.assertions.BasePlanTest)2 LongLiteral (io.trino.sql.tree.LongLiteral)2 LocalQueryRunner (io.trino.testing.LocalQueryRunner)2 TestingSession.testSessionBuilder (io.trino.testing.TestingSession.testSessionBuilder)2