deephaven / deephaven-core

Deephaven Community Core
Other
257 stars 80 forks source link

Query strings that call Python functions with additional arithmetic throw an error if not explicitly typecast #3119

Closed jjbrosnan closed 1 year ago

jjbrosnan commented 1 year ago

Description

In query strings in which a function is called amongst other logic (addition, subtraction, etc.), an error is raised complaining about no operator for the type java.lang.Object.

Steps to reproduce

from deephaven import empty_table
import numpy as np

def sine(a, x) -> np.double:
    return a * np.sin(x)

t = empty_table(10).update(["X = 0.1 * i", "Y = sine(2, X) + 1"])

Expected results

A 10-row table with two columns.

Actual results

The following error:

r-Scheduler-Serial-1 | i.d.s.s.SessionState      | Internal Error '69de7349-2ed9-4e44-a9b3-1140d027c432' java.lang.RuntimeException: Error in Python interpreter:
Type: <class 'deephaven.dherror.DHError'>
Value: table update operation failed. : Cannot find method plus(java.lang.Object, int)
Traceback (most recent call last):
  File "/opt/deephaven-venv/lib/python3.7/site-packages/deephaven/table.py", line 469, in update
    return Table(j_table=self.j_table.update(*formulas))
RuntimeError: io.deephaven.engine.table.impl.select.FormulaCompilationException: Formula compilation error for: sine(2, X) + 1
    at io.deephaven.engine.table.impl.select.DhFormulaColumn.initDef(DhFormulaColumn.java:206)
    at io.deephaven.engine.table.impl.select.SwitchColumn.initDef(SwitchColumn.java:66)
    at io.deephaven.engine.table.impl.select.analyzers.SelectAndViewAnalyzer.create(SelectAndViewAnalyzer.java:90)
    at io.deephaven.engine.table.impl.select.analyzers.SelectAndViewAnalyzer.create(SelectAndViewAnalyzer.java:61)
    at io.deephaven.engine.table.impl.QueryTable.lambda$selectOrUpdate$33(QueryTable.java:1255)
    at io.deephaven.engine.table.impl.perf.QueryPerformanceRecorder.withNugget(QueryPerformanceRecorder.java:518)
    at io.deephaven.engine.table.impl.QueryTable.lambda$selectOrUpdate$34(QueryTable.java:1240)
    at io.deephaven.engine.table.impl.QueryTable.memoizeResult(QueryTable.java:3110)
    at io.deephaven.engine.table.impl.QueryTable.selectOrUpdate(QueryTable.java:1239)
    at io.deephaven.engine.table.impl.QueryTable.update(QueryTable.java:1219)
    at io.deephaven.engine.table.impl.QueryTable.update(QueryTable.java:89)
    at io.deephaven.api.TableOperationsDefaults.update(TableOperationsDefaults.java:105)
    at org.jpy.PyLib.executeCode(Native Method)
    at org.jpy.PyObject.executeCode(PyObject.java:138)
    at io.deephaven.engine.util.PythonEvaluatorJpy.evalScript(PythonEvaluatorJpy.java:73)
    at io.deephaven.integrations.python.PythonDeephavenSession.lambda$evaluate$1(PythonDeephavenSession.java:183)
    at io.deephaven.util.locks.FunctionalLock.doLockedInterruptibly(FunctionalLock.java:50)
    at io.deephaven.integrations.python.PythonDeephavenSession.evaluate(PythonDeephavenSession.java:182)
    at io.deephaven.engine.util.AbstractScriptSession.lambda$evaluateScript$1(AbstractScriptSession.java:145)
    at io.deephaven.engine.context.ExecutionContext.lambda$apply$0(ExecutionContext.java:123)
    at io.deephaven.engine.context.ExecutionContext.apply(ExecutionContext.java:134)
    at io.deephaven.engine.context.ExecutionContext.apply(ExecutionContext.java:122)
    at io.deephaven.engine.util.AbstractScriptSession.evaluateScript(AbstractScriptSession.java:145)
    at io.deephaven.engine.util.DelegatingScriptSession.evaluateScript(DelegatingScriptSession.java:87)
    at io.deephaven.engine.util.ScriptSession.evaluateScript(ScriptSession.java:113)
    at io.deephaven.server.console.ConsoleServiceGrpcImpl.lambda$executeCommand$8(ConsoleServiceGrpcImpl.java:169)
    at io.deephaven.server.session.SessionState$ExportBuilder.lambda$submit$2(SessionState.java:1343)
    at io.deephaven.server.session.SessionState$ExportObject.doExport(SessionState.java:880)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at io.deephaven.server.runner.DeephavenApiServerModule$ThreadFactory.lambda$newThread$0(DeephavenApiServerModule.java:164)
    at java.base/java.lang.Thread.run(Thread.java:829)
caused by io.deephaven.engine.table.impl.lang.QueryLanguageParser$QueryLanguageParseException: 

Having trouble with the following expression:
Full expression           : sine(2, X) + 1
Expression having trouble : io.deephaven.engine.table.impl.lang.QueryLanguageParser$VisitArgs@218a1319
Exception message         : Cannot find method plus(java.lang.Object, int)

    at io.deephaven.engine.table.impl.lang.QueryLanguageParser.getMethod(QueryLanguageParser.java:505)
    at io.deephaven.engine.table.impl.lang.QueryLanguageParser.visit(QueryLanguageParser.java:1777)
    at io.deephaven.engine.table.impl.lang.QueryLanguageParser.visit(QueryLanguageParser.java:134)
    at com.github.javaparser.ast.expr.MethodCallExpr.accept(MethodCallExpr.java:116)
    at io.deephaven.engine.table.impl.lang.QueryLanguageParser.visit(QueryLanguageParser.java:1215)
    at io.deephaven.engine.table.impl.lang.QueryLanguageParser.visit(QueryLanguageParser.java:134)
    at com.github.javaparser.ast.expr.BinaryExpr.accept(BinaryExpr.java:140)
    at io.deephaven.engine.table.impl.lang.QueryLanguageParser.<init>(QueryLanguageParser.java:225)
    at io.deephaven.engine.table.impl.lang.QueryLanguageParser.<init>(QueryLanguageParser.java:178)
    at io.deephaven.engine.table.impl.select.codegen.FormulaAnalyzer.getCompiledFormula(FormulaAnalyzer.java:131)
    at io.deephaven.engine.table.impl.select.DhFormulaColumn.initDef(DhFormulaColumn.java:188)
    ... 33 more

Line: 471
Namespace: update
File: /opt/deephaven-venv/lib/python3.7/site-packages/deephaven/table.py
Traceback (most recent call last):
  File "<string>", line 7, in <module>
  File "/opt/deephaven-venv/lib/python3.7/site-packages/deephaven/table.py", line 471, in update

        at org.jpy.PyLib.executeCode(PyLib.java:-2)
        at org.jpy.PyObject.executeCode(PyObject.java:138)
        at io.deephaven.engine.util.PythonEvaluatorJpy.evalScript(PythonEvaluatorJpy.java:73)
        at io.deephaven.integrations.python.PythonDeephavenSession.lambda$evaluate$1(PythonDeephavenSession.java:183)
        at io.deephaven.util.locks.FunctionalLock.doLockedInterruptibly(FunctionalLock.java:50)
        at io.deephaven.integrations.python.PythonDeephavenSession.evaluate(PythonDeephavenSession.java:182)
        at io.deephaven.engine.util.AbstractScriptSession.lambda$evaluateScript$1(AbstractScriptSession.java:145)
        at io.deephaven.engine.context.ExecutionContext.lambda$apply$0(ExecutionContext.java:123)
        at io.deephaven.engine.context.ExecutionContext.apply(ExecutionContext.java:134)
        at io.deephaven.engine.context.ExecutionContext.apply(ExecutionContext.java:122)
        at io.deephaven.engine.util.AbstractScriptSession.evaluateScript(AbstractScriptSession.java:145)
        at io.deephaven.engine.util.DelegatingScriptSession.evaluateScript(DelegatingScriptSession.java:87)
        at io.deephaven.engine.util.ScriptSession.evaluateScript(ScriptSession.java:113)
        at io.deephaven.server.console.ConsoleServiceGrpcImpl.lambda$executeCommand$8(ConsoleServiceGrpcImpl.java:169)
        at io.deephaven.server.session.SessionState$ExportBuilder.lambda$submit$2(SessionState.java:1343)
        at io.deephaven.server.session.SessionState$ExportObject.doExport(SessionState.java:880)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
        at java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at io.deephaven.server.runner.DeephavenApiServerModule$ThreadFactory.lambda$newThread$0(DeephavenApiServerModule.java:164)
        at java.lang.Thread.run(Thread.java:829)

Additional details and attachments

Versions

jmao-denver commented 1 year ago

fixed by #4647