Categories: Directory
MINDIR
Returns the name of the subdirectory that ranks lowest in case-sensitive alphanumeric order. Supported object storage sources include Amazon S3 and Azure Storage. You can use this function only in WHERE and HAVING clauses to prune partitioned data by directory name.
Syntax
MINDIR('<source_name>', '<path>') → varchar
- <source_name>: The name of the source containing the table data.
- <path>: The path to the parent directory within the source.
Examples
Example 1: Suppose that there is a directory named querylogs in the /tmp directory. In the querylogs directory, there are three subdirectories:
201920202021
In each subdirectory, there is a CSV file that contains log data. You can use MINDIR to query the data that is in the 2019 subdirectory.
The result is the same as if you used the IMINDIR function.
SELECT * FROM dfs."/tmp/querylogs" WHERE dir0 = MINDIR('dfs','/tmp/querylogs')
-- 2019
Example 2: Suppose that there is a directory named products in the /tmp directory. In the products directory, there are these subdirectories in this order:
aABbcCdD
In each subdirectory, there is a CSV file that contains product data. When the query runs, the names of the subdirectories are sorted into case-sensitive order:
ABCDabcd
Because the Unicode values of upper-case letters are lower than the Unicode values of lower-case letters, the lower-case letters follow the upper-case ones. The letter with the lowest Unicode value in this example is A, and that is the name returned in dir0.
Use dir0 to retrieve the name of a subdirectory one level below the parent directory, dir1 to retrieve the name of a subdirectory two levels below, and so on.
SELECT * FROM dfs."/tmp/querylogs" WHERE dir0 = MINDIR('dfs','/tmp/querylogs')
-- A
Example 3: In this example, S3 is the name of the source. Use MINDIR in a HAVING clause to return the row count for only the earliest-named subdirectory.
SELECT dir0, COUNT(*) FROM S3."/data/events" GROUP BY dir0 HAVING dir0 = MINDIR('S3', '/data/events')