Search in sources :

Example 1 with InitialTableDefinition

use of io.deephaven.web.client.api.barrage.def.InitialTableDefinition in project deephaven-core by deephaven.

the class ClientTableState method applyTableCreationResponse.

public void applyTableCreationResponse(ExportedTableCreationResponse def) {
    assert def.getResultId().getTicket().getTicket_asB64().equals(getHandle().makeTicket().getTicket_asB64()) : "Ticket is incompatible with the table details";
    // by definition, the ticket is now exported and connected
    handle.setState(TableTicket.State.EXPORTED);
    handle.setConnected(true);
    // we conform to flight's schema representation of:
    // - IPC_CONTINUATION_TOKEN (4-byte int of -1)
    // - message size (4-byte int)
    // - a Message wrapping the schema
    ByteBuffer bb = new ByteBuffer(def.getSchemaHeader_asU8());
    bb.setPosition(bb.position() + 8);
    Message headerMessage = Message.getRootAsMessage(bb);
    assert headerMessage.headerType() == MessageHeader.Schema;
    Schema schema = headerMessage.header(new Schema());
    ColumnDefinition[] cols = new ColumnDefinition[(int) schema.fieldsLength()];
    for (int i = 0; i < schema.fieldsLength(); i++) {
        cols[i] = new ColumnDefinition();
        Field f = schema.fields(i);
        Map<String, String> fieldMetadata = keyValuePairs("deephaven:", f.customMetadataLength(), f::customMetadata);
        cols[i].setName(f.name().asString());
        cols[i].setColumnIndex(i);
        cols[i].setType(fieldMetadata.get("type"));
        cols[i].setStyleColumn("true".equals(fieldMetadata.get("isStyle")));
        cols[i].setFormatColumn("true".equals(fieldMetadata.get("isDateFormat")) || "true".equals(fieldMetadata.get("isNumberFormat")));
        cols[i].setForRow("true".equals(fieldMetadata.get("isRowStyle")));
        String formatColumnName = fieldMetadata.get("dateFormatColumn");
        if (formatColumnName == null) {
            formatColumnName = fieldMetadata.get("numberFormatColumn");
        }
        cols[i].setFormatColumnName(formatColumnName);
        cols[i].setStyleColumnName(fieldMetadata.get("styleColumn"));
        if (fieldMetadata.containsKey("inputtable.isKey")) {
            cols[i].setInputTableKeyColumn(Boolean.parseBoolean(fieldMetadata.get("inputtable.isKey")));
        }
        cols[i].setDescription(fieldMetadata.get("description"));
    }
    TableAttributesDefinition attributes = new TableAttributesDefinition(keyValuePairs("deephaven:attribute.", schema.customMetadataLength(), schema::customMetadata), keyValuePairs("deephaven:unsent.attribute.", schema.customMetadataLength(), schema::customMetadata).keySet());
    setTableDef(new InitialTableDefinition().setAttributes(attributes).setColumns(cols));
    setResolution(ResolutionState.RUNNING);
    setSize(Long.parseLong(def.getSize()));
}
Also used : TableAttributesDefinition(io.deephaven.web.client.api.barrage.def.TableAttributesDefinition) Message(io.deephaven.javascript.proto.dhinternal.arrow.flight.flatbuf.message_generated.org.apache.arrow.flatbuf.Message) Schema(io.deephaven.javascript.proto.dhinternal.arrow.flight.flatbuf.schema_generated.org.apache.arrow.flatbuf.Schema) ByteBuffer(io.deephaven.javascript.proto.dhinternal.flatbuffers.ByteBuffer) ColumnDefinition(io.deephaven.web.client.api.barrage.def.ColumnDefinition) Field(io.deephaven.javascript.proto.dhinternal.arrow.flight.flatbuf.schema_generated.org.apache.arrow.flatbuf.Field) InitialTableDefinition(io.deephaven.web.client.api.barrage.def.InitialTableDefinition)

Aggregations

Message (io.deephaven.javascript.proto.dhinternal.arrow.flight.flatbuf.message_generated.org.apache.arrow.flatbuf.Message)1 Field (io.deephaven.javascript.proto.dhinternal.arrow.flight.flatbuf.schema_generated.org.apache.arrow.flatbuf.Field)1 Schema (io.deephaven.javascript.proto.dhinternal.arrow.flight.flatbuf.schema_generated.org.apache.arrow.flatbuf.Schema)1 ByteBuffer (io.deephaven.javascript.proto.dhinternal.flatbuffers.ByteBuffer)1 ColumnDefinition (io.deephaven.web.client.api.barrage.def.ColumnDefinition)1 InitialTableDefinition (io.deephaven.web.client.api.barrage.def.InitialTableDefinition)1 TableAttributesDefinition (io.deephaven.web.client.api.barrage.def.TableAttributesDefinition)1