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

Simplify Input Table Interface. #4923

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -8,8 +8,8 @@
import io.deephaven.engine.table.Table;
import io.deephaven.engine.table.TableDefinition;
import io.deephaven.engine.table.TableFactory;
import io.deephaven.engine.table.impl.util.AppendOnlyArrayBackedMutableTable;
import io.deephaven.engine.table.impl.util.KeyedArrayBackedMutableTable;
import io.deephaven.engine.table.impl.util.AppendOnlyArrayBackedInputTable;
import io.deephaven.engine.table.impl.util.KeyedArrayBackedInputTable;
import io.deephaven.engine.util.TableTools;
import io.deephaven.qst.TableCreator;
import io.deephaven.qst.table.EmptyTable;
Expand Down Expand Up @@ -163,14 +163,14 @@ public static UpdatableTable of(InputTable inputTable) {
@Override
public UpdatableTable visit(InMemoryAppendOnlyInputTable inMemoryAppendOnly) {
final TableDefinition definition = DefinitionAdapter.of(inMemoryAppendOnly.schema());
return AppendOnlyArrayBackedMutableTable.make(definition);
return AppendOnlyArrayBackedInputTable.make(definition);
}

@Override
public UpdatableTable visit(InMemoryKeyBackedInputTable inMemoryKeyBacked) {
final TableDefinition definition = DefinitionAdapter.of(inMemoryKeyBacked.schema());
final String[] keyColumnNames = inMemoryKeyBacked.keys().toArray(String[]::new);
return KeyedArrayBackedMutableTable.make(definition, keyColumnNames);
return KeyedArrayBackedInputTable.make(definition, keyColumnNames);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* <p>
* The table is not keyed, all rows are added to the end of the table. Deletions and edits are not permitted.
*/
public class AppendOnlyArrayBackedMutableTable extends BaseArrayBackedMutableTable {
public class AppendOnlyArrayBackedInputTable extends BaseArrayBackedInputTable {
static final String DEFAULT_DESCRIPTION = "Append Only In-Memory Input Table";

/**
Expand All @@ -33,11 +33,11 @@ public class AppendOnlyArrayBackedMutableTable extends BaseArrayBackedMutableTab
*
* @return an empty AppendOnlyArrayBackedMutableTable with the given definition
*/
public static AppendOnlyArrayBackedMutableTable make(@NotNull TableDefinition definition) {
public static io.deephaven.engine.table.impl.util.AppendOnlyArrayBackedInputTable make(@NotNull TableDefinition definition) {
// noinspection resource
final Table initialTable = new QueryTable(definition, RowSetFactory.empty().toTracking(),
NullValueColumnSource.createColumnSourceMap(definition));
final AppendOnlyArrayBackedMutableTable result = new AppendOnlyArrayBackedMutableTable(
final io.deephaven.engine.table.impl.util.AppendOnlyArrayBackedInputTable result = new io.deephaven.engine.table.impl.util.AppendOnlyArrayBackedInputTable(
initialTable.getDefinition(), new ProcessPendingUpdater());
result.setAttribute(Table.ADD_ONLY_TABLE_ATTRIBUTE, Boolean.TRUE);
result.setFlat();
Expand All @@ -52,17 +52,17 @@ public static AppendOnlyArrayBackedMutableTable make(@NotNull TableDefinition de
*
* @return an empty AppendOnlyArrayBackedMutableTable with the given definition
*/
public static AppendOnlyArrayBackedMutableTable make(final Table initialTable) {
final AppendOnlyArrayBackedMutableTable result = new AppendOnlyArrayBackedMutableTable(
public static io.deephaven.engine.table.impl.util.AppendOnlyArrayBackedInputTable make(final Table initialTable) {
final io.deephaven.engine.table.impl.util.AppendOnlyArrayBackedInputTable result = new io.deephaven.engine.table.impl.util.AppendOnlyArrayBackedInputTable(
initialTable.getDefinition(), new ProcessPendingUpdater());
result.setAttribute(Table.ADD_ONLY_TABLE_ATTRIBUTE, Boolean.TRUE);
result.setFlat();
processInitial(initialTable, result);
return result;
}

private AppendOnlyArrayBackedMutableTable(@NotNull TableDefinition definition,
final ProcessPendingUpdater processPendingUpdater) {
private AppendOnlyArrayBackedInputTable(@NotNull TableDefinition definition,
final ProcessPendingUpdater processPendingUpdater) {
// noinspection resource
super(RowSetFactory.empty().toTracking(), makeColumnSourceMap(definition),
processPendingUpdater);
Expand Down Expand Up @@ -111,11 +111,11 @@ protected List<String> getKeyNames() {
}

@Override
ArrayBackedMutableInputTable makeHandler() {
return new AppendOnlyArrayBackedMutableInputTable();
ArrayBackedInputTable makeHandler() {
return new Handler();
}

private class AppendOnlyArrayBackedMutableInputTable extends ArrayBackedMutableInputTable {
private class Handler extends ArrayBackedInputTable {

@Override
public void validateDelete(Table tableToDelete) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import io.deephaven.engine.table.WritableColumnSource;
import io.deephaven.engine.table.impl.sources.ArrayBackedColumnSource;
import io.deephaven.engine.util.config.InputTableStatusListener;
import io.deephaven.engine.util.config.MutableInputTable;
import io.deephaven.engine.util.config.InputTable;
import io.deephaven.engine.table.impl.UpdatableTable;
import io.deephaven.engine.table.ColumnSource;
import io.deephaven.util.annotations.TestUseOnly;
Expand All @@ -24,7 +24,7 @@
import java.util.*;
import java.util.concurrent.CompletableFuture;

abstract class BaseArrayBackedMutableTable extends UpdatableTable {
abstract class BaseArrayBackedInputTable extends UpdatableTable {

/**
* Queue of pending changes. Only synchronized access is permitted.
Expand All @@ -45,21 +45,21 @@ abstract class BaseArrayBackedMutableTable extends UpdatableTable {
long nextRow = 0;
private long pendingProcessed = -1L;

public BaseArrayBackedMutableTable(TrackingRowSet rowSet, Map<String, ? extends ColumnSource<?>> nameToColumnSource,
ProcessPendingUpdater processPendingUpdater) {
public BaseArrayBackedInputTable(TrackingRowSet rowSet, Map<String, ? extends ColumnSource<?>> nameToColumnSource,
ProcessPendingUpdater processPendingUpdater) {
super(rowSet, nameToColumnSource, processPendingUpdater);
MutableInputTable mutableInputTable = makeHandler();
setAttribute(Table.INPUT_TABLE_ATTRIBUTE, mutableInputTable);
InputTable inputTable = makeHandler();
setAttribute(Table.INPUT_TABLE_ATTRIBUTE, inputTable);
setRefreshing(true);
processPendingUpdater.setThis(this);
}

public MutableInputTable mutableInputTable() {
return (MutableInputTable) getAttribute(Table.INPUT_TABLE_ATTRIBUTE);
public InputTable inputTable() {
return (InputTable) getAttribute(Table.INPUT_TABLE_ATTRIBUTE);
}

public Table readOnlyCopy() {
return copy(BaseArrayBackedMutableTable::applicableForReadOnly);
return copy(BaseArrayBackedInputTable::applicableForReadOnly);
}

private static boolean applicableForReadOnly(String attributeName) {
Expand All @@ -75,7 +75,7 @@ private static boolean applicableForReadOnly(String attributeName) {
return resultMap;
}

static void processInitial(Table initialTable, BaseArrayBackedMutableTable result) {
static void processInitial(Table initialTable, BaseArrayBackedInputTable result) {
final RowSetBuilderSequential builder = RowSetFactory.builderSequential();
result.processPendingTable(initialTable, new RowSetChangeRecorder() {
@Override
Expand All @@ -98,7 +98,7 @@ public void modifyRowKey(long key) {
result.getUpdateGraph().addSource(result);
}

public BaseArrayBackedMutableTable setDescription(String newDescription) {
public BaseArrayBackedInputTable setDescription(String newDescription) {
this.description = newDescription;
return this;
}
Expand Down Expand Up @@ -152,15 +152,15 @@ public void run() {
protected abstract List<String> getKeyNames();

protected static class ProcessPendingUpdater implements Updater {
private BaseArrayBackedMutableTable baseArrayBackedMutableTable;
private BaseArrayBackedInputTable baseArrayBackedInputTable;

@Override
public void accept(RowSetChangeRecorder rowSetChangeRecorder) {
baseArrayBackedMutableTable.processPending(rowSetChangeRecorder);
baseArrayBackedInputTable.processPending(rowSetChangeRecorder);
}

public void setThis(BaseArrayBackedMutableTable keyedArrayBackedMutableTable) {
this.baseArrayBackedMutableTable = keyedArrayBackedMutableTable;
public void setThis(BaseArrayBackedInputTable keyedArrayBackedMutableTable) {
this.baseArrayBackedInputTable = keyedArrayBackedMutableTable;
}
}

Expand All @@ -178,19 +178,19 @@ private PendingChange(Table table, boolean delete) {
}
}

ArrayBackedMutableInputTable makeHandler() {
return new ArrayBackedMutableInputTable();
ArrayBackedInputTable makeHandler() {
return new ArrayBackedInputTable();
}

protected class ArrayBackedMutableInputTable implements MutableInputTable {
protected class ArrayBackedInputTable implements InputTable {
@Override
public List<String> getKeyNames() {
return BaseArrayBackedMutableTable.this.getKeyNames();
return BaseArrayBackedInputTable.this.getKeyNames();
}

@Override
public TableDefinition getTableDefinition() {
return BaseArrayBackedMutableTable.this.getDefinition();
return BaseArrayBackedInputTable.this.getDefinition();
}

@Override
Expand Down Expand Up @@ -320,7 +320,7 @@ void waitForSequence(long sequence) {
// in order to allow updates.
while (processedSequence < sequence) {
try {
BaseArrayBackedMutableTable.this.awaitUpdate();
BaseArrayBackedInputTable.this.awaitUpdate();
} catch (InterruptedException ignored) {
}
}
Expand Down Expand Up @@ -354,7 +354,7 @@ private Map<String, WritableColumnSource<Object>> buildSourcesMap(int capacity,

@Override
public Table getTable() {
return BaseArrayBackedMutableTable.this;
return BaseArrayBackedInputTable.this;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* <p>
* This is used to implement in-memory editable table columns from web plugins.
*/
public class KeyedArrayBackedMutableTable extends BaseArrayBackedMutableTable {
public class KeyedArrayBackedInputTable extends BaseArrayBackedInputTable {

private static final String DEFAULT_DESCRIPTION = "In-Memory Input Table";

Expand All @@ -46,8 +46,8 @@ public class KeyedArrayBackedMutableTable extends BaseArrayBackedMutableTable {
*
* @return an empty KeyedArrayBackedMutableTable with the given definition and key columns
*/
public static KeyedArrayBackedMutableTable make(@NotNull TableDefinition definition,
final String... keyColumnNames) {
public static KeyedArrayBackedInputTable make(@NotNull TableDefinition definition,
final String... keyColumnNames) {
// noinspection resource
return make(new QueryTable(definition, RowSetFactory.empty().toTracking(),
NullValueColumnSource.createColumnSourceMap(definition)), keyColumnNames);
Expand All @@ -64,16 +64,16 @@ public static KeyedArrayBackedMutableTable make(@NotNull TableDefinition definit
*
* @return an empty KeyedArrayBackedMutableTable with the given definition and key columns
*/
public static KeyedArrayBackedMutableTable make(final Table initialTable, final String... keyColumnNames) {
final KeyedArrayBackedMutableTable result = new KeyedArrayBackedMutableTable(initialTable.getDefinition(),
public static KeyedArrayBackedInputTable make(final Table initialTable, final String... keyColumnNames) {
final KeyedArrayBackedInputTable result = new KeyedArrayBackedInputTable(initialTable.getDefinition(),
keyColumnNames, new ProcessPendingUpdater());
processInitial(initialTable, result);
result.startTrackingPrev();
return result;
}

private KeyedArrayBackedMutableTable(@NotNull TableDefinition definition, final String[] keyColumnNames,
final ProcessPendingUpdater processPendingUpdater) {
private KeyedArrayBackedInputTable(@NotNull TableDefinition definition, final String[] keyColumnNames,
final ProcessPendingUpdater processPendingUpdater) {
// noinspection resource
super(RowSetFactory.empty().toTracking(), makeColumnSourceMap(definition),
processPendingUpdater);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@

/**
* A minimal interface for mutable shared tables, providing the ability to write to the table instance this is attached
* to. MutableInputTable instances are set on the table as an attribute.
* to. InputTable instances are set on the table as an attribute.
* <p>
* Implementations of this interface will make their own guarantees about how atomically changes will be applied and
* what operations they support.
*/
public interface MutableInputTable {
public interface InputTable {
Copy link
Member

Choose a reason for hiding this comment

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

InputTableHandler?


/**
* Gets the names of the key columns.
Expand Down Expand Up @@ -96,7 +96,7 @@ default void validateDelete(Table tableToDelete) {
* This method will block until the rows are added. As a result, this method is not suitable for use from a
* {@link io.deephaven.engine.table.TableListener table listener} or any other
* {@link io.deephaven.engine.updategraph.NotificationQueue.Notification notification}-dispatched callback
* dispatched by this MutableInputTable's {@link io.deephaven.engine.updategraph.UpdateGraph update graph}. It may
* dispatched by this InputTable's {@link io.deephaven.engine.updategraph.UpdateGraph update graph}. It may
* be suitable to delete from another update graph if doing so does not introduce any cycles.
*
* @param newData The data to write to this table
Expand Down Expand Up @@ -125,7 +125,7 @@ default void validateDelete(Table tableToDelete) {
* This method will block until the rows are deleted. As a result, this method is not suitable for use from a
* {@link io.deephaven.engine.table.TableListener table listener} or any other
* {@link io.deephaven.engine.updategraph.NotificationQueue.Notification notification}-dispatched callback
* dispatched by this MutableInputTable's {@link io.deephaven.engine.updategraph.UpdateGraph update graph}. It may
* dispatched by this InputTable's {@link io.deephaven.engine.updategraph.UpdateGraph update graph}. It may
* be suitable to delete from another update graph if doing so does not introduce any cycles.
*
* @param table The rows to delete
Expand All @@ -142,7 +142,7 @@ default void delete(Table table) throws IOException {
* This method will block until the rows are deleted. As a result, this method is not suitable for use from a
* {@link io.deephaven.engine.table.TableListener table listener} or any other
* {@link io.deephaven.engine.updategraph.NotificationQueue.Notification notification}-dispatched callback
* dispatched by this MutableInputTable's {@link io.deephaven.engine.updategraph.UpdateGraph update graph}. It may
* dispatched by this InputTable's {@link io.deephaven.engine.updategraph.UpdateGraph update graph}. It may
* be suitable to delete from another update graph if doing so does not introduce any cycles.
*
* @param table Table containing the rows to delete
Expand Down Expand Up @@ -172,16 +172,16 @@ default void deleteAsync(Table table, RowSet rowSet, InputTableStatusListener li
}

/**
* Return a user-readable description of this MutableInputTable.
* Return a user-readable description of this InputTable.
*
* @return a description of this input table
*/
String getDescription();

/**
* Returns a Deephaven table that contains the current data for this MutableInputTable.
* Returns a Deephaven table that contains the current data for this InputTable.
*
* @return the current data in this MutableInputTable.
* @return the current data in this InputTable.
*/
Table getTable();

Expand All @@ -196,19 +196,19 @@ default boolean isKey(String columnName) {
}

/**
* Returns true if the specified column exists in this MutableInputTable.
* Returns true if the specified column exists in this InputTable.
*
* @param columnName the column to interrogate
* @return true if columnName exists in this MutableInputTable
* @return true if columnName exists in this InputTable
*/
default boolean hasColumn(String columnName) {
return getTableDefinition().getColumnNames().contains(columnName);
}

/**
* Queries whether this MutableInputTable is editable in the current context.
* Queries whether this InputTable is editable in the current context.
*
* @return true if this MutableInputTable may be edited, false otherwise TODO (deephaven/deephaven-core/issues/255):
* @return true if this InputTable may be edited, false otherwise TODO (deephaven/deephaven-core/issues/255):
* Add AuthContext and whatever else is appropriate
*/
boolean canEdit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import java.util.Random;

import static io.deephaven.engine.table.impl.util.TestKeyedArrayBackedMutableTable.handleDelayedRefresh;
import static io.deephaven.engine.table.impl.util.TestKeyedArrayBackedInputTable.handleDelayedRefresh;
import static io.deephaven.engine.testutil.TstUtils.*;
import static io.deephaven.engine.util.TableTools.*;

Expand Down Expand Up @@ -68,13 +68,13 @@ public void testNoSources() {
}

public void testMultipleSources() throws Exception {
final AppendOnlyArrayBackedMutableTable source1 = AppendOnlyArrayBackedMutableTable.make(TableDefinition.of(
final AppendOnlyArrayBackedInputTable source1 = AppendOnlyArrayBackedInputTable.make(TableDefinition.of(
ColumnDefinition.of("StringCol", Type.stringType())));
final BaseArrayBackedMutableTable.ArrayBackedMutableInputTable inputTable1 = source1.makeHandler();
final BaseArrayBackedInputTable.ArrayBackedInputTable inputTable1 = source1.makeHandler();

final AppendOnlyArrayBackedMutableTable source2 = AppendOnlyArrayBackedMutableTable.make(TableDefinition.of(
final AppendOnlyArrayBackedInputTable source2 = AppendOnlyArrayBackedInputTable.make(TableDefinition.of(
ColumnDefinition.of("IntCol", Type.intType())));
final BaseArrayBackedMutableTable.ArrayBackedMutableInputTable inputTable2 = source2.makeHandler();
final BaseArrayBackedInputTable.ArrayBackedInputTable inputTable2 = source2.makeHandler();

final Table functionBacked =
FunctionGeneratedTableFactory.create(() -> source1.lastBy().naturalJoin(source2, ""), source1, source2);
Expand Down
Loading