-
Notifications
You must be signed in to change notification settings - Fork 333
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
Fuzz tests for metric engine #3741
Comments
Thank you for being so interested! @CookiePieWw
Fuzz tests may not be easy; they always need to figure out the correct behavior of the database. Feel free to contact us if you have any questions. |
Thanks for your detailed introduction :) @WenyXu. From my perspective, the logical tables seem to be a view on the physical table with some overlapped columns and some newly added columns. I wonder if there are some common practices and requirements for both. For overlapped columns, do we need to keep the data type, constraints and options? I've noticed the data type and constraints can be different in logical tables and physical tables. For newly added columns, they are only allowed to be strings. The test example above take all the newly added columns as a primary key, so I wonder if it's necessary. |
Yes, it's designed for the scenario to use GreptimeDB as a Prometheus backend.
Sorry, I missed something. Could you provide an example to explain the difference? |
As for the physical table, here I add some constraints for val: CREATE TABLE phy (ts timestamp time index, val double not null default 0) engine=metric with ("physical_metric_table" = ""); Currently we can create a logical table with the CREATE TABLE phy (ts timestamp time index, val int, host string, primary key (host)) engine=metric with ("on_physical_table" = "phy"); I wonder if its appropriate to create sql like this for fuzz test. BTW, I found the database would crash once I create a metric table with 2 columns with the same name: mysql> CREATE TABLE `phy`(ts timestamp time index, val double) engine=metric with ("physical_metric_table" = "");
mysql> CREATE TABLE t1(ts timestamp time index, val double, host text, host string) engine=metric with ("on_physical_tab
le" = "phy");
ERROR 1815 (HY000): Internal error: 1003
mysql> show tables;
ERROR 1815 (HY000): Internal error: 1003 Is it the intended behavior? |
Good catch! It's a bug🥲 |
I got you. It's a bug; it will throw an error if users try to insert values into a logical table. Some validation needs to be added while creating the logical table(It will be tracked in another issue). Reproduce steps:
CREATE TABLE `phy`(ts timestamp time index, val double) engine=metric with ("physical_metric_table" = "");
CREATE TABLE t1 (ts timestamp time index, val int, host string, primary key (host)) engine=metric with ("on_physical_table" = "phy");
CREATE TABLE t2 (ts timestamp time index, val string, host string, primary key (host)) engine=metric with ("on_physical_table" = "phy");
For fuzz tests, let's start with naive cases.
CREATE TABLE t1 (ts timestamp time index, val double, host string, idc string, primary key(idc, host)) engine = metric with ("on_physical_table" = "phy"); |
Got it. I'll make some changes later. |
I've noticed that the existing insert fuzz test for the mito engine has not been activated yet. Are there some works ahead for it? If so, maybe I could solve it first before proceeding to the insert test for the metric engine. |
Let's activate the test. cc @zhongzc |
The order of columns of logical table is sorted instead of following the declaration order in create expr, as described in #3694 as an expected behavior. Since the issue has not been closed, I wonder if the behavior would be changed later. If not, I prepare to sort the columns in the create expr for insert fuzz test of the logical table. |
No, at least not recently.
The insert statement includes the columns explicitly; I guess it should work well without any change. INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...); |
Got it. I found that the |
I'm working on the validator of inserted rows recently and encountered a weird thing. The select query failed after an insertion. Minimal case here: CREATE TABLE `Nam`(
`NIsi` TIMESTAMP(9) TIME INDEX,
`uNDe` FLOAT,
`miNus` INT NULL,
ut BOOLEAN,
`doloRuM` DOUBLE NULL,
sit DOUBLE DEFAULT 0.282613557176039,
`bLandItiis` INT,
`DOLOREs` BIGINT,
excepturi INT,
`coRPorIS` BIGINT DEFAULT -3634152213850520260,
`maGNAm` FLOAT NULL,
est SMALLINT NOT NULL,
eos BOOLEAN DEFAULT true,
`ipSAM` BOOLEAN,
`viTAE` BOOLEAN NULL,
`vElit` DOUBLE NULL,
`doloRem` FLOAT NOT NULL,
`EXPeDITA` SMALLINT DEFAULT -21787,
`QuIA` FLOAT,
`FACILIs` BIGINT,
`Et` BIGINT,
`VEnIAM` FLOAT DEFAULT 0.67037076,
PRIMARY KEY(
ut,
`FACILIs`,
`DOLOREs`,
`Et`,
`bLandItiis`,
`QuIA`
)
) ENGINE = mito;
INSERT INTO
`Nam` (
ut,
`Et`,
`doloRem`,
`maGNAm`,
eos,
`NIsi`,
est,
`vElit`,
`doloRuM`,
`FACILIs`
)
VALUES
(
false,
-659085894348132302,
0.38609815,
0.6564076,
DEFAULT,
'1776-06-28 17:25:38.207225128+0000',
7684,
0.40258472138796686,
NULL,
NULL
);
> SELECT * from `Nam`;
ERROR 1815 (HY000): Internal error: 1003 I wonder if it's expected. |
Hi @CookiePieWw , Thanks a lot. I tried on the main branch, and didn't reproduce it. It should be fixed in #3876 |
Thanks! I forgot to re-compile with the recent commit. The patch works for me. I almost finished but get stuck on multiple timestamp types. I'm utilizing let fetched_value = {
let value_type = fetched_row.column(idx).type_info().name();
match value_type {
"BOOL" | "BOOLEAN" => RowValue::Value(Value::Boolean(
fetched_row.try_get::<bool, usize>(idx).unwrap(),
)),
... // other types,
"TIMESTAMP" => RowValue::Value(Value::Timestamp(
Timestamp::from_chrono_datetime(
fetched_row
.try_get::<DateTime<Utc>, usize>(idx)
.unwrap()
.naive_utc(),
)
.unwrap(),
)),
}
} But for the timestamp, with different time stamp types, the results will have a consistent shift compared to the original value: // For TIMESTAMP(0)
Expected value: '-261245-03-17 18:48:20+0000', got: '0899-03-17 18:48:20+0000'
Expected value: '-179184-12-17 05:26:54+0000', got: '+17424-12-17 05:26:54+0000'
Expected value: '-177707-06-01 00:41:21+0000', got: '+18901-06-01 00:41:21+0000'
// For TIMESTAMP(6)
Expected value: '-261794-08-31 14:46:02.445288+0000', got: '0350-08-31 14:46:02.445288+0000'
Expected value: '-261714-09-03 10:13:07.194687+0000', got: '0430-09-03 10:13:07.194687+0000'
Expected value: '-261460-02-22 02:24:41.115722+0000', got: '0684-02-22 02:24:41.115722+0000'
// For TIMESTAMP(9), it perfectly matched
Expected value: '1686-07-16 08:29:43.983304336+0000', got: '1686-07-16 08:29:43.983304+0000'
Expected value: '1686-08-25 17:41:03.238567505+0000', got: '1686-08-25 17:41:03.238567+0000'
Expected value: '1686-10-12 02:16:43.698871931+0000', got: '1686-10-12 02:16:43.698871+0000' It seems sqlx treat all the types as the same. I wonder how to correct it, maybe perform some conversions based on the original value type, but the unit field of the timestamp is private. |
Thanks @CookiePieWw , would you like to provide a repository for reproduction (or debug)? |
Does "TIMESTAMP" => RowValue::Value(Value::Timestamp( |
I mostly follow the docs about types of mysql in sqlx here: https://docs.rs/sqlx/latest/sqlx/mysql/types/index.html. It seems sqlx only consider one kind of timestamp: |
I created a draft pr in #3932 |
Thanks, I will take a look ASAP. |
Hi @CookiePieWw , After some investigation, I found the key problem: The encoding of timestamps in the MySQL protocol is defined here: At line 497, it casts The range of
One workaround here is to restrict the range of generated timestamps. e.g., we can restrict the range of greptimedb/tests-fuzz/src/ir.rs Lines 113 to 141 in 4ca7ac7
Maybe we need some functions like |
Ah I see. So GreptimeDB supports a much wider range of timestamp then MySQL, then the protocol fails to convert the timestamps of different ranges.
I'll firstly add a simple |
The metric engine's RFC: https://github.com/GreptimeTeam/greptimedb/blob/main/docs/rfcs/2023-07-10-metric-engine.md
The following tests show how we create tables in the metric engine:
greptimedb/tests/cases/standalone/common/create/create_metric_table.sql
Lines 1 to 36 in 7e56bf2
cc @waynexia
Originally posted by @WenyXu in #3732 (comment)
The text was updated successfully, but these errors were encountered: