#!/usr/bin/env python3# -*- coding: utf-8 -*-## Copyright 2020 Alibaba Group Holding Limited. All Rights Reserved.## Licensed under the Apache License, Version 2.0 (the "License");# you may not use this file except in compliance with the License.# You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License.#importarrayimportfunctools__all__=["declare","Vertex"]# Emulated PIE typeclassGraphScopeMetaType(type):def__getitem__(type,ix):returnarray(type,ix)GraphScopeTypeObject=GraphScopeMetaType("GrapeTypeObject",(object,),{})classGraphScopeType(GraphScopeTypeObject):def__init__(self,name=None):self.name=namedef__repr__(self):returnself.nameVertex=GraphScopeType("Vertex")# Place holderclass__PlaceHolder(object):"""Access it will trigger an exception"""def__init__(self,func):functools.update_wrapper(self,func)def__getattr__(self,key):raiseRuntimeError("Operation not allowed.")def__call__(self,*args,**kwargs):raiseRuntimeError("Operation not allowed.")
[docs]defdeclare(graphscope_type,variable):"""Declare a GraphScope data type. Args: graphscope_type (:class:`graphscope.analytical.udf.GraphScopeType`): Valid options are `graphscope.Vertex` variable: Python variable. Examples: >>> @pie(vd_type="string", md_type="string") >>> class MyAlgorithm(AppAssets): >>> @staticmethod >>> def Init(frag, context): >>> graphscope.declare(graphscope.Vertex, source) >>> # means `Vertex source;` in c++ code >>> @staticmethod >>> def PEval(frag, context): >>> pass >>> @staticmethod >>> def IncEval(frag, context): >>> pass """return__PlaceHolder(declare)