|
4 | 4 | package io.deephaven.engine.table.impl;
|
5 | 5 |
|
6 | 6 | import io.deephaven.api.ColumnName;
|
| 7 | +import io.deephaven.api.agg.Aggregation; |
| 8 | +import io.deephaven.api.agg.spec.AggSpec; |
7 | 9 | import io.deephaven.chunk.WritableChunk;
|
8 | 10 | import io.deephaven.chunk.attributes.Values;
|
| 11 | +import io.deephaven.csv.CsvTools; |
| 12 | +import io.deephaven.csv.util.CsvReaderException; |
9 | 13 | import io.deephaven.engine.context.ExecutionContext;
|
10 | 14 | import io.deephaven.engine.rowset.RowSequence;
|
| 15 | +import io.deephaven.engine.rowset.RowSequenceFactory; |
11 | 16 | import io.deephaven.engine.rowset.RowSetFactory;
|
12 | 17 | import io.deephaven.engine.rowset.RowSetShiftData;
|
13 | 18 | import io.deephaven.engine.table.*;
|
|
20 | 25 | import io.deephaven.engine.table.impl.sources.chunkcolumnsource.ChunkColumnSource;
|
21 | 26 | import io.deephaven.engine.testutil.ControlledUpdateGraph;
|
22 | 27 | import io.deephaven.engine.testutil.junit4.EngineCleanup;
|
| 28 | +import io.deephaven.engine.util.TableTools; |
23 | 29 | import io.deephaven.test.types.OutOfBandTest;
|
24 | 30 |
|
| 31 | +import junit.framework.TestCase; |
25 | 32 | import org.jetbrains.annotations.NotNull;
|
26 | 33 | import org.jetbrains.annotations.Nullable;
|
27 | 34 | import org.junit.Rule;
|
28 | 35 | import org.junit.Test;
|
29 | 36 | import org.junit.experimental.categories.Category;
|
30 | 37 |
|
| 38 | +import java.io.ByteArrayInputStream; |
31 | 39 | import java.time.Instant;
|
32 | 40 | import java.util.Arrays;
|
33 | 41 | import java.util.BitSet;
|
|
44 | 52 | import static io.deephaven.engine.table.impl.sources.ReinterpretUtils.byteToBooleanSource;
|
45 | 53 | import static io.deephaven.engine.table.impl.sources.ReinterpretUtils.longToInstantSource;
|
46 | 54 | import static io.deephaven.engine.table.impl.sources.ReinterpretUtils.maybeConvertToPrimitiveChunkType;
|
47 |
| -import static io.deephaven.engine.testutil.TstUtils.addToTable; |
48 |
| -import static io.deephaven.engine.testutil.TstUtils.assertTableEquals; |
49 |
| -import static io.deephaven.engine.testutil.TstUtils.testRefreshingTable; |
50 |
| -import static io.deephaven.engine.util.TableTools.booleanCol; |
51 |
| -import static io.deephaven.engine.util.TableTools.byteCol; |
52 |
| -import static io.deephaven.engine.util.TableTools.intCol; |
53 |
| -import static io.deephaven.engine.util.TableTools.newTable; |
| 55 | +import static io.deephaven.engine.testutil.TstUtils.*; |
| 56 | +import static io.deephaven.engine.util.TableTools.*; |
54 | 57 | import static io.deephaven.util.QueryConstants.NULL_INT;
|
55 | 58 | import static org.assertj.core.api.Assertions.assertThat;
|
56 | 59 |
|
@@ -201,6 +204,62 @@ public void testTreeSnapshotSatisfaction() throws ExecutionException, Interrupte
|
201 | 204 | concurrentExecutor.shutdown();
|
202 | 205 | }
|
203 | 206 |
|
| 207 | + @Test |
| 208 | + public void testSortedExpandAll() throws CsvReaderException { |
| 209 | + final String data = "A,B,C,N\n" + |
| 210 | + "Apple,One,Alpha,1\n" + |
| 211 | + "Apple,One,Alpha,2\n" + |
| 212 | + "Apple,One,Bravo,3\n" + |
| 213 | + "Apple,One,Bravo,4\n" + |
| 214 | + "Apple,One,Bravo,5\n" + |
| 215 | + "Apple,One,Bravo,6\n" + |
| 216 | + "Banana,Two,Alpha,7\n" + |
| 217 | + "Banana,Two,Alpha,8\n" + |
| 218 | + "Banana,Two,Bravo,3\n" + |
| 219 | + "Banana,Two,Bravo,4\n" + |
| 220 | + "Banana,Three,Bravo,1\n" + |
| 221 | + "Banana,Three,Bravo,1\n"; |
| 222 | + |
| 223 | + final Table source = CsvTools.readCsv(new ByteArrayInputStream(data.getBytes())); |
| 224 | + |
| 225 | + TableTools.show(source); |
| 226 | + final RollupTable rollupTable = source.rollup(List.of(Aggregation.of(AggSpec.sum(), "N")), "A", "B", "C"); |
| 227 | + final RollupTable sortedRollup = rollupTable.withNodeOperations( |
| 228 | + rollupTable.makeNodeOperationsRecorder(RollupTable.NodeType.Aggregated).sortDescending("N")); |
| 229 | + |
| 230 | + final String[] arrayWithNull = new String[1]; |
| 231 | + final Table keyTable = newTable( |
| 232 | + intCol(rollupTable.getRowDepthColumn().name(), 0), |
| 233 | + stringCol("A", arrayWithNull), |
| 234 | + stringCol("B", arrayWithNull), |
| 235 | + stringCol("C", arrayWithNull), |
| 236 | + byteCol("Action", HierarchicalTable.KEY_TABLE_ACTION_EXPAND_ALL)); |
| 237 | + |
| 238 | + final SnapshotState ss = rollupTable.makeSnapshotState(); |
| 239 | + final Table snapshot = |
| 240 | + snapshotToTable(rollupTable, ss, keyTable, ColumnName.of("Action"), null, RowSetFactory.flat(30)); |
| 241 | + TableTools.showWithRowSet(snapshot); |
| 242 | + |
| 243 | + final SnapshotState ssSort = sortedRollup.makeSnapshotState(); |
| 244 | + |
| 245 | + final Table snapshotSort = |
| 246 | + snapshotToTable(sortedRollup, ssSort, keyTable, ColumnName.of("Action"), null, RowSetFactory.flat(30)); |
| 247 | + TableTools.showWithRowSet(snapshotSort); |
| 248 | + |
| 249 | + // first we know that the size of the tables must be the same |
| 250 | + TestCase.assertEquals(snapshot.size(), snapshotSort.size()); |
| 251 | + // and the first row must be the same, because it is the parent |
| 252 | + assertTableEquals(snapshot.head(1), snapshotSort.head(1)); |
| 253 | + // then we have six rows of banana, and that should be identical |
| 254 | + assertTableEquals(snapshot.slice(5, 11), snapshotSort.slice(1, 7)); |
| 255 | + // then we need to check on the apple rows, but those are not actually identical because of sorting |
| 256 | + Table appleExpected = snapshot.where("A=`Apple`").sortDescending("N"); |
| 257 | + assertTableEquals(appleExpected, snapshotSort.slice(7, 11)); |
| 258 | + |
| 259 | + freeSnapshotTableChunks(snapshot); |
| 260 | + freeSnapshotTableChunks(snapshotSort); |
| 261 | + } |
| 262 | + |
204 | 263 | @SuppressWarnings("SameParameterValue")
|
205 | 264 | private static Table snapshotToTable(
|
206 | 265 | @NotNull final HierarchicalTable<?> hierarchicalTable,
|
|
0 commit comments