ALTER VIEW

적용 대상:검사 '예'로 표시 Databricks SQL 검사 '예'로 표시 Databricks 런타임

뷰와 연결된 메타데이터를 변경합니다. TBLPROPERTIES를 설정하여 뷰 정의를 변경하고, 뷰 이름을 다른 이름으로 변경하고, 뷰 메타데이터를 설정 및 설정 해제할 수 있습니다.

뷰가 캐시된 경우 이 명령은 뷰의 캐시된 데이터와 뷰를 참조하는 모든 종속 항목을 지웁니다. 다음에 뷰에 액세스할 때는 뷰 캐시가 채워지는 시간이 지연됩니다. 이 명령은 뷰의 종속 항목을 캐시되지 않은 상태로 둡니다.

구문

ALTER [ MATERIALIZED ] VIEW view_name
  { rename |
    SET TBLPROPERTIES clause |
    UNSET TBLPROPERTIES clause |
    alter_body |
    owner_to |
    schedule
    SET TAGS clause |
    UNSET TAGS clause }}}

rename
  RENAME TO to_view_name

alter_body
  AS query

property_key
  { idenitifier [. ...] | string_literal }

owner_to
  [ SET ] OWNER TO principal

schedule
  {
    { ADD | ALTER } SCHEDULE [ REFRESH ]
      CRON cron_string [ AT TIME ZONE timezone_id ] |
    DROP SCHEDULE
  }

매개 변수

  • view_name

    변경할 뷰를 식별합니다. 뷰를 찾을 수 없으면 Azure Databricks에서 TABLE_OR_VIEW_NOT_FOUND 오류가 발생합니다.

  • RENAME TO to_view_name

    스키마 내의 기존 뷰 이름을 바꿉니다. 구체화된 뷰의 이름을 바꿀 수 없습니다.

    to_view_name은 뷰의 새 이름을 지정합니다. to_view_name이 이미 있으면 TableAlreadyExistsException이 throw됩니다. to_view_name이 정규화된 경우 view_name스키마 이름과 일치해야 합니다.

  • SET TBLPROPERTIES

    하나 이상의 사용자 정의 속성을 설정 또는 다시 설정합니다.

  • UNSET TBLPROPERTIES

    사용자 정의 속성을 하나 이상 제거합니다.

  • AS query

    기본 테이블 또는 다른 뷰에서 뷰를 생성하는 쿼리입니다.

    이 절은 뷰에 부여된 권한이 유지된다는 점을 제외하고 기존 뷰의 CREATE OR REPLACE VIEW 문과 동일합니다.

  • [ SET ] OWNER TO principal

    뷰의 소유권을 principal로 이전합니다. hive_metastore에 뷰가 정의되지 않은 경우 사용자가 속한 그룹에만 소유권을 이전할 수 있습니다.

    적용 대상:검사 '예'로 표시 Databricks SQL 검사 '예'로 표시 Databricks Runtime 11.3 LTS 이상

    SET는 선택적 키워드로 허용됩니다.

  • SET TAGS ( { tag_name = tag_value } [, ...] )

    보기에 태그를 적용합니다. 뷰에 apply_tag 태그를 추가할 수 있는 권한이 있어야 합니다.

    적용 대상:검사 '예'로 표시 Databricks SQL 검사 '예'로 표시 Databricks Runtime 13.3 LTS 이상

  • UNSET 태그 ( tag_name [, ...] )

    테이블에서 태그를 제거합니다. 보기에서 태그를 제거할 수 있는 권한이 있어야 합니다 apply_tag .

    적용 대상:검사 '예'로 표시 Databricks SQL 검사 '예'로 표시 Databricks Runtime 13.3 LTS 이상

  • tag_name

    리터럴 STRING. tag_name 뷰 내에서 고유해야 합니다.

  • tag_value

    리터럴 STRING.

  • 일정 [ 새로 고침 ] CRON cron_string [ 표준 시간대 timezone_id ]

    구체화된 뷰에 일정을 추가하거나 일정을 변경할 수 있습니다.

    제공된 경우 스트리밍 테이블 또는 구체화된 뷰를 예약하여 지정된 석영 cron 일정으로 데이터를 새로 고칩니다. time_zone_values허용됩니다. AT TIME ZONE LOCAL은 지원되지 않습니다. 없는 경우 AT TIME ZONE 세션 표준 시간대가 사용됩니다. AT TIME ZONE 세션 표준 시간대가 설정되어 있지 않으면 오류가 throw됩니다. SCHEDULE 의미 체계는 .에 해당합니다 SCHEDULE REFRESH.

    Delta Live Tables 파이프라인 정의에는 구문을 사용할 SCHEDULE 수 없습니다.

예제

-- Rename only changes the view name.
-- The source and target schemas of the view have to be the same.
-- Use qualified or unqualified name for the source and target view.
> ALTER VIEW tempsc1.v1 RENAME TO tempsc1.v2;

-- Verify that the new view is created.
> DESCRIBE TABLE EXTENDED tempsc1.v2;
                            c1       int   NULL
                            c2    string   NULL

  # Detailed Table Information
                      Database   tempsc1
                         Table        v2

-- Before ALTER VIEW SET TBLPROPERTIES
> DESCRIBE TABLE EXTENDED tempsc1.v2;
                            c1       int   null
                            c2    string   null

  # Detailed Table Information
                      Database   tempsc1
                         Table        v2
              Table Properties    [....]

-- Set properties in TBLPROPERTIES
> ALTER VIEW tempsc1.v2 SET TBLPROPERTIES ('created.by.user' = "John", 'created.date' = '01-01-2001' );

-- Use `DESCRIBE TABLE EXTENDED tempsc1.v2` to verify
> DESCRIBE TABLE EXTENDED tempsc1.v2;
                            c1                                                   int   NULL
                            c2                                                string   NULL

  # Detailed Table Information
                      Database                                               tempsc1
                         Table                                                    v2
              Table Properties [created.by.user=John, created.date=01-01-2001, ....]

-- Remove the key created.by.user and created.date from `TBLPROPERTIES`
> ALTER VIEW tempsc1.v2 UNSET TBLPROPERTIES (`created`.`by`.`user`, created.date);

-- Use `DESCRIBE TABLE EXTENDED tempsc1.v2` to verify the changes
> DESCRIBE TABLE EXTENDED tempsc1.v2;
                            c1       int   NULL
                            c2    string   NULL

  # Detailed Table Information
                      Database   tempsc1
                         Table        v2
              Table Properties    [....]

-- Change the view definition
> ALTER VIEW tempsc1.v2 AS SELECT * FROM tempsc1.v1;

-- Use `DESCRIBE TABLE EXTENDED` to verify
> DESCRIBE TABLE EXTENDED tempsc1.v2;
                            c1                        int   NULL
                            c2                     string   NULL

  # Detailed Table Information
                      Database                    tempsc1
                         Table                         v2
                          Type                       VIEW
                     View Text   select * from tempsc1.v1
            View Original Text   select * from tempsc1.v1

-- Transfer ownership of a view to another user
> ALTER VIEW v1 OWNER TO `alf@melmak.et`

-- Adds a schedule to refresh a materialized view once a day
-- at midnight in Los Angeles
> ALTER MATERIALIZED VIEW my_mv
    ADD SCHEDULE CRON '0 0 0 * * ? *' AT TIME ZONE 'America/Los_Angeles';

-- Alters the schedule to run every 15 minutes for a materialized view
> ALTER MATERIALIZED VIEW my_mv
    ALTER SCHEDULE CRON '0 0/15 * * * ? *';

-- Drops the schedule for a materialized view
> ALTER MATERIALIZED VIEW my_mv
    DROP SCHEDULE;

-- Applies three tags to the view named `test`.
> ALTER VIEW test SET TAGS ('tag1' = 'val1', 'tag2' = 'val2', 'tag3' = 'val3');

-- Removes three tags from the view named `test`.
> ALTER VIEW test UNSET TAGS ('tag1', 'tag2', 'tag3');