def fn_call(self, request, context): response = function_service_pb2.PFunctionCallResponse() status = types_pb2.PStatus() status.status_code = 0 response.status.CopyFrom(status) if request.function_name == "add_int": result = types_pb2.PValues() result.has_null = False result_type = types_pb2.PGenericType() result_type.id = types_pb2.PGenericType.INT32 result.type.CopyFrom(result_type) result.int32_value.extend([x + y for x, y in zip(request.args[0].int32_value, request.args[1].int32_value)]) response.result.append(result) return response
def check_fn(self, request, context): response = function_service_pb2.PCheckFunctionResponse() status = types_pb2.PStatus() status.status_code = 0 response.status.CopyFrom(status) return response
def fn_call(self, request, context): response = function_service_pb2.PFunctionCallResponse() status = types_pb2.PStatus() status.status_code = 0 response.status.CopyFrom(status) if request.function_name == "rpc_sum_update": result = types_pb2.PValues() result.has_null = False result_type = types_pb2.PGenericType() result_type.id = types_pb2.PGenericType.INT64 result.type.CopyFrom(result_type) total=0 size= len(request.args[0].int64_value) for i in range(size): total += request.args[0].int64_value[i] if request.HasField("context"): total += request.context.function_context.args_data[0].int64_value[0] result.int64_value.append(total) response.result.append(result) if request.function_name == "rpc_sum_merge": result = types_pb2.PValues() result.has_null = False result_type = types_pb2.PGenericType() result_type.id = types_pb2.PGenericType.INT64 result.type.CopyFrom(result_type) args_len = len(request.args) total = 0 for i in range(args_len): total += request.args[i].int64_value[0] result.int64_value.append(total) response.result.append(result) if request.function_name == "rpc_sum_finalize": result = types_pb2.PValues() result.has_null = False result_type = types_pb2.PGenericType() result_type.id = types_pb2.PGenericType.INT64 result.type.CopyFrom(result_type) total = request.context.function_context.args_data[0].int64_value[0] result.int64_value.append(total) response.result.append(result) if request.function_name == "rpc_avg_update": result = types_pb2.PValues() result.has_null = False result_type = types_pb2.PGenericType() result_type.id = types_pb2.PGenericType.DOUBLE result.type.CopyFrom(result_type) total = 0 size = len(request.args[0].int32_value) for i in range(size): total += request.args[0].int32_value[i] if request.HasField("context"): total += request.context.function_context.args_data[0].double_value[0] size += request.context.function_context.args_data[0].int32_value[0] result.double_value.append(total) result.int32_value.append(size) response.result.append(result) if request.function_name == "rpc_avg_merge": result = types_pb2.PValues() result.has_null = False result_type = types_pb2.PGenericType() result_type.id = types_pb2.PGenericType.DOUBLE result.type.CopyFrom(result_type) total = 0 size = 0 args_len = len(request.args) for i in range(args_len): total += request.args[i].double_value[0] size += request.args[i].int32_value[0] result.double_value.append(total) result.int32_value.append(size) response.result.append(result) if request.function_name == "rpc_avg_finalize": result = types_pb2.PValues() result.has_null = False result_type = types_pb2.PGenericType() result_type.id = types_pb2.PGenericType.DOUBLE result.type.CopyFrom(result_type) total = request.context.function_context.args_data[0].double_value[0] size = request.context.function_context.args_data[0].int32_value[0] avg = total / size result.double_value.append(avg) response.result.append(result) if request.function_name == "rpc_count_visit_info_update": result = types_pb2.PValues() result.has_null = False result_type = types_pb2.PGenericType() result_type.id = types_pb2.PGenericType.STRING result.type.CopyFrom(result_type) size = len(request.args[0].string_value) currentMap=dict() if request.HasField("context"): context = request.context.function_context.args_data[0].string_value[0] currentMap = json.loads(context) for i in range(size): s = request.args[0].string_value[i] mapInfo = json.loads(s) ip=mapInfo['ip'] if currentMap.has_key(ip): last_val=currentMap[ip] last_val+=1 currentMap[ip] = last_val else: currentMap[ip] = 1 json_dict = json.dumps(currentMap) result.string_value.append(json_dict) response.result.append(result) if request.function_name == "rpc_count_visit_info_merge": result = types_pb2.PValues() result.has_null = False result_type = types_pb2.PGenericType() result_type.id = types_pb2.PGenericType.STRING result.type.CopyFrom(result_type) context1 = request.args[0].string_value[0] currentMap1 = json.loads(context1) context2 = request.args[1].string_value[0] currentMap2 = json.loads(context2) for ip,num in currentMap2.items(): if currentMap1.has_key(ip): currentMap1[ip] = currentMap1[ip] + num else: currentMap1[ip] = num json_dict = json.dumps(currentMap1) result.string_value.append(json_dict) response.result.append(result) if request.function_name == "rpc_count_visit_info_finalize": result = types_pb2.PValues() result.has_null = False result_type = types_pb2.PGenericType() result_type.id = types_pb2.PGenericType.STRING result.type.CopyFrom(result_type) context = request.context.function_context.args_data[0].string_value[0] currentMap = json.loads(context) sortedMap=sorted(currentMap.items(), key = lambda kv:(kv[1], kv[0]),reverse=True) resultMap=dict() topN=3 if len(sortedMap) < topN: topN = len(sortedMap) finalResult="" print(sortedMap) for i in range(topN): ip=sortedMap[i][0] finalResult +=ip +":"+str(sortedMap[i][1]) +" " result.string_value.append(finalResult) response.result.append(result) return response
def fn_call(self, request, context): response = function_service_pb2.PFunctionCallResponse() status = types_pb2.PStatus() status.status_code = 0 response.status.CopyFrom(status) if request.function_name == "rpc_sum_update": result = types_pb2.PValues() result.has_null = False result_type = types_pb2.PGenericType() result_type.id = types_pb2.PGenericType.INT64 result.type.CopyFrom(result_type) total = 0 size = len(request.args[0].int64_value) for i in range(size): total += request.args[0].int64_value[i] if request.HasField("context"): total += request.context.function_context.args_data[ 0].int64_value[0] result.int64_value.append(total) response.result.append(result) if request.function_name == "rpc_sum_merge": result = types_pb2.PValues() result.has_null = False result_type = types_pb2.PGenericType() result_type.id = types_pb2.PGenericType.INT64 result.type.CopyFrom(result_type) args_len = len(request.args) total = 0 for i in range(args_len): total += request.args[i].int64_value[0] result.int64_value.append(total) response.result.append(result) if request.function_name == "rpc_sum_finalize": result = types_pb2.PValues() result.has_null = False result_type = types_pb2.PGenericType() result_type.id = types_pb2.PGenericType.INT64 result.type.CopyFrom(result_type) total = request.context.function_context.args_data[0].int64_value[ 0] result.int64_value.append(total) response.result.append(result) if request.function_name == "rpc_avg_update": result = types_pb2.PValues() result.has_null = False result_type = types_pb2.PGenericType() result_type.id = types_pb2.PGenericType.DOUBLE result.type.CopyFrom(result_type) total = 0 size = len(request.args[0].int32_value) for i in range(size): total += request.args[0].int32_value[i] if request.HasField("context"): total += request.context.function_context.args_data[ 0].double_value[0] size += request.context.function_context.args_data[ 0].int32_value[0] result.double_value.append(total) result.int32_value.append(size) response.result.append(result) if request.function_name == "rpc_avg_merge": result = types_pb2.PValues() result.has_null = False result_type = types_pb2.PGenericType() result_type.id = types_pb2.PGenericType.DOUBLE result.type.CopyFrom(result_type) total = 0 size = 0 args_len = len(request.args) for i in range(args_len): total += request.args[i].double_value[0] size += request.args[i].int32_value[0] result.add_double.append(total) result.add_int32.append(size) response.result.append(result) if request.function_name == "rpc_avg_finalize": result = types_pb2.PValues() result.has_null = False result_type = types_pb2.PGenericType() result_type.id = types_pb2.PGenericType.DOUBLE result.type.CopyFrom(result_type) total = request.context.function_context.args_data[0].double_value[ 0] size = request.context.function_context.args_data[0].int32_value[0] avg = total / size result.double_value.append(avg) response.result.append(result) return response