16
16
17
17
package org .polypheny .db .workflow .dag .activities ;
18
18
19
- import com .fasterxml .jackson .databind .JsonNode ;
20
19
import java .util .List ;
21
20
import java .util .Map ;
22
21
import java .util .Optional ;
23
- import java .util .UUID ;
24
22
import org .polypheny .db .algebra .type .AlgDataType ;
23
+ import org .polypheny .db .catalog .logistic .DataModel ;
25
24
import org .polypheny .db .workflow .dag .settings .SettingDef .SettingValue ;
25
+ import org .polypheny .db .workflow .dag .variables .WritableVariableStore ;
26
26
import org .polypheny .db .workflow .engine .execution .ExecutionContext ;
27
27
import org .polypheny .db .workflow .engine .storage .CheckpointReader ;
28
- import org .polypheny .db .workflow .models .ActivityConfigModel ;
29
- import org .polypheny .db .workflow .models .ActivityModel ;
30
- import org .polypheny .db .workflow .models .RenderModel ;
31
28
32
29
public interface Activity {
33
30
34
- String getType ();
35
-
36
- UUID getId ();
37
-
38
- ActivityState getState ();
39
-
40
- /**
41
- * Changes the state of this activity to the specified state.
42
- * After initialization, this should never be done by the activity itself.
43
- * The state is typically changed by the scheduler.
44
- *
45
- * @param state the new state of this activity
46
- */
47
- void setState ( ActivityState state );
48
-
49
31
/**
50
32
* This method computes the output tuple-types by considering (a preview of) input types and settings.
51
33
* If the input types or settings are not available or cannot be validated yet, the output type is set to an empty {@link Optional}
@@ -61,32 +43,39 @@ public interface Activity {
61
43
*/
62
44
List <Optional <AlgDataType >> previewOutTypes ( List <Optional <AlgDataType >> inTypes , Map <String , Optional <SettingValue >> settings ) throws ActivityException ;
63
45
64
- void execute ( List <CheckpointReader > inputs , Map <String , SettingValue > settings , ExecutionContext ctx ) throws Exception ; // default execution method. TODO: introduce execution context to track progress, abort, inputs, outputs...
65
-
66
- void updateSettings ( Map <String , JsonNode > settings );
67
-
68
- ActivityConfigModel getConfig ();
69
46
70
- void setConfig ( ActivityConfigModel config );
71
-
72
- RenderModel getRendering ();
47
+ /**
48
+ * This method is called just before execution starts and can be used to write variables based on input tuple types and settings.
49
+ * To be able to update variables while having access to the input data, the activity should instead implement {@link VariableWriter}.
50
+ *
51
+ * @param inTypes a list of {@link AlgDataType} representing the input tuple types.
52
+ * @param settings a map of setting keys to {@link SettingValue} representing the settings.
53
+ * @param variables a WritableVariableStore to be used for updating any variable values.
54
+ */
55
+ default void updateVariables ( List <AlgDataType > inTypes , Map <String , SettingValue > settings , WritableVariableStore variables ) {
56
+ }
73
57
74
- void setRendering ( RenderModel rendering );
58
+ // settings do NOT include values from the updateVariables step.
75
59
76
- ActivityDef getDef ();
60
+ /**
61
+ * Execute this activity.
62
+ * Any input CheckpointReaders are provided and expected to be closed by the caller.
63
+ * CheckpointWriters for any outputs are created from the ExecutionContext.
64
+ * The settings do not incorporate any changes to variables from {@code updateVariables()}.
65
+ *
66
+ * @param inputs a list of input readers for each input specified by the annotation.
67
+ * @param settings the instantiated setting values, according to the specified settings annotations
68
+ * @param ctx ExecutionContext to be used for creating checkpoints, updating progress and periodically checking for an abort
69
+ * @throws Exception in case the execution fails at any point
70
+ */
71
+ void execute ( List <CheckpointReader > inputs , Map <String , SettingValue > settings , ExecutionContext ctx ) throws Exception ; // default execution method
77
72
78
73
/**
79
74
* Reset any execution-specific state of this activity.
80
75
* It is guaranteed to be called before execution starts.
81
76
*/
82
77
void reset ();
83
78
84
- ActivityModel toModel ( boolean includeState );
85
-
86
- static Activity fromModel ( ActivityModel model ) {
87
- return ActivityRegistry .activityFromModel ( model );
88
- }
89
-
90
79
enum PortType {
91
80
ANY ,
92
81
REL ,
@@ -102,17 +91,21 @@ public boolean canReadFrom( PortType other ) {
102
91
public boolean canWriteTo ( PortType other ) {
103
92
return this == other || other == ANY ;
104
93
}
105
- }
106
94
107
95
108
- enum ActivityState {
109
- IDLE ,
110
- QUEUED ,
111
- EXECUTING ,
112
- SKIPPED , // => execution was aborted
113
- FAILED ,
114
- FINISHED ,
115
- SAVED // => finished + checkpoint created
96
+ /**
97
+ * Returns the corresponding DataModel enum.
98
+ * In case of ANY, DataModel.RELATIONAL is returned.
99
+ *
100
+ * @return the corresponding DataModel
101
+ */
102
+ public DataModel getDataModel () {
103
+ return switch ( this ) {
104
+ case ANY , REL -> DataModel .RELATIONAL ;
105
+ case DOC -> DataModel .DOCUMENT ;
106
+ case LPG -> DataModel .GRAPH ;
107
+ };
108
+ }
116
109
}
117
110
118
111
0 commit comments