graphar_pyspark.info
Bindings to org.apache.graphar info classes.
1# Licensed to the Apache Software Foundation (ASF) under one 2# or more contributor license agreements. See the NOTICE file 3# distributed with this work for additional information 4# regarding copyright ownership. The ASF licenses this file 5# to you under the Apache License, Version 2.0 (the 6# "License"); you may not use this file except in compliance 7# with the License. You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, 12# software distributed under the License is distributed on an 13# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14# KIND, either express or implied. See the License for the 15# specific language governing permissions and limitations 16# under the License. 17 18"""Bindings to org.apache.graphar info classes.""" 19 20# because we are using type-hints, we need to define few custom TypeVar 21# to describe returns of classmethods; 22 23from __future__ import annotations 24 25import os 26from collections.abc import Sequence 27from typing import Optional, TypeVar, Union 28 29from py4j.java_collections import JavaList 30from py4j.java_gateway import JavaObject 31 32from graphar_pyspark import GraphArSession, _check_session 33from graphar_pyspark.enums import AdjListType, FileType, GarType 34 35# Return type of Property classmethods 36PropertyType = TypeVar("PropertyType", bound="Property") 37 38 39class Property: 40 """The property information of vertex or edge.""" 41 42 def __init__( 43 self, 44 name: Optional[str], 45 data_type: Optional[GarType], 46 is_primary: Optional[bool], 47 is_nullable: Optional[bool], 48 jvm_obj: Optional[JavaObject] = None, 49 ) -> None: 50 """One should not use this constructor directly, please use `from_scala` or `from_python`.""" 51 _check_session() 52 if jvm_obj is not None: 53 self._jvm_property_obj = jvm_obj 54 else: 55 property_pyobj = GraphArSession.graphar.Property() 56 property_pyobj.setName(name) 57 property_pyobj.setData_type(data_type.value) 58 property_pyobj.setIs_primary(is_primary) 59 property_pyobj.setIs_nullable(is_nullable) 60 61 self._jvm_property_obj = property_pyobj 62 63 def get_name(self) -> str: 64 """Get name from corresponding JVM object. 65 66 :returns: name 67 """ 68 return self._jvm_property_obj.getName() 69 70 def set_name(self, name: str) -> None: 71 """Mutate corresponding JVM object. 72 73 :param name: name 74 """ 75 self._jvm_property_obj.setName(name) 76 77 def get_data_type(self) -> GarType: 78 """Get data type from corresponding JVM object. 79 80 :returns: data type 81 """ 82 return GarType(self._jvm_property_obj.getData_type()) 83 84 def set_data_type(self, data_type: GarType) -> None: 85 """Mutate corresponding JVM object. 86 87 :param data_type: data type 88 """ 89 self._jvm_property_obj.setData_type(data_type.value) 90 91 def get_is_primary(self) -> bool: 92 """Get is priamry flag from corresponding JVM object. 93 94 :returns: is primary 95 """ 96 return self._jvm_property_obj.getIs_primary() 97 98 def set_is_primary(self, is_primary: bool) -> None: 99 """Mutate corresponding JVM object. 100 101 :param is_primary: is primary 102 """ 103 self._jvm_property_obj.setIs_primary(is_primary) 104 105 def set_is_nullable(self, is_nullable: bool) -> None: 106 """Mutate corresponding JVM object. 107 108 :param is_nullable: is nullable 109 """ 110 self._jvm_property_obj.setIs_nullable(is_nullable) 111 112 def get_is_nullable(self) -> bool: 113 """Get is nullable flag from corresponding JVM object. 114 115 :returns: is nullable 116 """ 117 return self._jvm_property_obj.getIs_nullable() 118 119 def to_scala(self) -> JavaObject: 120 """Transform object to JVM representation. 121 122 :returns: JavaObject 123 """ 124 return self._jvm_property_obj 125 126 @classmethod 127 def from_scala(cls: type[PropertyType], jvm_obj: JavaObject) -> PropertyType: 128 """Create an instance of the Class from the corresponding JVM object. 129 130 :param jvm_obj: scala object in JVM. 131 :returns: instance of Python Class. 132 """ 133 return cls(None, None, None, None, jvm_obj) 134 135 @classmethod 136 def from_python( 137 cls: type[PropertyType], 138 name: str, 139 data_type: GarType, 140 is_primary: bool, 141 is_nullable: Optional[bool] = None, 142 ) -> PropertyType: 143 """Create an instance of the Class from Python arguments. 144 145 :param name: property name 146 :param data_type: property data type 147 :param is_primary: flag that property is primary 148 :param is_nullable: flag that property is nullable (optional, default is None) 149 :returns: instance of Python Class. 150 """ 151 return cls(name, data_type, is_primary, is_nullable, None) 152 153 def __eq__(self, other: object) -> bool: 154 if not isinstance(other, Property): 155 return False 156 157 return ( 158 (self.get_name() == other.get_name()) 159 and (self.get_data_type() == other.get_data_type()) 160 and (self.get_is_primary() == other.get_is_primary()) 161 and (self.get_is_nullable() == other.get_is_nullable()) 162 ) 163 164 165# Return type of PropertyGroup classmethods 166PropertyGroupType = TypeVar("PropertyGroupType", bound="PropertyGroup") 167 168 169class PropertyGroup: 170 """PropertyGroup is a class to store the property group information.""" 171 172 def __init__( 173 self, 174 prefix: Optional[str], 175 file_type: Optional[FileType], 176 properties: Optional[Sequence[Property]], 177 jvm_obj: Optional[JavaObject], 178 ) -> None: 179 """One should not use this constructor directly, please use `from_scala` or `from_python`.""" 180 _check_session() 181 if jvm_obj is not None: 182 self._jvm_property_group_obj = jvm_obj 183 else: 184 property_group = GraphArSession.graphar.PropertyGroup() 185 property_group.setPrefix(prefix) 186 property_group.setFile_type(file_type.value) 187 property_group.setProperties( 188 [py_property.to_scala() for py_property in properties], 189 ) 190 self._jvm_property_group_obj = property_group 191 192 def get_prefix(self) -> str: 193 """Get prefix from the corresponding JVM object. 194 195 :returns: prefix 196 """ 197 return self._jvm_property_group_obj.getPrefix() 198 199 def set_prefix(self, prefix: str) -> None: 200 """Mutate the corresponding JVM object. 201 202 :param prefix: prefix 203 """ 204 self._jvm_property_group_obj.setPrefix(prefix) 205 206 def get_file_type(self) -> FileType: 207 """Get file type from the corresponding JVM object. 208 209 :returns: FileType 210 """ 211 return FileType(self._jvm_property_group_obj.getFile_type()) 212 213 def set_file_type(self, file_type: FileType) -> None: 214 """Mutate the corresponding JVM object. 215 216 :param file_type: FileType 217 """ 218 self._jvm_property_group_obj.setFile_type(file_type.value) 219 220 def get_properties(self) -> Sequence[Property]: 221 """Get properties from the corresponding JVM object. 222 223 :returns: list of Properties 224 """ 225 return [ 226 Property.from_scala(jvm_property) 227 for jvm_property in self._jvm_property_group_obj.getProperties() 228 ] 229 230 def set_properties(self, properties: Sequence[Property]) -> None: 231 """Mutate the corresponding JVM object. 232 233 :param properties: list of Properties 234 """ 235 self._jvm_property_group_obj.setProperties( 236 [py_property.to_scala() for py_property in properties], 237 ) 238 239 def to_scala(self) -> JavaObject: 240 """Transform object to JVM representation. 241 242 :returns: JavaObject 243 """ 244 return self._jvm_property_group_obj 245 246 @classmethod 247 def from_scala( 248 cls: type[PropertyGroupType], 249 jvm_obj: JavaObject, 250 ) -> PropertyGroupType: 251 """Create an instance of the Class from the corresponding JVM object. 252 253 :param jvm_obj: scala object in JVM. 254 :returns: instance of Python Class. 255 """ 256 return cls(None, None, None, jvm_obj) 257 258 @classmethod 259 def from_python( 260 cls: type[PropertyGroupType], 261 prefix: str, 262 file_type: FileType, 263 properties: Sequence[Property], 264 ) -> PropertyGroupType: 265 """Create an instance of the class from Python args. 266 267 :param prefix: path prefix 268 :param file_type: type of file 269 :param properties: list of properties 270 """ 271 return cls(prefix, file_type, properties, None) 272 273 def __eq__(self, other: object) -> bool: 274 if not isinstance(other, PropertyGroup): 275 return False 276 277 return ( 278 (self.get_prefix() == other.get_prefix()) 279 and (self.get_file_type() == other.get_file_type()) 280 and (len(self.get_properties()) == len(other.get_properties())) 281 and all( 282 p_left == p_right 283 for p_left, p_right in zip( 284 self.get_properties(), 285 other.get_properties(), 286 ) 287 ) 288 ) 289 290 291# Return type of VertexInfo classmethods 292VertexInfoType = TypeVar("VertexInfoType", bound="VertexInfo") 293 294 295class VertexInfo: 296 """VertexInfo is a class to store the vertex meta information.""" 297 298 def __init__( 299 self, 300 label: Optional[str], 301 chunk_size: Optional[int], 302 prefix: Optional[str], 303 property_groups: Optional[Sequence[PropertyGroup]], 304 version: Optional[str], 305 jvm_obj: Optional[JavaObject], 306 ) -> None: 307 """One should not use this constructor directly, please use `from_scala` or `from_python`.""" 308 _check_session() 309 if jvm_obj is not None: 310 self._jvm_vertex_info_obj = jvm_obj 311 else: 312 vertex_info = GraphArSession.graphar.VertexInfo() 313 vertex_info.setLabel(label) 314 vertex_info.setChunk_size(chunk_size) 315 vertex_info.setPrefix(prefix) 316 vertex_info.setProperty_groups( 317 [py_property_group.to_scala() for py_property_group in property_groups], 318 ) 319 vertex_info.setVersion(version) 320 self._jvm_vertex_info_obj = vertex_info 321 322 def get_label(self) -> str: 323 """Get label from the corresponding JVM object. 324 325 :returns: label 326 """ 327 return self._jvm_vertex_info_obj.getLabel() 328 329 def set_label(self, label: str) -> None: 330 """Mutate the corresponding JVM object. 331 332 :param label: new label 333 """ 334 self._jvm_vertex_info_obj.setLabel(label) 335 336 def get_chunk_size(self) -> int: 337 """Get chunk size from the corresponding JVM object. 338 339 :returns: chunk size 340 """ 341 return self._jvm_vertex_info_obj.getChunk_size() 342 343 def set_chunk_size(self, chunk_size: int) -> None: 344 """Mutate the corresponding JVM object. 345 346 :param chunk_size: new chunk size 347 """ 348 self._jvm_vertex_info_obj.setChunk_size(chunk_size) 349 350 def get_prefix(self) -> str: 351 """Get prefix from the corresponding JVM object. 352 353 :returns: prefix 354 """ 355 return self._jvm_vertex_info_obj.getPrefix() 356 357 def set_prefix(self, prefix: str) -> None: 358 """Mutate the corresponding JVM object. 359 360 :param prefix: the new pefix. 361 """ 362 self._jvm_vertex_info_obj.setPrefix(prefix) 363 364 def get_property_groups(self) -> Sequence[PropertyGroup]: 365 """Get property groups from the corresponding JVM object. 366 367 :returns: property groups 368 """ 369 return [ 370 PropertyGroup.from_scala(jvm_property_group) 371 for jvm_property_group in self._jvm_vertex_info_obj.getProperty_groups() 372 ] 373 374 def set_property_groups(self, property_groups: Sequence[PropertyGroup]) -> None: 375 """Mutate the corresponding JVM object. 376 377 :param property_groups: new property groups 378 """ 379 self._jvm_vertex_info_obj.setProperty_groups( 380 [py_property_group.to_scala() for py_property_group in property_groups], 381 ) 382 383 def get_version(self) -> str: 384 """Get version from the corresponding JVM object. 385 386 :returns: version 387 """ 388 return self._jvm_vertex_info_obj.getVersion() 389 390 def set_version(self, version: str) -> None: 391 """Mutate the corresponding JVM object. 392 393 :param version: the new version. 394 """ 395 self._jvm_vertex_info_obj.setVersion(version) 396 397 def contain_property_group(self, property_group: PropertyGroup) -> bool: 398 """Check if the vertex info contains the property group. 399 400 :param property_group: the property group to check. 401 :returns: true if the vertex info contains the property group, otherwise false. 402 """ 403 return self._jvm_vertex_info_obj.containPropertyGroup(property_group.to_scala()) 404 405 def contain_property(self, property_name: str) -> bool: 406 """Check if the vertex info contains certain property. 407 408 :param property_name: name of the property. 409 :returns: true if the vertex info contains the property, otherwise false. 410 """ 411 return self._jvm_vertex_info_obj.containProperty(property_name) 412 413 def get_property_group(self, property_name: str) -> PropertyGroup: 414 """Get the property group that contains property. 415 416 WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method! 417 418 :param property_name: name of the property. 419 :returns: property group that contains the property, otherwise raise IllegalArgumentException error. 420 """ 421 return PropertyGroup.from_scala( 422 self._jvm_vertex_info_obj.getPropertyGroup(property_name), 423 ) 424 425 def get_property_type(self, property_name: str) -> GarType: 426 """Get the data type of property. 427 428 WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method! 429 430 :param property_name: name of the property. 431 :returns: the data type in gar of the property. If the vertex info does not contains the property, raise IllegalArgumentException error. 432 """ 433 return GarType.from_scala( 434 self._jvm_vertex_info_obj.getPropertyType(property_name), 435 ) 436 437 def is_primary_key(self, property_name: str) -> bool: 438 """Check if the property is primary key. 439 440 :param property_name: name of the property to check. 441 :returns: true if the property if the primary key of vertex info, otherwise return false. 442 """ 443 return self._jvm_vertex_info_obj.isPrimaryKey(property_name) 444 445 def get_primary_key(self) -> str: 446 """Get primary key of vertex info. 447 448 :returns: name of the primary key. 449 """ 450 return self._jvm_vertex_info_obj.getPrimaryKey() 451 452 def is_nullable_key(self, property_name: str) -> bool: 453 """Check if the property is nullable key. 454 455 :param property_name: name of the property to check. 456 :returns: true if the property if a nullable key of vertex info, otherwise return false 457 """ 458 return self._jvm_vertex_info_obj.isNullableKey(property_name) 459 460 def is_validated(self) -> bool: 461 """Check if the vertex info is validated. 462 463 :returns: true if the vertex info is validated, otherwise return false. 464 """ 465 return self._jvm_vertex_info_obj.isValidated() 466 467 def get_vertices_num_file_path(self) -> str: 468 """Get the vertex num file path of vertex info. 469 470 :returns: vertex num file path of vertex info. 471 """ 472 return self._jvm_vertex_info_obj.getVerticesNumFilePath() 473 474 def get_file_path(self, property_group: PropertyGroup, chunk_index: int) -> str: 475 """Get the chunk file path of property group of vertex chunk. 476 477 :param property_group: the property group. 478 :param chunk_index: the index of vertex chunk 479 :returns: chunk file path. 480 481 """ 482 return self._jvm_vertex_info_obj.getFilePath( 483 property_group.to_scala(), 484 chunk_index, 485 ) 486 487 def get_path_prefix(self, property_group: PropertyGroup) -> str: 488 """Get the path prefix for the specified property group. 489 490 :param property_group: the property group. 491 :returns: the path prefix of the property group chunk files. 492 """ 493 return self._jvm_vertex_info_obj.getPathPrefix(property_group.to_scala()) 494 495 def dump(self) -> str: 496 """Dump to Yaml string. 497 498 :returns: yaml string 499 """ 500 return self._jvm_vertex_info_obj.dump() 501 502 @staticmethod 503 def load_vertex_info(vertex_info_path: str) -> "VertexInfo": 504 """Load a yaml file from path and construct a VertexInfo from it. 505 506 :param vertexInfoPath: yaml file path 507 :returns: VertexInfo object 508 """ 509 return VertexInfo.from_scala( 510 GraphArSession.graphar.VertexInfo.loadVertexInfo( 511 vertex_info_path, 512 GraphArSession.jss, 513 ), 514 ) 515 516 def to_scala(self) -> JavaObject: 517 """Transform object to JVM representation. 518 519 :returns: JavaObject 520 """ 521 return self._jvm_vertex_info_obj 522 523 @classmethod 524 def from_scala(cls: type[VertexInfoType], jvm_obj: JavaObject) -> VertexInfoType: 525 """Create an instance of the Class from the corresponding JVM object. 526 527 :param jvm_obj: scala object in JVM. 528 :returns: instance of Python Class. 529 """ 530 return VertexInfo( 531 None, 532 None, 533 None, 534 None, 535 None, 536 jvm_obj, 537 ) 538 539 @classmethod 540 def from_python( 541 cls: type[VertexInfoType], 542 label: str, 543 chunk_size: int, 544 prefix: str, 545 property_groups: Sequence[PropertyGroup], 546 version: str, 547 ) -> VertexInfoType: 548 """Create an instance of the class based on python args. 549 550 :param label: label of the vertex 551 :chunk_size: chunk size 552 :prefix: vertex prefix 553 :property_groups: list of property groups 554 :version: version of GraphAr format 555 """ 556 return VertexInfo(label, chunk_size, prefix, property_groups, version, None) 557 558 559# Return type of AdjList classmethods 560AdjListClassType = TypeVar("AdjListClassType", bound="AdjList") 561 562 563class AdjList: 564 """AdjList is a class to store the adj list information of edge.""" 565 566 def __init__( 567 self, 568 ordered: Optional[bool], 569 aligned_by: Optional[str], 570 prefix: Optional[str], 571 file_type: Optional[FileType], 572 jvm_obj: Optional[JavaObject], 573 ) -> None: 574 """One should not use this constructor directly, please use `from_scala` or `from_python`.""" 575 _check_session() 576 if jvm_obj is not None: 577 self._jvm_adj_list_obj = jvm_obj 578 else: 579 jvm_adj_list = GraphArSession.graphar.AdjList() 580 jvm_adj_list.setOrdered(ordered) 581 jvm_adj_list.setAligned_by(aligned_by) 582 jvm_adj_list.setPrefix(prefix) 583 jvm_adj_list.setFile_type(file_type.value) 584 self._jvm_adj_list_obj = jvm_adj_list 585 586 def get_ordered(self) -> bool: 587 """Get ordered flag from the corresponding JVM object. 588 589 :returns: ordered 590 """ 591 return self._jvm_adj_list_obj.getOrdered() 592 593 def set_ordered(self, ordered: bool) -> None: 594 """Mutate the corresponding JVM object. 595 596 :param ordered: new ordered flag 597 """ 598 self._jvm_adj_list_obj.setOrdered(ordered) 599 600 def get_aligned_by(self) -> str: 601 """Get aligned_by from the corresponding JVM object. 602 603 :returns: aligned by as a string ("src", "dst") 604 """ 605 return self._jvm_adj_list_obj.getAligned_by() 606 607 def set_aligned_by(self, aligned_by: str) -> None: 608 """Mutate the corresponding JVM object. 609 610 :param aligned_by: the new aligned_by (recommended to use "src" or "dst") 611 612 """ 613 self._jvm_adj_list_obj.setAligned_by(aligned_by) 614 615 def get_prefix(self) -> str: 616 """Get prefix from the corresponding JVM object. 617 618 :returns: prefix 619 """ 620 return self._jvm_adj_list_obj.getPrefix() 621 622 def set_prefix(self, prefix: str) -> None: 623 """Mutate the corresponding JVM object. 624 625 :param prefix: the new prefix 626 627 """ 628 self._jvm_adj_list_obj.setPrefix(prefix) 629 630 def get_file_type(self) -> FileType: 631 """Get FileType (as Enum) from the corresponding JVM object. 632 633 :returns: file type 634 """ 635 return FileType(self._jvm_adj_list_obj.getFile_type()) 636 637 def set_file_type(self, file_type: FileType) -> None: 638 """Mutate the corresponding JVM object. 639 640 :param file_type: the new file type 641 """ 642 self._jvm_adj_list_obj.setFile_type(file_type.value) 643 644 def get_adj_list_type(self) -> AdjListType: 645 """Get adj list type. 646 647 :returns: adj list type. 648 """ 649 return AdjListType(self._jvm_adj_list_obj.getAdjList_type()) 650 651 def to_scala(self) -> JavaObject: 652 """Transform object to JVM representation. 653 654 :returns: JavaObject 655 """ 656 return self._jvm_adj_list_obj 657 658 @classmethod 659 def from_scala( 660 cls: type[AdjListClassType], 661 jvm_obj: JavaObject, 662 ) -> AdjListClassType: 663 """Create an instance of the Class from the corresponding JVM object. 664 665 :param jvm_obj: scala object in JVM. 666 :returns: instance of Python Class. 667 """ 668 return AdjList(None, None, None, None, jvm_obj) 669 670 @classmethod 671 def from_python( 672 cls: type[AdjListClassType], 673 ordered: bool, 674 aligned_by: str, 675 prefix: str, 676 file_type: FileType, 677 ) -> AdjListClassType: 678 """Create an instance of the class from python arguments. 679 680 :param ordered: ordered flag 681 :param aligned_by: recommended values are "src" or "dst" 682 :param prefix: path prefix 683 :param file_type: file type 684 """ 685 if not prefix.endswith(os.sep): 686 prefix += os.sep 687 return AdjList(ordered, aligned_by, prefix, file_type, None) 688 689 def __eq__(self, other: object) -> bool: 690 if not isinstance(other, AdjList): 691 return False 692 693 return ( 694 (self.get_ordered() == other.get_ordered()) 695 and (self.get_aligned_by() == other.get_aligned_by()) 696 and (self.get_prefix() == other.get_prefix()) 697 and (self.get_file_type() == other.get_file_type()) 698 ) 699 700 701# Return type of EdgeInfo classmethods 702EdgeInfoType = TypeVar("EdgeInfoType", bound="EdgeInfo") 703 704 705class EdgeInfo: 706 """Edge info is a class to store the edge meta information.""" 707 708 def __init__( 709 self, 710 src_label: Optional[str], 711 edge_label: Optional[str], 712 dst_label: Optional[str], 713 chunk_size: Optional[int], 714 src_chunk_size: Optional[int], 715 dst_chunk_size: Optional[int], 716 directed: Optional[bool], 717 prefix: Optional[str], 718 adj_lists: Sequence[AdjList], 719 property_groups: Optional[Sequence[PropertyGroup]], 720 version: Optional[str], 721 jvm_edge_info_obj: JavaObject, 722 ) -> None: 723 """One should not use this constructor directly, please use `from_scala` or `from_python`.""" 724 _check_session() 725 if jvm_edge_info_obj is not None: 726 self._jvm_edge_info_obj = jvm_edge_info_obj 727 else: 728 edge_info = GraphArSession.graphar.EdgeInfo() 729 edge_info.setSrc_label(src_label) 730 edge_info.setEdge_label(edge_label) 731 edge_info.setDst_label(dst_label) 732 edge_info.setChunk_size(chunk_size) 733 edge_info.setSrc_chunk_size(src_chunk_size) 734 edge_info.setDst_chunk_size(dst_chunk_size) 735 edge_info.setDirected(directed) 736 edge_info.setPrefix(prefix) 737 edge_info.setAdj_lists( 738 [py_adj_list.to_scala() for py_adj_list in adj_lists], 739 ) 740 edge_info.setProperty_groups( 741 [py_property_group.to_scala() for py_property_group in property_groups], 742 ) 743 edge_info.setVersion(version) 744 self._jvm_edge_info_obj = edge_info 745 746 def get_src_label(self) -> str: 747 """Get src label from the corresponding JVM object. 748 749 :returns: src label 750 """ 751 return self._jvm_edge_info_obj.getSrc_label() 752 753 def set_src_label(self, src_label: str) -> None: 754 """Mutate the corresponding JVM object. 755 756 :param src_label: the new src label 757 """ 758 self._jvm_edge_info_obj.setSrc_label(src_label) 759 760 def get_edge_label(self) -> str: 761 """Get edge label from the corresponding JVM object. 762 763 :returns: edge label 764 """ 765 return self._jvm_edge_info_obj.getEdge_label() 766 767 def set_edge_label(self, edge_label: str) -> None: 768 """Mutate the corresponding JVM object. 769 770 :param edge_label: the new edge label 771 """ 772 self._jvm_edge_info_obj.setEdge_label(edge_label) 773 774 def get_dst_label(self) -> str: 775 """Get dst label from the corresponding JVM object. 776 777 :returns: dst label 778 """ 779 return self._jvm_edge_info_obj.getDst_label() 780 781 def set_dst_label(self, dst_label: str) -> None: 782 """Mutate the corresponding JVM object. 783 784 :param dst_label: the new dst label 785 """ 786 self._jvm_edge_info_obj.setDst_label(dst_label) 787 788 def get_chunk_size(self) -> int: 789 """Get chunk size from the corresponding JVM object. 790 791 :returns: chunk size 792 """ 793 return self._jvm_edge_info_obj.getChunk_size() 794 795 def set_chunk_size(self, chunk_size: int) -> None: 796 """Mutate the corresponding JVM object. 797 798 :param chunk_size: the new chunk size 799 """ 800 self._jvm_edge_info_obj.setChunk_size(chunk_size) 801 802 def get_src_chunk_size(self) -> int: 803 """Get source chunk size from the corresponding JVM object. 804 805 :returns: source chunk size 806 """ 807 return self._jvm_edge_info_obj.getSrc_chunk_size() 808 809 def set_src_chunk_size(self, src_chunk_size: int) -> None: 810 """Mutate the corresponding JVM object. 811 812 :param src_chunk_size: the new source chunk size. 813 """ 814 self._jvm_edge_info_obj.setSrc_chunk_size(src_chunk_size) 815 816 def get_dst_chunk_size(self) -> int: 817 """Get dest chunk size from the corresponding JVM object. 818 819 :returns: destination chunk size 820 """ 821 return self._jvm_edge_info_obj.getDst_chunk_size() 822 823 def set_dst_chunk_size(self, dst_chunk_size: int) -> None: 824 """Mutate the corresponding JVM object. 825 826 :param dst_chunk_size: the new destination chunk size. 827 """ 828 self._jvm_edge_info_obj.setDst_chunk_size(dst_chunk_size) 829 830 def get_directed(self) -> bool: 831 """Get directed flag from the corresponding JVM object. 832 833 :returns: directed flag 834 """ 835 return self._jvm_edge_info_obj.getDirected() 836 837 def set_directed(self, directed: bool) -> None: 838 """Mutate the corresponding JVM object. 839 840 :param directed: the new directed flag 841 """ 842 self._jvm_edge_info_obj.setDirected(directed) 843 844 def get_prefix(self) -> str: 845 """Get prefix from the corresponding JVM object. 846 847 :returns: prefix 848 """ 849 return self._jvm_edge_info_obj.getPrefix() 850 851 def set_prefix(self, prefix: str) -> None: 852 """Mutate the corresponding JVM object. 853 854 :param prefix: the new prefix 855 """ 856 self._jvm_edge_info_obj.setPrefix(prefix) 857 858 def get_adj_lists(self) -> Sequence[AdjList]: 859 """Get adj lists from the corresponding JVM object. 860 861 :returns: sequence of AdjList 862 """ 863 return [ 864 AdjList.from_scala(jvm_adj_list) 865 for jvm_adj_list in self._jvm_edge_info_obj.getAdj_lists() 866 ] 867 868 def set_adj_lists(self, adj_lists: Sequence[AdjList]) -> None: 869 """Mutate the corresponding JVM object. 870 871 :param adj_lists: the new adj lists, sequence of AdjList 872 """ 873 self._jvm_edge_info_obj.setAdj_lists( 874 [py_adj_list.to_scala() for py_adj_list in adj_lists], 875 ) 876 877 def get_property_groups(self) -> Sequence[PropertyGroup]: 878 """Get the property groups of adj list type. 879 880 WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method! 881 882 :returns: property groups of edge info. 883 """ 884 return [ 885 PropertyGroup.from_scala(jvm_property_group) 886 for jvm_property_group in self._jvm_edge_info_obj.getProperty_groups() 887 ] 888 889 def set_property_groups(self, property_groups: Sequence[PropertyGroup]) -> None: 890 """Mutate the corresponding JVM object. 891 892 :param property_groups: the new property groups, sequence of PropertyGroup 893 """ 894 self._jvm_edge_info_obj.setProperty_groups( 895 [py_property_group.to_scala() for py_property_group in property_groups], 896 ) 897 898 def get_version(self) -> str: 899 """Get GraphAr format version from the corresponding JVM object. 900 901 :returns: GraphAr format version 902 """ 903 return self._jvm_edge_info_obj.getVersion() 904 905 def set_version(self, version: str) -> None: 906 """Mutate the corresponding JVM object. 907 908 :param version: the new GraphAr format version 909 """ 910 self._jvm_edge_info_obj.setVersion(version) 911 912 def to_scala(self) -> JavaObject: 913 """Transform object to JVM representation. 914 915 :returns: JavaObject 916 """ 917 return self._jvm_edge_info_obj 918 919 @classmethod 920 def from_scala(cls: type[EdgeInfoType], jvm_obj: JavaObject) -> EdgeInfoType: 921 """Create an instance of the Class from the corresponding JVM object. 922 923 :param jvm_obj: scala object in JVM. 924 :returns: instance of Python Class. 925 """ 926 return EdgeInfo( 927 None, 928 None, 929 None, 930 None, 931 None, 932 None, 933 None, 934 None, 935 None, 936 None, 937 None, 938 jvm_obj, 939 ) 940 941 @classmethod 942 def from_python( 943 cls: type[EdgeInfoType], 944 src_label: str, 945 edge_label: str, 946 dst_label: str, 947 chunk_size: int, 948 src_chunk_size: int, 949 dst_chunk_size: int, 950 directed: bool, 951 prefix: str, 952 adj_lists: Sequence[AdjList], 953 property_groups: Sequence[PropertyGroup], 954 version: str, 955 ) -> EdgeInfoType: 956 """Create an instance of the class from python arguments. 957 958 :param src_label: source vertex label 959 :param edge_label: edges label 960 :param dst_label: destination vertex label 961 :param chunk_size: chunk size 962 :param src_chunk_size: source chunk size 963 :param dst_chunk_size: destination chunk size 964 :param directed: directed graph flag 965 :param prefix: path prefix 966 :param adj_lists: sequence of AdjList objects 967 :property_groups: sequence of of PropertyGroup objects 968 :param version: version of GraphAr format 969 """ 970 if not prefix.endswith(os.sep): 971 prefix += os.sep 972 973 return EdgeInfo( 974 src_label, 975 edge_label, 976 dst_label, 977 chunk_size, 978 src_chunk_size, 979 dst_chunk_size, 980 directed, 981 prefix, 982 adj_lists, 983 property_groups, 984 version, 985 None, 986 ) 987 988 def contain_adj_list(self, adj_list_type: AdjListType) -> bool: 989 """Check if the edge info supports the adj list type. 990 991 :param adj_list_type: adjList type in gar to check. 992 :returns: true if edge info supports the adj list type, otherwise return false. 993 """ 994 return self._jvm_edge_info_obj.containAdjList(adj_list_type.to_scala()) 995 996 def get_adj_list_prefix(self, adj_list_type: AdjListType) -> str: 997 """Get path prefix of adj list type. 998 999 WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method! 1000 1001 :param adj_list_type: The input adj list type in gar. 1002 :returns: path prefix of the adj list type, if edge info not support the adj list type, raise an IllegalArgumentException error. 1003 """ 1004 return self._jvm_edge_info_obj.getAdjListPrefix(adj_list_type.to_scala()) 1005 1006 def get_adj_list_file_type(self, adj_list_type: AdjListType) -> FileType: 1007 """Get the adj list topology chunk file type of adj list type. 1008 1009 WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method! 1010 1011 :param adj_list_type: the input adj list type. 1012 :returns: file format type in gar of the adj list type, if edge info not support the adj list type, 1013 raise an IllegalArgumentException error. 1014 """ 1015 return FileType.from_scala( 1016 self._jvm_edge_info_obj.getAdjListFileType(adj_list_type.to_scala()), 1017 ) 1018 1019 def contain_property_group( 1020 self, 1021 property_group: PropertyGroup, 1022 ) -> bool: 1023 """Check if the edge info contains the property group. 1024 1025 :param property_group: the property group to check. 1026 :returns: true if the edge info contains the property group in certain adj list 1027 structure. 1028 """ 1029 return self._jvm_edge_info_obj.containPropertyGroup( 1030 property_group.to_scala(), 1031 ) 1032 1033 def contain_property(self, property_name: str) -> bool: 1034 """Check if the edge info contains the property. 1035 1036 :param property_name: name of the property. 1037 :returns: true if edge info contains the property, otherwise false. 1038 """ 1039 return self._jvm_edge_info_obj.containProperty(property_name) 1040 1041 def get_property_group( 1042 self, 1043 property_name: str, 1044 ) -> PropertyGroup: 1045 """Get property group that contains property with adj list type. 1046 1047 WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method! 1048 1049 :param property_name: name of the property. 1050 :returns: property group that contains the property. If edge info not find the property group that contains the property, 1051 raise error. 1052 """ 1053 return PropertyGroup.from_scala( 1054 self._jvm_edge_info_obj.getPropertyGroup(property_name), 1055 ) 1056 1057 def get_property_type(self, property_name: str) -> GarType: 1058 """Get the data type of property. 1059 1060 WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method! 1061 1062 :param property_name: name of the property. 1063 :returns: data type in gar of the property. If edge info not contains the property, raise an IllegalArgumentException error. 1064 """ 1065 return GarType.from_scala( 1066 self._jvm_edge_info_obj.getPropertyType(property_name), 1067 ) 1068 1069 def is_primary_key(self, property_name: str) -> bool: 1070 """Check the property is primary key of edge info. 1071 1072 WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method! 1073 1074 :param property_name: name of the property. 1075 :returns: true if the property is the primary key of edge info, false if not. If 1076 edge info not contains the property, raise an IllegalArgumentException error. 1077 """ 1078 return self._jvm_edge_info_obj.isPrimaryKey(property_name) 1079 1080 def is_nullable_key(self, property_name: str) -> bool: 1081 """Check the property is nullable key of edge info. 1082 1083 :param property_name: name of the property. 1084 :returns: true if the property is the nullable key of edge info, false if not. If 1085 edge info not contains the property, raise an IllegalArgumentException error. 1086 """ 1087 return self._jvm_edge_info_obj.isNullableKey(property_name) 1088 1089 def get_primary_key(self) -> str: 1090 """Get Primary key of edge info. 1091 1092 :returns: primary key of edge info. 1093 """ 1094 return self._jvm_edge_info_obj.getPrimaryKey() 1095 1096 def is_validated(self) -> bool: 1097 """Check if the edge info is validated. 1098 1099 :returns: true if edge info is validated or false if not. 1100 """ 1101 return self._jvm_edge_info_obj.isValidated() 1102 1103 def get_vertices_num_file_path(self, adj_list_type: AdjListType) -> str: 1104 """Get the vertex num file path. 1105 1106 WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method! 1107 1108 :param adj_list_type: type of adj list structure. 1109 :returns: the vertex num file path. If edge info not support the adj list type, 1110 raise an IllegalArgumentException error. 1111 """ 1112 return self._jvm_edge_info_obj.getVerticesNumFilePath(adj_list_type.to_scala()) 1113 1114 def get_edges_num_path_prefix(self, adj_list_type: AdjListType) -> str: 1115 """Get the path prefix of the edge num file path. 1116 1117 WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method! 1118 1119 :param adj_list_type: type of adj list structure. 1120 :returns: the edge num file path. If edge info not support the adj list type, raise 1121 an IllegalArgumentException error. 1122 """ 1123 return self._jvm_edge_info_obj.getEdgesNumPathPrefix(adj_list_type.to_scala()) 1124 1125 def get_edges_num_file_path( 1126 self, 1127 chunk_index: int, 1128 adj_list_type: AdjListType, 1129 ) -> str: 1130 """Get the edge num file path of the vertex chunk. 1131 1132 WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method! 1133 1134 :param chunk_index: index of vertex chunk. 1135 :param adj_list_type: type of adj list structure. 1136 :returns: the edge num file path. If edge info not support the adj list type, raise 1137 an IllegalArgumentException error. 1138 """ 1139 return self._jvm_edge_info_obj.getEdgesNumFilePath( 1140 chunk_index, 1141 adj_list_type.to_scala(), 1142 ) 1143 1144 def get_adj_list_offset_file_path( 1145 self, 1146 chunk_index: int, 1147 adj_list_type: AdjListType, 1148 ) -> str: 1149 """Get the adj list offset chunk file path of vertex chunk the offset chunks is aligned with the vertex chunks. 1150 1151 WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method! 1152 1153 :param chunk_index: index of vertex chunk. 1154 :param adj_list_type: type of adj list structure. 1155 :returns: the offset chunk file path. If edge info not support the adj list type, raise an IllegalArgumentException error. 1156 1157 """ 1158 return self._jvm_edge_info_obj.getAdjListOffsetFilePath( 1159 chunk_index, 1160 adj_list_type.to_scala(), 1161 ) 1162 1163 def get_offset_path_prefix(self, adj_list_type: AdjListType) -> str: 1164 """Get the path prefix of the adjacency list offset for the given adjacency list type. 1165 1166 WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method! 1167 1168 :param adj_list_type: type of adj list structure. 1169 :returns: the path prefix of the offset. If edge info not support the adj list type, raise an IllegalArgumentException error. 1170 1171 """ 1172 return self._jvm_edge_info_obj.getOffsetPathPrefix(adj_list_type.to_scala()) 1173 1174 def get_adj_list_file_path( 1175 self, 1176 vertex_chunk_index: int, 1177 chunk_index: int, 1178 adj_list_type: AdjListType, 1179 ) -> str: 1180 """Get the file path of adj list topology chunk. 1181 1182 :param vertex_chunk_index: index of vertex chunk. 1183 :param chunk_index: index of edge chunk. 1184 :param adj_list_type: type of adj list structure. 1185 :returns: adj list chunk file path. 1186 """ 1187 return self._jvm_edge_info_obj.getAdjListFilePath( 1188 vertex_chunk_index, 1189 chunk_index, 1190 adj_list_type.to_scala(), 1191 ) 1192 1193 def get_adj_list_path_prefix( 1194 self, 1195 vertex_chunk_index: Optional[int], 1196 adj_list_type: AdjListType, 1197 ) -> str: 1198 """Get the path prefix of adj list topology chunk of certain vertex chunk. 1199 1200 :param vertex_chunk_index: index of vertex chunk (optional). 1201 :param adj_list_type: type of adj list structure. 1202 :returns: path prefix of the edge chunk of vertices of given vertex chunk. 1203 """ 1204 if vertex_chunk_index is None: 1205 return self._jvm_edge_info_obj.getAdjListPathPrefix( 1206 adj_list_type.to_scala(), 1207 ) 1208 1209 return self._jvm_edge_info_obj.getAdjListPathPrefix( 1210 vertex_chunk_index, 1211 adj_list_type.to_scala(), 1212 ) 1213 1214 def get_property_file_path( 1215 self, 1216 property_group: PropertyGroup, 1217 adj_list_type: AdjListType, 1218 vertex_chunk_index: int, 1219 chunk_index: int, 1220 ) -> str: 1221 """Get the chunk file path of adj list property group. the property group chunks is aligned with the adj list topology chunks. 1222 1223 WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method! 1224 1225 :param property_group: property group 1226 :param adj_list_type: type of adj list structure. 1227 :param vertex_chunk_index: index of vertex chunk. 1228 :param chunk_index: index of edge chunk. 1229 :returns: property group chunk file path. If edge info not contains the property group, raise an IllegalArgumentException error. 1230 """ 1231 return self._jvm_edge_info_obj.getPropertyFilePath( 1232 property_group.to_scala(), 1233 adj_list_type.to_scala(), 1234 vertex_chunk_index, 1235 chunk_index, 1236 ) 1237 1238 def get_property_group_path_prefix( 1239 self, 1240 property_group: PropertyGroup, 1241 adj_list_type: AdjListType, 1242 vertex_chunk_index: Optional[int] = None, 1243 ) -> str: 1244 """Get path prefix of adj list property group of certain vertex chunk. 1245 1246 WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method! 1247 1248 :param property_group: property group. 1249 :param adj_list_type: type of adj list structure. 1250 :param vertex_chunk_index: index of vertex chunk (optional, default is None). 1251 :returns: path prefix of property group chunks of of vertices of given vertex 1252 chunk. If edge info not contains the property group, raise an IllegalArgumentException error. 1253 """ 1254 if vertex_chunk_index is not None: 1255 return self._jvm_edge_info_obj.getPropertyGroupPathPrefix( 1256 property_group.to_scala(), 1257 adj_list_type.to_scala(), 1258 vertex_chunk_index, 1259 ) 1260 1261 return self._jvm_edge_info_obj.getPropertyGroupPathPrefix( 1262 property_group.to_scala(), 1263 adj_list_type.to_scala(), 1264 ) 1265 1266 def get_concat_key(self) -> str: 1267 """Get concat key. 1268 1269 :returns: concat key 1270 """ 1271 return self._jvm_edge_info_obj.getConcatKey() 1272 1273 def dump(self) -> str: 1274 """Dump to Yaml string. 1275 1276 :returns: yaml-string representation. 1277 """ 1278 return self._jvm_edge_info_obj.dump() 1279 1280 @staticmethod 1281 def load_edge_info(edge_info_path: str) -> "EdgeInfo": 1282 """Load a yaml file from path and construct a EdgeInfo from it. 1283 1284 :param edge_info_path: path of edge info YAML file. 1285 :returns: EdgeInfo object. 1286 """ 1287 return EdgeInfo.from_scala( 1288 GraphArSession.graphar.EdgeInfo.loadEdgeInfo( 1289 edge_info_path, 1290 GraphArSession.jss, 1291 ), 1292 ) 1293 1294 1295class GraphInfo: 1296 """GraphInfo is a class to store the graph meta information.""" 1297 1298 def __init__( 1299 self, 1300 name: Optional[str], 1301 prefix: Optional[str], 1302 vertices: Optional[list[str]], 1303 edges: Optional[list[str]], 1304 version: Optional[str], 1305 jvm_grpah_info_obj: Optional[JavaObject], 1306 ) -> None: 1307 """One should not use this constructor directly, please use `from_scala` or `from_python`.""" 1308 _check_session() 1309 if jvm_grpah_info_obj is not None: 1310 self._jvm_graph_info_obj = jvm_grpah_info_obj 1311 else: 1312 graph_info = GraphArSession.graphar.GraphInfo() 1313 graph_info.setName(name) 1314 graph_info.setPrefix(prefix) 1315 graph_info.setVertices(vertices) 1316 graph_info.setEdges(edges) 1317 graph_info.setVersion(version) 1318 self._jvm_graph_info_obj = graph_info 1319 1320 def get_name(self) -> str: 1321 """Get name from the corresponding JVM object. 1322 1323 :returns: name 1324 """ 1325 return self._jvm_graph_info_obj.getName() 1326 1327 def set_name(self, name: str) -> None: 1328 """Mutate the corresponding JVM object. 1329 1330 :param name: new name 1331 """ 1332 self._jvm_graph_info_obj.setName(name) 1333 1334 def get_prefix(self) -> str: 1335 """Get prefix from corresponding JVM object. 1336 1337 :returns: prefix 1338 """ 1339 return self._jvm_graph_info_obj.getPrefix() 1340 1341 def set_prefix(self, prefix: str) -> None: 1342 """Mutate the corresponding JVM object. 1343 1344 :param prefix: new prefix 1345 """ 1346 self._jvm_graph_info_obj.setPrefix(prefix) 1347 1348 def get_vertices(self) -> JavaList: 1349 """Get list of vertices from the corresponding JVM object. 1350 1351 :returns: vertices 1352 """ 1353 return self._jvm_graph_info_obj.getVertices() 1354 1355 def set_vertices(self, vertices: Union[list[str], JavaList]) -> None: 1356 """Mutate the corresponding JVM object. 1357 1358 :param vertices: new list of vertices 1359 """ 1360 self._jvm_graph_info_obj.setVertices(vertices) 1361 1362 def get_edges(self) -> JavaList: 1363 """Get list of edges from the corresponding JVM object. 1364 1365 :returns: edges 1366 """ 1367 return self._jvm_graph_info_obj.getEdges() 1368 1369 def set_edges(self, edges: Union[list[str], JavaList]) -> None: 1370 """Mutate the corresponding JVM object. 1371 1372 :param edges: new list of edges. 1373 """ 1374 self._jvm_graph_info_obj.setEdges(edges) 1375 1376 def get_version(self) -> str: 1377 """Get GraphAr format version from the corresponding JVM object. 1378 1379 :returns: version 1380 """ 1381 return self._jvm_graph_info_obj.getVersion() 1382 1383 def set_version(self, version: str) -> None: 1384 """Mutate the corresponding JVM object. 1385 1386 :param version: new version of GraphAr format 1387 """ 1388 self._jvm_graph_info_obj.setVersion(version) 1389 1390 def to_scala(self) -> JavaObject: 1391 """Transform object to JVM representation. 1392 1393 :returns: JavaObject 1394 """ 1395 return self._jvm_graph_info_obj 1396 1397 @staticmethod 1398 def from_scala(jvm_obj: JavaObject) -> "GraphInfo": 1399 """Create an instance of the Class from the corresponding JVM object. 1400 1401 :param jvm_obj: scala object in JVM. 1402 :returns: instance of Python Class. 1403 """ 1404 return GraphInfo(None, None, None, None, None, jvm_obj) 1405 1406 @staticmethod 1407 def from_python( 1408 name: str, 1409 prefix: str, 1410 vertices: Sequence[str], 1411 edges: Sequence[str], 1412 version: str, 1413 ) -> "GraphInfo": 1414 """Create an instance of the class from python arguments. 1415 1416 :param name: name of the graph 1417 :param prefix: path prefix 1418 :param vertices: list of vertices 1419 :param edges: list of edges 1420 :param version: version of GraphAr format 1421 """ 1422 if not prefix.endswith(os.sep): 1423 prefix += os.sep 1424 return GraphInfo(name, prefix, vertices, edges, version, None) 1425 1426 def add_vertex_info(self, vertex_info: VertexInfo) -> None: 1427 """Add VertexInfo to GraphInfo. 1428 1429 :param vertex_info: VertexInfo to add 1430 """ 1431 self._jvm_graph_info_obj.addVertexInfo(vertex_info.to_scala()) 1432 1433 def add_edge_info(self, edge_info: EdgeInfo) -> None: 1434 """Add EdgeInfo to GraphInfo. 1435 1436 :param edge_info: EdgeInfo to add 1437 """ 1438 self._jvm_graph_info_obj.addEdgeInfo(edge_info.to_scala()) 1439 1440 def get_vertex_info(self, label: str) -> VertexInfo: 1441 """Get vertex info from the corresponding JVM object. 1442 1443 :param label: label of vertex 1444 """ 1445 return VertexInfo.from_scala(self._jvm_graph_info_obj.getVertexInfo(label)) 1446 1447 def get_edge_info( 1448 self, 1449 src_label: str, 1450 edge_label: str, 1451 dst_label: str, 1452 ) -> EdgeInfo: 1453 """Get edge info from the corresponding JVM object. 1454 1455 :param src_label: source label 1456 :param edge_label: edge label 1457 :param dst_label: destination label 1458 """ 1459 return EdgeInfo.from_scala( 1460 self._jvm_graph_info_obj.getEdgeInfo(src_label, edge_label, dst_label), 1461 ) 1462 1463 def get_vertex_infos(self) -> dict[str, VertexInfo]: 1464 """Get all vertex infos from the corresponding JVM object. 1465 1466 :returns: Mapping label -> VertexInfo 1467 """ 1468 scala_map = self._jvm_graph_info_obj.getVertexInfos() 1469 keys_set_iter = scala_map.keySet().iterator() 1470 res = {} 1471 while keys_set_iter.hasNext(): 1472 k = keys_set_iter.next() 1473 res[k] = VertexInfo.from_scala(scala_map.get(k)) 1474 1475 return res 1476 1477 def get_edge_infos(self) -> dict[str, EdgeInfo]: 1478 """Get all edge infos from the corresponding JVM object. 1479 1480 :returns: Mapping {src_label}_{edge_label}_{dst_label} -> EdgeInfo 1481 """ 1482 scala_map = self._jvm_graph_info_obj.getEdgeInfos() 1483 keys_set_iter = scala_map.keySet().iterator() 1484 res = {} 1485 while keys_set_iter.hasNext(): 1486 k = keys_set_iter.next() 1487 res[k] = EdgeInfo.from_scala(scala_map.get(k)) 1488 1489 return res 1490 1491 def dump(self) -> str: 1492 """Dump to Yaml string. 1493 1494 :returns: YAML-string representation of object. 1495 """ 1496 return self._jvm_graph_info_obj.dump() 1497 1498 @staticmethod 1499 def load_graph_info(graph_info_path: str) -> "GraphInfo": 1500 """Load a yaml file from path and construct a GraphInfo from it. 1501 1502 :param graph_info_path: path of GraphInfo YAML file. 1503 :returns: GraphInfo object. 1504 """ 1505 return GraphInfo.from_scala( 1506 GraphArSession.graphar.GraphInfo.loadGraphInfo( 1507 graph_info_path, 1508 GraphArSession.jss, 1509 ), 1510 )
40class Property: 41 """The property information of vertex or edge.""" 42 43 def __init__( 44 self, 45 name: Optional[str], 46 data_type: Optional[GarType], 47 is_primary: Optional[bool], 48 is_nullable: Optional[bool], 49 jvm_obj: Optional[JavaObject] = None, 50 ) -> None: 51 """One should not use this constructor directly, please use `from_scala` or `from_python`.""" 52 _check_session() 53 if jvm_obj is not None: 54 self._jvm_property_obj = jvm_obj 55 else: 56 property_pyobj = GraphArSession.graphar.Property() 57 property_pyobj.setName(name) 58 property_pyobj.setData_type(data_type.value) 59 property_pyobj.setIs_primary(is_primary) 60 property_pyobj.setIs_nullable(is_nullable) 61 62 self._jvm_property_obj = property_pyobj 63 64 def get_name(self) -> str: 65 """Get name from corresponding JVM object. 66 67 :returns: name 68 """ 69 return self._jvm_property_obj.getName() 70 71 def set_name(self, name: str) -> None: 72 """Mutate corresponding JVM object. 73 74 :param name: name 75 """ 76 self._jvm_property_obj.setName(name) 77 78 def get_data_type(self) -> GarType: 79 """Get data type from corresponding JVM object. 80 81 :returns: data type 82 """ 83 return GarType(self._jvm_property_obj.getData_type()) 84 85 def set_data_type(self, data_type: GarType) -> None: 86 """Mutate corresponding JVM object. 87 88 :param data_type: data type 89 """ 90 self._jvm_property_obj.setData_type(data_type.value) 91 92 def get_is_primary(self) -> bool: 93 """Get is priamry flag from corresponding JVM object. 94 95 :returns: is primary 96 """ 97 return self._jvm_property_obj.getIs_primary() 98 99 def set_is_primary(self, is_primary: bool) -> None: 100 """Mutate corresponding JVM object. 101 102 :param is_primary: is primary 103 """ 104 self._jvm_property_obj.setIs_primary(is_primary) 105 106 def set_is_nullable(self, is_nullable: bool) -> None: 107 """Mutate corresponding JVM object. 108 109 :param is_nullable: is nullable 110 """ 111 self._jvm_property_obj.setIs_nullable(is_nullable) 112 113 def get_is_nullable(self) -> bool: 114 """Get is nullable flag from corresponding JVM object. 115 116 :returns: is nullable 117 """ 118 return self._jvm_property_obj.getIs_nullable() 119 120 def to_scala(self) -> JavaObject: 121 """Transform object to JVM representation. 122 123 :returns: JavaObject 124 """ 125 return self._jvm_property_obj 126 127 @classmethod 128 def from_scala(cls: type[PropertyType], jvm_obj: JavaObject) -> PropertyType: 129 """Create an instance of the Class from the corresponding JVM object. 130 131 :param jvm_obj: scala object in JVM. 132 :returns: instance of Python Class. 133 """ 134 return cls(None, None, None, None, jvm_obj) 135 136 @classmethod 137 def from_python( 138 cls: type[PropertyType], 139 name: str, 140 data_type: GarType, 141 is_primary: bool, 142 is_nullable: Optional[bool] = None, 143 ) -> PropertyType: 144 """Create an instance of the Class from Python arguments. 145 146 :param name: property name 147 :param data_type: property data type 148 :param is_primary: flag that property is primary 149 :param is_nullable: flag that property is nullable (optional, default is None) 150 :returns: instance of Python Class. 151 """ 152 return cls(name, data_type, is_primary, is_nullable, None) 153 154 def __eq__(self, other: object) -> bool: 155 if not isinstance(other, Property): 156 return False 157 158 return ( 159 (self.get_name() == other.get_name()) 160 and (self.get_data_type() == other.get_data_type()) 161 and (self.get_is_primary() == other.get_is_primary()) 162 and (self.get_is_nullable() == other.get_is_nullable()) 163 )
The property information of vertex or edge.
43 def __init__( 44 self, 45 name: Optional[str], 46 data_type: Optional[GarType], 47 is_primary: Optional[bool], 48 is_nullable: Optional[bool], 49 jvm_obj: Optional[JavaObject] = None, 50 ) -> None: 51 """One should not use this constructor directly, please use `from_scala` or `from_python`.""" 52 _check_session() 53 if jvm_obj is not None: 54 self._jvm_property_obj = jvm_obj 55 else: 56 property_pyobj = GraphArSession.graphar.Property() 57 property_pyobj.setName(name) 58 property_pyobj.setData_type(data_type.value) 59 property_pyobj.setIs_primary(is_primary) 60 property_pyobj.setIs_nullable(is_nullable) 61 62 self._jvm_property_obj = property_pyobj
One should not use this constructor directly, please use from_scala
or from_python
.
64 def get_name(self) -> str: 65 """Get name from corresponding JVM object. 66 67 :returns: name 68 """ 69 return self._jvm_property_obj.getName()
Get name from corresponding JVM object.
:returns: name
71 def set_name(self, name: str) -> None: 72 """Mutate corresponding JVM object. 73 74 :param name: name 75 """ 76 self._jvm_property_obj.setName(name)
Mutate corresponding JVM object.
Parameters
- name: name
78 def get_data_type(self) -> GarType: 79 """Get data type from corresponding JVM object. 80 81 :returns: data type 82 """ 83 return GarType(self._jvm_property_obj.getData_type())
Get data type from corresponding JVM object.
:returns: data type
85 def set_data_type(self, data_type: GarType) -> None: 86 """Mutate corresponding JVM object. 87 88 :param data_type: data type 89 """ 90 self._jvm_property_obj.setData_type(data_type.value)
Mutate corresponding JVM object.
Parameters
- data_type: data type
92 def get_is_primary(self) -> bool: 93 """Get is priamry flag from corresponding JVM object. 94 95 :returns: is primary 96 """ 97 return self._jvm_property_obj.getIs_primary()
Get is priamry flag from corresponding JVM object.
:returns: is primary
99 def set_is_primary(self, is_primary: bool) -> None: 100 """Mutate corresponding JVM object. 101 102 :param is_primary: is primary 103 """ 104 self._jvm_property_obj.setIs_primary(is_primary)
Mutate corresponding JVM object.
Parameters
- is_primary: is primary
106 def set_is_nullable(self, is_nullable: bool) -> None: 107 """Mutate corresponding JVM object. 108 109 :param is_nullable: is nullable 110 """ 111 self._jvm_property_obj.setIs_nullable(is_nullable)
Mutate corresponding JVM object.
Parameters
- is_nullable: is nullable
113 def get_is_nullable(self) -> bool: 114 """Get is nullable flag from corresponding JVM object. 115 116 :returns: is nullable 117 """ 118 return self._jvm_property_obj.getIs_nullable()
Get is nullable flag from corresponding JVM object.
:returns: is nullable
120 def to_scala(self) -> JavaObject: 121 """Transform object to JVM representation. 122 123 :returns: JavaObject 124 """ 125 return self._jvm_property_obj
Transform object to JVM representation.
:returns: JavaObject
127 @classmethod 128 def from_scala(cls: type[PropertyType], jvm_obj: JavaObject) -> PropertyType: 129 """Create an instance of the Class from the corresponding JVM object. 130 131 :param jvm_obj: scala object in JVM. 132 :returns: instance of Python Class. 133 """ 134 return cls(None, None, None, None, jvm_obj)
Create an instance of the Class from the corresponding JVM object.
Parameters
- jvm_obj: scala object in JVM. :returns: instance of Python Class.
136 @classmethod 137 def from_python( 138 cls: type[PropertyType], 139 name: str, 140 data_type: GarType, 141 is_primary: bool, 142 is_nullable: Optional[bool] = None, 143 ) -> PropertyType: 144 """Create an instance of the Class from Python arguments. 145 146 :param name: property name 147 :param data_type: property data type 148 :param is_primary: flag that property is primary 149 :param is_nullable: flag that property is nullable (optional, default is None) 150 :returns: instance of Python Class. 151 """ 152 return cls(name, data_type, is_primary, is_nullable, None)
Create an instance of the Class from Python arguments.
Parameters
- name: property name
- data_type: property data type
- is_primary: flag that property is primary
- is_nullable: flag that property is nullable (optional, default is None) :returns: instance of Python Class.
170class PropertyGroup: 171 """PropertyGroup is a class to store the property group information.""" 172 173 def __init__( 174 self, 175 prefix: Optional[str], 176 file_type: Optional[FileType], 177 properties: Optional[Sequence[Property]], 178 jvm_obj: Optional[JavaObject], 179 ) -> None: 180 """One should not use this constructor directly, please use `from_scala` or `from_python`.""" 181 _check_session() 182 if jvm_obj is not None: 183 self._jvm_property_group_obj = jvm_obj 184 else: 185 property_group = GraphArSession.graphar.PropertyGroup() 186 property_group.setPrefix(prefix) 187 property_group.setFile_type(file_type.value) 188 property_group.setProperties( 189 [py_property.to_scala() for py_property in properties], 190 ) 191 self._jvm_property_group_obj = property_group 192 193 def get_prefix(self) -> str: 194 """Get prefix from the corresponding JVM object. 195 196 :returns: prefix 197 """ 198 return self._jvm_property_group_obj.getPrefix() 199 200 def set_prefix(self, prefix: str) -> None: 201 """Mutate the corresponding JVM object. 202 203 :param prefix: prefix 204 """ 205 self._jvm_property_group_obj.setPrefix(prefix) 206 207 def get_file_type(self) -> FileType: 208 """Get file type from the corresponding JVM object. 209 210 :returns: FileType 211 """ 212 return FileType(self._jvm_property_group_obj.getFile_type()) 213 214 def set_file_type(self, file_type: FileType) -> None: 215 """Mutate the corresponding JVM object. 216 217 :param file_type: FileType 218 """ 219 self._jvm_property_group_obj.setFile_type(file_type.value) 220 221 def get_properties(self) -> Sequence[Property]: 222 """Get properties from the corresponding JVM object. 223 224 :returns: list of Properties 225 """ 226 return [ 227 Property.from_scala(jvm_property) 228 for jvm_property in self._jvm_property_group_obj.getProperties() 229 ] 230 231 def set_properties(self, properties: Sequence[Property]) -> None: 232 """Mutate the corresponding JVM object. 233 234 :param properties: list of Properties 235 """ 236 self._jvm_property_group_obj.setProperties( 237 [py_property.to_scala() for py_property in properties], 238 ) 239 240 def to_scala(self) -> JavaObject: 241 """Transform object to JVM representation. 242 243 :returns: JavaObject 244 """ 245 return self._jvm_property_group_obj 246 247 @classmethod 248 def from_scala( 249 cls: type[PropertyGroupType], 250 jvm_obj: JavaObject, 251 ) -> PropertyGroupType: 252 """Create an instance of the Class from the corresponding JVM object. 253 254 :param jvm_obj: scala object in JVM. 255 :returns: instance of Python Class. 256 """ 257 return cls(None, None, None, jvm_obj) 258 259 @classmethod 260 def from_python( 261 cls: type[PropertyGroupType], 262 prefix: str, 263 file_type: FileType, 264 properties: Sequence[Property], 265 ) -> PropertyGroupType: 266 """Create an instance of the class from Python args. 267 268 :param prefix: path prefix 269 :param file_type: type of file 270 :param properties: list of properties 271 """ 272 return cls(prefix, file_type, properties, None) 273 274 def __eq__(self, other: object) -> bool: 275 if not isinstance(other, PropertyGroup): 276 return False 277 278 return ( 279 (self.get_prefix() == other.get_prefix()) 280 and (self.get_file_type() == other.get_file_type()) 281 and (len(self.get_properties()) == len(other.get_properties())) 282 and all( 283 p_left == p_right 284 for p_left, p_right in zip( 285 self.get_properties(), 286 other.get_properties(), 287 ) 288 ) 289 )
PropertyGroup is a class to store the property group information.
173 def __init__( 174 self, 175 prefix: Optional[str], 176 file_type: Optional[FileType], 177 properties: Optional[Sequence[Property]], 178 jvm_obj: Optional[JavaObject], 179 ) -> None: 180 """One should not use this constructor directly, please use `from_scala` or `from_python`.""" 181 _check_session() 182 if jvm_obj is not None: 183 self._jvm_property_group_obj = jvm_obj 184 else: 185 property_group = GraphArSession.graphar.PropertyGroup() 186 property_group.setPrefix(prefix) 187 property_group.setFile_type(file_type.value) 188 property_group.setProperties( 189 [py_property.to_scala() for py_property in properties], 190 ) 191 self._jvm_property_group_obj = property_group
One should not use this constructor directly, please use from_scala
or from_python
.
193 def get_prefix(self) -> str: 194 """Get prefix from the corresponding JVM object. 195 196 :returns: prefix 197 """ 198 return self._jvm_property_group_obj.getPrefix()
Get prefix from the corresponding JVM object.
:returns: prefix
200 def set_prefix(self, prefix: str) -> None: 201 """Mutate the corresponding JVM object. 202 203 :param prefix: prefix 204 """ 205 self._jvm_property_group_obj.setPrefix(prefix)
Mutate the corresponding JVM object.
Parameters
- prefix: prefix
207 def get_file_type(self) -> FileType: 208 """Get file type from the corresponding JVM object. 209 210 :returns: FileType 211 """ 212 return FileType(self._jvm_property_group_obj.getFile_type())
Get file type from the corresponding JVM object.
:returns: FileType
214 def set_file_type(self, file_type: FileType) -> None: 215 """Mutate the corresponding JVM object. 216 217 :param file_type: FileType 218 """ 219 self._jvm_property_group_obj.setFile_type(file_type.value)
Mutate the corresponding JVM object.
Parameters
- file_type: FileType
221 def get_properties(self) -> Sequence[Property]: 222 """Get properties from the corresponding JVM object. 223 224 :returns: list of Properties 225 """ 226 return [ 227 Property.from_scala(jvm_property) 228 for jvm_property in self._jvm_property_group_obj.getProperties() 229 ]
Get properties from the corresponding JVM object.
:returns: list of Properties
231 def set_properties(self, properties: Sequence[Property]) -> None: 232 """Mutate the corresponding JVM object. 233 234 :param properties: list of Properties 235 """ 236 self._jvm_property_group_obj.setProperties( 237 [py_property.to_scala() for py_property in properties], 238 )
Mutate the corresponding JVM object.
Parameters
- properties: list of Properties
240 def to_scala(self) -> JavaObject: 241 """Transform object to JVM representation. 242 243 :returns: JavaObject 244 """ 245 return self._jvm_property_group_obj
Transform object to JVM representation.
:returns: JavaObject
247 @classmethod 248 def from_scala( 249 cls: type[PropertyGroupType], 250 jvm_obj: JavaObject, 251 ) -> PropertyGroupType: 252 """Create an instance of the Class from the corresponding JVM object. 253 254 :param jvm_obj: scala object in JVM. 255 :returns: instance of Python Class. 256 """ 257 return cls(None, None, None, jvm_obj)
Create an instance of the Class from the corresponding JVM object.
Parameters
- jvm_obj: scala object in JVM. :returns: instance of Python Class.
259 @classmethod 260 def from_python( 261 cls: type[PropertyGroupType], 262 prefix: str, 263 file_type: FileType, 264 properties: Sequence[Property], 265 ) -> PropertyGroupType: 266 """Create an instance of the class from Python args. 267 268 :param prefix: path prefix 269 :param file_type: type of file 270 :param properties: list of properties 271 """ 272 return cls(prefix, file_type, properties, None)
Create an instance of the class from Python args.
Parameters
- prefix: path prefix
- file_type: type of file
- properties: list of properties
296class VertexInfo: 297 """VertexInfo is a class to store the vertex meta information.""" 298 299 def __init__( 300 self, 301 label: Optional[str], 302 chunk_size: Optional[int], 303 prefix: Optional[str], 304 property_groups: Optional[Sequence[PropertyGroup]], 305 version: Optional[str], 306 jvm_obj: Optional[JavaObject], 307 ) -> None: 308 """One should not use this constructor directly, please use `from_scala` or `from_python`.""" 309 _check_session() 310 if jvm_obj is not None: 311 self._jvm_vertex_info_obj = jvm_obj 312 else: 313 vertex_info = GraphArSession.graphar.VertexInfo() 314 vertex_info.setLabel(label) 315 vertex_info.setChunk_size(chunk_size) 316 vertex_info.setPrefix(prefix) 317 vertex_info.setProperty_groups( 318 [py_property_group.to_scala() for py_property_group in property_groups], 319 ) 320 vertex_info.setVersion(version) 321 self._jvm_vertex_info_obj = vertex_info 322 323 def get_label(self) -> str: 324 """Get label from the corresponding JVM object. 325 326 :returns: label 327 """ 328 return self._jvm_vertex_info_obj.getLabel() 329 330 def set_label(self, label: str) -> None: 331 """Mutate the corresponding JVM object. 332 333 :param label: new label 334 """ 335 self._jvm_vertex_info_obj.setLabel(label) 336 337 def get_chunk_size(self) -> int: 338 """Get chunk size from the corresponding JVM object. 339 340 :returns: chunk size 341 """ 342 return self._jvm_vertex_info_obj.getChunk_size() 343 344 def set_chunk_size(self, chunk_size: int) -> None: 345 """Mutate the corresponding JVM object. 346 347 :param chunk_size: new chunk size 348 """ 349 self._jvm_vertex_info_obj.setChunk_size(chunk_size) 350 351 def get_prefix(self) -> str: 352 """Get prefix from the corresponding JVM object. 353 354 :returns: prefix 355 """ 356 return self._jvm_vertex_info_obj.getPrefix() 357 358 def set_prefix(self, prefix: str) -> None: 359 """Mutate the corresponding JVM object. 360 361 :param prefix: the new pefix. 362 """ 363 self._jvm_vertex_info_obj.setPrefix(prefix) 364 365 def get_property_groups(self) -> Sequence[PropertyGroup]: 366 """Get property groups from the corresponding JVM object. 367 368 :returns: property groups 369 """ 370 return [ 371 PropertyGroup.from_scala(jvm_property_group) 372 for jvm_property_group in self._jvm_vertex_info_obj.getProperty_groups() 373 ] 374 375 def set_property_groups(self, property_groups: Sequence[PropertyGroup]) -> None: 376 """Mutate the corresponding JVM object. 377 378 :param property_groups: new property groups 379 """ 380 self._jvm_vertex_info_obj.setProperty_groups( 381 [py_property_group.to_scala() for py_property_group in property_groups], 382 ) 383 384 def get_version(self) -> str: 385 """Get version from the corresponding JVM object. 386 387 :returns: version 388 """ 389 return self._jvm_vertex_info_obj.getVersion() 390 391 def set_version(self, version: str) -> None: 392 """Mutate the corresponding JVM object. 393 394 :param version: the new version. 395 """ 396 self._jvm_vertex_info_obj.setVersion(version) 397 398 def contain_property_group(self, property_group: PropertyGroup) -> bool: 399 """Check if the vertex info contains the property group. 400 401 :param property_group: the property group to check. 402 :returns: true if the vertex info contains the property group, otherwise false. 403 """ 404 return self._jvm_vertex_info_obj.containPropertyGroup(property_group.to_scala()) 405 406 def contain_property(self, property_name: str) -> bool: 407 """Check if the vertex info contains certain property. 408 409 :param property_name: name of the property. 410 :returns: true if the vertex info contains the property, otherwise false. 411 """ 412 return self._jvm_vertex_info_obj.containProperty(property_name) 413 414 def get_property_group(self, property_name: str) -> PropertyGroup: 415 """Get the property group that contains property. 416 417 WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method! 418 419 :param property_name: name of the property. 420 :returns: property group that contains the property, otherwise raise IllegalArgumentException error. 421 """ 422 return PropertyGroup.from_scala( 423 self._jvm_vertex_info_obj.getPropertyGroup(property_name), 424 ) 425 426 def get_property_type(self, property_name: str) -> GarType: 427 """Get the data type of property. 428 429 WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method! 430 431 :param property_name: name of the property. 432 :returns: the data type in gar of the property. If the vertex info does not contains the property, raise IllegalArgumentException error. 433 """ 434 return GarType.from_scala( 435 self._jvm_vertex_info_obj.getPropertyType(property_name), 436 ) 437 438 def is_primary_key(self, property_name: str) -> bool: 439 """Check if the property is primary key. 440 441 :param property_name: name of the property to check. 442 :returns: true if the property if the primary key of vertex info, otherwise return false. 443 """ 444 return self._jvm_vertex_info_obj.isPrimaryKey(property_name) 445 446 def get_primary_key(self) -> str: 447 """Get primary key of vertex info. 448 449 :returns: name of the primary key. 450 """ 451 return self._jvm_vertex_info_obj.getPrimaryKey() 452 453 def is_nullable_key(self, property_name: str) -> bool: 454 """Check if the property is nullable key. 455 456 :param property_name: name of the property to check. 457 :returns: true if the property if a nullable key of vertex info, otherwise return false 458 """ 459 return self._jvm_vertex_info_obj.isNullableKey(property_name) 460 461 def is_validated(self) -> bool: 462 """Check if the vertex info is validated. 463 464 :returns: true if the vertex info is validated, otherwise return false. 465 """ 466 return self._jvm_vertex_info_obj.isValidated() 467 468 def get_vertices_num_file_path(self) -> str: 469 """Get the vertex num file path of vertex info. 470 471 :returns: vertex num file path of vertex info. 472 """ 473 return self._jvm_vertex_info_obj.getVerticesNumFilePath() 474 475 def get_file_path(self, property_group: PropertyGroup, chunk_index: int) -> str: 476 """Get the chunk file path of property group of vertex chunk. 477 478 :param property_group: the property group. 479 :param chunk_index: the index of vertex chunk 480 :returns: chunk file path. 481 482 """ 483 return self._jvm_vertex_info_obj.getFilePath( 484 property_group.to_scala(), 485 chunk_index, 486 ) 487 488 def get_path_prefix(self, property_group: PropertyGroup) -> str: 489 """Get the path prefix for the specified property group. 490 491 :param property_group: the property group. 492 :returns: the path prefix of the property group chunk files. 493 """ 494 return self._jvm_vertex_info_obj.getPathPrefix(property_group.to_scala()) 495 496 def dump(self) -> str: 497 """Dump to Yaml string. 498 499 :returns: yaml string 500 """ 501 return self._jvm_vertex_info_obj.dump() 502 503 @staticmethod 504 def load_vertex_info(vertex_info_path: str) -> "VertexInfo": 505 """Load a yaml file from path and construct a VertexInfo from it. 506 507 :param vertexInfoPath: yaml file path 508 :returns: VertexInfo object 509 """ 510 return VertexInfo.from_scala( 511 GraphArSession.graphar.VertexInfo.loadVertexInfo( 512 vertex_info_path, 513 GraphArSession.jss, 514 ), 515 ) 516 517 def to_scala(self) -> JavaObject: 518 """Transform object to JVM representation. 519 520 :returns: JavaObject 521 """ 522 return self._jvm_vertex_info_obj 523 524 @classmethod 525 def from_scala(cls: type[VertexInfoType], jvm_obj: JavaObject) -> VertexInfoType: 526 """Create an instance of the Class from the corresponding JVM object. 527 528 :param jvm_obj: scala object in JVM. 529 :returns: instance of Python Class. 530 """ 531 return VertexInfo( 532 None, 533 None, 534 None, 535 None, 536 None, 537 jvm_obj, 538 ) 539 540 @classmethod 541 def from_python( 542 cls: type[VertexInfoType], 543 label: str, 544 chunk_size: int, 545 prefix: str, 546 property_groups: Sequence[PropertyGroup], 547 version: str, 548 ) -> VertexInfoType: 549 """Create an instance of the class based on python args. 550 551 :param label: label of the vertex 552 :chunk_size: chunk size 553 :prefix: vertex prefix 554 :property_groups: list of property groups 555 :version: version of GraphAr format 556 """ 557 return VertexInfo(label, chunk_size, prefix, property_groups, version, None)
VertexInfo is a class to store the vertex meta information.
299 def __init__( 300 self, 301 label: Optional[str], 302 chunk_size: Optional[int], 303 prefix: Optional[str], 304 property_groups: Optional[Sequence[PropertyGroup]], 305 version: Optional[str], 306 jvm_obj: Optional[JavaObject], 307 ) -> None: 308 """One should not use this constructor directly, please use `from_scala` or `from_python`.""" 309 _check_session() 310 if jvm_obj is not None: 311 self._jvm_vertex_info_obj = jvm_obj 312 else: 313 vertex_info = GraphArSession.graphar.VertexInfo() 314 vertex_info.setLabel(label) 315 vertex_info.setChunk_size(chunk_size) 316 vertex_info.setPrefix(prefix) 317 vertex_info.setProperty_groups( 318 [py_property_group.to_scala() for py_property_group in property_groups], 319 ) 320 vertex_info.setVersion(version) 321 self._jvm_vertex_info_obj = vertex_info
One should not use this constructor directly, please use from_scala
or from_python
.
323 def get_label(self) -> str: 324 """Get label from the corresponding JVM object. 325 326 :returns: label 327 """ 328 return self._jvm_vertex_info_obj.getLabel()
Get label from the corresponding JVM object.
:returns: label
330 def set_label(self, label: str) -> None: 331 """Mutate the corresponding JVM object. 332 333 :param label: new label 334 """ 335 self._jvm_vertex_info_obj.setLabel(label)
Mutate the corresponding JVM object.
Parameters
- label: new label
337 def get_chunk_size(self) -> int: 338 """Get chunk size from the corresponding JVM object. 339 340 :returns: chunk size 341 """ 342 return self._jvm_vertex_info_obj.getChunk_size()
Get chunk size from the corresponding JVM object.
:returns: chunk size
344 def set_chunk_size(self, chunk_size: int) -> None: 345 """Mutate the corresponding JVM object. 346 347 :param chunk_size: new chunk size 348 """ 349 self._jvm_vertex_info_obj.setChunk_size(chunk_size)
Mutate the corresponding JVM object.
Parameters
- chunk_size: new chunk size
351 def get_prefix(self) -> str: 352 """Get prefix from the corresponding JVM object. 353 354 :returns: prefix 355 """ 356 return self._jvm_vertex_info_obj.getPrefix()
Get prefix from the corresponding JVM object.
:returns: prefix
358 def set_prefix(self, prefix: str) -> None: 359 """Mutate the corresponding JVM object. 360 361 :param prefix: the new pefix. 362 """ 363 self._jvm_vertex_info_obj.setPrefix(prefix)
Mutate the corresponding JVM object.
Parameters
- prefix: the new pefix.
365 def get_property_groups(self) -> Sequence[PropertyGroup]: 366 """Get property groups from the corresponding JVM object. 367 368 :returns: property groups 369 """ 370 return [ 371 PropertyGroup.from_scala(jvm_property_group) 372 for jvm_property_group in self._jvm_vertex_info_obj.getProperty_groups() 373 ]
Get property groups from the corresponding JVM object.
:returns: property groups
375 def set_property_groups(self, property_groups: Sequence[PropertyGroup]) -> None: 376 """Mutate the corresponding JVM object. 377 378 :param property_groups: new property groups 379 """ 380 self._jvm_vertex_info_obj.setProperty_groups( 381 [py_property_group.to_scala() for py_property_group in property_groups], 382 )
Mutate the corresponding JVM object.
Parameters
- property_groups: new property groups
384 def get_version(self) -> str: 385 """Get version from the corresponding JVM object. 386 387 :returns: version 388 """ 389 return self._jvm_vertex_info_obj.getVersion()
Get version from the corresponding JVM object.
:returns: version
391 def set_version(self, version: str) -> None: 392 """Mutate the corresponding JVM object. 393 394 :param version: the new version. 395 """ 396 self._jvm_vertex_info_obj.setVersion(version)
Mutate the corresponding JVM object.
Parameters
- version: the new version.
398 def contain_property_group(self, property_group: PropertyGroup) -> bool: 399 """Check if the vertex info contains the property group. 400 401 :param property_group: the property group to check. 402 :returns: true if the vertex info contains the property group, otherwise false. 403 """ 404 return self._jvm_vertex_info_obj.containPropertyGroup(property_group.to_scala())
Check if the vertex info contains the property group.
Parameters
- property_group: the property group to check. :returns: true if the vertex info contains the property group, otherwise false.
406 def contain_property(self, property_name: str) -> bool: 407 """Check if the vertex info contains certain property. 408 409 :param property_name: name of the property. 410 :returns: true if the vertex info contains the property, otherwise false. 411 """ 412 return self._jvm_vertex_info_obj.containProperty(property_name)
Check if the vertex info contains certain property.
Parameters
- property_name: name of the property. :returns: true if the vertex info contains the property, otherwise false.
414 def get_property_group(self, property_name: str) -> PropertyGroup: 415 """Get the property group that contains property. 416 417 WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method! 418 419 :param property_name: name of the property. 420 :returns: property group that contains the property, otherwise raise IllegalArgumentException error. 421 """ 422 return PropertyGroup.from_scala( 423 self._jvm_vertex_info_obj.getPropertyGroup(property_name), 424 )
Get the property group that contains property.
WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method!
Parameters
- property_name: name of the property. :returns: property group that contains the property, otherwise raise IllegalArgumentException error.
426 def get_property_type(self, property_name: str) -> GarType: 427 """Get the data type of property. 428 429 WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method! 430 431 :param property_name: name of the property. 432 :returns: the data type in gar of the property. If the vertex info does not contains the property, raise IllegalArgumentException error. 433 """ 434 return GarType.from_scala( 435 self._jvm_vertex_info_obj.getPropertyType(property_name), 436 )
Get the data type of property.
WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method!
Parameters
- property_name: name of the property. :returns: the data type in gar of the property. If the vertex info does not contains the property, raise IllegalArgumentException error.
438 def is_primary_key(self, property_name: str) -> bool: 439 """Check if the property is primary key. 440 441 :param property_name: name of the property to check. 442 :returns: true if the property if the primary key of vertex info, otherwise return false. 443 """ 444 return self._jvm_vertex_info_obj.isPrimaryKey(property_name)
Check if the property is primary key.
Parameters
- property_name: name of the property to check. :returns: true if the property if the primary key of vertex info, otherwise return false.
446 def get_primary_key(self) -> str: 447 """Get primary key of vertex info. 448 449 :returns: name of the primary key. 450 """ 451 return self._jvm_vertex_info_obj.getPrimaryKey()
Get primary key of vertex info.
:returns: name of the primary key.
453 def is_nullable_key(self, property_name: str) -> bool: 454 """Check if the property is nullable key. 455 456 :param property_name: name of the property to check. 457 :returns: true if the property if a nullable key of vertex info, otherwise return false 458 """ 459 return self._jvm_vertex_info_obj.isNullableKey(property_name)
Check if the property is nullable key.
Parameters
- property_name: name of the property to check. :returns: true if the property if a nullable key of vertex info, otherwise return false
461 def is_validated(self) -> bool: 462 """Check if the vertex info is validated. 463 464 :returns: true if the vertex info is validated, otherwise return false. 465 """ 466 return self._jvm_vertex_info_obj.isValidated()
Check if the vertex info is validated.
:returns: true if the vertex info is validated, otherwise return false.
468 def get_vertices_num_file_path(self) -> str: 469 """Get the vertex num file path of vertex info. 470 471 :returns: vertex num file path of vertex info. 472 """ 473 return self._jvm_vertex_info_obj.getVerticesNumFilePath()
Get the vertex num file path of vertex info.
:returns: vertex num file path of vertex info.
475 def get_file_path(self, property_group: PropertyGroup, chunk_index: int) -> str: 476 """Get the chunk file path of property group of vertex chunk. 477 478 :param property_group: the property group. 479 :param chunk_index: the index of vertex chunk 480 :returns: chunk file path. 481 482 """ 483 return self._jvm_vertex_info_obj.getFilePath( 484 property_group.to_scala(), 485 chunk_index, 486 )
Get the chunk file path of property group of vertex chunk.
Parameters
- property_group: the property group.
- chunk_index: the index of vertex chunk :returns: chunk file path.
488 def get_path_prefix(self, property_group: PropertyGroup) -> str: 489 """Get the path prefix for the specified property group. 490 491 :param property_group: the property group. 492 :returns: the path prefix of the property group chunk files. 493 """ 494 return self._jvm_vertex_info_obj.getPathPrefix(property_group.to_scala())
Get the path prefix for the specified property group.
Parameters
- property_group: the property group. :returns: the path prefix of the property group chunk files.
496 def dump(self) -> str: 497 """Dump to Yaml string. 498 499 :returns: yaml string 500 """ 501 return self._jvm_vertex_info_obj.dump()
Dump to Yaml string.
:returns: yaml string
503 @staticmethod 504 def load_vertex_info(vertex_info_path: str) -> "VertexInfo": 505 """Load a yaml file from path and construct a VertexInfo from it. 506 507 :param vertexInfoPath: yaml file path 508 :returns: VertexInfo object 509 """ 510 return VertexInfo.from_scala( 511 GraphArSession.graphar.VertexInfo.loadVertexInfo( 512 vertex_info_path, 513 GraphArSession.jss, 514 ), 515 )
Load a yaml file from path and construct a VertexInfo from it.
Parameters
- vertexInfoPath: yaml file path :returns: VertexInfo object
517 def to_scala(self) -> JavaObject: 518 """Transform object to JVM representation. 519 520 :returns: JavaObject 521 """ 522 return self._jvm_vertex_info_obj
Transform object to JVM representation.
:returns: JavaObject
524 @classmethod 525 def from_scala(cls: type[VertexInfoType], jvm_obj: JavaObject) -> VertexInfoType: 526 """Create an instance of the Class from the corresponding JVM object. 527 528 :param jvm_obj: scala object in JVM. 529 :returns: instance of Python Class. 530 """ 531 return VertexInfo( 532 None, 533 None, 534 None, 535 None, 536 None, 537 jvm_obj, 538 )
Create an instance of the Class from the corresponding JVM object.
Parameters
- jvm_obj: scala object in JVM. :returns: instance of Python Class.
540 @classmethod 541 def from_python( 542 cls: type[VertexInfoType], 543 label: str, 544 chunk_size: int, 545 prefix: str, 546 property_groups: Sequence[PropertyGroup], 547 version: str, 548 ) -> VertexInfoType: 549 """Create an instance of the class based on python args. 550 551 :param label: label of the vertex 552 :chunk_size: chunk size 553 :prefix: vertex prefix 554 :property_groups: list of property groups 555 :version: version of GraphAr format 556 """ 557 return VertexInfo(label, chunk_size, prefix, property_groups, version, None)
Create an instance of the class based on python args.
Parameters
- label: label of the vertex :chunk_size: chunk size :prefix: vertex prefix :property_groups: list of property groups :version: version of GraphAr format
564class AdjList: 565 """AdjList is a class to store the adj list information of edge.""" 566 567 def __init__( 568 self, 569 ordered: Optional[bool], 570 aligned_by: Optional[str], 571 prefix: Optional[str], 572 file_type: Optional[FileType], 573 jvm_obj: Optional[JavaObject], 574 ) -> None: 575 """One should not use this constructor directly, please use `from_scala` or `from_python`.""" 576 _check_session() 577 if jvm_obj is not None: 578 self._jvm_adj_list_obj = jvm_obj 579 else: 580 jvm_adj_list = GraphArSession.graphar.AdjList() 581 jvm_adj_list.setOrdered(ordered) 582 jvm_adj_list.setAligned_by(aligned_by) 583 jvm_adj_list.setPrefix(prefix) 584 jvm_adj_list.setFile_type(file_type.value) 585 self._jvm_adj_list_obj = jvm_adj_list 586 587 def get_ordered(self) -> bool: 588 """Get ordered flag from the corresponding JVM object. 589 590 :returns: ordered 591 """ 592 return self._jvm_adj_list_obj.getOrdered() 593 594 def set_ordered(self, ordered: bool) -> None: 595 """Mutate the corresponding JVM object. 596 597 :param ordered: new ordered flag 598 """ 599 self._jvm_adj_list_obj.setOrdered(ordered) 600 601 def get_aligned_by(self) -> str: 602 """Get aligned_by from the corresponding JVM object. 603 604 :returns: aligned by as a string ("src", "dst") 605 """ 606 return self._jvm_adj_list_obj.getAligned_by() 607 608 def set_aligned_by(self, aligned_by: str) -> None: 609 """Mutate the corresponding JVM object. 610 611 :param aligned_by: the new aligned_by (recommended to use "src" or "dst") 612 613 """ 614 self._jvm_adj_list_obj.setAligned_by(aligned_by) 615 616 def get_prefix(self) -> str: 617 """Get prefix from the corresponding JVM object. 618 619 :returns: prefix 620 """ 621 return self._jvm_adj_list_obj.getPrefix() 622 623 def set_prefix(self, prefix: str) -> None: 624 """Mutate the corresponding JVM object. 625 626 :param prefix: the new prefix 627 628 """ 629 self._jvm_adj_list_obj.setPrefix(prefix) 630 631 def get_file_type(self) -> FileType: 632 """Get FileType (as Enum) from the corresponding JVM object. 633 634 :returns: file type 635 """ 636 return FileType(self._jvm_adj_list_obj.getFile_type()) 637 638 def set_file_type(self, file_type: FileType) -> None: 639 """Mutate the corresponding JVM object. 640 641 :param file_type: the new file type 642 """ 643 self._jvm_adj_list_obj.setFile_type(file_type.value) 644 645 def get_adj_list_type(self) -> AdjListType: 646 """Get adj list type. 647 648 :returns: adj list type. 649 """ 650 return AdjListType(self._jvm_adj_list_obj.getAdjList_type()) 651 652 def to_scala(self) -> JavaObject: 653 """Transform object to JVM representation. 654 655 :returns: JavaObject 656 """ 657 return self._jvm_adj_list_obj 658 659 @classmethod 660 def from_scala( 661 cls: type[AdjListClassType], 662 jvm_obj: JavaObject, 663 ) -> AdjListClassType: 664 """Create an instance of the Class from the corresponding JVM object. 665 666 :param jvm_obj: scala object in JVM. 667 :returns: instance of Python Class. 668 """ 669 return AdjList(None, None, None, None, jvm_obj) 670 671 @classmethod 672 def from_python( 673 cls: type[AdjListClassType], 674 ordered: bool, 675 aligned_by: str, 676 prefix: str, 677 file_type: FileType, 678 ) -> AdjListClassType: 679 """Create an instance of the class from python arguments. 680 681 :param ordered: ordered flag 682 :param aligned_by: recommended values are "src" or "dst" 683 :param prefix: path prefix 684 :param file_type: file type 685 """ 686 if not prefix.endswith(os.sep): 687 prefix += os.sep 688 return AdjList(ordered, aligned_by, prefix, file_type, None) 689 690 def __eq__(self, other: object) -> bool: 691 if not isinstance(other, AdjList): 692 return False 693 694 return ( 695 (self.get_ordered() == other.get_ordered()) 696 and (self.get_aligned_by() == other.get_aligned_by()) 697 and (self.get_prefix() == other.get_prefix()) 698 and (self.get_file_type() == other.get_file_type()) 699 )
AdjList is a class to store the adj list information of edge.
567 def __init__( 568 self, 569 ordered: Optional[bool], 570 aligned_by: Optional[str], 571 prefix: Optional[str], 572 file_type: Optional[FileType], 573 jvm_obj: Optional[JavaObject], 574 ) -> None: 575 """One should not use this constructor directly, please use `from_scala` or `from_python`.""" 576 _check_session() 577 if jvm_obj is not None: 578 self._jvm_adj_list_obj = jvm_obj 579 else: 580 jvm_adj_list = GraphArSession.graphar.AdjList() 581 jvm_adj_list.setOrdered(ordered) 582 jvm_adj_list.setAligned_by(aligned_by) 583 jvm_adj_list.setPrefix(prefix) 584 jvm_adj_list.setFile_type(file_type.value) 585 self._jvm_adj_list_obj = jvm_adj_list
One should not use this constructor directly, please use from_scala
or from_python
.
587 def get_ordered(self) -> bool: 588 """Get ordered flag from the corresponding JVM object. 589 590 :returns: ordered 591 """ 592 return self._jvm_adj_list_obj.getOrdered()
Get ordered flag from the corresponding JVM object.
:returns: ordered
594 def set_ordered(self, ordered: bool) -> None: 595 """Mutate the corresponding JVM object. 596 597 :param ordered: new ordered flag 598 """ 599 self._jvm_adj_list_obj.setOrdered(ordered)
Mutate the corresponding JVM object.
Parameters
- ordered: new ordered flag
601 def get_aligned_by(self) -> str: 602 """Get aligned_by from the corresponding JVM object. 603 604 :returns: aligned by as a string ("src", "dst") 605 """ 606 return self._jvm_adj_list_obj.getAligned_by()
Get aligned_by from the corresponding JVM object.
:returns: aligned by as a string ("src", "dst")
608 def set_aligned_by(self, aligned_by: str) -> None: 609 """Mutate the corresponding JVM object. 610 611 :param aligned_by: the new aligned_by (recommended to use "src" or "dst") 612 613 """ 614 self._jvm_adj_list_obj.setAligned_by(aligned_by)
Mutate the corresponding JVM object.
Parameters
- aligned_by: the new aligned_by (recommended to use "src" or "dst")
616 def get_prefix(self) -> str: 617 """Get prefix from the corresponding JVM object. 618 619 :returns: prefix 620 """ 621 return self._jvm_adj_list_obj.getPrefix()
Get prefix from the corresponding JVM object.
:returns: prefix
623 def set_prefix(self, prefix: str) -> None: 624 """Mutate the corresponding JVM object. 625 626 :param prefix: the new prefix 627 628 """ 629 self._jvm_adj_list_obj.setPrefix(prefix)
Mutate the corresponding JVM object.
Parameters
- prefix: the new prefix
631 def get_file_type(self) -> FileType: 632 """Get FileType (as Enum) from the corresponding JVM object. 633 634 :returns: file type 635 """ 636 return FileType(self._jvm_adj_list_obj.getFile_type())
Get FileType (as Enum) from the corresponding JVM object.
:returns: file type
638 def set_file_type(self, file_type: FileType) -> None: 639 """Mutate the corresponding JVM object. 640 641 :param file_type: the new file type 642 """ 643 self._jvm_adj_list_obj.setFile_type(file_type.value)
Mutate the corresponding JVM object.
Parameters
- file_type: the new file type
645 def get_adj_list_type(self) -> AdjListType: 646 """Get adj list type. 647 648 :returns: adj list type. 649 """ 650 return AdjListType(self._jvm_adj_list_obj.getAdjList_type())
Get adj list type.
:returns: adj list type.
652 def to_scala(self) -> JavaObject: 653 """Transform object to JVM representation. 654 655 :returns: JavaObject 656 """ 657 return self._jvm_adj_list_obj
Transform object to JVM representation.
:returns: JavaObject
659 @classmethod 660 def from_scala( 661 cls: type[AdjListClassType], 662 jvm_obj: JavaObject, 663 ) -> AdjListClassType: 664 """Create an instance of the Class from the corresponding JVM object. 665 666 :param jvm_obj: scala object in JVM. 667 :returns: instance of Python Class. 668 """ 669 return AdjList(None, None, None, None, jvm_obj)
Create an instance of the Class from the corresponding JVM object.
Parameters
- jvm_obj: scala object in JVM. :returns: instance of Python Class.
671 @classmethod 672 def from_python( 673 cls: type[AdjListClassType], 674 ordered: bool, 675 aligned_by: str, 676 prefix: str, 677 file_type: FileType, 678 ) -> AdjListClassType: 679 """Create an instance of the class from python arguments. 680 681 :param ordered: ordered flag 682 :param aligned_by: recommended values are "src" or "dst" 683 :param prefix: path prefix 684 :param file_type: file type 685 """ 686 if not prefix.endswith(os.sep): 687 prefix += os.sep 688 return AdjList(ordered, aligned_by, prefix, file_type, None)
Create an instance of the class from python arguments.
Parameters
- ordered: ordered flag
- aligned_by: recommended values are "src" or "dst"
- prefix: path prefix
- file_type: file type
706class EdgeInfo: 707 """Edge info is a class to store the edge meta information.""" 708 709 def __init__( 710 self, 711 src_label: Optional[str], 712 edge_label: Optional[str], 713 dst_label: Optional[str], 714 chunk_size: Optional[int], 715 src_chunk_size: Optional[int], 716 dst_chunk_size: Optional[int], 717 directed: Optional[bool], 718 prefix: Optional[str], 719 adj_lists: Sequence[AdjList], 720 property_groups: Optional[Sequence[PropertyGroup]], 721 version: Optional[str], 722 jvm_edge_info_obj: JavaObject, 723 ) -> None: 724 """One should not use this constructor directly, please use `from_scala` or `from_python`.""" 725 _check_session() 726 if jvm_edge_info_obj is not None: 727 self._jvm_edge_info_obj = jvm_edge_info_obj 728 else: 729 edge_info = GraphArSession.graphar.EdgeInfo() 730 edge_info.setSrc_label(src_label) 731 edge_info.setEdge_label(edge_label) 732 edge_info.setDst_label(dst_label) 733 edge_info.setChunk_size(chunk_size) 734 edge_info.setSrc_chunk_size(src_chunk_size) 735 edge_info.setDst_chunk_size(dst_chunk_size) 736 edge_info.setDirected(directed) 737 edge_info.setPrefix(prefix) 738 edge_info.setAdj_lists( 739 [py_adj_list.to_scala() for py_adj_list in adj_lists], 740 ) 741 edge_info.setProperty_groups( 742 [py_property_group.to_scala() for py_property_group in property_groups], 743 ) 744 edge_info.setVersion(version) 745 self._jvm_edge_info_obj = edge_info 746 747 def get_src_label(self) -> str: 748 """Get src label from the corresponding JVM object. 749 750 :returns: src label 751 """ 752 return self._jvm_edge_info_obj.getSrc_label() 753 754 def set_src_label(self, src_label: str) -> None: 755 """Mutate the corresponding JVM object. 756 757 :param src_label: the new src label 758 """ 759 self._jvm_edge_info_obj.setSrc_label(src_label) 760 761 def get_edge_label(self) -> str: 762 """Get edge label from the corresponding JVM object. 763 764 :returns: edge label 765 """ 766 return self._jvm_edge_info_obj.getEdge_label() 767 768 def set_edge_label(self, edge_label: str) -> None: 769 """Mutate the corresponding JVM object. 770 771 :param edge_label: the new edge label 772 """ 773 self._jvm_edge_info_obj.setEdge_label(edge_label) 774 775 def get_dst_label(self) -> str: 776 """Get dst label from the corresponding JVM object. 777 778 :returns: dst label 779 """ 780 return self._jvm_edge_info_obj.getDst_label() 781 782 def set_dst_label(self, dst_label: str) -> None: 783 """Mutate the corresponding JVM object. 784 785 :param dst_label: the new dst label 786 """ 787 self._jvm_edge_info_obj.setDst_label(dst_label) 788 789 def get_chunk_size(self) -> int: 790 """Get chunk size from the corresponding JVM object. 791 792 :returns: chunk size 793 """ 794 return self._jvm_edge_info_obj.getChunk_size() 795 796 def set_chunk_size(self, chunk_size: int) -> None: 797 """Mutate the corresponding JVM object. 798 799 :param chunk_size: the new chunk size 800 """ 801 self._jvm_edge_info_obj.setChunk_size(chunk_size) 802 803 def get_src_chunk_size(self) -> int: 804 """Get source chunk size from the corresponding JVM object. 805 806 :returns: source chunk size 807 """ 808 return self._jvm_edge_info_obj.getSrc_chunk_size() 809 810 def set_src_chunk_size(self, src_chunk_size: int) -> None: 811 """Mutate the corresponding JVM object. 812 813 :param src_chunk_size: the new source chunk size. 814 """ 815 self._jvm_edge_info_obj.setSrc_chunk_size(src_chunk_size) 816 817 def get_dst_chunk_size(self) -> int: 818 """Get dest chunk size from the corresponding JVM object. 819 820 :returns: destination chunk size 821 """ 822 return self._jvm_edge_info_obj.getDst_chunk_size() 823 824 def set_dst_chunk_size(self, dst_chunk_size: int) -> None: 825 """Mutate the corresponding JVM object. 826 827 :param dst_chunk_size: the new destination chunk size. 828 """ 829 self._jvm_edge_info_obj.setDst_chunk_size(dst_chunk_size) 830 831 def get_directed(self) -> bool: 832 """Get directed flag from the corresponding JVM object. 833 834 :returns: directed flag 835 """ 836 return self._jvm_edge_info_obj.getDirected() 837 838 def set_directed(self, directed: bool) -> None: 839 """Mutate the corresponding JVM object. 840 841 :param directed: the new directed flag 842 """ 843 self._jvm_edge_info_obj.setDirected(directed) 844 845 def get_prefix(self) -> str: 846 """Get prefix from the corresponding JVM object. 847 848 :returns: prefix 849 """ 850 return self._jvm_edge_info_obj.getPrefix() 851 852 def set_prefix(self, prefix: str) -> None: 853 """Mutate the corresponding JVM object. 854 855 :param prefix: the new prefix 856 """ 857 self._jvm_edge_info_obj.setPrefix(prefix) 858 859 def get_adj_lists(self) -> Sequence[AdjList]: 860 """Get adj lists from the corresponding JVM object. 861 862 :returns: sequence of AdjList 863 """ 864 return [ 865 AdjList.from_scala(jvm_adj_list) 866 for jvm_adj_list in self._jvm_edge_info_obj.getAdj_lists() 867 ] 868 869 def set_adj_lists(self, adj_lists: Sequence[AdjList]) -> None: 870 """Mutate the corresponding JVM object. 871 872 :param adj_lists: the new adj lists, sequence of AdjList 873 """ 874 self._jvm_edge_info_obj.setAdj_lists( 875 [py_adj_list.to_scala() for py_adj_list in adj_lists], 876 ) 877 878 def get_property_groups(self) -> Sequence[PropertyGroup]: 879 """Get the property groups of adj list type. 880 881 WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method! 882 883 :returns: property groups of edge info. 884 """ 885 return [ 886 PropertyGroup.from_scala(jvm_property_group) 887 for jvm_property_group in self._jvm_edge_info_obj.getProperty_groups() 888 ] 889 890 def set_property_groups(self, property_groups: Sequence[PropertyGroup]) -> None: 891 """Mutate the corresponding JVM object. 892 893 :param property_groups: the new property groups, sequence of PropertyGroup 894 """ 895 self._jvm_edge_info_obj.setProperty_groups( 896 [py_property_group.to_scala() for py_property_group in property_groups], 897 ) 898 899 def get_version(self) -> str: 900 """Get GraphAr format version from the corresponding JVM object. 901 902 :returns: GraphAr format version 903 """ 904 return self._jvm_edge_info_obj.getVersion() 905 906 def set_version(self, version: str) -> None: 907 """Mutate the corresponding JVM object. 908 909 :param version: the new GraphAr format version 910 """ 911 self._jvm_edge_info_obj.setVersion(version) 912 913 def to_scala(self) -> JavaObject: 914 """Transform object to JVM representation. 915 916 :returns: JavaObject 917 """ 918 return self._jvm_edge_info_obj 919 920 @classmethod 921 def from_scala(cls: type[EdgeInfoType], jvm_obj: JavaObject) -> EdgeInfoType: 922 """Create an instance of the Class from the corresponding JVM object. 923 924 :param jvm_obj: scala object in JVM. 925 :returns: instance of Python Class. 926 """ 927 return EdgeInfo( 928 None, 929 None, 930 None, 931 None, 932 None, 933 None, 934 None, 935 None, 936 None, 937 None, 938 None, 939 jvm_obj, 940 ) 941 942 @classmethod 943 def from_python( 944 cls: type[EdgeInfoType], 945 src_label: str, 946 edge_label: str, 947 dst_label: str, 948 chunk_size: int, 949 src_chunk_size: int, 950 dst_chunk_size: int, 951 directed: bool, 952 prefix: str, 953 adj_lists: Sequence[AdjList], 954 property_groups: Sequence[PropertyGroup], 955 version: str, 956 ) -> EdgeInfoType: 957 """Create an instance of the class from python arguments. 958 959 :param src_label: source vertex label 960 :param edge_label: edges label 961 :param dst_label: destination vertex label 962 :param chunk_size: chunk size 963 :param src_chunk_size: source chunk size 964 :param dst_chunk_size: destination chunk size 965 :param directed: directed graph flag 966 :param prefix: path prefix 967 :param adj_lists: sequence of AdjList objects 968 :property_groups: sequence of of PropertyGroup objects 969 :param version: version of GraphAr format 970 """ 971 if not prefix.endswith(os.sep): 972 prefix += os.sep 973 974 return EdgeInfo( 975 src_label, 976 edge_label, 977 dst_label, 978 chunk_size, 979 src_chunk_size, 980 dst_chunk_size, 981 directed, 982 prefix, 983 adj_lists, 984 property_groups, 985 version, 986 None, 987 ) 988 989 def contain_adj_list(self, adj_list_type: AdjListType) -> bool: 990 """Check if the edge info supports the adj list type. 991 992 :param adj_list_type: adjList type in gar to check. 993 :returns: true if edge info supports the adj list type, otherwise return false. 994 """ 995 return self._jvm_edge_info_obj.containAdjList(adj_list_type.to_scala()) 996 997 def get_adj_list_prefix(self, adj_list_type: AdjListType) -> str: 998 """Get path prefix of adj list type. 999 1000 WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method! 1001 1002 :param adj_list_type: The input adj list type in gar. 1003 :returns: path prefix of the adj list type, if edge info not support the adj list type, raise an IllegalArgumentException error. 1004 """ 1005 return self._jvm_edge_info_obj.getAdjListPrefix(adj_list_type.to_scala()) 1006 1007 def get_adj_list_file_type(self, adj_list_type: AdjListType) -> FileType: 1008 """Get the adj list topology chunk file type of adj list type. 1009 1010 WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method! 1011 1012 :param adj_list_type: the input adj list type. 1013 :returns: file format type in gar of the adj list type, if edge info not support the adj list type, 1014 raise an IllegalArgumentException error. 1015 """ 1016 return FileType.from_scala( 1017 self._jvm_edge_info_obj.getAdjListFileType(adj_list_type.to_scala()), 1018 ) 1019 1020 def contain_property_group( 1021 self, 1022 property_group: PropertyGroup, 1023 ) -> bool: 1024 """Check if the edge info contains the property group. 1025 1026 :param property_group: the property group to check. 1027 :returns: true if the edge info contains the property group in certain adj list 1028 structure. 1029 """ 1030 return self._jvm_edge_info_obj.containPropertyGroup( 1031 property_group.to_scala(), 1032 ) 1033 1034 def contain_property(self, property_name: str) -> bool: 1035 """Check if the edge info contains the property. 1036 1037 :param property_name: name of the property. 1038 :returns: true if edge info contains the property, otherwise false. 1039 """ 1040 return self._jvm_edge_info_obj.containProperty(property_name) 1041 1042 def get_property_group( 1043 self, 1044 property_name: str, 1045 ) -> PropertyGroup: 1046 """Get property group that contains property with adj list type. 1047 1048 WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method! 1049 1050 :param property_name: name of the property. 1051 :returns: property group that contains the property. If edge info not find the property group that contains the property, 1052 raise error. 1053 """ 1054 return PropertyGroup.from_scala( 1055 self._jvm_edge_info_obj.getPropertyGroup(property_name), 1056 ) 1057 1058 def get_property_type(self, property_name: str) -> GarType: 1059 """Get the data type of property. 1060 1061 WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method! 1062 1063 :param property_name: name of the property. 1064 :returns: data type in gar of the property. If edge info not contains the property, raise an IllegalArgumentException error. 1065 """ 1066 return GarType.from_scala( 1067 self._jvm_edge_info_obj.getPropertyType(property_name), 1068 ) 1069 1070 def is_primary_key(self, property_name: str) -> bool: 1071 """Check the property is primary key of edge info. 1072 1073 WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method! 1074 1075 :param property_name: name of the property. 1076 :returns: true if the property is the primary key of edge info, false if not. If 1077 edge info not contains the property, raise an IllegalArgumentException error. 1078 """ 1079 return self._jvm_edge_info_obj.isPrimaryKey(property_name) 1080 1081 def is_nullable_key(self, property_name: str) -> bool: 1082 """Check the property is nullable key of edge info. 1083 1084 :param property_name: name of the property. 1085 :returns: true if the property is the nullable key of edge info, false if not. If 1086 edge info not contains the property, raise an IllegalArgumentException error. 1087 """ 1088 return self._jvm_edge_info_obj.isNullableKey(property_name) 1089 1090 def get_primary_key(self) -> str: 1091 """Get Primary key of edge info. 1092 1093 :returns: primary key of edge info. 1094 """ 1095 return self._jvm_edge_info_obj.getPrimaryKey() 1096 1097 def is_validated(self) -> bool: 1098 """Check if the edge info is validated. 1099 1100 :returns: true if edge info is validated or false if not. 1101 """ 1102 return self._jvm_edge_info_obj.isValidated() 1103 1104 def get_vertices_num_file_path(self, adj_list_type: AdjListType) -> str: 1105 """Get the vertex num file path. 1106 1107 WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method! 1108 1109 :param adj_list_type: type of adj list structure. 1110 :returns: the vertex num file path. If edge info not support the adj list type, 1111 raise an IllegalArgumentException error. 1112 """ 1113 return self._jvm_edge_info_obj.getVerticesNumFilePath(adj_list_type.to_scala()) 1114 1115 def get_edges_num_path_prefix(self, adj_list_type: AdjListType) -> str: 1116 """Get the path prefix of the edge num file path. 1117 1118 WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method! 1119 1120 :param adj_list_type: type of adj list structure. 1121 :returns: the edge num file path. If edge info not support the adj list type, raise 1122 an IllegalArgumentException error. 1123 """ 1124 return self._jvm_edge_info_obj.getEdgesNumPathPrefix(adj_list_type.to_scala()) 1125 1126 def get_edges_num_file_path( 1127 self, 1128 chunk_index: int, 1129 adj_list_type: AdjListType, 1130 ) -> str: 1131 """Get the edge num file path of the vertex chunk. 1132 1133 WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method! 1134 1135 :param chunk_index: index of vertex chunk. 1136 :param adj_list_type: type of adj list structure. 1137 :returns: the edge num file path. If edge info not support the adj list type, raise 1138 an IllegalArgumentException error. 1139 """ 1140 return self._jvm_edge_info_obj.getEdgesNumFilePath( 1141 chunk_index, 1142 adj_list_type.to_scala(), 1143 ) 1144 1145 def get_adj_list_offset_file_path( 1146 self, 1147 chunk_index: int, 1148 adj_list_type: AdjListType, 1149 ) -> str: 1150 """Get the adj list offset chunk file path of vertex chunk the offset chunks is aligned with the vertex chunks. 1151 1152 WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method! 1153 1154 :param chunk_index: index of vertex chunk. 1155 :param adj_list_type: type of adj list structure. 1156 :returns: the offset chunk file path. If edge info not support the adj list type, raise an IllegalArgumentException error. 1157 1158 """ 1159 return self._jvm_edge_info_obj.getAdjListOffsetFilePath( 1160 chunk_index, 1161 adj_list_type.to_scala(), 1162 ) 1163 1164 def get_offset_path_prefix(self, adj_list_type: AdjListType) -> str: 1165 """Get the path prefix of the adjacency list offset for the given adjacency list type. 1166 1167 WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method! 1168 1169 :param adj_list_type: type of adj list structure. 1170 :returns: the path prefix of the offset. If edge info not support the adj list type, raise an IllegalArgumentException error. 1171 1172 """ 1173 return self._jvm_edge_info_obj.getOffsetPathPrefix(adj_list_type.to_scala()) 1174 1175 def get_adj_list_file_path( 1176 self, 1177 vertex_chunk_index: int, 1178 chunk_index: int, 1179 adj_list_type: AdjListType, 1180 ) -> str: 1181 """Get the file path of adj list topology chunk. 1182 1183 :param vertex_chunk_index: index of vertex chunk. 1184 :param chunk_index: index of edge chunk. 1185 :param adj_list_type: type of adj list structure. 1186 :returns: adj list chunk file path. 1187 """ 1188 return self._jvm_edge_info_obj.getAdjListFilePath( 1189 vertex_chunk_index, 1190 chunk_index, 1191 adj_list_type.to_scala(), 1192 ) 1193 1194 def get_adj_list_path_prefix( 1195 self, 1196 vertex_chunk_index: Optional[int], 1197 adj_list_type: AdjListType, 1198 ) -> str: 1199 """Get the path prefix of adj list topology chunk of certain vertex chunk. 1200 1201 :param vertex_chunk_index: index of vertex chunk (optional). 1202 :param adj_list_type: type of adj list structure. 1203 :returns: path prefix of the edge chunk of vertices of given vertex chunk. 1204 """ 1205 if vertex_chunk_index is None: 1206 return self._jvm_edge_info_obj.getAdjListPathPrefix( 1207 adj_list_type.to_scala(), 1208 ) 1209 1210 return self._jvm_edge_info_obj.getAdjListPathPrefix( 1211 vertex_chunk_index, 1212 adj_list_type.to_scala(), 1213 ) 1214 1215 def get_property_file_path( 1216 self, 1217 property_group: PropertyGroup, 1218 adj_list_type: AdjListType, 1219 vertex_chunk_index: int, 1220 chunk_index: int, 1221 ) -> str: 1222 """Get the chunk file path of adj list property group. the property group chunks is aligned with the adj list topology chunks. 1223 1224 WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method! 1225 1226 :param property_group: property group 1227 :param adj_list_type: type of adj list structure. 1228 :param vertex_chunk_index: index of vertex chunk. 1229 :param chunk_index: index of edge chunk. 1230 :returns: property group chunk file path. If edge info not contains the property group, raise an IllegalArgumentException error. 1231 """ 1232 return self._jvm_edge_info_obj.getPropertyFilePath( 1233 property_group.to_scala(), 1234 adj_list_type.to_scala(), 1235 vertex_chunk_index, 1236 chunk_index, 1237 ) 1238 1239 def get_property_group_path_prefix( 1240 self, 1241 property_group: PropertyGroup, 1242 adj_list_type: AdjListType, 1243 vertex_chunk_index: Optional[int] = None, 1244 ) -> str: 1245 """Get path prefix of adj list property group of certain vertex chunk. 1246 1247 WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method! 1248 1249 :param property_group: property group. 1250 :param adj_list_type: type of adj list structure. 1251 :param vertex_chunk_index: index of vertex chunk (optional, default is None). 1252 :returns: path prefix of property group chunks of of vertices of given vertex 1253 chunk. If edge info not contains the property group, raise an IllegalArgumentException error. 1254 """ 1255 if vertex_chunk_index is not None: 1256 return self._jvm_edge_info_obj.getPropertyGroupPathPrefix( 1257 property_group.to_scala(), 1258 adj_list_type.to_scala(), 1259 vertex_chunk_index, 1260 ) 1261 1262 return self._jvm_edge_info_obj.getPropertyGroupPathPrefix( 1263 property_group.to_scala(), 1264 adj_list_type.to_scala(), 1265 ) 1266 1267 def get_concat_key(self) -> str: 1268 """Get concat key. 1269 1270 :returns: concat key 1271 """ 1272 return self._jvm_edge_info_obj.getConcatKey() 1273 1274 def dump(self) -> str: 1275 """Dump to Yaml string. 1276 1277 :returns: yaml-string representation. 1278 """ 1279 return self._jvm_edge_info_obj.dump() 1280 1281 @staticmethod 1282 def load_edge_info(edge_info_path: str) -> "EdgeInfo": 1283 """Load a yaml file from path and construct a EdgeInfo from it. 1284 1285 :param edge_info_path: path of edge info YAML file. 1286 :returns: EdgeInfo object. 1287 """ 1288 return EdgeInfo.from_scala( 1289 GraphArSession.graphar.EdgeInfo.loadEdgeInfo( 1290 edge_info_path, 1291 GraphArSession.jss, 1292 ), 1293 )
Edge info is a class to store the edge meta information.
709 def __init__( 710 self, 711 src_label: Optional[str], 712 edge_label: Optional[str], 713 dst_label: Optional[str], 714 chunk_size: Optional[int], 715 src_chunk_size: Optional[int], 716 dst_chunk_size: Optional[int], 717 directed: Optional[bool], 718 prefix: Optional[str], 719 adj_lists: Sequence[AdjList], 720 property_groups: Optional[Sequence[PropertyGroup]], 721 version: Optional[str], 722 jvm_edge_info_obj: JavaObject, 723 ) -> None: 724 """One should not use this constructor directly, please use `from_scala` or `from_python`.""" 725 _check_session() 726 if jvm_edge_info_obj is not None: 727 self._jvm_edge_info_obj = jvm_edge_info_obj 728 else: 729 edge_info = GraphArSession.graphar.EdgeInfo() 730 edge_info.setSrc_label(src_label) 731 edge_info.setEdge_label(edge_label) 732 edge_info.setDst_label(dst_label) 733 edge_info.setChunk_size(chunk_size) 734 edge_info.setSrc_chunk_size(src_chunk_size) 735 edge_info.setDst_chunk_size(dst_chunk_size) 736 edge_info.setDirected(directed) 737 edge_info.setPrefix(prefix) 738 edge_info.setAdj_lists( 739 [py_adj_list.to_scala() for py_adj_list in adj_lists], 740 ) 741 edge_info.setProperty_groups( 742 [py_property_group.to_scala() for py_property_group in property_groups], 743 ) 744 edge_info.setVersion(version) 745 self._jvm_edge_info_obj = edge_info
One should not use this constructor directly, please use from_scala
or from_python
.
747 def get_src_label(self) -> str: 748 """Get src label from the corresponding JVM object. 749 750 :returns: src label 751 """ 752 return self._jvm_edge_info_obj.getSrc_label()
Get src label from the corresponding JVM object.
:returns: src label
754 def set_src_label(self, src_label: str) -> None: 755 """Mutate the corresponding JVM object. 756 757 :param src_label: the new src label 758 """ 759 self._jvm_edge_info_obj.setSrc_label(src_label)
Mutate the corresponding JVM object.
Parameters
- src_label: the new src label
761 def get_edge_label(self) -> str: 762 """Get edge label from the corresponding JVM object. 763 764 :returns: edge label 765 """ 766 return self._jvm_edge_info_obj.getEdge_label()
Get edge label from the corresponding JVM object.
:returns: edge label
768 def set_edge_label(self, edge_label: str) -> None: 769 """Mutate the corresponding JVM object. 770 771 :param edge_label: the new edge label 772 """ 773 self._jvm_edge_info_obj.setEdge_label(edge_label)
Mutate the corresponding JVM object.
Parameters
- edge_label: the new edge label
775 def get_dst_label(self) -> str: 776 """Get dst label from the corresponding JVM object. 777 778 :returns: dst label 779 """ 780 return self._jvm_edge_info_obj.getDst_label()
Get dst label from the corresponding JVM object.
:returns: dst label
782 def set_dst_label(self, dst_label: str) -> None: 783 """Mutate the corresponding JVM object. 784 785 :param dst_label: the new dst label 786 """ 787 self._jvm_edge_info_obj.setDst_label(dst_label)
Mutate the corresponding JVM object.
Parameters
- dst_label: the new dst label
789 def get_chunk_size(self) -> int: 790 """Get chunk size from the corresponding JVM object. 791 792 :returns: chunk size 793 """ 794 return self._jvm_edge_info_obj.getChunk_size()
Get chunk size from the corresponding JVM object.
:returns: chunk size
796 def set_chunk_size(self, chunk_size: int) -> None: 797 """Mutate the corresponding JVM object. 798 799 :param chunk_size: the new chunk size 800 """ 801 self._jvm_edge_info_obj.setChunk_size(chunk_size)
Mutate the corresponding JVM object.
Parameters
- chunk_size: the new chunk size
803 def get_src_chunk_size(self) -> int: 804 """Get source chunk size from the corresponding JVM object. 805 806 :returns: source chunk size 807 """ 808 return self._jvm_edge_info_obj.getSrc_chunk_size()
Get source chunk size from the corresponding JVM object.
:returns: source chunk size
810 def set_src_chunk_size(self, src_chunk_size: int) -> None: 811 """Mutate the corresponding JVM object. 812 813 :param src_chunk_size: the new source chunk size. 814 """ 815 self._jvm_edge_info_obj.setSrc_chunk_size(src_chunk_size)
Mutate the corresponding JVM object.
Parameters
- src_chunk_size: the new source chunk size.
817 def get_dst_chunk_size(self) -> int: 818 """Get dest chunk size from the corresponding JVM object. 819 820 :returns: destination chunk size 821 """ 822 return self._jvm_edge_info_obj.getDst_chunk_size()
Get dest chunk size from the corresponding JVM object.
:returns: destination chunk size
824 def set_dst_chunk_size(self, dst_chunk_size: int) -> None: 825 """Mutate the corresponding JVM object. 826 827 :param dst_chunk_size: the new destination chunk size. 828 """ 829 self._jvm_edge_info_obj.setDst_chunk_size(dst_chunk_size)
Mutate the corresponding JVM object.
Parameters
- dst_chunk_size: the new destination chunk size.
831 def get_directed(self) -> bool: 832 """Get directed flag from the corresponding JVM object. 833 834 :returns: directed flag 835 """ 836 return self._jvm_edge_info_obj.getDirected()
Get directed flag from the corresponding JVM object.
:returns: directed flag
838 def set_directed(self, directed: bool) -> None: 839 """Mutate the corresponding JVM object. 840 841 :param directed: the new directed flag 842 """ 843 self._jvm_edge_info_obj.setDirected(directed)
Mutate the corresponding JVM object.
Parameters
- directed: the new directed flag
845 def get_prefix(self) -> str: 846 """Get prefix from the corresponding JVM object. 847 848 :returns: prefix 849 """ 850 return self._jvm_edge_info_obj.getPrefix()
Get prefix from the corresponding JVM object.
:returns: prefix
852 def set_prefix(self, prefix: str) -> None: 853 """Mutate the corresponding JVM object. 854 855 :param prefix: the new prefix 856 """ 857 self._jvm_edge_info_obj.setPrefix(prefix)
Mutate the corresponding JVM object.
Parameters
- prefix: the new prefix
859 def get_adj_lists(self) -> Sequence[AdjList]: 860 """Get adj lists from the corresponding JVM object. 861 862 :returns: sequence of AdjList 863 """ 864 return [ 865 AdjList.from_scala(jvm_adj_list) 866 for jvm_adj_list in self._jvm_edge_info_obj.getAdj_lists() 867 ]
Get adj lists from the corresponding JVM object.
:returns: sequence of AdjList
869 def set_adj_lists(self, adj_lists: Sequence[AdjList]) -> None: 870 """Mutate the corresponding JVM object. 871 872 :param adj_lists: the new adj lists, sequence of AdjList 873 """ 874 self._jvm_edge_info_obj.setAdj_lists( 875 [py_adj_list.to_scala() for py_adj_list in adj_lists], 876 )
Mutate the corresponding JVM object.
Parameters
- adj_lists: the new adj lists, sequence of AdjList
878 def get_property_groups(self) -> Sequence[PropertyGroup]: 879 """Get the property groups of adj list type. 880 881 WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method! 882 883 :returns: property groups of edge info. 884 """ 885 return [ 886 PropertyGroup.from_scala(jvm_property_group) 887 for jvm_property_group in self._jvm_edge_info_obj.getProperty_groups() 888 ]
Get the property groups of adj list type.
WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method!
:returns: property groups of edge info.
890 def set_property_groups(self, property_groups: Sequence[PropertyGroup]) -> None: 891 """Mutate the corresponding JVM object. 892 893 :param property_groups: the new property groups, sequence of PropertyGroup 894 """ 895 self._jvm_edge_info_obj.setProperty_groups( 896 [py_property_group.to_scala() for py_property_group in property_groups], 897 )
Mutate the corresponding JVM object.
Parameters
- property_groups: the new property groups, sequence of PropertyGroup
899 def get_version(self) -> str: 900 """Get GraphAr format version from the corresponding JVM object. 901 902 :returns: GraphAr format version 903 """ 904 return self._jvm_edge_info_obj.getVersion()
Get GraphAr format version from the corresponding JVM object.
:returns: GraphAr format version
906 def set_version(self, version: str) -> None: 907 """Mutate the corresponding JVM object. 908 909 :param version: the new GraphAr format version 910 """ 911 self._jvm_edge_info_obj.setVersion(version)
Mutate the corresponding JVM object.
Parameters
- version: the new GraphAr format version
913 def to_scala(self) -> JavaObject: 914 """Transform object to JVM representation. 915 916 :returns: JavaObject 917 """ 918 return self._jvm_edge_info_obj
Transform object to JVM representation.
:returns: JavaObject
920 @classmethod 921 def from_scala(cls: type[EdgeInfoType], jvm_obj: JavaObject) -> EdgeInfoType: 922 """Create an instance of the Class from the corresponding JVM object. 923 924 :param jvm_obj: scala object in JVM. 925 :returns: instance of Python Class. 926 """ 927 return EdgeInfo( 928 None, 929 None, 930 None, 931 None, 932 None, 933 None, 934 None, 935 None, 936 None, 937 None, 938 None, 939 jvm_obj, 940 )
Create an instance of the Class from the corresponding JVM object.
Parameters
- jvm_obj: scala object in JVM. :returns: instance of Python Class.
942 @classmethod 943 def from_python( 944 cls: type[EdgeInfoType], 945 src_label: str, 946 edge_label: str, 947 dst_label: str, 948 chunk_size: int, 949 src_chunk_size: int, 950 dst_chunk_size: int, 951 directed: bool, 952 prefix: str, 953 adj_lists: Sequence[AdjList], 954 property_groups: Sequence[PropertyGroup], 955 version: str, 956 ) -> EdgeInfoType: 957 """Create an instance of the class from python arguments. 958 959 :param src_label: source vertex label 960 :param edge_label: edges label 961 :param dst_label: destination vertex label 962 :param chunk_size: chunk size 963 :param src_chunk_size: source chunk size 964 :param dst_chunk_size: destination chunk size 965 :param directed: directed graph flag 966 :param prefix: path prefix 967 :param adj_lists: sequence of AdjList objects 968 :property_groups: sequence of of PropertyGroup objects 969 :param version: version of GraphAr format 970 """ 971 if not prefix.endswith(os.sep): 972 prefix += os.sep 973 974 return EdgeInfo( 975 src_label, 976 edge_label, 977 dst_label, 978 chunk_size, 979 src_chunk_size, 980 dst_chunk_size, 981 directed, 982 prefix, 983 adj_lists, 984 property_groups, 985 version, 986 None, 987 )
Create an instance of the class from python arguments.
Parameters
- src_label: source vertex label
- edge_label: edges label
- dst_label: destination vertex label
- chunk_size: chunk size
- src_chunk_size: source chunk size
- dst_chunk_size: destination chunk size
- directed: directed graph flag
- prefix: path prefix
- adj_lists: sequence of AdjList objects :property_groups: sequence of of PropertyGroup objects
- version: version of GraphAr format
989 def contain_adj_list(self, adj_list_type: AdjListType) -> bool: 990 """Check if the edge info supports the adj list type. 991 992 :param adj_list_type: adjList type in gar to check. 993 :returns: true if edge info supports the adj list type, otherwise return false. 994 """ 995 return self._jvm_edge_info_obj.containAdjList(adj_list_type.to_scala())
Check if the edge info supports the adj list type.
Parameters
- adj_list_type: adjList type in gar to check. :returns: true if edge info supports the adj list type, otherwise return false.
997 def get_adj_list_prefix(self, adj_list_type: AdjListType) -> str: 998 """Get path prefix of adj list type. 999 1000 WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method! 1001 1002 :param adj_list_type: The input adj list type in gar. 1003 :returns: path prefix of the adj list type, if edge info not support the adj list type, raise an IllegalArgumentException error. 1004 """ 1005 return self._jvm_edge_info_obj.getAdjListPrefix(adj_list_type.to_scala())
Get path prefix of adj list type.
WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method!
Parameters
- adj_list_type: The input adj list type in gar. :returns: path prefix of the adj list type, if edge info not support the adj list type, raise an IllegalArgumentException error.
1007 def get_adj_list_file_type(self, adj_list_type: AdjListType) -> FileType: 1008 """Get the adj list topology chunk file type of adj list type. 1009 1010 WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method! 1011 1012 :param adj_list_type: the input adj list type. 1013 :returns: file format type in gar of the adj list type, if edge info not support the adj list type, 1014 raise an IllegalArgumentException error. 1015 """ 1016 return FileType.from_scala( 1017 self._jvm_edge_info_obj.getAdjListFileType(adj_list_type.to_scala()), 1018 )
Get the adj list topology chunk file type of adj list type.
WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method!
Parameters
- adj_list_type: the input adj list type. :returns: file format type in gar of the adj list type, if edge info not support the adj list type, raise an IllegalArgumentException error.
1020 def contain_property_group( 1021 self, 1022 property_group: PropertyGroup, 1023 ) -> bool: 1024 """Check if the edge info contains the property group. 1025 1026 :param property_group: the property group to check. 1027 :returns: true if the edge info contains the property group in certain adj list 1028 structure. 1029 """ 1030 return self._jvm_edge_info_obj.containPropertyGroup( 1031 property_group.to_scala(), 1032 )
Check if the edge info contains the property group.
Parameters
- property_group: the property group to check. :returns: true if the edge info contains the property group in certain adj list structure.
1034 def contain_property(self, property_name: str) -> bool: 1035 """Check if the edge info contains the property. 1036 1037 :param property_name: name of the property. 1038 :returns: true if edge info contains the property, otherwise false. 1039 """ 1040 return self._jvm_edge_info_obj.containProperty(property_name)
Check if the edge info contains the property.
Parameters
- property_name: name of the property. :returns: true if edge info contains the property, otherwise false.
1042 def get_property_group( 1043 self, 1044 property_name: str, 1045 ) -> PropertyGroup: 1046 """Get property group that contains property with adj list type. 1047 1048 WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method! 1049 1050 :param property_name: name of the property. 1051 :returns: property group that contains the property. If edge info not find the property group that contains the property, 1052 raise error. 1053 """ 1054 return PropertyGroup.from_scala( 1055 self._jvm_edge_info_obj.getPropertyGroup(property_name), 1056 )
Get property group that contains property with adj list type.
WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method!
Parameters
- property_name: name of the property. :returns: property group that contains the property. If edge info not find the property group that contains the property, raise error.
1058 def get_property_type(self, property_name: str) -> GarType: 1059 """Get the data type of property. 1060 1061 WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method! 1062 1063 :param property_name: name of the property. 1064 :returns: data type in gar of the property. If edge info not contains the property, raise an IllegalArgumentException error. 1065 """ 1066 return GarType.from_scala( 1067 self._jvm_edge_info_obj.getPropertyType(property_name), 1068 )
Get the data type of property.
WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method!
Parameters
- property_name: name of the property. :returns: data type in gar of the property. If edge info not contains the property, raise an IllegalArgumentException error.
1070 def is_primary_key(self, property_name: str) -> bool: 1071 """Check the property is primary key of edge info. 1072 1073 WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method! 1074 1075 :param property_name: name of the property. 1076 :returns: true if the property is the primary key of edge info, false if not. If 1077 edge info not contains the property, raise an IllegalArgumentException error. 1078 """ 1079 return self._jvm_edge_info_obj.isPrimaryKey(property_name)
Check the property is primary key of edge info.
WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method!
Parameters
- property_name: name of the property. :returns: true if the property is the primary key of edge info, false if not. If edge info not contains the property, raise an IllegalArgumentException error.
1081 def is_nullable_key(self, property_name: str) -> bool: 1082 """Check the property is nullable key of edge info. 1083 1084 :param property_name: name of the property. 1085 :returns: true if the property is the nullable key of edge info, false if not. If 1086 edge info not contains the property, raise an IllegalArgumentException error. 1087 """ 1088 return self._jvm_edge_info_obj.isNullableKey(property_name)
Check the property is nullable key of edge info.
Parameters
- property_name: name of the property. :returns: true if the property is the nullable key of edge info, false if not. If edge info not contains the property, raise an IllegalArgumentException error.
1090 def get_primary_key(self) -> str: 1091 """Get Primary key of edge info. 1092 1093 :returns: primary key of edge info. 1094 """ 1095 return self._jvm_edge_info_obj.getPrimaryKey()
Get Primary key of edge info.
:returns: primary key of edge info.
1097 def is_validated(self) -> bool: 1098 """Check if the edge info is validated. 1099 1100 :returns: true if edge info is validated or false if not. 1101 """ 1102 return self._jvm_edge_info_obj.isValidated()
Check if the edge info is validated.
:returns: true if edge info is validated or false if not.
1104 def get_vertices_num_file_path(self, adj_list_type: AdjListType) -> str: 1105 """Get the vertex num file path. 1106 1107 WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method! 1108 1109 :param adj_list_type: type of adj list structure. 1110 :returns: the vertex num file path. If edge info not support the adj list type, 1111 raise an IllegalArgumentException error. 1112 """ 1113 return self._jvm_edge_info_obj.getVerticesNumFilePath(adj_list_type.to_scala())
Get the vertex num file path.
WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method!
Parameters
- adj_list_type: type of adj list structure. :returns: the vertex num file path. If edge info not support the adj list type, raise an IllegalArgumentException error.
1115 def get_edges_num_path_prefix(self, adj_list_type: AdjListType) -> str: 1116 """Get the path prefix of the edge num file path. 1117 1118 WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method! 1119 1120 :param adj_list_type: type of adj list structure. 1121 :returns: the edge num file path. If edge info not support the adj list type, raise 1122 an IllegalArgumentException error. 1123 """ 1124 return self._jvm_edge_info_obj.getEdgesNumPathPrefix(adj_list_type.to_scala())
Get the path prefix of the edge num file path.
WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method!
Parameters
- adj_list_type: type of adj list structure. :returns: the edge num file path. If edge info not support the adj list type, raise an IllegalArgumentException error.
1126 def get_edges_num_file_path( 1127 self, 1128 chunk_index: int, 1129 adj_list_type: AdjListType, 1130 ) -> str: 1131 """Get the edge num file path of the vertex chunk. 1132 1133 WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method! 1134 1135 :param chunk_index: index of vertex chunk. 1136 :param adj_list_type: type of adj list structure. 1137 :returns: the edge num file path. If edge info not support the adj list type, raise 1138 an IllegalArgumentException error. 1139 """ 1140 return self._jvm_edge_info_obj.getEdgesNumFilePath( 1141 chunk_index, 1142 adj_list_type.to_scala(), 1143 )
Get the edge num file path of the vertex chunk.
WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method!
Parameters
- chunk_index: index of vertex chunk.
- adj_list_type: type of adj list structure. :returns: the edge num file path. If edge info not support the adj list type, raise an IllegalArgumentException error.
1145 def get_adj_list_offset_file_path( 1146 self, 1147 chunk_index: int, 1148 adj_list_type: AdjListType, 1149 ) -> str: 1150 """Get the adj list offset chunk file path of vertex chunk the offset chunks is aligned with the vertex chunks. 1151 1152 WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method! 1153 1154 :param chunk_index: index of vertex chunk. 1155 :param adj_list_type: type of adj list structure. 1156 :returns: the offset chunk file path. If edge info not support the adj list type, raise an IllegalArgumentException error. 1157 1158 """ 1159 return self._jvm_edge_info_obj.getAdjListOffsetFilePath( 1160 chunk_index, 1161 adj_list_type.to_scala(), 1162 )
Get the adj list offset chunk file path of vertex chunk the offset chunks is aligned with the vertex chunks.
WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method!
Parameters
- chunk_index: index of vertex chunk.
- adj_list_type: type of adj list structure. :returns: the offset chunk file path. If edge info not support the adj list type, raise an IllegalArgumentException error.
1164 def get_offset_path_prefix(self, adj_list_type: AdjListType) -> str: 1165 """Get the path prefix of the adjacency list offset for the given adjacency list type. 1166 1167 WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method! 1168 1169 :param adj_list_type: type of adj list structure. 1170 :returns: the path prefix of the offset. If edge info not support the adj list type, raise an IllegalArgumentException error. 1171 1172 """ 1173 return self._jvm_edge_info_obj.getOffsetPathPrefix(adj_list_type.to_scala())
Get the path prefix of the adjacency list offset for the given adjacency list type.
WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method!
Parameters
- adj_list_type: type of adj list structure. :returns: the path prefix of the offset. If edge info not support the adj list type, raise an IllegalArgumentException error.
1175 def get_adj_list_file_path( 1176 self, 1177 vertex_chunk_index: int, 1178 chunk_index: int, 1179 adj_list_type: AdjListType, 1180 ) -> str: 1181 """Get the file path of adj list topology chunk. 1182 1183 :param vertex_chunk_index: index of vertex chunk. 1184 :param chunk_index: index of edge chunk. 1185 :param adj_list_type: type of adj list structure. 1186 :returns: adj list chunk file path. 1187 """ 1188 return self._jvm_edge_info_obj.getAdjListFilePath( 1189 vertex_chunk_index, 1190 chunk_index, 1191 adj_list_type.to_scala(), 1192 )
Get the file path of adj list topology chunk.
Parameters
- vertex_chunk_index: index of vertex chunk.
- chunk_index: index of edge chunk.
- adj_list_type: type of adj list structure. :returns: adj list chunk file path.
1194 def get_adj_list_path_prefix( 1195 self, 1196 vertex_chunk_index: Optional[int], 1197 adj_list_type: AdjListType, 1198 ) -> str: 1199 """Get the path prefix of adj list topology chunk of certain vertex chunk. 1200 1201 :param vertex_chunk_index: index of vertex chunk (optional). 1202 :param adj_list_type: type of adj list structure. 1203 :returns: path prefix of the edge chunk of vertices of given vertex chunk. 1204 """ 1205 if vertex_chunk_index is None: 1206 return self._jvm_edge_info_obj.getAdjListPathPrefix( 1207 adj_list_type.to_scala(), 1208 ) 1209 1210 return self._jvm_edge_info_obj.getAdjListPathPrefix( 1211 vertex_chunk_index, 1212 adj_list_type.to_scala(), 1213 )
Get the path prefix of adj list topology chunk of certain vertex chunk.
Parameters
- vertex_chunk_index: index of vertex chunk (optional).
- adj_list_type: type of adj list structure. :returns: path prefix of the edge chunk of vertices of given vertex chunk.
1215 def get_property_file_path( 1216 self, 1217 property_group: PropertyGroup, 1218 adj_list_type: AdjListType, 1219 vertex_chunk_index: int, 1220 chunk_index: int, 1221 ) -> str: 1222 """Get the chunk file path of adj list property group. the property group chunks is aligned with the adj list topology chunks. 1223 1224 WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method! 1225 1226 :param property_group: property group 1227 :param adj_list_type: type of adj list structure. 1228 :param vertex_chunk_index: index of vertex chunk. 1229 :param chunk_index: index of edge chunk. 1230 :returns: property group chunk file path. If edge info not contains the property group, raise an IllegalArgumentException error. 1231 """ 1232 return self._jvm_edge_info_obj.getPropertyFilePath( 1233 property_group.to_scala(), 1234 adj_list_type.to_scala(), 1235 vertex_chunk_index, 1236 chunk_index, 1237 )
Get the chunk file path of adj list property group. the property group chunks is aligned with the adj list topology chunks.
WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method!
Parameters
- property_group: property group
- adj_list_type: type of adj list structure.
- vertex_chunk_index: index of vertex chunk.
- chunk_index: index of edge chunk. :returns: property group chunk file path. If edge info not contains the property group, raise an IllegalArgumentException error.
1239 def get_property_group_path_prefix( 1240 self, 1241 property_group: PropertyGroup, 1242 adj_list_type: AdjListType, 1243 vertex_chunk_index: Optional[int] = None, 1244 ) -> str: 1245 """Get path prefix of adj list property group of certain vertex chunk. 1246 1247 WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method! 1248 1249 :param property_group: property group. 1250 :param adj_list_type: type of adj list structure. 1251 :param vertex_chunk_index: index of vertex chunk (optional, default is None). 1252 :returns: path prefix of property group chunks of of vertices of given vertex 1253 chunk. If edge info not contains the property group, raise an IllegalArgumentException error. 1254 """ 1255 if vertex_chunk_index is not None: 1256 return self._jvm_edge_info_obj.getPropertyGroupPathPrefix( 1257 property_group.to_scala(), 1258 adj_list_type.to_scala(), 1259 vertex_chunk_index, 1260 ) 1261 1262 return self._jvm_edge_info_obj.getPropertyGroupPathPrefix( 1263 property_group.to_scala(), 1264 adj_list_type.to_scala(), 1265 )
Get path prefix of adj list property group of certain vertex chunk.
WARNING! Exceptions from the JVM are not checked inside, it is just a proxy-method!
Parameters
- property_group: property group.
- adj_list_type: type of adj list structure.
- vertex_chunk_index: index of vertex chunk (optional, default is None). :returns: path prefix of property group chunks of of vertices of given vertex chunk. If edge info not contains the property group, raise an IllegalArgumentException error.
1267 def get_concat_key(self) -> str: 1268 """Get concat key. 1269 1270 :returns: concat key 1271 """ 1272 return self._jvm_edge_info_obj.getConcatKey()
Get concat key.
:returns: concat key
1274 def dump(self) -> str: 1275 """Dump to Yaml string. 1276 1277 :returns: yaml-string representation. 1278 """ 1279 return self._jvm_edge_info_obj.dump()
Dump to Yaml string.
:returns: yaml-string representation.
1281 @staticmethod 1282 def load_edge_info(edge_info_path: str) -> "EdgeInfo": 1283 """Load a yaml file from path and construct a EdgeInfo from it. 1284 1285 :param edge_info_path: path of edge info YAML file. 1286 :returns: EdgeInfo object. 1287 """ 1288 return EdgeInfo.from_scala( 1289 GraphArSession.graphar.EdgeInfo.loadEdgeInfo( 1290 edge_info_path, 1291 GraphArSession.jss, 1292 ), 1293 )
Load a yaml file from path and construct a EdgeInfo from it.
Parameters
- edge_info_path: path of edge info YAML file. :returns: EdgeInfo object.
1296class GraphInfo: 1297 """GraphInfo is a class to store the graph meta information.""" 1298 1299 def __init__( 1300 self, 1301 name: Optional[str], 1302 prefix: Optional[str], 1303 vertices: Optional[list[str]], 1304 edges: Optional[list[str]], 1305 version: Optional[str], 1306 jvm_grpah_info_obj: Optional[JavaObject], 1307 ) -> None: 1308 """One should not use this constructor directly, please use `from_scala` or `from_python`.""" 1309 _check_session() 1310 if jvm_grpah_info_obj is not None: 1311 self._jvm_graph_info_obj = jvm_grpah_info_obj 1312 else: 1313 graph_info = GraphArSession.graphar.GraphInfo() 1314 graph_info.setName(name) 1315 graph_info.setPrefix(prefix) 1316 graph_info.setVertices(vertices) 1317 graph_info.setEdges(edges) 1318 graph_info.setVersion(version) 1319 self._jvm_graph_info_obj = graph_info 1320 1321 def get_name(self) -> str: 1322 """Get name from the corresponding JVM object. 1323 1324 :returns: name 1325 """ 1326 return self._jvm_graph_info_obj.getName() 1327 1328 def set_name(self, name: str) -> None: 1329 """Mutate the corresponding JVM object. 1330 1331 :param name: new name 1332 """ 1333 self._jvm_graph_info_obj.setName(name) 1334 1335 def get_prefix(self) -> str: 1336 """Get prefix from corresponding JVM object. 1337 1338 :returns: prefix 1339 """ 1340 return self._jvm_graph_info_obj.getPrefix() 1341 1342 def set_prefix(self, prefix: str) -> None: 1343 """Mutate the corresponding JVM object. 1344 1345 :param prefix: new prefix 1346 """ 1347 self._jvm_graph_info_obj.setPrefix(prefix) 1348 1349 def get_vertices(self) -> JavaList: 1350 """Get list of vertices from the corresponding JVM object. 1351 1352 :returns: vertices 1353 """ 1354 return self._jvm_graph_info_obj.getVertices() 1355 1356 def set_vertices(self, vertices: Union[list[str], JavaList]) -> None: 1357 """Mutate the corresponding JVM object. 1358 1359 :param vertices: new list of vertices 1360 """ 1361 self._jvm_graph_info_obj.setVertices(vertices) 1362 1363 def get_edges(self) -> JavaList: 1364 """Get list of edges from the corresponding JVM object. 1365 1366 :returns: edges 1367 """ 1368 return self._jvm_graph_info_obj.getEdges() 1369 1370 def set_edges(self, edges: Union[list[str], JavaList]) -> None: 1371 """Mutate the corresponding JVM object. 1372 1373 :param edges: new list of edges. 1374 """ 1375 self._jvm_graph_info_obj.setEdges(edges) 1376 1377 def get_version(self) -> str: 1378 """Get GraphAr format version from the corresponding JVM object. 1379 1380 :returns: version 1381 """ 1382 return self._jvm_graph_info_obj.getVersion() 1383 1384 def set_version(self, version: str) -> None: 1385 """Mutate the corresponding JVM object. 1386 1387 :param version: new version of GraphAr format 1388 """ 1389 self._jvm_graph_info_obj.setVersion(version) 1390 1391 def to_scala(self) -> JavaObject: 1392 """Transform object to JVM representation. 1393 1394 :returns: JavaObject 1395 """ 1396 return self._jvm_graph_info_obj 1397 1398 @staticmethod 1399 def from_scala(jvm_obj: JavaObject) -> "GraphInfo": 1400 """Create an instance of the Class from the corresponding JVM object. 1401 1402 :param jvm_obj: scala object in JVM. 1403 :returns: instance of Python Class. 1404 """ 1405 return GraphInfo(None, None, None, None, None, jvm_obj) 1406 1407 @staticmethod 1408 def from_python( 1409 name: str, 1410 prefix: str, 1411 vertices: Sequence[str], 1412 edges: Sequence[str], 1413 version: str, 1414 ) -> "GraphInfo": 1415 """Create an instance of the class from python arguments. 1416 1417 :param name: name of the graph 1418 :param prefix: path prefix 1419 :param vertices: list of vertices 1420 :param edges: list of edges 1421 :param version: version of GraphAr format 1422 """ 1423 if not prefix.endswith(os.sep): 1424 prefix += os.sep 1425 return GraphInfo(name, prefix, vertices, edges, version, None) 1426 1427 def add_vertex_info(self, vertex_info: VertexInfo) -> None: 1428 """Add VertexInfo to GraphInfo. 1429 1430 :param vertex_info: VertexInfo to add 1431 """ 1432 self._jvm_graph_info_obj.addVertexInfo(vertex_info.to_scala()) 1433 1434 def add_edge_info(self, edge_info: EdgeInfo) -> None: 1435 """Add EdgeInfo to GraphInfo. 1436 1437 :param edge_info: EdgeInfo to add 1438 """ 1439 self._jvm_graph_info_obj.addEdgeInfo(edge_info.to_scala()) 1440 1441 def get_vertex_info(self, label: str) -> VertexInfo: 1442 """Get vertex info from the corresponding JVM object. 1443 1444 :param label: label of vertex 1445 """ 1446 return VertexInfo.from_scala(self._jvm_graph_info_obj.getVertexInfo(label)) 1447 1448 def get_edge_info( 1449 self, 1450 src_label: str, 1451 edge_label: str, 1452 dst_label: str, 1453 ) -> EdgeInfo: 1454 """Get edge info from the corresponding JVM object. 1455 1456 :param src_label: source label 1457 :param edge_label: edge label 1458 :param dst_label: destination label 1459 """ 1460 return EdgeInfo.from_scala( 1461 self._jvm_graph_info_obj.getEdgeInfo(src_label, edge_label, dst_label), 1462 ) 1463 1464 def get_vertex_infos(self) -> dict[str, VertexInfo]: 1465 """Get all vertex infos from the corresponding JVM object. 1466 1467 :returns: Mapping label -> VertexInfo 1468 """ 1469 scala_map = self._jvm_graph_info_obj.getVertexInfos() 1470 keys_set_iter = scala_map.keySet().iterator() 1471 res = {} 1472 while keys_set_iter.hasNext(): 1473 k = keys_set_iter.next() 1474 res[k] = VertexInfo.from_scala(scala_map.get(k)) 1475 1476 return res 1477 1478 def get_edge_infos(self) -> dict[str, EdgeInfo]: 1479 """Get all edge infos from the corresponding JVM object. 1480 1481 :returns: Mapping {src_label}_{edge_label}_{dst_label} -> EdgeInfo 1482 """ 1483 scala_map = self._jvm_graph_info_obj.getEdgeInfos() 1484 keys_set_iter = scala_map.keySet().iterator() 1485 res = {} 1486 while keys_set_iter.hasNext(): 1487 k = keys_set_iter.next() 1488 res[k] = EdgeInfo.from_scala(scala_map.get(k)) 1489 1490 return res 1491 1492 def dump(self) -> str: 1493 """Dump to Yaml string. 1494 1495 :returns: YAML-string representation of object. 1496 """ 1497 return self._jvm_graph_info_obj.dump() 1498 1499 @staticmethod 1500 def load_graph_info(graph_info_path: str) -> "GraphInfo": 1501 """Load a yaml file from path and construct a GraphInfo from it. 1502 1503 :param graph_info_path: path of GraphInfo YAML file. 1504 :returns: GraphInfo object. 1505 """ 1506 return GraphInfo.from_scala( 1507 GraphArSession.graphar.GraphInfo.loadGraphInfo( 1508 graph_info_path, 1509 GraphArSession.jss, 1510 ), 1511 )
GraphInfo is a class to store the graph meta information.
1299 def __init__( 1300 self, 1301 name: Optional[str], 1302 prefix: Optional[str], 1303 vertices: Optional[list[str]], 1304 edges: Optional[list[str]], 1305 version: Optional[str], 1306 jvm_grpah_info_obj: Optional[JavaObject], 1307 ) -> None: 1308 """One should not use this constructor directly, please use `from_scala` or `from_python`.""" 1309 _check_session() 1310 if jvm_grpah_info_obj is not None: 1311 self._jvm_graph_info_obj = jvm_grpah_info_obj 1312 else: 1313 graph_info = GraphArSession.graphar.GraphInfo() 1314 graph_info.setName(name) 1315 graph_info.setPrefix(prefix) 1316 graph_info.setVertices(vertices) 1317 graph_info.setEdges(edges) 1318 graph_info.setVersion(version) 1319 self._jvm_graph_info_obj = graph_info
One should not use this constructor directly, please use from_scala
or from_python
.
1321 def get_name(self) -> str: 1322 """Get name from the corresponding JVM object. 1323 1324 :returns: name 1325 """ 1326 return self._jvm_graph_info_obj.getName()
Get name from the corresponding JVM object.
:returns: name
1328 def set_name(self, name: str) -> None: 1329 """Mutate the corresponding JVM object. 1330 1331 :param name: new name 1332 """ 1333 self._jvm_graph_info_obj.setName(name)
Mutate the corresponding JVM object.
Parameters
- name: new name
1335 def get_prefix(self) -> str: 1336 """Get prefix from corresponding JVM object. 1337 1338 :returns: prefix 1339 """ 1340 return self._jvm_graph_info_obj.getPrefix()
Get prefix from corresponding JVM object.
:returns: prefix
1342 def set_prefix(self, prefix: str) -> None: 1343 """Mutate the corresponding JVM object. 1344 1345 :param prefix: new prefix 1346 """ 1347 self._jvm_graph_info_obj.setPrefix(prefix)
Mutate the corresponding JVM object.
Parameters
- prefix: new prefix
1349 def get_vertices(self) -> JavaList: 1350 """Get list of vertices from the corresponding JVM object. 1351 1352 :returns: vertices 1353 """ 1354 return self._jvm_graph_info_obj.getVertices()
Get list of vertices from the corresponding JVM object.
:returns: vertices
1356 def set_vertices(self, vertices: Union[list[str], JavaList]) -> None: 1357 """Mutate the corresponding JVM object. 1358 1359 :param vertices: new list of vertices 1360 """ 1361 self._jvm_graph_info_obj.setVertices(vertices)
Mutate the corresponding JVM object.
Parameters
- vertices: new list of vertices
1363 def get_edges(self) -> JavaList: 1364 """Get list of edges from the corresponding JVM object. 1365 1366 :returns: edges 1367 """ 1368 return self._jvm_graph_info_obj.getEdges()
Get list of edges from the corresponding JVM object.
:returns: edges
1370 def set_edges(self, edges: Union[list[str], JavaList]) -> None: 1371 """Mutate the corresponding JVM object. 1372 1373 :param edges: new list of edges. 1374 """ 1375 self._jvm_graph_info_obj.setEdges(edges)
Mutate the corresponding JVM object.
Parameters
- edges: new list of edges.
1377 def get_version(self) -> str: 1378 """Get GraphAr format version from the corresponding JVM object. 1379 1380 :returns: version 1381 """ 1382 return self._jvm_graph_info_obj.getVersion()
Get GraphAr format version from the corresponding JVM object.
:returns: version
1384 def set_version(self, version: str) -> None: 1385 """Mutate the corresponding JVM object. 1386 1387 :param version: new version of GraphAr format 1388 """ 1389 self._jvm_graph_info_obj.setVersion(version)
Mutate the corresponding JVM object.
Parameters
- version: new version of GraphAr format
1391 def to_scala(self) -> JavaObject: 1392 """Transform object to JVM representation. 1393 1394 :returns: JavaObject 1395 """ 1396 return self._jvm_graph_info_obj
Transform object to JVM representation.
:returns: JavaObject
1398 @staticmethod 1399 def from_scala(jvm_obj: JavaObject) -> "GraphInfo": 1400 """Create an instance of the Class from the corresponding JVM object. 1401 1402 :param jvm_obj: scala object in JVM. 1403 :returns: instance of Python Class. 1404 """ 1405 return GraphInfo(None, None, None, None, None, jvm_obj)
Create an instance of the Class from the corresponding JVM object.
Parameters
- jvm_obj: scala object in JVM. :returns: instance of Python Class.
1407 @staticmethod 1408 def from_python( 1409 name: str, 1410 prefix: str, 1411 vertices: Sequence[str], 1412 edges: Sequence[str], 1413 version: str, 1414 ) -> "GraphInfo": 1415 """Create an instance of the class from python arguments. 1416 1417 :param name: name of the graph 1418 :param prefix: path prefix 1419 :param vertices: list of vertices 1420 :param edges: list of edges 1421 :param version: version of GraphAr format 1422 """ 1423 if not prefix.endswith(os.sep): 1424 prefix += os.sep 1425 return GraphInfo(name, prefix, vertices, edges, version, None)
Create an instance of the class from python arguments.
Parameters
- name: name of the graph
- prefix: path prefix
- vertices: list of vertices
- edges: list of edges
- version: version of GraphAr format
1427 def add_vertex_info(self, vertex_info: VertexInfo) -> None: 1428 """Add VertexInfo to GraphInfo. 1429 1430 :param vertex_info: VertexInfo to add 1431 """ 1432 self._jvm_graph_info_obj.addVertexInfo(vertex_info.to_scala())
Add VertexInfo to GraphInfo.
Parameters
- vertex_info: VertexInfo to add
1434 def add_edge_info(self, edge_info: EdgeInfo) -> None: 1435 """Add EdgeInfo to GraphInfo. 1436 1437 :param edge_info: EdgeInfo to add 1438 """ 1439 self._jvm_graph_info_obj.addEdgeInfo(edge_info.to_scala())
Add EdgeInfo to GraphInfo.
Parameters
- edge_info: EdgeInfo to add
1441 def get_vertex_info(self, label: str) -> VertexInfo: 1442 """Get vertex info from the corresponding JVM object. 1443 1444 :param label: label of vertex 1445 """ 1446 return VertexInfo.from_scala(self._jvm_graph_info_obj.getVertexInfo(label))
Get vertex info from the corresponding JVM object.
Parameters
- label: label of vertex
1448 def get_edge_info( 1449 self, 1450 src_label: str, 1451 edge_label: str, 1452 dst_label: str, 1453 ) -> EdgeInfo: 1454 """Get edge info from the corresponding JVM object. 1455 1456 :param src_label: source label 1457 :param edge_label: edge label 1458 :param dst_label: destination label 1459 """ 1460 return EdgeInfo.from_scala( 1461 self._jvm_graph_info_obj.getEdgeInfo(src_label, edge_label, dst_label), 1462 )
Get edge info from the corresponding JVM object.
Parameters
- src_label: source label
- edge_label: edge label
- dst_label: destination label
1464 def get_vertex_infos(self) -> dict[str, VertexInfo]: 1465 """Get all vertex infos from the corresponding JVM object. 1466 1467 :returns: Mapping label -> VertexInfo 1468 """ 1469 scala_map = self._jvm_graph_info_obj.getVertexInfos() 1470 keys_set_iter = scala_map.keySet().iterator() 1471 res = {} 1472 while keys_set_iter.hasNext(): 1473 k = keys_set_iter.next() 1474 res[k] = VertexInfo.from_scala(scala_map.get(k)) 1475 1476 return res
Get all vertex infos from the corresponding JVM object.
:returns: Mapping label -> VertexInfo
1478 def get_edge_infos(self) -> dict[str, EdgeInfo]: 1479 """Get all edge infos from the corresponding JVM object. 1480 1481 :returns: Mapping {src_label}_{edge_label}_{dst_label} -> EdgeInfo 1482 """ 1483 scala_map = self._jvm_graph_info_obj.getEdgeInfos() 1484 keys_set_iter = scala_map.keySet().iterator() 1485 res = {} 1486 while keys_set_iter.hasNext(): 1487 k = keys_set_iter.next() 1488 res[k] = EdgeInfo.from_scala(scala_map.get(k)) 1489 1490 return res
Get all edge infos from the corresponding JVM object.
:returns: Mapping {src_label}_{edge_label}_{dst_label} -> EdgeInfo
1492 def dump(self) -> str: 1493 """Dump to Yaml string. 1494 1495 :returns: YAML-string representation of object. 1496 """ 1497 return self._jvm_graph_info_obj.dump()
Dump to Yaml string.
:returns: YAML-string representation of object.
1499 @staticmethod 1500 def load_graph_info(graph_info_path: str) -> "GraphInfo": 1501 """Load a yaml file from path and construct a GraphInfo from it. 1502 1503 :param graph_info_path: path of GraphInfo YAML file. 1504 :returns: GraphInfo object. 1505 """ 1506 return GraphInfo.from_scala( 1507 GraphArSession.graphar.GraphInfo.loadGraphInfo( 1508 graph_info_path, 1509 GraphArSession.jss, 1510 ), 1511 )
Load a yaml file from path and construct a GraphInfo from it.
Parameters
- graph_info_path: path of GraphInfo YAML file. :returns: GraphInfo object.