Merge pull request #11388 from dataease/pr@dev-v2@fixDS

Pr@dev v2@fix ds
This commit is contained in:
taojinlong 2024-08-07 09:23:18 +08:00 committed by GitHub
commit 66dc4aadaa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 53 additions and 28 deletions

View File

@ -101,6 +101,21 @@ public class SqlparserUtils {
private static void handleFromItems(PlainSelect plainSelect, String dsType) throws Exception {
FromItem fromItem = plainSelect.getFromItem();
if (fromItem instanceof ParenthesedSelect) {
handleParenthesedSelect(fromItem, dsType);
plainSelect.setFromItem(fromItem);
} else {
if (fromItem instanceof ParenthesedFromItem) {
fromItem = ((ParenthesedFromItem) fromItem).getFromItem();
while (fromItem instanceof ParenthesedFromItem) {
fromItem = ((ParenthesedFromItem) fromItem).getFromItem();
}
handleParenthesedSelect(fromItem, dsType);
}
plainSelect.setFromItem(fromItem);
}
}
private static void handleParenthesedSelect(FromItem fromItem, String dsType) throws Exception {
if (((ParenthesedSelect) fromItem).getSelect() instanceof SetOperationList) {
StringBuilder result = new StringBuilder();
SetOperationList setOperationList = (SetOperationList) ((ParenthesedSelect) fromItem).getSelect().getSelectBody();
@ -125,8 +140,6 @@ public class SqlparserUtils {
fromItem.setAlias(new Alias(fromItem.getAlias().toString(), false));
}
}
plainSelect.setFromItem(fromItem);
}
}
private static void handleJoins(PlainSelect plainSelect, String dsType) throws Exception {

View File

@ -30,6 +30,8 @@ public class FieldUtils {
case "DATETIMEOFFSET":
case "SMALLDATETIME":
case "DATETIME64":
case "_TIMESTAMPTZ":
case "TIMESTAMPTZ":
return 1;// 时间
case "INT":
case "SMALLINT":

View File

@ -98,16 +98,19 @@ public class CalciteProvider extends Provider {
@Override
public List<DatasetTableDTO> getTables(DatasourceRequest datasourceRequest) {
List<DatasetTableDTO> tables = new ArrayList<>();
try (ConnectionObj con = getConnection(datasourceRequest.getDatasource()); Statement statement = getStatement(con.getConnection(), 30)) {
datasourceRequest.setDsVersion(con.getConnection().getMetaData().getDatabaseMajorVersion());
List<String> tablesSqls = getTablesSql(datasourceRequest);
for (String tablesSql : tablesSqls) {
try (ConnectionObj con = getConnection(datasourceRequest.getDatasource()); Statement statement = getStatement(con.getConnection(), 30); ResultSet resultSet = statement.executeQuery(tablesSql)) {
ResultSet resultSet = statement.executeQuery(tablesSql);
while (resultSet.next()) {
tables.add(getTableDesc(datasourceRequest, resultSet));
}
}
} catch (Exception e) {
DEException.throwException(e.getMessage());
}
}
return tables;
}
@ -237,6 +240,7 @@ public class CalciteProvider extends Provider {
ResultSet resultSet = null;
try (ConnectionObj con = getConnection(datasourceRequest.getDatasource());
Statement statement = getStatement(con.getConnection(), 30)) {
datasourceRequest.setDsVersion(con.getConnection().getMetaData().getDatabaseMajorVersion());
if (datasourceRequest.getDatasource().getType().equalsIgnoreCase("mongo") || datasourceRequest.getDatasource().getType().equalsIgnoreCase("doris")) {
resultSet = statement.executeQuery("select * from " + table + " limit 0 offset 0 ");
return fetchResultField(resultSet);
@ -1054,7 +1058,12 @@ public class CalciteProvider extends Provider {
String[] databasePrams = matcher.group(3).split("\\?");
database = databasePrams[0];
}
if(datasourceRequest.getDsVersion() < 22){
tableSqls.add("SELECT name, name FROM system.tables where database='DATABASE';".replace("DATABASE", database));
}else {
tableSqls.add("SELECT name, comment FROM system.tables where database='DATABASE';".replace("DATABASE", database));
}
break;
default:

View File

@ -15,6 +15,7 @@ public class DatasourceRequest implements Serializable {
protected String query;
protected String table;
protected DatasourceDTO datasource;
private Integer dsVersion;
private Integer pageSize;
private Integer page;
private Integer realSize;