Search in sources :

Example 1 with IndexSourceNode

use of io.trino.sql.planner.plan.IndexSourceNode in project trino by trinodb.

the class ColumnReference method getAssignedSymbol.

@Override
public Optional<Symbol> getAssignedSymbol(PlanNode node, Session session, Metadata metadata, SymbolAliases symbolAliases) {
    TableHandle tableHandle;
    Map<Symbol, ColumnHandle> assignments;
    if (node instanceof TableScanNode) {
        TableScanNode tableScanNode = (TableScanNode) node;
        tableHandle = tableScanNode.getTable();
        assignments = tableScanNode.getAssignments();
    } else if (node instanceof IndexSourceNode) {
        IndexSourceNode indexSourceNode = (IndexSourceNode) node;
        tableHandle = indexSourceNode.getTableHandle();
        assignments = indexSourceNode.getAssignments();
    } else {
        return Optional.empty();
    }
    TableMetadata tableMetadata = metadata.getTableMetadata(session, tableHandle);
    String actualTableName = tableMetadata.getTable().getTableName();
    // Wrong table -> doesn't match.
    if (!tableName.equalsIgnoreCase(actualTableName)) {
        return Optional.empty();
    }
    Optional<ColumnHandle> columnHandle = getColumnHandle(tableHandle, session, metadata);
    checkState(columnHandle.isPresent(), "Table %s doesn't have column %s. Typo in test?", tableName, columnName);
    return getAssignedSymbol(assignments, columnHandle.get());
}
Also used : TableMetadata(io.trino.metadata.TableMetadata) ColumnHandle(io.trino.spi.connector.ColumnHandle) TableScanNode(io.trino.sql.planner.plan.TableScanNode) Symbol(io.trino.sql.planner.Symbol) IndexSourceNode(io.trino.sql.planner.plan.IndexSourceNode) TableHandle(io.trino.metadata.TableHandle)

Example 2 with IndexSourceNode

use of io.trino.sql.planner.plan.IndexSourceNode in project trino by trinodb.

the class PruneIndexSourceColumns method pushDownProjectOff.

@Override
protected Optional<PlanNode> pushDownProjectOff(Context context, IndexSourceNode indexSourceNode, Set<Symbol> referencedOutputs) {
    Set<Symbol> prunedLookupSymbols = indexSourceNode.getLookupSymbols().stream().filter(referencedOutputs::contains).collect(toImmutableSet());
    Map<Symbol, ColumnHandle> prunedAssignments = Maps.filterEntries(indexSourceNode.getAssignments(), entry -> referencedOutputs.contains(entry.getKey()));
    List<Symbol> prunedOutputList = indexSourceNode.getOutputSymbols().stream().filter(referencedOutputs::contains).collect(toImmutableList());
    return Optional.of(new IndexSourceNode(indexSourceNode.getId(), indexSourceNode.getIndexHandle(), indexSourceNode.getTableHandle(), prunedLookupSymbols, prunedOutputList, prunedAssignments));
}
Also used : ColumnHandle(io.trino.spi.connector.ColumnHandle) Symbol(io.trino.sql.planner.Symbol) IndexSourceNode(io.trino.sql.planner.plan.IndexSourceNode)

Example 3 with IndexSourceNode

use of io.trino.sql.planner.plan.IndexSourceNode in project trino by trinodb.

the class IndexSourceMatcher method detailMatches.

@Override
public MatchResult detailMatches(PlanNode node, StatsProvider stats, Session session, Metadata metadata, SymbolAliases symbolAliases) {
    checkState(shapeMatches(node), "Plan testing framework error: shapeMatches returned false in detailMatches in %s", this.getClass().getName());
    IndexSourceNode indexSourceNode = (IndexSourceNode) node;
    TableMetadata tableMetadata = metadata.getTableMetadata(session, indexSourceNode.getTableHandle());
    String actualTableName = tableMetadata.getTable().getTableName();
    if (!expectedTableName.equalsIgnoreCase(actualTableName)) {
        return NO_MATCH;
    }
    return match();
}
Also used : TableMetadata(io.trino.metadata.TableMetadata) IndexSourceNode(io.trino.sql.planner.plan.IndexSourceNode)

Aggregations

IndexSourceNode (io.trino.sql.planner.plan.IndexSourceNode)3 TableMetadata (io.trino.metadata.TableMetadata)2 ColumnHandle (io.trino.spi.connector.ColumnHandle)2 Symbol (io.trino.sql.planner.Symbol)2 TableHandle (io.trino.metadata.TableHandle)1 TableScanNode (io.trino.sql.planner.plan.TableScanNode)1