Github user zellerh commented on a diff in the pull request:

    
https://github.com/apache/incubator-trafodion/pull/1046#discussion_r110052947
  
    --- Diff: core/sql/ustat/hs_globals.cpp ---
    @@ -1882,6 +1882,55 @@ NABoolean HSColumnStruct::operator==(const 
HSColumnStruct& other) const
         return ( colnum == other.colnum );
       }
     
    +//
    +// METHOD:  addTruncatedColumnReference()
    +//
    +// PURPOSE: Generates a column reference or a SUBSTRING
    +//          on a column reference which truncates the
    +//          column to the maximum length allowed in
    +//          UPDATE STATISTICS.
    +//
    +// INPUT:   'qry' - the SQL query string to append the 
    +//          reference to.
    +//          'colInfo' - struct containing datatype info
    +//          about the column.
    +//
    +void HSColumnStruct::addTruncatedColumnReference(NAString & qry)
    +  {
    +    HSGlobalsClass *hs_globals = GetHSContext();
    +    Lng32 maxLengthInBytes = hs_globals->maxCharColumnLengthInBytes;
    +    bool isOverSized = DFS2REC::isAnyCharacter(datatype) &&
    +                           (length > maxLengthInBytes);
    +    if (isOverSized)
    +      {
    +        // Note: The result data type of SUBSTRING is VARCHAR, always.
    +        // But if the column is CHAR, many places in the ustat code are not
    +        // expecting a VARCHAR. So, we stick a CAST around it to convert
    +        // it back to a CHAR in these cases.
    +
    +        NABoolean isFixedChar = DFS2REC::isSQLFixedChar(datatype);
    +        if (isFixedChar)
    +          qry += "CAST(";
    +        qry += "SUBSTRING(";
    +        qry += externalColumnName->data();
    +        qry += " FOR ";
    +        
    +        char temp[20];  // big enough for "nnnnnn)"
    +        sprintf(temp,"%d)", maxLengthInBytes / 
CharInfo::maxBytesPerChar(charset));
    +        qry += temp;
    +        if (isFixedChar)
    +          {
    +            qry += " AS CHAR(";
    +            qry += temp;
    +            qry += ")";
    --- End diff --
    
    This is a question to this pre-existing code: We added character and byte 
semantics, like Oracle has it, to UTF-8 character columns. Do we need something 
similar here? Maybe as simple as adding the keyword "BYTES" when we deal with 
UTF-8 character columns with a length specified in bytes?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to