Skip to content

Commit 69b73a8

Browse files
committed
optimize
1 parent df445f8 commit 69b73a8

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryTypeRegistry.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ final class BigQueryTypeRegistry {
5656
private static final Map<Class<?>, TypeDescriptor<?>> DESCRIPTORS_BY_CLASS;
5757
private static final Map<Integer, TypeDescriptor<?>> DESCRIPTORS_BY_JDBC_TYPE;
5858

59+
private static final DateTimeFormatter TIMESTAMP_FORMATTER =
60+
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSS");
61+
private static final DateTimeFormatter TIME_FORMATTER =
62+
DateTimeFormatter.ofPattern("HH:mm:ss.SSS");
63+
5964
static {
6065
DESCRIPTORS_BY_ORDINAL = new TypeDescriptor<?>[StandardSQLTypeName.values().length];
6166
DESCRIPTORS_BY_CLASS = new ConcurrentHashMap<>();
@@ -104,11 +109,10 @@ static TypeDescriptor<?> createStringDescriptor() {
104109
if (val == null) return null;
105110
if (val instanceof byte[]) return Base64.getEncoder().encodeToString((byte[]) val);
106111
if (val instanceof Timestamp) {
107-
return DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSS")
108-
.format(((Timestamp) val).toLocalDateTime());
112+
return TIMESTAMP_FORMATTER.format(((Timestamp) val).toLocalDateTime());
109113
}
110114
if (val instanceof Time) {
111-
return DateTimeFormatter.ofPattern("HH:mm:ss.SSS").format(((Time) val).toLocalTime());
115+
return TIME_FORMATTER.format(((Time) val).toLocalTime());
112116
}
113117
return String.valueOf(val);
114118
});

0 commit comments

Comments
 (0)