use of io.crate.metadata.table.SchemaInfo in project crate by crate.
the class Schemas method tableExists.
public boolean tableExists(TableIdent tableIdent) {
SchemaInfo schemaInfo = schemas.get(firstNonNull(tableIdent.schema(), DEFAULT_SCHEMA_NAME));
if (schemaInfo == null) {
return false;
}
schemaInfo.invalidateTableCache(tableIdent.name());
TableInfo tableInfo = schemaInfo.getTableInfo(tableIdent.name());
if (tableInfo == null) {
return false;
} else if ((tableInfo instanceof DocTableInfo)) {
return !isOrphanedAlias((DocTableInfo) tableInfo);
}
return true;
}
use of io.crate.metadata.table.SchemaInfo in project crate by crate.
the class SchemasTest method testTableAliasIsNotWritable.
@Test
public void testTableAliasIsNotWritable() throws Exception {
expectedException.expect(UnsupportedOperationException.class);
expectedException.expectMessage("foo.bar is an alias. Write, Drop or Alter operations are not supported");
TableIdent tableIdent = new TableIdent("foo", "bar");
SchemaInfo schemaInfo = mock(SchemaInfo.class);
DocTableInfo tableInfo = mock(DocTableInfo.class);
when(tableInfo.ident()).thenReturn(tableIdent);
when(schemaInfo.getTableInfo(tableIdent.name())).thenReturn(tableInfo);
when(schemaInfo.name()).thenReturn(tableIdent.schema());
when(tableInfo.isAlias()).thenReturn(true);
Schemas schemas = getReferenceInfos(schemaInfo);
schemas.getWritableTable(tableIdent);
}
use of io.crate.metadata.table.SchemaInfo in project crate by crate.
the class Schemas method tableExists.
public boolean tableExists(RelationName relationName) {
SchemaInfo schemaInfo = schemas.get(relationName.schema());
if (schemaInfo == null) {
return false;
}
schemaInfo.invalidateTableCache(relationName.name());
TableInfo tableInfo = schemaInfo.getTableInfo(relationName.name());
if (tableInfo == null) {
return false;
} else {
return true;
}
}
use of io.crate.metadata.table.SchemaInfo 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.metadata.table.SchemaInfo in project crate by crate.
the class SchemasTest method testSystemSchemaIsNotWritable.
@Test
public void testSystemSchemaIsNotWritable() throws Exception {
expectedException.expect(OperationOnInaccessibleRelationException.class);
expectedException.expectMessage("The relation \"foo.bar\" doesn't support or allow INSERT " + "operations, as it is read-only.");
RelationName relationName = new RelationName("foo", "bar");
SchemaInfo schemaInfo = mock(SchemaInfo.class);
TableInfo tableInfo = mock(TableInfo.class);
when(tableInfo.ident()).thenReturn(relationName);
when(tableInfo.supportedOperations()).thenReturn(Operation.SYS_READ_ONLY);
when(schemaInfo.getTableInfo(relationName.name())).thenReturn(tableInfo);
when(schemaInfo.name()).thenReturn(relationName.schema());
Schemas schemas = getReferenceInfos(schemaInfo);
schemas.getTableInfo(relationName, Operation.INSERT);
}
Aggregations