Partilhar via


LOAD DATA

Aplica-se a: Marque Sim Databricks Runtime

Carrega os dados em uma tabela Hive SerDe a partir do diretório ou arquivo especificado pelo usuário. Se um diretório for especificado, todos os arquivos do diretório serão carregados. Se um arquivo for especificado, somente o arquivo único será carregado. Além disso, a LOAD DATA instrução usa uma especificação de partição opcional. Quando uma partição é especificada, os arquivos de dados (quando a fonte de entrada é um diretório) ou o arquivo único (quando a fonte de entrada é um arquivo) são carregados na partição da tabela de destino.

Se a tabela estiver armazenada em cache, o comando limpará os dados armazenados em cache da tabela e todos os seus dependentes que se referem a ela. O cache será preenchido preguiçosamente quando a tabela ou os dependentes forem acessados na próxima vez.

Sintaxe

LOAD DATA [ LOCAL ] INPATH path [ OVERWRITE ] INTO TABLE table_name [ PARTITION clause ]

Parâmetros

  • path

    Caminho do sistema de arquivos. Pode ser um caminho absoluto ou relativo.

  • table_name

    Identifica a tabela a ser inserida. O nome não deve incluir uma especificação temporal. Se a tabela não puder ser encontrada, o Azure Databricks gerará um erro de TABLE_OR_VIEW_NOT_FOUND .

  • Cláusula PARTITION

    Um parâmetro opcional que especifica uma partição de destino para a inserção. Você também pode especificar apenas parcialmente a partição.

  • LOCAIS

    Se especificado, ele faz com que o INPATH seja resolvido no sistema de arquivos local, em vez do sistema de arquivos padrão, que normalmente é um armazenamento distribuído.

  • SUBSTITUIR

    Por padrão, novos dados são acrescentados à tabela. Se OVERWRITE for usada, a tabela será substituída por novos dados.

Exemplos

-- Example without partition specification.
-- Assuming the students table has already been created and populated.
> SELECT * FROM students;
      name                address student_id
 --------- ---------------------- ----------
 Amy Smith 123 Park Ave, San Jose     111111

> CREATE TABLE test_load (name VARCHAR(64), address VARCHAR(64), student_id INT) USING HIVE;

-- Assuming the students table is in '/user/hive/warehouse/'
> LOAD DATA LOCAL INPATH '/user/hive/warehouse/students' OVERWRITE INTO TABLE test_load;

> SELECT * FROM test_load;
      name                address student_id
 --------- ---------------------- ----------
 Amy Smith 123 Park Ave, San Jose     111111

-- Example with partition specification.
> CREATE TABLE test_partition (c1 INT, c2 INT, c3 INT) PARTITIONED BY (c2, c3);

> INSERT INTO test_partition PARTITION (c2 = 2, c3 = 3) VALUES (1);

> INSERT INTO test_partition PARTITION (c2 = 5, c3 = 6) VALUES (4);

> INSERT INTO test_partition PARTITION (c2 = 8, c3 = 9) VALUES (7);

> SELECT * FROM test_partition;
  c1  c2  c3
 --- --- ---
   1   2   3
   4   5   6
   7   8   9

> CREATE TABLE test_load_partition (c1 INT, c2 INT, c3 INT) USING HIVE PARTITIONED BY (c2, c3);

-- Assuming the test_partition table is in '/user/hive/warehouse/'
> LOAD DATA LOCAL INPATH '/user/hive/warehouse/test_partition/c2=2/c3=3'
      OVERWRITE INTO TABLE test_load_partition PARTITION (c2=2, c3=3);

> SELECT * FROM test_load_partition;
  c1  c2  c3
 --- --- ---
   1   2   3