Skip to content

Commit

Permalink
[fix][dingo-calcite] Encode according to the checkstyle specification
Browse files Browse the repository at this point in the history
  • Loading branch information
guojn1 authored and githubgxll committed Nov 22, 2024
1 parent bdd667a commit 20459e2
Show file tree
Hide file tree
Showing 26 changed files with 390 additions and 283 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import io.dingodb.calcite.rel.LogicalDingoTableScan;
import io.dingodb.calcite.stats.StatsCache;
import io.dingodb.common.CommonId;
import io.dingodb.meta.entity.Table;
import io.dingodb.common.type.TupleMapping;
import io.dingodb.meta.entity.Table;
import lombok.Getter;
import lombok.Setter;
import org.apache.calcite.plan.RelOptCluster;
Expand All @@ -41,9 +41,9 @@
import static io.dingodb.calcite.meta.DingoCostModelV1.getAvgRowSize;
import static io.dingodb.calcite.meta.DingoCostModelV1.getScanAvgRowSize;
import static io.dingodb.calcite.meta.DingoCostModelV1.getScanCost;
import static io.dingodb.calcite.meta.DingoCostModelV1.scanFactor;
import static io.dingodb.calcite.meta.DingoCostModelV1.netFactor;
import static io.dingodb.calcite.meta.DingoCostModelV1.scanConcurrency;
import static io.dingodb.calcite.meta.DingoCostModelV1.scanFactor;

public class LogicalIndexFullScan extends LogicalDingoTableScan {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class LogicalIndexScanWithRelOp extends TableScan {
@Getter
protected boolean rangeScan;

public LogicalIndexScanWithRelOp (
public LogicalIndexScanWithRelOp(
RelOptCluster cluster,
RelTraitSet traitSet,
List<RelHint> hints,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ public static void matchAggCount(DingoAggTransformRule rule, RelOptRuleCall call
int ix = (int) val1.getValue();
Column column = table.getColumns().get(ix);
int indexIx = indexTable.getColumns().indexOf(column);
RexInputRef rexInputRef = new RexInputRef(indexIx, scan.getCluster().getTypeFactory().createSqlType(SqlTypeName.INTEGER));
RexInputRef rexInputRef = new RexInputRef(
indexIx, scan.getCluster().getTypeFactory().createSqlType(SqlTypeName.INTEGER)
);
return RexConverter.convert(rexInputRef);
}).toArray(Expr[]::new);
relOp = RelOpBuilder.builder()
Expand Down Expand Up @@ -198,7 +200,8 @@ public interface Config extends RelRule.Config {
return new DingoAggTransformRule(this);
}

/** Forwards a call to {@link #onMatch(RelOptRuleCall)}. */
/**
* Forwards a call to {@link #onMatch(RelOptRuleCall)}. */
MatchHandler<DingoAggTransformRule> matchHandler();

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ public void onMatch(@NonNull RelOptRuleCall call) {
if (scan.getSelection() != null) {
schema = schema.select(scan.getSelection());
} else if (isCountNoArgListAgg) {
// Optimization scenario similar to this SQL: select count(*) from t1 where sal > 1 and id = 1 and name ='a'
// Optimization scenario similar to this SQL:
// select count(*) from t1 where sal > 1 and id = 1 and name ='a'
final List<Integer> selectedColumns = new ArrayList<>();
final RexVisitorImpl<Void> visitor = new RexVisitorImpl<Void>(true) {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@

import com.google.common.collect.ImmutableList;
import io.dingodb.calcite.DingoTable;
import io.dingodb.calcite.rel.DingoDocument;
import io.dingodb.calcite.rel.DingoGetByIndex;
import io.dingodb.calcite.rel.DingoGetByIndexMerge;
import io.dingodb.calcite.rel.DingoGetByKeys;
import io.dingodb.calcite.rel.DingoGetDocumentPreFilter;
import io.dingodb.calcite.rel.DingoTableScan;
import io.dingodb.calcite.rel.DingoDocument;
import io.dingodb.calcite.rel.LogicalDingoDocument;
import io.dingodb.calcite.rel.DocumentStreamConvertor;
import io.dingodb.calcite.rel.LogicalDingoDocument;
import io.dingodb.calcite.rel.dingo.DingoStreamingConverter;
import io.dingodb.calcite.traits.DingoConvention;
import io.dingodb.calcite.traits.DingoRelStreaming;
Expand Down Expand Up @@ -82,7 +82,9 @@ public void onMatch(RelOptRuleCall call) {
call.transformTo(relNode);
}

public static RelNode getDingoGetDocumentPreFilter(RexNode condition, LogicalDingoDocument document, boolean forJoin) {
public static RelNode getDingoGetDocumentPreFilter(
RexNode condition, LogicalDingoDocument document, boolean forJoin
) {
DingoTable dingoTable = document.getTable().unwrap(DingoTable.class);
assert dingoTable != null;
TupleMapping selection = getDefaultSelection(dingoTable);
Expand Down Expand Up @@ -117,7 +119,7 @@ public static RelNode getDingoGetDocumentPreFilter(RexNode condition, LogicalDin
DingoTableScan dingoTableScan = new DingoTableScan(document.getCluster(),
traitSet,
ImmutableList.of(),
document.getTable(),
document.getTable(),
condition,
selection,
null,
Expand All @@ -128,12 +130,12 @@ public static RelNode getDingoGetDocumentPreFilter(RexNode condition, LogicalDin
);

DocumentStreamConvertor documentStreamConvertor = new DocumentStreamConvertor(
document.getCluster(),
document.getTraitSet(),
document.getCluster(),
document.getTraitSet(),
dingoTableScan,
document.getIndexTableId(),
document.getIndexTableId(),
textIdPair.getKey(),
document.getIndexTable(),
document.getIndexTable(),
false);
return new DingoGetDocumentPreFilter(
document.getCluster(),
Expand Down Expand Up @@ -210,6 +212,7 @@ default DingoDocumentIndexRule toRule() {
return new DingoDocumentIndexRule(this);
}
}

private static RelNode prePrimaryOrScalarPlan(
RexNode condition,
LogicalDingoDocument document,
Expand Down Expand Up @@ -276,6 +279,7 @@ private static RelNode prePrimaryOrScalarPlan(
return new DingoStreamingConverter(document.getCluster(),
traits, dingoGetDocumentPreFilter);
}

private static Pair<Integer, Integer> getTextIdIndex(DingoTable dingoTable) {
List<IndexTable> indexes = dingoTable.getTable().getIndexes();
for (IndexTable index : indexes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class DingoDocumentJoinRule extends RelRule<DingoDocumentJoinRule.Config>
/**
* Creates a RelRule.
*
* @param config
* @param config config
*/
public DingoDocumentJoinRule(Config config) {
super(config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ public void onMatch(RelOptRuleCall call) {
return;
}
LogicalIndexScanWithRelOp logicalIndexScanWithRelOp = getLogicalIndexScanWithRelOp(scan);
if (logicalIndexScanWithRelOp == null) return;
if (logicalIndexScanWithRelOp == null) {
return;
}
call.transformTo(
logicalIndexScanWithRelOp
);
Expand Down Expand Up @@ -106,7 +108,9 @@ public static LogicalIndexScanWithRelOp getLogicalIndexScanWithRelOp(LogicalScan
int ix = (int) val1.getValue();
Column column = table.getColumns().get(ix);
int indexIx = indexTable.getColumns().indexOf(column);
RexInputRef rexInputRef = new RexInputRef(indexIx, scan.getCluster().getTypeFactory().createSqlType(SqlTypeName.INTEGER));
RexInputRef rexInputRef = new RexInputRef(
indexIx, scan.getCluster().getTypeFactory().createSqlType(SqlTypeName.INTEGER)
);
return RexConverter.convert(rexInputRef);
}).toArray(Expr[]::new);
RelOp relOp = RelOpBuilder.builder()
Expand All @@ -129,7 +133,8 @@ public static LogicalIndexScanWithRelOp getLogicalIndexScanWithRelOp(LogicalScan

@Value.Immutable
public interface Config extends RelRule.Config {
DingoFullScanProjectRule.Config DINGO_FULL_SCAN_PROJECT_RULE = ImmutableDingoFullScanProjectRule.Config.builder()
DingoFullScanProjectRule.Config DINGO_FULL_SCAN_PROJECT_RULE
= ImmutableDingoFullScanProjectRule.Config.builder()
.description("DingoFullScanProjectRule")
.operandSupplier(b0 ->
b0.operand(LogicalScanWithRelOp.class).trait(Convention.NONE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ public DingoFunctionScanRule(Config config) {
hybridSearch.getFilter(),
hybridSearch.hints
);
}
else if (rel instanceof DingoFunctionScan) {
} else if (rel instanceof DingoFunctionScan) {
DingoFunctionScan scan = (DingoFunctionScan) rel;
return new DingoFunctionScan(
scan.getCluster(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import io.dingodb.meta.entity.Column;
import io.dingodb.meta.entity.Table;
import org.apache.calcite.plan.RelOptRuleCall;

import org.apache.calcite.plan.RelOptTable;
import org.apache.calcite.plan.RelRule;
import org.apache.calcite.rel.RelCollation;
Expand Down Expand Up @@ -113,8 +112,12 @@ private static void matchProjectSortOrder(DingoIndexScanMatchRule rule, RelOptRu
new DingoRelCollationImpl(ImmutableList.of(), true, keepSerialOrder)));
return;
}
} else return;
if (RuleUtils.matchTablePrimary(logicalSort)) return;
} else {
return;
}
if (RuleUtils.matchTablePrimary(logicalSort)) {
return;
}

int[] ixs = scan.getSelection().getMappings();
List<Integer> ixList = new ArrayList<>();
Expand All @@ -127,7 +130,9 @@ private static void matchProjectSortOrder(DingoIndexScanMatchRule rule, RelOptRu
return;
}

if (validateNotRemoveSort(result.matchIndexTable, orderCol)) return;
if (validateNotRemoveSort(result.matchIndexTable, orderCol)) {
return;
}

RelCollation relCollation = RelCollationImpl.of(new ArrayList<>());

Expand Down Expand Up @@ -203,9 +208,13 @@ private static void matchSort(DingoIndexScanMatchRule rule, RelOptRuleCall call)
new DingoRelCollationImpl(ImmutableList.of(), true, keepSerialOrder)));
return;
}
} else return;
} else {
return;
}

if (RuleUtils.matchTablePrimary(logicalSort)) return;
if (RuleUtils.matchTablePrimary(logicalSort)) {
return;
}

int[] ixs = scan.getSelection().getMappings();
List<Integer> ixList = new ArrayList<>();
Expand Down Expand Up @@ -260,7 +269,9 @@ public static void indexRange(DingoIndexScanMatchRule rule, RelOptRuleCall call)
return;
}
LogicalProject logicalProject1 = getLogicalProject(scan, logicalProject);
if (logicalProject1 == null) return;
if (logicalProject1 == null) {
return;
}

call.transformTo(logicalProject1);
}
Expand Down Expand Up @@ -329,7 +340,9 @@ public static void indexRangeAsc(DingoIndexScanMatchRule rule, RelOptRuleCall ca
if (disableIndex) {
return;
}
if (RuleUtils.matchTablePrimary(logicalSort)) return;
if (RuleUtils.matchTablePrimary(logicalSort)) {
return;
}

List<RelFieldCollation> relFieldCollationList = logicalSort.getCollation().getFieldCollations();
if (relFieldCollationList.size() != 1) {
Expand All @@ -349,7 +362,9 @@ public static void indexRangeAsc(DingoIndexScanMatchRule rule, RelOptRuleCall ca
if (orderCol == null) {
return;
}
if (validateNotRemoveSort(logicalIndexRangeScan.getIndexTable(), orderCol)) return;
if (validateNotRemoveSort(logicalIndexRangeScan.getIndexTable(), orderCol)) {
return;
}
int keepSerialOrder = RuleUtils.getSerialOrder(relFieldCollation);
if (RuleUtils.preventRemoveOrder(keepSerialOrder)) {
return;
Expand All @@ -375,7 +390,9 @@ public static void nonLeftmostMatching(DingoIndexScanMatchRule rule, RelOptRuleC
LogicalDingoTableScan scan = call.rel(1);

RelNode relNode = getIndexFullScanRelNode(project, scan);
if (relNode == null) return;
if (relNode == null) {
return;
}

call.transformTo(relNode);
}
Expand All @@ -389,7 +406,9 @@ public static void nonLeftmostMatchingOrder(DingoIndexScanMatchRule rule, RelOpt
return;
}

if (RuleUtils.matchTablePrimary(logicalSort)) return;
if (RuleUtils.matchTablePrimary(logicalSort)) {
return;
}

List<RelFieldCollation> relFieldCollationList = logicalSort.getCollation().getFieldCollations();
if (relFieldCollationList.size() != 1) {
Expand All @@ -406,7 +425,9 @@ public static void nonLeftmostMatchingOrder(DingoIndexScanMatchRule rule, RelOpt
} else {
return;
}
if (validateNotRemoveSort(logicalIndexFullScan.getIndexTable(), orderCol)) return;
if (validateNotRemoveSort(logicalIndexFullScan.getIndexTable(), orderCol)) {
return;
}
int keepSerialOrder = RuleUtils.getSerialOrder(relFieldCollation);
if (RuleUtils.preventRemoveOrder(keepSerialOrder)) {
return;
Expand Down Expand Up @@ -651,7 +672,8 @@ public interface Config extends RelRule.Config {
b0.operand(LogicalSort.class).oneInput(b1 ->
b1.operand(LogicalProject.class).oneInput(b2 ->
b2.operand(LogicalDingoTableScan.class)
.predicate(scan -> scan.getFilter() == null && !(scan instanceof LogicalIndexFullScan)).noInputs()
.predicate(scan -> scan.getFilter() == null
&& !(scan instanceof LogicalIndexFullScan)).noInputs()
)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ public void onMatch(@NonNull RelOptRuleCall call) {
return;
}

KeyValueCodec codec = CodecService.getDefault().createKeyValueCodec(td.version, td.tupleType(), td.keyMapping());
KeyValueCodec codec = CodecService.getDefault().createKeyValueCodec(
td.version, td.tupleType(), td.keyMapping()
);
Object[] tuple = new Object[td.getColumns().size()];

byte[] prefixBytes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class DingoModifyIndexRule extends RelRule<RelRule.Config> implements Sub
/**
* Creates a temporary RelRule for update index col.
*
* @param config
* @param config config
*/
protected DingoModifyIndexRule(Config config) {
super(config);
Expand Down
Loading

0 comments on commit 20459e2

Please sign in to comment.