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

examples in README do not work #110

Closed
NikkyAI opened this issue Jul 19, 2020 · 4 comments
Closed

examples in README do not work #110

NikkyAI opened this issue Jul 19, 2020 · 4 comments

Comments

@NikkyAI
Copy link

NikkyAI commented Jul 19, 2020

first of all.. i am a total noob in redis and i am doing this using kotlin, so i might be making some really stupid errors here

using version 1.8.0
java 8
and writing my code in kotlin

i am running redis in docker and i am using https://hub.docker.com/r/redislabs/redismod/ latest

the first block of code

// Creating a complex query
Query q = new Query("hello world")
                    .addFilter(new Query.NumericFilter("price", 0, 1000))
                    .limit(0,5);

this seems to break because the argument type Query.Filter of addFilter is a private inner class so this is being thrown:

Exception in thread "main" java.lang.IllegalAccessError: tried to access class io.redisearch.Query$Filter from class moe.nikky.redistest.RedisTestKt
	at moe.nikky.redistest.RedisTestKt.main(RedisTest.kt:65)

i tried with java 11 too but there the error just gets more confusing

the other error is more of a runtime error

after adding all the extra fields to the index (looks like it should work)
the aggregate qury fails with a classcast exception, seems like jedis returns a JedisDataException that is blindly casted to byte[]

code

    val client = Client("testing", "localhost", 6379)

    // reset index on each run ?
    client.dropIndex(true)

    val sc: Schema = Schema()
        .addTextField("title", 5.0)
        .addTextField("body", 1.0)
        .addTextField("state", 1.0)
        .addNumericField("price")

    client.createIndex(sc, Client.IndexOptions.defaultOptions())

    // insert document(s)
    client.addDocument("doc1",
        mapOf(
            "title" to "hello world",
            "state" to "NY",
            "body" to "lorem ipsum",
            "price" to 1337
        )
    )

// aggregation query
    val r = AggregationBuilder("hello")
        .apply("@price/1000", "k")
        .groupBy("@state", Reducers.avg("@k").`as`("avgprice"))
        .filter("@avgprice>=2")
        .sortBy(10, SortedField.asc("@state"))

    println("executing:")
    println(r.argsString)
    val res2 = client.aggregate(r)

    println("result 2: $res2")
    res2.results.forEach { doc ->
        println("doc: $doc")
    }

the exception is

Exception in thread "main" java.lang.ClassCastException: redis.clients.jedis.exceptions.JedisDataException cannot be cast to [B
	at io.redisearch.AggregationResult.<init>(AggregationResult.java:33)
	at io.redisearch.client.Client.aggregate(Client.java:413)
	at moe.nikky.redistest.RedisTestKt.main(RedisTest.kt:85)

and points to here

cur.put(new String((byte[])raw.get(j)), raw.get(j+1));

when i run this query in RedisInsight i get a error as well, so i guess there is something wrong with the logic as well..
https://i.imgur.com/lmI3C0b.png

@gkorland
Copy link
Contributor

Query.Filter

Is indeed private but it shouldn't impose an issue in pure Java, but I don't see a reason not to make it public.

@gkorland
Copy link
Contributor

As for the ClassCastException thanks for reporting, I'll push a fix soon.

@NikkyAI
Copy link
Author

NikkyAI commented Jul 20, 2020

i tested a bit more and indeed it works fine in java, no idea why kotlin is having issues there
seems like some kind of edgecase anyways

@NikkyAI NikkyAI closed this as completed Jul 20, 2020
@gkorland
Copy link
Contributor

@NikkyAI I hope 1.8.1 https://github.com/RediSearch/JRediSearch/releases/tag/v1.8.1 should fix the kotlin issues.

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