in backend/schema/validators/column_validator.cc [65:107]
bool IsAllowedTypeChange(const zetasql::Type* old_column_type,
const zetasql::Type* new_column_type) {
if (old_column_type->Equals(new_column_type)) {
return true;
}
if (old_column_type->IsArray() != new_column_type->IsArray()) {
return false;
}
if (old_column_type->IsArray()) {
return IsAllowedTypeChange(BaseType(old_column_type),
BaseType(new_column_type));
}
// Allow conversions from BYTES to STRING and STRING to BYTES.
if ((new_column_type->IsString() && old_column_type->IsBytes()) ||
(new_column_type->IsBytes() && old_column_type->IsString())) {
return true;
}
// Allow conversions from PROTO to BYTES and BYTES to PROTO
if ((new_column_type->IsProto() && old_column_type->IsBytes()) ||
(new_column_type->IsBytes() && old_column_type->IsProto())) {
return true;
}
// Allow conversion from PROTO to PROTO or enum to enum
if ((new_column_type->IsProto() && old_column_type->IsProto()) ||
(new_column_type->IsEnum() && old_column_type->IsEnum())) {
return true;
}
// Allow conversion from enum to INT64 and INT64 to enum (this should ideally
// be INT32 but since cloud spanner doesn't support INT32 columns we support
// INT64 here)
if ((new_column_type->IsInt64() && old_column_type->IsEnum()) ||
(new_column_type->IsEnum() && old_column_type->IsInt64())) {
return true;
}
return false;
}