MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / executeType

Method executeType

src/Functions/dateName.cpp:135–204  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

133
134 template <typename DataType>
135 ColumnPtr executeType(const ColumnsWithTypeAndName & arguments, const DataTypePtr &, size_t input_rows_count) const
136 {
137 auto * times = checkAndGetColumn<typename DataType::ColumnType>(arguments[1].column.get());
138 if (!times)
139 return nullptr;
140
141 const ColumnConst * date_part_column = checkAndGetColumnConst<ColumnString>(arguments[0].column.get());
142 if (!date_part_column)
143 throw Exception(
144 ErrorCodes::ILLEGAL_COLUMN,
145 "Illegal column {} of first ('datepart') argument of function {}. Must be constant string.",
146 arguments[0].column->getName(),
147 getName());
148
149 String date_part = date_part_column->getValue<String>();
150
151 const DateLUTImpl * time_zone_tmp = nullptr;
152 if constexpr (std::is_same_v<DataType, DataTypeDateTime64> || std::is_same_v<DataType, DataTypeDateTime>)
153 time_zone_tmp = &extractTimeZoneFromFunctionArguments(arguments, 2, 1);
154 else
155 time_zone_tmp = &DateLUT::instance();
156
157 const auto & times_data = times->getData();
158 const DateLUTImpl & time_zone = *time_zone_tmp;
159
160 UInt32 scale [[maybe_unused]] = 0;
161 if constexpr (std::is_same_v<DataType, DataTypeDateTime64>)
162 {
163 scale = times->getScale();
164 }
165
166 auto result_column = ColumnString::create();
167 auto & result_column_data = result_column->getChars();
168 auto & result_column_offsets = result_column->getOffsets();
169
170 /* longest possible word, 'Wednesday' */
171 static constexpr size_t longest_word_length = 9;
172
173 result_column_data.resize_fill(times_data.size() * longest_word_length);
174 result_column_offsets.resize(times_data.size());
175
176 auto * begin = reinterpret_cast<char *>(result_column_data.data());
177
178 WriteBufferFromPointer buffer(begin, result_column_data.size());
179
180 using TimeType = DateTypeToTimeType<DataType>;
181 callOnDatePartWriter<TimeType>(date_part, [&](const auto & writer)
182 {
183 for (size_t i = 0; i < input_rows_count; ++i)
184 {
185 if constexpr (std::is_same_v<DataType, DataTypeDateTime64>)
186 {
187 const auto components = DecimalUtils::split(times_data[i], scale);
188 writer.write(buffer, static_cast<Int64>(components.whole), time_zone);
189 }
190 else
191 {
192 writer.write(buffer, times_data[i], time_zone);

Callers

nothing calls this directly

Calls 15

resize_fillMethod · 0.80
getNameFunction · 0.70
createFunction · 0.70
splitFunction · 0.70
ExceptionClass · 0.50
getMethod · 0.45
getNameMethod · 0.45
getDataMethod · 0.45
getScaleMethod · 0.45
getCharsMethod · 0.45
getOffsetsMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected