title: spark UDF to return list of Rows
body: <p>In spark SQL I am trying to join multiple table those are already in place.
  How ever i need to use a function which will take user input and then get details from two other tables,then use this result in the join.
  The query is some thing like below
      select  t1.col1,t1.col2,t2.col3,cast((t1.value * t3.value) from table1 t1
      left join table2 t2 on t1.col = t2.col
      left join fn_calculate (value1, value2) as t3 on t1.value = t3.value</p>
  
  <p>here fn_calculate is the function which is taking value1,value2 as parameters and then that function returns a table of rows.(in SQL server that is returning Table)</p>
  
  <p>I am trying to do this by using hive generic UDF which will take the input param and then return the dataframe? like below</p>
  
  <pre><code>public String evaluate(DeferredObject[] arguments) throws HiveException {
      if (arguments.length != 1) {
          return null;
      }
      if (arguments[0].get() == null) {
          return null;
      }
      DataFrame dataFrame = sqlContext
              .sql("select * from A where col1 = value and col2 =value2");
      javaSparkContext.close();
      return "dataFrame";
  }
  </code></pre>
  
  <p>or the scala functions do i need use like below?</p>
  
  <pre><code>static class Z extends scala.runtime.AbstractFunction0&lt;DataFrame&gt; { 
  
      @Override`enter code here`
  public DataFrame apply() {
          // TODO Auto-generated method stub
  return sqlContext.sql("select * from A where col1 = value and col2  
       =value2");
  }
  }
  </code></pre>