# Support for Expressions in Range Queries and Implementation of Distributed EXPLAIN ANALYZE | Greptime Biweekly Report

Source: https://greptime.com/blogs/2024-05-22-biweekly-report

## Summary

Together with our global community of contributors, GreptimeDB continues to evolve and flourish as a growing open-source project. We are grateful to each and every one of you.

Below are the highlights among recent commits:

- Introduced Flow Engine to provide continuous aggregation capabilities.

- Expressions can be used in Range Query, such as `RANGE (INTERVAL '2' day - INTERVAL '1' day)`.

- Support for using `EXPLAIN ANALYZE` in distributed mode to analyze query execution costs.

## Contributors

For the past two weeks, our community has been super active with a total of 86 PRs merged. 12 PRs from 8 individual contributors merged successfully, and lots are pending to be merged.

Congrats on becoming our most active contributors in the past 2 weeks:

- @[CookiePieWw](https://github.com/CookiePieWw) ([db#3932](https://github.com/GreptimeTeam/greptimedb/pull/3932))

- @[etolbakov](https://github.com/etolbakov) ([db#3924](https://github.com/GreptimeTeam/greptimedb/pull/3924))

- @[groobyming](https://github.com/groobyming) ([promql-parser#84](https://github.com/GreptimeTeam/promql-parser/pull/84))

- @[irenjj](https://github.com/irenjj) ([docs#940](https://github.com/GreptimeTeam/docs/pull/940) [docs#946](https://github.com/GreptimeTeam/docs/pull/946) [db#3910](https://github.com/GreptimeTeam/greptimedb/pull/3910))

- @[ltratt](https://github.com/ltratt) ([promql-parser#87](https://github.com/GreptimeTeam/promql-parser/pull/87))

- @[SergeTupchiy](https://github.com/SergeTupchiy) ([ingester-erl#40](https://github.com/GreptimeTeam/greptimedb-ingester-erl/pull/40))

- @[taobo](https://github.com/realtaobo) ([db#3901](https://github.com/GreptimeTeam/greptimedb/pull/3901) [db#3923](https://github.com/GreptimeTeam/greptimedb/pull/3923) [db#3995](https://github.com/GreptimeTeam/greptimedb/pull/3995))

- @[tizee](https://github.com/tizee) ([db#3751](https://github.com/GreptimeTeam/greptimedb/pull/3751))

👏  Welcome contributor @[groobyming](https://github.com/groobyming) @[ltratt](https://github.com/ltratt) @[tizee](https://github.com/tizee) join to the community as the new individual contributor, and congratulations on successfully merging their first PR, more PRs are waiting to be merged.

<figure>
<img src="/blogs/2024-05-22-biweekly-report/image1.png" alt="New Contributor of GreptimeDB" style="width: 70%; margin: 0 auto">
<figcaption>New Contributor of GreptimeDB</figcaption>
</figure>

A big THANK YOU to all our members and contributors! It is people like you who are making GreptimeDB a great product. Let's build an even greater community together.

## Highlights of Recent PRs

### [db#3823](https://github.com/GreptimeTeam/greptimedb/pull/3823) Using expressions in Range Query

Now, the Range Query has new support for the following features:

- Supporting Interval type calculations in the Range and Align parameters. For example, you can use `(INTERVAL '2' day - INTERVAL '1' day)` to compute time intervals.

- Specifying the time origin for alignment using expressions. For instance, `(now() - INTERVAL '1' hour)` can be used to align the query to one hour before the current time.

```sql
SELECT 
    ts, 
    min(val) RANGE (INTERVAL '2' day - INTERVAL '1' day) 
FROM 
    host 
ALIGN (INTERVAL '2' day - INTERVAL '1' day)
    TO (now() - INTERVAL '1' hour) 
ORDER BY ts;
```

These enhancements allow users to define time ranges and alignment points more flexibly, enabling more precise time-series data analysis.

Range Query is an extension syntax of GreptimeDB. For more information: https://docs.greptime.com/reference/sql/range

### [db#3908](https://github.com/GreptimeTeam/greptimedb/pull/3908) Supporting EXPLAIN ANALYZE in a distributed mode

In distributed mode, GreptimeDB now supports `EXPLAIN ANALYZE`, which executes the corresponding SQL statement. By running `EXPLAIN ANALYZE`, users can gain detailed insights into the performance of distributed queries, including execution time and resource utilization metrics. This feature is crucial for optimizing and troubleshooting complex queries in distributed environments.

```java
explain analyze SELECT count(*) FROM system_metrics;

+-------+------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| stage | node | plan                                                                                                                                                                            |
+-------+------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 0     | 0    |  MergeScanExec: peers=[4402341478400(1025, 0), ] metrics=[output_rows: 1, greptime_exec_read_cost: 0, ready_time: 6352264, finish_time: 7509279, first_consume_time: 7165836, ] |
|       |      |                                                                                                                                                                                 |
| 1     | 0    |  AggregateExec: mode=Final, gby=[], aggr=[COUNT(greptime.public.system_metrics.ts)] metrics=[output_rows: 1, elapsed_compute: 108029, ]                                         |
|       |      |   CoalescePartitionsExec metrics=[output_rows: 32, elapsed_compute: 83055, ]                                                                                                    |
|       |      |     AggregateExec: mode=Partial, gby=[], aggr=[COUNT(greptime.public.system_metrics.ts)] metrics=[output_rows: 32, elapsed_compute: 334913, ]                                   |
|       |      |       RepartitionExec: partitioning=RoundRobinBatch(32), input_partitions=1 metrics=[repart_time: 1, fetch_time: 441565, send_time: 30325, ]                                    |
|       |      |         StreamScanAdapter { stream: "<SendableRecordBatchStream>" } metrics=[output_rows: 3, mem_used: 24, ]                                                                    |
|       |      |                                                                                                                                                                                 |
|       |      | Total rows: 1                                                                                                                                                                   |
+-------+------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
```

### [db#3923](https://github.com/GreptimeTeam/greptimedb/pull/3923) Migrated the dependency from orc-rs to datafusion-orc

Earlier, we donated orc-rs to the [datafusion-contrib community](https://github.com/datafusion-contrib) and maintained it together with the community. Recently, the main repository's dependency on [orc-rs](https://github.com/wenyxu/orc-rs) has been migrated to [datafusion-orc](https://github.com/datafusion-contrib/datafusion-orc).

### [db#3932](https://github.com/GreptimeTeam/greptimedb/pull/3932) Fuzz testing now includes validation of inserted data

In previous work, we added fuzz testing for data writes. In this PR, we further enhanced it by adding validation for the data that has been written to ensure it meets the expected criteria.

## Good First Issue

### [db#3997](https://github.com/GreptimeTeam/greptimedb/issues/3997) Conduct fuzz testing for GreptimeDB clusters using shared storage

In [db#3967](https://github.com/GreptimeTeam/greptimedb/pull/3967), we ran GreptimeDB clusters and fuzz tests in CI. To better simulate real-world usage, we want to run fuzz testing for GreptimeDB clusters using shared storage in CI.

Keywords: CI

Difficulty: Medium

### [db#3973](https://github.com/GreptimeTeam/greptimedb/issues/3973) Add fuzz testing for the column type change feature

In [db#3517](https://github.com/GreptimeTeam/greptimedb/issues/3517), we supported altering the column data type. We need to add corresponding fuzz tests for this feature.

Keywords: Fuzz testing

Difficulty: Medium

### [db#3884](https://github.com/GreptimeTeam/greptimedb/issues/3884) Remove unnecessary traits and wrapper types from the query crate

The manifest doesn't have any checksum for data validation. We need a way to do the checksum validation for region manifests. A possible way is to save the checksum as the part of manifest  file name, for example, `000000000001-{checksum}.json`.

Most implementations simply forward requests to Datafusion. Since we are highly coupled with Datafusion and have no plans to support another query engine, we can remove these types.

Keywords: Refactoring

Difficulty: Simple

---

#### About Greptime


Greptime offers industry-leading time series database products and solutions to empower IoT and Observability scenarios, enabling enterprises to uncover valuable insights from their data with less time, complexity, and cost.

[GreptimeDB](https://github.com/GreptimeTeam/greptimedb) is an open-source, high-performance time-series database offering unified storage and analysis for metrics, logs, and events. Try it out instantly with [GreptimeCloud](https://www.greptime.com/product/cloud), a fully-managed DBaaS solution—no deployment needed!

The [Edge-Cloud Integrated Solution](https://greptime.com/product/carcloud) combines multimodal edge databases with cloud-based GreptimeDB to optimize IoT edge scenarios, cutting costs while boosting data performance.

Star us on [GitHub](https://github.com/GreptimeTeam/greptimedb) or join GreptimeDB Community on [Slack](https://www.greptime.com/slack) to get connected.
