private static void processFieldMappingsInFunctionDef()

in runtime/src/main/java/com/google/cloud/verticals/foundations/dataharmonization/builtins/options/UniqueVarAndFieldsExperiment.java [127:181]


  private static void processFieldMappingsInFunctionDef(
      FileInfo fileInfo,
      FunctionDefinition functionDefinition,
      Map<String, FunctionDefinition> blockIdToFunctionDefinitions,
      Map<String, TypeAndSource> fieldVarSourceMap,
      Set<String> functionDefinitionsProcessed,
      MetaData metaData) {

    for (FieldMapping mapping : functionDefinition.getMappingList()) {
      // Handle nested blocks, which are represented as functionCalls
      if (mapping.getValue().hasFunctionCall()) {
        FunctionCall fc = mapping.getValue().getFunctionCall();
        String functionReferenceId = fc.getReference().getName();
        FunctionDefinition referenceFunctionDefinition =
            blockIdToFunctionDefinitions.getOrDefault(functionReferenceId, null);

        if (referenceFunctionDefinition != null
            && referenceFunctionDefinition.getInheritParentVars()) {
          // This reference function def allows variable inheritance, so we recursively process it
          processFieldMappingsInFunctionDef(
              fileInfo,
              referenceFunctionDefinition,
              blockIdToFunctionDefinitions,
              fieldVarSourceMap,
              functionDefinitionsProcessed,
              metaData);
        }

        for (ValueSource vs : fc.getArgsList()) {
          // Handle args that are function calls, ex ternary blocks
          if (vs.hasFunctionCall()) {
            String argFunctionReferenceId = vs.getFunctionCall().getReference().getName();
            referenceFunctionDefinition =
                blockIdToFunctionDefinitions.getOrDefault(argFunctionReferenceId, null);

            if (referenceFunctionDefinition != null
                && referenceFunctionDefinition.getInheritParentVars()) {
              // Recursively process this function def
              processFieldMappingsInFunctionDef(
                  fileInfo,
                  referenceFunctionDefinition,
                  blockIdToFunctionDefinitions,
                  fieldVarSourceMap,
                  functionDefinitionsProcessed,
                  metaData);
            }
          }
        }
      } else {
        // Handle fields and vars in this mapping
        checkFieldsAndVarsInMappings(fileInfo, mapping, fieldVarSourceMap, metaData);
      }
    }
    functionDefinitionsProcessed.add(functionDefinition.getName());
  }