Skip to content

Commit

Permalink
Merge pull request #225 from fangyuefy/master
Browse files Browse the repository at this point in the history
JDBC Server API and core JdbcPipeline code optimization
  • Loading branch information
Functor10 committed Sep 21, 2020
2 parents d4f0d53 + 767a4e8 commit 4f9df03
Show file tree
Hide file tree
Showing 15 changed files with 307 additions and 406 deletions.
35 changes: 13 additions & 22 deletions core/src/main/java/com/qihoo/qsql/api/AutomaticConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public PreparedStatement prepareStatement(String sql) throws SQLException {
}

//caution: tableName has changed to dbName.tableName
if (names.stream().anyMatch(name -> ! tableNames.contains(name))) {
if (names.stream().anyMatch(name -> !tableNames.contains(name))) {
tableNames.clear();
tableNames.addAll(names);
} else {
Expand All @@ -104,52 +104,46 @@ public PreparedStatement prepareStatement(String sql) throws SQLException {
@Override
public PreparedStatement prepareStatement(String sql,
int resultSetType,
int resultSetConcurrency) throws SQLException {
int resultSetConcurrency) {
throw new UnsupportedApiException("");
}

@Override
public PreparedStatement prepareStatement(String sql,
int resultSetType,
int resultSetConcurrency,
int resultSetHoldability) throws SQLException {
int resultSetHoldability) {
throw new UnsupportedApiException("");
}

@Override
public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys)
throws SQLException {
public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) {
throw new UnsupportedApiException("");
}

@Override
public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException {
public PreparedStatement prepareStatement(String sql, int[] columnIndexes) {
throw new UnsupportedApiException("");
}

@Override
public PreparedStatement prepareStatement(String sql, String[] columnNames)
throws SQLException {
public PreparedStatement prepareStatement(String sql, String[] columnNames) {
throw new UnsupportedApiException("");
}

@Override
public CallableStatement prepareCall(String sql) throws SQLException {
public CallableStatement prepareCall(String sql) {
throw new UnsupportedApiException("");
}

@Override
public CallableStatement prepareCall(String sql,
int resultSetType,
int resultSetConcurrency) throws SQLException {
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) {
throw new UnsupportedApiException("");
}

@Override
public CallableStatement prepareCall(String sql,
int resultSetType,
int resultSetConcurrency,
int resultSetHoldability) throws SQLException {
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency,
int resultSetHoldability) {
throw new UnsupportedApiException("");
}

Expand Down Expand Up @@ -234,20 +228,17 @@ public void clearWarnings() throws SQLException {
}

@Override
public Statement createStatement() throws SQLException {
public Statement createStatement() {
throw new UnsupportedApiException("");
}

@Override
public Statement createStatement(int resultSetType,
int resultSetConcurrency,
int resultSetHoldability) throws SQLException {
public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) {
throw new UnsupportedApiException("");
}

@Override
public Statement createStatement(int resultSetType,
int resultSetConcurrency) throws SQLException {
public Statement createStatement(int resultSetType, int resultSetConcurrency) {
throw new UnsupportedApiException("");
}

Expand Down
8 changes: 6 additions & 2 deletions core/src/main/java/com/qihoo/qsql/api/DynamicSqlRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ public class DynamicSqlRunner extends SqlRunner {
super(builder);
}

private String getFullSchemaFromAssetDataSource() {
String getFullSchemaFromAssetDataSource() {
return "inline: " + MetadataPostman.getCalciteModelSchema(tableNames);
}

private QueryProcedure createQueryPlan(String sql) {
QueryProcedure createQueryPlan(String sql) {
String schema = environment.getSchemaPath();

if (schema.isEmpty()) {
Expand Down Expand Up @@ -84,6 +84,10 @@ public AbstractPipeline sql(String sql) {
return chooseAdaptPipeline(procedure);
}

public void setTableNames(List<String> tableNames) {
this.tableNames = tableNames;
}

/**
* Choose a suitable pipeline based on QueryProcedure.
*
Expand Down
18 changes: 12 additions & 6 deletions core/src/main/java/com/qihoo/qsql/api/SqlLogicalPlanView.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,37 @@
/**
* sql logical plan view.
*/
public class SqlLogicalPlanView {
public class SqlLogicalPlanView {

private static final Logger LOGGER = LoggerFactory.getLogger(SqlLogicalPlanView.class);
private List<String> tableNames;
protected Builder environment;

public static final SqlLogicalPlanView VIEW = new SqlLogicalPlanView();

public SqlLogicalPlanView() {
private SqlLogicalPlanView() {
this.environment = SqlRunner.builder();
}

public static SqlLogicalPlanView getInstance() {
return VIEW;
}

static {
PropertiesReader.configLogger();
}

private static final String TEST_DATA_URL = PropertiesReader.getTestDataFilePath();

/**
* method of logical plan view.
*/
public String getLogicalPlanView(String sql) {
LOGGER.info("The sql being parser: \n" + sql);
sql = sql.replace("explain ","").replace("EXPLAIN ","");
QueryTables tables = SqlUtil.parseTableName(sql);
tableNames = tables.tableNames;
environment.setTransformRunner(RunnerType.JDBC);

LOGGER.debug("Parsed table names for upper SQL are: {}", tableNames);
QueryProcedure procedure = createQueryPlan(sql);

return getQueryProcedureLogicalView(procedure);
}

Expand All @@ -74,6 +76,10 @@ private String getFullSchemaFromAssetDataSource() {
return "inline: " + MetadataPostman.getCalciteModelSchema(tableNames);
}

public static boolean isPlanView(String sql) {
return sql.toLowerCase().startsWith("explain");
}

private String getQueryProcedureLogicalView(QueryProcedure queryProcedure) {
TreeNode treeNode = queryProcedure.getTreeNode();
Gson gson = new GsonBuilder().disableHtmlEscaping().create();
Expand Down
Loading

0 comments on commit 4f9df03

Please sign in to comment.