fix(dameng): preserve spatial indexes in table DDL

This commit is contained in:
t8y2 2026-07-27 20:02:57 +08:00
parent efbffce9c9
commit f8b40e30a9
No known key found for this signature in database
2 changed files with 49 additions and 1 deletions

View File

@ -1324,11 +1324,14 @@ public final class DamengAgent extends BaseDatabaseAgent {
return result;
}
private static String indexDdl(String schema, String table, IndexInfo index) {
static String indexDdl(String schema, String table, IndexInfo index) {
StringBuilder ddl = new StringBuilder("CREATE ");
if (index.getIs_unique()) {
ddl.append("UNIQUE ");
}
if ("SPATIAL".equalsIgnoreCase(coalesce(index.getIndex_type()).trim())) {
ddl.append("SPATIAL ");
}
ddl.append("INDEX ")
.append(qualifiedName(schema, index.getName()))
.append(" ON ")

View File

@ -2,6 +2,7 @@ package com.dbx.agent.dameng;
import com.dbx.agent.DatabaseAgent;
import com.dbx.agent.ExecuteQueryOptions;
import com.dbx.agent.IndexInfo;
import com.dbx.agent.MetadataListConstraints;
import com.dbx.agent.QueryPageOptions;
import com.dbx.agent.QueryPageResult;
@ -82,6 +83,50 @@ class DamengAgentTest extends JdbcFakeExecutionBehaviorTest {
assertThrows(IllegalArgumentException.class, () -> DamengAgent.damengDdlObjectType("TABLE"));
}
@Test
void spatialIndexDdlPreservesDamengIndexType() {
IndexInfo index = new IndexInfo(
"IDX_TEST_LINESTRING",
List.of("LINESTRING"),
false,
false,
null,
"SPATIAL",
null,
null
);
assertEquals(
"CREATE SPATIAL INDEX \"SYSDBA\".\"IDX_TEST_LINESTRING\" ON \"SYSDBA\".\"TEST\" (\"LINESTRING\");",
DamengAgent.indexDdl("SYSDBA", "TEST", index)
);
}
@Test
void ordinaryIndexDdlKeepsExistingSyntax() {
IndexInfo index = new IndexInfo(
"IDX_TEST_NAME",
List.of("NAME"),
false,
false,
null,
"NORMAL",
null,
null
);
assertEquals(
"CREATE INDEX \"SYSDBA\".\"IDX_TEST_NAME\" ON \"SYSDBA\".\"TEST\" (\"NAME\");",
DamengAgent.indexDdl("SYSDBA", "TEST", index)
);
index.setIs_unique(true);
assertEquals(
"CREATE UNIQUE INDEX \"SYSDBA\".\"IDX_TEST_NAME\" ON \"SYSDBA\".\"TEST\" (\"NAME\");",
DamengAgent.indexDdl("SYSDBA", "TEST", index)
);
}
@Test
void constrainedTableQueryPushesFilterTypeAndPagingToDameng() {
DamengAgent.MetadataQuery query = DamengAgent.buildConstrainedTablesQuery(