如何将 Map 类型的参数从 Java 传递给 orientdb groovy 函数

How to pass Map type of parameter to orientdb groovy function from Java

我正在尝试将 Map 作为我的 orientdb groovy 函数的输入。但是 Groovy 函数正在将我的 Map 输入参数视为字符串。

请建议如何将输入参数的 Map 类型传递给 orientdb groovy 函数。

代码

public void MapInputTest() {
     Map < String, Object > inputMap = new HashMap < String, Object > ();
     inputMap.put("serviceId", "ETHA12721205");
     inputMap.put("serviceId1", "ETHA127212051");
     inputMap.put("serviceId2", "ETHA127212052");

     g.execute(Script.function("MapInputFunction", inputMap));
     System.out.println("returnedString is : ");
}

groovy 函数:

def MapInputFunction(Map mapInput) {
    println("class type of input parameter" + mapInput.getClass())
    println("class type " + mapInput)
    def tempMap = [: ]
    tempMap = mapInput
    return tempMap.get('serviceId')
}

错误

com.orientechnologies.orient.core.exception.OCommandExecutionException: Failed to execute command: function.MapInputFunction Cause:No signature of method: Script1.MapInputFunction() is applicable for argument types: (java.lang.String, java.lang.String, java.lang.String) values: [ETHA127212051, ETHA12721205, ETHA127212052]
    Possible solutions: MapInputFunction2(), MapInputFunction(java.lang.Object)
        at platform.orientdb.storage.DataGridStorage.executeCommand(DataGridStorage.java:631)
        at platform.orientdb.storage.DataGridStorage.command(DataGridStorage.java:601)
        at platform.orientdb.storage.message.CommandMessage.processMessage(CommandMessage.java:27)
        at platform.orientdb.storage.message.TxMessage.process(TxMessage.java:52)
        at platform.orientdb.storage.actor.TransactionActor.processMessage(TransactionActor.java:71)
        at platform.orientdb.storage.actor.ExternalStorageActor.onReceive(ExternalStorageActor.java:16)
        at akka.actor.UntypedActor$$anonfun$receive.applyOrElse(UntypedActor.scala:165)
        at akka.actor.Actor$class.aroundReceive(Actor.scala:484)
        at akka.actor.UntypedActor.aroundReceive(UntypedActor.scala:95)
        at akka.actor.ActorCell.receiveMessage(ActorCell.scala:526)
        at akka.actor.ActorCell.invoke(ActorCell.scala:495)
        at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:257)
        at akka.dispatch.Mailbox.run(Mailbox.scala:224)
        at akka.dispatch.Mailbox.exec(Mailbox.scala:234)
        at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)*emphasized text*
        at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
        at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
        at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)

在脚本中,假设参数的名称是 inputMap

然后发送以下内容

 Map < String, Object > parameters= new HashMap < String, Object > ();
     parameters.put("serviceId", "ETHA12721205");
     parameters.put("serviceId1", "ETHA127212051");

 Map < String, Object > inputMap = new HashMap < String, Object > ();
inputMap.put("inputMap",inputMap)

     g.execute(Script.function("MapInputFunction", inputMap));
     System.out.println("returnedString is : ");

脚本将能够读取作为地图数据结构的 inputMap