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

Fix bugs in moveColumns and renameColumns #5193

Merged
merged 8 commits into from
Feb 29, 2024
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
26 changes: 13 additions & 13 deletions engine/api/src/main/java/io/deephaven/engine/table/Table.java
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,8 @@ public interface Table extends
Table dropColumnFormats();

/**
* Produce a new table with the specified columns renamed using the syntax {@code "NewColumnName=OldColumnName"}.
* Produce a new table with the specified columns renamed using the specified {@link Pair pairs}. The renames are
nbauernfeind marked this conversation as resolved.
Show resolved Hide resolved
* simultaneous, and unordered, enabling direct swaps between column names.
nbauernfeind marked this conversation as resolved.
Show resolved Hide resolved
* <p>
* {@link IllegalArgumentException} will be thrown:
* <ul>
Expand All @@ -343,6 +344,7 @@ public interface Table extends

/**
* Produce a new table with the specified columns renamed using the syntax {@code "NewColumnName=OldColumnName"}.
* The renames are simultaneous, and unordered, enabling direct swaps between column names.
nbauernfeind marked this conversation as resolved.
Show resolved Hide resolved
* <p>
* {@link IllegalArgumentException} will be thrown:
* <ul>
Expand All @@ -357,13 +359,8 @@ public interface Table extends
Table renameColumns(String... pairs);

/**
* Produce a new table with the specified columns renamed using the provided function.
* <p>
* {@link IllegalArgumentException} will be thrown:
* <ul>
* <li>if a source column is used more than once</li>
* <li>if a destination column is used more than once</li>
* </ul>
* Produce a new table with the specified columns renamed using the provided function. The renames are simultaneous,
* and unordered, enabling direct swaps between column names.
nbauernfeind marked this conversation as resolved.
Show resolved Hide resolved
nbauernfeind marked this conversation as resolved.
Show resolved Hide resolved
*
* @param renameFunction The function to apply to each column name
* @return The new table, with the columns renamed
Expand All @@ -381,8 +378,9 @@ public interface Table extends
Table formatColumnWhere(String columnName, String condition, String formula);

/**
* Produce a new table with the specified columns moved to the rightmost position. Columns can be renamed with the
* usual syntax, i.e. {@code "NewColumnName=OldColumnName")}.
* Produce a new table with the specified columns moved to the leftmost position. Columns can be renamed with the
* usual syntax, i.e. {@code "NewColumnName=OldColumnName")}. The renames are simultaneous, and unordered, enabling
* direct swaps between column names.
nbauernfeind marked this conversation as resolved.
Show resolved Hide resolved
* <p>
* {@link IllegalArgumentException} will be thrown:
* <ul>
Expand All @@ -398,7 +396,8 @@ public interface Table extends

/**
* Produce a new table with the specified columns moved to the rightmost position. Columns can be renamed with the
* usual syntax, i.e. {@code "NewColumnName=OldColumnName")}.
* usual syntax, i.e. {@code "NewColumnName=OldColumnName")}. The renames are simultaneous, and unordered, enabling
nbauernfeind marked this conversation as resolved.
Show resolved Hide resolved
* direct swaps between column names.
* <p>
* {@link IllegalArgumentException} will be thrown:
* <ul>
Expand All @@ -413,8 +412,9 @@ public interface Table extends
Table moveColumnsDown(String... columnsToMove);

/**
* Produce a new table with the specified columns moved to the rightmost position. Columns can be renamed with the
* usual syntax, i.e. {@code "NewColumnName=OldColumnName")}.
* Produce a new table with the specified columns moved to the specified {@code index}. Column indices begin at 0.
* Columns can be renamed with the usual syntax, i.e. {@code "NewColumnName=OldColumnName")}. The renames are
nbauernfeind marked this conversation as resolved.
Show resolved Hide resolved
* simultaneous, and unordered, enabling direct swaps between column names.
nbauernfeind marked this conversation as resolved.
Show resolved Hide resolved
* <p>
* {@link IllegalArgumentException} will be thrown:
* <ul>
Expand Down
20 changes: 14 additions & 6 deletions py/server/deephaven/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,10 +665,12 @@ def drop_columns(self, cols: Union[str, Sequence[str]]) -> Table:

def move_columns(self, idx: int, cols: Union[str, Sequence[str]]) -> Table:
"""The move_columns method creates a new table with specified columns moved to a specific column index value.
Columns may be renamed with the same semantics as rename_columns. The renames are simultaneous, and unordered,
nbauernfeind marked this conversation as resolved.
Show resolved Hide resolved
enabling direct swaps between column names. Specifying a source or destination more than once is prohibited.

Args:
idx (int): the column index where the specified columns will be moved in the new table.
cols (Union[str, Sequence[str]]) : the column name(s)
cols (Union[str, Sequence[str]]) : the column name(s) or the column rename expr(s) as "X = Y"

Returns:
a new table
Expand All @@ -684,10 +686,12 @@ def move_columns(self, idx: int, cols: Union[str, Sequence[str]]) -> Table:

def move_columns_down(self, cols: Union[str, Sequence[str]]) -> Table:
"""The move_columns_down method creates a new table with specified columns appearing last in order, to the far
right.
right. Columns may be renamed with the same semantics as rename_columns. The renames are simultaneous, and
nbauernfeind marked this conversation as resolved.
Show resolved Hide resolved
unordered, enabling direct swaps between column names. Specifying a source or destination more than once is
prohibited.

Args:
cols (Union[str, Sequence[str]]) : the column name(s)
cols (Union[str, Sequence[str]]) : the column name(s) or the column rename expr(s) as "X = Y"

Returns:
a new table
Expand All @@ -703,10 +707,12 @@ def move_columns_down(self, cols: Union[str, Sequence[str]]) -> Table:

def move_columns_up(self, cols: Union[str, Sequence[str]]) -> Table:
"""The move_columns_up method creates a new table with specified columns appearing first in order, to the far
left.
left. Columns may be renamed with the same semantics as rename_columns. The renames are simultaneous, and
nbauernfeind marked this conversation as resolved.
Show resolved Hide resolved
unordered, enabling direct swaps between column names. Specifying a source or destination more than once is
prohibited.

Args:
cols (Union[str, Sequence[str]]) : the column name(s)
cols (Union[str, Sequence[str]]) : the column name(s) or the column rename expr(s) as "X = Y"

Returns:
a new table
Expand All @@ -721,7 +727,9 @@ def move_columns_up(self, cols: Union[str, Sequence[str]]) -> Table:
raise DHError(e, "table move_columns_up operation failed.") from e

def rename_columns(self, cols: Union[str, Sequence[str]]) -> Table:
"""The rename_columns method creates a new table with the specified columns renamed.
"""The rename_columns method creates a new table with the specified columns renamed. The renames are
simultaneous, and unordered, enabling direct swaps between column names. Specifying a source or
nbauernfeind marked this conversation as resolved.
Show resolved Hide resolved
destination more than once is prohibited.

Args:
cols (Union[str, Sequence[str]]) : the column rename expr(s) as "X = Y"
Expand Down
Loading