-
Notifications
You must be signed in to change notification settings - Fork 383
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
### What changes were proposed in this pull request? Add more static methods of Literal for Java client usage ### Why are the changes needed? Fix: #1383 ### Does this PR introduce _any_ user-facing change? no, but users can use `Literal` more conveniently by Java client ### How was this patch tested? UTs added
- Loading branch information
Showing
2 changed files
with
168 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
75 changes: 75 additions & 0 deletions
75
api/src/test/java/com/datastrato/gravitino/rel/TestLiteral.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright 2024 Datastrato Pvt Ltd. | ||
* This software is licensed under the Apache License version 2. | ||
*/ | ||
package com.datastrato.gravitino.rel; | ||
|
||
import static com.datastrato.gravitino.rel.expressions.literals.Literals.booleanLiteral; | ||
import static com.datastrato.gravitino.rel.expressions.literals.Literals.byteLiteral; | ||
import static com.datastrato.gravitino.rel.expressions.literals.Literals.date; | ||
import static com.datastrato.gravitino.rel.expressions.literals.Literals.doubleLiteral; | ||
import static com.datastrato.gravitino.rel.expressions.literals.Literals.floatLiteral; | ||
import static com.datastrato.gravitino.rel.expressions.literals.Literals.integer; | ||
import static com.datastrato.gravitino.rel.expressions.literals.Literals.longLiteral; | ||
import static com.datastrato.gravitino.rel.expressions.literals.Literals.shortLiteral; | ||
import static com.datastrato.gravitino.rel.expressions.literals.Literals.string; | ||
import static com.datastrato.gravitino.rel.expressions.literals.Literals.time; | ||
import static com.datastrato.gravitino.rel.expressions.literals.Literals.timestamp; | ||
|
||
import com.datastrato.gravitino.rel.expressions.literals.Literal; | ||
import com.datastrato.gravitino.rel.types.Types; | ||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.time.LocalTime; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class TestLiteral { | ||
|
||
@Test | ||
public void testLiterals() { | ||
Literal literal = booleanLiteral(Boolean.valueOf("true")); | ||
Assertions.assertEquals(literal.value(), true); | ||
Assertions.assertEquals(literal.dataType(), Types.BooleanType.get()); | ||
|
||
literal = byteLiteral(Byte.valueOf("1")); | ||
Assertions.assertEquals(literal.value(), (byte) 1); | ||
Assertions.assertEquals(literal.dataType(), Types.ByteType.get()); | ||
|
||
literal = shortLiteral(Short.valueOf("1")); | ||
Assertions.assertEquals(literal.value(), (short) 1); | ||
Assertions.assertEquals(literal.dataType(), Types.ShortType.get()); | ||
|
||
literal = integer(Integer.valueOf("1")); | ||
Assertions.assertEquals(literal.value(), 1); | ||
Assertions.assertEquals(literal.dataType(), Types.IntegerType.get()); | ||
|
||
literal = longLiteral(Long.valueOf("1")); | ||
Assertions.assertEquals(literal.value(), 1L); | ||
Assertions.assertEquals(literal.dataType(), Types.LongType.get()); | ||
|
||
literal = floatLiteral(Float.valueOf("1.234")); | ||
Assertions.assertEquals(literal.value(), 1.234f); | ||
Assertions.assertEquals(literal.dataType(), Types.FloatType.get()); | ||
|
||
literal = doubleLiteral(Double.valueOf("1.234")); | ||
Assertions.assertEquals(literal.value(), 1.234d); | ||
Assertions.assertEquals(literal.dataType(), Types.DoubleType.get()); | ||
|
||
literal = date(LocalDate.parse("2020-01-01")); | ||
Assertions.assertEquals(literal.value(), LocalDate.of(2020, 1, 1)); | ||
Assertions.assertEquals(literal.dataType(), Types.DateType.get()); | ||
|
||
literal = time(LocalTime.parse("12:34:56")); | ||
Assertions.assertEquals(literal.value(), LocalTime.of(12, 34, 56)); | ||
Assertions.assertEquals(literal.dataType(), Types.TimeType.get()); | ||
|
||
literal = timestamp(LocalDateTime.parse("2020-01-01T12:34:56")); | ||
Assertions.assertEquals(literal.value(), LocalDateTime.of(2020, 1, 1, 12, 34, 56)); | ||
Assertions.assertEquals(literal.dataType(), Types.TimestampType.withoutTimeZone()); | ||
|
||
literal = string("hello"); | ||
Assertions.assertEquals(literal.value(), "hello"); | ||
Assertions.assertEquals(literal.dataType(), Types.StringType.get()); | ||
} | ||
} |