Search in sources :

Example 11 with SchemaInfo

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;
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) DocTableInfo(io.crate.metadata.doc.DocTableInfo) TableInfo(io.crate.metadata.table.TableInfo) BlobSchemaInfo(io.crate.metadata.blob.BlobSchemaInfo) SysSchemaInfo(io.crate.metadata.sys.SysSchemaInfo) SchemaInfo(io.crate.metadata.table.SchemaInfo) InformationSchemaInfo(io.crate.metadata.information.InformationSchemaInfo)

Example 12 with SchemaInfo

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);
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) SchemaInfo(io.crate.metadata.table.SchemaInfo) Test(org.junit.Test)

Example 13 with SchemaInfo

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;
    }
}
Also used : TableInfo(io.crate.metadata.table.TableInfo) BlobSchemaInfo(io.crate.metadata.blob.BlobSchemaInfo) PgCatalogSchemaInfo(io.crate.metadata.pgcatalog.PgCatalogSchemaInfo) SysSchemaInfo(io.crate.metadata.sys.SysSchemaInfo) SchemaInfo(io.crate.metadata.table.SchemaInfo) InformationSchemaInfo(io.crate.metadata.information.InformationSchemaInfo)

Example 14 with SchemaInfo

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;
}
Also used : RelationUnknown(io.crate.exceptions.RelationUnknown) TableInfo(io.crate.metadata.table.TableInfo) BlobSchemaInfo(io.crate.metadata.blob.BlobSchemaInfo) PgCatalogSchemaInfo(io.crate.metadata.pgcatalog.PgCatalogSchemaInfo) SysSchemaInfo(io.crate.metadata.sys.SysSchemaInfo) SchemaInfo(io.crate.metadata.table.SchemaInfo) InformationSchemaInfo(io.crate.metadata.information.InformationSchemaInfo)

Example 15 with SchemaInfo

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);
}
Also used : TableInfo(io.crate.metadata.table.TableInfo) SchemaInfo(io.crate.metadata.table.SchemaInfo) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test) ViewsMetadataTest(io.crate.metadata.view.ViewsMetadataTest)

Aggregations

SchemaInfo (io.crate.metadata.table.SchemaInfo)16 BlobSchemaInfo (io.crate.metadata.blob.BlobSchemaInfo)10 InformationSchemaInfo (io.crate.metadata.information.InformationSchemaInfo)10 SysSchemaInfo (io.crate.metadata.sys.SysSchemaInfo)10 TableInfo (io.crate.metadata.table.TableInfo)10 PgCatalogSchemaInfo (io.crate.metadata.pgcatalog.PgCatalogSchemaInfo)7 DocTableInfo (io.crate.metadata.doc.DocTableInfo)6 RelationUnknown (io.crate.exceptions.RelationUnknown)3 SchemaUnknownException (io.crate.exceptions.SchemaUnknownException)3 VisibleForTesting (io.crate.common.annotations.VisibleForTesting)2 Row (io.crate.data.Row)2 PartitionUnknownException (io.crate.exceptions.PartitionUnknownException)2 ResourceUnknownException (io.crate.exceptions.ResourceUnknownException)2 CoordinatorTxnCtx (io.crate.metadata.CoordinatorTxnCtx)2 PartitionName (io.crate.metadata.PartitionName)2 RelationName (io.crate.metadata.RelationName)2 Schemas (io.crate.metadata.Schemas)2 Table (io.crate.sql.tree.Table)2 Settings (org.elasticsearch.common.settings.Settings)2 Test (org.junit.Test)2