1111
1212interface = InterfaceName .GET .value
1313
14-
1514def getGetRequestBody (data , options : GetOptions ):
15+ requestBody = {}
1616 ids = None
1717 if "ids" in data :
1818 ids = data ["ids" ]
@@ -25,25 +25,28 @@ def getGetRequestBody(data, options: GetOptions):
2525 idType = str (type (id ))
2626 raise SkyflowError (SkyflowErrorCodes .INVALID_INPUT , SkyflowErrorMessages .INVALID_ID_TYPE .value % (
2727 idType ), interface = interface )
28+ requestBody ["skyflow_ids" ] = ids
2829 try :
2930 table = data ["table" ]
3031 except KeyError :
3132 raise SkyflowError (SkyflowErrorCodes .INVALID_INPUT ,
3233 SkyflowErrorMessages .TABLE_KEY_ERROR , interface = interface )
3334 if not isinstance (table , str ):
3435 tableType = str (type (table ))
35-
3636 raise SkyflowError (SkyflowErrorCodes .INVALID_INPUT , SkyflowErrorMessages .INVALID_TABLE_TYPE .value % (
3737 tableType ), interface = interface )
38+ else :
39+ requestBody ["tableName" ] = table
3840
39- if options .tokens and data .get ("redaction" ):
40- raise SkyflowError (SkyflowErrorCodes .INVALID_INPUT ,
41- SkyflowErrorMessages .REDACTION_WITH_TOKENS_NOT_SUPPORTED , interface = interface )
42- if options .tokens and (data .get ('columnName' ) or data .get ('columnValues' )):
43- raise SkyflowError (SkyflowErrorCodes .TOKENS_GET_COLUMN_NOT_SUPPORTED ,
41+ if options .tokens :
42+ if data .get ("redaction" ):
43+ raise SkyflowError (SkyflowErrorCodes .INVALID_INPUT ,
44+ SkyflowErrorMessages .REDACTION_WITH_TOKENS_NOT_SUPPORTED , interface = interface )
45+ if (data .get ('columnName' ) or data .get ('columnValues' )):
46+ raise SkyflowError (SkyflowErrorCodes .TOKENS_GET_COLUMN_NOT_SUPPORTED ,
4447 SkyflowErrorMessages .TOKENS_GET_COLUMN_NOT_SUPPORTED , interface = interface )
45-
46- if not options . tokens :
48+ requestBody [ "tokenization" ] = options . tokens
49+ else :
4750 try :
4851 redaction = data ["redaction" ]
4952 except KeyError :
@@ -53,6 +56,8 @@ def getGetRequestBody(data, options: GetOptions):
5356 redactionType = str (type (redaction ))
5457 raise SkyflowError (SkyflowErrorCodes .INVALID_INPUT , SkyflowErrorMessages .INVALID_REDACTION_TYPE .value % (
5558 redactionType ), interface = interface )
59+ else :
60+ requestBody ["redaction" ] = redaction .value
5661
5762 columnName = None
5863 if "columnName" in data :
@@ -69,13 +74,17 @@ def getGetRequestBody(data, options: GetOptions):
6974 columnValuesType = str (type (columnValues ))
7075 raise SkyflowError (SkyflowErrorCodes .INVALID_INPUT , SkyflowErrorMessages .INVALID_COLUMN_VALUE .value % (
7176 columnValuesType ), interface = interface )
77+ else :
78+ requestBody ["column_name" ] = columnName
79+ requestBody ["column_values" ] = columnValues
7280
7381 if (ids is None and (columnName is None or columnValues is None )):
7482 raise SkyflowError (SkyflowErrorCodes .INVALID_INPUT ,
75- SkyflowErrorMessages .UNIQUE_COLUMN_OR_IDS_KEY_ERROR .value , interface = interface )
76- return ids , table , redaction .value , columnName , columnValues
77- return ids , table , "DEFAULT" , None , None
78-
83+ SkyflowErrorMessages .UNIQUE_COLUMN_OR_IDS_KEY_ERROR , interface = interface )
84+ elif (ids != None and (columnName != None or columnValues != None )):
85+ raise SkyflowError (SkyflowErrorCodes .INVALID_INPUT ,
86+ SkyflowErrorMessages .BOTH_IDS_AND_COLUMN_DETAILS_SPECIFIED , interface = interface )
87+ return requestBody
7988
8089async def sendGetRequests (data , options : GetOptions , url , token ):
8190 tasks = []
@@ -97,27 +106,22 @@ async def sendGetRequests(data, options: GetOptions, url, token):
97106
98107 validatedRecords = []
99108 for record in records :
100- ids , table , redaction , columnName , columnValues = getGetRequestBody (record , options )
101- validatedRecords .append (( ids , table , redaction , columnName , columnValues ) )
109+ requestBody = getGetRequestBody (record , options )
110+ validatedRecords .append (requestBody )
102111 async with ClientSession () as session :
103112 for record in validatedRecords :
104- ids , table , redaction , columnName , columnValues = record
105113 headers = {
106114 "Authorization" : "Bearer " + token ,
107115 "sky-metadata" : json .dumps (getMetrics ())
108116 }
109- params = {"redaction" : redaction }
110-
111- if ids is not None :
112- params ["skyflow_ids" ] = ids
113- if columnName is not None :
114- params ["column_name" ] = columnName
115- params ["column_values" ] = columnValues
117+ table = record .pop ("tableName" )
118+ params = record
119+ if options .tokens :
120+ params ["tokenization" ] = json .dumps (record ["tokenization" ])
116121 task = asyncio .ensure_future (
117- get (url , headers , params , session , record [ 1 ], options . tokens )
122+ get (url , headers , params , session , table )
118123 )
119124 tasks .append (task )
120125 await asyncio .gather (* tasks )
121126 await session .close ()
122-
123127 return tasks
0 commit comments