Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
csst-dfs
csst-dfs-api-cluster
Commits
afa0b0ba
Commit
afa0b0ba
authored
Dec 29, 2023
by
Wei Shoulin
Browse files
retrieve catalog columns
parent
5c73b401
Pipeline
#2869
passed with stage
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
csst_dfs_api_cluster/facility/level2.py
View file @
afa0b0ba
...
@@ -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
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment