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

Add dropColumns as TableOperations / TableSpec #3474

Merged
merged 6 commits into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
6 changes: 0 additions & 6 deletions engine/api/src/main/java/io/deephaven/engine/table/Table.java
Original file line number Diff line number Diff line change
Expand Up @@ -303,12 +303,6 @@ public interface Table extends
@ConcurrentMethod
Table updateView(Selectable... newColumns);

@ConcurrentMethod
Table dropColumns(Collection<String> columnNames);

@ConcurrentMethod
Table dropColumns(String... columnNames);

@ConcurrentMethod
Table dropColumnFormats();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,6 @@ default Table updateView(Selectable... newColumns) {
return updateView(List.of(newColumns));
}

@Override
@ConcurrentMethod
@FinalDefault
default Table dropColumns(Collection<String> columnNames) {
return dropColumns(columnNames.toArray(CollectionUtil.ZERO_LENGTH_STRING_ARRAY));
}

@Override
@ConcurrentMethod
@FinalDefault
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import io.deephaven.engine.liveness.LivenessArtifact;
import io.deephaven.engine.table.MatchPair;
import io.deephaven.engine.table.PartitionedTable;
import io.deephaven.engine.table.PartitionedTable.Proxy;
import io.deephaven.engine.table.Table;
import io.deephaven.engine.table.TableDefinition;
import io.deephaven.engine.table.TableUpdate;
Expand Down Expand Up @@ -571,5 +572,10 @@ public PartitionedTable.Proxy ungroup(boolean nullFill, Collection<? extends Col
return basicTransform(ct -> ct.ungroup(nullFill, columnsToUngroup));
}

@Override
public PartitionedTable.Proxy dropColumns(String... columnNames) {
return basicTransform(ct -> ct.dropColumns(columnNames));
}

// endregion TableOperations Implementation
}
Original file line number Diff line number Diff line change
Expand Up @@ -553,18 +553,21 @@ public void testDropColumns() {
final List<ColumnSource<?>> colSources =
Arrays.asList(TableTools.objColSource("c", "e", "g"), colSource(2, 4, 6), colSource(1.0, 2.0, 3.0));
final Table table = newTable(3, colNames, colSources);
assertEquals(3, table.dropColumns().getColumnSources().size());
assertEquals(3, table.dropColumns(Collections.emptyList()).getColumnSources().size());
Collection<? extends ColumnSource<?>> columnSourcesAfterDrop = table.getColumnSources();
ColumnSource<?>[] columnsAfterDrop =
columnSourcesAfterDrop.toArray(ColumnSource.ZERO_LENGTH_COLUMN_SOURCE_ARRAY);
Collection<? extends ColumnSource<?>> columnSources = table.dropColumns().getColumnSources();
Collection<? extends ColumnSource<?>> columnSources =
table.dropColumns(Collections.emptyList()).getColumnSources();
ColumnSource<?>[] columns = columnSources.toArray(ColumnSource.ZERO_LENGTH_COLUMN_SOURCE_ARRAY);
assertSame(columns[0], columnsAfterDrop[0]);
assertSame(columns[1], columnsAfterDrop[1]);
assertSame(columns[2], columnsAfterDrop[2]);
assertSame(table.getColumnSource("String"), table.dropColumns().getColumnSource("String"));
assertSame(table.getColumnSource("Int"), table.dropColumns().getColumnSource("Int"));
assertSame(table.getColumnSource("Double"), table.dropColumns().getColumnSource("Double"));
assertSame(table.getColumnSource("String"),
table.dropColumns(Collections.emptyList()).getColumnSource("String"));
assertSame(table.getColumnSource("Int"), table.dropColumns(Collections.emptyList()).getColumnSource("Int"));
assertSame(table.getColumnSource("Double"),
table.dropColumns(Collections.emptyList()).getColumnSource("Double"));

assertEquals(2, table.dropColumns("Int").getColumnSources().size());
columnSourcesAfterDrop = table.dropColumns("Int").getColumnSources();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import io.deephaven.proto.backplane.grpc.CreateInputTableRequest.InputTableKind.InMemoryAppendOnly;
import io.deephaven.proto.backplane.grpc.CreateInputTableRequest.InputTableKind.InMemoryKeyBacked;
import io.deephaven.proto.backplane.grpc.CrossJoinTablesRequest;
import io.deephaven.proto.backplane.grpc.DropColumnsRequest;
import io.deephaven.proto.backplane.grpc.EmptyTableRequest;
import io.deephaven.proto.backplane.grpc.ExactJoinTablesRequest;
import io.deephaven.proto.backplane.grpc.FetchTableRequest;
Expand Down Expand Up @@ -73,6 +74,7 @@
import io.deephaven.qst.table.AsOfJoinTable;
import io.deephaven.qst.table.Clock.Visitor;
import io.deephaven.qst.table.ClockSystem;
import io.deephaven.qst.table.DropColumnsTable;
import io.deephaven.qst.table.EmptyTable;
import io.deephaven.qst.table.ExactJoinTable;
import io.deephaven.qst.table.HeadTable;
Expand Down Expand Up @@ -505,6 +507,17 @@ public void visit(UngroupTable ungroupTable) {
out = op(Builder::setUngroup, request);
}

@Override
public void visit(DropColumnsTable dropColumnsTable) {
final DropColumnsRequest.Builder request = DropColumnsRequest.newBuilder()
.setResultId(ticket)
.setSourceId(ref(dropColumnsTable.parent()));
for (ColumnName dropColumn : dropColumnsTable.dropColumns()) {
request.addColumnNames(dropColumn.name());
}
out = op(Builder::setDropColumns, request);
}

private SelectOrUpdateRequest selectOrUpdate(SingleParentTable x,
Collection<Selectable> columns) {
SelectOrUpdateRequest.Builder builder =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.deephaven.qst.table.AggregateAllTable;
import io.deephaven.qst.table.AggregateTable;
import io.deephaven.qst.table.AsOfJoinTable;
import io.deephaven.qst.table.DropColumnsTable;
import io.deephaven.qst.table.EmptyTable;
import io.deephaven.qst.table.ExactJoinTable;
import io.deephaven.qst.table.HeadTable;
Expand Down Expand Up @@ -198,6 +199,13 @@ public void visit(UngroupTable ungroupTable) {
sb.append("])");
}

@Override
public void visit(DropColumnsTable dropColumnsTable) {
sb.append("dropColumns([");
append(Strings::of, dropColumnsTable.dropColumns(), sb);
sb.append("])");
}

private void join(String name, Join j) {
sb.append(name).append("([");
append(Strings::of, j.matches(), sb);
Expand Down
7 changes: 7 additions & 0 deletions qst/src/main/java/io/deephaven/qst/TableAdapterImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.deephaven.qst.table.AggregateAllTable;
import io.deephaven.qst.table.AggregateTable;
import io.deephaven.qst.table.AsOfJoinTable;
import io.deephaven.qst.table.DropColumnsTable;
import io.deephaven.qst.table.EmptyTable;
import io.deephaven.qst.table.ExactJoinTable;
import io.deephaven.qst.table.HeadTable;
Expand Down Expand Up @@ -309,6 +310,12 @@ public void visit(UngroupTable ungroupTable) {
.ungroup(ungroupTable.nullFill(), ungroupTable.ungroupColumns()));
}

@Override
public void visit(DropColumnsTable dropColumnsTable) {
addOp(dropColumnsTable,
parentOps(dropColumnsTable).dropColumns(dropColumnsTable.dropColumns().toArray(new ColumnName[0])));
}

private final class OutputTable implements Output<TOPS, TABLE> {
private final TABLE table;

Expand Down
50 changes: 50 additions & 0 deletions qst/src/main/java/io/deephaven/qst/table/DropColumnsTable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* Copyright (c) 2016-2022 Deephaven Data Labs and Patent Pending
*/
package io.deephaven.qst.table;

import io.deephaven.annotations.NodeStyle;
import io.deephaven.api.ColumnName;
import org.immutables.value.Value.Check;
import org.immutables.value.Value.Default;
import org.immutables.value.Value.Immutable;

import java.util.List;

@Immutable
@NodeStyle
public abstract class DropColumnsTable extends TableBase implements SingleParentTable {

public static Builder builder() {
return ImmutableDropColumnsTable.builder();
}

public abstract TableSpec parent();

public abstract List<ColumnName> dropColumns();

@Override
public final <V extends Visitor> V walk(V visitor) {
visitor.visit(this);
return visitor;
}

@Check
final void checkNonEmpty() {
if (dropColumns().isEmpty()) {
throw new IllegalArgumentException("Expected dropColumns() to be non-empty");
}
}
devinrsmith marked this conversation as resolved.
Show resolved Hide resolved

public interface Builder {
Builder parent(TableSpec parent);

Builder addDropColumns(ColumnName element);

Builder addDropColumns(ColumnName... elements);

Builder addAllDropColumns(Iterable<? extends ColumnName> elements);

DropColumnsTable build();
}
}
5 changes: 5 additions & 0 deletions qst/src/main/java/io/deephaven/qst/table/ParentsVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,11 @@ public void visit(UngroupTable ungroupTable) {
out = single(ungroupTable);
}

@Override
public void visit(DropColumnsTable dropColumnsTable) {
out = single(dropColumnsTable);
}

private static class Search {

private final Predicate<TableSpec> excludePaths;
Expand Down
25 changes: 25 additions & 0 deletions qst/src/main/java/io/deephaven/qst/table/TableBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,31 @@ public final UngroupTable ungroup(boolean nullFill, Collection<? extends ColumnN
.build();
}

@Override
public final DropColumnsTable dropColumns(String... columnNames) {
final DropColumnsTable.Builder builder = DropColumnsTable.builder()
.parent(this);
for (String columnName : columnNames) {
builder.addDropColumns(ColumnName.of(columnName));
}
return builder.build();
}

@Override
public final DropColumnsTable dropColumns(Collection<String> columnNames) {
final DropColumnsTable.Builder builder = DropColumnsTable.builder()
.parent(this);
for (String columnName : columnNames) {
builder.addDropColumns(ColumnName.of(columnName));
}
return builder.build();
}

@Override
public final DropColumnsTable dropColumns(ColumnName... columnNames) {
return DropColumnsTable.builder().parent(this).addDropColumns(columnNames).build();
}

@Override
public final <V extends TableSchema.Visitor> V walk(V visitor) {
visitor.visit(this);
Expand Down
2 changes: 2 additions & 0 deletions qst/src/main/java/io/deephaven/qst/table/TableSpec.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,5 +157,7 @@ interface Visitor {
void visit(UpdateByTable updateByTable);

void visit(UngroupTable ungroupTable);

void visit(DropColumnsTable dropColumnsTable);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,9 @@ public void visit(UpdateByTable updateByTable) {
public void visit(UngroupTable ungroupTable) {
accept(ungroupTable);
}

@Override
public void visit(DropColumnsTable dropColumnsTable) {
accept(dropColumnsTable);
}
}
2 changes: 1 addition & 1 deletion qst/src/main/java/io/deephaven/qst/table/TimeTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ final void checkTimeout() {
}
}

interface Builder {
public interface Builder {
Builder clock(Clock clock);

Builder interval(Duration interval);
Expand Down
2 changes: 1 addition & 1 deletion qst/src/main/java/io/deephaven/qst/table/UngroupTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public final <V extends Visitor> V walk(V visitor) {
return visitor;
}

interface Builder {
public interface Builder {
Builder parent(TableSpec parent);

Builder addUngroupColumns(ColumnName element);
Expand Down
27 changes: 27 additions & 0 deletions table-api/src/main/java/io/deephaven/api/TableOperations.java
Original file line number Diff line number Diff line change
Expand Up @@ -1300,4 +1300,31 @@ TOPS updateBy(UpdateByControl control, Collection<? extends UpdateByOperation> o
TOPS ungroup(boolean nullFill, Collection<? extends ColumnName> columnsToUngroup);

// -------------------------------------------------------------------------------------------

/**
* Drop the {@code columnNames} from {@code this} table.
*
* @param columnNames the columns to drop
* @return the table
*/
TOPS dropColumns(String... columnNames);

/**
* Drop the {@code columnNames} from {@code this} table.
*
* @param columnNames the columns to drop
* @return the table
*/
TOPS dropColumns(Collection<String> columnNames);

/**
* Drop the {@code columnNames} from {@code this} table.
*
* @param columnNames the columns to drop
* @return the table
*/
TOPS dropColumns(ColumnName... columnNames);
rcaudy marked this conversation as resolved.
Show resolved Hide resolved

// -------------------------------------------------------------------------------------------

}
Original file line number Diff line number Diff line change
Expand Up @@ -685,4 +685,19 @@ public final TOPS_1 ungroup(boolean nullFill, String... columnsToUngroup) {
public final TOPS_1 ungroup(boolean nullFill, Collection<? extends ColumnName> columnsToUngroup) {
return adapt(delegate.ungroup(nullFill, columnsToUngroup));
}

@Override
public final TOPS_1 dropColumns(String... columnNames) {
return adapt(delegate.dropColumns(columnNames));
}

@Override
public final TOPS_1 dropColumns(Collection<String> columnNames) {
return adapt(delegate.dropColumns(columnNames));
}

@Override
public final TOPS_1 dropColumns(ColumnName... columnNames) {
return adapt(delegate.dropColumns(columnNames));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,20 @@ default TOPS wavgBy(String weightColumn, Collection<String> groupByColumns) {

// -------------------------------------------------------------------------------------------

@Override
@ConcurrentMethod
default TOPS dropColumns(Collection<String> columnNames) {
return dropColumns(columnNames.toArray(new String[0]));
}

@Override
@ConcurrentMethod
default TOPS dropColumns(ColumnName... columnNames) {
return dropColumns(Arrays.stream(columnNames).map(ColumnName::name).toArray(String[]::new));
}

// -------------------------------------------------------------------------------------------

static Collection<String> splitToCollection(String string) {
return string.trim().isEmpty() ? Collections.emptyList()
: Arrays.stream(string.split(",")).map(String::trim).filter(s -> !s.isEmpty())
Expand Down