MCPcopy Create free account
hub / github.com/apache/arrow / CommonTemporal

Function CommonTemporal

cpp/src/arrow/compute/kernels/codegen_internal.cc:269–348  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

267}
268
269TypeHolder CommonTemporal(const TypeHolder* begin, size_t count) {
270 TimeUnit::type finest_unit = TimeUnit::SECOND;
271 const std::string* timezone = nullptr;
272 bool saw_date32 = false;
273 bool saw_date64 = false;
274 bool saw_duration = false;
275 bool saw_time_since_midnight = false;
276 const TypeHolder* end = begin + count;
277 for (auto it = begin; it != end; it++) {
278 auto id = it->type->id();
279 // a common timestamp is only possible if all types are timestamp like
280 switch (id) {
281 case Type::DATE32:
282 // Date32's unit is days, but the coarsest we have is seconds
283 saw_date32 = true;
284 continue;
285 case Type::DATE64:
286 finest_unit = std::max(finest_unit, TimeUnit::MILLI);
287 saw_date64 = true;
288 continue;
289 case Type::TIMESTAMP: {
290 const auto& ty = checked_cast<const TimestampType&>(*it->type);
291 if (timezone && *timezone != ty.timezone()) return TypeHolder(nullptr);
292 timezone = &ty.timezone();
293 finest_unit = std::max(finest_unit, ty.unit());
294 continue;
295 }
296 case Type::TIME32: {
297 const auto& type = checked_cast<const Time32Type&>(*it->type);
298 finest_unit = std::max(finest_unit, type.unit());
299 saw_time_since_midnight = true;
300 continue;
301 }
302 case Type::TIME64: {
303 const auto& type = checked_cast<const Time64Type&>(*it->type);
304 finest_unit = std::max(finest_unit, type.unit());
305 saw_time_since_midnight = true;
306 continue;
307 }
308 case Type::DURATION: {
309 const auto& ty = checked_cast<const DurationType&>(*it->type);
310 finest_unit = std::max(finest_unit, ty.unit());
311 saw_duration = true;
312 continue;
313 }
314 default:
315 return TypeHolder(nullptr);
316 }
317 }
318
319 bool saw_timestamp_or_date = timezone || saw_date64 || saw_date32 || saw_duration;
320
321 if (saw_time_since_midnight && saw_timestamp_or_date) {
322 // Cannot find common type
323 return TypeHolder(nullptr);
324 }
325 if (saw_timestamp_or_date) {
326 if (timezone) {

Callers 6

DispatchBestMethod · 0.85
DispatchBestMethod · 0.85
DispatchBestMethod · 0.85
DispatchBestMethod · 0.85
DispatchBestMethod · 0.85
TESTFunction · 0.85

Calls 8

timezoneMethod · 0.80
TypeHolderClass · 0.50
timestampFunction · 0.50
durationFunction · 0.50
time32Function · 0.50
time64Function · 0.50
idMethod · 0.45
unitMethod · 0.45

Tested by 1

TESTFunction · 0.68