You need to enable JavaScript to run this app.
Lake AI Service

Lake AI Service

Copy page
Download PDF
Text cleaning
Email address cleaning
Copy page
Download PDF
Email address cleaning

Operator introduction

Description

Regex-based email address cleaning operator.

Key features

  • Multi-scenario support: Built-in general matching patterns, and allows custom regular expressions.
  • Controllable replacement: Configurable replacement string for masking or placeholder substitution.
  • Batch compatibility: Supports batch processing.

Daft invocation

Operator parameters

Input

Input column name

Description

texts

String array; each element is text to be processed. None values are permitted.

Output

String array containing the replaced or cleaned text. If processing fails, the result is None.

Parameters

If a parameter does not have a default value, it must be specified.

Parameter name

Type

Default value

Description

pattern

str

r"[A-Za-z0-9.-+]+@[a-z0-9.-+]+.[a-z]+"

Regular expression used to locate email addresses. If passed in the form r'...' or r"...", the operator will remove the prefix.

repl

str

""

String used to replace matched email addresses.

Examples

The following code demonstrates how to use daft to run the CleanEmail operator to clean email addresses in text.

from __future__ import annotations

import os

import daft
from daft import col
from daft.las.functions.text.clean_email import CleanEmail
from daft.las.functions.udf import las_udf

if __name__ == "__main__":
    if os.getenv("DAFT_RUNNER", "native") == "ray":
        import logging

        import ray

        def configure_logging():
            logging.basicConfig(
                level=logging.INFO,
                format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
                datefmt="%Y-%m-%d %H:%M:%S.%s".format(),
            )
            logging.getLogger("tracing.span").setLevel(logging.WARNING)
            logging.getLogger("daft_io.stats").setLevel(logging.WARNING)
            logging.getLogger("DaftStatisticsManager").setLevel(logging.WARNING)
            logging.getLogger("DaftFlotillaScheduler").setLevel(logging.WARNING)
            logging.getLogger("DaftFlotillaDispatcher").setLevel(logging.WARNING)

        ray.init(dashboard_host="0.0.0.0", runtime_env={"worker_process_setup_hook": configure_logging})
        daft.set_runner_ray()
    daft.set_execution_config(actor_udf_ready_timeout=600)
    daft.set_execution_config(min_cpu_per_task=0)

    samples = {
        "text": [
            "lihua@163.com This is a test content.",
            "This is a test content.",
            None,
        ]
    }

    repl = "****"
    ds = daft.from_pydict(samples)

    ds = ds.with_column(
        "cleaned_text",
        las_udf(
            CleanEmail,
            construct_args={"repl": repl},
        )(col("text")),
    )
    ds.show()

    # ╭────────────────────────────────┬──────────────────────────────╮
    # │ text                           ┆ cleaned_text                 │
    # │ ---                            ┆ ---                          │
    # │ Utf8                           ┆ Utf8                         │
    # ╞════════════════════════════════╪══════════════════════════════╡
    # │ lihua@163.com This is a test … ┆ **** This is a test content. │
    # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
    # │ This is a test content. ┆ This is a test content. │
    # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
    # │ None                           ┆ None                         │
    # ╰────────────────────────────────┴──────────────────────────────╯
Last updated: 2026.05.12 19:06:38