def p_vertex(p): ''' vertex : '(' tag_list ')' | '(' STRING tag_list ')' ''' vid = None tags = None if len(p) == 4: tags = p[2] else: vid = p[2].get_sVal() tags = p[3] v = Vertex(vid=vid, tags=tags) p[0] = Value(vVal=v)
def as_node(self): """convert the vertex data to structure Node :return: Node """ if len(self._row.values) < self.PROP_START_INDEX: raise RuntimeError('The row value is bad format, ' 'as node failed: len is {}' .format(len(self._row.values))) vertex = Vertex() vertex.tags = [] vertex.vid = self._row.values[0] tag = Tag() tag.name = self._tag_name tag.props = {} index = self.PROP_START_INDEX while index < len(self._col_names): tag.props[self._col_names[index]] = self._row.values[index] index = index + 1 vertex.tags.append(tag) return Node(vertex).set_decode_type(self._decode_type)
def gen_vertex(cls, vid, tags): vertex = Vertex() vertex.vid = vid vertex.tags = tags return vertex
expected['"string"'] = Value(sVal='string') expected['''"string'string'"'''] = Value(sVal="string'string'") expected['[]'] = Value(lVal=List([])) expected['[1,2,3]'] = Value( lVal=List([Value(iVal=1), Value( iVal=2), Value(iVal=3)])) expected['{1,2,3}'] = Value( uVal=Set(set([Value( iVal=1), Value( iVal=2), Value(iVal=3)]))) expected['{}'] = Value(mVal=Map({})) expected['{k1:1,"k2":true}'] = Value(mVal=Map({ 'k1': Value(iVal=1), 'k2': Value(bVal=True) })) expected['()'] = Value(vVal=Vertex()) expected['("vid")'] = Value(vVal=Vertex(vid='vid')) expected['("vid":t)'] = Value(vVal=Vertex(vid='vid', tags=[Tag(name='t')])) expected['("vid":t:t)'] = Value( vVal=Vertex(vid='vid', tags=[Tag( name='t'), Tag(name='t')])) expected['("vid":t{p1:0,p2:" "})'] = Value(vVal=Vertex(vid='vid',\ tags=[Tag(name='t',props={'p1':Value(iVal=0),'p2':Value(sVal=' ')})])) expected['("vid":t1{p1:0,p2:" "}:t2{})'] = Value(vVal=Vertex(vid='vid',\ tags=[Tag(name='t1',props={'p1':Value(iVal=0),'p2':Value(sVal=' ')}),\ Tag(name='t2',props={})])) expected['-->'] = Value(eVal=Edge(type=1)) expected['<--'] = Value(eVal=Edge(type=-1)) expected['-[]->'] = Value(eVal=Edge(type=1)) expected['<-[]-'] = Value(eVal=Edge(type=-1)) expected['-[:e]->'] = Value(eVal=Edge(name='e', type=1))
Value(iVal=1), Value(iVal=2), Value(iVal=3), ])) expected['{1,2,3}'] = Value( uVal=NSet(set([ Value(iVal=1), Value(iVal=2), Value(iVal=3), ]))) expected['{}'] = Value(mVal=NMap({})) expected['{k1:1,"k2":true}'] = Value(mVal=NMap({ 'k1': Value(iVal=1), 'k2': Value(bVal=True) })) expected['()'] = Value(vVal=Vertex()) expected['("vid")'] = Value(vVal=Vertex(vid='vid')) expected['(123)'] = Value(vVal=Vertex(vid=123)) expected['(-123)'] = Value(vVal=Vertex(vid=-123)) expected['(hash("vid"))'] = Value(vVal=Vertex(vid=murmurhash2('vid'))) expected['("vid":t)'] = Value(vVal=Vertex(vid='vid', tags=[Tag(name='t')])) expected['("vid":t:t)'] = Value( vVal=Vertex(vid='vid', tags=[ Tag(name='t'), Tag(name='t'), ])) expected['("vid":t{p1:0,p2:" "})'] = Value(vVal=Vertex( vid='vid', tags=[ Tag(name='t', props={ 'p1': Value(iVal=0),
for cell in row: v = nbv.parse(cell) if v is None: raise Exception('Unable to parse %s' % cell) list.append(v) return Row(list) if __name__ == '__main__': headings = ['m', 'r', 'n'] rows = [ ['1', '2', '3'], ['()', '-->', '()'], ['("vid")', '<-[:e "1" -> "2" @-1 {p1: 0, p2: [1, 2, 3]}]-', '()'], ['<()-->()<--()>', '()', '"prop"'], ['EMPTY', 'NULL', 'BAD_TYPE'], ] expected = DataSet(column_names = headings,\ rows = [ Row([Value(iVal=1), Value(iVal=2), Value(iVal=3)]), Row([Value(vVal=Vertex()), Value(eVal=Edge(type=1)), Value(vVal=Vertex())]), Row([Value(vVal=Vertex('vid')), Value(eVal=Edge(name='e',type=-1,src='1',dst='2',ranking=-1,props={'p1': Value(iVal=0), 'p2': Value(lVal=List([Value(iVal=1),Value(iVal=2),Value(iVal=3)]))})), Value(vVal=Vertex())]), Row([Value(pVal=Path(src=Vertex(),steps=[Step(type=1,dst=Vertex()),Step(type=-1,dst=Vertex())])), Value(vVal=Vertex()), Value(sVal='prop')]), Row([Value(), Value(nVal=NullType.__NULL__), Value(nVal=NullType.BAD_TYPE)]) ]) table = bh.Table(headings=headings, rows=rows) dataset = parse(table) assert dataset == expected,\ "Parsed DataSet doesn't match, \nexpected: %s, \nactual: %s" % (expected, dataset)