Skip to content

Commit 98fc7ef

Browse files
committed
Metadata updated, minor Acrolinx fixes to improve score
1 parent d630768 commit 98fc7ef

File tree

1 file changed

+26
-27
lines changed

1 file changed

+26
-27
lines changed

articles/digital-twins/how-to-query-graph.md

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ titleSuffix: Azure Digital Twins
55
description: See how to query the Azure Digital Twins twin graph for information.
66
author: baanders
77
ms.author: baanders # Microsoft employees only
8-
ms.date: 03/02/2023
8+
ms.date: 03/06/2025
99
ms.topic: how-to
1010
ms.service: azure-digital-twins
1111

@@ -19,16 +19,16 @@ ms.service: azure-digital-twins
1919

2020
This article offers query examples and instructions for using the *Azure Digital Twins query language* to query your [twin graph](concepts-twins-graph.md) for information. (For an introduction to the query language, see [Query language](concepts-query-language.md).)
2121

22-
The article contains sample queries that illustrate the query language structure and common query operations for digital twins. It also describes how to run your queries after you've written them, using the [Azure Digital Twins Query API](/rest/api/digital-twins/dataplane/query) or an [SDK](concepts-apis-sdks.md#data-plane-overview).
22+
The article contains sample queries that illustrate the query language structure and common query operations for digital twins. It also describes how to run your queries after you write them, using the [Azure Digital Twins Query API](/rest/api/digital-twins/dataplane/query) or an [SDK](concepts-apis-sdks.md#data-plane-overview).
2323

2424
> [!NOTE]
25-
> If you're running the sample queries below with an API or SDK call, you'll need to condense the query text into a single line.
25+
> If you run the following sample queries with an API or SDK call, you need to condense the query text into a single line.
2626
2727
[!INCLUDE [digital-twins-query-reference.md](../../includes/digital-twins-query-reference.md)]
2828

2929
## Show all digital twins
3030

31-
Here's the basic query that will return a list of all digital twins in the instance:
31+
Here's the basic query that returns a list of all digital twins in the instance:
3232

3333
:::code language="sql" source="~/digital-twins-docs-samples/queries/examples.sql" id="GetAllTwins":::
3434

@@ -38,10 +38,10 @@ Get digital twins by properties (including ID and metadata):
3838

3939
:::code language="sql" source="~/digital-twins-docs-samples/queries/examples.sql" id="QueryByProperty1":::
4040

41-
As shown in the query above, the ID of a digital twin is queried using the metadata field `$dtId`.
41+
As shown in the previous query, the ID of a digital twin is queried using the metadata field `$dtId`.
4242

4343
>[!TIP]
44-
> If you are using Cloud Shell to run a query with metadata fields that begin with `$`, you should escape the `$` with a backslash to let Cloud Shell know it's not a variable and should be consumed as a literal in the query text.
44+
> If you're using Cloud Shell to run a query with metadata fields that begin with `$`, you should escape the `$` with a backslash to let Cloud Shell know it's not a variable and should be consumed as a literal in the query text.
4545
4646
You can also get twins based on whether a certain property is defined. Here's a query that gets twins that have a defined `Location` property:
4747

@@ -60,7 +60,7 @@ You can also get twins based on the type of a property. Here's a query that gets
6060
If a property is of the complex type `Map`, you can use the map keys and values directly in the query, like this:
6161
:::code language="sql" source="~/digital-twins-docs-samples/queries/examples.sql" id="QueryByProperty4":::
6262

63-
If the map key starts with a numeric character, you'll need to wrap the key in double square brackets (`[[<mapKey>]]`) to escape it in the query, similar to the strategy for [querying with reserved keywords](reference-query-reserved.md#escaping-reserved-keywords-in-queries).
63+
If the map key starts with a numeric character, you need to wrap the key in double square brackets (`[[<mapKey>]]`) to escape it in the query, similar to the strategy for [querying with reserved keywords](reference-query-reserved.md#escaping-reserved-keywords-in-queries).
6464

6565
## Query by model
6666

@@ -71,7 +71,7 @@ It considers [inheritance](concepts-models.md#model-inheritance) and model [vers
7171
* The twin directly implements the model provided to `IS_OF_MODEL()`, and the version number of the model on the twin is greater than or equal to the version number of the provided model
7272
* The twin implements a model that extends the model provided to `IS_OF_MODEL()`, and the twin's extended model version number is greater than or equal to the version number of the provided model
7373

74-
So for example, if you query for twins of the model `dtmi:example:widget;4`, the query will return all twins based on version 4 or greater of the widget model, and also twins based on version 4 or greater of any models that inherit from widget.
74+
So for example, if you query for twins of the model `dtmi:example:widget;4`, the query returns all twins based on version 4 or greater of the widget model, and also twins based on version 4 or greater of any models that inherit from widget.
7575

7676
`IS_OF_MODEL` can take several different parameters, and the rest of this section is dedicated to its different overload options.
7777

@@ -97,12 +97,12 @@ Here's a query example specifying a value for all three parameters:
9797

9898
## Query by relationship
9999

100-
When querying based on digital twins' relationships, the Azure Digital Twins query language has a special syntax.
100+
To query based on digital twins' relationships, the Azure Digital Twins query language provides a special syntax.
101101

102102
Relationships are pulled into the query scope in the `FROM` clause. Unlike in "classical" SQL-type languages, each expression in the `FROM` clause isn't a table; rather, the `FROM` clause expresses a cross-entity relationship traversal. To traverse across relationships, Azure Digital Twins uses a custom version of `JOIN`.
103103

104-
Recall that with the Azure Digital Twins [model](concepts-models.md) capabilities, relationships don't exist independently of twins, meaning that relationships here can't be queried independently and must be tied to a twin.
105-
To reflect this fact, the keyword `RELATED` is used in the `JOIN` clause to pull in the set of a certain type of relationship coming from the twin collection. The query must then filter in the `WHERE` clause, to indicate which specific twin(s) to use in the relationship query (using the twins' `$dtId` values).
104+
Recall that with the Azure Digital Twins [model](concepts-models.md) capabilities, relationships don't exist independently of twins. The result is that relationships can't be queried independently and must be tied to a twin.
105+
To reflect this fact, the keyword `RELATED` is used in the `JOIN` clause to pull in the set of a certain type of relationship coming from the twin collection. The query must then filter in the `WHERE` clause, to indicate which specific twins to use in the relationship query (using the twins' `$dtId` values).
106106

107107
The following sections give examples of what this looks like.
108108

@@ -112,10 +112,10 @@ Here's a sample relationship-based query. This code snippet selects all digital
112112

113113
:::code language="sql" source="~/digital-twins-docs-samples/queries/examples.sql" id="QueryByRelationship1":::
114114

115-
The type of the relationship (`contains` in the example above) is indicated using the relationship's `name` field from its [DTDL definition](concepts-models.md#basic-relationship-example).
115+
The type of the relationship (`contains` in the previous example) is indicated using the relationship's `name` field from its [DTDL definition](concepts-models.md#basic-relationship-example).
116116

117117
> [!NOTE]
118-
> The developer does not need to correlate this `JOIN` with a key value in the `WHERE` clause (or specify a key value inline with the `JOIN` definition). This correlation is computed automatically by the system, as the relationship properties themselves identify the target entity.
118+
> The developer doesn't need to correlate this `JOIN` with a key value in the `WHERE` clause (or specify a key value inline with the `JOIN` definition). The system automatically computes this correlation, as the relationship properties themselves identify the target entity.
119119
120120
### Query by the source or target of a relationship
121121

@@ -131,14 +131,13 @@ You can also start with the target of the relationship and trace the relationshi
131131

132132
### Query the properties of a relationship
133133

134-
Similarly to the way digital twins have properties described via DTDL, relationships can also have properties. You can query twins based on the properties of their relationships.
135-
The Azure Digital Twins query language allows filtering and projection of relationships, by assigning an alias to the relationship within the `JOIN` clause.
134+
Similar to the way that digital twins have properties described via DTDL, relationships can also have properties. You can query twins based on the properties of their relationships. The Azure Digital Twins query language allows filtering and projection of relationships, by assigning an alias to the relationship within the `JOIN` clause.
136135

137-
As an example, consider a `servicedBy` relationship that has a `reportedCondition` property. In the below query, this relationship is given an alias of `R` to reference its property.
136+
As an example, consider a `servicedBy` relationship that has a `reportedCondition` property. In the following query, this relationship is given an alias of `R` to reference its property.
138137

139138
:::code language="sql" source="~/digital-twins-docs-samples/queries/examples.sql" id="QueryByRelationship2":::
140139

141-
In the example above, note how `reportedCondition` is a property of the `servicedBy` relationship itself (NOT of some digital twin that has a `servicedBy` relationship).
140+
In the previous example, note how `reportedCondition` is a property of the `servicedBy` relationship itself (NOT of some digital twin that has a `servicedBy` relationship).
142141

143142
### Query with multiple JOINs
144143

@@ -156,7 +155,7 @@ You can count the number of items in a result set using the `Select COUNT` claus
156155

157156
:::code language="sql" source="~/digital-twins-docs-samples/queries/examples.sql" id="SelectCount1":::
158157

159-
Add a `WHERE` clause to count the number of items that meet a certain criteria. Here are some examples of counting with an applied filter based on the type of twin model (for more on this syntax, see [Query by model](#query-by-model) below):
158+
Add a `WHERE` clause to count the number of items that meet a certain criteria. The following examples demonstrate counting with an applied filter based on the type of twin model. For more information on this syntax, see [Query by model](#query-by-model).
160159

161160
:::code language="sql" source="~/digital-twins-docs-samples/queries/examples.sql" id="SelectCount2":::
162161

@@ -172,7 +171,7 @@ You can select the several "top" items in a query using the `Select TOP` clause.
172171

173172
## Filter results: specify return set with projections
174173

175-
By using projections in the `SELECT` statement, you can choose which columns a query will return. Projection is now supported for both primitive and complex properties. For more information about projections with Azure Digital Twins, see the [SELECT clause reference documentation](reference-query-clause-select.md#select-columns-with-projections).
174+
By using projections in the `SELECT` statement, you can choose which columns a query returns. Projection is now supported for both primitive and complex properties. For more information about projections with Azure Digital Twins, see the [SELECT clause reference documentation](reference-query-clause-select.md#select-columns-with-projections).
176175

177176
Here's an example of a query that uses projection to return twins and relationships. The following query projects the Consumer, Factory, and Edge from a scenario where a Factory with an ID of `ABC` is related to the Consumer through a relationship of `Factory.customer`, and that relationship is presented as the `Edge`.
178177

@@ -182,7 +181,7 @@ You can also use projection to return a property of a twin. The following query
182181

183182
:::code language="sql" source="~/digital-twins-docs-samples/queries/examples.sql" id="Projections2":::
184183

185-
You can also use projection to return a property of a relationship. Like in the previous example, the following query projects the `Name` property of the Consumers related to the Factory with an ID of `ABC` through a relationship of `Factory.customer`; but now it also returns two properties of that relationship, `prop1` and `prop2`. It does this by naming the relationship `Edge` and gathering its properties.
184+
You can also use projection to return a property of a relationship. Like in the previous example, the following query projects the `Name` property of the Consumers related to the Factory with an ID of `ABC` through a relationship of `Factory.customer`; but now it also returns two properties of that relationship, `prop1` and `prop2`. The query returns those two properties by naming the relationship `Edge` and gathering its properties.
186185

187186
:::code language="sql" source="~/digital-twins-docs-samples/queries/examples.sql" id="Projections3":::
188187

@@ -192,7 +191,7 @@ The following query does the same operations as the previous example, but it ali
192191

193192
:::code language="sql" source="~/digital-twins-docs-samples/queries/examples.sql" id="Projections4":::
194193

195-
Here's a similar query that queries the same set as above, but projects only the `Consumer.name` property as `consumerName`, and projects the complete Factory as a twin.
194+
Here's a similar query that queries the same set as the previous query, but projects only the `Consumer.name` property as `consumerName`, and projects the complete Factory as a twin.
196195

197196
:::code language="sql" source="~/digital-twins-docs-samples/queries/examples.sql" id="Projections5":::
198197

@@ -206,7 +205,7 @@ For example, consider a scenario in which Buildings contain Floors and Floors co
206205

207206
:::code language="sql" source="~/digital-twins-docs-samples/queries/examples.sql" id="INOperatorWithout":::
208207

209-
2. To find rooms, instead of considering the floors one-by-one and running a `JOIN` query to find the rooms for each one, you can query with a collection of the floors in the building (named Floor in the query below).
208+
2. To find rooms, instead of considering the floors one-by-one and running a `JOIN` query to find the rooms for each one, you can query with a collection of the floors in the building (named `Floor` in the following query).
210209

211210
In client app:
212211

@@ -220,7 +219,7 @@ For example, consider a scenario in which Buildings contain Floors and Floors co
220219

221220
## Other compound query examples
222221

223-
You can combine any of the above types of query using combination operators to include more detail in a single query. Here are some other examples of compound queries that query for more than one type of twin descriptor at once.
222+
You can combine any of the previously described types of query using combination operators to include more detail in a single query. Here are some other examples of compound queries that query for more than one type of twin descriptor at once.
224223

225224
* Out of the devices that Room 123 has, return the MxChip devices that serve the role of Operator
226225
:::code language="sql" source="~/digital-twins-docs-samples/queries/examples.sql" id="OtherExamples1":::
@@ -231,17 +230,17 @@ You can combine any of the above types of query using combination operators to i
231230

232231
## Run queries with the API
233232

234-
Once you've decided on a query string, you execute it by making a call to the [Query API](/rest/api/digital-twins/dataplane/query).
233+
Once you decide on a query string, you execute it by making a call to the [Query API](/rest/api/digital-twins/dataplane/query).
235234

236235
You can call the API directly, or use one of the [SDKs](concepts-apis-sdks.md#data-plane-overview) available for Azure Digital Twins.
237236

238237
The following code snippet illustrates the [.NET (C#) SDK](/dotnet/api/overview/azure/digitaltwins.core-readme) call from a client app:
239238

240239
:::code language="csharp" source="~/digital-twins-docs-samples/sdks/csharp/queries.cs" id="RunQuery":::
241240

242-
The query used in this call returns a list of digital twins, which the above example represents with [BasicDigitalTwin](/dotnet/api/azure.digitaltwins.core.basicdigitaltwin?view=azure-dotnet&preserve-view=true) objects. The return type of your data for each query will depend on what terms you specify with the `SELECT` statement:
243-
* Queries that begin with `SELECT * FROM ...` will return a list of digital twins (which can be serialized as `BasicDigitalTwin` objects, or other custom digital twin types that you may have created).
244-
* Queries that begin in the format `SELECT <A>, <B>, <C> FROM ...` will return a dictionary with keys `<A>`, `<B>`, and `<C>`.
241+
The query used in this call returns a list of digital twins, which the previous example represents with [BasicDigitalTwin](/dotnet/api/azure.digitaltwins.core.basicdigitaltwin?view=azure-dotnet&preserve-view=true) objects. The return type of your data for each query depends on what terms you specify with the `SELECT` statement:
242+
* Queries that begin with `SELECT * FROM ...` return a list of digital twins (which can be serialized as `BasicDigitalTwin` objects, or other custom digital twin types that you might create).
243+
* Queries that begin in the format `SELECT <A>, <B>, <C> FROM ...` return a dictionary with keys `<A>`, `<B>`, and `<C>`.
245244
* Other formats of `SELECT` statements can be crafted to return custom data. You might consider creating your own classes to handle customized result sets.
246245

247246
### Query with paging

0 commit comments

Comments
 (0)