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
9 // http://www.apache.org/licenses/LICENSE-2.0
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
21 #include "parquet/properties.h"
23 #include "arrow/io/buffered.h"
24 #include "arrow/io/memory.h"
25 #include "arrow/util/logging.h"
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
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
);
41 PARQUET_ASSIGN_OR_THROW(auto data
, source
->ReadAt(start
, num_bytes
));
43 if (data
->size() != num_bytes
) {
45 ss
<< "Tried reading " << num_bytes
<< " bytes starting at position " << start
46 << " from file but only got " << data
->size();
47 throw ParquetException(ss
.str());
49 return std::make_shared
<::arrow::io::BufferReader
>(data
);
53 ArrowReaderProperties
default_arrow_reader_properties() {
54 static ArrowReaderProperties default_reader_props
;
55 return default_reader_props
;
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
;
64 } // namespace parquet