Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6233267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:16:08+00:00 2026-05-24T10:16:08+00:00

I’m trying to do some log processing using Apache Pig Latin, and I was

  • 0

I’m trying to do some log processing using Apache Pig Latin, and I was wondering if there was an easier way to do this:

filtered_logs = FOREACH logs GENERATE numDay, reqSize, optimizedSize, origSize, compressionPct, cacheStatus;

grouped_logs = GROUP filtered_logs BY numDay;

results = FOREACH grouped_logs GENERATE group,
(SUM(filtered_logs.reqSize) + SUM(filtered_logs.optimizedSize)) / 1048576.00 AS     ClientThroughputMB,
(SUM(filtered_logs.reqSize) + SUM(filtered_logs.origSize)) / 1048576.00 AS ServerThroughputMB,
SUM(filtered_logs.origSize) / 1048576.00 AS OrigMB,
SUM(filtered_logs.optimizedSize) / 1048576.00 AS OptMB,
SUM(filtered_logs.reqSize) / 1048576.00 AS SentMB,
AVG(filtered_logs.compressionPct) AS CompressionAvg,
COUNT(filtered_logs) AS NumLogs;

cache_hit_logs = FILTER filtered_logs BY cacheStatus MATCHES '.*HIT.*';

grouped_cache_hit_logs = GROUP cache_hit_logs BY numDay;

cache_hits = FOREACH grouped_cache_hit_logs GENERATE group,
COUNT(cache_hit_logs) AS cnt;

final_results = JOIN results BY group, cache_hits BY group;
DUMP final_results;

(logs is defined, it’s basically reading in a pipe delimited log file and assigning the fields)

What I’m trying to do here is calculate the number of instances the field cacheStatus contains “HIT”, and also calculating other data, such as OrigMB, CompressionAvg, NumLogs etc. This current code works, but it seems to have a huge performance overhead. Is there a way in Pig Latin to do something along the lines of this (in MSSQL)?

SUM(CASE CacheStatus WHEN 'HIT' THEN 1 else 0 END) as CacheHit

(basically, I don’t want to process the log multiple times, I’d rather do it together all at once)

Sorry if my question is worded confusingly, I’m pretty new to Pig Latin.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T10:16:09+00:00Added an answer on May 24, 2026 at 10:16 am

    Nevermind, I found my own solution (silly me, forgot that I could just enclose statements in curly braces):

    results = FOREACH grouped_logs 
    {
        cache_hits = FILTER filtered_logs BY cacheStatus MATCHES '.*HIT.*';
    
        GENERATE group,
        (SUM(filtered_logs.reqSize) + SUM(filtered_logs.optimizedSize)) / 1048576.00 AS ClientThroughputMB,
        (SUM(filtered_logs.reqSize) + SUM(filtered_logs.origSize)) / 1048576.00 AS ServerThroughputMB,
        SUM(filtered_logs.origSize) / 1048576.00 AS OrigMB,
        SUM(filtered_logs.optimizedSize) / 1048576.00 AS OptMB,
        SUM(filtered_logs.reqSize) / 1048576.00 AS SentMB,
        AVG(filtered_logs.compressionPct) AS CompressionAvg,
        COUNT(filtered_logs) AS NumLogs,
        COUNT(cache_hits) AS CacheHit;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
I am trying to understand how to use SyndicationItem to display feed which is
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.