Repository: databendlabs/databend (language: rust)

Issue:
bug: An error occurs when the keyword analyze table is contained in the table
### Search before asking

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


### Version

main

### What's Wrong?

```
create or replace table test(`offset` varchar);
create or replace table test2(`OFFSET` varchar);
insert into test values('ttt');
insert into test2 values('ttt');
```
```

root@localhost:8000/default> analyze table test;
error: APIError: QueryFailed: [1005]error:
  --> SQL:1:51
  |
1 | SELECT approx_count_distinct_state(0.01625)(offset) as ndv_0, true as is_full from default.test AT (snapshot => '83e9ea85e38a4677a76da45a0dbc2282')
  | ------ ---------------------------         -------^
  | |      |                                   ||     |
  | |      |                                   ||     unexpected `)`, expecting `IS`, `IN`, `EXISTS`, `BETWEEN`, `+`, `-`, `*`, `/`, `//`, `DIV`, `%`, `||`, `<->`, `>`, `<`, `>=`, `<=`, `=`, `<>`, `!=`, `^`, `AND`, `OR`, `XOR`, `LIKE`, `NOT`, `REGEXP`, `RLIKE`, `SOUNDS`, <BitWiseOr>, <BitWiseAnd>, <BitWiseXor>, <ShiftLeft>, <ShiftRight>, `->`, `->>`, `#>`, `#>>`, `?`, `?|`, `?&`, `@>`, `<@`, `@?`, `@@`, `#-`, <Factorial>, <SquareRoot>, <BitWiseNot>, <CubeRoot>, <Abs>, `CAST`, `TRY_CAST`, `::`, `POSITION`, `IdentVariable`, `DATE_ADD`, `DATE_DIFF`, `DATE_SUB`, `DATE_TRUNC`, or 34 more ...
  | |      |                                   ||     while parsing expression
  | |      |                                   |while parsing `SELECT ...`
  | |      |                                   while parsing `(SELECT ...)`
  | |      while parsing expression
  | while parsing `SELECT ...`


root@localhost:8000/default> analyze table test2;
error: APIError: QueryFailed: [1005]error:
  --> SQL:1:51
  |
1 | SELECT approx_count_distinct_state(0.01625)(OFFSET) as ndv_0, true as is_full from default.test2 AT (snapshot => '539a13371892415393bf43c89f7917a8')
  | ------ ---------------------------         -------^
  | |      |                                   ||     |
  | |      |                                   ||     unexpected `)`, expecting `IS`, `IN`, `EXISTS`, `BETWEEN`, `+`, `-`, `*`, `/`, `//`, `DIV`, `%`, `||`, `<->`, `>`, `<`, `>=`, `<=`, `=`, `<>`, `!=`, `^`, `AND`, `OR`, `XOR`, `LIKE`, `NOT`, `REGEXP`, `RLIKE`, `SOUNDS`, <BitWiseOr>, <BitWiseAnd>, <BitWiseXor>, <ShiftLeft>, <ShiftRight>, `->`, `->>`, `#>`, `#>>`, `?`, `?|`, `?&`, `@>`, `<@`, `@?`, `@@`, `#-`, <Factorial>, <SquareRoot>, <BitWiseNot>, <CubeRoot>, <Abs>, `CAST`, `TRY_CAST`, `::`, `POSITION`, `IdentVariable`, `DATE_ADD`, `DATE_DIFF`, `DATE_SUB`, `DATE_TRUNC`, or 34 more ...
  | |      |                                   ||     while parsing expression
  | |      |                                   |while parsing `SELECT ...`
  | |      |                                   while parsing `(SELECT ...)`
  | |      while parsing expression
  | while parsing `SELECT ...`
 
```

### How to Reproduce?

_No response_

### Are you willing to submit PR?

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


Discussion / hints:

Fix patch:
diff --git a/src/query/service/src/interpreters/interpreter_table_analyze.rs b/src/query/service/src/interpreters/interpreter_table_analyze.rs
index e6f3867ac2c80..44ca5322cf00d 100644
--- a/src/query/service/src/interpreters/interpreter_table_analyze.rs
+++ b/src/query/service/src/interpreters/interpreter_table_analyze.rs
@@ -160,11 +160,16 @@ impl Interpreter for AnalyzeTableInterpreter {
                 )
             };
 
+            let quote = self
+                .ctx
+                .get_settings()
+                .get_sql_dialect()?
+                .default_ident_quote();
             let index_cols: Vec<(u32, String)> = schema
                 .fields()
                 .iter()
                 .filter(|f| RangeIndex::supported_type(&f.data_type().into()))
-                .map(|f| (f.column_id(), f.name.clone()))
+                .map(|f| (f.column_id(), format!("{quote}{}{quote}", f.name)))
                 .collect();
 
             // 0.01625 --> 12 buckets --> 4K size per column


Test patch:
diff --git a/tests/sqllogictests/suites/base/09_fuse_engine/09_0020_analyze.test b/tests/sqllogictests/suites/base/09_fuse_engine/09_0020_analyze.test
index 5ca45ff06c3de..73188c3027314 100644
--- a/tests/sqllogictests/suites/base/09_fuse_engine/09_0020_analyze.test
+++ b/tests/sqllogictests/suites/base/09_fuse_engine/09_0020_analyze.test
@@ -7,6 +7,23 @@ CREATE DATABASE db_09_0020
 statement ok
 USE db_09_0020
 
+statement ok
+create or replace table t_17129(`offset` varchar);
+
+statement ok
+insert into t_17129 values('ttt');
+
+statement ok
+analyze table t_17129;
+
+query TI
+select column_name, distinct_count from fuse_statistic('db_09_0020','t_17129');
+----
+offset 1
+
+statement ok
+drop table t_17129;
+
 statement ok
 create table t(a uint64)