Search in sources :

Example 1 with Column

use of com.facebook.presto.client.Column in project airpal by airbnb.

the class UsersResource method getUserQueries.

@GET
@Path("queries")
public Response getUserQueries(@Auth AirpalUser user, @PathParam("id") String userId, @QueryParam("results") int numResults, @QueryParam("table") List<PartitionedTable> tables) {
    Iterable<Job> recentlyRun;
    int results = Optional.of(numResults).or(0);
    if (results <= 0) {
        results = 100;
    }
    if (tables.size() < 1) {
        recentlyRun = jobHistoryStore.getRecentlyRunForUser(userId, results);
    } else {
        recentlyRun = jobHistoryStore.getRecentlyRunForUser(userId, results, Iterables.transform(tables, new PartitionedTableToTable()));
    }
    ImmutableList.Builder<Job> filtered = ImmutableList.builder();
    for (Job job : recentlyRun) {
        if (job.getTablesUsed().isEmpty() && (job.getState() == JobState.FAILED)) {
            filtered.add(job);
            continue;
        }
        for (Table table : job.getTablesUsed()) {
            if (AuthorizationUtil.isAuthorizedRead(user, table)) {
                filtered.add(new Job(job.getUser(), job.getQuery(), job.getUuid(), job.getOutput(), job.getQueryStats(), job.getState(), Collections.<Column>emptyList(), Collections.<Table>emptySet(), job.getQueryStartedDateTime(), job.getError(), job.getQueryFinishedDateTime()));
            }
        }
    }
    List<Job> sortedResult = Ordering.natural().nullsLast().onResultOf(JOB_ORDERING).reverse().immutableSortedCopy(filtered.build());
    return Response.ok(sortedResult).build();
}
Also used : Table(com.airbnb.airpal.presto.Table) PartitionedTableToTable(com.airbnb.airpal.presto.PartitionedTable.PartitionedTableToTable) PartitionedTable(com.airbnb.airpal.presto.PartitionedTable) Column(com.facebook.presto.client.Column) ImmutableList(com.google.common.collect.ImmutableList) PartitionedTableToTable(com.airbnb.airpal.presto.PartitionedTable.PartitionedTableToTable) Job(com.airbnb.airpal.api.Job) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 2 with Column

use of com.facebook.presto.client.Column in project airpal by airbnb.

the class ColumnCache method queryPartitions.

private List<HivePartition> queryPartitions(String query) {
    final ImmutableList.Builder<HivePartition> cache = ImmutableList.builder();
    final Map<Column, List<Object>> objects = Maps.newHashMap();
    QueryRunner queryRunner = queryRunnerFactory.create();
    QueryClient queryClient = new QueryClient(queryRunner, io.dropwizard.util.Duration.seconds(60), query);
    try {
        queryClient.executeWith(new Function<StatementClient, Void>() {

            @Nullable
            @Override
            public Void apply(StatementClient client) {
                QueryResults results = client.current();
                if (results.getData() != null && results.getColumns() != null) {
                    final List<Column> columns = results.getColumns();
                    for (Column column : columns) {
                        objects.put(column, Lists.newArrayList());
                    }
                    for (List<Object> row : results.getData()) {
                        for (int i = 0; i < row.size(); i++) {
                            Column column = columns.get(i);
                            objects.get(column).add(row.get(i));
                        }
                    }
                }
                return null;
            }
        });
    } catch (QueryClient.QueryTimeOutException e) {
        log.error("Caught timeout loading columns", e);
    }
    for (Map.Entry<Column, List<Object>> entry : objects.entrySet()) {
        cache.add(HivePartition.fromColumn(entry.getKey(), entry.getValue()));
    }
    return cache.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) StatementClient(com.facebook.presto.client.StatementClient) QueryRunner(com.airbnb.airpal.presto.QueryRunner) QueryResults(com.facebook.presto.client.QueryResults) QueryClient(com.airbnb.airpal.core.execution.QueryClient) Column(com.facebook.presto.client.Column) HiveColumn(com.airbnb.airpal.presto.hive.HiveColumn) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) Map(java.util.Map) Nullable(javax.annotation.Nullable) HivePartition(com.airbnb.airpal.presto.hive.HivePartition)

Example 3 with Column

use of com.facebook.presto.client.Column in project airpal by airbnb.

the class ColumnCache method queryColumns.

private List<HiveColumn> queryColumns(String query) {
    final ImmutableList.Builder<HiveColumn> cache = ImmutableList.builder();
    QueryRunner queryRunner = queryRunnerFactory.create();
    QueryClient queryClient = new QueryClient(queryRunner, io.dropwizard.util.Duration.seconds(60), query);
    try {
        queryClient.executeWith(new Function<StatementClient, Void>() {

            @Nullable
            @Override
            public Void apply(StatementClient client) {
                QueryResults results = client.current();
                if (results.getData() != null) {
                    for (List<Object> row : results.getData()) {
                        Column column = new Column((String) row.get(0), (String) row.get(1), new ClientTypeSignature(TypeSignature.parseTypeSignature((String) row.get(1))));
                        boolean isNullable = (Boolean) row.get(2);
                        boolean isPartition = (Boolean) row.get(3);
                        cache.add(HiveColumn.fromColumn(column, isNullable, isPartition));
                    }
                }
                return null;
            }
        });
    } catch (QueryClient.QueryTimeOutException e) {
        log.error("Caught timeout loading columns", e);
    }
    return cache.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) StatementClient(com.facebook.presto.client.StatementClient) QueryRunner(com.airbnb.airpal.presto.QueryRunner) QueryResults(com.facebook.presto.client.QueryResults) QueryClient(com.airbnb.airpal.core.execution.QueryClient) Column(com.facebook.presto.client.Column) HiveColumn(com.airbnb.airpal.presto.hive.HiveColumn) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) HiveColumn(com.airbnb.airpal.presto.hive.HiveColumn) ClientTypeSignature(com.facebook.presto.client.ClientTypeSignature) Nullable(javax.annotation.Nullable)

Example 4 with Column

use of com.facebook.presto.client.Column in project airpal by airbnb.

the class QueriesResource method getQueries.

@GET
public Response getQueries(@Auth AirpalUser user, @QueryParam("results") int numResults, @QueryParam("table") List<PartitionedTable> tables) {
    Iterable<Job> recentlyRun;
    int results = Optional.of(numResults).or(200);
    if (tables.size() < 1) {
        recentlyRun = jobHistoryStore.getRecentlyRun(results);
    } else {
        recentlyRun = jobHistoryStore.getRecentlyRun(results, Iterables.transform(tables, new PartitionedTable.PartitionedTableToTable()));
    }
    ImmutableList.Builder<Job> filtered = ImmutableList.builder();
    for (Job job : recentlyRun) {
        if (job.getTablesUsed().isEmpty() && (job.getState() == JobState.FAILED)) {
            filtered.add(job);
            continue;
        }
        for (Table table : job.getTablesUsed()) {
            if (AuthorizationUtil.isAuthorizedRead(user, table)) {
                filtered.add(new Job(job.getUser(), job.getQuery(), job.getUuid(), job.getOutput(), job.getQueryStats(), job.getState(), Collections.<Column>emptyList(), Collections.<Table>emptySet(), job.getQueryStartedDateTime(), job.getError(), job.getQueryFinishedDateTime()));
            }
        }
    }
    List<Job> sortedResult = Ordering.natural().nullsLast().onResultOf(JOB_ORDERING).reverse().immutableSortedCopy(filtered.build());
    return Response.ok(sortedResult).build();
}
Also used : Table(com.airbnb.airpal.presto.Table) PartitionedTable(com.airbnb.airpal.presto.PartitionedTable) Column(com.facebook.presto.client.Column) ImmutableList(com.google.common.collect.ImmutableList) PartitionedTable(com.airbnb.airpal.presto.PartitionedTable) Job(com.airbnb.airpal.api.Job) GET(javax.ws.rs.GET)

Example 5 with Column

use of com.facebook.presto.client.Column in project presto by prestodb.

the class PrestoResultSet method getColumnInfo.

private static List<ColumnInfo> getColumnInfo(List<Column> columns) {
    ImmutableList.Builder<ColumnInfo> list = ImmutableList.builder();
    for (Column column : columns) {
        ColumnInfo.Builder builder = new ColumnInfo.Builder().setCatalogName(// TODO
        "").setSchemaName(// TODO
        "").setTableName(// TODO
        "").setColumnLabel(column.getName()).setColumnName(// TODO
        column.getName()).setColumnTypeSignature(parseTypeSignature(column.getType().toUpperCase(ENGLISH))).setNullable(Nullable.UNKNOWN).setCurrency(false);
        setTypeInfo(builder, parseTypeSignature(column.getType()));
        list.add(builder.build());
    }
    return list.build();
}
Also used : Column(com.facebook.presto.client.Column) ImmutableList(com.google.common.collect.ImmutableList) DateTimeFormatterBuilder(org.joda.time.format.DateTimeFormatterBuilder)

Aggregations

Column (com.facebook.presto.client.Column)7 ImmutableList (com.google.common.collect.ImmutableList)6 Job (com.airbnb.airpal.api.Job)3 PartitionedTable (com.airbnb.airpal.presto.PartitionedTable)3 Table (com.airbnb.airpal.presto.Table)3 QueryResults (com.facebook.presto.client.QueryResults)3 GET (javax.ws.rs.GET)3 QueryClient (com.airbnb.airpal.core.execution.QueryClient)2 QueryRunner (com.airbnb.airpal.presto.QueryRunner)2 HiveColumn (com.airbnb.airpal.presto.hive.HiveColumn)2 StatementClient (com.facebook.presto.client.StatementClient)2 List (java.util.List)2 Nullable (javax.annotation.Nullable)2 Path (javax.ws.rs.Path)2 PartitionedTableToTable (com.airbnb.airpal.presto.PartitionedTable.PartitionedTableToTable)1 HivePartition (com.airbnb.airpal.presto.hive.HivePartition)1 ClientTypeSignature (com.facebook.presto.client.ClientTypeSignature)1 SQLException (java.sql.SQLException)1 Map (java.util.Map)1 Produces (javax.ws.rs.Produces)1