r.row未在Java驱动程序中实现。请改用lambda语法

时间:2018-04-22 20:15:48

标签: java rethinkdb

我想用Java查询RethinkDB。我有一个表格,其中包含 uri (类型:String)和时间戳( timestampNextCrawl )(类型:long)。我想返回时间戳低于System.currentTimeMillis()的所有行(但只有 uri 列)。

查询如下所示:

Cursor<String> cursor = r.db("squirrel")
        .table("knownurifilter")
        .optArg("index", "uri")
        .filter(r.row("timestampNextCrawl").le(System.currentTimeMillis()))
        .g("uri")
        .run(connector.connection);

它给了我以下错误:

com.rethinkdb.gen.exc.ReqlDriverError: r.row is not implemented in the Java driver. Use lambda syntax instead

at com.rethinkdb.gen.model.TopLevel.row(TopLevel.java:27)
at org.aksw.simba.squirrel.data.uri.filter.RDBKnownUriFilter.getOutdatedUris(RDBKnownUriFilter.java:57)
at org.aksw.simba.rethinkdb.UriTimeStampTests.testGetOutdatedUris(UriTimeStampTests.java:48)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at junit.framework.TestCase.runTest(TestCase.java:176)
at junit.framework.TestCase.runBare(TestCase.java:141)
at junit.framework.TestResult$1.protect(TestResult.java:122)
at junit.framework.TestResult.runProtected(TestResult.java:142)
at junit.framework.TestResult.run(TestResult.java:125)
at junit.framework.TestCase.run(TestCase.java:129)
at junit.framework.TestSuite.runTest(TestSuite.java:252)
at junit.framework.TestSuite.run(TestSuite.java:247)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:86)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

为什么?

1 个答案:

答案 0 :(得分:0)

您的查询中存在一些问题:

  • optArg not applicabletable
  • 索引在这里没有意义:filter始终适用于给定的序列,除非您通过ID(或任何其他RethinkDB工具,如between)获取文档,否则您需要表全扫描。 / LI>
  • filter表达式因Java驱动程序细节而无法工作,它只是告诉您不要直接使用RethinkDB.r。请尝试使用ReqlFunction1代替。

因此,您必须将查询更改为

RethinkDB.r.db("squirell")
    .table("knownurifilter")
    // Java 8
    .filter(doc -> doc.getField("timestampNextCrawl").le(System.currentTimeMillis()))
    .getField("uri")
    .run(connector.connection)

RethinkDB.r.db("squirrel")
    .table("knownurifilter")
    // Java 7 and earlier
    .filter(new ReqlFunction1() {
        @Override
        public Object apply(final ReqlExpr doc) {
            return doc.getField("timestampNextCrawl").le(System.currentTimeMillis());
        }
    })
    .getField("uri")
    .run(connector.connection)