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

feat: Add method to construct InputTableUpdater from Table #6680

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public BaseArrayBackedInputTable(TrackingRowSet rowSet, Map<String, ? extends Co
}

public InputTableUpdater inputTable() {
return (InputTableUpdater) getAttribute(Table.INPUT_TABLE_ATTRIBUTE);
return InputTableUpdater.from(this);
}

public Table readOnlyCopy() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@
*/
public interface InputTableUpdater {

/**
* Get the input table updater from the given {@code table}, or {@code null} if the input table updater is not set
* or is the wrong type.
*
* @param table the table
* @return the input table updater
* @see Table#INPUT_TABLE_ATTRIBUTE
*/
static InputTableUpdater from(Table table) {
final Object obj = table.getAttribute(Table.INPUT_TABLE_ATTRIBUTE);
return obj instanceof InputTableUpdater ? (InputTableUpdater) obj : null;
}

/**
* Gets the names of the key columns.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void testSimple() throws Exception {

assertTableEquals(input, kabut);

final InputTableUpdater inputTableUpdater = (InputTableUpdater) kabut.getAttribute(Table.INPUT_TABLE_ATTRIBUTE);
final InputTableUpdater inputTableUpdater = InputTableUpdater.from(kabut);
TestCase.assertNotNull(inputTableUpdater);

final Table input2 = TableTools.newTable(stringCol("Name", "Randy"), stringCol("Employer", "USGS"));
Expand Down Expand Up @@ -101,8 +101,7 @@ public void testAppendOnly() throws Exception {

assertTableEquals(input, aoabmt);

final InputTableUpdater inputTableUpdater =
(InputTableUpdater) aoabmt.getAttribute(Table.INPUT_TABLE_ATTRIBUTE);
final InputTableUpdater inputTableUpdater = InputTableUpdater.from(aoabmt);
TestCase.assertNotNull(inputTableUpdater);

final Table input2 =
Expand All @@ -127,7 +126,7 @@ public void testFilteredAndSorted() throws Exception {

final Table fs = kabut.where("Name.length() == 4").sort("Name");

final InputTableUpdater inputTableUpdater = (InputTableUpdater) fs.getAttribute(Table.INPUT_TABLE_ATTRIBUTE);
final InputTableUpdater inputTableUpdater = InputTableUpdater.from(fs);
TestCase.assertNotNull(inputTableUpdater);

final Table delete = TableTools.newTable(stringCol("Name", "Fred"));
Expand All @@ -149,7 +148,7 @@ public void testAddBack() throws Exception {

assertTableEquals(input, kabut);

final InputTableUpdater inputTableUpdater = (InputTableUpdater) kabut.getAttribute(Table.INPUT_TABLE_ATTRIBUTE);
final InputTableUpdater inputTableUpdater = InputTableUpdater.from(kabut);
TestCase.assertNotNull(inputTableUpdater);

final Table input2 =
Expand Down
5 changes: 1 addition & 4 deletions py/server/deephaven/table_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
_JKeyedArrayBackedInputTable = jpy.get_type("io.deephaven.engine.table.impl.util.KeyedArrayBackedInputTable")
_JTableDefinition = jpy.get_type("io.deephaven.engine.table.TableDefinition")
_JTable = jpy.get_type("io.deephaven.engine.table.Table")
_J_INPUT_TABLE_ATTRIBUTE = _JTable.INPUT_TABLE_ATTRIBUTE
_J_InputTableUpdater = jpy.get_type("io.deephaven.engine.util.input.InputTableUpdater")
_JRingTableTools = jpy.get_type("io.deephaven.engine.table.impl.sources.ring.RingTableTools")
_JSupplier = jpy.get_type('java.util.function.Supplier')
Expand Down Expand Up @@ -247,11 +246,9 @@ class InputTable(Table):

def __init__(self, j_table: jpy.JType):
super().__init__(j_table)
self.j_input_table = self.j_table.getAttribute(_J_INPUT_TABLE_ATTRIBUTE)
self.j_input_table = getattr(_J_InputTableUpdater, "from")(self.j_table)
if not self.j_input_table:
raise DHError("the provided table input is not suitable for input tables.")
if not _J_InputTableUpdater.jclass.isInstance(self.j_input_table):
raise DHError("the provided table's InputTable attribute type is not of InputTableUpdater type.")

def add(self, table: Table) -> None:
"""Synchronously writes rows from the provided table to this input table. If this is a keyed input table,
Expand Down
2 changes: 1 addition & 1 deletion py/server/tests/test_table_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ def test_input_table(self):

with self.assertRaises(DHError) as cm:
InputTable(place_holder_input_table)
self.assertIn("not of InputTableUpdater type", str(cm.exception))
self.assertIn("the provided table input is not suitable for input tables.", str(cm.exception))

self.assertTrue(isinstance(_wrapper.wrap_j_object(place_holder_input_table), Table))

Expand Down