Skip to content

Commit

Permalink
feat: customize channel information for sqlness tests (#4729)
Browse files Browse the repository at this point in the history
* feat: add pg and mysql server_address options

* feat: start pg and mysql server(standalone)

* feat: start pg and mysql in distribute

* feat: finally get there, specify postgres sqlness

* feat: support mysql sqlness

* fix: license

* fix: remove unused import

* fix: toml

* fix: clippy

* refactor: BeginProtocolInterceptorFactory to ProtocolInterceptorFactory

* fix: sqlness pg connect

* fix: clippy

* Apply suggestions from code review

Co-authored-by: Yingwen <[email protected]>

* fix: rustfmt

* fix: reconnect pg and mysql when restart

* test: add mysql related sqlness

* fix: wait for start while restarting

* fix: clippy

* fix: cargo lock conflict

fix: Cargo.lock conflict

* fix: usage of '@@tx_isolation' in sqlness

* fix: typos

* feat: retry with backoff when create client

* fix: use millisecond rather than microseconds in backoff

---------

Co-authored-by: Yingwen <[email protected]>
  • Loading branch information
J0HN50N133 and evenyag authored Oct 4, 2024
1 parent caf5f2c commit 47a3277
Show file tree
Hide file tree
Showing 12 changed files with 1,127 additions and 368 deletions.
797 changes: 519 additions & 278 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/log-store/src/kafka/client_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ impl ClientManager {
}

async fn try_create_client(&self, provider: &Arc<KafkaProvider>) -> Result<Client> {
// Sets to Retry to retry connecting if the kafka cluter replies with an UnknownTopic error.
// Sets to Retry to retry connecting if the kafka cluster replies with an UnknownTopic error.
// That's because the topic is believed to exist as the metasrv is expected to create required topics upon start.
// The reconnecting won't stop until succeed or a different error returns.
let client = self
Expand Down
2 changes: 1 addition & 1 deletion src/script/src/python/rspython/builtins/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ enum PyValue {
}

impl PyValue {
/// compare if results is just as expect, not using PartialEq because it is not transtive .e.g. [1,2,3] == len(3) == [4,5,6]
/// compare if results is just as expect, not using PartialEq because it is not transitive .e.g. [1,2,3] == len(3) == [4,5,6]
fn just_as_expect(&self, other: &Self) -> bool {
match (self, other) {
(PyValue::FloatVec(a), PyValue::FloatVec(b)) => a
Expand Down
29 changes: 29 additions & 0 deletions tests/cases/standalone/common/mysql.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
-- SQLNESS PROTOCOL MYSQL
SELECt @@tx_isolation;

+-----------------+
| @@tx_isolation; |
+-----------------+
| 0 |
+-----------------+

-- SQLNESS PROTOCOL MYSQL
SELECT @@version_comment;

+--------------------+
| @@version_comment; |
+--------------------+
| 0 |
+--------------------+

-- SQLNESS PROTOCOL MYSQL
SHOW DATABASES;

+--------------------+
| Database |
+--------------------+
| greptime_private |
| information_schema |
| public |
+--------------------+

8 changes: 8 additions & 0 deletions tests/cases/standalone/common/mysql.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- SQLNESS PROTOCOL MYSQL
SELECt @@tx_isolation;

-- SQLNESS PROTOCOL MYSQL
SELECT @@version_comment;

-- SQLNESS PROTOCOL MYSQL
SHOW DATABASES;
142 changes: 123 additions & 19 deletions tests/cases/standalone/common/system/pg_catalog.result
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,49 @@ create database pg_catalog;

Error: 1004(InvalidArguments), Schema pg_catalog already exists

select * from pg_catalog.pg_type order by oid;
-- make sure all the pg_catalog tables are only visible to postgres
select * from pg_catalog.pg_class;

Error: 4001(TableNotFound), Failed to plan SQL: Table not found: greptime.pg_catalog.pg_class

select * from pg_catalog.pg_namespace;

Error: 4001(TableNotFound), Failed to plan SQL: Table not found: greptime.pg_catalog.pg_namespace

select * from pg_catalog.pg_type;

Error: 4001(TableNotFound), Failed to plan SQL: Table not found: greptime.pg_catalog.pg_type

-- SQLNESS PROTOCOL POSTGRES
select * from pg_catalog.pg_type order by oid;

+-----+-----------+--------+
| oid | typname | typlen |
+-----+-----------+--------+
| 1 | String | -1 |
| 2 | Binary | -1 |
| 3 | Int8 | 1 |
| 4 | Int16 | 2 |
| 5 | Int32 | 4 |
| 6 | Int64 | 8 |
| 7 | UInt8 | 1 |
| 8 | UInt16 | 2 |
| 9 | UInt32 | 4 |
| 10 | UInt64 | 8 |
| 11 | Float32 | 4 |
| 12 | Float64 | 8 |
| 13 | Decimal | 16 |
| 14 | Date | 4 |
| 15 | DateTime | 8 |
| 16 | Timestamp | 8 |
| 17 | Time | 8 |
| 18 | Duration | 8 |
| 19 | Interval | 16 |
| 20 | List | -1 |
+-----+-----------+--------+

-- \d
-- SQLNESS PROTOCOL POSTGRES
SELECT n.nspname as "Schema",
c.relname as "Name",
CASE c.relkind WHEN 'r' THEN 'table' WHEN 'v' THEN 'view' WHEN 'm' THEN 'materialized view' WHEN 'i' THEN 'index' WHEN 'S' THEN 'sequence' WHEN 't' THEN 'TOAST table' WHEN 'f' THEN 'foreign table' WHEN 'p' THEN 'partitioned table' WHEN 'I' THEN 'partitioned index' END as "Type",
Expand All @@ -21,9 +59,14 @@ WHERE c.relkind IN ('r','p','v','m','S','f','')
AND pg_catalog.pg_table_is_visible(c.oid)
ORDER BY 1,2;

Error: 4001(TableNotFound), Failed to plan SQL: Table not found: greptime.pg_catalog.pg_class
+--------+---------+-------+-------+
| Schema | Name | Type | Owner |
+--------+---------+-------+-------+
| public | numbers | table | |
+--------+---------+-------+-------+

-- \dt
-- SQLNESS PROTOCOL POSTGRES
SELECT n.nspname as "Schema",
c.relname as "Name",
CASE c.relkind WHEN 'r' THEN 'table' WHEN 'v' THEN 'view' WHEN 'm' THEN 'materialized view' WHEN 'i' THEN 'index' WHEN 'S' THEN 'sequence' WHEN 't' THEN 'TOAST table' WHEN 'f' THEN 'foreign table' WHEN 'p' THEN 'partitioned table' WHEN 'I' THEN 'partitioned index' END as "Type",
Expand All @@ -37,22 +80,36 @@ WHERE c.relkind IN ('r','p','')
AND pg_catalog.pg_table_is_visible(c.oid)
ORDER BY 1,2;

Error: 4001(TableNotFound), Failed to plan SQL: Table not found: greptime.pg_catalog.pg_class
+--------+---------+-------+-------+
| Schema | Name | Type | Owner |
+--------+---------+-------+-------+
| public | numbers | table | |
+--------+---------+-------+-------+

-- make sure oid of namespace keep stable
-- SQLNESS PROTOCOL POSTGRES
SELECT * FROM pg_namespace ORDER BY oid;

Error: 4001(TableNotFound), Failed to plan SQL: Table not found: greptime.public.pg_namespace
+------------+--------------------+
| oid | nspname |
+------------+--------------------+
| 667359454 | pg_catalog |
| 3174397350 | information_schema |
| 3338153620 | greptime_private |
| 3927743705 | public |
+------------+--------------------+

create
database my_db;
-- SQLNESS PROTOCOL POSTGRES
create database my_db;

Affected Rows: 1

-- SQLNESS PROTOCOL POSTGRES
use my_db;

Affected Rows: 0


-- SQLNESS PROTOCOL POSTGRES
create table foo
(
ts TIMESTAMP TIME INDEX
Expand All @@ -61,6 +118,7 @@ create table foo
Affected Rows: 0

-- show tables in `my_db`
-- SQLNESS PROTOCOL POSTGRES
select relname
from pg_catalog.pg_class
where relnamespace = (
Expand All @@ -69,9 +127,14 @@ where relnamespace = (
where nspname = 'my_db'
);

Error: 4001(TableNotFound), Failed to plan SQL: Table not found: greptime.pg_catalog.pg_class
+---------+
| relname |
+---------+
| foo |
+---------+

-- \dt
-- SQLNESS PROTOCOL POSTGRES
SELECT n.nspname as "Schema",
c.relname as "Name",
CASE c.relkind WHEN 'r' THEN 'table' WHEN 'v' THEN 'view' WHEN 'm' THEN 'materialized view' WHEN 'i' THEN 'index' WHEN 'S' THEN 'sequence' WHEN 't' THEN 'TOAST table' WHEN 'f' THEN 'foreign table' WHEN 'p' THEN 'partitioned table' WHEN 'I' THEN 'partitioned index' END as "Type",
Expand All @@ -85,9 +148,15 @@ WHERE c.relkind IN ('r','p','')
AND pg_catalog.pg_table_is_visible(c.oid)
ORDER BY 1,2;

Error: 4001(TableNotFound), Failed to plan SQL: Table not found: greptime.pg_catalog.pg_class
+--------+---------+-------+-------+
| Schema | Name | Type | Owner |
+--------+---------+-------+-------+
| my_db | foo | table | |
| public | numbers | table | |
+--------+---------+-------+-------+

-- show tables in `my_db`, `public`
-- SQLNESS PROTOCOL POSTGRES
select relname
from pg_catalog.pg_class
where relnamespace in (
Expand All @@ -97,8 +166,14 @@ where relnamespace in (
)
order by relname;

Error: 4001(TableNotFound), Failed to plan SQL: Table not found: greptime.pg_catalog.pg_class
+---------+
| relname |
+---------+
| foo |
| numbers |
+---------+

-- SQLNESS PROTOCOL POSTGRES
select relname
from pg_catalog.pg_class
where relnamespace in (
Expand All @@ -107,8 +182,13 @@ where relnamespace in (
where nspname like 'my%'
);

Error: 4001(TableNotFound), Failed to plan SQL: Table not found: greptime.pg_catalog.pg_class
+---------+
| relname |
+---------+
| foo |
+---------+

-- SQLNESS PROTOCOL POSTGRES
select relnamespace, relname, relkind
from pg_catalog.pg_class
where relnamespace in (
Expand All @@ -120,34 +200,58 @@ where relnamespace in (
)
order by relnamespace, relname;

Error: 4001(TableNotFound), Failed to plan SQL: Table not found: greptime.pg_catalog.pg_class
+--------------+---------+---------+
| relnamespace | relname | relkind |
+--------------+---------+---------+
| 434869349 | foo | r |
+--------------+---------+---------+

-- SQLNESS PROTOCOL POSTGRES
use public;

Affected Rows: 0


-- SQLNESS PROTOCOL POSTGRES
drop schema my_db;

Affected Rows: 0

-- SQLNESS PROTOCOL POSTGRES
use pg_catalog;

Affected Rows: 0


-- pg_class
-- SQLNESS PROTOCOL POSTGRES
desc table pg_class;

Error: 4001(TableNotFound), Table not found: pg_class

+--------------+--------+-----+------+---------+---------------+
| Column | Type | Key | Null | Default | Semantic Type |
+--------------+--------+-----+------+---------+---------------+
| oid | UInt32 | | NO | | FIELD |
| relname | String | | NO | | FIELD |
| relnamespace | UInt32 | | NO | | FIELD |
| relkind | String | | NO | | FIELD |
| relowner | UInt32 | | NO | | FIELD |
+--------------+--------+-----+------+---------+---------------+

-- SQLNESS PROTOCOL POSTGRES
desc table pg_namespace;

Error: 4001(TableNotFound), Table not found: pg_namespace
+---------+--------+-----+------+---------+---------------+
| Column | Type | Key | Null | Default | Semantic Type |
+---------+--------+-----+------+---------+---------------+
| oid | UInt32 | | NO | | FIELD |
| nspname | String | | NO | | FIELD |
+---------+--------+-----+------+---------+---------------+

-- SQLNESS PROTOCOL POSTGRES
drop table my_db.foo;

Error: 4001(TableNotFound), Table not found: greptime.my_db.foo
Failed to execute query, encountered: Error { kind: Db, cause: Some(DbError { severity: "ERROR", parsed_severity: None, code: SqlState(E42P01), message: "Table not found: greptime.my_db.foo", detail: None, hint: None, position: None, where_: None, schema: None, table: None, column: None, datatype: None, constraint: None, file: None, line: None, routine: None }) }

-- SQLNESS PROTOCOL POSTGRES
use public;

Affected Rows: 0


Loading

0 comments on commit 47a3277

Please sign in to comment.