diff --git a/fe/fe-core/src/main/java/org/apache/doris/datasource/iceberg/IcebergExternalTable.java b/fe/fe-core/src/main/java/org/apache/doris/datasource/iceberg/IcebergExternalTable.java index e8db8a30ef40f9..cdfd574b8e6aa6 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/datasource/iceberg/IcebergExternalTable.java +++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/iceberg/IcebergExternalTable.java @@ -25,6 +25,7 @@ import org.apache.doris.catalog.PartitionType; import org.apache.doris.common.AnalysisException; import org.apache.doris.common.DdlException; +import org.apache.doris.common.util.SqlUtils; import org.apache.doris.common.util.Util; import org.apache.doris.datasource.ExternalTable; import org.apache.doris.datasource.SchemaCacheKey; @@ -75,6 +76,7 @@ public class IcebergExternalTable extends ExternalTable implements MTMVRelatedTa private boolean isValidRelatedTable = false; private boolean isView; private static final String ENGINE_PROP_NAME = "engine-name"; + private static final String TABLE_COMMENT_PROP = "comment"; public IcebergExternalTable(long id, String name, String remoteName, IcebergExternalCatalog catalog, IcebergExternalDatabase db) { @@ -146,6 +148,17 @@ public Table getIcebergTable() { return IcebergUtils.getIcebergTable(this); } + @Override + public String getComment() { + return properties().getOrDefault(TABLE_COMMENT_PROP, ""); + } + + @Override + public String getComment(boolean escapeQuota) { + String comment = getComment(); + return escapeQuota ? SqlUtils.escapeQuota(comment) : comment; + } + @Override public void beforeMTMVRefresh(MTMV mtmv) throws DdlException { } diff --git a/fe/fe-core/src/test/java/org/apache/doris/datasource/iceberg/IcebergExternalTableTest.java b/fe/fe-core/src/test/java/org/apache/doris/datasource/iceberg/IcebergExternalTableTest.java index 2d1e7a390ae637..6bb96bf0d43c75 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/datasource/iceberg/IcebergExternalTableTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/datasource/iceberg/IcebergExternalTableTest.java @@ -259,6 +259,22 @@ private IcebergExternalTable createSpyTable() { return spy; } + @Test + public void testGetComment() { + IcebergExternalTable spy = createSpyTable(); + Map properties = Maps.newHashMap(); + properties.put("comment", "my-table-comment"); + Mockito.when(icebergTable.properties()).thenReturn(properties); + + Assertions.assertEquals("my-table-comment", spy.getComment()); + + properties.put("comment", "comment with \"quote\""); + Assertions.assertEquals("comment with \\\"quote\\\"", spy.getComment(true)); + + properties.remove("comment"); + Assertions.assertEquals("", spy.getComment()); + } + /** Creates a mock Transform with the given canonical toString() value. * Also stubs isIdentity() and isVoid() based on the value. */ @SuppressWarnings({"unchecked", "rawtypes"}) @@ -398,4 +414,3 @@ public void testGetPartitionSpecSqlUnresolvableColumnSkipped() { Assertions.assertEquals("", spy.getPartitionSpecSql()); } } -