Help Center> Data Lake Insight> Best Practices> Using DLI to Convert Data Format from CSV to Parquet

Using DLI to Convert Data Format from CSV to Parquet

Application Scenarios

Parquet is a columnar storage substrate created for simpler data analysis. This format can speed up queries by allowing only the required columns to be read and calculated. In addition, Parquet is built to support very efficient compression schemes, which maximizes the storage efficiency on disks. Using DLI, you can easily convert data format form CSV to Parquet.

Operation Process

  1. Create a CSV file. See test.csv in Figure 1.

    Figure 1 Creating a test.csv file

  2. In the OBS management console, create a bucket named obs-csv-parquet and upload the test.csv file to OBS. See Figure 2.

    Figure 2 Uploading CSV data to OBS

  3. In the SQL editing box of the DLI management console, create an OBS table named test_csv_hw and import data in the test.csv file to test_csv_hw.

    create table test_csv_hw(id1 int, id2 int, id3 int, id4 int, id5 int) using csv options(path 'obs://obs-csv-parquet/test.csv')

  4. In the SQL editing box of the DLI management console, query data in the test_csv_hw table.

    Figure 3 Querying data in the test_csv_hw table

  5. Create a bucket named obs-parquet-data on OBS to store Parquet data.
  6. In the SQL job editing window of the DLI management console, create an OBS table named test_parquet_hw.

    CREATE TABLE `test_parquet_hw` (`id1` INT, `id2` INT, `id3` INT, `id4` INT, `id5` INT)
    USING parquet
    OPTIONS (
    path 'obs://obs-parquet-data/'
    )

    You do not need to specify a file because no Parquet file exists before the data is converted from the CSV format to the Parquet format.

  7. In the SQL job editing window of the DLI management console, convert CSV data into Parquet data and store the data in OBS.

    insert into test_parquet_hw select * from test_csv_hw

  8. Check the result. As shown in Figure 4, the system automatically creates a file for saving the result.

    Figure 4 Saving Parquet data