Skip to main content

Categories: Directory

IMINDIR

Returns the name of the subdirectory that ranks lowest in case-insensitive 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​

IMINDIR('<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:

  • 2019
  • 2020
  • 2021

In each subdirectory, there is a CSV file that contains log data. You can use IMINDIR to query the data that is in the 2019 subdirectory. The result is the same as if you used the MAXDIR function.

Query the data in the earliest-named subdirectory
SELECT * FROM dfs."/tmp/querylogs" WHERE dir0 = IMINDIR('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:

  • a
  • A
  • B
  • b
  • c
  • C
  • d
  • D

In each subdirectory, there is a CSV file that contains product data.

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.

Return the lowest-ranking subdirectory name (case-insensitive)
SELECT * FROM dfs."/tmp/querylogs" WHERE dir0 = IMINDIR('dfs','/tmp/querylogs')
-- a

Example 3: In this example, S3 is the name of the source. Use IMINDIR in a HAVING clause to return the row count for only the earliest-named subdirectory. The comparison is case-insensitive.

Return the row count for the earliest-named subdirectory
SELECT dir0, COUNT(*) FROM S3."/data/events" GROUP BY dir0 HAVING dir0 = IMINDIR('S3', '/data/events')