@@ -21,7 +21,6 @@ namespace DB::ErrorCodes
21
21
{
22
22
extern const int SYNTAX_ERROR;
23
23
}
24
-
25
24
namespace DB
26
25
{
27
26
@@ -59,18 +58,18 @@ bool DatetimeAdd::convertImpl(String & out, IParser::Pos & pos)
59
58
String period = getConvertedArgument (fn_name, pos);
60
59
// remove quotes from period.
61
60
trim (period);
62
- if ( period.front () == ' \" ' || period.front () == ' \' ' )
61
+ if (period.front () == ' \" ' || period.front () == ' \' ' )
63
62
{
64
63
// period.remove
65
- period.erase ( 0 , 1 ); // erase the first quote
66
- period.erase ( period.size () - 1 ); // erase the last quote
64
+ period.erase ( 0 , 1 ); // erase the first quote
65
+ period.erase ( period.size () - 1 ); // erase the last quote
67
66
}
68
67
++pos;
69
68
const String offset = getConvertedArgument (fn_name, pos);
70
69
++pos;
71
70
const String datetime = getConvertedArgument (fn_name, pos);
72
71
73
- out = std::format (" date_add({}, {}, {} )" ,period,offset,datetime);
72
+ out = std::format (" date_add({}, {}, {})" ,period,offset,datetime);
74
73
75
74
return true ;
76
75
@@ -85,10 +84,10 @@ bool DatetimePart::convertImpl(String & out, IParser::Pos & pos)
85
84
++pos;
86
85
String part = Poco::toUpper (getConvertedArgument (fn_name, pos));
87
86
trim (part);
88
- if (part.front () == ' \" ' || part.front () == ' \' ' )
87
+ if (part.front () == ' \" ' || part.front () == ' \' ' )
89
88
{
90
89
// period.remove
91
- part.erase ( 0 , 1 ); // erase the first quote
90
+ part.erase ( 0 , 1 ); // erase the first quote
92
91
part.erase ( part.size () - 1 ); // erase the last quote
93
92
}
94
93
String date;
@@ -99,9 +98,9 @@ bool DatetimePart::convertImpl(String & out, IParser::Pos & pos)
99
98
}
100
99
String format;
101
100
102
- if (part == " YEAR" )
101
+ if (part == " YEAR" )
103
102
format = " %G" ;
104
- else if (part == " QUARTER" )
103
+ else if (part == " QUARTER" )
105
104
format = " %Q" ;
106
105
else if (part == " MONTH" )
107
106
format = " %m" ;
@@ -118,10 +117,9 @@ bool DatetimePart::convertImpl(String & out, IParser::Pos & pos)
118
117
else if (part == " SECOND" )
119
118
format = " %S" ;
120
119
else
121
- throw Exception (" Unexpected argument " + part + " for " + fn_name, ErrorCodes::SYNTAX_ERROR);
122
-
123
- out = std::format (" formatDateTime({}, '{}' )" , date, format);
120
+ throw Exception (" Unexpected argument " + part + " for " + fn_name, ErrorCodes::SYNTAX_ERROR);
124
121
122
+ out = std::format (" formatDateTime({}, '{}')" , date, format);
125
123
return true ;
126
124
}
127
125
@@ -140,9 +138,7 @@ bool DatetimeDiff::convertImpl(String & out, IParser::Pos & pos)
140
138
arguments = arguments + getConvertedArgument (fn_name, pos);
141
139
142
140
out = std::format (" DateDiff({}) * -1" ,arguments);
143
-
144
141
return true ;
145
-
146
142
}
147
143
148
144
bool DayOfMonth::convertImpl (String & out, IParser::Pos & pos)
@@ -156,7 +152,6 @@ bool DayOfWeek::convertImpl(String & out, IParser::Pos & pos)
156
152
if (fn_name.empty ())
157
153
return false ;
158
154
++pos;
159
-
160
155
const String datetime_str = getConvertedArgument (fn_name, pos);
161
156
162
157
out = std::format (" concat((toDayOfWeek({})%7)::String , '.00:00:00')" ,datetime_str);
@@ -188,7 +183,6 @@ bool EndOfMonth::convertImpl(String & out, IParser::Pos & pos)
188
183
out = std::format (" toDateTime(toStartOfDay({}),9,'UTC') + (INTERVAL {} +1 MONTH) - (INTERVAL 1 microsecond)" , datetime_str, toString (offset));
189
184
190
185
return true ;
191
-
192
186
}
193
187
194
188
bool EndOfDay::convertImpl (String & out, IParser::Pos & pos)
@@ -231,8 +225,7 @@ bool EndOfWeek::convertImpl(String & out, IParser::Pos & pos)
231
225
}
232
226
out = std::format (" toDateTime(toStartOfDay({}),9,'UTC') + (INTERVAL {} +1 WEEK) - (INTERVAL 1 microsecond)" , datetime_str, toString (offset));
233
227
234
- return true ;
235
-
228
+ return true ;
236
229
}
237
230
238
231
bool EndOfYear::convertImpl (String & out, IParser::Pos & pos)
@@ -254,7 +247,6 @@ bool EndOfYear::convertImpl(String & out, IParser::Pos & pos)
254
247
out = std::format (" toDateTime(toStartOfDay({}),9,'UTC') + (INTERVAL {} +1 YEAR) - (INTERVAL 1 microsecond)" , datetime_str, toString (offset));
255
248
256
249
return true ;
257
-
258
250
}
259
251
260
252
bool FormatDateTime::convertImpl (String & out, IParser::Pos & pos)
@@ -270,10 +262,10 @@ bool FormatDateTime::convertImpl(String & out, IParser::Pos & pos)
270
262
trim (format);
271
263
272
264
// remove quotes and end space from format argument.
273
- if (format.front () == ' \" ' || format.front () == ' \' ' )
265
+ if (format.front () == ' \" ' || format.front () == ' \' ' )
274
266
{
275
- format.erase ( 0 , 1 ); // erase the first quote
276
- format.erase ( format.size () - 1 ); // erase the last quote
267
+ format.erase ( 0 , 1 ); // erase the first quote
268
+ format.erase ( format.size () - 1 ); // erase the last quote
277
269
}
278
270
279
271
std::vector<String> res;
@@ -297,7 +289,7 @@ bool FormatDateTime::convertImpl(String & out, IParser::Pos & pos)
297
289
// format specifier
298
290
String arg = res.back ();
299
291
300
- if (arg == " y" || arg == " yy" )
292
+ if (arg == " y" || arg == " yy" )
301
293
formatspecifier = formatspecifier + " %y" ;
302
294
else if (arg == " yyyy" )
303
295
formatspecifier = formatspecifier + " %Y" ;
@@ -325,16 +317,16 @@ bool FormatDateTime::convertImpl(String & out, IParser::Pos & pos)
325
317
i = i + arg.size ();
326
318
}
327
319
}
328
- if (decimal > 0 && formatspecifier.find (' .' )!= String::npos)
320
+ if (decimal > 0 && formatspecifier.find (' .' ) != String::npos)
329
321
{
330
322
331
323
out = std::format (" concat("
332
- " substring(toString(formatDateTime( {0} , '{1}' )),1, position(toString(formatDateTime({0},'{1}')),'.')) ,"
324
+ " substring(toString(formatDateTime( {0} , '{1}')),1, position(toString(formatDateTime({0},'{1}')),'.')) ,"
333
325
" substring(substring(toString({0}), position(toString({0}),'.')+1),1,{2}),"
334
- " substring(toString(formatDateTime( {0},'{1}')), position(toString(formatDateTime({0},'{1}')),'.')+1 ,length (toString(formatDateTime({0},'{1}'))))) " , datetime, formatspecifier,decimal);
326
+ " substring(toString(formatDateTime( {0},'{1}')), position(toString(formatDateTime({0},'{1}')),'.')+1 ,length (toString(formatDateTime({0},'{1}'))))) " , datetime, formatspecifier,decimal);
335
327
}
336
328
else
337
- out = std::format (" formatDateTime( {0},'{1}')" ,datetime, formatspecifier);
329
+ out = std::format (" formatDateTime( {0},'{1}')" ,datetime, formatspecifier);
338
330
339
331
return true ;
340
332
}
@@ -351,10 +343,10 @@ bool FormatTimeSpan::convertImpl(String & out, IParser::Pos & pos)
351
343
size_t decimal = 0 ;
352
344
trim (format);
353
345
// remove quotes and end space from format argument.
354
- if (format.front () == ' \" ' || format.front () == ' \' ' )
346
+ if (format.front () == ' \" ' || format.front () == ' \' ' )
355
347
{
356
- format.erase (0 , 1 ); // erase the first quote
357
- format.erase (format.size () - 1 ); // erase the last quote
348
+ format.erase (0 , 1 ); // erase the first quote
349
+ format.erase (format.size () - 1 ); // erase the last quote
358
350
}
359
351
std::vector<String> res;
360
352
getTokens (format, res);
@@ -364,7 +356,7 @@ bool FormatTimeSpan::convertImpl(String & out, IParser::Pos & pos)
364
356
365
357
bool is_day_in_format = false ;
366
358
String day_val = std::to_string (std::stoi (datetime) / 86400 );
367
- bool is_hour_zero = std::stoi (datetime)% 86400 >3600 ? false : true ;
359
+ bool is_hour_zero = std::stoi (datetime) % 86400 > 3600 ? false : true ;
368
360
369
361
while (i < format.size ())
370
362
{
@@ -416,9 +408,9 @@ bool FormatTimeSpan::convertImpl(String & out, IParser::Pos & pos)
416
408
if (decimal > 0 )
417
409
{
418
410
if (format.substr (format.length ()- decimal -1 , 1 ) == last_delim)
419
- out = std::format (" concat(substring(toString(formatDateTime( toDateTime64({0},9,'UTC') ,'{1}')),1, length(toString(formatDateTime( toDateTime64({0},9,'UTC'),'{1}'))) - position( reverse(toString(formatDateTime(toDateTime64({0},9,'UTC'),'{1}'))),'{3}')+1),substring(SUBSTRING(toString(toDateTime64({0},9,'UTC')),position(toString(toDateTime64({0},9,'UTC')),'.')+1),1,{2}))" , datetime,formatspecifier,decimal,last_delim);
411
+ out = std::format (" concat(substring(toString(formatDateTime( toDateTime64({0},9,'UTC') ,'{1}')),1, length(toString(formatDateTime( toDateTime64({0},9,'UTC'),'{1}'))) - position( reverse(toString(formatDateTime(toDateTime64({0},9,'UTC'),'{1}'))),'{3}')+1),substring(SUBSTRING(toString(toDateTime64({0},9,'UTC')),position(toString(toDateTime64({0},9,'UTC')),'.')+1),1,{2}))" , datetime, formatspecifier, decimal, last_delim);
420
412
else
421
- out = std::format (" concat(substring(toString(formatDateTime( toDateTime64({0},9,'UTC') ,'{1}')),1, length(toString(formatDateTime( toDateTime64({0},9,'UTC'),'{1}'))) - position( reverse(toString(formatDateTime(toDateTime64({0},9,'UTC'),'{1}'))),'{3}')),substring(SUBSTRING(toString(toDateTime64({0},9,'UTC')),position(toString(toDateTime64({0},9,'UTC')),'.')+1),1,{2}))" , datetime,formatspecifier,decimal,last_delim);
413
+ out = std::format (" concat(substring(toString(formatDateTime( toDateTime64({0},9,'UTC') ,'{1}')),1, length(toString(formatDateTime( toDateTime64({0},9,'UTC'),'{1}'))) - position( reverse(toString(formatDateTime(toDateTime64({0},9,'UTC'),'{1}'))),'{3}')),substring(SUBSTRING(toString(toDateTime64({0},9,'UTC')),position(toString(toDateTime64({0},9,'UTC')),'.')+1),1,{2}))" , datetime, formatspecifier, decimal, last_delim);
422
414
}
423
415
else
424
416
out = std::format (" formatDateTime(toDateTime64({0},9,'UTC'),'{1}')" , datetime,formatspecifier);
@@ -428,9 +420,9 @@ bool FormatTimeSpan::convertImpl(String & out, IParser::Pos & pos)
428
420
if (decimal > 0 )
429
421
{
430
422
if (format.substr (format.length ()- decimal - 1 , 1 ) == last_delim)
431
- out = std::format (" concat( leftPad('{5}' , {3} ,'0'),substring(toString(formatDateTime( toDateTime64({0},9,'UTC'),'{1}')),1, length(toString(formatDateTime( toDateTime64({0},9,'UTC'),'{1}'))) - position( reverse(toString(formatDateTime(toDateTime64({0},9,'UTC'),'{1}'))),'{4}') +1),substring(SUBSTRING(toString(toDateTime64({0},9,'UTC')),position(toString(toDateTime64({0},9,'UTC')),'.')+1),1,{2}))" , datetime,formatspecifier,decimal,pad,last_delim,day_val);
423
+ out = std::format (" concat( leftPad('{5}' , {3} ,'0'),substring(toString(formatDateTime( toDateTime64({0},9,'UTC'),'{1}')),1, length(toString(formatDateTime( toDateTime64({0},9,'UTC'),'{1}'))) - position( reverse(toString(formatDateTime(toDateTime64({0},9,'UTC'),'{1}'))),'{4}') +1),substring(SUBSTRING(toString(toDateTime64({0},9,'UTC')),position(toString(toDateTime64({0},9,'UTC')),'.')+1),1,{2}))" , datetime, formatspecifier, decimal,pad, last_delim, day_val);
432
424
else
433
- out = std::format (" concat( leftPad('{5}' , {3} ,'0') ,substring(toString(formatDateTime( toDateTime64({0},9,'UTC'),'{1}')),1, length(toString(formatDateTime( toDateTime64({0},9,'UTC'),'{1}'))) - position( reverse(toString(formatDateTime(toDateTime64({0},9,'UTC'),'{1}'))),'{4}')),substring(SUBSTRING(toString(toDateTime64({0},9,'UTC')),position(toString(toDateTime64({0},9,'UTC')),'.')+1),1,{2}),substring(toString(formatDateTime(toDateTime64({0},9,'UTC'),'{1}')),position( toString(formatDateTime( toDateTime64({0},9,'UTC'),'{1}')),'{4}'),length(toString(formatDateTime( toDateTime64({0},9,'UTC'),'{1}')))))" , datetime,formatspecifier,decimal,pad,last_delim,day_val);
425
+ out = std::format (" concat( leftPad('{5}' , {3} ,'0') ,substring(toString(formatDateTime( toDateTime64({0},9,'UTC'),'{1}')),1, length(toString(formatDateTime( toDateTime64({0},9,'UTC'),'{1}'))) - position( reverse(toString(formatDateTime(toDateTime64({0},9,'UTC'),'{1}'))),'{4}')),substring(SUBSTRING(toString(toDateTime64({0},9,'UTC')),position(toString(toDateTime64({0},9,'UTC')),'.')+1),1,{2}),substring(toString(formatDateTime(toDateTime64({0},9,'UTC'),'{1}')),position( toString(formatDateTime( toDateTime64({0},9,'UTC'),'{1}')),'{4}'),length(toString(formatDateTime( toDateTime64({0},9,'UTC'),'{1}')))))" , datetime, formatspecifier, decimal, pad, last_delim, day_val);
434
426
}
435
427
else if (decimal == 0 )
436
428
out = std::format (" concat( leftPad('{3}' , {2} ,'0'),toString(formatDateTime(toDateTime64({0},9,'UTC') ,'{1}')))" , datetime,formatspecifier,pad,day_val);
@@ -478,7 +470,7 @@ bool MakeTimeSpan::convertImpl(String & out, IParser::Pos & pos)
478
470
}
479
471
480
472
if (arg_count < 2 || arg_count > 4 )
481
- throw Exception (" argument count out of bound in function: " + fn_name, ErrorCodes::SYNTAX_ERROR);
473
+ throw Exception (" argument count out of bound in function: " + fn_name, ErrorCodes::SYNTAX_ERROR);
482
474
483
475
if (arg_count == 2 )
484
476
{
@@ -512,17 +504,15 @@ bool MakeTimeSpan::convertImpl(String & out, IParser::Pos & pos)
512
504
513
505
datetime_str = hour + " :" + minute + " :" + second;
514
506
day = day + " ." ;
515
-
516
507
}
517
508
else
518
- throw Exception (" argument count out of bound in function: " + fn_name, ErrorCodes::SYNTAX_ERROR);
509
+ throw Exception (" argument count out of bound in function: " + fn_name, ErrorCodes::SYNTAX_ERROR);
519
510
520
511
// Add dummy yyyy-mm-dd to parse datetime in CH
521
512
datetime_str = " 0000-00-00 " + datetime_str;
522
513
523
- out = std::format (" CONCAT('{}',toString(SUBSTRING(toString(toTime(parseDateTime64BestEffortOrNull('{}', 9 ,'UTC' ))),12)))" ,day ,datetime_str );
524
-
525
- return true ;
514
+ out = std::format (" CONCAT('{}',toString(SUBSTRING(toString(toTime(parseDateTime64BestEffortOrNull('{}', 9 ,'UTC'))),12)))" ,day ,datetime_str);
515
+ return true ;
526
516
}
527
517
528
518
bool MakeDateTime::convertImpl (String & out, IParser::Pos & pos)
@@ -550,7 +540,7 @@ bool MakeDateTime::convertImpl(String & out, IParser::Pos & pos)
550
540
551
541
if (arg_count < 7 )
552
542
{
553
- for (int i = arg_count;i < 7 ; ++i)
543
+ for (int i = arg_count;i < 7 ; ++i)
554
544
arguments = arguments + " 0 ," ;
555
545
}
556
546
@@ -726,7 +716,6 @@ bool WeekOfYear::convertImpl(String & out, IParser::Pos & pos)
726
716
727
717
bool MonthOfYear::convertImpl (String & out, IParser::Pos & pos)
728
718
{
729
-
730
719
return directMapping (out, pos, " toMonth" );
731
720
}
732
721
0 commit comments