graph = Graph()
connection = DriverRemoteConnection(
gremlin_endpoint, "g",
username=gremlin_username,
password=gremlin_password
)
g = graph.traversal().withRemote(connection)
def upload_node(row):
try:
# Extract values as strings to ensure scalar access
label = row['label'] if 'label' in row and pd.notnull(row['label']) else None
node_id = row['id'] if 'id' in row and pd.notnull(row['id']) else None
partition_key = row['Key'] if 'Key' in row and pd.notnull(row['Key']) else None
print(label, node_id, partition_key)
# Check for missing mandatory fields
if not label or not node_id or not partition_key:
print(f"Skipping row with missing values: label={label}, id={node_id}, Key={partition_key}")
return
# Create Gremlin vertex
g.addV(str(label)).property('id', str(node_id)).property('PartitionKey', str(partition_key)).next()
print(f"Node {node_id} uploaded successfully.")
except Exception as e:
print(f"Error uploading node {node_id if 'node_id' in locals() else 'unknown'}: {e}")
try:
print("Starting node upload...")
for _, row in df_client_pand100.iterrows(): # Iterate over rows
upload_node(row)
except Exception as e:
print(f"Unexpected error: {e}")
finally:
connection.close()
print("Node upload process complete.")
OUTPUT:
Starting node upload...
Client CL_182591 79
Error uploading node CL_182591: Connection was closed by server.
Node upload process complete.