Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package org.apache.doris.nereids.hint;

import org.apache.doris.catalog.TableIf;
import org.apache.doris.common.Pair;
import org.apache.doris.nereids.jobs.joinorder.hypergraph.bitmap.LongBitmap;
import org.apache.doris.nereids.trees.expressions.ExprId;
Expand Down Expand Up @@ -191,14 +190,14 @@ public RelationId findRelationIdAndTableName(String name) {
return null;
}

private boolean hasSameName() {
private Optional<String> hasSameName() {
Set<String> tableSet = Sets.newHashSet();
for (String table : tablelist) {
if (!tableSet.add(table)) {
return true;
return Optional.of(table);
}
}
return false;
return Optional.empty();
}

public Map<ExprId, String> getExprIdToTableNameMap() {
Expand Down Expand Up @@ -252,24 +251,47 @@ public Long getTotalBitmap() {
/**
* set total bitmap used in leading before we get into leading join
*/
public void setTotalBitmap() {
public void setTotalBitmap(Set<RelationId> inputRelationSets) {
Long totalBitmap = 0L;
if (hasSameName()) {
Optional<String> duplicateTableName = hasSameName();
if (duplicateTableName.isPresent()) {
this.setStatus(HintStatus.SYNTAX_ERROR);
this.setErrorMessage("duplicated table");
this.setErrorMessage("duplicated table:" + duplicateTableName.get());
}
Set<RelationId> existRelationSets = new HashSet<>();
for (int index = 0; index < getTablelist().size(); index++) {
RelationId id = findRelationIdAndTableName(getTablelist().get(index));
if (id == null) {
this.setStatus(HintStatus.SYNTAX_ERROR);
this.setErrorMessage("can not find table: " + getTablelist().get(index));
return;
}
existRelationSets.add(id);
totalBitmap = LongBitmap.set(totalBitmap, id.asInt());
}
if (getTablelist().size() < inputRelationSets.size()) {
Set<RelationId> missRelationIds = new HashSet<>();
missRelationIds.addAll(inputRelationSets);
missRelationIds.removeAll(existRelationSets);
String missingTablenames = getMissingTableNames(missRelationIds);
this.setStatus(HintStatus.SYNTAX_ERROR);
this.setErrorMessage("leading should have all tables in query block, missing tables: " + missingTablenames);
}
this.totalBitmap = totalBitmap;
}

private String getMissingTableNames(Set<RelationId> missRelationIds) {
String missTableNames = "";
for (RelationId id : missRelationIds) {
for (Pair<RelationId, String> pair : relationIdAndTableName) {
if (pair.first.equals(id)) {
missTableNames += pair.second + " ";
}
}
}
return missTableNames;
}

/**
* try to get join constraint, if can not get, it means join is inner join,
* @param joinTableBitmap table bitmap below this join
Expand Down Expand Up @@ -565,27 +587,4 @@ private Long getBitmap(LogicalPlan root) {
return null;
}
}

/**
* get leading containing tables which means leading wants to combine tables into joins
* @return long value represent tables we included
*/
public Long getLeadingTableBitmap(List<TableIf> tables) {
Long totalBitmap = 0L;
if (hasSameName()) {
this.setStatus(HintStatus.SYNTAX_ERROR);
this.setErrorMessage("duplicated table");
return totalBitmap;
}
for (int index = 0; index < getTablelist().size(); index++) {
RelationId id = findRelationIdAndTableName(getTablelist().get(index));
if (id == null) {
this.setStatus(HintStatus.SYNTAX_ERROR);
this.setErrorMessage("can not find table: " + getTablelist().get(index));
return totalBitmap;
}
totalBitmap = LongBitmap.set(totalBitmap, id.asInt());
}
return totalBitmap;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public List<Rule> buildRules() {
return ctx.root;
}
Hint leadingHint = ctx.cascadesContext.getHintMap().get("Leading");
((LeadingHint) leadingHint).setTotalBitmap();
((LeadingHint) leadingHint).setTotalBitmap(ctx.root.getInputRelations());
Long currentBitMap = LongBitmap.computeTableBitmap(ctx.root.getInputRelations());
if (((LeadingHint) leadingHint).getTotalBitmap().equals(currentBitMap)
&& leadingHint.isSuccess()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@
package org.apache.doris.nereids.trees.expressions.functions.window;

import org.apache.doris.catalog.FunctionSignature;
import org.apache.doris.nereids.exceptions.AnalysisException;
import org.apache.doris.nereids.trees.expressions.Expression;
import org.apache.doris.nereids.trees.expressions.functions.AlwaysNotNullable;
import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature;
import org.apache.doris.nereids.trees.expressions.literal.Literal;
import org.apache.doris.nereids.trees.expressions.shape.LeafExpression;
import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
import org.apache.doris.nereids.types.BigIntType;
import org.apache.doris.nereids.types.DataType;
import org.apache.doris.nereids.types.IntegerType;
import org.apache.doris.nereids.types.LargeIntType;
import org.apache.doris.nereids.types.SmallIntType;
Expand Down Expand Up @@ -64,6 +67,27 @@ public Ntile withChildren(List<Expression> children) {
return new Ntile(children.get(0));
}

@Override
public void checkLegalityBeforeTypeCoercion() {
DataType type = getBuckets().getDataType();
if (!type.isIntegralType()) {
throw new AnalysisException("The bucket of NTILE must be a integer: " + this.toSql());
}
if (!getBuckets().isConstant()) {
throw new AnalysisException(
"The bucket of NTILE must be a constant value: " + this.toSql());
}
if (getBuckets() instanceof Literal) {
if (((Literal) getBuckets()).getDouble() <= 0) {
throw new AnalysisException(
"The bucket parameter of NTILE must be a constant positive integer: " + this.toSql());
}
} else {
throw new AnalysisException(
"The bucket parameter of NTILE must be a constant positive integer: " + this.toSql());
}
}

@Override
public List<FunctionSignature> getSignatures() {
return SIGNATURES;
Expand Down
Loading