deephaven / deephaven-core

Deephaven Community Core
Other
251 stars 80 forks source link

[Groovy] Can't cast a column to a custom class in a query #1389

Open jakemulf opened 2 years ago

jakemulf commented 2 years ago

Description

class MyStringClass {
    private String strn

    MyStringClass(String strn) {
        this.strn = strn
    }

    String myString() {
        return this.strn
    }
}

obj1 = new MyStringClass("A")
obj2 = new MyStringClass("B")
obj3 = new MyStringClass("C")

source = newTable(
    col("Objects", obj1, obj2, obj3)
)

result = source.update("Match = ((MyStringClass) Objects_[i]).myString() == `A`")

Running this code gives the following error

Having trouble with the following expression:
Full expression           : ((MyStringClass) Objects_[i]).myString() == "A"
Expression having trouble : io.deephaven.db.tables.lang.DBLanguageParser$VisitArgs@2aede9ad
Exception message         : Cannot find class : MyStringClass

Steps to reproduce

Described above

Expected results

The update statement should recognize the casting of the column to MyStringClass and execute the query.

Actual results

The casting to MyStringClass is not recognized.

Additional details and attachments

If this is a result of user error, documenting how we should do this would be a sufficient resolution.

Versions

nbauernfeind commented 2 years ago

FYI, a work around for this is to add the class to your query library. I do believe such classes should automatically be available but I haven't investigated at this time.

io.deephaven.engine.context.ExecutionContext.getContext().getQueryLibrary().importClass(MyStringClass.class)