]> git.proxmox.com Git - ceph.git/blob - ceph/src/arrow/cpp/src/parquet/properties.cc
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / cpp / src / parquet / properties.cc
1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements. See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership. The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with 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,
12 // software distributed under the License is distributed on an
13 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 // KIND, either express or implied. See the License for the
15 // specific language governing permissions and limitations
16 // under the License.
17
18 #include <sstream>
19 #include <utility>
20
21 #include "parquet/properties.h"
22
23 #include "arrow/io/buffered.h"
24 #include "arrow/io/memory.h"
25 #include "arrow/util/logging.h"
26
27 namespace parquet {
28
29 std::shared_ptr<ArrowInputStream> ReaderProperties::GetStream(
30 std::shared_ptr<ArrowInputFile> source, int64_t start, int64_t num_bytes) {
31 if (buffered_stream_enabled_) {
32 // ARROW-6180 / PARQUET-1636 Create isolated reader that references segment
33 // of source
34 std::shared_ptr<::arrow::io::InputStream> safe_stream =
35 ::arrow::io::RandomAccessFile::GetStream(source, start, num_bytes);
36 PARQUET_ASSIGN_OR_THROW(
37 auto stream, ::arrow::io::BufferedInputStream::Create(buffer_size_, pool_,
38 safe_stream, num_bytes));
39 return std::move(stream);
40 } else {
41 PARQUET_ASSIGN_OR_THROW(auto data, source->ReadAt(start, num_bytes));
42
43 if (data->size() != num_bytes) {
44 std::stringstream ss;
45 ss << "Tried reading " << num_bytes << " bytes starting at position " << start
46 << " from file but only got " << data->size();
47 throw ParquetException(ss.str());
48 }
49 return std::make_shared<::arrow::io::BufferReader>(data);
50 }
51 }
52
53 ArrowReaderProperties default_arrow_reader_properties() {
54 static ArrowReaderProperties default_reader_props;
55 return default_reader_props;
56 }
57
58 std::shared_ptr<ArrowWriterProperties> default_arrow_writer_properties() {
59 static std::shared_ptr<ArrowWriterProperties> default_writer_properties =
60 ArrowWriterProperties::Builder().build();
61 return default_writer_properties;
62 }
63
64 } // namespace parquet