DataAI Spark Function Catalog

dataai-spark-functions contains the portable computational capabilities from the DataAI application. The functions accept Spark Dataset<Row> objects and return Spark DataFrames or small result records that contain DataFrames.

The library has no web server, database service, or external AI requirement. It executes inside the customer's Spark application and leaves persistence, scheduling, security, and orchestration under customer control.

Add the functions artifact

<dependency>
  <groupId>com.dataai</groupId>
  <artifactId>dataai-spark-functions</artifactId>
  <version>0.1.0-SNAPSHOT</version>
</dependency>

Install all modules locally during source development:

Set-Location C:\Projects\DataAI.Etl\spark
mvn clean install

Function families

ETL and quality

DataAI capabilitySpark APIResult
Normalize fieldsDataAiPipeline.normalize()Snake-case names, trimmed strings, blank-to-null values
Deterministic record keyDataAiPipeline.recordKey(...)SHA-256 _dataai_record_key
Field profilingFieldProfiler.profile(...)Counts, nulls, distinct values, range, mean, and standard deviation
Declarative validationDataAiPipeline.validate(...)Findings plus clean and rejected DataFrames
Automatic quality checksDataQualityFunctions.automaticChecks(...)Missing, duplicate, date, outlier, category, and text issues
Missing-value summaryDataQualityFunctions.missingValueSummary(...)Affected fields and record counts
Duplicate-record summaryDataQualityFunctions.duplicateRecordSummary(...)Complete duplicate count
Invalid-date summaryDataQualityFunctions.invalidDateSummary(...)Invalid date-like text counts
Numeric-outlier summaryDataQualityFunctions.numericOutlierSummary(...)Field-level outlier counts
Category consistencyDataQualityFunctions.inconsistentCategorySummary(...)Case/spacing/punctuation variants
Suspicious textDataQualityFunctions.suspiciousTextSummary(...)Whitespace, control, markup, length, and repetition issues

Declarative rule types:

DataAiResult result = DataAiPipeline.fromDataset(input)
        .normalize()
        .recordKey("order_id")
        .profile()
        .validate(
                RuleSpec.required("customer-required", "customer_id"),
                RuleSpec.unique("order-unique", "order_id"),
                RuleSpec.between("amount-range", "amount", 0, 100000),
                RuleSpec.inSet("status-values", "status", List.of("Open", "Closed")),
                RuleSpec.dateFormat("order-date", "order_date", "yyyy-MM-dd"),
                RuleSpec.length("reference-length", "reference", 1, 40))
        .execute();

General analytics

DataAI capabilitySpark API
Grouped descriptive statisticsAnalyticsFunctions.groupedSummary(...)
Pivot / cross-tabAnalyticsFunctions.pivot(...)
Base/comparison varianceAnalyticsFunctions.variance(...)
Contribution to totalIncluded in variance(...)
Top/bottom/average-nearest rankingAnalyticsFunctions.ranking(...)
Pairwise correlationAnalyticsFunctions.correlations(...)
Correlation thresholdAnalyticsFunctions.correlationThreshold(...)
Linear regression and predictionAnalyticsFunctions.linearRegression(...)

Supported aggregations: COUNT, COUNT_DISTINCT, SUM, MINIMUM, MAXIMUM, AVERAGE, STANDARD_DEVIATION.

Dataset<Row> variance = AnalyticsFunctions.variance(
        input,
        List.of("region"),
        "period",
        "2025",
        "2026",
        "revenue",
        Aggregation.SUM);

Dataset<Row> regression = AnalyticsFunctions.linearRegression(
        input, "units", "revenue", "region", 100.0);

Time analysis

DataAI capabilitySpark API
Day/week/month/quarter/year summaryTimeSeriesFunctions.summarize(...)
Moving averageTimeSeriesFunctions.rolling(..., MOVING_AVERAGE)
Rolling totalTimeSeriesFunctions.rolling(..., ROLLING_TOTAL)
Period-over-period changeIncluded in rolling(...)
Dataset<Row> rolling = TimeSeriesFunctions.rolling(
        input,
        List.of("region"),
        "order_date",
        TimePeriod.MONTH,
        "revenue",
        Aggregation.SUM,
        3,
        RollingOperation.MOVING_AVERAGE);

Business analytics

DataAI capabilitySpark API
Standard-deviation outliersBusinessFunctions.outliers(...)
Percentage-difference outliersBusinessFunctions.outliers(...)
Business minimum/maximum outliersBusinessFunctions.outliers(...)
Transparent anomaly scoresBusinessFunctions.anomalyScores(...)
Distribution driftBusinessFunctions.drift(...)
ABC/Pareto classificationBusinessFunctions.pareto(...)
Cohort retentionBusinessFunctions.cohort(...)
Funnel conversion/drop-offBusinessFunctions.funnel(...)
KPI ratio/difference/sum/productBusinessFunctions.kpi(...)
Dataset<Row> pareto = BusinessFunctions.pareto(
        input, "product", "revenue", Aggregation.SUM);

Dataset<Row> cohorts = BusinessFunctions.cohort(
        input, "customer_id", "activity_date", "revenue", TimePeriod.MONTH);

Market models

DataAI capabilitySpark API
Demand and projected demandMarketFunctions.demand(...)
Price-band sensitivityMarketFunctions.pricing(...)
Price elasticity projectionMarketFunctions.elasticity(...)
Basket co-occurrence/supportMarketFunctions.basket(...)
Segment summariesMarketFunctions.segments(...)
Churn/retention scoreMarketFunctions.churn(...)
Relative exposure riskMarketFunctions.risk(...)
Inventory velocity/reorder pointMarketFunctions.inventory(...)
Profit/margin/contributionMarketFunctions.profit(...)
Downside/base/upside scenarioMarketFunctions.scenario(...)

Assumption arguments use percentage points: 10.0 means 10 percent.

Dataset<Row> demand = MarketFunctions.demand(
        input,
        List.of("region", "product"),
        "units",
        "order_date",
        TimePeriod.MONTH,
        10.0);

Dataset<Row> profit = MarketFunctions.profit(
        input,
        List.of("region", "product"),
        "revenue",
        "direct_cost",
        null,
        null,
        0);

Geographic analysis

MapFunctions.readiness(...) returns a MapReadinessResult containing:

Checks classify missing coordinates, invalid latitude/longitude ranges, duplicate locations, valid coordinates without a name, and KML-ready rows.

MapReadinessResult map = MapFunctions.readiness(
        input, "latitude", "longitude", "location_name");

Matrix analysis and balancing

MatrixFunctions.crossTab(...) produces a Spark pivot. balance(...) performs iterative proportional fitting against row and column control totals.

MatrixBalanceResult balanced = MatrixFunctions.balance(
        cells,
        "region",
        "category",
        "value",
        rowTargets,
        columnTargets,
        "target_total",
        50,
        0.001);

if (!balanced.converged()) {
    throw new IllegalStateException("Matrix controls did not converge");
}

The balanced output includes original and balanced values, balancing coefficients, row/column targets, final totals, differences, and convergence metadata.

Data dictionary, recommendations, alerts, and narratives

DataAI capabilitySpark API
Data dictionary and detected rolesInsightFunctions.dataDictionary(...)
Chart recommendationsInsightFunctions.chartRecommendations(...)
Automated local narrativesInsightFunctions.narratives(...)
Rule-based alertsInsightFunctions.ruleBasedAlerts(...)

Narratives are deterministic and local. They do not send customer data to an external AI endpoint. Customers can optionally send the returned, governed summary DataFrame to their own approved AI integration.

Platform output adapters

Tableau output adapter

Add com.dataai:dataai-spark-tableau:0.1.0-SNAPSHOT when a Spark application needs standardized DataAI outputs for Tableau. TableauOutputs.from(...) accepts a DataAiResult and returns a TableauOutputBundle containing:

TableauOutputNames provides stable default table-name constants. The adapter does not persist, cache, collect, connect to Tableau, or make network calls. The customer explicitly writes the returned DataFrames to a format/catalog visible through Tableau's native Spark SQL or Databricks connector.

Use TableauFunctionOutputs.withRunMetadata(...) with any function-result DataFrame to add reserved result name, run ID, completion time, and library version fields. Use TableauFunctionOutputs.matrixBalance(...) to convert a MatrixBalanceResult with iteration count, maximum error, and convergence fields.

TableauOutputBundle tableau = TableauOutputs.from(result);

tableau.dashboardMetrics().write()
        .format("delta")
        .mode(SaveMode.Append)
        .saveAsTable("analytics.dataai_dashboard_metrics");

See Tableau output schema and function-to-Tableau coverage.

InterSystems IRIS adapter

Add com.dataai:dataai-spark-iris:0.1.0-SNAPSHOT when DataAI must read from or write approved outputs to InterSystems IRIS. IrisJdbcOptions creates a safe, customer-controlled JDBC configuration; IrisDataFrames provides table, partitioned-table, query, and explicitly invoked writer entry points.

IrisPipelineOutputs.from(...) converts a DataAiResult into clean, rejected, finding, profile, and pipeline-run DataFrames with stable IRIS output names. The adapter never chooses a target table or save mode and never invokes save() for the customer.

Use IrisFunctionOutputs.withRunMetadata(...) for any result DataFrame. Use IrisFunctionOutputs.matrixBalance(...) for matrix balancing with run, library, platform, convergence, iteration, and maximum-error metadata.

See IRIS function outputs and IRIS README. The adapter uses Spark's standard JDBC source and does not bundle the InterSystems driver, persist automatically, collect full data, call a DataAI service, or emit telemetry.

Execution behavior

Most APIs return lazy Spark DataFrames. Spark executes them only when a caller runs an action or writes the result. Two APIs intentionally perform actions:

Keep correlation field lists bounded and configure matrix iterations and tolerance appropriate to the data size.

Capabilities delegated to the customer's platform

The following DataAI application features are not copied into the computation JAR because Spark or the customer's BI/orchestration platform already owns them:

Application featureSpark ETL equivalent
CSV, JSON, Parquet, JDBC, and cloud importSparkSession.read() and customer connectors
Scheduled imports and reportsOracle AIDP, Airflow, Fabric, Databricks, or other job scheduler
Web dashboards and chart renderingPower BI, Tableau, Oracle Analytics, or customer UI
CSV/Excel/PDF/ZIP downloadsSpark writers and downstream reporting tools
User accounts and report permissionsCustomer identity, catalog, and platform policy
Interactive drill-back pagesPersist _dataai_record_key and query source records
External generative-AI interpretationOptional customer-approved AI adapter

This boundary keeps DataAI ETL an embeddable library rather than turning it into a hosted service.