mirror of
https://github.com/alibaba/DataX.git
synced 2025-05-04 00:43:29 +08:00
fix: datetime(6) Loss of precision in the last 3 digits bug #1258
This commit is contained in:
parent
91ea278762
commit
515dd00c43
@ -61,6 +61,7 @@ public class DateColumn extends Column {
|
|||||||
* */
|
* */
|
||||||
public DateColumn(final java.sql.Timestamp ts) {
|
public DateColumn(final java.sql.Timestamp ts) {
|
||||||
this(ts == null ? null : ts.getTime());
|
this(ts == null ? null : ts.getTime());
|
||||||
|
this.setRawNano(ts == null ? 0 : ts.getNanos());
|
||||||
this.setSubType(DateType.DATETIME);
|
this.setSubType(DateType.DATETIME);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,8 +87,11 @@ public class DateColumn extends Column {
|
|||||||
if (null == this.getRawData()) {
|
if (null == this.getRawData()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
java.sql.Timestamp myts = new java.sql.Timestamp((Long) this.getRawData());
|
||||||
return new Date((Long)this.getRawData());
|
myts.setNanos(this.getRawNano());
|
||||||
|
myts.setNanos(this.getRawNano());
|
||||||
|
return myts;
|
||||||
|
// return new Date((Long)this.getRawData());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -127,4 +131,14 @@ public class DateColumn extends Column {
|
|||||||
public void setSubType(DateType subType) {
|
public void setSubType(DateType subType) {
|
||||||
this.subType = subType;
|
this.subType = subType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getRawNano(){
|
||||||
|
return rawNano;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRawNano(int rawNano){
|
||||||
|
this.rawNano = rawNano;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -501,17 +501,20 @@ public class CommonRdbmsWriter {
|
|||||||
|
|
||||||
case Types.TIMESTAMP:
|
case Types.TIMESTAMP:
|
||||||
java.sql.Timestamp sqlTimestamp = null;
|
java.sql.Timestamp sqlTimestamp = null;
|
||||||
|
java.sql.Timestamp tsNano = null;
|
||||||
try {
|
try {
|
||||||
utilDate = column.asDate();
|
// utilDate = column.asDate();
|
||||||
|
tsNano = (java.sql.Timestamp)(column.asDate());
|
||||||
} catch (DataXException e) {
|
} catch (DataXException e) {
|
||||||
throw new SQLException(String.format(
|
throw new SQLException(String.format(
|
||||||
"TIMESTAMP 类型转换错误:[%s]", column));
|
"TIMESTAMP 类型转换错误:[%s]", column));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null != utilDate) {
|
// if (null != utilDate) {
|
||||||
sqlTimestamp = new java.sql.Timestamp(
|
// sqlTimestamp = new java.sql.Timestamp(
|
||||||
utilDate.getTime());
|
// utilDate.getTime());
|
||||||
}
|
// }
|
||||||
|
sqlTimestamp=tsNano;
|
||||||
preparedStatement.setTimestamp(columnIndex + 1, sqlTimestamp);
|
preparedStatement.setTimestamp(columnIndex + 1, sqlTimestamp);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user