Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Next »

Description

Converts a valid number string, a float number or a MAC address into an integer number. Note that float numbers are not rounded, so the result will be the integral part.

You can also extract an integer value from a json (json data type) using the Jq evaluation (jqeval) operation and convert it into integer type.

How does it work in the search window?

Select Create column in the search window toolbar, then select the To Int operation. You need to specify one argument:

Argument

Data type

String to convert / Number to convert / MAC to convert / Json to convert mandatory

string, float, mac, json

The data type of the values in the new column is integer.

Example 1

In the demo.ecommerce.data table, we want to divide the values of the bytesTransferred column by 2.5, and then transform the resulting float values into integer. First, use the Division (div, \) operation to get the results needed in a new column (BytesFloat). 

Then, add a new column using the To Int operation. The arguments needed are:

  • Number to convert BytesFloat column

Click Create column and you will see the following result:

Example 2

We have the following JSON string:

{"str": "hello", "int": 1, "float": 2.5, "boolean": true, "array": [1,2,3], "object": {"a": 5}}

And we want to extract the integer value in it in a new column and convert it to integer data type. To do it, the first step is transforming the string into a json data type column, and then using the Jq evaluation (jqeval) operation to extract the integer parts from the JSON objects.

Step 1: Transform the JSON string into json data type

We use the To json operation and enter the JSON string we want to use to get a column representing it in json data type.

Step 2: Extract the integer value from the JSON objects

Then, we use the Jq evaluation (jqeval) operation to extract the integer part of the JSON objects in a new column, in json data type. These are the required arguments:

  • jq -  Click the pencil icon and enter .int

  • json - json column

Step 3: Transform the integer values into integer data type

Finally, we use the To int operation to transform the integer representations in json data type into integer data type. 

Click Create column and you will see the following result:

How does it work in LINQ?

Use the operator select... as...  and add the operation syntax to create the new column. These are the valid formats of the To Int operation:

  • int(number_string)

  • int(float)

  • int(mac)

  • int(json_integer)

Example 1

You can copy the following LINQ script and try the first example explained above on the demo.ecommerce.data table. 

from demo.ecommerce.data
select bytesTransferred \ 2.5 as BytesFloat,
int(BytesFloat) as BytesInteger

Example 2

You can copy the following LINQ script and try the second example explained above on the demo.ecommerce.data table. 

from demo.ecommerce.data
select jsonparse("{\"str\": \"hello\", \"int\": 1, \"float\": 2.5, \"boolean\": true, \"array\": [1,2,3], \"object\": {\"a\": 5}}") as json
select jqeval(jqcompile(".int"), json) as jsonInt,
int(jsonInt) as Integer
  • No labels