MCPcopy Create free account
hub / github.com/LadybugDB/ladybug / hasImplicitCast

Method hasImplicitCast

src/function/vector_cast_functions.cpp:256–298  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

254}
255
256bool CastFunction::hasImplicitCast(const LogicalType& srcType, const LogicalType& dstType) {
257 if (LogicalTypeUtils::isNested(srcType) && LogicalTypeUtils::isNested(dstType)) {
258 if (srcType.getLogicalTypeID() == LogicalTypeID::ARRAY &&
259 dstType.getLogicalTypeID() == LogicalTypeID::LIST) {
260 return hasImplicitCastArrayToList(srcType, dstType);
261 }
262 if (srcType.getLogicalTypeID() == LogicalTypeID::LIST &&
263 dstType.getLogicalTypeID() == LogicalTypeID::ARRAY) {
264 return hasImplicitCastListToArray(srcType, dstType);
265 }
266 if (srcType.getLogicalTypeID() != dstType.getLogicalTypeID()) {
267 return false;
268 }
269 switch (srcType.getLogicalTypeID()) {
270 case LogicalTypeID::LIST:
271 return hasImplicitCastList(srcType, dstType);
272 case LogicalTypeID::ARRAY:
273 return hasImplicitCastArray(srcType, dstType);
274 case LogicalTypeID::STRUCT:
275 return hasImplicitCastStruct(srcType, dstType);
276 case LogicalTypeID::UNION:
277 return hasImplicitCastUnion(srcType, dstType);
278 case LogicalTypeID::MAP:
279 return hasImplicitCastMap(srcType, dstType);
280 default:
281 // LCOV_EXCL_START
282 UNREACHABLE_CODE;
283 // LCOV_EXCL_END
284 }
285 } else if (dstType.getLogicalTypeID() == LogicalTypeID::UNION) {
286 return hasImplicitCastUnion(srcType, dstType);
287 }
288 if (BuiltInFunctionsUtils::getCastCost(srcType.getLogicalTypeID(),
289 dstType.getLogicalTypeID()) != UNDEFINED_CAST_COST) {
290 return true;
291 }
292 // TODO(Jiamin): there are still other special cases
293 // We allow cast between any numerical types
294 if (LogicalTypeUtils::isNumerical(srcType) && LogicalTypeUtils::isNumerical(dstType)) {
295 return true;
296 }
297 return false;
298}
299
300template<typename EXECUTOR = UnaryFunctionExecutor>
301static std::unique_ptr<ScalarFunction> bindCastFromStringFunction(const std::string& functionName,

Callers

nothing calls this directly

Calls 8

hasImplicitCastListFunction · 0.85
hasImplicitCastArrayFunction · 0.85
hasImplicitCastStructFunction · 0.85
hasImplicitCastUnionFunction · 0.85
hasImplicitCastMapFunction · 0.85
getLogicalTypeIDMethod · 0.80

Tested by

no test coverage detected