-
Notifications
You must be signed in to change notification settings - Fork 237
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
[CALCITE-6282] Avatica ignores time precision when returning TIME results #241
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -154,7 +154,7 @@ protected Accessor createAccessor(ColumnMetaData columnMetaData, | |
case PRIMITIVE_INT: | ||
case INTEGER: | ||
case NUMBER: | ||
return new TimeFromNumberAccessor(getter, localCalendar); | ||
return new TimeFromNumberAccessor(getter, localCalendar, columnMetaData.precision); | ||
case JAVA_SQL_TIME: | ||
return new TimeAccessor(getter, localCalendar); | ||
default: | ||
|
@@ -165,11 +165,11 @@ protected Accessor createAccessor(ColumnMetaData columnMetaData, | |
case PRIMITIVE_LONG: | ||
case LONG: | ||
case NUMBER: | ||
return new TimestampFromNumberAccessor(getter, localCalendar); | ||
return new TimestampFromNumberAccessor(getter, localCalendar, columnMetaData.precision); | ||
case JAVA_SQL_TIMESTAMP: | ||
return new TimestampAccessor(getter, localCalendar); | ||
return new TimestampAccessor(getter, localCalendar, columnMetaData.precision); | ||
case JAVA_UTIL_DATE: | ||
return new TimestampFromUtilDateAccessor(getter, localCalendar); | ||
return new TimestampFromUtilDateAccessor(getter, localCalendar, columnMetaData.precision); | ||
default: | ||
throw new AssertionError("bad " + columnMetaData.type.rep); | ||
} | ||
|
@@ -241,11 +241,11 @@ protected Accessor createAccessor(ColumnMetaData columnMetaData, | |
/** Accesses a timestamp value as a string. | ||
* The timestamp is in SQL format (e.g. "2013-09-22 22:30:32"), | ||
* not Java format ("2013-09-22 22:30:32.123"). */ | ||
private static String timestampAsString(long v, Calendar calendar) { | ||
private static String timestampAsString(long v, Calendar calendar, int precision) { | ||
if (calendar != null) { | ||
v -= calendar.getTimeZone().getOffset(v); | ||
} | ||
return DateTimeUtils.unixTimestampToString(v); | ||
return DateTimeUtils.unixTimestampToString(v, precision); | ||
} | ||
|
||
/** Accesses a date value as a string, e.g. "2013-09-22". */ | ||
|
@@ -255,11 +255,11 @@ private static String dateAsString(int v, Calendar calendar) { | |
} | ||
|
||
/** Accesses a time value as a string, e.g. "22:30:32". */ | ||
private static String timeAsString(int v, Calendar calendar) { | ||
private static String timeAsString(int v, Calendar calendar, int precision) { | ||
if (calendar != null) { | ||
v -= calendar.getTimeZone().getOffset(v); | ||
} | ||
return DateTimeUtils.unixTimeToString(v); | ||
return DateTimeUtils.unixTimeToString(v, precision); | ||
} | ||
|
||
/** Implementation of {@link Cursor.Accessor}. */ | ||
|
@@ -955,10 +955,12 @@ protected Number getNumber() throws SQLException { | |
*/ | ||
static class TimeFromNumberAccessor extends NumberAccessor { | ||
private final Calendar localCalendar; | ||
private final int precision; | ||
|
||
TimeFromNumberAccessor(Getter getter, Calendar localCalendar) { | ||
TimeFromNumberAccessor(Getter getter, Calendar localCalendar, int precision) { | ||
super(getter, 0); | ||
this.localCalendar = localCalendar; | ||
this.precision = precision; | ||
} | ||
|
||
@Override public Object getObject() throws SQLException { | ||
|
@@ -986,7 +988,7 @@ static class TimeFromNumberAccessor extends NumberAccessor { | |
if (v == null) { | ||
return null; | ||
} | ||
return timeAsString(v.intValue(), null); | ||
return timeAsString(v.intValue(), null, this.precision); | ||
} | ||
|
||
protected Number getNumber() throws SQLException { | ||
|
@@ -1013,10 +1015,12 @@ protected Number getNumber() throws SQLException { | |
*/ | ||
static class TimestampFromNumberAccessor extends NumberAccessor { | ||
private final Calendar localCalendar; | ||
private final int precision; | ||
|
||
TimestampFromNumberAccessor(Getter getter, Calendar localCalendar) { | ||
TimestampFromNumberAccessor(Getter getter, Calendar localCalendar, int precision) { | ||
super(getter, 0); | ||
this.localCalendar = localCalendar; | ||
this.precision = precision; | ||
} | ||
|
||
@Override public Object getObject() throws SQLException { | ||
|
@@ -1052,7 +1056,7 @@ static class TimestampFromNumberAccessor extends NumberAccessor { | |
if (v == null) { | ||
return null; | ||
} | ||
return timestampAsString(v.longValue(), null); | ||
return timestampAsString(v.longValue(), null, this.precision); | ||
} | ||
|
||
protected Number getNumber() throws SQLException { | ||
|
@@ -1155,7 +1159,8 @@ static class TimeAccessor extends ObjectAccessor { | |
return null; | ||
} | ||
final int unix = DateTimeUtils.sqlTimeToUnixTime(time, localCalendar); | ||
return timeAsString(unix, null); | ||
// java.sql.Time only supports a precision of 0 | ||
return timeAsString(unix, null, 0); | ||
} | ||
|
||
@Override public long getLong() throws SQLException { | ||
|
@@ -1178,10 +1183,12 @@ static class TimeAccessor extends ObjectAccessor { | |
*/ | ||
static class TimestampAccessor extends ObjectAccessor { | ||
private final Calendar localCalendar; | ||
private final int precision; | ||
|
||
TimestampAccessor(Getter getter, Calendar localCalendar) { | ||
TimestampAccessor(Getter getter, Calendar localCalendar, int precision) { | ||
super(getter); | ||
this.localCalendar = localCalendar; | ||
this.precision = precision; | ||
} | ||
|
||
@Override public Timestamp getTimestamp(Calendar calendar) throws SQLException { | ||
|
@@ -1220,7 +1227,7 @@ static class TimestampAccessor extends ObjectAccessor { | |
} | ||
final long unix = | ||
DateTimeUtils.sqlTimestampToUnixTimestamp(timestamp, localCalendar); | ||
return timestampAsString(unix, null); | ||
return timestampAsString(unix, null, this.precision); | ||
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. For |
||
} | ||
|
||
@Override public long getLong() throws SQLException { | ||
|
@@ -1241,11 +1248,13 @@ static class TimestampAccessor extends ObjectAccessor { | |
*/ | ||
static class TimestampFromUtilDateAccessor extends ObjectAccessor { | ||
private final Calendar localCalendar; | ||
private final int precision; | ||
|
||
TimestampFromUtilDateAccessor(Getter getter, | ||
Calendar localCalendar) { | ||
Calendar localCalendar, int precision) { | ||
super(getter); | ||
this.localCalendar = localCalendar; | ||
this.precision = precision; | ||
} | ||
|
||
@Override public Timestamp getTimestamp(Calendar calendar) throws SQLException { | ||
|
@@ -1282,7 +1291,7 @@ static class TimestampFromUtilDateAccessor extends ObjectAccessor { | |
return null; | ||
} | ||
final long unix = DateTimeUtils.utilDateToUnixTimestamp(date, localCalendar); | ||
return timestampAsString(unix, null); | ||
return timestampAsString(unix, null, this.precision); | ||
} | ||
|
||
@Override public long getLong() throws SQLException { | ||
|
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
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.
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.
I have a question, should the 2 in
Time(2)
bescale
orprecision
?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.
I will rename it to "scale"
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.
I guess I have to leave it as
precision
, since both the columnMetadataFields which originate this value call itprecision
, and the helper functions that manipulate this field also call itprecision
(as you point out in your other comment). It would be too confusing to use different names for this value in different parts of the codebase.I propose we file a new issue if we want to modify the field name to
scale
, to make sure that we cover all the software layers involved. In the meantime it would be great to merge this PR because it fixes a genuine bug.