@@ -37,6 +37,7 @@ class TJsonQuery : public TViewerPipeClient {
37
37
Modern,
38
38
Multi,
39
39
Ydb,
40
+ Ydb2,
40
41
};
41
42
ESchemaType Schema = ESchemaType::Classic;
42
43
TRequestResponse<NKqp::TEvKqp::TEvCreateSessionResponse> CreateSessionResponse;
@@ -53,6 +54,8 @@ class TJsonQuery : public TViewerPipeClient {
53
54
return ESchemaType::Multi;
54
55
} else if (schemaStr == " ydb" ) {
55
56
return ESchemaType::Ydb;
57
+ } else if (schemaStr == " ydb2" ) {
58
+ return ESchemaType::Ydb2;
56
59
} else {
57
60
return ESchemaType::Classic;
58
61
}
@@ -394,8 +397,8 @@ class TJsonQuery : public TViewerPipeClient {
394
397
return valueParser.GetDyNumber ();
395
398
case NYdb::EPrimitiveType::Uuid:
396
399
return valueParser.GetUuid ().ToString ();
397
- default :
398
- Y_ENSURE ( false , TStringBuilder () << " Unsupported type: " << primitive); }
400
+ }
401
+ return NJson::JSON_UNDEFINED;
399
402
}
400
403
401
404
NJson::TJsonValue ColumnValueToJsonValue (NYdb::TValueParser& valueParser) {
@@ -427,6 +430,63 @@ class TJsonQuery : public TViewerPipeClient {
427
430
case NYdb::TTypeParser::ETypeKind::Decimal:
428
431
return valueParser.GetDecimal ().ToString ();
429
432
433
+ case NYdb::TTypeParser::ETypeKind::List:
434
+ {
435
+ NJson::TJsonValue jsonList;
436
+ jsonList.SetType (NJson::JSON_ARRAY);
437
+ valueParser.OpenList ();
438
+ while (valueParser.TryNextListItem ()) {
439
+ jsonList.AppendValue (ColumnValueToJsonValue (valueParser));
440
+ }
441
+ return jsonList;
442
+ }
443
+
444
+ case NYdb::TTypeParser::ETypeKind::Tuple:
445
+ {
446
+ NJson::TJsonValue jsonTuple;
447
+ jsonTuple.SetType (NJson::JSON_ARRAY);
448
+ valueParser.OpenTuple ();
449
+ while (valueParser.TryNextElement ()) {
450
+ jsonTuple.AppendValue (ColumnValueToJsonValue (valueParser));
451
+ }
452
+ return jsonTuple;
453
+ }
454
+
455
+ case NYdb::TTypeParser::ETypeKind::Struct:
456
+ {
457
+ NJson::TJsonValue jsonStruct;
458
+ jsonStruct.SetType (NJson::JSON_MAP);
459
+ valueParser.OpenStruct ();
460
+ while (valueParser.TryNextMember ()) {
461
+ jsonStruct[valueParser.GetMemberName ()] = ColumnValueToJsonValue (valueParser);
462
+ }
463
+ return jsonStruct;
464
+ }
465
+
466
+ case NYdb::TTypeParser::ETypeKind::Dict:
467
+ {
468
+ NJson::TJsonValue jsonDict;
469
+ jsonDict.SetType (NJson::JSON_MAP);
470
+ valueParser.OpenDict ();
471
+ while (valueParser.TryNextDictItem ()) {
472
+ valueParser.DictKey ();
473
+ TString key = valueParser.GetString ();
474
+ valueParser.DictPayload ();
475
+ jsonDict[key] = ColumnValueToJsonValue (valueParser);
476
+ }
477
+ return jsonDict;
478
+ }
479
+
480
+ case NYdb::TTypeParser::ETypeKind::Variant:
481
+ valueParser.OpenVariant ();
482
+ return ColumnValueToJsonValue (valueParser);
483
+
484
+ case NYdb::TTypeParser::ETypeKind::EmptyList:
485
+ return NJson::JSON_ARRAY;
486
+
487
+ case NYdb::TTypeParser::ETypeKind::EmptyDict:
488
+ return NJson::JSON_MAP;
489
+
430
490
default :
431
491
return NJson::JSON_UNDEFINED;
432
492
}
@@ -665,6 +725,37 @@ class TJsonQuery : public TViewerPipeClient {
665
725
}
666
726
}
667
727
}
728
+
729
+ if (Schema == ESchemaType::Ydb2) {
730
+ NJson::TJsonValue& jsonResults = jsonResponse[" result" ];
731
+ jsonResults.SetType (NJson::JSON_ARRAY);
732
+ for (const auto & resultSets : ResultSets) {
733
+ NJson::TJsonValue& jsonResult = jsonResults.AppendValue ({});
734
+ bool hasColumns = false ;
735
+ for (NYdb::TResultSet resultSet : resultSets) {
736
+ if (!hasColumns) {
737
+ NJson::TJsonValue& jsonColumns = jsonResult[" columns" ];
738
+ jsonColumns.SetType (NJson::JSON_ARRAY);
739
+ const auto & columnsMeta = resultSet.GetColumnsMeta ();
740
+ for (size_t columnNum = 0 ; columnNum < columnsMeta.size (); ++columnNum) {
741
+ NJson::TJsonValue& jsonColumn = jsonColumns.AppendValue ({});
742
+ const NYdb::TColumn& columnMeta = columnsMeta[columnNum];
743
+ jsonColumn[" name" ] = columnMeta.Name ;
744
+ jsonColumn[" type" ] = columnMeta.Type .ToString ();
745
+ }
746
+ hasColumns = true ;
747
+ }
748
+ NJson::TJsonValue& jsonRows = jsonResult[" rows" ];
749
+ const auto & columnsMeta = resultSet.GetColumnsMeta ();
750
+ NYdb::TResultSetParser rsParser (resultSet);
751
+ while (rsParser.TryNextRow ()) {
752
+ NJson::TJsonValue& jsonRow = jsonRows.AppendValue ({});
753
+ TString row = NYdb::FormatResultRowJson (rsParser, columnsMeta, IsBase64Encode ? NYdb::EBinaryStringEncoding::Base64 : NYdb::EBinaryStringEncoding::Unicode);
754
+ NJson::ReadJsonTree (row, &jsonRow);
755
+ }
756
+ }
757
+ }
758
+ }
668
759
}
669
760
if (response.HasQueryAst ()) {
670
761
jsonResponse[" ast" ] = response.GetQueryAst ();
0 commit comments