title: SparklyR wrapper for spark SQL: sqlContext.sql
body: <p>I am trying to write a wrapper for SQL function for SparklyR. I have created the following function:    </p>
  
  <pre><code>sqlfunction &lt;- function(sc, block) {
    spark_context(sc) %&gt;% 
  invoke("sqlContext.sql", block) }
  </code></pre>
  
  <p>Then I call it using the following:</p>
  
  <pre><code>newsqlData &lt;- sqlfunction(sc, "select
                            substr(V1,1,2),
                            substr(V1,3,3),
                            substr(V1,6,6),
                            substr(V1,12,4),
                            substr(V1,16,4)
                            FROM TABLE1 WHERE V1 IS NOT NULL")
  </code></pre>
  
  <p>But I get the following error:</p>
  
  <pre><code>Error: java.lang.IllegalArgumentException: invalid method sqlContext.sql for object 12
  at sparklyr.Invoke$.invoke(invoke.scala:113)
  at sparklyr.StreamHandler$.handleMethodCall(stream.scala:89)
  at sparklyr.StreamHandler$.read(stream.scala:55)
  at sparklyr.BackendHandler.channelRead0(handler.scala:49)
  at sparklyr.BackendHandler.channelRead0(handler.scala:14)
  at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105)
  at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308)
  at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294)
  at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
  at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308)
  at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294)
  at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:244)
  at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308)
  at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294)
  at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:846)
  at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131)
  at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:511)
  at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468)
  at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382)
  at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354)
  at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:111)
  at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:137)
  at java.lang.Thread.run(Thread.java:745)
  </code></pre>
  
  <p>Any suggestions or fixes would be greatly appreciated. </p>