如何解决gremlin id列提取-GLUE
我正在尝试将Neptune数据库顶点提取到CSV文件中,这在id列提取失败。下面是我尝试在AWS GLUE控制台中运行的脚本。
import boto3
import os
import sys
import site
import json
import pandas as pd
from setuptools.command import easy_install
from importlib import reload
s3 = boto3.client('s3')
dir_path = os.path.dirname(os.path.realpath(__file__))
#os.path.dirname(sys.modules['__main__'].__file__)
install_path = os.environ['GLUE_INSTALLATION']
easy_install.main( ["--install-dir",install_path,"gremlinpython"] )
reload(site)
from gremlin_python import statics
from gremlin_python.structure.graph import Graph
from gremlin_python.process.graph_traversal import __
from gremlin_python.process.strategies import *
from gremlin_python.process.traversal import T
from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection
graph = Graph()
remoteConn = DriverRemoteConnection('wss://neptune-test-new-reader-1.c3nqs7vjaggx.eu-west-1.neptune.amazonaws.com:8182/gremlin','g')
g = graph.traversal().withRemote(remoteConn)
vertices_columns = ['id','label','region','country']
vertices = g.V().hasLabel('airport').limit(2).project('id','country').by('T.id').by('T.label').by('region').by('country').select(values).fold()
for v in vertices:
print(v)
错误: 名称“值”未定义
在以下脚本中尝试了for循环
import boto3
import os
import sys
import site
import json
import pandas as pd
from setuptools.command import easy_install
from importlib import reload
s3 = boto3.client('s3')
dir_path = os.path.dirname(os.path.realpath(__file__))
#os.path.dirname(sys.modules['__main__'].__file__)
install_path = os.environ['GLUE_INSTALLATION']
easy_install.main( ["--install-dir",'country']
"""
vertices = g.V().hasLabel('airport').limit(2).project('id','country').by('T.id').by('T.label').by('region').by('country').select(values).fold()
for v in vertices:
print(v)
"""
#vertices = []
vertices = g.V().limit(1).valueMap(True).toList()
for v in vertices:
print(v)
for col in vertices_columns:
print(v[col])
#print(vertices)
错误:
打印输出(v) {T.id:1:'1',T.label:1:'airport','country':'US','region':'US-AL'} 关键错误:id
解决方法
values
中使用的select(values)
关键字是对定义为Column
一部分的枚举的引用。在代码中,您可以使用select(Column.values)
,并可以使用:
from gremlin_python.process.traversal import Column
这是一个Python示例:
>>> g.V('3').project('id','label','code').by(T.id).by(T.label).by('code').toList()
[{'id': '3','label': 'airport','code': 'AUS'}]
>>> g.V('3').project('id','code').by(T.id).by(T.label).by('code').select(Column.values).toList()
[['3','airport','AUS']]
请注意,T.id
和T.label
在引号内不是。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。