diff --git a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/converter/segment/from/impl/JoinTableConverter.java b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/converter/segment/from/impl/JoinTableConverter.java index 869b42556d20d..f4da9ea637c5f 100644 --- a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/converter/segment/from/impl/JoinTableConverter.java +++ b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/converter/segment/from/impl/JoinTableConverter.java @@ -46,10 +46,17 @@ public Optional convert(final JoinTableSegment segment) { SqlNode right = new TableConverter().convert(segment.getRight()).orElseThrow(IllegalStateException::new); Optional condition = convertJoinCondition(segment); SqlLiteral conditionType = convertConditionType(segment); - SqlLiteral joinType = JoinType.valueOf(segment.getJoinType()).symbol(SqlParserPos.ZERO); + SqlLiteral joinType = convertJoinType(segment); return Optional.of(new SqlJoin(SqlParserPos.ZERO, left, SqlLiteral.createBoolean(segment.isNatural(), SqlParserPos.ZERO), joinType, right, conditionType, condition.orElse(null))); } + private static SqlLiteral convertJoinType(final JoinTableSegment segment) { + if (JoinType.INNER.name().equals(segment.getJoinType()) && !segment.isNatural() && null == segment.getCondition() && segment.getUsing().isEmpty()) { + return JoinType.COMMA.symbol(SqlParserPos.ZERO); + } + return JoinType.valueOf(segment.getJoinType()).symbol(SqlParserPos.ZERO); + } + private SqlLiteral convertConditionType(final JoinTableSegment segment) { if (!segment.getUsing().isEmpty()) { return JoinConditionType.USING.symbol(SqlParserPos.ZERO); diff --git a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/executor/enumerable/EnumerableScanExecutor.java b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/executor/enumerable/EnumerableScanExecutor.java index 6eb80eff97d63..528da1fea773a 100644 --- a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/executor/enumerable/EnumerableScanExecutor.java +++ b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/executor/enumerable/EnumerableScanExecutor.java @@ -29,7 +29,6 @@ import org.apache.shardingsphere.infra.database.core.metadata.database.system.SystemDatabase; import org.apache.shardingsphere.infra.database.core.type.DatabaseType; import org.apache.shardingsphere.infra.database.opengauss.type.OpenGaussDatabaseType; -import org.apache.shardingsphere.infra.exception.core.external.sql.type.wrapper.SQLWrapperException; import org.apache.shardingsphere.infra.executor.kernel.model.ExecutionGroup; import org.apache.shardingsphere.infra.executor.kernel.model.ExecutionGroupContext; import org.apache.shardingsphere.infra.executor.kernel.model.ExecutionGroupReportContext; @@ -40,7 +39,6 @@ import org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutorCallback; import org.apache.shardingsphere.infra.executor.sql.execute.result.ExecuteResult; import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult; -import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResultMetaData; import org.apache.shardingsphere.infra.executor.sql.prepare.driver.DriverExecutionPrepareEngine; import org.apache.shardingsphere.infra.executor.sql.process.ProcessEngine; import org.apache.shardingsphere.infra.hint.HintValueContext; @@ -143,28 +141,33 @@ public Enumerable execute(final ShardingSphereTable table, final Enumera federationContext.getExecutionUnits().addAll(context.getExecutionUnits()); return createEmptyEnumerable(); } - return execute(queryContext, database, context); - } - - private AbstractEnumerable execute(final QueryContext queryContext, final ShardingSphereDatabase database, final ExecutionContext context) { try { - computeConnectionOffsets(context); - ExecutionGroupContext executionGroupContext = - prepareEngine.prepare(context.getRouteContext(), executorContext.getConnectionOffsets(), context.getExecutionUnits(), new ExecutionGroupReportContext(database.getName())); - setParameters(executionGroupContext.getInputGroups()); - processEngine.executeSQL(executionGroupContext, context.getQueryContext()); - List queryResults = jdbcExecutor.execute(executionGroupContext, callback).stream().map(QueryResult.class::cast).collect(Collectors.toList()); - MergeEngine mergeEngine = new MergeEngine(database, executorContext.getProps(), new ConnectionContext()); - MergedResult mergedResult = mergeEngine.merge(queryResults, queryContext.getSqlStatementContext()); - Collection statements = getStatements(executionGroupContext.getInputGroups()); - return createEnumerable(mergedResult, queryResults.get(0).getMetaData(), statements); - } catch (final SQLException ex) { - throw new SQLWrapperException(ex); + return createEnumerable(queryContext, database, context); } finally { processEngine.completeSQLExecution(); } } + private AbstractEnumerable createEnumerable(final QueryContext queryContext, final ShardingSphereDatabase database, final ExecutionContext context) { + return new AbstractEnumerable() { + + @SneakyThrows + @Override + public Enumerator enumerator() { + computeConnectionOffsets(context); + ExecutionGroupContext executionGroupContext = + prepareEngine.prepare(context.getRouteContext(), executorContext.getConnectionOffsets(), context.getExecutionUnits(), new ExecutionGroupReportContext(database.getName())); + setParameters(executionGroupContext.getInputGroups()); + processEngine.executeSQL(executionGroupContext, context.getQueryContext()); + List queryResults = jdbcExecutor.execute(executionGroupContext, callback).stream().map(QueryResult.class::cast).collect(Collectors.toList()); + MergeEngine mergeEngine = new MergeEngine(database, executorContext.getProps(), new ConnectionContext()); + MergedResult mergedResult = mergeEngine.merge(queryResults, queryContext.getSqlStatementContext()); + Collection statements = getStatements(executionGroupContext.getInputGroups()); + return new SQLFederationRowEnumerator(mergedResult, queryResults.get(0).getMetaData(), statements); + } + }; + } + private void computeConnectionOffsets(final ExecutionContext context) { for (ExecutionUnit each : context.getExecutionUnits()) { if (executorContext.getConnectionOffsets().containsKey(each.getDataSourceName())) { @@ -267,16 +270,6 @@ private void setParameters(final PreparedStatement preparedStatement, final List } } - private AbstractEnumerable createEnumerable(final MergedResult mergedResult, final QueryResultMetaData metaData, final Collection statements) { - return new AbstractEnumerable() { - - @Override - public Enumerator enumerator() { - return new SQLFederationRowEnumerator(mergedResult, metaData, statements); - } - }; - } - private QueryContext createQueryContext(final ShardingSphereMetaData metaData, final EnumerableScanExecutorContext sqlString, final DatabaseType databaseType, final boolean useCache) { String sql = sqlString.getSql().replace("\n", " "); SQLStatement sqlStatement = new SQLStatementParserEngine(databaseType, diff --git a/test/e2e/sql/src/test/resources/cases/dql/dql-integration-select-pagination-group-by-order-by.xml b/test/e2e/sql/src/test/resources/cases/dql/dql-integration-select-pagination-group-by-order-by.xml index 8638107a18fd7..4c4e7412a84e3 100644 --- a/test/e2e/sql/src/test/resources/cases/dql/dql-integration-select-pagination-group-by-order-by.xml +++ b/test/e2e/sql/src/test/resources/cases/dql/dql-integration-select-pagination-group-by-order-by.xml @@ -29,8 +29,7 @@ - - + @@ -46,7 +45,7 @@ - + @@ -62,7 +61,7 @@ - +