Skip to content

Commit

Permalink
fix(interactive): Unify Error Code in Compiler (#4182)
Browse files Browse the repository at this point in the history
Co-authored-by: fangfcg <[email protected]>
Co-authored-by: BingqingLyu <[email protected]>
Co-authored-by: xiaolei.zl <[email protected]>
  • Loading branch information
4 people authored Aug 29, 2024
1 parent c9afcb1 commit 387e33b
Show file tree
Hide file tree
Showing 35 changed files with 759 additions and 322 deletions.
2 changes: 1 addition & 1 deletion interactive_engine/compiler/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ gremlin_calcite_test:

run:
cd $(CUR_DIR) && $(java) \
-cp ".:./target/libs/*:./target/compiler-0.0.1-SNAPSHOT.jar" \
-cp ".:./target/compiler-0.0.1-SNAPSHOT.jar:./target/libs/*" \
-Djna.library.path=../executor/ir/target/release \
-Dgraph.schema=${graph.schema} \
-Dgraph.store=${graph.store} \
Expand Down
18 changes: 17 additions & 1 deletion interactive_engine/compiler/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,28 @@
<pluginId>grpc-java</pluginId>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier}
</pluginArtifact>
<protoSourceRoot>${project.basedir}/../executor/ir/proto</protoSourceRoot>
<outputDirectory>src/main/generated/</outputDirectory>
<clearOutputDirectory>false</clearOutputDirectory>
</configuration>
<executions>
<execution>
<id>error-code</id>
<configuration>
<protoSourceRoot>${project.basedir}/../../proto/error</protoSourceRoot>
<includes>
<include>frontend.proto</include>
</includes>
</configuration>
<goals>
<goal>compile</goal>
<goal>compile-custom</goal>
</goals>
</execution>
<execution>
<id>ir-proto</id>
<configuration>
<protoSourceRoot>${project.basedir}/../executor/ir/proto</protoSourceRoot>
</configuration>
<goals>
<goal>compile</goal>
<goal>compile-custom</goal>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,19 @@
import com.alibaba.graphscope.common.config.Configs;
import com.alibaba.graphscope.common.config.FrontendConfig;
import com.alibaba.graphscope.common.config.GraphConfig;
import com.alibaba.graphscope.common.ir.meta.IrMeta;
import com.alibaba.graphscope.common.ir.meta.IrMetaTracker;
import com.alibaba.graphscope.common.ir.meta.fetcher.DynamicIrMetaFetcher;
import com.alibaba.graphscope.common.ir.meta.fetcher.IrMetaFetcher;
import com.alibaba.graphscope.common.ir.meta.fetcher.StaticIrMetaFetcher;
import com.alibaba.graphscope.common.ir.meta.reader.HttpIrMetaReader;
import com.alibaba.graphscope.common.ir.meta.reader.LocalIrMetaReader;
import com.alibaba.graphscope.common.ir.planner.GraphRelOptimizer;
import com.alibaba.graphscope.common.ir.tools.*;
import com.alibaba.graphscope.common.ir.tools.GraphPlanner;
import com.alibaba.graphscope.common.ir.tools.LogicalPlanFactory;
import com.alibaba.graphscope.common.ir.tools.QueryCache;
import com.alibaba.graphscope.common.ir.tools.QueryIdGenerator;
import com.alibaba.graphscope.common.manager.IrMetaQueryCallback;
import com.alibaba.graphscope.cypher.antlr4.parser.CypherAntlr4Parser;
import com.alibaba.graphscope.cypher.antlr4.visitor.LogicalPlanVisitor;
import com.alibaba.graphscope.cypher.service.CypherBootstrapper;
import com.alibaba.graphscope.gremlin.antlr4x.parser.GremlinAntlr4Parser;
import com.alibaba.graphscope.gremlin.antlr4x.visitor.GraphBuilderVisitor;
import com.alibaba.graphscope.gremlin.integration.result.GraphProperties;
import com.alibaba.graphscope.gremlin.integration.result.TestGraphFactory;
import com.alibaba.graphscope.gremlin.service.IrGremlinServer;
Expand Down Expand Up @@ -86,14 +84,7 @@ public void start() throws Exception {
QueryIdGenerator idGenerator = new QueryIdGenerator(configs);
if (!FrontendConfig.GREMLIN_SERVER_DISABLED.get(configs)) {
GraphPlanner graphPlanner =
new GraphPlanner(
configs,
(GraphBuilder builder, IrMeta irMeta, String query) ->
new LogicalPlan(
new GraphBuilderVisitor(builder)
.visit(new GremlinAntlr4Parser().parse(query))
.build()),
optimizer);
new GraphPlanner(configs, new LogicalPlanFactory.Gremlin(), optimizer);
QueryCache queryCache = new QueryCache(configs, graphPlanner);
this.gremlinServer =
new IrGremlinServer(
Expand All @@ -108,12 +99,7 @@ public void start() throws Exception {
}
if (!FrontendConfig.NEO4J_BOLT_SERVER_DISABLED.get(configs)) {
GraphPlanner graphPlanner =
new GraphPlanner(
configs,
(GraphBuilder builder, IrMeta irMeta, String query) ->
new LogicalPlanVisitor(builder, irMeta)
.visit(new CypherAntlr4Parser().parse(query)),
optimizer);
new GraphPlanner(configs, new LogicalPlanFactory.Cypher(), optimizer);
QueryCache queryCache = new QueryCache(configs, graphPlanner);
this.cypherBootstrapper =
new CypherBootstrapper(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,7 @@ public class FrontendConfig {

public static final Config<Integer> PER_QUERY_STREAM_BUFFER_MAX_CAPACITY =
Config.intConfig("per.query.stream.buffer.max.capacity", 256);

public static final Config<Long> QUERY_PRINT_THRESHOLD_MS =
Config.longConfig("query.print.threshold.ms", 200l);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
*
* * 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.exception;

public enum ComponentCode {
FRONTEND(3);

private final int value;

ComponentCode(int value) {
this.value = value;
}

public int getValue() {
return value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
*
* * 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.exception;

import org.checkerframework.checker.nullness.qual.Nullable;

public class ExecutionException extends RuntimeException {
public ExecutionException(String msg, @Nullable Throwable t) {
super(msg);
if (t != null) {
setStackTrace(t.getStackTrace());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
*
* * 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.exception;

import com.alibaba.graphscope.proto.frontend.Code;
import com.google.common.collect.Maps;

import org.checkerframework.checker.nullness.qual.Nullable;

import java.util.Map;

public class FrontendException extends RuntimeException {
private final ComponentCode componentCode;
private final Code errorCode;
private final Map<String, Object> details;

public FrontendException(Code errorCode, String errorMsg) {
this(errorCode, errorMsg, null);
}

public FrontendException(Code errorCode, String errorMsg, @Nullable Throwable cause) {
this(errorCode, errorMsg, Maps.newHashMap(), cause);
}

public FrontendException(
Code errorCode,
String errorMsg,
Map<String, Object> details,
@Nullable Throwable cause) {
super(errorMsg);
if (cause != null) {
setStackTrace(cause.getStackTrace());
}
this.componentCode = ComponentCode.FRONTEND;
this.errorCode = errorCode;
this.details = Maps.newHashMap(details);
}

public Map getDetails() {
return this.details;
}

public Code getErrorCode() {
return errorCode;
}

@Override
public String getMessage() {
StringBuilder sb = new StringBuilder();
sb.append("ErrorCode: ").append(errorCode.name()).append("\n");
String msg = super.getMessage();
if (!msg.endsWith("\n")) {
msg += "\n";
}
sb.append("Message: ").append(msg);
sb.append("EC: ")
.append(String.format("%02d-%04d", componentCode.getValue(), errorCode.getNumber()))
.append("\n");
details.forEach(
(k, v) -> {
sb.append(k).append(": ").append(v).append("\n");
});
return sb.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@

package com.alibaba.graphscope.common.ir.meta.schema;

import com.alibaba.graphscope.common.exception.FrontendException;
import com.alibaba.graphscope.groot.common.exception.TypeNotFoundException;
import com.alibaba.graphscope.groot.common.schema.api.GraphElement;
import com.alibaba.graphscope.proto.frontend.Code;

import org.apache.calcite.plan.RelOptCluster;
import org.apache.calcite.plan.RelOptPlanner;
import org.apache.calcite.plan.RelOptSchema;
import org.apache.calcite.plan.RelOptTable;
import org.apache.calcite.rel.type.RelDataTypeFactory;
import org.apache.calcite.util.Static;
import org.apache.commons.lang3.ObjectUtils;
import org.checkerframework.checker.nullness.qual.Nullable;

Expand Down Expand Up @@ -58,7 +59,8 @@ public RelOptTable getTableForMember(List<String> tableName) {
GraphElement element = rootSchema.getElement(labelName);
return createRelOptTable(tableName, element);
} catch (TypeNotFoundException e) {
throw Static.RESOURCE.tableNotFound(labelName).ex();
throw new FrontendException(
Code.LABEL_NOT_FOUND, "Table '" + labelName + "' not found", e);
}
}

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

import com.alibaba.graphscope.common.config.Configs;
import com.alibaba.graphscope.common.config.FrontendConfig;
import com.alibaba.graphscope.common.exception.FrontendException;
import com.alibaba.graphscope.common.ir.meta.schema.GraphOptSchema;
import com.alibaba.graphscope.common.ir.meta.schema.IrGraphSchema;
import com.alibaba.graphscope.common.ir.rel.*;
Expand All @@ -38,6 +39,7 @@
import com.alibaba.graphscope.common.ir.tools.config.*;
import com.alibaba.graphscope.common.ir.type.*;
import com.alibaba.graphscope.gremlin.Utils;
import com.alibaba.graphscope.proto.frontend.Code;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
Expand Down Expand Up @@ -490,7 +492,8 @@ public RexGraphVariable variable(@Nullable String alias, String property) {
String varName = AliasInference.SIMPLE_NAME(alias) + AliasInference.DELIMITER + property;
List<ColumnField> columnFields = getAliasField(alias);
if (columnFields.size() != 1) {
throw new IllegalArgumentException(
throw new FrontendException(
Code.PROPERTY_NOT_FOUND,
"cannot get property="
+ property
+ " from alias="
Expand All @@ -502,7 +505,8 @@ public RexGraphVariable variable(@Nullable String alias, String property) {
RelDataTypeField aliasField = columnField.right;
if (property.equals(GraphProperty.LEN_KEY)) {
if (!(aliasField.getType() instanceof GraphPathType)) {
throw new ClassCastException(
throw new FrontendException(
Code.PROPERTY_NOT_FOUND,
"cannot get property='len' from type class ["
+ aliasField.getType().getClass()
+ "], should be ["
Expand All @@ -518,7 +522,8 @@ public RexGraphVariable variable(@Nullable String alias, String property) {
}
}
if (!(aliasField.getType() instanceof GraphSchemaType)) {
throw new ClassCastException(
throw new FrontendException(
Code.PROPERTY_NOT_FOUND,
"cannot get property=['id', 'label', 'all', 'key'] from type class ["
+ aliasField.getType().getClass()
+ "], should be ["
Expand Down Expand Up @@ -549,7 +554,8 @@ public RexGraphVariable variable(@Nullable String alias, String property) {
getTypeFactory().createSqlType(SqlTypeName.ANY));
} else if (property.equals(GraphProperty.START_V_KEY)) {
if (!(aliasField.getType() instanceof GraphPathType)) {
throw new ClassCastException(
throw new FrontendException(
Code.PROPERTY_NOT_FOUND,
"cannot get property='start_v' from type class ["
+ aliasField.getType().getClass()
+ "], should be ["
Expand All @@ -571,7 +577,8 @@ public RexGraphVariable variable(@Nullable String alias, String property) {
}
} else if (property.equals(GraphProperty.END_V_KEY)) {
if (!(aliasField.getType() instanceof GraphPathType)) {
throw new ClassCastException(
throw new FrontendException(
Code.PROPERTY_NOT_FOUND,
"cannot get property='end_v' from type class ["
+ aliasField.getType().getClass()
+ "], should be ["
Expand Down Expand Up @@ -606,7 +613,8 @@ public RexGraphVariable variable(@Nullable String alias, String property) {
}
properties.add(pField.getName());
}
throw new IllegalArgumentException(
throw new FrontendException(
Code.PROPERTY_NOT_FOUND,
"{property="
+ property
+ "} "
Expand Down Expand Up @@ -684,7 +692,8 @@ private List<ColumnField> getAliasField(String alias) {
inputQueue.addAll(cur.getInputs());
}
}
throw new IllegalArgumentException(
throw new FrontendException(
Code.TAG_NOT_FOUND,
"{alias="
+ AliasInference.SIMPLE_NAME(alias)
+ "} "
Expand Down
Loading

0 comments on commit 387e33b

Please sign in to comment.