use of io.crate.exceptions.RelationUnknown in project crate by crate.
the class TableSettingsResolver method forPartitionedTable.
private static Settings forPartitionedTable(Metadata metadata, RelationName relationName) {
String templateName = PartitionName.templateName(relationName.schema(), relationName.name());
IndexTemplateMetadata templateMetadata = metadata.templates().get(templateName);
if (templateMetadata == null) {
throw new RelationUnknown(relationName);
}
return templateMetadata.getSettings();
}
use of io.crate.exceptions.RelationUnknown in project crate by crate.
the class Schemas method resolveTableInfo.
public TableInfo resolveTableInfo(QualifiedName ident, Operation operation, User user, SearchPath searchPath) {
String identSchema = schemaName(ident);
String tableName = relationName(ident);
SchemaInfo schemaInfo;
TableInfo tableInfo = null;
if (identSchema == null) {
for (String pathSchema : searchPath) {
schemaInfo = schemas.get(pathSchema);
if (schemaInfo != null) {
tableInfo = schemaInfo.getTableInfo(tableName);
if (tableInfo != null) {
break;
}
}
}
if (tableInfo == null) {
SchemaInfo currentSchema = schemas.get(searchPath.currentSchema());
if (currentSchema == null) {
throw new RelationUnknown(tableName);
} else {
throw RelationUnknown.of(tableName, getSimilarTables(user, tableName, currentSchema.getTables()));
}
}
} else {
schemaInfo = schemas.get(identSchema);
if (schemaInfo == null) {
throw SchemaUnknownException.of(identSchema, getSimilarSchemas(user, identSchema));
} else {
tableInfo = schemaInfo.getTableInfo(tableName);
if (tableInfo == null) {
throw RelationUnknown.of(ident.toString(), getSimilarTables(user, tableName, schemaInfo.getTables()));
}
}
}
Operation.blockedRaiseException(tableInfo, operation);
return tableInfo;
}
use of io.crate.exceptions.RelationUnknown in project crate by crate.
the class InternalBlobTableInfoFactory method resolveIndexMetadata.
private IndexMetadata resolveIndexMetadata(String tableName, ClusterState state) {
String indexName = BlobIndex.fullIndexName(tableName);
Index index;
try {
index = indexNameExpressionResolver.concreteIndices(state, IndicesOptions.strictExpandOpen(), indexName)[0];
} catch (IndexNotFoundException ex) {
throw new RelationUnknown(indexName, ex);
}
return state.metadata().index(index);
}
use of io.crate.exceptions.RelationUnknown in project crate by crate.
the class RestoreSnapshotPlan method bind.
@VisibleForTesting
public static BoundRestoreSnapshot bind(AnalyzedRestoreSnapshot restoreSnapshot, CoordinatorTxnCtx txnCtx, NodeContext nodeCtx, Row parameters, SubQueryResults subQueryResults, Schemas schemas) {
Function<? super Symbol, Object> eval = x -> SymbolEvaluator.evaluate(txnCtx, nodeCtx, x, parameters, subQueryResults);
Settings settings = GenericPropertiesConverter.genericPropertiesToSettings(restoreSnapshot.properties().map(eval), SnapshotSettings.SETTINGS);
HashSet<BoundRestoreSnapshot.RestoreTableInfo> restoreTables = new HashSet<>(restoreSnapshot.tables().size());
for (Table<Symbol> table : restoreSnapshot.tables()) {
var relationName = RelationName.of(table.getName(), txnCtx.sessionContext().searchPath().currentSchema());
try {
DocTableInfo docTableInfo = schemas.getTableInfo(relationName, Operation.RESTORE_SNAPSHOT);
if (table.partitionProperties().isEmpty()) {
throw new RelationAlreadyExists(relationName);
}
var partitionName = toPartitionName(docTableInfo, Lists2.map(table.partitionProperties(), x -> x.map(eval)));
if (docTableInfo.partitions().contains(partitionName)) {
throw new PartitionAlreadyExistsException(partitionName);
}
restoreTables.add(new BoundRestoreSnapshot.RestoreTableInfo(relationName, partitionName));
} catch (RelationUnknown | SchemaUnknownException e) {
if (table.partitionProperties().isEmpty()) {
restoreTables.add(new BoundRestoreSnapshot.RestoreTableInfo(relationName, null));
} else {
var partitionName = toPartitionName(relationName, Lists2.map(table.partitionProperties(), x -> x.map(eval)));
restoreTables.add(new BoundRestoreSnapshot.RestoreTableInfo(relationName, partitionName));
}
}
}
return new BoundRestoreSnapshot(restoreSnapshot.repository(), restoreSnapshot.snapshot(), restoreTables, restoreSnapshot.includeTables(), restoreSnapshot.includeCustomMetadata(), restoreSnapshot.customMetadataTypes(), restoreSnapshot.includeGlobalSettings(), restoreSnapshot.globalSettings(), settings);
}
use of io.crate.exceptions.RelationUnknown in project crate by crate.
the class RelationAnalyzer method visitTable.
@Override
protected AnalyzedRelation visitTable(Table<?> node, StatementAnalysisContext context) {
QualifiedName tableQualifiedName = node.getName();
SearchPath searchPath = context.sessionContext().searchPath();
AnalyzedRelation relation;
TableInfo tableInfo;
try {
tableInfo = schemas.resolveTableInfo(tableQualifiedName, context.currentOperation(), context.sessionContext().sessionUser(), searchPath);
if (tableInfo instanceof DocTableInfo) {
// Dispatching of doc relations is based on the returned class of the schema information.
relation = new DocTableRelation((DocTableInfo) tableInfo);
} else {
relation = new TableRelation(tableInfo);
}
} catch (RelationUnknown e) {
Tuple<ViewMetadata, RelationName> viewMetadata;
try {
viewMetadata = schemas.resolveView(tableQualifiedName, searchPath);
} catch (RelationUnknown e1) {
// don't shadow original exception, as looking for the view is just a fallback
throw e;
}
ViewMetadata view = viewMetadata.v1();
AnalyzedRelation resolvedView = SqlParser.createStatement(view.stmt()).accept(this, context);
relation = new AnalyzedView(viewMetadata.v2(), view.owner(), resolvedView);
}
context.currentRelationContext().addSourceRelation(relation);
return relation;
}
Aggregations