【问题标题】:how to create javascript udf in apache cassandra如何在 apache cassandra 中创建 javascript udf
【发布时间】:2023-03-09 18:39:01
【问题描述】:

我是 Apache Cassandra 和 javascript 的新手,我需要在 Apache Cassandra 中创建 javascript udf。我在 Cassandra 中创建了一个简单的 udf,但我无法在查询中调用该函数并弹出错误

这里是与我的问题相关的所有详细信息

我的桌子是这样的

 id   | age | course | name    | sex
------+-----+--------+---------+--------
 st05 |  23 | b.tech |  nafees |   male
 st03 |  27 |    mca | lengdon |   male
 st02 |  24 |    mca |  jaanvi | female
 st01 |  22 |    mca |   sahil |   male
 st04 |  23 | b.tech |     jay |   male

CREATE TABLE test.student (
        id text PRIMARY KEY,
        age int,
        course text,
        name text,
        sex text
    )

我还在年龄列上创建了一个索引

CREATE INDEX age_index ON test.student (age);

我的函数是这样的

CREATE OR REPLACE FUNCTION  demojs (input int) 
   CALLED ON NULL INPUT 
   RETURNS int 
   LANGUAGE javascript AS 'function(input){
    return input;
   }';

我的查询是

 select * from student where age=demojs(22);

当我尝试执行查询时,出现以下错误

Traceback(最近一次调用最后一次):文件“C:\Program 文件\apache-cassandra-3.11.6\bin\cqlsh.py",第 1050 行,在 perform_simple_statement 结果 = future.result() 文件“C:\Program Files\apache-cassandra-3.11.6\bin..\lib\cassandra-driver-internal-only-3.11.0-bb96859b.zip\cassandra-driver-3.11 .0-bb96859b\cassandra\cluster.py", 第 3925 行,结果 raise self._final_exception FunctionFailure:来自服务器的错误:code=1400 [用户定义函数失败] message="执行 'test.demojs[int]' 失败: com.datastax.driver.core.exceptions.InvalidTypeException:无效 CQL 类型 int 的值"

谁能告诉我在这里做错了什么,这将有很大帮助

【问题讨论】:

    标签: javascript cassandra user-defined-functions


    【解决方案1】:

    函数的主体会是这样的

       CREATE OR REPLACE FUNCTION  demojs (input int) 
       CALLED ON NULL INPUT 
       RETURNS int 
       LANGUAGE javascript AS 'input;';
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-22
      • 2015-02-24
      相关资源
      最近更新 更多