Search in sources :

Example 1 with TableAttributesDefinition

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

the class JsTable method getAttribute.

@JsMethod
public Object getAttribute(String attributeName) {
    TableAttributesDefinition attrs = lastVisibleState().getTableDef().getAttributes();
    // If the value was present as something easy to serialize, return it.
    String value = attrs.getValue(attributeName);
    if (value != null) {
        return value;
    }
    // This shouldn't be used to detect the absence of an attribute, use getAttributes() for that
    if (!attrs.getRemainingAttributeKeys().contains(attributeName)) {
        return null;
    }
    // some other type. If this isn't correct, the server will fail and we'll fail the promise.
    return workerConnection.newState((c, cts, metadata) -> {
        // );
        throw new UnsupportedOperationException("getAttribute");
    }, "reading table from attribute with name " + attributeName).refetch(this, workerConnection.metadata()).then(cts -> Promise.resolve(new JsTable(workerConnection, cts)));
}
Also used : TableAttributesDefinition(io.deephaven.web.client.api.barrage.def.TableAttributesDefinition) JsMethod(jsinterop.annotations.JsMethod)

Example 2 with TableAttributesDefinition

use of io.deephaven.web.client.api.barrage.def.TableAttributesDefinition 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

TableAttributesDefinition (io.deephaven.web.client.api.barrage.def.TableAttributesDefinition)2 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 JsMethod (jsinterop.annotations.JsMethod)1