test: add copy clause sqlness tests (#1198)

This commit is contained in:
Weny Xu
2023-03-21 11:22:26 +08:00
committed by GitHub
parent 8fb97ea1d8
commit b8f7f603cf
6 changed files with 133 additions and 119 deletions

View File

@@ -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();
@@ -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();

View File

@@ -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 {

View File

@@ -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

View File

@@ -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;

View File

@@ -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

View File

@@ -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;