]> git.proxmox.com Git - ceph.git/blob - ceph/src/arrow/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/BlobConsumer.java
e57ecdf91707a7ebc6ff85a4f63f422ced43a20e
[ceph.git] / ceph / src / arrow / java / adapter / jdbc / src / main / java / org / apache / arrow / adapter / jdbc / consumer / BlobConsumer.java
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
18 package org.apache.arrow.adapter.jdbc.consumer;
19
20 import java.io.IOException;
21 import java.sql.Blob;
22 import java.sql.ResultSet;
23 import java.sql.SQLException;
24
25 import org.apache.arrow.vector.VarBinaryVector;
26
27 /**
28 * Consumer which consume blob type values from {@link ResultSet}.
29 * Write the data to {@link VarBinaryVector}.
30 */
31 public class BlobConsumer extends BaseConsumer<VarBinaryVector> {
32
33 private BinaryConsumer delegate;
34
35 private final boolean nullable;
36
37 /**
38 * Creates a consumer for {@link VarBinaryVector}.
39 */
40 public static BlobConsumer createConsumer(
41 BinaryConsumer delegate, int index, boolean nullable) {
42 return new BlobConsumer(delegate, index, nullable);
43 }
44
45 /**
46 * Instantiate a BlobConsumer.
47 */
48 public BlobConsumer(BinaryConsumer delegate, int index, boolean nullable) {
49 super(null, index);
50 this.delegate = delegate;
51 this.nullable = nullable;
52 }
53
54 @Override
55 public void consume(ResultSet resultSet) throws SQLException, IOException {
56 Blob blob = resultSet.getBlob(columnIndexInResultSet);
57 if (blob != null) {
58 delegate.consume(blob.getBinaryStream());
59 }
60 delegate.moveWriterPosition();
61 }
62
63 @Override
64 public void close() throws Exception {
65 delegate.close();
66 }
67
68 @Override
69 public void resetValueVector(VarBinaryVector vector) {
70 delegate = BinaryConsumer.createConsumer(vector, columnIndexInResultSet, nullable);
71 }
72 }