X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=ceph%2Fsrc%2Farrow%2Fjava%2Fadapter%2Fjdbc%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Farrow%2Fadapter%2Fjdbc%2Fconsumer%2FBlobConsumer.java;fp=ceph%2Fsrc%2Farrow%2Fjava%2Fadapter%2Fjdbc%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Farrow%2Fadapter%2Fjdbc%2Fconsumer%2FBlobConsumer.java;h=e57ecdf91707a7ebc6ff85a4f63f422ced43a20e;hb=1d09f67e50a235260a0812cca2fb044674d88150;hp=0000000000000000000000000000000000000000;hpb=a653f20b2fb9a1c0c3e465a23074d91f26031b5d;p=ceph.git diff --git a/ceph/src/arrow/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/BlobConsumer.java b/ceph/src/arrow/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/BlobConsumer.java new file mode 100644 index 000000000..e57ecdf91 --- /dev/null +++ b/ceph/src/arrow/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/BlobConsumer.java @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.arrow.adapter.jdbc.consumer; + +import java.io.IOException; +import java.sql.Blob; +import java.sql.ResultSet; +import java.sql.SQLException; + +import org.apache.arrow.vector.VarBinaryVector; + +/** + * Consumer which consume blob type values from {@link ResultSet}. + * Write the data to {@link VarBinaryVector}. + */ +public class BlobConsumer extends BaseConsumer { + + private BinaryConsumer delegate; + + private final boolean nullable; + + /** + * Creates a consumer for {@link VarBinaryVector}. + */ + public static BlobConsumer createConsumer( + BinaryConsumer delegate, int index, boolean nullable) { + return new BlobConsumer(delegate, index, nullable); + } + + /** + * Instantiate a BlobConsumer. + */ + public BlobConsumer(BinaryConsumer delegate, int index, boolean nullable) { + super(null, index); + this.delegate = delegate; + this.nullable = nullable; + } + + @Override + public void consume(ResultSet resultSet) throws SQLException, IOException { + Blob blob = resultSet.getBlob(columnIndexInResultSet); + if (blob != null) { + delegate.consume(blob.getBinaryStream()); + } + delegate.moveWriterPosition(); + } + + @Override + public void close() throws Exception { + delegate.close(); + } + + @Override + public void resetValueVector(VarBinaryVector vector) { + delegate = BinaryConsumer.createConsumer(vector, columnIndexInResultSet, nullable); + } +}