You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@samza.apache.org by "Aditya (JIRA)" <ji...@apache.org> on 2018/06/05 23:59:00 UTC

[jira] [Created] (SAMZA-1740) Samza-sql: Move SamzaSqlRelRecord class out of SamzaSqlRelMessage (for UDFs).

Aditya created SAMZA-1740:
-----------------------------

             Summary: Samza-sql: Move SamzaSqlRelRecord class out of SamzaSqlRelMessage (for UDFs).
                 Key: SAMZA-1740
                 URL: https://issues.apache.org/jira/browse/SAMZA-1740
             Project: Samza
          Issue Type: Bug
            Reporter: Aditya


For app users to extract nested fields from avro records, they need to write their own UDFs. For that, they will have to refer to avro records as Java types that Samza SQL translates to and uses, and not as Avro GenericRecord. In Samza-sql, we convert GenericRecord to SamzaSqlRelRecord. Currently, SamzaSqlRelRecord is an inner class of SamzaSqlRelMessage. Considering that we are making these Java types be directly usable by app writers in UDFs, we will have to make SamzaSqlRelRecord an independent class. We will also have to move this class to Samza api module.

An example of how SamzaSqlRelRecord could be used in UDF to extract pageKey from PageViewEvent is below:

/**

*UDF that fetches the brooklin envelope metadata value, given a fieldName.
*/
public class GetPageKeyUdf implements ScalarUdf<String> {
@Override
public void init(Config udfConfig) {
}

@Override
public String execute(Object... args) {
SamzaSqlRelRecord record = (SamzaSqlRelRecord) args[0];
Optional<Object> fieldValue = Optional.empty();
if (record != null)

{ fieldValue = record.getField("pageKey"); }

if (fieldValue.isPresent())

{ return fieldValue.get().toString(); }

return null;
}
}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)