forked from github/dataease
Merge pull request #11388 from dataease/pr@dev-v2@fixDS
Pr@dev v2@fix ds
This commit is contained in:
commit
66dc4aadaa
@ -101,34 +101,47 @@ public class SqlparserUtils {
|
||||
private static void handleFromItems(PlainSelect plainSelect, String dsType) throws Exception {
|
||||
FromItem fromItem = plainSelect.getFromItem();
|
||||
if (fromItem instanceof ParenthesedSelect) {
|
||||
if (((ParenthesedSelect) fromItem).getSelect() instanceof SetOperationList) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
SetOperationList setOperationList = (SetOperationList) ((ParenthesedSelect) fromItem).getSelect().getSelectBody();
|
||||
for (int i = 0; i < setOperationList.getSelects().size(); i++) {
|
||||
result.append(handlePlainSelect((PlainSelect) setOperationList.getSelects().get(i), null, dsType));
|
||||
if (i < setOperationList.getSelects().size() - 1) {
|
||||
result.append(" ").append(setOperationList.getOperations().get(i).toString()).append(" ");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
PlainSelect selectBody = ((ParenthesedSelect) fromItem).getSelect().getPlainSelect();
|
||||
Select subSelectTmp = (Select) CCJSqlParserUtil.parse(removeVariables(selectBody.toString(), dsType));
|
||||
((ParenthesedSelect) fromItem).setSelect(subSelectTmp.getSelectBody());
|
||||
if (dsType.equals(DatasourceConfiguration.DatasourceType.oracle.getType())) {
|
||||
if (fromItem.getAlias() != null) {
|
||||
fromItem.setAlias(new Alias(fromItem.getAlias().toString(), false));
|
||||
}
|
||||
} else {
|
||||
if (fromItem.getAlias() == null) {
|
||||
throw new Exception("Failed to parse sql, Every derived table must have its own alias!");
|
||||
}
|
||||
fromItem.setAlias(new Alias(fromItem.getAlias().toString(), false));
|
||||
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();
|
||||
for (int i = 0; i < setOperationList.getSelects().size(); i++) {
|
||||
result.append(handlePlainSelect((PlainSelect) setOperationList.getSelects().get(i), null, dsType));
|
||||
if (i < setOperationList.getSelects().size() - 1) {
|
||||
result.append(" ").append(setOperationList.getOperations().get(i).toString()).append(" ");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
PlainSelect selectBody = ((ParenthesedSelect) fromItem).getSelect().getPlainSelect();
|
||||
Select subSelectTmp = (Select) CCJSqlParserUtil.parse(removeVariables(selectBody.toString(), dsType));
|
||||
((ParenthesedSelect) fromItem).setSelect(subSelectTmp.getSelectBody());
|
||||
if (dsType.equals(DatasourceConfiguration.DatasourceType.oracle.getType())) {
|
||||
if (fromItem.getAlias() != null) {
|
||||
fromItem.setAlias(new Alias(fromItem.getAlias().toString(), false));
|
||||
}
|
||||
} else {
|
||||
if (fromItem.getAlias() == null) {
|
||||
throw new Exception("Failed to parse sql, Every derived table must have its own alias!");
|
||||
}
|
||||
fromItem.setAlias(new Alias(fromItem.getAlias().toString(), false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void handleJoins(PlainSelect plainSelect, String dsType) throws Exception {
|
||||
List<Join> joins = plainSelect.getJoins();
|
||||
if (joins != null) {
|
||||
|
@ -30,6 +30,8 @@ public class FieldUtils {
|
||||
case "DATETIMEOFFSET":
|
||||
case "SMALLDATETIME":
|
||||
case "DATETIME64":
|
||||
case "_TIMESTAMPTZ":
|
||||
case "TIMESTAMPTZ":
|
||||
return 1;// 时间
|
||||
case "INT":
|
||||
case "SMALLINT":
|
||||
|
@ -98,15 +98,18 @@ public class CalciteProvider extends Provider {
|
||||
@Override
|
||||
public List<DatasetTableDTO> getTables(DatasourceRequest datasourceRequest) {
|
||||
List<DatasetTableDTO> tables = new ArrayList<>();
|
||||
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)) {
|
||||
|
||||
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) {
|
||||
ResultSet resultSet = statement.executeQuery(tablesSql);
|
||||
while (resultSet.next()) {
|
||||
tables.add(getTableDesc(datasourceRequest, resultSet));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
DEException.throwException(e.getMessage());
|
||||
}
|
||||
} 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];
|
||||
}
|
||||
tableSqls.add("SELECT name, comment FROM system.tables where database='DATABASE';".replace("DATABASE", database));
|
||||
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:
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user