Using sorting for tags

This section describes sorting and sorting syntax for tags, and provides sorting examples.

About sorting

Sorting is a special string that can be specified in RPC calls. Sorting can be combined with filters or used separately from them. A sorting for tags is a group of conditions that specify the order of returned tags.

For example, if you want to get tags by using the GetTags method of TagProvider, and you also want those tags to be sorted by event identifier in descending order, then you can use the following sorting to do so:

sort: {

tag_id: desc

}

For examples of using sorting, see subsection "Making tag requests with sorting" below.

Combining sorting with filters

Sorting can be combined with filters.

sort: {

tag_id: desc

}

filter: {

tag_id = 1000-1100

}

For an example of using filters with sorting, see subsections "Making tag requests with sorting" below.

Sorting condition syntax

Sorting conditions use the following syntax:

field : order

where field is the name of the field affected by the condition, and order is one of two values:

The following are examples of sorting conditions:

tag_id : desc

tag_name : asc

tag_description : asc

Field names (tag requests)

The following table summarizes field names that can be used in tag requests.

Field names (tag requests)

Field name

Description

tag_id

Tag identifier

tag_name

Tag name

tag_description

Tag description

Making tag requests with sorting

The following TagNotifier service method uses sorting:

The following is an example of using sorting to get tags with the GetTags method:

tagStub = tag_provider_service_pb2_grpc.TagProviderStub(channel)

 

request = tag_provider_service_pb2.TagsRequest(filter = "sort: { tag_id: asc, tag_name: desc, tag_description: asc}")

response = tagStub.GetTags(request)

for tag in response:

print("\n\n")

print("Tag:", tag.id,

"| Name:", tag.briefInfo.name,

"| Changed at:", datetime.datetime.utcfromtimestamp(tag.timestamp.seconds).strftime('%Y-%m-%d %H:%M:%S'))

The following is an example of combining sorting and filters to get a subset of tags with the GetTags method:

tagStub = tag_provider_service_pb2_grpc.TagProviderStub(channel)

 

request = tag_provider_service_pb2.TagsRequest(filter = "filter:{tag_id=1000-2000} sort:{tag_id:desc}")

response = tagStub.GetTags(request)

for tag in response:

print("\n\n")

print("Tag:", tag.id,

"| Name:", tag.briefInfo.name,

"| Changed at:", datetime.datetime.utcfromtimestamp(tag.timestamp.seconds).strftime('%Y-%m-%d %H:%M:%S'))

Page top