115
115
import static io .trino .sql .RowPatternFormatter .formatPattern ;
116
116
import static io .trino .sql .SqlFormatter .Dialect .BIGQUERY ;
117
117
import static io .trino .sql .SqlFormatter .Dialect .DEFAULT ;
118
+ import static io .trino .sql .SqlFormatter .Dialect .DUCKDB ;
118
119
import static io .trino .sql .SqlFormatter .formatName ;
119
120
import static io .trino .sql .SqlFormatter .formatSql ;
120
121
import static io .trino .sql .tree .ComparisonExpression .Operator .EQUAL ;
@@ -138,7 +139,7 @@ public static String formatExpression(Expression expression, Dialect dialect)
138
139
139
140
private static String formatIdentifier (String s , Dialect dialect )
140
141
{
141
- if (dialect == DEFAULT ) {
142
+ if (dialect == DEFAULT || dialect == DUCKDB ) {
142
143
return '"' + s .replace ("\" " , "\" \" " ) + '"' ;
143
144
}
144
145
else if (dialect == BIGQUERY ) {
@@ -288,7 +289,7 @@ protected String visitArrayConstructor(ArrayConstructor node, Void context)
288
289
protected String visitSubscriptExpression (SubscriptExpression node , Void context )
289
290
{
290
291
String subscript ;
291
- if (dialect == DEFAULT ) {
292
+ if (dialect == DEFAULT || dialect == DUCKDB ) {
292
293
subscript = formatSql (node .getIndex (), dialect );
293
294
}
294
295
else if (dialect == BIGQUERY ) {
@@ -313,12 +314,18 @@ protected String visitLongLiteral(LongLiteral node, Void context)
313
314
@ Override
314
315
protected String visitDoubleLiteral (DoubleLiteral node , Void context )
315
316
{
317
+ if (dialect == DUCKDB ) {
318
+ return String .valueOf (node .getValue ());
319
+ }
316
320
return doubleFormatter .get ().format (node .getValue ());
317
321
}
318
322
319
323
@ Override
320
324
protected String visitDecimalLiteral (DecimalLiteral node , Void context )
321
325
{
326
+ if (dialect == DUCKDB ) {
327
+ return node .getValue ();
328
+ }
322
329
// TODO return node value without "DECIMAL '..'" when FeaturesConfig#parseDecimalLiteralsAsDouble switch is removed
323
330
return "DECIMAL '" + node .getValue () + "'" ;
324
331
}
@@ -338,6 +345,9 @@ protected String visitTimeLiteral(TimeLiteral node, Void context)
338
345
@ Override
339
346
protected String visitTimestampLiteral (TimestampLiteral node , Void context )
340
347
{
348
+ if (dialect == DUCKDB ) {
349
+ return "'" + node .getValue () + "'" ;
350
+ }
341
351
return "TIMESTAMP '" + node .getValue () + "'" ;
342
352
}
343
353
@@ -612,7 +622,7 @@ protected String visitLikePredicate(LikePredicate node, Void context)
612
622
.append (" LIKE " )
613
623
.append (process (node .getPattern (), context ));
614
624
615
- if (dialect == DEFAULT ) {
625
+ if (dialect == DEFAULT || dialect == DUCKDB ) {
616
626
node .getEscape ().ifPresent (escape -> builder .append (" ESCAPE " )
617
627
.append (process (escape , context )));
618
628
}
@@ -936,7 +946,7 @@ static String formatStringLiteral(String s, Dialect dialect)
936
946
}
937
947
938
948
StringBuilder builder = new StringBuilder ();
939
- if (dialect == DEFAULT ) {
949
+ if (dialect == DEFAULT || dialect == DUCKDB ) {
940
950
builder .append ("U&" );
941
951
}
942
952
builder .append ("'" );
@@ -952,7 +962,7 @@ static String formatStringLiteral(String s, Dialect dialect)
952
962
builder .append (ch );
953
963
}
954
964
else {
955
- if (dialect == DEFAULT ) {
965
+ if (dialect == DEFAULT || dialect == DUCKDB ) {
956
966
if (codePoint <= 0xFFFF ) {
957
967
builder .append ('\\' );
958
968
builder .append (format ("%04X" , codePoint ));
0 commit comments