Java Code Examples for com.facebook.presto.spi.SchemaTableName#getSchemaName()

The following examples show how to use com.facebook.presto.spi.SchemaTableName#getSchemaName() . 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
@Override
public ConnectorOutputTableHandle beginCreateTable(ConnectorSession session, ConnectorTableMetadata tableMetadata, Optional<ConnectorNewTableLayout> layout)
{
    checkNoRollback();   //采用乐观锁 设计

    SchemaTableName tableName = tableMetadata.getTable();
    client.createTable(tableMetadata);

    //--- es column is sort ----
    List<ElasticsearchColumnHandle> columns = tableMetadata.getColumns().stream()
            .map(columnMetadata -> new ElasticsearchColumnHandle(
                    columnMetadata.getName(),
                    columnMetadata.getType(),
                    columnMetadata.getComment(),
                    true,
                    columnMetadata.isHidden())).collect(Collectors.toList());
    ElasticsearchOutputTableHandle handle = new ElasticsearchOutputTableHandle(
            connectorId,
            tableName.getSchemaName(),
            tableName.getTableName(),
            columns);

    setRollback(() -> client.dropTable(tableMetadata.getTable()));  //回滚操作

    return handle;
}
 
Example 2
Source File: HbaseMetadata.java    From presto-connectors with Apache License 2.0 6 votes vote down vote up
@Override
public ConnectorOutputTableHandle beginCreateTable(ConnectorSession session, ConnectorTableMetadata tableMetadata, Optional<ConnectorNewTableLayout> layout)
{
    checkNoRollback();   //采用乐观锁 设计

    SchemaTableName tableName = tableMetadata.getTable();
    HbaseTable table = client.createTable(tableMetadata);

    HbaseTableHandle handle = new HbaseTableHandle(
            connectorId,
            tableName.getSchemaName(),
            tableName.getTableName(),
            table.getRowId(),
            table.isExternal(),
            table.getScanAuthorizations());

    setRollback(() -> client.dropTable(table));  //回滚操作

    return handle;
}
 
Example 3
Source File: NativeKuduClientSession.java    From presto-kudu with Apache License 2.0 6 votes vote down vote up
@Override
public KuduTable createTable(ConnectorTableMetadata tableMetadata, boolean ignoreExisting) {
    try {
        SchemaTableName schemeTableName= tableMetadata.getTable();
        String rawName = toRawName(schemeTableName);
        if (ignoreExisting) {
            if (client.tableExists(rawName)) {
                return null;
            }
        }
        if(!schemaExists(schemeTableName.getSchemaName())){
            throw new SchemaNotFoundException(schemeTableName.getSchemaName());
        }
        List<ColumnMetadata> columns = tableMetadata.getColumns();
        Map<String, Object> properties = tableMetadata.getProperties();

        Schema schema = buildSchema(columns, properties);
        CreateTableOptions options = buildCreateTableOptions(schema, properties);
        return client.createTable(rawName, schema, options);
    } catch (KuduException e) {
        throw new PrestoException(GENERIC_INTERNAL_ERROR, e);
    }
}
 
Example 4
Source File: Elasticsearch2Client.java    From presto-connectors with Apache License 2.0 5 votes vote down vote up
@Override
public ElasticsearchTable getTable(SchemaTableName tableName)
{
    String indexWildcard = tableName.getTableName();
    GetIndexRequest getIndexRequest = createGetIndexRequest(indexWildcard);
    //----es scher error --
    Thread.currentThread().setName("getTable_001");
    GetIndexResponse response = client.admin().indices()
            .getIndex(getIndexRequest).actionGet();
    if (response.getIndices() == null || response.getIndices().length == 0) {
        return null;
    }
    //TODO: es中运行index名访问时可以使用*进行匹配,所以可能会返回多个index的mapping, 因此下面需要进行mapping merge  test table = test1"*"
    ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings = response.getMappings();

    List<IndexResolution> resolutions;
    if (mappings.size() > 0) {
        resolutions = new ArrayList<>(mappings.size());
        for (ObjectObjectCursor<String, ImmutableOpenMap<String, MappingMetaData>> indexMappings : mappings) {
            resolutions.add(buildGetIndexResult(indexMappings.key, indexMappings.value));
        }
    }
    else {
        resolutions = emptyList();
    }

    IndexResolution indexWithMerged = merge(resolutions, indexWildcard);
    return new ElasticsearchTable(typeManager, tableName.getSchemaName(), tableName.getTableName(), indexWithMerged.get());
}
 
Example 5
Source File: Elasticsearch6Client.java    From presto-connectors with Apache License 2.0 5 votes vote down vote up
@Override
public ElasticsearchTable getTable(SchemaTableName tableName)
{
    String indexWildcard = tableName.getTableName();
    GetIndexRequest getIndexRequest = createGetIndexRequest(indexWildcard);
    Thread.currentThread().setName("getTable_001"); //----es scher error --
    GetIndexResponse response = client.admin().indices()
            .getIndex(getIndexRequest).actionGet();
    if (response.getIndices() == null || response.getIndices().length == 0) {
        return null;
    }
    //TODO: es中运行index名访问时可以使用*进行匹配,所以可能会返回多个index的mapping, 因此下面需要进行mapping merge  test table = test1"*"
    ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings = response.getMappings();

    List<IndexResolution> resolutions;
    if (mappings.size() > 0) {
        resolutions = new ArrayList<>(mappings.size());
        for (ObjectObjectCursor<String, ImmutableOpenMap<String, MappingMetaData>> indexMappings : mappings) {
            resolutions.add(buildGetIndexResult(indexMappings.key, indexMappings.value));
        }
    }
    else {
        resolutions = emptyList();
    }

    IndexResolution indexWithMerged = merge(resolutions, indexWildcard);
    return new ElasticsearchTable(typeManager, tableName.getSchemaName(), tableName.getTableName(), indexWithMerged.get());
}
 
Example 6
Source File: ElasticsearchMetadata.java    From presto-connectors with Apache License 2.0 5 votes vote down vote up
@Override
public ConnectorTableHandle getTableHandle(ConnectorSession session, SchemaTableName tableName)
{
    requireNonNull(tableName, "tableName is null");
    // Need to validate that SchemaTableName is a table
    if (!client.existsTable(tableName)) {
        return null;
    }
    return new ElasticsearchTableHandle(connectorId, tableName.getSchemaName(), tableName.getTableName());
}
 
Example 7
Source File: Elasticsearch5Client.java    From presto-connectors with Apache License 2.0 5 votes vote down vote up
@Override
public ElasticsearchTable getTable(SchemaTableName tableName)
{
    String indexWildcard = tableName.getTableName();
    GetIndexRequest getIndexRequest = createGetIndexRequest(indexWildcard);
    Thread.currentThread().setName("getTable_001"); //----es scher error --
    GetIndexResponse response = client.admin().indices()
            .getIndex(getIndexRequest).actionGet();
    if (response.getIndices() == null || response.getIndices().length == 0) {
        return null;
    }
    //TODO: es中运行index名访问时可以使用*进行匹配,所以可能会返回多个index的mapping, 因此下面需要进行mapping merge  test table = test1"*"
    ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings = response.getMappings();

    List<IndexResolution> resolutions;
    if (mappings.size() > 0) {
        resolutions = new ArrayList<>(mappings.size());
        for (ObjectObjectCursor<String, ImmutableOpenMap<String, MappingMetaData>> indexMappings : mappings) {
            resolutions.add(buildGetIndexResult(indexMappings.key, indexMappings.value));
        }
    }
    else {
        resolutions = emptyList();
    }

    IndexResolution indexWithMerged = merge(resolutions, indexWildcard);
    return new ElasticsearchTable(typeManager, tableName.getSchemaName(), tableName.getTableName(), indexWithMerged.get());
}
 
Example 8
Source File: NativeKuduClientSession.java    From presto-kudu with Apache License 2.0 5 votes vote down vote up
@Override
public KuduTable openTable(SchemaTableName schemaTableName) {
    String rawName = toRawName(schemaTableName);
    try {
        KuduTable table = client.openTable(rawName);
        return table;
    } catch (Exception e) {
        log.debug("Error on doOpenTable: " + e, e);
        if (!listSchemaNames().contains(schemaTableName.getSchemaName())) {
            throw new SchemaNotFoundException(schemaTableName.getSchemaName());
        } else {
            throw new TableNotFoundException(schemaTableName);
        }
    }
}
 
Example 9
Source File: NativeKuduClientSession.java    From presto-kudu with Apache License 2.0 5 votes vote down vote up
private String toRawName(SchemaTableName schemaTableName) {
    String rawName;
    if (schemaTableName.getSchemaName().equals(DEFAULT_SCHEMA)) {
        rawName = tenantPrefix + schemaTableName.getTableName();
    } else {
        rawName = tenantPrefix + schemaTableName.getSchemaName() + "." + schemaTableName.getTableName();
    }
    return rawName;
}
 
Example 10
Source File: KinesisMetadata.java    From presto-kinesis with Apache License 2.0 5 votes vote down vote up
@Override
public KinesisTableHandle getTableHandle(ConnectorSession session, SchemaTableName schemaTableName)
{
    KinesisStreamDescription table = getDefinedTables().get(schemaTableName);
    if (table == null) {
        throw new TableNotFoundException(schemaTableName);
    }

    return new KinesisTableHandle(connectorId,
            schemaTableName.getSchemaName(),
            schemaTableName.getTableName(),
            table.getStreamName(),
            getDataFormat(table.getMessage()));
}
 
Example 11
Source File: TestUtils.java    From presto-kinesis with Apache License 2.0 5 votes vote down vote up
public static Map.Entry<SchemaTableName, KinesisStreamDescription> createSimpleJsonStreamDescription(String streamName, SchemaTableName schemaTableName)
{
    // Format: {"id" : 1324, "name" : "some string"}
    ArrayList<KinesisStreamFieldDescription> fieldList = new ArrayList<KinesisStreamFieldDescription>();
    fieldList.add(new KinesisStreamFieldDescription("id", BigintType.BIGINT, "id", "comment", null, null, false));
    fieldList.add(new KinesisStreamFieldDescription("name", VarcharType.VARCHAR, "name", "comment", null, null, false));
    KinesisStreamFieldGroup grp = new KinesisStreamFieldGroup("json", fieldList);

    KinesisStreamDescription desc = new KinesisStreamDescription(schemaTableName.getTableName(), schemaTableName.getSchemaName(), streamName, grp);
    return new AbstractMap.SimpleImmutableEntry<>(schemaTableName, desc);
}
 
Example 12
Source File: TestUtils.java    From presto-kinesis with Apache License 2.0 4 votes vote down vote up
public static Map.Entry<SchemaTableName, KinesisStreamDescription> createEmptyStreamDescription(String streamName, SchemaTableName schemaTableName)
{
    return new AbstractMap.SimpleImmutableEntry<>(
            schemaTableName,
            new KinesisStreamDescription(schemaTableName.getTableName(), schemaTableName.getSchemaName(), streamName, null));
}