-
Notifications
You must be signed in to change notification settings - Fork 5
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
* #94 Added CAST function support Co-authored-by: Anastasiia Sergienko <anastasiia.sergienko@exasol.com>
- Loading branch information
1 parent
90cdea0
commit 1e4d903
Showing
11 changed files
with
155 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# Changes | ||
|
||
* [4.3.0](changes_4.3.0.md) | ||
* [4.2.0](changes_4.2.0.md) | ||
* [4.1.0](changes_4.1.0.md) | ||
* [4.0.0](changes_4.0.0.md) |
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,7 @@ | ||
# SQL Statement Builder 4.3.0, released 2020-10-22 | ||
|
||
Code Name: CAST function support | ||
|
||
## Features / Enhancements | ||
|
||
* #94: Added CAST function support |
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
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
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
63 changes: 63 additions & 0 deletions
63
src/main/java/com/exasol/sql/expression/function/exasol/CastExasolFunction.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,63 @@ | ||
package com.exasol.sql.expression.function.exasol; | ||
|
||
import java.util.List; | ||
|
||
import com.exasol.datatype.type.DataType; | ||
import com.exasol.sql.expression.ValueExpression; | ||
import com.exasol.sql.expression.ValueExpressionVisitor; | ||
import com.exasol.sql.expression.function.FunctionName; | ||
|
||
/** | ||
* This class represents the Exasol CAST function. | ||
*/ | ||
public class CastExasolFunction extends ExasolFunction { | ||
private final DataType type; | ||
|
||
private CastExasolFunction(final ValueExpression value, final DataType type) { | ||
super(ExasolScalarFunctionCast.CAST, List.of(value)); | ||
this.type = type; | ||
} | ||
|
||
/** | ||
* Create a new {@link CastExasolFunction} instance. | ||
* | ||
* @param valueExpression value to cast | ||
* @param type type to cast the value to | ||
* @return new {@link CastExasolFunction} | ||
*/ | ||
public static CastExasolFunction of(final ValueExpression valueExpression, final DataType type) { | ||
return new CastExasolFunction(valueExpression, type); | ||
} | ||
|
||
/** | ||
* Get the value to cast. | ||
* | ||
* @return value to cast | ||
*/ | ||
public ValueExpression getValue() { | ||
return this.valueExpressions.get(0); | ||
} | ||
|
||
/** | ||
* Get the type to cast the value to. | ||
* | ||
* @return type to cast the value to | ||
*/ | ||
public DataType getType() { | ||
return this.type; | ||
} | ||
|
||
@Override | ||
public boolean hasParenthesis() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public void accept(final ValueExpressionVisitor visitor) { | ||
visitor.visit(this); | ||
} | ||
|
||
private enum ExasolScalarFunctionCast implements FunctionName { | ||
CAST | ||
} | ||
} |
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
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
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
27 changes: 27 additions & 0 deletions
27
src/test/java/com/exasol/sql/expression/function/exasol/CastExasolFunctionTest.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,27 @@ | ||
package com.exasol.sql.expression.function.exasol; | ||
|
||
import static com.exasol.hamcrest.SqlFragmentRenderResultMatcher.rendersTo; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import com.exasol.datatype.type.Varchar; | ||
import com.exasol.sql.StatementFactory; | ||
import com.exasol.sql.dql.select.Select; | ||
import com.exasol.sql.expression.NullLiteral; | ||
|
||
class CastExasolFunctionTest { | ||
@Test | ||
void testRendering() { | ||
final Select select = StatementFactory.getInstance().select() | ||
.function(CastExasolFunction.of(NullLiteral.nullLiteral(), new Varchar(254))); | ||
assertThat(select, rendersTo("SELECT CAST(NULL AS VARCHAR(254))")); | ||
} | ||
|
||
@Test | ||
void testRenderingWithName() { | ||
final Select select = StatementFactory.getInstance().select() | ||
.function(CastExasolFunction.of(NullLiteral.nullLiteral(), new Varchar(254)), "TEST"); | ||
assertThat(select, rendersTo("SELECT CAST(NULL AS VARCHAR(254)) TEST")); | ||
} | ||
} |
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