Skip to content

Conversation

@zy-kkk
Copy link
Member

@zy-kkk zy-kkk commented May 8, 2024

Proposed changes

Issue Number: close #xxx

This PR supports a Table Value Function called Query. He can push a query directly to the catalog source for execution by specifying catalog and query without parsing by Doris. Doris only receives the results returned by the query.
Currently only JDBC Catalog is supported.

Example:

Doris > desc function query('catalog' = 'mysql','query' = 'select count(*) as cnt from test.test');           
+-------+--------+------+------+---------+-------+
| Field | Type   | Null | Key  | Default | Extra |
+-------+--------+------+------+---------+-------+
| cnt   | BIGINT | Yes  | true | NULL    | NONE  |
+-------+--------+------+------+---------+-------+

Doris > select * from query('catalog' = 'mysql','query' = 'select count(*) as cnt from test.test');           
+----------+
| cnt      |
+----------+
| 30000000 |
+----------+

Further comments

If this is a relatively large or complex change, kick off the discussion at dev@doris.apache.org by explaining why you chose the solution you did and what alternatives you considered, etc...

@doris-robot
Copy link

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR

Since 2024-03-18, the Document has been moved to doris-website.
See Doris Document.

@zy-kkk
Copy link
Member Author

zy-kkk commented May 8, 2024

run buildall

@zy-kkk zy-kkk marked this pull request as ready for review May 8, 2024 08:42
@zy-kkk
Copy link
Member Author

zy-kkk commented May 8, 2024

run buildall

@zy-kkk
Copy link
Member Author

zy-kkk commented May 8, 2024

run buildall

if (catalogIf instanceof JdbcExternalCatalog) {
return new JdbcQueryTableValueFunction(params);
} else {
throw new AnalysisException("Unsupported catalog type in query tvf: " + catalogName);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

print "type" as well

this.catalogIf = Env.getCurrentEnv().getCatalogMgr().getCatalog(catalogName);
}

public static QueryTableValueFunction createQueryTableValueFunction(Map<String, String> params)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing authorization check.
I think user need catalog level SELECT priv to exeute this tvf

@zy-kkk
Copy link
Member Author

zy-kkk commented May 8, 2024

run buildall

1 similar comment
@zy-kkk
Copy link
Member Author

zy-kkk commented May 9, 2024

run buildall

@doris-robot
Copy link

TPC-H: Total hot run time: 41548 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit 541cf185b31eade46e5e716c36d2ded08267dc13, data reload: false

------ Round 1 ----------------------------------
q1	17596	4284	4195	4195
q2	2007	183	187	183
q3	10467	1137	1209	1137
q4	10198	886	745	745
q5	7481	2745	2689	2689
q6	223	129	130	129
q7	1029	611	590	590
q8	9234	2142	2099	2099
q9	9072	6743	6716	6716
q10	8993	3874	3823	3823
q11	482	248	243	243
q12	419	228	228	228
q13	17372	3289	3158	3158
q14	273	231	219	219
q15	519	466	497	466
q16	536	406	400	400
q17	988	711	687	687
q18	8345	7733	7693	7693
q19	2560	1529	1540	1529
q20	643	329	321	321
q21	5155	4018	4447	4018
q22	359	288	280	280
Total cold run time: 113951 ms
Total hot run time: 41548 ms

----- Round 2, with runtime_filter_mode=off -----
q1	4481	4387	4367	4367
q2	380	279	287	279
q3	3144	2992	2846	2846
q4	1992	1641	1618	1618
q5	5365	5474	5458	5458
q6	214	120	119	119
q7	2350	1936	2002	1936
q8	3238	3383	3376	3376
q9	8629	8592	8681	8592
q10	4003	3727	3789	3727
q11	598	509	491	491
q12	831	632	620	620
q13	16041	3117	3225	3117
q14	300	290	263	263
q15	517	495	491	491
q16	487	444	444	444
q17	1789	1489	1465	1465
q18	7771	7707	7368	7368
q19	1635	1506	1569	1506
q20	1947	1787	1728	1728
q21	8953	4806	4851	4806
q22	556	481	499	481
Total cold run time: 75221 ms
Total hot run time: 55098 ms

@doris-robot
Copy link

TPC-DS: Total hot run time: 186956 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpcds-tools
TPC-DS sf100 test result on commit 541cf185b31eade46e5e716c36d2ded08267dc13, data reload: false

query1	913	356	351	351
query2	6895	2346	2289	2289
query3	6643	211	220	211
query4	22884	21257	21477	21257
query5	4212	417	419	417
query6	274	196	181	181
query7	4586	287	288	287
query8	243	187	189	187
query9	8940	2391	2413	2391
query10	432	245	243	243
query11	14783	14147	14141	14141
query12	135	94	87	87
query13	1643	388	371	371
query14	9722	7644	7282	7282
query15	244	165	171	165
query16	8072	262	272	262
query17	1736	565	551	551
query18	2106	286	277	277
query19	205	163	154	154
query20	97	87	86	86
query21	197	128	125	125
query22	5022	4860	4829	4829
query23	34480	33823	33526	33526
query24	10614	2911	2950	2911
query25	600	416	370	370
query26	698	153	149	149
query27	2219	315	328	315
query28	5740	2068	2041	2041
query29	845	612	602	602
query30	223	156	156	156
query31	1002	773	743	743
query32	92	51	54	51
query33	645	249	245	245
query34	886	469	474	469
query35	798	702	684	684
query36	1057	907	915	907
query37	99	63	63	63
query38	2867	2803	2759	2759
query39	1625	1545	1551	1545
query40	200	133	122	122
query41	41	38	37	37
query42	108	92	95	92
query43	592	571	546	546
query44	1062	725	751	725
query45	260	251	254	251
query46	1067	713	700	700
query47	1973	1872	1875	1872
query48	366	300	293	293
query49	849	403	390	390
query50	782	390	379	379
query51	6923	6890	6793	6793
query52	100	86	95	86
query53	353	274	282	274
query54	837	431	438	431
query55	73	70	76	70
query56	239	216	218	216
query57	1240	1178	1136	1136
query58	224	197	198	197
query59	3578	3146	3233	3146
query60	262	228	240	228
query61	88	85	88	85
query62	654	465	478	465
query63	312	279	278	278
query64	8402	7398	7360	7360
query65	3155	3095	3095	3095
query66	775	345	359	345
query67	15697	14978	15100	14978
query68	6562	525	526	525
query69	560	307	318	307
query70	1214	1127	1142	1127
query71	507	275	264	264
query72	8036	2541	2337	2337
query73	728	320	320	320
query74	6656	6059	6240	6059
query75	4477	2606	2610	2606
query76	4337	1034	1005	1005
query77	700	260	256	256
query78	10709	10275	10190	10190
query79	2889	501	499	499
query80	1249	426	429	426
query81	485	225	222	222
query82	1221	97	92	92
query83	194	163	171	163
query84	267	89	108	89
query85	1209	264	257	257
query86	446	317	314	314
query87	3283	3182	3175	3175
query88	4558	2416	2428	2416
query89	503	398	378	378
query90	2008	184	191	184
query91	124	96	98	96
query92	57	47	51	47
query93	4310	493	485	485
query94	1143	176	180	176
query95	392	308	309	308
query96	599	267	265	265
query97	3184	3008	2994	2994
query98	236	222	216	216
query99	1262	902	888	888
Total cold run time: 288791 ms
Total hot run time: 186956 ms

Copy link
Contributor

@morningman morningman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@github-actions github-actions bot added the approved Indicates a PR has been approved by one committer. label May 9, 2024
@github-actions
Copy link
Contributor

github-actions bot commented May 9, 2024

PR approved by at least one committer and no changes requested.

@github-actions
Copy link
Contributor

github-actions bot commented May 9, 2024

PR approved by anyone and no changes requested.

@morningman morningman merged commit 856c43b into apache:master May 10, 2024
@zy-kkk zy-kkk deleted the jdbc_tvf branch May 10, 2024 03:25
zy-kkk added a commit to zy-kkk/doris that referenced this pull request May 10, 2024
This PR supports a Table Value Function called `Query`. He can push a query directly to the catalog source for execution by specifying `catalog` and `query` without parsing by Doris. Doris only receives the results returned by the query.
Currently only JDBC Catalog is supported.

Example:

```
Doris > desc function query('catalog' = 'mysql','query' = 'select count(*) as cnt from test.test');           
+-------+--------+------+------+---------+-------+
| Field | Type   | Null | Key  | Default | Extra |
+-------+--------+------+------+---------+-------+
| cnt   | BIGINT | Yes  | true | NULL    | NONE  |
+-------+--------+------+------+---------+-------+

Doris > select * from query('catalog' = 'mysql','query' = 'select count(*) as cnt from test.test');           
+----------+
| cnt      |
+----------+
| 30000000 |
+----------+
```
yiguolei pushed a commit that referenced this pull request May 10, 2024
This PR supports a Table Value Function called `Query`. He can push a query directly to the catalog source for execution by specifying `catalog` and `query` without parsing by Doris. Doris only receives the results returned by the query.
Currently only JDBC Catalog is supported.

Example:

```
Doris > desc function query('catalog' = 'mysql','query' = 'select count(*) as cnt from test.test');           
+-------+--------+------+------+---------+-------+
| Field | Type   | Null | Key  | Default | Extra |
+-------+--------+------+------+---------+-------+
| cnt   | BIGINT | Yes  | true | NULL    | NONE  |
+-------+--------+------+------+---------+-------+

Doris > select * from query('catalog' = 'mysql','query' = 'select count(*) as cnt from test.test');           
+----------+
| cnt      |
+----------+
| 30000000 |
+----------+
```
ByteYue pushed a commit to ByteYue/doris that referenced this pull request May 15, 2024
This PR supports a Table Value Function called `Query`. He can push a query directly to the catalog source for execution by specifying `catalog` and `query` without parsing by Doris. Doris only receives the results returned by the query.
Currently only JDBC Catalog is supported.

Example:

```
Doris > desc function query('catalog' = 'mysql','query' = 'select count(*) as cnt from test.test');           
+-------+--------+------+------+---------+-------+
| Field | Type   | Null | Key  | Default | Extra |
+-------+--------+------+------+---------+-------+
| cnt   | BIGINT | Yes  | true | NULL    | NONE  |
+-------+--------+------+------+---------+-------+

Doris > select * from query('catalog' = 'mysql','query' = 'select count(*) as cnt from test.test');           
+----------+
| cnt      |
+----------+
| 30000000 |
+----------+
```
zy-kkk added a commit to zy-kkk/doris that referenced this pull request Jun 2, 2024
This PR supports a Table Value Function called `Query`. He can push a query directly to the catalog source for execution by specifying `catalog` and `query` without parsing by Doris. Doris only receives the results returned by the query.
Currently only JDBC Catalog is supported.

Example:

```
Doris > desc function query('catalog' = 'mysql','query' = 'select count(*) as cnt from test.test');
+-------+--------+------+------+---------+-------+
| Field | Type   | Null | Key  | Default | Extra |
+-------+--------+------+------+---------+-------+
| cnt   | BIGINT | Yes  | true | NULL    | NONE  |
+-------+--------+------+------+---------+-------+

Doris > select * from query('catalog' = 'mysql','query' = 'select count(*) as cnt from test.test');
+----------+
| cnt      |
+----------+
| 30000000 |
+----------+
```
@zy-kkk zy-kkk removed the dev/2.0.x label Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants