Skip to content

Commit a7d7763

Browse files
andygroveclaude
andauthored
Refactor: replace more dialect_of! checks with Dialect trait methods (apache#2175)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 4305dd4 commit a7d7763

File tree

7 files changed

+297
-29
lines changed

7 files changed

+297
-29
lines changed

src/dialect/bigquery.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,9 @@ impl Dialect for BigQueryDialect {
156156
fn supports_create_table_multi_schema_info_sources(&self) -> bool {
157157
true
158158
}
159+
160+
/// See <https://cloud.google.com/bigquery/docs/reference/standard-sql/query-syntax#select_replace>
161+
fn supports_select_wildcard_replace(&self) -> bool {
162+
true
163+
}
159164
}

src/dialect/clickhouse.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,44 @@ impl Dialect for ClickHouseDialect {
100100
fn supports_nested_comments(&self) -> bool {
101101
true
102102
}
103+
104+
/// See <https://clickhouse.com/docs/en/sql-reference/statements/optimize>
105+
fn supports_optimize_table(&self) -> bool {
106+
true
107+
}
108+
109+
/// See <https://clickhouse.com/docs/en/sql-reference/statements/select/prewhere>
110+
fn supports_prewhere(&self) -> bool {
111+
true
112+
}
113+
114+
/// See <https://clickhouse.com/docs/en/sql-reference/statements/select/order-by#order-by-expr-with-fill-modifier>
115+
fn supports_with_fill(&self) -> bool {
116+
true
117+
}
118+
119+
/// See <https://clickhouse.com/docs/en/sql-reference/statements/select/limit-by>
120+
fn supports_limit_by(&self) -> bool {
121+
true
122+
}
123+
124+
/// See <https://clickhouse.com/docs/en/sql-reference/statements/select/order-by#order-by-expr-with-fill-modifier>
125+
fn supports_interpolate(&self) -> bool {
126+
true
127+
}
128+
129+
/// See <https://clickhouse.com/docs/en/sql-reference/statements/select#settings-in-select-query>
130+
fn supports_settings(&self) -> bool {
131+
true
132+
}
133+
134+
/// See <https://clickhouse.com/docs/en/sql-reference/statements/select/format>
135+
fn supports_select_format(&self) -> bool {
136+
true
137+
}
138+
139+
/// See <https://clickhouse.com/docs/sql-reference/statements/select#replace>
140+
fn supports_select_wildcard_replace(&self) -> bool {
141+
true
142+
}
103143
}

src/dialect/duckdb.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,19 @@ impl Dialect for DuckDbDialect {
113113
fn supports_notnull_operator(&self) -> bool {
114114
true
115115
}
116+
117+
/// See <https://duckdb.org/docs/extensions/overview>
118+
fn supports_install(&self) -> bool {
119+
true
120+
}
121+
122+
/// See <https://duckdb.org/docs/sql/statements/attach#detach-syntax>
123+
fn supports_detach(&self) -> bool {
124+
true
125+
}
126+
127+
/// See <https://duckdb.org/docs/sql/query_syntax/select#replace-clause>
128+
fn supports_select_wildcard_replace(&self) -> bool {
129+
true
130+
}
116131
}

src/dialect/generic.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,4 +223,52 @@ impl Dialect for GenericDialect {
223223
fn supports_lambda_functions(&self) -> bool {
224224
true
225225
}
226+
227+
fn supports_select_wildcard_replace(&self) -> bool {
228+
true
229+
}
230+
231+
fn supports_select_wildcard_ilike(&self) -> bool {
232+
true
233+
}
234+
235+
fn supports_select_wildcard_rename(&self) -> bool {
236+
true
237+
}
238+
239+
fn supports_optimize_table(&self) -> bool {
240+
true
241+
}
242+
243+
fn supports_install(&self) -> bool {
244+
true
245+
}
246+
247+
fn supports_detach(&self) -> bool {
248+
true
249+
}
250+
251+
fn supports_prewhere(&self) -> bool {
252+
true
253+
}
254+
255+
fn supports_with_fill(&self) -> bool {
256+
true
257+
}
258+
259+
fn supports_limit_by(&self) -> bool {
260+
true
261+
}
262+
263+
fn supports_interpolate(&self) -> bool {
264+
true
265+
}
266+
267+
fn supports_settings(&self) -> bool {
268+
true
269+
}
270+
271+
fn supports_select_format(&self) -> bool {
272+
true
273+
}
226274
}

src/dialect/mod.rs

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,6 +1332,159 @@ pub trait Dialect: Debug + Any {
13321332
fn supports_binary_kw_as_cast(&self) -> bool {
13331333
false
13341334
}
1335+
1336+
/// Returns true if this dialect supports the `REPLACE` option in a
1337+
/// `SELECT *` wildcard expression.
1338+
///
1339+
/// Example:
1340+
/// ```sql
1341+
/// SELECT * REPLACE (col1 AS col1_alias) FROM table;
1342+
/// ```
1343+
///
1344+
/// [BigQuery](https://cloud.google.com/bigquery/docs/reference/standard-sql/query-syntax#select_replace)
1345+
/// [ClickHouse](https://clickhouse.com/docs/sql-reference/statements/select#replace)
1346+
/// [DuckDB](https://duckdb.org/docs/sql/query_syntax/select#replace-clause)
1347+
/// [Snowflake](https://docs.snowflake.com/en/sql-reference/sql/select#parameters)
1348+
fn supports_select_wildcard_replace(&self) -> bool {
1349+
false
1350+
}
1351+
1352+
/// Returns true if this dialect supports the `ILIKE` option in a
1353+
/// `SELECT *` wildcard expression.
1354+
///
1355+
/// Example:
1356+
/// ```sql
1357+
/// SELECT * ILIKE '%pattern%' FROM table;
1358+
/// ```
1359+
///
1360+
/// [Snowflake](https://docs.snowflake.com/en/sql-reference/sql/select#parameters)
1361+
fn supports_select_wildcard_ilike(&self) -> bool {
1362+
false
1363+
}
1364+
1365+
/// Returns true if this dialect supports the `RENAME` option in a
1366+
/// `SELECT *` wildcard expression.
1367+
///
1368+
/// Example:
1369+
/// ```sql
1370+
/// SELECT * RENAME col1 AS col1_alias FROM table;
1371+
/// ```
1372+
///
1373+
/// [Snowflake](https://docs.snowflake.com/en/sql-reference/sql/select#parameters)
1374+
fn supports_select_wildcard_rename(&self) -> bool {
1375+
false
1376+
}
1377+
1378+
/// Returns true if this dialect supports the `OPTIMIZE TABLE` statement.
1379+
///
1380+
/// Example:
1381+
/// ```sql
1382+
/// OPTIMIZE TABLE table_name;
1383+
/// ```
1384+
///
1385+
/// [ClickHouse](https://clickhouse.com/docs/en/sql-reference/statements/optimize)
1386+
fn supports_optimize_table(&self) -> bool {
1387+
false
1388+
}
1389+
1390+
/// Returns true if this dialect supports the `INSTALL` statement.
1391+
///
1392+
/// Example:
1393+
/// ```sql
1394+
/// INSTALL extension_name;
1395+
/// ```
1396+
///
1397+
/// [DuckDB](https://duckdb.org/docs/extensions/overview)
1398+
fn supports_install(&self) -> bool {
1399+
false
1400+
}
1401+
1402+
/// Returns true if this dialect supports the `DETACH` statement.
1403+
///
1404+
/// Example:
1405+
/// ```sql
1406+
/// DETACH DATABASE db_name;
1407+
/// ```
1408+
///
1409+
/// [DuckDB](https://duckdb.org/docs/sql/statements/attach#detach-syntax)
1410+
fn supports_detach(&self) -> bool {
1411+
false
1412+
}
1413+
1414+
/// Returns true if this dialect supports the `PREWHERE` clause
1415+
/// in `SELECT` statements.
1416+
///
1417+
/// Example:
1418+
/// ```sql
1419+
/// SELECT * FROM table PREWHERE col > 0 WHERE col < 100;
1420+
/// ```
1421+
///
1422+
/// [ClickHouse](https://clickhouse.com/docs/en/sql-reference/statements/select/prewhere)
1423+
fn supports_prewhere(&self) -> bool {
1424+
false
1425+
}
1426+
1427+
/// Returns true if this dialect supports the `WITH FILL` clause
1428+
/// in `ORDER BY` expressions.
1429+
///
1430+
/// Example:
1431+
/// ```sql
1432+
/// SELECT * FROM table ORDER BY col WITH FILL FROM 1 TO 10 STEP 1;
1433+
/// ```
1434+
///
1435+
/// [ClickHouse](https://clickhouse.com/docs/en/sql-reference/statements/select/order-by#order-by-expr-with-fill-modifier)
1436+
fn supports_with_fill(&self) -> bool {
1437+
false
1438+
}
1439+
1440+
/// Returns true if this dialect supports the `LIMIT BY` clause.
1441+
///
1442+
/// Example:
1443+
/// ```sql
1444+
/// SELECT * FROM table LIMIT 10 BY col;
1445+
/// ```
1446+
///
1447+
/// [ClickHouse](https://clickhouse.com/docs/en/sql-reference/statements/select/limit-by)
1448+
fn supports_limit_by(&self) -> bool {
1449+
false
1450+
}
1451+
1452+
/// Returns true if this dialect supports the `INTERPOLATE` clause
1453+
/// in `ORDER BY` expressions.
1454+
///
1455+
/// Example:
1456+
/// ```sql
1457+
/// SELECT * FROM table ORDER BY col WITH FILL INTERPOLATE (col2 AS col2 + 1);
1458+
/// ```
1459+
///
1460+
/// [ClickHouse](https://clickhouse.com/docs/en/sql-reference/statements/select/order-by#order-by-expr-with-fill-modifier)
1461+
fn supports_interpolate(&self) -> bool {
1462+
false
1463+
}
1464+
1465+
/// Returns true if this dialect supports the `SETTINGS` clause.
1466+
///
1467+
/// Example:
1468+
/// ```sql
1469+
/// SELECT * FROM table SETTINGS max_threads = 4;
1470+
/// ```
1471+
///
1472+
/// [ClickHouse](https://clickhouse.com/docs/en/sql-reference/statements/select#settings-in-select-query)
1473+
fn supports_settings(&self) -> bool {
1474+
false
1475+
}
1476+
1477+
/// Returns true if this dialect supports the `FORMAT` clause in `SELECT` statements.
1478+
///
1479+
/// Example:
1480+
/// ```sql
1481+
/// SELECT * FROM table FORMAT JSON;
1482+
/// ```
1483+
///
1484+
/// [ClickHouse](https://clickhouse.com/docs/en/sql-reference/statements/select/format)
1485+
fn supports_select_format(&self) -> bool {
1486+
false
1487+
}
13351488
}
13361489

13371490
/// Operators for which precedence must be defined.

src/dialect/snowflake.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,21 @@ impl Dialect for SnowflakeDialect {
616616
fn supports_semantic_view_table_factor(&self) -> bool {
617617
true
618618
}
619+
620+
/// See <https://docs.snowflake.com/en/sql-reference/sql/select#parameters>
621+
fn supports_select_wildcard_replace(&self) -> bool {
622+
true
623+
}
624+
625+
/// See <https://docs.snowflake.com/en/sql-reference/sql/select#parameters>
626+
fn supports_select_wildcard_ilike(&self) -> bool {
627+
true
628+
}
629+
630+
/// See <https://docs.snowflake.com/en/sql-reference/sql/select#parameters>
631+
fn supports_select_wildcard_rename(&self) -> bool {
632+
true
633+
}
619634
}
620635

621636
// Peeks ahead to identify tokens that are expected after

0 commit comments

Comments
 (0)