0

I am getting "Java compilation failed: cannot be resolved to a datatype" when trying to run the function in cassandra 3.11 version. I have compiled my class and deployed the jar in cassandra lib directory as well. Can somebody please help?Also please let me know if cassandra 3.11 is compatible to execute external JAR-based code for UDFs or not.

##    package getMap;

import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;

public class RollAgent {

public static void main(String[] args) {
    // TODO Auto-generated method stub
    Map<String, Integer> data = new HashMap<String, Integer>();
    data.put("abcd", 2);
    Map<String, Integer> returndata = RollAgent.grpagents(data);
     System.out.println(returndata);
}

private static Logger LOGGER = Logger.getLogger("string");
public static Map<String, Integer> grpagents(Map<String, Integer> data) {
    LOGGER.info("Steppin into agent rollups");
      Map<String, Integer> map = new HashMap<>();
      map.put("1", 10);
      map.put("2", 20);
      map.put("3", 30);
      return map;
  }
  }

   cassandra UDF:-

  CREATE OR REPLACE FUNCTION 
  glowroot1.grpagentNtracetallydur(state map<text, int>)  
  CALLED ON NULL INPUT 
  RETURNS map<text, int> 
  LANGUAGE java 
  as 'return getMap.RollAgent.grpagents(state);';
  ##
Alejandro
  • 7,290
  • 4
  • 34
  • 59
guest1
  • 1

2 Answers2

0

You should be able to create your own method if you use Cassandra 2.2 or later versions, although I found some open issues regarding 3: here is an example, that UDF works with 2.2 but does not work with 3.10

What I would double check:

  • cassandra.yaml, by default User-defined-functions are disabled in the config - set enable_user_defined_functions=true to enable it.

  • after copying the jar file to the $CASSANDRA_HOME/lib directory, restart the cassandra node.

Also based on the documentation I would modify the UDF:

CREATE OR REPLACE FUNCTION 
glowroot1.grpagentNtracetallydur(state map<text, int>)  
CALLED ON NULL INPUT 
RETURNS map<text, int> 
LANGUAGE java 
as $$return getMap.RollAgent.grpagents(state);$$;
Andrea Nagy
  • 1,201
  • 9
  • 21
0

For 3.10 works:

  1. You can add your class to package com.datastax.driver.core
  2. But you can not use getClassLoader for Logger.getLogger or you need to patch ThreadAwareSecurityManager.java (comment super.checkPermission(perm))

    public void checkPermission(Permission perm)
    {
            if (!isSecuredThread())
                    return;
            // required by JavaDriver 2.2.0-rc3 and 3.0.0-a2 or newer
            // code in com.datastax.driver.core.CodecUtils uses Guava stuff, which in turns requires this permission
            if (CHECK_MEMBER_ACCESS_PERMISSION.equals(perm))
                    return;
            return; //super.checkPermission(perm);
    }