0

I want to write a Scala function like

def functionA(objectMap:Map[String, ClassB], statements: List[String]): ClassB = {
  var retObj = new ClassB
  retObj = statements
  return retObj
}

Input of this function are:

1) objectMap(Map[String, ClassB)] which is Map having objectIdentifier as key and object as Value, e.g.

Map[{"object1": An instance of class ClassB},
    {"object2": An instance of class ClassB},
    {"object3": An instance of class ClassB}]]

2) statements (List[String]), which is Scala code coming from configuration like

val tmpOb1 = <object1>.join(<object2>)
val tmpOb2 = <object3>.sum(tmpOb1)

Now what I want from functionA is to parse the statements, replace placeholders like "<object*>" from real object, taken from objectMap and execute the statements.

How can I achieve the same?

Scala Version: 2.11
Spark: 2.2.1
user811602
  • 1,314
  • 2
  • 17
  • 47
  • ClassB is Spark DataFrame. I want customer to place their business logic outside codebase. – user811602 Oct 23 '18 at 13:26
  • Can you afford the injected code to be Java instead of Scala? In that case you could use [BeanShell](http://www.beanshell.org/). Else see [Scala Bean Scripting Framework Binding](https://www.scala-lang.org/old/node/6128.html) – Serg M Ten Oct 23 '18 at 13:32
  • @SergMTen I am new to Scala. I can use java if I can run it/integrate it with Scala. Can drool do that? I don't know. I can use third party open product for same, but will prefer Scala code/native approach – user811602 Oct 23 '18 at 13:32
  • hey, @user811602, can you try to precise your question? What is classC? – Leyla Lee Oct 23 '18 at 15:42
  • @LeylaLee I have updated question. function take Map[String, DataFrame] and List[String] and return one DataFrame. – user811602 Oct 23 '18 at 18:07
  • @LeylaLee I want to move few changing part of business logic outside of main codebase and put it in config. – user811602 Oct 23 '18 at 18:10
  • I am trying to achieve same using scala interpreter and getting InternalCompilerException https://stackoverflow.com/questions/52965997/internalcompilerexception-compiling-class-was-loaded-through-a-different-loader – user811602 Oct 24 '18 at 12:21

1 Answers1

0

I have achieved same using https://stackoverflow.com/a/52986351/811602, but for same I have created whole class and stub it with passed statements and load it at runtime.

user811602
  • 1,314
  • 2
  • 17
  • 47