Query - Query Twins
执行允许遍历关系和按属性值筛选的查询。 状态代码:
- 200 正常
- 400 错误的请求
- BadRequest - 延续标记无效。
- SqlQueryError - 查询包含一些错误。
- TimeoutError - 查询执行在 60 秒后超时。 尝试简化查询或添加条件以减小结果大小。
- 429 请求次数过多
- QuotaReachedError - 已达到最大查询速率限制。
POST https://digitaltwins-hostname/query?api-version=2023-10-31
URI 参数
名称 | 在 | 必需 | 类型 | 说明 |
---|---|---|---|---|
api-version
|
query | True |
string |
请求的 API 版本。 |
请求头
名称 | 必需 | 类型 | 说明 |
---|---|---|---|
max-items-per-page |
integer |
每个请求要检索的最大项数。 服务器可以选择返回小于请求的数字。 |
|
traceparent |
string |
标识分布式跟踪系统中的请求。 |
|
tracestate |
string |
提供特定于供应商的跟踪标识信息,并且是 traceparent 的配套信息。 |
请求正文
名称 | 类型 | 说明 |
---|---|---|
continuationToken |
string |
用于从上一个查询检索下一组结果的标记。 |
query |
string |
要执行的查询。 如果提供了延续标记,则忽略此值。 |
响应
名称 | 类型 | 说明 |
---|---|---|
200 OK |
成功 Headers query-charge: number |
|
Other Status Codes |
默认响应。 Headers x-ms-error-code: string |
安全性
oauth2
Type:
oauth2
Flow:
implicit
Authorization URL:
https://login.microsoftonline.com/common/oauth2/authorize?resource=0b07f429-9f4b-4714-9392-cc5e8e80c8b0
示例
Query for digital twins |
Query for digital twins through a relationship |
Retrieve paged query results |
Query for digital twins
Sample Request
POST https://digitaltwins-hostname/query?api-version=2023-10-31
{
"query": "SELECT * FROM DIGITALTWINS WHERE temp = 79"
}
Sample Response
{
"value": [
{
"$dtId": "Twin-01",
"$metadata": {
"$lastUpdateTime": "2022-02-28T00:30:00.1234567Z",
"$model": "dtmi:com:example:Sample;1",
"name": {
"lastUpdateTime": "2022-02-28T00:30:00.1234567Z"
},
"temp": {
"lastUpdateTime": "2022-02-28T00:30:00.1234567Z"
},
"comfortIndex": {
"lastUpdateTime": "2022-02-28T00:30:00.1234567Z"
}
},
"name": "Sample01",
"temp": 79,
"comfortIndex": 50
},
{
"$dtId": "Twin-02",
"$metadata": {
"$lastUpdateTime": "2022-02-28T00:29:00.1234567Z",
"$model": "dtmi:com:example:Sample;1",
"name": {
"lastUpdateTime": "2022-02-28T00:29:00.1234567Z"
},
"temp": {
"lastUpdateTime": "2022-02-28T00:29:00.1234567Z",
"sourceTime": "2022-05-31T12:00:00.000125009Z"
},
"comfortIndex": {
"lastUpdateTime": "2022-02-28T00:29:00.1234567Z"
}
},
"name": "Sample02",
"temp": 79,
"comfortIndex": 50
},
{
"$dtId": "Twin-03",
"$metadata": {
"$lastUpdateTime": "2022-02-28T00:31:00.1234567Z",
"$model": "dtmi:com:example:Sample;1",
"name": {
"lastUpdateTime": "2022-02-28T00:31:00.1234567Z"
},
"temp": {
"lastUpdateTime": "2022-02-28T00:31:00.1234567Z"
},
"comfortIndex": {
"lastUpdateTime": "2022-02-28T00:31:00.1234567Z"
}
},
"name": "Sample03",
"temp": 79,
"comfortIndex": 50
}
],
"continuationToken": "<token>"
}
Query for digital twins through a relationship
Sample Request
POST https://digitaltwins-hostname/query?api-version=2023-10-31
{
"query": "SELECT Widget, Gadget FROM DIGITALTWINS Widget JOIN Gadget RELATED Widget.Contains WHERE Widget.$dtId = 'Twin-01'"
}
Sample Response
{
"value": [
{
"Widget": {
"$dtId": "Twin-01",
"$metadata": {
"$lastUpdateTime": "2022-02-28T00:30:00.1234567Z",
"$model": "dtmi:com:example:Sample;1",
"name": {
"lastUpdateTime": "2022-02-28T00:30:00.1234567Z"
},
"temp": {
"lastUpdateTime": "2022-02-28T00:30:00.1234567Z"
},
"comfortIndex": {
"lastUpdateTime": "2022-02-28T00:30:00.1234567Z"
}
},
"name": "Sample01",
"temp": 79,
"comfortIndex": 50
},
"Gadget": {
"$dtId": "Twin-02",
"$metadata": {
"$lastUpdateTime": "2022-02-28T00:30:00.1234567Z",
"$model": "dtmi:com:example:Sample;1",
"name": {
"lastUpdateTime": "2022-02-28T00:30:00.1234567Z"
},
"temp": {
"lastUpdateTime": "2022-02-28T00:30:00.1234567Z"
},
"comfortIndex": {
"lastUpdateTime": "2022-02-28T00:30:00.1234567Z"
}
},
"name": "Sample02",
"temp": 79,
"comfortIndex": 50
}
},
{
"Widget": {
"$dtId": "Twin-01",
"$metadata": {
"$lastUpdateTime": "2022-02-28T00:30:00.1234567Z",
"$model": "dtmi:com:example:Sample;1",
"name": {
"lastUpdateTime": "2022-02-28T00:30:00.1234567Z"
},
"temp": {
"lastUpdateTime": "2022-02-28T00:30:00.1234567Z"
},
"comfortIndex": {
"lastUpdateTime": "2022-02-28T00:30:00.1234567Z"
}
},
"name": "Sample01",
"temp": 79,
"comfortIndex": 50
},
"Gadget": {
"$dtId": "Twin-10",
"$metadata": {
"$lastUpdateTime": "2022-02-28T00:30:00.1234567Z",
"$model": "dtmi:com:example:Sample;1",
"name": {
"lastUpdateTime": "2022-02-28T00:30:00.1234567Z"
},
"temp": {
"lastUpdateTime": "2022-02-28T00:30:00.1234567Z"
},
"comfortIndex": {
"lastUpdateTime": "2022-02-28T00:30:00.1234567Z"
}
},
"name": "Sample10",
"temp": 79,
"comfortIndex": 50
}
}
]
}
Retrieve paged query results
Sample Request
POST https://digitaltwins-hostname/query?api-version=2023-10-31
{
"continuationToken": "<continuationToken from previous query>"
}
Sample Response
{
"value": [
{
"$dtId": "Twin-04",
"$metadata": {
"$lastUpdateTime": "2022-02-28T00:30:00.1234567Z",
"$model": "dtmi:com:example:Sample;1",
"name": {
"lastUpdateTime": "2022-02-28T00:30:00.1234567Z"
},
"temp": {
"lastUpdateTime": "2022-02-28T00:30:00.1234567Z"
},
"comfortIndex": {
"lastUpdateTime": "2022-02-28T00:30:00.1234567Z"
}
},
"name": "Sample04",
"temp": 79,
"comfortIndex": 50
},
{
"$dtId": "Twin-05",
"$metadata": {
"$lastUpdateTime": "2022-02-28T00:30:00.1234567Z",
"$model": "dtmi:com:example:Sample;1",
"name": {
"lastUpdateTime": "2022-02-28T00:30:00.1234567Z"
},
"temp": {
"lastUpdateTime": "2022-02-28T00:30:00.1234567Z"
},
"comfortIndex": {
"lastUpdateTime": "2022-02-28T00:30:00.1234567Z"
}
},
"name": "Sample05",
"temp": 79,
"comfortIndex": 50
},
{
"$dtId": "Twin-06",
"$metadata": {
"$lastUpdateTime": "2022-02-28T00:30:00.1234567Z",
"$model": "dtmi:com:example:Sample;1",
"name": {
"lastUpdateTime": "2022-02-28T00:30:00.1234567Z"
},
"temp": {
"lastUpdateTime": "2022-02-28T00:30:00.1234567Z"
},
"comfortIndex": {
"lastUpdateTime": "2022-02-28T00:30:00.1234567Z"
}
},
"name": "Sample06",
"temp": 79,
"comfortIndex": 50
}
]
}
定义
名称 | 说明 |
---|---|
Error |
错误定义。 |
Error |
错误响应。 |
Inner |
比包含的错误提供的更具体的错误说明。 |
Query |
查询操作的结果和可选的继续标记。 |
Query |
包含查询语句或上一查询结果中的延续标记的查询规范。 |
Error
错误定义。
名称 | 类型 | 说明 |
---|---|---|
code |
string |
服务特定的错误代码,用作 HTTP 错误代码的子状态。 |
details |
Error[] |
内部错误详细信息。 |
innererror |
一个 对象,该对象包含比当前对象更具体的错误信息。 |
|
message |
string |
错误的可读表示形式。 |
ErrorResponse
错误响应。
名称 | 类型 | 说明 |
---|---|---|
error |
错误详细信息。 |
InnerError
比包含的错误提供的更具体的错误说明。
名称 | 类型 | 说明 |
---|---|---|
code |
string |
比包含的错误提供的更具体的错误代码。 |
innererror |
一个 对象,该对象包含比当前对象更具体的错误信息。 |
QueryResult
查询操作的结果和可选的继续标记。
名称 | 类型 | 说明 |
---|---|---|
continuationToken |
string |
可用于构造新的 QuerySpecification 以检索下一组结果的标记。 |
value |
object[] |
查询结果。 |
QuerySpecification
包含查询语句或上一查询结果中的延续标记的查询规范。
名称 | 类型 | 说明 |
---|---|---|
continuationToken |
string |
用于从上一个查询检索下一组结果的标记。 |
query |
string |
要执行的查询。 如果提供了延续标记,则忽略此值。 |
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈