ALTER VIEW

Si applica a:segno di spunta sì Databricks SQL segno di spunta sì Databricks Runtime

Modifica i metadati associati alla vista. Può modificare la definizione della vista, modificare il nome di una vista impostando un nome diverso, impostando e annullando l'impostazione dei metadati della vista.TBLPROPERTIES

Se la visualizzazione viene memorizzata nella cache, il comando cancella i dati memorizzati nella cache della visualizzazione e tutti i relativi dipendenti che vi fanno riferimento. La cache della visualizzazione verrà riempita in modo differire quando si accede alla visualizzazione alla successiva volta. Il comando lascia i dipendenti della visualizzazione come non memorizzati nella cache.

Sintassi

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
  }

Parametri

  • view_name

    Identifica la visualizzazione da modificare. Se non è possibile trovare la vista azure Databricks genera un errore di TABLE_OR_VIEW_NOT_FOUND .

  • RINOMINA IN to_view_name

    Rinomina la vista esistente all'interno dello schema. Non è possibile rinominare le viste materializzate.

    to_view_name specifica il nuovo nome della visualizzazione. Se l'oggetto to_view_name esiste già, viene generato un oggetto TableAlreadyExistsException . Se to_view_name è qualificato, deve corrispondere al nome dello schema di view_name.

  • edizione Standard T TBLPROPERTIES

    Imposta o reimposta una o più proprietà definite dall'utente.

  • UN edizione Standard T TBLPROPERTIES

    Rimuove una o più proprietà definite dall'utente.

  • Query AS

    Query che costruisce la vista da tabelle di base o da altre viste.

    Questa clausola equivale a un'istruzione CREATE OR REPLACE VIEW in una vista esistente, ad eccezione del fatto che i privilegi concessi nella vista vengono mantenuti.

  • [ edizione Standard T ] OWNER TO principal

    Trasferisce la proprietà della vista a principal. A meno che la vista non sia definita in hive_metastore , è possibile trasferire la proprietà solo a un gruppo a cui si appartiene.

    Si applica a:segno di spunta sì Databricks SQL segno di spunta sì Databricks Runtime 11.3 LTS e versioni successive

    SET è consentito come parola chiave facoltativa.

  • tag edizione Standard T ( { tag_name = tag_value } [, ...] )

    Applicare tag alla visualizzazione. È necessario disporre apply_tag dell'autorizzazione per aggiungere tag alla visualizzazione.

    Si applica a:segno di spunta sì Databricks SQL segno di spunta sì Databricks Runtime 13.3 LTS e versioni successive

  • UN edizione Standard T TAGS ( tag_name [, ...] )

    Rimuovere i tag dalla tabella. È necessario disporre apply_tag dell'autorizzazione per rimuovere i tag dalla visualizzazione.

    Si applica a:segno di spunta sì Databricks SQL segno di spunta sì Databricks Runtime 13.3 LTS e versioni successive

  • tag_name

    Valore letterale STRING. Deve tag_name essere univoco all'interno della visualizzazione.

  • tag_value

    Valore letterale STRING.

  • SCHEDULE [ REFRESH ] CRON cron_string [ AT TIME ZONE timezone_id ]

    Consente di aggiungere o modificare la pianificazione di una vista materializzata.

    Se specificato, pianifica la tabella di streaming o la vista materializzata per aggiornare i dati con la pianificazione cron di quarzi specificata. Vengono accettati solo time_zone_values . AT TIME ZONE LOCAL non è supportata. Se AT TIME ZONE è assente, viene usato il fuso orario della sessione. Se AT TIME ZONE è assente e il fuso orario della sessione non è impostato, viene generato un errore. SCHEDULE è semanticamente equivalente a SCHEDULE REFRESH.

    Non è possibile usare la SCHEDULE sintassi in una definizione di pipeline Delta Live Tables.

Esempi

-- 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');