action_="savefile"

<do action_="savefile"> saves the results of a 1010data query as a file in the user's FTP account or remote clous storage (ex. AWS S3, Azure Blob). (Available as of version 20)

Description

After running a query, the resulting data can be saved to a specified file (filename_) in the user’s FTP directory or remote cloud storage (ex. AWS S3, Azure Blob). To save to FTP, the user must be configured with a valid FTP directory. To save results to cloud storage, the user account must be configured with the appropriate keys to access the storage. See Storage account management for instructions on how to add keys to your user account.

To get the estimated size of the saved file without actually saving the file, omit the filename_ attribute and examine the package saved to the dynamic variable associated with the value_ attribute.

Syntax

<dynamic var="{pkg(;)}">
    <do action_="savefile" filename_="filename" 
     sep_="[FIELD_DELIMITER]" 
     recsep_="[RECORD_DELIMITER]" 
     eof_="0|1" formatted_="0|1" 
     names_="0|1" labels_="0|1" 
     value_="@var" checkname_="checkname" 
     mode_="delimited" > 
        [1010data_QUERY]
    </do>
</dynamic>

Attributes for action_="savefile"

filename_
Accepts a text value that specifies a valid 1010data file name.

The file name must begin with a letter and can only contain numbers, letters, and underscores. It cannot contain any spaces or other special characters.

When saving to remote cloud storage, specify the full path to the filename, ex. filename_="subdir1/subdirA/syndicated_ssp_history.txt"

target_
Destination cloud storage. Options are
  • s3 (AWS S3)
  • az (Azure Blob)
  • gcs (Google Cloud Storage - available as of version 20.15)
bucket_

Destination bucket in cloud storage. Required for target_="s3" or target_="gcs".

storage_account_name_

Destination storage account in Azure Blob. Required for target_="az".

container_

Destination container in Azure Blob. Required for target_="az".

api_key_

Name of key saved to the user’s 1010 account to access cloud storage.

sep_
Accepts a single character to use as the delimiter between fields (columns).

If this attribute is omitted or blank, a comma (,) is used as the default.

recsep_
Accepts a one- or two-character text value that defines the delimiter to use between records (rows).
Note: To specify a control character, enclose it within curly braces (e.g., {'\t'}).

If this attribute is omitted or blank, a newline (\n) is used as the default.

eof_
Specifies whether or not to omit the record separator at the end of the file. Accepts a 1 or 0.

When eof_="1", the record separator is included at the end of the file.

When eof_="0", the record separator is omitted from the end of the file.

The default is 1.

formatted_
Specifies whether to write data formatted according to the column format or as raw data. Accepts a 1 or 0.

When formatted_="1", the written data is formatted according to the column format.

When formatted_="0", the raw data is written.

The default is 0.

names_
Specifies whether or not to include a header line with column names. Accepts a 1 or 0.

When names_="1", a header line with column names is included.

When names_="0", a header line with column names is not included.

The default is 0.

labels_
Specifies whether or not to include a header line with column labels. Accepts a 1 or 0.

When labels_="1", a header line with column labels is included.

When labels_="0", a header line with column labels is not included.

The default is 0.

value_
The dynamic variable associated with the value_ attribute is set to a package containing information about the saved file.
The package contains the following keys:
estsize
Estimated size of the saved file.
nameok
Flag that indicates whether the file name specified to the checkname_ attribute is a valid file name (i.e., does not contain prohibited characters and is not the name of a subdirectory).

If the file name specified by the checkname_ attribute is a valid file name, this flag is set to 1. Otherwise, it is set to 0.

exists
Flag that indicates whether the file specified by the checkname_ attribute already exists in the user's FTP account.

If the file already exists in the user's FTP account, this flag is set to 1. Otherwise, it is set to 0.

The variable must be declared as a package in the opening <dynamic> tag of the QuickApp (e.g., <dynamic var_name="{pkg(;)}">).

checkname_
Accepts a text value that specifies a valid 1010data file name.

The file name must begin with a letter and can only contain numbers, letters, and underscores. It cannot contain any spaces or other special characters.

mode_
This attribute is optional and is reserved for future use.

Currently, the only valid value is:

  • delimited
format_

Output file format. Current options are parquet. Additional options may be added in the future.

max_row_group_length_

Integer to specify row group size for parquet files.

created_by_

String to set creator of parquet files.

compression_
The type of compression used to save the file. Options are
  • zip (the default value)
  • gzip
  • raw_gzip
  • zstd (parquet compression)
  • none (available as of version 21.26)

Examples

<do action_="savefile" target_="az" storage_account_name_="1010eu2djsmith" container_="1010-client-az" filename_="syndicated_ssp_history.txt" api_key_="sa_az_jsmith_master" sep_="|" recsep_="{'\r\n'}" formatted_="1" names_="1" labels_="1" mode_="delimited">
<do action_="savefile" target_="s3" bucket_="1010-client-s3" filename_="subdir1/subdirA/syndicated_ssp_history.txt" api_key_="sa_s3_jsmith_master" sep_="|" recsep_="{'\r\n'}" formatted_="1" names_="1" labels_="1" mode_="delimited"></do>
<do action_="savefile" target_="gcs" bucket_="bmathew-gcs" format_="parquet" filename_="syndicated_ssp_history.parquet" api_key_="sa_gcs_bmathew_master"></do>
<do action_="savefile" target_="s3" bucket_="1010-client-s3" format_="parquet" max_row_group_length_="100000" filename_="subdir1/subdirA/syndicated_ssp_history.parquet" api_key_="sa_s3_jsmith_master" compression_="zstd" created_by_="Foo Bar Fum"></do>