@@ -31,13 +31,6 @@ bool TimeSpan::convertImpl(String & out, IParser::Pos & pos)
31
31
out = res;
32
32
return false ;
33
33
}
34
- /*
35
- bool DateTime::convertImpl(String & out, IParser::Pos & pos)
36
- {
37
- String res = String(pos->begin, pos->end);
38
- out = res;
39
- return false;
40
- }*/
41
34
42
35
bool Ago::convertImpl (String & out, IParser::Pos & pos)
43
36
{
@@ -290,7 +283,7 @@ bool FormatDateTime::convertImpl(String & out, IParser::Pos & pos)
290
283
while (i < format.size ())
291
284
{
292
285
char c = format[i];
293
- if (!isalpha (c))
286
+ if (!isalpha (c))
294
287
{
295
288
// delimeter
296
289
if (c == ' ' || c == ' -' || c == ' _' || c == ' [' || c == ' ]' || c == ' /' || c == ' ,' || c == ' .' || c == ' :' )
@@ -304,7 +297,7 @@ bool FormatDateTime::convertImpl(String & out, IParser::Pos & pos)
304
297
// format specifier
305
298
String arg = res.back ();
306
299
307
- if (arg == " y" || arg == " yy" )
300
+ if (arg == " y" || arg == " yy" )
308
301
formatspecifier = formatspecifier + " %y" ;
309
302
else if (arg == " yyyy" )
310
303
formatspecifier = formatspecifier + " %Y" ;
@@ -341,7 +334,7 @@ bool FormatDateTime::convertImpl(String & out, IParser::Pos & pos)
341
334
" substring(toString(formatDateTime( {0},'{1}')), position(toString(formatDateTime({0},'{1}')),'.')+1 ,length (toString(formatDateTime({0},'{1}'))))) " ,datetime, formatspecifier,decimal);
342
335
}
343
336
else
344
- out = std::format (" formatDateTime( {0},'{1}')" ,datetime, formatspecifier);
337
+ out = std::format (" formatDateTime( {0},'{1}')" ,datetime, formatspecifier);
345
338
346
339
return true ;
347
340
}
@@ -355,13 +348,13 @@ bool FormatTimeSpan::convertImpl(String & out, IParser::Pos & pos)
355
348
const auto datetime = getConvertedArgument (fn_name, pos);
356
349
++pos;
357
350
auto format = getConvertedArgument (fn_name, pos);
358
- size_t decimal= 0 ;
351
+ size_t decimal = 0 ;
359
352
trim (format);
360
353
// remove quotes and end space from format argument.
361
354
if (format.front () == ' \" ' || format.front () == ' \' ' )
362
355
{
363
- format.erase ( 0 , 1 ); // erase the first quote
364
- format.erase ( format.size () - 1 ); // erase the last quote
356
+ format.erase (0 , 1 ); // erase the first quote
357
+ format.erase (format.size () - 1 ); // erase the last quote
365
358
}
366
359
std::vector<String> res;
367
360
getTokens (format, res);
@@ -370,13 +363,13 @@ bool FormatTimeSpan::convertImpl(String & out, IParser::Pos & pos)
370
363
371
364
372
365
bool is_day_in_format = false ;
373
- String day_val = std::to_string (std::stoi (datetime)/ 86400 );
366
+ String day_val = std::to_string (std::stoi (datetime) / 86400 );
374
367
bool is_hour_zero = std::stoi (datetime)%86400 >3600 ? false : true ;
375
368
376
369
while (i < format.size ())
377
370
{
378
371
char c = format[i];
379
- if (!isalpha (c))
372
+ if (!isalpha (c))
380
373
{
381
374
// delimeter
382
375
if (c == ' ' || c == ' -' || c == ' _' || c == ' [' || c == ' ]' || c == ' /' || c == ' ,' || c == ' .' || c == ' :' )
@@ -396,7 +389,7 @@ bool FormatTimeSpan::convertImpl(String & out, IParser::Pos & pos)
396
389
formatspecifier = formatspecifier + " %M" ;
397
390
else if (arg == " h" || arg == " hh" )
398
391
{
399
- if (is_hour_zero) // To handle the CH limit for 12hr format(01-12). If not handled , 1.00:00:00 returned as 1.12:00:00(in 12 hr format)
392
+ if (is_hour_zero) // To handle the CH limit for 12hr format(01-12). If not handled , 1.00:00:00 returned as 1.12:00:00(in 12 hr format)
400
393
formatspecifier = formatspecifier + " %H" ;
401
394
else
402
395
formatspecifier = formatspecifier + " %I" ;
@@ -405,7 +398,7 @@ bool FormatTimeSpan::convertImpl(String & out, IParser::Pos & pos)
405
398
formatspecifier = formatspecifier + " %H" ;
406
399
else if (arg.starts_with (' d' )) // && arg.size() >2)
407
400
{
408
- pad = std::max (arg.size (),day_val.length ());
401
+ pad = std::max (arg.size (), day_val.length ());
409
402
is_day_in_format = true ;
410
403
}
411
404
else if (arg.starts_with (' f' ) || arg.starts_with (' F' ))
@@ -416,29 +409,26 @@ bool FormatTimeSpan::convertImpl(String & out, IParser::Pos & pos)
416
409
i = i + arg.size ();
417
410
}
418
411
}
419
- auto last_delim = formatspecifier.substr (formatspecifier.length ()-1 ,formatspecifier.length ());
412
+ auto last_delim = formatspecifier.substr (formatspecifier.length ()-1 , formatspecifier.length ());
420
413
421
- if (!is_day_in_format)
414
+ if (!is_day_in_format)
422
415
{
423
- if (decimal > 0 )
416
+ if (decimal > 0 )
424
417
{
425
- if (format.substr (format.length ()- decimal -1 ,1 ) == last_delim)
426
- 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}'))),'{4}')+1),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,last_delim);
427
- else
428
- 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}'))),'{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,last_delim);
418
+ 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}'))),'{4}')+1),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,last_delim);
420
+ 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}'))),'{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,last_delim);
429
422
}
430
423
else
431
424
out = std::format (" formatDateTime(toDateTime64({0},9,'UTC'),'{1}')" , datetime,formatspecifier);
432
425
433
426
}
434
427
else
435
428
{
436
- if (decimal > 0 )
429
+ if (decimal > 0 )
437
430
{
438
- String heena = format.substr (format.length ()- decimal - 1 , 1 );
439
- if (heena == last_delim)
440
- std::cout <<" yes" ;
441
- if (format.substr (format.length ()- decimal - 1 , 1 ) == last_delim)
431
+ if (format.substr (format.length ()- decimal - 1 , 1 ) == last_delim)
442
432
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);
443
433
else
444
434
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);
@@ -491,7 +481,7 @@ bool MakeTimeSpan::convertImpl(String & out, IParser::Pos & pos)
491
481
if (arg_count < 2 || arg_count > 4 )
492
482
throw Exception (" argument count out of bound in function: " + fn_name, ErrorCodes::SYNTAX_ERROR);
493
483
494
- if (arg_count == 2 )
484
+ if (arg_count == 2 )
495
485
{
496
486
hour = args.back ();
497
487
args.pop_back ();
@@ -559,9 +549,9 @@ bool MakeDateTime::convertImpl(String & out, IParser::Pos & pos)
559
549
if (arg_count < 1 || arg_count > 7 )
560
550
throw Exception (" argument count out of bound in function: " + fn_name, ErrorCodes::SYNTAX_ERROR);
561
551
562
- if (arg_count < 7 )
552
+ if (arg_count < 7 )
563
553
{
564
- for (int i = arg_count;i < 7 ; ++i)
554
+ for (int i = arg_count;i < 7 ; ++i)
565
555
arguments = arguments + " 0 ," ;
566
556
}
567
557
@@ -714,15 +704,16 @@ bool UnixTimeSecondsToDateTime::convertImpl(String & out, IParser::Pos & pos)
714
704
return false ;
715
705
716
706
++pos;
717
- if (pos->type == TokenType::QuotedIdentifier || pos->type == TokenType::StringLiteral)
707
+ if (pos->type == TokenType::QuotedIdentifier || pos->type == TokenType::StringLiteral)
718
708
throw Exception (" String Literal is not accepted." + fn_name + " accepts only long, int and double " , ErrorCodes::BAD_ARGUMENTS);
719
709
720
- const String expression = getConvertedArgument (fn_name, pos);
710
+ String expression = getConvertedArgument (fn_name, pos);
721
711
722
- if (std::any_of (expression.begin (), expression.end (), ::isalpha))
712
+ if (std::any_of (expression.begin (), expression.end (), ::isalpha))
723
713
throw Exception (" String Literal is not accepted." + fn_name + " accepts only long, int and double " , ErrorCodes::BAD_ARGUMENTS);
724
714
725
- out = std::format (" toDateTime64({0},9,'UTC')" , expression);
715
+ std::remove (expression.begin (), expression.end (), ' ' );
716
+ out = std::format (" multiIf(toTypeName({0}) == 'String' or toTypeName({0}) == 'UUID' or toTypeName({0}) == 'DateTime64(3)' or toTypeName({0}) == 'DateTime64(6), or toTypeName({0}) == 'DateTime64(9) , 'Only Accepted arguments are float , int and double', toString(toDateTime64(abs({0}) , 9,'UTC')))" , expression);
726
717
727
718
return true ;
728
719
}
0 commit comments