[ 
https://issues.apache.org/jira/browse/DRILL-5419?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15998264#comment-15998264
 ] 

ASF GitHub Bot commented on DRILL-5419:
---------------------------------------

Github user arina-ielchiieva commented on a diff in the pull request:

    https://github.com/apache/drill/pull/819#discussion_r114957022
  
    --- Diff: common/src/main/java/org/apache/drill/common/types/Types.java ---
    @@ -340,18 +344,18 @@ public static int getJdbcDisplaySize(MajorType type) {
         case INTERVALYEAR:
           return precision > 0
               ? 5 + precision // P..Y12M
    -          : 0; // if precision is not set, return 0 because there's not 
enough info
    +          : UNDEFINED; // if precision is not set, return 0 because 
there's not enough info
     
         case INTERVALDAY:
           return precision > 0
               ? 12 + precision // P..DT12H60M60S assuming fractional seconds 
precision is not supported
    -          : 0; // if precision is not set, return 0 because there's not 
enough info
    +          : UNDEFINED; // if precision is not set, return 0 because 
there's not enough info
     
         case INTERVAL:
         case MAP:
         case LATE:
         case NULL:
    -    case UNION:           return 0;
    +    case UNION:           return UNDEFINED;
    --- End diff --
    
    If `MajorType` is `UNION`, it's `getSubTypeList()` is not empty. But it 
contains only minor types, i.e. no precision to calculate exact length but 
approximate length can be calculated. To change union type calculation we need 
to make changes in `Types.class` and in `fieldmeta.cpp` (C++ part). I'll have 
created separate Jira for this change - DRILL-5475.


> 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
>
>
> 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, i.e. 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.
> *LAG, LEAD*
> Return length is underlying column length but column type will be nullable.
> *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.
> *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)

Reply via email to