Skip to content

Commit

Permalink
[fix][dingo-executor] Use checkStyle to standardize code
Browse files Browse the repository at this point in the history
  • Loading branch information
guojn1 authored and githubgxll committed Nov 6, 2024
1 parent 72e93d9 commit f66262e
Show file tree
Hide file tree
Showing 43 changed files with 1,432 additions and 1,297 deletions.
1,592 changes: 803 additions & 789 deletions dingo-calcite/src/main/java/io/dingodb/calcite/rule/SubQueryRemoveRule.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ protected void addImplicitSubSchemaToBuilder(ImmutableSortedMap.Builder<String,
SubSnapshotSchema subSnapshotSchema = new SubSnapshotSchema(
rootSchema.is, name, rootSchema.context, ImmutableList.of(RootSnapshotSchema.ROOT_SCHEMA_NAME, name)
);
builder.put(name, SubCalciteSchema.builder().rootCalciteSchema(this).name(name).schema(subSnapshotSchema).build());
builder.put(name, SubCalciteSchema.builder().rootCalciteSchema(this)
.name(name).schema(subSnapshotSchema).build());
});
}

Expand All @@ -109,7 +110,9 @@ public void addImplicitTableToBuilder(ImmutableSortedSet.Builder<String> builder
}

@Override
protected void addImplicitFunctionsToBuilder(ImmutableList.Builder<Function> builder, String name, boolean caseSensitive) {
protected void addImplicitFunctionsToBuilder(
ImmutableList.Builder<Function> builder, String name, boolean caseSensitive
) {

}

Expand All @@ -124,7 +127,9 @@ protected void addImplicitTypeNamesToBuilder(ImmutableSortedSet.Builder<String>
}

@Override
protected void addImplicitTablesBasedOnNullaryFunctionsToBuilder(ImmutableSortedMap.Builder<String, Table> builder) {
protected void addImplicitTablesBasedOnNullaryFunctionsToBuilder(
ImmutableSortedMap.Builder<String, Table> builder
) {

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ protected void addImplicitTableToBuilder(ImmutableSortedSet.Builder<String> buil
}

@Override
protected void addImplicitFunctionsToBuilder(ImmutableList.Builder<Function> builder, String name, boolean caseSensitive) {
protected void addImplicitFunctionsToBuilder(
ImmutableList.Builder<Function> builder, String name, boolean caseSensitive
) {

}

Expand All @@ -128,7 +130,9 @@ protected void addImplicitTypeNamesToBuilder(ImmutableSortedSet.Builder<String>
}

@Override
protected void addImplicitTablesBasedOnNullaryFunctionsToBuilder(ImmutableSortedMap.Builder<String, Table> builder) {
protected void addImplicitTablesBasedOnNullaryFunctionsToBuilder(
ImmutableSortedMap.Builder<String, Table> builder
) {

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ public abstract class StatsOperator {
statsTblId = statsTable.tableId;
cmSketchTblId = cmSketchTable.tableId;
analyzeTaskCodec = CodecService.getDefault()
.createKeyValueCodec(analyzeTaskTable.version, analyzeTaskTable.tupleType(), analyzeTaskTable.keyMapping());
.createKeyValueCodec(
analyzeTaskTable.version, analyzeTaskTable.tupleType(), analyzeTaskTable.keyMapping()
);
bucketsCodec = CodecService.getDefault()
.createKeyValueCodec(bucketsTable.version, bucketsTable.tupleType(), bucketsTable.keyMapping());
statsCodec = CodecService.getDefault()
Expand Down Expand Up @@ -126,28 +128,15 @@ public static void upsert(StoreKvTxn store, KeyValueCodec codec, List<Object[]>
}

public static void delStats(String schemaName, String tableName) {
try {
// String delTemp = "delete from %s where schema_name='%s' and table_name='%s'";
// List<String> sqlList = new ArrayList<>();
// String sqlAnalyzeTask = String.format(delTemp, "mysql.analyze_task", schemaName, tableName);
// String sqlStats = String.format(delTemp, "mysql.table_stats", schemaName, tableName);
// String sqlBuckets = String.format(delTemp, "mysql.TABLE_BUCKETS", schemaName, tableName);
// String sqlCmSketch = String.format(delTemp, "mysql.CM_SKETCH", schemaName, tableName);
// sqlList.add(sqlAnalyzeTask);
// sqlList.add(sqlBuckets);
// sqlList.add(sqlStats);
// sqlList.add(sqlCmSketch);
// StatsCache.removeCache(schemaName, tableName);
} catch (Exception ignored) {
}
}

public static void delStats(String table, String schemaName, String tableName) {
String sqlTemp = "delete from %s where schema_name='%s' and table_name='%s'";
String sql = String.format(sqlTemp, table, schemaName, tableName);
String error = SessionUtil.INSTANCE.exeUpdateInTxn(sql);
if (error != null) {
LogUtils.error(log, "delStats error:{}, table:{}, schema:{}, tableName:{}", error, table, schemaName, tableName);
LogUtils.error(log, "delStats error:{}, table:{}, schema:{}, tableName:{}",
error, table, schemaName, tableName);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@
import io.dingodb.exec.expr.DingoCompileContext;
import io.dingodb.exec.expr.DingoRelConfig;
import io.dingodb.exec.utils.SchemaWrapperUtils;
import io.dingodb.expr.coding.CodingFlag;
import io.dingodb.expr.coding.RelOpCoder;
import io.dingodb.expr.rel.RelOp;
import io.dingodb.expr.rel.op.RelOpBuilder;
import io.dingodb.expr.runtime.expr.Expr;
import io.dingodb.expr.runtime.expr.Exprs;
import io.dingodb.expr.runtime.type.TupleType;
import io.dingodb.expr.coding.CodingFlag;
import io.dingodb.expr.coding.RelOpCoder;
import io.dingodb.meta.DdlService;
import io.dingodb.meta.MetaService;
import io.dingodb.meta.entity.Column;
Expand Down Expand Up @@ -138,7 +138,8 @@ public void run() {
= metaService.getRangeDistribution(tableId);

Set<RangeDistribution> distributions
= ps.calcPartitionRange(null, null, true, true, rangeDistributionNavigableMap);
= ps.calcPartitionRange(null, null, true, true,
rangeDistributionNavigableMap);

List<Histogram> histogramList = new ArrayList<>();
List<CountMinSketch> cmSketchList = new ArrayList<>();
Expand Down Expand Up @@ -319,9 +320,6 @@ private void buildHistogram(List<Histogram> histogramList,
histogramList.stream().flatMap(histogram ->
Arrays.stream(new DingoType[]{histogram.getDingoType(),
histogram.getDingoType()})).toArray(DingoType[]::new));
TupleMapping outputKeyMapping = TupleMapping.of(
IntStream.range(0, 0).boxed().collect(Collectors.toList())
);
CoprocessorV2 coprocessor = getCoprocessor(td, histogramList, outputSchema);
if (coprocessor == null) {
return null;
Expand All @@ -339,7 +337,14 @@ private void buildHistogram(List<Histogram> histogramList,
30000,
coprocessor
);
return Iterators.transform(iterator, wrap(CodecService.getDefault().createKeyValueCodec(td.version, outputSchema, outputKeyMapping)::decode)::apply);
TupleMapping outputKeyMapping = TupleMapping.of(
IntStream.range(0, 0).boxed().collect(Collectors.toList())
);
return Iterators.transform(
iterator,
wrap(CodecService.getDefault().createKeyValueCodec(td.version,
outputSchema, outputKeyMapping)::decode)::apply
);
}).collect(Collectors.toList());
for (Iterator<Object[]> iterator : iteratorList) {
if (iterator == null) {
Expand Down Expand Up @@ -410,13 +415,13 @@ private void endAnalyzeTask(String failReason, long rowCount) {
values[6] = StatsTaskState.FAIL.getState();
values[7] = failReason;
}
Timestamp startTime = (Timestamp) values[4];
values[5] = current;
values[9] = 0L;
values[10] = current;
values[3] = rowCount;
Long lastModifyCount = (Long) values[11];
values[11] = lastModifyCount + modify;
Timestamp startTime = (Timestamp) values[4];
long duration = now - startTime.getTime();
values[12] = duration;
long lastExecTime = (long) values[14];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ public Explain visit(@NonNull DingoInfoSchemaScan rel) {
}
String accessObj = "";
if (rel.getTable() != null) {
accessObj = Objects.requireNonNull(rel.getTable().unwrap(DingoTable.class)).getTable().getName();
accessObj = Objects.requireNonNull(rel.getTable().unwrap(DingoTable.class)).getTable().getName();
}
return new Explain("dingoInfoSchemaScan", rel.getRowCount(), "root", accessObj, filter);
}
Expand All @@ -389,6 +389,54 @@ public Explain visit(@NonNull DingoExportData rel) {
return explain1;
}

@Override
public Explain visit(@NonNull IndexFullScan rel) {
StringBuilder info = new StringBuilder();
if (rel.getFilter() != null) {
info.append("condition:");
info.append(rel.getFilter().toString());
}
info.append(",lookup:").append(rel.isLookup());
if (rel.getSelection() != null && rel.getSelection().size() < 10) {
info.append(",selection:").append(rel.getSelection().toString());
}
StringBuilder rootInfo = new StringBuilder("rpcBatchSize:" + ScopeVariables.getRpcBatchSize());
rootInfo.append(", parallel = ").append(Utils.parallel(rel.getKeepSerialOrder())).append(" ");
Explain explain1 = new Explain(
"indexFullScanReader", rel.getRowCount(), "root",
"", rootInfo.toString()
);
if (rel.isPushDown() && rel.getFilter() != null) {
Explain explain = new Explain("indexFullScan", rel.getFullRowCount(),
"cop[store]", rel.getIndexTable().getName(), info.toString());
explain1.getChildren().add(explain);
}
return explain1;
}

@Override
public Explain visit(@NonNull IndexRangeScan indexRangeScan) {
StringBuilder filter = new StringBuilder();
filter.append("parallel=").append(Utils.parallel(indexRangeScan.getKeepSerialOrder()));
if (indexRangeScan.getFilter() != null) {
filter.append(", condition=").append(indexRangeScan.getFilter().toString());
}
filter.append(", lookup:").append(indexRangeScan.isLookup());
return new Explain(
"indexRangeScan", indexRangeScan.getRowCount(), "root",
indexRangeScan.getIndexTable().getName(), filter.toString()
);
}

@Override
public Explain visit(@NonNull DingoGetDocumentPreFilter rel) {
String accessObj = "";
if (rel.getIndexTable() != null) {
accessObj = rel.getIndexTable().getName();
}
return getCommonExplain(rel, "DingoGetDocumentPreFilter", accessObj, "");
}

private Explain getCommonExplain(DingoRel rel, String id, String accessObj, String info) {
Explain explain = dingo(rel.getInput(0)).accept(this);
Explain explain1 = new Explain(
Expand Down Expand Up @@ -452,45 +500,6 @@ public Explain visitDingoAggregateReduce(@NonNull DingoReduceAggregate rel) {
return explain1;
}

@Override
public Explain visit(@NonNull IndexFullScan rel) {
StringBuilder info = new StringBuilder();
if (rel.getFilter() != null) {
info.append("condition:");
info.append(rel.getFilter().toString());
}
info.append(",lookup:").append(rel.isLookup());
if (rel.getSelection() != null && rel.getSelection().size() < 10) {
info.append(",selection:").append(rel.getSelection().toString());
}
StringBuilder rootInfo = new StringBuilder("rpcBatchSize:" + ScopeVariables.getRpcBatchSize());
rootInfo.append(", parallel = ").append(Utils.parallel(rel.getKeepSerialOrder())).append(" ");
Explain explain1 = new Explain(
"indexFullScanReader", rel.getRowCount(), "root",
"", rootInfo.toString()
);
if (rel.isPushDown() && rel.getFilter() != null) {
Explain explain = new Explain("indexFullScan", rel.getFullRowCount(),
"cop[store]", rel.getIndexTable().getName(), info.toString());
explain1.getChildren().add(explain);
}
return explain1;
}

@Override
public Explain visit(@NonNull IndexRangeScan indexRangeScan) {
StringBuilder filter = new StringBuilder();
filter.append("parallel=").append(Utils.parallel(indexRangeScan.getKeepSerialOrder()));
if (indexRangeScan.getFilter() != null) {
filter.append(", condition=").append(indexRangeScan.getFilter().toString());
}
filter.append(", lookup:").append(indexRangeScan.isLookup());
return new Explain(
"indexRangeScan", indexRangeScan.getRowCount(), "root",
indexRangeScan.getIndexTable().getName(), filter.toString()
);
}

@Override
public Explain visitDingoIndexScanWithRelOp(@NonNull DingoIndexScanWithRelOp rel) {
Explain explain;
Expand All @@ -510,12 +519,4 @@ public Explain visitDingoIndexScanWithRelOp(@NonNull DingoIndexScanWithRelOp rel
return explain1;
}

@Override
public Explain visit(@NonNull DingoGetDocumentPreFilter rel) {
String accessObj = "";
if (rel.getIndexTable() != null) {
accessObj = rel.getIndexTable().getName();
}
return getCommonExplain(rel, "DingoGetDocumentPreFilter", accessObj, "");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,37 +108,16 @@ private DingoScanWithRelOpVisitFun() {
} else {
int partitionNum = partitions.size();
if (td.getPartitionStrategy().equalsIgnoreCase("HASH")) {
// Partition will be split in executing time.
// if (rel.getRangeDistribution() != null || !Utils.parallel(rel.getKeepSerialOrder())) {
outputs.add(createVerticesForRange(
task,
idGenerator,
(start, end) -> createCalcDistributionVertex(rel, tableInfo, start, end, false, visitor),
null,
null,
scanVertexCreator
));
visitor.setScan(true);
return outputs;
// }
// NavigableMap<ComparableByteArray, RangeDistribution> rangeDistributions = tableInfo.getRangeDistributions();
// for (int i = 0; i < partitionNum; ++i) {
// Partition partition = partitions.get(i);
// NavigableMap<ComparableByteArray, RangeDistribution> subMap = rangeDistributions.subMap(
// new ComparableByteArray(partition.getStart()),
// true,
// new ComparableByteArray(partition.getEnd()),
// false
// );
// outputs.add(createVerticesForRange(
// task,
// idGenerator,
// (start, end) -> createCalcHashDistributionVertex(rel, subMap, start, end, false),
// null,
// null,
// scanVertexCreator
// ));
// }
outputs.add(createVerticesForRange(
task,
idGenerator,
(start, end) -> createCalcDistributionVertex(rel, tableInfo, start, end, false, visitor),
null,
null,
scanVertexCreator
));
visitor.setScan(true);
return outputs;
} else {
if (rel.getRangeDistribution() != null || !Utils.parallel(rel.getKeepSerialOrder())) {
outputs.add(createVerticesForRange(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ private static boolean doExpire(MysqlConnection mysqlConnection, String sql, Ato
ErrorCode.ER_PASSWORD_EXPIRE, mysqlConnection.getConnection().getClientInfo(CONNECTION_CHARSET));
return true;
}
} catch(SQLException e) {
} catch (SQLException e) {
LogUtils.info(log, e.getMessage(), e);
}
return false;
Expand Down Expand Up @@ -216,15 +216,18 @@ public void executeSingleQuery(String sql, AtomicLong packetId,
if (dingoStatement.isHasIncId()) {
Long lastInsertId = dingoStatement.getAutoIncId();
okPacket = MysqlPacketFactory.getInstance()
.getOkPacket(count, packetId, initServerStatus, new BigInteger(String.valueOf(lastInsertId)), sqlWarning);
.getOkPacket(
count, packetId, initServerStatus, new BigInteger(String.valueOf(lastInsertId)), sqlWarning
);
} else {
okPacket = MysqlPacketFactory.getInstance()
.getOkPacket(count, packetId, initServerStatus, BigInteger.ZERO, sqlWarning);
}
MysqlResponseHandler.responseOk(okPacket, mysqlConnection.channel);
}
} catch (SQLException sqlException) {
LogUtils.error(log, "sql exception sqlstate:" + sqlException.getSQLState() + ", code:" + sqlException.getErrorCode()
LogUtils.error(log, "sql exception sqlstate:" + sqlException.getSQLState() + ", code:"
+ sqlException.getErrorCode()
+ ", message:" + sqlException.getMessage());
MysqlResponseHandler.responseError(packetId, mysqlConnection.channel, sqlException, connCharSet);
} catch (Exception e) {
Expand Down Expand Up @@ -374,15 +377,14 @@ public void executeStatement(ExecuteStatementPacket statementPacket,
} catch (SQLException e) {
MysqlResponseHandler.responseError(packetId, mysqlConnection.channel, e, connectionCharSet);
} catch (Exception e) {
MysqlResponseHandler.responseError(packetId, mysqlConnection.channel, ErrorCode.ER_UNKNOWN_ERROR, connectionCharSet);
MysqlResponseHandler.responseError(
packetId, mysqlConnection.channel, ErrorCode.ER_UNKNOWN_ERROR, connectionCharSet
);
LogUtils.error(log, e.getMessage(), e);
}
}

public static int getInitServerStatus(DingoConnection connection) {
String tranReadOnly = connection.getClientInfo("transaction_read_only");
tranReadOnly = tranReadOnly == null ? "off" : tranReadOnly;
boolean txReadOnly = tranReadOnly.equalsIgnoreCase("on");
ITransaction transaction = connection.getTransaction();
boolean inTransaction = false;
if (transaction != null) {
Expand All @@ -395,6 +397,9 @@ public static int getInitServerStatus(DingoConnection connection) {
if (connection.getAutoCommit()) {
initServerStatus |= ServerStatus.SERVER_STATUS_AUTOCOMMIT;
}
String tranReadOnly = connection.getClientInfo("transaction_read_only");
tranReadOnly = tranReadOnly == null ? "off" : tranReadOnly;
boolean txReadOnly = tranReadOnly.equalsIgnoreCase("on");
if (txReadOnly) {
initServerStatus |= ServerStatus.SERVER_STATUS_IN_TRANS_READONLY;
}
Expand Down
Loading

0 comments on commit f66262e

Please sign in to comment.