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());
}
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()));
}
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()));
}
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);
}
}
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());
});
}
Aggregations