Skip to content

Commit

Permalink
* #97: Refactored functions tests.
Browse files Browse the repository at this point in the history
* #93: Replaced <code> by {@code}.
  • Loading branch information
AnastasiiaSergienko committed Mar 17, 2021
1 parent 4ad240b commit 6c907c0
Show file tree
Hide file tree
Showing 25 changed files with 351 additions and 405 deletions.
1 change: 1 addition & 0 deletions doc/changes/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Changes

* [4.4.1](changes_4.4.1.md)
* [4.4.0](changes_4.4.0.md)
* [4.3.0](changes_4.3.0.md)
* [4.2.0](changes_4.2.0.md)
Expand Down
11 changes: 11 additions & 0 deletions doc/changes/changes_4.4.1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# SQL Statement Builder 4.4.1, released 2021-??-??

Code Name:

## Refactoring

* #97: Refactored functions tests.
* #93: Replaced <code> by {@code}.

## Dependency Updates

2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.exasol</groupId>
<artifactId>sql-statement-builder</artifactId>
<version>4.4.0</version>
<version>4.4.1</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
38 changes: 18 additions & 20 deletions src/main/java/com/exasol/datatype/value/IntervalDayToSecond.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
import java.util.regex.Pattern;

/**
* This class implements the Exasol-proprietary data type value <code>INTERVAL DAY(x) TO SECONDS(y)
* </code>. It supports
* This class implements the Exasol-proprietary data type value {@code INTERVAL DAY(x) TO SECONDS(y)}. It supports
* conversions to and from strings and from milliseconds.
*
* <p>
Expand All @@ -21,12 +20,11 @@
* <li>milliseconds (or fraction of seconds)</li>
* </ul>
* <p>
* Since milliseconds are the highest resolution, each interval can also be expressed as a total
* number of milliseconds.
* This is also the recommended way to represent the interval values in other systems which do
* not natively support this data type.
* Since milliseconds are the highest resolution, each interval can also be expressed as a total number of milliseconds.
* This is also the recommended way to represent the interval values in other systems which do not natively support this
* data type.
*/
@java.lang.SuppressWarnings("squid:S4784") //regular expression is safe here
@java.lang.SuppressWarnings("squid:S4784") // regular expression is safe here
public final class IntervalDayToSecond extends AbstractInterval {
private static final int SIGN_MATCHING_GROUP = 1;
private static final int DAYS_MATCHING_GROUP = 2;
Expand All @@ -35,10 +33,10 @@ public final class IntervalDayToSecond extends AbstractInterval {
private static final int SECONDS_MATCHING_GROUP = 5;
private static final int MILLIS_MATCHING_GROUP = 6;
private static final Pattern INTERVAL_PATTERN = Pattern.compile("([-+])?(?:(\\d{1,9})\\s+)?" // days
+ "(\\d{1,2})" // hours
+ ":(\\d{1,2})" // minutes
+ "(?::(\\d{1,2})" // seconds
+ "(?:\\.(\\d{1,3}))?)?" // milliseconds
+ "(\\d{1,2})" // hours
+ ":(\\d{1,2})" // minutes
+ "(?::(\\d{1,2})" // seconds
+ "(?:\\.(\\d{1,3}))?)?" // milliseconds
);

private IntervalDayToSecond(final long value) {
Expand All @@ -52,7 +50,7 @@ private IntervalDayToSecond(final long absoluteValue, final boolean positive) {
@Override
public String toString() {
return String.format("%s%d %d:%02d:%02d.%03d", getSign(), getDays(), getHours(), getMinutes(), getSeconds(),
getMillis());
getMillis());
}

private long getDays() {
Expand Down Expand Up @@ -103,7 +101,7 @@ public static IntervalDayToSecond ofMillis(final long value) {
* The accepted format is:
* </p>
* <p>
* <code>[dddddddd ]<strong>hh:mm</strong>[:ss[.SSS]]</code>
* {@code [dddddddd ]<strong>hh:mm</strong>[:ss[.SSS]]}
* <p>
* Where
* </p>
Expand All @@ -130,18 +128,18 @@ public static IntervalDayToSecond parse(final String text) {
return createIntervalFromParsingResults(matcher);
} else {
throw new IllegalArgumentException(
"Text \"" + text + "\" cannot be parsed to an INTERVAL. Must match \"" + INTERVAL_PATTERN + "\"");
"Text \"" + text + "\" cannot be parsed to an INTERVAL. Must match \"" + INTERVAL_PATTERN + "\"");
}
}

private static IntervalDayToSecond createIntervalFromParsingResults(final Matcher matcher) {
final long parsedValue = MILLIS_PER_DAY * parseMatchingGroupToLong(matcher, DAYS_MATCHING_GROUP) //
+ MILLIS_PER_HOUR * parseMatchingGroupToLong(matcher, HOURS_MATCHING_GROUP) //
+ MILLIS_PER_MINUTE * parseMatchingGroupToLong(matcher, MINUTES_MATCHING_GROUP)
//
+ MILLIS_PER_SECOND * parseMatchingGroupToLong(matcher, SECONDS_MATCHING_GROUP)
//
+ parseMatchingGroupToLong(matcher, MILLIS_MATCHING_GROUP);
+ MILLIS_PER_HOUR * parseMatchingGroupToLong(matcher, HOURS_MATCHING_GROUP) //
+ MILLIS_PER_MINUTE * parseMatchingGroupToLong(matcher, MINUTES_MATCHING_GROUP)
//
+ MILLIS_PER_SECOND * parseMatchingGroupToLong(matcher, SECONDS_MATCHING_GROUP)
//
+ parseMatchingGroupToLong(matcher, MILLIS_MATCHING_GROUP);
final boolean parsedPositive = !"-".equals(matcher.group(SIGN_MATCHING_GROUP));
return new IntervalDayToSecond(parsedValue, parsedPositive);
}
Expand Down
16 changes: 7 additions & 9 deletions src/main/java/com/exasol/datatype/value/IntervalYearToMonth.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
import java.util.regex.Pattern;

/**
* This class implements the Exasol-proprietary data type value <code>INTERVAL YEAR(x) TO MONTH(y)
* </code>. It supports
* This class implements the Exasol-proprietary data type value {@code INTERVAL YEAR(x) TO MONTH(y)}. It supports
* conversions to and from strings and from a number of months.
*
* <p>
Expand All @@ -18,12 +17,11 @@
* <li>months</li>
* </ul>
* <p>
* Since months are the highest resolution, each interval can also be expressed as a total number
* of months. This is
* also the recommended way to represent the interval values in other systems which do not
* natively support this data type.
* Since months are the highest resolution, each interval can also be expressed as a total number of months. This is
* also the recommended way to represent the interval values in other systems which do not natively support this data
* type.
*/
@java.lang.SuppressWarnings("squid:S4784") //regular expression is safe here
@java.lang.SuppressWarnings("squid:S4784") // regular expression is safe here
public final class IntervalYearToMonth extends AbstractInterval {
private static final int SIGN_MATCHING_GROUP = 1;
private static final int YEARS_MATCHING_GROUP = 2;
Expand Down Expand Up @@ -98,12 +96,12 @@ public static IntervalYearToMonth parse(final String text) {
final Matcher matcher = INTERVAL_PATTERN.matcher(text);
if (matcher.matches()) {
final long parsedValue = MONTHS_PER_YEAR * parseMatchingGroupToLong(matcher, YEARS_MATCHING_GROUP) //
+ parseMatchingGroupToLong(matcher, MONTHS_MATCHING_GROUP);
+ parseMatchingGroupToLong(matcher, MONTHS_MATCHING_GROUP);
final boolean parsedPositive = !"-".equals(matcher.group(SIGN_MATCHING_GROUP));
return new IntervalYearToMonth(parsedValue, parsedPositive);
} else {
throw new IllegalArgumentException(
"Text \"" + text + "\" cannot be parsed to an INTERVAL. Must match \"" + INTERVAL_PATTERN + "\"");
"Text \"" + text + "\" cannot be parsed to an INTERVAL. Must match \"" + INTERVAL_PATTERN + "\"");
}
}
}
36 changes: 18 additions & 18 deletions src/main/java/com/exasol/sql/ColumnsDefinition.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static Builder builder() {
/**
* Add a new column to the {@link ColumnsDefinition}
*
* @param name name of the column to be added
* @param name name of the column to be added
* @param dataType data type of the column to be added
*/
public void add(final String name, final DataType dataType) {
Expand Down Expand Up @@ -77,7 +77,7 @@ public static class Builder {
* Add boolean column
*
* @param columnName name of the column to be added
* @return <code>this</code> for fluent programming
* @return {@code this} for fluent programming
*/
public Builder booleanColumn(final String columnName) {
this.columns.add(new Column(null, columnName, new Boolean()));
Expand All @@ -88,8 +88,8 @@ public Builder booleanColumn(final String columnName) {
* Add char column.
*
* @param columnName name of the column to be added
* @param length pre-defined length for stored strings
* @return <code>this</code> for fluent programming
* @param length pre-defined length for stored strings
* @return {@code this} for fluent programming
*/
public Builder charColumn(final String columnName, final int length) {
this.columns.add(new Column(null, columnName, new Char(length)));
Expand All @@ -100,8 +100,8 @@ public Builder charColumn(final String columnName, final int length) {
* Add varchar column.
*
* @param columnName name of the column to be added
* @param length pre-defined length for stored strings
* @return <code>this</code> for fluent programming
* @param length pre-defined length for stored strings
* @return {@code this} for fluent programming
*/
public Builder varcharColumn(final String columnName, final int length) {
this.columns.add(new Column(null, columnName, new Varchar(length)));
Expand All @@ -112,7 +112,7 @@ public Builder varcharColumn(final String columnName, final int length) {
* Add date column.
*
* @param columnName name of the column to be added
* @return <code>this</code> for fluent programming
* @return {@code this} for fluent programming
*/
public Builder dateColumn(final String columnName) {
this.columns.add(new Column(null, columnName, new Date()));
Expand All @@ -123,9 +123,9 @@ public Builder dateColumn(final String columnName) {
* Add decimal column.
*
* @param columnName name of the column to be added
* @param precision precision for numeric value
* @param scale scale for numeric value
* @return <code>this</code> for fluent programming
* @param precision precision for numeric value
* @param scale scale for numeric value
* @return {@code this} for fluent programming
*/
public Builder decimalColumn(final String columnName, final int precision, final int scale) {
this.columns.add(new Column(null, columnName, new Decimal(precision, scale)));
Expand All @@ -136,7 +136,7 @@ public Builder decimalColumn(final String columnName, final int precision, final
* Add double precision column.
*
* @param columnName name of the column to be added
* @return <code>this</code> for fluent programming
* @return {@code this} for fluent programming
*/
public Builder doublePrecisionColumn(final String columnName) {
this.columns.add(new Column(null, columnName, new DoublePrecision()));
Expand All @@ -147,7 +147,7 @@ public Builder doublePrecisionColumn(final String columnName) {
* Add timestamp column.
*
* @param columnName name of the column to be added
* @return <code>this</code> for fluent programming
* @return {@code this} for fluent programming
*/
public Builder timestampColumn(final String columnName) {
this.columns.add(new Column(null, columnName, new Timestamp()));
Expand All @@ -158,7 +158,7 @@ public Builder timestampColumn(final String columnName) {
* Add timestamp with local time zone column.
*
* @param columnName name of the column to be added
* @return <code>this</code> for fluent programming
* @return {@code this} for fluent programming
*/
public Builder timestampWithLocalTimeZoneColumn(final String columnName) {
this.columns.add(new Column(null, columnName, new TimestampWithLocalTimezone()));
Expand All @@ -168,10 +168,10 @@ public Builder timestampWithLocalTimeZoneColumn(final String columnName) {
/**
* Add interval day to second column.
*
* @param columnName name of the column to be added
* @param yearPrecision year precision value
* @param columnName name of the column to be added
* @param yearPrecision year precision value
* @param millisecondPrecision millisecond precision value
* @return <code>this</code> for fluent programming
* @return {@code this} for fluent programming
*/
public Builder intervalDayToSecondColumn(final String columnName, final int yearPrecision,
final int millisecondPrecision) {
Expand All @@ -183,9 +183,9 @@ public Builder intervalDayToSecondColumn(final String columnName, final int year
/**
* Add interval year to month column.
*
* @param columnName name of the column to be added
* @param columnName name of the column to be added
* @param yearPrecision year precision value
* @return <code>this</code> for fluent programming
* @return {@code this} for fluent programming
*/
public Builder intervalYearToMonthColumn(final String columnName, final int yearPrecision) {
this.columns.add(new Column(null, columnName, new IntervalYearToMonth(yearPrecision)));
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/exasol/sql/ValueTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public ValueTable(final Fragment root) {
*
* @param literals literals to be appended
*
* @return <code>this</code> for fluent programming
* @return {@code this} for fluent programming
*/
public ValueTable appendRow(final String... literals) {
this.rows.add(new ValueTableRow(this.root, literals));
Expand All @@ -40,7 +40,7 @@ public ValueTable appendRow(final String... literals) {
*
* @param row row to be appended
*
* @return <code>this</code> for fluent programming
* @return {@code this} for fluent programming
*/
public ValueTable appendRow(final ValueTableRow row) {
this.rows.add(row);
Expand Down Expand Up @@ -179,7 +179,7 @@ public void accept(final ValueTableVisitor visitor) {
/**
* Set alias for the value table.
*
* @param tableNameAlias table name alias
* @param tableNameAlias table name alias
* @param columnNameAliases zero or more column names aliases
*/
public void alias(final String tableNameAlias, final String... columnNameAliases) {
Expand Down
22 changes: 10 additions & 12 deletions src/main/java/com/exasol/sql/ValueTableRow.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.exasol.sql;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.*;

import com.exasol.sql.expression.ValueExpression;
import com.exasol.sql.expression.literal.*;
Expand Down Expand Up @@ -89,7 +87,7 @@ public Builder(final Fragment root) {
* Add one or more string literals to the row.
*
* @param values strings to be added
* @return <code>this</code> for fluent programming
* @return {@code this} for fluent programming
*/
public Builder add(final String... values) {
for (final String value : values) {
Expand All @@ -102,7 +100,7 @@ public Builder add(final String... values) {
* Add one or more char literals to the row.
*
* @param values chars to be added
* @return <code>this</code> for fluent programming
* @return {@code this} for fluent programming
*/
public Builder add(final char... values) {
for (final char value : values) {
Expand All @@ -115,7 +113,7 @@ public Builder add(final char... values) {
* Add one or more integer literals to the row.
*
* @param values integers to be added
* @return <code>this</code> for fluent programming
* @return {@code this} for fluent programming
*/
public Builder add(final int... values) {
for (final int value : values) {
Expand All @@ -128,7 +126,7 @@ public Builder add(final int... values) {
* Add one or more long literals to the row.
*
* @param values longs to be added
* @return <code>this</code> for fluent programming
* @return {@code this} for fluent programming
*/
public Builder add(final long... values) {
for (final long value : values) {
Expand All @@ -141,7 +139,7 @@ public Builder add(final long... values) {
* Add one or more double literals to the row.
*
* @param values doubles to be added
* @return <code>this</code> for fluent programming
* @return {@code this} for fluent programming
*/
public Builder add(final double... values) {
for (final double value : values) {
Expand All @@ -154,7 +152,7 @@ public Builder add(final double... values) {
* Add one or more float literals to the row.
*
* @param values floats to be added
* @return <code>this</code> for fluent programming
* @return {@code this} for fluent programming
*/
public Builder add(final float... values) {
for (final float value : values) {
Expand All @@ -167,7 +165,7 @@ public Builder add(final float... values) {
* Add one or more boolean literals to the row.
*
* @param values booleans to be added
* @return <code>this</code> for fluent programming
* @return {@code this} for fluent programming
*/
public Builder add(final boolean... values) {
for (final boolean value : values) {
Expand All @@ -179,7 +177,7 @@ public Builder add(final boolean... values) {
/**
* Add an {@link UnnamedPlaceholder} to the row.
*
* @return <code>this</code> for fluent programming
* @return {@code this} for fluent programming
*/
public Builder addPlaceholder() {
this.expressions.add(new UnnamedPlaceholder());
Expand All @@ -190,7 +188,7 @@ public Builder addPlaceholder() {
* Add a list of expressions to the {@link ValueTableRow}.
*
* @param expressions expressions to be added
* @return <code>this</code> for fluent programming
* @return {@code this} for fluent programming
*/
public Builder add(final List<ValueExpression> expressions) {
this.expressions.addAll(expressions);
Expand Down
Loading

0 comments on commit 6c907c0

Please sign in to comment.