From 872c0ebce142cea404b830fc056e7a63b7587bed Mon Sep 17 00:00:00 2001 From: Daniil Zulin Date: Mon, 25 Nov 2024 23:55:33 +0700 Subject: [PATCH] Safely unwrap OptionalType on table describe --- .../ydb/yoj/repository/ydb/client/YdbSchemaOperations.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/client/YdbSchemaOperations.java b/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/client/YdbSchemaOperations.java index 5a59f74c..8c8b7745 100644 --- a/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/client/YdbSchemaOperations.java +++ b/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/client/YdbSchemaOperations.java @@ -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; @@ -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); }) @@ -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); }