[
https://issues.apache.org/jira/browse/DRILL-5419?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15983065#comment-15983065
]
ASF GitHub Bot commented on DRILL-5419:
---------------------------------------
GitHub user arina-ielchiieva opened a pull request:
https://github.com/apache/drill/pull/819
DRILL-5419: Calculate return string length for literals & some string…
… functions
1. Revisited calculation logic for string literals and some string
functions (cast, upper, lower, initcap, reverse, concat, concat operator,
substring, substr, left, right, rpad, lpad, case statement, coalesce,
first_value, last_value).
2. Deprecated width and changed it to precision for string types.
3. Synchronized return type length calculation logic between limit 0 and
regular queries.
4. Performed minor refactoring, added appropriate unit tests.
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/arina-ielchiieva/drill DRILL-5419
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/drill/pull/819.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #819
----
commit c7ec21bc1caa02587f6b748ee6e213b78e916cb6
Author: Arina Ielchiieva <[email protected]>
Date: 2017-04-06T10:44:26Z
DRILL-5419: Calculate return string length for literals & some string
functions
----
> Calculate return string length for literals & some string functions
> -------------------------------------------------------------------
>
> Key: DRILL-5419
> URL: https://issues.apache.org/jira/browse/DRILL-5419
> Project: Apache Drill
> Issue Type: Bug
> Affects Versions: 1.9.0
> Reporter: Arina Ielchiieva
> Assignee: Arina Ielchiieva
> Attachments: version_with_cast.JPG, version_without_cast.JPG
>
>
> 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.
> Changes:
> *LITERALS*
> String literals length is the same as actual literal length.
> Example: for 'aaa' return length is 3.
> *CAST*
> 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, if column is known, the same
> length will be returned.
> Example:
> lower(cast(col as varchar(30))) will return 30.
> lower(col) will return max varchar length, since we don't know actual column
> length.
> *LPAD, RPAD*
> 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.
> *SUBSTR, SUBSTRING, LEFT, RIGHT*
> Calculates return length according to each function substring rules, for
> example, taking into account how many char should be substracted.
> *IF EXPRESSIONS (CASE STATEMENT, COALESCE), UNION OPERATOR*
> When combining string columns with different length, return length is max
> from source columns.
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)