I have been facing an issue while passing the list/set from my python code to tigergraph GSQL query

Hi,

Here is the code

Code ::

alerts_list=[‘28000.0’,‘29000.0’]
#alerts_list=(‘28000.0’,‘29000.0’)
code = “”"INTERPRET QUERY (SET State_ID, STRING New_Status, STRING Reason_L1) FOR GRAPH TX_CRD {

start = {Alert.*};

result =
        SELECT src
        FROM start:src
        WHERE src.State_ID IN State_ID
        POST-ACCUM src.Alert_Status = New_Status,
        //POST-ACCUM src.Reason_Status_L1 = Reason_L1
        src.Reason_Status_L1 = src.Reason_Status_L1 + "|" + Reason_L1;

}""",
params={“State_ID”: alerts_list}

res = conn.runInterpretedQuery(code, {“New_Status”: “actions”,“Reason_L1”: “rationale”})

#res = conn.runInterpretedQuery(code, {“State_ID”: alerts_list,“New_Status”: “Escalated”,“Reason_L1”: “rationale”})

Error ::


AttributeError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_15664/3472283601.py in
17
18
—> 19 res = conn.runInterpretedQuery(code, {“New_Status”: “actions”,“Reason_L1”: “rationale”})
20
21 #conn.vertexSetToDataFrame(res[0][“mac”])

~\Anaconda3\lib\site-packages\pyTigerGraph\pyTigerGraph.py in runInterpretedQuery(self, queryText, params)
1192 Documentation: Built-in Endpoints :: TigerGraph Server
1193 “”"
→ 1194 queryText = queryText.replace("$graphname", self.graphname)
1195 return self._post(self.gsUrl + “/gsqlserver/interpreted_query”, data=queryText, params=params, authMode=“pwd”)
1196

AttributeError: ‘tuple’ object has no attribute ‘replace’

Looking for the solution on the same,Thanks in advance!

Hey! Welcome to the community!

Looking through your code, it looks like the issue is that you did not specify a type for your set. Try this out; it should run without error:

alerts_list = ['28000.0', '29000.0']

conn.runInterpretedQuery('''

INTERPRET QUERY (SET<STRING> State_ID) FOR GRAPH MyGraph {
  PRINT State_ID;
}

''', params = {"State_ID": alerts_list})

When running the above code, you should be able to pass and print the parameter without problem; from there, you can add the rest of your query. I’d recommend checking out the Data Types TigerGraph documentation for more details! Also, if you use the query editor in GraphStudio, it can help catch the syntax errors.

Feel free to reach out if you have any other TigerGraph or GSQL questions!

1 Like