Search in sources :

Example 1 with GetTablesResp

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

the class DrillMetaImpl method serverGetTables.

private MetaResultSet serverGetTables(String catalog, final Pat schemaPattern, final Pat tableNamePattern, final List<String> typeList) {
    // Catalog is not a pattern
    final LikeFilter catalogNameFilter = newLikeFilter(quote(catalog));
    final LikeFilter schemaNameFilter = newLikeFilter(schemaPattern);
    final LikeFilter tableNameFilter = newLikeFilter(tableNamePattern);
    return new MetadataAdapter<MetaImpl.MetaTable, GetTablesResp, TableMetadata>(MetaTable.class) {

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

        ;

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

        ;

        @Override
        protected List<TableMetadata> getResult(GetTablesResp response) {
            return response.getTablesList();
        }

        @Override
        protected MetaImpl.MetaTable adapt(TableMetadata protoValue) {
            return new MetaImpl.MetaTable(protoValue.getCatalogName(), protoValue.getSchemaName(), protoValue.getTableName(), protoValue.getType());
        }

        ;
    }.getMeta(connection.getClient().getTables(catalogNameFilter, schemaNameFilter, tableNameFilter, typeList));
}
Also used : LikeFilter(org.apache.drill.exec.proto.UserProtos.LikeFilter) TableMetadata(org.apache.drill.exec.proto.UserProtos.TableMetadata) DrillPBError(org.apache.drill.exec.proto.UserBitShared.DrillPBError) GetTablesResp(org.apache.drill.exec.proto.UserProtos.GetTablesResp) 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 GetTablesResp

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

the class TestMetadataProvider method tablesWithTableNameFilterAndSchemaNameFilter.

@Test
public void tablesWithTableNameFilterAndSchemaNameFilter() throws Exception {
    // test("SELECT * FROM INFORMATION_SCHEMA.`TABLES` " +
    //    "WHERE TABLE_SCHEMA LIKE '%N\\_S%' ESCAPE '\\' AND TABLE_NAME LIKE '%o%'"); // SQL equivalent
    GetTablesResp resp = client.getTables(null, LikeFilter.newBuilder().setPattern("%N\\_S%").setEscape("\\").build(), LikeFilter.newBuilder().setPattern("%o%").build(), null).get();
    assertEquals(RequestStatus.OK, resp.getStatus());
    List<TableMetadata> tables = resp.getTablesList();
    assertEquals(0, tables.size());
}
Also used : TableMetadata(org.apache.drill.exec.proto.UserProtos.TableMetadata) GetTablesResp(org.apache.drill.exec.proto.UserProtos.GetTablesResp) Test(org.junit.Test)

Example 3 with GetTablesResp

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

the class TestMetadataProvider method tablesWithTableNameFilter.

@Test
public void tablesWithTableNameFilter() throws Exception {
    // test("SELECT * FROM INFORMATION_SCHEMA.`TABLES` WHERE TABLE_NAME LIKE '%o%'"); // SQL equivalent
    GetTablesResp resp = client.getTables(null, null, LikeFilter.newBuilder().setPattern("%o%").build(), null).get();
    assertEquals(RequestStatus.OK, resp.getStatus());
    List<TableMetadata> tables = resp.getTablesList();
    assertEquals(4, tables.size());
    verifyTable("sys", "boot", tables);
    verifyTable("sys", "memory", tables);
    verifyTable("sys", "options", tables);
    verifyTable("sys", "version", tables);
}
Also used : TableMetadata(org.apache.drill.exec.proto.UserProtos.TableMetadata) GetTablesResp(org.apache.drill.exec.proto.UserProtos.GetTablesResp) Test(org.junit.Test)

Example 4 with GetTablesResp

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

the class TestMetadataProvider method tablesWithTableFilter.

@Test
public void tablesWithTableFilter() throws Exception {
    // test("SELECT * FROM INFORMATION_SCHEMA.`TABLES` WHERE TABLE_TYPE IN ('TABLE')"); // SQL equivalent
    GetTablesResp resp = client.getTables(null, null, null, Arrays.asList("TABLE")).get();
    assertEquals(RequestStatus.OK, resp.getStatus());
    List<TableMetadata> tables = resp.getTablesList();
    assertTrue(tables.isEmpty());
}
Also used : TableMetadata(org.apache.drill.exec.proto.UserProtos.TableMetadata) GetTablesResp(org.apache.drill.exec.proto.UserProtos.GetTablesResp) Test(org.junit.Test)

Example 5 with GetTablesResp

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

the class TestMetadataProvider method tables.

@Test
public void tables() throws Exception {
    // test("SELECT * FROM INFORMATION_SCHEMA.`TABLES`"); // SQL equivalent
    GetTablesResp resp = client.getTables(null, null, null, null).get();
    assertEquals(RequestStatus.OK, resp.getStatus());
    List<TableMetadata> tables = resp.getTablesList();
    assertEquals(11, tables.size());
    verifyTable("INFORMATION_SCHEMA", "CATALOGS", tables);
    verifyTable("INFORMATION_SCHEMA", "COLUMNS", tables);
    verifyTable("INFORMATION_SCHEMA", "SCHEMATA", tables);
    verifyTable("INFORMATION_SCHEMA", "TABLES", tables);
    verifyTable("INFORMATION_SCHEMA", "VIEWS", tables);
    verifyTable("sys", "boot", tables);
    verifyTable("sys", "drillbits", tables);
    verifyTable("sys", "memory", tables);
    verifyTable("sys", "options", tables);
    verifyTable("sys", "threads", tables);
    verifyTable("sys", "version", tables);
}
Also used : TableMetadata(org.apache.drill.exec.proto.UserProtos.TableMetadata) GetTablesResp(org.apache.drill.exec.proto.UserProtos.GetTablesResp) Test(org.junit.Test)

Aggregations

GetTablesResp (org.apache.drill.exec.proto.UserProtos.GetTablesResp)6 TableMetadata (org.apache.drill.exec.proto.UserProtos.TableMetadata)6 Test (org.junit.Test)5 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