Though Drill is schema-less and cannot determine in advance what the length of the column should be but if query has an explicit type/length specified, Drill should return correct column length.
For example, JDBC / ODBC Driver is ALWAYS returning 64K as the length of a varchar or char even if casts are applied.
String literals length is the same as actual literal length.
Example: for 'aaa' return length is 3.
Return length is the one indicated in cast expression. This also applies when user has created view where each string columns was casted to varchar with some specific length.
This length will be returned to the user without need to apply cast one more time. Below mentioned functions can take leverage of underlying varchar length and calculate return length.
LOWER, UPPER, INITCAP, REVERSE, FIRST_VALUE, LAST_VALUE
Return length is underlying column length, i.e. if column is known, the same length will be returned.
lower(cast(col as varchar(30))) will return 30.
lower(col) will return max varchar length, since we don't know actual column length.
Return length is underlying column length but column type will be nullable.
Pads the string to the length specified. Return length is this specified length.
CONCAT, CONCAT OPERATOR (||)
Return length is sum of underlying columns length. If length is greater then varchar max length, varchar max length is returned.
IF EXPRESSIONS (CASE STATEMENT, COALESCE), UNION OPERATOR
When combining string columns with different length, return length is max from source columns.