diff --git a/.github/workflows/ci-pipeline-branch.yml b/.github/workflows/ci-pipeline-branch.yml index 61271eaa73fec..af8590accb8c3 100644 --- a/.github/workflows/ci-pipeline-branch.yml +++ b/.github/workflows/ci-pipeline-branch.yml @@ -34,14 +34,14 @@ jobs: echo ${GITHUB_SHA} > head_sha.txt - name: Upload the PR number - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: pr_num path: ./pr_num.txt retention-days: 3 - name: Upload the PR HEAD REF - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: head_sha path: ./head_sha.txt diff --git a/be/src/exec/mysql_scanner.cpp b/be/src/exec/mysql_scanner.cpp index 03c2706ce715b..83db7319bb2c2 100644 --- a/be/src/exec/mysql_scanner.cpp +++ b/be/src/exec/mysql_scanner.cpp @@ -164,35 +164,39 @@ Status MysqlScanner::query(const std::string& table, const std::vector 0) { - if (!is_filter_initial) { - is_filter_initial = true; - _sql_str += " WHERE ("; - } else { - _sql_str += " AND ("; - } - - bool is_first_conjunct = true; + std::vector conjuncts; for (auto& iter : filters_in) { - if (!is_first_conjunct) { - _sql_str += " AND ("; - } - is_first_conjunct = false; - if (iter.second.size() > 0) { - auto curr = iter.second.begin(); - auto end = iter.second.end(); - _sql_str += iter.first + " in ("; - _sql_str += *curr; - ++curr; - - // collect optional values. - while (curr != end) { - _sql_str += ", " + *curr; - ++curr; + if (iter.second.size() > 0 || filters_null_in_set[iter.first]) { + std::string tmp; + tmp += "(" + iter.first + " in ("; + for (auto& curr : iter.second) { + tmp += curr + ","; } if (filters_null_in_set[iter.first]) { - _sql_str += ", null"; + tmp += "null"; + } + if (tmp.back() == ',') { + tmp.pop_back(); } - _sql_str += ")) "; + tmp += "))"; + conjuncts.emplace_back(tmp); + } else { + // there is in predicate, but no value in it + // so there is no row from mysql node. + conjuncts.emplace_back("(0 = 1)"); + } + } + + if (conjuncts.size() > 0) { + if (!is_filter_initial) { + is_filter_initial = true; + _sql_str += " WHERE "; + } else { + _sql_str += " AND "; + } + _sql_str += conjuncts.at(0); + for (size_t i = 1; i < conjuncts.size(); i++) { + _sql_str += " AND " + conjuncts.at(i); } } } diff --git a/be/test/io/shared_buffered_input_stream_test.cpp b/be/test/io/shared_buffered_input_stream_test.cpp index bd39b679909aa..92c248be591ae 100644 --- a/be/test/io/shared_buffered_input_stream_test.cpp +++ b/be/test/io/shared_buffered_input_stream_test.cpp @@ -35,10 +35,10 @@ PARALLEL_TEST(SharedBufferedInputStreamTest, test_release) { sb_stream->set_coalesce_options(opts); // 150k -> 520k - auto r_active = io::SharedBufferedInputStream::IORange{.offset = 150 * 1024, .size = 370 * 1024}; + auto r_active = io::SharedBufferedInputStream::IORange(150 * 1024, 370 * 1024); ranges.push_back(r_active); // 550k -> 650k - auto r_lazy = io::SharedBufferedInputStream::IORange{.offset = 550 * 1024, .size = 100 * 1024}; + auto r_lazy = io::SharedBufferedInputStream::IORange(550 * 1024, 100 * 1024); ranges.push_back(r_lazy); auto st = sb_stream->set_io_ranges(ranges); ASSERT_OK(st); diff --git a/test/sql/test_external_mysql/R/test_external_mysql_clause b/test/sql/test_external_mysql/R/test_external_mysql_clause new file mode 100644 index 0000000000000..06b09c7be01ea --- /dev/null +++ b/test/sql/test_external_mysql/R/test_external_mysql_clause @@ -0,0 +1,82 @@ +-- name: testExternalMysqlCaluse +create database db_${uuid0}; +-- result: +-- !result +use db_${uuid0}; +-- result: +-- !result +CREATE TABLE `t00` ( + `id` int, + `s` string +) ENGINE=OLAP +DUPLICATE KEY(`id`) +COMMENT "OLAP" +DISTRIBUTED BY HASH(`id`) BUCKETS 1 +PROPERTIES ( +"replication_num" = "1", +"enable_persistent_index" = "false", +"replicated_storage" = "false", +"compression" = "LZ4" +); +-- result: +-- !result +insert into t00 values(1, "hello"), (2, "world"), (3, null); +-- result: +-- !result +CREATE EXTERNAL TABLE mysql_ext +( + `id` int, + `s` string +) +ENGINE=mysql +PROPERTIES +( + "host" = "${mysql_host}", + "port" = "${mysql_port}", + "user" = "${mysql_user}", + "password" = "${mysql_password}", + "database" = "db_${uuid0}", + "table" = "t00" +); +-- result: +-- !result +set cbo_derive_join_is_null_predicate = true; +-- result: +-- !result +select * from mysql_ext x inner join t00 on x.s = t00.s where t00.id = 3; +-- result: +-- !result +select * from mysql_ext x inner join t00 on x.s = t00.s where t00.id in (1, 2, 3); +-- result: +1 hello 1 hello +2 world 2 world +-- !result +select * from mysql_ext x inner join t00 on x.s = t00.s where t00.id in (1, 2); +-- result: +1 hello 1 hello +2 world 2 world +-- !result +select * from mysql_ext x inner join t00 on x.s = t00.s where t00.id in (1); +-- result: +1 hello 1 hello +-- !result +set cbo_derive_join_is_null_predicate = false; +-- result: +-- !result +select * from mysql_ext x inner join t00 on x.s = t00.s where t00.id = 3; +-- result: +-- !result +select * from mysql_ext x inner join t00 on x.s = t00.s where t00.id in (1, 2, 3); +-- result: +1 hello 1 hello +2 world 2 world +-- !result +select * from mysql_ext x inner join t00 on x.s = t00.s where t00.id in (1, 2); +-- result: +1 hello 1 hello +2 world 2 world +-- !result +select * from mysql_ext x inner join t00 on x.s = t00.s where t00.id in (1); +-- result: +1 hello 1 hello +-- !result \ No newline at end of file diff --git a/test/sql/test_external_mysql/T/test_external_mysql_clause b/test/sql/test_external_mysql/T/test_external_mysql_clause new file mode 100644 index 0000000000000..57d1b83ba963e --- /dev/null +++ b/test/sql/test_external_mysql/T/test_external_mysql_clause @@ -0,0 +1,58 @@ +-- name: testExternalMysqlCaluse + +create database db_${uuid0}; +use db_${uuid0}; + +CREATE TABLE `t00` ( + `id` int, + `s` string +) ENGINE=OLAP +DUPLICATE KEY(`id`) +COMMENT "OLAP" +DISTRIBUTED BY HASH(`id`) BUCKETS 1 +PROPERTIES ( +"replication_num" = "1", +"enable_persistent_index" = "false", +"replicated_storage" = "false", +"compression" = "LZ4" +); + +insert into t00 values(1, "hello"), (2, "world"), (3, null); + +CREATE EXTERNAL TABLE mysql_ext +( + `id` int, + `s` string +) +ENGINE=mysql +PROPERTIES +( + "host" = "${mysql_host}", + "port" = "${mysql_port}", + "user" = "${mysql_user}", + "password" = "${mysql_password}", + "database" = "db_${uuid0}", + "table" = "t00" +); + +set cbo_derive_join_is_null_predicate = true; + +select * from mysql_ext x inner join t00 on x.s = t00.s where t00.id = 3; + +select * from mysql_ext x inner join t00 on x.s = t00.s where t00.id in (1, 2, 3); + +select * from mysql_ext x inner join t00 on x.s = t00.s where t00.id in (1, 2); + +select * from mysql_ext x inner join t00 on x.s = t00.s where t00.id in (1); + + +set cbo_derive_join_is_null_predicate = false; + +select * from mysql_ext x inner join t00 on x.s = t00.s where t00.id = 3; + +select * from mysql_ext x inner join t00 on x.s = t00.s where t00.id in (1, 2, 3); + +select * from mysql_ext x inner join t00 on x.s = t00.s where t00.id in (1, 2); + +select * from mysql_ext x inner join t00 on x.s = t00.s where t00.id in (1); +