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 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
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 @@ -1106,10 +1106,7 @@ public Table flatten() {
}

if (isFlat()) {
if (isRefreshing()) {
manageWithCurrentScope();
}
return this;
return prepareReturnThis();
}

return getResult(new FlattenOperation(this));
Expand Down Expand Up @@ -1342,10 +1339,7 @@ private void propagateGrouping(SelectColumn[] selectColumns, QueryTable resultTa
@Override
public Table view(final Collection<? extends Selectable> viewColumns) {
if (viewColumns == null || viewColumns.isEmpty()) {
if (isRefreshing()) {
manageWithCurrentScope();
}
return this;
return prepareReturnThis();
}
return viewOrUpdateView(Flavor.View, SelectColumn.from(viewColumns));
}
Expand All @@ -1357,10 +1351,7 @@ public Table updateView(final Collection<? extends Selectable> viewColumns) {

private Table viewOrUpdateView(Flavor flavor, final SelectColumn... viewColumns) {
if (viewColumns == null || viewColumns.length == 0) {
if (isRefreshing()) {
manageWithCurrentScope();
}
return this;
return prepareReturnThis();
}

final String humanReadablePrefix = flavor.toString();
Expand Down Expand Up @@ -1477,6 +1468,9 @@ public Table lazyUpdate(final Collection<? extends Selectable> newColumns) {

@Override
public Table dropColumns(String... columnNames) {
if (columnNames == null || columnNames.length == 0) {
return prepareReturnThis();
}
return memoizeResult(MemoizedOperationKey.dropColumns(columnNames), () -> QueryPerformanceRecorder
.withNugget("dropColumns(" + Arrays.toString(columnNames) + ")", sizeForInstrumentation(), () -> {
final Mutable<Table> result = new MutableObject<>();
Expand Down Expand Up @@ -1547,10 +1541,7 @@ public Table renameColumns(MatchPair... pairs) {
return QueryPerformanceRecorder.withNugget("renameColumns(" + matchString(pairs) + ")",
sizeForInstrumentation(), () -> {
if (pairs == null || pairs.length == 0) {
if (isRefreshing()) {
manageWithCurrentScope();
}
return this;
return prepareReturnThis();
}

checkInitiateOperation();
Expand Down Expand Up @@ -2199,18 +2190,12 @@ static ColumnSource<?> maybeTransformToPrimitive(final ColumnSource<?> columnSou
public Table sort(Collection<SortColumn> columnsToSortBy) {
final SortPair[] sortPairs = SortPair.from(columnsToSortBy);
if (sortPairs.length == 0) {
if (isRefreshing()) {
manageWithCurrentScope();
}
return this;
return prepareReturnThis();
} else if (sortPairs.length == 1) {
final String columnName = sortPairs[0].getColumn();
final SortingOrder order = sortPairs[0].getOrder();
if (SortedColumnsAttribute.isSortedBy(this, columnName, order)) {
if (isRefreshing()) {
manageWithCurrentScope();
}
return this;
return prepareReturnThis();
}
}

Expand Down Expand Up @@ -2263,10 +2248,7 @@ public Table ungroup(boolean nullFill, Collection<? extends ColumnName> columnsT
return QueryPerformanceRecorder.withNugget("ungroup(" + Arrays.toString(columnsToUngroupBy) + ")",
sizeForInstrumentation(), () -> {
if (columnsToUngroupBy.length == 0) {
if (isRefreshing()) {
manageWithCurrentScope();
}
return this;
return prepareReturnThis();
}

checkInitiateOperation();
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
43 changes: 43 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,43 @@
/**
* 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;
}

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
30 changes: 30 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,34 @@ TOPS updateBy(UpdateByControl control, Collection<? extends UpdateByOperation> o
TOPS ungroup(boolean nullFill, Collection<? extends ColumnName> columnsToUngroup);

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

/**
* Creates a new table without the {@code columnNames} from {@code this}.
*
* @param columnNames the columns to drop
* @return the table
*/
@ConcurrentMethod
TOPS dropColumns(String... columnNames);

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

/**
* Creates a new table without the {@code columnNames} from {@code this}.
*
* @param columnNames the columns to drop
* @return the table
*/
@ConcurrentMethod
TOPS dropColumns(ColumnName... columnNames);

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

}
Loading