Skip to content

Commit

Permalink
Code style: Lint
Browse files Browse the repository at this point in the history
Fix various problems (which will be enforced by checks in
the next commit):
 * '//' not followed by space
 * Trailing whitespace
 * Duplicate empty lines in javadoc
  • Loading branch information
julianhyde committed Jul 6, 2023
1 parent 1b11d99 commit 9600147
Show file tree
Hide file tree
Showing 41 changed files with 104 additions and 96 deletions.
10 changes: 5 additions & 5 deletions babel/src/main/codegen/config.fmpp
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ data: {
createStatementParserMethods: [
"SqlCreateTable"
]

statementParserMethods: [
"PostgresqlSqlShow()",
"PostgresqlSqlSetOption()",
Expand All @@ -578,17 +578,17 @@ data: {
]

# Custom identifier token.
#
# PostgreSQL allows letters with diacritical marks and non-Latin letters
# in the beginning of identifier and additionally dollar sign in the rest of identifier.
#
# PostgreSQL allows letters with diacritical marks and non-Latin letters
# in the beginning of identifier and additionally dollar sign in the rest of identifier.
# Letters with diacritical marks and non-Latin letters
# are represented by character codes 128 to 255 (or in octal \200 to \377).
# See https://learn.microsoft.com/en-gb/office/vba/language/reference/user-interface-help/character-set-128255
# See https://github.com/postgres/postgres/blob/master/src/backend/parser/scan.l
#
# MySQL allows digit in the beginning of identifier
customIdentifierToken: "< IDENTIFIER: (<LETTER>|<DIGIT>|[\"\\200\"-\"\\377\"]) (<LETTER>|<DIGIT>|<DOLLAR>|[\"\\200\"-\"\\377\"])* >"

# Binary operators initialization.
# Example: "InfixCast".
extraBinaryExpressions: [
Expand Down
36 changes: 18 additions & 18 deletions babel/src/main/codegen/includes/parserPostgresqlImpls.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ SqlNode PostgresqlSqlOptionValues():
{
e = PostgresqlSqlOptionValue() { s = span(); list = startList(e); }
( <COMMA> e = PostgresqlSqlOptionValue() { list.add(e); } )*
{
return list.size() > 1 ? new SqlNodeList(list, s.end(this)) : e;
{
return list.size() > 1 ? new SqlNodeList(list, s.end(this)) : e;
}
}

Expand Down Expand Up @@ -194,31 +194,31 @@ SqlNode PostgresqlSqlBeginTransactionMode():
}
{
{ s = span(); }
(
(
LOOKAHEAD(2)
<READ>
<READ>
(
<WRITE> { m = SqlBegin.TransactionMode.READ_WRITE; }
|
<WRITE> { m = SqlBegin.TransactionMode.READ_WRITE; }
|
<ONLY> { m = SqlBegin.TransactionMode.READ_ONLY; }
)
|
<DEFERRABLE> { m = SqlBegin.TransactionMode.DEFERRABLE; }
|
<NOT> <DEFERRABLE> { m = SqlBegin.TransactionMode.NOT_DEFERRABLE; }
|
<ISOLATION> <LEVEL>
<ISOLATION> <LEVEL>
(
<SERIALIZABLE> { m = SqlBegin.TransactionMode.ISOLATION_LEVEL_SERIALIZABLE; }
|
|
<REPEATABLE> <READ> { m = SqlBegin.TransactionMode.ISOLATION_LEVEL_REPEATABLE_READ; }
|
<READ>
(
<COMMITTED> { m = SqlBegin.TransactionMode.ISOLATION_LEVEL_READ_COMMITTED; }
|
|
<READ>
(
<COMMITTED> { m = SqlBegin.TransactionMode.ISOLATION_LEVEL_READ_COMMITTED; }
|
<UNCOMMITTED> { m = SqlBegin.TransactionMode.ISOLATION_LEVEL_READ_UNCOMMITTED; }
)
)
)
) {
return m.symbol(s.end(this));
Expand All @@ -233,13 +233,13 @@ SqlNode PostgresqlSqlCommit():
}
{
{ s = span(); }
<COMMIT> [ <WORK> | <TRANSACTION> ] [
<COMMIT> [ <WORK> | <TRANSACTION> ] [
(
<AND> <CHAIN> { chain = AndChain.AND_CHAIN; }
|
<AND> <NO> <CHAIN>
)] {
final SqlParserPos pos = s.end(this);
final SqlParserPos pos = s.end(this);
return SqlCommit.OPERATOR.createCall(pos, chain.symbol(pos));
}
}
Expand All @@ -252,13 +252,13 @@ SqlNode PostgresqlSqlRollback():
}
{
{ s = span(); }
<ROLLBACK> [ <WORK> | <TRANSACTION> ] [
<ROLLBACK> [ <WORK> | <TRANSACTION> ] [
(
<AND> <CHAIN> { chain = AndChain.AND_CHAIN; }
|
<AND> <NO> <CHAIN>
)] {
final SqlParserPos pos = s.end(this);
final SqlParserPos pos = s.end(this);
return SqlRollback.OPERATOR.createCall(pos, chain.symbol(pos));
}
}
4 changes: 2 additions & 2 deletions core/src/main/codegen/default_config.fmpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,11 +441,11 @@ parser: {
# Example: "parserImpls.ftl".
implementationFiles: [
]

# Custom identifier token.
# Example: "< IDENTIFIER: (<LETTER>|<DIGIT>)+ >".
customIdentifierToken: ""

includePosixOperators: false
includeCompoundIdentifier: true
includeBraces: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1410,7 +1410,7 @@ static class ArgMinMaxImplementor extends StrictAggImplementor {
final Primitive p = Primitive.of(compType);
final boolean isMin = info.aggregation().kind == SqlKind.ARG_MIN;
final Object inf = p == null ? null : (isMin ? p.max : p.min);
//acc[1] = isMin ? {max value} : {min value};
// acc[1] = isMin ? {max value} : {min value};
reset.currentBlock().add(
Expressions.statement(
Expressions.assign(reset.accumulator().get(1),
Expand Down Expand Up @@ -2853,9 +2853,9 @@ private static class UnaryImplementor extends AbstractRexCallImplementor {
final Expression argValue = argValueList.get(0);

final Expression e;
//Special case for implementing unary minus with BigDecimal type
//for other data type(except BigDecimal) '-' operator is OK, but for
//BigDecimal, we should call negate method of BigDecimal
// Special case for implementing unary minus with BigDecimal type
// for other data type(except BigDecimal) '-' operator is OK, but for
// BigDecimal, we should call negate method of BigDecimal
if (expressionType == ExpressionType.Negate && argValue.type == BigDecimal.class
&& null != backupMethodName) {
e = Expressions.call(argValue, backupMethodName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package org.apache.calcite.config;

import org.apache.calcite.util.Bug;

import com.google.common.collect.ImmutableSet;

import org.checkerframework.checker.nullness.qual.Nullable;
Expand Down Expand Up @@ -437,7 +439,7 @@ private static CalciteSystemProperty<String> stringProperty(
}

private static <T> T firstNonEmpty(@CheckForNull T t0, T t1) {
//Bug.upgrade("remove when 18.0 is the minimum Guava version");
Bug.upgrade("remove when 18.0 is the minimum Guava version");
if (t0 != null) {
return t0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ Enumerable<MetaFunction> functions(final MetaSchema schema_, final String catalo
return Linq4j.asEnumerable(schema.calciteSchema.getFunctionNames())
.selectMany(name ->
Linq4j.asEnumerable(schema.calciteSchema.getFunctions(name, true))
//exclude materialized views from the result set
// exclude materialized views from the result set
.where(fn -> !(fn instanceof MaterializedViewTable.MaterializedViewTableMacro))
.select(fnx ->
new MetaFunction(
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/apache/calcite/plan/Strong.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public static boolean allStrong(List<RexNode> operands) {
* (equivalently, will definitely return null or false). */
public boolean isNotTrue(RexNode node) {
switch (node.getKind()) {
//TODO Enrich with more possible cases?
// TODO Enrich with more possible cases?
case IS_NOT_NULL:
return isNull(((RexCall) node).getOperands().get(0));
case OR:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,16 @@ public static RelMetadataProvider reflectiveSource(Method method,
@Deprecated // to be removed before 2.0
public static RelMetadataProvider reflectiveSource(MetadataHandler target,
Method... methods) {
return reflectiveSource(target, ImmutableList.copyOf(methods), target.getDef().handlerClass);
return reflectiveSource(target, ImmutableList.copyOf(methods),
target.getDef().handlerClass);
}

@SuppressWarnings("deprecation")
public static <M extends Metadata> RelMetadataProvider reflectiveSource(
MetadataHandler<? extends M> handler, Class<? extends MetadataHandler<M>> handlerClass) {
//When deprecated code is removed, handler.getDef().methods will no longer be required
MetadataHandler<? extends M> handler,
Class<? extends MetadataHandler<M>> handlerClass) {
// When deprecated code is removed, handler.getDef().methods will
// no longer be required
return reflectiveSource(handler, handler.getDef().methods, handlerClass);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ private enum CacheKeyStrategy {

/** Returns e.g. ", ignoreNulls". */
private StringBuilder safeArgList(StringBuilder buff, Method method) {
//We ignore the first 2 arguments since they are included other ways.
// We ignore the first 2 arguments since they are included other ways.
for (Ord<Class<?>> t : Ord.zip(method.getParameterTypes())
.subList(2, method.getParameterCount())) {
if (Primitive.is(t.e) || RexNode.class.isAssignableFrom(t.e)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ public static HandlerNameAndGeneratedCode generateHandler(
buff.append("public final class ").append(name).append("\n")
.append(" implements ").append(handlerClass.getCanonicalName()).append(" {\n");

// PROPERTIES
// Properties
Ord.forEach(declaredMethods.values(), (declaredMethod, i) ->
CacheGeneratorUtil.cacheProperties(buff, declaredMethod, i));
for (Map.Entry<MetadataHandler<?>, String> handlerAndName : handlerToName.entrySet()) {
buff.append(" public final ").append(handlerAndName.getKey().getClass().getName())
.append(' ').append(handlerAndName.getValue()).append(";\n");
}

// CONSTRUCTOR
// Constructor
buff.append(" public ").append(name).append("(\n");
for (Map.Entry<MetadataHandler<?>, String> handlerAndName : handlerToName.entrySet()) {
buff.append(" ")
Expand All @@ -108,7 +108,7 @@ public static HandlerNameAndGeneratedCode generateHandler(
}
buff.append(" }\n");

// METHODS
// Methods
getDefMethod(buff,
handlerToName.values()
.stream()
Expand Down Expand Up @@ -145,8 +145,8 @@ private static void getDefMethod(StringBuilder buff, @Nullable String handlerNam

private static String simpleNameForHandler(Class<? extends MetadataHandler<?>> clazz) {
String simpleName = clazz.getSimpleName();
// Previously the pattern was to have a nested in class named Handler
// So we need to add the parents class to get a unique name
// Previously the pattern was to have a nested in class named Handler.
// So we need to add the parents class to get a unique name.
if (simpleName.equals("Handler")) {
String[] parts = clazz.getName().split("[.$]");
return parts[parts.length - 2] + parts[parts.length - 1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
*
* <h2>Expressions</h2>
*
*
* <p>Every row-expression has a type. (Compare with
* {@link org.apache.calcite.sql.SqlNode}, which is created before validation,
* and therefore types may not be available.)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -721,10 +721,11 @@ private static void insertToJson(DocumentContext ctx, String path, Object value)
final String parentPath;
final String key;

//The following paragraph of logic is mainly used to obtain the parent node path of path and
//the key value that should be inserted when the preant Path is map.
//eg: path is $.a ,parentPath is $
//eg: path is $.a[1] ,parentPath is $.a
// The following paragraph of logic is mainly used to obtain the
// parent node path of path and the key value that should be
// inserted when the preant Path is map.
// eg: path is $.a ,parentPath is $
// eg: path is $.a[1] ,parentPath is $.a
Integer dotIndex = path.lastIndexOf(".");
Integer leftBracketIndex = path.lastIndexOf("[");
if (dotIndex.equals(-1) && leftBracketIndex.equals(-1)) {
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/apache/calcite/sql/SqlDialect.java
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,8 @@ public void unparseSqlDatetimeArithmetic(SqlWriter writer,
writer.sep((SqlKind.PLUS == sqlKind) ? "+" : "-");
call.operand(1).unparse(writer, leftPrec, rightPrec);
writer.endList(frame);
//Only two parameters are present normally
//Checking parameter count to prevent errors
// Only two parameters are present normally.
// Checking parameter count to prevent errors.
if (call.getOperandList().size() > 2) {
call.operand(2).unparse(writer, leftPrec, rightPrec);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ private static void unparseFloor(SqlWriter writer, SqlCall call) {
final SqlWriter.Frame frame = writer.startFunCall("DATEADD");
SqlNode operand = call.operand(1);
if (operand instanceof SqlIntervalLiteral) {
//There is no DATESUB method available, so change the sign.
// There is no DATESUB method available, so change the sign.
unparseSqlIntervalLiteralMssql(
writer, (SqlIntervalLiteral) operand, sqlKind == SqlKind.MINUS ? -1 : 1);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private InferTypes() {}
// because SqlAdvisorValidator produces
// unknown types for incomplete expressions.
// Maybe we need to distinguish the two kinds of unknown.
//assert !knownType.equals(unknownType);
// assert !knownType.equals(unknownType);
Arrays.fill(operandTypes, knownType);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2084,7 +2084,8 @@ private static class TimestampSubConvertlet implements SqlRexConvertlet {
final TimeUnit unit = first(timeFrame.unit(), TimeUnit.EPOCH);
final RexNode interval2Sub;
switch (unit) {
//Fractional second units are converted to seconds using their associated multiplier.
// Fractional second units are converted to seconds using their
// associated multiplier.
case MICROSECOND:
case NANOSECOND:
interval2Sub =
Expand Down
6 changes: 4 additions & 2 deletions core/src/main/java/org/apache/calcite/util/Bug.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
* usages of it. Also, the constant helps track the propagation of the fix: as
* the fix is integrated into other branches, the constant will be removed from
* those branches.
*
* <p>This class depends on no other classes.
* (In the past, a dependency on {@code Util} caused class-loading cycles.)
*/
public abstract class Bug {
//~ Static fields/initializers ---------------------------------------------
Expand Down Expand Up @@ -237,9 +240,8 @@ public static <T> T remark(T remark) {
* instead using a {@link Deprecated} annotation followed by a comment such as
* "to be removed before 2.0".
*/
@SuppressWarnings("unused")
public static boolean upgrade(String remark) {
Util.discard(remark);
return false;
}

}
2 changes: 0 additions & 2 deletions core/src/main/java/org/apache/calcite/util/Permutation.java
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,6 @@ private void setInternal(int source, int target) {
/**
* Checks whether this permutation is valid.
*
*
*
* @param fail Whether to assert if invalid
* @return Whether valid
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,14 @@
*/

var updateLocation = () => {
var urlParams = new URLSearchParams(location.search);
var urlParams = new URLSearchParams(location.search);
urlParams.set("step", currentStepIndex);
urlParams.set("dir", currentRankDirIdx);
window.history.pushState({}, "", "?" + urlParams.toString());
};

var parseLocation = () => {
var urlParams = new URLSearchParams(location.search);
var urlParams = new URLSearchParams(location.search);
if (urlParams.has("step")) {
var stepIdx = Number(urlParams.get("step"))
if (Number.isInteger(stepIdx))
Expand Down Expand Up @@ -309,7 +309,7 @@
g.setParent(nodeID, n.set);

// create links
if(n.inputs)
if(n.inputs)
for(var inputID of n.inputs) {
var input = state.nodes[inputID];
var edgeOptions = { arrowheadStyle: "normal" };
Expand Down Expand Up @@ -405,14 +405,14 @@

document.getElementById("toggle-list-button").addEventListener("click", () => {
var col1 = document.getElementById("step-list-column");
if (col1.style.display === "none")
if (col1.style.display === "none")
col1.style.display = "";
else
else
col1.style.display = "none";
});

// render initial state

parseLocation();
setCurrentStep(currentStepIndex);
fitContent();
Expand Down
Loading

0 comments on commit 9600147

Please sign in to comment.