Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for return programs #4

Open
westonpace opened this issue Jan 13, 2024 · 0 comments
Open

Add support for return programs #4

westonpace opened this issue Jan 13, 2024 · 0 comments

Comments

@westonpace
Copy link
Owner

Some Substrait functions can feature "return programs" which are small programs that must be run to calculate the return type. For example:

    name: "add"
    description: "Add two decimal values."
    impls:
      - args:
          - name: x
            value: decimal<P1,S1>
          - name: y
            value: decimal<P2,S2>
        options:
          overflow:
            values: [ SILENT, SATURATE, ERROR ]
        return: |-
          init_scale = max(S1,S2)
          init_prec = init_scale + max(P1 - S1, P2 - S2) + 1
          min_scale = min(init_scale, 6)
          delta = init_prec - 38
          prec = min(init_prec, 38)
          scale_after_borrow = max(init_scale - delta, min_scale)
          scale = init_prec > 38 ? scale_after_borrow : init_scale
          DECIMAL<prec, scale>

We should be able to add function builders for these functions and should be able to calculate the return type correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant