Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(fuzz): add create logical table target #3756

Merged

Conversation

CookiePieWw
Copy link
Collaborator

I hereby agree to the terms of the GreptimeDB CLA.

Refer to a related PR or issue link (optional)

#3741 and #3174

What's changed and what's your intention?

Fuzz test for metric engine. Create some logical tables on the same physical table.

Checklist

  • I have written the necessary rustdoc comments.
  • I have added the necessary unit tests and integration tests.
  • This PR does not require documentation updates.

@github-actions github-actions bot added the docs-not-required This change does not impact docs. label Apr 19, 2024
@WenyXu
Copy link
Member

WenyXu commented Apr 20, 2024

We can start by mocking the usage of GreptimeDB as Prometheu's backend(https://docs.greptime.com/user-guide/write-data/prometheus)

We always create two physical table with two columns: a timestamp(millisecond, datatypes) column and a value(double) column. The datatype is following the Prometheus document).

i.e.,

CREATE TABLE phy (ts timestamp time index, val double) engine=metric with ("physical_metric_table" = "");

Then we will get a physical table.

select column_name, data_type, semantic_type  from information_schema.columns where table_name = 'phy';
+-------------+--------------+---------------+
| column_name | data_type    | semantic_type |
+-------------+--------------+---------------+
| ts          | timestamp(3) | TIMESTAMP     |
| val         | double       | FIELD         |
+-------------+--------------+---------------+

Then, the fuzz target randomly creates many logical tables and validates the datatypes of the logical and physical table.

e.g.,

CREATE TABLE t2 (ts timestamp time index, val double, host string, idc string, primary key(idc, host)) engine = metric with ("on_physical_table" = "phy");

Validating the datatypes of the physical table.

select column_name, data_type, semantic_type, column_default from information_schema.columns where table_name = 'phy'; 
+-------------+-----------------+---------------+----------------+
| column_name | data_type       | semantic_type | column_default |
+-------------+-----------------+---------------+----------------+
| ts          | timestamp(3)    | FIELD         | NULL           |
| val         | double          | FIELD         | NULL           |
| __table_id  | int unsigned    | TAG           | NULL           |
| __tsid      | bigint unsigned | TAG           | NULL           |
| host        | string          | TAG           | NULL           |
| idc         | string          | TAG           | NULL           |
+-------------+-----------------+---------------+----------------+

Validating the datatypes of the logical table.

select column_name, data_type, semantic_type, column_default from information_schema.columns where table_name = 't2';
+-------------+--------------+---------------+----------------+
| column_name | data_type    | semantic_type | column_default |
+-------------+--------------+---------------+----------------+
| host        | string       | TAG           | NULL           |
| idc         | string       | TAG           | NULL           |
| ts          | timestamp(3) | TIMESTAMP     | NULL           |
| val         | double       | FIELD         | NULL           |
+-------------+--------------+---------------+----------------+

@WenyXu
Copy link
Member

WenyXu commented Apr 20, 2024

We can start by mocking the usage of GreptimeDB as Prometheu's backend(https://docs.greptime.com/user-guide/write-data/prometheus)

We always create two physical table with two columns: a timestamp(millisecond, datatypes) column and a value(double) column. The datatype is following the Prometheus document).

i.e.,

CREATE TABLE phy (ts timestamp time index, val double) engine=metric with ("physical_metric_table" = "");

Then we will get a physical table.

select column_name, data_type, semantic_type  from information_schema.columns where table_name = 'phy';
+-------------+--------------+---------------+
| column_name | data_type    | semantic_type |
+-------------+--------------+---------------+
| ts          | timestamp(3) | TIMESTAMP     |
| val         | double       | FIELD         |
+-------------+--------------+---------------+

Then, the fuzz target randomly creates many logical tables and validates the datatypes of the logical and physical table.

e.g.,

CREATE TABLE t2 (ts timestamp time index, val double, host string, idc string, primary key(idc, host)) engine = metric with ("on_physical_table" = "phy");

Validating the datatypes of the physical table.

select column_name, data_type, semantic_type, column_default from information_schema.columns where table_name = 'phy'; 
+-------------+-----------------+---------------+----------------+
| column_name | data_type       | semantic_type | column_default |
+-------------+-----------------+---------------+----------------+
| ts          | timestamp(3)    | FIELD         | NULL           |
| val         | double          | FIELD         | NULL           |
| __table_id  | int unsigned    | TAG           | NULL           |
| __tsid      | bigint unsigned | TAG           | NULL           |
| host        | string          | TAG           | NULL           |
| idc         | string          | TAG           | NULL           |
+-------------+-----------------+---------------+----------------+

Validating the datatypes of the logical table.

select column_name, data_type, semantic_type, column_default from information_schema.columns where table_name = 't2';
+-------------+--------------+---------------+----------------+
| column_name | data_type    | semantic_type | column_default |
+-------------+--------------+---------------+----------------+
| host        | string       | TAG           | NULL           |
| idc         | string       | TAG           | NULL           |
| ts          | timestamp(3) | TIMESTAMP     | NULL           |
| val         | double       | FIELD         | NULL           |
+-------------+--------------+---------------+----------------+

BTW, there is the bug. The semantic_type in the 1st row should be TIMESTAMP.

select column_name, data_type, semantic_type, column_default from information_schema.columns where table_name = 'phy'; 
+-------------+-----------------+---------------+----------------+
| column_name | data_type       | semantic_type | column_default |
+-------------+-----------------+---------------+----------------+
| ts          | timestamp(3)    | FIELD         | NULL           |
| val         | double          | FIELD         | NULL           |
| __table_id  | int unsigned    | TAG           | NULL           |
| __tsid      | bigint unsigned | TAG           | NULL           |
| host        | string          | TAG           | NULL           |
| idc         | string          | TAG           | NULL           |
+-------------+-----------------+---------------+----------------+

@CookiePieWw CookiePieWw force-pushed the create-logical-table-fuzz-test branch from b5652b3 to 56ac926 Compare April 22, 2024 13:41
@CookiePieWw CookiePieWw force-pushed the create-logical-table-fuzz-test branch from 598f109 to ead6ff2 Compare April 23, 2024 06:42
@CookiePieWw CookiePieWw marked this pull request as ready for review April 23, 2024 06:55
@CookiePieWw CookiePieWw requested a review from a team as a code owner April 23, 2024 06:55
@WenyXu WenyXu requested review from waynexia, WenyXu and zhongzc April 23, 2024 07:04
Copy link

codecov bot commented Apr 23, 2024

Codecov Report

Attention: Patch coverage is 98.18182% with 3 lines in your changes are missing coverage. Please review.

Project coverage is 85.32%. Comparing base (bf21527) to head (f569e32).
Report is 26 commits behind head on main.

❗ Current head f569e32 differs from pull request most recent head 6ca29f5. Consider uploading reports for the commit 6ca29f5 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3756      +/-   ##
==========================================
- Coverage   85.53%   85.32%   -0.22%     
==========================================
  Files         946      953       +7     
  Lines      159564   163046    +3482     
==========================================
+ Hits       136489   139120    +2631     
- Misses      23075    23926     +851     

tests-fuzz/src/generator/create_expr.rs Outdated Show resolved Hide resolved
tests-fuzz/src/generator/create_expr.rs Outdated Show resolved Hide resolved
tests-fuzz/src/generator/create_expr.rs Outdated Show resolved Hide resolved
@WenyXu
Copy link
Member

WenyXu commented Apr 24, 2024

The tests of #3772 may help you to build the fuzz test

@CookiePieWw CookiePieWw requested a review from WenyXu April 25, 2024 11:14
tests-fuzz/src/generator/create_expr.rs Outdated Show resolved Hide resolved
tests-fuzz/src/generator/create_expr.rs Outdated Show resolved Hide resolved
Copy link
Member

@WenyXu WenyXu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

tests-fuzz/src/ir.rs Outdated Show resolved Hide resolved
tests-fuzz/src/generator/create_expr.rs Outdated Show resolved Hide resolved
tests-fuzz/src/generator/create_expr.rs Outdated Show resolved Hide resolved
tests-fuzz/src/generator/create_expr.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@fengjiachun fengjiachun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@fengjiachun fengjiachun added this pull request to the merge queue Apr 26, 2024
Merged via the queue into GreptimeTeam:main with commit 934c7e3 Apr 26, 2024
18 checks passed
@CookiePieWw CookiePieWw deleted the create-logical-table-fuzz-test branch April 26, 2024 10:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs-not-required This change does not impact docs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants