-
Notifications
You must be signed in to change notification settings - Fork 52
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
DBZ-7362 Support DECFLOAT in Db2 connector #129
Changes from 2 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 |
---|---|---|
|
@@ -52,6 +52,10 @@ public SchemaBuilder schemaBuilder(Column column) { | |
case Types.TINYINT: | ||
// values are an 8-bit unsigned integer value between 0 and 255, we thus need to store it in short int | ||
return SchemaBuilder.int16(); | ||
case Types.OTHER: | ||
if (matches(column.typeName().toUpperCase(), "DECFLOAT")) { | ||
return SchemaBuilder.float64(); | ||
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. What is the real datatype coming from the database? It seems to me according to docs that it is either 16 or 32 bit signed floating point decimal. How does it differ from REAL/FLOAT? Does it makes sense to map it to either FLOAT32 or FLOAT64 based on the value? What Java class is returned by the JDBC driver when small and large DECFLOATs are used? 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. The range of a decimal floating point number is either 16 or 34 digits of precision. You can refer to this manual. https://www.ibm.com/docs/en/db2-for-zos/12?topic=numbers-decimal-floating-point-decfloat Create table like this, Then insert a record, INSERT INTO TEST.T1 (ID, C_DECFLOAT) VALUES (1, DECFLOAT(1.234)); To be honest, I don’t quite understand the difference between decfloat and float types. |
||
} | ||
default: | ||
return super.schemaBuilder(column); | ||
} | ||
|
@@ -64,6 +68,10 @@ public ValueConverter converter(Column column, Field fieldDefn) { | |
case Types.TINYINT: | ||
// values are an 8-bit unsigned integer value between 0 and 255, we thus need to store it in short int | ||
return (data) -> convertSmallInt(column, fieldDefn, data); | ||
case Types.OTHER: | ||
if (matches(column.typeName().toUpperCase(), "DECFLOAT")) { | ||
return (data) -> super.convertDouble(column, fieldDefn, data); | ||
} | ||
default: | ||
return super.converter(column, fieldDefn); | ||
} | ||
|
@@ -82,4 +90,18 @@ protected Object convertTimestampWithZone(Column column, Field fieldDefn, Object | |
return super.convertTimestampWithZone(column, fieldDefn, data); | ||
} | ||
|
||
/** | ||
* Determine if the uppercase form of a column's type exactly matches or begins with the specified prefix. | ||
* Note that this logic works when the column's {@link Column#typeName() type} contains the type name followed by parentheses. | ||
* | ||
* @param upperCaseTypeName the upper case form of the column's {@link Column#typeName() type name} | ||
* @param upperCaseMatch the upper case form of the expected type or prefix of the type; may not be null | ||
* @return {@code true} if the type matches the specified type, or {@code false} otherwise | ||
*/ | ||
protected static boolean matches(String upperCaseTypeName, String upperCaseMatch) { | ||
if (upperCaseTypeName == null) { | ||
return false; | ||
} | ||
return upperCaseMatch.equals(upperCaseTypeName) || upperCaseTypeName.startsWith(upperCaseMatch + "("); | ||
} | ||
} |
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.
Why not reuse the convertDecimal function? I think the contents of convertDecimal and convertDecfloat are the same.
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.
Hi, it is not. This is taken form PostgreSQL to hadnle potential issue with trailing zeroes. We don't know if it is problem here but it is kind of defensive measure.