使用java bolt驱动程序对AWS neptune进行日期特定查询

zqdjd7g9  于 2023-04-10  发布在  Java
关注(0)|答案(1)|浏览(65)

我想使用bolt java驱动程序将边缘添加到AWS neptune Graph DB。边缘的属性之一包含日期和时间。但似乎neptune支持java.util.Date Object,但bolt驱动程序不支持java.util.Date Object,并且它支持java.time.LocalDateTime Object。有没有办法解决这个问题?在下面添加更多细节可能会有所帮助。
螺栓驱动器版本:4.3.3
Java版本:Java 11(我正在运行AWS Lambda的代码,它不支持java11之后的Java)

示例代码如下:

Maven依赖:

<dependency>
          <groupId>org.neo4j.driver</groupId>
          <artifactId>neo4j-java-driver</artifactId>
          <version>4.3.3</version>
      </dependency>

将数据写入AWS Neptune Graph DB的Java代码:

Driver boltDriver = GraphDatabase.driver(neptuneConnectionString,
                    Config.builder().withConnectionTimeout(30, TimeUnit.SECONDS)
                            .withEncryption()
                            .withTrustStrategy(Config.TrustStrategy.trustSystemCertificates())
                            .build());

Map<String, Object> parameters = new HashMap<>();
        allParameters.put("locationId", "dsfsdf3453");
        allParameters.put("deviceId", "fdfdf4534");
        allParameters.put("edgeId", "dfdf45345");
        allParameters.put("loginAt", LocalDateTime.now());

var query = "MERGE (l:Location_J {locationId: $locationId}) MERGE (d:Device_J {deviceId: $deviceId}) MERGE (l)-[a:ACCESSES_J {loginAt: $loginAt}]->(d)";

boltDriver.session().run(query, parameters);

我得到以下例外:

WARNING: [0x06247997][uat-niyothon-neptune-2023.cluster-cfg5tfk5qker.ap-south-1.neptune.amazonaws.com:8182][021cdffffe623928-000035fc-0000b02d-f131b528da33cefe-05e79a93] Fatal error occurred in the pipeline
org.neo4j.driver.exceptions.DatabaseException: "Unexpected server exception 'Operation terminated (internal error)'"
at org.neo4j.driver.internal.util.ErrorUtil.newNeo4jError(ErrorUtil.java:90)
at org.neo4j.driver.internal.async.inbound.InboundMessageDispatcher.handleFailureMessage(InboundMessageDispatcher.java:108)
at org.neo4j.driver.internal.messaging.common.CommonMessageReader.unpackFailureMessage(CommonMessageReader.java:83)
at org.neo4j.driver.internal.messaging.common.CommonMessageReader.read(CommonMessageReader.java:59)
at org.neo4j.driver.internal.async.inbound.InboundMessageHandler.channelRead0(InboundMessageHandler.java:83)
at org.neo4j.driver.internal.async.inbound.InboundMessageHandler.channelRead0(InboundMessageHandler.java:35)
at org.neo4j.driver.internal.shaded.io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:99)
at org.neo4j.driver.internal.shaded.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at org.neo4j.driver.internal.shaded.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at org.neo4j.driver.internal.shaded.io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
at org.neo4j.driver.internal.shaded.io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:324)
at org.neo4j.driver.internal.shaded.io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:296)
at org.neo4j.driver.internal.async.inbound.MessageDecoder.channelRead(MessageDecoder.java:47)
at org.neo4j.driver.internal.shaded.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at org.neo4j.driver.internal.shaded.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at org.neo4j.driver.internal.shaded.io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
at org.neo4j.driver.internal.shaded.io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:324)
at org.neo4j.driver.internal.shaded.io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:296)
at org.neo4j.driver.internal.shaded.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at org.neo4j.driver.internal.shaded.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at org.neo4j.driver.internal.shaded.io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
at org.neo4j.driver.internal.shaded.io.netty.handler.ssl.SslHandler.unwrap(SslHandler.java:1368)
at org.neo4j.driver.internal.shaded.io.netty.handler.ssl.SslHandler.decodeJdkCompatible(SslHandler.java:1234)
at org.neo4j.driver.internal.shaded.io.netty.handler.ssl.SslHandler.decode(SslHandler.java:1280)
at org.neo4j.driver.internal.shaded.io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:507)
at org.neo4j.driver.internal.shaded.io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:446)
at org.neo4j.driver.internal.shaded.io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:276)
at org.neo4j.driver.internal.shaded.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at org.neo4j.driver.internal.shaded.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at org.neo4j.driver.internal.shaded.io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
at org.neo4j.driver.internal.shaded.io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
at org.neo4j.driver.internal.shaded.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at org.neo4j.driver.internal.shaded.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at org.neo4j.driver.internal.shaded.io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
at org.neo4j.driver.internal.shaded.io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)
at org.neo4j.driver.internal.shaded.io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:719)
at org.neo4j.driver.internal.shaded.io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:655)
at org.neo4j.driver.internal.shaded.io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:581)
at org.neo4j.driver.internal.shaded.io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
at org.neo4j.driver.internal.shaded.io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
at org.neo4j.driver.internal.shaded.io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at org.neo4j.driver.internal.shaded.io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.base/java.lang.Thread.run(Unknown Source)```
nszi6y05

nszi6y051#

目前,Amazon Neptune与Java Bolt客户端的集成不支持使用Java LocalDateTime类。
但是,您可以使用datetime函数并以这种方式将日期信息添加到查询中(作为字符串)。例如:

MERGE (l:Location_J {locationId: $locationId}) 
MERGE (d:Device_J {deviceId: $deviceId}) 
MERGE (l)-[a:ACCESSES_J {loginAt: datetime('2023-04-07T16:44:19Z'}]->(d)

或者,使用参数化形式

MERGE (l:Location_J {locationId: $locationId}) 
MERGE (d:Device_J {deviceId: $deviceId}) 
MERGE (l)-[a:ACCESSES_J {loginAt: datetime($myDatetimeString)}]->(d)

关键的部分是,现在,日期参数需要作为字符串提供。

相关问题