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 " deletion_vector_reader.h"
19+
20+ #include " rapidjson/document.h"
21+ #include " rapidjson/stringbuffer.h"
22+ #include " util/block_compression.h"
23+
24+ namespace doris {
25+ namespace vectorized {
26+ Status DeletionVectorReader::open () {
27+ if (_is_opened) [[unlikely]] {
28+ return Status::OK ();
29+ }
30+
31+ _init_system_properties ();
32+ _init_file_description ();
33+ RETURN_IF_ERROR (_create_file_reader ());
34+
35+ _file_size = _file_reader->size ();
36+ _is_opened = true ;
37+ return Status::OK ();
38+ }
39+
40+ Status DeletionVectorReader::read_at (size_t offset, Slice result) {
41+ if (UNLIKELY (_io_ctx && _io_ctx->should_stop )) {
42+ return Status::EndOfFile (" stop read." );
43+ }
44+ size_t bytes_read = 0 ;
45+ RETURN_IF_ERROR (_file_reader->read_at (offset, result, &bytes_read, _io_ctx));
46+ if (bytes_read != result.size ) [[unlikely]] {
47+ return Status::IOError (" Failed to read fully at offset {}, expected {}, got {}" , offset,
48+ result.size , bytes_read);
49+ }
50+ return Status::OK ();
51+ }
52+
53+ Status DeletionVectorReader::_create_file_reader () {
54+ if (UNLIKELY (_io_ctx && _io_ctx->should_stop )) {
55+ return Status::EndOfFile (" stop read." );
56+ }
57+
58+ _file_description.mtime = _range.__isset .modification_time ? _range.modification_time : 0 ;
59+ io::FileReaderOptions reader_options =
60+ FileFactory::get_reader_options (_state, _file_description);
61+ _file_reader = DORIS_TRY (io::DelegateReader::create_file_reader (
62+ _profile, _system_properties, _file_description, reader_options,
63+ io::DelegateReader::AccessMode::RANDOM, _io_ctx));
64+ return Status::OK ();
65+ }
66+
67+ void DeletionVectorReader::_init_file_description () {
68+ _file_description.path = _range.path ;
69+ _file_description.file_size = _range.__isset .file_size ? _range.file_size : -1 ;
70+ if (_range.__isset .fs_name ) {
71+ _file_description.fs_name = _range.fs_name ;
72+ }
73+ }
74+
75+ void DeletionVectorReader::_init_system_properties () {
76+ if (_range.__isset .file_type ) {
77+ // for compatibility
78+ _system_properties.system_type = _range.file_type ;
79+ } else {
80+ _system_properties.system_type = _params.file_type ;
81+ }
82+ _system_properties.properties = _params.properties ;
83+ _system_properties.hdfs_params = _params.hdfs_params ;
84+ if (_params.__isset .broker_addresses ) {
85+ _system_properties.broker_addresses .assign (_params.broker_addresses .begin (),
86+ _params.broker_addresses .end ());
87+ }
88+ }
89+
90+ } // namespace vectorized
91+ } // namespace doris
0 commit comments