use of com.alibaba.graphscope.gaia.store.GraphType 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);
}
}
Aggregations