Skip to content

Commit ea11d7b

Browse files
committed
Pr feedback and improved exceptions
1 parent f910063 commit ea11d7b

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcDateVectorAccessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public <T> T getObject(final Class<T> type) throws SQLException {
9595
} else if (type == Date.class) {
9696
value = getObject();
9797
} else {
98-
throw new SQLException("invalid class");
98+
throw new SQLException("Object type not supported for Date Vector");
9999
}
100100
return !type.isPrimitive() && wasNull ? null : type.cast(value);
101101
}

flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcTimeStampVectorAccessor.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.time.temporal.ChronoUnit;
3333
import java.util.Calendar;
3434
import java.util.Objects;
35+
import java.util.Set;
3536
import java.util.TimeZone;
3637
import java.util.concurrent.TimeUnit;
3738
import java.util.function.IntSupplier;
@@ -81,7 +82,9 @@ public Class<?> getObjectClass() {
8182
@Override
8283
public <T> T getObject(final Class<T> type) throws SQLException {
8384
final Object value;
84-
if (type == OffsetDateTime.class) {
85+
if (!this.isZoned & Set.of(OffsetDateTime.class, ZonedDateTime.class, Instant.class).contains(type)) {
86+
throw new SQLException("Vectors without timezones can't be converted to objects with offset/tz info.");
87+
} else if (type == OffsetDateTime.class) {
8588
value = getOffsetDateTime();
8689
} else if (type == LocalDateTime.class) {
8790
value = getLocalDateTime(null);
@@ -92,8 +95,9 @@ public <T> T getObject(final Class<T> type) throws SQLException {
9295
} else if (type == Timestamp.class) {
9396
value = getObject();
9497
} else {
95-
throw new SQLException("invalid class");
98+
throw new SQLException("Object type not supported for TimeStamp Vector");
9699
}
100+
97101
return !type.isPrimitive() && wasNull ? null : type.cast(value);
98102
}
99103

@@ -160,7 +164,7 @@ public Date getDate(Calendar calendar) {
160164
return null;
161165
}
162166

163-
return new Date(getTimstampWithOffset(calendar, localDateTime).getTime());
167+
return new Date(getTimestampWithOffset(calendar, localDateTime).getTime());
164168
}
165169

166170
@Override
@@ -170,7 +174,7 @@ public Time getTime(Calendar calendar) {
170174
return null;
171175
}
172176

173-
return new Time(getTimstampWithOffset(calendar, localDateTime).getTime());
177+
return new Time(getTimestampWithOffset(calendar, localDateTime).getTime());
174178
}
175179

176180
@Override
@@ -180,7 +184,7 @@ public Timestamp getTimestamp(Calendar calendar) {
180184
return null;
181185
}
182186

183-
return getTimstampWithOffset(calendar, localDateTime);
187+
return getTimestampWithOffset(calendar, localDateTime);
184188
}
185189

186190
/**
@@ -190,7 +194,7 @@ public Timestamp getTimestamp(Calendar calendar) {
190194
* vector includes TZ info. In order to maintain backward compatibility, we apply the offset if
191195
* needed for getDate, getTime, and getTimestamp.
192196
*/
193-
private Timestamp getTimstampWithOffset(Calendar calendar, LocalDateTime localDateTime) {
197+
private Timestamp getTimestampWithOffset(Calendar calendar, LocalDateTime localDateTime) {
194198
if (calendar != null && !isZoned) {
195199
TimeZone timeZone = calendar.getTimeZone();
196200
long millis = Timestamp.valueOf(localDateTime).getTime();

flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcTimeVectorAccessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public <T> T getObject(final Class<T> type) throws SQLException {
131131
} else if (type == Time.class) {
132132
value = getObject();
133133
} else {
134-
throw new SQLException("invalid class");
134+
throw new SQLException("Object type not supported for Time Vector");
135135
}
136136
return !type.isPrimitive() && wasNull ? null : type.cast(value);
137137
}

0 commit comments

Comments
 (0)