Issue with SQL sample given in README.md

52 views
Skip to first unread message

Divyank Duvedi

unread,
Nov 19, 2017, 2:21:42 PM11/19/17
to cqengine-discuss
Hi,

I have written a small program which is very similar to the SQL query example given in CQEngine's documentation. However when I run this code and even the one given in documentation, I am getting an exception.

Basically, I am writing a feature where in I'll get a collection of POJOs whose schema will not be known to me up-front and neither will that POJO contain CQEngine's Attribute objects which I can register to CQEngine's SQLParser. And using CQEngine I want to perform some basic SELECT queries.

Would you please assist in troubleshooting the above code?

Thanks,
Divyank

Divyank Duvedi

unread,
Nov 19, 2017, 2:26:36 PM11/19/17
to cqengine-discuss
EDIT: I am using cqengine-2.12.1.jar 

Niall Gallagher

unread,
Nov 19, 2017, 3:14:56 PM11/19/17
to cqengine...@googlegroups.com
Hi Divyank,

Your use case seems pretty reasonable. So let's see if we can get to the bottom of it...

It looks like you are using lombok to generate your POJO is that correct? Perhaps lombok-generated code is the culprit. Does the issue occur with a conventional/hand written POJO? If lombok is the culprit then we could separately look at addressing compatibility issues if necessary.

Also could you tell me:
- which JVM are you using?
- are you using CQEngine as a regular maven dependency, or are you using the CQEngine shaded jar "- all.jar" instead?

Finally- is there a way you could provide a standalone test case which reproduces the problem (or a class with a main method), which I could run myself?

Thanks,
Niall

Sent from my Android

--
-- You received this message because you are subscribed to the "cqengine-discuss" group.
http://groups.google.com/group/cqengine-discuss
---
You received this message because you are subscribed to the Google Groups "cqengine-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cqengine-discuss+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Divyank Duvedi

unread,
Nov 19, 2017, 4:21:29 PM11/19/17
to cqengine-discuss
Hi Niall,

Thanks for your quick response.

Yes, you are right that I am using Lombok to generate traditional Getters and Setters, however the error doesn't seems to go away even on writing my own getter/setters.

Answering your queries : 

1. My JVM version is : "Version 8 Update 151 (build 1.8.0_151-b12)"
2. I am using regular Maven dependency.
3. The example that I have posted in the initial message is a standalone main class, on which you can possibly reproduce the issue. Link : https://ideone.com/6Axjib

Also, I read the AttributeBytecodeGenerator documentation and it seems that it generates Attribute code only for fields of a POJO which are declared as non-private.Is there any reason that why this class doesn't supports code generation for private fields as it is fairly common practise across java developers to declare private members while creating a POJO which in my opinion limits the use of AttributeBytecodeGenerator.

Thanks,
Divyank
To unsubscribe from this group and stop receiving emails from it, send an email to cqengine-discu...@googlegroups.com.

Niall Gallagher

unread,
Nov 19, 2017, 5:33:45 PM11/19/17
to cqengine...@googlegroups.com
I have limited time to provide support sometimes, so it helps if test cases are SSCCEs - http://sscce.org . If I have to spend time setting up dependencies for lombok etc., then I won't be able to investigate this today.

AttributeBytecodeGenerator does not support private fields because private fields can only be accessed from the class in which they were declared. The only way to bypass this is to use reflection. For that you can use ReflectiveAttribute instead.

But an even better option is to upgrade to the latest version CQEngine 2.12.2, where AttributeBytecodeGenerator can now generate attributes for getter methods as well as fields. So if your POJO uses private fields but public getters, you can now generate attributes for its getters instead.

I'll try to get some time to run the example later in the week. If you can simplify the example in the meantime it would help though.

Thanks again,
Niall 


Sent from my Android


To unsubscribe from this group and stop receiving emails from it, send an email to cqengine-discuss+unsubscribe@googlegroups.com.

Divyank Duvedi

unread,
Nov 20, 2017, 3:28:35 AM11/20/17
to cqengine...@googlegroups.com
Hi Niall,

Really appreciate your help!

Here is a simplified version of the code : https://ideone.com/wNVC2W (I am assuming that you are having a dependency on Google Guava.)

Thanks,
Divyank


You received this message because you are subscribed to a topic in the Google Groups "cqengine-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cqengine-discuss/AdB-SbmRWpQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to cqengine-discuss+unsubscribe@googlegroups.com.

Niall

unread,
Nov 20, 2017, 9:55:18 AM11/20/17
to cqengine-discuss
Hi again Divyank,

I was able to run that latest example, and it's actually working for me.
I did split the example into two classes (Car and Activity) though, so I could run in my IDE. I also added a toString() method in the Car class. But I think otherwise it's the same.

When I run it, it prints the following to the console:
Car{name='mercedes', featureBulletPoints=[att, mehngi], randomMap={a=bmwMap}}

I'll paste the source of the two classes which work for me below, so you can compare this with the version which fails for you.

// Activity.java
package com.googlecode.cqengine.temp;

import java.util.ArrayList;
import java.util.List;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.googlecode.cqengine.ConcurrentIndexedCollection;
import com.googlecode.cqengine.IndexedCollection;
import com.googlecode.cqengine.codegen.AttributeBytecodeGenerator;
import com.googlecode.cqengine.query.parser.sql.SQLParser;
import com.googlecode.cqengine.resultset.ResultSet;


public class Activity {

public static void main(String args[]) {
List<Car> sampleList = new ArrayList<>();
sampleList.add(new Car("mercedes", ImmutableList.of("att", "mehngi"), ImmutableMap.of("a", "bmwMap")));
sampleList.add(new Car("bmw", ImmutableList.of("nice"), ImmutableMap.of("b", "set")));
sampleList.add(new Car("ferrari", ImmutableList.of("bahli att", "sports"), ImmutableMap.of("rando", "anothe")));
sampleList.add(new Car("rolls royce", ImmutableList.of("sirra", "kuch bhi"), ImmutableMap.of("blahh", "hola")));
IndexedCollection<Car> indexedCollection = new ConcurrentIndexedCollection<Car>();
indexedCollection.addAll(sampleList);
SQLParser<Car> sqlParser = SQLParser.forPojoWithAttributes(Car.class, AttributeBytecodeGenerator.createAttributes(Car.class));
ResultSet<Car> results = sqlParser.retrieve(indexedCollection, "SELECT * FROM indexedCollection WHERE name = 'mercedes'");
for(Car car : results) {
System.out.println(car);
}
results.close();
}
}

// Car.java
package com.googlecode.cqengine.temp;

import java.util.List;
import java.util.Map;

public class Car {

public String getName() {
return name;
}


public void setName(String name) {
this.name = name;
}


public List<String> getFeatureBulletPoints() {
return featureBulletPoints;
}


public void setFeatureBulletPoints(List<String> featureBulletPoints) {
this.featureBulletPoints = featureBulletPoints;
}


public Map<String, String> getRandomMap() {
return randomMap;
}


public void setRandomMap(Map<String, String> randomMap) {
this.randomMap = randomMap;
}

public String name;
public List<String> featureBulletPoints;
public Map<String, String> randomMap;

Car(String name, List<String> featureBulletPoints, Map<String, String> map) {
this.name = name;
this.featureBulletPoints = featureBulletPoints;
this.randomMap = map;
}

@Override
public String toString() {
return "Car{" +
"name='" + name + '\'' +
", featureBulletPoints=" + featureBulletPoints +
", randomMap=" + randomMap +
'}';
}
}

One additional possibility is that there might be a dependency conflict in your application - so maybe you could double-check that CQEngine is being run with the correct versions of it's dependencies?

Best regards,
Niall

Niall

unread,
Nov 20, 2017, 11:35:56 AM11/20/17
to cqengine-discuss
Hi Divyank,

I think I found the issue. I re-tested the same code using CQEngine's shaded jar and ran into the same exception you mentioned.

It looks like a jar packaging issue, which affects the shaded version of the CQEngine jar, but not the regular jar. So I guess you might be using the shaded build without knowing.
The issue is that the javassist library (which is a dependency of CQEngine's AttributeBytecodeGenerator) does not work correctly when it's its classes are relocated to a different package in the shaded jar by maven-shade-plugin. However it relates to the configuration in CQEngine's for the maven-shade-plugin, rather than a problem with javassist itself.

Anyway the problem can be resolved via a simple config change in the pom.xml of CQEngine.
I will have to wait until later today/tomorrow to make that fix and release a new version, but it should fix the issue for you. I'll let you know when it's available.

Best regards,
Niall
Reply all
Reply to author
Forward
0 new messages