create_file functie

Van toepassing op:controleren gemarkeerd ja Databricks SQL-controle gemarkeerd als ja Databricks Runtime 18 LTS en hoger

Important

Deze functie bevindt zich in de bètaversie. Werkruimtebeheerders kunnen de toegang tot deze functie beheren vanaf de pagina Previews . Zie Azure Databricks previews beheren.

Uploadt string- of binaire inhoud naar een bestemmingspad en geeft een FILE verwijzing terug naar het geüploade bestand.

Syntax

create_file(content => content
  [, destination_path => path ]
  [, if_file_exists => mode ]
  [, content_type => content_type ])

Je kunt argumenten positioneel of op naam doorgeven. Nadat je een argument bij naam hebt doorgegeven, moeten alle volgende argumenten ook bij naam worden doorgegeven. Voor meer informatie, zie aanroep van benoemde parameters.

Arguments

  • content: Een STRING of uitdrukking BINARY met de inhoud om als bestand op te slaan. A STRING wordt opgeslagen als UTF-8-gecodeerde bytes.
  • destination_path: Een optioneel STRING pad om de inhoud naartoe te uploaden.
  • if_file_exists: Een optioneel STRING systeem dat het gedrag instelt wanneer een bestand al op het bestemmingspad bestaat. Gilt alleen bij gebruik van het destination_path argument. Geaccepteerde waarden (hoofdlettergevoelig) zijn:
    • 'error': Geeft een fout. Dit is de standaardwaarde.
    • 'overwrite': Overschrijft het bestaande bestand.
    • 'skip': Slaat het uploaden over en geeft een FILE verwijzing terug naar het bestaande bestand.
  • content_type: Een optioneel STRING document dat het inhoudstype van het bestand specificeert. Als het niet wordt opgegeven, wordt het inhoudstype afgeleid uit de invoerbytes.

Returns

Een FILE waarde die verwijst naar het geüploade bestand.

Aantekeningen

  • Als je gebruikt destination_path, wordt het bestand atomair naar dat pad geüpload. Je moet schrijftoegang hebben tot de doellocatie, die meestal een Unity Catalog-volume is.
  • Als er al een bestand bestaat op het bestemmingspad, geeft Azure Databricks standaard een foutmelding, tenzij je op overwrite of skipzetif_file_exists.

Algemene foutvoorwaarden

  • CREATE_FILE_ERROR.FILE_ALREADY_EXISTS
  • CREATE_FILE_AUTHORIZATION_ERROR.WRITE_UNAUTHORIZED
  • CREATE_FILE_ILLEGAL_USAGE.CONTENT_REQUIRED
  • CREATE_FILE_ILLEGAL_USAGE.IF_FILE_EXISTS_WITHOUT_DESTINATION
  • CREATE_FILE_ILLEGAL_USAGE.IF_FILE_EXISTS_MODE

Voor meer informatie, zie Foutvoorwaarden in Azure Databricks.

Examples

Om een string als een nieuw bestand op een gegeven pad op te slaan:

SELECT create_file(
  content => 'hello, world',
  destination_path => '/Volumes/my_catalog/my_schema/my_volume/greetings.txt'
);

Om ruwe bytes op te slaan en het inhoudstype expliciet in te stellen:

SELECT create_file(
  content => my_binary_col,
  destination_path => '/Volumes/my_catalog/my_schema/my_volume/image.png',
  content_type => 'image/png'
)
FROM raw_uploads;

Om de upload over te slaan als er al een bestand op de bestemming bestaat:

SELECT create_file(
  content => my_binary_col,
  destination_path => '/Volumes/my_catalog/my_schema/my_volume/report.pdf',
  if_file_exists => 'skip'
);

Als destination_path niet is ingesteld, if_file_exists roept een fout op:

SELECT create_file(content => 'data', if_file_exists => 'overwrite');
Error: CREATE_FILE_ILLEGAL_USAGE.IF_FILE_EXISTS_WITHOUT_DESTINATION