From 113aecf51342852e31456eb9202a1fd1b7dbebdf Mon Sep 17 00:00:00 2001 From: Jakob Braun Date: Tue, 11 Aug 2020 11:00:23 +0200 Subject: [PATCH 1/4] #87: Added BigDecimal literal --- doc/changes/changes-4.0.1.md | 5 +++ doc/system_requirements.md | 2 +- pom.xml | 2 +- .../sql/expression/BigDecimalLiteral.java | 35 +++++++++++++++++++ .../expression/ValueExpressionVisitor.java | 2 ++ .../rendering/ValueExpressionRenderer.java | 7 ++++ .../sql/expression/TestBigDecimalLiteral.java | 16 +++++++++ .../TestBooleanExpressionRenderer.java | 11 ++++++ 8 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 doc/changes/changes-4.0.1.md create mode 100644 src/main/java/com/exasol/sql/expression/BigDecimalLiteral.java create mode 100644 src/test/java/com/exasol/sql/expression/TestBigDecimalLiteral.java diff --git a/doc/changes/changes-4.0.1.md b/doc/changes/changes-4.0.1.md new file mode 100644 index 00000000..f28c7ab6 --- /dev/null +++ b/doc/changes/changes-4.0.1.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/system_requirements.md b/doc/system_requirements.md index beff3887..f967e2bc 100644 --- a/doc/system_requirements.md +++ b/doc/system_requirements.md @@ -190,7 +190,7 @@ Needs: dsn #### Literal Values `req~literal-values~1` -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..790d30cc --- /dev/null +++ b/src/main/java/com/exasol/sql/expression/BigDecimalLiteral.java @@ -0,0 +1,35 @@ +package com.exasol.sql.expression; + +import java.math.BigDecimal; + +/** + * This class represents BigDecimal literals. + */ +// [impl->dsn~literal-values~1] +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); + } + + @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/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/TestBigDecimalLiteral.java b/src/test/java/com/exasol/sql/expression/TestBigDecimalLiteral.java new file mode 100644 index 00000000..764149d5 --- /dev/null +++ b/src/test/java/com/exasol/sql/expression/TestBigDecimalLiteral.java @@ -0,0 +1,16 @@ +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~1] +class TestBigDecimalLiteral { + @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/rendering/TestBooleanExpressionRenderer.java b/src/test/java/com/exasol/sql/expression/rendering/TestBooleanExpressionRenderer.java index 8ce1eda8..2804845b 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~1] + @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 From fd79eb9427245b14d9997953fab62308e7e249c0 Mon Sep 17 00:00:00 2001 From: Jakob Braun Date: Tue, 11 Aug 2020 11:09:40 +0200 Subject: [PATCH 2/4] small changes --- doc/changes/changelog.md | 1 + doc/changes/{changes-4.0.1.md => changes-4.1.0.md} | 0 2 files changed, 1 insertion(+) rename doc/changes/{changes-4.0.1.md => changes-4.1.0.md} (100%) 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.0.1.md b/doc/changes/changes-4.1.0.md similarity index 100% rename from doc/changes/changes-4.0.1.md rename to doc/changes/changes-4.1.0.md From 2c10d24ca7a6409431cc457b36ec1fa6193d553c Mon Sep 17 00:00:00 2001 From: Jakob Braun Date: Tue, 11 Aug 2020 11:17:38 +0200 Subject: [PATCH 3/4] #87 added missing function to BigDecimalLiteral --- .../com/exasol/sql/expression/BigDecimalLiteral.java | 9 +++++++++ .../com/exasol/sql/expression/TestBigDecimalLiteral.java | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/src/main/java/com/exasol/sql/expression/BigDecimalLiteral.java b/src/main/java/com/exasol/sql/expression/BigDecimalLiteral.java index 790d30cc..dc12d42b 100644 --- a/src/main/java/com/exasol/sql/expression/BigDecimalLiteral.java +++ b/src/main/java/com/exasol/sql/expression/BigDecimalLiteral.java @@ -23,6 +23,15 @@ 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); diff --git a/src/test/java/com/exasol/sql/expression/TestBigDecimalLiteral.java b/src/test/java/com/exasol/sql/expression/TestBigDecimalLiteral.java index 764149d5..279c9e40 100644 --- a/src/test/java/com/exasol/sql/expression/TestBigDecimalLiteral.java +++ b/src/test/java/com/exasol/sql/expression/TestBigDecimalLiteral.java @@ -9,6 +9,11 @@ // [utest->dsn~literal-values~1] 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")); From 14f3d6ee57c5d12dee141740b669cc7080b51b3a Mon Sep 17 00:00:00 2001 From: Jakob Braun Date: Tue, 11 Aug 2020 12:20:29 +0200 Subject: [PATCH 4/4] #87 updated OFT --- doc/design.md | 4 ++-- doc/system_requirements.md | 2 +- .../java/com/exasol/sql/expression/BigDecimalLiteral.java | 2 +- src/main/java/com/exasol/sql/expression/DefaultValue.java | 2 +- src/main/java/com/exasol/sql/expression/DoubleLiteral.java | 2 +- src/main/java/com/exasol/sql/expression/FloatLiteral.java | 2 +- src/main/java/com/exasol/sql/expression/IntegerLiteral.java | 2 +- src/main/java/com/exasol/sql/expression/LongLiteral.java | 2 +- src/main/java/com/exasol/sql/expression/NullLiteral.java | 2 +- src/main/java/com/exasol/sql/expression/StringLiteral.java | 2 +- .../java/com/exasol/sql/expression/DoubleLiteralTest.java | 2 +- src/test/java/com/exasol/sql/expression/FloatLiteralTest.java | 2 +- src/test/java/com/exasol/sql/expression/LongLiteralTest.java | 2 +- .../java/com/exasol/sql/expression/TestBigDecimalLiteral.java | 2 +- .../java/com/exasol/sql/expression/TestIntegerLiteral.java | 2 +- .../java/com/exasol/sql/expression/TestStringLiteral.java | 2 +- .../expression/rendering/TestBooleanExpressionRenderer.java | 2 +- 17 files changed, 18 insertions(+), 18 deletions(-) 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 f967e2bc..3e685f95 100644 --- a/doc/system_requirements.md +++ b/doc/system_requirements.md @@ -188,7 +188,7 @@ 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`, `BigDecimal`. diff --git a/src/main/java/com/exasol/sql/expression/BigDecimalLiteral.java b/src/main/java/com/exasol/sql/expression/BigDecimalLiteral.java index dc12d42b..0a258c48 100644 --- a/src/main/java/com/exasol/sql/expression/BigDecimalLiteral.java +++ b/src/main/java/com/exasol/sql/expression/BigDecimalLiteral.java @@ -5,7 +5,7 @@ /** * This class represents BigDecimal literals. */ -// [impl->dsn~literal-values~1] +// [impl->dsn~literal-values~2] public class BigDecimalLiteral extends AbstractValueExpression { private final BigDecimal literal; 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/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 index 279c9e40..39c2ede0 100644 --- a/src/test/java/com/exasol/sql/expression/TestBigDecimalLiteral.java +++ b/src/test/java/com/exasol/sql/expression/TestBigDecimalLiteral.java @@ -7,7 +7,7 @@ import org.junit.jupiter.api.Test; -// [utest->dsn~literal-values~1] +// [utest->dsn~literal-values~2] class TestBigDecimalLiteral { @Test void testGetValue() { 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 2804845b..a2ad4dee 100644 --- a/src/test/java/com/exasol/sql/expression/rendering/TestBooleanExpressionRenderer.java +++ b/src/test/java/com/exasol/sql/expression/rendering/TestBooleanExpressionRenderer.java @@ -214,7 +214,7 @@ void testComparisonOperatorsWithColumnReference() { ); } - //// [utest->dsn~literal-values~1] + //// [utest->dsn~literal-values~2] @Test void testBigDecimalLiteralComparison() { final BooleanExpression expression = eq(BigDecimalLiteral.of(BigDecimal.TEN),