Analyze full and incremental GitHub data with near real-time synchronization

更新时间:
复制 MD 格式

This topic describes how to use MaxCompute to synchronize GitHub data in near real-time and perform integrated analysis of full and incremental data.

Solution overview

This solution uses the GitHub Archive public dataset. It collects data for more than 10 event types from GitHub, such as projects and user behaviors, and writes the data to MaxCompute in near real-time to perform full and incremental updates. The solution uses various real-time data writing methods, including DataWorks data integration, Flink Change Data Capture (CDC), and Flink. With the resource isolation capabilities of MaxCompute Query Acceleration (MCQA) 2.0, you can create a batch processing resource group (QuotaA) and an interactive resource group (QuotaB). This setup lets you write and update full and incremental data in MaxCompute while performing interactive query and analysis. Additionally, you can use TopConsole and DataWorks Notebook to conduct in-depth analysis of real-time GitHub data changes from multiple dimensions, such as developers, projects, and programming languages.

Solution architecture and advantages

image.png

The preceding figure shows a design for a typical data analytics scenario. It can handle near real-time data writing for the current day and also update and query historical offline data.

  • Provides unified management of full and incremental data, including data aggregation, deduplication, and anti-fraud measures. It periodically writes back full data to the data warehouse detail (DWD) layer and updates the incremental materialized views (MVs) in the data warehouse service (DWS) and application data service (ADS) layers accordingly. Using Flink CDC and DataWorks real-time data integration, data is written to the incremental data tables of a Delta Table to enable incremental queries and updates.

  • Enables interactive data queries at the DWS/ADS layer. It supports auto-refresh for incremental MVs in DWS and ADS to ensure data timeliness. It also integrates with TopConsole and DataWorks for data querying and visualization.

  • Uses the MCQA 2.0 query acceleration engine to configure different quota groups under a resource isolation architecture. This supports both incremental data computing and interactive query and analysis scenarios.

Near real-time data warehouse: Delta Table incremental table format

For scenarios that involve both minute-level or hour-level near real-time data processing and large-scale batch processing, MaxCompute provides an integrated solution for data storage and computing. This solution is based on the unified table format of Delta Lake and supports integrated processing of full and incremental data in near real-time. It offers capabilities such as minute-level real-time Upsert writes and TimeTravel data flashback. Its core features include the following:

  • Supports near real-time writes with checkpoint intervals of less than one minute.

  • Supports near real-time SQL queries (Incremental Query). You can run queries within minutes after a write operation is complete.

  • Provides automatic management of data files through StorageService, AutoCompaction, and AutoSorting features.

Near real-time data warehouse: Incremental computing and Incremental Materialized Views (MVs)

The incremental computing feature of MaxCompute combines CDC and stream incremental query capabilities. This lets you build your own incremental data processing pipelines using custom SQL. Incremental MVs are an effective way to build incremental computing models. You only need to use declarative SQL to define the expected data results. By configuring different refresh parameters, you can specify the refresh rate or data freshness. The backend engine automatically performs incremental refreshes and internal optimizations to create a near real-time data analytics pipeline. Its core features include the following:

  • Declarative SQL.

  • Integration of incremental and full data, with unified SQL, storage, and computing.

  • Support for intelligent pipeline orchestration for incremental MVs.

  • Support for periodic tasks and stream processing features for incremental CDC applications.

  • Ensures data freshness through real-time or custom incremental data refreshes. The formula is: MV(T1) = delta(T0, T1) + MV(T0) .

Near real-time data warehouse: MCQA 2.0 query acceleration

The MCQA 2.0 query acceleration engine for MaxCompute is designed for business requirements that demand high performance, isolation, and stability. It builds a resource isolation management engine similar to a Virtual Warehouse to significantly improve interactive query performance. It supports exclusive computing resources at the tenant level and uses multi-threaded pipeline execution to fully utilize precisely managed, dedicated computing resources. It also supports full-link caching capabilities, all types of SQL jobs, screen display jobs, and DDL and DML jobs.

  • Supports building multiple quota groups for resource isolation in a single-tenant environment. It also supports interactive queries on these quota groups.

  • Supports group management for time-sharing resources.

  • Accelerates interactive query performance, doubling the performance of the previous version.

Procedure video

Procedure

Step 1: Prepare a MaxCompute project

Step

Procedure

Expected result

Step 0

Register for the invitational preview of new MaxCompute features

  1. Open the invitational preview application form for new MaxCompute features.

  2. Select Delta Table incremental table format, Incremental computing based on incremental materialized views, and MCQA 2.0 SQL engine query acceleration.

  3. Click Register.

The new MaxCompute features are enabled.

Step 1

Initialize a new MaxCompute project

  1. Open the MaxCompute console and click Create Project.

  2. In the Create Project dialog box, configure the following parameters.

    Set Project Name to delta_compute_yunqi. Set Project Type to Apsara Conference New Feature Invitational Preview Project. Configure other parameters as needed or keep the default settings.

    You can select the China (Beijing), China (Shanghai), or China (Hangzhou) region.

  3. Click OK.

  1. In the navigation pane on the left of the console, choose Workspace > SQL Analysis to open the Ad-Hoc Query page.

  2. On the left side of the SQL Analysis page, find the new project delta_compute_yunqi.

Step 2

Purchase a new quota in Quota Management

  1. In the navigation pane on the left of the MaxCompute console, choose Workspace > Quota Management and click Purchase Quota.

  2. Create a subscription level-1 quota and complete the payment as prompted on the page.

  3. Under the created level-1 quota group, create two different level-2 quota groups:

    • Batch processing quota group: batch_demo_yunqi

    • Interactive quota group: mcqa2_demo_yunqi

  4. Set the resources for the batch processing quota group and the interactive quota group.

On the Quota Management page, confirm that the batch processing quota group and the interactive quota group are created.

Step 3

Create a MaxCompute Delta Table

On the SQL Analysis page, run the following sample commands to create two MaxCompute internal tables:

  • Create the yunqi_github_events_odps_cdc table. Data will be written to this table in real-time using Flink CDC.

    -- Enable the upsertable feature for ODPS SQL.
    SET odps.sql.upsertable.table.enable=true;
    SET odps.storage.orc.enable.memcmp.sort.key=true; 
    
    -- Flink CDC
    CREATE TABLE IF NOT EXISTS yunqi_github_events_odps_cdc
    (
        id                     BIGINT NOT NULL COMMENT 'Event ID'
        ,actor_id              BIGINT COMMENT 'Event initiator ID'
        ,actor_login           STRING COMMENT 'Event initiator logon name'
        ,repo_id               BIGINT COMMENT 'Repo ID'
        ,repo_name             STRING COMMENT 'Full repo name: owner/Repository_name'
        ,org_id                BIGINT COMMENT 'ID of the organization that owns the repo'
        ,org_login             STRING COMMENT 'Name of the organization that owns the repo'
        ,`type`                STRING COMMENT 'Event type'
        ,created_at            TIMESTAMP NOT NULL COMMENT 'Time of event occurrence'
        ,action                STRING COMMENT 'Event action'
        ,commit_id             STRING COMMENT 'Commit record ID'
        ,member_id             BIGINT COMMENT 'Member ID'
        ,language              STRING COMMENT 'Programming language'
        ,PRIMARY KEY(id, created_at))
    STORED AS ALIORC  
    TBLPROPERTIES ('acid.data.retain.hours'='24',
         'acid.incremental.query.out.of.time.range.enabled'='true',
         'columnar.nested.type'='true',
         'transactional'='true',
         'write.bucket.num'='64',
         'acid.ingest.commit.num.check.limit'='10',
         'cdc.insert.into.passthrough.enable'='true', 
         'acid.cdc.mode.enable' = 'true',-- If asynchronous mode is enabled, you must make additional settings.
         'acid.cdc.build.async'='true', 
         'acid.cdc.build.interval'='60') 
    LIFECYCLE 36500;
    
  • Create the yunqi_github_events_odps_dw table. Data will be written to this table in real-time using DataWorks data integration.

    -- Enable the upsertable feature for ODPS SQL.
    SET odps.sql.upsertable.table.enable=true;
    SET odps.storage.orc.enable.memcmp.sort.key=true; 
    
    -- DataWorks real-time data synchronization
    CREATE TABLE IF NOT EXISTS yunqi_github_events_odps_dw
    (
        id                     BIGINT NOT NULL COMMENT 'Event ID'
        ,actor_id              BIGINT COMMENT 'Event initiator ID'
        ,actor_login           STRING COMMENT 'Event initiator logon name'
        ,repo_id               BIGINT COMMENT 'Repo ID'
        ,repo_name             STRING COMMENT 'Full repo name: owner/Repository_name'
        ,org_id                BIGINT COMMENT 'ID of the organization that owns the repo'
        ,org_login             STRING COMMENT 'Name of the organization that owns the repo'
        ,`type`                STRING COMMENT 'Event type'
        ,created_at            TIMESTAMP COMMENT 'Time of event occurrence'
        ,action                STRING COMMENT 'Event action'
        ,commit_id             STRING COMMENT 'Commit record ID'
        ,member_id             BIGINT COMMENT 'Member ID'
        ,language              STRING COMMENT 'Programming language'
        ,PRIMARY KEY(id))
    STORED AS ALIORC  
    TBLPROPERTIES ('acid.data.retain.hours'='24',
         'acid.incremental.query.out.of.time.range.enabled'='true',
         'columnar.nested.type'='true',
         'transactional'='true',
         'write.bucket.num'='64',
         'acid.ingest.commit.num.check.limit'='10',
         'cdc.insert.into.passthrough.enable'='true', 
         'acid.cdc.mode.enable' = 'true',-- CDC is synchronized by default.
         'acid.cdc.build.async'='true', -- If asynchronous mode is enabled, you must make additional settings.
         'acid.cdc.build.interval'='60') 
    LIFECYCLE 36500;

On the SQL Analysis page, select the project delta_compute_yunqi and confirm that the following two Delta Tables exist:

  • yunqi_github_events_odps_cdc

  • yunqi_github_events_odps_dw

Step 2: Write full and incremental data in near real-time

Obtain the real-time dataset from GitHub Archive using Flink CDC or DataWorks data integration.

Choose one of the following methods to write data as needed.

Flink CDC

Step

Procedure

Expected result

Step 1

Connect to and verify the real-time MySQL data source

The connection information for the MySQL data source is as follows.

Configuration Mode: Select Connection String Mode.
JDBC URL: Click Add Address and configure the following information:
Host IP Address:
rm-bp1z69dodhh85z9qa.mysql.rds.aliyuncs.com
Port: 3306

After entering the database name, the complete JDBC URL is:
jdbc:mysql://rm-bp1z69dodhh85z9qa.mysql.rds.aliyuncs.com:3306/github_events_share
Database Name: github_events_share
Username: workshop
Password: workshop#2017
This password is for tutorial purposes only. Do not use it in your actual business.
Note

Make sure the MySQL data source can be accessed over the public network. If it cannot be accessed over the public network, you can configure an Internet NAT gateway.

Confirm that the public GitHub data source is available.

--MySQL PublicData

id  'Event ID';
actor_id  'Event initiator ID';
actor_login  'Event initiator logon name';
repo_id  'Repo ID';
repo_name  'Repo name';
org_id  'ID of the organization that owns the repo';
org_login  'Name of the organization that owns the repo';
type  'Event type';
created_at  'Time of event occurrence';
action  'Event action';
commit_id  'Commit record ID';
member_id  'Member ID';
language  'Programming language';

Step 2

Using Flink

Writing data with CDC

Write real-time GitHub Event data to a MaxCompute Delta Table using Flink CDC. For more information, see Write data to a Delta Table in near real-time using open source Flink CDC.

  1. Select the data connectors.

  2. Write the task configuration YAML file. The following code shows a sample rds-to-maxcompute.yaml file for full database synchronization.

    # Author:         openlake@test.aliyunid.com
    # Created Time:   2024-08-27 12:46:11
    # Description:    Write your description here
    
    source:
      type: mysql
      hostname: rm-bp1z69dodhh85z9qa.mysql.rds.aliyuncs.com
      port: 3306
      username: workshop
      password: workshop#2017
      tables: github_events_share.\.*
      server-id: 5400-5404
    
    sink:
       type: maxcompute
       name: MaxComputeSink
       accessId: xxxxxxxxxxxxxxxxxxxxxx
       accessKey: xxxxxxxxxxxxxxxxxxxxxxx
       endpoint: http://xxx.xxx.xxx.xxx:8008
       tunnelEndpoint: http://xxx.xxx.xxx.xxx:8009
       project: delta_compute_yunqi
       bucketSize: 8
    
    pipeline:
       parallelism: 4
  3. Run the flink-cdc command to start real-time data synchronization.

    ./bin/flink-cdc.sh rds-to-maxcompute.yaml

Check the data changes in the yunqi_github_events_odps_cdc table in MaxCompute.

SELECT COUNT(1) FROM yunqi_github_events_odps_cdc; 

DataWorks data integration

Step

Operations

Expected result

Step 1

Connect to and verify the real-time MySQL data source

The connection information for the MySQL data source is as follows.

Configuration Mode: Select Connection String Mode.
JDBC URL: Click Add Address and configure the following information:
Host IP Address:
rm-bp1z69dodhh85z9qa.mysql.rds.aliyuncs.com
Port: 3306

After entering the database name, the complete JDBC URL is:
jdbc:mysql://rm-bp1z69dodhh85z9qa.mysql.rds.aliyuncs.com:3306/github_events_share
Database Name: github_events_share
Username: workshop
Password: workshop#2017
This password is for tutorial purposes only. Do not use it in your actual business.
Note

Make sure the MySQL data source can be accessed over the public network. If it cannot be accessed over the public network, you can configure an Internet NAT gateway.

Confirm that the public GitHub data source is available.

--MySQL PublicData

id  'Event ID';
actor_id  'Event initiator ID';
actor_login  'Event initiator logon name';
repo_id  'Repo ID';
repo_name  'Repo name';
org_id  'ID of the organization that owns the repo';
org_login  'Name of the organization that owns the repo';
type  'Event type';
created_at  'Time of event occurrence';
action  'Event action';
commit_id  'Commit record ID';
member_id  'Member ID';
language  'Programming language';

Step 2

Configure a real-time data source in DataWorks

Write real-time GitHub Event data to a MaxCompute Delta Table using DataWorks data integration (real-time data source).

  1. Create the data sources required for the sync task.

    Log on to the DataWorks console, switch to the China (Beijing) or China (Shanghai) region, and in the navigation pane on the left, choose Data Development and Governance > Data Integration.

    2024-09-18_14-29-21.png

    You can select an existing workspace or create a new one, and then click Go to Data Integration.

  2. On the DataWorks Data Integration page, click Data Source in the navigation pane on the left, and then click Add Data Source.

  3. In the Add Data Source dialog box, follow the on-screen instructions to create MySQL and MaxCompute data sources.

    • The following figure shows a sample MySQL configuration page. Enter the MySQL data source information provided in Step 1. For more information, see MySQL data source.

    • The following figure shows a sample MaxCompute configuration page. For more information, see Bind a MaxCompute compute resource.

Confirm that the source and destination data sources are connected.

Step 3

DataWorks: Real-time task synchronization

Write real-time GitHub Event data to a MaxCompute Delta Table using DataWorks data integration.

  1. On the DataWorks Data Integration page, click Sync Tasks in the navigation pane on the left, and then click Create Sync Task.

  2. On the Create Sync Task page, configure the following information.

    • For the Data source parameter, select MySQL.

    • Set Data Destination to MaxCompute.

    • The sample task name is sync_mysql_to_odps.

    • The synchronization type is Real-time Full Database.

    • For Resource Group, select the resource group created when you enabled DataWorks. Set the number of CUs to 5 CUs.

      Note
      • To maintain a stable connection to the public data source, the connection between the resource group and the public MySQL data source will be released after 7 days. This does not affect the connection between the resource group and your MySQL data source.

      • To run a data integration task for an entire database using a new version of a resource group, you must configure at least 2 CUs. For more information, see Billing for Serverless resource groups.

    • Set Source Data Source to mysql_github_source.

    • Select delta_compute_demo for the destination data source.

  3. Click Test Connectivity to ensure network connectivity between the data source and the resource group. For more information about network connectivity, see Network connectivity solutions.

  4. After the test is successful, click Next.

  5. On the Select the databases and tables to synchronize page, select the github table in MySQL and move it to Selected Databases and Tables.

  6. In the Destination Table Mapping area, select the corresponding table and click Batch Refresh Mappings. Based on the MaxCompute Delta Table created earlier, change the destination table name to yunqi_github_events_odps_dw and click Complete Configuration.

  7. On the Task List page, start the task and view the execution details.

    The public MySQL data source retains data from the last 7 days. Offline data will be synchronized through a full sync. Real-time data will be written to MaxCompute in real-time after the full initialization is complete.

  8. After the data is synchronized, go to MaxCompute TopConsole to perform near real-time data analysis.

Check the data changes in the yunqi_github_events_odps_dw table in MaxCompute.

SELECT COUNT(1) FROM yunqi_github_events_odps_dw; 

Step 3: Perform near real-time query analysis and incremental computing

  • Near real-time data analysis: Use the interactive quota group mcqa2_demo_yunqi (64 CUs) for SQL data analysis in MaxCompute TopConsole.

  • Incremental MV - automated dynamic table: Use the batch processing quota group batch_demo_yunqi (128 CUs) for dynamic table incremental computing in MaxCompute TopConsole.

  • Incremental computing - CDC/Stream/periodic Tasks: Use the batch processing quota group batch_demo_yunqi for custom incremental computing in MaxCompute TopConsole.

Step

Procedure

Expected result

Step 1

Use the interactive resource group for near real-time data analysis

  1. In the navigation pane on the left of the MaxCompute console, choose Workspace > SQL Analysis to open the Ad-Hoc Query page.

  2. Select the interactive quota group created in Step 1 to perform near real-time query analysis.

The specific SQL analysis steps are as follows:

  • Q1: What are the most active projects in the last 24 hours?

    --Q1: Top 5 most active projects in the last 24 hours
    SELECT
        repo_name,
        COUNT(*) AS events
    FROM
        yunqi_github_events_odps_dw
    WHERE
        date_add(created_at,-1)>'2024-08-26'
    GROUP BY
        repo_name
    ORDER BY
        events DESC
    LIMIT 5;
  • Q2: Who are the most active developers in the past 24 hours?

    --Q2: Top 5 most active developers in the last 24 hours
    SELECT
        actor_login,
        COUNT(*) AS events
    FROM
        yunqi_github_events_odps_dw
    WHERE
        date_add(created_at,-1)>'2024-08-26'
    GROUP BY
        actor_login
    ORDER BY
        events 
    LIMIT 5;
  • Q3: Total number of public events today

    --Q3: Total number of public events today
    SELECT count(*) FROM yunqi_github_events_odps_dw WHERE TO_DATE(created_at) >= date_add(now(),-1);
  • Q4: Display real-time events

    --Q4: Display real-time events
    SELECT
        cast(created_at as STRING ),
        actor_login,
        type,
        repo_name
    FROM
        yunqi_github_events_odps_dw
    ORDER BY
        created_at DESC
    LIMIT 5;

Observe the SQL query results.

Step 2

Use the batch processing resource group for incremental computing and aggregate queries with incremental MVs

  1. In the navigation pane on the left of the MaxCompute console, choose Workspace > SQL Analysis to open the Ad-Hoc Query page.

  2. Select the batch processing quota group created in Step 1 for batch MV applications.

The specific SQL analysis steps are as follows:

  1. Confirm that the Delta Table is created and that historical and incremental data is being updated.

    Create CDC information to track the Delta Table (Optional: CDC is automatically generated by default).

    --Q1: Create CDC information to track the Delta Table.
    ALTER TABLE yunqi_github_events_odps_dw build cdc; --Trigger the subsequent CDC process.
  2. Perform real-time incremental MV queries. Based on historical and incremental data, create a lightweight aggregation incremental MV that aggregates and counts the number of events by repo_name, language, and create_date.

    --Q2: Generate incremental materialized view MV1-yunqi_incre_mv1.
    SET useTunnel=FALSE;
    CREATE materialized VIEW IF NOT EXISTS yunqi_incre_mv1
    refresh every 2 minutes
    tblproperties("enable_auto_refresh"="true", "refresh_mode"="incremental")
    AS SELECT
        repo_name,
        language,
        COUNT(*) AS events,
        to_date(created_at) AS create_date
    FROM
        yunqi_github_events_odps_dw
    WHERE
        date_add(created_at,-1)>'2024-07-26' AND language IS NOT NULL
    GROUP BY
      repo_name,language,to_date(created_at);
    --Q3: Observe the source table status - Verify using SHOW HISTORY to view table behavior / Confirm CDC Build status.
    SHOW history FOR TABLE yunqi_github_events_odps_dw;
    SELECT * FROM table_changes('yunqi_github_events_odps_dw', 1);
  3. SQL analysis: Query the total number of events and the language for each repo within a specific time frame, based on repo_name and language.

    --Q4: Query the total number of events and the language, sorted by repo_name and language in descending order.
    SELECT repo_name, language, SUM(events) AS events_sum, COUNT(create_date) AS day_count 
    FROM yunqi_incre_mv1 
    WHERE events > 100 
    GROUP BY repo_name,language ORDER BY events_sum DESC;
    --Q5: View the historical operation changes of incremental materialized view MV1.
    SHOW history FOR TABLE yunqi_incre_mv1;
    -- Data is updated in 5-minute batches. If there are no changes, run the following command.
    ALTER materialized VIEW yunqi_incre_mv1 rebuild;
    SELECT * FROM table_changes('yunqi_github_events_odps_dw', 1);
  4. Build a cascading incremental materialized view MV2. Based on the existing incremental materialized view MV1, create a heavyweight aggregation layer.

    • Generate incremental materialized view MV2-yunqi_incre_mv2. Based on incremental MV1, materialize the SQL analysis results into incremental MV2. This is based on the query from Q4.

      --Q6: Generate cascading incremental materialized view MV2-yunqi_incre_mv2.
      SET useTunnel=FALSE;
      CREATE materialized VIEW IF NOT EXISTS yunqi_incre_mv2
      refresh every 2 minutes
      tblproperties("enable_auto_refresh"="true", "refresh_mode"="incremental")
      AS 
      SELECT repo_name, language, SUM(events) AS events_sum, COUNT(create_date) AS day_count 
      FROM yunqi_incre_mv1 
      WHERE events > 100 
      GROUP BY repo_name,language;
    • SQL analysis: Within a specific time frame, group by programming language and sort by the number of repos to query the total number of events for each language.

      --Q7: Sort popular programming languages.
      SELECT language, COUNT(repo_name) AS repo_cnt,MAX(events_sum) AS max_events FROM yunqi_incre_mv2 
      GROUP BY language ORDER BY repo_cnt DESC;
      --Q8: Observe the historical operation status of incremental MV2 / Table change information.
      SHOW history FOR TABLE yunqi_incre_mv2;
      -- Data is updated in 5-minute batches. If there are no changes, run the following command.
      ALTER materialized VIEW yunqi_incre_mv2 rebuild;
      SELECT * FROM table_changes('yunqi_incre_mv2', 2);

Observe the SQL query results.

Step 3

Use the batch processing resource group for incremental computing with Stream and Task applications

  1. In the navigation pane on the left of the MaxCompute console, choose Workspace > SQL Analysis to open the Ad-Hoc Query page.

  2. Select the batch processing quota group created in Step 1 for incremental CDC.

The specific SQL analysis steps are as follows:

  1. Create a stream object to query the newly added CDC records for subsequent incremental computing.

    --Q1: Query the latest version information of the table data.
    SELECT get_latest_version('yunqi_github_events_odps_dw'); 

    Create a Stream object. Use the information from get_latest_version to set the starting version for tracking incremental data. Select a historical version that is less than or equal to the latest version to start tracking incremental CDC records.

    --Q2: Create a Stream object.
    CREATE stream stream_githubs ON TABLE yunqi_github_events_odps_dw version AS OF 10 strmproperties('read_mode'='cdc') ;
    
    DESC stream stream_githubs;

  2. Create and run a Task. The task automatically performs incremental updates for repo_name.

    • Create the aggregation table yunqi_github_events_ads.

      --Create the aggregation table yunqi_github_events_ads.
      SET odps.sql.upsertable.table.enable=true;
      CREATE TABLE IF NOT EXISTS 
      yunqi_github_events_ads
      (
          repo_name             STRING COMMENT 'Full repo name: owner/Repository_name'
          ,language              STRING COMMENT 'Programming language'
          ,events_cnt            BIGINT COMMENT 'Number of events'
          ,create_date           DATE COMMENT 'Time of event occurrence'
      )
      STORED AS ALIORC  
      TBLPROPERTIES (
           'transactional'='true',
           'write.bucket.num'='64') 
      LIFECYCLE 36500;
    • The task automatically performs incremental updates for repo_name.

      --The task automatically performs incremental updates for repo_name.
      SET odps.sql.periodic.task.enabled=true;
      CREATE task yunqi_incre_task1
      schedule='45 second' 
      taskproperties('schedule_strategy'='200')
      WHEN stream_has_data('stream_githubs')
      AS INSERT overwrite yunqi_github_events_ads SELECT
          repo_name,
          language,
          COUNT(*) AS events_cnt,
          to_date(created_at) AS create_date
      FROM
          yunqi_github_events_odps_dw
      WHERE
          date_add(created_at,-1)>'2024-08-26' AND language IS NOT NULL
      GROUP BY
      repo_name,language,to_date(created_at);
      

      Every minute, the task automatically queries the incremental CDC data from the DWD layer, analyzes it, and writes the results to the ADS table yunqi_github_events_ads. Although this custom pipeline is complex to write, it lets you flexibly define the incremental computing and analysis logic using SQL. (Duration setting: You can set the schedule in seconds for intervals under 1 minute. For intervals over 1 minute, set it in minutes, up to a maximum of 59 minutes.)

  3. Update the Task status. The task automatically performs incremental updates for repo_name.

    --Update the Task status. The task automatically performs incremental updates for repo_name.
    ALTER task  yunqi_incre_task1  suspend;  --Pause
    ALTER task  yunqi_incre_task1  resume; --Resume
  4. Query the CDC build task status.

    --Query the CDC build task status.
    SHOW history FOR task yunqi_incre_task1;
    SELECT *  FROM stream_githubs

Observe the SQL query results.

Step 4: Configure multiple quotas and accelerate interactive queries

After scaling out an interactive Quota group from 64 CU to 96 CU, you can run an interactive query in the MaxCompute TopConsole on the new Quota group to observe the improvement in query acceleration.

Step

Procedure

Expected result

Step 1

Scale out the quota

  1. In the navigation pane on the left of the MaxCompute console, choose Workspace > Quota Management, and click Quota Configurations to the right of the target level-1 quota group.

  2. On the Basic Configurations page, click Edit Basic Configurations.

  3. Modify the interactive quota group mcqa2_demo_yunqi by scaling it out from 64 CUs to 128 CUs.

The target quota group is scaled out.

Step 2

Compare and analyze query performance and optimization

  1. In the navigation pane on the left of the MaxCompute console, choose Workspace > SQL Analysis to open the Ad-Hoc Query page.

  2. Select the interactive quota group created in Step 1 to perform near real-time query analysis and observe data changes.

The specific SQL analysis steps are as follows:

  • Q1 (Optional): Perform a major compaction operation to optimize queries.

    --Q1: Perform a major compaction operation to optimize queries.
    SET odps.merge.task.mode=service;
    ALTER TABLE yunqi_github_events_odps_dw compact major;

    Compare MCQA 2.0 query performance using the interactive resource group.

    --Q2: Near real-time query - Display real-time events.
    SELECT
        cast(created_at AS STRING ),
        actor_login,
        type,
        repo_name
    FROM
        yunqi_github_events_odps_dw
    ORDER BY
        created_at DESC
    LIMIT 5;
  • Incremental MV1 query: Query the total number of events and the language for each repo within a specific time frame, based on repo_name and language.

    --Q3: Query the total number of events and the language, sorted by repo_name and language in descending order.
    SELECT repo_name, language, SUM(events) AS events_sum, COUNT(create_date) AS day_count 
    FROM yunqi_incre_mv1 
    WHERE events > 100 
    GROUP BY repo_name,language ORDER BY events_sum DESC;
  • Incremental MV2 query: Within a specific time frame, group by programming language to query the number of repos and the total number of events for each language.

    --Q4: Sort popular programming languages.
    SELECT language, COUNT(repo_name) AS repo_cnt,MAX(events_sum) AS max_events FROM yunqi_incre_mv2 
    GROUP BY language;

Observe the SQL query results.

Step 5 (Optional): Perform integrated interactive analysis of full and incremental data

Use the DataWorks IDE module to perform integrated, near real-time analysis of full and incremental data.

Step

Procedure

Expected result

Step 1

Configure MaxCompute compute resources in the DataWorks IDE Data Development module

  1. Go to the DataWorks IDE Data Development page. In the navigation pane on the left, click the 数据目录.png icon to open the Data Catalog page.

  2. In the upper-right corner, click Workspace Management, select Compute Resources, and click Bind Compute Resource.

  3. On the right side of the page, configure Compute Resources, Compute Quota, and Resource Group.

  4. Bind the MaxCompute project and run the MaxCompute SQL task.

None

Step 2

Perform data analysis on the DataWorks IDE Data Development platform

The specific SQL analysis steps are as follows:

  • Q1: What are the most active projects in the past 24 hours?

    SELECT
        repo_name,
        COUNT(*) AS events
    FROM
        yunqi_github_events_odps_dw
    WHERE
        date_add(created_at,-1)>'2024-08-26'
    GROUP BY
        repo_name
    ORDER BY
        events DESC
    LIMIT 5;
  • Q2: Who are the most active developers in the past 24 hours?

    SELECT
        actor_login,
        COUNT(*) AS events
    FROM
        yunqi_github_events_odps_dw
    WHERE
        date_add(created_at,-1)>'2024-08-26'
    GROUP BY
        actor_login
    ORDER BY
        events 
    LIMIT 5;
  • Q3: Total number of public events today

    SELECT count(*) FROM yunqi_github_events_odps_dw WHERE TO_DATE(created_at) >= date_add(now(),-1);
  • Q4: Display real-time events

    SELECT
        cast(created_at AS STRING ),
        actor_login,
        type,
        repo_name
    FROM
        yunqi_github_events_odps_dw
    ORDER BY
        created_at DESC
    LIMIT 5;

Observe the SQL query results.

Summary

This example demonstrates a practical solution built on the new features of the MaxCompute near real-time data warehouse. MaxCompute provides integrated processing of full and incremental data and near real-time query capabilities. It upgrades its near real-time computing capabilities through a three-layer architecture: the data storage layer (Delta Table unified table format), the computing layer (incremental computing: CDC/Task/incremental MV), and the acceleration layer (MCQA 2.0 query acceleration engine). By following this typical demo, you can gain a deep understanding of how to build complete near real-time and integrated full and incremental computing tasks on MaxCompute, which simplifies computing optimization throughout data lifecycle.