Skip to content

Commit

Permalink
fix: Check for the getBaseTable API before calling it (#2168)
Browse files Browse the repository at this point in the history
- If it's not available, just fallback to the getKeyTable API (which we
were using before)
- Tested against deephaven-core 0.35.1
```
from deephaven import new_table

x = new_table({
    "Foo": [0, 1, 2, 0, 1, 2],
    "Bar": [4, 5, 6, 7, 8, 9]}
).partition_by(["Foo"])
```
  • Loading branch information
mofojed committed Jul 23, 2024
1 parent b741f4e commit a5cb947
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions packages/iris-grid/src/IrisGridPartitionedTableModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@ import MissingPartitionError, {
} from './MissingPartitionError';
import { PartitionedGridModelProvider } from './PartitionedGridModel';

type PartitionedTableWithBaseTable = DhType.PartitionedTable & {
getBaseTable: () => DhType.Table;
};

function isPartitionedTableWithBaseTable(
partitionedTable: DhType.PartitionedTable
): partitionedTable is PartitionedTableWithBaseTable {
return (
'getBaseTable' in partitionedTable &&
typeof partitionedTable.getBaseTable === 'function'
);
}

class IrisGridPartitionedTableModel
extends EmptyIrisGridModel
implements PartitionedGridModelProvider
Expand Down Expand Up @@ -80,8 +93,11 @@ class IrisGridPartitionedTableModel
}

async partitionBaseTable(): Promise<DhType.Table> {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return (this.partitionedTable as any).getBaseTable();
if (isPartitionedTableWithBaseTable(this.partitionedTable)) {
return this.partitionedTable.getBaseTable();
}
// Fallback to the key table if the base table API is not available
return this.partitionedTable.getKeyTable();
}

async partitionMergedTable(): Promise<DhType.Table> {
Expand Down

0 comments on commit a5cb947

Please sign in to comment.