-
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.
- Loading branch information
1 parent
90cdea0
commit 54aea29
Showing
8 changed files
with
145 additions
and
3 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-XX-XX | ||
|
||
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
60 changes: 60 additions & 0 deletions
60
src/main/java/com/exasol/sql/expression/function/exasol/ExasolCastFunction.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,60 @@ | ||
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.AbstractFunction; | ||
|
||
/** | ||
* This class represents the Exasol CAST function. | ||
*/ | ||
public class ExasolCastFunction extends AbstractFunction { | ||
private static final String CAST_FUNCTION_NAME = "CAST"; | ||
private final DataType type; | ||
|
||
private ExasolCastFunction(final ValueExpression value, final DataType type) { | ||
super(CAST_FUNCTION_NAME, List.of(value)); | ||
this.type = type; | ||
} | ||
|
||
/** | ||
* Create a new {@link ExasolCastFunction} instance. | ||
* | ||
* @param valueExpression value to cast | ||
* @param type type to cast the value to | ||
* @return new {@link ExasolCastFunction} | ||
*/ | ||
public static ExasolCastFunction of(final ValueExpression valueExpression, final DataType type) { | ||
return new ExasolCastFunction(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); | ||
} | ||
} |
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/ExasolCastFunctionTest.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 ExasolCastFunctionTest { | ||
|
||
@Test | ||
void testRendering() { | ||
final Select select = StatementFactory.getInstance().select().cast(NullLiteral.nullLiteral(), new Varchar(254)); | ||
assertThat(select, rendersTo("SELECT CAST(NULL AS VARCHAR(254))")); | ||
} | ||
|
||
@Test | ||
void testRenderingWithName() { | ||
final Select select = StatementFactory.getInstance().select().cast(NullLiteral.nullLiteral(), new Varchar(254), | ||
"TEST"); | ||
assertThat(select, rendersTo("SELECT CAST(NULL AS VARCHAR(254)) TEST")); | ||
} | ||
} |