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