in runtime/src/main/java/com/google/cloud/verticals/foundations/dataharmonization/builtins/options/UniqueVarAndFieldsExperiment.java [183:230]
private static void checkFieldsAndVarsInMappings(
FileInfo fileInfo,
FieldMapping m,
Map<String, TypeAndSource> fieldVarSourceMap,
MetaData metaData) {
String varOrFieldName = null;
String type = null;
if (m.hasVar() || m.hasField()) {
if (m.hasField()) {
varOrFieldName = m.getField().getPath();
type = FIELD_TYPE;
} else if (m.hasVar()) {
varOrFieldName = m.getVar().getName() + m.getVar().getPath();
type = VAR_TYPE;
}
Path path = Path.parse(varOrFieldName);
varOrFieldName = path.getSegments().get(0).toString();
Source source =
DebugInfo.getMetaEntry(
m.getMeta(), Source.getDescriptor().getFullName(), Source.class, UNKNOWN_SOURCE);
if (!fieldVarSourceMap.containsKey(varOrFieldName)) {
fieldVarSourceMap.put(varOrFieldName, new TypeAndSource(type, source));
} else {
// Found a var or field with the same name, check its type and see whether this is a
// conflict
// or a field or var update
TypeAndSource previousTypeAndSource = fieldVarSourceMap.get(varOrFieldName);
if (!previousTypeAndSource.getType().equals(type)) {
// Check whether a list to capture exceptions has been provided, as is done with the
// language server. If none is provided throw the exception, otherwise save the exception.
List<ImportException> exceptionsList = metaData.getMeta(IMPORT_EXCEPTION_LIST_KEY);
VarAndFieldOptionException varFieldOptionException =
new VarAndFieldOptionException(
fileInfo, varOrFieldName, source, type, previousTypeAndSource);
if (exceptionsList == null) {
throw varFieldOptionException;
}
exceptionsList.add(varFieldOptionException);
} else {
// Found the same type, either a field or var update. Update the map value to reflect
// this latest occurrence
fieldVarSourceMap.put(varOrFieldName, new TypeAndSource(type, source));
}
}
}
}