다음을 통해 공유


sample operator

Applies to: ✅Microsoft FabricAzure Data ExplorerAzure MonitorMicrosoft Sentinel

입력 테이블에서 지정된 난수의 행 수를 반환합니다.

Note

  • sample 는 값의 분포가 아닌 속도를 위해 준비됩니다. 특히, 연산자가 서로 다른 크기의 데이터 세트(예: a 또는 union 연산자)의 통합 2 데이터 세트를 연산자 이후에 사용하는 경우 '공정한' 결과를 생성하지 않음을 join 의미합니다. 테이블 참조 및 필터 바로 뒤를 사용하는 sample 것이 좋습니다.
  • sample 비결정적 연산자이며 쿼리 중에 평가될 때마다 다른 결과 집합을 반환합니다. 예를 들어 다음 쿼리는 두 개의 서로 다른 행을 생성합니다(동일한 행을 두 번 반환해야 하는 경우에도).

Syntax

T| sampleNumberOfRows

Learn more about syntax conventions.

Parameters

Name Type Required Description
T string ✔️ 입력 테이블 형식 식입니다.
NumberOfRows int, long 또는 real ✔️ 반환할 행 수입니다. 숫자 식을 지정할 수 있습니다.

Examples

이 섹션의 예제에서는 구문을 사용하여 시작하는 방법을 보여 주었습니다.

The examples in this article use publicly available tables in the help cluster, such as the StormEvents table in the Samples database.

The examples in this article use publicly available tables, such as the Weather table in the Weather analytics sample gallery. 작업 영역의 테이블과 일치하도록 예제 쿼리에서 테이블 이름을 수정해야 할 수 있습니다.

샘플 생성

이 쿼리는 숫자 범위를 만들고, 하나의 값을 샘플링한 다음, 해당 샘플을 복제합니다.

let _data = range x from 1 to 100 step 1;
let _sample = _data | sample 1;
union (_sample), (_sample)

Output

x
74
63

To ensure that in example above _sample is calculated once, one can use materialize() function:

let _data = range x from 1 to 100 step 1;
let _sample = materialize(_data | sample 1);
union (_sample), (_sample)

Output

x
24
24

특정 비율의 데이터 샘플 생성

지정된 행 수가 아닌 특정 비율의 데이터를 샘플링하려면

StormEvents | where rand() < 0.1

Output

테이블에는 출력의 처음 몇 행이 포함됩니다. 쿼리를 실행하여 전체 결과를 봅니다.

StartTime EndTime EpisodeId EventId State EventType
2007-01-01T00:00:00Z 2007-01-20T10:24:00Z 2403 11914 INDIANA Flood
2007-01-01T00:00:00Z 2007-01-24T18:47:00Z 2408 11930 INDIANA Flood
2007-01-01T00:00:00Z 2007-01-01T12:00:00Z 1979 12631 DELAWARE Heavy Rain
2007-01-01T00:00:00Z 2007-01-01T00:00:00Z 2592 13208 NORTH CAROLINA Thunderstorm Wind
2007-01-01T00:00:00Z 2007-01-31T23:59:00Z 1492 7069 MINNESOTA Drought
2007-01-01T00:00:00Z 2007-01-31T23:59:00Z 2240 10858 TEXAS Drought
... ... ... ... ... ...

키 샘플 생성

행이 아닌 키를 샘플링하려면(예: 샘플 10 ID 및 이러한 ID에 대한 모든 행 가져오기) sample-distinct 연산자와 함께 in 사용할 수 있습니다.

let sampleEpisodes = StormEvents | sample-distinct 10 of EpisodeId;
StormEvents
| where EpisodeId in (sampleEpisodes)

Output

테이블에는 출력의 처음 몇 행이 포함됩니다. 쿼리를 실행하여 전체 결과를 봅니다.

StartTime EndTime EpisodeId EventId State EventType
2007-09-18T20:00:00Z 2007-09-19T18:00:00Z 11074 60904 FLORIDA Heavy Rain
2007-09-20T21:57:00Z 2007-09-20T22:05:00Z 11078 60913 FLORIDA Tornado
2007-09-29T08:11:00Z 2007-09-29T08:11:00Z 11091 61032 ATLANTIC SOUTH Waterspout
2007-12-07T14:00:00Z 2007-12-08T04:00:00Z 13183 73241 AMERICAN SAMOA Flash Flood
2007-12-11T21:45:00Z 2007-12-12T16:45:00Z 12826 70787 KANSAS Flood
2007-12-13T09:02:00Z 2007-12-13T10:30:00Z 11780 64725 KENTUCKY Flood
... ... ... ... ... ...