fix(kingbase): list procedures from the plugin instead of the jdbc driver - #2956
Merged
Merged
Conversation
…iver KingBaseMetaData never overrode the list-level procedures(), so the call reached KbDatabaseMetaData#getProcedures, whose SPECIFIC_NAME expression "p.proname || '_' || p.oid" KingbaseES rejects with "operator does not exist: boolean || oid". The other PostgreSQL-family plugins answer this list themselves. Query sys_catalog.sys_proc the way the existing function list does, filtered to prokind = 'p', and map the rows to Procedure. KingBaseProcedureListTest drives the plugin through a proxy connection and fails if the driver path returns.
V8R3 tags every user routine 'u' and distinguishes a procedure only by its void return type, so the plain prokind = 'p' filter returned nothing there (procedures come back with prorettype 2278, a function returning int with 23). V8R6 and later keep using the 'p' marker, checked against KingbaseES V008R003 C002B0290 and V009R003C018.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related issue
No linked issue. The failure was reported directly from the desktop client's error payload
against a KingbaseES datasource (
GET /api/rdb/procedure/list); searching the tracker forkingbase,procedure, andoperator does not existfound no existing report for it.Summary
Opening the procedure list of a KingbaseES datasource failed with:
KingBaseMetaDataoverridesfunctions()and the singleprocedure(), but never thelist-level
procedures(), so the call fell throughDefaultMetaService.procedurestoDefaultSQLExecutor.procedures, which asks the JDBC driver. The driver buildsSPECIFIC_NAMEas
p.proname || '_' || p.oid AS SPECIFIC_NAME; the reportedPosition: 173lands on thesecond
||, whose right operand isp.oid.On a server running in MySQL compatibility mode
||is a logical OR, sop.proname || '_'is typed boolean and the second operator has no overload — exactly the reported
boolean || oid. Some driver builds detect that mode and switch toconcat(p.proname,'_',p.oid);the drivers this plugin ships,
kingbase8-8.6.0.jar(default) andkingbase8-8.2.0.jar, haveno such branch, so the driver statement is sent as is. It is assembled inside the driver, so
the plugin layer is the only place to fix it — as the other PostgreSQL-family plugins (xugudb,
sundb, oscar) already do.
The plugin now lists procedures from
sys_catalog.sys_procthe way its existingFUNCTION_LIST_SQLlists functions: joined tosys_namespace, schema bound, extension-ownedobjects excluded. Procedures are selected with
prokind = 'p' OR (prokind = 'u' AND prorettype = 2278): V8R6 and later mark them'p', while V8R3 tags every user routine'u'and distinguishes a procedure only by its void return type (2278 is void, a function returning
int is 23). Rows map to
Procedurewith the name trimmed and blank names dropped, keeping thefiltering the previous
DefaultMetaServiceimplementation applied.Affected surfaces
Verification
the plugin's default driver
kingbase8-8.6.0.jar:DatabaseMetaData#getProceduresthrowscom.kingbase8.util.KSQLException: ERROR: operator does not exist: boolean || oid, first framecom.kingbase8.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2679)—same class and same frame as the report.
KingBaseMetaData#proceduresthen ran through the same connection and driver onthat server and returned the schema's procedures instead of failing.
kingbase8-8.2.0.jar, the onlyshipped driver that accepts that server): the plugin path returns the procedures and excludes a
function of the same schema, while the driver path additionally lists that function as a
procedure.
mvn -B -f chat2db-community-server/pom.xml -pl :chat2db-community-kingbase -am -Dmaven.test.skip=false -DskipTests=false '-Dsurefire.includes=**/*Test.java' -Dmaven.test.failure.ignore=false test→ BUILD SUCCESS, 0 failures (spi 191, postgresql 70, kingbase 28 including the new test).
mvn -B -f chat2db-community-server/pom.xml -pl :chat2db-community-kingbase -am -Dmaven.test.skip=true package→ BUILD SUCCESS.KingBaseProcedureListTestdrivesprocedures()through a proxy connection and asserts theprepared statement is
PROCEDURE_LIST_SQL, that the SQL carries no||, that the schema isbound, and that names are trimmed and blank rows skipped. The proxy throws
UnsupportedOperationExceptionfor anything butprepareStatement, so the driver path cannotreturn unnoticed.
KingbaseES. The statement is compatibility-mode independent, and the two tested versions cover
both
prokindconventions.Risk and compatibility
this call. The
sys_catalognames and theprokind/prorettypemarkers were checked on V8R3and V9R3.
schemaNameis blank the new query returns an empty list, wherethe driver path returned search-path-visible procedures. Callers (schema tree, completion)
pass a schema for Kingbase, and the plugin's
functions()already behaves this way.Reviewer map
chat2db-community-kingbase/src/main/java/ai/chat2db/plugin/kingbase/KingBaseMetaData.java(procedures) and.../constant/SqlConstant.java(PROCEDURE_LIST_SQL).procedures()override is removed, the driver statement comes back and KingbaseES fails again withoperator does not exist: boolean || oid.Contributor declaration
AI assistance: the change and its test were drafted with an AI coding agent. The failing statement
was traced through the shipped driver bytecode, reproduced and re-checked on real KingbaseES
instances of two versions, and the final diff was reviewed before submission.