Skip to content

Commit

Permalink
Fix QueryScope uri resolution from python
Browse files Browse the repository at this point in the history
  • Loading branch information
devinrsmith committed Sep 29, 2022
1 parent d379f90 commit 1d5bd66
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
11 changes: 7 additions & 4 deletions py/server/deephaven/uri.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

""" Tools for resolving Uniform Resource Identifiers (URIs) into objects. """

from typing import Union
from typing import Any

import jpy

Expand All @@ -14,9 +14,9 @@
_JResolveTools = jpy.get_type("io.deephaven.uri.ResolveTools")


def resolve(uri: str) -> Union[jpy.JType, JObjectWrapper]:
def resolve(uri: str) -> Any:
"""Resolves a Uniform Resource Identifier (URI) string into an object. Objects with custom Python wrappers,
like Table, return an instance of the wrapper class; otherwise, the raw Java object is returned.
like Table, return an instance of the wrapper class; otherwise, the Java or Python object is returned.
Args:
Expand All @@ -30,6 +30,9 @@ def resolve(uri: str) -> Union[jpy.JType, JObjectWrapper]:
"""

try:
return wrap_j_object(_JResolveTools.resolve(uri))
# When grabbing something out of the query scope, it may already be presented as a PyObject; in which case,
# when the value gets back into python, it's a native python type - in which case, we don't need to wrap it.
item = _JResolveTools.resolve(uri)
return wrap_j_object(item) if isinstance(item, jpy.JType) else item
except Exception as e:
raise DHError(e, "failed to resolve the URI.") from e
16 changes: 15 additions & 1 deletion py/server/tests/test_uri.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@

import jpy

from deephaven import empty_table
from deephaven.jcompat import j_hashset
from deephaven.table import Table
from deephaven.uri import resolve
from tests.testbase import BaseTestCase


class UriTestCase(BaseTestCase):
def test_uri_local_table(self):
def test_uri_csv(self):
_JResolver = jpy.get_type("io.deephaven.server.uri.CsvTableResolver")
_JUriResolvers = jpy.get_type("io.deephaven.uri.resolver.UriResolvers")
_JUriResolversInstance = jpy.get_type("io.deephaven.uri.resolver.UriResolversInstance")
Expand All @@ -26,6 +27,19 @@ def test_uri_local_table(self):
t = resolve(uri)
self.assertIsInstance(t, Table)

def test_uri_query_scope(self):
_JResolver = jpy.get_type("io.deephaven.server.uri.QueryScopeResolver")
_JUriResolvers = jpy.get_type("io.deephaven.uri.resolver.UriResolvers")
_JUriResolversInstance = jpy.get_type("io.deephaven.uri.resolver.UriResolversInstance")
j_resolver = _JResolver.of(todo)
j_resolver_set = j_hashset({j_resolver})
j_resolvers = _JUriResolvers(j_resolver_set)
_JUriResolversInstance.init(j_resolvers)

my_table = empty_table(42).view("I=i")
uri = "dh:///scope/my_table"
t = resolve(uri)
self.assertIsInstance(t, Table)

if __name__ == "__main__":
unittest.main()
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.deephaven.uri.QueryScopeUri;
import io.deephaven.uri.resolver.UriResolver;
import io.deephaven.uri.resolver.UriResolversInstance;
import io.deephaven.util.annotations.VisibleForTesting;

import javax.inject.Inject;
import javax.inject.Provider;
Expand All @@ -30,6 +31,11 @@ public static QueryScopeResolver get() {
return UriResolversInstance.get().find(QueryScopeResolver.class).get();
}

@VisibleForTesting
public static QueryScopeResolver of(ScriptSession scriptSession) {
return new QueryScopeResolver(() -> scriptSession);
}

private final Provider<ScriptSession> globalSessionProvider;

@Inject
Expand Down

0 comments on commit 1d5bd66

Please sign in to comment.