Global Phone Notebook: Databricks Reference Guide#

Notebook Configuration#

Follow the instructions to get the notebook and details about installation in Notebook Installation.

Verify Single Phone#

The Verify Single Phone notebook validates and standardizes an individual phone number using the Global Phone API. It can return the response as JSON or write selected response fields to an output table.

Example#

  1. Set up your license key using Databricks secrets. See Databricks License Key Set Up.

  2. Fill in the required fields indicated by (*).

  3. Click Run all to run the notebook.

  4. The JSON response will be displayed in the View Results notebook section. If an output table is named, the result will append to the table.

Input Example

../../_images/Databricks-Global-Phone-Verify-Single-Example-Input.png

Output Example

../../_images/Databricks-Global-Phone-Verify-Single-Example-Output.png

Input Parameters#

The following table describes the input parameters for the Verify Single Phone notebook.

Parameter

Data Type

Description

Example

License

STRING

Required.
The License Key with Credits issued by Melissa.

Get it here.

See more information on license key set up.

Phone Number

STRING

Required.
Phone number to be verified.

949-858-3000

Country

STRING

Required.
The country code.

US

Options

STRING

[OptionName:Parameter], separated by commas (,).

See more information about endpoint options.
If omitted, Default Input Options will be applied.

TimeToWait:5

Country Of Origin

STRING

The country of origin code.

US

Output Table Name

STRING

The output table name.

A new table will be created if it doesn’t exist.
If the table exists, its structure must remain unchanged.
If left blank, only the JSON response is returned.

Output Table Fields

STRING

Case-sensitive.

Only valid when Output Table Name is provided.

Select fields for the output table. If left blank or Select All, all fields will output.
To output chosen fields, ensure Select All is deselected.

RecordID,
Results,
PhoneNumber,
AdministrativeArea,
CountryAbbreviation,
CountryName,
Carrier,
CallerID,
DST,
InternationalPhoneNumber,
Language,
Latitude,
Locality,
Longitude,
PhoneInternationalPrefix,
PhoneCountryDialingCode,
PhoneNationPrefix,
PhoneNationalDestinationCode,
PhoneSubscriberNumber,
UTC,
TimeZoneCode,
TimeZoneName,
PostalCode,
Suggestions

Verify Multiple Phones#

The Verify Multiple Phones notebook processes phone number records in batches, validating and standardizing key components using the Global Phone API.

It can handle tables of any size, returning the results in a specified output table and supports optional fields for flexible, accurate phone validation.

Requirements#

To use this notebook, you need to prepare an input table in Databricks beforehand referencing our default input fields below.

Input Fields#

Column Name

Data Type

Description

record_id

STRING

Required.
Record identifier, primary key.

phone_number

STRING

Required.
The phone number to be verified.

country

STRING

Required.
The country code.

country_of_origin

STRING

Required. Empty string is accepted.
The country of origin code.

Python Notebook Setup#

The step-by-step example below shows how to use the notebook. Replace with your values.

  • Step 0 - Prepare an input table

    Assume that the input table has the signature below:

    CREATE TABLE IF NOT EXISTS <catalog>.<schema>.<input_table> (
       RecId INT,
       Phone STRING,
       CountryCode STRING,
       OriginCountryCode STRING
    );
    

    This input table has different column names from the Input Fields. Mapping column names in Step 2 is necessary for the program to get the correct parameters.

Attention

Make sure your input table contains unique RecordID before running the next script. See more about Batch Processing Best Practices.

  • Step 1 - Required Privileges

    Ensure you have the necessary access to the input table and output table including SELECT, INSERT, UPDATE, USE SCHEMA, and USE CATALOG privileges for the tables involved.

  • Step 2 - Map Input Columns with the Default Input Fields

    Set the required parameters and map your input columns to our Input Fields.

    Check Input Parameters for more information.

    from melissadatacloudapi_databricks import Config, GLOBAL_PHONE, run
    
    config = Config(
        license_key=LICENSE_KEY,
        input_table="<catalog>.<schema>.<input_table>",
        output_table="<catalog>.<schema>.<output_table>",
        # Map your input columns with our input fields, replace with your actual column names
        # For optional columns, leave the field as "".
        parameter_mapping={
          "record_id": "RecId",
          "phone_number": "Phone",
          "country": "CountryCode",
          "country_of_origin": "OriginCountryCode",
        },
        request_parameters={
          "options": "",
        },
        output_columns="<field_1,field_2>",
        log_to_table=False,
        log_table="<catalog>.<schema>.<log_table>",
        duplicate_check=False,
    )
    
  • Step 3 - Call run() to verify your data

    run(GLOBAL_PHONE, config, spark=spark, dbutils=dbutils)
    
    # Output table view
    display(
        spark.sql(
            f"SELECT * FROM {config.output_table} ORDER BY TRY_CAST(RecordID AS BIGINT), RecordID LIMIT 1000"
        )
    )
    

Input Parameters#

The following table describes the input parameters for the Verify Multiple Phones notebook.

Parameter

Data Type

Description

Example

license_key

STRING

Required.
The License Key with Credits issued by Melissa.

Get it here.

See more information on license key set up.

parameter_mapping

Connects each Melissa field to a column in your input table. See Input Fields.

request_parameters

Sent once with every batch, applied to every record.

options
[OptionName:Parameter], separated by commas (,).

See more information about endpoint options.
If omitted, Default Input Options will be applied.

TimeToWait:5

input_table

STRING

Required.
Name of the input table.

catalog.schema.input_table_name

output_table

STRING

Required.
The output table name.

A new table will be created if it doesn’t exist.
If the table exists, its structure must remain unchanged.

catalog.schema.output_table_name

output_columns

STRING

Case-sensitive.

Fields in the output table; fields separated by commas (,) if not ‘ALL’.
Field names must match the available response fields. Use ALL to include every available field. This significantly increases the writing time to the output table, so we recommend using the default or specifying the output fields.
If omitted, see Default Output Fields.

RecordID,
InPhoneNumber,
InCountry,
PhoneNumber,
AdministrativeArea,
CountryAbbreviation,
CountryName,
Carrier,
CallerID,
DST,
InternationalPhoneNumber,
Language,
Latitude,
Locality,
Longitude,
PhoneInternationalPrefix,
PhoneCountryDialingCode,
PhoneNationPrefix,
PhoneNationalDestinationCode,
PhoneSubscriberNumber,
UTC,
TimeZoneCode,
TimeZoneName,
PostalCode,
Suggestions,
Results,
JSON_Response,
Timestamp

log_to_table

BOOLEAN

Enable or disable logs to facilitate troubleshooting in case of any issues.
- False (Default): No action will be taken. The notebook will process with no log writes.
- True: Enable event, batch progress, and error logging.

True

log_table

STRING

Name of the log table. Only valid when log_to_table = True.

catalog.schema.log_table_name

duplicate_check

BOOLEAN

Enable or disable several checks for duplicate RecordID.
- False (Default): No action will be taken. The notebook will process records coming from the input source as is.
- True: Enable several checks for duplicate RecordID. When enabled, a repeated RecordID stops the run before anything is sent, and records already in the output table are skipped. This makes it safe to rerun after a failure without submitting the same records to the service again.

True

Default Settings#

Default Input Options#

If input options is empty, default input options will be:

Parameter

Value

options

VerifyPhone:Express,
CallerID:FALSE,
DefaultCallingCode:<blank>,
EnableBatchSuggestion:FALSE,
TimeToWait:2

These are our recommended service options for general batch processing. See more information about endpoint options here.

Additional output columns available only with CallerID:TRUE

  • CallerID (US/CA only)

Default Output Fields#

If output_columns is an empty string or not provided, output table will have a default schema as below.

Column Name

Data Type

RecordID

STRING

InPhoneNumber

STRING

InCountry

STRING

Results

STRING

PhoneNumber

STRING

CountryAbbreviation

STRING

InternationalPhoneNumber

STRING

Carrier

STRING

PhoneInternationalPrefix

STRING

PhoneCountryDialingCode

STRING

PhoneNationPrefix

STRING

PhoneNationalDestinationCode

STRING

PhoneSubscriberNumber

STRING

Result Codes#

For the full list of result codes returned by Global Phone Notebook: Databricks, please visit here.

Interpreting Results#

Result codes yield more granular information about a given phone number. They are returned as a comma-delimited string of 4-character alpha-numeric codes, e.g. PS01,PS07,PS18 or PS07,PE04.

The SE## and GE## codes (Transmission Service Error and General Transmission Error) are used to signify more general errors, and are returned under the key TransmissionResults in the outermost level of our responses.

Global Phone Cloud API returns back a string of PSXX result codes in the “Results” field of the response. These result codes provide users with information about the response from the service.

In almost every case, one of the values of the “Results” string will be one of the following:

Code

Description

Recommendation

PS20

Number exists within a block of registered phone numbers.

Low Confidence - This number exists within a block of registered phone numbers that the service checks against.

PS22

Number was verified against current dialing equipment.

High Confidence - This number was verified against current dialing equipment. This result code will only be returned if the VerifyPhone option in the initial request to the service is set to Premium. (ex: &opt=VerifyPhone:Premium).

With these result codes users can easily build logic for what to do with good valid phone numbers and easily distinguish good phone numbers from bad phone numbers.

There are also PEXX codes that can be returned which indicate there was an error with a part of the requested phone number.