in zetasql-toolkit-core/src/main/java/com/google/zetasql/toolkit/Coercer.java [470:509]
public boolean coercesTo(Type fromType, Type toType, boolean isLiteral, boolean isParameter) {
if (fromType.isStruct()) {
return structCoercesTo((StructType) fromType, toType, isLiteral, isParameter);
}
if (fromType.isArray()) {
return arrayCoercesTo((ArrayType) fromType, toType, isLiteral, isParameter);
}
if (!fromType.isSimpleType() && !toType.isSimpleType()) {
return fromType.equivalent(toType);
}
TypeKind fromKind = fromType.getKind();
TypeKind toKind = toType.getKind();
Optional<CoercionMode> maybeCoercionMode =
supportedTypeCoercions.stream()
.filter(
typeCoercion ->
typeCoercion.fromKind.equals(fromKind) && typeCoercion.toKind.equals(toKind))
.map(typeCoercion -> typeCoercion.coercionMode)
.findFirst();
if (!maybeCoercionMode.isPresent()) {
return false;
}
CoercionMode coercionMode = maybeCoercionMode.get();
if (isLiteral && supportsLiteralCoercion(coercionMode)) {
return true;
}
if (isParameter && supportsParameterCoercion(coercionMode)) {
return true;
}
return supportsImplicitCoercion(coercionMode);
}