Skip to content

Commit

Permalink
Merge branch 'master' into refactoring/69_update_documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
AnastasiiaSergienko committed May 14, 2020
2 parents 646da6b + e1cf36f commit 15e9c55
Show file tree
Hide file tree
Showing 15 changed files with 130 additions and 104 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/exasol/sql/DerivedColumn.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public ValueExpression getValueExpression() {
* @return derived column name as a String
*/
public String getDerivedColumnName() {
return this.derivedColumnName;
return this.derivedColumnName.trim();
}

/**
Expand All @@ -80,4 +80,4 @@ public void accept(final InsertVisitor visitor) {
public void accept(final MergeVisitor visitor) {
visitor.visit(this);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.exasol.util.TreeNode;

/**
* Abstract base class for all types of BooleanExpressions
* Abstract base class for all types of BooleanExpressions.
*/
public abstract class AbstractBooleanExpression extends AbstractBottomUpTreeNode implements BooleanExpression {
protected AbstractBooleanExpression() {
Expand All @@ -29,18 +29,21 @@ public void accept(final BooleanExpressionVisitor visitor) {
}

/**
* Sub-classes must override this method so that the visitor knows the type of
* the visited class at compile time.
* Sub-classes must override this method so that the visitor knows the type of the visited class at compile time.
*
* @param visitor visitor to accept
*/
public abstract void acceptConcrete(final BooleanExpressionVisitor visitor);

/**
* Sub-classes must override this method so that the visitor knows the type of
* the visited class at compile time.
* Sub-classes must override this method so that the visitor knows the type of the visited class at compile time.
*
* @param visitor visitor to accept
*/
public abstract void dismissConcrete(final BooleanExpressionVisitor visitor);

@Override
public void accept(final ValueExpressionVisitor visitor) {
visitor.visit(this);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.exasol.sql.expression;

import com.exasol.util.TreeNode;

/**
* Common interface for all types of boolean expressions
*/
public interface BooleanExpression extends TreeNode {
public interface BooleanExpression extends ValueExpression {
/**
* Accept a visitor
*
Expand Down
10 changes: 0 additions & 10 deletions src/main/java/com/exasol/sql/expression/ExpressionTerm.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,6 @@ public static Function function(final FunctionName functionName, final ValueExpr
return ExasolFunction.of(functionName, valueExpressions);
}

/**
* Create a key word.
*
* @param value key word value
* @return key word
*/
public static KeyWord keyWord(final String value) {
return KeyWord.of(value);
}

/**
* Create a NULL literal.
*
Expand Down
32 changes: 0 additions & 32 deletions src/main/java/com/exasol/sql/expression/KeyWord.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public interface ValueExpressionVisitor {

public void visit(BinaryArithmeticExpression expression);

public void visit(KeyWord keyWord);

public void visit(NullLiteral nullLiteral);

public void visit(BooleanExpression booleanExpression);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.exasol.sql.expression.function.exasol;

import com.exasol.sql.expression.function.FunctionName;

/**
* This class is a list of Aggregate Functions that the Exasol database supports.
*
* <p>
* Currently unsupported functions: GROUPING, PERCENTILE_CONT, PERCENTILE_DISC, OVER clause for all aggregate functions
* and keywords. See {@link <a href="https://github.com/exasol/sql-statement-builder/issues/72"> github issue # 72</a>}
* </p>
*/
public enum ExasolAggregateFunction implements FunctionName {
APPROXIMATE_COUNT_DISTINCT, AVG, CORR, COUNT, COVAR_POP, COVAR_SAMP, FIRST_VALUE, GROUP_CONCAT, LAST_VALUE, MAX,
MEDIAN, MIN, REGR_SLOPE, REGR_INTERCEPT, REGR_COUNT, REGR_R2, REGR_AVGX, REGR_AVGY, REGR_SXX, REGR_SXY, REGR_SYY,
STDDEV, STDDEV_POP, STDDEV_SAMP, SUM, VAR_POP, VAR_SAMP, VARIANCE;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.exasol.sql.expression.function.exasol;

import com.exasol.sql.expression.function.FunctionName;

/**
* This class is a list of Analytic Functions that the Exasol database supports.
* <p>
* This class covers functions that are not in the {@link ExasolAggregateFunction} list.
* </p>
* <p>
* Currently unsupported functions: CUME_DIST, DENSE_RANK, LAG, LEAD, NTH_VALUE, NTILE, NAMED WINDOW CLAUSE,
* PERCENT_RANK, PERCENTILE_CONT, PERCENTILE_DISC, RANK, RATIO_TO_REPORT, ROW_NUMBER, OVER clause for all analytic
* functions, functions' prefixes that goes after parenthesis.
* </p>
*/
public enum ExasolAnalyticFunctions implements FunctionName {
ANY, EVERY, LISTAGG
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.exasol.sql.expression.function.exasol;

import static com.exasol.sql.expression.function.exasol.ExasolScalarFunction.*;

import java.util.*;

import com.exasol.sql.expression.ValueExpression;
Expand All @@ -14,8 +12,8 @@
* This class represents a function in the Exasol database.
*/
public class ExasolFunction extends AbstractTreeNode implements Function {
private static final List<FunctionName> functionsWithoutParenthesis = Arrays.asList(SYSDATE, CURRENT_SCHEMA,
CURRENT_SESSION, CURRENT_STATEMENT, CURRENT_USER, ROWNUM, ROWID, SCOPE_USER, USER);
private static final List<String> functionsWithoutParenthesis = Arrays.asList("SYSDATE", "CURRENT_SCHEMA",
"CURRENT_SESSION", "CURRENT_STATEMENT", "CURRENT_USER", "ROWNUM", "ROWID", "SCOPE_USER", "USER");
private final FunctionName functionName;
private final List<ValueExpression> valueExpressions;

Expand Down Expand Up @@ -56,7 +54,7 @@ public String getFunctionName() {

@Override
public boolean hasParenthesis() {
return !functionsWithoutParenthesis.contains(ExasolScalarFunction.valueOf(this.functionName.name()));
return !functionsWithoutParenthesis.contains(this.functionName.name());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,24 @@
import com.exasol.sql.expression.function.FunctionName;

/**
* This class is a list of Scalar Function that Exasol database supports.
* This class is a list of Scalar Functions that the Exasol database supports.
*
* Currently unsupported functions: CASE, SPACE, Functions for Hierarchical Queries.
* Currently unsupported functions: POSITION, DATE_TRUNC, EXTRACT, CAST, CONVERT, CASE, SPACE, Functions for
* Hierarchical Queries. Keywords inside function's body are also not supported. See
* {@link <a href="https://github.com/exasol/sql-statement-builder/issues/68"> github issue # 68</a>}
*/
public enum ExasolScalarFunction implements FunctionName {
// Numeric Functions
ABS, ACOS, ASIN, ATAN, ATAN2, CEIL, COS, COSH, COT, DEGREES, DIV, EXP, FLOOR, LN, LOG, LOG10, LOG2, MOD, PI, POWER,
RADIANS, RANDOM, ROUND, SIGN, SIN, SINH, SQRT, TAN, TANH, TRUNC,
// String Functions
ASCII, BIT_LENGTH, CHARACTER_LENGTH, CHAR, COLOGNE_PHONETIC, CONCAT, DUMP, EDIT_DISTANCE, INITCAP, INSERT, INSTR,
LCASE, LEFT, LENGTH, LOCATE, LOWER, LPAD, LTRIM, MID, OCTET_LENGTH, POSITION, REGEXP_INSTR, REGEXP_REPLACE,
REGEXP_SUBSTR, REPEAT, REPLACE, REVERSE, RIGHT, RPAD, RTRIM, SOUNDEX, SUBSTR, TRANSLATE, TRIM, UCASE, UNICODE,
UNICODECHR, UPPER,
// Data/Time Functions
LCASE, LEFT, LENGTH, LOCATE, LOWER, LPAD, LTRIM, MID, OCTET_LENGTH, REGEXP_INSTR, REGEXP_REPLACE, REGEXP_SUBSTR,
REPEAT, REPLACE, REVERSE, RIGHT, RPAD, RTRIM, SOUNDEX, SUBSTR, TRANSLATE, TRIM, UCASE, UNICODE, UNICODECHR, UPPER,
// Date/Time Functions
ADD_DAYS, ADD_HOURS, ADD_MINUTES, ADD_MONTHS, ADD_SECONDS, ADD_WEEKS, ADD_YEARS, CONVERT_TZ, CURRENT_DATE,
CURRENT_TIMESTAMP, DATE_TRUNC, DAY, DAYS_BETWEEN, DBTIMEZONE, EXTRACT, FROM_POSIX_TIME, HOUR, HOURS_BETWEEN,
LOCALTIMESTAMP, MINUTE, MINUTES_BETWEEN, NOW, NUMTODSINTERVAL, NUMTOYMINTERVAL, POSIX_TIME, SECOND, SECONDS_BETWEEN,
CURRENT_TIMESTAMP, DAY, DAYS_BETWEEN, DBTIMEZONE, FROM_POSIX_TIME, HOUR, HOURS_BETWEEN, LOCALTIMESTAMP, MINUTE,
MINUTES_BETWEEN, MONTH, MONTHS_BETWEEN, NOW, NUMTODSINTERVAL, NUMTOYMINTERVAL, POSIX_TIME, SECOND, SECONDS_BETWEEN,
SESSIONTIMEZONE, SYSDATE, SYSTIMESTAMP, WEEK, YEAR, YEARS_BETWEEN,
// Geospatial Functions
ST_AREA, ST_BOUNDARY, ST_BUFFER, ST_CENTROID, ST_CONTAINS, ST_CONVEXHULL, ST_CROSSES, ST_DIFFERENCE, ST_DIMENSION,
Expand All @@ -30,8 +31,8 @@ public enum ExasolScalarFunction implements FunctionName {
// Bitwise Function
BIT_AND, BIT_CHECK, BIT_LROTATE, BIT_LSHIFT, BIT_NOT, BIT_OR, BIT_RROTATE, BIT_RSHIFT, BIT_SET, BIT_TO_NUM, BIT_XOR,
// Conversion Functions
CAST, CONVERT, IS_NUMBER, IS_DATE, IS_TIMESTAMP, IS_BOOLEAN, IS_DSINTERVAL, IS_YMINTERVAL, TO_CHAR, TO_DATE,
TO_DSINTERVAL, TO_NUMBER, TO_TIMESTAMP, TO_YMINTERVAL,
IS_NUMBER, IS_DATE, IS_TIMESTAMP, IS_BOOLEAN, IS_DSINTERVAL, IS_YMINTERVAL, TO_CHAR, TO_DATE, TO_DSINTERVAL,
TO_NUMBER, TO_TIMESTAMP, TO_YMINTERVAL,
// Other Scalar Functions
COALESCE, CURRENT_SCHEMA, CURRENT_SESSION, CURRENT_STATEMENT, CURRENT_USER, DECODE, GREATEST, HASH_MD5, HASH_SHA,
HASH_SHA256, HASH_SHA512, HASH_TIGER, IPROC, LEAST, NULLIF, NULLIFZERO, NPROC, NVL, NVL2, ROWNUM, ROWID, SCOPE_USER,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.exasol.sql.expression.*;
import com.exasol.sql.rendering.StringRendererConfig;
import com.exasol.util.QuotesApplier;
import com.exasol.util.TreeNode;

/**
* Common base class for expression renderers.
Expand Down Expand Up @@ -62,8 +61,7 @@ protected void appendAutoQuoted(final String identifier) {
}

protected void appendCommaWhenNeeded(final ValueExpression valueExpression) {
if (this.lastVisited != null && !(this.lastVisited instanceof KeyWord)
&& !(valueExpression.getParent() instanceof BinaryArithmeticExpression)) {
if (this.lastVisited != null && !(valueExpression.getParent() instanceof BinaryArithmeticExpression)) {
if (this.lastVisited.isSibling(valueExpression) || (valueExpression.getParent() != this.lastVisited
&& this.lastVisited.getClass().equals(valueExpression.getClass()))) {
append(", ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,17 @@ protected void appendOperand(final ValueExpression operand) {
this.builder.append(expressionRenderer.render());
}

@Override
public void visit(final KeyWord keyWord) {
append(" ");
appendKeyword(keyWord.toString());
append(" ");
setLastVisited(keyWord);
}

@Override
public void visit(final NullLiteral nullLiteral) {
appendCommaWhenNeeded(nullLiteral);
appendKeyword("NULL");
setLastVisited(nullLiteral);
}

@Override
public void visit(final BooleanExpression booleanExpression) {
final BooleanExpressionRenderer expressionRenderer = new BooleanExpressionRenderer(this.config);
booleanExpression.accept(expressionRenderer);
append(expressionRenderer.render());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.exasol.sql.expression.function.exasol;

import static com.exasol.hamcrest.SqlFragmentRenderResultMatcher.rendersTo;
import static com.exasol.sql.expression.ExpressionTerm.column;
import static com.exasol.sql.expression.ExpressionTerm.integerLiteral;
import static org.hamcrest.MatcherAssert.assertThat;

import org.junit.jupiter.api.Test;

import com.exasol.sql.StatementFactory;
import com.exasol.sql.dql.select.Select;
import com.exasol.sql.expression.BooleanTerm;

public class ExasolAggregateFunctionTest {
@Test
void testAggregateFunctionCoalesce() {
final Select select = StatementFactory.getInstance().select() //
.function(ExasolAggregateFunction.APPROXIMATE_COUNT_DISTINCT, "COUNT_APPR", column("customer_id"));
select.from().table("orders");
select.where(BooleanTerm.gt(column("price"), integerLiteral(1000)));
assertThat(select,
rendersTo("SELECT APPROXIMATE_COUNT_DISTINCT(customer_id) COUNT_APPR FROM orders WHERE price > 1000"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.exasol.sql.expression.function.exasol;

import static com.exasol.hamcrest.SqlFragmentRenderResultMatcher.rendersTo;
import static com.exasol.sql.expression.ExpressionTerm.column;
import static com.exasol.sql.expression.ExpressionTerm.integerLiteral;
import static org.hamcrest.MatcherAssert.assertThat;

import org.junit.jupiter.api.Test;

import com.exasol.sql.StatementFactory;
import com.exasol.sql.dql.select.Select;
import com.exasol.sql.expression.BooleanTerm;

public class ExasolAnalyticFunctionTest {
@Test
void testAggregateFunctionCoalesce() {
final Select select = StatementFactory.getInstance().select() //
.field("department") //
.function(ExasolAnalyticFunctions.ANY, " ANY_ ", BooleanTerm.lt(column("age"), integerLiteral(30)));
select.from().table("employee_table");
select.groupBy(column("department"));
assertThat(select,
rendersTo("SELECT department, ANY((age < 30)) ANY_ FROM employee_table GROUP BY department"));
}
}
Loading

0 comments on commit 15e9c55

Please sign in to comment.