Skip to content

Software Engineer Intern Assignment - Jayaram #994

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 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
203 changes: 203 additions & 0 deletions README.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

/**
* {@link DirectiveContext} provides the context object to the processing of
* directives.

*/
public interface DirectiveContext extends DirectiveEnforcer, DirectiveAlias {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright © 2025 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.
*/
// --- File: ByteSize.java ---
package io.cdap.wrangler.api.parser;

import com.google.gson.JsonElement;
import com.google.gson.JsonPrimitive;

/**
* Token representing a byte size value (e.g., "10KB", "2.5MB").
*/
public class ByteSize implements Token {
private final long bytes;

public ByteSize(String value) {
String unit = value.replaceAll("[0-9.]", "").toUpperCase();
double number = Double.parseDouble(value.replaceAll("[^0-9.]", ""));
switch (unit) {
case "KB": this.bytes = (long) (number * 1024); break;
case "MB": this.bytes = (long) (number * 1024 * 1024); break;
case "GB": this.bytes = (long) (number * 1024 * 1024 * 1024); break;
default: this.bytes = (long) number; break;
}
}

public long getBytes() {
return this.bytes;
}

@Override
public Object value() {
return bytes;
}

@Override
public TokenType type() {
return TokenType.BYTE_SIZE;
}

@Override
public JsonElement toJson() {
return new JsonPrimitive(bytes);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright © 2025 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.
*/


// --- File: TimeDuration.java ---
package io.cdap.wrangler.api.parser;

import com.google.gson.JsonElement;
import com.google.gson.JsonPrimitive;

/**
* Token representing a time duration value (e.g., "150ms", "2.5s").
*/
public class TimeDuration implements Token {
private final long milliseconds;

public TimeDuration(String value) {
String unit = value.replaceAll("[0-9.]", "").toLowerCase();
double number = Double.parseDouble(value.replaceAll("[^0-9.]", ""));
switch (unit) {
case "s": this.milliseconds = (long) (number * 1000); break;
case "ms": this.milliseconds = (long) (number); break;
case "min": this.milliseconds = (long) (number * 60000); break;
default: this.milliseconds = (long) number; break;
}
}

public long getMilliseconds() {
return milliseconds;
}

@Override
public Object value() {
return milliseconds;
}

@Override
public TokenType type() {
return TokenType.TIME_DURATION;
}

@Override
public JsonElement toJson() {
return new JsonPrimitive(milliseconds);
}
}


85 changes: 43 additions & 42 deletions wrangler-api/src/main/java/io/cdap/wrangler/api/parser/Token.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,46 +14,47 @@
* the License.
*/

package io.cdap.wrangler.api.parser;
package io.cdap.wrangler.api.parser;

import com.google.gson.JsonElement;
import io.cdap.wrangler.api.annotations.PublicEvolving;

import java.io.Serializable;

/**
* The Token class represents the object that contains the value and type of
* the token as parsed by the parser of the grammar defined for recipe.
*
* <p>This class provides methods for retrieving the wrapped value of token parsed
* as well the type of token the implementation of this interface represents.</p>
*
* <p>It also provides method for providing the {@code JsonElement} of implementation
* of this interface.</p>
*/
@PublicEvolving
public interface Token extends Serializable {
/**
* Returns the {@code value} of the object wrapped by the
* implementation of this interface.
*
* @return {@code value} wrapped by the implementation of this interface.
*/
Object value();

/**
* Returns the {@code TokenType} of the object represented by the
* implementation of this interface.
*
* @return {@code TokenType} of the implementation object.
*/
TokenType type();

/**
* The class implementing this interface will return the {@code JsonElement}
* instance including the values of the object.
*
* @return {@code JsonElement} object containing members of implementing class.
*/
JsonElement toJson();
}
import com.google.gson.JsonElement;
import io.cdap.wrangler.api.annotations.PublicEvolving;

import java.io.Serializable;

/**
* The Token class represents the object that contains the value and type of
* the token as parsed by the parser of the grammar defined for recipe.
*
* <p>This class provides methods for retrieving the wrapped value of token parsed
* as well the type of token the implementation of this interface represents.</p>
*
* <p>It also provides method for providing the {@code JsonElement} of implementation
* of this interface.</p>
*/
@PublicEvolving
public interface Token extends Serializable {
/**
* Returns the {@code value} of the object wrapped by the
* implementation of this interface.
*
* @return {@code value} wrapped by the implementation of this interface.
*/
Object value();

/**
* Returns the {@code TokenType} of the object represented by the
* implementation of this interface.
*
* @return {@code TokenType} of the implementation object.
*/
TokenType type();

/**
* The class implementing this interface will return the {@code JsonElement}
* instance including the values of the object.
*
* @return {@code JsonElement} object containing members of implementing class.
*/
JsonElement toJson();
}

Loading