Repository: sqlfluff/sqlfluff
Pull request: Snowflake drop column fixes
### Brief summary of the change made
Fixes #1617. Linting an 'alter table drop dolumn statement' raised an unparsable section error. Including this specific sequence fixes the issue.

### Are there any other side effects of this change that we should be aware of?
Not that I'm aware of.

### Pull Request checklist
- [x] Please confirm you have completed any of the necessary steps below.


Problem statement:
Snowflake / drop column: unparsable section for drop column statement
## Expected Behaviour
I expected to be able to lint a SQL file containing a 'alter table ... drop column ...' statement.

## Observed Behaviour
When linting this SQL statement an unparsable section error occurred, see code report below:
```bash
== [test_schema/test_table/drop_test_column.sql] FAIL
L:   2 | P:  12 |  PRS | Line 2, Position 12: Found unparsable section: '
                       | test_column'
```

## Steps to Reproduce
1. Install the SQLFluff package version 0.7.0a4
2. Create a file with content below
3. Run sqlfluff lint --dialect snowflake <path-to-file>

Content drop_test_column.sql:
```sql
ALTER TABLE test_schema.test_table
DROP column test_column;

```

## Dialect
Snowflake

## Version
sqlfluff, version 0.7.0a4

## Configuration
```
[sqlfluff]
dialect = snowflake
exclude_rules = L009,L011,L029,L031,L034

[sqlfluff:rules]
tab_space_size = 2

[sqlfluff:rules:L010]  # Keywords
capitalisation_policy = upper

[sqlfluff:rules:L014]  # Tables, columns, views
extended_capitalisation_policy = lower

[sqlfluff:rules:L030]  # Function names
capitalisation_policy = upper

[sqlfluff:rules:L040]  # Null & Boolean Literals
capitalisation_policy = upper

[sqlfluff:rules:L016] # Max line length
max_line_length = 120
```

Hints from issue discussion:

Commit message: Update test files

Patch to review:
diff --git a/src/sqlfluff/dialects/dialect_snowflake.py b/src/sqlfluff/dialects/dialect_snowflake.py
index 854eadbdfca..8193dd8bc82 100644
--- a/src/sqlfluff/dialects/dialect_snowflake.py
+++ b/src/sqlfluff/dialects/dialect_snowflake.py
@@ -788,11 +788,15 @@ class AlterTableColumnStatementSegment(BaseSegment):
         "ALTER",
         "TABLE",
         Ref("TableReferenceSegment"),
-        OneOf("ALTER", "MODIFY"),
+        OneOf("ALTER", "MODIFY", "DROP"),
         OptionallyBracketed(
             Delimited(
                 OneOf(
                     # Add things
+                    Sequence(
+                        Ref.keyword("COLUMN", optional=True),
+                        Ref("SingleIdentifierGrammar"),
+                    ),
                     Sequence(
                         Ref.keyword("COLUMN", optional=True),
                         Ref("SingleIdentifierGrammar"),
diff --git a/test/fixtures/dialects/snowflake/snowflake_alter_table_column.sql b/test/fixtures/dialects/snowflake/snowflake_alter_table_column.sql
index 1a0a3e41a1f..b82e89b53d3 100644
--- a/test/fixtures/dialects/snowflake/snowflake_alter_table_column.sql
+++ b/test/fixtures/dialects/snowflake/snowflake_alter_table_column.sql
@@ -27,3 +27,6 @@ alter table empl_info modify
     column empl_id unset masking policy
   , column empl_dob unset masking policy
 ;
+
+alter table test_table column test_column;
+alter table test_schema.test_table column test_column;
diff --git a/test/fixtures/dialects/snowflake/snowflake_alter_table_column.yml b/test/fixtures/dialects/snowflake/snowflake_alter_table_column.yml
index a135eaaaa4a..a72644b9070 100644
--- a/test/fixtures/dialects/snowflake/snowflake_alter_table_column.yml
+++ b/test/fixtures/dialects/snowflake/snowflake_alter_table_column.yml
@@ -3,7 +3,7 @@
 # computed by SQLFluff when running the tests. Please run
 # `python test/generate_parse_fixture_yml.py`  to generate them after adding or
 # altering SQL files.
-_hash: ef15dedecc089fc8c97f4c6711b60ce49df61850e4a5ed998bfd55f0f5d309d4
+_hash: e96e904a863c121e05868d36181faed96219162fc10dfb3432527bac5acd292f
 file:
 - statement:
     alter_table_column_statement:
@@ -154,3 +154,23 @@ file:
     - keyword: masking
     - keyword: policy
 - statement_terminator: ;
+- statement:
+    alter_table_statement:
+    - keyword: alter
+    - keyword: table
+    - table_reference:
+        identifier: test_table
+    - parameter: column
+    - identifier: test_column
+- statement_terminator: ;
+- statement:
+    alter_table_statement:
+    - keyword: alter
+    - keyword: table
+    - table_reference:
+      - identifier: test_schema
+      - dot: .
+      - identifier: test_table
+    - parameter: column
+    - identifier: test_column
+- statement_terminator: ;


Code review comments:
diff_hunk: @@ -788,11 +788,15 @@ class AlterTableColumnStatementSegment(BaseSegment):
         "ALTER",
         "TABLE",
         Ref("TableReferenceSegment"),
-        OneOf("ALTER", "MODIFY"),
+        OneOf("ALTER", "MODIFY", "DROP"),
         OptionallyBracketed(
             Delimited(
                 OneOf(
                     # Add things
+                    Sequence(
+                        Ref.keyword("COLUMN", optional=True),
+                        Ref("SingleIdentifierGrammar"),
+                    ),
                     Sequence(
                         Ref.keyword("COLUMN", optional=True),
                         Ref("SingleIdentifierGrammar"),
path: src/sqlfluff/dialects/dialect_snowflake.py
text: @user1:
This is interesting. The `DROP` syntax is supported further down but insists on column name before.

Should we either:
1. Go with what you have, but remove the `DROP` from line 804? That would allow `ALTER TABLE ALTER column1` which is not technically correct.
2. Revert your change and make the column before it on line 802 optional? But that would allow `ALTER TABLE ALTER SET NOT NULL` which is not correct as column is missing.
3. Wrap whole thing in a `OneOf` and leave `ALTER` and `MODIFY` alone but pull `DROP` into it's own path?

Option 3 Is probably the most correct to be honest.

What's your thoughts?


@author:
Hm. I see your point. Will wrap the whole thing into an OneOf statement.

@author:
@user1 I think it is now fixed. Could you have a look again. Because we wrapped everything into a OneOf statement, I also had to create a sequence for the 'old' path.