RuleGo RuleGo
🏠Home
  • Quick Start
  • Rule Chain
  • Standard Components
  • Extension Components
  • Custom Components
  • Visualization
  • RuleGo-Server
  • AOP
  • Trigger
  • Advanced Topics
  • Performance
  • Standard Components
  • Extension Components
  • Custom Components
  • Components Marketplace
  • Overview
  • Quick Start
  • Routing
  • DSL
  • API
  • Options
  • Components
🔥Editor (opens new window)
  • RuleGo Editor (opens new window)
  • RuleGo Server (opens new window)
  • StreamSQL
  • AI Agent Framework
  • TPCLAW Agent Platform (opens new window)
  • Github (opens new window)
  • Gitee (opens new window)
  • Changelog (opens new window)
  • English
  • 简体中文
🏠Home
  • Quick Start
  • Rule Chain
  • Standard Components
  • Extension Components
  • Custom Components
  • Visualization
  • RuleGo-Server
  • AOP
  • Trigger
  • Advanced Topics
  • Performance
  • Standard Components
  • Extension Components
  • Custom Components
  • Components Marketplace
  • Overview
  • Quick Start
  • Routing
  • DSL
  • API
  • Options
  • Components
🔥Editor (opens new window)
  • RuleGo Editor (opens new window)
  • RuleGo Server (opens new window)
  • StreamSQL
  • AI Agent Framework
  • TPCLAW Agent Platform (opens new window)
  • Github (opens new window)
  • Gitee (opens new window)
  • Changelog (opens new window)
  • English
  • 简体中文

广告采用随机轮播方式显示 ❤️成为赞助商
  • Quick Start

  • Rule Chain

  • Standard Components

  • Extension Components

  • Custom Components

  • Components marketplace

  • Visualization

  • AOP

  • Trigger

  • Advanced Topic

  • Agent Framework

  • RuleGo-Server

  • FAQ

  • Endpoint Module

  • Support

  • StreamSQL

    • Overview
    • Quick Start
    • Core Concepts
    • SQL Reference
    • API Reference
    • RuleGo Integration
    • Schema Validation
    • Advanced Examples
    • functions

    • case-studies

      • Case Studies Overview
      • Stream-Table JOIN Metadata Enrichment
      • Session Window and Device Online Analysis
      • Change Data Capture Case Study
      • Sliding Window and Continuous Detection
      • Data Filtering and Transformation
        • Business Scenario
        • SQL
        • Input
        • Output
        • Behavior Notes
        • 📚 Related Docs
      • IoT Temperature Alerting and Metrics Aggregation
目录

Data Filtering and Transformation

# Data Filtering and Transformation

# Business Scenario

The most common class of need is per-row processing — filter, convert, and grade each reading as it arrives, one in / one out synchronously, with no window aggregation. For example: discard obviously bogus readings (temperature out of range), convert Celsius to Fahrenheit, tag a level by temperature (normal/warning/alert). Such needs use non-aggregation mode with EmitSync, where the caller gets the single-row result directly.

# SQL

SELECT deviceId,
       temperature,
       temperature * 1.8 + 32           AS temp_f,
       CASE WHEN temperature > 35 THEN 'CRITICAL'
            WHEN temperature > 30 THEN 'WARNING'
            ELSE 'OK' END               AS level
FROM stream
WHERE temperature > 0 AND temperature < 100
1
2
3
4
5
6
7
8

# Input

{"deviceId": "dev-01", "temperature": 28.0}
{"deviceId": "dev-02", "temperature": 32.0}
{"deviceId": "dev-03", "temperature": 38.0}
{"deviceId": "dev-04", "temperature": 999.0}
{"deviceId": "dev-05", "temperature": null}
1
2
3
4
5

# Output

EmitSync returns synchronously per row; rows that miss WHERE return nil (not an error):

{deviceId:dev-01 temperature:28   temp_f:82.4  level:OK}
{deviceId:dev-02 temperature:32   temp_f:89.6  level:WARNING}
{deviceId:dev-03 temperature:38   temp_f:100.4 level:CRITICAL}
[filtered] dev-04   // 999 out of range, caught by the bounds check
[filtered] dev-05   // null, caught by IS NOT NULL
1
2
3
4
5

# Behavior Notes

  • EmitSync is only for non-aggregation queries (no GROUP BY/window); calling it on an aggregation query errors with synchronous mode only supports non-aggregation queries.
  • WHERE filters raw rows: rows that fail the condition return nil, so you can distinguish "filtered" from "error". To filter after aggregation, use HAVING (see Sliding Window and Continuous Detection).
  • Arithmetic and aliases: temperature * 1.8 + 32 AS temp_f — write the expression inline and alias it, no UDF needed.
  • CASE WHEN: for grading/conditional assignment; WHERE supports comparisons (>, <, =) and AND/OR to combine conditions.

How to run

Non-aggregation queries use EmitSync(data) for a synchronous single-row result; no AddSink needed. See How to Run Case SQL for the full boilerplate.

# 📚 Related Docs

  • How to Run Case SQL
  • SQL Reference — WHERE, expressions, CASE
  • IoT Temperature Alerting and Metrics Aggregation — upgrading from single-point transform to windowed aggregation
Edit this page on GitHub (opens new window)
Last Updated: 2026/07/11, 04:40:00
Sliding Window and Continuous Detection
IoT Temperature Alerting and Metrics Aggregation

← Sliding Window and Continuous Detection IoT Temperature Alerting and Metrics Aggregation→

Theme by Vdoing | Copyright © 2023-2026 RuleGo Team | Apache 2.0 License

  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式