Skip to content

Query External Plan Reference Script

API Description

This API obtains the complete reference SQL scripts for an external materialization plan.

  • create table (create materialized table)

  • add partition (incrementally create partitions)

  • drop table

  • insert overwrite (backfill by partition)

API URL

GET /anymetrics/api/v1/accelerate/plan/queryReferenceScript

Request parameters

Common Request Headers

parameter Type required Description
tenant-id String Yes Tenant ID, used to identify the tenant for metric query content.
auth-type String Yes Authentication method. Supports UID, TOKEN, ACCOUNT, and APIKEY.
auth-value String Yes Authentication value corresponding to auth-type.

How to Obtain Common parameters

You can obtain this in the top navigation of Aloudata CAN under Metric Applications > API Integration.

image.png

Request parameters

Field Type required Description
uuid String Yes Unique ID of the materialization plan

Request Example

GET /anymetrics/api/v1/accelerate/plan/queryReferenceScript?uuid=ecfc2a9539a04ef49897a9b4e3d65e7f

Response parameter Description

Field Type Description
referenceSchedule Object Reference scheduling configuration for the external plan. Display only
sqlScripts Object SQL scripts organized by table name (DDL + DML)

referenceSchedule Field

Field Description
cron Scheduling cron expression
granularity Granularity, such as DAY
updateUpperInterval Upper bound offset
updateLowerInterval Lower bound offset
isFullRefresh Whether it is a full refresh

sqlScripts Field Structure

{
  "{tableName}": {
    "ddl": {
      "create_table": [{ "sql": "..." }],
      "add_partition": [{ "sql": "..." }],
      "drop_table": [{ "sql": "..." }]
    },
    "dml": {
      "insert_overwrite": [{ "sql": "..." }]
    }
  }
}

Response Example

{
  "data": {
    "referenceSchedule": {
      "cron": "0 0 0 * * ?",
      "granularity": "DAY",
      "updateUpperInterval": -1,
      "updateLowerInterval": -5,
      "isFullRefresh": true
    },
    "sqlScripts": {
      "table_name_demo": {
        "ddl": {
          "create_table": [
            {
              "sql": "CREATE TABLE `default_catalog`.`aloudatacan`.`table_name_demo` (`metric_time` DATE COMMENT 'Metric date', `sum_order_amount` DECIMAL(38, 10) COMMENT 'Sum of order_amount', `dim` STRING COMMENT 'dim') ENGINE=OLAP PARTITION BY RANGE(`metric_time`)(PARTITION default1 VALUES LESS THAN (\"1970-01-01\")) DISTRIBUTED BY RANDOM;"
            }
          ],
          "add_partition": [
            {
              "sql": "ALTER TABLE `default_catalog`.`aloudatacan`.`table_name_demo` ADD PARTITION IF NOT EXISTS ${partition_name} VALUES [(${start_time}), (${end_time})) "
            }
          ],
          "drop_table": [
            {
              "sql": "drop table `default_catalog`.`aloudatacan`.`table_name_demo`"
            }
          ]
        },
        "dml": {
          "insert_overwrite": [
            {
              "sql": "SELECT `t7`.`day_col` AS `metric_time`, `t7`.`f2` AS `sum_order_amount`, `t7`.`username` AS `dim` FROM (...) ORDER BY (`t7`.`day_col`) DESC"
            }
          ]
        }
      }
    }
  }
}