use of io.crate.exceptions.RelationUnknown in project crate by crate.
the class RelationAnalyzer method visitJoin.
@Override
protected AnalyzedRelation visitJoin(Join node, StatementAnalysisContext statementContext) {
AnalyzedRelation leftRel = node.getLeft().accept(this, statementContext);
AnalyzedRelation rightRel = node.getRight().accept(this, statementContext);
RelationAnalysisContext relationContext = statementContext.currentRelationContext();
Optional<JoinCriteria> optCriteria = node.getCriteria();
Symbol joinCondition = null;
if (optCriteria.isPresent()) {
JoinCriteria joinCriteria = optCriteria.get();
if (joinCriteria instanceof JoinOn || joinCriteria instanceof JoinUsing) {
final CoordinatorTxnCtx coordinatorTxnCtx = statementContext.transactionContext();
ExpressionAnalyzer expressionAnalyzer = new ExpressionAnalyzer(coordinatorTxnCtx, nodeCtx, statementContext.paramTyeHints(), new FullQualifiedNameFieldProvider(relationContext.sources(), relationContext.parentSources(), coordinatorTxnCtx.sessionContext().searchPath().currentSchema()), new SubqueryAnalyzer(this, statementContext));
Expression expr;
if (joinCriteria instanceof JoinOn) {
expr = ((JoinOn) joinCriteria).getExpression();
} else {
expr = JoinUsing.toExpression(leftRel.relationName().toQualifiedName(), rightRel.relationName().toQualifiedName(), ((JoinUsing) joinCriteria).getColumns());
}
try {
joinCondition = expressionAnalyzer.convert(expr, relationContext.expressionAnalysisContext());
} catch (RelationUnknown e) {
throw new RelationValidationException(e.getTableIdents(), String.format(Locale.ENGLISH, "missing FROM-clause entry for relation '%s'", e.getTableIdents()));
}
} else {
throw new UnsupportedOperationException(String.format(Locale.ENGLISH, "join criteria %s not supported", joinCriteria.getClass().getSimpleName()));
}
}
relationContext.addJoinType(JoinType.values()[node.getType().ordinal()], joinCondition);
return null;
}
use of io.crate.exceptions.RelationUnknown in project crate by crate.
the class DocTableInfoBuilder method docIndexMetadata.
private DocIndexMetadata docIndexMetadata() {
DocIndexMetadata docIndexMetadata;
String templateName = PartitionName.templateName(ident.schema(), ident.name());
if (metadata.getTemplates().containsKey(templateName)) {
docIndexMetadata = buildDocIndexMetadataFromTemplate(ident.indexNameOrAlias(), templateName);
// We need all concrete indices, regardless of their state, for operations such as reopening.
concreteIndices = indexNameExpressionResolver.concreteIndexNames(state, IndicesOptions.lenientExpandOpen(), ident.indexNameOrAlias());
// We need all concrete open indices, as closed indices must not appear in the routing.
concreteOpenIndices = indexNameExpressionResolver.concreteIndexNames(state, IndicesOptions.fromOptions(true, true, true, false, IndicesOptions.strictExpandOpenAndForbidClosed()), ident.indexNameOrAlias());
} else {
try {
concreteIndices = indexNameExpressionResolver.concreteIndexNames(state, IndicesOptions.strictExpandOpen(), ident.indexNameOrAlias());
concreteOpenIndices = concreteIndices;
if (concreteIndices.length == 0) {
// no matching index found
throw new RelationUnknown(ident);
}
docIndexMetadata = buildDocIndexMetadata(concreteIndices[0]);
} catch (IndexNotFoundException ex) {
throw new RelationUnknown(ident.fqn(), ex);
}
}
return docIndexMetadata;
}
use of io.crate.exceptions.RelationUnknown in project crate by crate.
the class DropTableAnalyzer method analyze.
private <T extends TableInfo> AnalyzedDropTable<T> analyze(QualifiedName name, boolean dropIfExists, SessionContext sessionContext) {
T tableInfo;
RelationName tableName;
boolean maybeCorrupt = false;
try {
// noinspection unchecked
tableInfo = (T) schemas.resolveTableInfo(name, Operation.DROP, sessionContext.sessionUser(), sessionContext.searchPath());
tableName = tableInfo.ident();
} catch (SchemaUnknownException | RelationUnknown e) {
tableName = RelationName.of(name, sessionContext.searchPath().currentSchema());
var metadata = clusterService.state().metadata();
var indexNameOrAlias = tableName.indexNameOrAlias();
if (metadata.hasIndex(indexNameOrAlias) || metadata.templates().containsKey(indexNameOrAlias)) {
tableInfo = null;
maybeCorrupt = true;
} else if (dropIfExists) {
tableInfo = null;
} else {
throw e;
}
} catch (OperationOnInaccessibleRelationException e) {
throw e;
} catch (Throwable t) {
if (!sessionContext.sessionUser().isSuperUser()) {
throw t;
}
tableInfo = null;
maybeCorrupt = true;
tableName = RelationName.of(name, sessionContext.searchPath().currentSchema());
LOGGER.info("Unexpected error resolving table during DROP TABLE operation on {}. " + "Proceeding with operation as table schema may be corrupt (error={})", tableName, t);
}
return new AnalyzedDropTable<>(tableInfo, dropIfExists, tableName, maybeCorrupt);
}
use of io.crate.exceptions.RelationUnknown in project crate by crate.
the class ReservoirSampler method getSamples.
public Samples getSamples(RelationName relationName, List<Reference> columns, int maxSamples) {
TableInfo table;
try {
table = schemas.getTableInfo(relationName);
} catch (RelationUnknown e) {
return Samples.EMPTY;
}
if (!(table instanceof DocTableInfo)) {
return Samples.EMPTY;
}
DocTableInfo docTable = (DocTableInfo) table;
Random random = Randomness.get();
Metadata metadata = clusterService.state().metadata();
CoordinatorTxnCtx coordinatorTxnCtx = CoordinatorTxnCtx.systemTransactionContext();
List<Streamer> streamers = Arrays.asList(Symbols.streamerArray(columns));
List<Engine.Searcher> searchersToRelease = new ArrayList<>();
CircuitBreaker breaker = circuitBreakerService.getBreaker(HierarchyCircuitBreakerService.QUERY);
RamAccounting ramAccounting = new BlockBasedRamAccounting(b -> breaker.addEstimateBytesAndMaybeBreak(b, "Reservoir-sampling"), MAX_BLOCK_SIZE_IN_BYTES);
try {
return getSamples(columns, maxSamples, docTable, random, metadata, coordinatorTxnCtx, streamers, searchersToRelease, ramAccounting);
} finally {
ramAccounting.close();
for (Engine.Searcher searcher : searchersToRelease) {
searcher.close();
}
}
}
Aggregations