Skip to main content

Streaming detection rules

Beta

Lakewatch is in Beta. Workspace admins can control access to this feature from the Previews page. See Manage workspace-level previews.

Experimental

Streaming detection rules are an experimental feature. Their behavior, settings, and limits can change.

A streaming detection rule evaluates each new row of a single source table as it arrives. It creates a signal for every row that matches the rule's SQL predicate. Use streaming rules for low-latency detections that don't wait for a schedule. Examples include signature matches, indicator of compromise (IOC) matches, and atomic signals, such as the creation of a new administrator account.

Lakewatch runs streaming rules on Lakeflow pipelines and manages their compute. You don't select a SQL warehouse or set a schedule.

To compare rule types and detection patterns, see Choose a detection rule type.

How streaming rules run​

A streaming rule evaluates newly appended rows. It doesn't scan the source table's full history. Use a scheduled rule to evaluate historical data or cover periods when the streaming rule was inactive.

The rule skips commits that update or delete existing rows, including any rows those commits insert. An insert-only MERGE is evaluated.

Changing the source table or run-as identity can cause the rule to evaluate previously processed rows again or leave gaps in coverage. Removing unprocessed source files with VACUUM can also leave gaps. Review the rule's system errors for coverage warnings.

Lakewatch doesn't provide cost attribution for individual streaming rules.

Event time​

Each signal records the time of the event that produced it. If you set output.event_time_column in the rule's YAML, Lakewatch uses that column. Otherwise, it uses the source's time column, if the table has one. If the chosen column is null for a row, or neither column exists, Lakewatch uses the time when it processed the row.

Built-in parsers produce a time column, so rules that read parsed tables usually don't need event_time_column.

Write the SQL predicate​

A streaming rule's logic is a SQL predicate: a condition that's true or false for each new row, like the condition in a WHERE clause. Each row where the predicate is true creates a signal. Write only the condition, as you would after WHERE. In the editor, the predicate follows a read-only SELECT * FROM <table> WHERE line.

SQL
activity_name = 'Logon' AND status = 'Failure' AND src_endpoint.ip IS NOT NULL

The predicate must be a single Boolean expression. A column, literal, or function on its own isn't accepted, even if it returns a Boolean. For example, write ENDSWITH(process.name, '.ps1') = true, not ENDSWITH(process.name, '.ps1').

Supported operators and functions​

Category

Supported

Logical

AND, OR, NOT

Comparison

=, ==, !=, <>, <=>, <, <=, >, >=

Pattern matching

LIKE, ILIKE, RLIKE, and their NOT forms

Membership

IN and NOT IN with a list of literal values

Null and Boolean tests

IS [NOT] NULL, IS [NOT] TRUE, IS [NOT] FALSE, IS [NOT] UNKNOWN, IS [NOT] DISTINCT FROM

Conditional

CASE (simple and searched)

Type conversion

CAST, TRY_CAST

Functions

COALESCE, UPPER, LOWER, CONCAT, TYPEOF, ENDSWITH

Semi-structured data

TRY_VARIANT_GET(<column>, '<path>', '<type>'), and : path extraction inside CAST or TRY_CAST

Category

Supported

Logical

AND, OR, NOT

Comparison

=, ==, !=, <>, <=>, <, <=, >, >=

Pattern matching

LIKE, ILIKE, RLIKE, and their NOT forms

Membership

IN and NOT IN with a list of literal values

Null and Boolean tests

IS [NOT] NULL, IS [NOT] TRUE, IS [NOT] FALSE, IS [NOT] UNKNOWN, IS [NOT] DISTINCT FROM

Conditional

CASE (simple and searched)

Type conversion

CAST, TRY_CAST

Functions

COALESCE, UPPER, LOWER, CONCAT, TYPEOF, ENDSWITH

Semi-structured data

TRY_VARIANT_GET(<column>, '<path>', '<type>'), and : path extraction inside CAST or TRY_CAST

For VARIANT columns, use TRY_VARIANT_GET with a literal path and type, or extract a path inside a cast. Paths can't use wildcards (*):

SQL
TRY_VARIANT_GET(raw, '$.user.name', 'string') = 'admin'
OR CAST(raw:event.action AS STRING) = 'DeleteTrail'

Not supported​

Use only the operators and functions in the supported list. Aggregations, window functions, joins, subqueries, and user-defined functions (UDFs) aren't supported. Use a scheduled rule for logic that needs other rows, other tables, or historical state.

BETWEEN, LIKE ANY, LIKE ALL, arithmetic operators, unary minus, and array subscripts such as a[0] aren't supported. For string concatenation, use CONCAT instead of ||.

A predicate can be up to 32,768 characters.

Avoid evaluation errors​

A predicate that passes validation can still fail on unexpected data. For example, CAST(code AS BIGINT) > 10 fails when code is 'bad'. Use TRY_CAST to return NULL for values that can't be converted:

SQL
TRY_CAST(code AS BIGINT) > 10

Evaluation errors can cause the rule to skip rows, which it doesn't evaluate again. Use TRY_CAST and expressions that handle null values, and check the rule's system errors.

Before you begin​

The rule's run-as identity must have SELECT on the source table. See Set the run-as principal.

The source must be a Delta table or a streaming table. Views aren't supported.

Share a run-as identity for the same source​

Databricks recommends using the same run-as identity for streaming rules that read the same source table. Lakewatch automatically groups these rules for shared processing, improving performance and compute efficiency as you add rules.

Choose an identity with the permissions required by all of the rules that share it. To configure the identity, see Set the run-as principal.

Create a streaming rule​

  1. Go to Detection rules and click Create detection rule.
  2. Under Choose a rule type, on Streaming rule, click Use streaming rule.
  3. In Detection input, configure the rule:
    • Folder, Rule name, and Description: See Configure common rule settings.
    • Source table (required): The table the rule reads, as catalog.schema.table. Enter the name. To browse for a table, click Browse tables.
    • Detection predicate (required): The condition to evaluate on each new row. The editor shows the SELECT * FROM <source table> WHERE line that your predicate completes. See Write the SQL predicate. To explore the source table while you write the predicate, click Open in Query.
  4. Configure signal output, MITRE ATT&CK mappings, and metadata. Streaming rules don't deduplicate signals, so the Signals section has no deduplication settings. Include all data is on by default.
  5. In Execution, set whether the rule is active with the Active toggle, and optionally click Edit run as principal to change its run-as identity. Streaming rules run continuously on compute that Lakewatch manages, so there's no schedule or SQL warehouse to set.
  6. Click Create rule, and then confirm.

Lakewatch opens the rule's overview page. Last Status shows Starting while Lakewatch adds the rule to streaming execution. See Monitor a streaming rule.

Signal output​

A streaming rule's signal summary, context values, and event-time column read the source row. Use source columns or expressions, with braces around evaluated values in the summary and context. Context keys are labels, so a summary can't reference a context key as if it were a source column.

For example, if the source has actor.user.name, use {actor.user.name} in the summary, even if you also create a context field named user_name.

Edit a streaming rule as YAML​

A streaming rule's YAML uses a streaming block in place of the scheduled rule's batch block. For fields shared by both rule types, see the common rule fields.

YAML
catalog_name: security
schema_name: detections
rule_name: failed_logon_streaming

description: Creates a signal for each failed logon as it arrives.
severity: Medium
category: Static Signature
fidelity: FIDELITY_INVESTIGATIVE

schedule:
enabled: true

streaming:
source:
table: security.parsed.authentication_events
predicate:
expression: "activity_name = 'Logon' AND status = 'Failure'"

output:
summary: 'Failed logon for {actor.user.name} from {src_endpoint.ip}'
default_context: true

YAML field

Required

Notes

streaming.source.table

Yes

The source table, as catalog.schema.table.

streaming.predicate.expression

Yes

The predicate. See Write the SQL predicate.

schedule.enabled

No

Whether the rule is active. Defaults to true. Don't set schedule.at_least_every or schedule.cron_expression.

output.event_time_column

No

The column that holds the event time. See Event time.

YAML field

Required

Notes

streaming.source.table

Yes

The source table, as catalog.schema.table.

streaming.predicate.expression

Yes

The predicate. See Write the SQL predicate.

schedule.enabled

No

Whether the rule is active. Defaults to true. Don't set schedule.at_least_every or schedule.cron_expression.

output.event_time_column

No

The column that holds the event time. See Event time.

A streaming rule can't include batch, deduplication, or deduplication_time_window. Lakewatch rejects a rule that sets them.

Monitor a streaming rule​

In the Detection rules list, the Type column shows a waves icon Waves icon. for a streaming rule and a clock icon Clock icon. for a scheduled rule. To see the rule type, hover over the icon. To show only streaming rules, filter the list by Type. To sort the rules by type, click the Type column heading.

To see a streaming rule's overview, open the rule. The overview shows Detection type as Streaming, the Source table, Compute as Managed by Lakewatch, and the Detection predicate. The execution mode is Continuous (streaming), and deduplication is None (streaming).

Streaming rules don't have a Run history tab. Instead, use these fields on the overview to monitor processing:

  • Last Status: The rule's processing status. A running rule can show Healthy without processing a batch in the last 24 hours if no new source data arrives. Check System errors if the rule is failing or degraded.
  • Delay: How long data in the latest batch waited for processing.
  • Last processed: When the rule last processed data.
  • Source data written: When the newest data in the latest batch was written to the source table.
  • Last 24 hours: Select an hour to see rows processed, signals and alerts created, processing delay, and errors.

System errors for streaming rules​

Open the rule's System errors tab to investigate evaluation failures, processing delays or interruptions, missing source data, and alert creation problems. Each system error describes the problem and the available next steps.

A Streaming rule possible coverage gap error means the rule might have missed source data. Review or replay the affected data if it's still available.

If the run-as identity loses access to the source table, restore its SELECT permission on the table. Lakewatch retries processing and resumes after you restore access.

Some failures might not appear clearly in system errors. If a rule doesn't produce the signals you expect, check its System errors tab or contact support.

Additional resources​