use of com.alibaba.graphscope.gaia.store.SchemaNotFoundException in project GraphScope by alibaba.
the class SchemaIdMakerStrategy method apply.
@Override
public void apply(Traversal.Admin<?, ?> traversal) {
try {
// label string -> label id
List<Step> steps = traversal.getSteps();
for (int i = 0; i < steps.size(); ++i) {
Step step = steps.get(i);
if (step instanceof HasContainerHolder) {
List<HasContainer> containers = ((HasContainerHolder) step).getHasContainers();
for (HasContainer container : containers) {
if (container.getKey().equals(T.label.getAccessor())) {
P predicate = container.getPredicate();
if (predicate.getValue() instanceof List && ((List) predicate.getValue()).get(0) instanceof String) {
List<String> values = (List<String>) predicate.getValue();
predicate.setValue(values.stream().map(k -> {
if (StringUtils.isNumeric(k)) {
return k;
} else {
long labelId = graphStore.getLabelId(k);
return String.valueOf(labelId);
}
}).collect(Collectors.toList()));
} else if (predicate.getValue() instanceof String) {
String value = (String) predicate.getValue();
if (StringUtils.isNumeric(value)) {
predicate.setValue(value);
} else {
long labelId = graphStore.getLabelId(value);
predicate.setValue(String.valueOf(labelId));
}
} else {
throw new UnsupportedOperationException("hasLabel value type not support " + predicate.getValue().getClass());
}
}
}
} else if (step instanceof VertexStep) {
String[] edgeLabels = ((VertexStep) step).getEdgeLabels();
for (int j = 0; j < edgeLabels.length; ++j) {
if (StringUtils.isNumeric(edgeLabels[j])) {
// do nothing
} else {
long labelId = graphStore.getLabelId(edgeLabels[j]);
edgeLabels[j] = String.valueOf(labelId);
}
}
}
}
GraphType graphType = config.getGraphType();
// property string -> property id
if (graphType == GraphType.MAXGRAPH) {
for (int i = 0; i < steps.size(); ++i) {
Step step = steps.get(i);
if (step instanceof HasContainerHolder) {
List<HasContainer> containers = ((HasContainerHolder) step).getHasContainers();
for (HasContainer container : containers) {
container.setKey(PlanUtils.convertToPropertyId(graphStore, container.getKey()));
}
} else if (step instanceof PropertiesStep || step instanceof PropertyMapStep) {
String[] oldKeys;
if (step instanceof PropertiesStep) {
oldKeys = ((PropertiesStep) step).getPropertyKeys();
} else {
oldKeys = ((PropertyMapStep) step).getPropertyKeys();
}
String[] newKeys = Arrays.stream(oldKeys).map(k -> PlanUtils.convertToPropertyId(graphStore, k)).toArray(String[]::new);
FieldUtils.writeField(step, "propertyKeys", newKeys, true);
} else if (step instanceof ByModulating) {
TraversalParent byParent = (TraversalParent) step;
for (Traversal.Admin k : byParent.getLocalChildren()) {
if (k instanceof ElementValueTraversal) {
ElementValueTraversal value = (ElementValueTraversal) k;
String propertyId = PlanUtils.convertToPropertyId(graphStore, value.getPropertyKey());
FieldUtils.writeField(value, "propertyKey", propertyId, true);
}
}
}
}
}
} catch (SchemaNotFoundException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of com.alibaba.graphscope.gaia.store.SchemaNotFoundException in project GraphScope by alibaba.
the class TraversalOpProcessor method select.
@Override
public ThrowingConsumer<Context> select(Context ctx) throws OpProcessorException {
final RequestMessage message = ctx.getRequestMessage();
final ThrowingConsumer<Context> op;
final GremlinExecutor executor = ctx.getGremlinExecutor();
final SimpleBindings b = new SimpleBindings();
final Map<String, String> aliases = (Map<String, String>) message.optionalArgs(Tokens.ARGS_ALIASES).get();
final String traversalSourceName = aliases.entrySet().iterator().next().getValue();
logger.info("tokens ops is {}", message.getOp());
if (config.getGraphType() == GraphType.MAXGRAPH) {
graphStore.updateSnapShotId();
}
switch(message.getOp()) {
case Tokens.OPS_BYTECODE:
op = (context -> {
try {
Object byteCode = message.getArgs().get(Tokens.ARGS_GREMLIN);
Traversal traversal = executor.eval((Bytecode) byteCode, new SimpleBindings(), null, traversalSourceName);
GaiaGraphOpProcessor.applyStrategy(traversal, config, graphStore);
long queryId = (long) queryIdMaker.getId(traversal);
TraversalBuilder traversalBuilder = new TraversalBuilder((Traversal.Admin) traversal).addConfig(PlanConfig.QUERY_ID, queryId).addConfig(PlanConfig.TAG_ID_MAKER, new TagIdMaker((Traversal.Admin) traversal)).addConfig(PlanConfig.QUERY_CONFIG, PlanUtils.getDefaultConfig(queryId, config));
if (config.getGraphType() == GraphType.MAXGRAPH) {
traversalBuilder.addConfig(PlanConfig.SNAPSHOT_ID, Long.valueOf(graphStore.getSnapShotId()));
}
AbstractBuilder jobReqBuilder = new TraversalTranslator(traversalBuilder).translate();
PlanUtils.print(jobReqBuilder);
broadcastProcessor.broadcast(jobReqBuilder.build(), new GremlinResultProcessor(ctx, new RemoteTraverserResultParser(traversalBuilder, graphStore, config)));
logger.info("query-{} finish", queryId);
} catch (SchemaNotFoundException e) {
throw new OpProcessorException("schema not found error", ResponseMessage.build(message).code(ResponseStatusCode.SUCCESS).result(Collections.EMPTY_LIST).create());
}
});
return op;
case Tokens.OPS_KEYS:
GaiaGraphOpProcessor.writeResultList(ctx, Collections.EMPTY_LIST, ResponseStatusCode.SUCCESS);
return null;
default:
String errorMsg = "not support " + message.getOp();
GaiaGraphOpProcessor.writeResultList(ctx, Collections.singletonList(errorMsg), ResponseStatusCode.REQUEST_ERROR_INVALID_REQUEST_ARGUMENTS);
return null;
}
}
use of com.alibaba.graphscope.gaia.store.SchemaNotFoundException in project GraphScope by alibaba.
the class AbstractGraphOpProcessor method evalOpInternal.
@Override
protected void evalOpInternal(Context ctx, Supplier<GremlinExecutor> gremlinExecutorSupplier, BindingSupplier bindingsSupplier) throws OpProcessorException {
final Timer.Context timerContext = evalOpTimer.time();
final RequestMessage msg = ctx.getRequestMessage();
final GremlinExecutor gremlinExecutor = gremlinExecutorSupplier.get();
final Map<String, Object> args = msg.getArgs();
final String script = (String) args.get(Tokens.ARGS_GREMLIN);
logger.info("script is {}", script);
final String language = args.containsKey(Tokens.ARGS_LANGUAGE) ? (String) args.get(Tokens.ARGS_LANGUAGE) : null;
final Bindings bindings = new SimpleBindings();
final GremlinExecutor.LifeCycle lifeCycle = createLifeCycle(ctx, gremlinExecutorSupplier, bindingsSupplier);
final CompletableFuture<Object> evalFuture = gremlinExecutor.eval(script, language, bindings, lifeCycle);
evalFuture.handle((v, t) -> {
long elapsed = timerContext.stop();
logger.info("query {} total execution time is {} ms", script, elapsed / 1000000.0f);
ResponseHandlerContext rhc = new ResponseHandlerContext(ctx);
if (t != null) {
if (t instanceof OpProcessorException) {
rhc.writeAndFlush(((OpProcessorException) t).getResponseMessage());
} else if (t instanceof TimedInterruptTimeoutException) {
// occurs when the TimedInterruptCustomizerProvider is in play
final String errorMessage = String.format("A timeout occurred within the script during evaluation" + " of [%s] - consider increasing the limit given" + " to TimedInterruptCustomizerProvider", msg);
logger.warn(errorMessage);
rhc.writeAndFlush(ResponseMessage.build(msg).code(ResponseStatusCode.SERVER_ERROR_TIMEOUT).statusMessage("Timeout during script evaluation triggered by" + " TimedInterruptCustomizerProvider").statusAttributeException(t).create());
} else if (t instanceof TimeoutException) {
final String errorMessage = String.format("Script evaluation exceeded the configured threshold" + " for request [%s]", msg);
logger.warn(errorMessage, t);
rhc.writeAndFlush(ResponseMessage.build(msg).code(ResponseStatusCode.SERVER_ERROR_TIMEOUT).statusMessage(t.getMessage()).statusAttributeException(t).create());
} else if (t instanceof SchemaNotFoundException) {
writeResultList(ctx, Collections.EMPTY_LIST, ResponseStatusCode.SUCCESS);
} else {
if (t instanceof MultipleCompilationErrorsException && t.getMessage().contains("Method too large") && ((MultipleCompilationErrorsException) t).getErrorCollector().getErrorCount() == 1) {
final String errorMessage = String.format("The Gremlin statement that was submitted exceeds" + " the maximum compilation size allowed by the" + " JVM, please split it into multiple smaller" + " statements");
logger.warn(errorMessage);
rhc.writeAndFlush(ResponseMessage.build(msg).code(ResponseStatusCode.SERVER_ERROR_SCRIPT_EVALUATION).statusMessage(errorMessage).statusAttributeException(t).create());
} else {
final String errorMessage = (t.getMessage() == null) ? t.toString() : t.getMessage();
logger.warn(String.format("Exception processing a script on request [%s].", msg), t);
rhc.writeAndFlush(ResponseMessage.build(msg).code(ResponseStatusCode.SERVER_ERROR_SCRIPT_EVALUATION).statusMessage(errorMessage).statusAttributeException(t).create());
}
}
}
return null;
});
}
Aggregations