---
policy: /ce/ca/google/sql/instance-cost-effective-region
logic: /ce/ca/google/sql/instance-cost-effective-region/prod.logic.yaml
executionTime: 2025-10-01T12:50:55.903230671Z
generationMs: 61
executionMs: 621
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: 1299
      actual: 1299
    conditionText:
      expected: extract('CA10__regionName__c') == 'europe-west3'
      actual: extract('CA10__regionName__c') == 'europe-west3'
    runtimeError: {}
  - id: '003'
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 1600
      actual: 1600
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
usedFiles:
  - path: /ce/ca/google/sql/instance-cost-effective-region/policy.yaml
    md5Hash: 626DB8CAD9729AD87E750C991CE7407C
    content: |
      ---
      names:
        full: "Google Cloud SQL Instance is located in a less cost-effective region"
        contextual: "Instance is located in a less cost-effective region"
      description: "This policy flags SQL Instances that are running in Google regions\
        \ with higher pricing and could potentially be migrated to more cost-effective regions."
      type: "BEST_PRACTICE"
      categories:
        - "COST"
      frameworkMappings:
        - "/frameworks/cloudaware/cost-efficiency-and-optimization/resource-optimization"
  - path: /ce/ca/google/sql/instance-cost-effective-region/prod.logic.yaml
    md5Hash: 00DF825415029589406CC7F8D3C85432
    content: |
      ---
      inputType: "CA10__CaGoogleSqlInstance__c"
      importExtracts:
        - file: "/types/CA10__CaGoogleSqlInstance__c/object.extracts.yaml"
      testData:
        - file: 'test-data.json'
      conditions:
        - status: "INCOMPLIANT"
          currentStateMessage: "The Instance is running in us-west2 which is more expensive than us-west1."
          remediationMessage: "Consider migrating the Instance to us-west1."
          check:
            IS_EQUAL:
              left:
                EXTRACT: CA10__regionName__c
              right:
                TEXT: "us-west2"
        - status: "INCOMPLIANT"
          currentStateMessage: "The Instance is running in us-west3 which is more expensive than us-west1."
          remediationMessage: "Consider migrating the Instance to us-west1."
          check:
            IS_EQUAL:
              left:
                EXTRACT: CA10__regionName__c
              right:
                TEXT: "us-west3"
        - status: "INCOMPLIANT"
          currentStateMessage: "The Instance is running in us-west4 which is more expensive than us-west1."
          remediationMessage: "Consider migrating the Instance to us-west1."
          check:
            IS_EQUAL:
              left:
                EXTRACT: CA10__regionName__c
              right:
                TEXT: "us-west4"
        - status: "INCOMPLIANT"
          currentStateMessage: "The Instance is running in us-south1 which is more expensive than us-east1, us-east5 or us-central1."
          remediationMessage: "Consider migrating the Instance to us-east1, us-east5 or us-central1."
          check:
            IS_EQUAL:
              left:
                EXTRACT: CA10__regionName__c
              right:
                TEXT: "us-south1"
        - status: "INCOMPLIANT"
          currentStateMessage: "The Instance is running in northamerica-northeast1 which is more expensive than us-east1, us-east5 or us-central1."
          remediationMessage: "Consider migrating the Instance to us-east1, us-east5 or us-central1."
          check:
            IS_EQUAL:
              left:
                EXTRACT: CA10__regionName__c
              right:
                TEXT: "northamerica-northeast1"
        - status: "INCOMPLIANT"
          currentStateMessage: "The Instance is running in northamerica-northeast2 which is more expensive than us-east1, us-east5 or us-central1."
          remediationMessage: "Consider migrating the Instance to us-east1, us-east5 or us-central1."
          check:
            IS_EQUAL:
              left:
                EXTRACT: CA10__regionName__c
              right:
                TEXT: "northamerica-northeast2"
        - status: "INCOMPLIANT"
          currentStateMessage: "The Instance is running in europe-north1 which is more expensive than europe-north2 or europe-west1."
          remediationMessage: "Consider migrating the Instance to europe-north2 or europe-west1."
          check:
            IS_EQUAL:
              left:
                EXTRACT: CA10__regionName__c
              right:
                TEXT: "europe-north1"
        - status: "INCOMPLIANT"
          currentStateMessage: "The Instance is running in europe-southwest1 which is more expensive than europe-north2 or europe-west1."
          remediationMessage: "Consider migrating the Instance to europe-north2 or europe-west1."
          check:
            IS_EQUAL:
              left:
                EXTRACT: CA10__regionName__c
              right:
                TEXT: "europe-southwest1"
        - status: "INCOMPLIANT"
          currentStateMessage: "The Instance is running in europe-west1 which is more expensive than europe-north2 or europe-west1."
          remediationMessage: "Consider migrating the Instance to europe-north2 or europe-west1."
          check:
            IS_EQUAL:
              left:
                EXTRACT: CA10__regionName__c
              right:
                TEXT: "europe-west4"
        - status: "INCOMPLIANT"
          currentStateMessage: "The Instance is running in europe-west12 which is more expensive than europe-north2 or europe-west1."
          remediationMessage: "Consider migrating the Instance to europe-north2 or europe-west1."
          check:
            IS_EQUAL:
              left:
                EXTRACT: CA10__regionName__c
              right:
                TEXT: "europe-west12"
        - status: "INCOMPLIANT"
          currentStateMessage: "The Instance is running in europe-west2 which is more expensive than europe-north2 or europe-west1."
          remediationMessage: "Consider migrating the Instance to europe-north2 or europe-west1."
          check:
            IS_EQUAL:
              left:
                EXTRACT: CA10__regionName__c
              right:
                TEXT: "europe-west2"
        - status: "INCOMPLIANT"
          currentStateMessage: "The Instance is running in europe-west3 which is more expensive than europe-north2 or europe-west1."
          remediationMessage: "Consider migrating the Instance to europe-north2 or europe-west1."
          check:
            IS_EQUAL:
              left:
                EXTRACT: CA10__regionName__c
              right:
                TEXT: "europe-west3"
        - status: "INCOMPLIANT"
          currentStateMessage: "The Instance is running in europe-west6 which is more expensive than europe-north2 or europe-west1."
          remediationMessage: "Consider migrating the Instance to europe-north2 or europe-west1."
          check:
            IS_EQUAL:
              left:
                EXTRACT: CA10__regionName__c
              right:
                TEXT: "europe-west6"
        - status: "INCOMPLIANT"
          currentStateMessage: "The Instance is running in europe-west8 which is more expensive than europe-north2 or europe-west1."
          remediationMessage: "Consider migrating the Instance to europe-north2 or europe-west1."
          check:
            IS_EQUAL:
              left:
                EXTRACT: CA10__regionName__c
              right:
                TEXT: "europe-west8"
        - status: "INCOMPLIANT"
          currentStateMessage: "The Instance is running in europe-west9 which is more expensive than europe-north2 or europe-west1."
          remediationMessage: "Consider migrating the Instance to europe-north2 or europe-west1."
          check:
            IS_EQUAL:
              left:
                EXTRACT: CA10__regionName__c
              right:
                TEXT: "europe-west9"
      otherwise:
        status: "COMPLIANT"
        currentStateMessage: "The Instance is located in a cost-effective region."
  - path: /ce/ca/google/sql/instance-cost-effective-region/test-data.json
    md5Hash: 19D28E30904B65AA8F6061ECB7672E2F
    content: |
      [
        {
          "expectedResult": {
            "status": "DISAPPEARED",
            "conditionIndex": "99",
            "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-09-26T07:07:35Z" },
          "Id": "001",
          "CA10__disappearanceTime__c": "2023-11-29T10:24:08Z",
          "CA10__regionName__c": "us-east4"
        },
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "1299",
            "conditionText": "extract('CA10__regionName__c') == 'europe-west3'",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-09-26T07:07:35Z" },
          "Id": "002",
          "CA10__disappearanceTime__c": null,
          "CA10__regionName__c": "europe-west3"
        },
        {
          "expectedResult": {
            "status": "COMPLIANT",
            "conditionIndex": "1600",
            "conditionText": "otherwise",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-09-26T07:07:35Z" },
          "Id": "003",
          "CA10__disappearanceTime__c": null,
          "CA10__regionName__c": "us-east4"
        }
      ]
  - path: /types/CA10__CaGoogleSqlInstance__c/object.extracts.yaml
    md5Hash: 8DD86EFB2FFA06BD1E9BC0452FF2EC8A
    content: "---\nextracts:\n  - name: \"CA10__databaseVersion__c\"\n    value: \n\
      \      FIELD:\n        path: \"CA10__databaseVersion__c\"\n        undeterminedIf:\n\
      \          isEmpty:  \"Database version should not be empty\"\n  - name: \"\
      CA10__ipv4Enabled__c\"\n    value: \n      FIELD:\n        path: \"CA10__ipv4Enabled__c\"\
      \n        undeterminedIf:\n          isEmpty:  \"Ipv4Enabled should not be empty\"\
      \n  - name: \"caJsonFrom__databaseFlagsJson__c\"\n    value: \n      JSON_FROM:\n\
      \        arg:\n          FIELD:\n            path: CA10__databaseFlagsJson__c\n\
      \            returnType: BYTES\n        undeterminedIf:\n          isInvalid:\
      \ \"Database Flags JSON is invalid.\"\n          isEmpty: \"Database Flags JSON\
      \ is empty.\"\n  - name: \"caJsonText__databaseFlagsSkipShowDatabaseFlagValue__c\"\
      \n    value: \n      JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caJsonFrom__databaseFlagsJson__c\"\
      \n        expression: \"to_string([?name == 'skip_show_database'].value[] |\
      \ [0])\"\n        undeterminedIf:\n          evaluationError: \"The JSON query\
      \ has failed.\"\n          resultTypeMismatch: \"The JSON query did not return\
      \ text type.\"\n  - name: \"caJsonText__databaseFlagsLocalInfileFlagValue__c\"\
      \n    value: \n      JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caJsonFrom__databaseFlagsJson__c\"\
      \n        expression: \"to_string([?name == 'local_infile'].value[] | [0])\"\
      \n        undeterminedIf:\n          evaluationError: \"The JSON query has failed.\"\
      \n          resultTypeMismatch: \"The JSON query did not return text type.\"\
      \n  - name: \"caJsonText__databaseFlagsLogErrorVerbosityFlagValue__c\"\n   \
      \ value: \n      JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caJsonFrom__databaseFlagsJson__c\"\
      \n        expression:  \"to_string([?name == 'log_error_verbosity'].value[]\
      \ | [0])\"\n        undeterminedIf:\n          evaluationError: \"The JSON query\
      \ has failed.\"\n          resultTypeMismatch: \"The JSON query did not return\
      \ text type.\"\n  - name: \"caJsonText__databaseFlagsLogConnectionsFlagValue__c\"\
      \n    value: \n      JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caJsonFrom__databaseFlagsJson__c\"\
      \n        expression: \"to_string([?name == 'log_connections'].value[] | [0])\"\
      \n        undeterminedIf:\n          evaluationError: \"The JSON query has failed.\"\
      \n          resultTypeMismatch: \"The JSON query did not return text type.\"\
      \n  - name: \"caJsonText__databaseFlagsLogDisconnectionsFlagValue__c\"\n   \
      \ value: \n      JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caJsonFrom__databaseFlagsJson__c\"\
      \n        expression:  \"to_string([?name == 'log_disconnections'].value[] |\
      \ [0])\"\n        undeterminedIf:\n          evaluationError: \"The JSON query\
      \ has failed.\"\n          resultTypeMismatch: \"The JSON query did not return\
      \ text type.\"\n  - name: \"caJsonText__databaseFlagsLogStatementFlagValue__c\"\
      \n    value: \n      JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caJsonFrom__databaseFlagsJson__c\"\
      \n        expression: \"to_string([?name == 'log_statement'].value[] | [0])\"\
      \n        undeterminedIf:\n          evaluationError: \"The JSON query has failed.\"\
      \n          resultTypeMismatch: \"The JSON query did not return text type.\"\
      \n  - name: \"caJsonText__databaseFlagsLogMinMessagesFlagValue__c\"\n    value:\
      \ \n      JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caJsonFrom__databaseFlagsJson__c\"\
      \n        expression: \"to_string([?name == 'log_min_messages'].value[] | [0])\"\
      \n        undeterminedIf:\n          evaluationError: \"The JSON query has failed.\"\
      \n          resultTypeMismatch: \"The JSON query did not return text type.\"\
      \n  - name: \"caJsonText__databaseFlagsLogMinErrorStatementFlagValue__c\"\n\
      \    value: \n      JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caJsonFrom__databaseFlagsJson__c\"\
      \n        expression: \"to_string([?name == 'log_min_error_statement'].value[]\
      \ | [0])\"\n        undeterminedIf:\n          evaluationError: \"The JSON query\
      \ has failed.\"\n          resultTypeMismatch: \"The JSON query did not return\
      \ text type.\"\n  - name: \"caJsonText__databaseFlagsLogMinDurationStatementFlagValue__c\"\
      \n    value: \n      JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caJsonFrom__databaseFlagsJson__c\"\
      \n        expression: \"to_string([?name == 'log_min_duration_statement'].value[]\
      \ | [0])\"\n        undeterminedIf:\n          evaluationError: \"The JSON query\
      \ has failed.\"\n          resultTypeMismatch: \"The JSON query did not return\
      \ text type.\"\n  - name: \"caJsonText__databaseFlagsCloudsqlEnablePgauditFlagValue__c\"\
      \n    value: \n      JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caJsonFrom__databaseFlagsJson__c\"\
      \n        expression: \"to_string([?name == 'cloudsql.enable_pgaudit'].value[]\
      \ | [0])\"\n        undeterminedIf:\n          evaluationError: \"The JSON query\
      \ has failed.\"\n          resultTypeMismatch: \"The JSON query did not return\
      \ text type.\"\n  - name: \"caJsonText__databaseFlagsExternalScriptsEnabledFlagValue__c\"\
      \n    value: \n      JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caJsonFrom__databaseFlagsJson__c\"\
      \n        expression: \"to_string([?name == 'external scripts enabled'].value[]\
      \ | [0])\"\n        undeterminedIf:\n          evaluationError: \"The JSON query\
      \ has failed.\"\n          resultTypeMismatch: \"The JSON query did not return\
      \ text type.\"\n  - name: \"caJsonText__databaseFlagsCrossDbOwnershipChainingFlagValue__c\"\
      \n    value: \n      JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caJsonFrom__databaseFlagsJson__c\"\
      \n        expression: \"to_string([?name == 'cross db ownership chaining'].value[]\
      \ | [0])\"\n        undeterminedIf:\n          evaluationError: \"The JSON query\
      \ has failed.\"\n          resultTypeMismatch: \"The JSON query did not return\
      \ text type.\"\n\n  - name: \"caJsonText__databaseFlagsUserConnectionsFlagValue__c\"\
      \n    value: \n      JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caJsonFrom__databaseFlagsJson__c\"\
      \n        expression: \"to_string([?name == 'user connections'].value[] | [0])\"\
      \n        undeterminedIf:\n          evaluationError: \"The JSON query has failed.\"\
      \n          resultTypeMismatch: \"The JSON query did not return text type.\"\
      \n\n  - name: \"caJsonText__databaseFlagsUserOptionsFlagValue__c\"\n    value:\
      \ \n      JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caJsonFrom__databaseFlagsJson__c\"\
      \n        expression: \"to_string([?name == 'user options'].value[] | [0])\"\
      \n        undeterminedIf:\n          evaluationError: \"The JSON query has failed.\"\
      \n          resultTypeMismatch: \"The JSON query did not return text type.\"\
      \n  - name: \"caJsonText__databaseFlagsRemoteAccessFlagValue__c\"\n    value:\
      \ \n      JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caJsonFrom__databaseFlagsJson__c\"\
      \n        expression: \"to_string([?name == 'remote access'].value[] | [0])\"\
      \n        undeterminedIf:\n          evaluationError: \"The JSON query has failed.\"\
      \n          resultTypeMismatch: \"The JSON query did not return text type.\"\
      \n  - name: \"caJsonText__databaseFlags3625FlagValue__c\"\n    value: \n   \
      \   JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caJsonFrom__databaseFlagsJson__c\"\
      \n        expression: \"to_string([?name == '3625'].value[] | [0])\"\n     \
      \   undeterminedIf:\n          evaluationError: \"The JSON query has failed.\"\
      \n          resultTypeMismatch: \"The JSON query did not return text type.\"\
      \n  - name: \"caJsonText__databaseFlagsContainedDatabaseAuthenticationFlagValue__c\"\
      \n    value: \n      JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caJsonFrom__databaseFlagsJson__c\"\
      \n        expression: \"to_string([?name == 'contained database authentication'].value[]\
      \ | [0])\"\n        undeterminedIf:\n          evaluationError: \"The JSON query\
      \ has failed.\"\n          resultTypeMismatch: \"The JSON query did not return\
      \ text type.\"\n  - name: \"CA10__authorizedNetworksJson__c\"\n    value: \n\
      \      FIELD:\n        path: \"CA10__authorizedNetworksJson__c\"\n        returnType:\
      \ BYTES\n  - name: \"caJsonFrom__authorizedNetworksJson__c\"\n    value: \n\
      \      JSON_FROM:\n        arg: \n          EXTRACT: \"CA10__authorizedNetworksJson__c\"\
      \n        undeterminedIf:\n          isInvalid: \"Authorized Networks JSON is\
      \ invalid.\"  \n  - name: \"caJsonText__authorizedNetworksJsonValue__c\"\n \
      \   value: \n      JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caJsonFrom__authorizedNetworksJson__c\"\
      \n        expression: \"to_string([].value)\"\n        undeterminedIf:\n   \
      \       evaluationError: \"The JSON query was failed.\"\n          resultTypeMismatch:\
      \ \"The JSON query did not return a text.\"\n  - name: \"CA10__instanceType__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__instanceType__c\"\n     \
      \   undeterminedIf:\n          isEmpty: \"Instance type should not be empty\"\
      \n  - name: \"CA10__backendType__c\"\n    value: \n      FIELD:\n        path:\
      \ \"CA10__backendType__c\"\n        undeterminedIf:\n          isEmpty: \"Backend\
      \ type should not be empty\"\n  - name: \"CA10__backupEnabled__c\"\n    value:\
      \ \n      FIELD:\n        path: \"CA10__backupEnabled__c\"\n        undeterminedIf:\n\
      \          isEmpty: \"Backup enabled should not be empty\"\n  - name: \"CA10__backupStartTime__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__backupStartTime__c\"\n  -\
      \ name: \"CA10__sslMode__c\"\n    value: \n      FIELD:\n        path: \"CA10__sslMode__c\"\
      \n  - name: \"CA10__createTime__c\"\n    value: \n      FIELD:\n        path:\
      \ \"CA10__createTime__c\"\n  - name: \"CA10__state__c\"\n    value: \n     \
      \ FIELD:\n        path: \"CA10__state__c\"\n  - name: \"CA10__cpuUtilizationAvg30Day__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__cpuUtilizationAvg30Day__c\"\
      \n  - name: \"CA10__memoryUtilizationAvg30Day__c\"\n    value: \n      FIELD:\n\
      \        path: \"CA10__memoryUtilizationAvg30Day__c\"\n  - name: \"CA10__diskReadIoOpsRate30Day__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__diskReadIoOpsRate30Day__c\"\
      \n  - name: \"CA10__diskWriteIoOpsRate30Day__c\"\n    value: \n      FIELD:\n\
      \        path: \"CA10__diskWriteIoOpsRate30Day__c\"\n  - name: \"CA10__cloudSqlConnectionsAvg30Day__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__cloudSqlConnectionsAvg30Day__c\"\
      \n# Text\n  - name: \"CA10__regionName__c\"\n    value: \n      FIELD:\n   \
      \     path: \"CA10__regionName__c\"\n"
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" : "1299",
      "conditionText" : "extract('CA10__regionName__c') == 'europe-west3'",
      "runtimeError" : null
    }
  }, {
    "Id" : "003",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "1600",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaGoogleSqlInstance__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__regionName__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-09-26T07:07:35Z")
    },
    "Id" : "001",
    "CA10__disappearanceTime__c" : new Date("2023-11-29T10:24:08Z"),
    "CA10__regionName__c" : "us-east4"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-09-26T07:07:35Z")
    },
    "Id" : "002",
    "CA10__regionName__c" : "europe-west3"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-09-26T07:07:35Z")
    },
    "Id" : "003",
    "CA10__regionName__c" : "us-east4"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaGoogleSqlInstance__c(
      obj STRUCT<
          Id STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__regionName__c 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 TextLib = new function () {
          this.normalize = function(arg) {
              return arg == null ? '' : arg.replace(/\s+/g, ' ').trim().toLowerCase();
          };
          this.isEmpty = function(arg) {
              return this.normalize(arg) == '';
          };
          this.isNotEmpty = function(arg) {
              return this.normalize(arg) != '';
          };
          this.equal = function(left, right) {
              return this.normalize(left) == this.normalize(right);
          };
          this.notEqual = function(left, right) {
              return this.normalize(left) != this.normalize(right);
          };
          this.startsWith = function(arg, substring) {
              return this.normalize(arg).startsWith(this.normalize(substring));
          };
          this.endsWith = function(arg, substring) {
              return this.normalize(arg).endsWith(this.normalize(substring));
          };
          this.contains = function(arg, substring) {
              return this.normalize(arg).includes(this.normalize(substring));
          };
          this.containsAll = function(arg, substrings) {
              if (substrings == null || substrings.length === 0) return false;
              let normalizedArg = this.normalize(arg);
              return substrings.every(sub => normalizedArg.includes(this.normalize(sub)));
          };
          this.containsAny = function(arg, substrings) {
              if (substrings == null || substrings.length === 0) return false;
              let normalizedArg = this.normalize(arg);
              return substrings.some(sub => normalizedArg.includes(this.normalize(sub)));
          };
      }();
      var references1 = [];
      // condition[0], conditionIndex:[0..99]
      references1.push('Deleted From Google [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};
      }
      // condition[1], conditionIndex:[100..199]
      function extract3() { if (!this.out) { this.out = obj.CA10__regionName__c; } return this.out; };
      references1.push('Region Name [obj.CA10__regionName__c]: ' + obj.CA10__regionName__c);
      if (TextLib.equal(extract3.call(extract3), 'us-west2')) {
          return {status: 'INCOMPLIANT', conditionIndex: 199, conditionText: "extract('CA10__regionName__c') == 'us-west2'", currentStateMessage: "The Instance is running in us-west2 which is more expensive than us-west1.", currentStateReferences: references1.join('\n'), remediation: "Consider migrating the Instance to us-west1.", runtimeError: null};
      }
      // condition[2], conditionIndex:[200..299]
      function extract6() { if (!this.out) { this.out = obj.CA10__regionName__c; } return this.out; };
      if (TextLib.equal(extract6.call(extract6), 'us-west3')) {
          return {status: 'INCOMPLIANT', conditionIndex: 299, conditionText: "extract('CA10__regionName__c') == 'us-west3'", currentStateMessage: "The Instance is running in us-west3 which is more expensive than us-west1.", currentStateReferences: references1.join('\n'), remediation: "Consider migrating the Instance to us-west1.", runtimeError: null};
      }
      // condition[3], conditionIndex:[300..399]
      function extract9() { if (!this.out) { this.out = obj.CA10__regionName__c; } return this.out; };
      if (TextLib.equal(extract9.call(extract9), 'us-west4')) {
          return {status: 'INCOMPLIANT', conditionIndex: 399, conditionText: "extract('CA10__regionName__c') == 'us-west4'", currentStateMessage: "The Instance is running in us-west4 which is more expensive than us-west1.", currentStateReferences: references1.join('\n'), remediation: "Consider migrating the Instance to us-west1.", runtimeError: null};
      }
      // condition[4], conditionIndex:[400..499]
      function extract12() { if (!this.out) { this.out = obj.CA10__regionName__c; } return this.out; };
      if (TextLib.equal(extract12.call(extract12), 'us-south1')) {
          return {status: 'INCOMPLIANT', conditionIndex: 499, conditionText: "extract('CA10__regionName__c') == 'us-south1'", currentStateMessage: "The Instance is running in us-south1 which is more expensive than us-east1, us-east5 or us-central1.", currentStateReferences: references1.join('\n'), remediation: "Consider migrating the Instance to us-east1, us-east5 or us-central1.", runtimeError: null};
      }
      // condition[5], conditionIndex:[500..599]
      function extract15() { if (!this.out) { this.out = obj.CA10__regionName__c; } return this.out; };
      if (TextLib.equal(extract15.call(extract15), 'northamerica-northeast1')) {
          return {status: 'INCOMPLIANT', conditionIndex: 599, conditionText: "extract('CA10__regionName__c') == 'northamerica-northeast1'", currentStateMessage: "The Instance is running in northamerica-northeast1 which is more expensive than us-east1, us-east5 or us-central1.", currentStateReferences: references1.join('\n'), remediation: "Consider migrating the Instance to us-east1, us-east5 or us-central1.", runtimeError: null};
      }
      // condition[6], conditionIndex:[600..699]
      function extract18() { if (!this.out) { this.out = obj.CA10__regionName__c; } return this.out; };
      if (TextLib.equal(extract18.call(extract18), 'northamerica-northeast2')) {
          return {status: 'INCOMPLIANT', conditionIndex: 699, conditionText: "extract('CA10__regionName__c') == 'northamerica-northeast2'", currentStateMessage: "The Instance is running in northamerica-northeast2 which is more expensive than us-east1, us-east5 or us-central1.", currentStateReferences: references1.join('\n'), remediation: "Consider migrating the Instance to us-east1, us-east5 or us-central1.", runtimeError: null};
      }
      // condition[7], conditionIndex:[700..799]
      function extract21() { if (!this.out) { this.out = obj.CA10__regionName__c; } return this.out; };
      if (TextLib.equal(extract21.call(extract21), 'europe-north1')) {
          return {status: 'INCOMPLIANT', conditionIndex: 799, conditionText: "extract('CA10__regionName__c') == 'europe-north1'", currentStateMessage: "The Instance is running in europe-north1 which is more expensive than europe-north2 or europe-west1.", currentStateReferences: references1.join('\n'), remediation: "Consider migrating the Instance to europe-north2 or europe-west1.", runtimeError: null};
      }
      // condition[8], conditionIndex:[800..899]
      function extract24() { if (!this.out) { this.out = obj.CA10__regionName__c; } return this.out; };
      if (TextLib.equal(extract24.call(extract24), 'europe-southwest1')) {
          return {status: 'INCOMPLIANT', conditionIndex: 899, conditionText: "extract('CA10__regionName__c') == 'europe-southwest1'", currentStateMessage: "The Instance is running in europe-southwest1 which is more expensive than europe-north2 or europe-west1.", currentStateReferences: references1.join('\n'), remediation: "Consider migrating the Instance to europe-north2 or europe-west1.", runtimeError: null};
      }
      // condition[9], conditionIndex:[900..999]
      function extract27() { if (!this.out) { this.out = obj.CA10__regionName__c; } return this.out; };
      if (TextLib.equal(extract27.call(extract27), 'europe-west4')) {
          return {status: 'INCOMPLIANT', conditionIndex: 999, conditionText: "extract('CA10__regionName__c') == 'europe-west4'", currentStateMessage: "The Instance is running in europe-west1 which is more expensive than europe-north2 or europe-west1.", currentStateReferences: references1.join('\n'), remediation: "Consider migrating the Instance to europe-north2 or europe-west1.", runtimeError: null};
      }
      // condition[10], conditionIndex:[1000..1099]
      function extract30() { if (!this.out) { this.out = obj.CA10__regionName__c; } return this.out; };
      if (TextLib.equal(extract30.call(extract30), 'europe-west12')) {
          return {status: 'INCOMPLIANT', conditionIndex: 1099, conditionText: "extract('CA10__regionName__c') == 'europe-west12'", currentStateMessage: "The Instance is running in europe-west12 which is more expensive than europe-north2 or europe-west1.", currentStateReferences: references1.join('\n'), remediation: "Consider migrating the Instance to europe-north2 or europe-west1.", runtimeError: null};
      }
      // condition[11], conditionIndex:[1100..1199]
      function extract33() { if (!this.out) { this.out = obj.CA10__regionName__c; } return this.out; };
      if (TextLib.equal(extract33.call(extract33), 'europe-west2')) {
          return {status: 'INCOMPLIANT', conditionIndex: 1199, conditionText: "extract('CA10__regionName__c') == 'europe-west2'", currentStateMessage: "The Instance is running in europe-west2 which is more expensive than europe-north2 or europe-west1.", currentStateReferences: references1.join('\n'), remediation: "Consider migrating the Instance to europe-north2 or europe-west1.", runtimeError: null};
      }
      // condition[12], conditionIndex:[1200..1299]
      function extract36() { if (!this.out) { this.out = obj.CA10__regionName__c; } return this.out; };
      if (TextLib.equal(extract36.call(extract36), 'europe-west3')) {
          return {status: 'INCOMPLIANT', conditionIndex: 1299, conditionText: "extract('CA10__regionName__c') == 'europe-west3'", currentStateMessage: "The Instance is running in europe-west3 which is more expensive than europe-north2 or europe-west1.", currentStateReferences: references1.join('\n'), remediation: "Consider migrating the Instance to europe-north2 or europe-west1.", runtimeError: null};
      }
      // condition[13], conditionIndex:[1300..1399]
      function extract39() { if (!this.out) { this.out = obj.CA10__regionName__c; } return this.out; };
      if (TextLib.equal(extract39.call(extract39), 'europe-west6')) {
          return {status: 'INCOMPLIANT', conditionIndex: 1399, conditionText: "extract('CA10__regionName__c') == 'europe-west6'", currentStateMessage: "The Instance is running in europe-west6 which is more expensive than europe-north2 or europe-west1.", currentStateReferences: references1.join('\n'), remediation: "Consider migrating the Instance to europe-north2 or europe-west1.", runtimeError: null};
      }
      // condition[14], conditionIndex:[1400..1499]
      function extract42() { if (!this.out) { this.out = obj.CA10__regionName__c; } return this.out; };
      if (TextLib.equal(extract42.call(extract42), 'europe-west8')) {
          return {status: 'INCOMPLIANT', conditionIndex: 1499, conditionText: "extract('CA10__regionName__c') == 'europe-west8'", currentStateMessage: "The Instance is running in europe-west8 which is more expensive than europe-north2 or europe-west1.", currentStateReferences: references1.join('\n'), remediation: "Consider migrating the Instance to europe-north2 or europe-west1.", runtimeError: null};
      }
      // condition[15], conditionIndex:[1500..1599]
      function extract45() { if (!this.out) { this.out = obj.CA10__regionName__c; } return this.out; };
      if (TextLib.equal(extract45.call(extract45), 'europe-west9')) {
          return {status: 'INCOMPLIANT', conditionIndex: 1599, conditionText: "extract('CA10__regionName__c') == 'europe-west9'", currentStateMessage: "The Instance is running in europe-west9 which is more expensive than europe-north2 or europe-west1.", currentStateReferences: references1.join('\n'), remediation: "Consider migrating the Instance to europe-north2 or europe-west1.", runtimeError: null};
      }
      return {status: 'COMPLIANT', conditionIndex: 1600, conditionText: "otherwise", currentStateMessage: "The Instance is located in a cost-effective region.", 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.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
          sObject.CA10__regionName__c AS CA10__regionName__c,
          process_CA10__CaGoogleSqlInstance__c(
              STRUCT(
                  sObject.Id AS Id,
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__regionName__c AS CA10__regionName__c
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaGoogleSqlInstance__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
