Skip to content
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

#87: Added BigDecimal literal #88

Merged
merged 4 commits into from
Aug 11, 2020
Merged
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
1 change: 1 addition & 0 deletions doc/changes/changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Changes

* [4.1.0](changes-4.1.0.md)
* [4.0.0](changes-4.0.0.md)
5 changes: 5 additions & 0 deletions doc/changes/changes-4.1.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# SQL Statement Builder 4.1.0, released 2020-08-11

## Features / Enhancements

* #87: Added BigDecimal literal
4 changes: 2 additions & 2 deletions doc/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions doc/system_requirements.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.exasol</groupId>
<artifactId>sql-statement-builder</artifactId>
<version>4.0.0</version>
<version>4.1.0</version>
<name>Exasol SQL Statement Builder</name>
<description>This module provides a Builder for SQL statements that helps creating the correct structure and
validates variable parts of the statements.
Expand Down
44 changes: 44 additions & 0 deletions src/main/java/com/exasol/sql/expression/BigDecimalLiteral.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/exasol/sql/expression/DefaultValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* This is for example used in updates embedded into {@code MERGE} statements.
* </p>
*/
// [impl->dsn~literal-values~1]
// [impl->dsn~literal-values~2]
public final class DefaultValue extends AbstractValueExpression {
private static final DefaultValue instance = new DefaultValue();

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/exasol/sql/expression/DoubleLiteral.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/exasol/sql/expression/FloatLiteral.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/exasol/sql/expression/LongLiteral.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/exasol/sql/expression/NullLiteral.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/exasol/sql/expression/StringLiteral.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
21 changes: 21 additions & 0 deletions src/test/java/com/exasol/sql/expression/TestBigDecimalLiteral.java
Original file line number Diff line number Diff line change
@@ -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"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"));
}
}