Uploaded image for project: 'Samza'
  1. Samza
  2. SAMZA-1740

Samza-sql: Move SamzaSqlRelRecord class out of SamzaSqlRelMessage (for UDFs).

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • None
    • None
    • None

    Description

      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;
      }
      }

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              atoomula Aditya Toomula
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated: