Execute Queries In Azure Cosmos DB For NoSQL #TestSeries

Which keyword represents all in a sql query?

*

When writing a SQL query to fetch results from an item, does the name of the source matter?

No

Which keyword is used to return distinct values from a query?

DISTINCT

Which keyword is used to flatten the results of a query?

VALUE

If using VALUE in a query, is it required to use DISTINCT?

No

Note – Each item in a container has a property called tags

What is the tags property?

The tags property is an array of objects with id and name properties.

Which function is used to check if the item has a tags property?

IS_DEFINED

Which function is used to check if the tags property defined for an item is of type array?

IS_ARRAY

Which function is used in each of the following cases –

  1. to lower the value – LOWER()
  2. to get the current date – GetCurrentDateTime()
  3. to concate values – CONCAT()

Which class is used in the SDK to define a query?

QueryDefinition

Which method of QueryDefinition is used to get the query results?

GetItemQueryIteratorThe asynchronous stream structure will automatically handle the looping and pagination to go to the server and get each subsequent page of results.

You are tasked with writing the shortest possible SQL query to select all items and include all fields from your container. Which of these queries is both valid and would accomplish this task?

select * from table

Which SQL keyword is used to flatten your query results into an array of a specific field value for each item?

VALUE

You have a container named products. What must the data source be named after the FROM keyword in the query?

We can use any name

What is the scope of JOIN in a NoSQL query?

single item

Which method is used in the SDK to add parameters to query?

.WithParameters(string,string)

Which class is used to support asynchronous streams to iterate over multiple pages of results?

Microsoft.Azure.Cosmos.Container

What are the steps to paginate a query result in SDK?

  1. define a SQL query string that you wish to execute and then use it as a constructor parameter for a variable of type QueryDefinition
  2. Build an object of type QueryRequestOptions using the MaxItemCount property to specify how many items you wish to return in each page
  3. Create a FeedIterator<> using your generic type and the GetItemQueryIterator method
  4. The feediterator class contains a HasMoreResults boolean property that indicates more pages to return server side. The iterator also has ReadNextAsync method that gets the next set of items into an enumerable collection that can be iterated in a for each loop.

You have a container of products with JSON documents that contain a string property named name. The JSON documents also all contain a property named tags that’s an array of string values. You’re tasked with authoring a SQL query that will create a cross-product of the document names and tags. Which SQL query should you use?

SELECT p.name, t FROM products p JOIN t IN p.tags

Which method of the Microsoft.Azure.Cosmos.Container class takes in a SQL query as a string parameter and returns an iterator that can be used to iterate over the query results as deserialized C# objects?

GetItemQueryIterator

Foolishly Yours,
Avantika

Happy Learning 🙂



Leave a comment