Apache Hop version?
2.19
Java version?
21
Operating system
Windows
What happened?
Affected: 2.19.0 and earlier.
MsSqlServerDatabaseMeta.getFieldDefinition() emits DATETIME for both Hop Date and Timestamp:
case IValueMeta.TYPE_TIMESTAMP, IValueMeta.TYPE_DATE:
retval += "DATETIME";
break;
The mapping cannot round-trip SQL Server's current temporal types:
| Source column |
JDBC/Hop metadata |
Generated DDL |
Change |
date |
Types.DATE / Date |
DATETIME |
date-only becomes date and time |
time |
Types.TIME / Date |
DATETIME |
time-only becomes date and time |
datetime2(7) |
Date or Timestamp |
DATETIME |
lower precision and smaller range |
This is not only a naming difference. SQL Server datetime starts at 1753 and rounds to 3.33 ms,
while datetime2 starts at year 0001 and supports 100 ns precision. See Microsoft's
date and time data types.
Steps to reproduce
- Create a SQL Server table with a
date, a time and a datetime2(7) column.
- Read it and generate the table DDL from the resulting row metadata — Table Output's SQL
button, or MsSqlServerDatabaseMeta.getFieldDefinition() directly.
Expected: DATE, TIME and DATETIME2 — the table can be recreated from the metadata that was
read.
Actual: DATETIME for all three. Reproduced against 2.19.0 by passing the metadata read for
these columns to getFieldDefinition(). The native SQL Server meta inherits the same method.
Suggested fix
Use IValueMeta.getOriginalColumnType() when it is available so Types.DATE and Types.TIME
generate DATE and TIME. Generate DATETIME2 for Hop Timestamp and use it as the modern fallback
where the original SQL type cannot be recovered. Add round-trip tests for all three source types and
both SQL Server connection variants.
Issue Priority
Priority: 2
Issue Component
Component: Database
Apache Hop version?
2.19
Java version?
21
Operating system
Windows
What happened?
Affected: 2.19.0 and earlier.
MsSqlServerDatabaseMeta.getFieldDefinition()emitsDATETIMEfor both Hop Date and Timestamp:The mapping cannot round-trip SQL Server's current temporal types:
dateTypes.DATE/ DateDATETIMEtimeTypes.TIME/ DateDATETIMEdatetime2(7)DATETIMEThis is not only a naming difference. SQL Server
datetimestarts at 1753 and rounds to 3.33 ms,while
datetime2starts at year 0001 and supports 100 ns precision. See Microsoft'sdate and time data types.
Steps to reproduce
date, atimeand adatetime2(7)column.button, or
MsSqlServerDatabaseMeta.getFieldDefinition()directly.Expected:
DATE,TIMEandDATETIME2— the table can be recreated from the metadata that wasread.
Actual:
DATETIMEfor all three. Reproduced against 2.19.0 by passing the metadata read forthese columns to
getFieldDefinition(). The native SQL Server meta inherits the same method.Suggested fix
Use
IValueMeta.getOriginalColumnType()when it is available soTypes.DATEandTypes.TIMEgenerate
DATEandTIME. GenerateDATETIME2for Hop Timestamp and use it as the modern fallbackwhere the original SQL type cannot be recovered. Add round-trip tests for all three source types and
both SQL Server connection variants.
Issue Priority
Priority: 2
Issue Component
Component: Database