r.row 未在 Java 驱动程序中实现。改为使用 lambda 语法
r.row is not implemented in the Java driver. Use lambda syntax instead
我想用 Java 查询 RethinkDB。我有一个 table 和列 uri(类型:String
)和一个时间戳(timestampNextCrawl)(类型: long
)。我想 return 时间戳低于 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.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)
这是为什么?
您的查询有几个问题:
optArg
是 not applicable 到 table
。
- 索引在这里没有意义:
filter
总是在给定的序列上工作,你需要 table 全面扫描,除非你通过 ID 获取文档(或任何其他 RethinkDB 工具,如 between
).
- 由于 Java 驱动程序的特殊性,
filter
表达式无法工作,它只是告诉您不要直接使用 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)
我想用 Java 查询 RethinkDB。我有一个 table 和列 uri(类型:String
)和一个时间戳(timestampNextCrawl)(类型: long
)。我想 return 时间戳低于 System.currentTimeMillis()
.
查询如下所示:
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.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)
这是为什么?
您的查询有几个问题:
optArg
是 not applicable 到table
。- 索引在这里没有意义:
filter
总是在给定的序列上工作,你需要 table 全面扫描,除非你通过 ID 获取文档(或任何其他 RethinkDB 工具,如between
). - 由于 Java 驱动程序的特殊性,
filter
表达式无法工作,它只是告诉您不要直接使用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)