Skip to content

Commit

Permalink
fix: Modify getKeyColumns method for JsInputTable (#5600)
Browse files Browse the repository at this point in the history
* Made JsInputTable.getKeyColumns and JsInputTable.getValueColumns return a Frozen/Stable Array similar to the JsTable.getColumns
* Created corresponding test file ( InputTableTestGwt ) with unit tests that check both methods
  • Loading branch information
AkshatJawne authored Jun 12, 2024
1 parent e3bf07e commit 61f5a7a
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package io.deephaven.web.client.api.input;

import elemental2.core.JsObject;
import elemental2.core.JsArray;
import elemental2.promise.Promise;
import io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.inputtable_pb.AddTableRequest;
import io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.inputtable_pb.DeleteTableRequest;
Expand All @@ -16,13 +17,15 @@
import io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.ticket_pb.Ticket;
import io.deephaven.web.client.api.Callbacks;
import io.deephaven.web.client.api.Column;
import io.deephaven.web.client.api.JsLazy;
import io.deephaven.web.client.api.JsTable;
import io.deephaven.web.client.api.barrage.stream.ResponseStreamWrapper;
import io.deephaven.web.shared.fu.JsRunnable;
import jsinterop.annotations.JsIgnore;
import jsinterop.annotations.JsOptional;
import jsinterop.annotations.JsProperty;
import jsinterop.annotations.JsType;
import jsinterop.base.Js;
import jsinterop.base.JsPropertyMap;

import java.util.ArrayList;
Expand Down Expand Up @@ -51,12 +54,16 @@ public class JsInputTable {
private final JsTable table;
private final String[] keys;
private final String[] values;
private final JsLazy<Column[]> keyColumns;
private final JsLazy<Column[]> valueColumns;

@JsIgnore
public JsInputTable(JsTable from, String[] keys, String[] values) {
this.table = from;
this.keys = JsObject.freeze(keys);
this.values = JsObject.freeze(values);
this.keyColumns = JsLazy.of(() -> JsObject.freeze(table.findColumns(keys)));
this.valueColumns = JsLazy.of(() -> JsObject.freeze(table.findColumns(values)));
}

/**
Expand All @@ -70,15 +77,16 @@ public String[] getKeys() {
}

/**
* A list of the key Column objects
*
* @return {@link Column} array.
* A list of the key columns.
*
* @return Column array.
*/
@JsProperty
public Column[] getKeyColumns() {
return table.findColumns(keys);
return keyColumns.get();
}


/**
* A list of the value columns, by name
*
Expand All @@ -96,7 +104,7 @@ public String[] getValues() {
*/
@JsProperty
public Column[] getValueColumns() {
return table.findColumns(values);
return valueColumns.get();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@
package io.deephaven.web;

import com.google.gwt.junit.tools.GWTTestSuite;
import io.deephaven.web.client.api.HierarchicalTableTestGwt;
import io.deephaven.web.client.api.NullValueTestGwt;
import io.deephaven.web.client.api.PartitionedTableTestGwt;
import io.deephaven.web.client.api.*;
import io.deephaven.web.client.api.storage.JsStorageServiceTestGwt;
import io.deephaven.web.client.api.subscription.ConcurrentTableTestGwt;
import io.deephaven.web.client.api.TableManipulationTestGwt;
import io.deephaven.web.client.api.subscription.ViewportTestGwt;
import io.deephaven.web.client.fu.LazyPromiseTestGwt;
import junit.framework.Test;
Expand All @@ -31,6 +28,7 @@ public static Test suite() {
suite.addTestSuite(HierarchicalTableTestGwt.class);
suite.addTestSuite(PartitionedTableTestGwt.class);
suite.addTestSuite(JsStorageServiceTestGwt.class);
suite.addTestSuite(InputTableTestGwt.class);

// This should be a unit test, but it requires a browser environment to run on GWT 2.9
// GWT 2.9 doesn't have proper bindings for Promises in HtmlUnit, so we need to use the IntegrationTest suite
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
//
// Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending
//
package io.deephaven.web.client.api;

import elemental2.core.JsArray;
import jsinterop.base.Js;

public class InputTableTestGwt extends AbstractAsyncGwtTestCase {
private final TableSourceBuilder tables = new TableSourceBuilder()
.script("from deephaven import empty_table, input_table")
.script("source",
"empty_table(5).update([\"A=`` + i\", \"B=`` + i * 2\", \"C=i\", \"D=i * 2\", \"E=`` + i\", \"F=`` + i * 2\",])")
.script("result1", "input_table(init_table=source, key_cols=[])")
.script("result2", "input_table(init_table=source, key_cols=[\"A\" , \"B\" ])")
.script("result3", "input_table(init_table=source, key_cols=[\"C\"])")
.script("result4", "input_table(init_table=source, key_cols=[\"E\" , \"F\" ])");

public void testInputTable() {
connect(tables)
.then(table("result1"))
.then(JsTable::inputTable)
.then(inputTable -> {
JsArray<Column> keyColumns = Js.uncheckedCast(inputTable.getKeyColumns());
assertEquals(0, keyColumns.length);
return null;
})
.then(this::finish).catch_(this::report);

connect(tables)
.then(table("result2"))
.then(JsTable::inputTable)
.then(inputTable -> {
JsArray<Column> keyColumns = Js.uncheckedCast(inputTable.getKeyColumns());
assertEquals(2,
keyColumns.filter((col, idx) -> col.getName() == "A" || col.getName() == "B").length);
JsArray<Column> valueColumns = Js.uncheckedCast(inputTable.getValues());
assertEquals(4, valueColumns.filter((col, idx) -> col.getName() == "C" || col.getName() == "D"
|| col.getName() == "E" || col.getName() == "F").length);
return null;
})
.then(this::finish).catch_(this::report);

connect(tables)
.then(table("result3"))
.then(JsTable::inputTable)
.then(inputTable -> {
JsArray<Column> keyColumns = Js.uncheckedCast(inputTable.getKeyColumns());
assertEquals(1, keyColumns.filter((col, idx) -> col.getName() == "C").length);
JsArray<Column> valueColumns = Js.uncheckedCast(inputTable.getValues());
assertEquals(5, valueColumns.filter((col, idx) -> col.getName() == "A" || col.getName() == "B"
|| col.getName() == "D" || col.getName() == "E" || col.getName() == "F").length);
return null;
})
.then(this::finish).catch_(this::report);

connect(tables)
.then(table("result4"))
.then(JsTable::inputTable)
.then(inputTable -> {
JsArray<Column> keyColumns = Js.uncheckedCast(inputTable.getKeyColumns());
assertEquals(2,
keyColumns.filter((col, idx) -> col.getName() == "E" || col.getName() == "F").length);
JsArray<Column> valueColumns = Js.uncheckedCast(inputTable.getValues());
assertEquals(4, valueColumns.filter((col, idx) -> col.getName() == "A" || col.getName() == "B"
|| col.getName() == "C" || col.getName() == "D").length);
return null;
})
.then(this::finish).catch_(this::report);
}

@Override
public String getModuleName() {
return "io.deephaven.web.DeephavenIntegrationTest";
}
}

0 comments on commit 61f5a7a

Please sign in to comment.