Notebook SmartMover USA: Databricks Python Package

Notebook SmartMover USA: Databricks Python Package#

Introduction#

The Melissa Databricks Python Package provides access to the SmartMover API from Databricks notebooks. It processes US address records from a Databricks table and writes move update and address standardization results to an output table.

Click here to learn more about the SmartMover Cloud API.

Prerequisites#

  • Access to a Databricks workspace.

  • An input table containing US address and contact data.

  • Permission to read the input table and create or write to the output table.

  • The Melissa Databricks Python Package installed in the Databricks environment. See installation.

  • A Melissa License Key with Credits. See License Key Information.

  • A consistent job_id for all records in the same list when processing records for NCOA reporting.

Usage#

Imports#

from melissadatacloudapi_databricks import Config, SMARTMOVER, run

Components#

Name

Description

Config

Holds the settings for a run: license key, input and output tables, field mapping, request parameters, output columns, logging, and duplicate checking.

Set jobs_table to save the report links, one row per job_id and paf_id.

The settings are validated when run starts. A missing or unknown setting stops the run with an error before any records are sent.

See Configuration.

SMARTMOVER

The product definition for SmartMover. It tells run which Cloud API to call, which input fields are accepted, and which output columns are available.

Required input fields: record_id and address_line_1.
Required request parameter: job_id.
Optional request parameters: paf_id, execution_id, columns, options and opt_smart_mover_list_name.
Report links: CASSReportLink and NCOAReportLink are saved to the jobs table.
Records per request: 100.

run

Processes every record in the input table and writes the results to the output table.

run(product, config, df=None, spark=None, dbutils=None)

- product: SMARTMOVER.
- config: The Config object.
- df: Optional.
- spark: The Spark session. In a notebook, pass spark.
- dbutils: Optional. In a notebook, pass dbutils.

See Execution.

Configuration#

Map the request fields to input table columns. Leave optional mappings as an empty string if those columns are unavailable. The API is for US address processing.

config = Config(
   license_key=LICENSE_KEY,
   input_table="<catalog>.<schema>.<input_table>",
   output_table="<catalog>.<schema>.<output_table>",
   parameter_mapping={
       "record_id": "",
       "address_line_1": "",
       "city": "",
       "state": "",
       "postal_code": "",
       "country": "",
       "company": "",
       "name_full": "",
       "name_first": "",
       "name_middle": "",
       "name_last": "",
       "name_prefix": "",
       "name_suffix": "",
       "address_line_2": "",
       "suite": "",
       "private_mailbox": "",
       "urbanization": "",
       "plus4": "",
   },
   request_parameters={
       "job_id": "YOUR_JOB_ID",
       "paf_id": "",
       "columns": "",
       "options": "ProcessingType:Individual",
       "opt_smart_mover_list_name": "",
   },
   output_columns="",
   log_to_table=False,
   log_table="<catalog>.<schema>.<log_table>",
   duplicate_check=False,
)

Input Parameters#

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.

job_id
Required. Identifies records belonging to the same list for NCOA reporting. Use the same value for all records in one list.

paf_id
For Broker accounts, identifies the end user. Empty string is accepted.

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

columns
Requested response columns, separated by commas (,). See request columns.

opt_smart_mover_list_name
Identifies the current list. It will be included in reports returned by SmartMover V3 after processing.

job_id: jobid1234,
options: ProcessingType:Standard

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 output column names in the example list. Use ALL to include every available field.
If omitted, see Default Output Fields.

RecordID,
InCompany,
InNameFull,
InNameFirst,
InNameMiddle,
InNamePrefix,
InNameSuffix,
InNameLast,
InPlus4,
InAddressLine1,
InAddressLine2,
InSuite,
InCity,
InState,
InPostalCode,
InPrivateMailbox,
InUrbanization,
InCountry,
Results,
AddressExtras,
AddressKey,
AddressLine1,
AddressLine2,
AddressTypeCode,
BaseMelissaAddressKey,
CarrierRoute,
City,
CityAbbreviation,
CompanyName,
CountryCode,
CountryName,
DeliveryIndicator,
DeliveryPointCheckDigit,
DeliveryPointCode,
MelissaAddressKey,
MoveEffectiveDate,
MoveTypeCode,
PostalCode,
State,
StateName,
Urbanization,
Response,
Timestamp,
NameFirst,
NameFull,
NameLast,
NameMiddle,
NamePrefix,
NameSuffix,
OriginalAddressLine1,
OriginalAddressLine2,
OriginalCity,
OriginalCityAbbreviation,
OriginalCountryCode,
OriginalPlus4,
OriginalPostalCode,
OriginalPrivateMailbox,
OriginalResults,
OriginalState,
OriginalStateName,
OriginalSuite,
OriginalUrbanization,
AddressDeliveryInstallation,
AddressHouseNumber,
AddressLockBox,
AddressPostDirection,
AddressPreDirection,
AddressPrivateMailboxName,
AddressPrivateMailboxRange,
AddressRouteService,
AddressStreetName,
AddressStreetSuffix,
AddressSuiteName,
AddressSuiteNumber,
StandardizedAddressLine1,
StandardizedAddressLine2,
StandardizedBaseMelissaAddressKey,
StandardizedCarrierRoute,
StandardizedCity,
StandardizedCityAbbreviation,
StandardizedCountryCode,
StandardizedDeliveryIndicator,
StandardizedDeliveryPointCheckDigit,
StandardizedDeliveryPointCode,
StandardizedMelissaAddressKey,
StandardizedPlus4,
StandardizedPostalCode,
StandardizedPrivateMailbox,
StandardizedResults,
StandardizedState,
StandardizedStateName,
StandardizedSuite,
StandardizedUrbanization,
DPVFootNotes,
MoveReturnCode,
Plus4,
PrivateMailbox,
Suite

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

jobs_table

STRING

Name of the jobs table.

Automatically save summary report links to a report table. A new table will be created if it doesn’t exist. See Save Summary Report Links for more information.

catalog.schema.jobs_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

Example#

config = Config(
   license_key=LICENSE_KEY,
   input_table="main.default.addresses",
   output_table="main.default.addresses_smartmover",
   parameter_mapping={
      "record_id": "RecordID",
      "company": "Company",
      "name_full": "FullName",
      "address_line_1": "AddressLine1",
      "city": "City",
      "state": "State",
      "postal_code": "PostalCode",
      "country": "Country",
   },
   request_parameters={
      "job_id": "jobid1234",
      "paf_id": "",
      "options": "ProcessingType:Standard",
   },
   output_columns="RecordID,Results,AddressLine1,MoveTypeCode,MoveReturnCode",
   log_to_table=True,
   log_table="main.default.addresses_logs",
   duplicate_check=False,
)

Execution#

run(SMARTMOVER, config, spark=spark, dbutils=dbutils)