@@ -85,14 +85,14 @@ private String doUnParse(
85
85
* Function syntax for functions without parenthesis (e.g., CURRENT_DATE, LOCALTIMESTAMP,
86
86
* LOCALTIME, CURRENT_TIMESTAMP, CURRENT_TIME).
87
87
*/
88
- SqlCallSyntax NO_PARENTHESIS = (sqlName , operands , context ) -> sqlName ;
88
+ SqlCallSyntax NO_PARENTHESIS = (sqlName , operands , sqlFactory ) -> sqlName ;
89
89
90
90
/**
91
91
* Function syntax for handling DISTINCT aggregates. Special case. It does not have a syntax
92
92
* itself, but modifies the syntax of the nested call.
93
93
*/
94
94
SqlCallSyntax DISTINCT =
95
- (sqlName , operands , context ) -> {
95
+ (sqlName , operands , sqlFactory ) -> {
96
96
final CallExpression callExpression = (CallExpression ) operands .get (0 );
97
97
if (callExpression .getFunctionDefinition () instanceof BuiltInFunctionDefinition ) {
98
98
final BuiltInFunctionDefinition builtinDefinition =
@@ -102,40 +102,40 @@ private String doUnParse(
102
102
.unparseDistinct (
103
103
builtinDefinition .getSqlName (),
104
104
callExpression .getResolvedChildren (),
105
- context );
105
+ sqlFactory );
106
106
} else {
107
107
return SqlCallSyntax .FUNCTION .unparseDistinct (
108
108
callExpression .getFunctionName (),
109
109
callExpression .getResolvedChildren (),
110
- context );
110
+ sqlFactory );
111
111
}
112
112
};
113
113
114
114
/** Function syntax for collection ctors, such as ARRAY[1, 2, 3] or MAP['a', 1, 'b', 2]. */
115
115
SqlCallSyntax COLLECTION_CTOR =
116
- (sqlName , operands , context ) ->
116
+ (sqlName , operands , sqlFactory ) ->
117
117
String .format (
118
118
"%s[%s]" ,
119
119
sqlName ,
120
120
operands .stream ()
121
121
.map (
122
122
resolvedExpression ->
123
123
resolvedExpression .asSerializableString (
124
- context ))
124
+ sqlFactory ))
125
125
.collect (Collectors .joining (", " )));
126
126
127
127
/** Binary operator syntax, as in "x - y". */
128
128
SqlCallSyntax BINARY_OP =
129
- (sqlName , operands , context ) ->
129
+ (sqlName , operands , sqlFactory ) ->
130
130
String .format (
131
131
"%s %s %s" ,
132
- CallSyntaxUtils .asSerializableOperand (operands .get (0 ), context ),
132
+ CallSyntaxUtils .asSerializableOperand (operands .get (0 ), sqlFactory ),
133
133
sqlName ,
134
- CallSyntaxUtils .asSerializableOperand (operands .get (1 ), context ));
134
+ CallSyntaxUtils .asSerializableOperand (operands .get (1 ), sqlFactory ));
135
135
136
136
/** Syntax for unparsing '+', Special handling for a plus on string arguments. */
137
137
SqlCallSyntax PLUS_OP =
138
- (sqlName , operands , context ) -> {
138
+ (sqlName , operands , sqlFactory ) -> {
139
139
boolean isString =
140
140
operands .stream ()
141
141
.anyMatch (
@@ -145,9 +145,9 @@ private String doUnParse(
145
145
.is (LogicalTypeFamily .CHARACTER_STRING ));
146
146
if (isString ) {
147
147
return FUNCTION .unparse (
148
- BuiltInFunctionDefinitions .CONCAT .getSqlName (), operands , context );
148
+ BuiltInFunctionDefinitions .CONCAT .getSqlName (), operands , sqlFactory );
149
149
} else {
150
- return BINARY_OP .unparse (sqlName , operands , context );
150
+ return BINARY_OP .unparse (sqlName , operands , sqlFactory );
151
151
}
152
152
};
153
153
@@ -156,60 +156,60 @@ private String doUnParse(
156
156
* AND w".
157
157
*/
158
158
SqlCallSyntax MULTIPLE_BINARY_OP =
159
- (sqlName , operands , context ) ->
159
+ (sqlName , operands , sqlFactory ) ->
160
160
operands .stream ()
161
161
.map (
162
162
expression ->
163
163
CallSyntaxUtils .asSerializableOperand (
164
- expression , context ))
164
+ expression , sqlFactory ))
165
165
.collect (Collectors .joining (String .format (" %s " , sqlName )));
166
166
167
167
/** Postfix unary operator syntax, as in "x ++". */
168
168
SqlCallSyntax UNARY_SUFFIX_OP =
169
- (sqlName , operands , context ) ->
169
+ (sqlName , operands , sqlFactory ) ->
170
170
String .format (
171
171
"%s %s" ,
172
- CallSyntaxUtils .asSerializableOperand (operands .get (0 ), context ),
172
+ CallSyntaxUtils .asSerializableOperand (operands .get (0 ), sqlFactory ),
173
173
sqlName );
174
174
175
175
/** Prefix unary operator syntax, as in "- x". */
176
176
SqlCallSyntax UNARY_PREFIX_OP =
177
- (sqlName , operands , context ) ->
177
+ (sqlName , operands , sqlFactory ) ->
178
178
String .format (
179
179
"%s %s" ,
180
180
sqlName ,
181
- CallSyntaxUtils .asSerializableOperand (operands .get (0 ), context ));
181
+ CallSyntaxUtils .asSerializableOperand (operands .get (0 ), sqlFactory ));
182
182
183
183
/**
184
184
* Special sql syntax for CAST operators (CAST, TRY_CAST, REINTERPRET_CAST).
185
185
*
186
186
* <p>Example: CAST(123 AS STRING)
187
187
*/
188
188
SqlCallSyntax CAST =
189
- (sqlName , operands , context ) ->
189
+ (sqlName , operands , sqlFactory ) ->
190
190
String .format (
191
191
"%s(%s AS %s)" ,
192
192
sqlName ,
193
- operands .get (0 ).asSerializableString (context ),
194
- operands .get (1 ).asSerializableString (context ));
193
+ operands .get (0 ).asSerializableString (sqlFactory ),
194
+ operands .get (1 ).asSerializableString (sqlFactory ));
195
195
196
196
/**
197
197
* Special sql syntax for SUBSTRING operators (SUBSTRING, SUBSTR).
198
198
*
199
199
* <p>Example: SUBSTR('abc' FROM 'abcdef' FOR 3)
200
200
*/
201
201
SqlCallSyntax SUBSTRING =
202
- (sqlName , operands , context ) -> {
202
+ (sqlName , operands , sqlFactory ) -> {
203
203
final String s =
204
204
String .format (
205
205
"%s(%s FROM %s" ,
206
206
sqlName ,
207
- operands .get (0 ).asSerializableString (context ),
208
- operands .get (1 ).asSerializableString (context ));
207
+ operands .get (0 ).asSerializableString (sqlFactory ),
208
+ operands .get (1 ).asSerializableString (sqlFactory ));
209
209
if (operands .size () == 3 ) {
210
210
return s
211
211
+ String .format (
212
- " FOR %s)" , operands .get (2 ).asSerializableString (context ));
212
+ " FOR %s)" , operands .get (2 ).asSerializableString (sqlFactory ));
213
213
}
214
214
215
215
return s + ")" ;
@@ -226,16 +226,16 @@ private String doUnParse(
226
226
* </ul>
227
227
*/
228
228
SqlCallSyntax FLOOR_OR_CEIL =
229
- (sqlName , operands , context ) -> {
229
+ (sqlName , operands , sqlFactory ) -> {
230
230
if (operands .size () == 1 ) {
231
231
// case for numeric floor & ceil
232
- return SqlCallSyntax .FUNCTION .unparse (sqlName , operands , context );
232
+ return SqlCallSyntax .FUNCTION .unparse (sqlName , operands , sqlFactory );
233
233
} else {
234
234
// case for flooring/ceiling to temporal units
235
235
return String .format (
236
236
"%s(%s TO %s)" ,
237
237
sqlName ,
238
- operands .get (0 ).asSerializableString (context ),
238
+ operands .get (0 ).asSerializableString (sqlFactory ),
239
239
((ValueLiteralExpression ) operands .get (1 ))
240
240
.getValueAs (TimeIntervalUnit .class )
241
241
.get ());
@@ -248,7 +248,7 @@ private String doUnParse(
248
248
* <p>Example: TRIM(BOTH ' ' FROM ' 0 ');
249
249
*/
250
250
SqlCallSyntax TRIM =
251
- (sqlName , operands , context ) -> {
251
+ (sqlName , operands , sqlFactory ) -> {
252
252
final boolean trimLeading =
253
253
((ValueLiteralExpression ) operands .get (0 )).getValueAs (Boolean .class ).get ();
254
254
final boolean trimTrailing =
@@ -268,8 +268,8 @@ private String doUnParse(
268
268
269
269
return String .format (
270
270
format ,
271
- operands .get (2 ).asSerializableString (context ),
272
- operands .get (3 ).asSerializableString (context ));
271
+ operands .get (2 ).asSerializableString (sqlFactory ),
272
+ operands .get (3 ).asSerializableString (sqlFactory ));
273
273
};
274
274
275
275
/**
@@ -278,27 +278,27 @@ private String doUnParse(
278
278
* <p>Example: OVERLAY('abcd' PLACING 'def' FROM 3 FOR 2)
279
279
*/
280
280
SqlCallSyntax OVERLAY =
281
- (sqlName , operands , context ) -> {
281
+ (sqlName , operands , sqlFactory ) -> {
282
282
final String s =
283
283
String .format (
284
284
"OVERLAY(%s PLACING %s FROM %s" ,
285
- operands .get (0 ).asSerializableString (context ),
286
- operands .get (1 ).asSerializableString (context ),
287
- operands .get (2 ).asSerializableString (context ));
285
+ operands .get (0 ).asSerializableString (sqlFactory ),
286
+ operands .get (1 ).asSerializableString (sqlFactory ),
287
+ operands .get (2 ).asSerializableString (sqlFactory ));
288
288
289
289
// optional length
290
290
if (operands .size () == 4 ) {
291
291
return s
292
292
+ String .format (
293
- " FOR %s)" , operands .get (3 ).asSerializableString (context ));
293
+ " FOR %s)" , operands .get (3 ).asSerializableString (sqlFactory ));
294
294
}
295
295
296
296
return s + ")" ;
297
297
};
298
298
299
299
/** Special sql syntax for AS. The string literal is formatted as an identifier. */
300
300
SqlCallSyntax AS =
301
- (sqlName , operands , context ) -> {
301
+ (sqlName , operands , sqlFactory ) -> {
302
302
if (operands .size () != 2 ) {
303
303
throw new TableException (
304
304
"The AS function with multiple aliases is not SQL"
@@ -308,63 +308,64 @@ private String doUnParse(
308
308
final String identifier = ExpressionUtils .stringValue (operands .get (1 ));
309
309
return String .format (
310
310
"%s %s %s" ,
311
- CallSyntaxUtils .asSerializableOperand (operands .get (0 ), context ),
311
+ CallSyntaxUtils .asSerializableOperand (operands .get (0 ), sqlFactory ),
312
312
sqlName ,
313
313
EncodingUtils .escapeIdentifier (identifier ));
314
314
};
315
315
316
316
/** Call syntax for {@link BuiltInFunctionDefinitions#IN}. */
317
317
SqlCallSyntax IN =
318
- (sqlName , operands , context ) ->
318
+ (sqlName , operands , sqlFactory ) ->
319
319
String .format (
320
320
"%s IN (%s)" ,
321
- operands .get (0 ).asSerializableString (context ),
321
+ operands .get (0 ).asSerializableString (sqlFactory ),
322
322
operands .subList (1 , operands .size ()).stream ()
323
323
.map (
324
324
resolvedExpression ->
325
325
resolvedExpression .asSerializableString (
326
- context ))
326
+ sqlFactory ))
327
327
.collect (Collectors .joining (", " )));
328
328
329
- SqlCallSyntax WINDOW_START_END = (sqlName , operands , context ) -> String .format ("%s" , sqlName );
329
+ SqlCallSyntax WINDOW_START_END =
330
+ (sqlName , operands , sqlFactory ) -> String .format ("%s" , sqlName );
330
331
331
332
/**
332
333
* Special sql syntax for LIKE.
333
334
*
334
335
* <p>Example: 'TE_ST' LIKE '%E&_S%' ESCAPE '&';
335
336
*/
336
337
SqlCallSyntax LIKE =
337
- (sqlName , operands , context ) -> {
338
+ (sqlName , operands , sqlFactory ) -> {
338
339
if (operands .size () == 2 ) {
339
340
return String .format (
340
341
"%s %s %s" ,
341
- CallSyntaxUtils .asSerializableOperand (operands .get (0 ), context ),
342
+ CallSyntaxUtils .asSerializableOperand (operands .get (0 ), sqlFactory ),
342
343
sqlName ,
343
- CallSyntaxUtils .asSerializableOperand (operands .get (1 ), context ));
344
+ CallSyntaxUtils .asSerializableOperand (operands .get (1 ), sqlFactory ));
344
345
} else {
345
346
return String .format (
346
347
"%s %s %s ESCAPE %s" ,
347
- CallSyntaxUtils .asSerializableOperand (operands .get (0 ), context ),
348
+ CallSyntaxUtils .asSerializableOperand (operands .get (0 ), sqlFactory ),
348
349
sqlName ,
349
- CallSyntaxUtils .asSerializableOperand (operands .get (1 ), context ),
350
- CallSyntaxUtils .asSerializableOperand (operands .get (2 ), context ));
350
+ CallSyntaxUtils .asSerializableOperand (operands .get (1 ), sqlFactory ),
351
+ CallSyntaxUtils .asSerializableOperand (operands .get (2 ), sqlFactory ));
351
352
}
352
353
};
353
354
354
355
SqlCallSyntax OVER =
355
- ((sqlName , operands , context ) -> {
356
- String projection = operands .get (0 ).asSerializableString (context );
357
- String order = operands .get (1 ).asSerializableString (context );
356
+ ((sqlName , operands , sqlFactory ) -> {
357
+ String projection = operands .get (0 ).asSerializableString (sqlFactory );
358
+ String order = operands .get (1 ).asSerializableString (sqlFactory );
358
359
String rangeBounds =
359
360
CallSyntaxUtils .overRangeToSerializableString (
360
- operands .get (2 ), operands .get (3 ), context );
361
+ operands .get (2 ), operands .get (3 ), sqlFactory );
361
362
if (operands .size () == 4 ) {
362
363
return String .format ("%s OVER(ORDER BY %s%s)" , projection , order , rangeBounds );
363
364
} else {
364
365
return String .format (
365
366
"%s OVER(PARTITION BY %s ORDER BY %s%s)" ,
366
367
projection ,
367
- CallSyntaxUtils .asSerializableOperand (operands .get (4 ), context ),
368
+ CallSyntaxUtils .asSerializableOperand (operands .get (4 ), sqlFactory ),
368
369
order ,
369
370
rangeBounds );
370
371
}
0 commit comments