

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

# Memasukkan dan memuat data ke dalam tabel Amazon Keyspaces
<a name="getting-started.dml.create"></a>

Untuk membuat data dalam `book_awards` tabel Anda, gunakan `INSERT` pernyataan untuk menambahkan satu baris. 

1. Buka AWS CloudShell dan sambungkan ke Amazon Keyspaces menggunakan perintah berikut. Pastikan untuk memperbarui *us-east-1* dengan Wilayah Anda sendiri.

   ```
   cqlsh-expansion cassandra.us-east-1.amazonaws.com 9142 --ssl
   ```

   Output dari perintah itu akan terlihat seperti ini.

   ```
   Connected to Amazon Keyspaces at cassandra.us-east-1.amazonaws.com:9142
   [cqlsh 6.1.0 | Cassandra 3.11.2 | CQL spec 3.4.4 | Native protocol v4]
   Use HELP for help.
   cqlsh current consistency level is ONE.
   ```

1. Sebelum Anda dapat menulis data ke tabel Amazon Keyspaces menggunakan cqlsh, Anda harus mengatur konsistensi tulis untuk sesi cqlsh saat ini. `LOCAL_QUORUM` Untuk informasi selengkapnya tentang tingkat konsistensi yang didukung, lihat[Tulis tingkat konsistensi](consistency.md#WriteConsistency). Perhatikan bahwa langkah ini tidak diperlukan jika Anda menggunakan editor CQL di. Konsol Manajemen AWS

   ```
   CONSISTENCY LOCAL_QUORUM;
   ```

1. Untuk menyisipkan satu catatan, jalankan perintah berikut di editor CQL.

   ```
   INSERT INTO catalog.book_awards (award, year, category, rank, author, book_title, publisher)
   VALUES ('Wolf', 2023, 'Fiction',3,'Shirley Rodriguez','Mountain', 'AnyPublisher') ;
   ```

1. Verifikasi bahwa data telah ditambahkan dengan benar ke tabel Anda dengan menjalankan perintah berikut.

   ```
   SELECT * FROM catalog.book_awards;
   ```

   Output dari pernyataan akan terlihat seperti ini.

   ```
    year | award | category | rank | author            | book_title | publisher
   ------+-------+----------+------+-------------------+------------+--------------
    2023 |  Wolf |  Fiction |    3 | Shirley Rodriguez |   Mountain | AnyPublisher
   
   (1 rows)
   ```

**Untuk menyisipkan beberapa catatan dari file menggunakan cqlsh**

1. Unduh contoh file CSV (`keyspaces_sample_table.csv`) yang terkandung dalam file arsip [samplemigration.zip](samples/samplemigration.zip). Buka zip arsip dan catat jalur ke`keyspaces_sample_table.csv`.  
![\[Tangkapan layar file CSV yang menunjukkan output tabel setelah mengimpor file csv.\]](http://docs.aws.amazon.com/id_id/keyspaces/latest/devguide/images/keyspaces-awards.png)

1. Buka AWS CloudShell di Konsol Manajemen AWS dan sambungkan ke Amazon Keyspaces menggunakan perintah berikut. Pastikan untuk memperbarui *us-east-1* dengan Wilayah Anda sendiri.

   ```
   cqlsh-expansion cassandra.us-east-1.amazonaws.com 9142 --ssl
   ```

1. Pada `cqlsh` prompt (`cqlsh>`), tentukan ruang kunci.

   ```
   USE catalog ;
   ```

1. Tetapkan konsistensi tulis ke`LOCAL_QUORUM`. Untuk informasi selengkapnya tentang tingkat konsistensi yang didukung, lihat[Tulis tingkat konsistensi](consistency.md#WriteConsistency).

   ```
   CONSISTENCY LOCAL_QUORUM;
   ```

1. Dalam AWS CloudShell pilih **Tindakan** di sisi kanan atas layar dan kemudian pilih **Unggah file untuk mengunggah file** csv yang diunduh sebelumnya. Catat jalur ke file.

1. Pada prompt keyspace (`cqlsh:catalog>`), jalankan pernyataan berikut.

   ```
   COPY book_awards (award, year, category, rank, author, book_title, publisher) FROM '/home/cloudshell-user/keyspaces_sample_table.csv' WITH header=TRUE ;
   ```

   Output dari pernyataan harus terlihat mirip dengan ini.

   ```
   cqlsh:catalog> COPY book_awards (award, year, category, rank, author, book_title, publisher)                      FROM '/home/cloudshell-user/keyspaces_sample_table.csv' WITH delimiter=',' AND header=TRUE ;
   cqlsh current consistency level is LOCAL_QUORUM.
   Reading options from /home/cloudshell-user/.cassandra/cqlshrc:[copy]: {'numprocesses': '16', 'maxattempts': '1000'}
   Reading options from /home/cloudshell-user/.cassandra/cqlshrc:[copy-from]: {'ingestrate': '1500', 'maxparseerrors': '1000', 'maxinserterrors': '-1', 'maxbatchsize': '10', 'minbatchsize': '1', 'chunksize': '30'}
   Reading options from the command line: {'delimiter': ',', 'header': 'TRUE'}
   Using 16 child processes
   
   Starting copy of catalog.book_awards with columns [award, year, category, rank, author, book_title, publisher].
   OSError: handle is closed      0 rows/s; Avg. rate:       0 rows/s
   Processed: 9 rows; Rate:       0 rows/s; Avg. rate:       0 rows/s
   9 rows imported from 1 files in 0 day, 0 hour, 0 minute, and 26.706 seconds (0 skipped).
   ```

1. Verifikasi bahwa data telah ditambahkan dengan benar ke tabel Anda dengan menjalankan kueri berikut.

   ```
   SELECT * FROM book_awards ;
   ```

   Anda akan melihat output berikut.

   ```
    year | award            | category    | rank | author             | book_title            | publisher
   ------+------------------+-------------+------+--------------------+-----------------------+---------------
    2020 |             Wolf | Non-Fiction |    1 |        Wang Xiulan |      History of Ideas | Example Books
    2020 |             Wolf | Non-Fiction |    2 | Ana Carolina Silva |         Science Today | SomePublisher
    2020 |             Wolf | Non-Fiction |    3 |  Shirley Rodriguez | The Future of Sea Ice |  AnyPublisher
    2020 | Kwesi Manu Prize |     Fiction |    1 |         Akua Mansa |     Where did you go? | SomePublisher
    2020 | Kwesi Manu Prize |     Fiction |    2 |        John Stiles |             Yesterday | Example Books
    2020 | Kwesi Manu Prize |     Fiction |    3 |         Nikki Wolf | Moving to the Chateau |  AnyPublisher
    2020 |      Richard Roe |     Fiction |    1 |  Alejandro Rosalez |           Long Summer | SomePublisher
    2020 |      Richard Roe |     Fiction |    2 |        Arnav Desai |               The Key | Example Books
    2020 |      Richard Roe |     Fiction |    3 |      Mateo Jackson |      Inside the Whale |  AnyPublisher
   
   (9 rows)
   ```

Untuk mempelajari lebih lanjut tentang cara `cqlsh COPY` mengunggah data dari file csv ke tabel Amazon Keyspaces, lihat. [Tutorial: Memuat data ke Amazon Keyspaces menggunakan cqlsh](bulk-upload.md)