Skip to content

Commit 7e200b0

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

7 files changed

Lines changed: 297 additions & 29 deletions

File tree

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

13421495
/// 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)