Skip to content

Commit

Permalink
fix(interactive): Fix Bugs in Dynamic Params (#3279)
Browse files Browse the repository at this point in the history
<!--
Thanks for your contribution! please review
https://github.com/alibaba/GraphScope/blob/main/CONTRIBUTING.md before
opening an issue.
-->

## What do these changes do?
Fix bugs in dynamic params:
1. Fix bugs where multiple dynamic parameters with the same name
appeared in a query.
2. Fix bugs in dynamic parameter type inference when dynamic parameter
is nested in a complex expression (i.e. $age + 1).

## Related issue number

<!-- Are there any issues opened that will be resolved by merging this
change? -->

Fixes
  • Loading branch information
shirly121 authored Oct 19, 2023
1 parent dc08671 commit ff8a795
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import org.apache.calcite.sql.SqlKind;
import org.apache.calcite.sql.SqlOperator;
import org.apache.calcite.sql.type.BasicSqlType;
import org.apache.calcite.sql.type.GraphInferTypes;
import org.apache.calcite.sql.type.IntervalSqlType;
import org.apache.calcite.sql.type.SqlTypeName;
import org.apache.calcite.tools.RelBuilder;
Expand Down Expand Up @@ -572,6 +573,11 @@ private RexNode call_(SqlOperator operator, List<RexNode> operandList) {
throw new UnsupportedOperationException(
"operator " + operator.getKind().name() + " not supported");
}
// infer unknown operands types from other known types
if (operator.getOperandTypeInference() != GraphInferTypes.RETURN_TYPE) {
operandList =
inferOperandTypes(operator, getTypeFactory().createUnknownType(), operandList);
}
RexCallBinding callBinding =
new RexCallBinding(getTypeFactory(), operator, operandList, ImmutableList.of());
// check count of operands, if fail throw exceptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ public int generate(@Nullable String paramName) {
}

public ImmutableMap<Integer, String> getDynamicParams() {
return this.paramsBuilder.build();
return this.paramsBuilder.buildKeepingLast();
}

private RexLiteral createIntervalLiteral(String fieldName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.alibaba.graphscope.common.ir;

import com.alibaba.graphscope.common.ir.tools.GraphBuilder;
import com.alibaba.graphscope.common.ir.tools.GraphRexBuilder;
import com.alibaba.graphscope.common.ir.tools.GraphStdOperatorTable;
import com.alibaba.graphscope.common.ir.tools.config.GraphOpt;
import com.alibaba.graphscope.common.ir.tools.config.LabelConfig;
Expand Down Expand Up @@ -169,6 +170,18 @@ public void unary_minus_test() {
Assert.assertEquals("-(a.age)", node.toString());
}

// @age + 1
@Test
public void dynamic_param_type_test() {
GraphRexBuilder rexBuilder = (GraphRexBuilder) builder.getRexBuilder();
RexNode plus =
builder.call(
GraphStdOperatorTable.PLUS,
rexBuilder.makeGraphDynamicParam("age", 0),
builder.literal(1));
Assert.assertEquals(SqlTypeName.INTEGER, plus.getType().getSqlTypeName());
}

private SourceConfig mockSourceConfig(String alias) {
return new SourceConfig(
GraphOpt.Source.VERTEX, new LabelConfig(false).addLabel("person"), alias);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,4 +291,24 @@ public void match_15_test() {
+ "], matchOpt=[INNER])",
node.explain().trim());
}

@Test
public void match_16_test() {
RelNode node =
Utils.eval(
"Match (a:person {name: $name})-[b]->(c:person {name: $name})"
+ " Return a, c")
.build();
Assert.assertEquals(
"GraphLogicalProject(a=[a], c=[c], isAppend=[false])\n"
+ " GraphLogicalSingleMatch(input=[null],"
+ " sentence=[GraphLogicalGetV(tableConfig=[{isAll=false, tables=[person]}],"
+ " alias=[c], fusedFilter=[[=(DEFAULT.name, ?0)]], opt=[END])\n"
+ " GraphLogicalExpand(tableConfig=[{isAll=true, tables=[created, knows]}],"
+ " alias=[b], opt=[OUT])\n"
+ " GraphLogicalSource(tableConfig=[{isAll=false, tables=[person]}],"
+ " alias=[a], fusedFilter=[[=(DEFAULT.name, ?0)]], opt=[VERTEX])\n"
+ "], matchOpt=[INNER])",
node.explain().trim());
}
}

0 comments on commit ff8a795

Please sign in to comment.