Table Functions
This section describes table functions, including their syntax, parameters, and usage examples.
Function List
|
Function |
Description |
|---|---|
|
Creates a table from a CSV file. |
|
|
Creates a dictionary from a table. |
tab_parse_csv
This function creates a table from a CSV file.
- Function format
tab_parse_csv(data, sep=',', quote='"', lstrip=True, headers=None, case_insensitive=True, primary_keys=None)
- Parameter description
Parameter
Type
Mandatory
Description
data
String
No
Text format. Generally, the CSV format is used.
sep
String
No
Delimiter. In CSV format, the default delimiter is commas (,).
quote
String
No
Quote character. If the value contains a delimiter, use quote characters to wrap it. The default quote character is the double quotation mark (").
lstrip
Boolean
No
Whether to delete the space at the beginning of each keyword. The default value is True.
headers
String or string list
No
Parsed domain information. By default, the first line is extracted. If the first line is data, this parameter needs to be transferred.
case_insensitive
Boolean
No
Whether the case is insensitive. The default value is True.
primary_keys
String or string list
No
Primary key in the data.
If this parameter is set and the mapping enrichment function is used, the fields in the field parameter of the mapping enrichment function must align with the specified primary keys. For details about the mapping enrichment function, see Mapping and Enrichment Functions.
- Returned result
The table mapped based on the CSV file.
- Function example
- Directly build a table and map a field value.
- Test data
{ "city": "nanjing" } - Processing rule
e_table_map( tab_parse_csv("province,city,pop,gdp\nshanghai,shanghai,2000,1000\njiangsu,nanjing,800,500"), "city", "province" ) - Processing result
city: nanjing province: jiangsu
- Test data
- Directly build a table and map multiple field values.
- Test data
{ "city": "nanjing", "province": "jiangsu" } - Processing rule
e_table_map( tab_parse_csv("province,city,pop,gdp\nshanghai,shanghai,2000,1000\njiangsu,nanjing,800,500"), ["province", "city"], ["pop", "gdp"] ) - Processing result
city: nanjing province: jiangsu gdp: 500 pop: 800
- Test data
- If the mapping of multiple fields is different from the table column name, the first field in the source field brackets denotes the source field, and the second denotes the table field. In the target field brackets, the first field denotes the table field, and the second denotes the new field.
- Test data
{ "city": "nanjing", "province": "jiangsu" } - Processing 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")] ) - Processing result
city: nanjing province: jiangsu GDP: 500 population: 800
- Test data
- Directly build a table and map a field value.
tab_to_dict
This function creates a dictionary from a table.
- Function format
tab_to_dict(table, key_field, value_field, key_join=",", value_join=",")
- Parameter description
Parameter
Type
Mandatory
Description
table
table
Yes
Table information.
key_field
String or string list
Yes
Table column used to construct dictionary keywords. Multiple columns need to be combined using key_join.
value_field
String or string list
Yes
Table column used to construct dictionary values. Multiple columns need to be combined using value_join.
key_join
String
No
Connection string for concatenating multiple columns of dictionary keywords. The default value is a comma (,).
value_join
String
No
Connection string for concatenating multiple columns of dictionary values. The default value is a comma (,).
- Returned result
The dictionary mapped based on the table.
- Function example
- Directly build a table and map a field value.
- Test data
{ "k1": "v1", "city": "nj" } - Processing rule
e_dict_map( tab_to_dict(tab_parse_csv("city,pop\nsh,2000\nnj,800"), "city", "pop"), "city", "popu", ) - Processing result
k1: v1 city: nj popu: 800
- Test data
- Directly build a table and map multiple field values.
- Test data
{ "k1": "v1", "city": "js,nj" } - Processing rule
e_dict_map( tab_to_dict( tab_parse_csv("province,city,pop\nsh,sh,2000\njs,nj,800"), ["province", "city"], "pop" ), "city", "popu" ) - Processing result
k1: v1 city: js,nj popu: 800
- Test data
- Directly build a table and map a field value.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot