ALTER VIEW

Se aplica a:casilla marcada como Sí Databricks SQL casilla marcada como Sí Databricks Runtime

Altera los metadatos asociados a la vista. Puede cambiar la definición de la vista, modificar el nombre de una vista por un nombre diferente, así como establecer y anular los metadatos de la vista al establecer TBLPROPERTIES.

Si la vista se almacena en caché, el comando borra los datos almacenados en caché de la vista y todos los elementos dependientes que hacen referencia a ella. La memoria caché de la vista se irá rellenando lentamente cuando se acceda a la vista la próxima vez. El comando deja los dependientes de la vista sin almacenar en caché.

Sintaxis

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
  }

Parámetros

  • view_name

    Identifica la vista que se va a alterar. Si no se encuentra la vista, Azure Databricks genera un error TABLE_OR_VIEW_NOT_FOUND.

  • RENAME TO to_view_name

    Cambia el nombre de la vista existente dentro del esquema. No se puede cambiar el nombre de las vistas materializadas.

    to_view_name especifica el nuevo nombre de la vista. Si to_view_name ya existe, se produce TableAlreadyExistsException. Si to_view_name está cualificado, debe coincidir con el nombre del esquema de view_name.

  • SET TBLPROPERTIES

    Este parámetro le permite establecer o restablecer una o más propiedades que defina el usuario.

  • UNSET TBLPROPERTIES

    Este parámetro quita una o más propiedades que defina el usuario.

  • AS query

    Consulta que construye la vista a partir de tablas base u otras vistas.

    Esta cláusula es equivalente a una instrucción CREATE OR REPLACE VIEW sobre una vista existente, excepto que se conservan los privilegios concedidos sobre la vista.

  • [ SET ] OWNER TO principal

    Transfiere la propiedad de la vista a principal. A menos que la vista esté definida en hive_metastore, solo puede transferir la propiedad a un grupo al que pertenezca.

    Se aplica a:casilla marcada como sí Databricks SQL casilla marcada como Sí Databricks Runtime 11.3 LTS y versiones posteriores

    SET se permite como una palabra clave opcional.

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

    Aplica etiquetas a la vista. Debe tener el permiso apply_tag para agregar etiquetas a la vista.

    Se aplica a:casilla marcada como sí Databricks SQL casilla marcada como sí Databricks Runtime 13.3 LTS y versiones posteriores

  • ETIQUETAS UNSET ( tag_name [, ...] )

    Elimina las etiquetas de la tabla. Debe tener el permiso apply_tag para quitar etiquetas de la vista.

    Se aplica a:casilla marcada como sí Databricks SQL casilla marcada como sí Databricks Runtime 13.3 LTS y versiones posteriores

  • tag_name

    Un literal de STRING. El tag_name debe ser único dentro del vista.

  • tag_value

    Un literal de STRING.

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

    Permite agregar una programación a una vista materializada o modificarla.

    Si se proporciona, programa la tabla de streaming para actualizar sus datos con la programación quartz cron especificada. Solo se aceptan valores time_zone_values. No se admite AT TIME ZONE LOCAL. Si AT TIME ZONE no está presente, se usa la zona horaria de la sesión. Si AT TIME ZONE no está presente y no se establece la zona horaria de la sesión, se produce un error. SCHEDULE es equivalente semánticamente a SCHEDULE REFRESH.

    No se puede usar la sintaxis SCHEDULE en una definición de canalización de Delta Live Tables.

Ejemplos

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