com.facebook.presto.spi.SchemaTablePrefix Java Examples

The following examples show how to use com.facebook.presto.spi.SchemaTablePrefix. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ElasticsearchMetadata.java    From presto-connectors with Apache License 2.0 6 votes vote down vote up
private List<SchemaTableName> listTables(ConnectorSession session, SchemaTablePrefix prefix)
{
    // List all tables if schema or table is null
    if (prefix.getSchemaName() == null || prefix.getTableName() == null) {
        return listTables(session, prefix.getSchemaName());
    }

    // Make sure requested table exists, returning the single table of it does
    SchemaTableName table = new SchemaTableName(prefix.getSchemaName(), prefix.getTableName());
    if (getTableHandle(session, table) != null) {
        return ImmutableList.of(table);
    }

    // Else, return empty list
    return ImmutableList.of();
}
 
Example #2
Source File: HbaseMetadata.java    From presto-connectors with Apache License 2.0 6 votes vote down vote up
private List<SchemaTableName> listTables(ConnectorSession session, SchemaTablePrefix prefix)
{
    // List all tables if schema or table is null
    if (prefix.getSchemaName() == null || prefix.getTableName() == null) {
        return listTables(session, prefix.getSchemaName());
    }

    // Make sure requested table exists, returning the single table of it does
    SchemaTableName table = new SchemaTableName(prefix.getSchemaName(), prefix.getTableName());
    if (getTableHandle(session, table) != null) {
        return ImmutableList.of(table);
    }

    // Else, return empty list
    return ImmutableList.of();
}
 
Example #3
Source File: ParaflowMetaDataReader.java    From paraflow with Apache License 2.0 6 votes vote down vote up
public List<SchemaTableName> listTables(SchemaTablePrefix prefix)
{
    List<SchemaTableName> tables = new ArrayList<>();
    String dbPrefix = prefix.getSchemaName();
    String tblPrefix = prefix.getTableName();

    // if dbPrefix not mean to match all
    String tblName;
    String dbName;
    if (dbPrefix != null && tblPrefix != null) {
        MetaProto.StringListType stringListType = metaClient.listTables(dbPrefix);
        if (stringListType.getStrCount() == 0) {
            return tables;
        }
        for (int i = 0; i < stringListType.getStrCount(); i++) {
            tblName = stringListType.getStr(0);
            dbName = dbPrefix;
            tables.add(new SchemaTableName(dbName, tblName));
        }
    }
    return tables;
}
 
Example #4
Source File: EthereumMetadata.java    From presto-ethereum with Apache License 2.0 6 votes vote down vote up
@Override
public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession session, SchemaTablePrefix prefix)
{
    requireNonNull(prefix, "prefix is null");

    ImmutableMap.Builder<SchemaTableName, List<ColumnMetadata>> columns = ImmutableMap.builder();

    List<SchemaTableName> tableNames = prefix.getSchemaName() == null ? listTables(session, null) : ImmutableList.of(new SchemaTableName(prefix.getSchemaName(), prefix.getTableName()));

    for (SchemaTableName tableName : tableNames) {
        ConnectorTableMetadata tableMetadata = getTableMetadata(tableName);
        // table can disappear during listing operation
        if (tableMetadata != null) {
            columns.put(tableName, tableMetadata.getColumns());
        }
    }
    return columns.build();
}
 
Example #5
Source File: KuduMetadata.java    From presto-kudu with Apache License 2.0 6 votes vote down vote up
@Override
public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession session,
                                                                   SchemaTablePrefix prefix) {
    requireNonNull(prefix, "SchemaTablePrefix is null");

    List<SchemaTableName> tables;
    if (prefix.getSchemaName() == null) {
        tables = listTables(session, Optional.empty());
    } else if (prefix.getTableName() == null) {
        tables = listTables(session, prefix.getSchemaName());
    } else {
        tables = ImmutableList.of(new SchemaTableName(prefix.getSchemaName(), prefix.getTableName()));
    }

    ImmutableMap.Builder<SchemaTableName, List<ColumnMetadata>> columns = ImmutableMap.builder();
    for (SchemaTableName tableName : tables) {
        KuduTableHandle tableHandle = getTableHandle(session, tableName);
        ConnectorTableMetadata tableMetadata = getTableMetadata(tableHandle);
        columns.put(tableName, tableMetadata.getColumns());
    }
    return columns.build();
}
 
Example #6
Source File: KinesisMetadata.java    From presto-kinesis with Apache License 2.0 6 votes vote down vote up
@Override
public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession session, SchemaTablePrefix prefix)
{
    checkNotNull(prefix, "prefix is null");
    log.debug("Called listTableColumns on %s.%s", prefix.getSchemaName(), prefix.getTableName());

    ImmutableMap.Builder<SchemaTableName, List<ColumnMetadata>> columns = ImmutableMap.builder();

    // NOTE: prefix.getTableName or prefix.getSchemaName can be null
    List<SchemaTableName> tableNames;
    if (prefix.getSchemaName() != null && prefix.getTableName() != null) {
        tableNames = ImmutableList.of(new SchemaTableName(prefix.getSchemaName(), prefix.getTableName()));
    }
    else {
        tableNames = listTables(session, (String) null);
    }

    for (SchemaTableName tableName : tableNames) {
        ConnectorTableMetadata tableMetadata = getTableMetadata(tableName);
        if (tableMetadata != null) {
            columns.put(tableName, tableMetadata.getColumns());
        }
    }
    return columns.build();
}
 
Example #7
Source File: ElasticsearchMetadata.java    From presto-connectors with Apache License 2.0 5 votes vote down vote up
@Override
public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession session, SchemaTablePrefix prefix)
{
    requireNonNull(prefix, "prefix is null");
    ImmutableMap.Builder<SchemaTableName, List<ColumnMetadata>> columns = ImmutableMap.builder();
    for (SchemaTableName tableName : listTables(session, prefix)) {
        ConnectorTableMetadata tableMetadata = getTableMetadata(tableName);
        // table can disappear during listing operation
        if (tableMetadata != null) {
            columns.put(tableName, tableMetadata.getColumns());
        }
    }
    return columns.build();
}
 
Example #8
Source File: HbaseMetadata.java    From presto-connectors with Apache License 2.0 5 votes vote down vote up
@Override
public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession session, SchemaTablePrefix prefix)
{
    requireNonNull(prefix, "prefix is null");
    ImmutableMap.Builder<SchemaTableName, List<ColumnMetadata>> columns = ImmutableMap.builder();
    for (SchemaTableName tableName : listTables(session, prefix)) {
        ConnectorTableMetadata tableMetadata = getTableMetadata(tableName);
        // table can disappear during listing operation
        if (tableMetadata != null) {
            columns.put(tableName, tableMetadata.getColumns());
        }
    }
    return columns.build();
}
 
Example #9
Source File: ParaflowMetadata.java    From paraflow with Apache License 2.0 5 votes vote down vote up
@Override
public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession session, SchemaTablePrefix prefix)
{
    Map<SchemaTableName, List<ColumnMetadata>> tableColumns = new HashMap<>();
    List<SchemaTableName> tableNames = paraflowMetaDataReader.listTables(prefix);
    for (SchemaTableName table : tableNames) {
        List<ColumnMetadata> columnMetadatas = paraflowMetaDataReader.getTableColMetadata(connectorId, table.getSchemaName(),
                table.getTableName()).orElse(new ArrayList<>());
        tableColumns.putIfAbsent(table, columnMetadatas);
    }
    return tableColumns;
}