]> git.proxmox.com Git - ceph.git/blame - ceph/src/arrow/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/TimestampConsumer.java
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / java / adapter / jdbc / src / main / java / org / apache / arrow / adapter / jdbc / consumer / TimestampConsumer.java
CommitLineData
1d09f67e
TL
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18package org.apache.arrow.adapter.jdbc.consumer;
19
20import java.sql.ResultSet;
21import java.sql.SQLException;
22import java.sql.Timestamp;
23
24import org.apache.arrow.vector.TimeStampMilliVector;
25
26/**
27 * Consumer which consume timestamp type values from {@link ResultSet}.
28 * Write the data to {@link TimeStampMilliVector}.
29 */
30public abstract class TimestampConsumer {
31
32 /**
33 * Creates a consumer for {@link TimeStampMilliVector}.
34 */
35 public static JdbcConsumer<TimeStampMilliVector> createConsumer(
36 TimeStampMilliVector vector, int index, boolean nullable) {
37 if (nullable) {
38 return new NullableTimestampConsumer(vector, index);
39 } else {
40 return new NonNullableTimestampConsumer(vector, index);
41 }
42 }
43
44 /**
45 * Nullable consumer for timestamp.
46 */
47 static class NullableTimestampConsumer extends BaseConsumer<TimeStampMilliVector> {
48
49 /**
50 * Instantiate a TimestampConsumer.
51 */
52 public NullableTimestampConsumer(TimeStampMilliVector vector, int index) {
53 super(vector, index);
54 }
55
56 @Override
57 public void consume(ResultSet resultSet) throws SQLException {
58 Timestamp timestamp = resultSet.getTimestamp(columnIndexInResultSet);
59 if (!resultSet.wasNull()) {
60 // for fixed width vectors, we have allocated enough memory proactively,
61 // so there is no need to call the setSafe method here.
62 vector.set(currentIndex, timestamp.getTime());
63 }
64 currentIndex++;
65 }
66 }
67
68 /**
69 * Non-nullable consumer for timestamp.
70 */
71 static class NonNullableTimestampConsumer extends BaseConsumer<TimeStampMilliVector> {
72
73 /**
74 * Instantiate a TimestampConsumer.
75 */
76 public NonNullableTimestampConsumer(TimeStampMilliVector vector, int index) {
77 super(vector, index);
78 }
79
80 @Override
81 public void consume(ResultSet resultSet) throws SQLException {
82 Timestamp timestamp = resultSet.getTimestamp(columnIndexInResultSet);
83 // for fixed width vectors, we have allocated enough memory proactively,
84 // so there is no need to call the setSafe method here.
85 vector.set(currentIndex, timestamp.getTime());
86 currentIndex++;
87 }
88 }
89}