diff --git a/doc/changes/changelog.md b/doc/changes/changelog.md index b4e2f5a7..a2356338 100644 --- a/doc/changes/changelog.md +++ b/doc/changes/changelog.md @@ -1,3 +1,4 @@ # Changes +* [4.1.0](changes-4.1.0.md) * [4.0.0](changes-4.0.0.md) \ No newline at end of file diff --git a/doc/changes/changes-4.1.0.md b/doc/changes/changes-4.1.0.md new file mode 100644 index 00000000..f28c7ab6 --- /dev/null +++ b/doc/changes/changes-4.1.0.md @@ -0,0 +1,5 @@ +# SQL Statement Builder 4.1.0, released 2020-08-11 + +## Features / Enhancements + +* #87: Added BigDecimal literal \ No newline at end of file diff --git a/doc/design.md b/doc/design.md index f06586a9..c05c9111 100644 --- a/doc/design.md +++ b/doc/design.md @@ -48,13 +48,13 @@ Needs: impl, utest Tags: Select Statement Builder ### Using Literal Values -`dsn~literal-values~1` +`dsn~literal-values~2` Forwarded from requirements. Covers: -* `req~literal-values~1` +* `req~literal-values~2` Needs: impl, utest diff --git a/doc/system_requirements.md b/doc/system_requirements.md index beff3887..3e685f95 100644 --- a/doc/system_requirements.md +++ b/doc/system_requirements.md @@ -188,9 +188,9 @@ Covers: Needs: dsn #### Literal Values -`req~literal-values~1` +`req~literal-values~2` -ESB supports the following literal values: `default`, `double`, `float`, `integer`, `long`, `null`, `string`. +ESB supports the following literal values: `default`, `double`, `float`, `integer`, `long`, `null`, `string`, `BigDecimal`. Covers: diff --git a/pom.xml b/pom.xml index 078c0929..0bae3270 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 com.exasol sql-statement-builder - 4.0.0 + 4.1.0 Exasol SQL Statement Builder This module provides a Builder for SQL statements that helps creating the correct structure and validates variable parts of the statements. diff --git a/src/main/java/com/exasol/sql/expression/BigDecimalLiteral.java b/src/main/java/com/exasol/sql/expression/BigDecimalLiteral.java new file mode 100644 index 00000000..0a258c48 --- /dev/null +++ b/src/main/java/com/exasol/sql/expression/BigDecimalLiteral.java @@ -0,0 +1,44 @@ +package com.exasol.sql.expression; + +import java.math.BigDecimal; + +/** + * This class represents BigDecimal literals. + */ +// [impl->dsn~literal-values~2] +public class BigDecimalLiteral extends AbstractValueExpression { + private final BigDecimal literal; + + private BigDecimalLiteral(BigDecimal literal) { + this.literal = literal; + } + + /** + * Create a new {@link BigDecimalLiteral} from a BigDecimal. + * + * @param literal content + * @return new {@link StringLiteral} + */ + public static BigDecimalLiteral of(BigDecimal literal) { + return new BigDecimalLiteral(literal); + } + + /** + * Get the value of the {@link BigDecimalLiteral}. + * + * @return BigDecimal value + */ + public BigDecimal getValue() { + return literal; + } + + @Override + public void accept(ValueExpressionVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return literal.toString(); + } +} diff --git a/src/main/java/com/exasol/sql/expression/DefaultValue.java b/src/main/java/com/exasol/sql/expression/DefaultValue.java index a4f132ee..c941c6d6 100644 --- a/src/main/java/com/exasol/sql/expression/DefaultValue.java +++ b/src/main/java/com/exasol/sql/expression/DefaultValue.java @@ -7,7 +7,7 @@ * This is for example used in updates embedded into {@code MERGE} statements. *

*/ -// [impl->dsn~literal-values~1] +// [impl->dsn~literal-values~2] public final class DefaultValue extends AbstractValueExpression { private static final DefaultValue instance = new DefaultValue(); diff --git a/src/main/java/com/exasol/sql/expression/DoubleLiteral.java b/src/main/java/com/exasol/sql/expression/DoubleLiteral.java index 23c2e77c..3a879776 100644 --- a/src/main/java/com/exasol/sql/expression/DoubleLiteral.java +++ b/src/main/java/com/exasol/sql/expression/DoubleLiteral.java @@ -3,7 +3,7 @@ /** * This class represents double literals. */ -// [impl->dsn~literal-values~1] +// [impl->dsn~literal-values~2] public class DoubleLiteral extends AbstractValueExpression { private final double value; diff --git a/src/main/java/com/exasol/sql/expression/FloatLiteral.java b/src/main/java/com/exasol/sql/expression/FloatLiteral.java index fa15c508..944b94de 100644 --- a/src/main/java/com/exasol/sql/expression/FloatLiteral.java +++ b/src/main/java/com/exasol/sql/expression/FloatLiteral.java @@ -3,7 +3,7 @@ /** * This class represents float literals. */ -// [impl->dsn~literal-values~1] +// [impl->dsn~literal-values~2] public class FloatLiteral extends AbstractValueExpression { private final float value; diff --git a/src/main/java/com/exasol/sql/expression/IntegerLiteral.java b/src/main/java/com/exasol/sql/expression/IntegerLiteral.java index 4c33a7d0..28bf6c10 100644 --- a/src/main/java/com/exasol/sql/expression/IntegerLiteral.java +++ b/src/main/java/com/exasol/sql/expression/IntegerLiteral.java @@ -3,7 +3,7 @@ /** * This class represents integer literals. */ -// [impl->dsn~literal-values~1] +// [impl->dsn~literal-values~2] public final class IntegerLiteral extends AbstractValueExpression { private final int value; diff --git a/src/main/java/com/exasol/sql/expression/LongLiteral.java b/src/main/java/com/exasol/sql/expression/LongLiteral.java index 685847d2..e2b18c7d 100644 --- a/src/main/java/com/exasol/sql/expression/LongLiteral.java +++ b/src/main/java/com/exasol/sql/expression/LongLiteral.java @@ -3,7 +3,7 @@ /** * This class represents long literals. */ -// [impl->dsn~literal-values~1] +// [impl->dsn~literal-values~2] public class LongLiteral extends AbstractValueExpression { private final long value; diff --git a/src/main/java/com/exasol/sql/expression/NullLiteral.java b/src/main/java/com/exasol/sql/expression/NullLiteral.java index 44075248..2e7bf1bb 100644 --- a/src/main/java/com/exasol/sql/expression/NullLiteral.java +++ b/src/main/java/com/exasol/sql/expression/NullLiteral.java @@ -3,7 +3,7 @@ /** * This class represents a null literal. */ -// [impl->dsn~literal-values~1] +// [impl->dsn~literal-values~2] public final class NullLiteral extends AbstractValueExpression { private static final NullLiteral instance = new NullLiteral(); diff --git a/src/main/java/com/exasol/sql/expression/StringLiteral.java b/src/main/java/com/exasol/sql/expression/StringLiteral.java index e056b665..e572cf14 100644 --- a/src/main/java/com/exasol/sql/expression/StringLiteral.java +++ b/src/main/java/com/exasol/sql/expression/StringLiteral.java @@ -3,7 +3,7 @@ /** * This class represents string literals (or character literals in SQL terms). */ -// [impl->dsn~literal-values~1] +// [impl->dsn~literal-values~2] public final class StringLiteral extends AbstractValueExpression { private final String literal; diff --git a/src/main/java/com/exasol/sql/expression/ValueExpressionVisitor.java b/src/main/java/com/exasol/sql/expression/ValueExpressionVisitor.java index 723abca8..ec503aea 100644 --- a/src/main/java/com/exasol/sql/expression/ValueExpressionVisitor.java +++ b/src/main/java/com/exasol/sql/expression/ValueExpressionVisitor.java @@ -20,6 +20,8 @@ public interface ValueExpressionVisitor { public void visit(FloatLiteral literal); + public void visit(BigDecimalLiteral literal); + public void visit(BooleanLiteral literal); public void visit(ColumnReference columnReference); diff --git a/src/main/java/com/exasol/sql/expression/rendering/ValueExpressionRenderer.java b/src/main/java/com/exasol/sql/expression/rendering/ValueExpressionRenderer.java index 1a164327..88065686 100644 --- a/src/main/java/com/exasol/sql/expression/rendering/ValueExpressionRenderer.java +++ b/src/main/java/com/exasol/sql/expression/rendering/ValueExpressionRenderer.java @@ -54,6 +54,13 @@ public void visit(final FloatLiteral literal) { setLastVisited(literal); } + @Override + public void visit(BigDecimalLiteral literal) { + appendCommaWhenNeeded(literal); + append(literal.toString()); + setLastVisited(literal); + } + @Override public void visit(final BooleanLiteral literal) { appendCommaWhenNeeded(literal); diff --git a/src/test/java/com/exasol/sql/expression/DoubleLiteralTest.java b/src/test/java/com/exasol/sql/expression/DoubleLiteralTest.java index dc49b294..eeea3b9c 100644 --- a/src/test/java/com/exasol/sql/expression/DoubleLiteralTest.java +++ b/src/test/java/com/exasol/sql/expression/DoubleLiteralTest.java @@ -5,7 +5,7 @@ import org.junit.jupiter.api.Test; -// [utest->dsn~literal-values~1] +// [utest->dsn~literal-values~2] class DoubleLiteralTest { @Test void testGetValue() { diff --git a/src/test/java/com/exasol/sql/expression/FloatLiteralTest.java b/src/test/java/com/exasol/sql/expression/FloatLiteralTest.java index bd3a5777..0e8dd602 100644 --- a/src/test/java/com/exasol/sql/expression/FloatLiteralTest.java +++ b/src/test/java/com/exasol/sql/expression/FloatLiteralTest.java @@ -5,7 +5,7 @@ import org.junit.jupiter.api.Test; -// [utest->dsn~literal-values~1] +// [utest->dsn~literal-values~2] class FloatLiteralTest { @Test void testGetValue() { diff --git a/src/test/java/com/exasol/sql/expression/LongLiteralTest.java b/src/test/java/com/exasol/sql/expression/LongLiteralTest.java index 88f9ccf6..31e13db8 100644 --- a/src/test/java/com/exasol/sql/expression/LongLiteralTest.java +++ b/src/test/java/com/exasol/sql/expression/LongLiteralTest.java @@ -5,7 +5,7 @@ import org.junit.jupiter.api.Test; -// [utest->dsn~literal-values~1] +// [utest->dsn~literal-values~2] class LongLiteralTest { @Test void testGetValue() { diff --git a/src/test/java/com/exasol/sql/expression/TestBigDecimalLiteral.java b/src/test/java/com/exasol/sql/expression/TestBigDecimalLiteral.java new file mode 100644 index 00000000..39c2ede0 --- /dev/null +++ b/src/test/java/com/exasol/sql/expression/TestBigDecimalLiteral.java @@ -0,0 +1,21 @@ +package com.exasol.sql.expression; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; + +import java.math.BigDecimal; + +import org.junit.jupiter.api.Test; + +// [utest->dsn~literal-values~2] +class TestBigDecimalLiteral { + @Test + void testGetValue() { + assertThat(BigDecimalLiteral.of(BigDecimal.TEN).getValue(), equalTo(BigDecimal.TEN)); + } + + @Test + void testGetToString() { + assertThat(BigDecimalLiteral.of(BigDecimal.valueOf(123)).toString(), equalTo("123")); + } +} \ No newline at end of file diff --git a/src/test/java/com/exasol/sql/expression/TestIntegerLiteral.java b/src/test/java/com/exasol/sql/expression/TestIntegerLiteral.java index 889d5894..6f0d71bf 100644 --- a/src/test/java/com/exasol/sql/expression/TestIntegerLiteral.java +++ b/src/test/java/com/exasol/sql/expression/TestIntegerLiteral.java @@ -5,7 +5,7 @@ import org.junit.jupiter.api.Test; -// [utest->dsn~literal-values~1] +// [utest->dsn~literal-values~2] class TestIntegerLiteral { @Test void testGetValue() { diff --git a/src/test/java/com/exasol/sql/expression/TestStringLiteral.java b/src/test/java/com/exasol/sql/expression/TestStringLiteral.java index f8191f2d..8145133b 100644 --- a/src/test/java/com/exasol/sql/expression/TestStringLiteral.java +++ b/src/test/java/com/exasol/sql/expression/TestStringLiteral.java @@ -5,7 +5,7 @@ import org.junit.jupiter.api.Test; -// [utest->dsn~literal-values~1] +// [utest->dsn~literal-values~2] class TestStringLiteral { @Test void testGetToString() { diff --git a/src/test/java/com/exasol/sql/expression/rendering/TestBooleanExpressionRenderer.java b/src/test/java/com/exasol/sql/expression/rendering/TestBooleanExpressionRenderer.java index 8ce1eda8..a2ad4dee 100644 --- a/src/test/java/com/exasol/sql/expression/rendering/TestBooleanExpressionRenderer.java +++ b/src/test/java/com/exasol/sql/expression/rendering/TestBooleanExpressionRenderer.java @@ -7,8 +7,11 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.assertAll; +import java.math.BigDecimal; + import org.junit.jupiter.api.Test; +import com.exasol.sql.expression.BigDecimalLiteral; import com.exasol.sql.expression.BooleanExpression; import com.exasol.sql.expression.ComparisonOperator; import com.exasol.sql.rendering.StringRendererConfig; @@ -210,4 +213,12 @@ void testComparisonOperatorsWithColumnReference() { rendersTo("t.city >= t.machi")) // ); } + + //// [utest->dsn~literal-values~2] + @Test + void testBigDecimalLiteralComparison() { + final BooleanExpression expression = eq(BigDecimalLiteral.of(BigDecimal.TEN), + BigDecimalLiteral.of(BigDecimal.valueOf(10.2))); + assertThat(expression, rendersTo("10 = 10.2")); + } } \ No newline at end of file