Commit 0f2d363b authored by Wei Shoulin's avatar Wei Shoulin
Browse files

data to dict

parent 5c53ab5c
...@@ -121,7 +121,8 @@ def find_req(function, kwargs): ...@@ -121,7 +121,8 @@ def find_req(function, kwargs):
else: else:
columns.append(col) columns.append(col)
return Result.ok_data(data = records).append("totalCount", totalCount)\ data = Record.from_list(records, columns)
return Result.ok_data(data = data).append("totalCount", totalCount)\
.append("columns", columns) .append("columns", columns)
except grpc.RpcError as e: except grpc.RpcError as e:
...@@ -137,9 +138,18 @@ def get_req(function, kwargs): ...@@ -137,9 +138,18 @@ def get_req(function, kwargs):
) )
if resp.record: if resp.record:
record = pickle.loads(resp.record) record = pickle.loads(resp.record)
cols = resp.columns
columns = []
for col in cols:
if col in columns:
columns.append("%s_1" % (col, ))
else:
columns.append(col)
if record: if record:
data = Record.from_tuple(record, resp.columns) data = Record.from_tuple(record, columns)
return Result.ok_data(data=data).append("columns", resp.columns) return Result.ok_data(data=data)
else: else:
return Result.error(message=f"not found") return Result.error(message=f"not found")
else: else:
...@@ -173,7 +183,16 @@ def write_req(function, kwargs): ...@@ -173,7 +183,16 @@ def write_req(function, kwargs):
if resp.success: if resp.success:
if resp.record: if resp.record:
record = pickle.loads(resp.record) record = pickle.loads(resp.record)
return Result.ok_data(data=record).append("columns", resp.columns) cols = resp.columns
columns = []
for col in cols:
if col in columns:
columns.append("%s_1" % (col, ))
else:
columns.append(col)
if record:
data = Record.from_tuple(record, columns)
return Result.ok_data(data=data)
else: else:
return Result.error(message = str(resp.error.detail)) return Result.error(message = str(resp.error.detail))
except grpc.RpcError as e: except grpc.RpcError as e:
...@@ -197,7 +216,16 @@ def write_stream_req(function, byte_stream, kwargs): ...@@ -197,7 +216,16 @@ def write_stream_req(function, byte_stream, kwargs):
if resp.success: if resp.success:
if resp.record: if resp.record:
record = pickle.loads(resp.record) record = pickle.loads(resp.record)
return Result.ok_data(data=record).append("columns", resp.columns) cols = resp.columns
columns = []
for col in cols:
if col in columns:
columns.append("%s_1" % (col, ))
else:
columns.append(col)
if record:
data = Record.from_tuple(record, columns)
return Result.ok_data(data=data)
else: else:
return Result.error(message = str(resp.error.detail)) return Result.error(message = str(resp.error.detail))
except grpc.RpcError as e: except grpc.RpcError as e:
......
...@@ -10,8 +10,6 @@ class Level0DataApi(object): ...@@ -10,8 +10,6 @@ class Level0DataApi(object):
@grpc_channel @grpc_channel
def find(self, **kwargs): def find(self, **kwargs):
result = find_req("Level0Servicer.Find", kwargs) result = find_req("Level0Servicer.Find", kwargs)
data = Record.from_list(result["data"], result["columns"])
result["data"] = data
return result return result
@grpc_channel @grpc_channel
def get(self, **kwargs): def get(self, **kwargs):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment