Skip to content

Commit

Permalink
[ISSUE-197] Support translate complex join to match
Browse files Browse the repository at this point in the history
  • Loading branch information
Leomrlin authored Oct 13, 2023
1 parent 75dd00d commit 719ae4f
Show file tree
Hide file tree
Showing 89 changed files with 4,187 additions and 288 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@ public List<TableField> getValueFields() {
return getFields().subList(getValueOffset(), size());
}

public IType<?>[] getValueTypes() {
IType<?>[] valueTypes = new IType[size() - getValueOffset()];
List<TableField> valueFields = getValueFields();
for (int i = 0; i < valueFields.size(); i++) {
valueTypes[i ] = valueFields.get(i).getType();
}
return valueTypes;
}

public static EdgeType emptyEdge(IType<?> idType) {
TableField srcField = new TableField(DEFAULT_SRC_ID_NAME, idType, false);
TableField targetField = new TableField(DEFAULT_TARGET_ID_NAME, idType, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public int getTimestampIndex() {

public EdgeRecordType add(String fieldName, RelDataType type, boolean caseSensitive) {
if (type instanceof MetaFieldType) {
throw new IllegalArgumentException("Cannot add MetaFieldType");
type = ((MetaFieldType) type).getType();
}
List<RelDataTypeField> fields = new ArrayList<>(getFieldList());

Expand Down Expand Up @@ -188,9 +188,10 @@ static int indexOf(List<RelDataTypeField> fields, String name) {

public static EdgeRecordType emptyEdgeType(RelDataType idType, RelDataTypeFactory typeFactory) {
List<RelDataTypeField> fields = new ArrayList<>();
fields.add(new RelDataTypeFieldImpl(EdgeType.DEFAULT_SRC_ID_NAME, EdgeType.SRC_ID_FIELD_POSITION, idType));
fields.add(
new RelDataTypeFieldImpl(EdgeType.DEFAULT_TARGET_ID_NAME, EdgeType.TARGET_ID_FIELD_POSITION, idType));
fields.add(new RelDataTypeFieldImpl(EdgeType.DEFAULT_SRC_ID_NAME,
EdgeType.SRC_ID_FIELD_POSITION, MetaFieldType.edgeSrcId(idType, typeFactory)));
fields.add(new RelDataTypeFieldImpl(EdgeType.DEFAULT_TARGET_ID_NAME,
EdgeType.TARGET_ID_FIELD_POSITION, MetaFieldType.edgeTargetId(idType, typeFactory)));
fields.add(new RelDataTypeFieldImpl(GraphSchema.LABEL_FIELD_NAME, EdgeType.LABEL_FIELD_POSITION,
typeFactory.createSqlType(SqlTypeName.VARCHAR)));
return EdgeRecordType.createEdgeType(fields, EdgeType.DEFAULT_SRC_ID_NAME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ public MetaField getMetaField() {
return metaField;
}

public RelDataType getType() {
return type;
}

public enum MetaField {
VERTEX_ID,
VERTEX_TYPE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public boolean isId(int index) {

public VertexRecordType add(String fieldName, RelDataType type, boolean caseSensitive) {
if (type instanceof MetaFieldType) {
throw new IllegalArgumentException("Cannot add MetaFieldType");
type = ((MetaFieldType) type).getType();
}
List<RelDataTypeField> fields = new ArrayList<>(getFieldList());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public class GQLOptimizer {

private final List<RuleGroup> ruleGroups = new ArrayList<>();

private int times = 3;

public GQLOptimizer(Context context) {
this.context = context;
}
Expand All @@ -52,10 +54,22 @@ public void addRuleGroup(RuleGroup ruleGroup) {
}
}

public int setTimes(int newTimes) {
int oldTimes = this.times;
this.times = newTimes;
return oldTimes;
}

public RelNode optimize(RelNode root) {
return optimize(root, this.times);
}

public RelNode optimize(RelNode root, int runTimes) {
RelNode optimizedNode = root;
for (RuleGroup rules : ruleGroups) {
optimizedNode = applyRules(rules, optimizedNode);
for (int i = 0; i < runTimes ; i++) {
for (RuleGroup rules : ruleGroups) {
optimizedNode = applyRules(rules, optimizedNode);
}
}
return optimizedNode;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.antgroup.geaflow.dsl.optimize.rule.GQLAggregateProjectMergeRule;
import com.antgroup.geaflow.dsl.optimize.rule.GQLMatchUnionMergeRule;
import com.antgroup.geaflow.dsl.optimize.rule.GQLProjectRemoveRule;
import com.antgroup.geaflow.dsl.optimize.rule.MatchJoinMatchMergeRule;
import com.antgroup.geaflow.dsl.optimize.rule.MatchJoinTableToGraphMatchRule;
import com.antgroup.geaflow.dsl.optimize.rule.MatchSortToLogicalSortRule;
import com.antgroup.geaflow.dsl.optimize.rule.PathInputReplaceRule;
Expand Down Expand Up @@ -85,8 +86,11 @@ public class OptimizeRules {
PushJoinFilterConditionRule.INSTANCE,
PushConsecutiveJoinConditionRule.INSTANCE,
TableJoinTableToGraphRule.INSTANCE,
MatchJoinMatchMergeRule.INSTANCE,
MatchJoinTableToGraphMatchRule.INSTANCE,
TableJoinMatchToGraphMatchRule.INSTANCE);
TableJoinMatchToGraphMatchRule.INSTANCE,
MatchJoinMatchMergeRule.INSTANCE
);

private static final List<RelOptRule> POST_OPTIMIZE_RULES = ImmutableList.of(
PathInputReplaceRule.INSTANCE
Expand Down
Loading

0 comments on commit 719ae4f

Please sign in to comment.