Skip to content

Commit 7b87b17

Browse files
authored
Updates for Golang
1 parent ce6407a commit 7b87b17

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

articles/cosmos-db/cassandra/find-request-unit-charge-cassandra.md

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ ms.service: cosmos-db
77
ms.subservice: cosmosdb-cassandra
88
ms.topic: how-to
99
ms.date: 10/14/2020
10-
ms.devlang: csharp, java
11-
ms.custom: devx-track-csharp, devx-track-java
10+
ms.devlang: csharp, java, golang
11+
ms.custom: devx-track-csharp, devx-track-java, devx-track-golang
1212
---
1313
# Find the request unit charge for operations executed in Azure Cosmos DB Cassandra API
1414
[!INCLUDE[appliesto-cassandra-api](../includes/appliesto-cassandra-api.md)]
@@ -21,7 +21,7 @@ This article presents the different ways you can find the [request unit](../requ
2121

2222
When you perform operations against the Azure Cosmos DB Cassandra API, the RU charge is returned in the incoming payload as a field named `RequestCharge`. You have multiple options for retrieving the RU charge.
2323

24-
## Use the .NET SDK
24+
## [.NET SDK](#tab/dotnet-sdk)
2525

2626
When you use the [.NET SDK](https://www.nuget.org/packages/CassandraCSharpDriver/), you can retrieve the incoming payload under the `Info` property of a `RowSet` object:
2727

@@ -32,7 +32,7 @@ double requestCharge = BitConverter.ToDouble(rowSet.Info.IncomingPayload["Reques
3232

3333
For more information, see [Quickstart: Build a Cassandra app by using the .NET SDK and Azure Cosmos DB](manage-data-dotnet.md).
3434

35-
## Use the Java SDK
35+
## [Java SDK](#tab/java-sdk)
3636

3737
When you use the [Java SDK](https://mvnrepository.com/artifact/com.datastax.cassandra/cassandra-driver-core), you can retrieve the incoming payload by calling the `getExecutionInfo()` method on a `ResultSet` object:
3838

@@ -43,6 +43,22 @@ Double requestCharge = resultSet.getExecutionInfo().getIncomingPayload().get("Re
4343

4444
For more information, see [Quickstart: Build a Cassandra app by using the Java SDK and Azure Cosmos DB](manage-data-java.md).
4545

46+
## [GOCQL Driver](#tab/gocql-driver)
47+
48+
When you use the [GOCQL driver](https://github.com/gocql/gocql), you can retrieve the incoming payload by calling the `GetCustomPayload()` method on a [`Iter`](https://pkg.go.dev/github.com/gocql/gocql#Iter) type:
49+
50+
```go
51+
query := session.Query(fmt.Sprintf("SELECT * FROM <keyspace.table> where <value> = ?", keyspace, table)).Bind(<value>)
52+
iter := query.Iter()
53+
requestCharge := iter.GetCustomPayload()["RequestCharge"]
54+
requestChargeBits := binary.BigEndian.Uint64(requestCharge)
55+
requestChargeValue := math.Float64frombits(requestChargeBits)
56+
fmt.Printf("%v\n", requestChargeValue)
57+
```
58+
59+
For more information, see [Quickstart: Build a Cassandra app by using GOCQL and Azure Cosmos DB](manage-data-go.md).
60+
61+
---
4662
## Next steps
4763

4864
To learn about optimizing your RU consumption, see these articles:

0 commit comments

Comments
 (0)