use of com.alibaba.graphscope.gaia.plan.strategy.global.property.cache.ToFetchProperties in project GraphScope by alibaba.
the class StepPropertiesMeta method addProperties.
public void addProperties(ToFetchProperties properties) {
boolean isAll = properties.isAll() || this.properties.isAll();
List<String> add = new ArrayList<>();
if (!isAll) {
add.addAll(this.properties.getProperties());
add.addAll(properties.getProperties());
}
this.properties = new ToFetchProperties(isAll, add);
}
use of com.alibaba.graphscope.gaia.plan.strategy.global.property.cache.ToFetchProperties in project GraphScope by alibaba.
the class JobBuilderResource method attachResource.
@Override
public void attachResource(StepBuilder stepBuilder) {
AbstractBuilder target = stepBuilder.getJobBuilder();
Step step = stepBuilder.getStep();
buildJob(stepBuilder);
if (!step.getLabels().isEmpty() && target instanceof JobBuilder) {
// do nothing just as(tag)
Gremlin.QueryParams params = Gremlin.QueryParams.newBuilder().setRequiredProperties(PlanUtils.convertFrom(new ToFetchProperties(false, Collections.EMPTY_LIST))).build();
Gremlin.IdentityStep.Builder identityStep = Gremlin.IdentityStep.newBuilder().setQueryParams(params);
((JobBuilder) target).map(GremlinStepResource.createResourceBuilder(step, stepBuilder.getConf()).setIdentityStep(identityStep).build().toByteString());
}
}
use of com.alibaba.graphscope.gaia.plan.strategy.global.property.cache.ToFetchProperties in project GraphScope by alibaba.
the class CachePropGaiaGraphStep method cacheProperties.
@Override
public Gremlin.PropKeys cacheProperties() {
List<String> keys = new ArrayList<>();
List<HasContainer> containers = this.getHasContainers();
for (HasContainer container : containers) {
if (!container.getKey().equals(T.label.getAccessor()) && !container.getKey().equals(T.id.getAccessor())) {
keys.add(container.getKey());
}
}
keys.addAll(toFetchProperties.getProperties());
return PlanUtils.convertFrom(new ToFetchProperties(toFetchProperties.isAll(), keys));
}
use of com.alibaba.graphscope.gaia.plan.strategy.global.property.cache.ToFetchProperties in project GraphScope by alibaba.
the class TagKeyExtractor method modulateBy.
default Gremlin.ByKey modulateBy(Traversal.Admin value) {
Gremlin.ByKey.Builder builder = Gremlin.ByKey.newBuilder();
if (value == null || value instanceof IdentityTraversal) {
return Gremlin.ByKey.newBuilder().build();
} else if (value instanceof ElementValueTraversal) {
String propertyKey = ((ElementValueTraversal) value).getPropertyKey();
if (StringUtils.isNumeric(propertyKey)) {
builder.setKey(Common.Key.newBuilder().setNameId(Integer.valueOf(propertyKey)));
} else {
builder.setKey(Common.Key.newBuilder().setName(propertyKey));
}
} else if (value instanceof TokenTraversal) {
// resultKeys.add(((TokenTraversal) value).getToken().getAccessor());
T token = ((TokenTraversal) value).getToken();
if (token == T.label) {
builder.setKey(Common.Key.newBuilder().setLabel(Common.LabelKey.newBuilder()));
} else if (token == T.id) {
builder.setKey(Common.Key.newBuilder().setId(Common.IdKey.newBuilder()));
} else {
throw new UnsupportedOperationException("cannot support other T type " + token.name());
}
} else if (value instanceof ColumnTraversal) {
Column column = ((ColumnTraversal) value).getColumn();
if (column == Column.keys) {
builder.setMapKeys(Gremlin.MapKey.newBuilder());
} else {
builder.setMapValues(Gremlin.MapValue.newBuilder());
}
} else if (value != null && value.getSteps().size() == 1 && value.getStartStep() instanceof PropertyMapStep) {
PropertyMapStep propertyMapStep = (PropertyMapStep) value.getStartStep();
String[] propertyKeys = propertyMapStep.getPropertyKeys();
boolean needAllProps = (propertyKeys == null || propertyKeys.length == 0) ? true : false;
builder.setPropKeys(PlanUtils.convertFrom(new ToFetchProperties(needAllProps, Arrays.asList(propertyKeys))));
} else if (value != null && value.getSteps().size() == 1 && value.getStartStep() instanceof PropertiesStep) {
PropertiesStep propertiesStep = (PropertiesStep) value.getStartStep();
// todo: if value() -> fetch first from all properties (support by runtime)
if (propertiesStep.getPropertyKeys() != null && propertiesStep.getPropertyKeys().length > 0) {
String propertyKey = (propertiesStep.getPropertyKeys())[0];
if (StringUtils.isNumeric(propertyKey)) {
builder.setKey(Common.Key.newBuilder().setNameId(Integer.valueOf(propertyKey)));
} else {
builder.setKey(Common.Key.newBuilder().setName(propertyKey));
}
}
} else if (value != null && value instanceof PreBySubTraversal) {
builder.setComputed(Gremlin.SubValue.newBuilder());
} else if (value.getSteps().size() == 1 && value.getStartStep() instanceof TraversalMapStep) {
TraversalMapStep startStep = (TraversalMapStep) value.getStartStep();
Traversal.Admin mapTraversal = (Traversal.Admin) startStep.getLocalChildren().get(0);
if (!(mapTraversal instanceof ColumnTraversal)) {
throw new UnsupportedOperationException();
} else {
return modulateBy(mapTraversal);
}
} else if (value.getSteps().size() == 2 && (value.getStartStep() instanceof TraversalMapStep && value.getEndStep() instanceof PropertiesStep)) {
TraversalMapStep startStep = (TraversalMapStep) value.getStartStep();
Traversal.Admin mapTraversal = (Traversal.Admin) startStep.getLocalChildren().get(0);
if (!(mapTraversal instanceof ColumnTraversal)) {
throw new UnsupportedOperationException();
} else {
Gremlin.ByKey selectMap = modulateBy(mapTraversal);
PropertiesStep valuePropertiesStep = (PropertiesStep) value.getEndStep();
Traversal.Admin tmp = new DefaultTraversal();
tmp.addStep(new PropertiesStep(tmp, valuePropertiesStep.getReturnType(), valuePropertiesStep.getPropertyKeys()));
// select(keys).values("xxx")
Gremlin.ByKey selectMapWithValue = modulateBy(tmp);
if (selectMap.getItemCase() == Gremlin.ByKey.ItemCase.MAP_KEYS) {
return Gremlin.ByKey.newBuilder().setMapKeys(Gremlin.MapKey.newBuilder().setKey(selectMapWithValue.getKey())).build();
} else {
return Gremlin.ByKey.newBuilder().setMapValues(Gremlin.MapValue.newBuilder().setKey(selectMapWithValue.getKey())).build();
}
}
} else {
throw new UnsupportedOperationException("cannot support other value traversal " + value);
}
return builder.build();
}
Aggregations