Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't filter by joined integer values with RSQL #384

Closed
micheljung opened this issue Feb 3, 2017 · 4 comments
Closed

Can't filter by joined integer values with RSQL #384

micheljung opened this issue Feb 3, 2017 · 4 comments

Comments

@micheljung
Copy link

I'm using elide-datastore-hibernate5 v2.5.0.

If you basically have:

public class Car {
  @Id
  private int id;
  private Person owner;
}

public class Person {
  @Id
  private int id;
}

These work:

# Basic
/owner?filter[id]=1
/car?filter[owner.id]=1

# RSQL
/owner?filter=id==1

But this doesn't:

# RSQL
/car?filter=owner.id==1

Exception:

Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
	at org.hibernate.type.descriptor.java.IntegerTypeDescriptor.unwrap(IntegerTypeDescriptor.java:19) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
	at org.hibernate.type.descriptor.sql.IntegerTypeDescriptor$1.doBind(IntegerTypeDescriptor.java:46) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
	at org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:74) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
	at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:257) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
	at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:252) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
	at org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:2046) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
	at org.hibernate.loader.Loader.bindParameterValues(Loader.java:2015) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
	at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1945) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
	at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1898) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
	at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1876) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
	at org.hibernate.loader.Loader.scroll(Loader.java:2693) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
	at org.hibernate.loader.criteria.CriteriaLoader.scroll(CriteriaLoader.java:104) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
	at org.hibernate.internal.SessionImpl.scroll(SessionImpl.java:1727) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
	at org.hibernate.internal.CriteriaImpl.scroll(CriteriaImpl.java:377) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
	at com.yahoo.elide.datastores.hibernate5.HibernateTransaction.loadObjects(HibernateTransaction.java:271) ~[elide-datastore-hibernate5-2.5.0.jar:na]
	at com.yahoo.elide.datastores.hibernate5.HibernateTransaction.loadObjectsWithSortingAndPagination(HibernateTransaction.java:241) ~[elide-datastore-hibernate5-2.5.0.jar:na]
	at com.yahoo.elide.core.PersistentResource.loadRecordsWithSortingAndPagination(PersistentResource.java:352) ~[elide-core-2.5.0.jar:na]
	at com.yahoo.elide.parsers.state.CollectionTerminalState.getResourceCollection(CollectionTerminalState.java:135) ~[elide-core-2.5.0.jar:na]
	at com.yahoo.elide.parsers.state.CollectionTerminalState.handleGet(CollectionTerminalState.java:68) ~[elide-core-2.5.0.jar:na]
	at com.yahoo.elide.parsers.state.StateContext.handleGet(StateContext.java:110) ~[elide-core-2.5.0.jar:na]
	at com.yahoo.elide.parsers.GetVisitor.visitQuery(GetVisitor.java:34) ~[elide-core-2.5.0.jar:na]
	at com.yahoo.elide.parsers.GetVisitor.visitQuery(GetVisitor.java:21) ~[elide-core-2.5.0.jar:na]
	at com.yahoo.elide.generated.parsers.CoreParser$QueryContext.accept(CoreParser.java:556) ~[elide-core-2.5.0.jar:na]
	at org.antlr.v4.runtime.tree.AbstractParseTreeVisitor.visitChildren(AbstractParseTreeVisitor.java:70) ~[antlr4-runtime-4.5.1-1.jar:4.5.1-1]
	at com.yahoo.elide.generated.parsers.CoreBaseVisitor.visitStart(CoreBaseVisitor.java:20) ~[elide-core-2.5.0.jar:na]
	at com.yahoo.elide.parsers.BaseVisitor.visitStart(BaseVisitor.java:47) ~[elide-core-2.5.0.jar:na]
	at com.yahoo.elide.parsers.BaseVisitor.visitStart(BaseVisitor.java:33) ~[elide-core-2.5.0.jar:na]
	at com.yahoo.elide.generated.parsers.CoreParser$StartContext.accept(CoreParser.java:107) ~[elide-core-2.5.0.jar:na]
	at org.antlr.v4.runtime.tree.AbstractParseTreeVisitor.visit(AbstractParseTreeVisitor.java:42) ~[antlr4-runtime-4.5.1-1.jar:4.5.1-1]
	at com.yahoo.elide.Elide.get(Elide.java:369) ~[elide-core-2.5.0.jar:na]
	at com.yahoo.elide.Elide.get(Elide.java:407) ~[elide-core-2.5.0.jar:na]
	at com.faforever.api.data.JsonApiController.jsonApiGet(JsonApiController.java:44) ~[main/:na]
@DennisMcWherter
Copy link
Collaborator

DennisMcWherter commented Feb 3, 2017

Thanks for the simple case to reproduce, I'll get to work on reproducing this locally and report back. Looks like a value coercion issue somewhere. Will report back with more information soon!

@DennisMcWherter
Copy link
Collaborator

DennisMcWherter commented Feb 3, 2017

Looked into this further and it is definitely a coercion issue. I have to pop this off the stack for a moment for a higher priority issue, but I should be able to get back to this quickly. This is also an issue to be addressed in Elide 3.0.

The problem is that the RSQL grammar isn't coercing Strings -> expected value (in this case, String -> Int) before sending wrapping it as a generic Predicate. The only requirement is that whatever interface performs the coercion has access to the EntityDictionary and knows about the entity and its field names.

The fix should be relatively straightforward: in the RSQL grammar code, coerce the list of values to their appropriate type before wrapping them as a Predicate (known as FilterPredicate in Elide 3.0).

^^^
That is mostly a note for myself so I know where to pick this up when I return :) Anyone with spare cycles is welcome to take a crack at it, ofc though.

@DennisMcWherter
Copy link
Collaborator

Sorry for the delay on this. I have a PR here.

Turns out that we had an indexing problem in our RSQL dialect implementation which-- unfortunately-- resulted in invalid type coercion.

@DennisMcWherter
Copy link
Collaborator

PR has been merged and this change will be released in 2.5.1. Thanks for reporting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants