public boolean isEdgeTable() { return !isVertexTable(); }
public boolean isEdgeTable() { return !isVertexTable(); }
Map<String, PropertyColumn> getPropertiesFor(SchemaTable schemaTable) { Preconditions.checkArgument(schemaTable.getTable().startsWith(VERTEX_PREFIX) || schemaTable.getTable().startsWith(EDGE_PREFIX), "label must start with \"%s\" or \"%s\"", Topology.VERTEX_PREFIX, Topology.EDGE_PREFIX); if (schemaTable.isVertexTable()) { Optional<VertexLabel> vertexLabelOptional = getVertexLabel(schemaTable.withOutPrefix().getTable()); if (vertexLabelOptional.isPresent()) { return vertexLabelOptional.get().getProperties(); } } else { Optional<EdgeLabel> edgeLabelOptional = getEdgeLabel(schemaTable.withOutPrefix().getTable()); if (edgeLabelOptional.isPresent()) { return edgeLabelOptional.get().getProperties(); } } return Collections.emptyMap(); }
Map<String, PropertyColumn> getPropertiesWithGlobalUniqueIndexFor(SchemaTable schemaTable) { Preconditions.checkArgument(schemaTable.getTable().startsWith(VERTEX_PREFIX) || schemaTable.getTable().startsWith(EDGE_PREFIX), "label must start with \"%s\" or \"%s\"", VERTEX_PREFIX, EDGE_PREFIX); if (schemaTable.isVertexTable()) { Optional<VertexLabel> vertexLabelOptional = getVertexLabel(schemaTable.withOutPrefix().getTable()); if (vertexLabelOptional.isPresent()) { return vertexLabelOptional.get().getGlobalUniqueIndexProperties(); } } else { Optional<EdgeLabel> edgeLabelOptional = getEdgeLabel(schemaTable.withOutPrefix().getTable()); if (edgeLabelOptional.isPresent()) { return edgeLabelOptional.get().getGlobalUniqueIndexProperties(); } } return Collections.emptyMap(); }
Map<String, PropertyType> getTableFor(SchemaTable schemaTable) { Preconditions.checkArgument(schemaTable.getTable().startsWith(VERTEX_PREFIX) || schemaTable.getTable().startsWith(EDGE_PREFIX), "label must start with \"%s\" or \"%s\"", VERTEX_PREFIX, EDGE_PREFIX); if (schemaTable.isVertexTable()) { Optional<VertexLabel> vertexLabelOptional = getVertexLabel(schemaTable.withOutPrefix().getTable()); if (vertexLabelOptional.isPresent()) { return vertexLabelOptional.get().getPropertyTypeMap(); } } else { Optional<EdgeLabel> edgeLabelOptional = getEdgeLabel(schemaTable.withOutPrefix().getTable()); if (edgeLabelOptional.isPresent()) { return edgeLabelOptional.get().getPropertyTypeMap(); } } return Collections.emptyMap(); }
Map<String, PropertyType> getTableFor(SchemaTable schemaTable) { Preconditions.checkArgument(schemaTable.getTable().startsWith(VERTEX_PREFIX) || schemaTable.getTable().startsWith(EDGE_PREFIX), "label must start with \"%s\" or \"%s\"", VERTEX_PREFIX, EDGE_PREFIX); if (schemaTable.isVertexTable()) { Optional<VertexLabel> vertexLabelOptional = getVertexLabel(schemaTable.withOutPrefix().getTable()); if (vertexLabelOptional.isPresent()) { return vertexLabelOptional.get().getPropertyTypeMap(); } } else { Optional<EdgeLabel> edgeLabelOptional = getEdgeLabel(schemaTable.withOutPrefix().getTable()); if (edgeLabelOptional.isPresent()) { return edgeLabelOptional.get().getPropertyTypeMap(); } } return Collections.emptyMap(); }
private boolean hasNoEdgeLabels(SchemaTable schemaTable) { Optional<Schema> schemaOptional = sqlgGraph.getTopology().getSchema(schemaTable.getSchema()); Preconditions.checkState(schemaOptional.isPresent(), "BUG: %s not found in the topology.", schemaTable.getSchema()); Schema schema = schemaOptional.get(); boolean result = true; if (schemaTable.isVertexTable()) { //Need to delete any in/out edges. Optional<VertexLabel> vertexLabelOptional = schema.getVertexLabel(schemaTable.withOutPrefix().getTable()); Preconditions.checkState(vertexLabelOptional.isPresent(), "BUG: %s not found in the topology.", schemaTable.withOutPrefix().getTable()); VertexLabel vertexLabel = vertexLabelOptional.get(); Collection<EdgeLabel> outEdgeLabels = vertexLabel.getOutEdgeLabels().values(); Collection<EdgeLabel> inEdgeLabels = vertexLabel.getInEdgeLabels().values(); result = outEdgeLabels.isEmpty() && inEdgeLabels.isEmpty(); } return result; }
private boolean hasNoEdgeLabels(SchemaTable schemaTable) { Optional<Schema> schemaOptional = sqlgGraph.getTopology().getSchema(schemaTable.getSchema()); Preconditions.checkState(schemaOptional.isPresent(), "BUG: %s not found in the topology.", schemaTable.getSchema()); Schema schema = schemaOptional.get(); boolean result = true; if (schemaTable.isVertexTable()) { //Need to delete any in/out edges. Optional<VertexLabel> vertexLabelOptional = schema.getVertexLabel(schemaTable.withOutPrefix().getTable()); Preconditions.checkState(vertexLabelOptional.isPresent(), "BUG: %s not found in the topology.", schemaTable.withOutPrefix().getTable()); VertexLabel vertexLabel = vertexLabelOptional.get(); Collection<EdgeLabel> outEdgeLabels = vertexLabel.getOutEdgeLabels().values(); Collection<EdgeLabel> inEdgeLabels = vertexLabel.getInEdgeLabels().values(); result = outEdgeLabels.isEmpty() && inEdgeLabels.isEmpty(); } return result; }
Map<String, PropertyColumn> getPropertiesFor(SchemaTable schemaTable) { Preconditions.checkArgument(schemaTable.getTable().startsWith(VERTEX_PREFIX) || schemaTable.getTable().startsWith(EDGE_PREFIX), "label must start with \"%s\" or \"%s\"", Topology.VERTEX_PREFIX, Topology.EDGE_PREFIX); if (schemaTable.isVertexTable()) { Optional<VertexLabel> vertexLabelOptional = getVertexLabel(schemaTable.withOutPrefix().getTable()); if (vertexLabelOptional.isPresent()) { return vertexLabelOptional.get().getProperties(); } } else { Optional<EdgeLabel> edgeLabelOptional = getEdgeLabel(schemaTable.withOutPrefix().getTable()); if (edgeLabelOptional.isPresent()) { return edgeLabelOptional.get().getProperties(); } } return Collections.emptyMap(); }
Map<String, PropertyColumn> getPropertiesWithGlobalUniqueIndexFor(SchemaTable schemaTable) { Preconditions.checkArgument(schemaTable.getTable().startsWith(VERTEX_PREFIX) || schemaTable.getTable().startsWith(EDGE_PREFIX), "label must start with \"%s\" or \"%s\"", VERTEX_PREFIX, EDGE_PREFIX); if (schemaTable.isVertexTable()) { Optional<VertexLabel> vertexLabelOptional = getVertexLabel(schemaTable.withOutPrefix().getTable()); if (vertexLabelOptional.isPresent()) { return vertexLabelOptional.get().getGlobalUniqueIndexProperties(); } } else { Optional<EdgeLabel> edgeLabelOptional = getEdgeLabel(schemaTable.withOutPrefix().getTable()); if (edgeLabelOptional.isPresent()) { return edgeLabelOptional.get().getGlobalUniqueIndexProperties(); } } return Collections.emptyMap(); }
public static void constructDistinctOptionalQueries(SchemaTableTree current, List<Pair<LinkedList<SchemaTableTree>, Set<SchemaTableTree>>> result) { LinkedList<SchemaTableTree> stack = current.constructQueryStackFromLeaf(); //left joins but not the leave nodes as they are already present in the main sql result set. if (current.isOptionalLeftJoin() && (current.getStepDepth() < current.getReplacedStepDepth())) { Set<SchemaTableTree> leftyChildren = new HashSet<>(); leftyChildren.addAll(current.children); Pair<LinkedList<SchemaTableTree>, Set<SchemaTableTree>> p = Pair.of(stack, leftyChildren); result.add(p); } for (SchemaTableTree child : current.children) { if (child.isVertexStep() && child.getSchemaTable().isVertexTable()) { constructDistinctOptionalQueries(child, result); } else { for (SchemaTableTree vertexChild : child.children) { constructDistinctOptionalQueries(vertexChild, result); } } } }
public static void constructDistinctOptionalQueries(SchemaTableTree current, List<Pair<LinkedList<SchemaTableTree>, Set<SchemaTableTree>>> result) { LinkedList<SchemaTableTree> stack = current.constructQueryStackFromLeaf(); //left joins but not the leave nodes as they are already present in the main sql result set. if (current.isOptionalLeftJoin() && (current.getStepDepth() < current.getReplacedStepDepth())) { Set<SchemaTableTree> leftyChildren = new HashSet<>(); leftyChildren.addAll(current.children); Pair<LinkedList<SchemaTableTree>, Set<SchemaTableTree>> p = Pair.of(stack, leftyChildren); result.add(p); } for (SchemaTableTree child : current.children) { if (child.isVertexStep() && child.getSchemaTable().isVertexTable()) { constructDistinctOptionalQueries(child, result); } else { for (SchemaTableTree vertexChild : child.children) { constructDistinctOptionalQueries(vertexChild, result); } } } }
@SuppressWarnings("unchecked") private static <E> E loadElement( SqlgGraph sqlgGraph, Map<String, Integer> columnMap, ResultSet resultSet, SchemaTableTree leafSchemaTableTree) throws SQLException { SchemaTable schemaTable = leafSchemaTableTree.getSchemaTable(); String idProperty = leafSchemaTableTree.idProperty(); Integer columnCount = columnMap.get(idProperty); Long id = resultSet.getLong(columnCount); SqlgElement sqlgElement; if (schemaTable.isVertexTable()) { String rawLabel = schemaTable.getTable().substring(VERTEX_PREFIX.length()); sqlgElement = SqlgVertex.of(sqlgGraph, id, schemaTable.getSchema(), rawLabel); leafSchemaTableTree.loadProperty(resultSet, sqlgElement); } else { String rawLabel = schemaTable.getTable().substring(EDGE_PREFIX.length()); sqlgElement = new SqlgEdge(sqlgGraph, id, schemaTable.getSchema(), rawLabel); leafSchemaTableTree.loadProperty(resultSet, sqlgElement); leafSchemaTableTree.loadEdgeInOutVertices(resultSet, (SqlgEdge) sqlgElement); } return (E) sqlgElement; }
@SuppressWarnings("unchecked") private static <E> E loadElement( SqlgGraph sqlgGraph, Map<String, Integer> columnMap, ResultSet resultSet, SchemaTableTree leafSchemaTableTree) throws SQLException { SchemaTable schemaTable = leafSchemaTableTree.getSchemaTable(); String idProperty = leafSchemaTableTree.idProperty(); Integer columnCount = columnMap.get(idProperty); Long id = resultSet.getLong(columnCount); SqlgElement sqlgElement; if (schemaTable.isVertexTable()) { String rawLabel = schemaTable.getTable().substring(VERTEX_PREFIX.length()); sqlgElement = SqlgVertex.of(sqlgGraph, id, schemaTable.getSchema(), rawLabel); leafSchemaTableTree.loadProperty(resultSet, sqlgElement); } else { String rawLabel = schemaTable.getTable().substring(EDGE_PREFIX.length()); sqlgElement = new SqlgEdge(sqlgGraph, id, schemaTable.getSchema(), rawLabel); leafSchemaTableTree.loadProperty(resultSet, sqlgElement); leafSchemaTableTree.loadEdgeInOutVertices(resultSet, (SqlgEdge) sqlgElement); } return (E) sqlgElement; }
private void process(SchemaTableTree rootSchemaTableTree) { SchemaTable table = rootSchemaTableTree.getSchemaTable(); Optional<? extends AbstractLabel> label; if (table.isVertexTable()) { label = sqlgGraph.getTopology().getVertexLabel(table.getSchema(), table.withOutPrefix().getTable()); } else if (table.isEdgeTable()) { label = sqlgGraph.getTopology().getEdgeLabel(table.getSchema(), table.withOutPrefix().getTable()); } else { label = Optional.empty(); } process(sqlgGraph, rootSchemaTableTree, label.orElseThrow(illegalState("unknown table: %s", table))); }
private void setIdentifiersAndDistributionColumn() { if (this.schemaTable.isVertexTable()) { VertexLabel vertexLabel = this.sqlgGraph.getTopology().getVertexLabel( this.schemaTable.withOutPrefix().getSchema(), this.schemaTable.withOutPrefix().getTable() ).orElseThrow(() -> new IllegalStateException(String.format("Label %s must ne present.", this.schemaTable.toString()))); this.identifiers = vertexLabel.getIdentifiers(); if (vertexLabel.isDistributed()) { this.distributionColumn = vertexLabel.getDistributionPropertyColumn().getName(); } else { this.distributionColumn = null; } } else { EdgeLabel edgeLabel = this.sqlgGraph.getTopology().getEdgeLabel( this.schemaTable.withOutPrefix().getSchema(), this.schemaTable.withOutPrefix().getTable() ).orElseThrow(() -> new IllegalStateException(String.format("Label %s must ne present.", this.schemaTable.toString()))); this.identifiers = edgeLabel.getIdentifiers(); if (edgeLabel.isDistributed()) { this.distributionColumn = edgeLabel.getDistributionPropertyColumn().getName(); } else { this.distributionColumn = null; } } }
private void setIdentifiersAndDistributionColumn() { if (this.schemaTable.isVertexTable()) { VertexLabel vertexLabel = this.sqlgGraph.getTopology().getVertexLabel( this.schemaTable.withOutPrefix().getSchema(), this.schemaTable.withOutPrefix().getTable() ).orElseThrow(() -> new IllegalStateException(String.format("Label %s must ne present.", this.schemaTable.toString()))); this.identifiers = vertexLabel.getIdentifiers(); if (vertexLabel.isDistributed()) { this.distributionColumn = vertexLabel.getDistributionPropertyColumn().getName(); } else { this.distributionColumn = null; } } else { EdgeLabel edgeLabel = this.sqlgGraph.getTopology().getEdgeLabel( this.schemaTable.withOutPrefix().getSchema(), this.schemaTable.withOutPrefix().getTable() ).orElseThrow(() -> new IllegalStateException(String.format("Label %s must ne present.", this.schemaTable.toString()))); this.identifiers = edgeLabel.getIdentifiers(); if (edgeLabel.isDistributed()) { this.distributionColumn = edgeLabel.getDistributionPropertyColumn().getName(); } else { this.distributionColumn = null; } } }
public static void constructDistinctEmitBeforeQueries(SchemaTableTree current, List<LinkedList<SchemaTableTree>> result) { LinkedList<SchemaTableTree> stack = current.constructQueryStackFromLeaf(); //if its at the full depth it existVertexLabel already been loaded. //local step together with emit will createVertexLabel a fake emit. The fake emit will indicate that the incoming traverser must be emitted. if (!current.isLocalStep() && current.isEmit() && (current.getStepDepth() < current.getReplacedStepDepth())) { result.add(stack); } if (current.isLocalStep() && current.isEmit()) { current.setFakeEmit(true); } for (SchemaTableTree child : current.children) { if (child.isVertexStep() && child.getSchemaTable().isVertexTable()) { constructDistinctEmitBeforeQueries(child, result); } else { for (SchemaTableTree vertexChild : child.children) { constructDistinctEmitBeforeQueries(vertexChild, result); } } } }
public static void constructDistinctEmitBeforeQueries(SchemaTableTree current, List<LinkedList<SchemaTableTree>> result) { LinkedList<SchemaTableTree> stack = current.constructQueryStackFromLeaf(); //if its at the full depth it existVertexLabel already been loaded. //local step together with emit will createVertexLabel a fake emit. The fake emit will indicate that the incoming traverser must be emitted. if (!current.isLocalStep() && current.isEmit() && (current.getStepDepth() < current.getReplacedStepDepth())) { result.add(stack); } if (current.isLocalStep() && current.isEmit()) { current.setFakeEmit(true); } for (SchemaTableTree child : current.children) { if (child.isVertexStep() && child.getSchemaTable().isVertexTable()) { constructDistinctEmitBeforeQueries(child, result); } else { for (SchemaTableTree vertexChild : child.children) { constructDistinctEmitBeforeQueries(vertexChild, result); } } } }
/** * This is only called for vertex steps. * Constructs the label paths from the given schemaTable to the leaf vertex labels for the gremlin query. * For each path Sqlg will executeRegularQuery a sql query. The union of the queries is the result the gremlin query. * The vertex labels can be calculated from the steps. * * @param schemaTable The schema and table * @param replacedStepTree The original VertexSteps and HasSteps that were replaced * @return a List of paths. Each path is itself a list of SchemaTables. */ public SchemaTableTree parse(SchemaTable schemaTable, ReplacedStepTree replacedStepTree) { ReplacedStep<?, ?> rootReplacedStep = replacedStepTree.root().getReplacedStep(); Preconditions.checkArgument(!rootReplacedStep.isGraphStep(), "Expected VertexStep, found GraphStep"); Set<SchemaTableTree> schemaTableTrees = new HashSet<>(); //replacedSteps contains a fake label representing the incoming vertex for the SqlgVertexStepStrategy. SchemaTableTree rootSchemaTableTree = new SchemaTableTree(this.sqlgGraph, schemaTable, 0, replacedStepTree.getDepth()); rootSchemaTableTree.setOptionalLeftJoin(rootReplacedStep.isLeftJoin()); rootSchemaTableTree.setEmit(rootReplacedStep.isEmit()); rootSchemaTableTree.setUntilFirst(rootReplacedStep.isUntilFirst()); rootSchemaTableTree.initializeAliasColumnNameMaps(); rootSchemaTableTree.setStepType(schemaTable.isVertexTable() ? SchemaTableTree.STEP_TYPE.VERTEX_STEP : SchemaTableTree.STEP_TYPE.EDGE_VERTEX_STEP); schemaTableTrees.add(rootSchemaTableTree); replacedStepTree.walkReplacedSteps(schemaTableTrees); rootSchemaTableTree.removeNodesInvalidatedByHas(); rootSchemaTableTree.removeAllButDeepestAndAddCacheLeafNodes(replacedStepTree.getDepth()); rootSchemaTableTree.setLocalStep(true); return rootSchemaTableTree; }