Creating a Table
Function
This API is used to create a table.
Debugging
You can debug this API in API Explorer.
URI
- URI format
- 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
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| table_name | Yes | String | Name of the created table.
|
| 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. |
| 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
| 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.
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.
Last Article: Table-related APIs
Next Article: Deleting a Table
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.