[vectorized](jdbc) fix external table of oracle have keyworld column (#15487)

if column name is keyword of oracle, the query will report error
This commit is contained in:
zhangstar333
2022-12-31 12:48:26 +08:00
committed by GitHub
parent 781fa17993
commit c47bdf6606
4 changed files with 12 additions and 2 deletions

View File

@ -98,6 +98,8 @@ Parameter Description:
```
select * from mysql_table where k1 > 1000 and k3 ='term';
```
Because it is possible to use keywords in the database as column name, in order to solve this problem, escape characters will be automatically added to field names and table names in SQL statements according to the standards of each database. For example, MYSQL (``), PostgreSQL (""), SQLServer ([]), and ORACLE (""), But this may cause case sensitivity of field names. You can check the query statements issued to each database after escape through explain SQL.
### Data write
After the JDBC external table is create in Doris, the data can be written directly by the `insert into` statement, the query results of Doris can be written to the JDBC external table, or the data can be imported from one JDBC table to another.

View File

@ -97,6 +97,7 @@ PROPERTIES (
```
select * from mysql_table where k1 > 1000 and k3 ='term';
```
由于可能存在使用数据库内部的关键字作为字段名,为解决这种状况下仍能正确查询,所以在SQL语句中,会根据各个数据库的标准自动在字段名与表名上加上转义符。例如 MYSQL(``)、PostgreSQL("")、SQLServer([])、ORACLE(""),所以此时可能会造成字段名的大小写敏感,具体可以通过explain sql,查看转义后下发到各个数据库的查询语句。
### 数据写入

View File

@ -96,6 +96,11 @@ public class OdbcTable extends Table {
return list.stream().map(s -> "\"" + s + "\"").collect(Collectors.joining("."));
}
private static String oracleProperName(String name) {
List<String> list = Arrays.asList(name.split("\\."));
return list.stream().map(s -> "\"" + s.toUpperCase() + "\"").collect(Collectors.joining("."));
}
public static String databaseProperName(TOdbcTableType tableType, String name) {
switch (tableType) {
case MYSQL:
@ -104,6 +109,8 @@ public class OdbcTable extends Table {
return mssqlProperName(name);
case POSTGRESQL:
return psqlProperName(name);
case ORACLE:
return oracleProperName(name);
default:
return name;
}

View File

@ -1312,7 +1312,7 @@ public class QueryPlanTest extends TestWithFeService {
// this table is Oracle ODBC table, so abs(k1) should not be pushed down
queryStr = "explain select * from odbc_oracle where k1 > 10 and abs(k1) > 10";
explainString = getSQLPlanOrErrorMsg(queryStr);
Assert.assertTrue(explainString.contains("k1 > 10"));
Assert.assertTrue(explainString.contains("\"K1\" > 10"));
Assert.assertTrue(!explainString.contains("abs(k1) > 10"));
}
@ -1352,7 +1352,7 @@ public class QueryPlanTest extends TestWithFeService {
String explainString = getSQLPlanOrErrorMsg(queryStr);
Assert.assertTrue(explainString.contains("TABLENAME IN DORIS: odbc_oracle"));
Assert.assertTrue(explainString.contains("TABLE TYPE: ORACLE"));
Assert.assertTrue(explainString.contains("TABLENAME OF EXTERNAL TABLE: tbl1"));
Assert.assertTrue(explainString.contains("TABLENAME OF EXTERNAL TABLE: \"TBL1\""));
// enable transaction of ODBC Sink
Deencapsulation.setField(connectContext.getSessionVariable(), "enableOdbcTransaction", true);