Github user zellerh commented on a diff in the pull request:
https://github.com/apache/incubator-trafodion/pull/1046#discussion_r110060012
--- 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 --
... thinking about this again, we don't have a SUBSTRING method that will
give the first n _bytes_ of a UTF-8 string, truncated to the next UTF-8
character. So, without such a function we can't really do what I suggested
above.
If we have a long UTF-8 column c and maxLengthInBytes is 256, then we will
take SUBSTRING(c for 64) here. In many situations and languages, this will be
about 64 bytes of information, not 256.
---
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.
---