forked from apache/doris
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtext_reader.cpp
More file actions
132 lines (112 loc) · 5.26 KB
/
Copy pathtext_reader.cpp
File metadata and controls
132 lines (112 loc) · 5.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// 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.
#include "text_reader.h"
#include <gen_cpp/PlanNodes_types.h>
#include <gen_cpp/Types_types.h>
#include <glog/logging.h>
#include "common/compiler_util.h" // IWYU pragma: keep
#include "common/status.h"
#include "exec/line_reader.h"
#include "io/file_factory.h"
#include "io/fs/buffered_reader.h"
#include "io/fs/file_reader.h"
#include "io/fs/s3_file_reader.h"
#include "runtime/descriptors.h"
#include "runtime/runtime_state.h"
#include "vec/core/block.h"
#include "vec/exec/format/csv/csv_reader.h"
#include "vec/exec/format/file_reader/new_plain_text_line_reader.h"
#include "vec/exec/scan/scanner.h"
namespace doris::vectorized {
#include "common/compile_check_begin.h"
void HiveTextFieldSplitter::do_split(const Slice& line, std::vector<Slice>* splitted_values) {
const char* data = line.data;
const size_t size = line.size;
size_t value_start = 0;
for (size_t i = 0; i < size; ++i) {
if (data[i] == _value_sep[0]) {
// hive will escape the field separator in string
if (_escape_char != 0 && i > 0 && data[i - 1] == _escape_char) {
continue;
}
process_value_func(data, value_start, i - value_start, _trimming_char, splitted_values);
value_start = i + _value_sep_len;
}
}
process_value_func(data, value_start, size - value_start, _trimming_char, splitted_values);
}
TextReader::TextReader(RuntimeState* state, RuntimeProfile* profile, ScannerCounter* counter,
const TFileScanRangeParams& params, const TFileRangeDesc& range,
const std::vector<SlotDescriptor*>& file_slot_descs, io::IOContext* io_ctx)
: CsvReader(state, profile, counter, params, range, file_slot_descs, io_ctx) {}
Status TextReader::_init_options() {
// get column_separator and line_delimiter
_value_separator = _params.file_attributes.text_params.column_separator;
_value_separator_length = _value_separator.size();
_line_delimiter = _params.file_attributes.text_params.line_delimiter;
_line_delimiter_length = _line_delimiter.size();
if (_params.file_attributes.text_params.__isset.escape) {
_escape = _params.file_attributes.text_params.escape;
}
_options.escape_char = _escape;
_options.collection_delim = _params.file_attributes.text_params.collection_delimiter[0];
_options.map_key_delim = _params.file_attributes.text_params.mapkv_delimiter[0];
_options.null_format = _params.file_attributes.text_params.null_format.data();
_options.null_len = _params.file_attributes.text_params.null_format.length();
return Status::OK();
}
Status TextReader::_deserialize_one_cell(DataTypeSerDeSPtr serde, IColumn& column, Slice& slice) {
return serde->deserialize_one_cell_from_hive_text(column, slice, _options);
}
Status TextReader::_create_line_reader() {
std::shared_ptr<TextLineReaderContextIf> text_line_reader_ctx;
text_line_reader_ctx = std::make_shared<PlainTextLineReaderCtx>(_line_delimiter,
_line_delimiter_length, false);
_fields_splitter = std::make_unique<HiveTextFieldSplitter>(
false, false, _value_separator, _value_separator_length, -1, _escape);
_line_reader =
NewPlainTextLineReader::create_unique(_profile, _file_reader, _decompressor.get(),
text_line_reader_ctx, _size, _start_offset);
return Status::OK();
}
Status TextReader::_validate_line(const Slice& line, bool* success) {
// text file do not need utf8 check
*success = true;
return Status::OK();
}
Status TextReader::_deserialize_nullable_string(IColumn& column, Slice& slice) {
auto& null_column = assert_cast<ColumnNullable&>(column);
if (_options.null_len > 0) {
if (slice.compare(Slice(_options.null_format, _options.null_len)) == 0) {
null_column.insert_data(nullptr, 0);
return Status::OK();
}
}
static DataTypeStringSerDe stringSerDe;
auto st = stringSerDe.deserialize_one_cell_from_hive_text(null_column.get_nested_column(),
slice, _options);
if (!st.ok()) {
// fill null if fail
null_column.insert_data(nullptr, 0); // 0 is meaningless here
return Status::OK();
}
// fill not null if success
null_column.get_null_map_data().push_back(0);
return Status::OK();
}
#include "common/compile_check_end.h"
} // namespace doris::vectorized