Esempio n. 1
0
def create_graph(session_id, graph_type, **kwargs):
    """Create an `CREATE_GRAPH` op, add op to default dag.

    Args:
        session_id (str): Refer to session that the graph will be create on.
        graph_type (:enum:`GraphType`): GraphType defined in proto.types.proto.
        **kwargs: additional properties respect to different `graph_type`.

    Returns:
        An op to create a graph in c++ side with necessary configurations.
    """
    config = {
        types_pb2.GRAPH_TYPE: utils.graph_type_to_attr(graph_type),
    }

    if graph_type == types_pb2.ARROW_PROPERTY:
        attrs = kwargs.pop("attrs", None)
        if attrs:
            for k, v in attrs.items():
                if isinstance(v, attr_value_pb2.AttrValue):
                    config[k] = v
    elif graph_type == types_pb2.DYNAMIC_PROPERTY:
        config[types_pb2.E_FILE] = utils.s_to_attr(kwargs["efile"])
        config[types_pb2.V_FILE] = utils.s_to_attr(kwargs["vfile"])
        config[types_pb2.DIRECTED] = utils.b_to_attr(kwargs["directed"])
    else:
        raise RuntimeError("Not supported graph type {}".format(graph_type))

    op = Operation(session_id,
                   types_pb2.CREATE_GRAPH,
                   config=config,
                   output_types=types_pb2.GRAPH)
    return op
Esempio n. 2
0
def gremlin_to_subgraph(
    interactive_query, gremlin_script, request_options=None, oid_type="int64"
):
    """Create a subgraph from gremlin output.

    Args:
        interactive_query (:class:`graphscope.interactive.query.InteractiveQueryDAGNode`):
            The GIE instance holds the graph that gremlin query on.
        gremlin_script (str):
            gremlin script to be executed.
        request_options (dict, optional): gremlin request options. format:
            {
                "engine": "gae"
            }
        oid_type (str, optional):
            Type of vertex original id. Defaults to "int64".

    Returns:
        An op to create the subgraph from gremlin script
    """
    config = {}
    config[types_pb2.GIE_GREMLIN_QUERY_MESSAGE] = utils.s_to_attr(gremlin_script)
    config[types_pb2.OID_TYPE] = utils.s_to_attr(oid_type)
    if request_options:
        config[types_pb2.GIE_GREMLIN_REQUEST_OPTIONS] = utils.s_to_attr(
            json.dumps(request_options)
        )
    op = Operation(
        interactive_query.session_id,
        types_pb2.SUBGRAPH,
        config=config,
        inputs=[interactive_query.op],
        output_types=types_pb2.GRAPH,
    )
    return op
Esempio n. 3
0
def add_column(graph, results, selector):
    """Add a column to `graph`, produce a new graph.

    Args:
        graph (:class:`Graph`): Source ArrowProperty graph.
        results (:class:`Context`): Results that generated by previous app querying.
        selector (str): Used to select a subrange of data of results, add them
            as one column of graph.

    Returns:
        A new graph with new columns added.
    """
    config = {
        types_pb2.GRAPH_NAME: utils.s_to_attr(graph.key),
        types_pb2.GRAPH_TYPE: utils.graph_type_to_attr(graph.graph_type),
        types_pb2.CTX_NAME: utils.s_to_attr(results.key),
        types_pb2.SELECTOR: utils.s_to_attr(selector),
    }
    op = Operation(
        graph._session_id,
        types_pb2.ADD_COLUMN,
        config=config,
        output_types=types_pb2.GRAPH,
    )
    return op
Esempio n. 4
0
def copy_graph(graph, copy_type="identical"):
    """Create copy operation for nx graph.

    Args:
        graph (:class:`nx.Graph`): A nx graph.
        copy_type (str): 'identical': copy graph to destination graph without any change.
                         'reverse': copy graph to destination graph with reversing the graph edges

    Returns:
        Operation
    """
    check_argument(graph.graph_type in (graph_def_pb2.ARROW_PROPERTY,
                                        graph_def_pb2.DYNAMIC_PROPERTY))
    check_argument(copy_type in ("identical", "reverse"))
    config = {
        types_pb2.GRAPH_NAME: utils.s_to_attr(graph.key),
        types_pb2.COPY_TYPE: utils.s_to_attr(copy_type),
    }

    op = Operation(
        graph.session_id,
        types_pb2.COPY_GRAPH,
        config=config,
        output_types=types_pb2.GRAPH,
    )
    return op
Esempio n. 5
0
def project_dynamic_property_graph(graph, v_prop, e_prop, v_prop_type, e_prop_type):
    """Create project graph operation for nx graph.

    Args:
        graph (:class:`nx.Graph`): A nx graph.
        v_prop (str): The node attribute key to project.
        e_prop (str): The edge attribute key to project.
        v_prop_type (str): Type of the node attribute.
        e_prop_type (str): Type of the edge attribute.

    Returns:
        Operation to project a dynamic property graph. Results in a simple graph.
    """
    check_argument(graph.graph_type == types_pb2.DYNAMIC_PROPERTY)
    config = {
        types_pb2.GRAPH_NAME: utils.s_to_attr(graph.key),
        types_pb2.GRAPH_TYPE: utils.graph_type_to_attr(types_pb2.DYNAMIC_PROJECTED),
        types_pb2.V_PROP_KEY: utils.s_to_attr(v_prop),
        types_pb2.E_PROP_KEY: utils.s_to_attr(e_prop),
        types_pb2.V_DATA_TYPE: utils.s_to_attr(utils.data_type_to_cpp(v_prop_type)),
        types_pb2.E_DATA_TYPE: utils.s_to_attr(utils.data_type_to_cpp(e_prop_type)),
    }

    op = Operation(
        graph.session_id,
        types_pb2.PROJECT_GRAPH,
        config=config,
        output_types=types_pb2.GRAPH,
    )
    return op
Esempio n. 6
0
def context_to_numpy(context, selector=None, vertex_range=None, axis=0):
    """Retrieve results as a numpy ndarray.

    Args:
        results (:class:`Context`): Results return by `run_app` operation, store the query results.
        selector (str): Select the type of data to retrieve.
        vertex_range (str): Specify a range to retrieve.

    Returns:
        An op to retrieve query results and convert to numpy ndarray.
    """
    config = {}
    if selector is not None:
        config[types_pb2.SELECTOR] = utils.s_to_attr(selector)
    if vertex_range is not None:
        config[types_pb2.VERTEX_RANGE] = utils.s_to_attr(vertex_range)
    if axis is not None:
        config[types_pb2.AXIS] = utils.i_to_attr(axis)
    op = Operation(
        context.session_id,
        types_pb2.CONTEXT_TO_NUMPY,
        config=config,
        inputs=[context.op],
        output_types=types_pb2.TENSOR,
    )
    return op
Esempio n. 7
0
def modify_edges(graph, modify_type, edges, attr={}, weight=None):
    """Create modify edges operation for nx graph.

    Args:
        graph (:class:`nx.Graph`): A nx graph.
        modify_type (`type_pb2.(NX_ADD_EDGES | NX_DEL_EDGES | NX_UPDATE_EDGES)`): The modify type
        edges (list): List of edges to be inserted into or delete from graph based on `modify_type`

    Returns:
        An op to modify edges on the graph.
    """
    check_argument(graph.graph_type == graph_def_pb2.DYNAMIC_PROPERTY)
    config = {}
    config[types_pb2.GRAPH_NAME] = utils.s_to_attr(graph.key)
    config[types_pb2.MODIFY_TYPE] = utils.modify_type_to_attr(modify_type)
    config[types_pb2.PROPERTIES] = utils.s_to_attr(json.dumps(attr))
    if weight:
        config[types_pb2.EDGE_KEY] = utils.s_to_attr(weight)
    op = Operation(
        graph.session_id,
        types_pb2.MODIFY_EDGES,
        config=config,
        large_attr=utils.bytes_to_large_attr(edges),
        output_types=types_pb2.GRAPH,
    )
    return op
Esempio n. 8
0
def arrow_to_dynamic(graph):
    """Transform a :class:`Graph` object to :class:`nx.Graph`.

    Args:
        graph (:class:`Graph`): Source graph, which type should be ARROW_PROPERTY.

    Returns:
        An op of transform arrow graph to dynamic graph with necessary configurations.
    """
    check_argument(graph.graph_type == graph_def_pb2.ARROW_PROPERTY)
    config = {
        types_pb2.GRAPH_NAME:
        utils.s_to_attr(graph.key),
        types_pb2.GRAPH_TYPE:
        utils.graph_type_to_attr(graph_def_pb2.ARROW_PROPERTY),
        types_pb2.DST_GRAPH_TYPE:
        utils.graph_type_to_attr(graph_def_pb2.DYNAMIC_PROPERTY),
        types_pb2.OID_TYPE:
        utils.s_to_attr(utils.data_type_to_cpp(graph.schema.oid_type)),
        types_pb2.VID_TYPE:
        utils.s_to_attr(utils.data_type_to_cpp(graph.schema.vid_type)),
        types_pb2.DEFAULT_LABEL_ID:
        utils.i_to_attr(graph._default_label_id),
    }
    op = Operation(
        graph.session_id,
        types_pb2.TRANSFORM_GRAPH,
        config=config,
        output_types=types_pb2.GRAPH,
    )
    return op
Esempio n. 9
0
def graph_to_dataframe(graph, selector=None, vertex_range=None):
    """Retrieve graph raw data as a pandas DataFrame.

    Args:
        graph (:class:`Graph`): Source graph.
        selector (str): Select the type of data to retrieve.
        vertex_range (str): Specify a range to retrieve.

    Returns:
        An op to convert a graph's data to pandas DataFrame.
    """
    config = {
        types_pb2.GRAPH_NAME: utils.s_to_attr(graph.key),
    }
    if selector is not None:
        config[types_pb2.SELECTOR] = utils.s_to_attr(selector)
    if vertex_range is not None:
        config[types_pb2.VERTEX_RANGE] = utils.s_to_attr(vertex_range)
    op = Operation(
        graph._session_id,
        types_pb2.GRAPH_TO_DATAFRAME,
        config=config,
        output_types=types_pb2.DATAFRAME,
    )
    return op
Esempio n. 10
0
def to_vineyard_tensor(context, selector=None, vertex_range=None, axis=None):
    """Retrieve results as vineyard tensor.

    Parameters:
        results (:class:`Context`): Results return by `run_app` operation, store the query results.
        selector (str): Select the type of data to retrieve.
        vertex_range (str): Specify a range to retrieve.
    Returns:
        An op to convert query results into a vineyard tensor.
    """
    config = {}
    if selector is not None:
        config[types_pb2.SELECTOR] = utils.s_to_attr(selector)
    if vertex_range is not None:
        config[types_pb2.VERTEX_RANGE] = utils.s_to_attr(vertex_range)
    if axis is not None:
        config[types_pb2.AXIS] = utils.i_to_attr(axis)
    op = Operation(
        context.session_id,
        types_pb2.TO_VINEYARD_TENSOR,
        config=config,
        inputs=[context.op],
        output_types=types_pb2.VINEYARD_TENSOR,
    )
    return op
Esempio n. 11
0
def gremlin_query(interactive_query, query, request_options=None):
    """Execute a gremlin query.

    Args:
        interactive_query (:class:`graphscope.interactive.query.InteractiveQueryDAGNode`):
            The GIE instance holds the graph that gremlin query on.
        query (str):
            Scripts that written in gremlin quering language.
        request_options (dict, optional): gremlin request options. format:
            {
                "engine": "gae"
            }

    Returns:
        An op to execute a gremlin query on the GIE instance.
    """
    config = {}
    config[types_pb2.GIE_GREMLIN_QUERY_MESSAGE] = utils.s_to_attr(query)
    if request_options:
        config[types_pb2.GIE_GREMLIN_REQUEST_OPTIONS] = utils.s_to_attr(
            json.dumps(request_options))
    op = Operation(
        interactive_query.session_id,
        types_pb2.GREMLIN_QUERY,
        config=config,
        inputs=[interactive_query.op],
        output_types=types_pb2.GREMLIN_RESULTS,
    )
    return op
Esempio n. 12
0
def report_graph(
    graph, report_type, node=None, edge=None, fid=None, lid=None, key=None
):
    """Create report operation for nx graph.

    This operation is used to simulate networkx graph reporting methods with variaty
    report type and corresponding config parameters.

    Args:
        graph (`nx.Graph`): A nx graph.
        report_type: report type, can be
            type_pb2.(NODE_NUM,
                      EDGE_NUM,
                      HAS_NODE,
                      HAS_EDGE,
                      NODE_DATA,
                      EDGE_DATA,
                      NEIGHBORS_BY_NODE,
                      SUCCS_BY_NODE,
                      PREDS_BY_NODE,
                      NEIGHBORS_BY_LOC,
                      SUCCS_BY_LOC,
                      PREDS_BY_LOC,
                      DEG_BY_NODE,
                      IN_DEG_BY_NODE,
                      OUT_DEG_BY_NODE,
                      DEG_BY_LOC,
                      IN_DEG_BY_LOC,
                      OUT_DEG_BY_LOC,
                      NODES_BY_LOC)
        node (str): node id, used as node id with 'NODE' report types. (optional)
        edge (str): an edge with 'EDGE' report types. (optional)
        fid (int): fragment id, with 'LOC' report types. (optional)
        lid (int): local id of node in grape_engine, with 'LOC; report types. (optional)
        key (str): edge key for MultiGraph or MultiDiGraph, with 'EDGE' report types. (optional)

    Returns:
        An op to do reporting job.
    """
    config = {
        types_pb2.GRAPH_NAME: utils.s_to_attr(graph.key),
        types_pb2.REPORT_TYPE: utils.report_type_to_attr(report_type),
    }
    if node is not None:
        config[types_pb2.NODE] = utils.s_to_attr(node)
    if edge is not None:
        config[types_pb2.EDGE] = utils.s_to_attr(edge)
    if fid is not None:
        config[types_pb2.FID] = utils.i_to_attr(fid)
    if lid is not None:
        config[types_pb2.LID] = utils.i_to_attr(lid)

    config[types_pb2.EDGE_KEY] = utils.s_to_attr(str(key) if key is not None else "")
    op = Operation(
        graph.session_id,
        types_pb2.REPORT_GRAPH,
        config=config,
        output_types=types_pb2.RESULTS,
    )
    return op
Esempio n. 13
0
def output(context, fd, selector, vertex_range, **kwargs):
    """Output result to `fd`, this will be handled by registered vineyard C++ adaptor.

    Args:
        results (:class:`Context`): Results return by `run_app` operation, store the query results.
        fd (str): Such as `file:///tmp/result_path`
        selector (str): Select the type of data to retrieve.
        vertex_range (str): Specify a range to retrieve.
    Returns:
        An op to output results to `fd`.
    """
    config = {}
    config[types_pb2.FD] = utils.s_to_attr(fd)
    config[types_pb2.SELECTOR] = utils.s_to_attr(selector)
    config[types_pb2.STORAGE_OPTIONS] = utils.s_to_attr(json.dumps(kwargs))
    if vertex_range is not None:
        config[types_pb2.VERTEX_RANGE] = utils.s_to_attr(vertex_range)

    op = Operation(
        context.session_id,
        types_pb2.OUTPUT,
        config=config,
        inputs=[context.op],
        output_types=types_pb2.NULL_OUTPUT,
    )
    return op
Esempio n. 14
0
def context_to_dataframe(results, selector=None, vertex_range=None):
    """Retrieve results as a pandas DataFrame.

    Args:
        results (:class:`Context`): Results return by `run_app` operation, store the query results.
        selector (str): Select the type of data to retrieve.
        vertex_range (str): Specify a range to retrieve.

    Returns:
        An op to retrieve query results and convert to pandas DataFrame.
    """
    config = {
        types_pb2.CTX_NAME: utils.s_to_attr(results.key),
    }
    if selector is not None:
        config[types_pb2.SELECTOR] = utils.s_to_attr(selector)
    if vertex_range is not None:
        config[types_pb2.VERTEX_RANGE] = utils.s_to_attr(vertex_range)
    op = Operation(
        results._session_id,
        types_pb2.CONTEXT_TO_DATAFRAME,
        config=config,
        output_types=types_pb2.DATAFRAME,
    )
    return op
Esempio n. 15
0
def project_arrow_property_graph_to_simple(
    graph,
    v_prop,
    e_prop,
):
    """Project arrow property graph to a simple graph.

    Args:
        graph (:class:`graphscope.Graph`): Source graph, which type should be ARROW_PROPERTY
        v_prop (str): The node attribute key to project.
        e_prop (str): The edge attribute key to project.

    Returns:
        Operation to project a property graph, results in a simple ARROW_PROJECTED graph.
    """
    check_argument(graph.graph_type == graph_def_pb2.ARROW_PROPERTY)
    config = {
        types_pb2.V_PROP_KEY: utils.s_to_attr(v_prop),
        types_pb2.E_PROP_KEY: utils.s_to_attr(e_prop),
    }
    op = Operation(
        graph.session_id,
        types_pb2.PROJECT_TO_SIMPLE,
        config=config,
        inputs=[graph.op],
        output_types=types_pb2.GRAPH,
    )
    return op
Esempio n. 16
0
def run_app(graph, app, *args, **kwargs):
    """Run `app` on the `graph`.

    Args:
        graph (:class:`Graph`): A loaded graph.
        app (:class:`App`): A loaded app that will be queried.
        key (str): Key of query results, can be used to retrieve results.
        *args: Additional query params that will be used in evaluation.
        **kwargs: Key-value formated query params that mostly used in Cython apps.

    Returns:
        An op to run app on the specified graph, with optional query parameters.
    """
    config = {
        types_pb2.GRAPH_NAME: utils.s_to_attr(graph.key),
        types_pb2.APP_NAME: utils.s_to_attr(app.key),
    }
    output_prefix = kwargs.pop("output_prefix", ".")
    config[types_pb2.OUTPUT_PREFIX] = utils.s_to_attr(output_prefix)
    # optional query arguments.
    params = utils.pack_query_params(*args, **kwargs)
    query_args = query_args_pb2.QueryArgs()
    query_args.args.extend(params)

    op = Operation(
        graph._session_id,
        types_pb2.RUN_APP,
        config=config,
        output_types=types_pb2.RESULTS,
        query_args=query_args,
    )
    return op
Esempio n. 17
0
def _get_config(
    edges: Sequence[EdgeLabel],
    vertices: Sequence[VertexLabel],
    directed: bool,
    oid_type: str,
    generate_eid: bool,
) -> Dict:
    config = {}
    attr = attr_value_pb2.AttrValue()

    for label in chain(edges, vertices):
        label.finish(oid_type)

    for edge in edges:
        attr.list.func.extend([process_edge(edge)])

    attr.list.func.extend([process_vertex(vertex) for vertex in vertices])

    directed_attr = utils.b_to_attr(directed)
    generate_eid_attr = utils.b_to_attr(generate_eid)
    config[types_pb2.ARROW_PROPERTY_DEFINITION] = attr
    config[types_pb2.DIRECTED] = directed_attr
    config[types_pb2.OID_TYPE] = utils.s_to_attr(oid_type)
    config[types_pb2.GENERATE_EID] = generate_eid_attr
    # vid_type is fixed
    config[types_pb2.VID_TYPE] = utils.s_to_attr("uint64_t")
    config[types_pb2.IS_FROM_VINEYARD_ID] = utils.b_to_attr(False)
    return config
Esempio n. 18
0
    def get_attr(self):
        attr_list = attr_value_pb2.NameAttrList()
        attr_list.name = "{}_{}".format(self.source_label,
                                        self.destination_label)
        attr_list.attr[types_pb2.SRC_LABEL].CopyFrom(
            utils.s_to_attr(self.source_label))
        attr_list.attr[types_pb2.DST_LABEL].CopyFrom(
            utils.s_to_attr(self.destination_label))
        attr_list.attr[types_pb2.LOAD_STRATEGY].CopyFrom(
            utils.s_to_attr(self.load_strategy))
        attr_list.attr[types_pb2.SRC_VID].CopyFrom(
            utils.s_to_attr(str(self.source_vid)))
        attr_list.attr[types_pb2.DST_VID].CopyFrom(
            utils.s_to_attr(str(self.destination_vid)))

        attr_list.attr[types_pb2.LOADER].CopyFrom(self.loader.get_attr())

        props = []
        for prop in self.properties[2:]:
            prop_attr = attr_value_pb2.NameAttrList()
            prop_attr.name = prop[0]
            prop_attr.attr[0].CopyFrom(utils.type_to_attr(prop[1]))
            props.append(prop_attr)
        attr_list.attr[types_pb2.PROPERTIES].list.func.extend(props)
        return attr_list
Esempio n. 19
0
 def attr(self) -> Sequence[attr_value_pb2.Chunk]:
     chunk_list = []
     for sub_label in self.sub_labels.values():
         chunk = sub_label.get_attr()
         chunk.attr[types_pb2.CHUNK_NAME].CopyFrom(utils.s_to_attr("edge"))
         chunk.attr[types_pb2.CHUNK_TYPE].CopyFrom(
             utils.s_to_attr("loader"))
         chunk.attr[types_pb2.LABEL].CopyFrom(utils.s_to_attr(self.label))
         chunk_list.append(chunk)
     return chunk_list
Esempio n. 20
0
 def _construct_op_of_empty_graph(self):
     config = {}
     config[types_pb2.ARROW_PROPERTY_DEFINITION] = attr_value_pb2.AttrValue()
     config[types_pb2.DIRECTED] = utils.b_to_attr(self._directed)
     config[types_pb2.GENERATE_EID] = utils.b_to_attr(self._generate_eid)
     config[types_pb2.OID_TYPE] = utils.s_to_attr(self._oid_type)
     config[types_pb2.VID_TYPE] = utils.s_to_attr("uint64_t")
     config[types_pb2.IS_FROM_VINEYARD_ID] = utils.b_to_attr(False)
     return dag_utils.create_graph(
         self.session_id, graph_def_pb2.ARROW_PROPERTY, inputs=None, attrs=config
     )
Esempio n. 21
0
def project_arrow_property_graph(
    graph,
    v_label_id,
    v_prop_id,
    e_label_id,
    e_prop_id,
    v_data_type,
    e_data_type,
    oid_type=None,
    vid_type=None,
):
    """Project arrow property graph to a simple graph.

    Args:
        graph (:class:`Graph`): Source graph, which type should be ARROW_PROPERTY
        dst_graph_key (str): The key of projected graph.
        v_label_id (int): Label id of vertex used to project.
        v_prop_id (int): Property id of vertex used to project.
        e_label_id (int): Label id of edge used to project.
        e_prop_id (int): Property id of edge used to project.

    Returns:
        An op to project `graph`, results in a simple ARROW_PROJECTED graph.
    """
    check_argument(graph.graph_type == types_pb2.ARROW_PROPERTY)
    config = {
        types_pb2.GRAPH_NAME:
        utils.s_to_attr(graph.key),
        types_pb2.GRAPH_TYPE:
        utils.graph_type_to_attr(types_pb2.ARROW_PROJECTED),
        types_pb2.V_LABEL_ID:
        utils.i_to_attr(v_label_id),
        types_pb2.V_PROP_ID:
        utils.i_to_attr(v_prop_id),
        types_pb2.E_LABEL_ID:
        utils.i_to_attr(e_label_id),
        types_pb2.E_PROP_ID:
        utils.i_to_attr(e_prop_id),
        types_pb2.OID_TYPE:
        utils.s_to_attr(oid_type),
        types_pb2.VID_TYPE:
        utils.s_to_attr(vid_type),
        types_pb2.V_DATA_TYPE:
        utils.s_to_attr(utils.data_type_to_cpp(v_data_type)),
        types_pb2.E_DATA_TYPE:
        utils.s_to_attr(utils.data_type_to_cpp(e_data_type)),
    }
    op = Operation(
        graph._session_id,
        types_pb2.PROJECT_GRAPH,
        config=config,
        output_types=types_pb2.GRAPH,
    )
    return op
Esempio n. 22
0
 def _from_vineyard_id(self, vineyard_id):
     config = {}
     config[types_pb2.IS_FROM_VINEYARD_ID] = b_to_attr(True)
     config[types_pb2.VINEYARD_ID] = i_to_attr(vineyard_id)
     # FIXME(hetao) hardcode oid/vid type for codegen, when loading from vineyard
     #
     # the metadata should be retrived from vineyard
     config[types_pb2.OID_TYPE] = s_to_attr("int64_t")
     config[types_pb2.VID_TYPE] = s_to_attr("uint64_t")
     op = create_graph(self._session_id, types_pb2.ARROW_PROPERTY, attrs=config)
     graph_def = op.eval()
     return graph_def
Esempio n. 23
0
 def _from_vineyard_name(self, vineyard_name):
     config = {}
     config[types_pb2.IS_FROM_VINEYARD_ID] = utils.b_to_attr(True)
     config[types_pb2.VINEYARD_NAME] = utils.s_to_attr(str(vineyard_name))
     # FIXME(hetao) hardcode oid/vid type for codegen, when loading from vineyard
     #
     # the metadata should be retrived from vineyard
     config[types_pb2.OID_TYPE] = utils.s_to_attr("int64_t")
     config[types_pb2.VID_TYPE] = utils.s_to_attr("uint64_t")
     return dag_utils.create_graph(self.session_id,
                                   types_pb2.ARROW_PROPERTY,
                                   attrs=config)
Esempio n. 24
0
def get_context_data(results, node):
    config = {
        types_pb2.CONTEXT_KEY: utils.s_to_attr(results.key),
        types_pb2.NODE: utils.s_to_attr(node),
    }
    op = Operation(
        results._session_id,
        types_pb2.GET_CONTEXT_DATA,
        config=config,
        output_types=types_pb2.RESULTS,
    )
    return op
Esempio n. 25
0
 def _construct_op_from_vineyard_id(self, vineyard_id):
     assert self._session is not None
     config = {}
     config[types_pb2.IS_FROM_VINEYARD_ID] = utils.b_to_attr(True)
     config[types_pb2.VINEYARD_ID] = utils.i_to_attr(int(vineyard_id))
     # FIXME(hetao) hardcode oid/vid type for codegen, when loading from vineyard
     #
     # the metadata should be retrived from vineyard
     config[types_pb2.OID_TYPE] = utils.s_to_attr("int64_t")
     config[types_pb2.VID_TYPE] = utils.s_to_attr("uint64_t")
     return dag_utils.create_graph(
         self.session_id, graph_def_pb2.ARROW_PROPERTY, attrs=config
     )
Esempio n. 26
0
 def get_attr(self):
     if not self.finished:
         self.finish()
     attr = attr_value_pb2.AttrValue()
     attr.func.name = "loader"
     attr.func.attr[types_pb2.PROTOCOL].CopyFrom(utils.s_to_attr(self.protocol))
     # Let graphscope handle local files cause it's implemented in c++ and
     # doesn't add an additional stream layer.
     # Maybe handled by vineyard in the near future
     if self.protocol == "file":
         source = "{}#{}".format(self.source, self.options)
         attr.func.attr[types_pb2.VALUES].CopyFrom(
             utils.bytes_to_attr(source.encode("utf-8"))
         )
     elif self.protocol in ("numpy", "pandas"):
         attr.func.attr[types_pb2.ROW_NUM].CopyFrom(utils.i_to_attr(self.row_num))
         attr.func.attr[types_pb2.COLUMN_NUM].CopyFrom(
             utils.i_to_attr(self.column_num)
         )
         # Use key start from 10000 + col_index to store raw bytes.
         for i in range(len(self.property_bytes)):
             attr.func.attr[10000 + i].CopyFrom(
                 utils.bytes_to_attr(self.property_bytes[i])
             )
     else:  # Let vineyard handle other data source.
         attr.func.attr[types_pb2.VALUES].CopyFrom(
             utils.bytes_to_attr(self.source.encode("utf-8"))
         )
     return attr
Esempio n. 27
0
def add_edges(graph, **kwargs):
    """Create an `ADD_EDGES` op, add op to default dag.

    Args:
        graph (:class:`Graph`): a :class:`Graph` instance.
        **kwargs: additional properties respect to different `graph_type`.

    Returns:
        An op to add edges to a graph in c++ side with necessary configurations.
    """
    config = {
        types_pb2.GRAPH_NAME: utils.s_to_attr(graph.key),
        types_pb2.GRAPH_TYPE: utils.graph_type_to_attr(graph.graph_type),
    }

    if graph.graph_type == types_pb2.ARROW_PROPERTY:
        attrs = kwargs.pop("attrs", None)
        if attrs:
            for k, v in attrs.items():
                if isinstance(v, attr_value_pb2.AttrValue):
                    config[k] = v
    else:
        raise ValueError(f"Not support add edges on graph type {graph.graph_type}")
    op = Operation(
        graph.session_id,
        types_pb2.ADD_EDGES,
        config=config,
        output_types=types_pb2.GRAPH,
    )
    return op
Esempio n. 28
0
def run_app(app, *args, **kwargs):
    """Run `bound app` on the `graph`.

    Args:
        app (:class:`AppDAGNode`): A :class:`AppDAGNode` instance which represent a bound app.
        key (str): Key of query results, can be used to retrieve results.
        *args: Additional query params that will be used in evaluation.
        **kwargs: Key-value formated query params that mostly used in Cython apps.

    Returns:
        An op to run app on the specified graph, with optional query parameters.
    """
    inputs = [app.op]
    config = {}
    output_prefix = kwargs.pop("output_prefix", ".")
    config[types_pb2.OUTPUT_PREFIX] = utils.s_to_attr(output_prefix)
    # optional query arguments.
    params = utils.pack_query_params(*args, **kwargs)
    query_args = query_args_pb2.QueryArgs()
    query_args.args.extend(params)
    op = Operation(
        app.session_id,
        types_pb2.RUN_APP,
        inputs=inputs,
        config=config,
        output_types=types_pb2.RESULTS,
        query_args=query_args,
    )
    return op
Esempio n. 29
0
def create_interactive_query(graph, engine_params):
    """Create a interactive engine that query on the :code:`graph`

    Args:
        graph (:class:`graphscope.framework.graph.GraphDAGNode`):
            Source property graph.
        engine_params (dict, optional):
            Configuration to startup the interactive engine. See detail in:
            `interactive_engine/deploy/docker/dockerfile/executor.vineyard.properties`

    Returns:
        An op to create a interactive engine based on a graph.
    """
    config = {}
    if engine_params is not None:
        config[types_pb2.GIE_GREMLIN_ENGINE_PARAMS] = utils.s_to_attr(
            json.dumps(engine_params))
    op = Operation(
        graph.session_id,
        types_pb2.CREATE_INTERACTIVE_QUERY,
        config=config,
        inputs=[graph.op],
        output_types=types_pb2.INTERACTIVE_QUERY,
    )
    return op
Esempio n. 30
0
def create_subgraph(graph, nodes=None, edges=None):
    """Create subgraph operation for nx graph.

    Args:
        graph (:class:`nx.Graph`): A nx graph.
        nodes (list): the nodes to induce a subgraph.
        edges (list): the edges to induce a edge-induced subgraph.

    Returns:
        Operation
    """
    check_argument(graph.graph_type == graph_def_pb2.DYNAMIC_PROPERTY)
    config = {
        types_pb2.GRAPH_NAME: utils.s_to_attr(graph.key),
    }
    if nodes is not None:
        config[types_pb2.NODES] = utils.bytes_to_attr(nodes)
    if edges is not None:
        config[types_pb2.EDGES] = utils.bytes_to_attr(edges)

    op = Operation(
        graph.session_id,
        types_pb2.INDUCE_SUBGRAPH,
        config=config,
        output_types=types_pb2.GRAPH,
    )
    return op