Skip to content

Add AggregateStats directive with ByteSize and TimeDuration parsing #973

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: develop
Choose a base branch
from
63 changes: 22 additions & 41 deletions .github/workflows/build-report.yml
Original file line number Diff line number Diff line change
@@ -1,56 +1,37 @@
# Copyright © 2024 Cask Data, Inc.
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.

# This workflow will build a Java project with Maven
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
# Note: Any changes to this workflow would be used only after merging into develop
name: Build Unit Tests Report

on:
workflow_run:
workflows:
- Build with unit tests
- Build with unit tests
types:
- completed
- completed

permissions:
actions: read # Allows reading workflow run information
statuses: write # Required if the action updates commit statuses
checks: write # Required if it updates GitHub Checks API
actions: read
statuses: write
checks: write

jobs:
build:
runs-on: ubuntu-latest

if: ${{ github.event.workflow_run.conclusion != 'skipped' }}

steps:
# Pinned 1.0.0 version
- uses: marocchino/action-workflow_run-status@54b6e87d6cb552fc5f36dbe9a722a6048725917a

- name: Download artifact
uses: actions/download-artifact@v4
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ github.event.workflow_run.id }}
path: artifacts/

- name: Surefire Report
# Pinned 3.5.2 version
uses: mikepenz/action-junit-report@16a9560bd02f11e7e3bf6b3e2ef6bba6c9d07c32
if: always()
with:
report_paths: '**/target/surefire-reports/TEST-*.xml'
github_token: ${{ secrets.GITHUB_TOKEN }}
detailed_summary: true
commit: ${{ github.event.workflow_run.head_sha }}
check_name: Build Test Report

- uses: marocchino/action-workflow_run-status@54b6e87d6cb552fc5f36dbe9a722a6048725917a

- name: Download artifact
uses: actions/download-artifact@v4
with:
run-id: ${{ github.event.workflow_run.id }}
path: artifacts/

- name: Surefire Report
uses: mikepenz/action-junit-report@16a9560bd02f11e7e3bf6b3e2ef6bba6c9d07c32
if: always()
with:
report_paths: '**/target/surefire-reports/TEST-*.xml'
detailed_summary: true
github_token: ${{ secrets.GITHUB_TOKEN }}
commit: ${{ github.event.workflow_run.head_sha }}
check_name: Build Test Report
32 changes: 6 additions & 26 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
# Copyright © 2021 Cask Data, Inc.
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.

# This workflow will build a Java project with Maven
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
# Note: Any changes to this workflow would be used only after merging into develop
name: Build with unit tests

on:
Expand All @@ -25,30 +11,25 @@ jobs:
build:
runs-on: k8s-runner-build

# We allow builds:
# 1) When it's a merge into a branch
# 2) For PRs that are labeled as build and
# - It's a code change
# - A build label was just added
# A bit complex, but prevents builds when other labels are manipulated
if: >
github.event_name == 'push'
|| (contains(github.event.pull_request.labels.*.name, 'build')
&& (github.event.action != 'labeled' || github.event.label.name == 'build')
)
&& (github.event.action != 'labeled' || github.event.label.name == 'build'))

steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.workflow_run.head_sha }}
- name: Cache

- name: Cache Maven packages
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ github.workflow }}-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-${{ github.workflow }}

- name: Build with Maven
run: mvn clean test -fae -T 2 -B -V -DcloudBuild -Dmaven.wagon.http.retryHandler.count=3 -Dmaven.wagon.httpconnectionManager.ttlSeconds=25

- name: Archive build artifacts
uses: actions/upload-artifact@v4
if: always()
Expand All @@ -57,4 +38,3 @@ jobs:
path: |
**/target/rat.txt
**/target/surefire-reports/*

Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package io.cdap.wrangler.api.parser;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* A token that represents byte size like 10KB, 1.5MB, etc.
*/
public class ByteSize extends Token {
private static final Pattern PATTERN = Pattern.compile("(?i)([\\d.]+)\\s*(B|KB|MB|GB|TB)");
private final double size;
private final String unit;

public ByteSize(String value) {
super(value);
Matcher matcher = PATTERN.matcher(value.trim());
if (!matcher.matches()) {
throw new IllegalArgumentException("Invalid byte size format: " + value);
}

this.size = Double.parseDouble(matcher.group(1));
this.unit = matcher.group(2).toUpperCase();
}

public long getBytes() {
switch (unit) {
case "B":
return (long) size;
case "KB":
return (long) (size * 1024);
case "MB":
return (long) (size * 1024 * 1024);
case "GB":
return (long) (size * 1024 * 1024 * 1024);
case "TB":
return (long) (size * 1024L * 1024 * 1024 * 1024);
default:
throw new IllegalStateException("Unknown unit: " + unit);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,22 @@ options {
/**
* Parser Grammar for recognizing tokens and constructs of the directives language.
*/
BYTE_SIZE
: [0-9]+ ('.' [0-9]+)? BYTE_UNIT
;

TIME_DURATION
: [0-9]+ ('.' [0-9]+)? TIME_UNIT
;

fragment BYTE_UNIT
: ('B' | 'KB' | 'MB' | 'GB' | 'TB' | 'b' | 'kb' | 'mb' | 'gb' | 'tb')
;

fragment TIME_UNIT
: ('ns' | 'us' | 'ms' | 's' | 'm' | 'h' | 'd')
;

recipe
: statements EOF
;
Expand Down Expand Up @@ -140,9 +156,15 @@ numberRange
;

value
: String | Number | Column | Bool
: String
| Number
| Column
| Bool
| BYTE_SIZE
| TIME_DURATION
;


ecommand
: '!' Identifier
;
Expand All @@ -154,6 +176,14 @@ config
column
: Column
;
byteSizeArg
: BYTE_SIZE
;

timeDurationArg
: TIME_DURATION
;


text
: String
Expand Down
Loading