rule: AL02

issue_561:
  # Test for https://github.com/sqlfluff/sqlfluff/issues/561
  pass_str: |
    select
      array_agg(catalog_item_id) within group
        (order by product_position asc) over (partition by (event_id, shelf_position))
      as shelf_catalog_items
    from x
  configs:
    core:
      dialect: snowflake

test_fail_explicit_column_default:
  # Test explicit column alias
  fail_str: select 1 bar from table1 b
  fix_str: select 1 AS bar from table1 b

test_fail_explicit_column_explicit:
  # Test explicit column alias
  fail_str: select 1 bar from table1 b
  fix_str: select 1 AS bar from table1 b
  configs:
    rules:
      aliasing.column:
        aliasing: explicit

test_fail_explicit_column_implicit:
  # Test explicit column alias
  fail_str: select 1 AS bar from table1 b
  fix_str: select 1 bar from table1 b
  configs:
    rules:
      aliasing.column:
        aliasing: implicit

test_pass_tsql_alternative_alias:
  # Test explicit column alias
  pass_str: select alias1 = col1
  configs:
    core:
      dialect: tsql

test_fail_alias_ending_equals:
  # Test explicit column alias doesn't catch false positives
  fail_str: select col1 "example="
  fix_str: select col1 AS "example="

test_fail_alias_ending_raw_equals:
  # Test explicit column alias doesn't catch false positives
  fail_str: select col1 raw_equals
  fix_str: select col1 AS raw_equals


test_alias_expression_align_4515_1:
  # Test more failing alias expressions
  fail_str: |
    select
        test a
    from example_table
  fix_str: |
    select
        test AS a
    from example_table
  configs:
    layout:
      type:
        alias_expression:
          spacing_before: align
          align_within: select_clause
          align_scope: bracketed

test_alias_expression_align_4515_2:
  # Test more failing alias expressions
  fail_str: |
    select
        test a,
        test b
    from example_table
  fix_str: |
    select
        test AS a,
        test AS b
    from example_table
  configs:
    layout:
      type:
        alias_expression:
          spacing_before: align
          align_within: select_clause
          align_scope: bracketed

test_alias_expression_align_4515_3:
  # Test more failing alias expressions
  fail_str: |
    select
        testy_testy_testy a,
        test b
    from example_table
  fix_str: |
    select
        testy_testy_testy AS a,
        test              AS b
    from example_table
  configs:
    layout:
      type:
        alias_expression:
          spacing_before: align
          align_within: select_clause
          align_scope: bracketed
