Skip to content

Commit ecd3441

Browse files
committed
Aggregate-dedicated editors: AggregateGroupByEditor, AggregateAggregationsEditor
1 parent 163c197 commit ecd3441

6 files changed

Lines changed: 36 additions & 83 deletions

File tree

components-api/src/main/java/pl/touk/nussknacker/engine/api/editor/EditorType.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,7 @@ public enum EditorType {
1717
TYPED_TABULAR_DATA_EDITOR,
1818
SPEL_EDITOR,
1919
JSON_TEMPLATE_EDITOR,
20-
MULTI_SELECT_EDITOR
20+
MULTI_SELECT_EDITOR,
21+
AGGREGATE_GROUP_BY_EDITOR,
22+
AGGREGATE_AGGREGATIONS_EDITOR
2123
}

components-api/src/main/scala/pl/touk/nussknacker/engine/api/definition/ParameterEditor.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,7 @@ case object CronParameterEditor extends ParameterEditor with StaticParameterEdit
100100
@JsonCodec case class MultiSelectEditor(possibleValues: List[MultiSelectFixedValue])
101101
extends ParameterEditor
102102
with StaticParameterEditor
103+
104+
case object AggregateGroupByEditor extends ParameterEditor
105+
106+
case object AggregateAggregationsEditor extends ParameterEditor

engine/flink/components/base-unbounded/src/main/scala/pl/touk/nussknacker/engine/flink/util/transformer/aggregate/sampleTransformers.scala

Lines changed: 10 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -30,32 +30,13 @@ object sampleTransformers {
3030

3131
@MethodToInvoke(returnType = classOf[AnyRef])
3232
def execute(
33-
@ParamName("groupBy") groupBy: LazyParameter[AnyRef],
33+
@ParamName("groupBy") @Editor(EditorType.AGGREGATE_GROUP_BY_EDITOR) groupBy: LazyParameter[AnyRef],
3434
@ParamName("aggregator")
3535
@AdditionalVariables(Array(new AdditionalVariable(name = "AGG", clazz = classOf[AggregateHelper])))
36-
@Editor(
37-
`type` = EditorType.FIXED_VALUES_EDITOR,
38-
possibleValues = Array(
39-
new LabeledExpression(label = "First", expression = "#AGG.first"),
40-
new LabeledExpression(label = "Last", expression = "#AGG.last"),
41-
new LabeledExpression(label = "Min", expression = "#AGG.min"),
42-
new LabeledExpression(label = "Max", expression = "#AGG.max"),
43-
new LabeledExpression(label = "Sum", expression = "#AGG.sum"),
44-
new LabeledExpression(label = "Average", expression = "#AGG.average"),
45-
new LabeledExpression(label = "CountWhen", expression = "#AGG.countWhen"),
46-
new LabeledExpression(label = "StddevPop", expression = "#AGG.stddevPop"),
47-
new LabeledExpression(label = "StddevSamp", expression = "#AGG.stddevSamp"),
48-
new LabeledExpression(label = "VarPop", expression = "#AGG.varPop"),
49-
new LabeledExpression(label = "VarSamp", expression = "#AGG.varSamp"),
50-
new LabeledExpression(label = "Median", expression = "#AGG.median"),
51-
new LabeledExpression(label = "List", expression = "#AGG.list"),
52-
new LabeledExpression(label = "Set", expression = "#AGG.set"),
53-
new LabeledExpression(label = "ApproximateSetCardinality", expression = "#AGG.approxCardinality")
54-
)
55-
)
56-
@Editor(`type` = EditorType.SPEL_EDITOR)
36+
@Editor(`type` = EditorType.AGGREGATE_AGGREGATIONS_EDITOR)
37+
@DefaultValue("#AGG.map({count: #AGG.sum})")
5738
aggregator: Aggregator,
58-
@ParamName("aggregateBy") aggregateBy: LazyParameter[AnyRef],
39+
@ParamName("aggregateBy") @Editor(EditorType.AGGREGATE_AGGREGATIONS_EDITOR) aggregateBy: LazyParameter[AnyRef],
5940
@ParamName("windowLength") @DefaultValue("T(java.time.Duration).parse('PT1H')") length: java.time.Duration,
6041
@ParamName("emitWhenEventLeft") @DefaultValue("false") emitWhenEventLeft: Boolean,
6142
@OutputVariableName variableName: String
@@ -90,30 +71,11 @@ object sampleTransformers {
9071

9172
@MethodToInvoke(returnType = classOf[AnyRef])
9273
def execute(
93-
@ParamName("groupBy") groupBy: LazyParameter[AnyRef],
74+
@ParamName("groupBy") @Editor(EditorType.AGGREGATE_GROUP_BY_EDITOR) groupBy: LazyParameter[AnyRef],
9475
@ParamName("aggregator")
9576
@AdditionalVariables(Array(new AdditionalVariable(name = "AGG", clazz = classOf[AggregateHelper])))
96-
@Editor(
97-
`type` = EditorType.FIXED_VALUES_EDITOR,
98-
possibleValues = Array(
99-
new LabeledExpression(label = "First", expression = "#AGG.first"),
100-
new LabeledExpression(label = "Last", expression = "#AGG.last"),
101-
new LabeledExpression(label = "Min", expression = "#AGG.min"),
102-
new LabeledExpression(label = "Max", expression = "#AGG.max"),
103-
new LabeledExpression(label = "Sum", expression = "#AGG.sum"),
104-
new LabeledExpression(label = "Average", expression = "#AGG.average"),
105-
new LabeledExpression(label = "CountWhen", expression = "#AGG.countWhen"),
106-
new LabeledExpression(label = "StddevPop", expression = "#AGG.stddevPop"),
107-
new LabeledExpression(label = "StddevSamp", expression = "#AGG.stddevSamp"),
108-
new LabeledExpression(label = "VarPop", expression = "#AGG.varPop"),
109-
new LabeledExpression(label = "VarSamp", expression = "#AGG.varSamp"),
110-
new LabeledExpression(label = "Median", expression = "#AGG.median"),
111-
new LabeledExpression(label = "List", expression = "#AGG.list"),
112-
new LabeledExpression(label = "Set", expression = "#AGG.set"),
113-
new LabeledExpression(label = "ApproximateSetCardinality", expression = "#AGG.approxCardinality")
114-
)
115-
)
116-
@Editor(`type` = EditorType.SPEL_EDITOR)
77+
@Editor(`type` = EditorType.AGGREGATE_AGGREGATIONS_EDITOR)
78+
@DefaultValue("#AGG.map({count: #AGG.sum})")
11779
aggregator: Aggregator,
11880
@ParamName("aggregateBy") aggregateBy: LazyParameter[AnyRef],
11981
@ParamName("windowLength") @DefaultValue("T(java.time.Duration).parse('PT1H')") length: java.time.Duration,
@@ -154,30 +116,11 @@ object sampleTransformers {
154116

155117
@MethodToInvoke(returnType = classOf[AnyRef])
156118
def execute(
157-
@ParamName("groupBy") groupBy: LazyParameter[AnyRef],
119+
@ParamName("groupBy") @Editor(EditorType.AGGREGATE_GROUP_BY_EDITOR) groupBy: LazyParameter[AnyRef],
158120
@ParamName("aggregator")
159121
@AdditionalVariables(Array(new AdditionalVariable(name = "AGG", clazz = classOf[AggregateHelper])))
160-
@Editor(
161-
`type` = EditorType.FIXED_VALUES_EDITOR,
162-
possibleValues = Array(
163-
new LabeledExpression(label = "First", expression = "#AGG.first"),
164-
new LabeledExpression(label = "Last", expression = "#AGG.last"),
165-
new LabeledExpression(label = "Min", expression = "#AGG.min"),
166-
new LabeledExpression(label = "Max", expression = "#AGG.max"),
167-
new LabeledExpression(label = "Sum", expression = "#AGG.sum"),
168-
new LabeledExpression(label = "Average", expression = "#AGG.average"),
169-
new LabeledExpression(label = "CountWhen", expression = "#AGG.countWhen"),
170-
new LabeledExpression(label = "StddevPop", expression = "#AGG.stddevPop"),
171-
new LabeledExpression(label = "StddevSamp", expression = "#AGG.stddevSamp"),
172-
new LabeledExpression(label = "VarPop", expression = "#AGG.varPop"),
173-
new LabeledExpression(label = "VarSamp", expression = "#AGG.varSamp"),
174-
new LabeledExpression(label = "Median", expression = "#AGG.median"),
175-
new LabeledExpression(label = "List", expression = "#AGG.list"),
176-
new LabeledExpression(label = "Set", expression = "#AGG.set"),
177-
new LabeledExpression(label = "ApproximateSetCardinality", expression = "#AGG.approxCardinality")
178-
)
179-
)
180-
@Editor(`type` = EditorType.SPEL_EDITOR)
122+
@Editor(`type` = EditorType.AGGREGATE_AGGREGATIONS_EDITOR)
123+
@DefaultValue("#AGG.map({count: #AGG.sum})")
181124
aggregator: Aggregator,
182125
@ParamName("aggregateBy") aggregateBy: LazyParameter[AnyRef],
183126
@ParamName("endSessionCondition") @DefaultValue("false") endSessionCondition: LazyParameter[java.lang.Boolean],

scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/component/parameter/defaults/EditorBasedLanguageDeterminer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ object EditorBasedLanguageDeterminer {
1111
case BoolParameterEditor | DateParameterEditor | TimeParameterEditor | DateTimeParameterEditor |
1212
TextareaParameterEditor | DurationParameterEditor(_) | PeriodParameterEditor(_) | CronParameterEditor |
1313
FixedValuesParameterEditor(_) | FixedValuesWithIconParameterEditor(_) |
14-
FixedValuesWithRadioParameterEditor(_) =>
14+
FixedValuesWithRadioParameterEditor(_) | AggregateGroupByEditor | AggregateAggregationsEditor =>
1515
Expression.Language.Spel
1616
case JsonParameterEditor | MultiSelectEditor(_) => Expression.Language.Json
1717
case JsonTemplateParameterEditor => Expression.Language.JsonTemplate

scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/component/parameter/defaults/EditorPossibleValuesBasedDefaultValueDeterminer.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ protected object EditorPossibleValuesBasedDefaultValueDeterminer extends Paramet
4747
case DateTimeParameterEditor => None
4848
case BoolParameterEditor => None
4949
case TextareaParameterEditor => None
50+
case AggregateGroupByEditor => None
51+
case AggregateAggregationsEditor => None
5052
}
5153

5254
}

scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/component/parameter/editor/EditorExtractor.scala

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,22 @@ object EditorExtractor {
4444
.map(value => FixedExpressionValue(value.expression(), value.label()))
4545
.toList
4646
)
47-
case EditorType.DATE_EDITOR => DateParameterEditor
48-
case EditorType.TIME_EDITOR => TimeParameterEditor
49-
case EditorType.DATE_TIME_EDITOR => DateTimeParameterEditor
50-
case EditorType.DURATION_EDITOR => DurationParameterEditor(editor.timeRangeComponents().toList)
51-
case EditorType.PERIOD_EDITOR => PeriodParameterEditor(editor.timeRangeComponents().toList)
52-
case EditorType.CRON_EDITOR => CronParameterEditor
53-
case EditorType.TEXTAREA_EDITOR => TextareaParameterEditor
54-
case EditorType.JSON_EDITOR => JsonParameterEditor
55-
case EditorType.SQL_EDITOR => SqlParameterEditor
56-
case EditorType.SPEL_TEMPLATE_EDITOR => SpelTemplateParameterEditor
57-
case EditorType.DICT_EDITOR => DictParameterEditor(editor.dictId())
58-
case EditorType.TYPED_TABULAR_DATA_EDITOR => TabularTypedDataEditor
59-
case EditorType.SPEL_EDITOR => SpelParameterEditor
60-
case EditorType.JSON_TEMPLATE_EDITOR => JsonTemplateParameterEditor
47+
case EditorType.DATE_EDITOR => DateParameterEditor
48+
case EditorType.TIME_EDITOR => TimeParameterEditor
49+
case EditorType.DATE_TIME_EDITOR => DateTimeParameterEditor
50+
case EditorType.DURATION_EDITOR => DurationParameterEditor(editor.timeRangeComponents().toList)
51+
case EditorType.PERIOD_EDITOR => PeriodParameterEditor(editor.timeRangeComponents().toList)
52+
case EditorType.CRON_EDITOR => CronParameterEditor
53+
case EditorType.TEXTAREA_EDITOR => TextareaParameterEditor
54+
case EditorType.JSON_EDITOR => JsonParameterEditor
55+
case EditorType.SQL_EDITOR => SqlParameterEditor
56+
case EditorType.SPEL_TEMPLATE_EDITOR => SpelTemplateParameterEditor
57+
case EditorType.DICT_EDITOR => DictParameterEditor(editor.dictId())
58+
case EditorType.TYPED_TABULAR_DATA_EDITOR => TabularTypedDataEditor
59+
case EditorType.SPEL_EDITOR => SpelParameterEditor
60+
case EditorType.AGGREGATE_GROUP_BY_EDITOR => AggregateGroupByEditor
61+
case EditorType.AGGREGATE_AGGREGATIONS_EDITOR => AggregateAggregationsEditor
62+
case EditorType.JSON_TEMPLATE_EDITOR => JsonTemplateParameterEditor
6163
case EditorType.MULTI_SELECT_EDITOR =>
6264
MultiSelectEditor(
6365
editor

0 commit comments

Comments
 (0)