Quick preview

更新时间:
复制 MD 格式

The quick preview feature lets you quickly verify data processing statements and check the output, free of charge. This topic describes how to use the feature and provides an example.

Prerequisites

Data has been collected. For more information, see data collection.

Procedure

  1. Log on to the Simple Log Service console.

  2. Navigate to the data transformation page.

    1. In the Projects section, click the project you want.

    2. On the Log Storage > Logstores tab, click the logstore you want.

    3. On the query and analysis page, click Data Transformation.

  3. In the upper-right corner of the page, select a time range.

    After you select a time range, make sure that logs appear on the Raw Logs tab.

  4. In the editor, enter the data processing statement.

    For more information about the syntax, see data processing syntax.

    Note

    The editor supports comments in data processing statements. You can use this feature to debug your code line by line.

  5. Preview the data.

    1. In the upper-right corner of the page, click Quick.

    2. At the bottom of the page, click Test Data.

    3. On the Test Data tab, enter test data.

      Test data includes base data and dimension table data.

      {
        "time_local": "25/May/2020:01:56:22",
        "user agent": "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.18 (KHTML, like Gecko) Chrome/11.xxx) Safari/534.18",
        "request:method": "GET",
        "remote user": "john"
      }
      • On the Data tab, set the test data.

        On the Raw Logs tab, find a log entry and click Add Test Data to add it as a sample. You can also enter test data manually.

        Note
        • The size of the test data for a single preview cannot exceed 1 MB.

        • Separate multiple test data entries with a blank line.

        • For field values that span multiple lines, enclose the value in triple backticks (```) to ensure it is parsed as a single field.

        • On the Data tab, test data can be in key-value (KV) or JSON format. In KV format, use a colon (:) to separate a key from its value.

        • Example 1: This sample contains two test entries. The first is in KV format and includes a multi-line traceback field. The second is in JSON format.

          time_local: 25/May/2020:01:56:22
          user agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.18 (KHTML, like Gecko) Chrome/11.0.661.0 Safari/534.18
          "request:method": GET
          ```    
          traceback: Traceback (most recent call last):
            File "traceback_print_exc.py", line 20, in <module>
              produce_exception()
            File "/home/user/code/test.py", line 16, in produce_exception
              produce_exception(recursion_level-1)
            File "/home/user/code/test.py", line 18, in produce_exception
              raise RuntimeError()
          RuntimeError
          ```
          {
            "time_local": "25/May/2020:01:56:22",
            "user agent": "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.18 (KHTML, like Gecko) Chrome/11.0.661.0 Safari/534.18",
            "request:method": "GET",
            "remote user": "john"
          }
        • Example 2: A single JSON array that contains three test data entries.

          [
            {
              "time_local": "25/May/2020:01:56:22",
              "user agent": "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.18 (KHTML, like Gecko) Chrome/11.0.661.0 Safari/534.18",
              "request:method": "GET",
              "remote user": "john"
            },
            {
              "time_local": "25/May/2020:01:56:22",
              "user agent": "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.18 (KHTML, like Gecko) Chrome/11.0.661.0 Safari/534.18",
              "request:method": "GET",
              "remote user": "john"
            },
            {
              "time_local": "25/May/2020:01:56:22",
              "user agent": "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.18 (KHTML, like Gecko) Chrome/11.0.661.0 Safari/534.18",
              "request:method": "GET",
              "remote user": "john"
            }
          ]
      • On the Dimension Table tab, set the test data.

        A dimension table provides sample data for resource functions, which enrich your logs with external data. This lets you test and debug these functions during the preview.

        Note

        In the Dimension Table tab, the data sample for test data must be in CSV format for the res_rds_mysql or res_log_LogStore_pull resource functions, but can be in CSV or JSON format for the res_oss_file or res_local resource functions.

        Example: The following sample contains two test data entries. The first is in CSV format, and the second is in JSON format.

        ip,country,province
        127.0.0.1,China,Shanghai
        192.168.0.0,China,Zhejiang
        [
          {
            "ip": "127.0.0.1",
            "country": "China",
            "province": "Shanghai"
          },
          {
            "ip": "192.168.0.0",
            "country": "China",
            "province": "Zhejiang"
          }
        ]
    4. Click Preview Data.

      Note

      Each preview returns up to 100 processing results.

      You can then view the results on the Transformation Results tab.

      • If data processing fails due to an invalid statement or incorrect permissions, follow the on-screen instructions to fix the issue.

      • If the processing results are as expected, you can create a data transformation job to apply the statement. For more information, see Create a data transformation job.

Quick preview example

  • Data processing statement

    In the editor, enter the following data processing statement.

    # e_set("insert_field", "test_value")
    e_table_map(
        res_rds_mysql(
            address="rm-uf6wjk5****.mysql.rds.aliyuncs.com",
            username="test_username",
            password="****",
            database="test_db",
            table="test_table",
        ),
        "ip",
        ["country", "province"],
    )
  • Test data

    On the Test Data > Data tab, enter the following content.

    {
        "id": "1001", 
        "ip": "127.0.0.1"
    }
  • Dimension table data

    On the Test Data > Dimension Table tab, enter the following content.

    ip,country,province
    127.0.0.1,China,Shanghai
    192.168.0.0,China,Zhejiang
  • Preview result

    Click Preview Data. On the Transformation Results tab, the output for target0 shows the following fields: id:1001, ip:127.0.0.1, country:China, and province:Shanghai. This indicates that the dimension table successfully enriched the log with the country and province fields. The summary of run results displays Total: 1, Succeeded: 1, Failed: 0.