Code generation

Finally, things can be improved even more, since Apache Spark runs on the Java Virtual Machine (JVM), which allows byte code to be created and modified during runtime. Let's consider an addition of values a and b, resulting in the expression a+b. Normally, this expression had to be interpreted by the JVM for each row of the Dataset. It would be nice if we could generate the JVM ByteCode for this expression on the fly. This is possible, and Catalyst makes use of a very cool Scala feature called Quasiquotes, which basically allows an arbitrary string containing Scala code to be compiled into ByteCode on the fly, if it starts with q. So for example, q"row.get($a)+row.get($b)" will tell the Scala compiler to use this String to generate further JVM byte code. This way, less code has to be interpreted, which speeds things up.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.255.36