use of io.crate.metadata.IndexParts in project crate by crate.
the class UserPrivileges method matchPrivilegeOfAnyType.
/**
* Try to match a privilege at the given collection ignoring the type.
*/
public boolean matchPrivilegeOfAnyType(Privilege.Clazz clazz, @Nullable String ident) {
boolean foundPrivilege;
switch(clazz) {
case CLUSTER:
foundPrivilege = hasAnyClusterPrivilege();
break;
case SCHEMA:
foundPrivilege = hasAnySchemaPrivilege(ident);
if (foundPrivilege == false) {
foundPrivilege = hasAnyClusterPrivilege();
}
break;
case TABLE:
foundPrivilege = hasAnyTablePrivilege(ident);
if (foundPrivilege == false) {
String schemaIdent = new IndexParts(ident).getSchema();
foundPrivilege = hasAnySchemaPrivilege(schemaIdent);
if (foundPrivilege == false) {
foundPrivilege = hasAnyClusterPrivilege();
}
}
break;
case VIEW:
foundPrivilege = hasAnyViewPrivilege(ident);
if (foundPrivilege == false) {
String schemaIdent = new IndexParts(ident).getSchema();
foundPrivilege = hasAnySchemaPrivilege(schemaIdent);
if (foundPrivilege == false) {
foundPrivilege = hasAnyClusterPrivilege();
}
}
break;
default:
throw new IllegalStateException("Unsupported privilege class=" + clazz);
}
return foundPrivilege;
}
use of io.crate.metadata.IndexParts in project crate by crate.
the class UserDefinedFunctionService method validateFunctionIsNotInUseByGeneratedColumn.
void validateFunctionIsNotInUseByGeneratedColumn(String schema, String functionName, UserDefinedFunctionsMetadata functionsMetadata, ClusterState currentState) {
// The iteration of schemas/tables must happen on the node context WITHOUT the UDF already removed.
// Otherwise the lazy table factories will already fail while evaluating generated functionsMetadata.
// To avoid that, a copy of the node context with the removed UDF function is used on concrete expression evaluation.
var nodeCtxWithRemovedFunction = new NodeContext(nodeCtx.functions().copyOf());
updateImplementations(schema, functionsMetadata.functionsMetadata().stream(), nodeCtxWithRemovedFunction);
var metadata = currentState.metadata();
var indices = Stream.of(metadata.getConcreteAllIndices()).filter(NO_BLOB_NOR_DANGLING).map(IndexParts::new).filter(indexParts -> !indexParts.isPartitioned()).collect(Collectors.toList());
var templates = metadata.getTemplates().keysIt();
while (templates.hasNext()) {
var indexParts = new IndexParts(templates.next());
if (indexParts.isPartitioned()) {
indices.add(indexParts);
}
}
var indexNameExpressionResolver = new IndexNameExpressionResolver();
for (var indexParts : indices) {
var tableInfo = new DocTableInfoBuilder(nodeCtx, indexParts.toRelationName(), currentState, indexNameExpressionResolver).build();
TableReferenceResolver tableReferenceResolver = new TableReferenceResolver(tableInfo.columns(), tableInfo.ident());
CoordinatorTxnCtx coordinatorTxnCtx = CoordinatorTxnCtx.systemTransactionContext();
ExpressionAnalyzer exprAnalyzer = new ExpressionAnalyzer(coordinatorTxnCtx, nodeCtxWithRemovedFunction, ParamTypeHints.EMPTY, tableReferenceResolver, null);
for (var ref : tableInfo.columns()) {
if (ref instanceof GeneratedReference) {
var genRef = (GeneratedReference) ref;
Expression expression = SqlParser.createExpression(genRef.formattedGeneratedExpression());
try {
exprAnalyzer.convert(expression, new ExpressionAnalysisContext(coordinatorTxnCtx.sessionContext()));
} catch (UnsupportedOperationException e) {
throw new IllegalArgumentException("Cannot drop function '" + functionName + "', it is still in use by '" + tableInfo + "." + genRef + "'");
}
}
}
}
}
use of io.crate.metadata.IndexParts in project crate by crate.
the class UserPrivileges method matchPrivilege.
/**
* Try to match a privilege at the given collection.
* If none is found for the current {@link Privilege.Clazz}, try to find one on the upper class.
* If a privilege with a {@link Privilege.State#DENY} state is found, false is returned.
*/
public boolean matchPrivilege(@Nullable Privilege.Type type, Privilege.Clazz clazz, @Nullable String ident, String defaultSchema) {
Privilege foundPrivilege = privilegeByIdent.get(new PrivilegeIdent(type, clazz, ident));
if (foundPrivilege == null) {
switch(clazz) {
case SCHEMA:
foundPrivilege = privilegeByIdent.get(new PrivilegeIdent(type, Privilege.Clazz.CLUSTER, null));
break;
case TABLE:
case VIEW:
String schemaIdent = new IndexParts(ident, defaultSchema).getSchema();
foundPrivilege = privilegeByIdent.get(new PrivilegeIdent(type, Privilege.Clazz.SCHEMA, schemaIdent));
if (foundPrivilege == null) {
foundPrivilege = privilegeByIdent.get(new PrivilegeIdent(type, Privilege.Clazz.CLUSTER, null));
}
break;
default:
}
}
if (foundPrivilege == null) {
return false;
}
switch(foundPrivilege.state()) {
case GRANT:
return true;
case DENY:
default:
return false;
}
}
use of io.crate.metadata.IndexParts in project crate by crate.
the class SQLExecutor method resolveTableInfo.
public <T extends TableInfo> T resolveTableInfo(String tableName) {
IndexParts indexParts = new IndexParts(tableName);
QualifiedName qualifiedName = QualifiedName.of(indexParts.getSchema(), indexParts.getTable());
return (T) schemas.resolveTableInfo(qualifiedName, Operation.READ, sessionContext.sessionUser(), sessionContext.searchPath());
}
Aggregations