Skip to main content

LOCAL

Description​

This function reads files from managed compute hosts. It does not upload files from your computer. Before using local storage, ask VeloDB Cloud support to confirm access and arrange any required files, mount points, and managed configuration. For ordinary file queries, use S3, HTTP, or HDFS with storage reachable from the warehouse.

Local table-valued-function(tvf), allows users to read and access local file contents on be node, just like accessing relational table. Currently supports csv/csv_with_names/csv_with_names_and_types/json/parquet/orc file format.

Syntax​

LOCAL(
"file_path" = "<file_path>",
"backend_id" = "<backend_id>",
"format" = "<format>"
[, "<optional_property_key>" = "<optional_property_value>" [, ...] ]
);

Required parameters​

ParameterDescriptionRemarks
file_pathThe path of the file to be read, which is relative to the user_files_secure_path directory. The user_files_secure_path parameter is a BE configuration item.
The path cannot include .., and glob syntax can be used for pattern matching, such as logs/*.log.
backend_idThe ID of the BE node where the file is located. It can be obtained via the show backends command.Use a support-approved backend ID.
formatThe file format, which is required. Supported formats are csv/csv_with_names/csv_with_names_and_types/json/parquet/orc.

Optional parameters​

ParameterDescriptionRemarks
shared_storageDefaults to false. If true, the specified file is located on shared storage (e.g., NAS). The shared storage must support POSIX file interfaces and be mounted on all BE nodes.
When shared_storage is true, backend_id can be omitted. The query engine may use the selected cluster's backend nodes to access the data. If backend_id is set, the data will be accessed only on the specified BE node.
column_separatorThe column separator, optional, defaults to \t.
line_delimiterThe line delimiter, optional, defaults to \n.
compress_typeThe compression type, optional. Supported types are UNKNOWN/PLAIN/GZ/LZO/BZ2/LZ4FRAME/DEFLATE/SNAPPYBLOCK. Defaults to UNKNOWN, and the type will be automatically inferred from the uri suffix.
read_json_by_lineFor JSON format imports, optional, defaults to true.Refer to: Json Load
strip_outer_arrayFor JSON format imports, optional, defaults to false.Refer to: Json Load
json_rootFor JSON format imports, optional, defaults to empty.Refer to: Json Load
json_pathsFor JSON format imports, optional, defaults to empty.Refer to: Json Load
num_as_stringFor JSON format imports, optional, defaults to false.Refer to: Json Load
fuzzy_parseFor JSON format imports, optional, defaults to false.Refer to: Json Load
trim_double_quotesFor CSV format imports, optional, defaults to false. If true, it will trim the outermost double quotes around each field in the CSV file.For CSV format
skip_linesFor CSV format imports, optional, defaults to 0, which means skipping the first few lines of the CSV file. When the format is csv_with_names or csv_with_names_and_types, this parameter is ignored.For CSV format
path_partition_keysOptional, specifies the partition column names carried in the file path, e.g., /path/to/city=beijing/date="2023-07-09", then fill in path_partition_keys="city,date". This will automatically read the corresponding column names and values from the path for import.
enable_mapping_varbinaryDefaults to false. For unannotated Parquet binary fields and ORC BINARY fields, maps to STRING by default or VARBINARY when enabled.
enable_mapping_timestamp_tzDefaults to false in Core 26.1.3. When enabled, infers TIMESTAMPTZ for supported Parquet/ORC timestamp fields. When false, compatibility inference is retained. Independent of enable_mapping_varbinary. A future release makes the mapping mandatory and ignores this option.Current Core 26.1.3 behavior.
hive.parquet.time-zoneFuture release. Specifies the Parquet INT96 writer time zone. This property is unavailable in Core 26.1.3. See Parquet timestamp compatibility.Future release.

Access control requirements​

PrivilegeObjectNotes
ADMIN_PRIVglobal

Usage notes​

  • For more detailed usage of local tvf, please refer to S3 tvf, The only difference between them is the way of accessing the storage system.

  • Access data on NAS through local tvf

    NAS shared storage allows to be mounted to multiple nodes at the same time. Each node can access files in the shared storage just like local files. Therefore, the NAS can be thought of as a local file system, accessed through local tvf.

    When setting "shared_storage" = "true", The query engine assumes that the specified file can be accessed from any BE node. When a set of files is specified using wildcards, The query engine distributes requests to access files to multiple BE nodes, so that multiple nodes can be used to perform distributed file scanning and improve query performance.

Examples​

Analyze the log file on specified BE:

select * from local(
"file_path" = "log/be.out",
"backend_id" = "10006",
"format" = "csv")
where c1 like "%start_time%" limit 10;
+--------------------------------------------------------+
| c1 |
+--------------------------------------------------------+
| start time: 2023 年 08 月 07 日 星期一 23:20:32 CST |
| start time: 2023 年 08 月 07 日 星期一 23:32:10 CST |
| start time: 2023 年 08 月 08 日 星期二 00:20:50 CST |
| start time: 2023 年 08 月 08 日 星期二 00:29:15 CST |
+--------------------------------------------------------+

Read a CSV file provisioned by support as student.csv under the managed secure file directory:

select * from local(
"file_path" = "student.csv",
"backend_id" = "10003",
"format" = "csv");
+------+---------+--------+
| c1 | c2 | c3 |
+------+---------+--------+
| 1 | alice | 18 |
| 2 | bob | 20 |
| 3 | jack | 24 |
| 4 | jackson | 19 |
| 5 | liming | d18 |
+------+---------+--------+

Query files on NAS:

select * from local(
"file_path" = "<support-approved-relative-path>/prefix_*.txt",
"format" = "csv",
"column_separator" =",",
"shared_storage" = "true");
+------+------+------+
| c1 | c2 | c3 |
+------+------+------+
| 1 | 2 | 3 |
| 1 | 2 | 3 |
| 1 | 2 | 3 |
| 1 | 2 | 3 |
| 1 | 2 | 3 |
+------+------+------+

Can be used with desc function :

desc function local(
"file_path" = "student.csv",
"backend_id" = "10003",
"format" = "csv");
+-------+------+------+-------+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+------+------+-------+---------+-------+
| c1 | TEXT | Yes | false | NULL | NONE |
| c2 | TEXT | Yes | false | NULL | NONE |
| c3 | TEXT | Yes | false | NULL | NONE |
+-------+------+------+-------+---------+-------+

Ask AI