Skip to content

Commit

Permalink
[Spotless] Applying Google Code Format for core #5 (opensearch-projec…
Browse files Browse the repository at this point in the history
…t#1951)

* Integ/sl google java format5 (#332)

Adding core final GJF fix.

Signed-off-by: Mitchell Gale <[email protected]>

* remove repeated unused checkstyle.

Signed-off-by: Mitchell Gale <[email protected]>

* spotless apply

Signed-off-by: Mitchell Gale <[email protected]>

* replaced nbsp with pre tag.

Signed-off-by: Mitchell Gale <[email protected]>

* Add test fixtures to failure ignore in core build.gradle.

Signed-off-by: Mitchell Gale <[email protected]>

---------

Signed-off-by: Mitchell Gale <[email protected]>
  • Loading branch information
MitchellGale committed Aug 18, 2023
1 parent d9a78df commit 70f45ee
Show file tree
Hide file tree
Showing 133 changed files with 5,571 additions and 5,608 deletions.
38 changes: 29 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

buildscript {
ext {
opensearch_version = System.getProperty("opensearch.version", "2.10.0-SNAPSHOT")
opensearch_version = System.getProperty("opensearch.version", "3.0.0-SNAPSHOT")
isSnapshot = "true" == System.getProperty("build.snapshot", "true")
buildVersionQualifier = System.getProperty("build.version_qualifier", "")
version_tokens = opensearch_version.tokenize('-')
Expand Down Expand Up @@ -84,18 +84,32 @@ repositories {
spotless {
java {
target fileTree('.') {
include '**/*.java'
include 'core/src/main/java/org/opensearch/sql/DataSourceSchemaName.java',
'core/src/test/java/org/opensearch/sql/data/**/*.java',
'core/src/test/java/org/opensearch/sql/config/**/*.java',
'core/src/test/java/org/opensearch/sql/analysis/**/*.java',
'core/src/main/java/org/opensearch/sql/planner/**/*.java',
'core/src/main/java/org/opensearch/sql/storage/**/*.java',
'core/src/main/java/org/opensearch/sql/utils/**/*.java',
'core/src/main/java/org/opensearch/sql/monitor/**/*.java',
'core/src/main/java/org/opensearch/sql/expression/**/*.java',
'core/src/main/java/org/opensearch/sql/executor/**/*.java',
'core/src/main/java/org/opensearch/sql/exception/**/*.java',
'core/src/main/java/org/opensearch/sql/analysis/**/*.java',
'core/src/test/java/org/opensearch/sql/data/**/*.java',
'core/src/test/java/org/opensearch/sql/datasource/**/*.java',
'core/src/test/java/org/opensearch/sql/ast/**/*.java'
exclude '**/build/**', '**/build-*/**'
}
// importOrder()
importOrder()
// licenseHeader("/*\n" +
// " * Copyright OpenSearch Contributors\n" +
// " * SPDX-License-Identifier: Apache-2.0\n" +
// " */\n\n")
// removeUnusedImports()
// trimTrailingWhitespace()
removeUnusedImports()
trimTrailingWhitespace()
endWithNewline()
// googleJavaFormat('1.17.0').reflowLongStrings().groupArtifact('com.google.googlejavaformat:google-java-format')
googleJavaFormat('1.17.0').reflowLongStrings().groupArtifact('com.google.googlejavaformat:google-java-format')
}
}

Expand All @@ -113,9 +127,8 @@ allprojects {
sourceCompatibility = targetCompatibility = "11"
}
configurations.all {
resolutionStrategy.force "com.squareup.okio:okio:3.5.0"
resolutionStrategy.force "org.jetbrains.kotlin:kotlin-stdlib:1.9.0"
resolutionStrategy.force "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.9.0"
resolutionStrategy.force "org.jetbrains.kotlin:kotlin-stdlib:1.6.0"
resolutionStrategy.force "org.jetbrains.kotlin:kotlin-stdlib-common:1.6.0"
}
}

Expand Down Expand Up @@ -217,5 +230,12 @@ task updateVersion {
println "Setting version to ${newVersion}."
// String tokenization to support -SNAPSHOT
ant.replaceregexp(file:'build.gradle', match: '"opensearch.version", "\\d.*"', replace: '"opensearch.version", "' + newVersion.tokenize('-')[0] + '-SNAPSHOT"', flags:'g', byline:true)
ant.replaceregexp(match:'"version": "\\d+.\\d+.\\d+.\\d+', replace:'"version": ' + '"' + newVersion.tokenize('-')[0] + '.0', flags:'g', byline:true) {
fileset(dir: projectDir) {
include(name: "workbench/package.json")
include(name: "workbench/opensearch_dashboards.json")
}
}
ant.replaceregexp(file:'workbench/opensearch_dashboards.json', match:'"opensearchDashboardsVersion": "\\d+.\\d+.\\d+', replace:'"opensearchDashboardsVersion": ' + '"' + newVersion.tokenize('-')[0], flags:'g', byline:true)
}
}
16 changes: 16 additions & 0 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,29 @@ plugins {
id 'java-library'
id "io.freefair.lombok"
id 'jacoco'
id 'info.solidsoft.pitest' version '1.9.0'
id 'java-test-fixtures'
}

repositories {
mavenCentral()
}

// Being ignored as a temporary measure before being removed in favour of
// spotless https://github.com/opensearch-project/sql/issues/1101
checkstyleTest.ignoreFailures = true
checkstyleMain.ignoreFailures = true
checkstyleTestFixtures.ignoreFailures = true

pitest {
targetClasses = ['org.opensearch.sql.*']
pitestVersion = '1.9.0'
threads = 4
outputFormats = ['HTML', 'XML']
timestampedReports = false
junit5PluginVersion = '1.0.0'
}

dependencies {
api group: 'com.google.guava', name: 'guava', version: '32.0.1-jre'
api group: 'org.apache.commons', name: 'commons-lang3', version: '3.12.0'
Expand Down
14 changes: 11 additions & 3 deletions core/src/main/java/org/opensearch/sql/ast/dsl/AstDSL.java
Original file line number Diff line number Diff line change
Expand Up @@ -249,23 +249,31 @@ public static Function function(String funcName, UnresolvedExpression... funcArg
}

/**
*
*
* <pre>
* CASE
* WHEN search_condition THEN result_expr
* [WHEN search_condition THEN result_expr] ...
* [ELSE result_expr]
* WHEN search_condition THEN result_expr<br>
* [WHEN search_condition THEN result_expr] ...
* [ELSE result_expr]
* END
* </pre>
*/
public UnresolvedExpression caseWhen(UnresolvedExpression elseClause,
When... whenClauses) {
return caseWhen(null, elseClause, whenClauses);
}

/**
*
*
* <pre>
* CASE case_value_expr
* WHEN compare_expr THEN result_expr
* [WHEN compare_expr THEN result_expr] ...
* [ELSE result_expr]
* END
* </pre>
*/
public UnresolvedExpression caseWhen(UnresolvedExpression caseValueExpr,
UnresolvedExpression elseClause,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/


package org.opensearch.sql.ast.expression;

import static java.util.Objects.requireNonNull;
Expand All @@ -29,9 +28,7 @@ public QualifiedName(String name) {
this.parts = Collections.singletonList(name);
}

/**
* QualifiedName Constructor.
*/
/** QualifiedName Constructor. */
public QualifiedName(Iterable<String> parts) {
List<String> partsList = StreamSupport.stream(parts.spliterator(), false).collect(toList());
if (partsList.isEmpty()) {
Expand All @@ -40,9 +37,7 @@ public QualifiedName(Iterable<String> parts) {
this.parts = partsList;
}

/**
* Construct {@link QualifiedName} from list of string.
*/
/** Construct {@link QualifiedName} from list of string. */
public static QualifiedName of(String first, String... rest) {
requireNonNull(first);
ArrayList<String> parts = new ArrayList<>();
Expand All @@ -55,9 +50,7 @@ public static QualifiedName of(Iterable<String> parts) {
return new QualifiedName(parts);
}

/**
* Get Prefix of {@link QualifiedName}.
*/
/** Get Prefix of {@link QualifiedName}. */
public Optional<QualifiedName> getPrefix() {
if (parts.size() == 1) {
return Optional.empty();
Expand All @@ -71,7 +64,8 @@ public String getSuffix() {

/**
* Get first part of the qualified name.
* @return first part
*
* @return first part
*/
public Optional<String> first() {
if (parts.size() == 1) {
Expand All @@ -81,17 +75,18 @@ public Optional<String> first() {
}

/**
* Get rest parts of the qualified name. Assume that there must be remaining parts
* so caller is responsible for the check (first() or size() must be called first).
* <pre>
* Get rest parts of the qualified name. Assume that there must be remaining parts so caller is
* responsible for the check (first() or size() must be called first).
* For example:
* {@code
* QualifiedName name = ...
* Optional<String> first = name.first();
* if (first.isPresent()) {
* name.rest() ...
* }
* QualifiedName name = ...
* Optional<String> first = name.first();
* if (first.isPresent()) {
* name.rest() ...
* }
* }
* @return rest part(s)
* @return rest part(s)
*/
public QualifiedName rest() {
return QualifiedName.of(parts.subList(1, parts.size()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,18 @@
* SPDX-License-Identifier: Apache-2.0
*/


package org.opensearch.sql.data.model;

import org.opensearch.sql.exception.ExpressionEvaluationException;

/**
* Abstract ExprValue.
*/
/** Abstract ExprValue. */
public abstract class AbstractExprValue implements ExprValue {
/**
* The customize compareTo logic.
*/
/** The customize compareTo logic. */
@Override
public int compareTo(ExprValue other) {
if (this.isNull() || this.isMissing() || other.isNull() || other.isMissing()) {
throw new IllegalStateException(
"[BUG] Unreachable, Comparing with NULL or MISSING is undefined");
"[BUG] Unreachable, Comparing with NULL or MISSING is undefined");
}
if ((this.isNumber() && other.isNumber())
|| (this.isDateTime() && other.isDateTime())
Expand All @@ -34,13 +29,36 @@ public int compareTo(ExprValue other) {
}

/**
* The customize equals logic.
* The customize equals logic.<br>
* The table below list the NULL and MISSING handling logic.
* A B A == B
* NULL NULL TRUE
* NULL MISSING FALSE
* MISSING NULL FALSE
* MISSING MISSING TRUE
*
* <table>
* <tr>
* <th>A</th>
* <th>B</th>
* <th>A == B</th>
* </tr>
* <tr>
* <td>NULL</td>
* <td>NULL</td>
* <td>TRUE</td>
* </tr>
* <tr>
* <td>NULL</td>
* <td>MISSING</td>
* <td>FALSE</td>
* </tr>
* <tr>
* <td>MISSING</td>
* <td>NULL</td>
* <td>FALSE</td>
* </tr>
* <tr>
* <td>MISSING</td>
* <td>MISSING</td>
* <td>TRUE</td>
* </tr>
* </table>
*/
@Override
public boolean equals(Object o) {
Expand All @@ -59,13 +77,9 @@ public boolean equals(Object o) {
}
}

/**
* The expression value compare.
*/
/** The expression value compare. */
public abstract int compare(ExprValue other);

/**
* The expression value equal.
*/
/** The expression value equal. */
public abstract boolean equal(ExprValue other);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/


package org.opensearch.sql.data.model;

import static java.time.format.DateTimeFormatter.ISO_LOCAL_TIME;
Expand All @@ -23,23 +22,20 @@
import org.opensearch.sql.exception.SemanticCheckException;
import org.opensearch.sql.expression.function.FunctionProperties;

/**
* Expression Time Value.
*/
/** Expression Time Value. */
@RequiredArgsConstructor
public class ExprTimeValue extends AbstractExprValue {

private final LocalTime time;

/**
* Constructor of ExprTimeValue.
*/
/** Constructor of ExprTimeValue. */
public ExprTimeValue(String time) {
try {
this.time = LocalTime.parse(time, DATE_TIME_FORMATTER_VARIABLE_NANOS_OPTIONAL);
} catch (DateTimeParseException e) {
throw new SemanticCheckException(String.format("time:%s in unsupported format, please use "
+ "HH:mm:ss[.SSSSSSSSS]", time));
throw new SemanticCheckException(
String.format(
"time:%s in unsupported format, please use 'HH:mm:ss[.SSSSSSSSS]'", time));
}
}

Expand Down Expand Up @@ -67,8 +63,7 @@ public LocalDateTime datetimeValue(FunctionProperties functionProperties) {
}

public Instant timestampValue(FunctionProperties functionProperties) {
return ZonedDateTime.of(dateValue(functionProperties), timeValue(), UTC_ZONE_ID)
.toInstant();
return ZonedDateTime.of(dateValue(functionProperties), timeValue(), UTC_ZONE_ID).toInstant();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@

/**
* The definition of widening type rule for expression value.
* ExprType Widens to data types
* INTEGER LONG, FLOAT, DOUBLE
* LONG FLOAT, DOUBLE
* FLOAT DOUBLE
* DOUBLE DOUBLE
* STRING STRING
* BOOLEAN BOOLEAN
* ARRAY ARRAY
* STRUCT STRUCT
*
* <table border="3">
* <tr><th>ExprType</th><th>Widens to data types</th></tr>
* <tr><td>INTEGER</td><td>LONG, FLOAT, DOUBLE</td></tr>
* <tr><td>LONG</td><td>FLOAT, DOUBLE</td></tr>
* <tr><td>FLOAT</td><td>DOUBLE</td></tr>
* <tr><td>DOUBLE</td><td>DOUBLE</td></tr>
* <tr><td>STRING</td><td>STRING</td></tr>
* <tr><td>BOOLEAN</td><td>BOOLEAN</td></tr>
* <tr><td>ARRAY</td><td>ARRAY</td></tr>
* <tr><td>STRUCT</td><td>STRUCT</td></tr>
* </table>
*/
@UtilityClass
public class WideningTypeRule {
Expand Down Expand Up @@ -53,9 +56,8 @@ private static int distance(ExprType type1, ExprType type2, int distance) {
}

/**
* The max type among two types. The max is defined as follow
* if type1 could widen to type2, then max is type2, vice versa
* if type1 could't widen to type2 and type2 could't widen to type1,
* The max type among two types. The max is defined as follow if type1 could widen to type2, then
* max is type2, vice versa if type1 couldn't widen to type2 and type2 could't widen to type1,
* then throw {@link ExpressionEvaluationException}.
*
* @param type1 type1
Expand Down
Loading

0 comments on commit 70f45ee

Please sign in to comment.