Search in sources :

Example 6 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 7 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 8 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(UnsupportedOperationException.class);
    expectedException.expectMessage("The table foo.bar is read-only. Write, Drop or Alter operations are not supported");
    TableIdent tableIdent = new TableIdent("foo", "bar");
    SchemaInfo schemaInfo = mock(SchemaInfo.class);
    TableInfo tableInfo = mock(TableInfo.class);
    when(tableInfo.ident()).thenReturn(tableIdent);
    when(schemaInfo.getTableInfo(tableIdent.name())).thenReturn(tableInfo);
    when(schemaInfo.name()).thenReturn(tableIdent.schema());
    Schemas schemas = getReferenceInfos(schemaInfo);
    schemas.getWritableTable(tableIdent);
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) TableInfo(io.crate.metadata.table.TableInfo) SchemaInfo(io.crate.metadata.table.SchemaInfo) Test(org.junit.Test)

Aggregations

SchemaInfo (io.crate.metadata.table.SchemaInfo)8 DocTableInfo (io.crate.metadata.doc.DocTableInfo)5 BlobSchemaInfo (io.crate.metadata.blob.BlobSchemaInfo)4 InformationSchemaInfo (io.crate.metadata.information.InformationSchemaInfo)4 SysSchemaInfo (io.crate.metadata.sys.SysSchemaInfo)4 TableInfo (io.crate.metadata.table.TableInfo)4 SchemaUnknownException (io.crate.exceptions.SchemaUnknownException)2 TableUnknownException (io.crate.exceptions.TableUnknownException)2 Settings (org.elasticsearch.common.settings.Settings)2 Test (org.junit.Test)2 Sets (com.google.common.collect.Sets)1 PartitionUnknownException (io.crate.exceptions.PartitionUnknownException)1 ResourceUnknownException (io.crate.exceptions.ResourceUnknownException)1 PartitionName (io.crate.metadata.PartitionName)1 QualifiedName (io.crate.sql.tree.QualifiedName)1 Statement (io.crate.sql.tree.Statement)1 Table (io.crate.sql.tree.Table)1 TransportPutIndexTemplateAction (org.elasticsearch.action.admin.indices.template.put.TransportPutIndexTemplateAction)1 ClusterService (org.elasticsearch.cluster.ClusterService)1 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)1