Spark SQL UDF

Source: Internet
Author: User

Currently Spark SQL does not support custom UDFs, catalyst for the underlying SQL engine.

In SqlContext there is an analyzer to give a emptyfunctionregistry, if the SQL engine function can not be found, will be found in this functionregistry

Lookup in Emptyfunctionregistry just throws an exception.

So I've customized a functionregistry, SqlContext

@transient  protected[sql]lazyval analyzer:analyzer =    newanalyzer (catalog, Emptyfunctionregistry, CaseSensitive =true)

Class Udfrgistry extends Functionregistry {    def lookupfunction (name:string, children:seq[expression]): Expression = {      name.tolowercase match {case        ' col_set ' =>collect (Children (0)) Case        "Array" =>array (children (0) Case        "contains" =>contains (children) Case        _ = = throw new Unsupportedoperationexception      }    }  } class Sparksqlcontext (Val spctx:sparkcontext) extends SqlContext (spctx) {  @transient  override lazy Val Analyzer:analyzer =    New Analyzer (catalog, new UDF. Udfrgistry, casesensitive = True)}

This will allow you to find a custom function.

Spark SQL UDF

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.