Search in sources :

Example 1 with Column

use of io.prestosql.client.Column in project hetu-core by openlookeng.

the class Query method setQueryOutputInfo.

private synchronized void setQueryOutputInfo(QueryExecution.QueryOutputInfo outputInfo) {
    // if first callback, set column names
    if (columns == null) {
        List<String> columnNames = outputInfo.getColumnNames();
        List<Type> columnTypes = outputInfo.getColumnTypes();
        checkArgument(columnNames.size() == columnTypes.size(), "Column names and types size mismatch");
        ImmutableList.Builder<Column> list = ImmutableList.builder();
        for (int i = 0; i < columnNames.size(); i++) {
            list.add(createColumn(columnNames.get(i), columnTypes.get(i)));
        }
        columns = list.build();
        types = outputInfo.getColumnTypes();
    }
    for (TaskLocation outputLocation : outputInfo.getBufferLocations()) {
        exchangeClient.addLocation(outputLocation);
    }
    if (outputInfo.isNoMoreBufferLocations()) {
        exchangeClient.noMoreLocations();
    }
}
Also used : Type(io.prestosql.spi.type.Type) BooleanType(io.prestosql.spi.type.BooleanType) Column(io.prestosql.client.Column) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) TaskLocation(io.prestosql.operator.TaskLocation)

Example 2 with Column

use of io.prestosql.client.Column in project hetu-core by openlookeng.

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(column.getTypeSignature()).setNullable(Nullable.UNKNOWN).setCurrency(false);
        setTypeInfo(builder, column.getTypeSignature());
        list.add(builder.build());
    }
    return list.build();
}
Also used : Column(io.prestosql.client.Column) ImmutableList(com.google.common.collect.ImmutableList) DateTimeFormatterBuilder(org.joda.time.format.DateTimeFormatterBuilder)

Example 3 with Column

use of io.prestosql.client.Column in project hetu-core by openlookeng.

the class PrestoResultSet method getColumns.

private static List<Column> getColumns(StatementClient client, Consumer<QueryStats> progressCallback) throws SQLException {
    while (client.isRunning()) {
        QueryStatusInfo tmpResults = client.currentStatusInfo();
        progressCallback.accept(QueryStats.create(tmpResults.getId(), tmpResults.getStats()));
        List<Column> columns = tmpResults.getColumns();
        if (columns != null) {
            return columns;
        }
        client.advance();
    }
    verify(client.isFinished());
    QueryStatusInfo tmpResults = client.finalStatusInfo();
    if (tmpResults.getError() == null) {
        throw new SQLException(format("Query has no columns (#%s)", tmpResults.getId()));
    }
    throw resultsException(tmpResults);
}
Also used : Column(io.prestosql.client.Column) SQLException(java.sql.SQLException) QueryStatusInfo(io.prestosql.client.QueryStatusInfo)

Example 4 with Column

use of io.prestosql.client.Column in project hetu-core by openlookeng.

the class MetadataResource method getTableColumns.

@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("columns/{catalog}/{schema}/{table}")
public Response getTableColumns(@PathParam("catalog") String catalogName, @PathParam("schema") String schemaName, @PathParam("table") String tableName, @Context HttpServletRequest servletRequest) throws ExecutionException {
    String user = AccessControlUtil.getUser(accessControl, new HttpRequestSessionContext(servletRequest, groupProvider));
    List<Column> columnList = columnService.getColumns(catalogName, schemaName, tableName, user);
    return Response.ok(columnList).build();
}
Also used : Column(io.prestosql.client.Column) HttpRequestSessionContext(io.prestosql.server.HttpRequestSessionContext) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 5 with Column

use of io.prestosql.client.Column in project hetu-core by openlookeng.

the class TestAlignedTablePrinter method testAlignedPrintingHex.

@Test
public void testAlignedPrintingHex() throws Exception {
    List<Column> columns = ImmutableList.<Column>builder().add(column("first", VARCHAR)).add(column("binary", VARBINARY)).add(column("last", VARCHAR)).build();
    StringWriter writer = new StringWriter();
    OutputPrinter printer = new AlignedTablePrinter(columns, writer);
    printer.printRows(rows(row("hello", bytes("hello"), "world"), row("a", bytes("some long text that is more than 16 bytes"), "b"), row("cat", bytes(""), "dog")), true);
    printer.finish();
    String expected = "" + " first |                     binary                      | last  \n" + "-------+-------------------------------------------------+-------\n" + " hello | 68 65 6c 6c 6f                                  | world \n" + " a     | 73 6f 6d 65 20 6c 6f 6e 67 20 74 65 78 74 20 74+| b     \n" + "       | 68 61 74 20 69 73 20 6d 6f 72 65 20 74 68 61 6e+|       \n" + "       | 20 31 36 20 62 79 74 65 73                      |       \n" + " cat   |                                                 | dog   \n" + "(3 rows)\n";
    assertEquals(writer.getBuffer().toString(), expected);
}
Also used : StringWriter(java.io.StringWriter) Column(io.prestosql.client.Column) Test(org.testng.annotations.Test)

Aggregations

Column (io.prestosql.client.Column)11 StringWriter (java.io.StringWriter)5 Test (org.testng.annotations.Test)5 ImmutableList (com.google.common.collect.ImmutableList)4 QueryData (io.prestosql.client.QueryData)2 QueryStatusInfo (io.prestosql.client.QueryStatusInfo)2 List (java.util.List)2 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ErrorLocation (io.prestosql.client.ErrorLocation)1 QueryError (io.prestosql.client.QueryError)1 StatementClient (io.prestosql.client.StatementClient)1 QueryStats (io.prestosql.execution.QueryStats)1 TaskLocation (io.prestosql.operator.TaskLocation)1 ExecutionFailureException (io.prestosql.queryeditorui.execution.ExecutionClient.ExecutionFailureException)1 QueryClient (io.prestosql.queryeditorui.execution.QueryClient)1 QueryTimeOutException (io.prestosql.queryeditorui.execution.QueryClient.QueryTimeOutException)1 BasicQueryInfo (io.prestosql.queryeditorui.execution.QueryInfoClient.BasicQueryInfo)1 QueryRunner (io.prestosql.queryeditorui.execution.QueryRunner)1 FileTooLargeException (io.prestosql.queryeditorui.output.builders.FileTooLargeException)1 JobOutputBuilder (io.prestosql.queryeditorui.output.builders.JobOutputBuilder)1