@@ -129,9 +129,12 @@ void ThrowOnError(const TStatus& status) {
129
129
}
130
130
131
131
bool HasCharsInString (const TString& str) {
132
- for (auto c : str) {
133
- if (std::isalpha (c)) {
134
- return true ;
132
+ for (TStringBuf q (str), line; q.ReadLine (line);) {
133
+ line = line.NextTok (" --" );
134
+ for (auto c: line) {
135
+ if (std::isalpha (c)) {
136
+ return true ;
137
+ }
135
138
}
136
139
}
137
140
return false ;
@@ -370,41 +373,105 @@ bool CompareValueImpl(const T& valResult, TStringBuf vExpected) {
370
373
return valResult == valExpected;
371
374
}
372
375
373
- bool CompareValue (const NYdb::TValue& v, TStringBuf vExpected) {
374
- const auto & vp = v.GetProto ();
375
- if (vp.has_bool_value ()) {
376
- return CompareValueImpl<bool >(vp.bool_value (), vExpected);
377
- }
378
- if (vp.has_int32_value ()) {
379
- return CompareValueImpl<i32>(vp.int32_value (), vExpected);
380
- }
381
- if (vp.has_uint32_value ()) {
382
- return CompareValueImpl<ui32>(vp.uint32_value (), vExpected);
383
- }
384
- if (vp.has_int64_value ()) {
385
- return CompareValueImpl<i64>(vp.int64_value (), vExpected);
386
- }
387
- if (vp.has_uint64_value ()) {
388
- return CompareValueImpl<ui64>(vp.uint64_value (), vExpected);
389
- }
390
- if (vp.has_float_value ()) {
391
- return CompareValueImpl<float >(vp.float_value (), vExpected);
376
+ template <class T >
377
+ bool CompareValueImplFloat (const T& valResult, TStringBuf vExpected, const double floatPrecesion) {
378
+ T valExpected;
379
+ if (!TryFromString<T>(vExpected, valExpected)) {
380
+ Cerr << " cannot parse expected as " << typeid (valResult).name () << " (" << vExpected << " )" << Endl;
381
+ return false ;
392
382
}
393
- if (vp.has_double_value ()) {
394
- return CompareValueImpl<double >(vp.double_value (), vExpected);
383
+ return valResult > (1 - floatPrecesion) * valExpected && valResult < (1 + floatPrecesion) * valExpected;
384
+ }
385
+
386
+ bool CompareValueImplDatetime (const TInstant& valResult, TStringBuf vExpected, TDuration unit) {
387
+ TInstant expected;
388
+ if (!TInstant::TryParseIso8601 (vExpected, expected)) {
389
+ i64 i;
390
+ if (!TryFromString (vExpected, i)) {
391
+ Cerr << " cannot parse expected as " << typeid (valResult).name () << " (" << vExpected << " )" << Endl;
392
+ return false ;
393
+ }
394
+ expected = TInstant::Zero () + i * unit;
395
395
}
396
- if (vp.has_text_value ()) {
397
- return CompareValueImpl<TString>(TString (vp.text_value ().data (), vp.text_value ().size ()), vExpected);
396
+ return valResult == expected;
397
+ }
398
+
399
+ template <class T >
400
+ bool CompareValueImplDatetime64 (const T& valResult, TStringBuf vExpected, TDuration unit) {
401
+ T valExpected;
402
+ if (!TryFromString<T>(vExpected, valExpected)) {
403
+ TInstant expected;
404
+ if (!TInstant::TryParseIso8601 (vExpected, expected)) {
405
+ Cerr << " cannot parse expected as " << typeid (valResult).name () << " (" << vExpected << " )" << Endl;
406
+ return false ;
407
+ }
408
+ valExpected = expected.GetValue () / unit.GetValue ();
398
409
}
399
- if (vp.has_null_flag_value ()) {
400
- return vExpected == " " ;
410
+ return valResult == valExpected;
411
+ }
412
+
413
+ bool CompareValue (const NYdb::TValue& v, TStringBuf vExpected, double floatPrecession) {
414
+ TValueParser vp (v);
415
+ TTypeParser tp (v.GetType ());
416
+ if (tp.GetKind () == TTypeParser::ETypeKind::Optional) {
417
+ if (vp.IsNull ()) {
418
+ return vExpected == " " ;
419
+ }
420
+ vp.OpenOptional ();
421
+ tp.OpenOptional ();
422
+ }
423
+ switch (tp.GetPrimitive ()) {
424
+ case EPrimitiveType::Bool:
425
+ return CompareValueImpl (vp.GetBool (), vExpected);
426
+ case EPrimitiveType::Int8:
427
+ return CompareValueImpl (vp.GetInt8 (), vExpected);
428
+ case EPrimitiveType::Uint8:
429
+ return CompareValueImpl (vp.GetUint8 (), vExpected);
430
+ case EPrimitiveType::Int16:
431
+ return CompareValueImpl (vp.GetInt16 (), vExpected);
432
+ case EPrimitiveType::Uint16:
433
+ return CompareValueImpl (vp.GetUint16 (), vExpected);
434
+ case EPrimitiveType::Int32:
435
+ return CompareValueImpl (vp.GetInt32 (), vExpected);
436
+ case EPrimitiveType::Uint32:
437
+ return CompareValueImpl (vp.GetUint32 (), vExpected);
438
+ case EPrimitiveType::Int64:
439
+ return CompareValueImpl (vp.GetInt64 (), vExpected);
440
+ case EPrimitiveType::Uint64:
441
+ return CompareValueImpl (vp.GetUint64 (), vExpected);
442
+ case EPrimitiveType::Float:
443
+ return CompareValueImplFloat (vp.GetFloat (), vExpected, floatPrecession);
444
+ case EPrimitiveType::Double:
445
+ return CompareValueImplFloat (vp.GetDouble (), vExpected, floatPrecession);
446
+ case EPrimitiveType::Date:
447
+ return CompareValueImplDatetime (vp.GetDate (), vExpected, TDuration::Days (1 ));
448
+ case EPrimitiveType::Datetime:
449
+ return CompareValueImplDatetime (vp.GetDatetime (), vExpected, TDuration::Seconds (1 ));
450
+ case EPrimitiveType::Timestamp:
451
+ return CompareValueImplDatetime (vp.GetTimestamp (), vExpected, TDuration::MicroSeconds (1 ));
452
+ case EPrimitiveType::Interval:
453
+ return CompareValueImpl (vp.GetInterval (), vExpected);
454
+ case EPrimitiveType::Date32:
455
+ return CompareValueImplDatetime64 (vp.GetDate32 (), vExpected, TDuration::Days (1 ));
456
+ case EPrimitiveType::Datetime64:
457
+ return CompareValueImplDatetime64 (vp.GetDatetime64 (), vExpected, TDuration::Seconds (1 ));
458
+ case EPrimitiveType::Timestamp64:
459
+ return CompareValueImplDatetime64 (vp.GetTimestamp64 (), vExpected, TDuration::MicroSeconds (1 ));
460
+ case EPrimitiveType::Interval64:
461
+ return CompareValueImpl (vp.GetInterval64 (), vExpected);
462
+ case EPrimitiveType::String:
463
+ return CompareValueImpl (vp.GetString (), vExpected);
464
+ case EPrimitiveType::Utf8:
465
+ return CompareValueImpl (vp.GetUtf8 (), vExpected);
466
+ default :
467
+ Cerr << " unexpected type for comparision: " << v.GetProto ().DebugString () << Endl;
468
+ return false ;
401
469
}
402
- Cerr << " unexpected type for comparision: " << vp.DebugString () << Endl;
403
- return false ;
404
470
}
405
471
406
472
407
473
bool TQueryResultInfo::IsExpected (std::string_view expected) const {
474
+ constexpr double floatPrecesion = 0.0001 ;
408
475
if (expected.empty ()) {
409
476
return true ;
410
477
}
@@ -452,7 +519,7 @@ bool TQueryResultInfo::IsExpected(std::string_view expected) const {
452
519
return false ;
453
520
}
454
521
TStringBuf cItem = splitter.Consume ();
455
- if (!CompareValue (resultValue, cItem)) {
522
+ if (!CompareValue (resultValue, cItem, floatPrecesion )) {
456
523
Cerr << " has diff: " << resultValue.GetProto ().DebugString () << " ;EXPECTED:" << cItem << Endl;
457
524
return false ;
458
525
}
0 commit comments