com.facebook.presto.spi.ConnectorTableHandle Java Examples

The following examples show how to use com.facebook.presto.spi.ConnectorTableHandle. 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 Map<String, ColumnHandle> getColumnHandles(ConnectorSession session, ConnectorTableHandle tableHandle)
    {
        ElasticsearchTableHandle handle = (ElasticsearchTableHandle) tableHandle;
        checkArgument(handle.getConnectorId().equals(connectorId), "tableHandle is not for this connector");

        ElasticsearchTable table = client.getTable(handle.getSchemaTableName());
        if (table == null) {
            throw new TableNotFoundException(handle.getSchemaTableName());
        }
        return table.getColumns().stream().collect(Collectors.toMap(x -> x.getName(), x -> x));
//        ImmutableMap.Builder<String, ColumnHandle> columnHandles = ImmutableMap.builder();
//        for (ElasticsearchColumnHandle column : table.getColumns()) {
//            columnHandles.put(column.getName(), column);
//        }
//        return columnHandles.build();
    }
 
Example #2
Source File: KuduMetadata.java    From presto-kudu with Apache License 2.0 6 votes vote down vote up
@Override
public Map<String, ColumnHandle> getColumnHandles(ConnectorSession session,
                                                  ConnectorTableHandle connectorTableHandle) {
    KuduTableHandle tableHandle = fromConnectorTableHandle(session, connectorTableHandle);
    Schema schema = clientSession.getTableSchema(tableHandle);

    ImmutableMap.Builder<String, ColumnHandle> columnHandles = ImmutableMap.builder();
    for (int i = 0; i < schema.getColumnCount(); i++) {
        ColumnSchema col = schema.getColumnByIndex(i);
        String name = col.getName();
        Type type = TypeHelper.fromKuduColumn(col);
        KuduColumnHandle columnHandle = new KuduColumnHandle(name, i, type);
        columnHandles.put(name, columnHandle);
    }

    return columnHandles.build();
}
 
Example #3
Source File: ElasticsearchMetadata.java    From presto-connectors with Apache License 2.0 6 votes vote down vote up
@Override
public ConnectorInsertTableHandle beginInsert(ConnectorSession session, ConnectorTableHandle tableHandle)
{
    checkNoRollback();
    ElasticsearchTableHandle handle = (ElasticsearchTableHandle) tableHandle;
    setRollback(() -> {
        //--------插入操作无法回退
        // Rollbacks for inserts are off the table when it comes to data in Hbase.
        // When a batch of Mutations fails to be inserted, the general strategy
        // is to run the insert operation again until it is successful
        // Any mutations that were successfully written will be overwritten
        // with the same values, so that isn't a problem.
        throw new PrestoException(NOT_SUPPORTED, format("Unable to rollback insert for table %s.%s. Some rows may have been written. Please run your insert again.", handle.getSchemaName(), handle.getTableName()));
    });
    return handle;
}
 
Example #4
Source File: HbaseMetadata.java    From presto-connectors with Apache License 2.0 6 votes vote down vote up
@Override
public Map<String, ColumnHandle> getColumnHandles(ConnectorSession session, ConnectorTableHandle tableHandle)
{
    HbaseTableHandle handle = (HbaseTableHandle) tableHandle;
    checkArgument(handle.getConnectorId().equals(connectorId), "tableHandle is not for this connector");

    HbaseTable table = client.getTable(handle.toSchemaTableName());
    if (table == null) {
        throw new TableNotFoundException(handle.toSchemaTableName());
    }

    ImmutableMap.Builder<String, ColumnHandle> columnHandles = ImmutableMap.builder();
    for (HbaseColumnHandle column : table.getColumns()) {
        columnHandles.put(column.getName(), column);
    }
    return columnHandles.build();
}
 
Example #5
Source File: KuduMetadata.java    From presto-kudu with Apache License 2.0 6 votes vote down vote up
@Override
public ConnectorInsertTableHandle beginInsert(ConnectorSession session, ConnectorTableHandle connectorTableHandle) {
    KuduTableHandle tableHandle = fromConnectorTableHandle(session, connectorTableHandle);

    KuduTable table = tableHandle.getTable(clientSession);
    Schema schema = table.getSchema();

    List<ColumnSchema> columns = schema.getColumns();
    List<String> columnNames = columns.stream().map(ColumnSchema::getName).collect(toImmutableList());
    List<Type> columnTypes = columns.stream()
            .map(TypeHelper::fromKuduColumn).collect(toImmutableList());

    return new KuduInsertTableHandle(
            connectorId,
            tableHandle.getSchemaTableName(),
            columnNames,
            columnTypes,
            table);
}
 
Example #6
Source File: HbaseMetadata.java    From presto-connectors with Apache License 2.0 6 votes vote down vote up
@Override
public ConnectorInsertTableHandle beginInsert(ConnectorSession session, ConnectorTableHandle tableHandle)
{
    checkNoRollback();
    HbaseTableHandle handle = (HbaseTableHandle) tableHandle;
    setRollback(() -> {
        //--------插入操作无法回退
        // Rollbacks for inserts are off the table when it comes to data in Hbase.
        // When a batch of Mutations fails to be inserted, the general strategy
        // is to run the insert operation again until it is successful
        // Any mutations that were successfully written will be overwritten
        // with the same values, so that isn't a problem.
        throw new PrestoException(NOT_SUPPORTED, format("Unable to rollback insert for table %s.%s. Some rows may have been written. Please run your insert again.", handle.getSchema(), handle.getTable()));
    });
    return handle;
}
 
Example #7
Source File: HbaseMetadata.java    From presto-connectors with Apache License 2.0 6 votes vote down vote up
@Override
public ConnectorTableHandle getTableHandle(ConnectorSession session, SchemaTableName tableName)
{
    if (!listSchemaNames(session).contains(tableName.getSchemaName().toLowerCase(Locale.ENGLISH))) {
        return null;
    }

    // Need to validate that SchemaTableName is a table
    if (!this.listViews(session, tableName.getSchemaName()).contains(tableName)) {
        HbaseTable table = client.getTable(tableName);
        if (table == null) {
            return null;
        }

        return new HbaseTableHandle(
                connectorId,
                table.getSchema(),
                table.getTable(),
                table.getRowId(),
                table.isExternal(),
                table.getScanAuthorizations());
    }

    return null;
}
 
Example #8
Source File: ParaflowMetadata.java    From paraflow with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, ColumnHandle> getColumnHandles(ConnectorSession session, ConnectorTableHandle tableHandle)
{
    ParaflowTableHandle table = checkType(tableHandle, ParaflowTableHandle.class, "table");
    List<ParaflowColumnHandle> cols = paraflowMetaDataReader.getTableColumnHandle(connectorId, table.getSchemaName(), table.getTableName())
            .orElse(new ArrayList<>());
    Map<String, ColumnHandle> columnMap = new HashMap<>();
    for (ParaflowColumnHandle col : cols) {
        columnMap.putIfAbsent(col.getName(), col);
    }
    return columnMap;
}
 
Example #9
Source File: EthereumMetadata.java    From presto-ethereum with Apache License 2.0 5 votes vote down vote up
@Override
public ColumnMetadata getColumnMetadata(
        ConnectorSession session,
        ConnectorTableHandle tableHandle,
        ColumnHandle columnHandle
) {
    convertTableHandle(tableHandle);
    return convertColumnHandle(columnHandle).getColumnMetadata();
}
 
Example #10
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 #11
Source File: KuduMetadata.java    From presto-kudu with Apache License 2.0 5 votes vote down vote up
@Override
public ColumnMetadata getColumnMetadata(ConnectorSession session,
                                        ConnectorTableHandle tableHandle, ColumnHandle columnHandle) {
    fromConnectorTableHandle(session, tableHandle);
    KuduColumnHandle kuduColumnHandle = checkType(columnHandle, KuduColumnHandle.class, "columnHandle");
    if (kuduColumnHandle.isVirtualRowId()) {
        return new ColumnMetadata(KuduColumnHandle.ROW_ID, VarbinaryType.VARBINARY, null, true);
    } else {
        return kuduColumnHandle.getColumnMetadata();
    }
}
 
Example #12
Source File: KuduMetadata.java    From presto-kudu with Apache License 2.0 5 votes vote down vote up
@Override
public List<ConnectorTableLayoutResult> getTableLayouts(ConnectorSession session,
                                                        ConnectorTableHandle tableHandle,
                                                        Constraint<ColumnHandle> constraint,
                                                        Optional<Set<ColumnHandle>> desiredColumns) {
    KuduTableHandle handle = fromConnectorTableHandle(session, tableHandle);
    ConnectorTableLayout layout = new ConnectorTableLayout(
            new KuduTableLayoutHandle(handle, constraint.getSummary(), desiredColumns));
    return ImmutableList.of(new ConnectorTableLayoutResult(layout, constraint.getSummary()));
}
 
Example #13
Source File: KuduMetadata.java    From presto-kudu with Apache License 2.0 5 votes vote down vote up
@Override
public void renameColumn(ConnectorSession session, ConnectorTableHandle tableHandle, ColumnHandle source,
                         String target) {
    KuduTableHandle kuduTableHandle = fromConnectorTableHandle(session, tableHandle);
    KuduColumnHandle kuduColumnHandle = (KuduColumnHandle) source;
    clientSession.renameColumn(kuduTableHandle.getSchemaTableName(), kuduColumnHandle.getName(), target);
}
 
Example #14
Source File: KinesisHandleResolver.java    From presto-kinesis with Apache License 2.0 5 votes vote down vote up
KinesisTableHandle convertTableHandle(ConnectorTableHandle tableHandle)
{
    requireNonNull(tableHandle, "tableHandle is null");
    checkArgument(tableHandle instanceof KinesisTableHandle, "tableHandle is not an instance of KinesisTableHandle");
    KinesisTableHandle kinesisTableHandle = (KinesisTableHandle) tableHandle;
    checkArgument(kinesisTableHandle.getConnectorId().equals(connectorId), "tableHandle is not for this connector");

    return kinesisTableHandle;
}
 
Example #15
Source File: KinesisMetadata.java    From presto-kinesis with Apache License 2.0 5 votes vote down vote up
@Override
public List<ConnectorTableLayoutResult> getTableLayouts(ConnectorSession connectorSession, ConnectorTableHandle table,
                                                        Constraint<ColumnHandle> constraint, Optional<Set<ColumnHandle>> optional)
{
    KinesisTableHandle tblHandle = handleResolver.convertTableHandle(table);
    ConnectorTableLayout layout = new ConnectorTableLayout(new KinesisTableLayoutHandle(connectorId, tblHandle));
    return ImmutableList.of(new ConnectorTableLayoutResult(layout, constraint.getSummary()));
 }
 
Example #16
Source File: KinesisMetadata.java    From presto-kinesis with Apache License 2.0 5 votes vote down vote up
@Override
public ConnectorTableMetadata getTableMetadata(ConnectorSession connectorSession, ConnectorTableHandle tableHandle)
{
    KinesisTableHandle kinesisTableHandle = handleResolver.convertTableHandle(tableHandle);
    log.debug("Called getTableMetadata on %s.%s", kinesisTableHandle.getSchemaName(), kinesisTableHandle.getTableName());
    return getTableMetadata(kinesisTableHandle.toSchemaTableName());
}
 
Example #17
Source File: KinesisMetadata.java    From presto-kinesis with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, ColumnHandle> getColumnHandles(ConnectorSession connectorSession, ConnectorTableHandle tableHandle)
{
    KinesisTableHandle kinesisTableHandle = handleResolver.convertTableHandle(tableHandle);

    KinesisStreamDescription kinesisStreamDescription = getDefinedTables().get(kinesisTableHandle.toSchemaTableName());
    if (kinesisStreamDescription == null) {
        throw new TableNotFoundException(kinesisTableHandle.toSchemaTableName());
    }

    ImmutableMap.Builder<String, ColumnHandle> columnHandles = ImmutableMap.builder();

    int index = 0;
    // Note: partition key and related fields are handled by internalFieldDescriptions below
    KinesisStreamFieldGroup message = kinesisStreamDescription.getMessage();
    if (message != null) {
        List<KinesisStreamFieldDescription> fields = message.getFields();
        if (fields != null) {
            for (KinesisStreamFieldDescription kinesisStreamFieldDescription : fields) {
                columnHandles.put(kinesisStreamFieldDescription.getName(), kinesisStreamFieldDescription.getColumnHandle(connectorId, index++));
            }
        }
    }

    for (KinesisInternalFieldDescription kinesisInternalFieldDescription : internalFieldDescriptions) {
        columnHandles.put(kinesisInternalFieldDescription.getName(), kinesisInternalFieldDescription.getColumnHandle(connectorId, index++, kinesisConnectorConfig.isHideInternalColumns()));
    }

    return columnHandles.build();
}
 
Example #18
Source File: KinesisMetadata.java    From presto-kinesis with Apache License 2.0 5 votes vote down vote up
@Override
public ColumnMetadata getColumnMetadata(ConnectorSession connectorSession, ConnectorTableHandle tableHandle, ColumnHandle columnHandle)
{
    handleResolver.convertTableHandle(tableHandle);
    KinesisColumnHandle kinesisColumnHandle = handleResolver.convertColumnHandle(columnHandle);

    return kinesisColumnHandle.getColumnMetadata();
}
 
Example #19
Source File: ParaflowMetadata.java    From paraflow with Apache License 2.0 5 votes vote down vote up
@Override
public List<ConnectorTableLayoutResult> getTableLayouts(ConnectorSession session, ConnectorTableHandle table, Constraint<ColumnHandle> constraint, Optional<Set<ColumnHandle>> desiredColumns)
{
    ParaflowTableHandle paraflowTable = checkType(table, ParaflowTableHandle.class, "table");
    SchemaTableName tableName = paraflowTable.getSchemaTableName();
    ParaflowTableLayoutHandle tableLayout = paraflowMetaDataReader.getTableLayout(connectorId, tableName.getSchemaName(), tableName.getTableName()).orElse(null);
    if (tableLayout == null) {
        return ImmutableList.of();
    }
    tableLayout.setPredicates(constraint.getSummary() != null ? Optional.of(constraint.getSummary()) : Optional.empty());
    ConnectorTableLayout layout = getTableLayout(session, tableLayout);

    return ImmutableList.of(new ConnectorTableLayoutResult(layout, constraint.getSummary()));
}
 
Example #20
Source File: ElasticsearchMetadata.java    From presto-connectors with Apache License 2.0 5 votes vote down vote up
@Override
public List<ConnectorTableLayoutResult> getTableLayouts(ConnectorSession session, ConnectorTableHandle table, Constraint<ColumnHandle> constraint, Optional<Set<ColumnHandle>> desiredColumns)
{
    ElasticsearchTableHandle tableHandle = (ElasticsearchTableHandle) table;
    ConnectorTableLayout layout = new ConnectorTableLayout(new ElasticsearchTableLayoutHandle(tableHandle, constraint.getSummary()));
    return ImmutableList.of(new ConnectorTableLayoutResult(layout, constraint.getSummary()));
}
 
Example #21
Source File: ElasticsearchMetadata.java    From presto-connectors with Apache License 2.0 5 votes vote down vote up
@Override
public ConnectorTableMetadata getTableMetadata(ConnectorSession session, ConnectorTableHandle table)
{
    ElasticsearchTableHandle handle = (ElasticsearchTableHandle) table;
    checkArgument(handle.getConnectorId().equals(connectorId), "table is not for this connector");
    SchemaTableName tableName = new SchemaTableName(handle.getSchemaName(), handle.getTableName());
    ConnectorTableMetadata metadata = getTableMetadata(tableName);
    if (metadata == null) {
        throw new TableNotFoundException(tableName);
    }
    return metadata;
}
 
Example #22
Source File: ElasticsearchMetadata.java    From presto-connectors with Apache License 2.0 5 votes vote down vote up
@Override
public void dropTable(ConnectorSession session, ConnectorTableHandle tableHandle)
{
    ElasticsearchTableHandle handle = (ElasticsearchTableHandle) tableHandle;
    if (handle != null) {
        client.dropTable(handle.getSchemaTableName());
    }
}
 
Example #23
Source File: HbaseMetadata.java    From presto-connectors with Apache License 2.0 5 votes vote down vote up
@Override
public void dropTable(ConnectorSession session, ConnectorTableHandle tableHandle)
{
    HbaseTableHandle handle = (HbaseTableHandle) tableHandle;
    HbaseTable table = client.getTable(handle.toSchemaTableName());
    if (table != null) {
        client.dropTable(table);
    }
}
 
Example #24
Source File: HbaseMetadata.java    From presto-connectors with Apache License 2.0 5 votes vote down vote up
@Override
public List<ConnectorTableLayoutResult> getTableLayouts(ConnectorSession session, ConnectorTableHandle table, Constraint<ColumnHandle> constraint, Optional<Set<ColumnHandle>> desiredColumns)
{
    HbaseTableHandle tableHandle = (HbaseTableHandle) table;
    ConnectorTableLayout layout = new ConnectorTableLayout(new HbaseTableLayoutHandle(tableHandle, constraint.getSummary()));
    return ImmutableList.of(new ConnectorTableLayoutResult(layout, constraint.getSummary()));
}
 
Example #25
Source File: HbaseMetadata.java    From presto-connectors with Apache License 2.0 5 votes vote down vote up
@Override
public ConnectorTableMetadata getTableMetadata(ConnectorSession session, ConnectorTableHandle table)
{
    HbaseTableHandle handle = (HbaseTableHandle) table;
    checkArgument(handle.getConnectorId().equals(connectorId), "table is not for this connector");
    SchemaTableName tableName = new SchemaTableName(handle.getSchema(), handle.getTable());
    ConnectorTableMetadata metadata = getTableMetadata(tableName);
    if (metadata == null) {
        throw new TableNotFoundException(tableName);
    }
    return metadata;
}
 
Example #26
Source File: ParaflowMetadata.java    From paraflow with Apache License 2.0 5 votes vote down vote up
@Override
public ConnectorTableMetadata getTableMetadata(ConnectorSession session, ConnectorTableHandle table)
{
    ParaflowTableHandle paraflowTable = (ParaflowTableHandle) table;
    checkArgument(paraflowTable.getConnectorId().equals(connectorId), "tableHandle is not for this connector");
    SchemaTableName tableName = new SchemaTableName(paraflowTable.getSchemaName(), paraflowTable.getTableName());
    return getTableMetadata(tableName);
}
 
Example #27
Source File: ParaflowHandleResolver.java    From paraflow with Apache License 2.0 4 votes vote down vote up
@Override
public Class<? extends ConnectorTableHandle> getTableHandleClass()
{
    return ParaflowTableHandle.class;
}
 
Example #28
Source File: ParaflowMetadata.java    From paraflow with Apache License 2.0 4 votes vote down vote up
@Override
public ColumnMetadata getColumnMetadata(ConnectorSession session, ConnectorTableHandle tableHandle, ColumnHandle columnHandle)
{
    ParaflowColumnHandle column = (ParaflowColumnHandle) columnHandle;
    return new ColumnMetadata(column.getName(), column.getType(), column.getComment(), false);
}
 
Example #29
Source File: ElasticsearchMetadata.java    From presto-connectors with Apache License 2.0 4 votes vote down vote up
@Override
public ColumnMetadata getColumnMetadata(ConnectorSession session, ConnectorTableHandle tableHandle, ColumnHandle columnHandle)
{
    return ((ElasticsearchColumnHandle) columnHandle).getColumnMetadata();
}
 
Example #30
Source File: ParaflowMetadata.java    From paraflow with Apache License 2.0 4 votes vote down vote up
@Override
public void dropTable(ConnectorSession session, ConnectorTableHandle tableHandle)
{
    ParaflowTableHandle paraflowTableHandle = (ParaflowTableHandle) tableHandle;
    paraflowMetaDataReader.dropTable(paraflowTableHandle.getSchemaName(), paraflowTableHandle.getTableName());
}