From d387f74b1d5c249c6728de57da406bdeb79faf25 Mon Sep 17 00:00:00 2001 From: brian moore Date: Mon, 23 Feb 2026 16:07:48 -0500 Subject: [PATCH] bm/support-leading-comma --- src/line.rs | 9 + src/merger.rs | 91 +- src/splitter.rs | 19 +- .../preformatted/002_select_from_where.sql | 8 +- tests/data/preformatted/003_literals.sql | 19 +- tests/data/preformatted/004_with_select.sql | 9 +- .../data/preformatted/008_reserved_names.sql | 38 +- .../preformatted/301_multiline_jinjafmt.sql | 16 +- .../302_jinjafmt_multiline_str.sql | 5 +- tests/data/unformatted/100_select_case.sql | 31 +- tests/data/unformatted/101_multiline.sql | 16 +- .../data/unformatted/102_lots_of_comments.sql | 31 +- .../data/unformatted/103_window_functions.sql | 35 +- tests/data/unformatted/104_joins.sql | 19 +- tests/data/unformatted/105_fmt_off.sql | 5 +- tests/data/unformatted/106_leading_commas.sql | 15 +- tests/data/unformatted/107_jinja_blocks.sql | 10 +- .../data/unformatted/109_lateral_flatten.sql | 13 +- .../unformatted/110_other_identifiers.sql | 14 +- .../111_chained_boolean_between.sql | 23 +- tests/data/unformatted/112_semicolons.sql | 14 +- tests/data/unformatted/113_utils_group_by.sql | 22 +- tests/data/unformatted/114_unions.sql | 42 +- .../unformatted/115_select_star_except.sql | 73 +- .../unformatted/117_whitespace_in_tokens.sql | 7 +- tests/data/unformatted/118_within_group.sql | 10 +- .../unformatted/119_psycopg_placeholders.sql | 13 +- tests/data/unformatted/120_array_literals.sql | 29 +- .../121_stubborn_merge_edge_cases.sql | 93 +- tests/data/unformatted/122_values.sql | 54 +- tests/data/unformatted/123_spark_keywords.sql | 104 +- .../unformatted/124_bq_compound_types.sql | 52 +- .../data/unformatted/125_numeric_literals.sql | 50 +- tests/data/unformatted/126_blank_lines.sql | 11 +- tests/data/unformatted/127_more_comments.sql | 26 +- tests/data/unformatted/129_duckdb_joins.sql | 49 +- .../unformatted/130_athena_data_types.sql | 8 +- .../unformatted/131_assignment_statement.sql | 7 +- tests/data/unformatted/135_star_columns.sql | 11 +- tests/data/unformatted/200_base_model.sql | 114 +- tests/data/unformatted/202_unpivot_macro.sql | 9 +- .../203_gitlab_email_domain_type.sql | 23 +- .../unformatted/205_rittman_hubspot_deals.sql | 110 +- .../unformatted/206_gitlab_prep_geozone.sql | 133 ++- .../unformatted/207_rittman_int_journals.sql | 4 +- ...209_rittman_int_web_events_sessionized.sql | 208 ++-- .../unformatted/210_gitlab_gdpr_delete.sql | 23 +- .../unformatted/211_http_2019_cdn_17_20.sql | 59 +- .../unformatted/212_http_2019_cms_14_02.sql | 47 +- .../213_gitlab_fct_sales_funnel_target.sql | 186 +-- .../unformatted/214_get_unique_attributes.sql | 9 +- ...a_revenue_revenue_contract_line_source.sql | 1024 +++++++++++------ .../unformatted/218_multiple_c_comments.sql | 20 +- tests/data/unformatted/219_any_all_agg.sql | 8 +- .../data/unformatted/220_clickhouse_joins.sql | 43 +- .../221_dbt_config_dollar_quoted.sql | 37 +- .../222_colorado_claims_extract.sql | 238 ++-- .../222_jinja_unbalanced_brackets.sql | 19 +- tests/data/unformatted/300_jinjafmt.sql | 7 +- .../unformatted/400_create_fn_and_select.sql | 35 +- tests/data/unformatted/401_explain_select.sql | 12 +- tests/data/unformatted/403_grant_revoke.sql | 24 +- .../404_create_function_pg_examples.sql | 30 +- ...405_create_function_snowflake_examples.sql | 33 +- .../406_create_function_bq_examples.sql | 54 +- .../407_alter_function_pg_examples.sql | 15 +- .../408_alter_function_snowflake_examples.sql | 6 +- .../409_create_external_function.sql | 14 +- .../data/unformatted/410_create_warehouse.sql | 9 +- tests/data/unformatted/411_create_clone.sql | 8 +- 70 files changed, 2449 insertions(+), 1213 deletions(-) diff --git a/src/line.rs b/src/line.rs index b4775db..78ef4c8 100644 --- a/src/line.rs +++ b/src/line.rs @@ -250,6 +250,15 @@ impl Line { .find(|n| !n.is_newline()) } + /// Get the second non-newline node (useful for leading-comma lines like `, lateral`). + pub fn second_content_node<'a>(&self, arena: &'a [Node]) -> Option<&'a Node> { + self.nodes + .iter() + .map(|&i| &arena[i]) + .filter(|n| !n.is_newline()) + .nth(1) + } + /// Get the index of the first non-newline node. pub fn first_content_node_idx(&self, arena: &[Node]) -> Option { self.nodes.iter().copied().find(|&i| !arena[i].is_newline()) diff --git a/src/merger.rs b/src/merger.rs index 3bfe11b..b146d37 100644 --- a/src/merger.rs +++ b/src/merger.rs @@ -155,32 +155,44 @@ impl LineMerger { } } - /// Convert leading commas to trailing commas by merging standalone comma - /// lines with the preceding non-blank content line. - /// Python sqlfmt always uses trailing comma style. + /// Merge standalone comma lines with the FOLLOWING content line. + /// Leading-comma style: `, next_item` on one line. /// Don't merge commas with Jinja block tags ({% if %}, {% else %}, etc.) /// as the comma is part of the block's content, not the tag itself. /// Uses a mark-and-sweep approach to avoid O(n²) from Vec::remove(). fn fix_standalone_commas(&self, lines: &mut Vec, arena: &[Node]) { let len = lines.len(); let mut remove = vec![false; len]; - let mut last_content_idx: Option = None; for i in 0..len { if remove[i] { continue; } - if lines[i].is_standalone_comma(arena) && i > 0 { - if let Some(pi) = last_content_idx { - if !is_jinja_block_line(&lines[pi], arena) { - let to_merge = vec![lines[pi].clone(), lines[i].clone()]; + if lines[i].is_standalone_comma(arena) { + // Find next non-blank content line + let mut next_content_idx: Option = None; + for j in (i + 1)..len { + if !remove[j] + && !lines[j].is_blank_line(arena) + && !lines[j].is_standalone_comment_line(arena) + { + next_content_idx = Some(j); + break; + } + } + if let Some(ni) = next_content_idx { + if !is_jinja_block_line(&lines[ni], arena) + && !line_has_interior_split_points(&lines[ni], arena) + { + let to_merge = vec![lines[i].clone(), lines[ni].clone()]; if let Ok(merged) = self.create_merged_line(&to_merge, arena) { if let Some(merged_line) = merged.into_iter().find(|l| !l.is_blank_line(arena)) { - lines[pi] = merged_line; + lines[ni] = merged_line; remove[i] = true; - for j in (pi + 1)..i { + // Remove blank lines between comma and next content + for j in (i + 1)..ni { if lines[j].is_blank_line(arena) { remove[j] = true; } @@ -191,10 +203,6 @@ impl LineMerger { } } } - - if !lines[i].is_blank_line(arena) && !lines[i].is_standalone_comment_line(arena) { - last_content_idx = Some(i); - } } if remove.iter().any(|&r| r) { @@ -293,6 +301,13 @@ impl LineMerger { return Err(ControlFlow::CannotMerge); } + // Leading-comma style: never merge across comma-starting lines. + // Must check BEFORE setting first_content_seen so that the first + // content line of a segment (e.g., `, sum(`) is not blocked. + if is_content && first_content_seen && line.starts_with_comma(arena) { + return Err(ControlFlow::CannotMerge); + } + // --- Interior standalone comment detection --- if is_content { if pending_interior_comment { @@ -512,6 +527,10 @@ impl LineMerger { }); } + // LATERAL: with leading commas, the comma is on the LATERAL line itself + // (e.g., `, lateral flatten(...)`) so check if the head line starts with comma + // and the second content node is LATERAL, or if the first content is LATERAL + // and the previous segment's tail ends with comma. if first.token.token_type == crate::token::TokenType::UntermKeyword && first.value.eq_ignore_ascii_case("lateral") { @@ -525,6 +544,16 @@ impl LineMerger { } return self.create_merged_line(&segment.lines, arena).is_ok(); } + // Leading-comma style: `, lateral` — first content is comma, second is lateral + if first.is_comma() { + if let Some(second) = line.second_content_node(arena) { + if second.token.token_type == crate::token::TokenType::UntermKeyword + && second.value.eq_ignore_ascii_case("lateral") + { + return self.create_merged_line(&segment.lines, arena).is_ok(); + } + } + } false } @@ -750,6 +779,34 @@ impl LineMerger { } } +/// Check if a line has interior nodes that would cause the splitter to re-split +/// if the line were prepended with a comma. This prevents fix_standalone_commas +/// from creating non-idempotent output. +fn line_has_interior_split_points(line: &Line, arena: &[Node]) -> bool { + let mut first_content = true; + for &idx in &line.nodes { + let node = &arena[idx]; + if node.is_newline() { + continue; + } + if first_content { + first_content = false; + continue; + } + // These would cause the splitter to split before them + if node.is_operator(arena) && !node.is_bracket_operator(arena) { + return true; + } + if node.is_boolean_operator() { + return true; + } + if node.is_unterm_keyword() { + return true; + } + } + false +} + /// Check if a line starts with a Jinja block tag. fn is_jinja_block_line(line: &Line, arena: &[Node]) -> bool { line.first_content_node(arena) @@ -923,11 +980,11 @@ mod tests { #[test] fn test_create_merged_line_basic() { - // Two short columns should merge onto one SELECT line + // Two short columns should stay split with leading commas let result = format_sql("SELECT\n a,\n b\n"); assert!( - result.contains("a,"), - "Short columns should merge: {}", + result.contains(", b"), + "Short columns should use leading commas: {}", result ); } diff --git a/src/splitter.rs b/src/splitter.rs index 34efcdd..555ffd1 100644 --- a/src/splitter.rs +++ b/src/splitter.rs @@ -10,8 +10,8 @@ use crate::token::{Token, TokenType}; /// /// Mirrors the Python sqlfmt LineSplitter exactly: /// - Iterates node-by-node with split_before/split_after flags -/// - Splits AFTER commas, opening brackets, keywords, query dividers -/// - Splits BEFORE operators, keywords, closing brackets, multiline jinja +/// - Splits AFTER opening brackets, keywords, query dividers +/// - Splits BEFORE commas, operators, keywords, closing brackets, multiline jinja /// - Uses iterative (not recursive) approach to handle very long lines pub struct LineSplitter; @@ -135,6 +135,11 @@ impl LineSplitter { return true; } + // Leading-comma style: split BEFORE commas so they lead the next line + if node.is_comma() { + return true; + } + false } @@ -162,9 +167,6 @@ impl LineSplitter { fn maybe_split_after(&self, node_idx: NodeIndex, arena: &[Node]) -> (bool, bool) { let node = &arena[node_idx]; - if node.is_comma() { - return (true, false); - } // BUT NOT after angle brackets (< for type constructors like array). // Angle bracket content is typically short and should stay on the same line. if node.is_opening_bracket() { @@ -230,8 +232,6 @@ impl LineSplitter { (comments, Vec::new()) } else if comments.is_empty() { (Vec::new(), Vec::new()) - } else if new_nodes.len() == 1 && arena[new_nodes[0]].token.token_type == TokenType::Comma { - (Vec::new(), comments) } else { // Use slice contains() instead of HashSet for small node sets let remaining_nodes: &[NodeIndex] = if index < line.nodes.len() { @@ -365,7 +365,8 @@ mod tests { } #[test] - fn test_split_after_comma() { + fn test_split_before_comma() { + // Leading-comma style: split BEFORE the comma let mut arena = Vec::new(); let a = make_node(&mut arena, TokenType::Name, "a", ""); let comma = make_node(&mut arena, TokenType::Comma, ",", ""); @@ -382,6 +383,8 @@ mod tests { "Expected at least 2 lines, got {}", result.len() ); + // First line should have "a" (no comma) + // Second line should start with comma } #[test] diff --git a/tests/data/preformatted/002_select_from_where.sql b/tests/data/preformatted/002_select_from_where.sql index a21e8b3..edfc1e7 100644 --- a/tests/data/preformatted/002_select_from_where.sql +++ b/tests/data/preformatted/002_select_from_where.sql @@ -1,7 +1,7 @@ select - a_long_field_name, - another_long_field_name, - (one_field + another_field) as c, - a final_field + a_long_field_name + , another_long_field_name + , (one_field + another_field) as c + , a final_field from my_schema."my_QUOTED_ table!" where one_field < another_field diff --git a/tests/data/preformatted/003_literals.sql b/tests/data/preformatted/003_literals.sql index 4711305..a622c76 100644 --- a/tests/data/preformatted/003_literals.sql +++ b/tests/data/preformatted/003_literals.sql @@ -1,8 +1,13 @@ select - 1 + 1, - sum(1.05), - 1.4 - 15.17, - -.45 + -0.99, - -0.710 - sum(-34.5), - (1 + 1) - (4 - 0.6), - 3.14159 + 1 + + 1 + , sum(1.05) + , 1.4 + - 15.17 + , -.45 + + -0.99 + , -0.710 + - sum(-34.5) + , (1 + 1) + - (4 - 0.6) + , 3.14159 diff --git a/tests/data/preformatted/004_with_select.sql b/tests/data/preformatted/004_with_select.sql index 7641cf0..3b1e6c7 100644 --- a/tests/data/preformatted/004_with_select.sql +++ b/tests/data/preformatted/004_with_select.sql @@ -1,3 +1,10 @@ -with my_cte as (select 1, b, another_field from my_schema.my_table) +with + my_cte as ( + select + 1 + , b + , another_field + from my_schema.my_table + ) select * from another_cte diff --git a/tests/data/preformatted/008_reserved_names.sql b/tests/data/preformatted/008_reserved_names.sql index 17ceb4e..9872e68 100644 --- a/tests/data/preformatted/008_reserved_names.sql +++ b/tests/data/preformatted/008_reserved_names.sql @@ -1,21 +1,21 @@ with - "select" as (select * from foo.select), - "case" as (select * from foo.case), - "end" as (select * from foo.end), - "as" as (select * from foo.as), - "interval" as (select * from foo.interval), - "exclude" as (select * from foo.exclude), - "using" as (select * from foo.using), - "on" as (select * from foo.on), - "and" as (select * from foo.and), - "limit" as (select * from foo.limit), - "over" as (select * from foo.over), - "between" as (select * from foo.between), - "union" as (select * from foo.union), - "explain" as (select * from foo.explain), - "grant" as (select * from foo.grant), - "create" as (select * from foo.create), - "alter" as (select * from foo.alter), - "truncate" as (select * from foo.truncate), - "drop" as (select * from foo.drop) + "select" as (select * from foo.select) + , "case" as (select * from foo.case) + , "end" as (select * from foo.end) + , "as" as (select * from foo.as) + , "interval" as (select * from foo.interval) + , "exclude" as (select * from foo.exclude) + , "using" as (select * from foo.using) + , "on" as (select * from foo.on) + , "and" as (select * from foo.and) + , "limit" as (select * from foo.limit) + , "over" as (select * from foo.over) + , "between" as (select * from foo.between) + , "union" as (select * from foo.union) + , "explain" as (select * from foo.explain) + , "grant" as (select * from foo.grant) + , "create" as (select * from foo.create) + , "alter" as (select * from foo.alter) + , "truncate" as (select * from foo.truncate) + , "drop" as (select * from foo.drop) select 1 diff --git a/tests/data/preformatted/301_multiline_jinjafmt.sql b/tests/data/preformatted/301_multiline_jinjafmt.sql index 92806d6..bb40e71 100644 --- a/tests/data/preformatted/301_multiline_jinjafmt.sql +++ b/tests/data/preformatted/301_multiline_jinjafmt.sql @@ -7,12 +7,18 @@ with end_date="sysdate() + interval '1 year'", ) }} - ), - final as ( + ) + , final as ( select - date_day as dt, - date_trunc('month', date_day) as mnth, - date_part('day', date_day) as day_of_month + date_day as dt + , date_trunc( + 'month' + , date_day + ) as mnth + , date_part( + 'day' + , date_day + ) as day_of_month from base_spine ) diff --git a/tests/data/preformatted/302_jinjafmt_multiline_str.sql b/tests/data/preformatted/302_jinjafmt_multiline_str.sql index a124d3b..b078bf9 100644 --- a/tests/data/preformatted/302_jinjafmt_multiline_str.sql +++ b/tests/data/preformatted/302_jinjafmt_multiline_str.sql @@ -15,4 +15,7 @@ ) }} -select campaign_name, date_part, count(distinct user_id) as users +select + campaign_name + , date_part + , count(distinct user_id) as users diff --git a/tests/data/unformatted/100_select_case.sql b/tests/data/unformatted/100_select_case.sql index faca415..734f643 100644 --- a/tests/data/unformatted/100_select_case.sql +++ b/tests/data/unformatted/100_select_case.sql @@ -25,21 +25,30 @@ select from some_table )))))__SQLFMT_OUTPUT__((((( select - my_first_field, - my_second_field as an_alias, - case + my_first_field + , + my_second_field as an_alias + , case when another_field = some_other_value then some_really_long_value - end as my_case_statement, - case + end as my_case_statement + , case when caser = 'my_literal' then some_really_really_long_value_to_wrap_this_next_line else 42 - end, - case when (my_field) then end_field end::numeric(10, 2) as casted_case, - (case when ending then false end) + (case when 2 then true end)::varchar(10), - another_field, - case when true then 10 end + 4, - case -- a comment with no spaces + end + , + case when (my_field) then end_field end::numeric( + 10 + , 2 + ) as casted_case + , + (case when ending then false end) + + (case when 2 then true end)::varchar(10) + , another_field + , + case when true then 10 end + + 4 + , case -- a comment with no spaces when something_long_that_keeps_this_from_wrapping then something_else_long_long_long else another_super_long_field_name diff --git a/tests/data/unformatted/101_multiline.sql b/tests/data/unformatted/101_multiline.sql index 2a41bc3..5109dba 100644 --- a/tests/data/unformatted/101_multiline.sql +++ b/tests/data/unformatted/101_multiline.sql @@ -55,12 +55,20 @@ select * from renamed /* what!?! */ where true * but we're not going to parse those */ with - source as (select * from {{ ref("my_model") }}), - /* This is a multiline comment in very bad style, + source as (select * from {{ ref("my_model") }}) + , + renamed as ( + /* This is a multiline comment in very bad style, * which starts and ends on lines with other tokens. */ - renamed as (select id, another_field, and_another, and_still_another from source), - {% set my_variable_in_bad_style = ["a", "short", "list", "of", "strings"] %} + select + id + , another_field + , and_another + , and_still_another + from source + ) + , {% set my_variable_in_bad_style = ["a", "short", "list", "of", "strings"] %} {# # And this is a nice multiline jinja comment diff --git a/tests/data/unformatted/102_lots_of_comments.sql b/tests/data/unformatted/102_lots_of_comments.sql index 6fc3cd5..99b8529 100644 --- a/tests/data/unformatted/102_lots_of_comments.sql +++ b/tests/data/unformatted/102_lots_of_comments.sql @@ -40,28 +40,35 @@ with one as ( select -- short 1 - ), + ) + , two as ( select -- too long but it's an inline comment so it has to stay here or we'll get stability issues - a_long_enough_field, another_long_enough_field - ), - three as (select 1), -- short enough + a_long_enough_field + , another_long_enough_field + ) + , + three as (select 1) + , -- short enough four as ( select - my_table.a_field, -- too long but it's an inline comment so it has to stay here or we'll get stability issues - my_table.b_field, - my_table.c_field + my_table.a_field + , -- too long but it's an inline comment so it has to stay here or we'll get stability issues + my_table.b_field + , my_table.c_field from my_table where something == 5 ) select -- not distinct - one_really_long_field_name, -- with a long comment that will never wrap above this line + one_really_long_field_name + , -- with a long comment that will never wrap above this line -- a standalone comment - a_short_field, -- with another comment - something_else, - another_thing_entirely, - yet_another_field + a_short_field + , -- with another comment + something_else + , another_thing_entirely + , yet_another_field -- another standalone comment from a_really_long_table -- an inline comment on a semicolon ; diff --git a/tests/data/unformatted/103_window_functions.sql b/tests/data/unformatted/103_window_functions.sql index f45d0f6..0a65bfc 100644 --- a/tests/data/unformatted/103_window_functions.sql +++ b/tests/data/unformatted/103_window_functions.sql @@ -11,25 +11,42 @@ from my_table )))))__SQLFMT_OUTPUT__((((( select - a, - sum(a) over () as b, - row_number() over () as c, + a + , + sum(a) over () as b + , + row_number() over () as c + , count(case when a is null then 1 end) over ( - partition by user_id, date_trunc('year', performed_at) - ) as d, + partition by + user_id + , date_trunc( + 'year' + , performed_at + ) + ) as d + , first_value(a ignore nulls) over ( partition by user_id order by performed_at desc rows between unbounded preceding and unbounded following - ) as e, + ) as e + , count(*) filter (where a is null) over ( - partition by user_id, date_trunc('year', performed_at) - ) as f, + partition by + user_id + , date_trunc( + 'year' + , performed_at + ) + ) as f + , first_value(a ignore nulls) over ( partition by user_id order by performed_at desc range between unbounded preceding and unbounded following - ) as g, + ) as g + , last_value(a ignore nulls) over ( partition by user_id order by performed_at asc diff --git a/tests/data/unformatted/104_joins.sql b/tests/data/unformatted/104_joins.sql index ed226e2..db8980c 100644 --- a/tests/data/unformatted/104_joins.sql +++ b/tests/data/unformatted/104_joins.sql @@ -15,7 +15,14 @@ natural full outer join six left anti join seven on one.seven = seven.one cross join {{ ref('bar_bar_bar') }} as bar )))))__SQLFMT_OUTPUT__((((( -select one.one, two.two, three.three, four.four, five.five, six.six, seven.seven +select + one.one + , two.two + , three.three + , four.four + , five.five + , six.six + , seven.seven from one join two on one.two = two.one inner join "my_database"."my_schema".three as three on one.three = three.one @@ -27,7 +34,15 @@ left outer join and something_else right join ( - select id, five, six, seven, eight, nine from my_table where some_filter is true + select + id + , five + , six + , seven + , eight + , nine + from my_table + where some_filter is true ) as five using (five.id) natural full outer join six left anti join seven on one.seven = seven.one diff --git a/tests/data/unformatted/105_fmt_off.sql b/tests/data/unformatted/105_fmt_off.sql index 1c4ffc0..e251edd 100644 --- a/tests/data/unformatted/105_fmt_off.sql +++ b/tests/data/unformatted/105_fmt_off.sql @@ -12,7 +12,10 @@ group by a )))))__SQLFMT_OUTPUT__((((( -select a, b, c +select + a + , b + , c -- fmt: off FROM diff --git a/tests/data/unformatted/106_leading_commas.sql b/tests/data/unformatted/106_leading_commas.sql index 9c507db..92ed9be 100644 --- a/tests/data/unformatted/106_leading_commas.sql +++ b/tests/data/unformatted/106_leading_commas.sql @@ -8,11 +8,12 @@ select something from my_table )))))__SQLFMT_OUTPUT__((((( select - something, - another_thing, - and_another, - *, - sum(something) as something_else, - and_another / 100 as alias, - row_number() over (partition by something) as n + something + , another_thing + , and_another + , * + , sum(something) as something_else + , and_another + / 100 as alias + , row_number() over (partition by something) as n from my_table diff --git a/tests/data/unformatted/107_jinja_blocks.sql b/tests/data/unformatted/107_jinja_blocks.sql index a5bc3ba..b423ba0 100644 --- a/tests/data/unformatted/107_jinja_blocks.sql +++ b/tests/data/unformatted/107_jinja_blocks.sql @@ -36,7 +36,8 @@ Hello! I'm data, not code. with {%- for model in list_o_models %} - {{ model }} as (select * from {{ ref(model) }}), + {{ model }} as (select * from {{ ref(model) }}) + , {% endfor -%} base as ( select * @@ -44,12 +45,15 @@ with {% if "Hello" in block_o_text %} {{ ref("hello") }} {% else %} {{ ref("goodbye") }} {% endif %} - ), + ) + , joined as ( select {% for model in list_o_models %} {{ model }}.column_a as {{ model }}_field - {%- if not loop.last -%},{%- endif %} + {%- if not loop.last -%} + , + {%- endif %} {% endfor %} from base {% for model in list_o_models %} diff --git a/tests/data/unformatted/109_lateral_flatten.sql b/tests/data/unformatted/109_lateral_flatten.sql index 0dd1704..9d8e69c 100644 --- a/tests/data/unformatted/109_lateral_flatten.sql +++ b/tests/data/unformatted/109_lateral_flatten.sql @@ -7,9 +7,12 @@ from , lateral flatten( input => src:events ); )))))__SQLFMT_OUTPUT__((((( select - src:device_type::string, - src:version::string, - _airbyte_data:"AccountId"::varchar as accountid, - value -from raw_source, lateral flatten(input => src:events) + src:device_type::string + , src:version::string + , _airbyte_data:"AccountId"::varchar as accountid + , value +from + raw_source + , lateral + flatten(input => src:events) ; diff --git a/tests/data/unformatted/110_other_identifiers.sql b/tests/data/unformatted/110_other_identifiers.sql index 2aa7f1f..21d2efc 100644 --- a/tests/data/unformatted/110_other_identifiers.sql +++ b/tests/data/unformatted/110_other_identifiers.sql @@ -3,5 +3,15 @@ select from @my_stage( file_format => 'csv_format', pattern => '.*my_pattern.*') v )))))__SQLFMT_OUTPUT__((((( -select v.$1, v.$2, ?3, ?4 -from @my_stage(file_format => 'csv_format', pattern => '.*my_pattern.*') v +select + v.$1 + , v.$2 + , ?3 + , ?4 +from + @my_stage( + file_format + => 'csv_format' + , pattern + => '.*my_pattern.*' + ) v diff --git a/tests/data/unformatted/111_chained_boolean_between.sql b/tests/data/unformatted/111_chained_boolean_between.sql index 8f561d5..2711fdc 100644 --- a/tests/data/unformatted/111_chained_boolean_between.sql +++ b/tests/data/unformatted/111_chained_boolean_between.sql @@ -17,15 +17,20 @@ where and lat between -90 and 90 )))))__SQLFMT_OUTPUT__((((( select - radio, - mcc, - net as mnc, - area as lac, - cell % 65536 as cid, - cell / 65536 as rnc, - cell as long_cid, - lon, - lat + radio + , mcc + , + net as mnc + , + area as lac + , cell + % 65536 as cid + , cell + / 65536 as rnc + , + cell as long_cid + , lon + , lat from towershift where radio != 'CDMA' diff --git a/tests/data/unformatted/112_semicolons.sql b/tests/data/unformatted/112_semicolons.sql index b470acc..093006f 100644 --- a/tests/data/unformatted/112_semicolons.sql +++ b/tests/data/unformatted/112_semicolons.sql @@ -10,12 +10,22 @@ where something and something_else ; )))))__SQLFMT_OUTPUT__((((( -select several_fields, several_fields, several_fields, several_fields, several_fields +select + several_fields + , several_fields + , several_fields + , several_fields + , several_fields from my_model ; select one_liner ; -select several_fields, several_fields, several_fields, several_fields, several_fields +select + several_fields + , several_fields + , several_fields + , several_fields + , several_fields from my_model where something and something_else ; diff --git a/tests/data/unformatted/113_utils_group_by.sql b/tests/data/unformatted/113_utils_group_by.sql index a92b2f4..7775499 100644 --- a/tests/data/unformatted/113_utils_group_by.sql +++ b/tests/data/unformatted/113_utils_group_by.sql @@ -14,16 +14,16 @@ where something_is_true {{ dbt_utils.group_by(10) }} -- todo: keep line break )))))__SQLFMT_OUTPUT__((((( select - field_a, - field_a, - field_a, - field_a, - field_a, - field_a, - field_a, - field_a, - field_a, - field_a, - count(*) + field_a + , field_a + , field_a + , field_a + , field_a + , field_a + , field_a + , field_a + , field_a + , field_a + , count(*) from my_table where something_is_true {{ dbt_utils.group_by(10) }} -- todo: keep line break diff --git a/tests/data/unformatted/114_unions.sql b/tests/data/unformatted/114_unions.sql index 1d49bdb..d817156 100644 --- a/tests/data/unformatted/114_unions.sql +++ b/tests/data/unformatted/114_unions.sql @@ -77,11 +77,13 @@ union union all ( select - 'median_time_s' as ranking, - client, - category, - canonicaldomain, - median_time_s as metric, + 'median_time_s' as ranking + , client + , category + , canonicaldomain + , + median_time_s as metric + , dense_rank() over ( partition by client order by median_time_s desc ) as sorted_order @@ -91,27 +93,27 @@ union all with geos as ( select - *, - 'mr' as geo_code, - 'Mauritania' as geo, - 'Africa' as region, - 'Western Africa' as subregion + * + , 'mr' as geo_code + , 'Mauritania' as geo + , 'Africa' as region + , 'Western Africa' as subregion from `chrome-ux-report.country_mr.201907` union all select - *, - 'mu' as geo_code, - 'Mauritius' as geo, - 'Africa' as region, - 'Eastern Africa' as subregion + * + , 'mu' as geo_code + , 'Mauritius' as geo + , 'Africa' as region + , 'Eastern Africa' as subregion from `chrome-ux-report.country_mu.201907` union all select - *, - 'yt' as geo_code, - 'Mayotte' as geo, - 'Africa' as region, - 'Eastern Africa' as subregion + * + , 'yt' as geo_code + , 'Mayotte' as geo + , 'Africa' as region + , 'Eastern Africa' as subregion from `chrome-ux-report.country_yt.201907` ) select geo diff --git a/tests/data/unformatted/115_select_star_except.sql b/tests/data/unformatted/115_select_star_except.sql index 52cbb6e..7d3a1fe 100644 --- a/tests/data/unformatted/115_select_star_except.sql +++ b/tests/data/unformatted/115_select_star_except.sql @@ -29,48 +29,67 @@ left join recentagg_toppositivesymptoms_array using (id) left join recentagg_topactivities_array using (id) )))))__SQLFMT_OUTPUT__((((( select - * except (field_a, field_b, field_c), - field_a::int as field_a, - field_b::varchar as field_b, - field_c::decimal(10, 2) as field_c + * except ( + field_a + , field_b + , field_c + ) + , field_a::int as field_a + , field_b::varchar as field_b + , field_c::decimal( + 10 + , 2 + ) as field_c from my_table ; select * except ( - really_long_field_a, - really_long_field_b, - really_long_field_c, - really_long_field_d - ), - really_long_field_a::int as field_a + really_long_field_a + , really_long_field_b + , really_long_field_c + , really_long_field_d + ) + , really_long_field_a::int as field_a from my_table ; select - * exclude (field_a, field_b, field_c), - field_a::int as field_a, - field_b::varchar as field_b, - field_c::decimal(10, 2) as field_c + * exclude ( + field_a + , field_b + , field_c + ) + , field_a::int as field_a + , field_b::varchar as field_b + , field_c::decimal( + 10 + , 2 + ) as field_c from my_table ; select * replace ( - really_long_field_a as really_long_field_b, - really_long_field_c as really_long_field_d - ), - replace(one_thing, another_thing, some_string) + really_long_field_a as really_long_field_b + , really_long_field_c as really_long_field_d + ) + , replace( + one_thing + , another_thing + , some_string + ) from my_table ; select - recentagg_root.* except (recentagg), - ( + recentagg_root.* + except (recentagg) + , ( select as struct - recentagg.*, - recentagg_topphases_array.topphases, - recentagg_topsymptoms_array.topsymptoms, - recentagg_toppositivesymptoms_array.toppositivesymptoms, - recentagg_topactivities_array.topactivities, - ) recentagg, -from recentagg_root + recentagg.* + , recentagg_topphases_array.topphases + , recentagg_topsymptoms_array.topsymptoms + , recentagg_toppositivesymptoms_array.toppositivesymptoms + , recentagg_topactivities_array.topactivities + ,) recentagg + , from recentagg_root left join recentagg_topphases_array using (id) left join recentagg_topsymptoms_array using (id) left join recentagg_toppositivesymptoms_array using (id) diff --git a/tests/data/unformatted/117_whitespace_in_tokens.sql b/tests/data/unformatted/117_whitespace_in_tokens.sql index 44f3fde..33e7659 100644 --- a/tests/data/unformatted/117_whitespace_in_tokens.sql +++ b/tests/data/unformatted/117_whitespace_in_tokens.sql @@ -23,7 +23,12 @@ comment */ select top 25 * from "my table" -where id not in (1, 2, 3) +where + id not in ( + 1 + , 2 + , 3 + ) union all select distinct * from "your table" diff --git a/tests/data/unformatted/118_within_group.sql b/tests/data/unformatted/118_within_group.sql index c57d4a0..3c955e8 100644 --- a/tests/data/unformatted/118_within_group.sql +++ b/tests/data/unformatted/118_within_group.sql @@ -8,13 +8,15 @@ from my_table as foobar select array_agg(distinct foobar.my_special_foo) within group ( order by foobar.another_foo - ) as a_very_long_alias, - array_agg( + ) as a_very_long_alias + , array_agg( distinct foobar.my_special_foo || foobar.another_very_long_foo - ) within group (order by foobar.another_foo desc) as a_very_long_alias, + ) within group (order by foobar.another_foo desc) as a_very_long_alias + , array_agg(distinct foobar.my_special_foo) within group ( order by foobar.another_foo - ) filter (where barbar = "bazbaz" and bazbaz = "quxqux") as something_else, + ) filter (where barbar = "bazbaz" and bazbaz = "quxqux") as something_else + , array_agg(distinct foobar.my_special_foo) within group ( order by foobar.another_foo ) filter ( diff --git a/tests/data/unformatted/119_psycopg_placeholders.sql b/tests/data/unformatted/119_psycopg_placeholders.sql index b1f5ac1..27c92b0 100644 --- a/tests/data/unformatted/119_psycopg_placeholders.sql +++ b/tests/data/unformatted/119_psycopg_placeholders.sql @@ -5,7 +5,16 @@ select image_data from images where id = %s ; -select image_data, dividend %% divisor as escaped_mod_operator +select + image_data + , dividend + %% divisor as escaped_mod_operator from images -where id in (%(one)s, %(two)s, %(three)s, %(f!o^u+r)s) +where + id in ( + %(one)s + , %(two)s + , %(three)s + , %(f!o^u+r)s + ) ; diff --git a/tests/data/unformatted/120_array_literals.sql b/tests/data/unformatted/120_array_literals.sql index 263c8b1..2d2a376 100644 --- a/tests/data/unformatted/120_array_literals.sql +++ b/tests/data/unformatted/120_array_literals.sql @@ -9,16 +9,33 @@ select from bar )))))__SQLFMT_OUTPUT__((((( select - 'xero' as billing_platform, - [invoice_id, invoice.invoice_number] as billing_platform_references, - usage_activity_by_stage_monthly['manage'][ + 'xero' as billing_platform + , [ + invoice_id + , invoice.invoice_number + ] as billing_platform_references + , usage_activity_by_stage_monthly['manage'][ 'events' ] as monthly_active_users_last_28_days from hello ; select - split_array('foo, bar, baz, qux', ',')[2] as baz, - ['foo', 'bar', 'baz', 'qux'] as literal, - ['foo', 'bar', 'baz', 'qux'][2] as indexed_literal, + split_array( + 'foo, bar, baz, qux' + , ',' + )[2] as baz + , [ + 'foo' + , 'bar' + , 'baz' + , 'qux' + ] as literal + , [ + 'foo' + , 'bar' + , 'baz' + , 'qux' + ][2] as indexed_literal + , some_table.some_dict['a key'] as dict_access from bar diff --git a/tests/data/unformatted/121_stubborn_merge_edge_cases.sql b/tests/data/unformatted/121_stubborn_merge_edge_cases.sql index 816ab18..9cf7ab2 100644 --- a/tests/data/unformatted/121_stubborn_merge_edge_cases.sql +++ b/tests/data/unformatted/121_stubborn_merge_edge_cases.sql @@ -65,48 +65,79 @@ countif((stats.checkboxes > 0 or stats.radios > 0) with joined as ( select - d.*, - d.days_in_deal_stage_0 - + coalesce(d.days_in_deal_stage_1, 0) - + coalesce(d.days_in_deal_stage_2, 0) - + coalesce(d.days_in_deal_stage_3, 0) - + coalesce(d.days_in_deal_stage_4, 0) - + coalesce(d.days_in_deal_stage_5, 0) - + coalesce(d.days_in_deal_stage_6, 0) - + coalesce(d.days_in_deal_stage_7, 0) as days_in_pipeline, - p.pipeline_label, - p.pipeline_display_order, - s.pipeline_stage_label, - s.pipeline_stage_display_order, - s.pipeline_stage_close_probability_pct, - s.pipeline_stage_closed_won, - u.owner_full_name, - u.owner_email + d.* + , + d.days_in_deal_stage_0 + coalesce( + d.days_in_deal_stage_1 + , 0 + ) + + coalesce( + d.days_in_deal_stage_2 + , 0 + ) + + coalesce( + d.days_in_deal_stage_3 + , 0 + ) + + coalesce( + d.days_in_deal_stage_4 + , 0 + ) + + coalesce( + d.days_in_deal_stage_5 + , 0 + ) + + coalesce( + d.days_in_deal_stage_6 + , 0 + ) + + coalesce( + d.days_in_deal_stage_7 + , 0 + ) as days_in_pipeline + , p.pipeline_label + , p.pipeline_display_order + , s.pipeline_stage_label + , s.pipeline_stage_display_order + , s.pipeline_stage_close_probability_pct + , s.pipeline_stage_closed_won + , u.owner_full_name + , u.owner_email from renamed d join hubspot_deal_stages s on d.deal_pipeline_stage_id = s.pipeline_stage_id join hubspot_deal_pipelines_source p on s.pipeline_id = p.pipeline_id left outer join hubspot_deal_owners u on safe_cast(d.deal_owner_id as int64) = u.owner_id - ), + ) + , converting_sessions_deduped as ( select - session_id session_id, - max(blended_user_id) as blended_user_id, - sum(first_order_total_revenue) as first_order_total_revenue, - sum(repeat_order_total_revenue) as repeat_order_total_revenue, - max(currency_code) as currency_code, - sum(count_first_order_conversions) as count_first_order_conversions, - sum(count_repeat_order_conversions) as count_repeat_order_conversions, - sum(count_order_conversions) as count_order_conversions, - sum(count_registration_conversions) as count_registration_conversions, - sum(count_registration_conversions) + session_id session_id + , + max(blended_user_id) as blended_user_id + , + sum(first_order_total_revenue) as first_order_total_revenue + , + sum(repeat_order_total_revenue) as repeat_order_total_revenue + , + max(currency_code) as currency_code + , + sum(count_first_order_conversions) as count_first_order_conversions + , + sum(count_repeat_order_conversions) as count_repeat_order_conversions + , + sum(count_order_conversions) as count_order_conversions + , + sum(count_registration_conversions) as count_registration_conversions + , sum(count_registration_conversions) + sum(count_first_order_conversions) - + sum(count_repeat_order_conversions) as count_conversions, + + sum(count_repeat_order_conversions) as count_conversions + , max(converted_ts) as converted_ts from converting_events group by 1 - ), -select * + ) + , select * from converting_sessions_deduped ; -- COPYRIGHT HTTP ARCHIVE diff --git a/tests/data/unformatted/122_values.sql b/tests/data/unformatted/122_values.sql index 7846064..09762a8 100644 --- a/tests/data/unformatted/122_values.sql +++ b/tests/data/unformatted/122_values.sql @@ -10,28 +10,48 @@ from (values ('some long string literal', 'another very long literal', 'more str ) as v; )))))__SQLFMT_OUTPUT__((((( select * -from (values (1, 2, 3), (4, 5, 6)) +from + ( + values + ( + 1 + , 2 + , 3 + ) + , ( + 4 + , 5 + , 6 + ) + ) ; select * from ( values ( - 'some long string literal', - 'another very long literal', - 'more string literal values', - 1, - 2, - 3 - ), - ( - 'some long string literal', - 'another very long literal', - 'more string literal values', - 4, - 5, - 6 - ), - ('something shorter', 'short', 'fits', 7, 8, 9) + 'some long string literal' + , 'another very long literal' + , 'more string literal values' + , 1 + , 2 + , 3 + ) + , ( + 'some long string literal' + , 'another very long literal' + , 'more string literal values' + , 4 + , 5 + , 6 + ) + , ( + 'something shorter' + , 'short' + , 'fits' + , 7 + , 8 + , 9 + ) ) as v ; diff --git a/tests/data/unformatted/123_spark_keywords.sql b/tests/data/unformatted/123_spark_keywords.sql index 649c431..0607cb3 100644 --- a/tests/data/unformatted/123_spark_keywords.sql +++ b/tests/data/unformatted/123_spark_keywords.sql @@ -30,71 +30,107 @@ from a_super_duper_really_very_long_long_long_long_table_name tablesample (bucket 4 out of 10) ; -select age, name +select + age + , name from person cluster by age ; select - foooooooooooooooooooooooooo, - barrrrrrrrrrrrrrrrrrrrrrrrrrrr, - bazzzzzzzzzzzzzzzzzzzzzzzzzz, - quxxxxxxxxxxxxxxxxxxxxxxxxxx + foooooooooooooooooooooooooo + , barrrrrrrrrrrrrrrrrrrrrrrrrrrr + , bazzzzzzzzzzzzzzzzzzzzzzzzzz + , quxxxxxxxxxxxxxxxxxxxxxxxxxx from person cluster by - foooooooooooooooooooooooooo, - barrrrrrrrrrrrrrrrrrrrrrrrrrrr, - bazzzzzzzzzzzzzzzzzzzzzzzzzz, - quxxxxxxxxxxxxxxxxxxxxxxxxxx + foooooooooooooooooooooooooo + , barrrrrrrrrrrrrrrrrrrrrrrrrrrr + , bazzzzzzzzzzzzzzzzzzzzzzzzzz + , quxxxxxxxxxxxxxxxxxxxxxxxxxx ; -select age, name +select + age + , name from person distribute by age ; select - foooooooooooooooooooooooooo, - barrrrrrrrrrrrrrrrrrrrrrrrrrrr, - bazzzzzzzzzzzzzzzzzzzzzzzzzz, - quxxxxxxxxxxxxxxxxxxxxxxxxxx + foooooooooooooooooooooooooo + , barrrrrrrrrrrrrrrrrrrrrrrrrrrr + , bazzzzzzzzzzzzzzzzzzzzzzzzzz + , quxxxxxxxxxxxxxxxxxxxxxxxxxx from person distribute by - foooooooooooooooooooooooooo, - barrrrrrrrrrrrrrrrrrrrrrrrrrrr, - bazzzzzzzzzzzzzzzzzzzzzzzzzz, - quxxxxxxxxxxxxxxxxxxxxxxxxxx + foooooooooooooooooooooooooo + , barrrrrrrrrrrrrrrrrrrrrrrrrrrr + , bazzzzzzzzzzzzzzzzzzzzzzzzzz + , quxxxxxxxxxxxxxxxxxxxxxxxxxx ; -select age, name +select + age + , name from person sort by age ; select - foooooooooooooooooooooooooo, - barrrrrrrrrrrrrrrrrrrrrrrrrrrr, - bazzzzzzzzzzzzzzzzzzzzzzzzzz, - quxxxxxxxxxxxxxxxxxxxxxxxxxx + foooooooooooooooooooooooooo + , barrrrrrrrrrrrrrrrrrrrrrrrrrrr + , bazzzzzzzzzzzzzzzzzzzzzzzzzz + , quxxxxxxxxxxxxxxxxxxxxxxxxxx from person sort by - foooooooooooooooooooooooooo, - barrrrrrrrrrrrrrrrrrrrrrrrrrrr, - bazzzzzzzzzzzzzzzzzzzzzzzzzz, - quxxxxxxxxxxxxxxxxxxxxxxxxxx + foooooooooooooooooooooooooo + , barrrrrrrrrrrrrrrrrrrrrrrrrrrr + , bazzzzzzzzzzzzzzzzzzzzzzzzzz + , quxxxxxxxxxxxxxxxxxxxxxxxxxx ; select * from - person - pivot (sum(age) as a, avg(class) as c for name in ('John' as john, 'Mike' as mike)) + person pivot ( + sum(age) as a + , avg(class) as c + for name in ( + 'John' as john + , 'Mike' as mike + ) + ) ; select * from person pivot ( - sum(age) as a, - avg(class) as c - for(name, age) in (('John', 30) as c1, ('Mike', 40) as c2) + sum(age) as a + , avg(class) as c + for( + name + , age + ) in ( + ( + 'John' + , 30 + ) as c1 + , ( + 'Mike' + , 40 + ) as c2 + ) ) ; select * from person -lateral view explode(array(30, 60)) tablename as c_age -lateral view explode(array(40, 80)) as d_age +lateral view + explode( + array( + 30 + , 60 + ) + ) tablename as c_age +lateral view + explode( + array( + 40 + , 80 + ) + ) as d_age ; select * from person diff --git a/tests/data/unformatted/124_bq_compound_types.sql b/tests/data/unformatted/124_bq_compound_types.sql index 790ab46..d3e62f9 100644 --- a/tests/data/unformatted/124_bq_compound_types.sql +++ b/tests/data/unformatted/124_bq_compound_types.sql @@ -13,14 +13,48 @@ bytes( as bar )))))__SQLFMT_OUTPUT__((((( select - array[1, 2, 3] as floats, - struct("Nathan" as name, array[] as laps), - struct(1, 2), - array[ - 3, 4, 5, 6, 1000000, 20000000, 30000000, 409000000, 5000000, 60000000, 700000 - ] as ints, - array['1', '2', '3'] as strings + array[ + 1 + , 2 + , 3 + ] as floats + , struct( + "Nathan" as name + , array[] as laps + ) + , struct( + 1 + , 2 + ) + , array[ + 3 + , 4 + , 5 + , 6 + , 1000000 + , 20000000 + , 30000000 + , 409000000 + , 5000000 + , 60000000 + , 700000 + ] as ints + , array[ + '1' + , '2' + , '3' + ] as strings ; -create function foo(bar array, int64>>) -returns array, int64>> +create function + foo( + bar array + , int64>> + ) +returns + array + , int64>> as bar diff --git a/tests/data/unformatted/125_numeric_literals.sql b/tests/data/unformatted/125_numeric_literals.sql index 0424f50..9966990 100644 --- a/tests/data/unformatted/125_numeric_literals.sql +++ b/tests/data/unformatted/125_numeric_literals.sql @@ -1,28 +1,28 @@ select 1, 1.0, +1, +1.0, -1, -1.0, 1e9, 1e+9, 1e-9, -1e9, -1e+9, +1e-9, -1e-9, 1.6e9, 1.6e-9, 1., 1.e9, 1.e-9, -1., -1.e-9, 0xFF, 0b000111, 0O2112, 1_000_000, 3.141_592_6 )))))__SQLFMT_OUTPUT__((((( select - 1, - 1.0, - +1, - +1.0, - -1, - -1.0, - 1e9, - 1e+9, - 1e-9, - -1e9, - -1e+9, - +1e-9, - -1e-9, - 1.6e9, - 1.6e-9, - 1., - 1.e9, - 1.e-9, - -1., - -1.e-9, - 0xff, - 0b000111, - 0o2112, - 1_000_000, - 3.141_592_6 + 1 + , 1.0 + , +1 + , +1.0 + , -1 + , -1.0 + , 1e9 + , 1e+9 + , 1e-9 + , -1e9 + , -1e+9 + , +1e-9 + , -1e-9 + , 1.6e9 + , 1.6e-9 + , 1. + , 1.e9 + , 1.e-9 + , -1. + , -1.e-9 + , 0xff + , 0b000111 + , 0o2112 + , 1_000_000 + , 3.141_592_6 diff --git a/tests/data/unformatted/126_blank_lines.sql b/tests/data/unformatted/126_blank_lines.sql index a94386d..8bdb96f 100644 --- a/tests/data/unformatted/126_blank_lines.sql +++ b/tests/data/unformatted/126_blank_lines.sql @@ -53,14 +53,11 @@ select 1 select - foooooooooooo, - barrrrrrrrrrr, - - bazzzzzzzzzzz, - - quxxxxxxxxxxx, - foooooooooooo + , barrrrrrrrrrr + , bazzzzzzzzzzz + , quxxxxxxxxxxx + , foooooooooooo + barrrrrrrrrr + bazzzzzzzzzzz + quxxxxxxxxxxx as foooooooooooo_bar_baz_qux diff --git a/tests/data/unformatted/127_more_comments.sql b/tests/data/unformatted/127_more_comments.sql index c33513b..0e85d22 100644 --- a/tests/data/unformatted/127_more_comments.sql +++ b/tests/data/unformatted/127_more_comments.sql @@ -34,23 +34,27 @@ with table_a as ( select /* Notice that this select statement can fit on a single line without comments */ - col1, - col2, -- col2 + col1 + , col2 + , -- col2 /* Special column */ - special_column, - from {{ ref("table_a") }} - ), + special_column + , from {{ ref("table_a") }} + ) + /* Some interesting comments above a CTE with a leading comma */ - table_b as (select * from {{ ref("table_b") }}) + , table_b as (select * from {{ ref("table_b") }}) select * -from table_a, table_b +from + table_a + , table_b ; select - 1, + 1 -- two - 2, -- two inline + , 2 -- two inline -- three - 3, -- three inline - 4 -- four inline + , 3 -- three inline + , 4 -- four inline diff --git a/tests/data/unformatted/129_duckdb_joins.sql b/tests/data/unformatted/129_duckdb_joins.sql index bf848a2..c271e1d 100644 --- a/tests/data/unformatted/129_duckdb_joins.sql +++ b/tests/data/unformatted/129_duckdb_joins.sql @@ -35,22 +35,31 @@ FROM trades t ASOF LEFT JOIN prices p USING (symbol, created_at); -- Source https://duckdb.org/docs/sql/query_syntax/from.html -- Copyright DuckDB Foundation. -- return a list of cars that have a valid region. -select cars.name, cars.manufacturer +select + cars.name + , cars.manufacturer from cars semi join region on cars.region = region.id ; -- return a list of cars with no recorded safety data. -select cars.name, cars.manufacturer +select + cars.name + , cars.manufacturer from cars anti join safety_data on cars.safety_report_id = safety_data.report_id ; select * -from range(3) t(i), lateral(select i + 1) t2(j) +from + range(3) t(i) + , lateral(select i + 1) t2(j) ; select * from - generate_series(0, 1) t(i), - lateral( + generate_series( + 0 + , 1 + ) t(i) + , lateral( select i + 10 union all select i + 100 @@ -58,15 +67,21 @@ from ; CREATE TABLE t1 AS SELECT * FROM range(3) t(i), LATERAL (SELECT i + 1) t2(j); select * -from t1, lateral(select i + j) t2(k) +from + t1 + , lateral(select i + j) t2(k) ; -- treat two data frames as a single table -select df1.*, df2.* +select + df1.* + , df2.* from df1 positional join df2 ; -- attach prices to stock trades -select t.*, p.price +select + t.* + , p.price from trades t asof join prices p on t.symbol = p.symbol and t.created_at >= p.created_at ; @@ -77,10 +92,22 @@ asof left join prices p on t.symbol = p.symbol and t.created_at >= p.created_at ; select * from trades t -asof join prices p using (symbol, created_at) +asof join prices p using + ( + symbol + , created_at + ) ; -- Returns symbol, trades.created_at, price (but NOT prices.created_at) -select t.symbol, t.created_at as trade_when, p.created_at as price_when, price +select + t.symbol + , t.created_at as trade_when + , p.created_at as price_when + , price from trades t -asof left join prices p using (symbol, created_at) +asof left join prices p using + ( + symbol + , created_at + ) ; diff --git a/tests/data/unformatted/130_athena_data_types.sql b/tests/data/unformatted/130_athena_data_types.sql index d712267..f8862cd 100644 --- a/tests/data/unformatted/130_athena_data_types.sql +++ b/tests/data/unformatted/130_athena_data_types.sql @@ -6,4 +6,10 @@ json_parse(foo) as array< from dwh.table )))))__SQLFMT_OUTPUT__((((( -- source: https://github.com/tconbeer/sqlfmt/issues/500 -select cast(json_parse(foo) as array>) from dwh.table +select + cast( + json_parse(foo) as array< + map> + ) +from dwh.table diff --git a/tests/data/unformatted/131_assignment_statement.sql b/tests/data/unformatted/131_assignment_statement.sql index 28430d7..7de709c 100644 --- a/tests/data/unformatted/131_assignment_statement.sql +++ b/tests/data/unformatted/131_assignment_statement.sql @@ -2,6 +2,11 @@ select partman.create_parent( 'public.deliveries_finished', 'created_at', 'nativ )))))__SQLFMT_OUTPUT__((((( select partman.create_parent( - 'public.deliveries_finished', 'created_at', 'native', 'daily', p_premake := 20 + 'public.deliveries_finished' + , 'created_at' + , 'native' + , 'daily' + , p_premake + := 20 ) ; diff --git a/tests/data/unformatted/135_star_columns.sql b/tests/data/unformatted/135_star_columns.sql index b10ad71..95d96f9 100644 --- a/tests/data/unformatted/135_star_columns.sql +++ b/tests/data/unformatted/135_star_columns.sql @@ -2,4 +2,13 @@ SELECT coalesce(*COLUMNS(['a', 'b', 'c'])) AS result )))))__SQLFMT_OUTPUT__((((( -- https://github.com/tconbeer/sqlfmt/issues/657 -select coalesce(*columns(['a', 'b', 'c'])) as result +select + coalesce( + *columns( + [ + 'a' + , 'b' + , 'c' + ] + ) + ) as result diff --git a/tests/data/unformatted/200_base_model.sql b/tests/data/unformatted/200_base_model.sql index 7000dbf..cb1e560 100644 --- a/tests/data/unformatted/200_base_model.sql +++ b/tests/data/unformatted/200_base_model.sql @@ -38,46 +38,108 @@ with source as (select * from {{ source('my_application', 'users') }}), select * from renamed )))))__SQLFMT_OUTPUT__((((( with - source as (select * from {{ source("my_application", "users") }}), + source as (select * from {{ source("my_application", "users") }}) + , renamed as ( select -- ids - id, - nullif(xid, '') as xid, - + id + , nullif( + xid + , '' + ) as xid -- date - created_on, - updated_on, - - nullif(email, '') as email, - + , created_on + , updated_on + , nullif( + email + , '' + ) as email -- names - nullif(full_name, '') as full_name, - nullif( + , nullif( + full_name + , '' + ) as full_name + , nullif( trim( case - when regexp_count(nullif(full_name, ''), ' ') = 0 - then nullif(full_name, '') - when regexp_count(nullif(full_name, ''), ' ') = 1 - then split_part(nullif(full_name, ''), ' ', 1) - else regexp_substr(nullif(full_name, ''), '.* .* ') -- let's explain what is going on here + when + regexp_count( + nullif( + full_name + , '' + ) + , ' ' + ) + = 0 + then + nullif( + full_name + , '' + ) + when + regexp_count( + nullif( + full_name + , '' + ) + , ' ' + ) + = 1 + then + split_part( + nullif( + full_name + , '' + ) + , ' ' + , 1 + ) + else + regexp_substr( + nullif( + full_name + , '' + ) + , '.* .* ' + ) -- let's explain what is going on here end - ), - 'TEST_USER' - ) as first_name, - nullif( + ) + , 'TEST_USER' + ) as first_name + , nullif( split_part( - nullif(full_name, ''), - ' ', - greatest(2, regexp_count(nullif(full_name, ''), ' ') + 1) - ), - '' + nullif( + full_name + , '' + ) + , ' ' + , greatest( + 2 + , regexp_count( + nullif( + full_name + , '' + ) + , ' ' + ) + + 1 + ) + ) + , '' ) as last_name from source - where nvl(is_deleted, false) is false and id <> 123456 -- a very long comment about why we would exclude this user from this table that we will not wrap + where + + nvl( + is_deleted + , false + ) + is false + and id <> 123456 -- a very long comment about why we would exclude this user from this table that we will not wrap ) select * diff --git a/tests/data/unformatted/202_unpivot_macro.sql b/tests/data/unformatted/202_unpivot_macro.sql index 29e91f8..97f96be 100644 --- a/tests/data/unformatted/202_unpivot_macro.sql +++ b/tests/data/unformatted/202_unpivot_macro.sql @@ -79,12 +79,15 @@ {%- for col in include_cols -%} select - {%- for exclude_col in exclude %} {{ exclude_col }}, {%- endfor %} + {%- for exclude_col in exclude %} + {{ exclude_col }} + , + {%- endfor %} cast( '{{ col.column }}' as {{ dbt_utils.type_string() }} - ) as {{ field_name }}, - cast( + ) as {{ field_name }} + , cast( {% if col.data_type == "boolean" %} {{ dbt_utils.cast_bool_to_text(col.column) }} {% else %}{{ col.column }} diff --git a/tests/data/unformatted/203_gitlab_email_domain_type.sql b/tests/data/unformatted/203_gitlab_email_domain_type.sql index 6187915..950f746 100644 --- a/tests/data/unformatted/203_gitlab_email_domain_type.sql +++ b/tests/data/unformatted/203_gitlab_email_domain_type.sql @@ -49,8 +49,12 @@ END case when - {{ lead_source }} - in ('DiscoverOrg', 'Zoominfo', 'Purchased List', 'GitLab.com') + {{ lead_source }} in ( + 'DiscoverOrg' + , 'Zoominfo' + , 'Purchased List' + , 'GitLab.com' + ) then 'Bulk load or list purchase or spam impacted' when trim({{ email_domain }}) is null then 'Missing email domain' @@ -58,19 +62,28 @@ END when {{ email_domain }} like any ( {%- for personal_email_domain in personal_email_domains_partial_match -%} - '%{{personal_email_domain}}%' {%- if not loop.last -%}, {% endif %} + '%{{personal_email_domain}}%' + {%- if not loop.last -%} + , + {% endif %} {% endfor %} ) or {{ email_domain }} in ( {%- for personal_email_domain in personal_email_domains_full_match -%} - '{{personal_email_domain}}' {%- if not loop.last -%}, {% endif %} + '{{personal_email_domain}}' + {%- if not loop.last -%} + , + {% endif %} {% endfor %} ) or not {{ email_domain }} not in ( {%- for personal_email_domain in personal_email_domains_full_match -%} - '{{personal_email_domain}}' {%- if not loop.last -%}, {% endif %} + '{{personal_email_domain}}' + {%- if not loop.last -%} + , + {% endif %} {% endfor %} ) diff --git a/tests/data/unformatted/205_rittman_hubspot_deals.sql b/tests/data/unformatted/205_rittman_hubspot_deals.sql index 9526bd3..0c77ef4 100644 --- a/tests/data/unformatted/205_rittman_hubspot_deals.sql +++ b/tests/data/unformatted/205_rittman_hubspot_deals.sql @@ -108,70 +108,104 @@ select * from joined with source as ( select * from {{ source("fivetran_hubspot_crm", "deals") }} - ), + ) + , hubspot_deal_company as ( select * from {{ source("fivetran_hubspot_crm", "deal_companies") }} - ), + ) + , hubspot_deal_pipelines_source as ( select * from {{ source("fivetran_hubspot_crm", "pipelines") }} - ), + ) + , hubspot_deal_property_history as ( select * from {{ source("fivetran_hubspot_crm", "property_history") }} - ), + ) + , hubspot_deal_stages as ( select * from {{ source("fivetran_hubspot_crm", "pipeline_stages") }} - ), + ) + , hubspot_deal_owners as ( select * from {{ source("fivetran_hubspot_crm", "owners") }} - ), + ) + , renamed as ( select - deal_id as deal_id, - property_dealname as deal_name, - property_dealtype as deal_type, - property_description as deal_description, - deal_pipeline_stage_id as deal_pipeline_stage_id, - deal_pipeline_id as deal_pipeline_id, - is_deleted as deal_is_deleted, - property_amount as deal_amount, - owner_id as deal_owner_id, - property_amount_in_home_currency - as deal_amount_local_currency, - property_closed_lost_reason as deal_closed_lost_reason, - property_closedate as deal_closed_date, - property_createdate as deal_created_date, + deal_id as deal_id + , + property_dealname as deal_name + , + property_dealtype as deal_type + , + property_description as deal_description + , + deal_pipeline_stage_id as deal_pipeline_stage_id + , + deal_pipeline_id as deal_pipeline_id + , + is_deleted as deal_is_deleted + , + property_amount as deal_amount + , + owner_id as deal_owner_id + , property_amount_in_home_currency + as deal_amount_local_currency + , + property_closed_lost_reason as deal_closed_lost_reason + , + property_closedate as deal_closed_date + , + property_createdate as deal_created_date + , property_hs_lastmodifieddate as deal_last_modified_date from source - ), + ) + , joined as ( select - d.deal_id, - concat( - '{{ var(' stg_hubspot_crm_id - prefix ') }}', - cast(a.company_id as string) - ) as company_id, - d.* except (deal_id), - timestamp_millis( + d.deal_id + , concat( + '{{ var(' stg_hubspot_crm_id + - prefix ') }}' + , cast(a.company_id as string) + ) as company_id + , d.* + except (deal_id) + , timestamp_millis( safe_cast(h.value as int64) - ) as deal_pipeline_stage_ts, - p.label as pipeline_label, - p.display_order as pipeline_display_order, - s.label as pipeline_stage_label, - s.display_order as pipeline_stage_display_order, - s.probability as pipeline_stage_close_probability_pct, - s.closed_won as pipeline_stage_closed_won, - concat(u.first_name, ' ', u.last_name) as owner_full_name, + ) as deal_pipeline_stage_ts + , + p.label as pipeline_label + , + p.display_order as pipeline_display_order + , + s.label as pipeline_stage_label + , + s.display_order as pipeline_stage_display_order + , + s.probability as pipeline_stage_close_probability_pct + , + s.closed_won as pipeline_stage_closed_won + , concat( + u.first_name + , ' ' + , u.last_name + ) as owner_full_name + , u.email as owner_email from renamed d left outer join hubspot_deal_company a on d.deal_id = a.deal_id left outer join hubspot_deal_property_history h on d.deal_id = h.deal_id - and h.name - = concat('hs_date_entered_', d.deal_pipeline_stage_id) + and h.name = concat( + 'hs_date_entered_' + , d.deal_pipeline_stage_id + ) join hubspot_deal_stages s on d.deal_pipeline_stage_id = s.stage_id diff --git a/tests/data/unformatted/206_gitlab_prep_geozone.sql b/tests/data/unformatted/206_gitlab_prep_geozone.sql index 5021e6c..f5d0a00 100644 --- a/tests/data/unformatted/206_gitlab_prep_geozone.sql +++ b/tests/data/unformatted/206_gitlab_prep_geozone.sql @@ -52,65 +52,112 @@ FROM final # SEE: # https://github.com/tconbeer/gitlab-analytics-sqlfmt/blob/9360d2f1986c37615926b0416e8d0fb23cae3e6e/LICENSE with - source as (select * from {{ ref("geozones_yaml_flatten_source") }}), - grouping as ( + source as (select * from {{ ref("geozones_yaml_flatten_source") }}) + , grouping as ( select - geozone_title, - iff( - country = 'United States', - geozone_title || ', ' || country, - geozone_title - ) as geozone_locality, - 'All, ' || country as country_locality, - geozone_factor, - country, - state_or_province, - valid_from, - valid_to, - is_current, + geozone_title + , iff( + country + = 'United States' + , geozone_title + || ', ' + || country + , geozone_title + ) as geozone_locality + , 'All, ' + || country as country_locality + , geozone_factor + , country + , state_or_province + , valid_from + , valid_to + , is_current /* Filling in NULLs with a value for the inequality check in the next step of the gaps and islands problem (finding groups based on when the factor changes and not just the value of the factor) */ - lag(geozone_factor, 1, 0) over ( - partition by country, state_or_province order by valid_from - ) as lag_factor, + , lag( + geozone_factor + , 1 + , 0 + ) over ( + partition by + country + , state_or_province + order by valid_from + ) as lag_factor + , conditional_true_event(geozone_factor != lag_factor) over ( - partition by country, state_or_province order by valid_from - ) as locality_group, - lead(valid_from, 1) over ( - partition by country, state_or_province order by valid_from + partition by + country + , state_or_province + order by valid_from + ) as locality_group + , lead( + valid_from + , 1 + ) over ( + partition by + country + , state_or_province + order by valid_from ) as next_entry from source - ), - final as ( + ) + , final as ( select distinct - geozone_title, - geozone_factor, - geozone_locality, - country_locality, - country as geozone_country, - state_or_province as geozone_state_or_province, + geozone_title + , geozone_factor + , geozone_locality + , country_locality + , + country as geozone_country + , + state_or_province as geozone_state_or_province + , min(valid_from) over ( - partition by country, state_or_province, locality_group - )::date as first_file_date, + partition by + country + , state_or_province + , locality_group + )::date as first_file_date + , max(valid_to) over ( - partition by country, state_or_province, locality_group - )::date as last_file_date, + partition by + country + , state_or_province + , locality_group + )::date as last_file_date -- Fixed date represents when location factor becan to be collected in -- source data. - iff( - locality_group = 1, - least('2020-03-24', first_file_date), - first_file_date - ) as valid_from, - max(coalesce(next_entry,{{ var("tomorrow") }})) over ( - partition by country, state_or_province, locality_group - )::date as valid_to, + , iff( + locality_group + = 1 + , least( + '2020-03-24' + , first_file_date + ) + , first_file_date + ) as valid_from + , max( + coalesce( + next_entry + ,{{ var("tomorrow") }} + ) + ) over ( + partition by + country + , state_or_province + , locality_group + )::date as valid_to + , boolor_agg(is_current) over ( - partition by country, state_or_province, locality_group + partition by + country + , state_or_province + , locality_group ) as is_current_file from grouping diff --git a/tests/data/unformatted/207_rittman_int_journals.sql b/tests/data/unformatted/207_rittman_int_journals.sql index d43f476..0600ca9 100644 --- a/tests/data/unformatted/207_rittman_int_journals.sql +++ b/tests/data/unformatted/207_rittman_int_journals.sql @@ -38,7 +38,9 @@ select * from journal_merge_list {% set relation_source = "stg_" + source + "_journals" %} - select '{{source}}' as source, * + select + '{{source}}' as source + , * from {{ ref(relation_source) }} {% if not loop.last %} diff --git a/tests/data/unformatted/209_rittman_int_web_events_sessionized.sql b/tests/data/unformatted/209_rittman_int_web_events_sessionized.sql index 2c4d703..1bad3be 100644 --- a/tests/data/unformatted/209_rittman_int_web_events_sessionized.sql +++ b/tests/data/unformatted/209_rittman_int_web_events_sessionized.sql @@ -202,13 +202,15 @@ from ordered_conversion_tagged ) {% endif %} */ - ), + ) + , numbered as ( select - *, + * + , row_number() over ( partition by visitor_id order by event_ts @@ -216,13 +218,15 @@ from ordered_conversion_tagged from events - ), + ) + , lagged as ( select - *, + * + , lag(event_ts) over ( partition by visitor_id order by event_number @@ -230,37 +234,41 @@ from ordered_conversion_tagged from numbered - ), + ) + , diffed as ( select - *, - {{ dbt_utils.datediff("event_ts", "previous_event_ts", "second") }} + * + , {{ dbt_utils.datediff("event_ts", "previous_event_ts", "second") }} as period_of_inactivity from lagged - ), + ) + , new_sessions as ( select - *, - case + * + , case when period_of_inactivity * -1 <= {{ var("web_inactivity_cutoff") }} then 0 else 1 end as new_session from diffed - ), + ) + , session_numbers as ( select - *, + * + , sum(new_session) over ( partition by visitor_id @@ -270,80 +278,95 @@ from ordered_conversion_tagged from new_sessions - ), + ) + , session_ids as ( select - event_id, - event_type, - event_ts, - event_details, - page_title, - page_url_path, - referrer_host, - search, - page_url, - page_url_host, - gclid, - utm_term, - utm_content, - utm_medium, - utm_campaign, - utm_source, - ip, - visitor_id, - user_id, - device, - device_category, - event_number, - md5( + event_id + , event_type + , event_ts + , event_details + , page_title + , page_url_path + , referrer_host + , search + , page_url + , page_url_host + , gclid + , utm_term + , utm_content + , utm_medium + , utm_campaign + , utm_source + , ip + , visitor_id + , user_id + , device + , device_category + , event_number + , md5( cast( concat( - coalesce(cast(visitor_id as string), ''), - '-', - coalesce(cast(session_number as string), '') + coalesce( + cast(visitor_id as string) + , '' + ) + , '-' + , coalesce( + cast(session_number as string) + , '' + ) ) as string ) - ) as session_id, - site, - order_id, - total_revenue, - currency_code + ) as session_id + , site + , order_id + , total_revenue + , currency_code from session_numbers - ), - id_stitching as (select * from {{ ref("int_web_events_user_stitching") }}), + ) + , + id_stitching as (select * from {{ ref("int_web_events_user_stitching") }}) + , joined as ( select - session_ids.*, - - coalesce( - id_stitching.user_id, session_ids.visitor_id + session_ids.* + , coalesce( + id_stitching.user_id + , session_ids.visitor_id ) as blended_user_id from session_ids left join id_stitching on id_stitching.visitor_id = session_ids.visitor_id - ), + ) + , ordered as ( select - *, + * + , row_number() over ( partition by blended_user_id order by event_ts - ) as event_seq, + ) as event_seq + , row_number() over ( - partition by blended_user_id, session_id order by event_ts - ) as event_in_session_seq, - - case + partition by + blended_user_id + , session_id + order by event_ts + ) as event_in_session_seq + , case when event_type = 'Page View' - and session_id = lead(session_id, 1) over ( - partition by visitor_id order by event_number - ) + and session_id = lead( + session_id + , 1 + ) over (partition by visitor_id order by event_number) then {{ dbt_utils.datediff( @@ -355,56 +378,61 @@ from ordered_conversion_tagged end time_on_page_secs from joined - ), + ) + , ordered_conversion_tagged as ( select o.* {% if var("attribution_conversion_event_type") %} - , - case + , case when o.event_type in ( - '{{ var(' attribution_conversion_event_type ') }}', - '{{ var(' attribution_create_account_event_type ') }}' + '{{ var(' attribution_conversion_event_type ') }}' + , '{{ var(' attribution_create_account_event_type ') }}' ) then - lag(o.page_url, 1) over ( - partition by o.blended_user_id order by o.event_seq - ) - end as converting_page_url, - case + lag( + o.page_url + , 1 + ) over (partition by o.blended_user_id order by o.event_seq) + end as converting_page_url + , case when o.event_type in ( - '{{ var(' attribution_conversion_event_type ') }}', - '{{ var(' attribution_create_account_event_type ') }}' + '{{ var(' attribution_conversion_event_type ') }}' + , '{{ var(' attribution_create_account_event_type ') }}' ) then - lag(o.page_title, 1) over ( - partition by o.blended_user_id order by o.event_seq - ) - end as converting_page_title, - case + lag( + o.page_title + , 1 + ) over (partition by o.blended_user_id order by o.event_seq) + end as converting_page_title + , case when o.event_type in ( - '{{ var(' attribution_conversion_event_type ') }}', - '{{ var(' attribution_create_account_event_type ') }}' + '{{ var(' attribution_conversion_event_type ') }}' + , '{{ var(' attribution_create_account_event_type ') }}' ) then - lag(o.page_url, 2) over ( - partition by o.blended_user_id order by o.event_seq - ) - end as pre_converting_page_url, - case + lag( + o.page_url + , 2 + ) over (partition by o.blended_user_id order by o.event_seq) + end as pre_converting_page_url + , case when o.event_type in ( - '{{ var(' attribution_conversion_event_type ') }}', - '{{ var(' attribution_create_account_event_type ') }}' + '{{ var(' attribution_conversion_event_type ') }}' + , '{{ var(' attribution_create_account_event_type ') }}' ) then - lag(o.page_title, 2) over ( - partition by o.blended_user_id order by o.event_seq - ) - end as pre_converting_page_title, + lag( + o.page_title + , 2 + ) over (partition by o.blended_user_id order by o.event_seq) + end as pre_converting_page_title + , {% endif %} from ordered o ) diff --git a/tests/data/unformatted/210_gitlab_gdpr_delete.sql b/tests/data/unformatted/210_gitlab_gdpr_delete.sql index e4ce6c0..c70f09d 100644 --- a/tests/data/unformatted/210_gitlab_gdpr_delete.sql +++ b/tests/data/unformatted/210_gitlab_gdpr_delete.sql @@ -48,8 +48,11 @@ with || '.' || lower(table_schema) || '.' - || lower(table_name) as fqd_name, - listagg(column_name, ',') as email_column_names + || lower(table_name) as fqd_name + , listagg( + column_name + , ',' + ) as email_column_names from "RAW"."INFORMATION_SCHEMA"."COLUMNS" where lower(column_name) like '%email%' @@ -59,16 +62,19 @@ with and lower(table_name) like ('gitlab_dotcom_%') group by 1 - ), - non_email_columns as ( + ) + , non_email_columns as ( select lower(table_catalog) || '.' || lower(table_schema) || '.' - || lower(table_name) as fqd_name, - listagg(column_name, ',') as non_email_column_names + || lower(table_name) as fqd_name + , listagg( + column_name + , ',' + ) as non_email_column_names from "RAW"."INFORMATION_SCHEMA"."COLUMNS" as a where lower(column_name) not like '%email%' @@ -82,6 +88,9 @@ with ) -select a.fqd_name, a.email_column_names, b.non_email_column_names +select + a.fqd_name + , a.email_column_names + , b.non_email_column_names from email_columns a left join non_email_columns b on a.fqd_name = b.fqd_name diff --git a/tests/data/unformatted/211_http_2019_cdn_17_20.sql b/tests/data/unformatted/211_http_2019_cdn_17_20.sql index 84662a6..dfdcbde 100644 --- a/tests/data/unformatted/211_http_2019_cdn_17_20.sql +++ b/tests/data/unformatted/211_http_2019_cdn_17_20.sql @@ -28,29 +28,50 @@ ORDER BY # https://github.com/tconbeer/http_archive_almanac/blob/a57e75a9d37e150cb7963b821d9a33ad3d651571/LICENSE # 17_20: Percentage of responses with s-maxage directive select - _table_suffix as client, - ifnull(nullif(regexp_extract(_cdn_provider, r'^([^,]*).*'), ''), 'ORIGIN') as cdn, - countif(lower(resp_cache_control) like '%s-maxage%') as freq, - countif(firsthtml and lower(resp_cache_control) like '%s-maxage%') as firsthtmlfreq, - countif( + _table_suffix as client + , ifnull( + nullif( + regexp_extract( + _cdn_provider + , r'^([^,]*).*' + ) + , '' + ) + , 'ORIGIN' + ) as cdn + , + countif(lower(resp_cache_control) like '%s-maxage%') as freq + , + countif(firsthtml and lower(resp_cache_control) like '%s-maxage%') as firsthtmlfreq + , countif( not firsthtml and lower(resp_cache_control) like '%s-maxage%' - ) as resourcefreq, - count(0) as total, - round( - countif(lower(resp_cache_control) like '%s-maxage%') * 100 / count(0), 2 - ) as pct, - round( + ) as resourcefreq + , + count(0) as total + , round( + countif(lower(resp_cache_control) like '%s-maxage%') + * 100 + / count(0) + , 2 + ) as pct + , round( countif(firsthtml and lower(resp_cache_control) like '%s-maxage%') * 100 - / count(0), - 2 - ) as firsthtmlpct, - round( + / count(0) + , 2 + ) as firsthtmlpct + , round( countif(not firsthtml and lower(resp_cache_control) like '%s-maxage%') * 100 - / count(0), - 2 + / count(0) + , 2 ) as resourcepct from `httparchive.summary_requests.2019_07_01_*` -group by client, cdn -order by client asc, freq desc +group by + client + , cdn +order by + client + asc + , + freq desc diff --git a/tests/data/unformatted/212_http_2019_cms_14_02.sql b/tests/data/unformatted/212_http_2019_cms_14_02.sql index 241bfea..e00d5cd 100644 --- a/tests/data/unformatted/212_http_2019_cms_14_02.sql +++ b/tests/data/unformatted/212_http_2019_cms_14_02.sql @@ -35,34 +35,47 @@ ORDER BY # https://github.com/tconbeer/http_archive_almanac/blob/a57e75a9d37e150cb7963b821d9a33ad3d651571/LICENSE # 14_02: AMP plugin mode select - client, - amp_plugin_mode, - count(distinct url) as freq, - sum(count(distinct url)) over (partition by client) as total, - round( - count(distinct url) * 100 / sum(count(distinct url)) over (partition by client), - 2 + client + , amp_plugin_mode + , + count(distinct url) as freq + , + sum(count(distinct url)) over (partition by client) as total + , round( + count(distinct url) + * 100 + / sum(count(distinct url)) over (partition by client) + , 2 ) as pct from ( select - client, - page as url, - split( + client + , + page as url + , split( regexp_extract( - body, - '(?i)]+name=[\'"]?generator[^>]+content=[\'"]?AMP Plugin v(\\d+\\.\\d+[^\'">]*)' - ), - ';' + body + , '(?i)]+name=[\'"]?generator[^>]+content=[\'"]?AMP Plugin v(\\d+\\.\\d+[^\'">]*)' + ) + , ';' )[safe_offset(1)] as amp_plugin_mode from `httparchive.almanac.summary_response_bodies` where date = '2019-07-01' and firsthtml ) inner join ( - select _table_suffix as client, url + select + _table_suffix as client + , url from `httparchive.technologies.2019_07_01_*` where app = 'WordPress' - ) using (client, url) -group by client, amp_plugin_mode + ) using + ( + client + , url + ) +group by + client + , amp_plugin_mode order by freq / total desc diff --git a/tests/data/unformatted/213_gitlab_fct_sales_funnel_target.sql b/tests/data/unformatted/213_gitlab_fct_sales_funnel_target.sql index 15de335..2d4beea 100644 --- a/tests/data/unformatted/213_gitlab_fct_sales_funnel_target.sql +++ b/tests/data/unformatted/213_gitlab_fct_sales_funnel_target.sql @@ -170,21 +170,26 @@ For FY23 and beyond, targets in the sheetload file were set at the user_segment_ ("date_details_source", "date_details_source"), ] ) -}}, -date as ( +}} + +, date as ( - select distinct fiscal_month_name_fy, fiscal_year, first_day_of_month + select distinct + fiscal_month_name_fy + , fiscal_year + , first_day_of_month from date_details_source -), -target_matrix as ( +) +, target_matrix as ( select - sheetload_sales_funnel_targets_matrix_source.*, - date.first_day_of_month, - date.fiscal_year, - {{ get_keyed_nulls("sales_qualified_source.dim_sales_qualified_source_id") }} - as dim_sales_qualified_source_id, + sheetload_sales_funnel_targets_matrix_source.* + , date.first_day_of_month + , date.fiscal_year + , {{ get_keyed_nulls("sales_qualified_source.dim_sales_qualified_source_id") }} + as dim_sales_qualified_source_id + , {{ get_keyed_nulls("order_type.dim_order_type_id") }} as dim_order_type_id from {{ ref("sheetload_sales_funnel_targets_matrix_source") }} left join @@ -214,8 +219,8 @@ target_matrix as ( ) }} = {{ sales_funnel_text_slugify("order_type.order_type_name") }} -), -fy22_user_hierarchy as ( +) +, fy22_user_hierarchy as ( /* For FY22, targets in the sheetload file were set at the user_area grain, so we join to the stamped hierarchy on the user_area. We also want to find the last user_area in the fiscal year because if there were multiple hierarchies for this user_area, the last one created is assumed to be the correct version. It is necessary to have a 1:1 relationship between area in the target @@ -225,8 +230,8 @@ sheetload and user_area in the hierarchy so the targets do not fan out. from sfdc_user_hierarchy_stamped where fiscal_year = 2022 and is_last_user_area_in_fiscal_year = 1 -), -fy23_and_beyond_user_hierarchy as ( +) +, fy23_and_beyond_user_hierarchy as ( /* For FY23 and beyond, targets in the sheetload file were set at the user_segment_geo_region_area grain, so we join to the stamped hierarchy on the user_segment_geo_region_area. */ @@ -234,28 +239,28 @@ For FY23 and beyond, targets in the sheetload file were set at the user_segment_ from sfdc_user_hierarchy_stamped where fiscal_year > 2022 and is_last_user_hierarchy_in_fiscal_year = 1 -), -unioned_targets as ( +) +, unioned_targets as ( select - target_matrix.kpi_name, - target_matrix.first_day_of_month, - target_matrix.dim_sales_qualified_source_id, - target_matrix.opportunity_source, - target_matrix.dim_order_type_id, - target_matrix.order_type, - target_matrix.fiscal_year, - target_matrix.allocated_target, - fy22_user_hierarchy.crm_opp_owner_sales_segment_geo_region_area_stamped, - fy22_user_hierarchy.dim_crm_user_hierarchy_stamped_id, - fy22_user_hierarchy.dim_crm_opp_owner_sales_segment_stamped_id, - fy22_user_hierarchy.crm_opp_owner_sales_segment_stamped, - fy22_user_hierarchy.dim_crm_opp_owner_geo_stamped_id, - fy22_user_hierarchy.crm_opp_owner_geo_stamped, - fy22_user_hierarchy.dim_crm_opp_owner_region_stamped_id, - fy22_user_hierarchy.crm_opp_owner_region_stamped, - fy22_user_hierarchy.dim_crm_opp_owner_area_stamped_id, - fy22_user_hierarchy.crm_opp_owner_area_stamped + target_matrix.kpi_name + , target_matrix.first_day_of_month + , target_matrix.dim_sales_qualified_source_id + , target_matrix.opportunity_source + , target_matrix.dim_order_type_id + , target_matrix.order_type + , target_matrix.fiscal_year + , target_matrix.allocated_target + , fy22_user_hierarchy.crm_opp_owner_sales_segment_geo_region_area_stamped + , fy22_user_hierarchy.dim_crm_user_hierarchy_stamped_id + , fy22_user_hierarchy.dim_crm_opp_owner_sales_segment_stamped_id + , fy22_user_hierarchy.crm_opp_owner_sales_segment_stamped + , fy22_user_hierarchy.dim_crm_opp_owner_geo_stamped_id + , fy22_user_hierarchy.crm_opp_owner_geo_stamped + , fy22_user_hierarchy.dim_crm_opp_owner_region_stamped_id + , fy22_user_hierarchy.crm_opp_owner_region_stamped + , fy22_user_hierarchy.dim_crm_opp_owner_area_stamped_id + , fy22_user_hierarchy.crm_opp_owner_area_stamped from target_matrix left join fy22_user_hierarchy @@ -270,24 +275,25 @@ unioned_targets as ( union all select - target_matrix.kpi_name, - target_matrix.first_day_of_month, - target_matrix.dim_sales_qualified_source_id, - target_matrix.opportunity_source, - target_matrix.dim_order_type_id, - target_matrix.order_type, - target_matrix.fiscal_year, - target_matrix.allocated_target, - fy23_and_beyond_user_hierarchy.crm_opp_owner_sales_segment_geo_region_area_stamped, - fy23_and_beyond_user_hierarchy.dim_crm_user_hierarchy_stamped_id, - fy23_and_beyond_user_hierarchy.dim_crm_opp_owner_sales_segment_stamped_id, - fy23_and_beyond_user_hierarchy.crm_opp_owner_sales_segment_stamped, - fy23_and_beyond_user_hierarchy.dim_crm_opp_owner_geo_stamped_id, - fy23_and_beyond_user_hierarchy.crm_opp_owner_geo_stamped, - fy23_and_beyond_user_hierarchy.dim_crm_opp_owner_region_stamped_id, - fy23_and_beyond_user_hierarchy.crm_opp_owner_region_stamped, - fy23_and_beyond_user_hierarchy.dim_crm_opp_owner_area_stamped_id, - fy23_and_beyond_user_hierarchy.crm_opp_owner_area_stamped + target_matrix.kpi_name + , target_matrix.first_day_of_month + , target_matrix.dim_sales_qualified_source_id + , target_matrix.opportunity_source + , target_matrix.dim_order_type_id + , target_matrix.order_type + , target_matrix.fiscal_year + , target_matrix.allocated_target + , + fy23_and_beyond_user_hierarchy.crm_opp_owner_sales_segment_geo_region_area_stamped + , fy23_and_beyond_user_hierarchy.dim_crm_user_hierarchy_stamped_id + , fy23_and_beyond_user_hierarchy.dim_crm_opp_owner_sales_segment_stamped_id + , fy23_and_beyond_user_hierarchy.crm_opp_owner_sales_segment_stamped + , fy23_and_beyond_user_hierarchy.dim_crm_opp_owner_geo_stamped_id + , fy23_and_beyond_user_hierarchy.crm_opp_owner_geo_stamped + , fy23_and_beyond_user_hierarchy.dim_crm_opp_owner_region_stamped_id + , fy23_and_beyond_user_hierarchy.crm_opp_owner_region_stamped + , fy23_and_beyond_user_hierarchy.dim_crm_opp_owner_area_stamped_id + , fy23_and_beyond_user_hierarchy.crm_opp_owner_area_stamped from target_matrix left join fy23_and_beyond_user_hierarchy @@ -301,8 +307,8 @@ unioned_targets as ( and target_matrix.fiscal_year = fy23_and_beyond_user_hierarchy.fiscal_year where target_matrix.fiscal_year > 2022 -), -final_targets as ( +) +, final_targets as ( select @@ -318,41 +324,43 @@ final_targets as ( ] ) }} - as sales_funnel_target_id, - unioned_targets.kpi_name, - unioned_targets.first_day_of_month, - unioned_targets.fiscal_year, - unioned_targets.opportunity_source as sales_qualified_source, - unioned_targets.dim_sales_qualified_source_id, - unioned_targets.order_type, - unioned_targets.dim_order_type_id, - unioned_targets.crm_opp_owner_sales_segment_geo_region_area_stamped - as crm_user_sales_segment_geo_region_area, - coalesce( - sfdc_user_hierarchy_live.dim_crm_user_hierarchy_live_id, - unioned_targets.dim_crm_user_hierarchy_stamped_id - ) as dim_crm_user_hierarchy_live_id, - coalesce( - sfdc_user_hierarchy_live.dim_crm_user_sales_segment_id, - unioned_targets.dim_crm_opp_owner_sales_segment_stamped_id - ) as dim_crm_user_sales_segment_id, - coalesce( - sfdc_user_hierarchy_live.dim_crm_user_geo_id, - unioned_targets.dim_crm_opp_owner_geo_stamped_id - ) as dim_crm_user_geo_id, - coalesce( - sfdc_user_hierarchy_live.dim_crm_user_region_id, - unioned_targets.dim_crm_opp_owner_region_stamped_id - ) as dim_crm_user_region_id, - coalesce( - sfdc_user_hierarchy_live.dim_crm_user_area_id, - unioned_targets.dim_crm_opp_owner_area_stamped_id - ) as dim_crm_user_area_id, - unioned_targets.dim_crm_user_hierarchy_stamped_id, - unioned_targets.dim_crm_opp_owner_sales_segment_stamped_id, - unioned_targets.dim_crm_opp_owner_geo_stamped_id, - unioned_targets.dim_crm_opp_owner_region_stamped_id, - unioned_targets.dim_crm_opp_owner_area_stamped_id, + as sales_funnel_target_id + , unioned_targets.kpi_name + , unioned_targets.first_day_of_month + , unioned_targets.fiscal_year + , + unioned_targets.opportunity_source as sales_qualified_source + , unioned_targets.dim_sales_qualified_source_id + , unioned_targets.order_type + , unioned_targets.dim_order_type_id + , unioned_targets.crm_opp_owner_sales_segment_geo_region_area_stamped + as crm_user_sales_segment_geo_region_area + , coalesce( + sfdc_user_hierarchy_live.dim_crm_user_hierarchy_live_id + , unioned_targets.dim_crm_user_hierarchy_stamped_id + ) as dim_crm_user_hierarchy_live_id + , coalesce( + sfdc_user_hierarchy_live.dim_crm_user_sales_segment_id + , unioned_targets.dim_crm_opp_owner_sales_segment_stamped_id + ) as dim_crm_user_sales_segment_id + , coalesce( + sfdc_user_hierarchy_live.dim_crm_user_geo_id + , unioned_targets.dim_crm_opp_owner_geo_stamped_id + ) as dim_crm_user_geo_id + , coalesce( + sfdc_user_hierarchy_live.dim_crm_user_region_id + , unioned_targets.dim_crm_opp_owner_region_stamped_id + ) as dim_crm_user_region_id + , coalesce( + sfdc_user_hierarchy_live.dim_crm_user_area_id + , unioned_targets.dim_crm_opp_owner_area_stamped_id + ) as dim_crm_user_area_id + , unioned_targets.dim_crm_user_hierarchy_stamped_id + , unioned_targets.dim_crm_opp_owner_sales_segment_stamped_id + , unioned_targets.dim_crm_opp_owner_geo_stamped_id + , unioned_targets.dim_crm_opp_owner_region_stamped_id + , unioned_targets.dim_crm_opp_owner_area_stamped_id + , sum(unioned_targets.allocated_target) as allocated_target from unioned_targets diff --git a/tests/data/unformatted/214_get_unique_attributes.sql b/tests/data/unformatted/214_get_unique_attributes.sql index 1126544..a66e9b1 100644 --- a/tests/data/unformatted/214_get_unique_attributes.sql +++ b/tests/data/unformatted/214_get_unique_attributes.sql @@ -45,10 +45,11 @@ {% endif %} {% for attribute in results_list %} - , - get({{ node_col }}, '{{ attribute }}')::varchar( - 256 - ) as attribute_{{ dbt_utils.slugify(attribute) | replace("@", "") }} + , get( + {{ node_col }} + , '{{ attribute }}' + )::varchar(256) + as attribute_{{ dbt_utils.slugify(attribute) | replace("@", "") }} {% endfor %} {% endmacro %} diff --git a/tests/data/unformatted/216_gitlab_zuora_revenue_revenue_contract_line_source.sql b/tests/data/unformatted/216_gitlab_zuora_revenue_revenue_contract_line_source.sql index 4c45356..ca2ff57 100644 --- a/tests/data/unformatted/216_gitlab_zuora_revenue_revenue_contract_line_source.sql +++ b/tests/data/unformatted/216_gitlab_zuora_revenue_revenue_contract_line_source.sql @@ -372,350 +372,692 @@ with from {{ source("zuora_revenue", "zuora_revenue_revenue_contract_line") }} qualify rank() over (partition by id order by incr_updt_dt desc) = 1 - ), - renamed as ( + ) + , renamed as ( select - id::varchar as revenue_contract_line_id, - rc_id::varchar as revenue_contract_id, - type::varchar as revenue_contract_line_type, - rc_pob_id::varchar as revenue_contract_performance_obligation_id, - ext_sll_prc::float as extended_selling_price, - ext_fv_prc::float as extended_fair_value_price, - def_amt::float as deferred_amount, - rec_amt::float as recognized_amount, - cv_amt::float as carve_amount, - alctbl_xt_prc::varchar as allocatable_price, - alctd_xt_prc::varchar as allocated_price, - bld_def_amt::varchar as billed_deferred_amount, - bld_rec_amt::varchar as billed_recognized_amount, - cstmr_nm::varchar as customer_name, - so_num::varchar as sales_order_number, - so_book_date::datetime as sales_order_book_date, - so_line_num::varchar as sales_order_line_number, - so_line_id::varchar as sales_order_line_id, - item_num::varchar as item_number, - bndl_cnfg_id::varchar as bundle_configuration_id, - ord_qty::varchar as order_quantity, - inv_qty::varchar as invoice_quantity, - ret_qty::varchar as return_quantity, - start_date::varchar as revenue_start_date, - end_date::varchar as revenue_end_date, - duration::varchar as revenue_amortization_duration, - ext_lst_prc::varchar as list_price, - batch_id::varchar as revenue_contract_batch_id, - curr::varchar as transactional_currency, - f_cur::varchar as functional_currency, - f_ex_rate::varchar as functional_currency_exchage_rate, - g_ex_rate::varchar as reporting_currency_exchange_rate, - disc_amt::float as discount_amount, - disc_pct::float as discount_percent, - alctbl_fn_xt_prc::varchar as allocatable_functional_price, - ref_doc_line_id::varchar as reference_document_line_id, - lt_def_acnt::varchar as long_term_deferred_account, - fv_grp_id::varchar as fair_value_group_id, - fv_pct::float as fair_value_percent, - fv_prc::float as fair_value_price, - fv_type::varchar as fair_value_type, - err_msg::varchar as error_message, - def_segments::varchar as deferred_accounting_segment, - rev_segments::varchar as revenue_accounting_segment, - atr1::varchar as revenue_contract_line_attribute_1, - atr2::varchar as revenue_contract_line_attribute_2, - atr3::varchar as revenue_contract_line_attribute_3, - atr4::varchar as revenue_contract_line_attribute_4, - atr5::varchar as revenue_contract_line_attribute_5, - atr6::varchar as revenue_contract_line_attribute_6, - atr7::varchar as revenue_contract_line_attribute_7, - atr8::varchar as revenue_contract_line_attribute_8, - atr9::varchar as revenue_contract_line_attribute_9, - atr10::varchar as revenue_contract_line_attribute_10, - atr11::varchar as revenue_contract_line_attribute_11, - atr12::varchar as revenue_contract_line_attribute_12, - atr13::varchar as revenue_contract_line_attribute_13, - atr14::varchar as revenue_contract_line_attribute_14, - atr15::varchar as revenue_contract_line_attribute_15, - atr16::varchar as revenue_contract_line_attribute_16, - atr17::varchar as revenue_contract_line_attribute_17, - atr18::varchar as revenue_contract_line_attribute_18, - atr19::varchar as revenue_contract_line_attribute_19, - atr20::varchar as revenue_contract_line_attribute_20, - atr21::varchar as revenue_contract_line_attribute_21, - atr22::varchar as revenue_contract_line_attribute_22, - atr23::varchar as revenue_contract_line_attribute_23, - atr24::varchar as revenue_contract_line_attribute_24, - atr25::varchar as revenue_contract_line_attribute_25, - atr26::varchar as revenue_contract_line_attribute_26, - atr27::varchar as revenue_contract_line_attribute_27, - atr28::varchar as revenue_contract_line_attribute_28, - atr29::varchar as revenue_contract_line_attribute_29, - atr30::varchar as revenue_contract_line_attribute_30, - atr31::varchar as revenue_contract_line_attribute_31, - atr32::varchar as revenue_contract_line_attribute_32, - atr33::varchar as revenue_contract_line_attribute_33, - atr34::varchar as revenue_contract_line_attribute_34, - atr35::varchar as revenue_contract_line_attribute_35, - atr36::varchar as revenue_contract_line_attribute_36, - atr37::varchar as revenue_contract_line_attribute_37, - atr38::varchar as revenue_contract_line_attribute_38, - atr39::varchar as revenue_contract_line_attribute_39, - atr40::varchar as revenue_contract_line_attribute_40, - atr41::varchar as revenue_contract_line_attribute_41, - atr42::varchar as revenue_contract_line_attribute_42, - atr43::varchar as revenue_contract_line_attribute_43, - atr44::varchar as revenue_contract_line_attribute_44, - atr45::varchar as revenue_contract_line_attribute_45, - atr46::varchar as revenue_contract_line_attribute_46, - atr47::varchar as revenue_contract_line_attribute_47, - atr48::varchar as revenue_contract_line_attribute_48, - atr49::varchar as revenue_contract_line_attribute_49, - atr50::varchar as revenue_contract_line_attribute_50, - atr51::varchar as revenue_contract_line_attribute_51, - atr52::varchar as revenue_contract_line_attribute_52, - atr53::varchar as revenue_contract_line_attribute_53, - atr54::varchar as revenue_contract_line_attribute_54, - atr55::varchar as revenue_contract_line_attribute_55, - atr56::varchar as revenue_contract_line_attribute_56, - atr57::varchar as revenue_contract_line_attribute_57, - atr58::varchar as revenue_contract_line_attribute_58, - atr59::varchar as revenue_contract_line_attribute_59, - atr60::varchar as revenue_contract_line_attribute_60, - num1::varchar as revenue_contract_line_number_1, - num2::varchar as revenue_contract_line_number_2, - num3::varchar as revenue_contract_line_number_3, - num4::varchar as revenue_contract_line_number_4, - num5::varchar as revenue_contract_line_number_5, - num6::varchar as revenue_contract_line_number_6, - num7::varchar as revenue_contract_line_number_7, - num8::varchar as revenue_contract_line_number_8, - num9::varchar as revenue_contract_line_number_9, - num10::varchar as revenue_contract_line_number_10, - num11::varchar as revenue_contract_line_number_11, - num12::varchar as revenue_contract_line_number_12, - num13::varchar as revenue_contract_line_number_13, - num14::varchar as revenue_contract_line_number_14, - num15::varchar as revenue_contract_line_number_15, - date1::datetime as revenue_contract_line_date_1, - date2::datetime as revenue_contract_line_date_2, - date3::datetime as revenue_contract_line_date_3, - date4::datetime as revenue_contract_line_date_4, - date5::datetime as revenue_contract_line_date_5, - model_id::varchar as model_id, - unschd_adj::varchar as unscheduled_adjustment, - posted_pct::float as posted_percent, - rel_pct::float as released_percent, - term::varchar as revenue_contract_line_term, - vc_type_id::varchar as variable_consideration_type_id, - po_num::varchar as purchase_order_number, - quote_num::varchar as quote_number, - schd_ship_dt::datetime as scheduled_ship_date, - ship_dt::datetime as ship_date, - sales_rep_name::varchar as sales_representative_name, - cust_num::varchar as customer_number, - prod_ctgry::varchar as product_category, - prod_class::varchar as product_class, - prod_fmly::varchar as product_family, - prod_ln::varchar as product_line, - business_unit::varchar as business_unit, - ct_mod_date::datetime as contract_modification_date, - ct_num::varchar as contract_number, - ct_date::datetime as contract_date, - ct_line_num::varchar as contract_line_number, - ct_line_id::varchar as contract_line_id, - cum_cv_amt::varchar as cumulative_carve_amount, - cum_alctd_amt::varchar as cumulative_allocated_amount, - comments::varchar as revenue_contract_line_comment, - prnt_ln_id::varchar as parent_revenue_contract_line_id, - prnt_ref_ln_id::varchar as parent_reference_line_id, - cv_eligible_flag::varchar as is_carve_eligible, - return_flag::varchar as is_return, - within_fv_range_flag::varchar as is_within_fair_value_range, - stated_flag::varchar as is_stated, - standalone_flag::varchar as is_standalone, - disc_adj_flag::varchar as is_discount_adjustment, - approval_status_flag::varchar as approval_status, - fv_eligible_flag::varchar as is_fair_value_eligible, - manual_fv_flag::varchar as is_manual_fair_value, - rssp_calc_type::varchar as rssp_calculation_type, - unbill_flag::varchar as is_unbilled, - manual_crtd_flag::varchar as is_manual_created, - vc_clearing_flag::varchar as is_variable_consideration_clearing, - mje_line_flag::varchar as is_manual_journal_entry_line, - update_or_insert_flag::varchar as is_update_or_insert, - delink_lvl_flag::varchar as delink_level, - concat(crtd_prd_id::varchar, '01') as created_period_id, - book_id::varchar as book_id, - client_id::varchar as client_id, - sec_atr_val::varchar as security_attribute_value, - crtd_by::varchar as revenue_contract_line_created_by, - crtd_dt::datetime as revenue_contract_line_created_date, - updt_by::varchar as revenue_contract_line_updated_by, - updt_dt::datetime as revenue_contract_line_updated_date, - incr_updt_dt::varchar as incremental_update_date, - offset_segments::varchar as offset_accounting_segment, - sob_id::varchar as set_of_books_id, - fv_date::datetime as fair_value_date, - orig_fv_date::datetime as original_fair_value_date, - vc_amt::float as varaiable_consideration_amount, - unit_sell_prc::float as unit_sell_price, - unit_list_prc::float as unit_list_price, - impair_retrieve_amt::float as impairment_retrieve_amount, - bndl_prnt_id::varchar as bundle_parent_id, - company_code::varchar as company_code, - cancel_flag::varchar as is_cancelled, - below_fv_prc::float as below_fair_value_price, - above_fv_prc::float as above_fair_value_price, - fv_tmpl_id::varchar as fair_value_template_id, - fv_expr::varchar as fair_value_expiration, - below_mid_pct::float as below_mid_percent, - above_mid_pct::float as above_mid_percent, - ic_account::varchar as intercompany_account, - ca_account::varchar as contract_asset_account, - ci_account::varchar as ci_account, - al_account::varchar as al_account, - ar_account::varchar as ar_account, - contra_ar_acct::varchar as contra_ar_account, - payables_acct::varchar as payables_account, - lt_def_adj_acct::varchar as long_term_deferred_adjustment_account, - ub_liab_acct::varchar as ub_liability_account, - alloc_rec_hold_flag::varchar as is_allocation_recognition_hold, - alloc_schd_hold_flag::varchar as is_allocation_schedule_hold, - alloc_trtmt_flag::varchar as is_allocation_treatment, - contra_entry_flag::varchar as is_contra_entry, - conv_wfall_flag::varchar as is_conv_waterfall, - ct_mod_code_flag::varchar as contract_modification_code, - impairment_type_flag::varchar as impairment_type, - previous_fv_flag::varchar as previous_fair_value, - reclass_flag::varchar as is_reclass, - rev_rec_hold_flag::varchar as is_revenue_recognition_hold, - rev_schd_hold_flag::varchar as is_revenue_schedule_hold, - rev_schd_flag::varchar as is_revevnue_schedule, - trnsfr_hold_flag::varchar as is_transfer_hold, - alloc_delink_flag::varchar as is_allocation_delink, - cancel_by_rord_flag::varchar as is_canceled_by_reduction_order, - cv_eligible_lvl2_flag::varchar as is_level_2_carve_eligible, - rc_level_range_flag::varchar as revenue_contract_level, - rssp_fail_flag::varchar as is_rssp_failed, - vc_eligible_flag::varchar as is_variable_consideration_eligible, - ghost_line_flag::varchar as is_ghost_line, - initial_ct_flag::varchar as is_initial_contract, - material_rights_flag::varchar as is_material_rights, - ramp_up_flag::varchar as is_ramp_up, - lt_def_cogs_acct::varchar as long_term_deferred_cogs_account, - lt_ca_account::varchar as long_term_ca_account, - tot_bgd_hrs::float as total_budget_hours, - tot_bgd_cst::float as total_budget_cost, - fcst_date::datetime as forecast_date, - link_identifier::varchar as link_identifier, - prod_life_term::varchar as product_life_term, - ramp_identifier::varchar as ramp_identifier, - mr_line_id::varchar as material_rights_line_id, - price_point::varchar as price_point, - tp_pct_ssp::float as transaction_price_ssp_percent, - orig_quantity::float as original_quantity, - split_ref_doc_line_id::varchar as split_reference_document_line_id, - overstated_amt::float as overstated_amount, - ovst_lst_amt::float as overstated_list_price_amount, - ref_rc_id::varchar as reference_revenue_contract_id, - split_flag::varchar as is_split, - ord_orch_flag::varchar as is_ord_orch, - upd_model_id_flag::varchar as updated_model_id, - new_pob_flag::varchar as is_new_performance_obligation, - mr_org_prc::float as material_rights_org_percent, - action_type::varchar as action_type, - pord_def_amt::float as pord_deferred_amount, - pord_rec_amt::float as pord_recognized_amount, - net_sll_prc::float as net_sell_price, - net_lst_prc::float as net_list_price, - full_cm_flag::varchar as full_cm_flag, - skip_ct_mod_flag::varchar as is_skip_contract_modification, - step1_rc_level_range_flag::varchar as step_1_revenue_contract_level_range, - impairment_exception_flag::varchar as is_impairment_exception, - pros_defer_flag::varchar as is_pros_deferred, - manual_so_flag::varchar as is_manual_sales_order, - zero_doll_rec_flag::varchar as is_zero_dollar_recognition, - cv_amt_imprtmt::varchar as carve_amount_imprtmt, - full_pord_disc_flag::varchar as is_full_pord_discount, - zero_dollar_rord_flag::varchar as is_zero_dollar_reduction_order, - subscrp_id::varchar as subscription_id, - subscrp_name::varchar as subscription_name, - subscrp_version::varchar as subscription_version, - subscrp_start_date::datetime as subscription_start_date, - subscrp_end_date::datetime as subscription_end_date, - subscrp_owner::varchar as subscription_owner, - invoice_owner::varchar as invoice_owner, - rp_id::varchar as rate_plan_id, - rp_name::varchar as rate_plan_name, - rpc_num::varchar as rate_plan_charge_number, - rpc_name::varchar as rate_plan_charge_name, - rpc_version::varchar as rate_plan_charge_version, - rpc_model::varchar as rate_plan_charge_model, - rpc_type::varchar as rate_plan_charge_type, - rpc_trigger_evt::varchar as rate_plan_charge_trigger_event, - rpc_segment::varchar as rate_plan_charge_segment, - rpc_id::varchar as rate_plan_charge_id, - orig_rpc_id::varchar as original_rate_plan_charge_id, - subscrp_type::varchar as subscription_type, - charge_level::varchar as charge_level, - amendment_id::varchar as amendment_id, - amendment_type::varchar as amendment_type, - amendment_reason::varchar as amendment_reason, - order_id::varchar as order_id, - order_item_id::varchar as order_item_id, - order_action_id::varchar as order_action_id, - account_id::varchar as billing_account_id, - product_id::varchar as product_id, - product_rp_id::varchar as product_rate_plan_id, - product_rpc_id::varchar as product_rate_plan_charge_id, - charge_crtd_date::datetime as charge_created_date, - charge_last_updt_date::datetime as charge_last_updated_date, - bill_id::varchar as revenue_contract_bill_id, - bill_item_id::varchar as revenue_contract_bill_item_id, - zbill_batch_id::varchar as zbilling_batch_id, - ramp_deal_ref::varchar as ramp_deal_id, - seq_num::varchar as sequence_number, - avg_prcing_mthd::varchar as average_pricing_method, - prc_frmt::varchar as percent_format, - prnt_chrg_segment::varchar as parent_charge_segment, - prnt_chrg_num::varchar as parent_charge_number, - entity_id::varchar as entity_id, - ssp_sll_prc::float as ssp_sell_price, - ssp_lst_prc::float as ssp_list_price, - subscrp_trm_st_dt::datetime as subscription_term_start_date, - subscrp_trm_end_dt::datetime as subscription_term_end_date, - subscrp_term_num::varchar as subscrp_term_number, - old_sell_prc::float as old_sell_price, - rstrct_so_val_upd_flag::varchar as is_restricted_sales_order_value_update, - zbilling_cmplte_flag::varchar as is_zbilling_complete, - zbil_unschd_adj_flag::varchar as is_zbilling_unscheduled_adjustment, - zbill_cancel_line_flag::varchar as is_zbillling_cancelled_line, - non_distinct_pob_flag::varchar as is_non_distinct_performance_obligation, - zbill_ctmod_rule_flag::varchar as is_zbilling_contract_modification_rule, - sys_inv_exist_flag::varchar as is_system_inv_exist, - zbill_manual_so_flag::varchar as is_zbillling_manual_sales_order, - so_term_change_flag::varchar as is_sales_order_term_change, - ramp_alloc_pct::float as ramp_allocation_percent, - ramp_alctbl_prc::float as ramp_allocatable_percent, - ramp_alctd_prc::float as ramp_allocted_percent, - ramp_cv_amt::float as ramp_carve_amount, - ramp_cum_cv_amt::float as ramp_cumulative_carve_amount, - ramp_cum_alctd_amt::float as ramp_cumulative_allocated_amount, - ovg_exist_flag::varchar as is_overage_exists, - zbill_ramp_flag::varchar as is_zbilling_ramp, - update_by_rord_flag::varchar as is_updated_by_reduction_order, - unbilled_evergreen_flag::varchar as is_unbilled_evergreen, - k2_batch_id::varchar as k2_batch_id, - reason_code::varchar as reason_code, - concat( - updt_prd_id::varchar, '01' - ) as revenue_contract_line_updated_period_id, - ramp_id::varchar as ramp_id, - concat(unbl_rvsl_prd::varchar, '01') as unbilled_reversal_period, - ramp_cv_chg_flag::varchar as is_ramp_carve, - zero_flip_flag::varchar as is_zero_f, - pros_decrse_prc_flag::varchar as is_pros_decrse_p, - concat(defer_prd_id::varchar, '01') as deferred_period_id + id::varchar as revenue_contract_line_id + , + rc_id::varchar as revenue_contract_id + , + type::varchar as revenue_contract_line_type + , + rc_pob_id::varchar as revenue_contract_performance_obligation_id + , + ext_sll_prc::float as extended_selling_price + , + ext_fv_prc::float as extended_fair_value_price + , + def_amt::float as deferred_amount + , + rec_amt::float as recognized_amount + , + cv_amt::float as carve_amount + , + alctbl_xt_prc::varchar as allocatable_price + , + alctd_xt_prc::varchar as allocated_price + , + bld_def_amt::varchar as billed_deferred_amount + , + bld_rec_amt::varchar as billed_recognized_amount + , + cstmr_nm::varchar as customer_name + , + so_num::varchar as sales_order_number + , + so_book_date::datetime as sales_order_book_date + , + so_line_num::varchar as sales_order_line_number + , + so_line_id::varchar as sales_order_line_id + , + item_num::varchar as item_number + , + bndl_cnfg_id::varchar as bundle_configuration_id + , + ord_qty::varchar as order_quantity + , + inv_qty::varchar as invoice_quantity + , + ret_qty::varchar as return_quantity + , + start_date::varchar as revenue_start_date + , + end_date::varchar as revenue_end_date + , + duration::varchar as revenue_amortization_duration + , + ext_lst_prc::varchar as list_price + , + batch_id::varchar as revenue_contract_batch_id + , + curr::varchar as transactional_currency + , + f_cur::varchar as functional_currency + , + f_ex_rate::varchar as functional_currency_exchage_rate + , + g_ex_rate::varchar as reporting_currency_exchange_rate + , + disc_amt::float as discount_amount + , + disc_pct::float as discount_percent + , + alctbl_fn_xt_prc::varchar as allocatable_functional_price + , + ref_doc_line_id::varchar as reference_document_line_id + , + lt_def_acnt::varchar as long_term_deferred_account + , + fv_grp_id::varchar as fair_value_group_id + , + fv_pct::float as fair_value_percent + , + fv_prc::float as fair_value_price + , + fv_type::varchar as fair_value_type + , + err_msg::varchar as error_message + , + def_segments::varchar as deferred_accounting_segment + , + rev_segments::varchar as revenue_accounting_segment + , + atr1::varchar as revenue_contract_line_attribute_1 + , + atr2::varchar as revenue_contract_line_attribute_2 + , + atr3::varchar as revenue_contract_line_attribute_3 + , + atr4::varchar as revenue_contract_line_attribute_4 + , + atr5::varchar as revenue_contract_line_attribute_5 + , + atr6::varchar as revenue_contract_line_attribute_6 + , + atr7::varchar as revenue_contract_line_attribute_7 + , + atr8::varchar as revenue_contract_line_attribute_8 + , + atr9::varchar as revenue_contract_line_attribute_9 + , + atr10::varchar as revenue_contract_line_attribute_10 + , + atr11::varchar as revenue_contract_line_attribute_11 + , + atr12::varchar as revenue_contract_line_attribute_12 + , + atr13::varchar as revenue_contract_line_attribute_13 + , + atr14::varchar as revenue_contract_line_attribute_14 + , + atr15::varchar as revenue_contract_line_attribute_15 + , + atr16::varchar as revenue_contract_line_attribute_16 + , + atr17::varchar as revenue_contract_line_attribute_17 + , + atr18::varchar as revenue_contract_line_attribute_18 + , + atr19::varchar as revenue_contract_line_attribute_19 + , + atr20::varchar as revenue_contract_line_attribute_20 + , + atr21::varchar as revenue_contract_line_attribute_21 + , + atr22::varchar as revenue_contract_line_attribute_22 + , + atr23::varchar as revenue_contract_line_attribute_23 + , + atr24::varchar as revenue_contract_line_attribute_24 + , + atr25::varchar as revenue_contract_line_attribute_25 + , + atr26::varchar as revenue_contract_line_attribute_26 + , + atr27::varchar as revenue_contract_line_attribute_27 + , + atr28::varchar as revenue_contract_line_attribute_28 + , + atr29::varchar as revenue_contract_line_attribute_29 + , + atr30::varchar as revenue_contract_line_attribute_30 + , + atr31::varchar as revenue_contract_line_attribute_31 + , + atr32::varchar as revenue_contract_line_attribute_32 + , + atr33::varchar as revenue_contract_line_attribute_33 + , + atr34::varchar as revenue_contract_line_attribute_34 + , + atr35::varchar as revenue_contract_line_attribute_35 + , + atr36::varchar as revenue_contract_line_attribute_36 + , + atr37::varchar as revenue_contract_line_attribute_37 + , + atr38::varchar as revenue_contract_line_attribute_38 + , + atr39::varchar as revenue_contract_line_attribute_39 + , + atr40::varchar as revenue_contract_line_attribute_40 + , + atr41::varchar as revenue_contract_line_attribute_41 + , + atr42::varchar as revenue_contract_line_attribute_42 + , + atr43::varchar as revenue_contract_line_attribute_43 + , + atr44::varchar as revenue_contract_line_attribute_44 + , + atr45::varchar as revenue_contract_line_attribute_45 + , + atr46::varchar as revenue_contract_line_attribute_46 + , + atr47::varchar as revenue_contract_line_attribute_47 + , + atr48::varchar as revenue_contract_line_attribute_48 + , + atr49::varchar as revenue_contract_line_attribute_49 + , + atr50::varchar as revenue_contract_line_attribute_50 + , + atr51::varchar as revenue_contract_line_attribute_51 + , + atr52::varchar as revenue_contract_line_attribute_52 + , + atr53::varchar as revenue_contract_line_attribute_53 + , + atr54::varchar as revenue_contract_line_attribute_54 + , + atr55::varchar as revenue_contract_line_attribute_55 + , + atr56::varchar as revenue_contract_line_attribute_56 + , + atr57::varchar as revenue_contract_line_attribute_57 + , + atr58::varchar as revenue_contract_line_attribute_58 + , + atr59::varchar as revenue_contract_line_attribute_59 + , + atr60::varchar as revenue_contract_line_attribute_60 + , + num1::varchar as revenue_contract_line_number_1 + , + num2::varchar as revenue_contract_line_number_2 + , + num3::varchar as revenue_contract_line_number_3 + , + num4::varchar as revenue_contract_line_number_4 + , + num5::varchar as revenue_contract_line_number_5 + , + num6::varchar as revenue_contract_line_number_6 + , + num7::varchar as revenue_contract_line_number_7 + , + num8::varchar as revenue_contract_line_number_8 + , + num9::varchar as revenue_contract_line_number_9 + , + num10::varchar as revenue_contract_line_number_10 + , + num11::varchar as revenue_contract_line_number_11 + , + num12::varchar as revenue_contract_line_number_12 + , + num13::varchar as revenue_contract_line_number_13 + , + num14::varchar as revenue_contract_line_number_14 + , + num15::varchar as revenue_contract_line_number_15 + , + date1::datetime as revenue_contract_line_date_1 + , + date2::datetime as revenue_contract_line_date_2 + , + date3::datetime as revenue_contract_line_date_3 + , + date4::datetime as revenue_contract_line_date_4 + , + date5::datetime as revenue_contract_line_date_5 + , + model_id::varchar as model_id + , + unschd_adj::varchar as unscheduled_adjustment + , + posted_pct::float as posted_percent + , + rel_pct::float as released_percent + , + term::varchar as revenue_contract_line_term + , + vc_type_id::varchar as variable_consideration_type_id + , + po_num::varchar as purchase_order_number + , + quote_num::varchar as quote_number + , + schd_ship_dt::datetime as scheduled_ship_date + , + ship_dt::datetime as ship_date + , + sales_rep_name::varchar as sales_representative_name + , + cust_num::varchar as customer_number + , + prod_ctgry::varchar as product_category + , + prod_class::varchar as product_class + , + prod_fmly::varchar as product_family + , + prod_ln::varchar as product_line + , + business_unit::varchar as business_unit + , + ct_mod_date::datetime as contract_modification_date + , + ct_num::varchar as contract_number + , + ct_date::datetime as contract_date + , + ct_line_num::varchar as contract_line_number + , + ct_line_id::varchar as contract_line_id + , + cum_cv_amt::varchar as cumulative_carve_amount + , + cum_alctd_amt::varchar as cumulative_allocated_amount + , + comments::varchar as revenue_contract_line_comment + , + prnt_ln_id::varchar as parent_revenue_contract_line_id + , + prnt_ref_ln_id::varchar as parent_reference_line_id + , + cv_eligible_flag::varchar as is_carve_eligible + , + return_flag::varchar as is_return + , + within_fv_range_flag::varchar as is_within_fair_value_range + , + stated_flag::varchar as is_stated + , + standalone_flag::varchar as is_standalone + , + disc_adj_flag::varchar as is_discount_adjustment + , + approval_status_flag::varchar as approval_status + , + fv_eligible_flag::varchar as is_fair_value_eligible + , + manual_fv_flag::varchar as is_manual_fair_value + , + rssp_calc_type::varchar as rssp_calculation_type + , + unbill_flag::varchar as is_unbilled + , + manual_crtd_flag::varchar as is_manual_created + , + vc_clearing_flag::varchar as is_variable_consideration_clearing + , + mje_line_flag::varchar as is_manual_journal_entry_line + , + update_or_insert_flag::varchar as is_update_or_insert + , + delink_lvl_flag::varchar as delink_level + , concat( + crtd_prd_id::varchar + , '01' + ) as created_period_id + , + book_id::varchar as book_id + , + client_id::varchar as client_id + , + sec_atr_val::varchar as security_attribute_value + , + crtd_by::varchar as revenue_contract_line_created_by + , + crtd_dt::datetime as revenue_contract_line_created_date + , + updt_by::varchar as revenue_contract_line_updated_by + , + updt_dt::datetime as revenue_contract_line_updated_date + , + incr_updt_dt::varchar as incremental_update_date + , + offset_segments::varchar as offset_accounting_segment + , + sob_id::varchar as set_of_books_id + , + fv_date::datetime as fair_value_date + , + orig_fv_date::datetime as original_fair_value_date + , + vc_amt::float as varaiable_consideration_amount + , + unit_sell_prc::float as unit_sell_price + , + unit_list_prc::float as unit_list_price + , + impair_retrieve_amt::float as impairment_retrieve_amount + , + bndl_prnt_id::varchar as bundle_parent_id + , + company_code::varchar as company_code + , + cancel_flag::varchar as is_cancelled + , + below_fv_prc::float as below_fair_value_price + , + above_fv_prc::float as above_fair_value_price + , + fv_tmpl_id::varchar as fair_value_template_id + , + fv_expr::varchar as fair_value_expiration + , + below_mid_pct::float as below_mid_percent + , + above_mid_pct::float as above_mid_percent + , + ic_account::varchar as intercompany_account + , + ca_account::varchar as contract_asset_account + , + ci_account::varchar as ci_account + , + al_account::varchar as al_account + , + ar_account::varchar as ar_account + , + contra_ar_acct::varchar as contra_ar_account + , + payables_acct::varchar as payables_account + , + lt_def_adj_acct::varchar as long_term_deferred_adjustment_account + , + ub_liab_acct::varchar as ub_liability_account + , + alloc_rec_hold_flag::varchar as is_allocation_recognition_hold + , + alloc_schd_hold_flag::varchar as is_allocation_schedule_hold + , + alloc_trtmt_flag::varchar as is_allocation_treatment + , + contra_entry_flag::varchar as is_contra_entry + , + conv_wfall_flag::varchar as is_conv_waterfall + , + ct_mod_code_flag::varchar as contract_modification_code + , + impairment_type_flag::varchar as impairment_type + , + previous_fv_flag::varchar as previous_fair_value + , + reclass_flag::varchar as is_reclass + , + rev_rec_hold_flag::varchar as is_revenue_recognition_hold + , + rev_schd_hold_flag::varchar as is_revenue_schedule_hold + , + rev_schd_flag::varchar as is_revevnue_schedule + , + trnsfr_hold_flag::varchar as is_transfer_hold + , + alloc_delink_flag::varchar as is_allocation_delink + , + cancel_by_rord_flag::varchar as is_canceled_by_reduction_order + , + cv_eligible_lvl2_flag::varchar as is_level_2_carve_eligible + , + rc_level_range_flag::varchar as revenue_contract_level + , + rssp_fail_flag::varchar as is_rssp_failed + , + vc_eligible_flag::varchar as is_variable_consideration_eligible + , + ghost_line_flag::varchar as is_ghost_line + , + initial_ct_flag::varchar as is_initial_contract + , + material_rights_flag::varchar as is_material_rights + , + ramp_up_flag::varchar as is_ramp_up + , + lt_def_cogs_acct::varchar as long_term_deferred_cogs_account + , + lt_ca_account::varchar as long_term_ca_account + , + tot_bgd_hrs::float as total_budget_hours + , + tot_bgd_cst::float as total_budget_cost + , + fcst_date::datetime as forecast_date + , + link_identifier::varchar as link_identifier + , + prod_life_term::varchar as product_life_term + , + ramp_identifier::varchar as ramp_identifier + , + mr_line_id::varchar as material_rights_line_id + , + price_point::varchar as price_point + , + tp_pct_ssp::float as transaction_price_ssp_percent + , + orig_quantity::float as original_quantity + , + split_ref_doc_line_id::varchar as split_reference_document_line_id + , + overstated_amt::float as overstated_amount + , + ovst_lst_amt::float as overstated_list_price_amount + , + ref_rc_id::varchar as reference_revenue_contract_id + , + split_flag::varchar as is_split + , + ord_orch_flag::varchar as is_ord_orch + , + upd_model_id_flag::varchar as updated_model_id + , + new_pob_flag::varchar as is_new_performance_obligation + , + mr_org_prc::float as material_rights_org_percent + , + action_type::varchar as action_type + , + pord_def_amt::float as pord_deferred_amount + , + pord_rec_amt::float as pord_recognized_amount + , + net_sll_prc::float as net_sell_price + , + net_lst_prc::float as net_list_price + , + full_cm_flag::varchar as full_cm_flag + , + skip_ct_mod_flag::varchar as is_skip_contract_modification + , + step1_rc_level_range_flag::varchar as step_1_revenue_contract_level_range + , + impairment_exception_flag::varchar as is_impairment_exception + , + pros_defer_flag::varchar as is_pros_deferred + , + manual_so_flag::varchar as is_manual_sales_order + , + zero_doll_rec_flag::varchar as is_zero_dollar_recognition + , + cv_amt_imprtmt::varchar as carve_amount_imprtmt + , + full_pord_disc_flag::varchar as is_full_pord_discount + , + zero_dollar_rord_flag::varchar as is_zero_dollar_reduction_order + , + subscrp_id::varchar as subscription_id + , + subscrp_name::varchar as subscription_name + , + subscrp_version::varchar as subscription_version + , + subscrp_start_date::datetime as subscription_start_date + , + subscrp_end_date::datetime as subscription_end_date + , + subscrp_owner::varchar as subscription_owner + , + invoice_owner::varchar as invoice_owner + , + rp_id::varchar as rate_plan_id + , + rp_name::varchar as rate_plan_name + , + rpc_num::varchar as rate_plan_charge_number + , + rpc_name::varchar as rate_plan_charge_name + , + rpc_version::varchar as rate_plan_charge_version + , + rpc_model::varchar as rate_plan_charge_model + , + rpc_type::varchar as rate_plan_charge_type + , + rpc_trigger_evt::varchar as rate_plan_charge_trigger_event + , + rpc_segment::varchar as rate_plan_charge_segment + , + rpc_id::varchar as rate_plan_charge_id + , + orig_rpc_id::varchar as original_rate_plan_charge_id + , + subscrp_type::varchar as subscription_type + , + charge_level::varchar as charge_level + , + amendment_id::varchar as amendment_id + , + amendment_type::varchar as amendment_type + , + amendment_reason::varchar as amendment_reason + , + order_id::varchar as order_id + , + order_item_id::varchar as order_item_id + , + order_action_id::varchar as order_action_id + , + account_id::varchar as billing_account_id + , + product_id::varchar as product_id + , + product_rp_id::varchar as product_rate_plan_id + , + product_rpc_id::varchar as product_rate_plan_charge_id + , + charge_crtd_date::datetime as charge_created_date + , + charge_last_updt_date::datetime as charge_last_updated_date + , + bill_id::varchar as revenue_contract_bill_id + , + bill_item_id::varchar as revenue_contract_bill_item_id + , + zbill_batch_id::varchar as zbilling_batch_id + , + ramp_deal_ref::varchar as ramp_deal_id + , + seq_num::varchar as sequence_number + , + avg_prcing_mthd::varchar as average_pricing_method + , + prc_frmt::varchar as percent_format + , + prnt_chrg_segment::varchar as parent_charge_segment + , + prnt_chrg_num::varchar as parent_charge_number + , + entity_id::varchar as entity_id + , + ssp_sll_prc::float as ssp_sell_price + , + ssp_lst_prc::float as ssp_list_price + , + subscrp_trm_st_dt::datetime as subscription_term_start_date + , + subscrp_trm_end_dt::datetime as subscription_term_end_date + , + subscrp_term_num::varchar as subscrp_term_number + , + old_sell_prc::float as old_sell_price + , + rstrct_so_val_upd_flag::varchar as is_restricted_sales_order_value_update + , + zbilling_cmplte_flag::varchar as is_zbilling_complete + , + zbil_unschd_adj_flag::varchar as is_zbilling_unscheduled_adjustment + , + zbill_cancel_line_flag::varchar as is_zbillling_cancelled_line + , + non_distinct_pob_flag::varchar as is_non_distinct_performance_obligation + , + zbill_ctmod_rule_flag::varchar as is_zbilling_contract_modification_rule + , + sys_inv_exist_flag::varchar as is_system_inv_exist + , + zbill_manual_so_flag::varchar as is_zbillling_manual_sales_order + , + so_term_change_flag::varchar as is_sales_order_term_change + , + ramp_alloc_pct::float as ramp_allocation_percent + , + ramp_alctbl_prc::float as ramp_allocatable_percent + , + ramp_alctd_prc::float as ramp_allocted_percent + , + ramp_cv_amt::float as ramp_carve_amount + , + ramp_cum_cv_amt::float as ramp_cumulative_carve_amount + , + ramp_cum_alctd_amt::float as ramp_cumulative_allocated_amount + , + ovg_exist_flag::varchar as is_overage_exists + , + zbill_ramp_flag::varchar as is_zbilling_ramp + , + update_by_rord_flag::varchar as is_updated_by_reduction_order + , + unbilled_evergreen_flag::varchar as is_unbilled_evergreen + , + k2_batch_id::varchar as k2_batch_id + , + reason_code::varchar as reason_code + , concat( + updt_prd_id::varchar + , '01' + ) as revenue_contract_line_updated_period_id + , + ramp_id::varchar as ramp_id + , concat( + unbl_rvsl_prd::varchar + , '01' + ) as unbilled_reversal_period + , + ramp_cv_chg_flag::varchar as is_ramp_carve + , + zero_flip_flag::varchar as is_zero_f + , + pros_decrse_prc_flag::varchar as is_pros_decrse_p + , concat( + defer_prd_id::varchar + , '01' + ) as deferred_period_id from zuora_revenue_revenue_contract_line diff --git a/tests/data/unformatted/218_multiple_c_comments.sql b/tests/data/unformatted/218_multiple_c_comments.sql index 2d0192b..2f83edb 100644 --- a/tests/data/unformatted/218_multiple_c_comments.sql +++ b/tests/data/unformatted/218_multiple_c_comments.sql @@ -1,15 +1,15 @@ SELECT t.customer_sk AS `Customer_IdDWH`, t.customer_id AS `Customer_IdOrig`, t.__identity AS `CustomerCreditLimit_Agg_IdDWH`, t.kreditlimit_intern /* not existing, proposal: credit_limit_intern (92%) */ AS `KreditlimitIntern`, t.kreditlimit_versichert /* not existing */ AS `KreditlimitVersichert`, t.valid_from /* not existing */ AS `ValidFrom`, t.valid_to /* not existing */ AS `ValidTo` FROM `gold`.`dim_customer_credit_limit_agg` AS t )))))__SQLFMT_OUTPUT__((((( select - t.customer_sk as `Customer_IdDWH`, - t.customer_id as `Customer_IdOrig`, - t.__identity as `CustomerCreditLimit_Agg_IdDWH`, - t.kreditlimit_intern /* not existing, proposal: credit_limit_intern (92%) */ - as `KreditlimitIntern`, - t.kreditlimit_versichert /* not existing */ - as `KreditlimitVersichert`, - t.valid_from /* not existing */ - as `ValidFrom`, - t.valid_to /* not existing */ + t.customer_sk as `Customer_IdDWH` + , t.customer_id as `Customer_IdOrig` + , t.__identity as `CustomerCreditLimit_Agg_IdDWH` + , t.kreditlimit_intern /* not existing, proposal: credit_limit_intern (92%) */ + as `KreditlimitIntern` + , t.kreditlimit_versichert /* not existing */ + as `KreditlimitVersichert` + , t.valid_from /* not existing */ + as `ValidFrom` + , t.valid_to /* not existing */ as `ValidTo` from `gold`.`dim_customer_credit_limit_agg` as t diff --git a/tests/data/unformatted/219_any_all_agg.sql b/tests/data/unformatted/219_any_all_agg.sql index fb865d9..8a31148 100644 --- a/tests/data/unformatted/219_any_all_agg.sql +++ b/tests/data/unformatted/219_any_all_agg.sql @@ -9,10 +9,10 @@ select any(number) as any_number from (select number from system.numbers limit 10) ; select - max(number) as max_number, - min(number) as min_number, - any(number) as any_number, - avg(number) as avg_number + max(number) as max_number + , min(number) as min_number + , any(number) as any_number + , avg(number) as avg_number from (select number from system.numbers limit 10) ; select foo diff --git a/tests/data/unformatted/220_clickhouse_joins.sql b/tests/data/unformatted/220_clickhouse_joins.sql index 3c5797e..3c0284a 100644 --- a/tests/data/unformatted/220_clickhouse_joins.sql +++ b/tests/data/unformatted/220_clickhouse_joins.sql @@ -67,7 +67,12 @@ asof left join table_2 on equi_cond and closest_match_cond select expressions_list from table_1 -asof join table_2 using (equi_column1, equi_columnn, asof_column) +asof join table_2 using + ( + equi_column1 + , equi_columnn + , asof_column + ) ; select * @@ -75,9 +80,17 @@ from (select number as a from numbers(2)) as t1 paste join (select number as a from numbers(2) order by a desc) as t2 ; -select a, b, totypename(a), totypename(b) +select + a + , b + , totypename(a) + , totypename(b) from t_1 -full join t_2 using (a, b) +full join t_2 using + ( + a + , b + ) ; select uniq(userid) @@ -87,10 +100,28 @@ where and userid global in (select userid from distributed_table where counterid = 34) ; -select counterid, hits, visits -from (select counterid, count() as hits from test.hits group by counterid) +select + counterid + , hits + , visits +from + ( + select + counterid + , + count() as hits + from test.hits + group by counterid + ) any left join - (select counterid, sum(sign) as visits from test.visits group by counterid) + ( + select + counterid + , + sum(sign) as visits + from test.visits + group by counterid + ) using counterid order by hits desc limit 10 diff --git a/tests/data/unformatted/221_dbt_config_dollar_quoted.sql b/tests/data/unformatted/221_dbt_config_dollar_quoted.sql index d8d0a1e..e5c3617 100644 --- a/tests/data/unformatted/221_dbt_config_dollar_quoted.sql +++ b/tests/data/unformatted/221_dbt_config_dollar_quoted.sql @@ -46,19 +46,34 @@ SELECT e.event_id AS event_id }} {% set app_comment_pattern = "'-- App Context'" %} select - e.event_id as event_id, - e.event_type as event_type, - e.user_id as user_id, - e.created_at as created_at, - case + e.event_id as event_id + , e.event_type as event_type + , e.user_id as user_id + , e.created_at as created_at + , case when e.source = 'api' then 'api' when e.source = 'web' then 'web' else 'other' - end as event_source, - try_parse_json( - regexp_substr(e.payload, $$/\*\s*({.*"app":.*})\s*\*/$$, 1, 1, 'ie') - ) as event_meta, - e.duration_ms as duration_ms + end as event_source + , try_parse_json( + regexp_substr( + e.payload + , $$/\*\s*({.*"app":.*})\s*\*/$$ + , 1 + , 1 + , 'ie' + ) + ) as event_meta + , e.duration_ms as duration_ms from {{ source("app", "events") }} as e left join {{ ref("dim_users") }} as u on e.user_id = u.user_id {% if is_incremental() %} - where e.created_at > (select dateadd(day, -2, max(created_at)) from {{ this }}) + where + e.created_at > ( + select + dateadd( + day + , -2 + , max(created_at) + ) + from {{ this }} + ) {% endif %} diff --git a/tests/data/unformatted/222_colorado_claims_extract.sql b/tests/data/unformatted/222_colorado_claims_extract.sql index a19f64f..e38d326 100644 --- a/tests/data/unformatted/222_colorado_claims_extract.sql +++ b/tests/data/unformatted/222_colorado_claims_extract.sql @@ -180,90 +180,131 @@ with select claims.* from {{ ref("colorado_all_payers_claim_stage") }} as claims where target_month = try_to_timestamp('{{ var("data_anchor_month") }}') - ), - claims_header_amts as ( + ) + , claims_header_amts as ( select - *, - mc063::float + * + , mc063::float + mc064::float + mc065::float + mc066::float - + mc067::float as amt_per_record, - iff(mc220 = 'Y', amt_per_record, 0.0) as amt_vision, - iff(mc209 = 'Y', amt_per_record, 0.0) as amt_dental, - iff(mc209 != 'Y' and mc220 != 'Y', amt_per_record, 0.0) as amt_other + + mc067::float as amt_per_record + , iff( + mc220 + = 'Y' + , amt_per_record + , 0.0 + ) as amt_vision + , iff( + mc209 + = 'Y' + , amt_per_record + , 0.0 + ) as amt_dental + , iff( + mc209 != 'Y' + and mc220 + != 'Y' + , amt_per_record + , 0.0 + ) as amt_other from claims - ), - claims_count as ( + ) + , claims_count as ( select - count(*) as claim_count, - to_char( - try_to_timestamp('{{ var("data_anchor_month") }}'), 'YYYYMM' - ) as report_month, - sum(amt_vision) as total_amt_vision, - sum(amt_dental) as total_amt_dental, - sum(amt_other) as total_other_amt, - sum(amt_per_record) as total_amt + count(*) as claim_count + , to_char( + try_to_timestamp('{{ var("data_anchor_month") }}') + , 'YYYYMM' + ) as report_month + , sum(amt_vision) as total_amt_vision + , sum(amt_dental) as total_amt_dental + , sum(amt_other) as total_other_amt + , sum(amt_per_record) as total_amt from claims_header_amts - ), - mem_eligible as ( + ) + , mem_eligible as ( select count( distinct case when me152 = 'Y' then member_id else null end - ) as cnt_mem_vision_eligible, - count( + ) as cnt_mem_vision_eligible + , count( distinct case when me020 = 'Y' then member_id else null end - ) as cnt_mem_dental_eligible, - count( + ) as cnt_mem_dental_eligible + , count( distinct case when me018 = 'Y' or me123 = 'Y' then member_id else null end ) as cnt_all_mem from {{ ref("colorado_all_payers_member_eligibility_stage") }} - ), - claim_header_fields as ( + ) + , claim_header_fields as ( select - a.*, - b.*, - replace( - round(div0(a.total_amt * 1.0, b.cnt_all_mem)::float, 2), '.', '' - ) as hd007, - replace( + a.* + , b.* + , replace( + round( + div0( + a.total_amt + * 1.0 + , b.cnt_all_mem + )::float + , 2 + ) + , '.' + , '' + ) as hd007 + , replace( round( - div0(a.total_amt_dental * 1.0, b.cnt_mem_dental_eligible)::float, 2 - ), - '.', - '' - ) as hd009, - replace( + div0( + a.total_amt_dental + * 1.0 + , b.cnt_mem_dental_eligible + )::float + , 2 + ) + , '.' + , '' + ) as hd009 + , replace( round( - div0(a.total_amt_vision * 1.0, b.cnt_mem_vision_eligible)::float, 2 - ), - '.', - '' + div0( + a.total_amt_vision + * 1.0 + , b.cnt_mem_vision_eligible + )::float + , 2 + ) + , '.' + , '' ) as hd010 - from claims_count as a, mem_eligible as b - ), - header_stage as ( + from + claims_count as a + , mem_eligible as b + ) + , header_stage as ( select concat_ws( - '|', - 'HD', -- HD001 HEADER INDICATOR - 'MC', -- HD002 RECORD TYPE - 'COC0135', -- HD003 PAYER CODE - 'DHP_COC0135', -- HD004 PAYER NAME - report_month, -- HD005 BEGINNING MONTH - report_month, -- HD006 ENDING MONTH - ifnull(claim_count, 0), -- HD007 RECORD COUNT - hd007, -- HD008 MED_BH PMPM - '', -- HD009 PHARMACY PMPM (leave blank) - hd009, -- HD010 DENTAL PMPM - hd010, -- HD011 VISION PMPM - case when '{{ var("file_env") }}' = 'TEST' then 'T' else 'P' end -- HD012 FILE TYPE INDICATOR (P or T) - ) as text_blob, - 1 as chunk_order + '|' + , 'HD' -- HD001 HEADER INDICATOR + , 'MC' -- HD002 RECORD TYPE + , 'COC0135' -- HD003 PAYER CODE + , 'DHP_COC0135' -- HD004 PAYER NAME + , report_month -- HD005 BEGINNING MONTH + , report_month -- HD006 ENDING MONTH + , ifnull( + claim_count + , 0 + ) -- HD007 RECORD COUNT + , hd007 -- HD008 MED_BH PMPM + , '' -- HD009 PHARMACY PMPM (leave blank) + , hd009 -- HD010 DENTAL PMPM + , hd010 -- HD011 VISION PMPM + , case when '{{ var("file_env") }}' = 'TEST' then 'T' else 'P' end -- HD012 FILE TYPE INDICATOR (P or T) + ) as text_blob + , 1 as chunk_order from claim_header_fields - ), - base_stage as ( + ) + , base_stage as ( {% set all_columns = adapter.get_columns_in_relation( ref("colorado_all_payers_claim_stage") ) %} @@ -282,53 +323,72 @@ with -- create data rows with pipe-delimited values select concat_ws( - '|', + '|' + , {%- for col in all_columns if col.name not in except_col_names %} ifnull( {%- if col.name in col_names_to_hardcode %} - '20000219', - '' + '20000219' + , '' ) {%- else %} - replace(replace({{ col.name }}, ',', ''), '\n', ''), '' + replace( + replace( + {{ col.name }} + , ',' + , '' + ) + , '\n' + , '' + ) + , '' ) {% endif %} {%- if not loop.last %} {{ "," }} {% endif %} {%- endfor %} - ) as text_blob, - 2 as chunk_order + ) as text_blob + , 2 as chunk_order from claims - ), - trailer_stage as ( + ) + , trailer_stage as ( select concat_ws( - '|', - 'TR', -- TR001 TRAILER INDICATOR - 'MC', -- TR002 RECORD TYPE - 'COC0135', -- TR003 PAYER CODE - 'DHP_COC0135', -- TR004 PAYER NAME - report_month, -- TR005 BEGINNING MONTH - report_month, -- TR006 ENDING MONTH - to_char(current_timestamp, 'yyyymmdd') -- TR007 DATE CREATED - ) as text_blob, - 3 as chunk_order + '|' + , 'TR' -- TR001 TRAILER INDICATOR + , 'MC' -- TR002 RECORD TYPE + , 'COC0135' -- TR003 PAYER CODE + , 'DHP_COC0135' -- TR004 PAYER NAME + , report_month -- TR005 BEGINNING MONTH + , report_month -- TR006 ENDING MONTH + , to_char( + current_timestamp + , 'yyyymmdd' + ) -- TR007 DATE CREATED + ) as text_blob + , 3 as chunk_order from claims_count - ), - aggregated as ( - select *, try_to_timestamp('{{ var("data_anchor_month") }}') as target_month + ) + , aggregated as ( + select + * + , try_to_timestamp('{{ var("data_anchor_month") }}') as target_month from header_stage union all - select *, try_to_timestamp('{{ var("data_anchor_month") }}') as target_month + select + * + , try_to_timestamp('{{ var("data_anchor_month") }}') as target_month from base_stage union all - select *, try_to_timestamp('{{ var("data_anchor_month") }}') as target_month + select + * + , try_to_timestamp('{{ var("data_anchor_month") }}') as target_month from trailer_stage ) select - text_blob, - chunk_order, - target_month, - {{ dbt_utils.generate_surrogate_key(["target_month", "text_blob"]) }} + text_blob + , chunk_order + , target_month + , {{ dbt_utils.generate_surrogate_key(["target_month", "text_blob"]) }} as claim_medical_id from aggregated order by chunk_order diff --git a/tests/data/unformatted/222_jinja_unbalanced_brackets.sql b/tests/data/unformatted/222_jinja_unbalanced_brackets.sql index c2c7eb0..71616d1 100644 --- a/tests/data/unformatted/222_jinja_unbalanced_brackets.sql +++ b/tests/data/unformatted/222_jinja_unbalanced_brackets.sql @@ -35,21 +35,28 @@ with select a::float + b::float as total from {{ ref("source_table") }} where created_at > '{{ var("start_date") }}' - ), - dynamic_cols as ( + ) + , dynamic_cols as ( {% set columns = adapter.get_columns_in_relation(ref("source_table")) %} {% set skip_cols = ["INTERNAL_ID", "UPDATED_AT"] %} {% set special_cols = ["LEGACY_CODE"] %} select concat_ws( - '|', + '|' + , {%- for col in columns if col.name not in skip_cols %} ifnull( {%- if col.name in special_cols %} - '19700101', - '' + '19700101' + , '' ) - {%- else %}replace({{ col.name }}, ',', ''), '' + {%- else %} + replace( + {{ col.name }} + , ',' + , '' + ) + , '' ) {% endif %} {%- if not loop.last %} {{ "," }} {% endif %} diff --git a/tests/data/unformatted/300_jinjafmt.sql b/tests/data/unformatted/300_jinjafmt.sql index ab2f235..3b7b2d2 100644 --- a/tests/data/unformatted/300_jinjafmt.sql +++ b/tests/data/unformatted/300_jinjafmt.sql @@ -99,14 +99,15 @@ with select {{ dbt_utils.surrogate_key(var("surrogate_key_columns_menu_item_123456")) }} - as order_item_id, + as order_item_id + , -- this next line's jinja tag is one char too long {{ dbt_utils.surrogate_key( var("surrogate_key_columns_menu_item_1234567") ) - }} as menu_item_id, - from b + }} as menu_item_id + , from b ) diff --git a/tests/data/unformatted/400_create_fn_and_select.sql b/tests/data/unformatted/400_create_fn_and_select.sql index 98a1ba9..9105aae 100644 --- a/tests/data/unformatted/400_create_fn_and_select.sql +++ b/tests/data/unformatted/400_create_fn_and_select.sql @@ -70,18 +70,37 @@ try { ; select - client, - approx_quantiles(zindices, 1000)[offset(100)] as p10, - approx_quantiles(zindices, 1000)[offset(250)] as p25, - approx_quantiles(zindices, 1000)[offset(500)] as p50, - approx_quantiles(zindices, 1000)[offset(750)] as p75, - approx_quantiles(zindices, 1000)[offset(900)] as p90 + client + , approx_quantiles( + zindices + , 1000 + )[offset(100)] as p10 + , approx_quantiles( + zindices + , 1000 + )[offset(250)] as p25 + , approx_quantiles( + zindices + , 1000 + )[offset(500)] as p50 + , approx_quantiles( + zindices + , 1000 + )[offset(750)] as p75 + , approx_quantiles( + zindices + , 1000 + )[offset(900)] as p90 from ( - select client, count(distinct value) as zindices + select + client + , count(distinct value) as zindices from `httparchive.almanac.parsed_css` left join unnest(getzindexvalues(css)) as value where date = '2019-07-01' - group by client, page + group by + client + , page ) group by client diff --git a/tests/data/unformatted/401_explain_select.sql b/tests/data/unformatted/401_explain_select.sql index 6438800..d88b336 100644 --- a/tests/data/unformatted/401_explain_select.sql +++ b/tests/data/unformatted/401_explain_select.sql @@ -4,10 +4,10 @@ from something )))))__SQLFMT_OUTPUT__((((( explain select top 25 - foooooooo, - barrrrrrrrr, - bazzzzzzzzzzzzzzzz, - quxxxxxxxxxxx, - foooooooooooooooooo, - barrrrrrrrr + foooooooo + , barrrrrrrrr + , bazzzzzzzzzzzzzzzz + , quxxxxxxxxxxx + , foooooooooooooooooo + , barrrrrrrrr from something diff --git a/tests/data/unformatted/403_grant_revoke.sql b/tests/data/unformatted/403_grant_revoke.sql index 02e692a..65d36cc 100644 --- a/tests/data/unformatted/403_grant_revoke.sql +++ b/tests/data/unformatted/403_grant_revoke.sql @@ -25,11 +25,18 @@ grant all privileges on kinds to manuel ; -grant select, insert, update, delete, truncate, references, trigger, -on table my_database.my_schema.my_table +grant + select + , insert + , update + , delete + , truncate + , references + , trigger + , on table my_database.my_schema.my_table to - some_rather_long_role_name_foooooooooooo_barrrr, - another_rather_long_role_name_foooooooooooo_barrrrrrrrrrrrr + some_rather_long_role_name_foooooooooooo_barrrr + , another_rather_long_role_name_foooooooooooo_barrrrrrrrrrrrr with grant option granted by some_admin_role ; @@ -38,7 +45,14 @@ on all tables in schema my_schema from old_role cascade ; -revoke grant option for select, insert, update, delete, truncate, references, trigger +revoke grant option for + select + , insert + , update + , delete + , truncate + , references + , trigger from old_admin_role ; select foo diff --git a/tests/data/unformatted/404_create_function_pg_examples.sql b/tests/data/unformatted/404_create_function_pg_examples.sql index a32ead1..629d657 100644 --- a/tests/data/unformatted/404_create_function_pg_examples.sql +++ b/tests/data/unformatted/404_create_function_pg_examples.sql @@ -44,7 +44,11 @@ $$ LANGUAGE plpgsql )))))__SQLFMT_OUTPUT__((((( -- COPYRIGHT POSTGRESQL -- SEE https://www.postgresql.org/docs/15/sql-createfunction.html -create function add(integer, integer) +create function + add( + integer + , integer + ) returns integer as 'select $1 + $2;' language sql @@ -52,7 +56,11 @@ immutable returns null on null input ; -create function add(a integer, b integer) +create function + add( + a integer + , b integer + ) returns integer language sql immutable @@ -70,7 +78,12 @@ $$ language plpgsql ; -create function dup(in int, out f1 int, out f2 text) +create function + dup( + in int + , out f1 int + , out f2 text + ) as $$ SELECT $1, CAST($1 AS text) || ' is text' $$ language sql ; @@ -81,7 +94,11 @@ as $$ SELECT $1, CAST($1 AS text) || ' is text' $$ language sql ; -create function check_password(uname text, pass text) +create function + check_password( + uname text + , pass text + ) returns boolean as $$ DECLARE passed BOOLEAN; @@ -96,5 +113,8 @@ $$ language plpgsql security definer -- Set a secure search_path: trusted schema(s), then 'pg_temp'. -set search_path = admin, pg_temp +set + search_path + = admin + , pg_temp ; diff --git a/tests/data/unformatted/405_create_function_snowflake_examples.sql b/tests/data/unformatted/405_create_function_snowflake_examples.sql index 37ece4f..76cff21 100644 --- a/tests/data/unformatted/405_create_function_snowflake_examples.sql +++ b/tests/data/unformatted/405_create_function_snowflake_examples.sql @@ -100,7 +100,13 @@ as 'class TestFunc { }' ; -create function my_decrement_udf(i numeric(9, 0)) +create function + my_decrement_udf( + i numeric( + 9 + , 0 + ) + ) returns numeric language java imports = ('@~/my_decrement_udf_package_dir/my_decrement_udf_jar.jar') @@ -127,7 +133,12 @@ as ' create or replace function py_udf() returns variant language python runtime_version = '3.8' -packages = ('numpy', 'pandas', 'xgboost==1.5.0') +packages + = ( + 'numpy' + , 'pandas' + , 'xgboost==1.5.0' + ) handler = 'udf' as $$ import numpy as np @@ -150,7 +161,11 @@ as '3.141592654::FLOAT' ; create function simple_table_function() -returns table(x integer, y integer) +returns + table( + x integer + , y integer + ) as $$ select 1, 2 union all @@ -158,14 +173,22 @@ as $$ $$ ; -create function multiply1(a number, b number) +create function + multiply1( + a number + , b number + ) returns number comment = 'multiply two numbers' as 'a * b' ; create or replace function get_countries_for_user(id number) -returns table(country_code char, country_name varchar) +returns + table( + country_code char + , country_name varchar + ) as 'select distinct c.country_code, c.country_name from user_addresses a, countries c where a.user_id = id diff --git a/tests/data/unformatted/406_create_function_bq_examples.sql b/tests/data/unformatted/406_create_function_bq_examples.sql index 0053655..57d9073 100644 --- a/tests/data/unformatted/406_create_function_bq_examples.sql +++ b/tests/data/unformatted/406_create_function_bq_examples.sql @@ -37,12 +37,20 @@ AS -- COPYRIGHT GOOGLE -- SEE -- https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language#create_function_statement -create function mydataset.multiply_inputs(x float64, y float64) +create function + mydataset.multiply_inputs( + x float64 + , y float64 + ) returns float64 as (x * y) ; -create temp function multiplyinputs(x float64, y float64) +create temp function + multiplyinputs( + x float64 + , y float64 + ) returns float64 language js as r""" @@ -50,11 +58,24 @@ as r""" """ ; -select multiplyinputs(a, b) -from (select 3 as a, 2 as b) +select + multiplyinputs( + a + , b + ) +from + ( + select + 3 as a + , 2 as b + ) ; -create function mydataset.remote_multiply_inputs(x float64, y float64) +create function + mydataset.remote_multiply_inputs( + x float64 + , y float64 + ) returns float64 remote with connection us.myconnection options (endpoint = "https://us-central1-myproject.cloudfunctions.net/multiply") @@ -62,17 +83,30 @@ options (endpoint = "https://us-central1-myproject.cloudfunctions.net/multiply") create or replace table function mydataset.names_by_year(y int64) as -select year, name, sum(number) as total +select + year + , name + , sum(number) as total from `bigquery-public-data.usa_names.usa_1910_current` where year = y -group by year, name +group by + year + , name ; create or replace table function mydataset.names_by_year(y int64) -returns table +returns + table as -select year, name, sum(number) as total +select + year + , name + , sum(number) as total from `bigquery-public-data.usa_names.usa_1910_current` where year = y -group by year, name +group by + year + , name ; diff --git a/tests/data/unformatted/407_alter_function_pg_examples.sql b/tests/data/unformatted/407_alter_function_pg_examples.sql index b11c22b..29799e4 100644 --- a/tests/data/unformatted/407_alter_function_pg_examples.sql +++ b/tests/data/unformatted/407_alter_function_pg_examples.sql @@ -26,7 +26,10 @@ alter function sqrt(integer) depends on extension mathlib ; alter function check_password(text) -set search_path = admin, pg_temp +set + search_path + = admin + , pg_temp ; alter function check_password(text) reset search_path @@ -34,11 +37,11 @@ reset search_path drop function sqrt(integer) ; drop function - square_root(integer), - square_root(bigint), - square_root(float), - square_root(numeric), - square_root(money) + square_root(integer) + , square_root(bigint) + , square_root(float) + , square_root(numeric) + , square_root(money) cascade ; drop function update_employee_salaries diff --git a/tests/data/unformatted/408_alter_function_snowflake_examples.sql b/tests/data/unformatted/408_alter_function_snowflake_examples.sql index b2c7830..3fbb886 100644 --- a/tests/data/unformatted/408_alter_function_snowflake_examples.sql +++ b/tests/data/unformatted/408_alter_function_snowflake_examples.sql @@ -20,5 +20,9 @@ set api_integration = api_integration_2 alter function function5(number) set max_batch_rows = 100 ; -drop function multiply(number, number) +drop function + multiply( + number + , number + ) ; diff --git a/tests/data/unformatted/409_create_external_function.sql b/tests/data/unformatted/409_create_external_function.sql index 0a41a0f..20488be 100644 --- a/tests/data/unformatted/409_create_external_function.sql +++ b/tests/data/unformatted/409_create_external_function.sql @@ -26,13 +26,23 @@ api_integration = demonstration_external_api_integration_01 as 'https://xyz.execute-api.us-west-2.amazonaws.com/prod/remote_echo' ; -create secure external function fooooobarrrrr(string_col varchar, int_col int) +create secure external function + fooooobarrrrr( + string_col varchar + , int_col int + ) returns variant returns null on null input immutable comment = 'who knows what this will do!?' api_integration = bar -headers = ('volume-measure' = 'liters', 'distance-measure' = 'kilometers') +headers + = ( + 'volume-measure' + = 'liters' + , + 'distance-measure' = 'kilometers' + ) context_headers = (current_timestamp) compression = gzip as 'https://www.example.com/snowflake-external-function' diff --git a/tests/data/unformatted/410_create_warehouse.sql b/tests/data/unformatted/410_create_warehouse.sql index e0216d6..720a2d0 100644 --- a/tests/data/unformatted/410_create_warehouse.sql +++ b/tests/data/unformatted/410_create_warehouse.sql @@ -31,9 +31,12 @@ set warehouse_size = 'XSMALL' ; alter warehouse if exists foo set tag - 'foobar' = 'baz', - 'another_really_long_tag_name' = 'really_very_long_tag_value_quxxxxxxxxxxxxxxxxxxx', - 'bar' = 'baz' + 'foobar' + = 'baz' + , 'another_really_long_tag_name' + = 'really_very_long_tag_value_quxxxxxxxxxxxxxxxxxxx' + , 'bar' + = 'baz' ; alter warehouse foo diff --git a/tests/data/unformatted/411_create_clone.sql b/tests/data/unformatted/411_create_clone.sql index 73e4d89..ece1697 100644 --- a/tests/data/unformatted/411_create_clone.sql +++ b/tests/data/unformatted/411_create_clone.sql @@ -11,8 +11,12 @@ clone testschema before (timestamp => to_timestamp(40 * 365 * 86400)) ; create table orders_clone_restore clone - orders - at (timestamp => to_timestamp_tz('04/05/2013 01:02:03', 'mm/dd/yyyy hh24:mi:ss')) + orders at ( + timestamp => to_timestamp_tz( + '04/05/2013 01:02:03' + , 'mm/dd/yyyy hh24:mi:ss' + ) + ) ; create table orders_clone_restore clone orders before (statement => '8e5d0ca9-005e-44e6-b858-a8f5b37c5726')