limit

Limits the number of output records by cancelling the query when the specified count is reached.

Command properties

PropertyValue
Command typeTransforming
Required permissionNone
License usageN/A
Parallel executionSupported
Distributed executionRuns on Control Node (reducer)

Syntax

limit [OFFSET] COUNT

Target

[OFFSET]
Number of records to skip. Defaults to 0 if omitted.
COUNT
Maximum number of records to output.

Error codes

Parsing errors
Error codeMessageDescription
20600오프셋은 1개 또는 2개 입니다.No argument or more than 2 arguments
20601잘못된 오프셋 타입입니다: [msg]An argument is not an integer
Runtime errors

N/A

Description

The limit command skips OFFSET records from the input, outputs COUNT records, then cancels the query. Be careful when placing aggregation commands after limit in the query pipeline, as they may not work as intended when the query is cancelled mid-execution.

In a distributed environment, this command runs on Control Nodes.

Examples

  1. Retrieve the top 10 records

    table duration=1h WEB_LOGS | limit 10
    

    Outputs only 10 records from the last 1 hour of web logs.

  2. Specify skip count and output count

    table duration=1h WEB_LOGS | limit 100 10
    

    Skips 100 records and then outputs 10 records.

  3. Extract the top records from inline data

    json "[{'name': 'Alice'}, {'name': 'Bob'}, {'name': 'Charlie'}, {'name': 'David'}]"
    | limit 2
    

    Outputs only the first 2 records.