---
title: "getQueryData方法"
author: "kang"
date: "2010-01-19T11:08:59Z"
tags: []
categories: ["企业架构"]
slug: "getquerydata"
draft: false
lastmod: "2010-01-22T10:55:52Z"
id: 574588
url: "https://kang.iteye.com/blog/574588"
---

getQueryData方法，有6个参数，分别是：

实体id，查询类型，聚集层次，开始时间，结束时间，聚合周期。

该方法还带着一系列异常信息，捕获到这些异常就抛出。

 

getQueryData ( int  *entityId*,     [QueryType](/admin/blogs/a00100_gabfbb64a2ec7afa6cbb18aa171775c9ec.html#gabfbb64a2ec7afa6cbb18aa171775c9ec)  *queryType*,     [AggregationLevel](/admin/blogs/a00100_ga24113763b8f0700f5add77661e7f6e4f.html#ga24113763b8f0700f5add77661e7f6e4f)  *aggregationLevel*,     Date  *startTime*,     Date  *endTime*,     int  *aggPeriod*     )     throws [DcmIllegalIdException](/admin/blogs/a00017.html), [DcmIllegalQueryException](/admin/blogs/a00019.html), [DcmDataAccessException](/admin/blogs/a00009.html), [DcmIllegalArgumentException](/admin/blogs/a00015.html), [DcmCommunicationException](/admin/blogs/a00007.html)

Performs a query on collection data for the dates specified.  
When the requested entity represents a group, the returned value(s) takes into account collected data associated with all managed nodes within that group.

对于指定的日期范围，在收集的数据上，执行查询操作。

当请求的entity是一个group时，返回值就是这个group中包含的所有受管理node的收集数据的合计。

 

This method aggregates data over the aggPeriod specified.

这个方法在指定集聚周期上聚合数据。

Your aggPeriod must be a multiple of the largest measurement data granularity value. To get this value,call [getQueryAggregationPeriodList()](/admin/blogs/a00006_a4056b591c388a4059177c6b69f8f1531.html#a4056b591c388a4059177c6b69f8f1531 "Gets an array of aggregation periods you can use for getQueryData().")

你的聚合周期必须是最大存储数据粒度值的倍数。为了获取这个值，请调用方法[getQueryAggregationPeriodList()](/admin/blogs/a00006_a4056b591c388a4059177c6b69f8f1531.html#a4056b591c388a4059177c6b69f8f1531 "Gets an array of aggregation periods you can use for getQueryData().")。 

 

Note:  
Value of the query result data is aggregated from data?s time-aggPeriod to data?s time.

查询结果数据的值，是从开始时间到间隔时间来统计的。

 

For example, if query with BeginTime = 10:30:00, EndTime = 10:37:10, and aggPeriod = 180 seconds, assume data granularity is the default value (180 seconds), the query results are:

比如，假如查询的开始时间是10：30：00，结束时间是10：37：10，并且，聚集周期是180秒，假设数据粒度是默认值(180秒)，则查询结果是：

PTData1--Entity ID: 17,Time: 10:33:00,Value: 3030,  
PTData2--Entity ID: 17,Time: 10:36:00,Value: 3100,  
PTData3--Entity ID: 17,Time: 10:37:10,Value: -1  
PTData1?s value is aggregated from 10:30:00 to 10:33:00, and PTData2?s value is aggregated from 10:33:30 to 10:36:00. PTData3?s value is aggregated from 10:36:00 to 10:37:10, but there is no record so it return -1.

 

PTData1的值是从10：30：00统计到10：33：00，并且PTData2的值是从10：33：30统计到10：36：00；

yinyan说明：这边10：33：30中的30秒，应该是区别前一个PTData值和后一个是不同时间段的意思吧。sampling frequency应该是30秒，在这个例子的假设中。

 

PTData3的值是从10：36：00统计到10：37：10，但是这边没有记录(没有达到180秒)，就返回－1.

 

If you send this query at 10:30:00, the data is not returned because there is no aggPeriod from the BeginTime.

假如现在时间是10：30：00，你现在发送这个query，那么是没有数据能返回回来的，因为从开始时间算起没有聚合周期。(即从开始时间算起，相当于是想查询将来时间段的数据，此时肯定还没有数据记录呢)

 

**Parameters:**

  *entityId*  the unique identifier of the entity   *queryType*  the type of query.   *aggregationLevel*  the level to which to aggregate the collected data   *startTime*  The time at which to start the query. For queries that do not include a measurement granularity greater 360 seconds, use a multiple of 6 minutes (360 seconds). For queries with measurement granularity greater than 360 seconds, must be a multiple of the measurement granularity . A NULL value sets startTime to the earliest time in the database.   *endTime*  The time at which to end the query. A null value sets endTime to the latest time in the database.   *aggPeriod*  the period, in seconds, over which the collected data is aggregated. Must be a multiple of the largest measurement granularity value during the time range of this call. A value of 0 sets the aggPeriod to the smallest possible value. A value of -1 sets the aggPeriod to the largest possible value.  
To get the largest sampling frequency during the time range of this call, call [getQueryAggregationPeriodList()](/admin/blogs/a00006_a4056b591c388a4059177c6b69f8f1531.html#a4056b591c388a4059177c6b69f8f1531 "Gets an array of aggregation periods you can use for getQueryData().").

**--&gt;20100122追加：**

**关于aggPeriod：**

关于aggPeriod为0和-1时的解释：

aggPeriod为0，是getQueryAggregationPeriodList()方法 return 值(the value of aggregation period list for the time range 这个时间范围内采样周期的数组)中最大的一个。  
表示的意思是：这段时间内采样数据各周期的最小公倍数(但因为各个周期本身就是倍数关系，所以取最大数即可)。  
举例：现在查询的周期内，有两种采样周期的数据：3分钟和6分钟。假如aggPeriod值为0，则使用6分钟为查询周期。(假如使用3分钟，会导致6分钟采样周期的数据被生生”断开“，其实也是断不开的)

aggPeriod为-1，表示的意思是：endTime - startTime的值，跟默认值进行比较后修正为结果值。  
举例：endTime - startTime的值的结果为45分钟，而默认值是6分钟，则修正后的结果值为42分钟。(6×7+3=45)  
endTime - startTime的值的结果为42分钟，而默认值是6分钟，则结果值不需要修正，直接为42分钟。

 

**Returns:**

an array of data.

返回数据是数组类型的数据。

**Exceptions:**

  [*DcmIllegalIdException*](/admin/blogs/a00017.html "An invalid ID was entered.")  The *entityId* parameter is invalid.   [*DcmIllegalQueryException*](/admin/blogs/a00019.html "The query cannot be executed as requested.")  the query cannot be executed due to an incorrect time range, a time range beyond database maintenance period, a mismatch between the entity type and the aggregation type.   [*DcmDataAccessException*](/admin/blogs/a00009.html "There was a problem with the database access.")  The data in the database could not be accessed.   [*DcmIllegalArgumentException*](/admin/blogs/a00015.html "An argument was invalid.")  an argument is invalid.   [*DcmCommunicationException*](/admin/blogs/a00007.html "Intel(R) DCM failed to communicate with the node.")   

**See also:**

[DataAccess::getQueryAggregationPeriodList](/admin/blogs/a00006_a4056b591c388a4059177c6b69f8f1531.html#a4056b591c388a4059177c6b69f8f1531 "Gets an array of aggregation periods you can use for getQueryData().")