Search in sources :

Example 71 with TableHandle

use of io.trino.metadata.TableHandle in project trino by trinodb.

the class AbstractOperatorBenchmark method getColumnTypes.

protected final List<Type> getColumnTypes(String tableName, String... columnNames) {
    checkState(session.getCatalog().isPresent(), "catalog not set");
    checkState(session.getSchema().isPresent(), "schema not set");
    // look up the table
    Metadata metadata = localQueryRunner.getMetadata();
    QualifiedObjectName qualifiedTableName = new QualifiedObjectName(session.getCatalog().get(), session.getSchema().get(), tableName);
    TableHandle tableHandle = metadata.getTableHandle(session, qualifiedTableName).orElseThrow(() -> new IllegalArgumentException(format("Table '%s' does not exist", qualifiedTableName)));
    Map<String, ColumnHandle> allColumnHandles = metadata.getColumnHandles(session, tableHandle);
    return Arrays.stream(columnNames).map(allColumnHandles::get).map(columnHandle -> metadata.getColumnMetadata(session, tableHandle, columnHandle).getType()).collect(toImmutableList());
}
Also used : QueryId(io.trino.spi.QueryId) EMPTY(io.trino.spi.connector.DynamicFilter.EMPTY) Arrays(java.util.Arrays) SpillSpaceTracker(io.trino.spiller.SpillSpaceTracker) SymbolAllocator(io.trino.sql.planner.SymbolAllocator) TypeSignatureProvider.fromTypes(io.trino.sql.analyzer.TypeSignatureProvider.fromTypes) TaskStateMachine(io.trino.execution.TaskStateMachine) OperatorContext(io.trino.operator.OperatorContext) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) PageSourceOperator(io.trino.operator.PageSourceOperator) PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) Map(java.util.Map) ConnectorPageSource(io.trino.spi.connector.ConnectorPageSource) MemoryPool(io.trino.memory.MemoryPool) Operator(io.trino.operator.Operator) ImmutableMap(com.google.common.collect.ImmutableMap) ResolvedFunction(io.trino.metadata.ResolvedFunction) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) PageFunctionCompiler(io.trino.sql.gen.PageFunctionCompiler) SplitSource(io.trino.split.SplitSource) CpuTimer(io.airlift.stats.CpuTimer) QueryContext(io.trino.memory.QueryContext) TaskId(io.trino.execution.TaskId) PageProjection(io.trino.operator.project.PageProjection) String.format(java.lang.String.format) Preconditions.checkState(com.google.common.base.Preconditions.checkState) Constraint.alwaysTrue(io.trino.spi.connector.Constraint.alwaysTrue) DataSize(io.airlift.units.DataSize) List(java.util.List) NOT_PARTITIONED(io.trino.spi.connector.NotPartitionedPartitionHandle.NOT_PARTITIONED) TestingSession.testSessionBuilder(io.trino.testing.TestingSession.testSessionBuilder) DriverContext(io.trino.operator.DriverContext) BIGINT(io.trino.spi.type.BigintType.BIGINT) Split(io.trino.metadata.Split) DynamicFilter(io.trino.spi.connector.DynamicFilter) Optional(java.util.Optional) Expression(io.trino.sql.tree.Expression) SystemSessionProperties.getFilterAndProjectMinOutputPageSize(io.trino.SystemSessionProperties.getFilterAndProjectMinOutputPageSize) Session(io.trino.Session) TypeAnalyzer.createTestingTypeAnalyzer(io.trino.sql.planner.TypeAnalyzer.createTestingTypeAnalyzer) SqlToRowExpressionTranslator.translate(io.trino.sql.relational.SqlToRowExpressionTranslator.translate) Iterables(com.google.common.collect.Iterables) StageId(io.trino.execution.StageId) AllowAllAccessControl(io.trino.security.AllowAllAccessControl) NANOSECONDS(java.util.concurrent.TimeUnit.NANOSECONDS) MEGABYTE(io.airlift.units.DataSize.Unit.MEGABYTE) Type(io.trino.spi.type.Type) SystemSessionProperties.getFilterAndProjectMinOutputPageRowCount(io.trino.SystemSessionProperties.getFilterAndProjectMinOutputPageRowCount) ArrayList(java.util.ArrayList) HashGenerationOptimizer(io.trino.sql.planner.optimizations.HashGenerationOptimizer) GIGABYTE(io.airlift.units.DataSize.Unit.GIGABYTE) ImmutableList(com.google.common.collect.ImmutableList) TaskStats(io.trino.operator.TaskStats) InputPageProjection(io.trino.operator.project.InputPageProjection) Verify.verify(com.google.common.base.Verify.verify) UNGROUPED_SCHEDULING(io.trino.spi.connector.ConnectorSplitManager.SplitSchedulingStrategy.UNGROUPED_SCHEDULING) NodeRef(io.trino.sql.tree.NodeRef) LocalQueryRunner(io.trino.testing.LocalQueryRunner) Objects.requireNonNull(java.util.Objects.requireNonNull) TaskContext(io.trino.operator.TaskContext) PageProcessor(io.trino.operator.project.PageProcessor) ColumnHandle(io.trino.spi.connector.ColumnHandle) Lifespan(io.trino.execution.Lifespan) OperatorFactory(io.trino.operator.OperatorFactory) Symbol(io.trino.sql.planner.Symbol) CpuDuration(io.airlift.stats.CpuTimer.CpuDuration) AggregationMetadata(io.trino.operator.aggregation.AggregationMetadata) MoreFutures.getFutureValue(io.airlift.concurrent.MoreFutures.getFutureValue) FilterAndProjectOperator(io.trino.operator.FilterAndProjectOperator) QualifiedName(io.trino.sql.tree.QualifiedName) TableHandle(io.trino.metadata.TableHandle) QualifiedObjectName(io.trino.metadata.QualifiedObjectName) RowExpression(io.trino.sql.relational.RowExpression) Metadata(io.trino.metadata.Metadata) TypeProvider(io.trino.sql.planner.TypeProvider) TransactionId(io.trino.transaction.TransactionId) Driver(io.trino.operator.Driver) SECONDS(java.util.concurrent.TimeUnit.SECONDS) TestingGcMonitor(io.airlift.stats.TestingGcMonitor) ColumnHandle(io.trino.spi.connector.ColumnHandle) AggregationMetadata(io.trino.operator.aggregation.AggregationMetadata) Metadata(io.trino.metadata.Metadata) TableHandle(io.trino.metadata.TableHandle) QualifiedObjectName(io.trino.metadata.QualifiedObjectName)

Example 72 with TableHandle

use of io.trino.metadata.TableHandle in project trino by trinodb.

the class MemoryLocalQueryRunner method dropTable.

public void dropTable(String tableName) {
    Session session = localQueryRunner.getDefaultSession();
    Metadata metadata = localQueryRunner.getMetadata();
    Optional<TableHandle> tableHandle = metadata.getTableHandle(session, QualifiedObjectName.valueOf(tableName));
    assertTrue(tableHandle.isPresent(), "Table " + tableName + " does not exist");
    metadata.dropTable(session, tableHandle.get());
}
Also used : Metadata(io.trino.metadata.Metadata) TableHandle(io.trino.metadata.TableHandle) Session(io.trino.Session)

Example 73 with TableHandle

use of io.trino.metadata.TableHandle in project trino by trinodb.

the class TestThriftProjectionPushdown method testDoesNotFire.

@Test
public void testDoesNotFire() {
    PushProjectionIntoTableScan pushProjectionIntoTableScan = new PushProjectionIntoTableScan(tester().getPlannerContext(), tester().getTypeAnalyzer(), new ScalarStatsCalculator(tester().getPlannerContext(), tester().getTypeAnalyzer()));
    String columnName = "orderstatus";
    ColumnHandle columnHandle = new ThriftColumnHandle(columnName, VARCHAR, "", false);
    ConnectorTableHandle tableWithColumns = new ThriftTableHandle(TINY_SCHEMA, "nation", TupleDomain.all(), Optional.of(ImmutableSet.of(columnHandle)));
    tester().assertThat(pushProjectionIntoTableScan).on(p -> {
        Symbol orderStatusSymbol = p.symbol(columnName, VARCHAR);
        return p.project(Assignments.of(p.symbol("expr_2", VARCHAR), orderStatusSymbol.toSymbolReference()), p.tableScan(new TableHandle(new CatalogName(CATALOG), tableWithColumns, ThriftTransactionHandle.INSTANCE), ImmutableList.of(orderStatusSymbol), ImmutableMap.of(orderStatusSymbol, columnHandle)));
    }).doesNotFire();
}
Also used : ThriftTransactionHandle(io.trino.plugin.thrift.ThriftTransactionHandle) Test(org.testng.annotations.Test) ThriftTableHandle(io.trino.plugin.thrift.ThriftTableHandle) CatalogName(io.trino.connector.CatalogName) VARCHAR(io.trino.spi.type.VarcharType.VARCHAR) ImmutableList(com.google.common.collect.ImmutableList) Closer(com.google.common.io.Closer) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle) LocalQueryRunner(io.trino.testing.LocalQueryRunner) Map(java.util.Map) ColumnHandle(io.trino.spi.connector.ColumnHandle) ThriftQueryRunner.startThriftServers(io.trino.plugin.thrift.integration.ThriftQueryRunner.startThriftServers) ThriftColumnHandle(io.trino.plugin.thrift.ThriftColumnHandle) Symbol(io.trino.sql.planner.Symbol) AfterClass(org.testng.annotations.AfterClass) PlanMatchPattern.expression(io.trino.sql.planner.assertions.PlanMatchPattern.expression) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest) Assignments(io.trino.sql.planner.plan.Assignments) DriftServer(io.airlift.drift.server.DriftServer) IOException(java.io.IOException) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) TupleDomain(io.trino.spi.predicate.TupleDomain) ScalarStatsCalculator(io.trino.cost.ScalarStatsCalculator) SchemaTableName(io.trino.spi.connector.SchemaTableName) Collectors.joining(java.util.stream.Collectors.joining) List(java.util.List) TestingSession.testSessionBuilder(io.trino.testing.TestingSession.testSessionBuilder) TableHandle(io.trino.metadata.TableHandle) PlanMatchPattern.project(io.trino.sql.planner.assertions.PlanMatchPattern.project) SymbolReference(io.trino.sql.tree.SymbolReference) PushProjectionIntoTableScan(io.trino.sql.planner.iterative.rule.PushProjectionIntoTableScan) PruneTableScanColumns(io.trino.sql.planner.iterative.rule.PruneTableScanColumns) Optional(java.util.Optional) ThriftQueryRunner.driftServerPort(io.trino.plugin.thrift.integration.ThriftQueryRunner.driftServerPort) PlanMatchPattern.tableScan(io.trino.sql.planner.assertions.PlanMatchPattern.tableScan) Session(io.trino.Session) ThriftPlugin(io.trino.plugin.thrift.ThriftPlugin) ColumnHandle(io.trino.spi.connector.ColumnHandle) ThriftColumnHandle(io.trino.plugin.thrift.ThriftColumnHandle) ThriftTableHandle(io.trino.plugin.thrift.ThriftTableHandle) PushProjectionIntoTableScan(io.trino.sql.planner.iterative.rule.PushProjectionIntoTableScan) Symbol(io.trino.sql.planner.Symbol) ScalarStatsCalculator(io.trino.cost.ScalarStatsCalculator) ThriftColumnHandle(io.trino.plugin.thrift.ThriftColumnHandle) ThriftTableHandle(io.trino.plugin.thrift.ThriftTableHandle) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle) TableHandle(io.trino.metadata.TableHandle) CatalogName(io.trino.connector.CatalogName) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle) Test(org.testng.annotations.Test) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest)

Aggregations

TableHandle (io.trino.metadata.TableHandle)73 Session (io.trino.Session)37 QualifiedObjectName (io.trino.metadata.QualifiedObjectName)33 ColumnHandle (io.trino.spi.connector.ColumnHandle)31 ImmutableMap (com.google.common.collect.ImmutableMap)29 ImmutableList (com.google.common.collect.ImmutableList)28 Optional (java.util.Optional)26 Symbol (io.trino.sql.planner.Symbol)24 Test (org.testng.annotations.Test)24 CatalogName (io.trino.connector.CatalogName)23 Map (java.util.Map)21 TupleDomain (io.trino.spi.predicate.TupleDomain)18 List (java.util.List)17 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)16 BIGINT (io.trino.spi.type.BigintType.BIGINT)15 Type (io.trino.spi.type.Type)15 Assignments (io.trino.sql.planner.plan.Assignments)15 Expression (io.trino.sql.tree.Expression)15 ImmutableSet (com.google.common.collect.ImmutableSet)14 Metadata (io.trino.metadata.Metadata)14