File tree Expand file tree Collapse file tree 2 files changed +63
-0
lines changed
packages/cubejs-schema-compiler/src/adapter
rust/cubesql/cubesql/src/compile Expand file tree Collapse file tree 2 files changed +63
-0
lines changed Original file line number Diff line number Diff line change @@ -113,6 +113,12 @@ export class PrestodbQuery extends BaseQuery {
113113 const templates = super . sqlTemplates ( ) ;
114114 templates . functions . DATETRUNC = 'DATE_TRUNC({{ args_concat }})' ;
115115 templates . functions . DATEPART = 'DATE_PART({{ args_concat }})' ;
116+ templates . statements . select = 'SELECT {{ select_concat | map(attribute=\'aliased\') | join(\', \') }} \n' +
117+ 'FROM (\n {{ from }}\n) AS {{ from_alias }} \n' +
118+ '{% if group_by %} GROUP BY {{ group_by | map(attribute=\'index\') | join(\', \') }}{% endif %}' +
119+ '{% if order_by %} ORDER BY {{ order_by | map(attribute=\'expr\') | join(\', \') }}{% endif %}' +
120+ '{% if offset %}\nOFFSET {{ offset }}{% endif %}' +
121+ '{% if limit %}\nLIMIT {{ limit }}{% endif %}' ;
116122 templates . expressions . extract = 'EXTRACT({{ date_part }} FROM {{ expr }})' ;
117123 templates . expressions . interval = 'INTERVAL \'{{ num }}\' {{ date_part }}' ;
118124 return templates ;
Original file line number Diff line number Diff line change @@ -21220,4 +21220,61 @@ limit
2122021220
2122121221 Ok(())
2122221222 }
21223+
21224+ #[tokio::test]
21225+ async fn test_athena_offset_limit_push_down() {
21226+ if !Rewriter::sql_push_down_enabled() {
21227+ return;
21228+ }
21229+ init_logger();
21230+
21231+ let query_plan = convert_select_to_query_plan_customized(
21232+ "
21233+ SELECT
21234+ SUM(s) AS s,
21235+ p AS p
21236+ FROM (
21237+ SELECT
21238+ taxful_total_price AS p,
21239+ CASE
21240+ WHEN taxful_total_price = 1 THEN 0
21241+ ELSE SUM(taxful_total_price)
21242+ END AS s
21243+ FROM KibanaSampleDataEcommerce AS k
21244+ GROUP BY 1
21245+ ) AS t
21246+ GROUP BY 2
21247+ LIMIT 2
21248+ OFFSET 1
21249+ "
21250+ .to_string(),
21251+ DatabaseProtocol::PostgreSQL,
21252+ vec![
21253+ (
21254+ "statements/select".to_string(),
21255+ r#"SELECT {{ select_concat | map(attribute='aliased') | join(', ') }}
21256+ FROM ({{ from }}) AS {{ from_alias }}
21257+ {% if group_by %} GROUP BY {{ group_by | map(attribute='index') | join(', ') }}{% endif %}
21258+ {% if order_by %} ORDER BY {{ order_by | map(attribute='expr') | join(', ') }}{% endif %}{% if offset %}
21259+ OFFSET {{ offset }}{% endif %}{% if limit %}
21260+ LIMIT {{ limit }}{% endif %}"#.to_string(),
21261+ ),
21262+ ]
21263+ )
21264+ .await;
21265+
21266+ let physical_plan = query_plan.as_physical_plan().await.unwrap();
21267+ println!(
21268+ "Physical plan: {}",
21269+ displayable(physical_plan.as_ref()).indent()
21270+ );
21271+
21272+ let logical_plan = query_plan.as_logical_plan();
21273+ let sql = logical_plan
21274+ .find_cube_scan_wrapper()
21275+ .wrapped_sql
21276+ .unwrap()
21277+ .sql;
21278+ assert!(sql.contains("OFFSET 1\nLIMIT 2"));
21279+ }
2122321280}
You can’t perform that action at this time.
0 commit comments