Search in sources :

Example 1 with TableUnknownException

use of io.crate.exceptions.TableUnknownException in project crate by crate.

the class DropBlobTableAnalyzerTest method testDeletingNoExistingTableSetsNoopIfIgnoreNonExistentTablesIsSet.

@Test
public void testDeletingNoExistingTableSetsNoopIfIgnoreNonExistentTablesIsSet() throws Exception {
    when(schemas.getTableInfo(tableIdent)).thenThrow(new TableUnknownException(tableIdent));
    DropBlobTableAnalyzedStatement statement = analyzer.analyze(new DropBlobTable(table, true));
    assertThat(statement.noop(), is(true));
}
Also used : DropBlobTable(io.crate.sql.tree.DropBlobTable) TableUnknownException(io.crate.exceptions.TableUnknownException) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 2 with TableUnknownException

use of io.crate.exceptions.TableUnknownException in project crate by crate.

the class DropBlobTableAnalyzerTest method testDeletingNonExistingTableRaisesException.

@Test
public void testDeletingNonExistingTableRaisesException() throws Exception {
    when(schemas.getTableInfo(tableIdent)).thenThrow(new TableUnknownException(tableIdent));
    expectedException.expect(TableUnknownException.class);
    expectedException.expectMessage("Table 'blob.Irrelevant' unknown");
    analyzer.analyze(new DropBlobTable(table, false));
}
Also used : DropBlobTable(io.crate.sql.tree.DropBlobTable) TableUnknownException(io.crate.exceptions.TableUnknownException) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 3 with TableUnknownException

use of io.crate.exceptions.TableUnknownException in project crate by crate.

the class DocTableInfoBuilder method docIndexMetaData.

private DocIndexMetaData docIndexMetaData() {
    DocIndexMetaData docIndexMetaData;
    String templateName = PartitionName.templateName(ident.schema(), ident.name());
    boolean createdFromTemplate = false;
    if (metaData.getTemplates().containsKey(templateName)) {
        docIndexMetaData = buildDocIndexMetaDataFromTemplate(ident.indexName(), templateName);
        createdFromTemplate = true;
        concreteIndices = indexNameExpressionResolver.concreteIndices(state, IndicesOptions.lenientExpandOpen(), ident.indexName());
    } else {
        try {
            concreteIndices = indexNameExpressionResolver.concreteIndices(state, IndicesOptions.strictExpandOpen(), ident.indexName());
            if (concreteIndices.length == 0) {
                // no matching index found
                throw new TableUnknownException(ident);
            }
            docIndexMetaData = buildDocIndexMetaData(concreteIndices[0]);
        } catch (IndexNotFoundException ex) {
            throw new TableUnknownException(ident.fqn(), ex);
        }
    }
    if ((!createdFromTemplate && concreteIndices.length == 1) || !checkAliasSchema) {
        return docIndexMetaData;
    }
    for (String concreteIndice : concreteIndices) {
        if (IndexMetaData.State.CLOSE.equals(metaData.indices().get(concreteIndice).getState())) {
            throw new UnhandledServerException(String.format(Locale.ENGLISH, "Unable to access the partition %s, it is closed", concreteIndice));
        }
        try {
            docIndexMetaData = docIndexMetaData.merge(buildDocIndexMetaData(concreteIndice), transportPutIndexTemplateAction, createdFromTemplate);
        } catch (IOException e) {
            throw new UnhandledServerException("Unable to merge/build new DocIndexMetaData", e);
        }
    }
    return docIndexMetaData;
}
Also used : IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) UnhandledServerException(io.crate.exceptions.UnhandledServerException) TableUnknownException(io.crate.exceptions.TableUnknownException) IOException(java.io.IOException)

Example 4 with TableUnknownException

use of io.crate.exceptions.TableUnknownException in project crate by crate.

the class InternalBlobTableInfoFactory method resolveIndexMetaData.

private IndexMetaData resolveIndexMetaData(String tableName, ClusterState state) {
    String index = BlobIndex.fullIndexName(tableName);
    String[] concreteIndices;
    try {
        concreteIndices = indexNameExpressionResolver.concreteIndices(state, IndicesOptions.strictExpandOpen(), index);
    } catch (IndexNotFoundException ex) {
        throw new TableUnknownException(index, ex);
    }
    return state.metaData().index(concreteIndices[0]);
}
Also used : IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) TableUnknownException(io.crate.exceptions.TableUnknownException)

Example 5 with TableUnknownException

use of io.crate.exceptions.TableUnknownException in project crate by crate.

the class Schemas method getTableInfo.

/**
     * @param ident the table ident to get a TableInfo for
     * @return an instance of TableInfo for the given ident, guaranteed to be not null
     * @throws io.crate.exceptions.SchemaUnknownException if schema given in <code>ident</code>
     *                                                    does not exist
     * @throws io.crate.exceptions.TableUnknownException  if table given in <code>ident</code> does
     *                                                    not exist in the given schema
     */
public TableInfo getTableInfo(TableIdent ident) {
    SchemaInfo schemaInfo = getSchemaInfo(ident);
    TableInfo info;
    info = schemaInfo.getTableInfo(ident.name());
    if (info == null) {
        throw new TableUnknownException(ident);
    }
    return info;
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) TableInfo(io.crate.metadata.table.TableInfo) TableUnknownException(io.crate.exceptions.TableUnknownException) BlobSchemaInfo(io.crate.metadata.blob.BlobSchemaInfo) SysSchemaInfo(io.crate.metadata.sys.SysSchemaInfo) SchemaInfo(io.crate.metadata.table.SchemaInfo) InformationSchemaInfo(io.crate.metadata.information.InformationSchemaInfo)

Aggregations

TableUnknownException (io.crate.exceptions.TableUnknownException)5 DropBlobTable (io.crate.sql.tree.DropBlobTable)2 CrateUnitTest (io.crate.test.integration.CrateUnitTest)2 IndexNotFoundException (org.elasticsearch.index.IndexNotFoundException)2 Test (org.junit.Test)2 UnhandledServerException (io.crate.exceptions.UnhandledServerException)1 BlobSchemaInfo (io.crate.metadata.blob.BlobSchemaInfo)1 DocTableInfo (io.crate.metadata.doc.DocTableInfo)1 InformationSchemaInfo (io.crate.metadata.information.InformationSchemaInfo)1 SysSchemaInfo (io.crate.metadata.sys.SysSchemaInfo)1 SchemaInfo (io.crate.metadata.table.SchemaInfo)1 TableInfo (io.crate.metadata.table.TableInfo)1 IOException (java.io.IOException)1