Formula validation configuration

When you work with Deephaven tables, you often create custom columns or filter data using expressions like:

  • myTable.update(myColumn = x + y * 2)
  • myTable.where("Double.isFinite(Price)")

These expressions get sent to the Deephaven server over gRPC and compiled into executable code. For security reasons, the server needs to validate that these expressions only call approved methods and functions. Script session code execution is not validated as the Deephaven engine does not parse script code. The console service can be disabled via configuration.

This guide explains how to configure formula validation using two main approaches:

  • Annotations (for your own code)
  • Pointcut expressions (for external libraries)

When does validation occur?

Formula validation happens when requests are sent over gRPC, such as those made by any of Deephaven's client APIs:

Validation does not apply to:

  • Code you write directly in the console/script editor.
  • Python functions or Groovy closures in your session scope (these are blocked when validation is enabled).

How validation works

When you write a formula, Deephaven:

  1. Parses your expression to find all method calls.
  2. Checks each method call against the configured rules.
  3. Either permits or denies the expression based on those rules.

Method 1: Annotations (for your own code)

Use this approach when you're writing your own Java classes and want to make specific methods available in Deephaven formulas.

Annotations are special markers you add to your Java code to indicate which methods should be allowed in formulas. The key annotation is @UserInvocationPermitted.

How annotations work

  1. Add the annotation to your class or individual methods.
  2. Give it a name using the value parameter (like a category name).
  3. Configure Deephaven to recognize that category name.
  4. Optionally specify scope to limit to static or instance methods only.

Annotate entire classes

When you annotate a class, all public methods in that class become available:

Limit annotations to static or instance methods

You can restrict which types of methods are allowed:

Annotate individual methods

For more precise control, annotate specific methods instead of entire classes:

Best practices for annotations

When designing your annotations, follow these recommendations:

  • Use descriptive annotation values that clearly indicate the method category (e.g., math_operations, string_utilities).
  • Group logically related methods together rather than creating separate annotations for each method.
  • Avoid creating too many small annotation categories, as this increases configuration complexity.
  • Consider the security implications - only annotate methods that are safe for user formulas.
  • Group related methods under the same annotation value to reduce configuration.

Configuration

After adding annotations to your code, you must tell Deephaven to recognize them by setting configuration properties.

Default configuration:

Deephaven comes with pre-configured annotations for built-in functionality:

Adding your own annotations:

  • The property name format is: ColumnExpressionValidator.annotationSets.<your_name>.
  • List all your annotation values separated by commas.

Method 2: Pointcut expressions (for external libraries)

Use this approach when you want to allow methods from libraries you don't control (like Java's built-in classes, third-party libraries, etc.).

Since you can't add annotations to external code, you use pointcut expressions - patterns that match method signatures. AspectJ Pointcut expressions, as defined by OpenRewrite's method matcher, are a simple way to match one or more Java methods.

Understanding pointcut patterns

A pointcut expression has three parts:

  1. Class name: The full package and class name (e.g., java.lang.String).
  2. Method name: The specific method or * for any method.
  3. Parameters: The parameter types or (..) for any parameters.

Pattern matching symbols

  • * = Match any single item (one method name, one parameter type, etc.).
  • .. = Match any number of parameters of any type.
  • ; = Separate multiple patterns in one property.

Common examples

Default Deephaven pointcut configuration

Deephaven comes pre-configured with safe methods from common Java classes:

Backwards compatibility (Deephaven 0.39.x and earlier)

For older versions only: Prior to Deephaven 0.40.0, validation used a simple method name allowlist instead of the sophisticated system described above.

To revert to the old behavior (not recommended for new deployments):

Note

The old system was less secure and flexible. The new annotation and pointcut system provides better security and control.