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/util/logging.h"
25
26namespace parquet {
27
28std::shared_ptr<ArrowInputStream> ReaderProperties::GetStream(
29 std::shared_ptr<ArrowInputFile> source, int64_t start, int64_t num_bytes) {
30 if (buffered_stream_enabled_) {
31 // ARROW-6180 / PARQUET-1636 Create isolated reader that references segment
32 // of source
33 std::shared_ptr<::arrow::io::InputStream> safe_stream =
34 ::arrow::io::RandomAccessFile::GetStream(source, start, num_bytes);
35 std::shared_ptr<::arrow::io::BufferedInputStream> stream;
36 PARQUET_THROW_NOT_OK(::arrow::io::BufferedInputStream::Create(
37 buffer_size_, pool_, safe_stream, &stream, num_bytes));
38 return std::move(stream);
39 } else {
40 std::shared_ptr<Buffer> data;
41 PARQUET_THROW_NOT_OK(source->ReadAt(start, num_bytes, &data));
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
53ArrowReaderProperties default_arrow_reader_properties() {
54 static ArrowReaderProperties default_reader_props;
55 return default_reader_props;
56}
57
58std::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
65