MCPcopy Create free account
hub / github.com/ByConity/ByConity / executeImpl

Method executeImpl

src/Functions/FunctionFile.cpp:76–162  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

74 bool useDefaultImplementationForConstants() const override { return true; }
75
76 ColumnPtr executeImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr & result_type, size_t input_rows_count) const override
77 {
78 const ColumnPtr column = arguments[0].column;
79 const ColumnString * column_src = checkAndGetColumn<ColumnString>(column.get());
80 if (!column_src)
81 throw Exception(ErrorCodes::ILLEGAL_COLUMN,
82 "Illegal column {} of argument of function {}", arguments[0].column->getName(), getName());
83
84 String default_result;
85
86 ColumnUInt8::MutablePtr col_null_map_to;
87 ColumnUInt8::Container * vec_null_map_to [[maybe_unused]] = nullptr;
88
89 if (arguments.size() == 2)
90 {
91 if (result_type->isNullable())
92 {
93 col_null_map_to = ColumnUInt8::create(input_rows_count, false);
94 vec_null_map_to = &col_null_map_to->getData();
95 }
96 else
97 {
98 const auto & default_column = arguments[1].column;
99 const ColumnConst * default_col = checkAndGetColumn<ColumnConst>(default_column.get());
100
101 if (!default_col)
102 throw Exception(ErrorCodes::ILLEGAL_COLUMN, "Illegal column {} of argument of function {}",
103 arguments[1].column->getName(), getName());
104
105 default_result = default_col->getValue<String>();
106 }
107 }
108
109 auto result = ColumnString::create();
110 auto & res_chars = result->getChars();
111 auto & res_offsets = result->getOffsets();
112
113 res_offsets.resize(input_rows_count);
114
115 fs::path user_files_absolute_path = fs::canonical(fs::path(getContext()->getUserFilesPath()));
116 std::string user_files_absolute_path_string = user_files_absolute_path.string();
117
118 // If run in Local mode, no need for path checking.
119 bool need_check = getContext()->getApplicationType() != Context::ApplicationType::LOCAL;
120
121 for (size_t row = 0; row < input_rows_count; ++row)
122 {
123 std::string_view filename = column_src->getDataAt(row).toView();
124 fs::path file_path(filename.data(), filename.data() + filename.size());
125
126 if (file_path.is_relative())
127 file_path = user_files_absolute_path / file_path;
128
129 /// Do not use fs::canonical or fs::weakly_canonical.
130 /// Otherwise it will not allow to work with symlinks in `user_files_path` directory.
131 file_path = fs::absolute(file_path).lexically_normal();
132
133 try

Callers

nothing calls this directly

Calls 15

getUserFilesPathMethod · 0.80
getApplicationTypeMethod · 0.80
toViewMethod · 0.80
getNameFunction · 0.70
createFunction · 0.70
ExceptionClass · 0.50
copyDataFunction · 0.50
getMethod · 0.45
getNameMethod · 0.45
sizeMethod · 0.45
isNullableMethod · 0.45
getDataMethod · 0.45

Tested by

no test coverage detected