1
+ // Licensed to the Apache Software Foundation (ASF) under one
2
+ // or more contributor license agreements. See the NOTICE file
3
+ // distributed with this work for additional information
4
+ // regarding copyright ownership. The ASF licenses this file
5
+ // to you under the Apache License, Version 2.0 (the
6
+ // "License"); you may not use this file except in compliance
7
+ // with the License. You may obtain a copy of the License at
8
+ //
9
+ // http://www.apache.org/licenses/LICENSE-2.0
10
+ //
11
+ // Unless required by applicable law or agreed to in writing,
12
+ // software distributed under the License is distributed on an
13
+ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ // KIND, either express or implied. See the License for the
15
+ // specific language governing permissions and limitations
16
+ // under the License.
17
+
18
+ import groovy.json.JsonOutput
19
+ import groovy.json.JsonSlurper
20
+ import groovy.json.StringEscapeUtils
21
+
22
+ def getProfileList = {
23
+ def dst = ' http://' + context. config. feHttpAddress
24
+ def conn = new URL (dst + " /rest/v1/query_profile" ). openConnection()
25
+ conn. setRequestMethod(" GET" )
26
+ def encoding = Base64 . getEncoder(). encodeToString((context. config. feHttpUser + " :" +
27
+ (context. config. feHttpPassword == null ? " " : context. config. feHttpPassword)). getBytes(" UTF-8" ))
28
+ conn. setRequestProperty(" Authorization" , " Basic ${ encoding} " )
29
+ return conn. getInputStream(). getText()
30
+ }
31
+
32
+ def getProfile = { id ->
33
+ def dst = ' http://' + context. config. feHttpAddress
34
+ def conn = new URL (dst + " /api/profile/text/?query_id=$id " ). openConnection()
35
+ conn. setRequestMethod(" GET" )
36
+ def encoding = Base64 . getEncoder(). encodeToString((context. config. feHttpUser + " :" +
37
+ (context. config. feHttpPassword == null ? " " : context. config. feHttpPassword)). getBytes(" UTF-8" ))
38
+ conn. setRequestProperty(" Authorization" , " Basic ${ encoding} " )
39
+ // set conn parameters
40
+
41
+ return conn. getInputStream(). getText()
42
+ }
43
+
44
+ suite(' test_execute_by_frontend' ) {
45
+ sql """
46
+ CREATE TABLE if not exists `test_execute_by_frontend` (
47
+ `id` INT,
48
+ `name` varchar(32)
49
+ )ENGINE=OLAP
50
+ UNIQUE KEY(`id`)
51
+ DISTRIBUTED BY HASH(`id`) BUCKETS 1
52
+ PROPERTIES (
53
+ "replication_allocation" = "tag.location.default: 1"
54
+ );
55
+ """
56
+
57
+ sql " set enable_profile=true"
58
+ def simpleSql1 = " select * from test_execute_by_frontend"
59
+ sql " ${ simpleSql1} "
60
+ simpleSql2 = """ select cast("1" as Int)"""
61
+ sql " ${ simpleSql2} "
62
+ def isRecorded = false
63
+ def wholeString = getProfileList()
64
+ List profileData = new JsonSlurper (). parseText(wholeString). data. rows
65
+ String queryId1 = " " ;
66
+ String queryId2 = " " ;
67
+
68
+ for (final def profileItem in profileData) {
69
+ if (profileItem[" Sql Statement" ]. toString() == simpleSql1) {
70
+ isRecorded = true
71
+ queryId1 = profileItem[" Profile ID" ]. toString()
72
+ assertEquals (" internal" , profileItem[" Default Catalog" ]. toString())
73
+ }
74
+ if (profileItem[" Sql Statement" ]. toString() == simpleSql2) {
75
+ queryId2 = profileItem[" Profile ID" ]. toString()
76
+ }
77
+ }
78
+
79
+ assertTrue (isRecorded)
80
+
81
+ String profileContent1 = getProfile(queryId1)
82
+ def executionProfileIdx1 = profileContent1. indexOf(" Executed By Frontend: true" )
83
+ assertTrue (executionProfileIdx1 > 0 )
84
+ String profileContent2 = getProfile(queryId2)
85
+ def executionProfileIdx2 = profileContent2. indexOf(" Executed By Frontend: true" )
86
+ assertTrue (executionProfileIdx2 > 0 )
87
+
88
+ sql """ SET enable_profile = false """
89
+ sql """ DROP TABLE IF EXISTS test_execute_by_frontend """
90
+ }
0 commit comments