Skip to content

Pull data from a Hologres database for data enrichment

This topic describes how to use resource functions to pull data from a Hologres database for data enrichment.

Use the e_search_table_map function to enrich log data

  • Raw data

    • Hologres Sample data records in a table of a database
    product_idproduct_nameproduct_priceproduct_sales_numbersex
    2lipstick2882219girl
    5watch1399265boy
    6mac4200265boy
    3mouse202583boy
    1basketball353658boy
    4notebook95427girl
    • Sample log in a Logstore of Simple Log Service

      __source__:192.168.2.100
      __tag__:__client_ip__:192.168.1.100
      age:22
      name:xiaoli
      profession:students
      sex:girl
      
      __source__:192.168.2.200
      __tag__:__client_ip__:192.168.1.200
      age:21
      name:xiaoming
      profession:students
      sex:boy
  • Transformation rule Compare the sex field in the Logstore and the sex field in the Hologres database. Both fields match only when the sex values are the same.If both fields match, the value of the product_name field is pulled from the Hologres database and concatenated with the log data in the Logstore into new data.

    python
    e_search_table_map(
      res_rds_mysql(
        address="rds-host",
        username="mysql-username",
        password="yourpassword",
        database="yourdatabasename",
        table="yourtablename",
        refresh_interval=60,
        connector='pgsql'
      ),
      inpt="sex",
      output_fields="product_name",
      multi_match=True,
      multi_join=","
    )

    Note To ensure data security and network stability, we recommend that you access the Hologres database over a virtual private cloud (VPC).You can obtain the endpoint from the network configurations of the Hologres instance and use the endpoint to access a Hologres database over a VPC. After you obtain the endpoint, replace the value of the address field with the endpoint.

  • Transformation result

    __source__:192.168.2.100
    __tag__:__client_ip__:192.168.1.100
    __tag__:__receive_time__:1615518043
    __topic__:
    age:22
    name:xiaoli
    product_name:lipstick,notebook
    profession:students
    sex:girl
    
    __source__:192.168.2.200
    __tag__:__client_ip__:192.168.1.200
    __tag__:__receive_time__:1615518026
    __topic__:
    age:21
    name:xiaoming
    product_name:basketball,watch,mac,mouse
    profession:students
    sex:boy