////
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at
  http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
////
:documentationPath: /pipeline/transforms/
:language: en_US
:description: The Get Variables transform allows you to get the value of a variable and returns rows or adds values to existing input rows.
:openvar: ${
:closevar: }

= image:transforms/icons/getvariable.svg[Get variables transform Icon, role="image-doc-icon"] Get variables

[%noheader,cols="3a,1a", role="table-no-borders" ]
|===
|
== Description
The Get Variables transform allows you to get the value of a variable and create field(s) from it. You only need to use this transform if you need the variable value in a field.

TIP:  If you need to refer to a previous pipeline’s data row(s) fields, then use a Get rows from result transform.
|
== Supported Engines
[%noheader,cols="2,1a",frame=none, role="table-supported-engines"]
!===
!Hop Engine! image:check_mark.svg[Supported, 24]
!Spark! image:question_mark.svg[Maybe Supported, 24]
!Flink! image:question_mark.svg[Maybe Supported, 24]
!Dataflow! image:question_mark.svg[Maybe Supported, 24]
!===
|===

== Usage
Note that workflow/environment variables are set only once. A pipeline needs to start to get any new variables. A running or sequential or nested (nested pipelines are technically the same pipeline) pipeline can't fetch new variable values. A pipeline is considered started when a pipeline starts for every row in a pipeline executor.

Refer to parameters/variables using the syntax: {openvar}myVariable{closevar}, for example from a previous pipeline.

*Two ways to pass fields, parameters to variables downstream:*

Parameters must be unique per pipeline (case is not a differentiator). The pipeline executor parameter value takes precedence over the pipeline’s properties parameter value. The sending parameter value takes precedence over the default value of the receiving pipeline’s properties parameter.

  * Use a pipeline executor transform or a Repeat action:
    - Send: add fields on the Parameters tab (parameter name can be same as field name) to send.
    - Receive: in the immediate downstream pipeline, use Get variables to set variables/fields from Parameters using format: {openvar}myParam{closevar}
  * Edit any upstream pipeline’s properties:
    - Send: Add a parameter on the parameters tab of a pipeline’s properties (Edit pipeline icon), and optionally give it a default value. The parameter value can be set in a pipeline using various transforms.
    - Receive: in the immediate downstream pipeline, use Get variables to set variables/fields from Parameters using format: {openvar}myParam{closevar}


*Other:*

See also the Set Variables transform.

To convert the Variable into a data type other than String use Select Values - Meta Data tab.

To get system values, including command line arguments, use the Get System Info transform.

For example, in the variable column, you can specify: `{openvar}java.io.tmpdir{closevar}/hop/tempfile.txt` and it will be evaluated as `/tmp/hop/tempfile.txt` on Unix-like systems.

== Troubleshooting

You must always specify the data type or you will have errors like the following:

``2023/07/21 09:30:23 - REST client.0 - ERROR: Because of an error, this transform can't continue: 
  2023/07/21 09:30:23 - REST client.0 - TOKEN_URL None : Unknown type 0 specified.
  2023/07/21 09:30:23 - REST client.0 - ERROR: org.apache.hop.core.exception.HopValueException:``

== Options

[options="header"]
|===
|Option|Description
|Transform Name|The name of this transform as it appears in the pipeline workspace.
|Name|Name of the field.
|Variable a|Allows you to enter variables as complete strings to return rows or add values to input rows.
For example, you can specify: ${openvar}java.io.tmpdir{closevar}/hop/tempfile.txt and it will be expanded to /tmp/hop/tempfile.txt on Unix-like systems.

// CTRL-space snippet
include::../../snippets/variables/control-space.adoc[]

|Type|Specifies the field type: String, Date, Number, Boolean, Integer, BigNumber, Serializable, or Binary.
|Format|Allows you to specify the format of the field after the type has been determined.
|Length|For Number: Total number of significant figures in a number; For String: total length of string; For Date: length of printed output of the string (for example, entering 4 would only return the year).
|Precision|For Number: Number of floating point digits.
Not used for String, Date, or Boolean.
|Currency|Used to interpret numbers with currency symbols.
For example, $10,000.00 or E5.000,00.
|Decimal|Used to indicate whether to use a period (".") or comma (",") for number values.
|Group|Used to indicate whether to use a period (".") or comma (",") for number values.
|TrimType|Type trim this field before processing: select either none, left, right, or both (left and right).
|===

