---
policy: /ce/ca/aws/elb/load-balancer-unused
logic: /ce/ca/aws/elb/load-balancer-unused/prod.logic.yaml
executionTime: 2025-10-01T12:45:31.47192324Z
generationMs: 101
executionMs: 882
rows:
  - id: '001'
    match: true
    status:
      expected: DISAPPEARED
      actual: DISAPPEARED
    conditionIndex:
      expected: 99
      actual: 99
    conditionText:
      expected: isDisappeared(CA10__disappearanceTime__c)
      actual: isDisappeared(CA10__disappearanceTime__c)
    runtimeError: {}
  - id: '002'
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: CA10__AWS_EC2_Load_Balancer_Listeners__r.hasNo(COMPLIANT)
      actual: CA10__AWS_EC2_Load_Balancer_Listeners__r.hasNo(COMPLIANT)
    runtimeError: {}
  - id: '003'
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: CA10__instanceLinks__r.hasNo(COMPLIANT)
      actual: CA10__instanceLinks__r.hasNo(COMPLIANT)
    runtimeError: {}
  - id: '004'
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 300
      actual: 300
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/elb/load-balancer-unused/policy.yaml
    md5Hash: 3013B397CFDC9150CDE7CBE2A2236896
    content: |-
      ---
      names:
        full: "AWS ELB Load Balancer is unused"
        contextual: "Load Balancer is unused"
      description: "Ensure that AWS Elastic Load Balancers are actively serving traffic.\
        \ A load balancer is considered unused if it has no listeners configured or\
        \ no healthy instances or targets registered. Unused load balancers can incur\
        \ costs without providing any benefit and may represent a misconfiguration in\
        \ the environment."
      type: "COMPLIANCE_POLICY"
      categories:
        - "COST"
      frameworkMappings:
        - "/frameworks/cloudaware/cost-efficiency-and-optimization/waste-reduction"
  - path: /ce/ca/aws/elb/load-balancer-unused/prod.logic.yaml
    md5Hash: 890EDAA5C1244835F92031BADDD05526
    content: |
      ---
      inputType: "CA10__CaAwsLoadBalancer__c"
      testData:
        - file: 'test-data.json'
      conditions:
        - status: "INCOMPLIANT"
          currentStateMessage: "The Load Balancer has no listeners."
          remediationMessage: "Consider adding listeners to the Load Balancer or deleting it if it is no longer needed."
          check:
            RELATED_LIST_HAS_NO:
              status: "COMPLIANT"
              relationshipName: "CA10__AWS_EC2_Load_Balancer_Listeners__r"
        - status: "INCOMPLIANT"
          currentStateMessage: "The Load Balancer has no registered targets."
          remediationMessage: "Ensure that the instances or targets in the target groups are healthy, or delete the Load Balancer if it is no longer needed."
          check:
            RELATED_LIST_HAS_NO:
              status: "COMPLIANT"
              relationshipName: "CA10__instanceLinks__r"
      otherwise:
        status: "COMPLIANT"
        currentStateMessage: "The Load Balancer is used."
      relatedLists:
        - relationshipName: "CA10__AWS_EC2_Load_Balancer_Listeners__r"
          conditions: []
          otherwise:
            status: COMPLIANT
            currentStateMessage: "This is an Load Balancer listener."
        - relationshipName: "CA10__instanceLinks__r"
          conditions: []
          otherwise:
            status: "COMPLIANT"
            currentStateMessage: "This is a target instance."
  - path: /ce/ca/aws/elb/load-balancer-unused/test-data.json
    md5Hash: 3E1DFD4D477170002393D0AF6A5D5B64
    content: |-
      [
        {
          "expectedResult": {
            "status": "DISAPPEARED",
            "conditionIndex": "99",
            "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
            "runtimeError": null
          },
          "context": {
            "snapshotTime": "2025-09-10T17:26:32Z"
          },
          "Id": "001",
          "RecordTypeId": "RecordTypeId1",
          "CA10__disappearanceTime__c": "2025-09-01T08:53:31Z",
          "RecordType": {
            "DeveloperName": "caAwsLoadBalancerApplication",
            "Id": "RecordTypeId1"
          },
          "CA10__AWS_EC2_Load_Balancer_Listeners__r": [
            {
              "Id": "001_1",
              "RecordTypeId": "RecordTypeId2",
              "CA10__disappearanceTime__c": "2025-09-01T09:08:27Z",
              "CA10__loadBalancer__c": "001",
              "RecordType": {
                "DeveloperName": "caAwsLoadBalancerListenerApplication",
                "Id": "RecordTypeId2"
              }
            }
          ],
          "CA10__instanceLinks__r": [
            {
              "Id": "001_2",
              "RecordTypeId": "RecordTypeId3",
              "CA10__disappearanceTime__c": "2025-09-01T11:20:43Z",
              "CA10__state__c": "unhealthy",
              "CA10__loadBalancer__c": "001",
              "RecordType": {
                "DeveloperName": "caAwsLoadBalancerInstanceLinkApplication",
                "Id": "RecordTypeId3"
              }
            }
          ]
        },
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "199",
            "conditionText": "CA10__AWS_EC2_Load_Balancer_Listeners__r.hasNo(COMPLIANT)",
            "runtimeError": null
          },
          "context": {
            "snapshotTime": "2025-09-10T17:26:32Z"
          },
          "Id": "002",
          "RecordTypeId": "RecordTypeId1",
          "CA10__disappearanceTime__c": null,
          "RecordType": {
            "DeveloperName": "caAwsLoadBalancerApplication",
            "Id": "RecordTypeId1"
          },
          "CA10__AWS_EC2_Load_Balancer_Listeners__r": [],
          "CA10__instanceLinks__r": []
        },
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "299",
            "conditionText": "CA10__instanceLinks__r.hasNo(COMPLIANT)",
            "runtimeError": null
          },
          "context": {
            "snapshotTime": "2025-09-10T17:26:32Z"
          },
          "Id": "003",
          "RecordTypeId": "RecordTypeId1",
          "CA10__disappearanceTime__c": null,
          "RecordType": {
            "DeveloperName": "caAwsLoadBalancerApplication",
            "Id": "RecordTypeId1"
          },
          "CA10__AWS_EC2_Load_Balancer_Listeners__r": [
            {
              "Id": "003_1",
              "RecordTypeId": "RecordTypeId2",
              "CA10__disappearanceTime__c": null,
              "CA10__loadBalancer__c": "003",
              "RecordType": {
                "DeveloperName": "caAwsLoadBalancerListenerApplication",
                "Id": "RecordTypeId2"
              }
            }
          ],
          "CA10__instanceLinks__r": []
        },
        {
          "expectedResult": {
            "status": "COMPLIANT",
            "conditionIndex": "300",
            "conditionText": "otherwise",
            "runtimeError": null
          },
          "context": {
            "snapshotTime": "2025-09-10T17:26:32Z"
          },
          "Id": "004",
          "RecordTypeId": "RecordTypeId1",
          "CA10__disappearanceTime__c": null,
          "RecordType": {
            "DeveloperName": "caAwsLoadBalancerApplication",
            "Id": "RecordTypeId1"
          },
          "CA10__AWS_EC2_Load_Balancer_Listeners__r": [
            {
              "Id": "004_1",
              "RecordTypeId": "RecordTypeId2",
              "CA10__disappearanceTime__c": null,
              "CA10__loadBalancer__c": "004",
              "RecordType": {
                "DeveloperName": "caAwsLoadBalancerListenerApplication",
                "Id": "RecordTypeId2"
              }
            }
          ],
          "CA10__instanceLinks__r": [
            {
              "Id": "004_2",
              "RecordTypeId": "RecordTypeId3",
              "CA10__disappearanceTime__c": null,
              "CA10__state__c": "healthy",
              "CA10__loadBalancer__c": "004",
              "RecordType": {
                "DeveloperName": "caAwsLoadBalancerInstanceLinkApplication",
                "Id": "RecordTypeId3"
              }
            }
          ]
        }
      ]
script: |-
  CREATE TEMP FUNCTION mock_ExpectedResult()
  RETURNS ARRAY<STRUCT<
          Id STRING,
          expectedResult STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, runtimeError STRING>
      >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "Id" : "001",
    "expectedResult" : {
      "status" : "DISAPPEARED",
      "conditionIndex" : "99",
      "conditionText" : "isDisappeared(CA10__disappearanceTime__c)",
      "runtimeError" : null
    }
  }, {
    "Id" : "002",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "CA10__AWS_EC2_Load_Balancer_Listeners__r.hasNo(COMPLIANT)",
      "runtimeError" : null
    }
  }, {
    "Id" : "003",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "CA10__instanceLinks__r.hasNo(COMPLIANT)",
      "runtimeError" : null
    }
  }, {
    "Id" : "004",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "300",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsLoadBalancer__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      RecordTypeId STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-09-10T17:26:32Z")
    },
    "Id" : "001",
    "RecordTypeId" : "RecordTypeId1",
    "CA10__disappearanceTime__c" : new Date("2025-09-01T08:53:31Z")
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-09-10T17:26:32Z")
    },
    "Id" : "002",
    "RecordTypeId" : "RecordTypeId1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-09-10T17:26:32Z")
    },
    "Id" : "003",
    "RecordTypeId" : "RecordTypeId1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-09-10T17:26:32Z")
    },
    "Id" : "004",
    "RecordTypeId" : "RecordTypeId1"
  } ];
  """;

  CREATE TEMP FUNCTION mock_RecordType()
  RETURNS ARRAY<STRUCT<
      DeveloperName STRING,
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-09-10T17:26:32Z")
    },
    "DeveloperName" : "caAwsLoadBalancerApplication",
    "Id" : "RecordTypeId1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-09-10T17:26:32Z")
    },
    "DeveloperName" : "caAwsLoadBalancerListenerApplication",
    "Id" : "RecordTypeId2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-09-10T17:26:32Z")
    },
    "DeveloperName" : "caAwsLoadBalancerInstanceLinkApplication",
    "Id" : "RecordTypeId3"
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsLoadBalancerListener__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      RecordTypeId STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__loadBalancer__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-09-10T17:26:32Z")
    },
    "Id" : "001_1",
    "RecordTypeId" : "RecordTypeId2",
    "CA10__disappearanceTime__c" : new Date("2025-09-01T09:08:27Z"),
    "CA10__loadBalancer__c" : "001"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-09-10T17:26:32Z")
    },
    "Id" : "003_1",
    "RecordTypeId" : "RecordTypeId2",
    "CA10__loadBalancer__c" : "003"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-09-10T17:26:32Z")
    },
    "Id" : "004_1",
    "RecordTypeId" : "RecordTypeId2",
    "CA10__loadBalancer__c" : "004"
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsLoadBalancerInstanceLink__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      RecordTypeId STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__loadBalancer__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-09-10T17:26:32Z")
    },
    "Id" : "001_2",
    "RecordTypeId" : "RecordTypeId3",
    "CA10__disappearanceTime__c" : new Date("2025-09-01T11:20:43Z"),
    "CA10__loadBalancer__c" : "001"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-09-10T17:26:32Z")
    },
    "Id" : "004_2",
    "RecordTypeId" : "RecordTypeId3",
    "CA10__loadBalancer__c" : "004"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAwsLoadBalancer__c(
      obj STRUCT<
          Id STRING,
          RecordTypeId STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          RecordType STRUCT<
              DeveloperName STRING,
              Id STRING
          >,
          CA10__AWS_EC2_Load_Balancer_Listeners__r ARRAY<STRUCT<
              Id STRING,
              RecordTypeId STRING,
              CA10__disappearanceTime__c TIMESTAMP,
              CA10__loadBalancer__c STRING,
              RecordType STRUCT<
                  DeveloperName STRING,
                  Id STRING
              >,
              result STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, currentStateMessage STRING, currentStateReferences STRING, remediation STRING, runtimeError STRING>
          >>,
          CA10__instanceLinks__r ARRAY<STRUCT<
              Id STRING,
              RecordTypeId STRING,
              CA10__disappearanceTime__c TIMESTAMP,
              CA10__loadBalancer__c STRING,
              RecordType STRUCT<
                  DeveloperName STRING,
                  Id STRING
              >,
              result STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, currentStateMessage STRING, currentStateReferences STRING, remediation STRING, runtimeError STRING>
          >>
      >,
      snapshotTime TIMESTAMP
  )
  RETURNS STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, currentStateMessage STRING, currentStateReferences STRING, remediation STRING, runtimeError STRING>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
      var references1 = [];
      // condition[0], conditionIndex:[0..99]
      references1.push('Deleted From AWS [CA10__disappearanceTime__c]: ' + obj.CA10__disappearanceTime__c);
      if (obj.CA10__disappearanceTime__c != null) {
          return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared(CA10__disappearanceTime__c)", currentStateMessage: "Object is deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      var count_CA10__AWS_EC2_Load_Balancer_Listeners__r_COMPLIANT2 = 0;
      if (obj.CA10__AWS_EC2_Load_Balancer_Listeners__r != null) {
          for (var i3 = 0; i3 < obj.CA10__AWS_EC2_Load_Balancer_Listeners__r.length; i3++) {
              if (obj.CA10__AWS_EC2_Load_Balancer_Listeners__r[i3].result.status == 'COMPLIANT') {
                  count_CA10__AWS_EC2_Load_Balancer_Listeners__r_COMPLIANT2 += 1;
              }
          }
      }
      // condition[1], conditionIndex:[100..199]
      references1.push('Related list [CA10__AWS_EC2_Load_Balancer_Listeners__r] ' + (count_CA10__AWS_EC2_Load_Balancer_Listeners__r_COMPLIANT2 == 0 ? 'does not have' : 'has') + ' objects in COMPLIANT status');
      if (count_CA10__AWS_EC2_Load_Balancer_Listeners__r_COMPLIANT2 == 0) {
          return {status: 'INCOMPLIANT', conditionIndex: 199, conditionText: "CA10__AWS_EC2_Load_Balancer_Listeners__r.hasNo(COMPLIANT)", currentStateMessage: "The Load Balancer has no listeners.", currentStateReferences: references1.join('\n'), remediation: "Consider adding listeners to the Load Balancer or deleting it if it is no longer needed.", runtimeError: null};
      }
      var count_CA10__instanceLinks__r_COMPLIANT4 = 0;
      if (obj.CA10__instanceLinks__r != null) {
          for (var i5 = 0; i5 < obj.CA10__instanceLinks__r.length; i5++) {
              if (obj.CA10__instanceLinks__r[i5].result.status == 'COMPLIANT') {
                  count_CA10__instanceLinks__r_COMPLIANT4 += 1;
              }
          }
      }
      // condition[2], conditionIndex:[200..299]
      references1.push('Related list [CA10__instanceLinks__r] ' + (count_CA10__instanceLinks__r_COMPLIANT4 == 0 ? 'does not have' : 'has') + ' objects in COMPLIANT status');
      if (count_CA10__instanceLinks__r_COMPLIANT4 == 0) {
          return {status: 'INCOMPLIANT', conditionIndex: 299, conditionText: "CA10__instanceLinks__r.hasNo(COMPLIANT)", currentStateMessage: "The Load Balancer has no registered targets.", currentStateReferences: references1.join('\n'), remediation: "Ensure that the instances or targets in the target groups are healthy, or delete the Load Balancer if it is no longer needed.", runtimeError: null};
      }
      return {status: 'COMPLIANT', conditionIndex: 300, conditionText: "otherwise", currentStateMessage: "The Load Balancer is used.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
  """;

  CREATE TEMP FUNCTION process_CA10__AWS_EC2_Load_Balancer_Listeners__r(
      obj STRUCT<
          Id STRING,
          RecordTypeId STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__loadBalancer__c STRING,
          RecordType STRUCT<
              DeveloperName STRING,
              Id STRING
          >
      >,
      snapshotTime TIMESTAMP
  )
  RETURNS STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, currentStateMessage STRING, currentStateReferences STRING, remediation STRING, runtimeError STRING>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
      var references1 = [];
      // condition[0], conditionIndex:[0..99]
      references1.push('Deleted From AWS [CA10__disappearanceTime__c]: ' + obj.CA10__disappearanceTime__c);
      if (obj.CA10__disappearanceTime__c != null) {
          return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared(CA10__disappearanceTime__c)", currentStateMessage: "Object is deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      return {status: 'COMPLIANT', conditionIndex: 100, conditionText: "otherwise", currentStateMessage: "This is an Load Balancer listener.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
  """;

  CREATE TEMP FUNCTION process_CA10__instanceLinks__r(
      obj STRUCT<
          Id STRING,
          RecordTypeId STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__loadBalancer__c STRING,
          RecordType STRUCT<
              DeveloperName STRING,
              Id STRING
          >
      >,
      snapshotTime TIMESTAMP
  )
  RETURNS STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, currentStateMessage STRING, currentStateReferences STRING, remediation STRING, runtimeError STRING>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
      var references1 = [];
      // condition[0], conditionIndex:[0..99]
      references1.push('Deleted From AWS [CA10__disappearanceTime__c]: ' + obj.CA10__disappearanceTime__c);
      if (obj.CA10__disappearanceTime__c != null) {
          return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared(CA10__disappearanceTime__c)", currentStateMessage: "Object is deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      return {status: 'COMPLIANT', conditionIndex: 100, conditionText: "otherwise", currentStateMessage: "This is a target instance.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
  """;


  SELECT
    expectedResult.Id as Id,
    IF (
      IFNULL(expectedResult.expectedResult.status, '') = IFNULL(sObject.result.status, '')
      AND IFNULL(expectedResult.expectedResult.conditionIndex, -1) = IFNULL(sObject.result.conditionIndex, -1)
      AND IFNULL(expectedResult.expectedResult.conditionText, '') = IFNULL(sObject.result.conditionText, '')
      AND IFNULL(expectedResult.expectedResult.runtimeError, '') = IFNULL(sObject.result.runtimeError, ''),
      "MATCH",
      "FAIL"
    ) as match,
    expectedResult.expectedResult.status as expectedStatus, sObject.result.status as actualStatus,
    expectedResult.expectedResult.conditionIndex as expectedConditionIndex, sObject.result.conditionIndex as actualConditionIndex,
    expectedResult.expectedResult.conditionText as expectedConditionText, sObject.result.conditionText as actualConditionText,
    expectedResult.expectedResult.runtimeError as expectedRuntimeError, sObject.result.runtimeError as actualRuntimeError
  FROM UNNEST(mock_ExpectedResult()) expectedResult
  LEFT JOIN (
      SELECT
          sObject.Id AS Id,
          sObject.RecordTypeId AS RecordTypeId,
          sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
          STRUCT (
              `RecordType`.DeveloperName AS DeveloperName,
              `RecordType`.Id AS Id
          ) AS RecordType,
          `CA10__AWS_EC2_Load_Balancer_Listeners__r`.arr AS CA10__AWS_EC2_Load_Balancer_Listeners__r,
          `CA10__instanceLinks__r`.arr AS CA10__instanceLinks__r,
          process_CA10__CaAwsLoadBalancer__c(
              STRUCT(
                  sObject.Id AS Id,
                  sObject.RecordTypeId AS RecordTypeId,
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  STRUCT (
                      `RecordType`.DeveloperName AS DeveloperName,
                      `RecordType`.Id AS Id
                  ) AS RecordType,
                  `CA10__AWS_EC2_Load_Balancer_Listeners__r`.arr AS CA10__AWS_EC2_Load_Balancer_Listeners__r,
                  `CA10__instanceLinks__r`.arr AS CA10__instanceLinks__r
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAwsLoadBalancer__c()) AS sObject
      LEFT JOIN UNNEST(mock_RecordType()) AS `RecordType`
          ON sObject.RecordTypeId = `RecordType`.Id
      LEFT JOIN (
          SELECT
              sObject.CA10__loadBalancer__c,
              ARRAY_AGG(
                  STRUCT(
                      sObject.Id AS Id,
                      sObject.RecordTypeId AS RecordTypeId,
                      sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                      sObject.CA10__loadBalancer__c AS CA10__loadBalancer__c,
                      STRUCT (
                          `RecordType`.DeveloperName AS DeveloperName,
                          `RecordType`.Id AS Id
                      ) AS RecordType,
                      process_CA10__AWS_EC2_Load_Balancer_Listeners__r(
                          STRUCT(
                              sObject.Id AS Id,
                              sObject.RecordTypeId AS RecordTypeId,
                              sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                              sObject.CA10__loadBalancer__c AS CA10__loadBalancer__c,
                              STRUCT (
                                  `RecordType`.DeveloperName AS DeveloperName,
                                  `RecordType`.Id AS Id
                              ) AS RecordType
                          ),
                          sObject.context.snapshotTime
                      ) as result
                  )
              ) AS arr
          FROM UNNEST(mock_CA10__CaAwsLoadBalancerListener__c()) AS sObject
          LEFT JOIN UNNEST(mock_RecordType()) AS `RecordType`
              ON sObject.RecordTypeId = `RecordType`.Id
          GROUP BY sObject.CA10__loadBalancer__c
      ) AS `CA10__AWS_EC2_Load_Balancer_Listeners__r`
          ON sObject.Id = `CA10__AWS_EC2_Load_Balancer_Listeners__r`.CA10__loadBalancer__c
      LEFT JOIN (
          SELECT
              sObject.CA10__loadBalancer__c,
              ARRAY_AGG(
                  STRUCT(
                      sObject.Id AS Id,
                      sObject.RecordTypeId AS RecordTypeId,
                      sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                      sObject.CA10__loadBalancer__c AS CA10__loadBalancer__c,
                      STRUCT (
                          `RecordType`.DeveloperName AS DeveloperName,
                          `RecordType`.Id AS Id
                      ) AS RecordType,
                      process_CA10__instanceLinks__r(
                          STRUCT(
                              sObject.Id AS Id,
                              sObject.RecordTypeId AS RecordTypeId,
                              sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                              sObject.CA10__loadBalancer__c AS CA10__loadBalancer__c,
                              STRUCT (
                                  `RecordType`.DeveloperName AS DeveloperName,
                                  `RecordType`.Id AS Id
                              ) AS RecordType
                          ),
                          sObject.context.snapshotTime
                      ) as result
                  )
              ) AS arr
          FROM UNNEST(mock_CA10__CaAwsLoadBalancerInstanceLink__c()) AS sObject
          LEFT JOIN UNNEST(mock_RecordType()) AS `RecordType`
              ON sObject.RecordTypeId = `RecordType`.Id
          GROUP BY sObject.CA10__loadBalancer__c
      ) AS `CA10__instanceLinks__r`
          ON sObject.Id = `CA10__instanceLinks__r`.CA10__loadBalancer__c
  ) sObject ON sObject.Id = expectedResult.Id;
