-
Notifications
You must be signed in to change notification settings - Fork 0
fix(gaussdb): inherit PostgreSQL indexes(), drop 'public' from systemSchemas, add getSqlEditorHints #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix(gaussdb): inherit PostgreSQL indexes(), drop 'public' from systemSchemas, add getSqlEditorHints #13
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,12 @@ | ||
| package ai.chat2db.plugin.gaussdb; | ||
|
|
||
| import ai.chat2db.plugin.postgresql.PostgreSQLMetaData; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.io.InputStream; | ||
| import java.lang.reflect.Method; | ||
| import java.lang.reflect.Proxy; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.sql.Connection; | ||
| import java.sql.PreparedStatement; | ||
| import java.sql.ResultSet; | ||
|
|
@@ -11,9 +15,32 @@ | |
|
|
||
| import static ai.chat2db.plugin.gaussdb.constant.GaussDBMetaDataConstants.TABLE_DDL_SQL; | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||
| import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
|
||
| class GaussDBMetaDataTest { | ||
|
|
||
| @Test | ||
| void indexesInheritsPostgreSqlImplementationWithTypesAndForeignKeys() throws Exception { | ||
| Method indexes = GaussDBMetaData.class.getMethod( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
For a valid quoted GaussDB schema or table whose name contains a single quote, the old JDBC metadata call accepted the name as a value, but the inherited implementation now interpolates it into the single-quoted AGENTS.md reference: AGENTS.md:L144-L145 Useful? React with 👍 / 👎. |
||
| "indexes", Connection.class, String.class, String.class, String.class); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When the table-detail or index-list API identifies a GaussDB table without a schema, which AGENTS.md reference: AGENTS.md:L56-L58 Useful? React with 👍 / 👎. |
||
|
|
||
| assertEquals(PostgreSQLMetaData.class, indexes.getDeclaringClass()); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a GaussDB foreign key uses different local and referenced column names, such as AGENTS.md reference: AGENTS.md:L144-L145 Useful? React with 👍 / 👎. |
||
| } | ||
|
|
||
| @Test | ||
| void gaussdbJsonDoesNotMarkPublicSchemaAsSystem() throws Exception { | ||
| String json; | ||
| try (InputStream in = GaussDBMetaDataTest.class.getResourceAsStream( | ||
| "/ai/chat2db/plugin/gaussdb/gaussdb.json")) { | ||
| assertNotNull(in, "gaussdb.json must be on the test classpath"); | ||
| json = new String(in.readAllBytes(), StandardCharsets.UTF_8); | ||
| } | ||
|
|
||
| assertFalse(json.contains("\"public\""), | ||
| "the default user schema 'public' must not be listed in systemSchemas"); | ||
| } | ||
|
|
||
| @Test | ||
| void tableDdlUsesTableOidAndRemovesSearchPath() { | ||
| String nativeDdl = """ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| package ai.chat2db.plugin.gaussdb; | ||
|
|
||
| import ai.chat2db.community.domain.api.enums.completion.SqlCompletionCandidateTypeEnum; | ||
| import ai.chat2db.community.domain.api.enums.completion.SqlCompletionEditorHintTypeEnum; | ||
| import ai.chat2db.community.domain.api.model.completion.SqlCompletionCandidate; | ||
| import ai.chat2db.community.domain.api.model.completion.SqlCompletionEditorHint; | ||
| import ai.chat2db.community.domain.api.model.completion.request.DbSqlCompletionRequest; | ||
| import ai.chat2db.community.domain.api.model.completion.result.SqlCompletionMetadataResponse; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
|
||
| class GaussDBSyntaxPluginTest { | ||
|
|
||
| @Test | ||
| void providesInsertEditorHintsLikePostgreSqlSibling() { | ||
| String sql = "INSERT INTO app.demo (id, enabled, created_at) VALUES ("; | ||
| List<SqlCompletionCandidate> columns = List.of( | ||
| column("id", "integer", 1), | ||
| column("enabled", "boolean", 2), | ||
| column("created_at", "timestamp", 3)); | ||
| DbSqlCompletionRequest request = DbSqlCompletionRequest.of( | ||
| sql, sql.length(), "GAUSSDB", 0, | ||
| metadataRequest -> SqlCompletionMetadataResponse.of(columns)); | ||
|
|
||
| List<SqlCompletionEditorHint> hints = new GaussDBSyntaxPlugin().getSqlEditorHints(request); | ||
|
|
||
| assertEquals(1, hints.size()); | ||
| assertEquals(SqlCompletionEditorHintTypeEnum.INSERT_VALUE, hints.get(0).getType()); | ||
| assertEquals(List.of("0", "FALSE", "CURRENT_TIMESTAMP"), | ||
| hints.get(0).getItems().stream() | ||
| .map(SqlCompletionEditorHint.Item::getDefaultValue).toList()); | ||
| } | ||
|
|
||
| private SqlCompletionCandidate column(String name, String type, int rank) { | ||
| SqlCompletionCandidate candidate = SqlCompletionCandidate.of(SqlCompletionCandidateTypeEnum.COLUMN, name); | ||
| candidate.setColumnName(name); | ||
| candidate.setDataType(type); | ||
| candidate.setSortRank(rank); | ||
| return candidate; | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a GaussDB database where two schemas reuse a foreign-key constraint name, the inherited
SELECT_KEY_INDEXjoinskey_column_usageandconstraint_column_usageto the filtered constraint only byconstraint_name(PostgreSQLMetaDataConstants.java:54). Rows from the other schema are consequently mixed into the selected table's foreign-key metadata, potentially changing the reported target schema/table and duplicating columns. Qualify both joins by constraint catalog/schema and name, or provide a GaussDB-specific query, and cover repeated constraint names across schemas.AGENTS.md reference: AGENTS.md:L144-L145
Useful? React with 👍 / 👎.