Skip to content

Commit

Permalink
added test coverage and fixed checkstyle failures
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew Wells <[email protected]>
  • Loading branch information
matthewryanwells committed Jul 10, 2023
1 parent 1c64d5c commit bb236f0
Showing 1 changed file with 60 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import static org.opensearch.sql.ast.dsl.AstDSL.booleanLiteral;
import static org.opensearch.sql.ast.dsl.AstDSL.cast;
import static org.opensearch.sql.ast.dsl.AstDSL.compare;
import static org.opensearch.sql.ast.dsl.AstDSL.dateLiteral;
import static org.opensearch.sql.ast.dsl.AstDSL.defaultFieldsArgs;
import static org.opensearch.sql.ast.dsl.AstDSL.defaultSortFieldArgs;
import static org.opensearch.sql.ast.dsl.AstDSL.defaultStatsArgs;
Expand All @@ -40,6 +41,7 @@
import static org.opensearch.sql.ast.dsl.AstDSL.relation;
import static org.opensearch.sql.ast.dsl.AstDSL.sort;
import static org.opensearch.sql.ast.dsl.AstDSL.stringLiteral;
import static org.opensearch.sql.ast.dsl.AstDSL.timestampLiteral;
import static org.opensearch.sql.ast.dsl.AstDSL.unresolvedArg;
import static org.opensearch.sql.ast.dsl.AstDSL.xor;

Expand Down Expand Up @@ -869,4 +871,62 @@ public void indexCanBeId() {
defaultStatsArgs()
));
}

@Test
public void testExtractFunctionExpr() {
assertEqual("source=t | eval f=extract(day from '2001-05-07 10:11:12')",
eval(
relation("t"),
let(
field("f"),
function("extract",
stringLiteral("day"), stringLiteral("2001-05-07 10:11:12"))
)
));
}


@Test
public void testGet_FormatFunctionExpr() {
assertEqual("source=t | eval f=get_format(DATE,'USA')",
eval(
relation("t"),
let(
field("f"),
function("get_format",
stringLiteral("DATE"), stringLiteral("USA"))
)
));
}

@Test
public void testTimeStampAddFunctionExpr() {
assertEqual("source=t | eval f=timestampadd(YEAR, 15, '2001-03-06 00:00:00')",
eval(
relation("t"),
let(
field("f"),
function("timestampadd",
stringLiteral("YEAR"),
intLiteral(15),
stringLiteral("2001-03-06 00:00:00"))
)
));
}

@Test
public void testTimeStampDiffFunctionExpr() {
assertEqual("source=t | eval f=timestampdiff("
+ "YEAR, '1997-01-01 00:00:00', '2001-03-06 00:00:00')",
eval(
relation("t"),
let(
field("f"),
function("timestampdiff",
stringLiteral("YEAR"),
stringLiteral("1997-01-01 00:00:00"),
stringLiteral("2001-03-06 00:00:00"))
)
));
}
}

0 comments on commit bb236f0

Please sign in to comment.