Skip to content

Commit

Permalink
test: add copy clause sqlness tests (GreptimeTeam#1198)
Browse files Browse the repository at this point in the history
  • Loading branch information
WenyXu authored and paomian committed Oct 19, 2023
1 parent 24faa9d commit 532d4cf
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 119 deletions.
115 changes: 0 additions & 115 deletions src/datanode/src/tests/instance_test.rs
Expand Up @@ -769,36 +769,6 @@ async fn test_delete() {
check_output_stream(output, expect).await;
}

#[tokio::test(flavor = "multi_thread")]
async fn test_execute_copy_to() {
let instance = setup_test_instance("test_execute_copy_to").await;

// setups
execute_sql(
&instance,
"create table demo(host string, cpu double, memory double, ts timestamp time index);",
)
.await;

let output = execute_sql(
&instance,
r#"insert into demo(host, cpu, memory, ts) values
('host1', 66.6, 1024, 1655276557000),
('host2', 88.8, 333.3, 1655276558000)
"#,
)
.await;
assert!(matches!(output, Output::AffectedRows(2)));

// exports
let data_dir = instance.data_tmp_dir().path();

let copy_to_stmt = format!("Copy demo TO '{}/export/demo.parquet'", data_dir.display());

let output = execute_sql(&instance, &copy_to_stmt).await;
assert!(matches!(output, Output::AffectedRows(2)));
}

#[tokio::test(flavor = "multi_thread")]
async fn test_execute_copy_to_s3() {
logging::init_default_ut_logging();
Expand Down Expand Up @@ -838,91 +808,6 @@ async fn test_execute_copy_to_s3() {
}
}

#[tokio::test(flavor = "multi_thread")]
async fn test_execute_copy_from() {
let instance = setup_test_instance("test_execute_copy_from").await;

// setups
execute_sql(
&instance,
"create table demo(host string, cpu double, memory double, ts timestamp time index);",
)
.await;

let output = execute_sql(
&instance,
r#"insert into demo(host, cpu, memory, ts) values
('host1', 66.6, 1024, 1655276557000),
('host2', 88.8, 333.3, 1655276558000)
"#,
)
.await;
assert!(matches!(output, Output::AffectedRows(2)));

// export
let data_dir = instance.data_tmp_dir().path();

let copy_to_stmt = format!("Copy demo TO '{}/export/demo.parquet'", data_dir.display());

let output = execute_sql(&instance, &copy_to_stmt).await;
assert!(matches!(output, Output::AffectedRows(2)));

struct Test<'a> {
sql: &'a str,
table_name: &'a str,
}
let tests = [
Test {
sql: &format!(
"Copy with_filename FROM '{}/export/demo.parquet_1_2'",
data_dir.display()
),
table_name: "with_filename",
},
Test {
sql: &format!("Copy with_path FROM '{}/export/'", data_dir.display()),
table_name: "with_path",
},
Test {
sql: &format!(
"Copy with_pattern FROM '{}/export/' WITH (PATTERN = 'demo.*')",
data_dir.display()
),
table_name: "with_pattern",
},
];

for test in tests {
// import
execute_sql(
&instance,
&format!(
"create table {}(host string, cpu double, memory double, ts timestamp time index);",
test.table_name
),
)
.await;

let output = execute_sql(&instance, test.sql).await;
assert!(matches!(output, Output::AffectedRows(2)));

let output = execute_sql(
&instance,
&format!("select * from {} order by ts", test.table_name),
)
.await;
let expected = "\
+-------+------+--------+---------------------+
| host | cpu | memory | ts |
+-------+------+--------+---------------------+
| host1 | 66.6 | 1024.0 | 2022-06-15T07:02:37 |
| host2 | 88.8 | 333.3 | 2022-06-15T07:02:38 |
+-------+------+--------+---------------------+"
.to_string();
check_output_stream(output, expected).await;
}
}

#[tokio::test(flavor = "multi_thread")]
async fn test_execute_copy_from_s3() {
logging::init_default_ut_logging();
Expand Down
4 changes: 0 additions & 4 deletions src/datanode/src/tests/test_util.rs
Expand Up @@ -116,10 +116,6 @@ impl MockInstance {
pub(crate) fn inner(&self) -> &Instance {
&self.instance
}

pub(crate) fn data_tmp_dir(&self) -> &TempDir {
&self._guard._data_tmp_dir
}
}

struct TestGuard {
Expand Down
79 changes: 79 additions & 0 deletions tests/cases/standalone/copy/copy_from_fs.result
@@ -0,0 +1,79 @@
CREATE TABLE demo(host string, cpu double, memory double, ts TIMESTAMP time index);

Affected Rows: 0

insert into demo(host, cpu, memory, ts) values ('host1', 66.6, 1024, 1655276557000), ('host2', 88.8, 333.3, 1655276558000);

Affected Rows: 2

Copy demo TO '/tmp/demo/export/demo.parquet';

Affected Rows: 2

CREATE TABLE with_filename(host string, cpu double, memory double, ts timestamp time index);

Affected Rows: 0

Copy with_filename FROM '/tmp/demo/export/demo.parquet_1_2';

Affected Rows: 2

select * from with_filename order by ts;

+-------+------+--------+---------------------+
| host | cpu | memory | ts |
+-------+------+--------+---------------------+
| host1 | 66.6 | 1024.0 | 2022-06-15T07:02:37 |
| host2 | 88.8 | 333.3 | 2022-06-15T07:02:38 |
+-------+------+--------+---------------------+

CREATE TABLE with_path(host string, cpu double, memory double, ts timestamp time index);

Affected Rows: 0

Copy with_path FROM '/tmp/demo/export/';

Affected Rows: 2

select * from with_path order by ts;

+-------+------+--------+---------------------+
| host | cpu | memory | ts |
+-------+------+--------+---------------------+
| host1 | 66.6 | 1024.0 | 2022-06-15T07:02:37 |
| host2 | 88.8 | 333.3 | 2022-06-15T07:02:38 |
+-------+------+--------+---------------------+

CREATE TABLE with_pattern(host string, cpu double, memory double, ts timestamp time index);

Affected Rows: 0

Copy with_pattern FROM '/tmp/demo/export/' WITH (PATTERN = 'demo.*');

Affected Rows: 2

select * from with_pattern order by ts;

+-------+------+--------+---------------------+
| host | cpu | memory | ts |
+-------+------+--------+---------------------+
| host1 | 66.6 | 1024.0 | 2022-06-15T07:02:37 |
| host2 | 88.8 | 333.3 | 2022-06-15T07:02:38 |
+-------+------+--------+---------------------+

drop table demo;

Affected Rows: 1

drop table with_filename;

Affected Rows: 1

drop table with_path;

Affected Rows: 1

drop table with_pattern;

Affected Rows: 1

31 changes: 31 additions & 0 deletions tests/cases/standalone/copy/copy_from_fs.sql
@@ -0,0 +1,31 @@
CREATE TABLE demo(host string, cpu double, memory double, ts TIMESTAMP time index);

insert into demo(host, cpu, memory, ts) values ('host1', 66.6, 1024, 1655276557000), ('host2', 88.8, 333.3, 1655276558000);

Copy demo TO '/tmp/demo/export/demo.parquet';

CREATE TABLE with_filename(host string, cpu double, memory double, ts timestamp time index);

Copy with_filename FROM '/tmp/demo/export/demo.parquet_1_2';

select * from with_filename order by ts;

CREATE TABLE with_path(host string, cpu double, memory double, ts timestamp time index);

Copy with_path FROM '/tmp/demo/export/';

select * from with_path order by ts;

CREATE TABLE with_pattern(host string, cpu double, memory double, ts timestamp time index);

Copy with_pattern FROM '/tmp/demo/export/' WITH (PATTERN = 'demo.*');

select * from with_pattern order by ts;

drop table demo;

drop table with_filename;

drop table with_path;

drop table with_pattern;
16 changes: 16 additions & 0 deletions tests/cases/standalone/copy/copy_to_fs.result
@@ -0,0 +1,16 @@
CREATE TABLE demo(host string, cpu double, memory double, ts TIMESTAMP time index);

Affected Rows: 0

insert into demo(host, cpu, memory, ts) values ('host1', 66.6, 1024, 1655276557000), ('host2', 88.8, 333.3, 1655276558000);

Affected Rows: 2

Copy demo TO '/tmp/export/demo.parquet';

Affected Rows: 2

drop table demo;

Affected Rows: 1

7 changes: 7 additions & 0 deletions tests/cases/standalone/copy/copy_to_fs.sql
@@ -0,0 +1,7 @@
CREATE TABLE demo(host string, cpu double, memory double, ts TIMESTAMP time index);

insert into demo(host, cpu, memory, ts) values ('host1', 66.6, 1024, 1655276557000), ('host2', 88.8, 333.3, 1655276558000);

Copy demo TO '/tmp/export/demo.parquet';

drop table demo;

0 comments on commit 532d4cf

Please sign in to comment.