Updated on 2022-12-07 GMT+08:00

Creating a Database or a Table

Definition of Database and Table in DLI

A database, built on the computer storage device, is a data warehouse where data is organized, stored, and managed based on its structure.

The table is an important part of the database. It consists of rows and columns. Each column functions as a field. Each value in a field (column) represents a type of data.

The database is a framework and the table contains data content. A database has one or more tables.

The basic database concept and usage in DLI are similar to those in the Oracle database. DLI permissions are granted on a per database basis.

You can create databases and tables on the management console or using SQL statements. This section describes how to create a database and a table on the management console.

A view can be created only by using SQL statements. You cannot create a view on the Create Table page.

Precautions

  • If a folder and a file have the same name in the OBS directory, the file path is preferred as the path of the OBS table to be created.

Creating a Database

  1. You can create a database on either the Data Management page or the SQL Editor page.

    • To create a database on the Data Management page:
      1. On the left of the management console, choose Data Management > Databases and Tables.
      2. In the upper right corner of the Databases and Tables page, click Create Database to create a database.
    • To create a database on the SQL Editor page:
      1. On the left of the management console, click SQL Editor.
      2. In the navigation pane on the left, click beside Databases.

  2. In the displayed Create Database dialog box, specify Name and Description by referring to Table 1.

    Table 1 Description

    Parameter

    Description

    Example

    Database Name

    • The database name can contain only digits, letters, and underscores (_), but cannot contain only digits or start with an underscore (_).
    • The database name is case insensitive and cannot be left blank.
    • The length of the database name cannot exceed 128 characters.
    NOTE:

    The default database is a built-in database. You cannot create the database named default.

    DB01

    Enterprise Project

    If the created queue belongs to an enterprise project, you can select the corresponding enterprise project.

    An enterprise project facilitates project-level management and grouping of cloud resources and users.

    For details about how to set enterprise projects, see .

    NOTE:

    This parameter is displayed only for users who have enabled the Enterprise Management Service.

    -

    Description

    Description of a database.

    -

  3. Click OK.

    After a database is created, you can view and select the database for use on the Databases and Tables page or SQL Editor page.

Creating a Table

Before creating a table, ensure that a database has been created.

  1. You can create a table on either the Databases and Tables page or the SQL Editor page.

    Datasource connection tables, such as View tables, HBase (MRS) tables, OpenTSDB (MRS) tables, DWS tables, RDS tables, and CSS tables, cannot be created. You can use SQL to create views and datasource connection tables. For details, see sections Creating a View and Creating a Datasource Connection Table in the Data Lake Insight SQL Syntax Reference.

    • To create a table on the Data Management page:
      1. On the left of the management console, choose Data Management > Databases and Tables.
      2. On the Databases and Tables page, select the database for which you want to create a table. In the Operation column, click More > Create Table to create a table in the current database.
    • To create a table on the SQL Editor page:
      1. On the left of the management console, click SQL Editor.
      2. In the navigation pane of the displayed SQL Editor page, click Databases. You can create a table in either of the following ways:
        • Click a database name. In the Tables area, click on the right to create a table in the current database.
        • Click on the right of the database and choose Create Table from the shortcut menu to create a table in the current database.

  2. In the displayed Create Table dialog box, set parameters as required.

    • If you set Data Location to DLI, set related parameters by referring to Table 2.
    • If you set Data Location to OBS, set related parameters by referring to Table 2 and Table 3.
      Table 2 Common parameters

      Parameter

      Description

      Example

      Table Name

      • 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 ($). An example value is $test.
      • The length of the table name cannot exceed 128 characters.

      table01

      Data Location

      Data storage location. Currently, DLI and OBS are supported.

      OBS

      Description

      Description of the table.

      -

      Column Type

      Available values: Normal or Partition

      Normal

      Column

      Name of a column in a table. The column name must contain at least one letter and can contain underscores (_). It cannot contain only digits.

      You can select Normal or Partition. Partition columns are dedicated to partition tables. User data is partitioned to improve query efficiency.

      NOTE:

      The column name is case-insensitive and must be unique.

      name

      Type

      Data type of a column. This parameter corresponds to Column Name.

      • string: The data is of the string type.
      • int: Each integer is stored on four bytes.
      • date: The value ranges from 0000-01-01 to 9999-12-31.
      • double: Each number is stored on eight bytes.
      • boolean: Each value is stored on one byte.
      • decimal: The valid bits are positive integers between 1 to 38, including 1 and 38. The decimal digits are integers less than 10.
      • smallint/short: The number is stored on two bytes.
      • bigint/long: The number is stored on eight bytes.
      • timestamp: The data indicates a date and time. The value can be accurate to six decimal points.
      • float: Each number is stored on four bytes.
      • tinyint: Each number is stored on one byte. Only OBS tables support this data type.

      string

      Column Description

      Description of a column.

      -

      Operation

      • Add Column
      • Delete
        NOTE:

        If the table to be created includes a great number of columns, you are advised to use SQL statements to create the table or import column information from the local EXCEL file.

      -

      Table 3 Parameter description when Data Location is set to OBS

      Parameter

      Description

      Example

      Data Format

      DLI supports the following data formats:

      • Parquet: DLI can read non-compressed data or data that is compressed using Snappy and gzip.
      • CSV: DLI can read non-compressed data or data that is compressed using gzip.
      • ORC: DLI can read non-compressed data or data that is compressed using Snappy.
      • JSON: DLI can read non-compressed data or data that is compressed using gzip.
      • Avro: DLI can read uncompressed Avro data.

      CSV

      Storage Path

      Enter or select an OBS path. The path can be a folder or a path.

      NOTE:

      If you need to import data stored in OBS to the OBS table, set this parameter to the path of a folder. If the table creation path is a file, data fails to be imported.

      obs://obs1/sampledata.csv

      Table Header: No/Yes

      This parameter is valid only when Data Format is set to CSV. Whether the data source to be imported contains the table header.

      Click Advanced Settings and select the check box next to Table Header: No. If the check box is selected, the table header is displayed. If the check box is deselected, no table header is displayed.

      -

      User-defined Delimiter

      This parameter is valid only when Data Format is set to CSV and you select User-defined Delimiter.

      The following delimiters are supported:

      • Comma (,)
      • Vertical bar (|)
      • Tab character (\t)
      • Others: Enter a user-defined delimiter.

      Comma (,)

      User-defined Quotation Character

      This parameter is valid only when Data Format is set to CSV and you select User-defined Quotation Character.

      The following quotation characters are supported:

      • Single quotation mark (')
      • Double quotation marks (")
      • Others: Enter a user-defined quotation character.

      Single quotation mark (')

      User-defined Escape Character

      This parameter is valid only when Data Format is set to CSV and you select User-defined Escape Character.

      The following escape characters are supported:

      • Backslash (\)
      • Others: Enter a user-defined escape character.

      Backslash (\)

      Date Format

      This parameter is valid only when Data Format is set to CSV or JSON.

      This parameter specifies the format of the date in the table and is valid only Advanced Settings is selected. The default value is yyyy-MM-dd. For definition of characters involved in the date pattern, see Table 3 in the

      2000-01-01

      Timestamp Format

      This parameter is valid only when Data Format is set to CSV or JSON.

      This parameter specifies the format of the timestamp in the table and is valid only Advanced Settings is selected. The default value is yyyy-MM-dd HH:mm:ss. For definition of characters involved in the time pattern, see Table 3 in the

      2000-01-01 09:00:00

  3. Click OK.

    After a table is created, you can view and select the table for use on the Data Management page or SQL Editor page.

  4. (Optional) After a DLI table is created, you can decide whether to directly import data to the table.