APIG Sink Stream

Overview

CS outputs the job result to open APIs of APIG. You can access data through API calling on APIG. APIG is an API hosting service with high performance, availability, and security. It allows users to create, manage, and deploy APIs at any scale. With APIG, you can implement system integration, micro-service aggregation, and serverless architectures easily and quickly with low costs and risks. For more information about API Gateway, see the API Gateway User Guide (API Calling).

Prerequisites

  • Ensure that you have created an application on APIG using your account. For details about how to create an application using API calling, see Creating an Application in the API Gateway User Guide (API Calling).

Syntax

Syntax

CREATE SINK STREAM stream_id (attr_name attr_type (',' attr_name attr_type)* )WITH (type = "apig",region = "",app_id= "",encode= "",field_delimiter= "");

Description

Table 1 Syntax description

Parameter

Mandatory

Description

type

Yes

Output channel type. Value apig indicates that data is stored to APIG.

region

Yes

Region where APIG for storing the data is located.

app_id

Yes

ID of the application used for API calling.

encode

Yes

Data encoding format. The value can be csv and json.

NOTE:
  • If the encoding format is csv, you need to configure field separators.
  • If the encoding format is json, you need to configure whether to generate an empty field. For details, see the examples.

field_delimiter

Yes

Separator used to separate every two attributes.

  • This parameter needs to be configured if the CSV encoding format is adopted. It can be user-defined, for example, a comma (,).
  • This parameter is not required if the JSON encoding format is adopted.

json_config

No

If encode is set to json, you can set this parameter to specify the mapping between the JSON field and the stream definition field. An example of the format is as follows: field1=data_json.field1; field2=data_json.field2.

Precautions

None

Example

  • CSV: Data is written to APIG as codes in CSV format which are separated by commas (,). If there are multiple partitions, car_owner is used as the key to distribute data to different partitions. An example is as follows: "ZJA710XC", "lilei", "BMW", 700000.
    CREATE SINK STREAM audi_cheaper_than_30w (
      car_id STRING,
      car_owner STRING,
      car_brand STRING,
      car_price INT
    )
    WITH (
      type = "apig",
      app_id = "xxxxxxxxxx",
      region = "cn-north-1" ,
      encode = "csv",
      field_delimiter = ","
    ); 
  • JSON: Data is output to APIG and encoded using JSON. If there are multiple partitions, car_owner and car_brand are used as the keys to distribute data to different partitions. If enableOutputNull is set to true, an empty field (the value is null) is generated. If set to false, no empty field is generated. An example is as follows: "car_id ":"ZJA710XC", "car_owner ":"lilei", "car_brand ":"BMW", "car_price ":700000.
    CREATE SINK STREAM audi_cheaper_than_30w (
      car_id STRING,
      car_owner STRING,
      car_brand STRING,
      car_price INT
    )
    WITH (
      type = "apig",
      app_id = "6ac32a6596614bf69fb5c5553f26963f",
      region = "cn-north-1" ,
      encode = "json",
      enable_output_null = "false"
    );