ערוך

שתף באמצעות


Azure Digital Twins query language

This article describes the basics of the query language and its capabilities. Recall that the center of Azure Digital Twins is the twin graph, constructed from digital twins and relationships. This graph can be queried to get information about the digital twins and relationships it contains. These queries are written in a custom SQL-like query language, referred to as the Azure Digital Twins query language. This language is similar to the IoT Hub query language with many comparable features.

For more detailed examples of query syntax and how to run query requests, see Query the twin graph.

About the queries

You can use the Azure Digital Twins query language to retrieve digital twins according to their...

  • Properties (including tag properties)
  • Models
  • Relationships
    • Properties of the relationships

To submit a query to the service from a client app, you'll use the Azure Digital Twins Query API. One way to use the API is through one of the SDKs for Azure Digital Twins.

Reference documentation

The Query language reference can be found under Reference in the left table of contents for the Azure Digital Twins documentation. You can also go directly to the reference sections using the links below:

Considerations for querying

When writing queries for Azure Digital Twins, keep the following considerations in mind:

  • Remember case sensitivity: All Azure Digital Twins query operations are case-sensitive, so take care to use the exact names defined in the models. If property names are misspelled or incorrectly cased, the result set is empty with no errors returned.

  • Escape single quotes: If your query text includes a single quote character in the data, the quote will need to be escaped with the \ character. Here's an example that deals with a property value of D'Souza:

    SELECT * FROM DIGITALTWINS WHERE Name = 'D\'Souza'
    

Note

After making a change to the data in your graph, there may be a latency of up to 10 seconds before the changes will be reflected in queries.

The DigitalTwins API reflects changes immediately, so if you need an instant response, use an API request (DigitalTwins GetById) or an SDK call (GetDigitalTwin) to get twin data instead of a query.

Querying historized twin data over time

The Azure Digital Twins query language is only for querying the present state of your digital twins and relationships.

To run queries on historized twin graph data collected over time, use the data history feature to connect your Azure Digital Twins instance to an Azure Data Explorer cluster. This will automatically historize graph updates to Azure Data Explorer, where they can be queried using the Azure Digital Twins plugin for Azure Data Explorer.

Next steps

Learn how to write queries and see client code examples in Query the twin graph.