Creating a Table

Function

This API is used to create a table.

Debugging

You can debug this API in API Explorer.

URI

  • URI format

    POST /v1.0/{project_id}/databases/{database_name}/tables

  • Parameter description
    Table 1 URI parameters

    Parameter

    Mandatory

    Type

    Description

    project_id

    Yes

    String

    Project ID, which is used for resource isolation. For details about how to obtain its value, see Obtaining a Project ID.

    database_name

    Yes

    String

    Name of the database where the new table resides.

Request

Table 2 Request parameters

Parameter

Mandatory

Type

Description

table_name

Yes

String

Name of the created table.

  • The table name can contain only digits, letters, and underscores (_), but cannot contain only digits or start with an underscore (_).
  • The table name is case insensitive and cannot be left unspecified.
  • The table name can contain the dollar sign ($). Example: $test
  • The length of the database name cannot exceed 128 characters.

data_location

Yes

String

Data storage location. OBS tables and DLI tables are available.

description

No

String

Information about the new table.

columns

Yes

Array of Objects

Columns of the new table. For details about column parameters, see Table 3.

data_type

No

String

Type of the data to be added to the OBS table. The options are as follows: Parquet, ORC, CSV, JSON, Carbon, and Avro.

NOTE:

This parameter is mandatory for an OBS table.

data_path

No

String

Storage path of data in the new OBS table, which must be a path on OBS and must begin with obs.

NOTE:

This parameter is mandatory for an OBS table.

with_column_header

No

Boolean

Whether the table header is included in the OBS table data. Only data in CSV files has this attribute.

delimiter

No

String

User-defined data delimiter. Only data in CSV files has this attribute.

quote_char

No

String

User-defined reference character. Double quotation marks ("\") are used by default. Only data in CSV files has this attribute.

escape_char

No

String

User-defined escape character. Backslashes (\\) are used by default. Only data in CSV files has this attribute.

date_format

No

String

User-defined date type. yyyy-MM-dd is used by default. For details about the characters involved in the date format, see Table 3. Only data in CSV and JSON files has this attribute.

timestamp_format

No

String

User-defined timestamp type. yyyy-MM-dd HH:mm:ss is used by default. For definitions about characters in the timestamp format, see Table 3. Only data in CSV and JSON files has this attribute.

Table 3 columns parameters

Parameter

Mandatory

Type

Description

column_name

Yes

String

Name of a column.

type

Yes

String

Data type of a column.

description

No

String

Description of a column.

is_partition_column

No

Boolean

Whether the column is a partition column. The value true indicates a partition column, and the value false indicates a non-partition column. The default value is false.

NOTE:

When creating a partition table, ensure that at least one column in the table is a non-partition column. For details, see "Request example".

Response

Table 4 Response parameters

Parameter

Type

Description

is_success

Boolean

Whether the request is successfully executed. Value true indicates that the request is successfully executed.

message

String

System prompt. If execution succeeds, the parameter setting may be left blank.

Example

  • Example request
    {
      "table_name": "tb1",
      "data_location": "OBS",
      "description": "",
      "data_type": "csv",
      "data_path": "obs://obs/path1",
      "columns": [
      {
         "column_name": "column1",
         "type": "string",
         "description": "",
         "is_partition_column": true
      },
      {
         "column_name": "column2",
         "type": "string",
         "description": "",
         "is_partition_column": false
      }
      ],
      "with_column_header": true,
      "delimiter": ",",
      "quote_char": "\"",
      "escape_char": "\\",
      "date_format": "yyyy-MM-dd",
      "timestamp_format": "yyyy-MM-dd HH:mm:ss"
    }

    The values of date_format and timestamp_format must be the same as the time format in the imported CSV file.

  • Example response (successful request)
    {
      "is_success": true,
      "message": ""
    }

Status Codes

Table 5 describes the status code.

Table 5 Status codes

Status Code

Description

200

The job is created successfully.

400

Request error.

500

Internal service error.

Error Codes

If an error occurs when this API is invoked, the system does not return the result similar to the preceding example, but returns the error code and error information. For details, see Error Code.