Using a Dictionary in Graphs
The dictionary can be accessed in multiple ways by various components in the graph. It can be accessed from:
Readers and Writers. Both of them support dictionaries as their data source or data target via the File URL attribute.
The dictionary can also be accessed with CTL or Java source code in any component that defines a transformation (all Joiners, Map, Normalizer, etc).
Accessing Dictionary from Readers and Writers
To reference the dictionary parameter in the File URL attribute of a graph component, this attribute must have the following form: dict:
. Depending on the type of the parameter in the dictionary and the processingType
, the value can be used either as a name of the input or output file or it can be used directly as data source or data target (i.e. the data will be read from or written to the parameter directly).
Processing types are the following:
-
For Readers
discrete
This is the default processing type. It does not need to be specified.source
For information about URL in Readers, see also Reading from Dictionary.
-
For Writers
source
This processing type is preselected by default.stream
If no processing type is specified, stream is used.discrete
For information about URL in Writers, see also Writing to Dictionary.
For example, dict:mountains.csv
can be used as either input or output in a Reader or a Writer, respectively (in this case, the property type is writable.channel
).
Accessing Dictionary with Java
To access the values from the Java code embedded in the components of a graph, methods of the org.jetel.graph.Dictionary
class must be used.
For example, to get the value of the heightMin
property, you can use a code similar to the following snippet:
getGraph().getDictionary().getValue("heightMin")
In the snippet above, you can see that we need an instance of TransformationGraph
, which is usually available via the getGraph()
method in any place where you can put your own code. The current dictionary is then retrieved via the getDictionary()
method and finally the value of the property is read by calling the getValue(String)
method.
For further information, see the JavaDoc documentation.
Accessing Dictionary with CTL2
If the dictionary entries should be used in CTL2, they must be defined in the graph. Working with the entries uses standard CTL2 syntax. No dictionary functions are available in CTL2.
For more information, see Dictionary in CTL2.
Updated 12 months ago