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))); }
@SuppressWarnings("unchecked") Collection<String> predicateValues = (Collection<String>) predicateValue; SchemaTable schemaTableWithOutPrefix = SchemaTable.from(sqlgGraph, table).withOutPrefix(); for (String value : predicateValues) { if (!isVertex && !value.contains(".")) { SchemaTable predicateValueAsSchemaTableWithPrefix = SchemaTable.from(sqlgGraph, value).withPrefix(isVertex ? VERTEX_PREFIX : EDGE_PREFIX); tableWithPrefixes.add(predicateValueAsSchemaTableWithPrefix.toString()); return biPredicate.test(table, tableWithPrefixes); } else if (tableWithPrefixes.isEmpty()) { return biPredicate.test(schemaTableWithOutPrefix.getTable(), edgeTableWithoutSchemaAndPrefixes); } else { return biPredicate.test(table, tableWithPrefixes) || biPredicate.test(schemaTableWithOutPrefix.getTable(), edgeTableWithoutSchemaAndPrefixes); if (!isVertex && !((String) predicateValue).contains(".")) { SchemaTable schemaTableWithOutPrefix = SchemaTable.from(sqlgGraph, table).withOutPrefix(); return biPredicate.test(schemaTableWithOutPrefix.getTable(), predicateValue); } else { SchemaTable predicateValueAsSchemaTableWithPrefix = SchemaTable.from(sqlgGraph, (String) predicateValue).withPrefix(isVertex ? VERTEX_PREFIX : EDGE_PREFIX); return biPredicate.test(table, predicateValueAsSchemaTableWithPrefix.toString());
private SchemaTable getHasContainerSchemaTable(SchemaTableTree schemaTableTree, SchemaTable predicateSchemaTable) { SchemaTable hasContainerLabelSchemaTable; //Check if we are on a vertex or edge if (schemaTableTree.getSchemaTable().getTable().startsWith(VERTEX_PREFIX)) { hasContainerLabelSchemaTable = SchemaTable.of(predicateSchemaTable.getSchema(), VERTEX_PREFIX + predicateSchemaTable.getTable()); } else { hasContainerLabelSchemaTable = SchemaTable.of(predicateSchemaTable.getSchema(), EDGE_PREFIX + predicateSchemaTable.getTable()); } return hasContainerLabelSchemaTable; }
public Map<String, PropertyType> getTableFor(SchemaTable schemaTable) { Map<String, PropertyType> result = getAllTables(schemaTable.getSchema().equals(Topology.SQLG_SCHEMA), schemaTable.getSchema().equals(Schema.GLOBAL_UNIQUE_INDEX_SCHEMA)).get(schemaTable.toString()); if (result != null) { return Collections.unmodifiableMap(result); } return Collections.emptyMap(); }
void addVertex(boolean temporary, boolean streaming, SqlgVertex sqlgVertex, Map<String, Object> keyValueMap) { SchemaTable schemaTable = SchemaTable.of(sqlgVertex.getSchema(), sqlgVertex.getTable(), temporary); if (!streaming) { Pair<SortedSet<String>, Map<SqlgVertex, Map<String, Object>>> pairs = this.vertexCache.get(schemaTable); if (!schemaTable.isTemporary()) { vertexLabel = sqlgGraph.getTopology().getVertexLabel(schemaTable.getSchema(), schemaTable.getTable()).orElseThrow( () -> new IllegalStateException(String.format("VertexLabel %s not found.", schemaTable.toString())));
private SqlgVertex internalStreamVertex(Object... keyValues) { Preconditions.checkState(this.sqlDialect.supportsStreamingBatchMode(), "Streaming batch mode is not supported."); final String label = ElementHelper.getLabelValue(keyValues).orElse(Vertex.DEFAULT_LABEL); SchemaTable schemaTablePair = SchemaTable.from(this, label); SchemaTable streamingBatchModeVertexSchemaTable = this.tx().getBatchManager().getStreamingBatchModeVertexSchemaTable(); if (streamingBatchModeVertexSchemaTable != null && !streamingBatchModeVertexSchemaTable.toString().equals(schemaTablePair.toString())) { throw new IllegalStateException("Streaming batch mode must occur for one label at a time. Expected \"" + streamingBatchModeVertexSchemaTable + "\" found \"" + label + "\". First commit the transaction or call SqlgGraph.flush() before streaming a different label"); } List<String> keys = this.tx().getBatchManager().getStreamingBatchModeVertexKeys(); Triple<Map<String, PropertyType>, Map<String, Object>, Map<String, Object>> keyValueMapTriple = SqlgUtil.validateVertexKeysValues(this.sqlDialect, keyValues, keys); final Pair<Map<String, Object>, Map<String, Object>> keyValueMapPair = Pair.of(keyValueMapTriple.getMiddle(), keyValueMapTriple.getRight()); final Map<String, PropertyType> columns = keyValueMapTriple.getLeft(); this.tx().readWrite(); this.getTopology().ensureVertexLabelExist(schemaTablePair.getSchema(), schemaTablePair.getTable(), columns); return new SqlgVertex(this, false, true, schemaTablePair.getSchema(), schemaTablePair.getTable(), keyValueMapPair); }
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(); }
private void updateFileSystemType(Bdio.FileSystemType fileSystemType) { SchemaTable file = SchemaTable.from(graph(), Bdio.Class.File.name()).withPrefix(VERTEX_PREFIX); SchemaTable parent = SchemaTable.from(graph(), Bdio.ObjectProperty.parent.name()).withPrefix(EDGE_PREFIX); List<TraversalStrategy<?>> strategies = traversal().getStrategies().toList(); .schemaTable(parent) .append("\nWHERE\n\t") .qualify(file.getTable(), Topology.ID) .append(" = ") .qualify(parent.getTable(), file.withOutPrefix() + IN_VERTEX_COLUMN_END) .forEachAppend(strategies.stream().flatMap(ofType(PartitionStrategy.class)), (p, s) -> s.maybeWrapInQuotes(file.getTable()).append('.').in(p.getPartitionKey(), p.getReadPartitions(), PropertyType.STRING), " AND ", " AND ", "") .append(" AND (") .qualify(file.getTable(), Bdio.DataProperty.fileSystemType.name()) // TODO Context .append(" IS NULL OR ") .qualify(file.getTable(), Bdio.DataProperty.fileSystemType.name())// TODO Context .append(" = ") .qualify(file.getTable(), Bdio.DataProperty.byteCount.name()) // TODO Context .append(" IS NOT NULL OR ") .qualify(file.getTable(), Bdio.DataProperty.contentType.name()) // TODO Context .append(" IS NOT NULL)"); } else if (fileSystemType != Bdio.FileSystemType.DIRECTORY) { VertexLabel fileLabel = graph().getTopology().ensureVertexLabelExist(file.getSchema(), file.withOutPrefix().getTable()); graph().getTopology().ensureEdgeLabelExist(parent.withOutPrefix().getTable(), fileLabel, fileLabel, ImmutableMap.of()); graph().getTopology().ensureVertexLabelPropertiesExist(file.getSchema(), file.withOutPrefix().getTable(), ImmutableMap.of( Bdio.DataProperty.fileSystemType.name(), PropertyType.STRING,
/** * @deprecated Please use {@link Topology#ensureVertexLabelExist(String, Map)} and {@link VertexLabel#ensureIndexExists(IndexType, List)}. */ @Deprecated public void createVertexLabeledIndex(String label, Object... dummykeyValues) { Map<String, PropertyType> columns = SqlgUtil.transformToColumnDefinitionMap(dummykeyValues); SchemaTable schemaTablePair = SchemaTable.from(this, label); VertexLabel vertexLabel = this.getTopology().ensureVertexLabelExist(schemaTablePair.getSchema(), schemaTablePair.getTable(), columns); List<PropertyColumn> properties = new ArrayList<>(); List<String> keys = SqlgUtil.transformToKeyList(dummykeyValues); for (String key : keys) { properties.add(vertexLabel.getProperty(key).get()); } vertexLabel.ensureIndexExists(IndexType.NON_UNIQUE, properties); }
SQLServerVertexCacheBulkRecord(SQLServerBulkCopy bulkCopy, SqlgGraph sqlgGraph, SchemaTable schemaTable, Pair<SortedSet<String>, Map<SqlgVertex, Map<String, Object>>> vertices) throws SQLServerException { this.rowIter = vertices.getRight().entrySet().iterator(); if (!schemaTable.isTemporary()) { this.propertyColumns = sqlgGraph.getTopology() .getSchema(schemaTable.getSchema()).orElseThrow(() -> new IllegalStateException(String.format("Schema %s not found", schemaTable.getSchema()))) .getVertexLabel(schemaTable.getTable()).orElseThrow(() -> new IllegalStateException(String.format("VertexLabel %s not found", schemaTable.getTable()))) .getProperties(); } else { this.properties = sqlgGraph.getTopology().getPublicSchema().getTemporaryTable(VERTEX_PREFIX + schemaTable.getTable()); } int i = 1; this.columns = vertices.getLeft(); this.dummy = this.columns.isEmpty(); if (this.dummy) { bulkCopy.addColumnMapping(i, "dummy"); this.columnMetadata.put(i, new ColumnMetadata( "dummy", sqlgGraph.getSqlDialect().propertyTypeToJavaSqlType(PropertyType.INTEGER)[0], 0, 0, null, PropertyType.INTEGER )); } else { addMetaData(bulkCopy, sqlgGraph); } }
default List<Triple<SqlgSqlExecutor.DROP_QUERY, String, SchemaTable>> sqlTruncate(SqlgGraph sqlgGraph, SchemaTable schemaTable) { Preconditions.checkState(schemaTable.isWithPrefix(), "SqlDialect.sqlTruncate' schemaTable must start with a prefix %s or %s", Topology.VERTEX_PREFIX, Topology.EDGE_PREFIX); return Collections.singletonList( Triple.of( SqlgSqlExecutor.DROP_QUERY.TRUNCATE, "TRUNCATE TABLE " + maybeWrapInQoutes(schemaTable.getSchema()) + "." + maybeWrapInQoutes(schemaTable.getTable()), schemaTable ) ); }
private Set<SchemaTableTree> calculatePathFromVertexToEdge(SchemaTableTree schemaTableTree, SchemaTable schemaTableTo, Direction direction, Map<SchemaTable, List<Multimap<BiPredicate, RecordId>>> groupedIds) { Set<SchemaTableTree> result = new HashSet<>(); //add the child for schemaTableTo to the tree SchemaTableTree schemaTableTree1 = schemaTableTree.addChild( schemaTableTo, direction, Vertex.class, this, this.labels ); SchemaTable schemaTable = SchemaTable.from(this.topology.getSqlgGraph(), schemaTableTo.toString()); List<Multimap<BiPredicate, RecordId>> biPredicateRecordIs = groupedIds.get(schemaTable.withOutPrefix()); addIdHasContainers(schemaTableTree1, biPredicateRecordIs); result.add(schemaTableTree1); return result; }
HasContainer labelHasContainer = this.labelHasContainers.get(0); String table = (String) labelHasContainer.getValue(); SchemaTable schemaTableWithPrefix = SchemaTable.from(sqlgGraph, table).withPrefix(VERTEX_PREFIX); if (filteredAllTables.containsKey(schemaTableWithPrefix.toString())) { collectSchemaTableTrees(sqlgGraph, replacedStepDepth, result, groupedIds, schemaTableWithPrefix.toString());
void addToAllTables(String tableName, Map<String, PropertyType> propertyTypeMap) { Preconditions.checkState(isSqlWriteLockHeldByCurrentThread() || isTopologyMapWriteLockHeldByCurrentThread()); this.allTableCache.put(tableName, propertyTypeMap); SchemaTable schemaTable = SchemaTable.from(this.sqlgGraph, tableName); if (schemaTable.getTable().startsWith(VERTEX_PREFIX) && !this.schemaTableForeignKeyCache.containsKey(schemaTable)) { //This happens for VertexLabel that have no edges, //else the addOutForeignKeysToVertexLabel or addInForeignKeysToVertexLabel would have already added it to the cache. this.schemaTableForeignKeyCache.put(schemaTable, Pair.of(new HashSet<>(), new HashSet<>())); } }
@Override protected void createParentEdges() { SchemaTable file = SchemaTable.from(graph(), Bdio.Class.File.name()).withPrefix(VERTEX_PREFIX); SchemaTable parent = SchemaTable.from(graph(), Bdio.ObjectProperty.parent.name()).withPrefix(EDGE_PREFIX); List<TraversalStrategy<?>> strategies = traversal().getStrategies().toList(); Map<String, Object> traversalProperties = new LinkedHashMap<>(); graph().getTopology().ensureEdgeLabelExist(Bdio.ObjectProperty.parent.name(), file.withOutPrefix(), file.withOutPrefix(), Maps.transformValues(traversalProperties, PropertyType::from)); .append(" (") .forEachAppend(traversalProperties.keySet().stream(), (k, s) -> s.maybeWrapInQuotes(k), ", ", "", ", ") .maybeWrapInQuotes(file.withOutPrefix() + IN_VERTEX_COLUMN_END) .append(", ") .maybeWrapInQuotes(file.withOutPrefix() + OUT_VERTEX_COLUMN_END) .append(")\n SELECT ") .forEachAppend(traversalProperties.values().stream(), (v, s) -> s.valueToValuesString(v), ", ", "", ", ")
private static void printEdgeInOutVertexIdFromClauseFor(SqlgGraph sqlgGraph, SchemaTableTree firstSchemaTableTree, SchemaTableTree lastSchemaTableTree, ColumnList cols) { Preconditions.checkState(lastSchemaTableTree.getSchemaTable().isEdgeTable()); Set<ForeignKey> edgeForeignKeys = sqlgGraph.getTopology().getEdgeForeignKeys().get(lastSchemaTableTree.getSchemaTable().toString()); for (ForeignKey edgeForeignKey : edgeForeignKeys) { if (firstSchemaTableTree == null || !firstSchemaTableTree.equals(lastSchemaTableTree) || firstSchemaTableTree.getDirection() != edgeForeignKey.getDirection()) { for (String foreignKey : edgeForeignKey.getCompositeKeys()) { String alias = lastSchemaTableTree.calculateAliasPropertyName(foreignKey); cols.addForeignKey(lastSchemaTableTree, foreignKey, alias); } } } }
@Override public String toString() { return this.schemaTable.toString(); }
@Override public SchemaTable createObject(final Map data) { return SchemaTable.of((String)data.get("schema"), (String) data.get("table")); } }
static Index createIndex(SqlgGraph sqlgGraph, AbstractLabel abstractLabel, String indexName, IndexType indexType, List<PropertyColumn> properties) { Index index = new Index(indexName, indexType, abstractLabel, properties); SchemaTable schemaTable = SchemaTable.of(abstractLabel.getSchema().getName(), abstractLabel.getLabel()); //For partitioned tables the index is on each partition. //It is created when the partition is created. if (!abstractLabel.isPartition()) { String prefix = abstractLabel instanceof VertexLabel ? VERTEX_PREFIX : EDGE_PREFIX; index.createIndex(sqlgGraph, schemaTable.withPrefix(prefix), index.getName()); } else { for (Partition partition : abstractLabel.getPartitions().values()) { partition.createIndexOnLeafPartitions(index); } } TopologyManager.addIndex(sqlgGraph, index); index.committed = false; return index; }