snowflakedb / snowflake-cli

Snowflake CLI is an open-source command-line tool explicitly designed for developer-centric workloads in addition to SQL operations.
https://docs.snowflake.com/developer-guide/snowflake-cli-v2/index
Apache License 2.0
168 stars 53 forks source link

SNOW-1230490: Allow Snowpark Function to define returns as name-type list #894

Open kokorin opened 5 months ago

kokorin commented 5 months ago

Description

We are investigating usage of Snow CLI 2.1.0 in our project in which we have UDTF defined. Right now returns property of Snowflake Function definition has str type. So we have to use a workaround defining returns: "table (id int, name string)".

I think it may be useful to allow name-type list to be specified the same way as for signature property:

...
returns:
  - name: id
    type: int
  - name: name
    type: string
...

Context

No response

sfc-gh-turbaszek commented 5 months ago

Thanks for the proposal @kokorin! Happy to brainstorm on that one. Will simply changing the returns to list be enough? I have a feeling we would need to consider something like

returns:
   return_type: table
   columns:
       - name: "foo"
          type: "string"

returns:
   return_type: value
   type: "string"

What do you think?

kokorin commented 5 months ago

@sfc-gh-turbaszek to be honest return_type is confusing especially in second case. May be it could be better to have another top-level list in snowflake.yml:

definition_version: 1
snowpark:
  functions: 
    - name: my_udf
      # other props
      returns: string
  table_functions: 
    - name: my_udtf
      # other props
      returns: 
        - name: id
          type: int
        - name: name
          type: string
  procedures: [ ... ]

In that case it will be possible to validate signature.

Apart from that it can be useful to have more strict differentiation between UDF and UDTF:

definition_version: 1
snowpark:
  functions: 
    - name: my_udf
      # other props
      returns: string
    - name: my_udtf
      # other props
      returns_columns: 
        - name: id
          type: int
        - name: name
          type: string
  procedures: [ ... ]