Skip to content

Commit

Permalink
Safely unwrap OptionalType on table describe
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniil Zulin committed Nov 25, 2024
1 parent 159c6c0 commit 872c0eb
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import tech.ydb.table.settings.PartitioningSettings;
import tech.ydb.table.settings.TtlSettings;
import tech.ydb.table.values.OptionalType;
import tech.ydb.table.values.Type;
import tech.ydb.yoj.databind.schema.Schema;
import tech.ydb.yoj.repository.db.EntitySchema;
import tech.ydb.yoj.repository.db.exception.CreateTableException;
Expand Down Expand Up @@ -283,7 +284,7 @@ private Table describeTableInternal(String path) {
table.getColumns().stream()
.map(c -> {
String columnName = c.getName();
String simpleType = ((OptionalType) c.getType()).getItemType().toPb().getTypeId().name();
String simpleType = safeUnwrapOptional(c.getType()).toPb().getTypeId().name();
boolean isPrimaryKey = table.getPrimaryKeys().contains(columnName);
return new Column(columnName, simpleType, isPrimaryKey);
})
Expand All @@ -297,6 +298,10 @@ private Table describeTableInternal(String path) {
);
}

private Type safeUnwrapOptional(Type type) {
return type.getKind() == Type.Kind.OPTIONAL ? type.unwrapOptional() : type;
}

public void removeTablespace() {
removeTablespace(tablespace);
}
Expand Down

0 comments on commit 872c0eb

Please sign in to comment.