

Amazon Timestream for LiveAnalytics와 유사한 기능을 원하는 경우 Amazon Timestream for InfluxDB를 고려해 보세요. 간소화된 데이터 수집과 실시간 분석을 위한 10밀리초 미만의 쿼리 응답 시간을 제공합니다. [여기](https://docs.aws.amazon.com//timestream/latest/developerguide/timestream-for-influxdb.html)에서 자세히 알아보세요.

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# 함수 필터링 및 축소
<a name="timeseries-specific-constructs.functions.filter-reduce"></a>

Amazon Timestream은 시계열 데이터에 대한 필터를 수행하고 작업을 줄이기 위한 함수를 지원합니다. 이 섹션에서는 Timestream for LiveAnalytics 필터 및 감소 함수와 샘플 쿼리에 대한 사용 정보를 제공합니다.



## 사용 정보
<a name="w2aab7c59c13c13c23b7"></a>


| 함수 | 출력 데이터 유형 | 설명 | 
| --- | --- | --- | 
|  `filter(timeseries(T), function(T, Boolean))`  |  timeseries(T)  |  전달된 `function`이 `true`를 반환하는 값을 사용하여 입력 시계열에서 시계열을 구성합니다.  | 
|  `reduce(timeseries(T), initialState S, inputFunction(S, T, S), outputFunction(S, R))`  |  R  |  시계열에서 축소된 단일 값을 반환합니다. `inputFunction`은 각 요소에 대해 순서대로 시계열로 간접적으로 호출됩니다. 현재 요소를 가져오는 것 외에도 inputFunction은 현재 상태(처음에는 `initialState`)를 받아 새 상태를 반환합니다. `outputFunction`이 간접적으로 호출되어 최종 상태를 결과 값으로 바꿉니다. `outputFunction`은 항등 함수일 수 있습니다.  | 

## 쿼리 예제
<a name="w2aab7c59c13c13c23b9"></a>

**Example**  
측정값이 70보다 큰 호스트 및 필터 포인트의 CPU 사용률 시계열을 구성합니다.  

```
WITH time_series_view AS (
    SELECT INTERPOLATE_LINEAR(
        CREATE_TIME_SERIES(time, ROUND(measure_value::double,2)), 
            SEQUENCE(ago(15m), ago(1m), 10s)) AS cpu_user
    FROM sample.DevOps
    WHERE hostname = 'host-Hovjv' and measure_name = 'cpu_utilization'
        AND time > ago(30m)
    GROUP BY hostname
)
SELECT FILTER(cpu_user, x -> x.value > 70.0) AS cpu_above_threshold
from time_series_view
```

**Example**  
호스트의 CPU 사용률 시계열을 구성하고 측정값의 제곱 합계를 결정합니다.  

```
WITH time_series_view AS (
    SELECT INTERPOLATE_LINEAR(
        CREATE_TIME_SERIES(time, ROUND(measure_value::double,2)), 
            SEQUENCE(ago(15m), ago(1m), 10s)) AS cpu_user
    FROM sample.DevOps
    WHERE hostname = 'host-Hovjv' and measure_name = 'cpu_utilization'
        AND time > ago(30m)
    GROUP BY hostname
)
SELECT REDUCE(cpu_user,
    DOUBLE '0.0',
    (s, x) -> x.value * x.value + s,
    s -> s)
from time_series_view
```

**Example**  
호스트의 CPU 사용률 시계열을 구성하고 CPU 임곗값을 초과하는 샘플의 비율을 결정합니다.  

```
WITH time_series_view AS (
    SELECT INTERPOLATE_LINEAR(
        CREATE_TIME_SERIES(time, ROUND(measure_value::double,2)), 
            SEQUENCE(ago(15m), ago(1m), 10s)) AS cpu_user
    FROM sample.DevOps
    WHERE hostname = 'host-Hovjv' and measure_name = 'cpu_utilization'
        AND time > ago(30m)
    GROUP BY hostname
)
SELECT ROUND(
    REDUCE(cpu_user, 
      -- initial state 
      CAST(ROW(0, 0) AS ROW(count_high BIGINT, count_total BIGINT)),
      -- function to count the total points and points above a certain threshold
      (s, x) -> CAST(ROW(s.count_high + IF(x.value > 70.0, 1, 0), s.count_total + 1) AS ROW(count_high BIGINT, count_total BIGINT)),
      -- output function converting the counts to fraction above threshold
      s -> IF(s.count_total = 0, NULL, CAST(s.count_high AS DOUBLE) / s.count_total)), 
    4) AS fraction_cpu_above_threshold
from time_series_view
```