[
https://issues.apache.org/jira/browse/SAMZA-1740?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16508432#comment-16508432
]
ASF GitHub Bot commented on SAMZA-1740:
---------------------------------------
Github user asfgit closed the pull request at:
https://github.com/apache/samza/pull/545
> 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
> Priority: Major
>
> 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)