Search in sources :

Example 1 with GetSchemasResp

use of org.apache.drill.exec.proto.UserProtos.GetSchemasResp in project drill by apache.

the class DrillMetaImpl method serverGetSchemas.

private MetaResultSet serverGetSchemas(String catalog, Pat schemaPattern) {
    final LikeFilter catalogNameFilter = newLikeFilter(quote(catalog));
    final LikeFilter schemaNameFilter = newLikeFilter(schemaPattern);
    return new MetadataAdapter<MetaImpl.MetaSchema, GetSchemasResp, SchemaMetadata>(MetaImpl.MetaSchema.class) {

        @Override
        protected RequestStatus getStatus(GetSchemasResp response) {
            return response.getStatus();
        }

        @Override
        protected List<SchemaMetadata> getResult(GetSchemasResp response) {
            return response.getSchemasList();
        }

        @Override
        protected DrillPBError getError(GetSchemasResp response) {
            return response.getError();
        }

        @Override
        protected MetaSchema adapt(SchemaMetadata value) {
            return new MetaImpl.MetaSchema(value.getCatalogName(), value.getSchemaName());
        }
    }.getMeta(connection.getClient().getSchemas(catalogNameFilter, schemaNameFilter));
}
Also used : LikeFilter(org.apache.drill.exec.proto.UserProtos.LikeFilter) GetSchemasResp(org.apache.drill.exec.proto.UserProtos.GetSchemasResp) DrillPBError(org.apache.drill.exec.proto.UserBitShared.DrillPBError) SchemaMetadata(org.apache.drill.exec.proto.UserProtos.SchemaMetadata) ArrayList(java.util.ArrayList) List(java.util.List) MetaImpl(org.apache.calcite.avatica.MetaImpl) RequestStatus(org.apache.drill.exec.proto.UserProtos.RequestStatus)

Example 2 with GetSchemasResp

use of org.apache.drill.exec.proto.UserProtos.GetSchemasResp in project drill by apache.

the class TestMetadataProvider method schemas.

@Test
public void schemas() throws Exception {
    // test("SELECT * FROM INFORMATION_SCHEMA.SCHEMATA"); // SQL equivalent
    GetSchemasResp resp = client.getSchemas(null, null).get();
    assertEquals(RequestStatus.OK, resp.getStatus());
    List<SchemaMetadata> schemas = resp.getSchemasList();
    assertEquals(9, schemas.size());
    verifySchema("INFORMATION_SCHEMA", schemas);
    verifySchema("cp.default", schemas);
    verifySchema("dfs.default", schemas);
    verifySchema("dfs.root", schemas);
    verifySchema("dfs.tmp", schemas);
    verifySchema("dfs_test.default", schemas);
    verifySchema("dfs_test.home", schemas);
    verifySchema("dfs_test.tmp", schemas);
    verifySchema("sys", schemas);
}
Also used : GetSchemasResp(org.apache.drill.exec.proto.UserProtos.GetSchemasResp) SchemaMetadata(org.apache.drill.exec.proto.UserProtos.SchemaMetadata) Test(org.junit.Test)

Example 3 with GetSchemasResp

use of org.apache.drill.exec.proto.UserProtos.GetSchemasResp in project drill by apache.

the class TestMetadataProvider method schemasWithCatalogNameFilterAndSchemaNameFilter.

@Test
public void schemasWithCatalogNameFilterAndSchemaNameFilter() throws Exception {
    // test("SELECT * FROM INFORMATION_SCHEMA.SCHEMATA " +
    //    "WHERE CATALOG_NAME LIKE '%RI%' AND SCHEMA_NAME LIKE '%y%'"); // SQL equivalent
    GetSchemasResp resp = client.getSchemas(LikeFilter.newBuilder().setPattern("%RI%").build(), LikeFilter.newBuilder().setPattern("%dfs_test%").build()).get();
    assertEquals(RequestStatus.OK, resp.getStatus());
    List<SchemaMetadata> schemas = resp.getSchemasList();
    assertEquals(3, schemas.size());
    verifySchema("dfs_test.default", schemas);
    verifySchema("dfs_test.home", schemas);
    verifySchema("dfs_test.tmp", schemas);
}
Also used : GetSchemasResp(org.apache.drill.exec.proto.UserProtos.GetSchemasResp) SchemaMetadata(org.apache.drill.exec.proto.UserProtos.SchemaMetadata) Test(org.junit.Test)

Example 4 with GetSchemasResp

use of org.apache.drill.exec.proto.UserProtos.GetSchemasResp in project drill by apache.

the class TestMetadataProvider method schemasWithSchemaNameFilter.

@Test
public void schemasWithSchemaNameFilter() throws Exception {
    // test("SELECT * FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME LIKE '%y%'"); // SQL equivalent
    GetSchemasResp resp = client.getSchemas(null, LikeFilter.newBuilder().setPattern("%y%").build()).get();
    assertEquals(RequestStatus.OK, resp.getStatus());
    List<SchemaMetadata> schemas = resp.getSchemasList();
    assertEquals(1, schemas.size());
    verifySchema("sys", schemas);
}
Also used : GetSchemasResp(org.apache.drill.exec.proto.UserProtos.GetSchemasResp) SchemaMetadata(org.apache.drill.exec.proto.UserProtos.SchemaMetadata) Test(org.junit.Test)

Aggregations

GetSchemasResp (org.apache.drill.exec.proto.UserProtos.GetSchemasResp)4 SchemaMetadata (org.apache.drill.exec.proto.UserProtos.SchemaMetadata)4 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)1 List (java.util.List)1 MetaImpl (org.apache.calcite.avatica.MetaImpl)1 DrillPBError (org.apache.drill.exec.proto.UserBitShared.DrillPBError)1 LikeFilter (org.apache.drill.exec.proto.UserProtos.LikeFilter)1 RequestStatus (org.apache.drill.exec.proto.UserProtos.RequestStatus)1