Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix](JdbcCatalog) fix that the predicate column name does not have back quote when querying the JDBC appearance #26479

Merged
merged 4 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,11 @@ CREATE TABLE doris_test.dt_null (
CREATE VIEW doris_test.mysql_view as
select 10086 as col_1, 4294967295 as col_2, tinyint_u as col_3 from doris_test.all_types where tinyint_u=201;

CREATE TABLE doris_test.test_key_word (
`id` int,
`key` int
) ENGINE=INNODB CHARSET=utf8;

CREATE TABLE show_test_do_not_modify.ex_tb0 (
`id` int PRIMARY KEY,
`name` varchar(128)
Expand Down
3 changes: 3 additions & 0 deletions docker/thirdparties/docker-compose/mysql/init/04-insert.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1153,6 +1153,9 @@ SET SESSION sql_mode=(SELECT REPLACE(@@sql_mode,'STRICT_TRANS_TABLES',''));
INSERT INTO doris_test.dt_null
VALUES ('2023-06-17 10:00:00'),('0000-00-00 00:00:00');


insert into doris_test.test_key_word values (1, 1), (2, 2);

SET SESSION sql_mode=(SELECT REPLACE(@@sql_mode,'NO_ZERO_DATE',''));
SET SESSION sql_mode=(SELECT REPLACE(@@sql_mode,'NO_ZERO_IN_DATE',''));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,19 @@ public static String conjunctExprToString(TOdbcTableType tableType, Expr expr) {
return filter;
}

if (expr.contains(SlotRef.class) && expr instanceof BinaryPredicate) {
ArrayList<Expr> children = expr.getChildren();
String filter;
if (children.get(0) instanceof SlotRef) {
filter = JdbcTable.databaseProperName(tableType, children.get(0).toMySql());
} else {
filter = children.get(0).toMySql();
}
filter += " " + ((BinaryPredicate) expr).getOp().toString() + " ";
filter += children.get(1).toMySql();
return filter;
}

// only for old planner
if (expr.contains(BoolLiteral.class) && "1".equals(expr.getStringValue()) && expr.getChildren().isEmpty()) {
return "1 = 1";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ bca 2022-11-02 2022-11-02 8012 vivo
1.12345 1.12345 1.12345 1.12345 1.12345 1.12345
123456789012345678901234567890123.12345 12345678901234567890123456789012.12345 1234567890123456789012345678901234.12345 123456789012345678901234567890123.12345 123456789012345678901234567890123456789012345678901234567890.12345 123456789012345678901234567890123456789012345678901234567890.12345

-- !ex_tb21 --
2 2

-- !information_schema --
CHARACTER_SETS
COLLATIONS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ suite("test_clickhouse_jdbc_catalog", "p0,external,clickhouse,external_docker,ex
order_qt_func_push2 """select * from ts where ts <= unix_timestamp(from_unixtime(ts,'yyyyMMdd'));"""
explain {
sql("select * from ts where ts <= unix_timestamp(from_unixtime(ts,'yyyy-MM-dd'));")
contains """QUERY: SELECT "id", "ts" FROM "doris_test"."ts" WHERE (ts <= toUnixTimestamp(FROM_UNIXTIME(ts, '%Y-%m-%d')))"""
contains """QUERY: SELECT "id", "ts" FROM "doris_test"."ts" WHERE ("ts" <= toUnixTimestamp(FROM_UNIXTIME(ts, '%Y-%m-%d')))"""
}

sql """ drop catalog if exists ${catalog_name} """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ suite("test_mysql_jdbc_catalog", "p0,external,mysql,external_docker,external_doc
String ex_tb18 = "ex_tb18";
String ex_tb19 = "ex_tb19";
String ex_tb20 = "ex_tb20";
String ex_tb21 = "test_key_word";
String test_insert = "test_insert";
String test_insert2 = "test_insert2";
String test_insert_all_types = "test_insert_all_types";
Expand Down Expand Up @@ -158,6 +159,7 @@ suite("test_mysql_jdbc_catalog", "p0,external,mysql,external_docker,external_doc
order_qt_ex_tb18 """ select * from ${ex_tb18} order by num_tinyint; """
order_qt_ex_tb19 """ select * from ${ex_tb19} order by date_value; """
order_qt_ex_tb20 """ select * from ${ex_tb20} order by decimal_normal; """
order_qt_ex_tb21 """ select `key`, `id` from ${ex_tb21} where `key` = 2 order by id;"""
order_qt_information_schema """ show tables from information_schema; """
order_qt_auto_default_t """insert into ${auto_default_t}(name) values('a'); """
order_qt_dt """select * from ${dt}; """
Expand Down Expand Up @@ -367,7 +369,7 @@ suite("test_mysql_jdbc_catalog", "p0,external,mysql,external_docker,external_doc
explain {
sql ("select k6, k8 from test1 where nvl(k6, null) = 1 and k8 = 1;")

contains "QUERY: SELECT `k6`, `k8` FROM `doris_test`.`test1` WHERE (k8 = 1)"
contains "QUERY: SELECT `k6`, `k8` FROM `doris_test`.`test1` WHERE (`k8` = 1)"
}
sql """ admin set frontend config ("enable_func_pushdown" = "true"); """
sql """ drop catalog if exists mysql_fun_push_catalog; """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ suite("test_mysql_jdbc_catalog_nereids", "p0,external,mysql,external_docker,exte

explain {
sql("""select id from ${ex_tb0} where id = 111;""")
contains "WHERE (id = 111)"
contains "WHERE (`id` = 111)"
}
qt_ex_tb0_where """select id from ${ex_tb0} where id = 111;"""
order_qt_ex_tb0 """ select id, name from ${ex_tb0} order by id; """
Expand Down