com.baidu.hugegraph.util.E Java Examples
The following examples show how to use
com.baidu.hugegraph.util.E.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HdfsDirectory.java From hugegraph-tools with Apache License 2.0 | 6 votes |
@Override public void ensureDirectoryExist(boolean create) { FileSystem fs = this.fileSystem(); Path path = new Path(this.directory()); try { if (fs.exists(path)) { E.checkState(fs.getFileStatus(path).isDirectory(), "Can't use directory '%s' because " + "a file with same name exists.", this.directory()); } else { if (create) { E.checkState(fs.mkdirs(path), "The directory does not exist and created " + "failed: '%s'", path.toString()); } else { E.checkState(false, "The directory does not exist: '%s'", path.toString()); } } } catch (IOException e) { throw new ToolsException("Invalid directory '%s'", e, this.directory()); } }
Example #2
Source File: SingleSourceShortestPathTraverser.java From hugegraph with Apache License 2.0 | 6 votes |
public WeightedPaths singleSourceShortestPaths(Id sourceV, Directions dir, String label, String weight, long degree, long skipDegree, long capacity, long limit) { E.checkNotNull(sourceV, "source vertex id"); E.checkNotNull(dir, "direction"); checkDegree(degree); checkCapacity(capacity); checkSkipDegree(skipDegree, degree, capacity); checkLimit(limit); Id labelId = this.getEdgeLabelId(label); Traverser traverser = new Traverser(sourceV, dir, labelId, weight, degree, skipDegree, capacity, limit); while (true) { // Found, reach max depth or reach capacity, stop searching traverser.forward(); if (traverser.done()) { return traverser.shortestPaths(); } checkCapacity(traverser.capacity, traverser.size, "shortest path"); } }
Example #3
Source File: GraphIndexTransaction.java From hugegraph with Apache License 2.0 | 6 votes |
private HugeElement constructErrorElem( ConditionQuery query, HugeElement element, Map<PropertyKey, Object> incorrectPKs) { HugeElement errorElem = element.copyAsFresh(); Set<Id> propKeys = query.userpropKeys(); for (Id key : propKeys) { Set<Object> conditionValues = query.userpropValues(key); E.checkState(!conditionValues.isEmpty(), "Expect user property values for key '%s', " + "but got none", key); if (conditionValues.size() > 1) { // It's inside/between Query (processed in range index) return null; } HugeProperty<?> prop = element.getProperty(key); Object errorValue = conditionValues.iterator().next(); if (prop == null || !Objects.equals(prop.value(), errorValue)) { PropertyKey pkey = this.graph().propertyKey(key); errorElem.addProperty(pkey, errorValue); incorrectPKs.put(pkey, errorValue); } } return errorElem; }
Example #4
Source File: CassandraTables.java From hugegraph with Apache License 2.0 | 6 votes |
@Override protected List<Object> idColumnValue(Id id) { EdgeId edgeId; if (id instanceof EdgeId) { edgeId = (EdgeId) id; } else { String[] idParts = EdgeId.split(id); if (idParts.length == 1) { // Delete edge by label return Arrays.asList((Object[]) idParts); } id = IdUtil.readString(id.asString()); edgeId = EdgeId.parse(id.asString()); } E.checkState(edgeId.direction() == this.direction, "Can't query %s edges from %s edges table", edgeId.direction(), this.direction); return idColumnValue(edgeId); }
Example #5
Source File: VertexLabelBuilder.java From hugegraph with Apache License 2.0 | 6 votes |
public VertexLabelBuilder(SchemaTransaction transaction, HugeGraph graph, String name) { super(transaction, graph); E.checkNotNull(name, "name"); this.id = null; this.name = name; this.idStrategy = IdStrategy.DEFAULT; this.properties = new HashSet<>(); this.primaryKeys = new ArrayList<>(); this.nullableKeys = new HashSet<>(); this.ttl = 0L; this.ttlStartTime = null; this.enableLabelIndex = null; this.userdata = new Userdata(); this.checkExist = true; }
Example #6
Source File: BinarySerializer.java From hugegraph with Apache License 2.0 | 6 votes |
protected void parseColumn(BackendColumn col, HugeVertex vertex) { BytesBuffer buffer = BytesBuffer.wrap(col.name); Id id = this.keyWithIdPrefix ? buffer.readId() : vertex.id(); E.checkState(buffer.remaining() > 0, "Missing column type"); byte type = buffer.read(); // Parse property if (type == HugeType.PROPERTY.code()) { Id pkeyId = buffer.readId(); this.parseProperty(pkeyId, BytesBuffer.wrap(col.value), vertex); } // Parse edge else if (type == HugeType.EDGE_IN.code() || type == HugeType.EDGE_OUT.code()) { this.parseEdge(col, vertex, vertex.graph()); } // Parse system property else if (type == HugeType.SYS_PROPERTY.code()) { // pass } // Invalid entry else { E.checkState(false, "Invalid entry(%s) with unknown type(%s): 0x%s", id, type & 0xff, Bytes.toHex(col.name)); } }
Example #7
Source File: VertexLabelBuilder.java From hugegraph with Apache License 2.0 | 6 votes |
private void checkTtl() { E.checkArgument(this.ttl >= 0, "The ttl must be >= 0, but got: %s", this.ttl); if (this.ttl == 0L) { E.checkArgument(this.ttlStartTime == null, "Can't set ttl start time if ttl is not set"); return; } if (this.ttlStartTime == null) { return; } // Check whether the properties contains the specified keys E.checkArgument(!this.properties.isEmpty(), "The properties can't be empty when exist " + "ttl start time for edge label '%s'", this.name); E.checkArgument(this.properties.contains(this.ttlStartTime), "The ttl start time '%s' must be contained in " + "properties '%s' for vertex label '%s'", this.ttlStartTime, this.name, this.properties); PropertyKey pkey = this.graph().propertyKey(this.ttlStartTime); E.checkArgument(pkey.dataType().isDate(), "The ttl start time property must be date type," + "but got '%s(%s)'", this.ttlStartTime, pkey.dataType()); }
Example #8
Source File: SubGraphTraverser.java From hugegraph with Apache License 2.0 | 6 votes |
private PathSet subGraphPaths(Id sourceV, Directions dir, String label, int depth, long degree, long capacity, long limit, boolean rings, boolean sourceInRing) { E.checkNotNull(sourceV, "source vertex id"); E.checkNotNull(dir, "direction"); checkPositive(depth, "max depth"); checkDegree(degree); checkCapacity(capacity); checkLimit(limit); Id labelId = this.getEdgeLabelId(label); Traverser traverser = new Traverser(sourceV, labelId, depth, degree, capacity, limit, rings, sourceInRing); PathSet paths = new PathSet(); while (true) { paths.addAll(traverser.forward(dir)); if (--depth <= 0 || traverser.reachLimit() || traverser.finished()) { break; } } return paths; }
Example #9
Source File: NeighborRankAPI.java From hugegraph with Apache License 2.0 | 6 votes |
private NeighborRankTraverser.Step jsonToStep(HugeGraph graph) { E.checkArgument(this.degree > 0 || this.degree == NO_LIMIT, "The degree must be > 0, but got: %s", this.degree); E.checkArgument(this.top > 0 && this.top <= MAX_TOP, "The top of each layer can't exceed %s", MAX_TOP); Map<Id, String> labelIds = new HashMap<>(); if (this.labels != null) { for (String label : this.labels) { EdgeLabel el = graph.edgeLabel(label); labelIds.put(el.id(), label); } } return new NeighborRankTraverser.Step(this.direction, labelIds, this.degree, this.top); }
Example #10
Source File: EdgesAPI.java From hugegraph with Apache License 2.0 | 6 votes |
@GET @Timed @Compress @Produces(APPLICATION_JSON_WITH_CHARSET) public String list(@Context GraphManager manager, @PathParam("graph") String graph, @QueryParam("ids") List<String> stringIds) { LOG.debug("Graph [{}] get edges by ids: {}", graph, stringIds); E.checkArgument(stringIds != null && !stringIds.isEmpty(), "The ids parameter can't be null or empty"); Object[] ids = new Id[stringIds.size()]; for (int i = 0; i < ids.length; i++) { ids[i] = HugeEdge.getIdValue(stringIds.get(i), false); } HugeGraph g = graph(manager, graph); Iterator<Edge> edges = g.edges(ids); return manager.serializer(g).writeEdges(edges, false); }
Example #11
Source File: BackupManager.java From hugegraph-tools with Apache License 2.0 | 6 votes |
private void removeShardsFilesIfExists() { File logDir = new File(this.logDir()); E.checkArgument(logDir.exists() && logDir.isDirectory(), "The log directory '%s' not exists or is file", logDir); for (File file : logDir.listFiles()) { if (file.getName().endsWith(SHARDS_SUFFIX)) { try { FileUtils.forceDelete(file); } catch (IOException e) { throw new ToolsException("Failed to delete shard file " + "'%s'", file); } } } }
Example #12
Source File: MappingConverter.java From hugegraph-loader with Apache License 2.0 | 6 votes |
public static void main(String[] args) { E.checkArgument(args.length == 1, "args: file"); String input = args[0]; LOG.info("Prepare to convert mapping file {}", input); File file = FileUtils.getFile(input); if (!file.exists() || !file.isFile()) { LOG.error("The file '{}' doesn't exists or not a file", input); throw new IllegalArgumentException(String.format( "The file '%s' doesn't exists or not a file", input)); } LoadMapping mapping = LoadMapping.of(input); String outputPath = getOutputPath(file); MappingUtil.write(mapping, outputPath); LOG.info("Convert mapping file successfuly, stored at {}", outputPath); }
Example #13
Source File: HugeElement.java From hugegraph with Apache License 2.0 | 6 votes |
public void setExpiredTime() { SchemaLabel label = this.schemaLabel(); if (label.ttl() == 0L) { return; } long now = this.graph.now(); if (SchemaLabel.NONE_ID.equals(label.ttlStartTime())) { this.expiredTime(now + label.ttl()); return; } Date date = this.getPropertyValue(label.ttlStartTime()); if (date == null) { this.expiredTime(now + label.ttl()); return; } long expired = date.getTime() + label.ttl(); E.checkArgument(expired > now, "The expired time '%s' of '%s' is prior to now: %s", new Date(expired), this, now); this.expiredTime(expired); }
Example #14
Source File: SchemaTransaction.java From hugegraph with Apache License 2.0 | 6 votes |
@Watched(prefix = "schema") private static Id asyncRun(HugeGraph graph, SchemaElement schema, boolean sync, SchemaCallable callable, Set<Id> dependencies) { E.checkArgument(schema != null, "Schema can't be null"); String name = SchemaCallable.formatTaskName(schema.type(), schema.id(), schema.name()); JobBuilder<Object> builder = JobBuilder.of(graph).name(name) .job(callable) .dependencies(dependencies); HugeTask<?> task = builder.schedule(); // If TASK_SYNC_DELETION is true, wait async thread done before // continue. This is used when running tests. if (sync) { task.syncWait(); } return task.id(); }
Example #15
Source File: GremlinClient.java From hugegraph with Apache License 2.0 | 6 votes |
public Response doGetRequest(String auth, MultivaluedMap<String, String> params) { WebTarget target = this.webTarget; for (Map.Entry<String, List<String>> entry : params.entrySet()) { E.checkArgument(entry.getValue().size() == 1, "Invalid query param '%s', can only accept " + "one value, but got %s", entry.getKey(), entry.getValue()); target = target.queryParam(entry.getKey(), entry.getValue().get(0)); } return target.request() .header(HttpHeaders.AUTHORIZATION, auth) .accept(MediaType.APPLICATION_JSON) .acceptEncoding(CompressInterceptor.GZIP) .get(); }
Example #16
Source File: AbstractTransaction.java From hugegraph with Apache License 2.0 | 6 votes |
@Watched(prefix = "tx") public Number queryNumber(Query query) { LOG.debug("Transaction queryNumber: {}", query); E.checkArgument(query.aggregate() != null, "The aggregate must be set for number query: %s", query); Query squery = this.serializer.writeQuery(query); this.beforeRead(); try { return this.store.queryNumber(squery); } finally { this.afterRead(); } }
Example #17
Source File: CassandraTables.java From hugegraph with Apache License 2.0 | 6 votes |
@Override protected BackendEntry mergeEntries(BackendEntry e1, BackendEntry e2) { // Merge edges into vertex // TODO: merge rows before calling row2Entry() CassandraBackendEntry current = (CassandraBackendEntry) e1; CassandraBackendEntry next = (CassandraBackendEntry) e2; E.checkState(current == null || current.type().isVertex(), "The current entry must be null or VERTEX"); E.checkState(next != null && next.type().isEdge(), "The next entry must be EDGE"); long maxSize = BackendEntryIterator.INLINE_BATCH_SIZE; if (current != null && current.subRows().size() < maxSize) { Object nextVertexId = next.column(HugeKeys.OWNER_VERTEX); if (current.id().equals(IdGenerator.of(nextVertexId))) { current.subRow(next.row()); return current; } } return this.wrapByVertex(next); }
Example #18
Source File: IndexLabelBuilder.java From hugegraph with Apache License 2.0 | 6 votes |
private void checkPrimaryKeyIndex(SchemaLabel schemaLabel) { if (schemaLabel instanceof VertexLabel) { VertexLabel vl = (VertexLabel) schemaLabel; if (vl.idStrategy().isPrimaryKey()) { if (this.indexType.isSecondary() || this.indexType.isUnique() || this.indexType.isShard() && this.allStringIndex(this.indexFields)) { List<String> pks = this.graph() .mapPkId2Name(vl.primaryKeys()); E.checkArgument(!this.indexFields.containsAll(pks), "No need to build index on properties " + "%s, because they contains all primary " + "keys %s for vertex label '%s'", this.indexFields, pks, vl.name()); } } } }
Example #19
Source File: CassandraStore.java From hugegraph with Apache License 2.0 | 6 votes |
public CassandraStore(final BackendStoreProvider provider, final String keyspace, final String store) { E.checkNotNull(keyspace, "keyspace"); E.checkNotNull(store, "store"); this.provider = provider; this.keyspace = keyspace; this.store = store; this.tables = new ConcurrentHashMap<>(); this.sessions = null; this.conf = null; this.registerMetaHandlers(); LOG.debug("Store loaded: {}", store); }
Example #20
Source File: BackendTable.java From hugegraph with Apache License 2.0 | 5 votes |
public List<Shard> getSplits(Session session, long splitSize) { E.checkArgument(splitSize >= MIN_SHARD_SIZE, "The split-size must be >= %s bytes, but got %s", MIN_SHARD_SIZE, splitSize); long size = this.estimateDataSize(session); if (size <= 0) { size = this.estimateNumKeys(session) * ESTIMATE_BYTES_PER_KV; } double count = Math.ceil(size / (double) splitSize); if (count <= 0) { count = 1; } long maxKey = this.maxKey(); double each = maxKey / count; long offset = 0L; String last = this.position(offset); List<Shard> splits = new ArrayList<>((int) count); while (offset < maxKey) { offset += each; if (offset > maxKey) { splits.add(new Shard(last, END, 0L)); break; } String current = this.position(offset); splits.add(new Shard(last, current, 0L)); last = current; } return splits; }
Example #21
Source File: TaskAPI.java From hugegraph-client with Apache License 2.0 | 5 votes |
public TasksWithPage list(String status, String page, long limit) { E.checkArgument(page != null, "The page can not be null"); this.client.checkApiVersion("0.48", "getting tasks by paging"); Map<String, Object> params = new LinkedHashMap<>(); params.put("limit", limit); params.put("page", page); if (status != null) { params.put("status", status); } RestResult result = this.client.get(this.path(), params); return result.readObject(TasksWithPage.class); }
Example #22
Source File: VertexLabelBuilder.java From hugegraph with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") private void checkNullableKeys(Action action) { // Not using switch-case to avoid indent too much if (action == Action.ELIMINATE) { if (!this.nullableKeys.isEmpty()) { throw new NotAllowException( "Not support to eliminate nullableKeys " + "for vertex label currently"); } return; } VertexLabel vertexLabel = this.vertexLabelOrNull(this.name); // The originProps is empty when firstly create vertex label List<String> originProps = vertexLabel == null ? ImmutableList.of() : this.graph() .mapPkId2Name(vertexLabel.properties()); Set<String> appendProps = this.properties; E.checkArgument(CollectionUtil.union(originProps, appendProps) .containsAll(this.nullableKeys), "The nullableKeys: %s to be created or appended " + "must belong to the origin/new properties: %s/%s", this.nullableKeys, originProps, appendProps); E.checkArgument(!CollectionUtil.hasIntersection(this.primaryKeys, this.nullableKeys), "The nullableKeys: %s are not allowed to " + "belong to primaryKeys: %s of vertex label '%s'", this.nullableKeys, this.primaryKeys, this.name); if (action == Action.APPEND) { Collection<String> newAddedProps = CollectionUtils.subtract( appendProps, originProps); E.checkArgument(this.nullableKeys.containsAll(newAddedProps), "The new added properties: %s must be nullable", newAddedProps); } }
Example #23
Source File: HugeVertex.java From hugegraph with Apache License 2.0 | 5 votes |
/** * Add edge with direction OUT * @param edge the out edge */ public void addOutEdge(HugeEdge edge) { if (edge.ownerVertex() == null) { edge.sourceVertex(this); } E.checkState(edge.isDirection(Directions.OUT), "The owner vertex('%s') of OUT edge '%s' should be '%s'", edge.ownerVertex().id(), edge, this.id()); this.edges.add(edge); }
Example #24
Source File: MysqlTable.java From hugegraph with Apache License 2.0 | 5 votes |
@Override protected void registerMetaHandlers() { this.registerMetaHandler("splits", (session, meta, args) -> { E.checkArgument(args.length == 1, "The args count of %s must be 1", meta); long splitSize = (long) args[0]; return this.shardSpliter.getSplits(session, splitSize); }); }
Example #25
Source File: Query.java From hugegraph with Apache License 2.0 | 5 votes |
public long skipOffset(long offset) { E.checkArgument(offset >= 0L, "Invalid offset value: %s", offset); if (this.originQuery != null) { return this.rootOriginQuery().skipOffset(offset); } this.actualOffset += offset; return this.actualOffset; }
Example #26
Source File: VertexAPI.java From hugegraph with Apache License 2.0 | 5 votes |
@PUT @Timed(name = "single-update") @Path("{id}") @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON_WITH_CHARSET) @RolesAllowed({"admin", "$owner=$graph $action=vertex_write"}) public String update(@Context GraphManager manager, @PathParam("graph") String graph, @PathParam("id") String idValue, @QueryParam("action") String action, JsonVertex jsonVertex) { LOG.debug("Graph [{}] update vertex: {}", graph, jsonVertex); checkUpdatingBody(jsonVertex); Id id = checkAndParseVertexId(idValue); // Parse action param boolean append = checkAndParseAction(action); HugeGraph g = graph(manager, graph); HugeVertex vertex = (HugeVertex) g.vertices(id).next(); VertexLabel vertexLabel = vertex.schemaLabel(); for (String key : jsonVertex.properties.keySet()) { PropertyKey pkey = g.propertyKey(key); E.checkArgument(vertexLabel.properties().contains(pkey.id()), "Can't update property for vertex '%s' because " + "there is no property key '%s' in its vertex label", id, key); } commit(g, () -> updateProperties(vertex, jsonVertex, append)); return manager.serializer(g).writeVertex(vertex); }
Example #27
Source File: Event.java From hugegraph-common with Apache License 2.0 | 5 votes |
public void checkArgs(Class<?>... classes) throws IllegalArgumentException { E.checkArgument(this.args.length == classes.length, "The args count of event '%s' should be %s(actual %s)", this.name, classes.length, this.args.length); int i = 0; for (Class<?> c : classes) { Object arg = this.args[i++]; if (arg == null) { continue; } E.checkArgument(c.isAssignableFrom(arg.getClass()), "The arg '%s'(%s) can't match %s", arg, arg.getClass(), c); } }
Example #28
Source File: StandardUserManager.java From hugegraph with Apache License 2.0 | 5 votes |
@Override public Id createAccess(HugeAccess access) { this.invalidCache(); E.checkArgument(this.groups.exists(access.source()), "Not exists group '%s'", access.source()); E.checkArgument(this.targets.exists(access.target()), "Not exists target '%s'", access.target()); return this.access.add(access); }
Example #29
Source File: RelationshipManager.java From hugegraph with Apache License 2.0 | 5 votes |
public RelationshipManager(HugeGraphParams graph, String label, Function<Edge, T> dser) { E.checkNotNull(graph, "graph"); this.graph = graph; this.label = label; this.deser = dser; }
Example #30
Source File: VertexLabelAPI.java From hugegraph-client with Apache License 2.0 | 5 votes |
public List<VertexLabel> list(List<String> names) { this.client.checkApiVersion("0.48", "getting schema by names"); E.checkArgument(names != null && !names.isEmpty(), "The vertex label names can't be null or empty"); Map<String, Object> params = ImmutableMap.of("names", names); RestResult result = this.client.get(this.path(), params); return result.readList(this.type(), VertexLabel.class); }