entry_point

entry_point

entry_point는 Python UDF를 만들 때 호출할 Python 함수를 지정하는 설정이에요. Python UDF는 현재 Snowflake, BigQuery, Databricks에서 지원되며, 각 웨어하우스마다 엔트리 포인트 함수를 부르는 이름이 달라요.

출처: 문서

본문

functions:
  - name: <function name>
    config:
      entry_point: <string> # required for Snowflake and BigQuery; optional and ignored on Databricks

정의 (Definition)

Python UDF를 만들 때 entry_point에서 호출할 Python 함수를 지정해요. Python UDF는 현재 Snowflake, BigQuery, Databricks에서 지원되며, 각 웨어하우스마다 엔트리 포인트 함수를 부르는 이름이 달라요.

예시 (Example)

functions/my_function.py에 엔트리 포인트로 main 함수를 사용하는 다음과 같은 Python UDF가 있다고 해 볼게요:

import re

def _digits_only(s: str) -> bool:
    return bool(re.search(r'^[0-9]+$', s or ''))

def _to_flag(is_match: bool) -> int:
    return 1 if is_match else 0

def main(a_string: str) -> int:
    """
    This is used as the entry point for the UDF.
    Returns 1 if a_string represents a positive integer (e.g., "10"),
    else 0.
    """
    return _to_flag(_digits_only(a_string))

UDF를 정의한 후 YAML 파일에서 mainentry_point로 지정할 수 있어요. entry_point: mainmain 함수를 UDF의 엔트리 포인트로 가리키고, _digits_only_to_flag는 헬퍼 함수예요.

functions:
  - name: is_positive_int
    description: Returns 1 if a_string matches ^[0-9]+$, else 0
    config:
      runtime_version: "3.11"    # required
      entry_point: main          # required: points to the function above
    arguments:
      - name: a_string
        data_type: string
    returns:
      data_type: integer

더 알아보기 (Learn more)