Repository: sqlfluff/sqlfluff
Issue category: Bug Report

Regression: spacing rules for functions
### Search before asking

- [X] I searched the [issues](https://github.com/sqlfluff/sqlfluff/issues) and found no similar issues.


### What Happened

I have this spark sql query 
```sql
select /*+ repartition(200) */
    one,
    two
from
    mytable
```
and starting from commit 18293ce419e9605e978e47b7f3e83fd7543f4818 sqlfluff is failing with
```
== [query.sql] FAIL                                                                                                                                                                                    
L:   1 | P:  23 | LT01 | Expected single whitespace between function name
                       | identifier and start bracket '('.
                       | [layout.spacing]
```

### Expected Behaviour

I expect sqlfluff to ignore spacing in the query comments. Or there should be an option to disable this behavior

### Observed Behaviour

sqlfluff is failing with
```
== [query.sql] FAIL                                                                                                                                                                                    
L:   1 | P:  23 | LT01 | Expected single whitespace between function name
                       | identifier and start bracket '('.
                       | [layout.spacing]
```

### How to reproduce

Create file `query.sql`:
```sql
select /*+ repartition(200) */
    one,
    two
from
    mytable
```
Then execute
```
git checkout 18293ce419e9605e978e47b7f3e83fd7543f4818
uv venv
uv pip install .
uv run sqlfluff lint --dialect sparksql ./query.sql 
```

### Dialect

sparksql

### Version

version 3.1.1 didn't have the issue, version 3.2.0 is the first release that has the issue
I bisected the problem to commit 18293ce419e9605e978e47b7f3e83fd7543f4818 

### Configuration

default

### Are you willing to work on and submit a PR to address the issue?

- [ ] Yes I am willing to submit a PR!

### Code of Conduct

- [X] I agree to follow this project's [Code of Conduct](https://github.com/sqlfluff/sqlfluff/blob/main/CODE_OF_CONDUCT.md)



Functions to edit:
src/sqlfluff/dialects/dialect_sparksql.py:HintFunctionSegment

Patch:
diff --git a/src/sqlfluff/dialects/dialect_sparksql.py b/src/sqlfluff/dialects/dialect_sparksql.py
index bc8d4252886..bd2d519ce8d 100644
--- a/src/sqlfluff/dialects/dialect_sparksql.py
+++ b/src/sqlfluff/dialects/dialect_sparksql.py
@@ -1968,19 +1968,7 @@ class HintFunctionSegment(BaseSegment):
 
     match_grammar = Sequence(
         Ref("FunctionNameSegment"),
-        Bracketed(
-            Delimited(
-                AnyNumberOf(
-                    Ref("SingleIdentifierGrammar"),
-                    Ref("NumericLiteralSegment"),
-                    Ref("TableReferenceSegment"),
-                    Ref("ColumnReferenceSegment"),
-                    min_times=1,
-                ),
-            ),
-            # May be Bare Function unique to Hints, i.e. REBALANCE
-            optional=True,
-        ),
+        Ref("FunctionContentsSegment", optional=True),
     )
 
 

Test patch: diff --git a/test/fixtures/dialects/sparksql/insert_overwrite_directory.yml b/test/fixtures/dialects/sparksql/insert_overwrite_directory.yml
index a6367faa95d..9fd0cf3dd5c 100644
--- a/test/fixtures/dialects/sparksql/insert_overwrite_directory.yml
+++ b/test/fixtures/dialects/sparksql/insert_overwrite_directory.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: b19c5c1de0e98b801765c0fc5e50a61d9540e3ce8037ee021284b4fbd6d8bf1d
+_hash: 1a1d483f184ec0255394fd87cfc6cec2e5ee976d93fcb404ace2e41d2e76116c
 file:
 - statement:
     insert_overwrite_directory_statement:
@@ -242,10 +242,12 @@ file:
                 hint_function:
                   function_name:
                     function_name_identifier: COALESCE
-                  bracketed:
-                    start_bracket: (
-                    numeric_literal: '1'
-                    end_bracket: )
+                  function_contents:
+                    bracketed:
+                      start_bracket: (
+                      expression:
+                        numeric_literal: '1'
+                      end_bracket: )
                 end_hint: '*/'
             select_clause_element:
               wildcard_expression:
diff --git a/test/fixtures/dialects/sparksql/select_hints.yml b/test/fixtures/dialects/sparksql/select_hints.yml
index 79b7fa18f0a..f0385d65b07 100644
--- a/test/fixtures/dialects/sparksql/select_hints.yml
+++ b/test/fixtures/dialects/sparksql/select_hints.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: 17d210004cf1b2cc4a9861681dd50739ed79ac4a0172ae16ad8a18fd885c03cd
+_hash: b7a5f1a6d838148caf30c0057a70f0d07683f9d092086886c7001c28048731e3
 file:
 - statement:
     select_statement:
@@ -15,10 +15,12 @@ file:
             hint_function:
               function_name:
                 function_name_identifier: COALESCE
-              bracketed:
-                start_bracket: (
-                numeric_literal: '3'
-                end_bracket: )
+              function_contents:
+                bracketed:
+                  start_bracket: (
+                  expression:
+                    numeric_literal: '3'
+                  end_bracket: )
             end_hint: '*/'
       - select_clause_element:
           column_reference:
@@ -49,10 +51,12 @@ file:
             hint_function:
               function_name:
                 function_name_identifier: REPARTITION
-              bracketed:
-                start_bracket: (
-                numeric_literal: '3'
-                end_bracket: )
+              function_contents:
+                bracketed:
+                  start_bracket: (
+                  expression:
+                    numeric_literal: '3'
+                  end_bracket: )
             end_hint: '*/'
       - select_clause_element:
           column_reference:
@@ -83,10 +87,13 @@ file:
             hint_function:
               function_name:
                 function_name_identifier: REPARTITION
-              bracketed:
-                start_bracket: (
-                naked_identifier: c
-                end_bracket: )
+              function_contents:
+                bracketed:
+                  start_bracket: (
+                  expression:
+                    column_reference:
+                      naked_identifier: c
+                  end_bracket: )
             end_hint: '*/'
       - select_clause_element:
           column_reference:
@@ -117,12 +124,16 @@ file:
             hint_function:
               function_name:
                 function_name_identifier: REPARTITION
-              bracketed:
-                start_bracket: (
-                numeric_literal: '3'
-                comma: ','
-                naked_identifier: c
-                end_bracket: )
+              function_contents:
+                bracketed:
+                - start_bracket: (
+                - expression:
+                    numeric_literal: '3'
+                - comma: ','
+                - expression:
+                    column_reference:
+                      naked_identifier: c
+                - end_bracket: )
             end_hint: '*/'
       - select_clause_element:
           column_reference:
@@ -153,10 +164,13 @@ file:
             hint_function:
               function_name:
                 function_name_identifier: REPARTITION_BY_RANGE
-              bracketed:
-                start_bracket: (
-                naked_identifier: c
-                end_bracket: )
+              function_contents:
+                bracketed:
+                  start_bracket: (
+                  expression:
+                    column_reference:
+                      naked_identifier: c
+                  end_bracket: )
             end_hint: '*/'
       - select_clause_element:
           column_reference:
@@ -187,12 +201,16 @@ file:
             hint_function:
               function_name:
                 function_name_identifier: REPARTITION_BY_RANGE
-              bracketed:
-                start_bracket: (
-                numeric_literal: '3'
-                comma: ','
-                naked_identifier: c
-                end_bracket: )
+              function_contents:
+                bracketed:
+                - start_bracket: (
+                - expression:
+                    numeric_literal: '3'
+                - comma: ','
+                - expression:
+                    column_reference:
+                      naked_identifier: c
+                - end_bracket: )
             end_hint: '*/'
       - select_clause_element:
           column_reference:
@@ -253,10 +271,13 @@ file:
             hint_function:
               function_name:
                 function_name_identifier: REBALANCE
-              bracketed:
-                start_bracket: (
-                naked_identifier: c
-                end_bracket: )
+              function_contents:
+                bracketed:
+                  start_bracket: (
+                  expression:
+                    column_reference:
+                      naked_identifier: c
+                  end_bracket: )
             end_hint: '*/'
       - select_clause_element:
           column_reference:
@@ -287,28 +308,36 @@ file:
           - hint_function:
               function_name:
                 function_name_identifier: REPARTITION
-              bracketed:
-                start_bracket: (
-                numeric_literal: '100'
-                end_bracket: )
+              function_contents:
+                bracketed:
+                  start_bracket: (
+                  expression:
+                    numeric_literal: '100'
+                  end_bracket: )
           - comma: ','
           - hint_function:
               function_name:
                 function_name_identifier: COALESCE
-              bracketed:
-                start_bracket: (
-                numeric_literal: '500'
-                end_bracket: )
+              function_contents:
+                bracketed:
+                  start_bracket: (
+                  expression:
+                    numeric_literal: '500'
+                  end_bracket: )
           - comma: ','
           - hint_function:
               function_name:
                 function_name_identifier: REPARTITION_BY_RANGE
-              bracketed:
-                start_bracket: (
-                numeric_literal: '3'
-                comma: ','
-                naked_identifier: c
-                end_bracket: )
+              function_contents:
+                bracketed:
+                - start_bracket: (
+                - expression:
+                    numeric_literal: '3'
+                - comma: ','
+                - expression:
+                    column_reference:
+                      naked_identifier: c
+                - end_bracket: )
           - end_hint: '*/'
       - select_clause_element:
           column_reference:
@@ -339,10 +368,13 @@ file:
             hint_function:
               function_name:
                 function_name_identifier: BROADCAST
-              bracketed:
-                start_bracket: (
-                naked_identifier: t1
-                end_bracket: )
+              function_contents:
+                bracketed:
+                  start_bracket: (
+                  expression:
+                    column_reference:
+                      naked_identifier: t1
+                  end_bracket: )
             end_hint: '*/'
       - select_clause_element:
           column_reference:
@@ -399,10 +431,13 @@ file:
             hint_function:
               function_name:
                 function_name_identifier: BROADCASTJOIN
-              bracketed:
-                start_bracket: (
-                naked_identifier: t1
-                end_bracket: )
+              function_contents:
+                bracketed:
+                  start_bracket: (
+                  expression:
+                    column_reference:
+                      naked_identifier: t1
+                  end_bracket: )
             end_hint: '*/'
       - select_clause_element:
           column_reference:
@@ -459,10 +494,13 @@ file:
             hint_function:
               function_name:
                 function_name_identifier: MAPJOIN
-              bracketed:
-                start_bracket: (
-                naked_identifier: t2
-                end_bracket: )
+              function_contents:
+                bracketed:
+                  start_bracket: (
+                  expression:
+                    column_reference:
+                      naked_identifier: t2
+                  end_bracket: )
             end_hint: '*/'
       - select_clause_element:
           column_reference:
@@ -519,10 +557,13 @@ file:
             hint_function:
               function_name:
                 function_name_identifier: SHUFFLE_MERGE
-              bracketed:
-                start_bracket: (
-                naked_identifier: t1
-                end_bracket: )
+              function_contents:
+                bracketed:
+                  start_bracket: (
+                  expression:
+                    column_reference:
+                      naked_identifier: t1
+                  end_bracket: )
             end_hint: '*/'
       - select_clause_element:
           column_reference:
@@ -579,10 +620,13 @@ file:
             hint_function:
               function_name:
                 function_name_identifier: MERGEJOIN
-              bracketed:
-                start_bracket: (
-                naked_identifier: t2
-                end_bracket: )
+              function_contents:
+                bracketed:
+                  start_bracket: (
+                  expression:
+                    column_reference:
+                      naked_identifier: t2
+                  end_bracket: )
             end_hint: '*/'
       - select_clause_element:
           column_reference:
@@ -639,10 +683,13 @@ file:
             hint_function:
               function_name:
                 function_name_identifier: MERGE
-              bracketed:
-                start_bracket: (
-                naked_identifier: t1
-                end_bracket: )
+              function_contents:
+                bracketed:
+                  start_bracket: (
+                  expression:
+                    column_reference:
+                      naked_identifier: t1
+                  end_bracket: )
             end_hint: '*/'
       - select_clause_element:
           column_reference:
@@ -699,10 +746,13 @@ file:
             hint_function:
               function_name:
                 function_name_identifier: SHUFFLE_HASH
-              bracketed:
-                start_bracket: (
-                naked_identifier: t1
-                end_bracket: )
+              function_contents:
+                bracketed:
+                  start_bracket: (
+                  expression:
+                    column_reference:
+                      naked_identifier: t1
+                  end_bracket: )
             end_hint: '*/'
       - select_clause_element:
           column_reference:
@@ -759,10 +809,13 @@ file:
             hint_function:
               function_name:
                 function_name_identifier: SHUFFLE_REPLICATE_NL
-              bracketed:
-                start_bracket: (
-                naked_identifier: t1
-                end_bracket: )
+              function_contents:
+                bracketed:
+                  start_bracket: (
+                  expression:
+                    column_reference:
+                      naked_identifier: t1
+                  end_bracket: )
             end_hint: '*/'
       - select_clause_element:
           column_reference:
@@ -819,20 +872,28 @@ file:
           - hint_function:
               function_name:
                 function_name_identifier: BROADCAST
-              bracketed:
-                start_bracket: (
-                naked_identifier: t1
-                end_bracket: )
+              function_contents:
+                bracketed:
+                  start_bracket: (
+                  expression:
+                    column_reference:
+                      naked_identifier: t1
+                  end_bracket: )
           - comma: ','
           - hint_function:
               function_name:
                 function_name_identifier: MERGE
-              bracketed:
-              - start_bracket: (
-              - naked_identifier: t1
-              - comma: ','
-              - naked_identifier: t2
-              - end_bracket: )
+              function_contents:
+                bracketed:
+                - start_bracket: (
+                - expression:
+                    column_reference:
+                      naked_identifier: t1
+                - comma: ','
+                - expression:
+                    column_reference:
+                      naked_identifier: t2
+                - end_bracket: )
           - end_hint: '*/'
       - select_clause_element:
           column_reference:
@@ -889,13 +950,15 @@ file:
             hint_function:
               function_name:
                 function_name_identifier: BROADCAST
-              bracketed:
-                start_bracket: (
-                table_reference:
-                - naked_identifier: db
-                - dot: .
-                - naked_identifier: t1
-                end_bracket: )
+              function_contents:
+                bracketed:
+                  start_bracket: (
+                  expression:
+                    column_reference:
+                    - naked_identifier: db
+                    - dot: .
+                    - naked_identifier: t1
+                  end_bracket: )
             end_hint: '*/'
       - select_clause_element:
           column_reference:
diff --git a/test/fixtures/dialects/sparksql/select_sort_by.yml b/test/fixtures/dialects/sparksql/select_sort_by.yml
index 0c3bed49f46..0226949f048 100644
--- a/test/fixtures/dialects/sparksql/select_sort_by.yml
+++ b/test/fixtures/dialects/sparksql/select_sort_by.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: 0123e607c738aa6e9bd1cc1d75eeaaf8d0f32ad4646bbe82e8ef2e7781a69915
+_hash: ac53a271e7f933adb38da8d484ae968ce808e415ab41a629cc1e5b326cfd5f1a
 file:
 - statement:
     select_statement:
@@ -15,10 +15,13 @@ file:
             hint_function:
               function_name:
                 function_name_identifier: REPARTITION
-              bracketed:
-                start_bracket: (
-                naked_identifier: zip_code
-                end_bracket: )
+              function_contents:
+                bracketed:
+                  start_bracket: (
+                  expression:
+                    column_reference:
+                      naked_identifier: zip_code
+                  end_bracket: )
             end_hint: '*/'
       - select_clause_element:
           column_reference:
@@ -82,10 +85,13 @@ file:
             hint_function:
               function_name:
                 function_name_identifier: REPARTITION
-              bracketed:
-                start_bracket: (
-                naked_identifier: zip_code
-                end_bracket: )
+              function_contents:
+                bracketed:
+                  start_bracket: (
+                  expression:
+                    column_reference:
+                      naked_identifier: zip_code
+                  end_bracket: )
             end_hint: '*/'
       - select_clause_element:
           column_reference:
@@ -147,10 +153,13 @@ file:
             hint_function:
               function_name:
                 function_name_identifier: REPARTITION
-              bracketed:
-                start_bracket: (
-                naked_identifier: zip_code
-                end_bracket: )
+              function_contents:
+                bracketed:
+                  start_bracket: (
+                  expression:
+                    column_reference:
+                      naked_identifier: zip_code
+                  end_bracket: )
             end_hint: '*/'
       - select_clause_element:
           column_reference:
@@ -218,10 +227,13 @@ file:
             hint_function:
               function_name:
                 function_name_identifier: REPARTITION
-              bracketed:
-                start_bracket: (
-                naked_identifier: zip_code
-                end_bracket: )
+              function_contents:
+                bracketed:
+                  start_bracket: (
+                  expression:
+                    column_reference:
+                      naked_identifier: zip_code
+                  end_bracket: )
             end_hint: '*/'
       - select_clause_element:
           column_reference:
@@ -287,10 +299,13 @@ file:
             hint_function:
               function_name:
                 function_name_identifier: REPARTITION
-              bracketed:
-                start_bracket: (
-                naked_identifier: zip_code
-                end_bracket: )
+              function_contents:
+                bracketed:
+                  start_bracket: (
+                  expression:
+                    column_reference:
+                      naked_identifier: zip_code
+                  end_bracket: )
             end_hint: '*/'
       - select_clause_element:
           column_reference:
@@ -360,10 +375,13 @@ file:
             hint_function:
               function_name:
                 function_name_identifier: REPARTITION
-              bracketed:
-                start_bracket: (
-                naked_identifier: zip_code
-                end_bracket: )
+              function_contents:
+                bracketed:
+                  start_bracket: (
+                  expression:
+                    column_reference:
+                      naked_identifier: zip_code
+                  end_bracket: )
             end_hint: '*/'
       - select_clause_element:
           column_reference:
diff --git a/test/fixtures/rules/std_rule_cases/LT01-functions.yml b/test/fixtures/rules/std_rule_cases/LT01-functions.yml
index 093c16561d2..7c4c0b63ea8 100644
--- a/test/fixtures/rules/std_rule_cases/LT01-functions.yml
+++ b/test/fixtures/rules/std_rule_cases/LT01-functions.yml
@@ -26,3 +26,14 @@ test_pass_drop_function_go:
   configs:
     core:
       dialect: tsql
+
+test_pass_select_hint:
+  pass_str: |
+    select /*+ repartition(200) */
+        one,
+        two
+    from
+        mytable
+  configs:
+    core:
+      dialect: sparksql