From cfb2ba68292a1390fd09bed70bc52fc827bd69fc Mon Sep 17 00:00:00 2001 From: Mike Pigott Date: Sun, 3 Feb 2019 12:06:37 -0500 Subject: [PATCH] ARROW-3966: Using a helper method for building a UTC calendar with root locale. --- .../java/org/apache/arrow/adapter/jdbc/JdbcToArrow.java | 8 +++----- .../org/apache/arrow/adapter/jdbc/JdbcToArrowUtils.java | 9 +++++++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/JdbcToArrow.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/JdbcToArrow.java index df5fc69b9a679..16200b458b8a1 100644 --- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/JdbcToArrow.java +++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/JdbcToArrow.java @@ -23,8 +23,6 @@ import java.sql.SQLException; import java.sql.Statement; import java.util.Calendar; -import java.util.Locale; -import java.util.TimeZone; import org.apache.arrow.memory.BaseAllocator; import org.apache.arrow.memory.RootAllocator; @@ -90,7 +88,7 @@ public static VectorSchemaRoot sqlToArrow(Connection connection, String query, B Preconditions.checkNotNull(allocator, "Memory allocator object can not be null"); JdbcToArrowConfig config = - new JdbcToArrowConfig(allocator, Calendar.getInstance(TimeZone.getTimeZone("UTC"), Locale.ROOT), false); + new JdbcToArrowConfig(allocator, JdbcToArrowUtils.getUtcCalendar(), false); return sqlToArrow(connection, query, config); } @@ -155,7 +153,7 @@ public static VectorSchemaRoot sqlToArrow(Connection connection, String query, J public static VectorSchemaRoot sqlToArrow(ResultSet resultSet) throws SQLException, IOException { Preconditions.checkNotNull(resultSet, "JDBC ResultSet object can not be null"); - return sqlToArrow(resultSet, Calendar.getInstance(TimeZone.getTimeZone("UTC"), Locale.ROOT)); + return sqlToArrow(resultSet, JdbcToArrowUtils.getUtcCalendar()); } /** @@ -172,7 +170,7 @@ public static VectorSchemaRoot sqlToArrow(ResultSet resultSet, BaseAllocator all Preconditions.checkNotNull(allocator, "Memory Allocator object can not be null"); JdbcToArrowConfig config = - new JdbcToArrowConfig(allocator, Calendar.getInstance(TimeZone.getTimeZone("UTC"), Locale.ROOT), false); + new JdbcToArrowConfig(allocator, JdbcToArrowUtils.getUtcCalendar(), false); return sqlToArrow(resultSet, config); } diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/JdbcToArrowUtils.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/JdbcToArrowUtils.java index 703d1c5e20e75..a363c14af88f4 100644 --- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/JdbcToArrowUtils.java +++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/JdbcToArrowUtils.java @@ -38,7 +38,9 @@ import java.util.Calendar; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Map; +import java.util.TimeZone; import org.apache.arrow.memory.RootAllocator; import org.apache.arrow.vector.BaseFixedWidthVector; @@ -108,6 +110,13 @@ public static Schema jdbcToArrowSchema(ResultSetMetaData rsmd, Calendar calendar return jdbcToArrowSchema(rsmd, new JdbcToArrowConfig(new RootAllocator(0), calendar, false)); } + /** + * Returns the instance of a {java.util.Calendar} with the UTC time zone and root locale. + */ + public static Calendar getUtcCalendar() { + return Calendar.getInstance(TimeZone.getTimeZone("UTC"), Locale.ROOT); + } + /** * Create Arrow {@link Schema} object for the given JDBC {@link ResultSetMetaData}. *