Search in sources :

Example 71 with TableHandle

use of io.prestosql.spi.metadata.TableHandle in project hetu-core by openlookeng.

the class MetadataManager method beginUpdate.

@Override
public TableHandle beginUpdate(Session session, TableHandle tableHandle, List<Type> updatedColumnTypes) {
    CatalogName catalogName = tableHandle.getCatalogName();
    ConnectorMetadata metadata = getMetadataForWrite(session, catalogName);
    ConnectorTableHandle newHandle = metadata.beginUpdate(session.toConnectorSession(catalogName), tableHandle.getConnectorHandle(), updatedColumnTypes);
    return new TableHandle(tableHandle.getCatalogName(), newHandle, tableHandle.getTransaction(), tableHandle.getLayout());
}
Also used : CatalogName(io.prestosql.spi.connector.CatalogName) ConnectorVacuumTableHandle(io.prestosql.spi.connector.ConnectorVacuumTableHandle) ConnectorDeleteAsInsertTableHandle(io.prestosql.spi.connector.ConnectorDeleteAsInsertTableHandle) ConnectorUpdateTableHandle(io.prestosql.spi.connector.ConnectorUpdateTableHandle) ConnectorOutputTableHandle(io.prestosql.spi.connector.ConnectorOutputTableHandle) TableHandle(io.prestosql.spi.metadata.TableHandle) ConnectorTableHandle(io.prestosql.spi.connector.ConnectorTableHandle) ConnectorInsertTableHandle(io.prestosql.spi.connector.ConnectorInsertTableHandle) ConnectorMetadata(io.prestosql.spi.connector.ConnectorMetadata) ConnectorTableHandle(io.prestosql.spi.connector.ConnectorTableHandle)

Example 72 with TableHandle

use of io.prestosql.spi.metadata.TableHandle in project hetu-core by openlookeng.

the class MetadataManager method applyProjection.

public Optional<ProjectionApplicationResult<TableHandle>> applyProjection(Session session, TableHandle table, List<ConnectorExpression> projections, Map<String, ColumnHandle> assignments) {
    CatalogName catalogName = table.getCatalogName();
    ConnectorMetadata metadata = getMetadata(session, catalogName);
    if (metadata.usesLegacyTableLayouts()) {
        return Optional.empty();
    }
    ConnectorSession connectorSession = session.toConnectorSession(catalogName);
    return metadata.applyProjection(connectorSession, table.getConnectorHandle(), projections, assignments).map(result -> new ProjectionApplicationResult<>(new TableHandle(catalogName, result.getHandle(), table.getTransaction(), Optional.empty()), result.getProjections(), result.getAssignments()));
}
Also used : CatalogName(io.prestosql.spi.connector.CatalogName) ConnectorSession(io.prestosql.spi.connector.ConnectorSession) ConnectorVacuumTableHandle(io.prestosql.spi.connector.ConnectorVacuumTableHandle) ConnectorDeleteAsInsertTableHandle(io.prestosql.spi.connector.ConnectorDeleteAsInsertTableHandle) ConnectorUpdateTableHandle(io.prestosql.spi.connector.ConnectorUpdateTableHandle) ConnectorOutputTableHandle(io.prestosql.spi.connector.ConnectorOutputTableHandle) TableHandle(io.prestosql.spi.metadata.TableHandle) ConnectorTableHandle(io.prestosql.spi.connector.ConnectorTableHandle) ConnectorInsertTableHandle(io.prestosql.spi.connector.ConnectorInsertTableHandle) ConnectorMetadata(io.prestosql.spi.connector.ConnectorMetadata)

Example 73 with TableHandle

use of io.prestosql.spi.metadata.TableHandle in project hetu-core by openlookeng.

the class MetadataManager method applyDelete.

@Override
public Optional<TableHandle> applyDelete(Session session, TableHandle table, Constraint constraint) {
    CatalogName catalogName = table.getCatalogName();
    ConnectorMetadata metadata = getMetadata(session, catalogName);
    if (metadata.usesLegacyTableLayouts()) {
        return Optional.empty();
    }
    ConnectorSession connectorSession = session.toConnectorSession(catalogName);
    return metadata.applyDelete(connectorSession, table.getConnectorHandle(), constraint).map(newHandle -> new TableHandle(catalogName, newHandle, table.getTransaction(), Optional.empty()));
}
Also used : CatalogName(io.prestosql.spi.connector.CatalogName) ConnectorSession(io.prestosql.spi.connector.ConnectorSession) ConnectorVacuumTableHandle(io.prestosql.spi.connector.ConnectorVacuumTableHandle) ConnectorDeleteAsInsertTableHandle(io.prestosql.spi.connector.ConnectorDeleteAsInsertTableHandle) ConnectorUpdateTableHandle(io.prestosql.spi.connector.ConnectorUpdateTableHandle) ConnectorOutputTableHandle(io.prestosql.spi.connector.ConnectorOutputTableHandle) TableHandle(io.prestosql.spi.metadata.TableHandle) ConnectorTableHandle(io.prestosql.spi.connector.ConnectorTableHandle) ConnectorInsertTableHandle(io.prestosql.spi.connector.ConnectorInsertTableHandle) ConnectorMetadata(io.prestosql.spi.connector.ConnectorMetadata)

Example 74 with TableHandle

use of io.prestosql.spi.metadata.TableHandle in project hetu-core by openlookeng.

the class StatementAnalyzer method validateUpdateIndex.

private void validateUpdateIndex(Table table, Optional<Scope> scope) {
    UpdateIndex updateIndex = (UpdateIndex) analysis.getOriginalStatement();
    IndexRecord indexRecord;
    try {
        indexRecord = heuristicIndexerManager.getIndexClient().lookUpIndexRecord(updateIndex.getIndexName().toString());
    } catch (IOException e) {
        throw new UncheckedIOException("Error reading index records, ", e);
    }
    QualifiedObjectName tableFullName = QualifiedObjectName.valueOf(indexRecord.qualifiedTable);
    accessControl.checkCanCreateIndex(session.getRequiredTransactionId(), session.getIdentity(), tableFullName);
    String tableName = tableFullName.toString();
    Optional<TableHandle> tableHandle = metadata.getTableHandle(session, tableFullName);
    if (!tableHandle.isPresent()) {
        throw new SemanticException(MISSING_ATTRIBUTE, table, "Unable to update index. " + "Index table '%s' may have been dropped from outside OLK. Index should also be dropped.", tableFullName);
    }
    List<Pair<String, Type>> indexColumns = new LinkedList<>();
    for (String i : indexRecord.columns) {
        indexColumns.add(new Pair<>(i, UNKNOWN));
    }
    try {
        // Use this place holder to check the existence of index and lock the place
        Properties properties = new Properties();
        properties.setProperty(INPROGRESS_PROPERTY_KEY, "TRUE");
        CreateIndexMetadata placeHolder = new CreateIndexMetadata(updateIndex.getIndexName().toString(), tableName, indexRecord.indexType, 0L, indexColumns, indexRecord.partitions, properties, session.getUser(), UNDEFINED);
        synchronized (StatementAnalyzer.class) {
            IndexClient.RecordStatus recordStatus = heuristicIndexerManager.getIndexClient().lookUpIndexRecord(placeHolder);
            switch(recordStatus) {
                case IN_PROGRESS_SAME_NAME:
                    throw new SemanticException(INDEX_ALREADY_EXISTS, updateIndex, "Index '%s' is being created by another user. Check running queries for details. If there is no running query for this index, " + "the index may be in an unexpected error state and should be dropped using 'DROP INDEX %s'", updateIndex.getIndexName().toString(), updateIndex.getIndexName().toString());
                case IN_PROGRESS_SAME_CONTENT:
                    throw new SemanticException(INDEX_ALREADY_EXISTS, updateIndex, "Index with same (table,column,indexType) is being created by another user. Check running queries for details. " + "If there is no running query for this index, the index may be in an unexpected error state and should be dropped using 'DROP INDEX'");
                case IN_PROGRESS_SAME_INDEX_PART_CONFLICT:
                    if (indexRecord.partitions.isEmpty()) {
                        throw new SemanticException(INDEX_ALREADY_EXISTS, updateIndex, "Index with same (table,column,indexType) is being created by another user. Check running queries for details. " + "If there is no running query for this index, the index may be in an unexpected error state and should be dropped using 'DROP INDEX %s'", updateIndex.getIndexName().toString());
                    }
                // allow different queries to run with explicitly same partitions
                case NOT_FOUND:
                    throw new SemanticException(MISSING_INDEX, updateIndex, "Index with name '%s' does not exist", updateIndex.getIndexName().toString());
            }
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : CreateIndexMetadata(io.prestosql.spi.connector.CreateIndexMetadata) IndexClient(io.prestosql.spi.heuristicindex.IndexClient) UncheckedIOException(java.io.UncheckedIOException) UpdateIndex(io.prestosql.sql.tree.UpdateIndex) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) NodeUtils.mapFromProperties(io.prestosql.sql.NodeUtils.mapFromProperties) SystemSessionProperties(io.prestosql.SystemSessionProperties) Properties(java.util.Properties) IndexRecord(io.prestosql.spi.heuristicindex.IndexRecord) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) MetadataUtil.createQualifiedObjectName(io.prestosql.metadata.MetadataUtil.createQualifiedObjectName) LinkedList(java.util.LinkedList) TableHandle(io.prestosql.spi.metadata.TableHandle) Pair(io.prestosql.spi.heuristicindex.Pair)

Example 75 with TableHandle

use of io.prestosql.spi.metadata.TableHandle in project hetu-core by openlookeng.

the class TestHiveIntegrationSmokeTest method getHiveTableProperty.

private Object getHiveTableProperty(String tableName, Function<HiveTableHandle, Object> propertyGetter) {
    Session session = getSession();
    Metadata metadata = ((DistributedQueryRunner) getQueryRunner()).getCoordinator().getMetadata();
    return transaction(getQueryRunner().getTransactionManager(), getQueryRunner().getAccessControl()).readOnly().execute(session, transactionSession -> {
        QualifiedObjectName name = new QualifiedObjectName(catalog, TPCH_SCHEMA, tableName);
        TableHandle table = metadata.getTableHandle(transactionSession, name).orElseThrow(() -> new AssertionError("table not found: " + name));
        table = metadata.applyFilter(transactionSession, table, Constraint.alwaysTrue()).orElseThrow(() -> new AssertionError("applyFilter did not return a result")).getHandle();
        return propertyGetter.apply((HiveTableHandle) table.getConnectorHandle());
    });
}
Also used : Metadata(io.prestosql.metadata.Metadata) TableMetadata(io.prestosql.metadata.TableMetadata) ColumnMetadata(io.prestosql.spi.connector.ColumnMetadata) InsertTableHandle(io.prestosql.metadata.InsertTableHandle) TableHandle(io.prestosql.spi.metadata.TableHandle) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) Session(io.prestosql.Session) ConnectorSession(io.prestosql.spi.connector.ConnectorSession)

Aggregations

TableHandle (io.prestosql.spi.metadata.TableHandle)79 ColumnHandle (io.prestosql.spi.connector.ColumnHandle)34 Session (io.prestosql.Session)33 QualifiedObjectName (io.prestosql.spi.connector.QualifiedObjectName)32 Symbol (io.prestosql.spi.plan.Symbol)30 CatalogName (io.prestosql.spi.connector.CatalogName)28 Metadata (io.prestosql.metadata.Metadata)27 ImmutableList (com.google.common.collect.ImmutableList)25 TableMetadata (io.prestosql.metadata.TableMetadata)25 ColumnMetadata (io.prestosql.spi.connector.ColumnMetadata)25 TableScanNode (io.prestosql.spi.plan.TableScanNode)25 Map (java.util.Map)24 Optional (java.util.Optional)24 ImmutableMap (com.google.common.collect.ImmutableMap)22 PlanNode (io.prestosql.spi.plan.PlanNode)22 List (java.util.List)22 ArrayList (java.util.ArrayList)21 HashMap (java.util.HashMap)21 ConnectorTableHandle (io.prestosql.spi.connector.ConnectorTableHandle)20 Type (io.prestosql.spi.type.Type)19