38
38
import tech .ydb .proto .ValueProtos ;
39
39
import tech .ydb .proto .ValueProtos .TypedValue ;
40
40
import tech .ydb .proto .common .CommonProtos ;
41
+ import tech .ydb .proto .scheme .SchemeOperationProtos ;
41
42
import tech .ydb .proto .table .YdbTable ;
42
43
import tech .ydb .table .Session ;
43
44
import tech .ydb .table .description .ChangefeedDescription ;
@@ -661,7 +662,7 @@ public CompletableFuture<Result<TableDescription>> describeTable(String path, De
661
662
String traceId = getTraceIdOrGenerateNew (settings .getTraceId ());
662
663
final GrpcRequestSettings grpcRequestSettings = makeGrpcRequestSettings (settings .getTimeoutDuration (), traceId );
663
664
return tableRpc .describeTable (request , grpcRequestSettings )
664
- .thenApply (result -> result . map ( desc -> mapDescribeTable (desc , settings ) ));
665
+ .thenApply (res -> mapDescribeTable (res , settings ));
665
666
}
666
667
667
668
private static TableTtl mapTtlSettings (YdbTable .TtlSettings ttl ) {
@@ -745,12 +746,22 @@ private static ChangefeedDescription.State mapChangefeedState(YdbTable.Changefee
745
746
}
746
747
}
747
748
748
- private static TableDescription mapDescribeTable (
749
- YdbTable .DescribeTableResult result ,
750
- DescribeTableSettings describeTableSettings
751
- ) {
749
+ private static Result <TableDescription > mapDescribeTable (Result <YdbTable .DescribeTableResult > describeResult ,
750
+ DescribeTableSettings settings ) {
751
+ if (!describeResult .isSuccess ()) {
752
+ return describeResult .map (null );
753
+ }
754
+ YdbTable .DescribeTableResult desc = describeResult .getValue ();
755
+ SchemeOperationProtos .Entry .Type entryType = desc .getSelf ().getType ();
756
+
757
+ if (entryType != SchemeOperationProtos .Entry .Type .TABLE &&
758
+ entryType != SchemeOperationProtos .Entry .Type .COLUMN_TABLE ) {
759
+ String errorMsg = "Entry " + desc .getSelf ().getName () + " with type " + entryType + " is not a table" ;
760
+ return Result .fail (Status .of (StatusCode .SCHEME_ERROR ).withIssues (Issue .of (errorMsg , Issue .Severity .ERROR )));
761
+ }
762
+
752
763
TableDescription .Builder description = TableDescription .newBuilder ();
753
- switch (result .getStoreType ()) {
764
+ switch (desc .getStoreType ()) {
754
765
case STORE_TYPE_ROW :
755
766
description = description .setStoreType (TableDescription .StoreType .ROW );
756
767
break ;
@@ -763,13 +774,13 @@ private static TableDescription mapDescribeTable(
763
774
break ;
764
775
}
765
776
766
- for (int i = 0 ; i < result .getColumnsCount (); i ++) {
767
- YdbTable .ColumnMeta column = result .getColumns (i );
777
+ for (int i = 0 ; i < desc .getColumnsCount (); i ++) {
778
+ YdbTable .ColumnMeta column = desc .getColumns (i );
768
779
description .addNonnullColumn (column .getName (), ProtoType .fromPb (column .getType ()), column .getFamily ());
769
780
}
770
- description .setPrimaryKeys (result .getPrimaryKeyList ());
771
- for (int i = 0 ; i < result .getIndexesCount (); i ++) {
772
- YdbTable .TableIndexDescription idx = result .getIndexes (i );
781
+ description .setPrimaryKeys (desc .getPrimaryKeyList ());
782
+ for (int i = 0 ; i < desc .getIndexesCount (); i ++) {
783
+ YdbTable .TableIndexDescription idx = desc .getIndexes (i );
773
784
774
785
if (idx .hasGlobalIndex ()) {
775
786
description .addGlobalIndex (idx .getName (), idx .getIndexColumnsList (), idx .getDataColumnsList ());
@@ -783,8 +794,8 @@ private static TableDescription mapDescribeTable(
783
794
description .addGlobalUniqueIndex (idx .getName (), idx .getIndexColumnsList (), idx .getDataColumnsList ());
784
795
}
785
796
}
786
- YdbTable .TableStats tableStats = result .getTableStats ();
787
- if (describeTableSettings .isIncludeTableStats () && tableStats != null ) {
797
+ YdbTable .TableStats tableStats = desc .getTableStats ();
798
+ if (settings .isIncludeTableStats () && tableStats != null ) {
788
799
Timestamp creationTime = tableStats .getCreationTime ();
789
800
Instant createdAt = creationTime == null ? null : Instant .ofEpochSecond (creationTime .getSeconds (),
790
801
creationTime .getNanos ());
@@ -796,26 +807,24 @@ private static TableDescription mapDescribeTable(
796
807
description .setTableStats (stats );
797
808
798
809
List <YdbTable .PartitionStats > partitionStats = tableStats .getPartitionStatsList ();
799
- if (describeTableSettings .isIncludePartitionStats () && partitionStats != null ) {
810
+ if (settings .isIncludePartitionStats () && partitionStats != null ) {
800
811
for (YdbTable .PartitionStats stat : partitionStats ) {
801
812
description .addPartitionStat (stat .getRowsEstimate (), stat .getStoreSize ());
802
813
}
803
814
}
804
815
}
805
- YdbTable .PartitioningSettings partitioningSettings = result .getPartitioningSettings ();
806
- if (partitioningSettings != null ) {
807
- PartitioningSettings settings = new PartitioningSettings ();
808
- settings .setPartitionSize (partitioningSettings .getPartitionSizeMb ());
809
- settings .setMinPartitionsCount (partitioningSettings .getMinPartitionsCount ());
810
- settings .setMaxPartitionsCount (partitioningSettings .getMaxPartitionsCount ());
811
- settings .setPartitioningByLoad (partitioningSettings .getPartitioningByLoad () == CommonProtos .
812
- FeatureFlag .Status .ENABLED );
813
- settings .setPartitioningBySize (partitioningSettings .getPartitioningBySize () == CommonProtos .
814
- FeatureFlag .Status .ENABLED );
815
- description .setPartitioningSettings (settings );
816
+ YdbTable .PartitioningSettings protoPs = desc .getPartitioningSettings ();
817
+ if (protoPs != null ) {
818
+ PartitioningSettings ps = new PartitioningSettings ();
819
+ ps .setPartitionSize (protoPs .getPartitionSizeMb ());
820
+ ps .setMinPartitionsCount (protoPs .getMinPartitionsCount ());
821
+ ps .setMaxPartitionsCount (protoPs .getMaxPartitionsCount ());
822
+ ps .setPartitioningByLoad (protoPs .getPartitioningByLoad () == CommonProtos .FeatureFlag .Status .ENABLED );
823
+ ps .setPartitioningBySize (protoPs .getPartitioningBySize () == CommonProtos .FeatureFlag .Status .ENABLED );
824
+ description .setPartitioningSettings (ps );
816
825
}
817
826
818
- List <YdbTable .ColumnFamily > columnFamiliesList = result .getColumnFamiliesList ();
827
+ List <YdbTable .ColumnFamily > columnFamiliesList = desc .getColumnFamiliesList ();
819
828
if (columnFamiliesList != null ) {
820
829
for (YdbTable .ColumnFamily family : columnFamiliesList ) {
821
830
ColumnFamily .Compression compression ;
@@ -831,8 +840,8 @@ private static TableDescription mapDescribeTable(
831
840
);
832
841
}
833
842
}
834
- if (describeTableSettings .isIncludeShardKeyBounds ()) {
835
- List <ValueProtos .TypedValue > shardKeyBoundsList = result .getShardKeyBoundsList ();
843
+ if (settings .isIncludeShardKeyBounds ()) {
844
+ List <ValueProtos .TypedValue > shardKeyBoundsList = desc .getShardKeyBoundsList ();
836
845
if (shardKeyBoundsList != null ) {
837
846
Optional <Value <?>> leftValue = Optional .empty ();
838
847
for (ValueProtos .TypedValue typedValue : shardKeyBoundsList ) {
@@ -851,8 +860,8 @@ private static TableDescription mapDescribeTable(
851
860
}
852
861
}
853
862
854
- description .setTtlSettings (mapTtlSettings (result .getTtlSettings ()));
855
- for (YdbTable .ChangefeedDescription pb : result .getChangefeedsList ()) {
863
+ description .setTtlSettings (mapTtlSettings (desc .getTtlSettings ()));
864
+ for (YdbTable .ChangefeedDescription pb : desc .getChangefeedsList ()) {
856
865
description .addChangefeed (new ChangefeedDescription (
857
866
pb .getName (),
858
867
mapChangefeedMode (pb .getMode ()),
@@ -863,7 +872,7 @@ private static TableDescription mapDescribeTable(
863
872
));
864
873
}
865
874
866
- return description .build ();
875
+ return Result . success ( description .build () );
867
876
}
868
877
869
878
private static YdbTable .TransactionSettings txSettings (Transaction .Mode transactionMode ) {
0 commit comments