[#11590] fix(doris): upgrade type system for Doris 3.0+/4.0.x compatibility#11763
Open
jiangxt2 wants to merge 1 commit into
Open
[#11590] fix(doris): upgrade type system for Doris 3.0+/4.0.x compatibility#11763jiangxt2 wants to merge 1 commit into
jiangxt2 wants to merge 1 commit into
Conversation
6fe4bf5 to
6d5e661
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Improves Apache Doris JDBC catalog type handling to better interoperate with Doris 3.0+/4.0.x, focusing on parameterized type parsing and DATETIME precision extraction, with accompanying unit test updates.
Changes:
- Enhance
DorisTypeConverterto normalize/parse parameterized scalar types (e.g.,decimal(10,2),datetime(3)) and add mappings for additional Doris scalar/external types. - Update
DorisTableOperations.calculateDatetimePrecision()to parseDATETIME(N)directly from the type string before falling back to JDBC metadata/driver-version gating. - Extend/adjust unit tests around DATETIME precision and type conversion.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| catalogs/catalog-jdbc-doris/src/main/java/org/apache/gravitino/catalog/doris/converter/DorisTypeConverter.java | Adds base-type stripping and parameter parsing; expands scalar/external type mappings; changes DateType output to datev2. |
| catalogs/catalog-jdbc-doris/src/main/java/org/apache/gravitino/catalog/doris/operation/DorisTableOperations.java | Parses DATETIME(N) precision from type string first; keeps driver-version guard for plain DATETIME. |
| catalogs/catalog-jdbc-doris/src/test/java/org/apache/gravitino/catalog/doris/converter/TestDorisTypeConverter.java | Adds coverage for new mappings, parameterized type parsing, and malformed parameter handling. |
| catalogs/catalog-jdbc-doris/src/test/java/org/apache/gravitino/catalog/doris/operation/TestDorisTableOperations.java | Adds tests for DATETIME(N) parsing and behavior under unsupported MySQL driver versions; adjusts unsupported-type test set. |
Comment on lines
+474
to
+478
| @@ -475,11 +475,7 @@ public void testCreateNotSupportTypeTable() { | |||
| Types.IntervalDayType.get(), | |||
| Types.IntervalYearType.get(), | |||
| Types.UUIDType.get(), | |||
| Types.ListType.of(Types.DateType.get(), true), | |||
| Types.MapType.of(Types.StringType.get(), Types.IntegerType.get(), true), | |||
| Types.UnionType.of(Types.IntegerType.get()), | |||
| Types.StructType.of( | |||
| Types.StructType.Field.notNullField("col_1", Types.IntegerType.get()))); | |||
| Types.UnionType.of(Types.IntegerType.get())); | |||
Comment on lines
+68
to
+76
| if (parenIndex > 0) { | ||
| try { | ||
| String precisionStr = typeName.substring(parenIndex + 1, typeName.length() - 1); | ||
| int precision = Integer.parseInt(precisionStr); | ||
| return Types.TimestampType.withoutTimeZone(precision); | ||
| } catch (NumberFormatException e) { | ||
| // Fall through to default datetime handling | ||
| } | ||
| } |
Comment on lines
+134
to
+142
| if (p1 == 0 && parenIndex > 0) { | ||
| try { | ||
| String[] parts = typeName.substring(parenIndex + 1, typeName.length() - 1).split(","); | ||
| p1 = Integer.parseInt(parts[0].trim()); | ||
| p2 = parts.length >= 2 ? Integer.parseInt(parts[1].trim()) : 0; | ||
| } catch (NumberFormatException e) { | ||
| return Types.ExternalType.of(typeName); | ||
| } | ||
| } |
Code Coverage Report
Files
|
…ompatibility - datev2: fromGravitino(DateType) returns "datev2" for Doris 4.0.x compatibility - DATETIME precision: parse from "datetime(N)" type string when JDBC metadata is null - Parameter type parsing: extract base type from "int(11)" to prevent ExternalType fallback - Type mapping: binary/json/variant/ip/largeint/bitmap/hll to BinaryType/ExternalType - ExternalType round-trip: fromGravitino(ExternalType) returns catalogString() - Error handling: parseTypeParamsOrExternal catches NumberFormatException, returns ExternalType Signed-off-by: jiangxt2 <jiangxt2@vip.qq.com> Co-Authored-By: Chang-Tong <zdcheerful@hotmail.com> Co-Authored-By: ArtificialIdoit <bill.sea@hotmail.com> Co-Authored-By: cwq222 <15503804976@163.com>
be05223 to
d8fc157
Compare
Author
|
Updated the PR to address review feedback and code review findings:
CI checks triggered — ready for review. |
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.
What changes were proposed in this pull request?
Type Converter Enhancement (
DorisTypeConverter.java)toGravitino()direction (Doris → Gravitino):(
"int(11)"→"int","decimal(10,2)"→"decimal") before switch matching,preventing them from falling into
ExternalTypefallbackdatetime(N)precision: Parse precision directly from type string when JDBCdatetimePrecisionis null, bypassing inaccurateCOLUMN_SIZEfrom older MySQL driversbinary/varbinary→BinaryType,json/variant/ipv4/ipv6/
largeint/bitmap/hll/bigint unsigned→ExternalType,datev2→DateTypeparseTypeParamsOrExternal()catchesNumberFormatExceptiononmalformed type strings and returns
ExternalTypeinstead of crashingendsWith(")")check preventsStringIndexOutOfBoundsExceptionfor inputs like
"datetime("or"varchar("fromGravitino()direction (Gravitino → Doris):datev2:DateType→"datev2"(Doris 1.2+ acceptsdatev2; 4.0.x requires itdue to
disable_datev1=true)ExternalTyperound-trip:ExternalType→catalogString()(e.g.ExternalType("json")→"json")array/map/structare mapped toExternalTypeintoGravitinodirection.
fromGravitinodoes not handleListType/MapType/StructType(throwsIllegalArgumentException). Full complex type support requiresSHOW CREATE TABLEparsing,which will be added in a follow-up PR.
DATETIME Precision Fix (
DorisTableOperations.java)DATETIME(N)first: Parse precision directly from type string (e.g."DATETIME(3)"→ 3), no dependency on JDBC
COLUMN_SIZEor driver versionDATETIMEfallback: UsesCOLUMN_SIZEwith MySQL driver version guard(requires >= 8.0.16 for accurate precision)
Does this PR introduce any user-facing change?
No. Type mapping improvements are transparent to users. Complex types (
array/map/struct)are recognized as
ExternalTyperather than being completely unknown.How was this patch tested?
Unit tests (
TestDorisTypeConverter):datev2,datetime(N)precision (0/3/6)int(11),varchar(100),decimal(10,2),datetime(3)json,variant,ipv4,ipv6,largeint,bitmap,hll,bigint unsignedvarchar(abc),char(xyz),decimal(a,b)DATETIME precision tests (
TestDorisTableOperations):DATETIME(0/3/6)precision parsing,DATETIME(x)invalid inputDATETIME(3)with unsupported driver version (returns 3, not null)Cross-version E2E verification (local Doris clusters):
datev2column creation verified on all three versionsDATETIME(N)precision verified on all three versionsRelated to #11590, Fixes #11762