Skip to content

Commit

Permalink
[branch-2.0](JdbcCatalog) fix that the predicate column name does not…
Browse files Browse the repository at this point in the history
… have back quote when querying the JDBC appearance (#26479) (#26560)

master pr: #26479
  • Loading branch information
BePPPower authored Nov 9, 2023
1 parent 4eb75bd commit c355adb
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,10 @@ 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,
Expand Down
2 changes: 2 additions & 0 deletions docker/thirdparties/docker-compose/mysql/init/04-insert.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1152,3 +1152,5 @@ VALUES ('2023-06-17 10:00:00', '2023-06-17 10:00:01.1', '2023-06-17 10:00:02.22'
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);
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 auto_default_t = "auto_default_t";
Expand Down Expand Up @@ -115,6 +116,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 @@ -307,7 +309,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

0 comments on commit c355adb

Please sign in to comment.