|
25 | 25 |
|
26 | 26 | import java.nio.charset.StandardCharsets; |
27 | 27 | import java.sql.Connection; |
| 28 | +import java.sql.Date; |
28 | 29 | import java.sql.PreparedStatement; |
29 | 30 | import java.sql.ResultSet; |
30 | 31 | import java.sql.SQLException; |
| 32 | +import java.time.LocalDate; |
31 | 33 | import java.util.Arrays; |
32 | 34 | import java.util.Collections; |
33 | 35 | import java.util.List; |
|
38 | 40 | import org.apache.arrow.memory.RootAllocator; |
39 | 41 | import org.apache.arrow.vector.IntVector; |
40 | 42 | import org.apache.arrow.vector.VectorSchemaRoot; |
| 43 | +import org.apache.arrow.vector.types.DateUnit; |
41 | 44 | import org.apache.arrow.vector.types.Types; |
42 | 45 | import org.apache.arrow.vector.types.pojo.ArrowType; |
43 | 46 | import org.apache.arrow.vector.types.pojo.Field; |
@@ -180,6 +183,49 @@ public void testQueryWithParameterBinding() throws SQLException { |
180 | 183 | } |
181 | 184 | } |
182 | 185 |
|
| 186 | + @Test |
| 187 | + public void testQueryWithDateMillisecondParameterBinding() throws SQLException { |
| 188 | + final String query = "Fake query with date millisecond parameter"; |
| 189 | + final Schema schema = |
| 190 | + new Schema(Collections.singletonList(Field.nullable("", Types.MinorType.INT.getType()))); |
| 191 | + final Schema parameterSchema = |
| 192 | + new Schema( |
| 193 | + Collections.singletonList( |
| 194 | + Field.nullable("", new ArrowType.Date(DateUnit.MILLISECOND)))); |
| 195 | + final LocalDate date = LocalDate.of(2000, 1, 1); |
| 196 | + final List<List<Object>> expected = |
| 197 | + Collections.singletonList(Collections.singletonList(date.atStartOfDay())); |
| 198 | + |
| 199 | + PRODUCER.addSelectQuery( |
| 200 | + query, |
| 201 | + schema, |
| 202 | + Collections.singletonList( |
| 203 | + listener -> { |
| 204 | + try (final BufferAllocator allocator = new RootAllocator(Long.MAX_VALUE); |
| 205 | + final VectorSchemaRoot root = VectorSchemaRoot.create(schema, allocator)) { |
| 206 | + ((IntVector) root.getVector(0)).setSafe(0, 10); |
| 207 | + root.setRowCount(1); |
| 208 | + listener.start(root); |
| 209 | + listener.putNext(); |
| 210 | + } catch (final Throwable throwable) { |
| 211 | + listener.error(throwable); |
| 212 | + } finally { |
| 213 | + listener.completed(); |
| 214 | + } |
| 215 | + })); |
| 216 | + |
| 217 | + PRODUCER.addExpectedParameters(query, parameterSchema, expected); |
| 218 | + |
| 219 | + try (final PreparedStatement preparedStatement = connection.prepareStatement(query)) { |
| 220 | + preparedStatement.setDate(1, Date.valueOf(date)); |
| 221 | + |
| 222 | + try (final ResultSet resultSet = preparedStatement.executeQuery()) { |
| 223 | + resultSet.next(); |
| 224 | + assert true; |
| 225 | + } |
| 226 | + } |
| 227 | + } |
| 228 | + |
183 | 229 | @Test |
184 | 230 | @Disabled("https://github.com/apache/arrow/issues/34741: flaky test") |
185 | 231 | public void testPreparedStatementExecutionOnce() throws SQLException { |
|
0 commit comments