2424import java .util .Map ;
2525import java .util .Set ;
2626import java .util .stream .Collectors ;
27+ import java .util .stream .Stream ;
2728
2829/**
2930 * Tools for creating a new ShiftedColumn(s) for a given input table and a source column(s)
@@ -43,10 +44,7 @@ private ShiftedColumnOperation() {}
4344 public static Table addShiftedColumns (
4445 final @ NotNull Table source ,
4546 final @ NotNull ShiftedColumnDefinition ... shifted ) {
46- final String shiftedName = Arrays .stream (shifted )
47- .map (Object ::toString )
48- .collect (Collectors .joining ("," ));
49- final String nuggetName = "addShiftedColumns ( " + shiftedName + ") " ;
47+ final String nuggetName = "addShiftedColumns(" + friendlyShiftDescription (Arrays .stream (shifted )) + ")" ;
5048 return getShiftedColumnsUsingNugget (nuggetName , source ,
5149 new LinkedHashSet <>(Arrays .stream (shifted ).collect (Collectors .toList ())));
5250 }
@@ -61,15 +59,21 @@ public static Table addShiftedColumns(
6159 public static Table addShiftedColumns (
6260 final @ NotNull Table source ,
6361 final @ NotNull Set <ShiftedColumnDefinition > shifted ) {
64- final String shiftedName = shifted .stream ()
65- .map (Object ::toString )
66- .collect (Collectors .joining ("," ));
67- final String nuggetName = "addShiftedColumns ( " + shiftedName + ") " ;
62+ final String nuggetName = "addShiftedColumns(" + friendlyShiftDescription (shifted .stream ()) + ")" ;
6863 return getShiftedColumnsUsingNugget (nuggetName , source , shifted );
6964 }
7065
66+ private static String friendlyShiftDescription (@ NotNull Stream <ShiftedColumnDefinition > shifted ) {
67+ final Map <Long , List <ShiftedColumnDefinition >> byShiftAmount = shifted
68+ .collect (Collectors .groupingBy (ShiftedColumnDefinition ::getShiftAmount , LinkedHashMap ::new ,
69+ Collectors .toList ()));
70+ return byShiftAmount .entrySet ().stream ().map (e -> "["
71+ + e .getValue ().stream ().map (ShiftedColumnDefinition ::getColumnName ).collect (Collectors .joining (", " ))
72+ + "], " + e .getKey ()).collect (Collectors .joining ("," ));
73+ }
74+
7175 /**
72- * Delegates to {@link ShiftedColumnOperation#getShiftedColumns(Table, Set)} using QueryPerformanceRecorder.
76+ * Delegates to {@link ShiftedColumnOperation#getShiftedColumns(Table, Set, String )} using QueryPerformanceRecorder.
7377 *
7478 * @param source the source table, used to create new table with the shifted column
7579 * @param shifted the shifted column definition(s) that define the operation
@@ -82,7 +86,7 @@ private static Table getShiftedColumnsUsingNugget(
8286 final @ NotNull Table source ,
8387 final @ NotNull Set <ShiftedColumnDefinition > shifted ) {
8488 return QueryPerformanceRecorder .withNugget (nuggetName , source .sizeForInstrumentation (),
85- () -> getShiftedColumns (source , shifted ));
89+ () -> getShiftedColumns (source , shifted , nuggetName ));
8690 }
8791
8892 /**
@@ -91,13 +95,15 @@ private static Table getShiftedColumnsUsingNugget(
9195 *
9296 * @param source the source table, used to create new table with the shifted column
9397 * @param shifted the shifted column definition(s) that define the operation
98+ * @param listenerDescription the description to use for the listener
9499 * @return a new Table that has all columns from input table plus additional shifted column(s) created from the
95100 * provided definition(s)
96101 */
97102 @ NotNull
98103 private static Table getShiftedColumns (
99104 final @ NotNull Table source ,
100- final @ NotNull Set <ShiftedColumnDefinition > shifted ) {
105+ final @ NotNull Set <ShiftedColumnDefinition > shifted ,
106+ final @ NotNull String listenerDescription ) {
101107
102108 final Map <String , ColumnSource <?>> columnSourceMap = new LinkedHashMap <>(source .getColumnSourceMap ());
103109 final Map <String , Set <String >> sourceToShiftModColSetMap = new LinkedHashMap <>();
@@ -146,7 +152,7 @@ private static Table getShiftedColumns(
146152 source .getDefinition ().getColumnNamesArray (), resultTableMCSs .toArray (ModifiedColumnSet []::new ));
147153
148154 if (source .isRefreshing ()) {
149- final BaseTable .ListenerImpl listener = new BaseTable .ListenerImpl ("propagateUpdates" , source , result ) {
155+ final BaseTable .ListenerImpl listener = new BaseTable .ListenerImpl (listenerDescription , source , result ) {
150156 @ Override
151157 public void onUpdate (TableUpdate upstream ) {
152158 final TableUpdateImpl downstream = TableUpdateImpl .copy (upstream , downstreamColumnSet );
0 commit comments