Commit afa0b0ba authored by Wei Shoulin's avatar Wei Shoulin
Browse files

retrieve catalog columns

parent 5c73b401
Pipeline #2869 passed with stage
...@@ -8,10 +8,9 @@ from collections.abc import Iterable ...@@ -8,10 +8,9 @@ from collections.abc import Iterable
from csst_dfs_commons.models import Result from csst_dfs_commons.models import Result
from csst_dfs_commons.models.common import from_proto_model_list from csst_dfs_commons.models.common import from_proto_model_list
from csst_dfs_commons.models.level2 import Level2Record from csst_dfs_commons.models.level2 import Level2Record, filter_table_name
from csst_dfs_commons.models.constants import UPLOAD_CHUNK_SIZE from csst_dfs_commons.models.constants import UPLOAD_CHUNK_SIZE
from csst_dfs_proto.facility.level2 import level2_pb2, level2_pb2_grpc from csst_dfs_proto.facility.level2 import level2_pb2, level2_pb2_grpc
from ..common.service import ServiceProxy from ..common.service import ServiceProxy
from ..common.utils import * from ..common.utils import *
...@@ -66,6 +65,24 @@ class Level2DataApi(object): ...@@ -66,6 +65,24 @@ class Level2DataApi(object):
except grpc.RpcError as e: except grpc.RpcError as e:
return Result.error(message="%s:%s" % (e.code().value, e.details())) return Result.error(message="%s:%s" % (e.code().value, e.details()))
def catalog_columns(self, **kwargs):
''' retrieve columns data type
:param kwargs: Parameter dictionary, key items support:
data_type: [str]
columns: [list], list of str
'''
data_type = get_parameter(kwargs, "data_type", "")
columns = get_parameter(kwargs, "columns", [])
if type(columns) != list:
columns = [columns]
resp = self.catalog_query(sql=f"describe {filter_table_name(data_type)}")
if resp.success:
resp['data'] = [(rec[0], rec[1]) for rec in resp.data if rec[0].lower() in [col.lower() for col in columns] or len(columns) == 0]
resp['columns'] = ['Field', 'Type']
resp['totalCount'] = len(resp['data'])
return resp
def catalog_query(self, **kwargs): def catalog_query(self, **kwargs):
''' retrieve level2catalog records from database ''' retrieve level2catalog records from database
......
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