How to return distinct multi-word strings from blocks of usage log text with POSIX?












1















First time poster and still learning the ropes, so I apologize if the description below is overly verbose.



I have a database of usage logs I'm pulling data from via various pre-parsed fields. This query is intended to return the count of how many times a distinct error signature was logged over a given period of time. Each logged error is assigned a signature_id, errors of the same type are all assigned the same signature_id. One of the fields I'm returning in my query, message, returns the entire message stack trace/block of usage log text.



I want my query to group by signature_id, which is a pre-parsed field in the table I'm selecting from. I'm struggling to make it work because, while similar error types are assigned the same signature_id', every usage log differs slightly due to the timestamp of when the message was logged. So my query is grouping bymessageinstead ofsignature`.



EX: Of what my query returns if I return the entire usage log message



signature_id    
b2dea422

message
2019-01-17 18:01:52,130 ip-BLANK [WARN ][159] [request_id=00e74d7c] Type=Blank.Multiverse.Web.Mvc.Attributes.Usage+UsageLoggingException Message=UsageLogContext not present in HttpContext.Current.Items Data: Signature=b2dea422 Stack Trace: at Blank.Blank.Web.Mvc.Attributes.Usage.GetUsageLogContext() at Blank.Blank.Web.Mvc.Attributes.Usage.AddData(Object data)

count
1

signature_id
b2dea422

message
2019-01-17 16:21:36,681,130 ip-BLANK [WARN ][38] [request_id=c140f8ea] Type=Blank.Multiverse.Web.Mvc.Attributes.Usage+UsageLoggingException Message=UsageLogContext not present in HttpContext.Current.Items Data: Signature=b2dea422 Stack Trace: at Blank.Blank.Web.Mvc.Attributes.Usage.GetUsageLogContext() at Blank.Blank.Web.Mvc.Attributes.Usage.AddData(Object data)

count
1


I mentioned above that every usage log differs due to the timestamp of when a given message was logged, but similar error types are assigned the same signature_id. Similar error types also share the same Exception Message=...



EX: Every time a message is logged with signature_id=ab7d890pq, it will also have Exception Message=Cannot read property 'get' of undefined in the message block.



Since the table I'm selecting from doesn't have a pre-parsed exception_message field, I want to parse out the Exception Message= string so my GROUP BY will return the count of distinct logged signature_id's and a column with the exception message is for each distinct signature.



My current query shown below begins to parse out the exceptionmessgage string, but I can't get it to return the entire string:



SELECT CASE
WHEN sourcecategory = 'source_hello_world_category' THEN 'hwCategory'
END AS Service,
signature,
NULLIF(SUBSTRING(REGEXP_SUBSTR(message, 'Message=\w+[[:space:]]+'), 9), '') AS exceptionmessage,
count(*)
FROM user_usage_logs
WHERE (signature IS NOT NULL
AND signature NOT IN ('ccce9e73',
'787dd1b5',
'17fc66bc',
'ca384d1f',
'20121ecb',
'ccce9e73'))
AND sourcecategory IN ('source_hello_world_category')
AND messagetime > (getdate() - 1)
GROUP BY signature,
sourcecategory,
exceptionmessage
ORDER BY COUNT DESC
LIMIT 10;


The code shown above returns:



signature_id   exceptionmessage        count

b1det422 Cannot 31,321
330ope77 Unauthorized 1,207
53m6m466 Reference 311


This is an example of I want returned:



signature_id   exceptionmessage                                  count

b1det422 Cannot read property 'get' of undefined Stack 31,321
330ope77 Unauthorized access response for many users 1,207
53m6m466 Reference cannot be set to an empty.object.3 311









share|improve this question







New contributor




Chase Small is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

























    1















    First time poster and still learning the ropes, so I apologize if the description below is overly verbose.



    I have a database of usage logs I'm pulling data from via various pre-parsed fields. This query is intended to return the count of how many times a distinct error signature was logged over a given period of time. Each logged error is assigned a signature_id, errors of the same type are all assigned the same signature_id. One of the fields I'm returning in my query, message, returns the entire message stack trace/block of usage log text.



    I want my query to group by signature_id, which is a pre-parsed field in the table I'm selecting from. I'm struggling to make it work because, while similar error types are assigned the same signature_id', every usage log differs slightly due to the timestamp of when the message was logged. So my query is grouping bymessageinstead ofsignature`.



    EX: Of what my query returns if I return the entire usage log message



    signature_id    
    b2dea422

    message
    2019-01-17 18:01:52,130 ip-BLANK [WARN ][159] [request_id=00e74d7c] Type=Blank.Multiverse.Web.Mvc.Attributes.Usage+UsageLoggingException Message=UsageLogContext not present in HttpContext.Current.Items Data: Signature=b2dea422 Stack Trace: at Blank.Blank.Web.Mvc.Attributes.Usage.GetUsageLogContext() at Blank.Blank.Web.Mvc.Attributes.Usage.AddData(Object data)

    count
    1

    signature_id
    b2dea422

    message
    2019-01-17 16:21:36,681,130 ip-BLANK [WARN ][38] [request_id=c140f8ea] Type=Blank.Multiverse.Web.Mvc.Attributes.Usage+UsageLoggingException Message=UsageLogContext not present in HttpContext.Current.Items Data: Signature=b2dea422 Stack Trace: at Blank.Blank.Web.Mvc.Attributes.Usage.GetUsageLogContext() at Blank.Blank.Web.Mvc.Attributes.Usage.AddData(Object data)

    count
    1


    I mentioned above that every usage log differs due to the timestamp of when a given message was logged, but similar error types are assigned the same signature_id. Similar error types also share the same Exception Message=...



    EX: Every time a message is logged with signature_id=ab7d890pq, it will also have Exception Message=Cannot read property 'get' of undefined in the message block.



    Since the table I'm selecting from doesn't have a pre-parsed exception_message field, I want to parse out the Exception Message= string so my GROUP BY will return the count of distinct logged signature_id's and a column with the exception message is for each distinct signature.



    My current query shown below begins to parse out the exceptionmessgage string, but I can't get it to return the entire string:



    SELECT CASE
    WHEN sourcecategory = 'source_hello_world_category' THEN 'hwCategory'
    END AS Service,
    signature,
    NULLIF(SUBSTRING(REGEXP_SUBSTR(message, 'Message=\w+[[:space:]]+'), 9), '') AS exceptionmessage,
    count(*)
    FROM user_usage_logs
    WHERE (signature IS NOT NULL
    AND signature NOT IN ('ccce9e73',
    '787dd1b5',
    '17fc66bc',
    'ca384d1f',
    '20121ecb',
    'ccce9e73'))
    AND sourcecategory IN ('source_hello_world_category')
    AND messagetime > (getdate() - 1)
    GROUP BY signature,
    sourcecategory,
    exceptionmessage
    ORDER BY COUNT DESC
    LIMIT 10;


    The code shown above returns:



    signature_id   exceptionmessage        count

    b1det422 Cannot 31,321
    330ope77 Unauthorized 1,207
    53m6m466 Reference 311


    This is an example of I want returned:



    signature_id   exceptionmessage                                  count

    b1det422 Cannot read property 'get' of undefined Stack 31,321
    330ope77 Unauthorized access response for many users 1,207
    53m6m466 Reference cannot be set to an empty.object.3 311









    share|improve this question







    New contributor




    Chase Small is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.























      1












      1








      1








      First time poster and still learning the ropes, so I apologize if the description below is overly verbose.



      I have a database of usage logs I'm pulling data from via various pre-parsed fields. This query is intended to return the count of how many times a distinct error signature was logged over a given period of time. Each logged error is assigned a signature_id, errors of the same type are all assigned the same signature_id. One of the fields I'm returning in my query, message, returns the entire message stack trace/block of usage log text.



      I want my query to group by signature_id, which is a pre-parsed field in the table I'm selecting from. I'm struggling to make it work because, while similar error types are assigned the same signature_id', every usage log differs slightly due to the timestamp of when the message was logged. So my query is grouping bymessageinstead ofsignature`.



      EX: Of what my query returns if I return the entire usage log message



      signature_id    
      b2dea422

      message
      2019-01-17 18:01:52,130 ip-BLANK [WARN ][159] [request_id=00e74d7c] Type=Blank.Multiverse.Web.Mvc.Attributes.Usage+UsageLoggingException Message=UsageLogContext not present in HttpContext.Current.Items Data: Signature=b2dea422 Stack Trace: at Blank.Blank.Web.Mvc.Attributes.Usage.GetUsageLogContext() at Blank.Blank.Web.Mvc.Attributes.Usage.AddData(Object data)

      count
      1

      signature_id
      b2dea422

      message
      2019-01-17 16:21:36,681,130 ip-BLANK [WARN ][38] [request_id=c140f8ea] Type=Blank.Multiverse.Web.Mvc.Attributes.Usage+UsageLoggingException Message=UsageLogContext not present in HttpContext.Current.Items Data: Signature=b2dea422 Stack Trace: at Blank.Blank.Web.Mvc.Attributes.Usage.GetUsageLogContext() at Blank.Blank.Web.Mvc.Attributes.Usage.AddData(Object data)

      count
      1


      I mentioned above that every usage log differs due to the timestamp of when a given message was logged, but similar error types are assigned the same signature_id. Similar error types also share the same Exception Message=...



      EX: Every time a message is logged with signature_id=ab7d890pq, it will also have Exception Message=Cannot read property 'get' of undefined in the message block.



      Since the table I'm selecting from doesn't have a pre-parsed exception_message field, I want to parse out the Exception Message= string so my GROUP BY will return the count of distinct logged signature_id's and a column with the exception message is for each distinct signature.



      My current query shown below begins to parse out the exceptionmessgage string, but I can't get it to return the entire string:



      SELECT CASE
      WHEN sourcecategory = 'source_hello_world_category' THEN 'hwCategory'
      END AS Service,
      signature,
      NULLIF(SUBSTRING(REGEXP_SUBSTR(message, 'Message=\w+[[:space:]]+'), 9), '') AS exceptionmessage,
      count(*)
      FROM user_usage_logs
      WHERE (signature IS NOT NULL
      AND signature NOT IN ('ccce9e73',
      '787dd1b5',
      '17fc66bc',
      'ca384d1f',
      '20121ecb',
      'ccce9e73'))
      AND sourcecategory IN ('source_hello_world_category')
      AND messagetime > (getdate() - 1)
      GROUP BY signature,
      sourcecategory,
      exceptionmessage
      ORDER BY COUNT DESC
      LIMIT 10;


      The code shown above returns:



      signature_id   exceptionmessage        count

      b1det422 Cannot 31,321
      330ope77 Unauthorized 1,207
      53m6m466 Reference 311


      This is an example of I want returned:



      signature_id   exceptionmessage                                  count

      b1det422 Cannot read property 'get' of undefined Stack 31,321
      330ope77 Unauthorized access response for many users 1,207
      53m6m466 Reference cannot be set to an empty.object.3 311









      share|improve this question







      New contributor




      Chase Small is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.












      First time poster and still learning the ropes, so I apologize if the description below is overly verbose.



      I have a database of usage logs I'm pulling data from via various pre-parsed fields. This query is intended to return the count of how many times a distinct error signature was logged over a given period of time. Each logged error is assigned a signature_id, errors of the same type are all assigned the same signature_id. One of the fields I'm returning in my query, message, returns the entire message stack trace/block of usage log text.



      I want my query to group by signature_id, which is a pre-parsed field in the table I'm selecting from. I'm struggling to make it work because, while similar error types are assigned the same signature_id', every usage log differs slightly due to the timestamp of when the message was logged. So my query is grouping bymessageinstead ofsignature`.



      EX: Of what my query returns if I return the entire usage log message



      signature_id    
      b2dea422

      message
      2019-01-17 18:01:52,130 ip-BLANK [WARN ][159] [request_id=00e74d7c] Type=Blank.Multiverse.Web.Mvc.Attributes.Usage+UsageLoggingException Message=UsageLogContext not present in HttpContext.Current.Items Data: Signature=b2dea422 Stack Trace: at Blank.Blank.Web.Mvc.Attributes.Usage.GetUsageLogContext() at Blank.Blank.Web.Mvc.Attributes.Usage.AddData(Object data)

      count
      1

      signature_id
      b2dea422

      message
      2019-01-17 16:21:36,681,130 ip-BLANK [WARN ][38] [request_id=c140f8ea] Type=Blank.Multiverse.Web.Mvc.Attributes.Usage+UsageLoggingException Message=UsageLogContext not present in HttpContext.Current.Items Data: Signature=b2dea422 Stack Trace: at Blank.Blank.Web.Mvc.Attributes.Usage.GetUsageLogContext() at Blank.Blank.Web.Mvc.Attributes.Usage.AddData(Object data)

      count
      1


      I mentioned above that every usage log differs due to the timestamp of when a given message was logged, but similar error types are assigned the same signature_id. Similar error types also share the same Exception Message=...



      EX: Every time a message is logged with signature_id=ab7d890pq, it will also have Exception Message=Cannot read property 'get' of undefined in the message block.



      Since the table I'm selecting from doesn't have a pre-parsed exception_message field, I want to parse out the Exception Message= string so my GROUP BY will return the count of distinct logged signature_id's and a column with the exception message is for each distinct signature.



      My current query shown below begins to parse out the exceptionmessgage string, but I can't get it to return the entire string:



      SELECT CASE
      WHEN sourcecategory = 'source_hello_world_category' THEN 'hwCategory'
      END AS Service,
      signature,
      NULLIF(SUBSTRING(REGEXP_SUBSTR(message, 'Message=\w+[[:space:]]+'), 9), '') AS exceptionmessage,
      count(*)
      FROM user_usage_logs
      WHERE (signature IS NOT NULL
      AND signature NOT IN ('ccce9e73',
      '787dd1b5',
      '17fc66bc',
      'ca384d1f',
      '20121ecb',
      'ccce9e73'))
      AND sourcecategory IN ('source_hello_world_category')
      AND messagetime > (getdate() - 1)
      GROUP BY signature,
      sourcecategory,
      exceptionmessage
      ORDER BY COUNT DESC
      LIMIT 10;


      The code shown above returns:



      signature_id   exceptionmessage        count

      b1det422 Cannot 31,321
      330ope77 Unauthorized 1,207
      53m6m466 Reference 311


      This is an example of I want returned:



      signature_id   exceptionmessage                                  count

      b1det422 Cannot read property 'get' of undefined Stack 31,321
      330ope77 Unauthorized access response for many users 1,207
      53m6m466 Reference cannot be set to an empty.object.3 311






      sql regex substring posix amazon-redshift






      share|improve this question







      New contributor




      Chase Small is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question







      New contributor




      Chase Small is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question






      New contributor




      Chase Small is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked Jan 18 at 16:14









      Chase SmallChase Small

      61




      61




      New contributor




      Chase Small is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Chase Small is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Chase Small is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.
























          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });






          Chase Small is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54257680%2fhow-to-return-distinct-multi-word-strings-from-blocks-of-usage-log-text-with-pos%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          Chase Small is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          Chase Small is a new contributor. Be nice, and check out our Code of Conduct.













          Chase Small is a new contributor. Be nice, and check out our Code of Conduct.












          Chase Small is a new contributor. Be nice, and check out our Code of Conduct.
















          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54257680%2fhow-to-return-distinct-multi-word-strings-from-blocks-of-usage-log-text-with-pos%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Homophylophilia

          Updating UILabel text programmatically using a function

          Cloud Functions - OpenCV Videocapture Read method fails for larger files from cloud storage