For primitive types, two types are compatible if they have the same id. For nested types, two types are compatible if they have the same id and their children are also compatible. E.g. [NULL] is compatible with [1,2] E.g. {a: NULL, b: NULL} is compatible with {a: [1,2], b: ['c']}
| 287 | // E.g. [NULL] is compatible with [1,2] |
| 288 | // E.g. {a: NULL, b: NULL} is compatible with {a: [1,2], b: ['c']} |
| 289 | static bool compatible(const LogicalType& type, const LogicalType& target) { |
| 290 | if (type.isInternalType() != target.isInternalType()) { |
| 291 | return false; |
| 292 | } |
| 293 | if (type.getLogicalTypeID() == LogicalTypeID::ANY) { |
| 294 | return true; |
| 295 | } |
| 296 | if (type.getLogicalTypeID() != target.getLogicalTypeID()) { |
| 297 | return false; |
| 298 | } |
| 299 | switch (type.getLogicalTypeID()) { |
| 300 | case LogicalTypeID::LIST: { |
| 301 | return compatible(ListType::getChildType(type), ListType::getChildType(target)); |
| 302 | } |
| 303 | case LogicalTypeID::ARRAY: { |
| 304 | return compatible(ArrayType::getChildType(type), ArrayType::getChildType(target)); |
| 305 | } |
| 306 | case LogicalTypeID::STRUCT: { |
| 307 | if (StructType::getNumFields(type) != StructType::getNumFields(target)) { |
| 308 | return false; |
| 309 | } |
| 310 | for (auto i = 0u; i < StructType::getNumFields(type); ++i) { |
| 311 | if (!compatible(StructType::getField(type, i).getType(), |
| 312 | StructType::getField(target, i).getType())) { |
| 313 | return false; |
| 314 | } |
| 315 | } |
| 316 | return true; |
| 317 | } |
| 318 | case LogicalTypeID::DECIMAL: |
| 319 | case LogicalTypeID::UNION: |
| 320 | case LogicalTypeID::MAP: |
| 321 | case LogicalTypeID::NODE: |
| 322 | case LogicalTypeID::REL: |
| 323 | case LogicalTypeID::RECURSIVE_REL: |
| 324 | return false; |
| 325 | default: |
| 326 | return true; |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | // Handle special cases where value can be compatible to a type. This happens when a value is a |
| 331 | // nested value but does not have any child. |
no test coverage detected