Skip to content

Commit c576bc9

Browse files
authored
Merge pull request #186632 from iriaosara/cqlsh_quickstart
Adding cqlsh quickstart
2 parents f33a011 + b7fcee6 commit c576bc9

File tree

2 files changed

+110
-0
lines changed

2 files changed

+110
-0
lines changed

articles/cosmos-db/TOC.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,6 +1007,8 @@
10071007
href: cassandra/manage-data-python.md
10081008
- name: Golang
10091009
href: cassandra/manage-data-go.md
1010+
- name: CQLSH
1011+
href: cassandra/manage-data-cqlsh.md
10101012
- name: Tutorials
10111013
items:
10121014
- name: 1 - Create and manage data
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
---
2+
title: 'Quickstart: Cassandra API with CQLSH - Azure Cosmos DB'
3+
description: This quickstart shows how to use the Azure Cosmos DB's Apache Cassandra API to create a profile application using CQLSH.
4+
author: iriaosara
5+
ms.author: iriaosara
6+
ms.service: cosmos-db
7+
ms.subservice: cosmosdb-cassandra
8+
ms.topic: quickstart
9+
ms.date: 01/24/2022
10+
ms.custom: template-quickstart
11+
---
12+
13+
14+
# Quickstart: Build a Cassandra app with CQLSH and Azure Cosmos DB
15+
[!INCLUDE[appliesto-cassandra-api](../includes/appliesto-cassandra-api.md)]
16+
17+
> [!div class="op_single_selector"]
18+
> * [.NET](manage-data-dotnet.md)
19+
> * [.NET Core](manage-data-dotnet-core.md)
20+
> * [Java v3](manage-data-java.md)
21+
> * [Java v4](manage-data-java-v4-sdk.md)
22+
> * [Node.js](manage-data-nodejs.md)
23+
> * [Python](manage-data-python.md)
24+
> * [Golang](manage-data-go.md)
25+
26+
In this quickstart, you create an Azure Cosmos DB Cassandra API account, and use CQLSH to create a Cassandra database and container. Azure Cosmos DB is a multi-model database service that lets you quickly create and query document, table, key-value, and graph databases with global distribution and horizontal scale capabilities.
27+
28+
29+
## Prerequisites
30+
- An Azure account with an active subscription. [Create one for free](https://azure.microsoft.com/free/?ref=microsoft.com&utm_source=microsoft.com&utm_medium=docs&utm_campaign=visualstudio). Or [try Azure Cosmos DB for free](https://azure.microsoft.com/try/cosmosdb/) without an Azure subscription.
31+
32+
## Create a database account
33+
34+
Before you can create a document database, you need to create a Cassandra account with Azure Cosmos DB.
35+
36+
[!INCLUDE [cosmos-db-create-dbaccount-cassandra](../includes/cosmos-db-create-dbaccount-cassandra.md)]
37+
38+
## Install standalone CQLSH tool
39+
40+
Refer to [CQL shell](cassandra-support.md#cql-shell) on steps on how to launch a standalone cqlsh tool.
41+
42+
43+
## Update your connection string
44+
45+
Now go back to the Azure portal to get your connection string information and copy it into the app. The connection string details enable your app to communicate with your hosted database.
46+
47+
1. In your Azure Cosmos DB account in the [Azure portal](https://portal.azure.com/), select **Connection String**.
48+
49+
:::image type="content" source="./media/manage-data-java/copy-username-connection-string-azure-portal.png" alt-text="View and copy a username from the Azure portal, Connection String page":::
50+
51+
2. Use the :::image type="icon" source="./media/manage-data-java/copy-button-azure-portal.png"::: button on the right side of the screen to copy the USERNAME and PASSWORD value.
52+
53+
3. In your terminal, set the SSL variables:
54+
```bash
55+
# Export the SSL variables:
56+
export SSL_VERSION=TLSv1_2
57+
export SSL_VALIDATE=false
58+
```
59+
60+
4. Connect to Azure Cosmos DB API for Cassandra:
61+
- Paste the USERNAME and PASSWORD value into the command.
62+
```sql
63+
cqlsh <USERNAME>.cassandra.cosmos.azure.com 10350 -u <USERNAME> -p <PASSWORD> --ssl --protocol-version=4
64+
```
65+
66+
67+
## CQL commands to create and run an app
68+
- Create keyspace
69+
```sql
70+
CREATE KEYSPACE IF NOT EXISTS uprofile
71+
WITH REPLICATION = { 'class' : 'NetworkTopologyStrategy', 'datacenter1' : 1 };
72+
```
73+
- Create a table
74+
```sql
75+
CREATE TABLE IF NOT EXISTS uprofile.user (user_id int PRIMARY KEY, user_name text, user_bcity text);
76+
```
77+
- Insert a row into user table
78+
```sql
79+
INSERT INTO uprofile.user (user_id, user_name, user_bcity) VALUES (101,'johnjoe','New York')
80+
```
81+
You can also insert data using the COPY command.
82+
```sql
83+
COPY uprofile.user(user_id, user_name, user_bcity) FROM '/path to file/fileName.csv'
84+
WITH DELIMITER = ',' ;
85+
```
86+
- Query the user table
87+
```sql
88+
SELECT * FROM uprofile.users;
89+
```
90+
91+
In the Azure portal, open **Data Explorer** to query, modify, and work with this new data.
92+
:::image type="content" source="./media/manage-data-java/view-data-explorer-java-app.png" alt-text="View the data in Data Explorer - Azure Cosmos DB":::
93+
94+
95+
## Review SLAs in the Azure portal
96+
97+
[!INCLUDE [cosmosdb-tutorial-review-slas](../includes/cosmos-db-tutorial-review-slas.md)]
98+
99+
## Clean up resources
100+
101+
[!INCLUDE [cosmosdb-delete-resource-group](../includes/cosmos-db-delete-resource-group.md)]
102+
103+
## Next steps
104+
105+
In this quickstart, you learned how to create an Azure Cosmos DB account with Cassandra API using CQLSH that creates a Cassandra database and container. You can now import additional data into your Azure Cosmos DB account.
106+
107+
> [!div class="nextstepaction"]
108+
> [Import Cassandra data into Azure Cosmos DB](migrate-data.md)

0 commit comments

Comments
 (0)