Syntax, parameters, and examples of table functions.
Functions
|
Category |
Function |
Description |
|
Text to table |
Builds a table from text in CSV format. |
|
|
Table to dictionary |
Builds a dictionary from a table. |
tab_parse_csv
Builds a table from text in CSV format.
-
Syntax
tab_parse_csv( data, sep=',', quote='"', lstrip=True, headers=None, case_insensitive=True, primary_keys=None, ) -
Parameters
Parameter name
Data type
Required
Description
data
String
Yes
The text in CSV format.
sep
String
No
The separator for the CSV format. The default value is a comma (,).
quote
String
No
The quote character. If a value contains the separator, you must enclose the value in quotes. The default value is a double quotation mark (").
lstrip
Boolean
No
Whether to remove leading spaces from each keyword. Default value: True.
headers
String, String List
No
The header names for each parsed field. By default, headers are read from the first row. If the first row contains data instead of headers, specify the headers by using this parameter.
case_insensitive
Boolean
No
Whether matching is case-insensitive. Default value: True.
primary_keys
String, String List
No
The primary key in the data.
After you set this parameter, if you use a mapping enrichment function, the field specified in the field parameter of the function must be the same as this primary key. For more information about mapping enrichment functions, see Mapping enrichment functions.
-
Response
Returns the mapped table data.
-
Examples
-
Example 1: Build a table and map the value of a field.
-
Raw log
city:nanjing -
Transformation rule
e_table_map( tab_parse_csv( "province,city,pop,gdp\nshanghai,shanghai,2000,1000\njiangsu,nanjing,800,500" ), "city", "province", ) -
Result
city:nanjing province:jiangsu
-
-
Example 2: Build a table and map the values of multiple fields.
-
Raw log
city:nanjing province:jiangsu -
Transformation rule
e_table_map( tab_parse_csv( "province,city,pop,gdp\nshanghai,shanghai,2000,1000\njiangsu,nanjing,800,500" ), ["province", "city"], ["pop", "gdp"], ) -
Result
city:nanjing gdp:500 pop:800 province:jiangsu
-
-
Example 3: Map fields with names that differ from the table column names. In each source field tuple, the first element is the source field and the second is the table field. In each destination field tuple, the first element is the table field and the second is the new field.
-
Raw log
city:nanjing province:jiangsu -
Transformation rule
e_table_map( tab_parse_csv( "prov,city,pop,gdp\nshanghai,shanghai,2000,1000\njiangsu,nanjing,800,500" ), [("province", "prov"), "city"], [("pop", "population"), ("gdp", "GDP")], ) -
Result
GDP:500 city:nanjing population:800 province:jiangsu
-
-
Example 4: Map fields with names that differ from the table column names, with primary keys specified. In each source field tuple, the first element is the source field and the second is the table field. In each destination field tuple, the first element is the table field and the second is the new field. The table field in the source field tuple must match the primary key.
-
Raw log
city:nanjing province:jiangsu -
Transformation rule
e_table_map( tab_parse_csv( "prov,city,pop,gdp\nshanghai,shanghai,2000,1000\njiangsu,nanjing,800,500", primary_keys=["prov", "city"], ), [("province", "prov"), "city"], [("pop", "population"), ("gdp", "GDP")], ) -
Result
GDP:500 city:nanjing population:800 province:jiangsu
-
-
tab_to_dict
Builds a dictionary from a table.
-
Syntax
tab_to_dict(table, key_field, value_field, key_join=",", value_join=",") -
Parameters
Parameter Name
Data type
Required
Description
table
table
Yes
The table data.
key_field
String, String List
Yes
The table column or columns used to build the dictionary keys. If you specify multiple columns, they are joined by the string specified in
key_join.value_field
String, String List
Yes
The table column or columns used to build the dictionary values. If you specify multiple columns, they are joined by the string specified in
value_join.key_join
String
No
The string used to join multiple columns to form a key. The default value is a comma (,).
value_join
String
No
The string used to join multiple columns to form a value. The default value is a comma (,).
-
Response
Returns the mapped dictionary data.
-
Examples
-
Example 1
-
Raw log
k1:v1 city:nj -
Transformation rule
e_dict_map( tab_to_dict(tab_parse_csv("city,pop\nsh,2000\nnj,800"), "city", "pop"), "city", "popu", ) -
Result
k1:v1 city:nj popu:800
-
-
Example 2
-
Raw log
k1:v1 city:js,nj -
Transformation rule
e_dict_map( tab_to_dict( tab_parse_csv("province,city,pop\nsh,sh,2000\njs,nj,800"), ["province", "city"], "pop", ), "city", "popu", ) -
Result
k1:v1 city:js,nj popu:800
-
-