-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Develop #975
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
ShinaKumari
wants to merge
2
commits into
data-integrations:develop
Choose a base branch
from
ShinaKumari:develop
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Develop #975
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
Here's how you can proceed with the Wrangler enhancement: Step 1: Fork the Repository Step 2: Modify the Grammar.......// Modify the parser rules to accept these tokens. Step 3: Update the API (wrangler-api)......//Update the Token Types to support these new types. Changes that i have done : Define Byte as a BYTE_SIZE,and Time as TIMEDURATION classes. THEN I FIX IT IN THE WRABGLER CORE FOLDER \\Directives.g4 Extend the base Token class correctly (from io.cdap.wrangler.api.parser.Token). // Add lexer rules for BYTE_SIZE and TIME_DURATION BYTE : [0-9]+ ('KB'|'MB'|'GB'|'B'); TIME_DURATION : [0-9]+ ('ms'|'s'|'m'|'h'|'d'); // parser rules byteSizeArg : BYTE; timeDurationArg : TIME; package io.cdap.wrangler.api.parser; import com.google.gson.JsonElement; import com.google.gson.JsonPrimitive; public class Byte implements Token { private final long bytes; public Byte(String value) { this.bytes = parseByteSize(value.trim().toUpperCase()); } private long parseByteSize(String value) { if (value.endsWith("KB")) { return (long)(Double.parseDouble(value.replace("KB", "")) * 1024); } else if (value.endsWith("MB")) { return (long)(Double.parseDouble(value.replace("MB", "")) * 1024 * 1024); } else if (value.endsWith("GB")) { return (long)(Double.parseDouble(value.replace("GB", "")) * 1024 * 1024 * 1024); } else if (value.endsWith("B")) { return Long.parseLong(value.replace("B", "")); } else { throw new IllegalArgumentException("Invalid byte size format: " + value); } } public long getBytes() { return bytes; } @OverRide public Object value() { return bytes; } @OverRide public TokenType type() { return TokenType.BYTE; } @OverRide public JsonElement toJson() { return new JsonPrimitive(bytes); } } ........ package io.cdap.wrangler.api.parser; import com.google.gson.JsonElement; import com.google.gson.JsonPrimitive; public class Time implements Token { private final long nanoseconds; public Time (String value) { this.nanoseconds = parseTimeDuration(value.trim().toLowerCase()); } private long parseTimeDuration(String value) { if (value.endsWith("ns")) { return Long.parseLong(value.replace("ns", "")); } else if (value.endsWith("ms")) { return (long)(Double.parseDouble(value.replace("ms", "")) * 1_000_000); } else if (value.endsWith("s")) { return (long)(Double.parseDouble(value.replace("s", "")) * 1_000_000_000); } else if (value.endsWith("m")) { return (long)(Double.parseDouble(value.replace("m", "")) * 60 * 1_000_000_000L); } else if (value.endsWith("h")) { return (long)(Double.parseDouble(value.replace("h", "")) * 3600 * 1_000_000_000L); } else { throw new IllegalArgumentException("Invalid time duration format: " + value); } } public long getNanoseconds() { return nanoseconds; } @OverRide public Object value() { return nanoseconds; } @OverRide public TokenType type() { return TokenType.TIME; } @OverRide public JsonElement toJson() { return new JsonPrimitive(nanoseconds); } } ........ package io.cdap.wrangler.api.parser; public enum Tokenn { BYTE, TIME; } //BYTE_SIZE //TIME_DURATION ....... IDENTIFIER, BYTE, TIME ....
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Added ByteSize as a Byte and TimeDuration as a Time parser with directive