Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(interactive): Support Start Tag for Graph Operators in Compiler #3376

Merged
merged 3 commits into from
Nov 28, 2023
Merged
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 @@ -14,7 +14,10 @@
import com.alibaba.graphscope.common.ir.rex.RexPermuteGraphShuttle;
import com.alibaba.graphscope.common.ir.rex.RexVariableAliasCollector;
import com.alibaba.graphscope.common.ir.tools.GraphBuilder;
import com.alibaba.graphscope.common.ir.tools.config.*;
import com.alibaba.graphscope.common.ir.tools.config.ExpandConfig;
import com.alibaba.graphscope.common.ir.tools.config.GetVConfig;
import com.alibaba.graphscope.common.ir.tools.config.LabelConfig;
import com.alibaba.graphscope.common.ir.tools.config.SourceConfig;
import com.alibaba.graphscope.common.ir.type.GraphNameOrId;
import com.alibaba.graphscope.common.ir.type.GraphProperty;
import com.alibaba.graphscope.common.ir.type.GraphSchemaType;
Expand Down Expand Up @@ -447,7 +450,8 @@ public TrimResult trimFields(GraphLogicalPathExpand pathExpand, UsedFields field
pathExpand.getFetch(),
pathExpand.getResultOpt(),
pathExpand.getPathOpt(),
pathExpand.getAliasName());
pathExpand.getAliasName(),
pathExpand.getStartAlias());
return result(newPathExpand, mapping, pathExpand);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.alibaba.graphscope.common.ir.rel.graph;

import com.alibaba.graphscope.common.ir.rel.type.AliasNameWithId;
import com.alibaba.graphscope.common.ir.rel.type.TableConfig;
import com.alibaba.graphscope.common.ir.tools.AliasInference;
import com.alibaba.graphscope.common.ir.type.GraphSchemaType;
Expand Down Expand Up @@ -55,12 +56,15 @@ public abstract class AbstractBindableTableScan extends TableScan {

protected final int aliasId;

protected final AliasNameWithId startAlias;

protected AbstractBindableTableScan(
GraphOptCluster cluster,
List<RelHint> hints,
@Nullable RelNode input,
TableConfig tableConfig,
@Nullable String aliasName) {
@Nullable String aliasName,
AliasNameWithId startAlias) {
super(
cluster,
RelTraitSet.createEmpty(),
Expand All @@ -74,14 +78,15 @@ protected AbstractBindableTableScan(
AliasInference.inferDefault(
aliasName, AliasInference.getUniqueAliasList(input, true));
this.aliasId = cluster.getIdGenerator().generate(this.aliasName);
this.startAlias = Objects.requireNonNull(startAlias);
}

protected AbstractBindableTableScan(
GraphOptCluster cluster,
List<RelHint> hints,
TableConfig tableConfig,
String aliasName) {
this(cluster, hints, null, tableConfig, aliasName);
this(cluster, hints, null, tableConfig, aliasName, AliasNameWithId.DEFAULT);
}

@Override
Expand Down Expand Up @@ -132,6 +137,10 @@ public RelWriter explainTerms(RelWriter pw) {
return pw.itemIf("input", input, !Objects.isNull(input))
.item("tableConfig", tableConfig)
.item("alias", AliasInference.SIMPLE_NAME(getAliasName()))
.itemIf(
"startAlias",
startAlias.getAliasName(),
startAlias.getAliasName() != AliasInference.DEFAULT_NAME)
.itemIf("fusedProject", project, !ObjectUtils.isEmpty(project))
.itemIf("fusedFilter", filters, !ObjectUtils.isEmpty(filters));
}
Expand All @@ -156,4 +165,8 @@ public void setFilters(ImmutableList<RexNode> filters) {
public @Nullable ImmutableList<RexNode> getFilters() {
return filters;
}

public AliasNameWithId getStartAlias() {
return startAlias;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.alibaba.graphscope.common.ir.rel.graph;

import com.alibaba.graphscope.common.ir.rel.type.AliasNameWithId;
import com.alibaba.graphscope.common.ir.rel.type.TableConfig;
import com.alibaba.graphscope.common.ir.tools.config.GraphOpt;

Expand All @@ -37,8 +38,9 @@ protected GraphLogicalExpand(
RelNode input,
GraphOpt.Expand opt,
TableConfig tableConfig,
@Nullable String alias) {
super(cluster, hints, input, tableConfig, alias);
@Nullable String alias,
AliasNameWithId startAlias) {
super(cluster, hints, input, tableConfig, alias, startAlias);
this.opt = opt;
}

Expand All @@ -48,8 +50,9 @@ public static GraphLogicalExpand create(
RelNode input,
GraphOpt.Expand opt,
TableConfig tableConfig,
@Nullable String alias) {
return new GraphLogicalExpand(cluster, hints, input, opt, tableConfig, alias);
@Nullable String alias,
AliasNameWithId startAlias) {
return new GraphLogicalExpand(cluster, hints, input, opt, tableConfig, alias, startAlias);
}

public GraphOpt.Expand getOpt() {
Expand All @@ -69,6 +72,7 @@ public GraphLogicalExpand copy(RelTraitSet traitSet, List<RelNode> inputs) {
inputs.get(0),
this.getOpt(),
this.tableConfig,
this.getAliasName());
this.getAliasName(),
this.getStartAlias());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.alibaba.graphscope.common.ir.rel.graph;

import com.alibaba.graphscope.common.ir.rel.type.AliasNameWithId;
import com.alibaba.graphscope.common.ir.rel.type.TableConfig;
import com.alibaba.graphscope.common.ir.tools.config.GraphOpt;

Expand All @@ -37,8 +38,9 @@ protected GraphLogicalGetV(
RelNode input,
GraphOpt.GetV opt,
TableConfig tableConfig,
@Nullable String alias) {
super(cluster, hints, input, tableConfig, alias);
@Nullable String alias,
AliasNameWithId startAlias) {
super(cluster, hints, input, tableConfig, alias, startAlias);
this.opt = opt;
}

Expand All @@ -48,8 +50,9 @@ public static GraphLogicalGetV create(
RelNode input,
GraphOpt.GetV opt,
TableConfig tableConfig,
@Nullable String alias) {
return new GraphLogicalGetV(cluster, hints, input, opt, tableConfig, alias);
@Nullable String alias,
AliasNameWithId startAlias) {
return new GraphLogicalGetV(cluster, hints, input, opt, tableConfig, alias, startAlias);
}

public GraphOpt.GetV getOpt() {
Expand All @@ -69,6 +72,7 @@ public GraphLogicalGetV copy(RelTraitSet traitSet, List<RelNode> inputs) {
inputs.get(0),
this.getOpt(),
this.tableConfig,
this.getAliasName());
this.getAliasName(),
this.getStartAlias());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.alibaba.graphscope.common.ir.rel.graph;

import com.alibaba.graphscope.common.ir.rel.type.AliasNameWithId;
import com.alibaba.graphscope.common.ir.tools.AliasInference;
import com.alibaba.graphscope.common.ir.tools.config.GraphOpt;
import com.alibaba.graphscope.common.ir.type.GraphPathType;
Expand Down Expand Up @@ -52,6 +53,8 @@ public class GraphLogicalPathExpand extends SingleRel {

private final int aliasId;

private final AliasNameWithId startAlias;

protected GraphLogicalPathExpand(
GraphOptCluster cluster,
@Nullable List<RelHint> hints,
Expand All @@ -62,7 +65,8 @@ protected GraphLogicalPathExpand(
@Nullable RexNode fetch,
GraphOpt.PathExpandResult resultOpt,
GraphOpt.PathExpandPath pathOpt,
@Nullable String aliasName) {
@Nullable String aliasName,
AliasNameWithId startAlias) {
super(cluster, RelTraitSet.createEmpty(), input);
this.expand = Objects.requireNonNull(expand);
this.getV = Objects.requireNonNull(getV);
Expand All @@ -74,6 +78,7 @@ protected GraphLogicalPathExpand(
AliasInference.inferDefault(
aliasName, AliasInference.getUniqueAliasList(input, true));
this.aliasId = cluster.getIdGenerator().generate(this.aliasName);
this.startAlias = Objects.requireNonNull(startAlias);
}

public static GraphLogicalPathExpand create(
Expand All @@ -86,9 +91,20 @@ public static GraphLogicalPathExpand create(
@Nullable RexNode fetch,
GraphOpt.PathExpandResult resultOpt,
GraphOpt.PathExpandPath pathOpt,
String aliasName) {
String aliasName,
AliasNameWithId startAlias) {
return new GraphLogicalPathExpand(
cluster, hints, input, expand, getV, offset, fetch, resultOpt, pathOpt, aliasName);
cluster,
hints,
input,
expand,
getV,
offset,
fetch,
resultOpt,
pathOpt,
aliasName,
startAlias);
}

@Override
Expand All @@ -100,7 +116,11 @@ public RelWriter explainTerms(RelWriter pw) {
.itemIf("fetch", fetch, fetch != null)
.item("path_opt", getPathOpt())
.item("result_opt", getResultOpt())
.item("alias", AliasInference.SIMPLE_NAME(getAliasName()));
.item("alias", AliasInference.SIMPLE_NAME(getAliasName()))
.itemIf(
"start_alias",
startAlias.getAliasName(),
startAlias.getAliasName() != AliasInference.DEFAULT_NAME);
}

public String getAliasName() {
Expand Down Expand Up @@ -135,6 +155,10 @@ public RelNode getGetV() {
return fetch;
}

public AliasNameWithId getStartAlias() {
return startAlias;
}

@Override
protected RelDataType deriveRowType() {
ObjectUtils.requireNonEmpty(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2020 Alibaba Group Holding Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.alibaba.graphscope.common.ir.rel.type;

import com.alibaba.graphscope.common.ir.tools.AliasInference;

public class AliasNameWithId {
public static final AliasNameWithId DEFAULT =
new AliasNameWithId(AliasInference.DEFAULT_NAME, AliasInference.DEFAULT_ID);

private final String aliasName;
private final int aliasId;

public AliasNameWithId(String aliasName, int aliasId) {
this.aliasName = aliasName;
this.aliasId = aliasId;
}

public String getAliasName() {
return aliasName;
}

public int getAliasId() {
return aliasId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ public RelNode visit(GraphLogicalExpand expand) {
if (expand.getAliasId() != AliasInference.DEFAULT_ID) {
checkFfiResult(LIB.setEdgexpdAlias(ptrExpand, ArgUtils.asAlias(expand.getAliasId())));
}
if (expand.getStartAlias().getAliasId() != AliasInference.DEFAULT_ID) {
checkFfiResult(
LIB.setEdgexpdVtag(
ptrExpand, ArgUtils.asNameOrId(expand.getStartAlias().getAliasId())));
}
checkFfiResult(
LIB.setEdgexpdMeta(
ptrExpand,
Expand Down Expand Up @@ -149,6 +154,11 @@ public RelNode visit(GraphLogicalGetV getV) {
if (getV.getAliasId() != AliasInference.DEFAULT_ID) {
checkFfiResult(LIB.setGetvAlias(ptrGetV, ArgUtils.asAlias(getV.getAliasId())));
}
if (getV.getStartAlias().getAliasId() != AliasInference.DEFAULT_ID) {
checkFfiResult(
LIB.setGetvTag(
ptrGetV, ArgUtils.asNameOrId(getV.getStartAlias().getAliasId())));
}
checkFfiResult(
LIB.setGetvMeta(
ptrGetV,
Expand All @@ -175,6 +185,11 @@ public RelNode visit(GraphLogicalPathExpand pxd) {
if (pxd.getAliasId() != AliasInference.DEFAULT_ID) {
checkFfiResult(LIB.setPathxpdAlias(ptrPxd, ArgUtils.asAlias(pxd.getAliasId())));
}
if (pxd.getStartAlias().getAliasId() != AliasInference.DEFAULT_ID) {
checkFfiResult(
LIB.setPathxpdTag(
ptrPxd, ArgUtils.asNameOrId(pxd.getStartAlias().getAliasId())));
}
return new PhysicalNode(pxd, ptrPxd);
}

Expand Down
Loading
Loading