Search in sources :

Example 6 with SchemaTableName

use of com.facebook.presto.spi.SchemaTableName in project presto by prestodb.

the class AccumuloMetadata method getTableMetadata.

@Override
public ConnectorTableMetadata getTableMetadata(ConnectorSession session, ConnectorTableHandle table) {
    AccumuloTableHandle handle = (AccumuloTableHandle) 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;
}
Also used : TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) AccumuloTableHandle(com.facebook.presto.accumulo.model.AccumuloTableHandle) SchemaTableName(com.facebook.presto.spi.SchemaTableName) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata)

Example 7 with SchemaTableName

use of com.facebook.presto.spi.SchemaTableName in project presto by prestodb.

the class AccumuloMetadata method listTableColumns.

@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();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) SchemaTableName(com.facebook.presto.spi.SchemaTableName) ImmutableMap(com.google.common.collect.ImmutableMap) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata)

Example 8 with SchemaTableName

use of com.facebook.presto.spi.SchemaTableName in project presto by prestodb.

the class ZooKeeperMetadataManager method createTableMetadata.

public void createTableMetadata(AccumuloTable table) {
    SchemaTableName tableName = table.getSchemaTableName();
    String tablePath = getTablePath(tableName);
    try {
        if (curator.checkExists().forPath(tablePath) != null) {
            throw new InvalidActivityException(format("Metadata for table %s already exists", tableName));
        }
    } catch (Exception e) {
        throw new PrestoException(ZOOKEEPER_ERROR, "ZK error when checking if table already exists", e);
    }
    try {
        curator.create().creatingParentsIfNeeded().forPath(tablePath, toJsonBytes(table));
    } catch (Exception e) {
        throw new PrestoException(ZOOKEEPER_ERROR, "Error creating table znode in ZooKeeper", e);
    }
}
Also used : InvalidActivityException(javax.activity.InvalidActivityException) PrestoException(com.facebook.presto.spi.PrestoException) SchemaTableName(com.facebook.presto.spi.SchemaTableName) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) PrestoException(com.facebook.presto.spi.PrestoException) InvalidActivityException(javax.activity.InvalidActivityException)

Example 9 with SchemaTableName

use of com.facebook.presto.spi.SchemaTableName in project presto by prestodb.

the class ZooKeeperMetadataManager method getViewNames.

public Set<String> getViewNames(String schema) {
    String schemaPath = getSchemaPath(schema);
    boolean exists;
    try {
        exists = curator.checkExists().forPath(schemaPath) != null;
    } catch (Exception e) {
        throw new PrestoException(ZOOKEEPER_ERROR, "Error checking if schema exists", e);
    }
    if (exists) {
        try {
            Set<String> tables = new HashSet<>();
            tables.addAll(curator.getChildren().forPath(schemaPath).stream().filter(x -> isAccumuloView(new SchemaTableName(schema, x))).collect(Collectors.toList()));
            return tables;
        } catch (Exception e) {
            throw new PrestoException(ZOOKEEPER_ERROR, "Error fetching schemas", e);
        }
    } else {
        throw new PrestoException(ZOOKEEPER_ERROR, "No metadata for schema " + schema);
    }
}
Also used : PrestoException(com.facebook.presto.spi.PrestoException) SchemaTableName(com.facebook.presto.spi.SchemaTableName) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) PrestoException(com.facebook.presto.spi.PrestoException) InvalidActivityException(javax.activity.InvalidActivityException) HashSet(java.util.HashSet)

Example 10 with SchemaTableName

use of com.facebook.presto.spi.SchemaTableName in project presto by prestodb.

the class ZooKeeperMetadataManager method createViewMetadata.

public void createViewMetadata(AccumuloView view) {
    SchemaTableName tableName = view.getSchemaTableName();
    String viewPath = getTablePath(tableName);
    try {
        if (curator.checkExists().forPath(viewPath) != null) {
            throw new InvalidActivityException(format("Metadata for view %s already exists", tableName));
        }
    } catch (Exception e) {
        throw new PrestoException(ZOOKEEPER_ERROR, "ZK error when checking if view already exists", e);
    }
    try {
        curator.create().creatingParentsIfNeeded().forPath(viewPath, toJsonBytes(view));
    } catch (Exception e) {
        throw new PrestoException(ZOOKEEPER_ERROR, "Error creating view znode in ZooKeeper", e);
    }
}
Also used : InvalidActivityException(javax.activity.InvalidActivityException) PrestoException(com.facebook.presto.spi.PrestoException) SchemaTableName(com.facebook.presto.spi.SchemaTableName) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) PrestoException(com.facebook.presto.spi.PrestoException) InvalidActivityException(javax.activity.InvalidActivityException)

Aggregations

SchemaTableName (com.facebook.presto.spi.SchemaTableName)159 ImmutableList (com.google.common.collect.ImmutableList)49 List (java.util.List)42 Test (org.testng.annotations.Test)40 TableNotFoundException (com.facebook.presto.spi.TableNotFoundException)35 ImmutableMap (com.google.common.collect.ImmutableMap)35 ConnectorTableMetadata (com.facebook.presto.spi.ConnectorTableMetadata)31 PrestoException (com.facebook.presto.spi.PrestoException)31 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)25 ConnectorMetadata (com.facebook.presto.spi.connector.ConnectorMetadata)19 ArrayList (java.util.ArrayList)19 Collectors.toList (java.util.stream.Collectors.toList)17 ConnectorSession (com.facebook.presto.spi.ConnectorSession)16 Map (java.util.Map)16 ColumnHandle (com.facebook.presto.spi.ColumnHandle)15 ConnectorTableHandle (com.facebook.presto.spi.ConnectorTableHandle)14 SchemaTablePrefix (com.facebook.presto.spi.SchemaTablePrefix)14 Optional (java.util.Optional)14 Table (com.facebook.presto.hive.metastore.Table)13 Path (org.apache.hadoop.fs.Path)12