Skip to content

Conversation

@shubhamprasad318
Copy link

This pull request enhances CDAP Wrangler with native support for parsing byte size and time duration units and introduces an aggregate-stats directive to compute totals from source columns. The changes cover grammar modifications, API updates, core parser adjustments, directive implementation, and comprehensive testing as specified in the Software Engineer Intern Assignment.

Changes Overview

  1. Grammar Modifications
    Directives.g4:
    Added lexer tokens BYTE_SIZE (supporting B, KB, MB, GB, TB) and TIME_DURATION (supporting ns, ms, s, m, h).
    Introduced parser rules (e.g., byteSizeArg and timeDurationArg) to capture these tokens.
    Regenerated ANTLR parser code using mvnd compile.

  2. API Updates (wrangler-api module)

Implemented ByteSize.java and TimeDuration.java to parse input strings like "10KB" and "100ms" into canonical values (bytes and nanoseconds).
Updated relevant token definitions (in TokenType and UsageDefinition) to support the new types.
Fixed Checkstyle issues in wrangler-api.

  1. Core Parser Updates (wrangler-core module)
    Modified RecipeVisitor.java to handle the new parser rules via corresponding visitor methods (e.g., visitByteSizeArg and visitTimeDurationArg).
    Ensured that recipes that use the new tokens parse correctly.

  2. New Directive Implementation (wrangler-core module)

Created AggregateStatsDirective.java in the package io.cdap/directives/aggregates.
5. Testing (wrangler-core module)

Unit Tests for Parsers:

Added ByteSizeTest.java and TimeDurationTest.java to validate parsing of various inputs such as "10kb", "1.5MB", "5ms", and "2.1s".

Parser Tests:

Updated GrammarBasedParserTest.java / RecipeCompilerTest.java to ensure recipes that use new syntax compile correctly and that invalid syntax is rejected.

Directive Testing:

Added AggregateStatsDirectiveTest.java (or AggregateStatsTest.java) using TestingRig.execute(recipe, rows) to simulate log or transaction data, verifying that:

The aggregate output row contains the correct value for total size (in MB) and total time (in seconds).

Aggregation is performed accurately across multiple rows.

@google-cla
Copy link

google-cla bot commented Apr 15, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant