Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update JS API to support gRPC input tables #1565

Merged
merged 12 commits into from
Nov 19, 2021

Conversation

niloc132
Copy link
Member

Building on #1440, this adds support in the JS API for input tables.

CSV upload is rebuilt in this as well, and expanded to be more generic, so that input tables can reuse the same logic. This should be at least as flexible as the UI previously required (though the ability to handle arrays of data has been removed temporarily, but to my knowledge it was never in active use).

Copy link
Member

@mofojed mofojed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit of minor cleanup, and a couple of questions

if (onlyTable.getColumns().length == keys.length && onlyTable.findColumns(keys).length == keys.length) {
ticketToDelete = onlyTable.getHandle().makeTicket();
} else {
// view the only table
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it throw if the tablesToDelete doesn't match the schema of the input table you're deleting from?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will throw, but not until later. I can add a local check here to give a clearer message.

ResponseStreamWrapper<ExportedTableCreationResponse> wrapper = ResponseStreamWrapper.of(
table.getConnection().tableServiceClient().batch(batch, table.getConnection().metadata()));
wrapper.onData(response -> {
// kill the promise on the first failure we see
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to get more than one failure? Then we might be double rejecting the promise

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double rejecting just means you lose a later reject (or resolve), no? This code is operating on that assumption for now, rather than accumulate errors or something - is that okay?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea I guess that's fine

mofojed
mofojed previously approved these changes Nov 17, 2021

// write the value, and mark non-null if necessary
if (boolValue != NULL_BOOLEAN_AS_BYTE) {
nulls.set(i);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is inconsistent w.r.t. a corresponding nullCount -- however, I think this use case also applies; that we explicitly want to send the empty validity buffer.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this time, I am not sending a dhNulls=true, but doing a vanilla DoPut, just with deephaven:type metadata.

private static void writeSimpleNumbers(Object[] data, JsConsumer<Node> addNode, JsConsumer<Uint8Array> addBuffer,
double bytesPerElement, double nullValue, JsFunction<ArrayBuffer, ? extends TypedArray> bufferConstructor) {
int nullCount = 0;
BitSet nulls = new BitSet(data.length);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment here on the null counting; I'd send the empty validity buffer explicitly

table.getConnection().inputTableServiceClient().addTableToInputTable(addTableRequest,
table.getConnection().metadata(), c::apply);
}).then(success -> {
if (merged != tablesToAdd[0]) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the check; but correctness might be more obvious if you stick to the length check like on line 101.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The goal in having a different check was to acknowledge "this is an intermediate instance so it must be closed" - if the logic between here and 101 changes, I would want to allow for this still to be correct.

What do you think of something instead like Arrays.stream(tablesToAdd).allMatch(t -> t != merged)?

nbauernfeind
nbauernfeind previously approved these changes Nov 19, 2021
@niloc132 niloc132 mentioned this pull request Nov 19, 2021
6 tasks
@niloc132 niloc132 merged commit 96f7035 into deephaven:main Nov 19, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Nov 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants