This topic describes the syntax and parameters of table functions. This topic also provides examples on how to use the functions.

Functions

Category Function Description
Text to table tab_parse_csv Constructs a table from CSV-formatted text.
Table to dictionary tab_to_dict Constructs a dictionary from a table.

tab_parse_csv

The tab_parse_csv function constructs a table from CSV-formatted text.
  • Syntax

    tab_parse_csv(data, sep=',', quote='"', lstrip=True, headers=None, case_insensitive=True)
  • Parameters

    Parameter Type Required Description
    data String Yes The CSV-formatted text.
    sep String No The delimiter that is used in the CSV-formatted text. The default value is a comma (,).
    quote String No The quote. If a value contains the delimiter, you must use the quote to enclose the value. The default value is double quotation marks (").
    lstrip Bool No Specifies whether to remove the spaces from the left of each keyword. Default value: True.
    headers String\String List No The headings that are obtained after parsing. By default, the system retrieves the headings from the first line of the CSV-formatted text. If the first line does not store headings, you can configure this parameter to pass headings to the function. The value of this parameter can be a string or a string list.
    case_insensitive Bool No Specifies whether data is not case-sensitive when the system performs mapping. Default value: True.
  • Response

    The table that you construct is returned.

  • Examples

    • Example 1: Construct a table and map the value of a field to the table.
      • 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: Construct a table and map the values of multiple fields to the table.
      • 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: Construct a table and map the values of multiple fields to the table. The field names are different from the column names in the table. In the parentheses that include the source fields, the first field is a field of the raw log and the second field is a field of the table. In the parentheses that include the destination fields, the first field is a field of the table and the second field is a new field that is returned.
      • 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

tab_to_dict

The tab_to_dict function constructs a dictionary from a table.
  • Syntax

    tab_to_dict(table, key_field, value_field, key_join=",", value_join=",")
  • Parameters

    Parameter Type Required Description
    table Table Yes The data in the table.
    key_field String\String List Yes The columns that are used to construct keys in the dictionary. Connect multiple columns with the character specified by key_join.
    value_field String\String List Yes The columns that are used to construct values in the dictionary. Connect multiple columns with the character specified by value_join.
    key_join String No The string that is used to connect multiple columns. The columns are used as keys in the dictionary. The default value is a comma (,).
    value_join String No The string that is used to connect multiple columns. The columns are used as values in the dictionary. The default value is a comma (,).
  • Response

    The dictionary that you construct is returned.

  • 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