> For the complete documentation index, see [llms.txt](https://docs.panther.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.panther.com/ko/pantherflow/statements.md).

# PantherFlow 문

## 개요

{% hint style="info" %}
PantherFlow는 Panther 버전 1.110부터 오픈 베타로 제공되며, 모든 고객이 사용할 수 있습니다. 버그 보고와 기능 요청은 Panther 지원팀에 공유해 주세요.
{% endhint %}

PantherFlow 쿼리는 하나 이상의 문으로 구성됩니다. 문에는 두 가지 유형이 있습니다: [테이블형 식 문](#tabular-expression-statements) 그리고 [`let` 문](#let-statements).

같은 쿼리의 여러 문은 세미콜론(`;`). 마지막 문에는 세미콜론이 필요하지 않습니다.

## 테이블형 식 문

테이블형 식 문은 보통 "파이프 쿼리"라고 들으면 떠오르는 것입니다—데이터 원본과 일반적으로 하나 이상의 연산자로 구성되며, 이들은 파이프 문자(`|`). 각 연산자는 데이터를 받아 작업을 수행한 다음, 변환된 데이터를 다음 연산자에 전달합니다.

{% hint style="info" %}
다음에서 [검색](/ko/search/search-tool.md#using-pantherflow-in-search), 쿼리를 데이터베이스 및 테이블 이름(아래에 표시된 것처럼) 또는 `union` 연산자입니다. 이 둘 중 어느 것도 제공되지 않으면 Search는 [데이터베이스 및 테이블 드롭다운 필드](/ko/search/search-tool.md#using-database-table-and-date-range-filters).
{% endhint %}

```kusto
panther_logs.public.aws_cloudtrail
| where accountId != '1234567'
| summarize Count=agg.count() by eventName
| extend tooHigh = Count > 100
| where tooHigh
| sort Count
| limit 10
```

### 데이터 원본

각 PantherFlow 쿼리는 데이터 원본을 지정해야 합니다. 다음 중 어느 것이든 데이터 원본으로 사용할 수 있습니다:

* 테이블형 식 문
* [테이블 변수](#table-variables)
* [`datatable`](/ko/pantherflow/operators/datatable.md)
* [`union`](/ko/pantherflow/operators/union.md)
* [`range`](/ko/pantherflow/operators/range.md)

## `let` 문

A `let` 문은 이후 문에서 사용할 수 있는 변수에 값을 할당합니다. `let` 문은 두 가지 유형의 변수를 정의할 수 있습니다:

* **테이블 변수**: 테이블형 식을 나타내며, 이후에는 테이블처럼 사용할 수 있습니다
* **스칼라 변수**: 스칼라 값 또는 스칼라 값으로 평가되는 식을 나타냅니다

변수는 다음 문에서 `let` 참조되기 전에 정의되어야 합니다. 모든 `let` 문은 세미콜론(`;`) 다음에 다른 문이 뒤따를 경우로 끝나야 합니다.

### 테이블 변수

테이블 변수는 다음을 사용하여 테이블형 식 문을 변수에 할당할 때 생성됩니다 `let`. 그런 다음 테이블형 식 문처럼 참조할 수 있습니다(즉, 이는 가능한 [데이터 원본](#data-sources)).

테이블 변수에 할당된 테이블형 식 문은 변수가 이후 문에서 참조되거나, "호출"될 때까지 실행되지 않습니다.

테이블 변수로 쿼리에 이름을 붙이면 다음과 같은 경우 유용할 수 있습니다:

* 같은 쿼리를 두 번 이상 작성하고 싶지 않을 때
* 다른 사람들이 쿼리가 무엇을 하는지 더 쉽게 이해할 수 있게 하고 싶을 때

**예시**

다음 예제는 테이블 변수인 `elbOK`. 아래에서, `elbOK` 정의된 그대로 실행됩니다 `let` 문:

```kusto
let elbOK = panther_logs.public.aws_alb
| where elbStatusCode == 200;

elbOK
```

여기서 추가 연산자가 `elbOK` 테이블형 식 문 내에 적용됩니다:

```kusto
let elbOK = panther_logs.public.aws_alb
| where elbStatusCode == 200;

elbOK 
| where p_event_time > time.ago(1h)
```

테이블 변수를 데이터세트를 참조하는 어디에서나 사용할 수 있으며, 다음과 함께 사용할 수도 있습니다 [`union` 연산자](/ko/pantherflow/operators/union.md):

```kusto
let ec2Events = panther_logs.public.aws_cloudtrail
| where p_event_time > time.ago(1h)
| where eventSource == "ec2.amazonaws.com";

let s3Events = panther_logs.public.aws_cloudtrail
| where p_event_time > time.ago(1h)
| where eventSource == "s3.amazonaws.com";

union ec2Events, s3Events
| summarize count=agg.count() by eventName, eventSource
| sort count desc
```

### 스칼라 변수

비테이블형 식을 변수에 할당하면 스칼라 변수가 생성됩니다. 스칼라 변수는 이후 쿼리 전반에서 참조할 수 있습니다.

스칼라 변수를 선언하면 다음과 같은 경우 유용할 수 있습니다:

* 특히 동일한 값을 여러 번 사용할 때 쿼리를 더 읽기 쉽고 유지 관리하기 쉽게 만들 수 있습니다
* 그렇지 않으면 오해될 수 있는 값에 이름을 붙일 수 있습니다

다음 사항에 유의하세요 [아래의 스칼라 변수 제한 사항](#scalar-variable-limitations).

#### **예시**

다음 예제는 스칼라 변수인 `threshold`, 그런 다음 이를 [`where`](/ko/pantherflow/operators/where.md) 절에서 참조합니다:

```kusto
let threshold = 100;

panther_logs.public.aws_cloudtrail
| where p_event_time > time.ago(1d)
| summarize count=agg.count() by eventName
| where count > threshold
```

스칼라 변수의 값은 다음을 사용할 수 있습니다 [함수](/ko/pantherflow/functions.md), 또한 스칼라 변수는 함수의 매개변수로 사용할 수 있습니다:

```kusto
let domain = "example.com";
let searchSuffix = strings.cat("@", domain);

panther_logs.public.aws_cloudtrail
| where strings.ends_with(userIdentity.principalId, searchSuffix)
| summarize count=agg.count() by eventName
```

스칼라 변수와 함께 산술 식도 사용할 수 있습니다:

```kusto
let hourInSeconds = 60 * 60;
let dayInSeconds = hourInSeconds * 24;
let weekInSeconds = dayInSeconds * 7;

panther_logs.public.aws_cloudtrail
| extend ageInSeconds = time.diff("s", p_event_time, time.now())
| extend ageCategory = case(
    ageInSeconds < hourInSeconds, "1시간 미만",
    ageInSeconds < dayInSeconds, "하루 미만",
    ageInSeconds < weekInSeconds, "1주 미만",
    "1주 초과"
)
| summarize count=agg.count() by ageCategory
```

강력한 쿼리를 위해 스칼라 변수와 테이블 변수를 함께 사용할 수 있습니다:

```kusto
// 스칼라 변수
let minSeverity = 3;
let timeRange = 7d;
let criticalServices = ["ec2.amazonaws.com", "iam.amazonaws.com", "s3.amazonaws.com"];

// 테이블 변수
let baseQuery = panther_logs.public.aws_cloudtrail
| where p_event_time > time.ago(timeRange)
| where eventSource in criticalServices;

// 테이블 변수
let failedActions = baseQuery
| where errorCode != ""
| extend severity = case(
    errorCode == "AccessDenied", 4,
    errorCode == "UnauthorizedOperation", 3,
    strings.starts_with(errorCode, "Client"), 2,
    1
);

// 테이블형 식 문
failedActions
| where severity >= minSeverity
| summarize count=agg.count() by eventSource, errorCode, severity
| sort severity desc, count desc
```

### 변수 명명 규칙

변수 이름은 다음 규칙을 따라야 합니다:

* 첫 글자는 문자, 밑줄(`_`), 또는 달러 기호(`$`).
* 첫 글자 이후의 문자는 문자, 숫자 또는 밑줄이어야 합니다.
* 기존 테이블 이름은 변수 이름으로 사용할 수 없습니다.
  * 예를 들어, 이미 이름이 `aws_cloudtrail`, 다음을 사용할 수 없으며 `aws_cloudtrail` 변수 이름으로 사용할 수 없습니다.
* 한 번 사용된 변수 이름은 같은 PantherFlow 검색에서 다시 사용할 수 없습니다. 즉, 변수는 다시 정의할 수 없습니다.

**예시**

<table><thead><tr><th width="158.21954345703125">유효한 변수 이름</th><th width="360.1328125">유효하지 않은 변수 이름</th></tr></thead><tbody><tr><td><code>myVar123</code></td><td><code>123myVar</code> (숫자로 시작함)</td></tr><tr><td><code>my_var</code></td><td><code>my-var</code> (잘못된 문자)</td></tr><tr><td><code>_my_var</code></td><td><code>my.var</code> (잘못된 문자)</td></tr><tr><td><code>$my_var</code></td><td><code>my_var$</code> (<code>$</code> 첫 글자로만 허용됨)</td></tr></tbody></table>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.panther.com/ko/pantherflow/statements.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
