Repository: trafodion
Updated Branches:
  refs/heads/master a9bbe12aa -> 6dbea7e87


[TRAFODION-3177] Error when selecting count(*) from event_log_reader UDF

See the JIRA for a description of the issues.

- Removed code that required usage of a set of output columns
  to evaluate code. This check caused the error described in the
  test case, and I think it is no longer necessary. Removing it
  can speed up some cases where we now evaluate predicates in the
  UDF, for example:

  select count(*)
  from udf("_LIBMGR_".event_log_reader('f'))
  where log_file_node = 0;

- Added predicate evaluation code for MESSAGE, LOG_FILE_NODE,
  LOG_FILE_LINE, and PARSE_STATUS columns.


Project: http://git-wip-us.apache.org/repos/asf/trafodion/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafodion/commit/5ecb6890
Tree: http://git-wip-us.apache.org/repos/asf/trafodion/tree/5ecb6890
Diff: http://git-wip-us.apache.org/repos/asf/trafodion/diff/5ecb6890

Branch: refs/heads/master
Commit: 5ecb6890cb9fc381bca7c4f5c93ea8a28ed9fd31
Parents: 99da63e
Author: Hans Zeller <hzel...@apache.org>
Authored: Tue Aug 7 01:20:09 2018 +0000
Committer: Hans Zeller <hzel...@apache.org>
Committed: Tue Aug 7 01:20:09 2018 +0000

----------------------------------------------------------------------
 core/sql/sqludr/SqlUdrPredefLogReader.cpp | 145 +++++++++++++++++--------
 1 file changed, 99 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafodion/blob/5ecb6890/core/sql/sqludr/SqlUdrPredefLogReader.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqludr/SqlUdrPredefLogReader.cpp 
b/core/sql/sqludr/SqlUdrPredefLogReader.cpp
index 3a902a5..b5d9ab8 100644
--- a/core/sql/sqludr/SqlUdrPredefLogReader.cpp
+++ b/core/sql/sqludr/SqlUdrPredefLogReader.cpp
@@ -273,6 +273,8 @@ public:
     SQL_CODE_COLNUM,
     QUERY_ID_COLNUM,
     MESSAGE_COLNUM,
+    LAST_DEFAULT_COLNUM = MESSAGE_COLNUM,
+
     LOG_FILE_NODE_COLNUM, // optional columns
     LOG_FILE_NAME_COLNUM,
     LOG_FILE_LINE_COLNUM,
@@ -418,24 +420,11 @@ void 
ReadCppEventsUDFInterface::describeDataflowAndPredicates(UDRInvocationInfo
 {
   UDR::describeDataflowAndPredicates(info);
 
-  bool generatedColsAreUsed = false;
-  if (info.out().getColumn(LOG_TS_COLNUM).getUsage() == ColumnInfo::USED ||
-      info.out().getColumn(SEVERITY_COLNUM).getUsage() == ColumnInfo::USED ||
-      info.out().getColumn(COMPONENT_COLNUM).getUsage() == ColumnInfo::USED ||
-      info.out().getColumn(NODE_NUMBER_COLNUM).getUsage() == ColumnInfo::USED 
||
-      info.out().getColumn(CPU_COLNUM).getUsage() == ColumnInfo::USED ||
-      info.out().getColumn(PIN_COLNUM).getUsage() == ColumnInfo::USED ||
-      info.out().getColumn(PROCESS_NAME_COLNUM).getUsage() == ColumnInfo::USED 
||
-      info.out().getColumn(SQL_CODE_COLNUM).getUsage() == ColumnInfo::USED ||
-      info.out().getColumn(QUERY_ID_COLNUM).getUsage() == ColumnInfo::USED ||
-      info.out().getColumn(LOG_FILE_NAME_COLNUM).getUsage() == 
ColumnInfo::USED)
-    generatedColsAreUsed = true;
-
-  // Walk through predicates and find additional ones to push down
-  // or to evaluate locally
+  // Walk through predicates and evaluate any comparison predicates
+  // that have a constant in the UDF
   for (int p=0; p<info.getNumPredicates(); p++)
   {
-    if (generatedColsAreUsed && info.isAComparisonPredicate(p))
+    if (info.isAComparisonPredicate(p))
     {
       const ComparisonPredicateInfo &cpi = info.getComparisonPredicate(p);
       if (cpi.hasAConstantValue())
@@ -601,8 +590,18 @@ void 
ReadCppEventsUDFInterface::processData(UDRInvocationInfo &info,
     } 
 
     if (addFileColumns)
+    {
+      int myNodeNum = info.getMyInstanceNum();
+      char myNodeNumBuf[20];
+
+      snprintf(myNodeNumBuf, sizeof(myNodeNumBuf), "%d", myNodeNum);
+      if (!validateEvent(info, myNodeNumBuf, LOG_FILE_NODE_COLNUM, doTrace, 
pid))
+        // if this fails once, it will fail for any line in any file on this 
node
+        return;
+
       // log_file_node is the same for every row generated by this process
-      info.out().setInt(LOG_FILE_NODE_COLNUM, info.getMyInstanceNum());
+      info.out().setInt(LOG_FILE_NODE_COLNUM, myNodeNum);
+    }
 
     // 
---------------------------------------------------------------------------
     // Loop over the files in the log directory
@@ -786,22 +785,42 @@ void 
ReadCppEventsUDFInterface::processData(UDRInvocationInfo &info,
            if (haveRowToEmit)
            {
              // set final two columns, message text and parse error
-             setCharOutputColumn(info,
-                                 MESSAGE_COLNUM,
-                                 messageTextField.data(),
-                                 rowParseStatus);
+              if (validateEvent(info,
+                                messageTextField.data(),
+                                MESSAGE_COLNUM,
+                                doTrace,
+                                pid))
+                setCharOutputColumn(info,
+                                    MESSAGE_COLNUM,
+                                    messageTextField.data(),
+                                    rowParseStatus);
+              else
+                haveRowToEmit = 0;
+
              if (addFileColumns)
-               setCharOutputColumn(info,
-                                   PARSE_STATUS_COLNUM,
-                                   rowParseStatus.c_str(),
-                                   rowParseStatus);
-             numEventsReturned++;
-             emitRow(info);
-             if (doTrace)
-             {
-               printf("(%d) EVENT_LOG_READER emit1\n", pid);
-               fflush(stdout);
-             }
+              {
+                if (validateEvent(info,
+                                  rowParseStatus.c_str(),
+                                  PARSE_STATUS_COLNUM,
+                                  doTrace,
+                                  pid))
+                  setCharOutputColumn(info,
+                                      PARSE_STATUS_COLNUM,
+                                      rowParseStatus.c_str(),
+                                      rowParseStatus);
+                else
+                  haveRowToEmit = 0;
+              }
+              if (haveRowToEmit)
+              {
+                numEventsReturned++;
+                emitRow(info);
+                if (doTrace)
+                {
+                  printf("(%d) EVENT_LOG_READER emit1\n", pid);
+                  fflush(stdout);
+                }
+              }
            }
            
            // we read a line that will produce an output row, initialize
@@ -1086,7 +1105,18 @@ void 
ReadCppEventsUDFInterface::processData(UDRInvocationInfo &info,
              messageTextField.erase(0, numLeadingBlanks);
            
            if (addFileColumns)
+            {
+              char lineNumBuf[20];
+
+              snprintf(lineNumBuf, sizeof(lineNumBuf), "%d", lineNumber);
+             if (!validateEvent(info, lineNumBuf, LOG_FILE_LINE_COLNUM, 
doTrace, pid))
+              {
+                meetsConstraint = false;
+                continue;
+              }
+
              info.out().setInt(LOG_FILE_LINE_COLNUM, lineNumber);
+            }
          }
          
          haveRowToEmit = 1;
@@ -1096,23 +1126,44 @@ void 
ReadCppEventsUDFInterface::processData(UDRInvocationInfo &info,
         if (haveRowToEmit) 
         {
          // set final two columns, message text and parse error
-         setCharOutputColumn(info,
-                             MESSAGE_COLNUM,
-                             messageTextField.data(),
-                             rowParseStatus);
-         if (addFileColumns)
+          if (validateEvent(info,
+                            messageTextField.data(),
+                            MESSAGE_COLNUM,
+                            doTrace,
+                            pid))
             setCharOutputColumn(info,
-                                PARSE_STATUS_COLNUM,
-                                rowParseStatus.c_str(),
+                                MESSAGE_COLNUM,
+                                messageTextField.data(),
                                 rowParseStatus);
-          numEventsReturned++;
-          emitRow(info);
-          if (doTrace)
+          else
+            haveRowToEmit = 0;
+
+         if (addFileColumns)
           {
-            printf("(%d) EVENT_LOG_READER emit2\n", pid);
-            fflush(stdout);
+            if (validateEvent(info,
+                              rowParseStatus.c_str(),
+                              PARSE_STATUS_COLNUM,
+                              doTrace,
+                              pid))
+              setCharOutputColumn(info,
+                                  PARSE_STATUS_COLNUM,
+                                  rowParseStatus.c_str(),
+                                  rowParseStatus);
+            else
+              haveRowToEmit = 0;
+          }
+
+          if (haveRowToEmit)
+          {
+            numEventsReturned++;
+            emitRow(info);
+            if (doTrace)
+              {
+                printf("(%d) EVENT_LOG_READER emit2\n", pid);
+                fflush(stdout);
+              }
+            haveRowToEmit = 0;
           }
-         haveRowToEmit = 0;
           appendPos = 0;
        }
         // Close the input file
@@ -1311,17 +1362,19 @@ bool ReadCppEventsUDFInterface::validateEvent(const 
UDRInvocationInfo &info,
     // All other comparisons are assumed to be string compares
     else
     {
-      // convert predicate value
+      // convert and trim predicate value
       temp = constStr;
       constStr.clear();
       for(size_t j = 0; j < temp.size(); ++j)
         constStr += (std::toupper(temp[j]));
+      constStr.erase(constStr.find_last_not_of(" ")+1);
 
       // convert event value
       temp = currField;
       std::string eventStr;
       for(size_t j = 0; j < temp.size(); ++j)
         eventStr += (std::toupper(temp[j]));
+      eventStr.erase(eventStr.find_last_not_of(" ")+1);
 
       switch (info.getComparisonPredicate(i).getOperator())
       {

Reply via email to