Skip to content

Commit

Permalink
[regression-test](framework) fix bug when sql returns two column with…
Browse files Browse the repository at this point in the history
… same name (#47087)

### What problem does this PR solve?

Issue Number: close #xxx

Related PR: #xxx

Problem Summary:
sql_return_maparray use map data structure to save sql results. If sql
returns two column with same name, map will merge these two column
results, causing error results.
  • Loading branch information
shuke987 authored Jan 17, 2025
1 parent f14db21 commit 8189af5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,24 @@ class Suite implements GroovyInterceptable {
columnNames.add(meta.getColumnLabel(i + 1))
}

// Check if there are duplicates column names.
// SQL may return multiple columns with the same name.
// which cannot be handled by maps and will result in an error directly.
Set<String> uniqueSet = new HashSet<>()
Set<String> duplicates = new HashSet<>()

for (String str : columnNames) {
if (uniqueSet.contains(str)) {
duplicates.add(str)
} else {
uniqueSet.add(str)
}
}
if (!duplicates.isEmpty()) {
def errorMessage = "${sqlStr} returns duplicates headers: ${duplicates}"
throw new Exception(errorMessage)
}

// add result to res map list, each row is a map with key is column name
List<Map<String, Object>> res = new ArrayList<>()
for (int i = 0; i < result.size(); i++) {
Expand Down
14 changes: 3 additions & 11 deletions regression-test/suites/manager/test_manager_interface_1.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -485,13 +485,10 @@ suite('test_manager_interface_1',"p0") {
}
test_table_index()


//select a.*, b.*, c.NAME as WORKLOAD_GROUP_NAME from information_schema.active_queries a left join information_schema.backend_active_tasks b on a.QUERY_ID = b.QUERY_ID left join information_schema.workload_groups c on a.WORKLOAD_GROUP_ID = c.ID
def test_active_query = {

List<List<Object>> result = sql """ select 1;"""


def futures = []
futures.add( thread {

Expand All @@ -504,15 +501,10 @@ suite('test_manager_interface_1',"p0") {
futures.add( thread {
sleep(1500)

result = sql """
select a.*, b.*, c.NAME as WORKLOAD_GROUP_NAME from information_schema.active_queries a left join
information_schema.backend_active_tasks b on a.QUERY_ID = b.QUERY_ID left join information_schema.workload_groups c on a.WORKLOAD_GROUP_ID = c.ID
"""
logger.info("result = ${result}")

result = sql_return_maparray """
select a.*, b.*, c.NAME as WORKLOAD_GROUP_NAME from information_schema.active_queries a left join
information_schema.backend_active_tasks b on a.QUERY_ID = b.QUERY_ID left join information_schema.workload_groups c on a.WORKLOAD_GROUP_ID = c.ID
select a.*, b.TASK_CPU_TIME_MS, b.SCAN_ROWS, b.SCAN_BYTES, b.SHUFFLE_SEND_BYTES, b.SHUFFLE_SEND_ROWS, b.CURRENT_USED_MEMORY_BYTES, c.NAME as WORKLOAD_GROUP_NAME
from information_schema.active_queries a left join
information_schema.backend_active_tasks b on a.QUERY_ID = b.QUERY_ID left join information_schema.workload_groups c on a.WORKLOAD_GROUP_ID = c.ID
"""
logger.info("result = ${result}")

Expand Down

0 comments on commit 8189af5

Please sign in to comment.