Hive Automate supports a variety of number formulas. Formulas in Hive Automate are whitelisted Ruby methods, and therefore not all Ruby methods are supported. Syntax and functionality for these formulas are generally unchanged. Take note that most formulas will return an error and stop the job if it tries to operate on nulls (expressed as 'nil' in Ruby), except for present?, presence and blank?.

You can refer to the syntax and sample uses of these commands by clicking the links below:


Arithmetic operations

In the cases of arithmetic operations, whether the values are of integer types or decimal (float) types are important. Formulas will always stick to the types given as input, and the returned result will be of the most precise type.

For example:

  • If integer values are provided, an integer value will be returned.

  • If float values are provided, a float value will be returned.

  • If both float and integer values are provided, a float value will be returned, as that is more precise.


The add (+) operator

This operator allows the addition of operands on either side. This section talks about number arithmetic. Date arithmetic is possible as well.

Sample Usage

Formula

Result

Type

4 + 7

11

Fixnum

4.0 + 7

11.0

Float

4.0 + 7.0

11.0

Float


The subtract (-) operator

This operator subtracts the right hand operand from the left hand operand. This section talks about number arithmetic. Date arithmetic is possible as well.

Sample Usage

Formula

Result

Type

4 - 7

-3

Fixnum

4.0 - 7

-3.0

Float

4.0 - 7.0

-3.0

Float


The multiply (*) operator

This operator multiplies the operands on either side.

Sample Usage

Formula

Result

Type

4 * 7

28

Fixnum

4.0 * 7

28.0

Float

4.0 * 7.0

28.0

Float


The divide (/) operator

Divides left hand operand by right hand operand.

Sample Usage

Formula

Result

Type

4 / 7

0

Fixnum

4.0 / 7

0.571428...

Float

7 / 4

1

Fixnum

7 / 4.0

1.75

Float

7.0 / 4

1.75

Float

7.0 / 4.0

1.75

Float


The exponential (**) operator

Left hand operand to the power of the right hand operand.

Sample Usage

Formula

Result

Type

5**3

125

Fixnum

4**1.5

8.0

Float

4.0**2

16.0

Float

3**-1

"1/3"

Rational

8**(3**-1)

2.0

Float

7**-1.6

0.044447...

Float


The modulo (%) operator

Divides left hand operand by right hand operand and returns the remainder.

Sample Usage

Formula

Result

Type

4 % 7

4

Fixnum

4.0 % 7

4.0

Float

4 % 7.0

4.0

Float

7 % 4

3

Fixnum

7.0 % 4.0

3.0

Float


abs

Returns the absolute (positive) value of a number.

Syntax

number.abs

  • number - An input integer or float.

Sample usage

Formula

Result

45.abs

45

-45.abs

45

45.67.abs

45.67

-45.67.abs

45.67


round

Rounds off a numerical value. This formula returns a value with a specified number of decimal places.

Syntax

number.round(offset)

  • number - An input integer or float.

  • offset - (optional) The number of decimal places to return, you can provide negative values. If not specified, this formula will return the number with no decimal places.

Sample usage

Formula

Result

1234.567.round

1235

1234.567.round(2)

1234.57

1234.567.round(-2)

1230


blank?

This formula checks the input and returns true if it is non a value number or if it is null.

Syntax

Input.blank?

  • Input - An input datapill. It can be a string, number, date, or datetime datatype.

Sample usage

Formula

Result

123.blank?

false

0.blank?

false

nil.blank?

true

"".blank?

true


even?

Checks the integer input and returns true if it is an even number.

Syntax

integer.even?

  • integer - An input integer.

Sample usage

Formula

Result

123.even?

false

1234.even?

true


odd?

Checks the integer input and returns true if it is an odd number.

Syntax

integer.odd?

  • integer - An input integer.

Sample usage

Formula

Result

123.odd?

true

1234.odd?

false


present?

This formula will check the input and if there is a value present, it will return true. If the input is nil, boolean false, an empty string, or an empty list, the formula will return false.

Syntax

Input.present?

  • Input - An input datapill. It can be a string, number, date, or list datatype.

Sample usage

Formula

Result

"Any Value".present?

true

123.present?

true

0.present?

true

"2017-04-02T12:30:00.000000-07:00".present?

true

nil.present?

false

"".present?

false

[].present?

false


presence

Returns the data if it exists, returns nil if it does not.

Syntax

Input.presence

  • Input - An input datapill. It can be a string, number, date, or datetime datatype.

Sample usage

Formula

Result

nil.presence

nil

"".presence

nil

"Any Value".presence

"Any Value"

45.0.presence

45.0

0.presence

0


ceil

Rounds the input number to the next greater integer or float. You can specify the precision of the decimal digits.

Syntax

number.ceil(precision)

  • number - An input integer or float.

  • precision - (optional) The number of decimal places to return, you can provide negative values. If not specified, this formula will return the number with no decimal places.

Sample usage

Formula

Result

1234.567.ceil

1235

-1234.567.ceil

-1234

1234.567.ceil(2)

1234.57

1234.567.ceil(-2)

1300


floor

Rounds the input number to the next smaller integer or float. You can specify the precision of the decimal digits.

Syntax

number.floor(precision)

  • number - An input integer or float.

  • precision - (optional) The number of decimal places to return, you can provide negative values. If not specified, this formula will return the number with no decimal places.

Sample usage

Formula

Result

1234.567.floor

1234

-1234.567.floor

-1235

1234.567.floor(2)

1234.56

1234.567.floor(-2)

1200


to_f

Converts data to a float (number) datatype.

Syntax

Input.to_f

  • Input - A number input data. You can use a string datatype or an integer datatype.

Sample usage

Formula

Result

45.to_f

45.0

-45.to_f

-45.0

"45.67".to_f

45.67

"Automate".to_f

0

How it works

This formula checks whether the input contains any numbers, if no numbers are found, it returns 0. If the number does not have a decimal point, .0 will be added the number.


to_i

Converts data to an integer (whole number) datatype.

Syntax

Input.to_i

  • Input - A number input data. You can use a string datatype or a float datatype.

Sample usage

Formula

Result

45.43.to_i

45

-45.43.to_i

-45

"123".to_i

123

"Automate".to_i

0

How it works

This formula checks whether the input contains any numbers, if no numbers are found, it returns 0. If the number has a decimal point, everything after the decimal will be omitted.


to_s

Converts data to a string (text) datatype.

Syntax

Input.to_s

  • Input - Any input data. You can use number, array, object, or datetime datatypes.

Sample usage

Formula

Result

-45.67.to_s

"-45.67"

"123".to_s

"123"

[1,2,3].to_s

"[1,2,3]"

{key: "Automate"}.to_s

"{:key=>"Automate"}""

"2020-06-05T17:13:27.000000-07:00".to_s

"2020-06-05T17:13:27.000000-07:00"

"2020-06-05T17:13:27.000000-07:00".to_s(:short)

"05 Jun 17:13"

"2020-06-05T17:13:27.000000-07:00".to_s(:long)

"June 05, 2020 17:13"


to_currency

Formats integers/numbers to a currency-style.

Syntax

Input.to_currency

  • Input - Any input string.

Sample usage

Formula

Description

Result

"345.60".to_currency

Adds default currency symbol "$"

"$345.60"


to_phone

Converts string or number to a formatted phone number (user-defined).

Syntax

Input.to_phone

  • Input - Any input string or number.

Sample usage

Formula

Result

"5551234".to_phone

555-1234

1235551234.to_phone

123-555-1234

1235551234.to_phone(area_code: true)

(123) 555-1234

1235551234.to_phone(delimiter: " ")

123 555 1234

1235551234.to_phone(area_code: true, extension: 555)

(123) 555-1234 x 555

1235551234.to_phone(country_code: 1)

+1-123-555-1234

"123a456".to_phone

123a456

Did this answer your question?