// Desc: Test workflow pipeline use crate::test_utils::test_parser; use graphic_walker_parser::parser::model::Dataset; mod test_utils; #[test] fn test_fid_space() { let query = r#" { "workflow": [{ "type": "view", "query": [{ "op": "aggregate", "groupBy": [ "i d" ] }] }], "dataview": [{ "type": "sql", "query": [{ "sql": "select \"i d\", name1, name2 from (select 1 as \"i d\", * from default)", "fidMap": { "name1": "timestamp_s_col", "name2": "bigint_col" } }] }] }"#; let sql = "SELECT \"i d\" FROM (SELECT \"i d\", name1, name2 FROM (SELECT 1 AS \"i d\", * FROM (SELECT \"timestamp_s_col\" AS \"name1\", \"bigint_col\" AS \"name2\" FROM \"table_1\") AS \"k_gw_write_view\") AS \"k_gw_review_default\") AS \"view_0\" GROUP BY \"i d\""; let dataset = Dataset::Table { name: "table_1".to_string(), }; let err = test_parser(query, sql, &dataset); assert!(err.is_none()); } #[test] fn test_multi_filter() { let query = r#" { "workflow": [{ "type": "filter", "filters": [{ "fid": "col_1", "rule": { "type": "range", "value": [ 4.1387, 12.1 ] } }] }, { "type": "filter", "filters": [{ "fid": "col_2", "rule": { "type": "range", "value": [ 4.1387, 12.1 ] } }] }, { "type": "filter", "filters": [{ "fid": "col_3", "rule": { "type": "range", "value": [ 4.1387, 12.1 ] } }] }, { "type": "view", "query": [{ "op": "raw", "fields": [ "col_1", "col_1" ] }] } ] }"#; let sql = "SELECT \"col_1\", \"col_1\" FROM \"table_1\" WHERE \"col_1\" BETWEEN 4.1387 AND 12.1 AND \"col_2\" BETWEEN 4.1387 AND 12.1 AND \"col_3\" BETWEEN 4.1387 AND 12.1"; let dataset = Dataset::Table { name: "table_1".to_string(), }; let err = test_parser(query, sql, &dataset); assert!(err.is_none()); } #[test] fn test_unuse_transform() { let query = r#" { "workflow": [ { "type": "filter", "filters": [ { "fid": "lunch", "rule": { "type": "one of", "value": [ "standard" ] } } ] }, { "type": "transform", "transform": [ { "key": "gw_2a3l", "expression": { "op": "bin", "as": "gw_2a3l", "params": [ { "type": "field", "value": "math score" } ], "num": 10 } } ] }, { "type": "filter", "filters": [ { "fid": "gw_2a3l", "rule": { "type": "range", "value": [ 67.44462674323215, 90 ] } } ] }, { "type": "view", "query": [ { "op": "raw", "fields": [ "reading score", "writing score" ] } ] } ] }"#; let sql = "SELECT \"reading score\", \"writing score\" FROM (SELECT min(\"math score\") OVER () AS \"min_gw_2a3l\", max(\"math score\") OVER () AS \"max_gw_2a3l\", * FROM \"table_1\") AS \"view_0\" WHERE \"lunch\" IN ('standard') AND (\"min_gw_2a3l\" + (least(floor(((\"math score\" - \"min_gw_2a3l\") / ((\"max_gw_2a3l\" - \"min_gw_2a3l\") / 10.0))), 9) * ((\"max_gw_2a3l\" - \"min_gw_2a3l\") / 10.0))) BETWEEN 67.44462674323215 AND 90"; let dataset = Dataset::Table { name: "table_1".to_string(), }; let err = test_parser(query, sql, &dataset); assert!(err.is_none()); } #[test] fn test_multi_view() { let query = r#" { "workflow": [{ "type": "filter", "filters": [{ "fid": "col_1", "rule": { "type": "range", "value": [ 4.1387, 12.1 ] } }] }, { "type": "filter", "filters": [{ "fid": "col_2", "rule": { "type": "range", "value": [ 4.1387, 12.1 ] } }] }, { "type": "view", "query": [{ "op": "raw", "fields": [ "col_3", "col_4" ] }] }, { "type": "filter", "filters": [{ "fid": "col_5", "rule": { "type": "range", "value": [ 4.1387, 12.1 ] } }] }, { "type": "view", "query": [{ "op": "raw", "fields": [ "col_6", "col_7" ] }] } ] }"#; let sql = "SELECT *, \"col_6\", \"col_7\" FROM (SELECT \"col_3\", \"col_4\" FROM \"table_1\" WHERE \"col_1\" BETWEEN 4.1387 AND 12.1 AND \"col_2\" BETWEEN 4.1387 AND 12.1) AS \"view_0\" WHERE \"col_5\" BETWEEN 4.1387 AND 12.1"; let dataset = Dataset::Table { name: "table_1".to_string(), }; let err = test_parser(query, sql, &dataset); assert!(err.is_none()); } #[test] fn test_multi_view_with_dataview() { let query = r#" { "workflow": [{ "type": "filter", "filters": [{ "fid": "col_1", "rule": { "type": "range", "value": [ 4.1387, 12.1 ] } }] }, { "type": "filter", "filters": [{ "fid": "col_2", "rule": { "type": "range", "value": [ 4.1387, 12.1 ] } }] }, { "type": "view", "query": [{ "op": "raw", "fields": [ "col_1", "col_1" ] }] }, { "type": "filter", "filters": [{ "fid": "col_3", "rule": { "type": "range", "value": [ 4.1387, 12.1 ] } }] }, { "type": "view", "query": [{ "op": "raw", "fields": [ "col_1", "col_1" ] }] } ], "dataview": [{ "type": "sql", "query": [{ "sql": "select id, name1, name2 from (select 1 as id, * from default)", "fidMap": { "name1": "timestamp_s_col", "name2": "bigint_col" } }] }] }"#; let sql = "SELECT *, \"col_1\", \"col_1\" FROM (SELECT \"col_1\", \"col_1\" FROM (SELECT id, name1, name2 FROM (SELECT 1 AS id, * FROM (SELECT \"timestamp_s_col\" AS \"name1\", \"bigint_col\" AS \"name2\" FROM \"table_1\") AS \"k_gw_write_view\") AS \"k_gw_review_default\") AS \"view_0\" WHERE \"col_1\" BETWEEN 4.1387 AND 12.1 AND \"col_2\" BETWEEN 4.1387 AND 12.1) AS \"view_1\" WHERE \"col_3\" BETWEEN 4.1387 AND 12.1"; let dataset = Dataset::Table { name: "table_1".to_string(), }; let err = test_parser(query, sql, &dataset); assert!(err.is_none()); } #[test] fn test_sql_data_view() { let query = r#" { "workflow": [{ "type": "view", "query": [{ "op": "aggregate", "groupBy": [ "id" ] }] }], "dataview": [{ "type": "sql", "query": [{ "sql": "select id, name1, name2 from (select 1 as id, * from default)", "fidMap": { "name1": "timestamp_s_col", "name2": "bigint_col" } }] }] } "#; let sql = "SELECT \"id\" FROM (SELECT id, name1, name2 FROM (SELECT 1 AS id, * FROM (SELECT \"timestamp_s_col\" AS \"name1\", \"bigint_col\" AS \"name2\" FROM \"table_1\") AS \"k_gw_write_view\") AS \"k_gw_review_default\") AS \"view_0\" GROUP BY \"id\""; let dataset = Dataset::Table { name: "table_1".to_string(), }; let err = test_parser(query, sql, &dataset); assert!(err.is_none()); } #[test] fn test_aggregate_filter() { let query = r#" { "workflow": [{ "type": "view", "query": [{ "op": "aggregate", "groupBy": [ "gwc_3" ], "measures": [{ "field": "gwc_6", "agg": "sum", "asFieldKey": "gwc_6_sum" } ] }] }, { "type": "filter", "filters": [{ "fid": "gwc_6_sum", "rule": { "type": "one of", "value": [ 376.7899999999946 ] } }] } ] } "#; let sql = "SELECT * FROM (SELECT \"gwc_3\", sum(\"gwc_6\") AS \"gwc_6_sum\" FROM \"table_1\" GROUP BY \"gwc_3\") AS \"view_0\" WHERE \"gwc_6_sum\" IN (376.7899999999946)"; let dataset = Dataset::Table { name: "table_1".to_string(), }; let err = test_parser(query, sql, &dataset); assert!(err.is_none()); }