Some event fields work like enums. For example, the GCReferenceStatistics event has a field called type that can have the values 'Soft reference', 'Weak reference', 'Phantom reference' and 'Final reference'. Creating separate events for each type was not reasonable. Another example is the ActiveSettings event, which has a field called name that can be "enabled", "threshold", "stackTrace", "period", "cutoff" and "throttle". There are many more examples of enum fields in today's events. Sometimes there is a need to create views or tables where each enum name becomes a column. This is currently done with syntax similar to this:
COLUMN 'Event Type', 'Enabled', 'Threshold',
'Stack Trace','Period','Cutoff', 'Throttle'
FORMAT none, missing:whitespace, missing:whitespace, missing:whitespace,
missing:whitespace, missing:whitespace, missing:whitespace
SELECT E.id, LAST(E.value), LAST(T.value),
LAST(S.value), LAST(P.value),
LAST(C.value), LAST(U.value)
FROM
ActiveSetting AS E,
ActiveSetting AS T,
ActiveSetting AS S,
ActiveSetting AS P,
ActiveSetting AS C,
ActiveSetting AS U
WHERE
E.name = 'enabled' AND
T.name = 'threshold' AND
S.name = 'stackTrace' AND
P.name = 'period' AND
C.name = 'cutoff' AND
U.name = 'throttle'
GROUP BY
id
ORDER BY
E.id
which results in something like this:
Event Type Enabled Threshold Stack Trace Period Cutoff Throttle
--------------------------------------- ------- --------- ----------- ---------- ------ --------
Allocation Requiring GC false true
Allocation in new TLAB false true
Allocation outside TLAB false true
Boolean Flag true beginChunk
...
The syntax is verbose and requires that all enum fields are known by the query. If a value is missing, that column will be empty for all rows. It would be better if that column was not shown at all. One idea is to introduce a new syntax that allows queries to create a column for each name. The new syntax could be:
COLUMN 'Event Type', '{name}'
FORMAT none, missing:whitespace
SELECT E.id, LAST(E.value) | name FROM ActiveSetting GROUP BY id ORDER BY E.id
The pipe character instructs the query evaluator to split values by name and create a separate column for each name. For column names, a placeholder can be used to fill in the value.
From an implementation point of view, a Map will be stored in the column for each row, and values will be added to it. This is not much different from the current SET aggregator function. Before the table is rendered, the maps are expanded to the number of unique names, and new columns are added with column names formatted by the placeholder. To give the JVM a chance to decide the order of the columns, a LinkedHashMap can be used.
The query can also be used with FORMs, and if there is a FORMAT specifier, it will apply to all expanded columns. If we want to handle casing in the column, an alternative would be to include it in the placeholder, for example, {Name}.
COLUMN 'Event Type', 'Enabled', 'Threshold',
'Stack Trace','Period','Cutoff', 'Throttle'
FORMAT none, missing:whitespace, missing:whitespace, missing:whitespace,
missing:whitespace, missing:whitespace, missing:whitespace
SELECT E.id, LAST(E.value), LAST(T.value),
LAST(S.value), LAST(P.value),
LAST(C.value), LAST(U.value)
FROM
ActiveSetting AS E,
ActiveSetting AS T,
ActiveSetting AS S,
ActiveSetting AS P,
ActiveSetting AS C,
ActiveSetting AS U
WHERE
E.name = 'enabled' AND
T.name = 'threshold' AND
S.name = 'stackTrace' AND
P.name = 'period' AND
C.name = 'cutoff' AND
U.name = 'throttle'
GROUP BY
id
ORDER BY
E.id
which results in something like this:
Event Type Enabled Threshold Stack Trace Period Cutoff Throttle
--------------------------------------- ------- --------- ----------- ---------- ------ --------
Allocation Requiring GC false true
Allocation in new TLAB false true
Allocation outside TLAB false true
Boolean Flag true beginChunk
...
The syntax is verbose and requires that all enum fields are known by the query. If a value is missing, that column will be empty for all rows. It would be better if that column was not shown at all. One idea is to introduce a new syntax that allows queries to create a column for each name. The new syntax could be:
COLUMN 'Event Type', '{name}'
FORMAT none, missing:whitespace
SELECT E.id, LAST(E.value) | name FROM ActiveSetting GROUP BY id ORDER BY E.id
The pipe character instructs the query evaluator to split values by name and create a separate column for each name. For column names, a placeholder can be used to fill in the value.
From an implementation point of view, a Map will be stored in the column for each row, and values will be added to it. This is not much different from the current SET aggregator function. Before the table is rendered, the maps are expanded to the number of unique names, and new columns are added with column names formatted by the placeholder. To give the JVM a chance to decide the order of the columns, a LinkedHashMap can be used.
The query can also be used with FORMs, and if there is a FORMAT specifier, it will apply to all expanded columns. If we want to handle casing in the column, an alternative would be to include it in the placeholder, for example, {Name}.