Query Client
This is a simple client to query.
example
初始化客户端及元数据
from query_client import QueryClient qc = QueryClient() tables = qc.get_meta() # print(tables) 获取全部可查表,及其coloumns, 元数据 ## 目前只有两个相关表注册 can_table = tables["can_detail"] pcd_table = tables["pcd_label_desc"]
fetch
python
from sqlalchemy.sql.expression import select, text, and_
from query_client import QueryClient
import pandas as pd
qc = QueryClient()
tables = qc.get_meta()
mytable = tables["pcd_label_desc"]
# 1. fetch_by_stmt 初始化 statement, select/where/group_by
stmt = select(mytable.c.dataset, mytable.c.batch_path, text("array_distinct(categories) scenes"), text("cardinality(filter(categories, x -> x IN ('car'))) as target_cnt"))
r = qc.fetch_by_stmt(stmt)
df = pd.DataFrame(r)
# 2. fetch_by_sql
query = "select * from pcd_label_desc limit 10"
r = qc.fetch_by_sql(query)
df = pd.DataFrame(r)
具体示例
- 城区场景的筛选
- 定义单帧指标(各种目标数)
- group by 序列
- fetch_by_sql 实现方式
- cte 语法:
- t 表查询单帧的去重场景、不同类型的目标数指标,dataset 及batch 维度
- 利用 t 表的dataset, batch_path 维度聚合指标
- code example
query = """ WITH t AS ( SELECT dataset, batch_path, array_distinct(categories) scenes, cardinality( filter( categories, x -> x IN ( 'car', 'van', 'truck', 'mini_truck', 'special_truck', 'truck', 'cyclist', 'bicycle', 'pedestrian' ) ) ) AS target_cnt, cardinality( filter( categories, x -> x IN ( 'truck', 'mini_truck', 'special_truck' ) ) ) truck_cnt, cardinality(filter(categories, x -> x IN ('car', 'van'))) carvan_cnt, cardinality(filter(categories, x -> x = 'pedestrian')) pedestrian_cnt, cardinality( filter(categories, x -> x IN ('cyclist', 'bicycle')) ) cyclist_cnt FROM pcd_label_desc WHERE delivery_date = '20230310' AND any_match( road_condition, x -> x = 'highway_road' ) ) SELECT dataset, batch_path, array_distinct(FLATTEN(ARRAY_AGG(scenes))) scenes, SUM(target_cnt) target_cnt, SUM(carvan_cnt) carvan_cnt, SUM(pedestrian_cnt) pedestrian_cnt, SUM(truck_cnt) truck_cnt, SUM(cyclist_cnt) cyclist_cnt FROM t GROUP BY 1, 2 ORDER BY target_cnt DESC """ r = qc.fetch_by_sql(query) df = pd.DataFrame(r)
- cte 语法:
- fetch_by_stmt 实现方式
mytable = tables["pcd_label_desc"] stmt = select( mytable.c.dataset, mytable.c.batch_path, # 指定table聚合的维度 text("cardinality(filter(categories, x -> x IN ('car', 'van'))) carvan_cnt"), # 定义函数变换指标 # ... goon ) .where(and_( mytable.c.delivery_date == "20230310", text("any_match(road_condition, x -> x = 'city_road')") # 过滤城区场景 )) # 指标cte 表 cte = qc.with_cte(stmt) # 继续聚合 stmt2 = select( cte.c.dataset, cte.c.batch_path, text("SUM(carvan_cnt) carvan_cnt") ).group_by(cte.c.dataset, cte.c.batch_path) # 查询结果 r = qc.fetch_by_stmt(stmt2) df = pd.DataFrame(r)
Metadata
Release files for query-client 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| query_client-0.0.1.tar.gz | 4.1 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| query_client-0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.6 kB
Release files / query_client-0.0.1.tar.gz
| Download URL | query_client-0.0.1.tar.gz |
|---|---|
| Size | 4.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6ce95267438135c0b9beb432d6edf9048cd438bfc7fc43593a4e5101f8e1976e
|
|
BLAKE2b-256 checksum How to use checksums |
649a67799e79775e66eae44842696ca8c76e79004df258938ed36e47df7203b3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.8.10
|
Release files / query_client-0.0.1-py3-none-any.whl
| Download URL | query_client-0.0.1-py3-none-any.whl |
|---|---|
| Size | 4.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
40fba790a25f607f771e106b4cd8217514bc5b437c1335d2ad454c35cef04598
|
|
BLAKE2b-256 checksum How to use checksums |
b95c96233baf16fb013d409525c9f2a422d283dc80f614f5bac17a667226e3d3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.8.10
|
Security for query-client 0.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.