deephaven-core icon indicating copy to clipboard operation
deephaven-core copied to clipboard

Ad-hoc java compilation to classpath

Open devinrsmith opened this issue 1 year ago • 1 comments

This would add the ability for a user to dynamically add java code to the classpath. This should be considered with the same security considerations as ConsoleService.ExecuteCommand. This could be useful in use-cases where the dynamism of the queries is not known in advanced (ie, simply building the necessary JARs beforehand and starting the server with the extra classpath is not feasible). The code could then be referenced in the context of a formula, as a building block for script execution logic, or in further ad-hoc compilations.

For example, a user might want the following compiled and added onto the classpath:

package com.example;

import io.deephaven.engine.util.TableTools;

public class MyAdHocClass {
  public static int intDiv(int x, int y) {
    return x / y;
  }
  
  public static Table someTable() {
    return TableTools.newTable(...);
  }
}

Here is what it might look like to reference from a python script session:

import jpy
from deephaven.table import Table

my_table_1 = Table(jpy.get_type("com.example.MyAdHocClass").someTable())
my_table_2 = my_table_1.update_view(["Foo = com.example.MyAdHocClass.intDiv(X, Y)"])

and a groovy script session:

import com.example.MyAdHocClass

myTable1 = MyAdHocClass.someTable()
myTable2 = myTable1.updateView("Foo = com.example.MyAdHocClass.intDiv(X, Y)")

The physical compilation would likely need to be exposed as a new RPC, or as server side function that needs to be invoked through as script session (where security concerns are already matched).

It is possible to imagine this feature scoped down, where it is implemented solely as a java script session. In this scenario, the feature would be self-contained and not available when running a python or groovy sessions.

devinrsmith avatar Aug 16 '24 16:08 devinrsmith

It was also suggested this could be implemented as io.deephaven.plugin.type.ObjectType plugin (as opposed to top-level gRPC).

devinrsmith avatar Aug 19 '24 20:08 devinrsmith